WebKit Bugzilla
Attachment 368458 Details for
Bug 197356
: getDisplayMedia should be called on user gesture
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Patch
bug-197356-20190429090916.patch (text/plain), 18.33 KB, created by
youenn fablet
on 2019-04-29 09:09:17 PDT
(
hide
)
Description:
Patch
Filename:
MIME Type:
Creator:
youenn fablet
Created:
2019-04-29 09:09:17 PDT
Size:
18.33 KB
patch
obsolete
>Subversion Revision: 244694 >diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog >index d35e87b3777b700f063673b5e3de8aa9702fde77..3500ca7458df23f4953f1ae33ba3fa55b51bdbd1 100644 >--- a/Source/WebCore/ChangeLog >+++ b/Source/WebCore/ChangeLog >@@ -1,3 +1,27 @@ >+2019-04-28 Youenn Fablet <youenn@apple.com> >+ >+ getDisplayMedia should be called on user gesture >+ https://bugs.webkit.org/show_bug.cgi?id=197356 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ 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-27 Youenn Fablet <youenn@apple.com> > > RTCTrackEvent should be delayed until the whole remote description is set >diff --git a/Source/WebCore/Modules/mediastream/MediaDevices.cpp b/Source/WebCore/Modules/mediastream/MediaDevices.cpp >index e54ff3474d544397ee932f26d9797e3fb56e855f..52e5fd89f39601298d8da1dd8846969d173c2075 100644 >--- a/Source/WebCore/Modules/mediastream/MediaDevices.cpp >+++ b/Source/WebCore/Modules/mediastream/MediaDevices.cpp >@@ -102,10 +102,8 @@ static MediaConstraints createMediaConstraints(const Variant<bool, MediaTrackCon > 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 @@ void MediaDevices::getUserMedia(const StreamConstraints& constraints, Promise&& > > 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 >diff --git a/Source/WebCore/Modules/mediastream/MediaDevices.h b/Source/WebCore/Modules/mediastream/MediaDevices.h >index c6f451f327eb589112d8d1b2de793f38e62167f3..a5279a4e78586723bc7d884333962f1424bedfb6 100644 >--- a/Source/WebCore/Modules/mediastream/MediaDevices.h >+++ b/Source/WebCore/Modules/mediastream/MediaDevices.h >@@ -76,13 +76,15 @@ public: > 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(); > > using RefCounted<MediaDevices>::ref; > using RefCounted<MediaDevices>::deref; > >+ void setDisableGetDisplayMediaUserGestureConstraint(bool value) { m_disableGetDisplayMediaUserGestureConstraint = value; } >+ > private: > explicit MediaDevices(Document&); > >@@ -107,6 +109,7 @@ private: > 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 >diff --git a/Source/WebCore/Modules/mediastream/NavigatorMediaDevices.h b/Source/WebCore/Modules/mediastream/NavigatorMediaDevices.h >index 9883cb588ac0548a32f57208a21e297ef33f545e..d74f65202bd1f739229cb4f0ed46a6d963784abb 100644 >--- a/Source/WebCore/Modules/mediastream/NavigatorMediaDevices.h >+++ b/Source/WebCore/Modules/mediastream/NavigatorMediaDevices.h >@@ -47,7 +47,7 @@ public: > virtual ~NavigatorMediaDevices(); > static NavigatorMediaDevices* from(Navigator*); > >- static MediaDevices* mediaDevices(Navigator&); >+ WEBCORE_TESTSUPPORT_EXPORT static MediaDevices* mediaDevices(Navigator&); > MediaDevices* mediaDevices() const; > > private: >diff --git a/Source/WebCore/page/DOMWindow.h b/Source/WebCore/page/DOMWindow.h >index 16cbeb464a6768191861a69d5d14556165b78f59..fac795476e6e9a55e8c78dbd8574ddac5e5c2071 100644 >--- a/Source/WebCore/page/DOMWindow.h >+++ b/Source/WebCore/page/DOMWindow.h >@@ -158,7 +158,7 @@ public: > BarProp& scrollbars(); > BarProp& statusbar(); > BarProp& toolbar(); >- Navigator& navigator(); >+ WEBCORE_EXPORT Navigator& navigator(); > Navigator* optionalNavigator() const { return m_navigator.get(); } > Navigator& clientInformation() { return navigator(); } > >diff --git a/Source/WebCore/testing/Internals.cpp b/Source/WebCore/testing/Internals.cpp >index 64e03d849cb3b8f5ed6551c50e587fe30d1ba755..10edd277b4797bbd24b31cdf662cb82157cbd61c 100644 >--- a/Source/WebCore/testing/Internals.cpp >+++ b/Source/WebCore/testing/Internals.cpp >@@ -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 @@ void Internals::setMediaStreamSourceInterrupted(MediaStreamTrack& track, bool in > 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 >diff --git a/Source/WebCore/testing/Internals.h b/Source/WebCore/testing/Internals.h >index ee64537d249756c56534ed8169e495cedb58efc2..fbc74ab7f8a34a734cc3760d6dde43f4bfd6c56e 100644 >--- a/Source/WebCore/testing/Internals.h >+++ b/Source/WebCore/testing/Internals.h >@@ -706,6 +706,7 @@ public: > void simulateMediaStreamTrackCaptureSourceFailure(MediaStreamTrack&); > void setMediaStreamTrackIdentifier(MediaStreamTrack&, String&& id); > void setMediaStreamSourceInterrupted(MediaStreamTrack&, bool); >+ void setDisableGetDisplayMediaUserGestureConstraint(bool); > #endif > > String audioSessionCategory() const; >diff --git a/Source/WebCore/testing/Internals.idl b/Source/WebCore/testing/Internals.idl >index f2069efb5ff48c59cb411ff3dcb4fd70b99bde70..d883c045d36ff6c331ee81bfce637329f5aa3aa0 100644 >--- a/Source/WebCore/testing/Internals.idl >+++ b/Source/WebCore/testing/Internals.idl >@@ -679,6 +679,7 @@ enum CompositingPolicy { > [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); >diff --git a/Tools/ChangeLog b/Tools/ChangeLog >index 55e6841efafbbbb8511ef55591c48b5beaa8cecd..e7b27507182344a75d5ee181e8b0845a640ff053 100644 >--- a/Tools/ChangeLog >+++ b/Tools/ChangeLog >@@ -1,3 +1,18 @@ >+2019-04-29 Youenn Fablet <youenn@apple.com> >+ >+ getDisplayMedia should be called on user gesture >+ https://bugs.webkit.org/show_bug.cgi?id=197356 >+ <rdar://problem/50296074> >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ 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 Ryan Haddad <ryanhaddad@apple.com> > > Replace iOS build queue hardware >diff --git a/Tools/TestWebKitAPI/Tests/WebKit/getDisplayMedia.html b/Tools/TestWebKitAPI/Tests/WebKit/getDisplayMedia.html >index f11ba312d9bc5c4ffb94ea35b25341a703772f64..c4468c4ee881aa3ce08e573a468641f73840664b 100644 >--- a/Tools/TestWebKitAPI/Tests/WebKit/getDisplayMedia.html >+++ b/Tools/TestWebKitAPI/Tests/WebKit/getDisplayMedia.html >@@ -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'); >+ }); > }); > } > >diff --git a/Tools/TestWebKitAPI/Tests/WebKitCocoa/GetDisplayMedia.mm b/Tools/TestWebKitAPI/Tests/WebKitCocoa/GetDisplayMedia.mm >index 4d528344e537ba632ec6d08e24cad2e681ab4239..41a5e6febe343319dab39b3839da1317baac539f 100644 >--- a/Tools/TestWebKitAPI/Tests/WebKitCocoa/GetDisplayMedia.mm >+++ b/Tools/TestWebKitAPI/Tests/WebKitCocoa/GetDisplayMedia.mm >@@ -93,6 +93,8 @@ public: > 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"]; >diff --git a/LayoutTests/ChangeLog b/LayoutTests/ChangeLog >index 1e124e286b6786dbbd6ff62d6bdd2ef5437e9769..3264a8078bbd295b40f1de40250ae78849a9b1c6 100644 >--- a/LayoutTests/ChangeLog >+++ b/LayoutTests/ChangeLog >@@ -1,3 +1,20 @@ >+2019-04-28 Youenn Fablet <youenn@apple.com> >+ >+ getDisplayMedia should be called on user gesture >+ https://bugs.webkit.org/show_bug.cgi?id=197356 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ * 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-27 Youenn Fablet <youenn@apple.com> > > RTCTrackEvent should be delayed until the whole remote description is set >diff --git a/LayoutTests/fast/mediastream/media-stream-page-muted.html b/LayoutTests/fast/mediastream/media-stream-page-muted.html >index b277ca6964bcb94994bebd6f3a11f267559c0c2a..9deb9fdfcfcf90c28b9b577c625c7eb4073d6d91 100644 >--- a/LayoutTests/fast/mediastream/media-stream-page-muted.html >+++ b/LayoutTests/fast/mediastream/media-stream-page-muted.html >@@ -4,6 +4,9 @@ > <title>mediastream page muted</title> > <script src="../../resources/js-test-pre.js"></script> > <script> >+ if (window.internals) >+ internals.setDisableGetDisplayMediaUserGestureConstraint(true); >+ > async function checkPageState(activeState, inactiveState) { > await new Promise((resolve, reject) => { > let retryCount = 0; >diff --git a/LayoutTests/fast/mediastream/screencapture-user-gesture-expected.txt b/LayoutTests/fast/mediastream/screencapture-user-gesture-expected.txt >new file mode 100644 >index 0000000000000000000000000000000000000000..e38d80e867c2cd6112f01440112e5ce6199c9368 >--- /dev/null >+++ b/LayoutTests/fast/mediastream/screencapture-user-gesture-expected.txt >@@ -0,0 +1,4 @@ >+ >+PASS Allow getDisplayMedia call in case of user gesture >+PASS Deny getDisplayMedia call if no user gesture >+ >diff --git a/LayoutTests/fast/mediastream/screencapture-user-gesture.html b/LayoutTests/fast/mediastream/screencapture-user-gesture.html >new file mode 100644 >index 0000000000000000000000000000000000000000..4a45c6b53f3e28c5ee5d1177f314768eecd621e3 >--- /dev/null >+++ b/LayoutTests/fast/mediastream/screencapture-user-gesture.html >@@ -0,0 +1,18 @@ >+<script src="../../resources/testharness.js"></script> >+<script src="../../resources/testharnessreport.js"></script> >+<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> >diff --git a/LayoutTests/http/tests/media/media-stream/get-display-media-iframe-allow-attribute-expected.txt b/LayoutTests/http/tests/media/media-stream/get-display-media-iframe-allow-attribute-expected.txt >index 03745af89bb1ad545108ee90a59ae21447de42a9..da75905ed552bf096476214af3c5e1bde038f33d 100644 >--- a/LayoutTests/http/tests/media/media-stream/get-display-media-iframe-allow-attribute-expected.txt >+++ b/LayoutTests/http/tests/media/media-stream/get-display-media-iframe-allow-attribute-expected.txt >@@ -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" >diff --git a/LayoutTests/http/tests/media/media-stream/get-display-media-prompt.html b/LayoutTests/http/tests/media/media-stream/get-display-media-prompt.html >index fd739e6ea1af4e61452c963ef128104756b3d11d..4fdd059fb0084b0326a0e549694f86ddce4ea91a 100644 >--- a/LayoutTests/http/tests/media/media-stream/get-display-media-prompt.html >+++ b/LayoutTests/http/tests/media/media-stream/get-display-media-prompt.html >@@ -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="../../../../resources/js-test-post.js"></script> > </body> >-</html> >\ No newline at end of file >+</html> >diff --git a/LayoutTests/http/tests/media/media-stream/resources/get-display-media-devices-iframe.html b/LayoutTests/http/tests/media/media-stream/resources/get-display-media-devices-iframe.html >index c0f4508be3f62323874c94092863ea97be72d52f..9e33b66f92c445b665d8d155bbac36d777ce122a 100644 >--- a/LayoutTests/http/tests/media/media-stream/resources/get-display-media-devices-iframe.html >+++ b/LayoutTests/http/tests/media/media-stream/resources/get-display-media-devices-iframe.html >@@ -1,4 +1,7 @@ > <script> >+ if (window.internals) >+ internals.setDisableGetDisplayMediaUserGestureConstraint(true); >+ > async function enumerate(event) > { > let result; >diff --git a/LayoutTests/resources/testharnessreport.js b/LayoutTests/resources/testharnessreport.js >index 4036e56a95eca02ac052d8d392dcdb2b44b89d76..9f5ae2c415e19e9ea3c9280594320e1181dda16f 100644 >--- a/LayoutTests/resources/testharnessreport.js >+++ b/LayoutTests/resources/testharnessreport.js >@@ -29,6 +29,9 @@ if (self.testRunner) { > } > } > >+if (self.internals && internals.setDisableGetDisplayMediaUserGestureConstraint) >+ internals.setDisableGetDisplayMediaUserGestureConstraint(true); >+ > if (self.internals && internals.setICECandidateFiltering) > internals.setICECandidateFiltering(false); >
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Formatted Diff
|
Diff
Attachments on
bug 197356
:
368437
|
368438
|
368440
| 368458