Title: [251746] trunk
Revision
251746
Author
[email protected]
Date
2019-10-29 17:28:20 -0700 (Tue, 29 Oct 2019)

Log Message

UserMediaRequest should not prevent entering the back/forward cache
https://bugs.webkit.org/show_bug.cgi?id=203098
<rdar://problem/56716101>

Reviewed by Eric Carlson.

Source/WebCore:

Allow pages to enter the back/forward cache, even if they have a pending
getUserMedia promise. Whenever we get a permission decision from the
UIProcess, we now schedule a task to resolve/reject the promise on the
WindowEventLoop. The WindowEventLoop properly gets suspended while in
the back/forward cache.

Test: http/tests/navigation/page-cache-getUserMedia-pending-promise.html

* Modules/mediastream/MediaDevices.cpp:
(WebCore::MediaDevices::getUserMedia const):
If the document is not fully active, reject the promise with an InvalidStateError, as per:
- https://w3c.github.io/mediacapture-main/#dom-mediadevices-getusermedia (Step 4)

* Modules/mediastream/UserMediaRequest.cpp:
(WebCore::UserMediaRequest::allow):
(WebCore::UserMediaRequest::deny):
(WebCore::UserMediaRequest::shouldPreventEnteringBackForwardCache_DEPRECATED const): Deleted.
* Modules/mediastream/UserMediaRequest.h:

LayoutTests:

Add layout test coverage.

* fast/mediastream/MediaDevices-getUserMedia-expected.txt:
* http/tests/navigation/page-cache-getUserMedia-pending-promise-expected.txt: Added.
* http/tests/navigation/page-cache-getUserMedia-pending-promise.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (251745 => 251746)


--- trunk/LayoutTests/ChangeLog	2019-10-30 00:21:19 UTC (rev 251745)
+++ trunk/LayoutTests/ChangeLog	2019-10-30 00:28:20 UTC (rev 251746)
@@ -1,3 +1,17 @@
+2019-10-29  Chris Dumez  <[email protected]>
+
+        UserMediaRequest should not prevent entering the back/forward cache
+        https://bugs.webkit.org/show_bug.cgi?id=203098
+        <rdar://problem/56716101>
+
+        Reviewed by Eric Carlson.
+
+        Add layout test coverage.
+
+        * fast/mediastream/MediaDevices-getUserMedia-expected.txt:
+        * http/tests/navigation/page-cache-getUserMedia-pending-promise-expected.txt: Added.
+        * http/tests/navigation/page-cache-getUserMedia-pending-promise.html: Added.
+
 2019-10-29  Peng Liu  <[email protected]>
 
         [Picture-in-Picture Web API] Implement PictureInPictureWindow

Modified: trunk/LayoutTests/fast/mediastream/MediaDevices-getUserMedia-expected.txt (251745 => 251746)


--- trunk/LayoutTests/fast/mediastream/MediaDevices-getUserMedia-expected.txt	2019-10-30 00:21:19 UTC (rev 251745)
+++ trunk/LayoutTests/fast/mediastream/MediaDevices-getUserMedia-expected.txt	2019-10-30 00:28:20 UTC (rev 251746)
@@ -6,9 +6,9 @@
 PASS typeof navigator.mediaDevices.webkitGetUserMedia is 'undefined'
 
 PASS navigator.mediaDevices.getUserMedia({audio:true}).then(gotStream1); did not throw exception.
+PASS navigator.mediaDevices.getUserMedia.apply(undefined) rejected with error: TypeError: Can only call MediaDevices.getUserMedia on instances of MediaDevices
 PASS navigator.mediaDevices.getUserMedia() rejected with error: TypeError: Type error
 PASS navigator.mediaDevices.getUserMedia({}) rejected with error: TypeError: Type error
-PASS navigator.mediaDevices.getUserMedia.apply(undefined) rejected with error: TypeError: Can only call MediaDevices.getUserMedia on instances of MediaDevices
 PASS Stream 1 generated.
 PASS stream.getAudioTracks().length is 1
 PASS stream.getVideoTracks().length is 0

Added: trunk/LayoutTests/http/tests/navigation/page-cache-getUserMedia-pending-promise-expected.txt (0 => 251746)


--- trunk/LayoutTests/http/tests/navigation/page-cache-getUserMedia-pending-promise-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/http/tests/navigation/page-cache-getUserMedia-pending-promise-expected.txt	2019-10-30 00:28:20 UTC (rev 251746)
@@ -0,0 +1,15 @@
+Tests that a page with a pending getUserMedia request is able to go into the back/forward cache.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+pageshow - not from cache
+pagehide - entering cache
+pageshow - from cache
+PASS Page was restored from Page Cache
+PASS Promised was resolved
+PASS restoredFromPageCache is true
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/http/tests/navigation/page-cache-getUserMedia-pending-promise.html (0 => 251746)


