Title: [275883] trunk
Revision
275883
Author
[email protected]
Date
2021-04-13 07:10:32 -0700 (Tue, 13 Apr 2021)

Log Message

[macOS] Netflix videos opened in background tab never become playable after foregrounding
https://bugs.webkit.org/show_bug.cgi?id=224384

Reviewed by Eric Carlson.

Source/WebKit:

When a page calls `navigator.requestMediaKeySystemAccess()` in a background tab, the request
will be added to a pending request hash map. However, the current implementation of
`MediaKeySystemPermissionRequestManager` does not send the request when the tab switches
to foreground. This patch fixes this issue by adding the `MediaKeySystemPermissionRequestManager`
object as a `MediaCanStartListener` of `Document`, so that it will send its pending requests
when the tab switches to foreground (`mediaCanStart()`).

* WebKit.xcodeproj/project.pbxproj: Add two cpp files to the xcode project.

* WebProcess/EncryptedMedia/MediaKeySystemPermissionRequestManager.cpp:
Add the object as a `MediaCanStartListener` so that it can send the `MediaKeySystemRequest`
to the UI process when the tab switches to foreground.
(WebKit::MediaKeySystemPermissionRequestManager::startMediaKeySystemRequest):
(WebKit::MediaKeySystemPermissionRequestManager::cancelMediaKeySystemRequest):
(WebKit::MediaKeySystemPermissionRequestManager::mediaCanStart):
* WebProcess/EncryptedMedia/MediaKeySystemPermissionRequestManager.h:

LayoutTests:

* media/encrypted-media/mock-navigator-requestMediaKeySystemAccess-in-background-expected.txt: Added.
* media/encrypted-media/mock-navigator-requestMediaKeySystemAccess-in-background.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (275882 => 275883)


--- trunk/LayoutTests/ChangeLog	2021-04-13 14:08:32 UTC (rev 275882)
+++ trunk/LayoutTests/ChangeLog	2021-04-13 14:10:32 UTC (rev 275883)
@@ -1,3 +1,13 @@
+2021-04-13  Peng Liu  <[email protected]>
+
+        [macOS] Netflix videos opened in background tab never become playable after foregrounding
+        https://bugs.webkit.org/show_bug.cgi?id=224384
+
+        Reviewed by Eric Carlson.
+
+        * media/encrypted-media/mock-navigator-requestMediaKeySystemAccess-in-background-expected.txt: Added.
+        * media/encrypted-media/mock-navigator-requestMediaKeySystemAccess-in-background.html: Added.
+
 2021-04-13  Frédéric Wang  <[email protected]>
 
         ASSERTION FAILED: !m_needExceptionCheck in CloneSerializer::serialize with postMessage({g:42})

Added: trunk/LayoutTests/media/encrypted-media/mock-navigator-requestMediaKeySystemAccess-in-background-expected.txt (0 => 275883)


--- trunk/LayoutTests/media/encrypted-media/mock-navigator-requestMediaKeySystemAccess-in-background-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/media/encrypted-media/mock-navigator-requestMediaKeySystemAccess-in-background-expected.txt	2021-04-13 14:10:32 UTC (rev 275883)
@@ -0,0 +1,13 @@
+RUN(internals.initializeMockMediaSource())
+RUN(mock = internals.registerMockCDM())
+RUN(mock.supportedDataTypes = ["mock"])
+RUN(capabilities.initDataTypes = ["mock"])
+RUN(capabilities.videoCapabilities = [{ contentType: 'video/mock; codecs="mock"' }] )
+
+Call navigator.requestMediaKeySystemAccess() in a background tab
+RUN(promise = navigator.requestMediaKeySystemAccess("org.webkit.mock", [capabilities]))
+
+Switch the tab to foreground
+Promise resolved OK
+END OF TEST
+

Added: trunk/LayoutTests/media/encrypted-media/mock-navigator-requestMediaKeySystemAccess-in-background.html (0 => 275883)


