Title: [244749] trunk
Revision
244749
Author
[email protected]
Date
2019-04-29 13:04:33 -0700 (Mon, 29 Apr 2019)

Log Message

getDisplayMedia should be called on user gesture
https://bugs.webkit.org/show_bug.cgi?id=197356
Source/WebCore:

Reviewed by Eric Carlson.

Allow getDisplayMedia on user gesture only.
Otherwise reject the promise.
Minor refactoring to align getDisplayMedia, getUserMedia and
enumerateDevices when called with no document.

Test: fast/mediastream/screencapture-user-gesture.html

* Modules/mediastream/MediaDevices.cpp:
(WebCore::MediaDevices::getUserMedia const):
* Modules/mediastream/MediaDevices.h:
* Modules/mediastream/NavigatorMediaDevices.h:
* page/DOMWindow.h:
* testing/Internals.cpp:
(WebCore::Internals::setDisableGetDisplayMediaUserGestureConstraint):
* testing/Internals.h:
* testing/Internals.idl:

Tools:

<rdar://problem/50296074>

Reviewed by Eric Carlson.

Update test configuration to inject internals
so that we can use it to simulate a user click to call getDisplayMedia.

* TestWebKitAPI/Tests/WebKit/getDisplayMedia.html:
* TestWebKitAPI/Tests/WebKitCocoa/GetDisplayMedia.mm:
(TestWebKitAPI::GetDisplayMediaTest::SetUp):

LayoutTests:

Reviewed by Eric Carlson.

* fast/mediastream/media-stream-page-muted.html:
* fast/mediastream/screencapture-user-gesture-expected.txt: Added.
* fast/mediastream/screencapture-user-gesture.html: Added.
* http/tests/media/media-stream/get-display-media-iframe-allow-attribute-expected.txt:
* http/tests/media/media-stream/get-display-media-iframe-allow-attribute.html:
* http/tests/media/media-stream/get-display-media-prompt.html:
* http/tests/media/media-stream/resources/get-display-media-devices-iframe.html:

* resources/testharnessreport.js:

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (244748 => 244749)


--- trunk/LayoutTests/ChangeLog	2019-04-29 19:56:56 UTC (rev 244748)
+++ trunk/LayoutTests/ChangeLog	2019-04-29 20:04:33 UTC (rev 244749)
@@ -1,3 +1,20 @@
+2019-04-29  Youenn Fablet  <[email protected]>
+
+        getDisplayMedia should be called on user gesture
+        https://bugs.webkit.org/show_bug.cgi?id=197356
+
+        Reviewed by Eric Carlson.
+
+        * fast/mediastream/media-stream-page-muted.html:
+        * fast/mediastream/screencapture-user-gesture-expected.txt: Added.
+        * fast/mediastream/screencapture-user-gesture.html: Added.
+        * http/tests/media/media-stream/get-display-media-iframe-allow-attribute-expected.txt:
+        * http/tests/media/media-stream/get-display-media-iframe-allow-attribute.html:
+        * http/tests/media/media-stream/get-display-media-prompt.html:
+        * http/tests/media/media-stream/resources/get-display-media-devices-iframe.html:
+
+        * resources/testharnessreport.js:
+
 2019-04-29  Javier Fernandez  <[email protected]>
 
         line should not be broken before the first space after a word

Modified: trunk/LayoutTests/fast/mediastream/media-stream-page-muted.html (244748 => 244749)


--- trunk/LayoutTests/fast/mediastream/media-stream-page-muted.html	2019-04-29 19:56:56 UTC (rev 244748)
+++ trunk/LayoutTests/fast/mediastream/media-stream-page-muted.html	2019-04-29 20:04:33 UTC (rev 244749)
@@ -4,6 +4,9 @@
     <title>mediastream page muted</title>
     <script src=""
     <script>