--- trunk/LayoutTests/http/tests/navigation/page-cache-getUserMedia-pending-promise.html	                        (rev 0)
+++ trunk/LayoutTests/http/tests/navigation/page-cache-getUserMedia-pending-promise.html	2019-10-30 00:28:20 UTC (rev 251746)
@@ -0,0 +1,49 @@
+<!-- webkit-test-runner [ enableBackForwardCache=true ] -->
+<!DOCTYPE html>
+<html>
+<head>
+<script src=""
+</head>
+<body>
+<script>
+description('Tests that a page with a pending getUserMedia request is able to go into the back/forward cache.');
+jsTestIsAsync = true;
+let restoredFromPageCache = false;
+
+if (window.testRunner)
+    testRunner.setUserMediaPermission(true);
+
+window.addEventListener("pageshow", function(event) {
+    debug("pageshow - " + (event.persisted ? "" : "not ") + "from cache");
+    if (event.persisted) {
+        testPassed("Page was restored from Page Cache");
+        restoredFromPageCache = true;
+    }
+});
+
+window.addEventListener("pagehide", function(event) {
+    debug("pagehide - " + (event.persisted ? "" : "not ") + "entering cache");
+    if (!event.persisted) {
+        testFailed("Page failed to enter the Page Cache");
+        finishJSTest();
+    }
+
+    navigator.mediaDevices.getUserMedia({ audio: true }).then(() => {
+        testPassed("Promised was resolved");
+        shouldBeTrue("restoredFromPageCache");
+        finishJSTest();
+    }, () => {
+        testFailed("Promise was rejected");
+        finishJSTest();
+    });
+});
+
+_onload_ = () => {
+    setTimeout(() => {
+        testLink.click();
+    }, 0);
+}
+</script>
+<a id="testLink" href="" style="display: none">Link</a>
+</body>
+</html>

Modified: trunk/LayoutTests/platform/mac-wk1/TestExpectations (251745 => 251746)


--- trunk/LayoutTests/platform/mac-wk1/TestExpectations	2019-10-30 00:21:19 UTC (rev 251745)
+++ trunk/LayoutTests/platform/mac-wk1/TestExpectations	2019-10-30 00:28:20 UTC (rev 251746)
@@ -59,6 +59,7 @@
 http/tests/media/media-stream
 http/tests/ssl/media-stream
 inspector/page/overrideSetting-MockCaptureDevicesEnabled.html [ Skip ]
+http/tests/navigation/page-cache-getUserMedia-pending-promise.html [ Skip ]
 
 # Datalist is unsupported in WK1
 accessibility/datalist.html [ WontFix ]
@@ -819,4 +820,4 @@
 webkit.org/b/203501 imported/w3c/web-platform-tests/css/css-animations/animation-opacity-pause-and-set-time.html [ ImageOnlyFailure ]
 webkit.org/b/203501 imported/w3c/web-platform-tests/css/css-animations/animation-transform-pause-and-set-time.html [ ImageOnlyFailure ]
 
-webkit.org/b/203517 imported/w3c/web-platform-tests/css/css-sizing/dynamic-available-size-iframe.html [ Pass ImageOnlyFailure ]
\ No newline at end of file
+webkit.org/b/203517 imported/w3c/web-platform-tests/css/css-sizing/dynamic-available-size-iframe.html [ Pass ImageOnlyFailure ]

Modified: trunk/LayoutTests/platform/win/TestExpectations (251745 => 251746)


--- trunk/LayoutTests/platform/win/TestExpectations	2019-10-30 00:21:19 UTC (rev 251745)
+++ trunk/LayoutTests/platform/win/TestExpectations	2019-10-30 00:28:20 UTC (rev 251746)
@@ -866,6 +866,7 @@
 fast/mediastream [ Skip ]
 imported/w3c/web-platform-tests/mediacapture-streams [ Skip ]
 http/tests/media/media-stream [ Skip ]
+http/tests/navigation/page-cache-getUserMedia-pending-promise.html [ Skip ]
 
 # needs enhanced eventSender.contextMenu() return value
 #webkit.org/b/45021 media/context-menu-actions.html

Modified: trunk/Source/WebCore/ChangeLog (251745 => 251746)


