<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[244749] trunk</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/244749">244749</a></dd>
<dt>Author</dt> <dd>youenn@apple.com</dd>
<dt>Date</dt> <dd>2019-04-29 13:04:33 -0700 (Mon, 29 Apr 2019)</dd>
</dl>

<h3>Log Message</h3>
<pre>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:</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsChangeLog">trunk/LayoutTests/ChangeLog</a></li>
<li><a href="#trunkLayoutTestsfastmediastreammediastreampagemutedhtml">trunk/LayoutTests/fast/mediastream/media-stream-page-muted.html</a></li>
<li><a href="#trunkLayoutTestshttptestsmediamediastreamgetdisplaymediaiframeallowattributeexpectedtxt">trunk/LayoutTests/http/tests/media/media-stream/get-display-media-iframe-allow-attribute-expected.txt</a></li>
<li><a href="#trunkLayoutTestshttptestsmediamediastreamgetdisplaymediaprompthtml">trunk/LayoutTests/http/tests/media/media-stream/get-display-media-prompt.html</a></li>
<li><a href="#trunkLayoutTestshttptestsmediamediastreamresourcesgetdisplaymediadevicesiframehtml">trunk/LayoutTests/http/tests/media/media-stream/resources/get-display-media-devices-iframe.html</a></li>
<li><a href="#trunkLayoutTestsresourcestestharnessreportjs">trunk/LayoutTests/resources/testharnessreport.js</a></li>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreModulesmediastreamMediaDevicescpp">trunk/Source/WebCore/Modules/mediastream/MediaDevices.cpp</a></li>
<li><a href="#trunkSourceWebCoreModulesmediastreamMediaDevicesh">trunk/Source/WebCore/Modules/mediastream/MediaDevices.h</a></li>
<li><a href="#trunkSourceWebCoreModulesmediastreamNavigatorMediaDevicesh">trunk/Source/WebCore/Modules/mediastream/NavigatorMediaDevices.h</a></li>
<li><a href="#trunkSourceWebCorepageDOMWindowh">trunk/Source/WebCore/page/DOMWindow.h</a></li>
<li><a href="#trunkSourceWebCoretestingInternalscpp">trunk/Source/WebCore/testing/Internals.cpp</a></li>
<li><a href="#trunkSourceWebCoretestingInternalsh">trunk/Source/WebCore/testing/Internals.h</a></li>
<li><a href="#trunkSourceWebCoretestingInternalsidl">trunk/Source/WebCore/testing/Internals.idl</a></li>
<li><a href="#trunkToolsChangeLog">trunk/Tools/ChangeLog</a></li>
<li><a href="#trunkToolsTestWebKitAPITestsWebKitgetDisplayMediahtml">trunk/Tools/TestWebKitAPI/Tests/WebKit/getDisplayMedia.html</a></li>
<li><a href="#trunkToolsTestWebKitAPITestsWebKitCocoaGetDisplayMediamm">trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/GetDisplayMedia.mm</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsfastmediastreamscreencaptureusergestureexpectedtxt">trunk/LayoutTests/fast/mediastream/screencapture-user-gesture-expected.txt</a></li>
<li><a href="#trunkLayoutTestsfastmediastreamscreencaptureusergesturehtml">trunk/LayoutTests/fast/mediastream/screencapture-user-gesture.html</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (244748 => 244749)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog      2019-04-29 19:56:56 UTC (rev 244748)
+++ trunk/LayoutTests/ChangeLog 2019-04-29 20:04:33 UTC (rev 244749)
</span><span class="lines">@@ -1,3 +1,20 @@
</span><ins>+2019-04-29  Youenn Fablet  <youenn@apple.com>
+
+        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:
+
</ins><span class="cx"> 2019-04-29  Javier Fernandez  <jfernandez@igalia.com>
</span><span class="cx"> 
</span><span class="cx">         line should not be broken before the first space after a word
</span></span></pre></div>
<a id="trunkLayoutTestsfastmediastreammediastreampagemutedhtml"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/fast/mediastream/media-stream-page-muted.html (244748 => 244749)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -4,6 +4,9 @@
</span><span class="cx">     <title>mediastream page muted</title>
</span><span class="cx">     <script src="../../resources/js-test-pre.js"></script>
</span><span class="cx">     <script>
</span><ins>+        if (window.internals)
+            internals.setDisableGetDisplayMediaUserGestureConstraint(true);
+
</ins><span class="cx">         async function checkPageState(activeState, inactiveState) {
</span><span class="cx">             await new Promise((resolve, reject) => {
</span><span class="cx">                 let retryCount = 0;
</span></span></pre></div>
<a id="trunkLayoutTestsfastmediastreamscreencaptureusergestureexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/mediastream/screencapture-user-gesture-expected.txt (0 => 244749)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -0,0 +1,4 @@
</span><ins>+
+PASS Allow getDisplayMedia call in case of user gesture 
+PASS Deny getDisplayMedia call if no user gesture 
+
</ins></span></pre></div>
<a id="trunkLayoutTestsfastmediastreamscreencaptureusergesturehtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/mediastream/screencapture-user-gesture.html (0 => 244749)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -0,0 +1,18 @@
</span><ins>+<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>
</ins></span></pre></div>
<a id="trunkLayoutTestshttptestsmediamediastreamgetdisplaymediaiframeallowattributeexpectedtxt"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/http/tests/media/media-stream/get-display-media-iframe-allow-attribute-expected.txt (244748 => 244749)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -1,6 +1,6 @@
</span><del>-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.
</del><ins>+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.
</ins><span class="cx">      
</span><span class="cx"> 
</span><span class="cx"> PASS: <iframe allow=''> got "deny"
</span></span></pre></div>
<a id="trunkLayoutTestshttptestsmediamediastreamgetdisplaymediaprompthtml"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/http/tests/media/media-stream/get-display-media-prompt.html (244748 => 244749)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -9,6 +9,8 @@
</span><span class="cx">     <div id="console"></div>
</span><span class="cx"> 
</span><span class="cx"> <script>
</span><ins>+    if (window.internals)
+        internals.setDisableGetDisplayMediaUserGestureConstraint(true);
</ins><span class="cx"> 
</span><span class="cx">     let stream;
</span><span class="cx">     let err;
</span><span class="lines">@@ -127,4 +129,4 @@
</span><span class="cx"> </script>
</span><span class="cx"> <script src="../../../../resources/js-test-post.js"></script>
</span><span class="cx"> </body>
</span><del>-</html>
</del><span class="cx">\ No newline at end of file
</span><ins>+</html>
</ins></span></pre></div>
<a id="trunkLayoutTestshttptestsmediamediastreamresourcesgetdisplaymediadevicesiframehtml"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/http/tests/media/media-stream/resources/get-display-media-devices-iframe.html (244748 => 244749)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -1,4 +1,7 @@
</span><span class="cx"> <script>
</span><ins>+    if (window.internals)
+        internals.setDisableGetDisplayMediaUserGestureConstraint(true);
+
</ins><span class="cx">     async function enumerate(event)
</span><span class="cx">     {
</span><span class="cx">         let result;
</span></span></pre></div>
<a id="trunkLayoutTestsresourcestestharnessreportjs"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/resources/testharnessreport.js (244748 => 244749)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -29,6 +29,9 @@
</span><span class="cx">     }
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+if (self.internals && internals.setDisableGetDisplayMediaUserGestureConstraint)
+    internals.setDisableGetDisplayMediaUserGestureConstraint(true);
+
</ins><span class="cx"> if (self.internals && internals.setICECandidateFiltering)
</span><span class="cx">     internals.setICECandidateFiltering(false);
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (244748 => 244749)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -1,3 +1,27 @@
</span><ins>+2019-04-29  Youenn Fablet  <youenn@apple.com>
+
+        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:
+
</ins><span class="cx"> 2019-04-29  Javier Fernandez  <jfernandez@igalia.com>
</span><span class="cx"> 
</span><span class="cx">         line should not be broken before the first space after a word
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesmediastreamMediaDevicescpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/mediastream/MediaDevices.cpp (244748 => 244749)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -102,10 +102,8 @@
</span><span class="cx"> void MediaDevices::getUserMedia(const StreamConstraints& constraints, Promise&& promise) const
</span><span class="cx"> {
</span><span class="cx">     auto* document = this->document();
</span><del>-    if (!document) {
-        promise.reject(Exception { InvalidStateError });
</del><ins>+    if (!document)
</ins><span class="cx">         return;
</span><del>-    }
</del><span class="cx"> 
</span><span class="cx">     auto audioConstraints = createMediaConstraints(constraints.audio);
</span><span class="cx">     auto videoConstraints = createMediaConstraints(constraints.video);
</span><span class="lines">@@ -114,20 +112,21 @@
</span><span class="cx"> 
</span><span class="cx">     auto request = UserMediaRequest::create(*document, { MediaStreamRequest::Type::UserMedia, WTFMove(audioConstraints), WTFMove(videoConstraints) }, WTFMove(promise));
</span><span class="cx">     request->start();
</span><del>-
-    return;
</del><span class="cx"> }
</span><span class="cx"> 
</span><del>-ExceptionOr<void> MediaDevices::getDisplayMedia(const StreamConstraints& constraints, Promise&& promise) const
</del><ins>+void MediaDevices::getDisplayMedia(const StreamConstraints& constraints, Promise&& promise) const
</ins><span class="cx"> {
</span><span class="cx">     auto* document = this->document();
</span><span class="cx">     if (!document)
</span><del>-        return Exception { InvalidStateError };
</del><ins>+        return;
</ins><span class="cx"> 
</span><ins>+    if (!m_disableGetDisplayMediaUserGestureConstraint && !UserGestureIndicator::processingUserGesture()) {
+        promise.reject(Exception { InvalidAccessError, "getDisplayMedia must be called from a user gesture handler."_s });
+        return;
+    }
+
</ins><span class="cx">     auto request = UserMediaRequest::create(*document, { MediaStreamRequest::Type::DisplayMedia, { }, createMediaConstraints(constraints.video) }, WTFMove(promise));
</span><span class="cx">     request->start();
</span><del>-
-    return { };
</del><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void MediaDevices::enumerateDevices(EnumerateDevicesPromise&& promise) const
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesmediastreamMediaDevicesh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/mediastream/MediaDevices.h (244748 => 244749)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -76,7 +76,7 @@
</span><span class="cx">         Variant<bool, MediaTrackConstraints> audio;
</span><span class="cx">     };
</span><span class="cx">     void getUserMedia(const StreamConstraints&, Promise&&) const;
</span><del>-    ExceptionOr<void> getDisplayMedia(const StreamConstraints&, Promise&&) const;
</del><ins>+    void getDisplayMedia(const StreamConstraints&, Promise&&) const;
</ins><span class="cx">     void enumerateDevices(EnumerateDevicesPromise&&) const;
</span><span class="cx">     MediaTrackSupportedConstraints getSupportedConstraints();
</span><span class="cx"> 
</span><span class="lines">@@ -83,6 +83,8 @@
</span><span class="cx">     using RefCounted<MediaDevices>::ref;
</span><span class="cx">     using RefCounted<MediaDevices>::deref;
</span><span class="cx"> 
</span><ins>+    void setDisableGetDisplayMediaUserGestureConstraint(bool value) { m_disableGetDisplayMediaUserGestureConstraint = value; }
+
</ins><span class="cx"> private:
</span><span class="cx">     explicit MediaDevices(Document&);
</span><span class="cx"> 
</span><span class="lines">@@ -107,6 +109,7 @@
</span><span class="cx">     UserMediaClient::DeviceChangeObserverToken m_deviceChangeToken;
</span><span class="cx">     const EventNames& m_eventNames; // Need to cache this so we can use it from GC threads.
</span><span class="cx">     bool m_listeningForDeviceChanges { false };
</span><ins>+    bool m_disableGetDisplayMediaUserGestureConstraint { false };
</ins><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> } // namespace WebCore
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesmediastreamNavigatorMediaDevicesh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/mediastream/NavigatorMediaDevices.h (244748 => 244749)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -47,7 +47,7 @@
</span><span class="cx">     virtual ~NavigatorMediaDevices();
</span><span class="cx">     static NavigatorMediaDevices* from(Navigator*);
</span><span class="cx"> 
</span><del>-    static MediaDevices* mediaDevices(Navigator&);
</del><ins>+    WEBCORE_TESTSUPPORT_EXPORT static MediaDevices* mediaDevices(Navigator&);
</ins><span class="cx">     MediaDevices* mediaDevices() const;
</span><span class="cx"> 
</span><span class="cx"> private:
</span></span></pre></div>
<a id="trunkSourceWebCorepageDOMWindowh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/page/DOMWindow.h (244748 => 244749)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -158,7 +158,7 @@
</span><span class="cx">     BarProp& scrollbars();
</span><span class="cx">     BarProp& statusbar();
</span><span class="cx">     BarProp& toolbar();
</span><del>-    Navigator& navigator();
</del><ins>+    WEBCORE_EXPORT Navigator& navigator();
</ins><span class="cx">     Navigator* optionalNavigator() const { return m_navigator.get(); }
</span><span class="cx">     Navigator& clientInformation() { return navigator(); }
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCoretestingInternalscpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/testing/Internals.cpp (244748 => 244749)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -108,6 +108,7 @@
</span><span class="cx"> #include "LibWebRTCProvider.h"
</span><span class="cx"> #include "LoaderStrategy.h"
</span><span class="cx"> #include "MallocStatistics.h"
</span><ins>+#include "MediaDevices.h"
</ins><span class="cx"> #include "MediaEngineConfigurationFactory.h"
</span><span class="cx"> #include "MediaPlayer.h"
</span><span class="cx"> #include "MediaProducer.h"
</span><span class="lines">@@ -118,6 +119,7 @@
</span><span class="cx"> #include "MockLibWebRTCPeerConnection.h"
</span><span class="cx"> #include "MockPageOverlay.h"
</span><span class="cx"> #include "MockPageOverlayClient.h"
</span><ins>+#include "NavigatorMediaDevices.h"
</ins><span class="cx"> #include "NetworkLoadInformation.h"
</span><span class="cx"> #include "Page.h"
</span><span class="cx"> #include "PageCache.h"
</span><span class="lines">@@ -4705,6 +4707,15 @@
</span><span class="cx">     track.source().setInterruptedForTesting(interrupted);
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void Internals::setDisableGetDisplayMediaUserGestureConstraint(bool value)
+{
+    Document* document = contextDocument();
+    if (!document || !document->domWindow())
+        return;
+
+    if (auto* mediaDevices = NavigatorMediaDevices::mediaDevices(document->domWindow()->navigator()))
+        mediaDevices->setDisableGetDisplayMediaUserGestureConstraint(value);
+}
</ins><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx"> String Internals::audioSessionCategory() const
</span></span></pre></div>
<a id="trunkSourceWebCoretestingInternalsh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/testing/Internals.h (244748 => 244749)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -706,6 +706,7 @@
</span><span class="cx">     void simulateMediaStreamTrackCaptureSourceFailure(MediaStreamTrack&);
</span><span class="cx">     void setMediaStreamTrackIdentifier(MediaStreamTrack&, String&& id);
</span><span class="cx">     void setMediaStreamSourceInterrupted(MediaStreamTrack&, bool);
</span><ins>+    void setDisableGetDisplayMediaUserGestureConstraint(bool);
</ins><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx">     String audioSessionCategory() const;
</span></span></pre></div>
<a id="trunkSourceWebCoretestingInternalsidl"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/testing/Internals.idl (244748 => 244749)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -679,6 +679,7 @@
</span><span class="cx">     [Conditional=MEDIA_STREAM] void simulateMediaStreamTrackCaptureSourceFailure(MediaStreamTrack track);
</span><span class="cx">     [Conditional=MEDIA_STREAM] void setMediaStreamTrackIdentifier(MediaStreamTrack track, DOMString identifier);
</span><span class="cx">     [Conditional=MEDIA_STREAM] void setMediaStreamSourceInterrupted(MediaStreamTrack track, boolean interrupted);
</span><ins>+    [Conditional=MEDIA_STREAM] void setDisableGetDisplayMediaUserGestureConstraint(boolean value);
</ins><span class="cx"> 
</span><span class="cx">     unsigned long long documentIdentifier(Document document);
</span><span class="cx">     boolean isDocumentAlive(unsigned long long documentIdentifier);
</span></span></pre></div>
<a id="trunkToolsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Tools/ChangeLog (244748 => 244749)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/ChangeLog    2019-04-29 19:56:56 UTC (rev 244748)
+++ trunk/Tools/ChangeLog       2019-04-29 20:04:33 UTC (rev 244749)
</span><span class="lines">@@ -1,3 +1,18 @@
</span><ins>+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 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):
+
</ins><span class="cx"> 2019-04-26  Stephanie Lewis  <slewis@apple.com>
</span><span class="cx"> 
</span><span class="cx">         run-benchmarks should have an intial prep and restore env call for tasks that are too expensive to do for every iteration
</span></span></pre></div>
<a id="trunkToolsTestWebKitAPITestsWebKitgetDisplayMediahtml"></a>
<div class="modfile"><h4>Modified: trunk/Tools/TestWebKitAPI/Tests/WebKit/getDisplayMedia.html (244748 => 244749)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -7,16 +7,18 @@
</span><span class="cx"> 
</span><span class="cx">             function promptForCapture(constraints)
</span><span class="cx">             {
</span><del>-                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');
</del><ins>+                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');
+                    });
</ins><span class="cx">                 });
</span><span class="cx">             }
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkToolsTestWebKitAPITestsWebKitCocoaGetDisplayMediamm"></a>
<div class="modfile"><h4>Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/GetDisplayMedia.mm (244748 => 244749)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -93,6 +93,8 @@
</span><span class="cx">     virtual void SetUp()
</span><span class="cx">     {
</span><span class="cx">         m_configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
</span><ins>+        auto context = adoptWK(TestWebKitAPI::Util::createContextForInjectedBundleTest("InternalsInjectedBundleTest"));
+        m_configuration.get().processPool = (WKProcessPool *)context.get();
</ins><span class="cx"> 
</span><span class="cx">         auto handler = adoptNS([[GetDisplayMediaMessageHandler alloc] init]);
</span><span class="cx">         [[m_configuration userContentController] addScriptMessageHandler:handler.get() name:@"testHandler"];
</span></span></pre>
</div>
</div>

</body>
</html>