Skip to content

Commit

Permalink
Use WeakHashMap for m_videoElements in VideoFullscreenManager
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=259498

Reviewed by Eric Carlson.

Use WeakHasMap instead of HashMap of raw pointers.

* Source/WebKit/WebProcess/cocoa/VideoFullscreenManager.h:
* Source/WebKit/WebProcess/cocoa/VideoFullscreenManager.mm:
(WebKit::VideoFullscreenManager::removeContext):
(WebKit::VideoFullscreenManager::setupRemoteLayerHosting):
(WebKit::VideoFullscreenManager::enterVideoFullscreenForVideoElement):
(WebKit::VideoFullscreenManager::exitVideoFullscreenForVideoElement):
(WebKit::VideoFullscreenManager::exitVideoFullscreenToModeWithoutAnimation):
(WebKit::VideoFullscreenManager::updateTextTrackRepresentationForVideoElement):
(WebKit::VideoFullscreenManager::setTextTrackRepresentationContentScaleForVideoElement):
(WebKit::VideoFullscreenManager::setTextTrackRepresentationIsHiddenForVideoElement):

Canonical link: https://commits.webkit.org/266304@main
  • Loading branch information
rniwa committed Jul 25, 2023
1 parent 072aee3 commit bb1cedb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
3 changes: 2 additions & 1 deletion Source/WebKit/WebProcess/cocoa/VideoFullscreenManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include <wtf/HashMap.h>
#include <wtf/RefCounted.h>
#include <wtf/RefPtr.h>
#include <wtf/WeakHashMap.h>

namespace IPC {
class Connection;
Expand Down Expand Up @@ -195,7 +196,7 @@ class VideoFullscreenManager : public RefCounted<VideoFullscreenManager>, privat

WeakPtr<WebPage> m_page;
Ref<PlaybackSessionManager> m_playbackSessionManager;
HashMap<WebCore::HTMLVideoElement*, PlaybackSessionContextIdentifier> m_videoElements;
WeakHashMap<WebCore::HTMLVideoElement, PlaybackSessionContextIdentifier, WebCore::WeakPtrImplWithEventTargetData> m_videoElements;
HashMap<PlaybackSessionContextIdentifier, ModelInterfaceTuple> m_contextMap;
PlaybackSessionContextIdentifier m_controlsManagerContextId;
HashMap<PlaybackSessionContextIdentifier, int> m_clientCounts;
Expand Down
20 changes: 10 additions & 10 deletions Source/WebKit/WebProcess/cocoa/VideoFullscreenManager.mm
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ static FloatRect inlineVideoFrame(HTMLVideoElement& element)
model->setVideoElement(nullptr);
model->removeClient(*interface);
interface->invalidate();
m_videoElements.remove(videoElement.get());
m_videoElements.remove(*videoElement);
m_contextMap.remove(contextId);
}

Expand Down Expand Up @@ -283,7 +283,7 @@ static FloatRect inlineVideoFrame(HTMLVideoElement& element)
void VideoFullscreenManager::setupRemoteLayerHosting(HTMLVideoElement& videoElement)
{
auto contextId = m_playbackSessionManager->contextIdForMediaElement(videoElement);
auto addResult = m_videoElements.add(&videoElement, contextId);
auto addResult = m_videoElements.add(videoElement, contextId);
if (addResult.isNewEntry)
m_playbackSessionManager->sendLogIdentifierForMediaElement(videoElement);
ASSERT(addResult.iterator->value == contextId);
Expand Down Expand Up @@ -328,7 +328,7 @@ static FloatRect inlineVideoFrame(HTMLVideoElement& element)
INFO_LOG(LOGIDENTIFIER);

auto contextId = m_playbackSessionManager->contextIdForMediaElement(videoElement);
auto addResult = m_videoElements.add(&videoElement, contextId);
auto addResult = m_videoElements.add(videoElement, contextId);
if (addResult.isNewEntry)
m_playbackSessionManager->sendLogIdentifierForMediaElement(videoElement);
ASSERT(addResult.iterator->value == contextId);
Expand Down Expand Up @@ -410,9 +410,9 @@ static FloatRect inlineVideoFrame(HTMLVideoElement& element)
{
INFO_LOG(LOGIDENTIFIER);
ASSERT(m_page);
ASSERT(m_videoElements.contains(&videoElement));
ASSERT(m_videoElements.contains(videoElement));

auto contextId = m_videoElements.get(&videoElement);
auto contextId = m_videoElements.get(videoElement);
auto& interface = ensureInterface(contextId);
if (interface.animationState() != VideoFullscreenInterfaceContext::AnimationType::None) {
completionHandler(false);
Expand Down Expand Up @@ -440,12 +440,12 @@ static FloatRect inlineVideoFrame(HTMLVideoElement& element)
INFO_LOG(LOGIDENTIFIER);

ASSERT(m_page);
ASSERT(m_videoElements.contains(&videoElement));
ASSERT(m_videoElements.contains(videoElement));

if (m_videoElementInPictureInPicture == &videoElement)
m_videoElementInPictureInPicture = nullptr;

auto contextId = m_videoElements.get(&videoElement);
auto contextId = m_videoElements.get(videoElement);
if (!contextId.isValid()) {
// We have somehow managed to be asked to exit video fullscreen
// for a video element which was either never in fullscreen or
Expand Down Expand Up @@ -743,15 +743,15 @@ static FloatRect inlineVideoFrame(HTMLVideoElement& element)
{
if (!m_page)
return;
auto contextId = m_videoElements.get(&videoElement);
auto contextId = m_videoElements.get(videoElement);
m_page->send(Messages::VideoFullscreenManagerProxy::TextTrackRepresentationUpdate(contextId, WTFMove(textTrack)));
}

void VideoFullscreenManager::setTextTrackRepresentationContentScaleForVideoElement(WebCore::HTMLVideoElement& videoElement, float scale)
{
if (!m_page)
return;
auto contextId = m_videoElements.get(&videoElement);
auto contextId = m_videoElements.get(videoElement);
m_page->send(Messages::VideoFullscreenManagerProxy::TextTrackRepresentationSetContentsScale(contextId, scale));

}
Expand All @@ -760,7 +760,7 @@ static FloatRect inlineVideoFrame(HTMLVideoElement& element)
{
if (!m_page)
return;
auto contextId = m_videoElements.get(&videoElement);
auto contextId = m_videoElements.get(videoElement);
m_page->send(Messages::VideoFullscreenManagerProxy::TextTrackRepresentationSetHidden(contextId, hidden));

}
Expand Down

0 comments on commit bb1cedb

Please sign in to comment.