Title: [235429] trunk
Revision
235429
Author
you...@apple.com
Date
2018-08-28 11:00:00 -0700 (Tue, 28 Aug 2018)

Log Message

WebKitMediaSession should be GC collectable when its document is being stopped
https://bugs.webkit.org/show_bug.cgi?id=189016

Reviewed by Eric Carlson.

Source/WebCore:

Make sure WebKitMediaSession is  collectable after its document is stopped.
This is done by nullifying m_session when calling close.
This way hasPendingActivity() returns false when stop() is called.

Test: http/tests/media/clearkey/collect-webkit-media-session.html

* Modules/encryptedmedia/legacy/WebKitMediaKeySession.cpp:
(WebCore::WebKitMediaKeySession::WebKitMediaKeySession):
(WebCore::WebKitMediaKeySession::close):
* Modules/encryptedmedia/legacy/WebKitMediaKeySession.h:

LayoutTests:

* http/tests/media/clearkey/collect-webkit-media-session-expected.txt: Added.
* http/tests/media/clearkey/collect-webkit-media-session.html: Added.
* http/tests/media/clearkey/resources/mywebkitmediasessionframe.htm: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (235428 => 235429)


--- trunk/LayoutTests/ChangeLog	2018-08-28 17:53:15 UTC (rev 235428)
+++ trunk/LayoutTests/ChangeLog	2018-08-28 18:00:00 UTC (rev 235429)
@@ -1,3 +1,14 @@
+2018-08-28  Youenn Fablet  <you...@apple.com>
+
+        WebKitMediaSession should be GC collectable when its document is being stopped
+        https://bugs.webkit.org/show_bug.cgi?id=189016
+
+        Reviewed by Eric Carlson.
+
+        * http/tests/media/clearkey/collect-webkit-media-session-expected.txt: Added.
+        * http/tests/media/clearkey/collect-webkit-media-session.html: Added.
+        * http/tests/media/clearkey/resources/mywebkitmediasessionframe.htm: Added.
+
 2018-08-28  Aditya Keerthi  <akeer...@apple.com>
 
         [Datalist] Pressing enter without a selected option shouldn't change the input

Added: trunk/LayoutTests/http/tests/media/clearkey/collect-webkit-media-session-expected.txt (0 => 235429)


--- trunk/LayoutTests/http/tests/media/clearkey/collect-webkit-media-session-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/http/tests/media/clearkey/collect-webkit-media-session-expected.txt	2018-08-28 18:00:00 UTC (rev 235429)
@@ -0,0 +1,4 @@
+
+
+PASS Ensure that the frame's document get collected after being stopped while doing some webkit media session calls 
+

Added: trunk/LayoutTests/http/tests/media/clearkey/collect-webkit-media-session.html (0 => 235429)


--- trunk/LayoutTests/http/tests/media/clearkey/collect-webkit-media-session.html	                        (rev 0)
+++ trunk/LayoutTests/http/tests/media/clearkey/collect-webkit-media-session.html	2018-08-28 18:00:00 UTC (rev 235429)
@@ -0,0 +1,45 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<script src=""
+<script src=""
+<script>
+function waitFor(duration)
+{
+    return new Promise((resolve) => setTimeout(resolve, duration));
+}
+
+var resolveCallback, rejectCallback;
+var promise = new Promise((resolve, reject) => {
+    resolveCallback = resolve;
+    rejectCallback = reject;
+});
+
+async function done()
+{
+    try {
+        const frameIdentifier = internals.documentIdentifier(iframe.contentDocument);
+        iframe.src = ""
+        let counter = 0;
+        while (++counter < 10) {
+            if (!internals.isDocumentAlive(frameIdentifier)) {
+                resolveCallback();
+                return;
+            }
+            if (window.GCController)
+                GCController.collect();
+
+            await waitFor(50);
+        }
+    } finally {
+        rejectCallback("Test failed");
+    }
+}
+
+promise_test((test) => {
+    if (!window.internals)
+        rejectCallback("Test require internals API");
+    return promise;
+}, "Ensure that the frame's document get collected after being stopped while doing some webkit media session calls");
+
+</script>
+<iframe src="" id="iframe"></iframe>

Added: trunk/LayoutTests/http/tests/media/clearkey/resources/mywebkitmediasessionframe.htm (0 => 235429)