+        if (window.internals)
+            internals.setDisableGetDisplayMediaUserGestureConstraint(true);
+
         async function checkPageState(activeState, inactiveState) {
             await new Promise((resolve, reject) => {
                 let retryCount = 0;

Added: trunk/LayoutTests/fast/mediastream/screencapture-user-gesture-expected.txt (0 => 244749)


--- trunk/LayoutTests/fast/mediastream/screencapture-user-gesture-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/mediastream/screencapture-user-gesture-expected.txt	2019-04-29 20:04:33 UTC (rev 244749)
@@ -0,0 +1,4 @@
+
+PASS Allow getDisplayMedia call in case of user gesture 
+PASS Deny getDisplayMedia call if no user gesture 
+

Added: trunk/LayoutTests/fast/mediastream/screencapture-user-gesture.html (0 => 244749)


--- trunk/LayoutTests/fast/mediastream/screencapture-user-gesture.html	                        (rev 0)
+++ trunk/LayoutTests/fast/mediastream/screencapture-user-gesture.html	2019-04-29 20:04:33 UTC (rev 244749)
@@ -0,0 +1,18 @@
+<script src=""
+<script src=""
+<script>
+if (window.internals)
+    internals.setDisableGetDisplayMediaUserGestureConstraint(false);
+
+promise_test(() => {
+    let promise;
+    internals.withUserGesture(() => {
+        promise = navigator.mediaDevices.getDisplayMedia({video : true});
+    });
+    return promise;
+}, "Allow getDisplayMedia call in case of user gesture");
+
+promise_test((test) => {
+    return promise_rejects(test, "InvalidAccessError", navigator.mediaDevices.getDisplayMedia({video : true}));
+}, "Deny getDisplayMedia call if no user gesture");
+</script>

Modified: trunk/LayoutTests/http/tests/media/media-stream/get-display-media-iframe-allow-attribute-expected.txt (244748 => 244749)


--- trunk/LayoutTests/http/tests/media/media-stream/get-display-media-iframe-allow-attribute-expected.txt	2019-04-29 19:56:56 UTC (rev 244748)
+++ trunk/LayoutTests/http/tests/media/media-stream/get-display-media-iframe-allow-attribute-expected.txt	2019-04-29 20:04:33 UTC (rev 244749)
@@ -1,6 +1,6 @@
-CONSOLE MESSAGE: line 5: Trying to call getDisplayMedia from a frame without correct 'allow' attribute.
-CONSOLE MESSAGE: line 5: Trying to call getDisplayMedia from a frame without correct 'allow' attribute.
-CONSOLE MESSAGE: line 5: Trying to call getDisplayMedia from a frame without correct 'allow' attribute.
+CONSOLE MESSAGE: line 8: Trying to call getDisplayMedia from a frame without correct 'allow' attribute.
+CONSOLE MESSAGE: line 8: Trying to call getDisplayMedia from a frame without correct 'allow' attribute.
+CONSOLE MESSAGE: line 8: Trying to call getDisplayMedia from a frame without correct 'allow' attribute.
      
 
 PASS: <iframe allow=''> got "deny"

Modified: trunk/LayoutTests/http/tests/media/media-stream/get-display-media-prompt.html (244748 => 244749)


--- trunk/LayoutTests/http/tests/media/media-stream/get-display-media-prompt.html	2019-04-29 19:56:56 UTC (rev 244748)
+++ trunk/LayoutTests/http/tests/media/media-stream/get-display-media-prompt.html	2019-04-29 20:04:33 UTC (rev 244749)
@@ -9,6 +9,8 @@
     <div id="console"></div>
 
 <script>
+    if (window.internals)
+        internals.setDisableGetDisplayMediaUserGestureConstraint(true);
 
     let stream;
     let err;
@@ -127,4 +129,4 @@
 </script>
 <script src=""
 </body>
-</html>
\ No newline at end of file
+</html>

Modified: trunk/LayoutTests/http/tests/media/media-stream/resources/get-display-media-devices-iframe.html (244748 => 244749)


--- trunk/LayoutTests/http/tests/media/media-stream/resources/get-display-media-devices-iframe.html	2019-04-29 19:56:56 UTC (rev 244748)
+++ trunk/LayoutTests/http/tests/media/media-stream/resources/get-display-media-devices-iframe.html	2019-04-29 20:04:33 UTC (rev 244749)
@@ -1,4 +1,7 @@
 <script>
+    if (window.internals)
+        internals.setDisableGetDisplayMediaUserGestureConstraint(true);
+
     async function enumerate(event)
     {
         let result;

Modified: trunk/LayoutTests/resources/testharnessreport.js (244748 => 244749)


--- trunk/LayoutTests/resources/testharnessreport.js	2019-04-29 19:56:56 UTC (rev 244748)
+++ trunk/LayoutTests/resources/testharnessreport.js	2019-04-29 20:04:33 UTC (rev 244749)
@@ -29,6 +29,9 @@
     }
 }
 
+if (self.internals && internals.setDisableGetDisplayMediaUserGestureConstraint)
+    internals.setDisableGetDisplayMediaUserGestureConstraint(true);
+
 if (self.internals && internals.setICECandidateFiltering)
     internals.setICECandidateFiltering(false);
 

Modified: trunk/Source/WebCore/ChangeLog (244748 => 244749)


--- trunk/Source/WebCore/ChangeLog	2019-04-29 19:56:56 UTC (rev 244748)
+++ trunk/Source/WebCore/ChangeLog	2019-04-29 20:04:33 UTC (rev 244749)
@@ -1,3 +1,27 @@
+2019-04-29  Youenn Fablet  <[email protected]>
+
+        getDisplayMedia should be called on user gesture
+        https://bugs.webkit.org/show_bug.cgi?id=197356
+
+        Reviewed by Eric Carlson.
+
+        Allow getDisplayMedia on user gesture only.
+        Otherwise reject the promise.
+        Minor refactoring to align getDisplayMedia, getUserMedia and
+        enumerateDevices when called with no document.
+
+        Test: fast/mediastream/screencapture-user-gesture.html
+
+        * Modules/mediastream/MediaDevices.cpp:
+        (WebCore::MediaDevices::getUserMedia const):
+        * Modules/mediastream/MediaDevices.h:
+        * Modules/mediastream/NavigatorMediaDevices.h:
+        * page/DOMWindow.h:
+        * testing/Internals.cpp:
+        (WebCore::Internals::setDisableGetDisplayMediaUserGestureConstraint):
+        * testing/Internals.h:
+        * testing/Internals.idl:
+
 2019-04-29  Javier Fernandez  <[email protected]>
 
         line should not be broken before the first space after a word

Modified: trunk/Source/WebCore/Modules/mediastream/MediaDevices.cpp (244748 => 244749)


--- trunk/Source/WebCore/Modules/mediastream/MediaDevices.cpp	2019-04-29 19:56:56 UTC (rev 244748)
+++ trunk/Source/WebCore/Modules/mediastream/MediaDevices.cpp	2019-04-29 20:04:33 UTC (rev 244749)
@@ -102,10 +102,8 @@
 void MediaDevices::getUserMedia(const StreamConstraints& constraints, Promise&& promise) const
 {
     auto* document = this->document();
-    if (!document) {
-        promise.reject(Exception { InvalidStateError });
+    if (!document)
         return;
-    }
 
     auto audioConstraints = createMediaConstraints(constraints.audio);
     auto videoConstraints = createMediaConstraints(constraints.video);
@@ -114,20 +112,21 @@
 
     auto request = UserMediaRequest::create(*document, { MediaStreamRequest::Type::UserMedia, WTFMove(audioConstraints), WTFMove(videoConstraints) }, WTFMove(promise));
     request->start();
-
-    return;
 }
 
-ExceptionOr<void> MediaDevices::getDisplayMedia(const StreamConstraints& constraints, Promise&& promise) const
+void MediaDevices::getDisplayMedia(const StreamConstraints& constraints, Promise&& promise) const
 {
     auto* document = this->document();
     if (!document)
-        return Exception { InvalidStateError };
+        return;
 
+    if (!m_disableGetDisplayMediaUserGestureConstraint && !UserGestureIndicator::processingUserGesture()) {
+        promise.reject(Exception { InvalidAccessError, "getDisplayMedia must be called from a user gesture handler."_s });
+        return;
+    }
+
     auto request = UserMediaRequest::create(*document, { MediaStreamRequest::Type::DisplayMedia, { }, createMediaConstraints(constraints.video) }, WTFMove(promise));
     request->start();
-
-    return { };
 }
 
 void MediaDevices::enumerateDevices(EnumerateDevicesPromise&& promise) const

Modified: trunk/Source/WebCore/Modules/mediastream/MediaDevices.h (244748 => 244749)


--- trunk/Source/WebCore/Modules/mediastream/MediaDevices.h	2019-04-29 19:56:56 UTC (rev 244748)
+++ trunk/Source/WebCore/Modules/mediastream/MediaDevices.h	2019-04-29 20:04:33 UTC (rev 244749)
@@ -76,7 +76,7 @@
         Variant<bool, MediaTrackConstraints> audio;
     };
     void getUserMedia(const StreamConstraints&, Promise&&) const;
-    ExceptionOr<void> getDisplayMedia(const StreamConstraints&, Promise&&) const;
+    void getDisplayMedia(const StreamConstraints&, Promise&&) const;
     void enumerateDevices(EnumerateDevicesPromise&&) const;
     MediaTrackSupportedConstraints getSupportedConstraints();
 
@@ -83,6 +83,8 @@
     using RefCounted<MediaDevices>::ref;
     using RefCounted<MediaDevices>::deref;
 
+    void setDisableGetDisplayMediaUserGestureConstraint(bool value) { m_disableGetDisplayMediaUserGestureConstraint = value; }
+
 private:
     explicit MediaDevices(Document&);
 
@@ -107,6 +109,7 @@
     UserMediaClient::DeviceChangeObserverToken m_deviceChangeToken;
     const EventNames& m_eventNames; // Need to cache this so we can use it from GC threads.
     bool m_listeningForDeviceChanges { false };
+    bool m_disableGetDisplayMediaUserGestureConstraint { false };
 };
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/Modules/mediastream/NavigatorMediaDevices.h (244748 => 244749)