--- trunk/Source/WebCore/ChangeLog	2019-10-30 00:21:19 UTC (rev 251745)
+++ trunk/Source/WebCore/ChangeLog	2019-10-30 00:28:20 UTC (rev 251746)
@@ -1,3 +1,30 @@
+2019-10-29  Chris Dumez  <[email protected]>
+
+        UserMediaRequest should not prevent entering the back/forward cache
+        https://bugs.webkit.org/show_bug.cgi?id=203098
+        <rdar://problem/56716101>
+
+        Reviewed by Eric Carlson.
+
+        Allow pages to enter the back/forward cache, even if they have a pending
+        getUserMedia promise. Whenever we get a permission decision from the
+        UIProcess, we now schedule a task to resolve/reject the promise on the
+        WindowEventLoop. The WindowEventLoop properly gets suspended while in
+        the back/forward cache.
+
+        Test: http/tests/navigation/page-cache-getUserMedia-pending-promise.html
+
+        * Modules/mediastream/MediaDevices.cpp:
+        (WebCore::MediaDevices::getUserMedia const):
+        If the document is not fully active, reject the promise with an InvalidStateError, as per:
+        - https://w3c.github.io/mediacapture-main/#dom-mediadevices-getusermedia (Step 4)
+
+        * Modules/mediastream/UserMediaRequest.cpp:
+        (WebCore::UserMediaRequest::allow):
+        (WebCore::UserMediaRequest::deny):
+        (WebCore::UserMediaRequest::shouldPreventEnteringBackForwardCache_DEPRECATED const): Deleted.
+        * Modules/mediastream/UserMediaRequest.h:
+
 2019-10-29  Peng Liu  <[email protected]>
 
         [Picture-in-Picture Web API] Implement PictureInPictureWindow

Modified: trunk/Source/WebCore/Modules/mediastream/MediaDevices.cpp (251745 => 251746)


