Title: [260529] trunk/Source/WebCore
Revision
260529
Author
[email protected]
Date
2020-04-22 12:38:00 -0700 (Wed, 22 Apr 2020)

Log Message

fast/events/event-handler-detached-document-dispatchEvent.html is crashing
https://bugs.webkit.org/show_bug.cgi?id=210859
<rdar://problem/62072269>

Reviewed by Jer Noble.

A media session may not have a Page when it is created, so register with the MediaUsageManager
in inActiveDocumentChanged if necessary.

No new tests, fixes an existing test.

* html/MediaElementSession.cpp:
(WebCore::MediaElementSession::MediaElementSession):
(WebCore::MediaElementSession::~MediaElementSession):
(WebCore::MediaElementSession::addedMediaUsageManagerSessionIfNecessary):
(WebCore::MediaElementSession::inActiveDocumentChanged):
(WebCore::MediaElementSession::updateMediaUsageIfChanged):
* html/MediaElementSession.h:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (260528 => 260529)


--- trunk/Source/WebCore/ChangeLog	2020-04-22 19:24:55 UTC (rev 260528)
+++ trunk/Source/WebCore/ChangeLog	2020-04-22 19:38:00 UTC (rev 260529)
@@ -1,3 +1,24 @@
+2020-04-22  Eric Carlson  <[email protected]>
+
+        fast/events/event-handler-detached-document-dispatchEvent.html is crashing
+        https://bugs.webkit.org/show_bug.cgi?id=210859
+        <rdar://problem/62072269>
+
+        Reviewed by Jer Noble.
+
+        A media session may not have a Page when it is created, so register with the MediaUsageManager
+        in inActiveDocumentChanged if necessary.
+
+        No new tests, fixes an existing test.
+
+        * html/MediaElementSession.cpp:
+        (WebCore::MediaElementSession::MediaElementSession):
+        (WebCore::MediaElementSession::~MediaElementSession):
+        (WebCore::MediaElementSession::addedMediaUsageManagerSessionIfNecessary):
+        (WebCore::MediaElementSession::inActiveDocumentChanged):
+        (WebCore::MediaElementSession::updateMediaUsageIfChanged):
+        * html/MediaElementSession.h:
+
 2020-04-22  Antti Koivisto  <[email protected]>
 
         REGRESSION (r249160): Deleting newline after pasting text ending in a newline results in a discontinuity

Modified: trunk/Source/WebCore/html/MediaElementSession.cpp (260528 => 260529)


--- trunk/Source/WebCore/html/MediaElementSession.cpp	2020-04-22 19:24:55 UTC (rev 260528)
+++ trunk/Source/WebCore/html/MediaElementSession.cpp	2020-04-22 19:38:00 UTC (rev 260529)
@@ -120,20 +120,33 @@
     , m_logIdentifier(element.logIdentifier())
 #endif
 {
-#if ENABLE(MEDIA_USAGE)
-    if (auto page = m_element.document().page())
-        page->chrome().client().addMediaUsageManagerSession(mediaSessionIdentifier(), m_element.sourceApplicationIdentifier(), m_element.document().url());
-#endif
+    addedMediaUsageManagerSessionIfNecessary();
 }
 
 MediaElementSession::~MediaElementSession()
 {
 #if ENABLE(MEDIA_USAGE)
-    if (auto page = m_element.document().page())
+    auto page = m_element.document().page();
+    if (page && m_haveAddedMediaUsageManagerSession)
         page->chrome().client().removeMediaUsageManagerSession(mediaSessionIdentifier());
 #endif
 }
 
+void MediaElementSession::addedMediaUsageManagerSessionIfNecessary()
+{
+#if ENABLE(MEDIA_USAGE)
+    if (m_haveAddedMediaUsageManagerSession)
+        return;
+
+    auto page = m_element.document().page();
+    if (!page)
+        return;
+
+    m_haveAddedMediaUsageManagerSession = true;
+    page->chrome().client().addMediaUsageManagerSession(mediaSessionIdentifier(), m_element.sourceApplicationIdentifier(), m_element.document().url());
+#endif
+}
+
 void MediaElementSession::registerWithDocument(Document& document)
 {
 #if ENABLE(WIRELESS_PLAYBACK_TARGET)
@@ -200,6 +213,7 @@
 {
     m_elementIsHiddenBecauseItWasRemovedFromDOM = !m_element.inActiveDocument();
     scheduleClientDataBufferingCheck();
+    addedMediaUsageManagerSessionIfNecessary();
 }
 
 void MediaElementSession::scheduleClientDataBufferingCheck()
@@ -1068,6 +1082,7 @@
     m_mediaUsageInfo = WTFMove(usage);
 
 #if ENABLE(MEDIA_USAGE)
+    ASSERT(m_haveAddedMediaUsageManagerSession);
     page->chrome().client().updateMediaUsageManagerSessionState(mediaSessionIdentifier(), *m_mediaUsageInfo);
 #endif
 }

Modified: trunk/Source/WebCore/html/MediaElementSession.h (260528 => 260529)


--- trunk/Source/WebCore/html/MediaElementSession.h	2020-04-22 19:24:55 UTC (rev 260528)
+++ trunk/Source/WebCore/html/MediaElementSession.h	2020-04-22 19:38:00 UTC (rev 260529)
@@ -189,6 +189,8 @@
     void clientDataBufferingTimerFired();
     void updateClientDataBuffering();
 
+    void addedMediaUsageManagerSessionIfNecessary();
+
     HTMLMediaElement& m_element;
     BehaviorRestrictions m_restrictions;
 
@@ -216,6 +218,10 @@
 #if !RELEASE_LOG_DISABLED
     const void* m_logIdentifier;
 #endif
+
+#if ENABLE(MEDIA_USAGE)
+    bool m_haveAddedMediaUsageManagerSession { false };
+#endif
 };
 
 String convertEnumerationToString(const MediaPlaybackDenialReason);
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to