--- trunk/Source/WebCore/Modules/mediastream/NavigatorMediaDevices.h	2019-04-29 19:56:56 UTC (rev 244748)
+++ trunk/Source/WebCore/Modules/mediastream/NavigatorMediaDevices.h	2019-04-29 20:04:33 UTC (rev 244749)
@@ -47,7 +47,7 @@
     virtual ~NavigatorMediaDevices();
     static NavigatorMediaDevices* from(Navigator*);
 
-    static MediaDevices* mediaDevices(Navigator&);
+    WEBCORE_TESTSUPPORT_EXPORT static MediaDevices* mediaDevices(Navigator&);
     MediaDevices* mediaDevices() const;
 
 private:

Modified: trunk/Source/WebCore/page/DOMWindow.h (244748 => 244749)


--- trunk/Source/WebCore/page/DOMWindow.h	2019-04-29 19:56:56 UTC (rev 244748)
+++ trunk/Source/WebCore/page/DOMWindow.h	2019-04-29 20:04:33 UTC (rev 244749)
@@ -158,7 +158,7 @@
     BarProp& scrollbars();
     BarProp& statusbar();
     BarProp& toolbar();
-    Navigator& navigator();
+    WEBCORE_EXPORT Navigator& navigator();
     Navigator* optionalNavigator() const { return m_navigator.get(); }
     Navigator& clientInformation() { return navigator(); }
 