--- trunk/Source/WebCore/Modules/mediastream/MediaDevices.cpp	2019-10-30 00:21:19 UTC (rev 251745)
+++ trunk/Source/WebCore/Modules/mediastream/MediaDevices.cpp	2019-10-30 00:28:20 UTC (rev 251746)
@@ -107,8 +107,10 @@
 void MediaDevices::getUserMedia(const StreamConstraints& constraints, Promise&& promise) const
 {
     auto* document = this->document();
-    if (!document)
+    if (!document || !document->isFullyActive()) {
+        promise.reject(Exception { InvalidStateError, "Document is not fully active"_s });
         return;
+    }
 
     auto audioConstraints = createMediaConstraints(constraints.audio);
     auto videoConstraints = createMediaConstraints(constraints.video);

Modified: trunk/Source/WebCore/Modules/mediastream/UserMediaRequest.cpp (251745 => 251746)


--- trunk/Source/WebCore/Modules/mediastream/UserMediaRequest.cpp	2019-10-30 00:21:19 UTC (rev 251745)
+++ trunk/Source/WebCore/Modules/mediastream/UserMediaRequest.cpp	2019-10-30 00:28:20 UTC (rev 251746)
@@ -47,6 +47,7 @@
 #include "RealtimeMediaSourceCenter.h"
 #include "Settings.h"
 #include "UserMediaController.h"
+#include "WindowEventLoop.h"
 #include <wtf/Scope.h>
 
 namespace WebCore {
@@ -229,48 +230,53 @@
 void UserMediaRequest::allow(CaptureDevice&& audioDevice, CaptureDevice&& videoDevice, String&& deviceIdentifierHashSalt, CompletionHandler<void()>&& completionHandler)
 {
     RELEASE_LOG(MediaStream, "UserMediaRequest::allow %s %s", audioDevice ? audioDevice.persistentId().utf8().data() : "", videoDevice ? videoDevice.persistentId().utf8().data() : "");
+    auto* document = this->document();
+    if (!document)
+        return completionHandler();
 
-    auto callback = [this, protector = makePendingActivity(*this), completionHandler = WTFMove(completionHandler)](RefPtr<MediaStreamPrivate>&& privateStream) mutable {
-        auto scopeExit = makeScopeExit([completionHandler = WTFMove(completionHandler)]() mutable {
-            completionHandler();
-        });
-        if (isContextStopped())
-            return;
+    document->eventLoop().queueTask(TaskSource::UserInteraction, *document, [this, protectedThis = makeRef(*this), audioDevice = WTFMove(audioDevice), videoDevice = WTFMove(videoDevice), deviceIdentifierHashSalt = WTFMove(deviceIdentifierHashSalt), completionHandler = WTFMove(completionHandler)]() mutable {
+        auto callback = [this, protector = makePendingActivity(*this), completionHandler = WTFMove(completionHandler)](RefPtr<MediaStreamPrivate>&& privateStream) mutable {
+            auto scopeExit = makeScopeExit([completionHandler = WTFMove(completionHandler)]() mutable {
+                completionHandler();
+            });
+            if (isContextStopped())
+                return;
 
-        if (!privateStream) {
-            RELEASE_LOG(MediaStream, "UserMediaRequest::allow failed to create media stream!");
-            deny(MediaAccessDenialReason::HardwareError);
-            return;
-        }
+            if (!privateStream) {
+                RELEASE_LOG(MediaStream, "UserMediaRequest::allow failed to create media stream!");
+                deny(MediaAccessDenialReason::HardwareError);
+                return;
+            }
 
-        auto& document = downcast<Document>(*m_scriptExecutionContext);
-        privateStream->monitorOrientation(document.orientationNotifier());
+            auto& document = downcast<Document>(*m_scriptExecutionContext);
+            privateStream->monitorOrientation(document.orientationNotifier());
 
-        auto stream = MediaStream::create(document, privateStream.releaseNonNull());
-        stream->startProducingData();
+            auto stream = MediaStream::create(document, privateStream.releaseNonNull());
+            stream->startProducingData();
 
-        if (!isMediaStreamCorrectlyStarted(stream)) {
-            deny(MediaAccessDenialReason::HardwareError);
-            return;
-        }
+            if (!isMediaStreamCorrectlyStarted(stream)) {
+                deny(MediaAccessDenialReason::HardwareError);
+                return;
+            }
 
-        ASSERT(document.isCapturing());
-        stream->document()->setHasCaptureMediaStreamTrack();
-        m_promise->resolve(WTFMove(stream));
-    };
+            ASSERT(document.isCapturing());
+            stream->document()->setHasCaptureMediaStreamTrack();
+            m_promise->resolve(WTFMove(stream));
+        };
 
-    auto& document = downcast<Document>(*scriptExecutionContext());
-    document.setDeviceIDHashSalt(deviceIdentifierHashSalt);
+        auto& document = downcast<Document>(*scriptExecutionContext());
+        document.setDeviceIDHashSalt(deviceIdentifierHashSalt);
 
-    RealtimeMediaSourceCenter::singleton().createMediaStream(document.logger(), WTFMove(callback), WTFMove(deviceIdentifierHashSalt), WTFMove(audioDevice), WTFMove(videoDevice), m_request);
+        RealtimeMediaSourceCenter::singleton().createMediaStream(document.logger(), WTFMove(callback), WTFMove(deviceIdentifierHashSalt), WTFMove(audioDevice), WTFMove(videoDevice), m_request);
 
-    if (!m_scriptExecutionContext)
-        return;
+        if (!m_scriptExecutionContext)
+            return;
 
 #if ENABLE(WEB_RTC)
-    if (auto* page = document.page())
-        page->rtcController().disableICECandidateFilteringForDocument(document);
+        if (auto* page = document.page())
+            page->rtcController().disableICECandidateFilteringForDocument(document);
 #endif
+    });
 }
 
 void UserMediaRequest::deny(MediaAccessDenialReason reason, const String& message)
@@ -318,10 +324,12 @@
         break;
     }
 
-    if (!message.isEmpty())
-        m_promise->reject(code, message);
-    else
-        m_promise->reject(code);
+    document()->eventLoop().queueTask(TaskSource::UserInteraction, *document(), [this, protectedThis = makeRef(*this), code, message]() mutable {
+        if (!message.isEmpty())
+            m_promise->reject(code, message);
+        else
+            m_promise->reject(code);
+    });
 }
 
 void UserMediaRequest::stop()
@@ -336,12 +344,6 @@
     return "UserMediaRequest";
 }
 
-// FIXME: This should never prevent entering the back/forward cache.
-bool UserMediaRequest::shouldPreventEnteringBackForwardCache_DEPRECATED() const
-{
-    return hasPendingActivity();
-}
-
 Document* UserMediaRequest::document() const
 {
     return downcast<Document>(m_scriptExecutionContext);

Modified: trunk/Source/WebCore/Modules/mediastream/UserMediaRequest.h (251745 => 251746)


--- trunk/Source/WebCore/Modules/mediastream/UserMediaRequest.h	2019-10-30 00:21:19 UTC (rev 251745)
+++ trunk/Source/WebCore/Modules/mediastream/UserMediaRequest.h	2019-10-30 00:28:20 UTC (rev 251746)
@@ -85,7 +85,6 @@
 
     void stop() final;
     const char* activeDOMObjectName() const final;
-    bool shouldPreventEnteringBackForwardCache_DEPRECATED() const final;
 
     void mediaStreamDidFail(RealtimeMediaSource::Type);
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to