--- trunk/LayoutTests/http/tests/media/clearkey/resources/mywebkitmediasessionframe.htm	                        (rev 0)
+++ trunk/LayoutTests/http/tests/media/clearkey/resources/mywebkitmediasessionframe.htm	2018-08-28 18:00:00 UTC (rev 235429)
@@ -0,0 +1,32 @@
+<!DOCTYPE html>
+<html>
+<head>
+    <script>
+        var keyId;
+        var session;
+
+        function go()
+        {
+            video.addEventListener('webkitneedkey', needkey, true);
+            video.src = '';
+        }
+
+        function needkey(event)
+        {
+            if (!video.webkitKeys)
+                video.webkitSetMediaKeys(new WebKitMediaKeys('org.w3c.clearkey'));
+
+            if (!video.webkitKeys) {
+                log('Error: org.w3c.clearkey not supported.');
+                return;
+            }
+
+            session = video.webkitKeys.createSession('application/x-mpegurl', event.initData);
+            parent.done();
+        }
+    </script>
+</head>
+<body _onload_="go()">
+    <video id="video" controls></video>
+</body>
+</html>

Modified: trunk/Source/WebCore/ChangeLog (235428 => 235429)


--- trunk/Source/WebCore/ChangeLog	2018-08-28 17:53:15 UTC (rev 235428)
+++ trunk/Source/WebCore/ChangeLog	2018-08-28 18:00:00 UTC (rev 235429)
@@ -1,3 +1,21 @@
+2018-08-28  Youenn Fablet  <you...@apple.com>
+
+        WebKitMediaSession should be GC collectable when its document is being stopped
+        https://bugs.webkit.org/show_bug.cgi?id=189016
+
+        Reviewed by Eric Carlson.
+
+        Make sure WebKitMediaSession is  collectable after its document is stopped.
+        This is done by nullifying m_session when calling close.
+        This way hasPendingActivity() returns false when stop() is called.
+
+        Test: http/tests/media/clearkey/collect-webkit-media-session.html
+
+        * Modules/encryptedmedia/legacy/WebKitMediaKeySession.cpp:
+        (WebCore::WebKitMediaKeySession::WebKitMediaKeySession):
+        (WebCore::WebKitMediaKeySession::close):
+        * Modules/encryptedmedia/legacy/WebKitMediaKeySession.h:
+
 2018-08-28  Ali Juma  <aj...@chromium.org>
 
         [IntersectionObserver] Fix build after r235424

Modified: trunk/Source/WebCore/Modules/encryptedmedia/legacy/WebKitMediaKeySession.cpp (235428 => 235429)


--- trunk/Source/WebCore/Modules/encryptedmedia/legacy/WebKitMediaKeySession.cpp	2018-08-28 17:53:15 UTC (rev 235428)
+++ trunk/Source/WebCore/Modules/encryptedmedia/legacy/WebKitMediaKeySession.cpp	2018-08-28 18:00:00 UTC (rev 235429)
@@ -56,6 +56,8 @@
     , m_keyRequestTimer(*this, &WebKitMediaKeySession::keyRequestTimerFired)
     , m_addKeyTimer(*this, &WebKitMediaKeySession::addKeyTimerFired)
 {
+    if (m_session)
+        m_sessionId = m_session->sessionId();
 }
 
 WebKitMediaKeySession::~WebKitMediaKeySession()
@@ -68,8 +70,10 @@
 
 void WebKitMediaKeySession::close()
 {
-    if (m_session)
+    if (m_session) {
         m_session->releaseKeys();
+        m_session = nullptr;
+    }
 }
 
 RefPtr<ArrayBuffer> WebKitMediaKeySession::cachedKeyForKeyId(const String& keyId) const
@@ -77,11 +81,6 @@
     return m_session ? m_session->cachedKeyForKeyID(keyId) : nullptr;
 }
 
-const String& WebKitMediaKeySession::sessionId() const
-{
-    return m_session->sessionId();
-}
-
 void WebKitMediaKeySession::generateKeyRequest(const String& mimeType, Ref<Uint8Array>&& initData)
 {
     m_pendingKeyRequests.append({ mimeType, WTFMove(initData) });

Modified: trunk/Source/WebCore/Modules/encryptedmedia/legacy/WebKitMediaKeySession.h (235428 => 235429)


--- trunk/Source/WebCore/Modules/encryptedmedia/legacy/WebKitMediaKeySession.h	2018-08-28 17:53:15 UTC (rev 235428)
+++ trunk/Source/WebCore/Modules/encryptedmedia/legacy/WebKitMediaKeySession.h	2018-08-28 18:00:00 UTC (rev 235429)
@@ -48,7 +48,7 @@
 
     WebKitMediaKeyError* error() { return m_error.get(); }
     const String& keySystem() const { return m_keySystem; }
-    const String& sessionId() const;
+    const String& sessionId() const { return m_sessionId; }
     ExceptionOr<void> update(Ref<Uint8Array>&& key);
     void close();
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to