Modified: trunk/Source/WebCore/testing/Internals.cpp (244748 => 244749)


--- trunk/Source/WebCore/testing/Internals.cpp	2019-04-29 19:56:56 UTC (rev 244748)
+++ trunk/Source/WebCore/testing/Internals.cpp	2019-04-29 20:04:33 UTC (rev 244749)
@@ -108,6 +108,7 @@
 #include "LibWebRTCProvider.h"
 #include "LoaderStrategy.h"
 #include "MallocStatistics.h"
+#include "MediaDevices.h"
 #include "MediaEngineConfigurationFactory.h"
 #include "MediaPlayer.h"
 #include "MediaProducer.h"
@@ -118,6 +119,7 @@
 #include "MockLibWebRTCPeerConnection.h"
 #include "MockPageOverlay.h"
 #include "MockPageOverlayClient.h"
+#include "NavigatorMediaDevices.h"
 #include "NetworkLoadInformation.h"
 #include "Page.h"
 #include "PageCache.h"
@@ -4705,6 +4707,15 @@
     track.source().setInterruptedForTesting(interrupted);
 }
 
+void Internals::setDisableGetDisplayMediaUserGestureConstraint(bool value)
+{
+    Document* document = contextDocument();
+    if (!document || !document->domWindow())
+        return;
+
+    if (auto* mediaDevices = NavigatorMediaDevices::mediaDevices(document->domWindow()->navigator()))
+        mediaDevices->setDisableGetDisplayMediaUserGestureConstraint(value);
+}
 #endif
 
 String Internals::audioSessionCategory() const

Modified: trunk/Source/WebCore/testing/Internals.h (244748 => 244749)


--- trunk/Source/WebCore/testing/Internals.h	2019-04-29 19:56:56 UTC (rev 244748)
+++ trunk/Source/WebCore/testing/Internals.h	2019-04-29 20:04:33 UTC (rev 244749)
@@ -706,6 +706,7 @@
     void simulateMediaStreamTrackCaptureSourceFailure(MediaStreamTrack&);
     void setMediaStreamTrackIdentifier(MediaStreamTrack&, String&& id);
     void setMediaStreamSourceInterrupted(MediaStreamTrack&, bool);