--- trunk/LayoutTests/media/encrypted-media/mock-navigator-requestMediaKeySystemAccess-in-background.html	                        (rev 0)
+++ trunk/LayoutTests/media/encrypted-media/mock-navigator-requestMediaKeySystemAccess-in-background.html	2021-04-13 14:10:32 UTC (rev 275883)
@@ -0,0 +1,39 @@
+<!DOCTYPE html>
+<html>
+<head>
+    <script src=""
+    <script type="text/_javascript_">
+    var mock;
+    var promise;
+    var capabilities = {};
+
+    function runTest()
+    {
+        if (!window.internals) {
+            failTest("Internals is required for this test.")
+            return;
+        }
+
+        run('internals.initializeMockMediaSource()');
+        run('mock = internals.registerMockCDM()');
+        run('mock.supportedDataTypes = ["mock"]');
+        run('capabilities.initDataTypes = ["mock"]');
+        run(`capabilities.videoCapabilities = [{ contentType: 'video/mock; codecs="mock"' }] `);
+
+        consoleWrite("");
+        consoleWrite("Call navigator.requestMediaKeySystemAccess() in a background tab");
+        internals.settings.setCanStartMedia(false);
+        run('promise = navigator.requestMediaKeySystemAccess("org.webkit.mock", [capabilities])');
+
+        setTimeout(() => {
+            consoleWrite("");
+            consoleWrite("Switch the tab to foreground");
+            internals.settings.setCanStartMedia(true);
+            shouldResolve(promise).then(endTest, failTest);
+        }, 200);
+    }
+    </script>
+</head>
+<body _onload_="runTest()">
+</body>
+</html>

Modified: trunk/Source/WebKit/ChangeLog (275882 => 275883)


--- trunk/Source/WebKit/ChangeLog	2021-04-13 14:08:32 UTC (rev 275882)
+++ trunk/Source/WebKit/ChangeLog	2021-04-13 14:10:32 UTC (rev 275883)
@@ -1,3 +1,27 @@
+2021-04-13  Peng Liu  <[email protected]>
+
+        [macOS] Netflix videos opened in background tab never become playable after foregrounding
+        https://bugs.webkit.org/show_bug.cgi?id=224384
+
+        Reviewed by Eric Carlson.
+
+        When a page calls `navigator.requestMediaKeySystemAccess()` in a background tab, the request
+        will be added to a pending request hash map. However, the current implementation of
+        `MediaKeySystemPermissionRequestManager` does not send the request when the tab switches
+        to foreground. This patch fixes this issue by adding the `MediaKeySystemPermissionRequestManager`
+        object as a `MediaCanStartListener` of `Document`, so that it will send its pending requests
+        when the tab switches to foreground (`mediaCanStart()`).
+
+        * WebKit.xcodeproj/project.pbxproj: Add two cpp files to the xcode project.
+
+        * WebProcess/EncryptedMedia/MediaKeySystemPermissionRequestManager.cpp:
+        Add the object as a `MediaCanStartListener` so that it can send the `MediaKeySystemRequest`
+        to the UI process when the tab switches to foreground.
+        (WebKit::MediaKeySystemPermissionRequestManager::startMediaKeySystemRequest):
+        (WebKit::MediaKeySystemPermissionRequestManager::cancelMediaKeySystemRequest):
+        (WebKit::MediaKeySystemPermissionRequestManager::mediaCanStart):
+        * WebProcess/EncryptedMedia/MediaKeySystemPermissionRequestManager.h:
+
 2021-04-13  Philippe Normand  <[email protected]>
 
         [GStreamer] CaptureDevice monitor used from UIProcess

Modified: trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj (275882 => 275883)


--- trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj	2021-04-13 14:08:32 UTC (rev 275882)
+++ trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj	2021-04-13 14:10:32 UTC (rev 275883)
@@ -3014,6 +3014,8 @@
 		1D0530D3259162C900E436F7 /* WebKit-macos.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "WebKit-macos.plist"; sourceTree = "<group>"; };
 		1D0530D4259162C900E436F7 /* WebKit-watchos.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "WebKit-watchos.plist"; sourceTree = "<group>"; };
 		1D0530D52591941500E436F7 /* generate-feature-flags-plist.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = "generate-feature-flags-plist.sh"; sourceTree = "<group>"; };
+		1D0B66192624C11800F9712F /* WebMediaKeySystemClient.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebMediaKeySystemClient.cpp; sourceTree = "<group>"; };
+		1D0B661A2624C19600F9712F /* MediaKeySystemPermissionRequestManager.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = MediaKeySystemPermissionRequestManager.cpp; path = EncryptedMedia/MediaKeySystemPermissionRequestManager.cpp; sourceTree = "<group>"; };
 		1D0ECEAA23FC858400D172F6 /* RemoteMediaPlayerProxyCocoa.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = RemoteMediaPlayerProxyCocoa.mm; sourceTree = "<group>"; };
 		1D32F89823A8465A00B1EA6A /* RemoteMediaResource.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RemoteMediaResource.h; sourceTree = "<group>"; };
 		1D32F89923A8468000B1EA6A /* RemoteMediaResource.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = RemoteMediaResource.cpp; sourceTree = "<group>"; };
@@ -9584,6 +9586,7 @@
 		9ACC07A925C812E700DC6386 /* EncryptedMedia */ = {
 			isa = PBXGroup;
 			children = (
+				1D0B661A2624C19600F9712F /* MediaKeySystemPermissionRequestManager.cpp */,
 				9ACC07AC25C8132D00DC6386 /* MediaKeySystemPermissionRequestManager.h */,
 			);
 			name = EncryptedMedia;
@@ -9774,6 +9777,7 @@
 				BC032D6A10F4378D0058C15A /* WebFrameLoaderClient.h */,
 				BC1BE1DF12D54A410004A228 /* WebGeolocationClient.cpp */,
 				BC1BE1DE12D54A410004A228 /* WebGeolocationClient.h */,
+				1D0B66192624C11800F9712F /* WebMediaKeySystemClient.cpp */,
 				9ACC07B625C81D3300DC6386 /* WebMediaKeySystemClient.h */,
 				513FFB8E201459C2002596EA /* WebMessagePortChannelProvider.cpp */,
 				513FFB8F201459C2002596EA /* WebMessagePortChannelProvider.h */,

Modified: trunk/Source/WebKit/WebProcess/EncryptedMedia/MediaKeySystemPermissionRequestManager.cpp (275882 => 275883)


--- trunk/Source/WebKit/WebProcess/EncryptedMedia/MediaKeySystemPermissionRequestManager.cpp	2021-04-13 14:08:32 UTC (rev 275882)
+++ trunk/Source/WebKit/WebProcess/EncryptedMedia/MediaKeySystemPermissionRequestManager.cpp	2021-04-13 14:10:32 UTC (rev 275883)
@@ -63,6 +63,8 @@
     }
 
     auto& pendingRequests = m_pendingMediaKeySystemRequests.add(document, Vector<Ref<MediaKeySystemRequest>>()).iterator->value;
+    if (pendingRequests.isEmpty())
+        document->addMediaCanStartListener(*this);
     pendingRequests.append(request);
 }
 
@@ -104,9 +106,19 @@
     if (!pendingRequests.isEmpty())
         return;
 
+    document->removeMediaCanStartListener(*this);
     m_pendingMediaKeySystemRequests.remove(iterator);
 }
 
+void MediaKeySystemPermissionRequestManager::mediaCanStart(Document& document)
+{
+    ASSERT(document.page()->canStartMedia());
+
+    auto pendingRequests = m_pendingMediaKeySystemRequests.take(&document);
+    for (auto& pendingRequest : pendingRequests)
+        sendMediaKeySystemRequest(pendingRequest);
+}
+
 void MediaKeySystemPermissionRequestManager::mediaKeySystemWasGranted(uint64_t requestID, CompletionHandler<void()>&& completionHandler)
 {
     auto request = m_ongoingMediaKeySystemRequests.take(makeObjectIdentifier<MediaKeySystemRequestIdentifierType>(requestID));

Modified: trunk/Source/WebKit/WebProcess/EncryptedMedia/MediaKeySystemPermissionRequestManager.h (275882 => 275883)


--- trunk/Source/WebKit/WebProcess/EncryptedMedia/MediaKeySystemPermissionRequestManager.h	2021-04-13 14:08:32 UTC (rev 275882)
+++ trunk/Source/WebKit/WebProcess/EncryptedMedia/MediaKeySystemPermissionRequestManager.h	2021-04-13 14:10:32 UTC (rev 275883)
@@ -28,6 +28,7 @@
 #if ENABLE(ENCRYPTED_MEDIA)
 
 #include "SandboxExtension.h"
+#include <WebCore/MediaCanStartListener.h>
 #include <WebCore/MediaKeySystemClient.h>
 #include <WebCore/MediaKeySystemRequest.h>
 #include <wtf/HashMap.h>
@@ -38,7 +39,7 @@
 
 class WebPage;
 
-class MediaKeySystemPermissionRequestManager {
+class MediaKeySystemPermissionRequestManager : private WebCore::MediaCanStartListener {
     WTF_MAKE_FAST_ALLOCATED;
 public:
     explicit MediaKeySystemPermissionRequestManager(WebPage&);
@@ -52,6 +53,9 @@
 private:
     void sendMediaKeySystemRequest(WebCore::MediaKeySystemRequest&);
 
+    // WebCore::MediaCanStartListener
+    void mediaCanStart(WebCore::Document&) final;
+
     WebPage& m_page;
 
     HashMap<WebCore::MediaKeySystemRequestIdentifier, Ref<WebCore::MediaKeySystemRequest>> m_ongoingMediaKeySystemRequests;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to