+    void setDisableGetDisplayMediaUserGestureConstraint(bool);
 #endif
 
     String audioSessionCategory() const;

Modified: trunk/Source/WebCore/testing/Internals.idl (244748 => 244749)


--- trunk/Source/WebCore/testing/Internals.idl	2019-04-29 19:56:56 UTC (rev 244748)
+++ trunk/Source/WebCore/testing/Internals.idl	2019-04-29 20:04:33 UTC (rev 244749)
@@ -679,6 +679,7 @@
     [Conditional=MEDIA_STREAM] void simulateMediaStreamTrackCaptureSourceFailure(MediaStreamTrack track);
     [Conditional=MEDIA_STREAM] void setMediaStreamTrackIdentifier(MediaStreamTrack track, DOMString identifier);
     [Conditional=MEDIA_STREAM] void setMediaStreamSourceInterrupted(MediaStreamTrack track, boolean interrupted);
+    [Conditional=MEDIA_STREAM] void setDisableGetDisplayMediaUserGestureConstraint(boolean value);
 
     unsigned long long documentIdentifier(Document document);
     boolean isDocumentAlive(unsigned long long documentIdentifier);

Modified: trunk/Tools/ChangeLog (244748 => 244749)


--- trunk/Tools/ChangeLog	2019-04-29 19:56:56 UTC (rev 244748)
+++ trunk/Tools/ChangeLog	2019-04-29 20:04:33 UTC (rev 244749)
@@ -1,3 +1,18 @@
+2019-04-29  Youenn Fablet  <[email protected]>
+
+        getDisplayMedia should be called on user gesture
+        https://bugs.webkit.org/show_bug.cgi?id=197356
+        <rdar://problem/50296074>
+
+        Reviewed by Eric Carlson.
+
+        Update test configuration to inject internals
+        so that we can use it to simulate a user click to call getDisplayMedia.
+
+        * TestWebKitAPI/Tests/WebKit/getDisplayMedia.html:
+        * TestWebKitAPI/Tests/WebKitCocoa/GetDisplayMedia.mm:
+        (TestWebKitAPI::GetDisplayMediaTest::SetUp):
+
 2019-04-26  Stephanie Lewis  <[email protected]>
 
         run-benchmarks should have an intial prep and restore env call for tasks that are too expensive to do for every iteration

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKit/getDisplayMedia.html (244748 => 244749)


--- trunk/Tools/TestWebKitAPI/Tests/WebKit/getDisplayMedia.html	2019-04-29 19:56:56 UTC (rev 244748)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit/getDisplayMedia.html	2019-04-29 20:04:33 UTC (rev 244749)
@@ -7,16 +7,18 @@
 
             function promptForCapture(constraints)
             {
-                navigator.mediaDevices.getDisplayMedia(constraints)
-                .then((s) => {
-                    stream = s;
-                    video.srcObject = stream;
-                    if (window.webkit)
-                      window.webkit.messageHandlers.testHandler.postMessage('allowed');
-                })
-                .catch((error) => {
-                    if (window.webkit)
-                       window.webkit.messageHandlers.testHandler.postMessage('denied');
+                window.internals.withUserGesture(async () => {
+                    navigator.mediaDevices.getDisplayMedia(constraints)
+                    .then((s) => {
+                        stream = s;
+                        video.srcObject = stream;
+                        if (window.webkit)
+                          window.webkit.messageHandlers.testHandler.postMessage('allowed');
+                    })
+                    .catch((error) => {
+                        if (window.webkit)
+                           window.webkit.messageHandlers.testHandler.postMessage('denied');
+                    });
                 });
             }
 

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/GetDisplayMedia.mm (244748 => 244749)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/GetDisplayMedia.mm	2019-04-29 19:56:56 UTC (rev 244748)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/GetDisplayMedia.mm	2019-04-29 20:04:33 UTC (rev 244749)
@@ -93,6 +93,8 @@
     virtual void SetUp()
     {
         m_configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
+        auto context = adoptWK(TestWebKitAPI::Util::createContextForInjectedBundleTest("InternalsInjectedBundleTest"));
+        m_configuration.get().processPool = (WKProcessPool *)context.get();
 
         auto handler = adoptNS([[GetDisplayMediaMessageHandler alloc] init]);
         [[m_configuration userContentController] addScriptMessageHandler:handler.get() name:@"testHandler"];
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to