<!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>[198092] 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/198092">198092</a></dd>
<dt>Author</dt> <dd>weinig@apple.com</dd>
<dt>Date</dt> <dd>2016-03-13 21:43:58 -0700 (Sun, 13 Mar 2016)</dd>
</dl>

<h3>Log Message</h3>
<pre>Implement unprivileged execCommand(&quot;copy&quot;) and execCommand(&quot;cut&quot;)
&lt;rdar://problem/24354406&gt;
https://bugs.webkit.org/show_bug.cgi?id=146336

Reviewed by Dean Jackson.

Source/WebCore:

Test: editing/execCommand/clipboard-access-with-user-gesture.html

* WebCore.xcodeproj/project.pbxproj:
Add new files.

* editing/ClipboardAccessPolicy.h:
Added.

* editing/EditorCommand.cpp:
(WebCore::defaultValueForSupportedCopyCut):
(WebCore::supportedCopyCut):
Match other browsers and allow the copy and cut commands
to be executed when there is a user gesture.

* page/Settings.h:
Add include of ClipboardAccessPolicy.h.

* page/Settings.in:
Add new setting for ClipboardAccessPolicy

LayoutTests:

* editing/execCommand/clipboard-access-with-user-gesture-expected.txt: Added.
* editing/execCommand/clipboard-access-with-user-gesture.html: Added.
Add test for using execCommand(&quot;copy&quot;) and execCommand(&quot;cut&quot;) during a user gesture.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsChangeLog">trunk/LayoutTests/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreWebCorexcodeprojprojectpbxproj">trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj</a></li>
<li><a href="#trunkSourceWebCoreeditingEditorCommandcpp">trunk/Source/WebCore/editing/EditorCommand.cpp</a></li>
<li><a href="#trunkSourceWebCorepageSettingsh">trunk/Source/WebCore/page/Settings.h</a></li>
<li><a href="#trunkSourceWebCorepageSettingsin">trunk/Source/WebCore/page/Settings.in</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkLayoutTestseditingexecCommandclipboardaccesswithusergestureexpectedtxt">trunk/LayoutTests/editing/execCommand/clipboard-access-with-user-gesture-expected.txt</a></li>
<li><a href="#trunkLayoutTestseditingexecCommandclipboardaccesswithusergesturehtml">trunk/LayoutTests/editing/execCommand/clipboard-access-with-user-gesture.html</a></li>
<li><a href="#trunkSourceWebCoreeditingClipboardAccessPolicyh">trunk/Source/WebCore/editing/ClipboardAccessPolicy.h</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (198091 => 198092)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog        2016-03-14 03:58:26 UTC (rev 198091)
+++ trunk/LayoutTests/ChangeLog        2016-03-14 04:43:58 UTC (rev 198092)
</span><span class="lines">@@ -1,3 +1,15 @@
</span><ins>+2016-03-13  Sam Weinig  &lt;sam@webkit.org&gt;
+
+        Implement unprivileged execCommand(&quot;copy&quot;) and execCommand(&quot;cut&quot;)
+        &lt;rdar://problem/24354406&gt;
+        https://bugs.webkit.org/show_bug.cgi?id=146336
+
+        Reviewed by Dean Jackson.
+
+        * editing/execCommand/clipboard-access-with-user-gesture-expected.txt: Added.
+        * editing/execCommand/clipboard-access-with-user-gesture.html: Added.
+        Add test for using execCommand(&quot;copy&quot;) and execCommand(&quot;cut&quot;) during a user gesture.
+
</ins><span class="cx"> 2016-03-13  Dean Jackson  &lt;dino@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         DRT should enable WebGL by default on Mac
</span></span></pre></div>
<a id="trunkLayoutTestseditingexecCommandclipboardaccesswithusergestureexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/editing/execCommand/clipboard-access-with-user-gesture-expected.txt (0 => 198092)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/editing/execCommand/clipboard-access-with-user-gesture-expected.txt                                (rev 0)
+++ trunk/LayoutTests/editing/execCommand/clipboard-access-with-user-gesture-expected.txt        2016-03-14 04:43:58 UTC (rev 198092)
</span><span class="lines">@@ -0,0 +1,121 @@
</span><ins>+This test checks that JavaScript programs can execute copy and paste commands, but only during a user gesture.
+
+On success, you will see a series of &quot;PASS&quot; messages, followed by &quot;TEST COMPLETE&quot;.
+
+
+
+Testing copying an editableParagraph range without a user gesture.
+PASS document.queryCommandEnabled('copy') is false
+PASS eventSeen['copy'] is false
+PASS document.queryCommandSupported('copy') is false
+PASS eventSeen['copy'] is false
+PASS document.execCommand('copy') is false
+PASS eventSeen['copy'] is false
+
+Testing copying an editableParagraph caret without a user gesture.
+PASS document.queryCommandEnabled('copy') is false
+PASS eventSeen['copy'] is false
+PASS document.queryCommandSupported('copy') is false
+PASS eventSeen['copy'] is false
+PASS document.execCommand('copy') is false
+PASS eventSeen['copy'] is false
+
+Testing copying an non-editable range without a user gesture.
+PASS document.queryCommandEnabled('copy') is false
+PASS eventSeen['copy'] is false
+PASS document.queryCommandSupported('copy') is false
+PASS eventSeen['copy'] is false
+PASS document.execCommand('copy') is false
+PASS eventSeen['copy'] is false
+
+Testing copying an non-editable caret without a user gesture.
+PASS document.queryCommandEnabled('copy') is false
+PASS eventSeen['copy'] is false
+PASS document.queryCommandSupported('copy') is false
+PASS eventSeen['copy'] is false
+PASS document.execCommand('copy') is false
+PASS eventSeen['copy'] is false
+
+Testing copying an editable plaint-text range without a user gesture.
+PASS document.queryCommandEnabled('copy') is false
+PASS eventSeen['copy'] is false
+PASS document.queryCommandSupported('copy') is false
+PASS eventSeen['copy'] is false
+PASS document.execCommand('copy') is false
+PASS eventSeen['copy'] is false
+
+Testing copying an editable plaint-text caret without a user gesture.
+PASS document.queryCommandEnabled('copy') is false
+PASS eventSeen['copy'] is false
+PASS document.queryCommandSupported('copy') is false
+PASS eventSeen['copy'] is false
+PASS document.execCommand('copy') is false
+PASS eventSeen['copy'] is false
+
+Testing copying when there is no selection without a user gesture.
+PASS document.queryCommandEnabled('copy') is false
+PASS eventSeen['copy'] is false
+PASS document.queryCommandSupported('copy') is false
+PASS eventSeen['copy'] is false
+PASS document.execCommand('copy') is false
+PASS eventSeen['copy'] is false
+
+Testing cutting an editableParagraph range without a user gesture.
+PASS document.queryCommandEnabled('cut') is false
+PASS eventSeen['cut'] is false
+PASS document.queryCommandSupported('cut') is false
+PASS eventSeen['cut'] is false
+PASS document.execCommand('cut') is false
+PASS eventSeen['cut'] is false
+
+Testing cutting an editableParagraph caret without a user gesture.
+PASS document.queryCommandEnabled('cut') is false
+PASS eventSeen['cut'] is false
+PASS document.queryCommandSupported('cut') is false
+PASS eventSeen['cut'] is false
+PASS document.execCommand('cut') is false
+PASS eventSeen['cut'] is false
+
+Testing cutting an non-editable range without a user gesture.
+PASS document.queryCommandEnabled('cut') is false
+PASS eventSeen['cut'] is false
+PASS document.queryCommandSupported('cut') is false
+PASS eventSeen['cut'] is false
+PASS document.execCommand('cut') is false
+PASS eventSeen['cut'] is false
+
+Testing cutting an non-editable caret without a user gesture.
+PASS document.queryCommandEnabled('cut') is false
+PASS eventSeen['cut'] is false
+PASS document.queryCommandSupported('cut') is false
+PASS eventSeen['cut'] is false
+PASS document.execCommand('cut') is false
+PASS eventSeen['cut'] is false
+
+Testing cutting an editable plaint-text range without a user gesture.
+PASS document.queryCommandEnabled('cut') is false
+PASS eventSeen['cut'] is false
+PASS document.queryCommandSupported('cut') is false
+PASS eventSeen['cut'] is false
+PASS document.execCommand('cut') is false
+PASS eventSeen['cut'] is false
+
+Testing cutting an editable plaint-text caret without a user gesture.
+PASS document.queryCommandEnabled('cut') is false
+PASS eventSeen['cut'] is false
+PASS document.queryCommandSupported('cut') is false
+PASS eventSeen['cut'] is false
+PASS document.execCommand('cut') is false
+PASS eventSeen['cut'] is false
+
+Testing cutting when there is no selection without a user gesture.
+PASS document.queryCommandEnabled('cut') is false
+PASS eventSeen['cut'] is false
+PASS document.queryCommandSupported('cut') is false
+PASS eventSeen['cut'] is false
+PASS document.execCommand('cut') is false
+PASS eventSeen['cut'] is false
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
</ins></span></pre></div>
<a id="trunkLayoutTestseditingexecCommandclipboardaccesswithusergesturehtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/editing/execCommand/clipboard-access-with-user-gesture.html (0 => 198092)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/editing/execCommand/clipboard-access-with-user-gesture.html                                (rev 0)
+++ trunk/LayoutTests/editing/execCommand/clipboard-access-with-user-gesture.html        2016-03-14 04:43:58 UTC (rev 198092)
</span><span class="lines">@@ -0,0 +1,275 @@
</span><ins>+&lt;!DOCTYPE html&gt;
+&lt;html&gt;
+&lt;head&gt;
+&lt;meta charset=&quot;utf-8&quot;&gt;
+&lt;script src=&quot;../../resources/js-test-pre.js&quot;&gt;&lt;/script&gt;
+&lt;/head&gt;
+&lt;body&gt;
+&lt;script&gt;
+
+description(&quot;This test checks that JavaScript programs can execute copy and paste commands, but only during a user gesture.&quot;);
+
+// Override the test runner default befavior of allowing all keyboard access, and act more like
+// a browser.
+if (window.testRunner)
+    window.testRunner.setJavaScriptCanAccessClipboard(false);
+
+function clearSelectionContainer()
+{
+    var container = document.getElementById('container');
+    if (container)
+        container.remove();
+}
+
+function resetSelectionContainer()
+{
+    clearSelectionContainer();
+
+    var container = document.createElement(&quot;div&quot;);
+    container.id = &quot;container&quot;;
+
+    var nonEditableParagraph = document.createElement(&quot;p&quot;);
+    nonEditableParagraph.id = &quot;nonEditableParagraph&quot;;
+    nonEditableParagraph.appendChild(document.createTextNode(&quot;x&quot;));
+    container.appendChild(nonEditableParagraph);
+
+    var editableParagraph = document.createElement(&quot;p&quot;);
+    editableParagraph.id = &quot;editableParagraph&quot;;
+    editableParagraph.appendChild(document.createTextNode(&quot;x&quot;));
+    editableParagraph.setAttribute(&quot;contentEditable&quot;, &quot;true&quot;);
+    container.appendChild(editableParagraph);
+
+    var editablePlainTextParagraph = document.createElement(&quot;p&quot;);
+    editablePlainTextParagraph.id = &quot;editablePlainTextParagraph&quot;;
+    editablePlainTextParagraph.appendChild(document.createTextNode(&quot;x&quot;));
+    editablePlainTextParagraph.setAttribute(&quot;contentEditable&quot;, &quot;plaintext-only&quot;);
+    container.appendChild(editablePlainTextParagraph);
+
+    document.body.appendChild(container);
+}
+
+function makeSelection(elementId, selectionStart, selectionEnd)
+{
+    resetSelectionContainer();
+
+    var selection = window.getSelection();
+    selection.removeAllRanges();
+
+    var element = document.getElementById(elementId);
+
+    var range = document.createRange();
+    range.setStart(element.firstChild, selectionStart);
+    range.setEnd(element.firstChild, selectionEnd);
+    selection.addRange(range);
+}
+
+var eventSeen = {
+    &quot;copy&quot;: false,
+    &quot;cut&quot;: false,
+    &quot;beforecopy&quot;: false,
+    &quot;beforecut&quot;: false
+}
+
+function resetSeenFlags()
+{
+    eventSeen.copy = false;
+    eventSeen.cut = false;
+    eventSeen.beforecopy = false;
+    eventSeen.beforecut = false;
+}
+
+document.body.oncopy = function(event)
+{
+    eventSeen[&quot;copy&quot;] = true;
+}
+
+document.body.oncut = function()
+{
+    eventSeen[&quot;cut&quot;] = true;
+}
+
+document.body.onbeforecopy = function()
+{
+    eventSeen[&quot;beforecopy&quot;] = true;
+}
+
+document.body.onbeforecut = function()
+{
+    eventSeen[&quot;beforecut&quot;] = true;
+}
+
+function test(command, enabledExpected, supportedExpected, executedExpected)
+{
+    resetSeenFlags();
+    shouldBe(&quot;document.queryCommandEnabled('&quot; + command +&quot;')&quot;, &quot;&quot; + enabledExpected);
+    shouldBeFalse(&quot;eventSeen['&quot; + command +&quot;']&quot;);
+
+    resetSeenFlags();
+    shouldBe(&quot;document.queryCommandSupported('&quot; + command +&quot;')&quot;, &quot;&quot; + supportedExpected);
+    shouldBeFalse(&quot;eventSeen['&quot; + command +&quot;']&quot;);
+
+    resetSeenFlags();
+    shouldBe(&quot;document.execCommand('&quot; + command +&quot;')&quot;, &quot;&quot; + executedExpected);
+    shouldBe(&quot;eventSeen['&quot; + command +&quot;']&quot;, &quot;&quot; + executedExpected);
+}
+
+function header(msg)
+{
+    debug(&quot;&quot;);
+    debug(msg);
+}
+
+var buttonForCopy = document.createElement(&quot;button&quot;);
+buttonForCopy.id = &quot;copyButton&quot;;
+buttonForCopy.textContent = &quot;Copy&quot;;
+buttonForCopy.onclick = function()
+{
+    header(&quot;Testing copying an editableParagraph range in a user gesture.&quot;)
+    makeSelection(&quot;editableParagraph&quot;, 0, 1);
+    test(&quot;copy&quot;, true, true, true);
+
+    header(&quot;Testing copying an editableParagraph caret in a user gesture.&quot;)
+    makeSelection(&quot;editableParagraph&quot;, 0, 0);
+    test(&quot;copy&quot;, false, true, true);
+
+    header(&quot;Testing copying an non-editable range in a user gesture.&quot;)
+    makeSelection(&quot;nonEditableParagraph&quot;, 0, 1);
+    test(&quot;copy&quot;, true, true, true);
+
+    header(&quot;Testing copying an non-editable caret in a user gesture.&quot;)
+    makeSelection(&quot;nonEditableParagraph&quot;, 0, 0);
+    test(&quot;copy&quot;, false, true, true);
+
+    header(&quot;Testing copying an editable plaint-text range in a user gesture.&quot;)
+    makeSelection(&quot;editablePlainTextParagraph&quot;, 0, 1);
+    test(&quot;copy&quot;, true, true, true);
+
+    header(&quot;Testing copying an editable plaint-text caret in a user gesture.&quot;)
+    makeSelection(&quot;editablePlainTextParagraph&quot;, 0, 0);
+    test(&quot;copy&quot;, false, true, true);
+
+    header(&quot;Testing copying when there is no selection in a user gesture.&quot;)
+    window.getSelection().removeAllRanges();
+    test(&quot;copy&quot;, false, true, true);
+
+    clearSelectionContainer();
+}
+document.body.appendChild(buttonForCopy);
+
+var buttonForCut = document.createElement(&quot;button&quot;);
+buttonForCut.id = &quot;cutButton&quot;;
+buttonForCut.textContent = &quot;Cut&quot;;
+buttonForCut.onclick = function()
+{
+    header(&quot;Testing cutting an editableParagraph range in a user gesture.&quot;)
+    makeSelection(&quot;editableParagraph&quot;, 0, 1);
+    test(&quot;cut&quot;, true, true, true);
+
+    header(&quot;Testing cutting an editableParagraph caret in a user gesture.&quot;)
+    makeSelection(&quot;editableParagraph&quot;, 0, 0);
+    test(&quot;cut&quot;, false, true, true);
+
+    header(&quot;Testing cutting an non-editable range in a user gesture.&quot;)
+    makeSelection(&quot;nonEditableParagraph&quot;, 0, 1);
+    test(&quot;cut&quot;, false, true, true);
+
+    header(&quot;Testing cutting an non-editable caret in a user gesture.&quot;)
+    makeSelection(&quot;nonEditableParagraph&quot;, 0, 0);
+    test(&quot;cut&quot;, false, true, true);
+
+    header(&quot;Testing cutting an editable plaint-text range in a user gesture.&quot;)
+    makeSelection(&quot;editablePlainTextParagraph&quot;, 0, 1);
+    test(&quot;cut&quot;, true, true, true);
+
+    header(&quot;Testing cutting an editable plaint-text caret in a user gesture.&quot;)
+    makeSelection(&quot;editablePlainTextParagraph&quot;, 0, 0);
+    test(&quot;cut&quot;, false, true, true);
+
+    header(&quot;Testing cutting when there is no selection in a user gesture.&quot;)
+    window.getSelection().removeAllRanges();
+    test(&quot;cut&quot;, false, true, true);
+
+    clearSelectionContainer();
+}
+document.body.appendChild(buttonForCut);
+
+// First test copy/cut without user gestures.
+header(&quot;Testing copying an editableParagraph range without a user gesture.&quot;)
+makeSelection(&quot;editableParagraph&quot;, 0, 1);
+test(&quot;copy&quot;, false, false, false);
+
+header(&quot;Testing copying an editableParagraph caret without a user gesture.&quot;)
+makeSelection(&quot;editableParagraph&quot;, 0, 0);
+test(&quot;copy&quot;, false, false, false);
+
+header(&quot;Testing copying an non-editable range without a user gesture.&quot;)
+makeSelection(&quot;nonEditableParagraph&quot;, 0, 1);
+test(&quot;copy&quot;, false, false, false);
+
+header(&quot;Testing copying an non-editable caret without a user gesture.&quot;)
+makeSelection(&quot;nonEditableParagraph&quot;, 0, 0);
+test(&quot;copy&quot;, false, false, false);
+
+header(&quot;Testing copying an editable plaint-text range without a user gesture.&quot;)
+makeSelection(&quot;editablePlainTextParagraph&quot;, 0, 1);
+test(&quot;copy&quot;, false, false, false);
+
+header(&quot;Testing copying an editable plaint-text caret without a user gesture.&quot;)
+makeSelection(&quot;editablePlainTextParagraph&quot;, 0, 0);
+test(&quot;copy&quot;, false, false, false);
+
+header(&quot;Testing copying when there is no selection without a user gesture.&quot;)
+window.getSelection().removeAllRanges();
+test(&quot;copy&quot;, false, false, false);
+
+clearSelectionContainer();
+
+header(&quot;Testing cutting an editableParagraph range without a user gesture.&quot;)
+makeSelection(&quot;editableParagraph&quot;, 0, 1);
+test(&quot;cut&quot;, false, false, false);
+
+header(&quot;Testing cutting an editableParagraph caret without a user gesture.&quot;)
+makeSelection(&quot;editableParagraph&quot;, 0, 0);
+test(&quot;cut&quot;, false, false, false);
+
+header(&quot;Testing cutting an non-editable range without a user gesture.&quot;)
+makeSelection(&quot;nonEditableParagraph&quot;, 0, 1);
+test(&quot;cut&quot;, false, false, false);
+
+header(&quot;Testing cutting an non-editable caret without a user gesture.&quot;)
+makeSelection(&quot;nonEditableParagraph&quot;, 0, 0);
+test(&quot;cut&quot;, false, false, false);
+
+header(&quot;Testing cutting an editable plaint-text range without a user gesture.&quot;)
+makeSelection(&quot;editablePlainTextParagraph&quot;, 0, 1);
+test(&quot;cut&quot;, false, false, false);
+
+header(&quot;Testing cutting an editable plaint-text caret without a user gesture.&quot;)
+makeSelection(&quot;editablePlainTextParagraph&quot;, 0, 0);
+test(&quot;cut&quot;, false, false, false);
+
+header(&quot;Testing cutting when there is no selection without a user gesture.&quot;)
+window.getSelection().removeAllRanges();
+test(&quot;cut&quot;, false, false, false);
+
+clearSelectionContainer();
+
+// Then test copy/cut with user gestures.
+if (window.testRunner) {
+    function clickButton(button)
+    {
+        eventSender.mouseMoveTo(button.offsetLeft + button.offsetWidth / 2, button.offsetTop + button.offsetHeight / 2);
+        eventSender.mouseDown();
+        eventSender.mouseUp();
+    }
+
+    clickButton(buttonForCopy);
+    clickButton(buttonForCut);
+
+    buttonForCopy.remove();
+    buttonForCut.remove();
+}
+&lt;/script&gt;
+&lt;script src=&quot;../../resources/js-test-post.js&quot;&gt;&lt;/script&gt;
+&lt;/body&gt;
+&lt;/html&gt;
</ins></span></pre></div>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (198091 => 198092)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2016-03-14 03:58:26 UTC (rev 198091)
+++ trunk/Source/WebCore/ChangeLog        2016-03-14 04:43:58 UTC (rev 198092)
</span><span class="lines">@@ -1,3 +1,31 @@
</span><ins>+2016-03-13  Sam Weinig  &lt;sam@webkit.org&gt;
+
+        Implement unprivileged execCommand(&quot;copy&quot;) and execCommand(&quot;cut&quot;)
+        &lt;rdar://problem/24354406&gt;
+        https://bugs.webkit.org/show_bug.cgi?id=146336
+
+        Reviewed by Dean Jackson.
+
+        Test: editing/execCommand/clipboard-access-with-user-gesture.html
+
+        * WebCore.xcodeproj/project.pbxproj:
+        Add new files.
+
+        * editing/ClipboardAccessPolicy.h:
+        Added.
+
+        * editing/EditorCommand.cpp:
+        (WebCore::defaultValueForSupportedCopyCut):
+        (WebCore::supportedCopyCut):
+        Match other browsers and allow the copy and cut commands
+        to be executed when there is a user gesture.
+
+        * page/Settings.h:
+        Add include of ClipboardAccessPolicy.h.
+
+        * page/Settings.in:
+        Add new setting for ClipboardAccessPolicy
+
</ins><span class="cx"> 2016-03-13  Ryosuke Niwa  &lt;rniwa@webkit.org&gt;
</span><span class="cx"> 
</span><span class="cx">         REGRESSION (r190840): crash inside details element's slotNameFunction
</span></span></pre></div>
<a id="trunkSourceWebCoreWebCorexcodeprojprojectpbxproj"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (198091 => 198092)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj        2016-03-14 03:58:26 UTC (rev 198091)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj        2016-03-14 04:43:58 UTC (rev 198092)
</span><span class="lines">@@ -2733,6 +2733,7 @@
</span><span class="cx">                 7C33F35A1B4A044800502CAF /* JSCharacterDataCustom.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7C33F3581B4A044800502CAF /* JSCharacterDataCustom.cpp */; };
</span><span class="cx">                 7C33F35E1B4A04CE00502CAF /* JSDocumentTypeCustom.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7C33F35C1B4A04CE00502CAF /* JSDocumentTypeCustom.cpp */; };
</span><span class="cx">                 7C33F3621B4A050400502CAF /* JSDocumentFragmentCustom.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7C33F3601B4A050400502CAF /* JSDocumentFragmentCustom.cpp */; };
</span><ins>+                7C3A91E61C963B8800D1A7E3 /* ClipboardAccessPolicy.h in Headers */ = {isa = PBXBuildFile; fileRef = 7C3A91E51C963B8800D1A7E3 /* ClipboardAccessPolicy.h */; settings = {ATTRIBUTES = (Private, ); }; };
</ins><span class="cx">                 7C3B79711908757B00B47A2D /* UserMessageHandler.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7C3B796F1908757B00B47A2D /* UserMessageHandler.cpp */; };
</span><span class="cx">                 7C3B79721908757B00B47A2D /* UserMessageHandler.h in Headers */ = {isa = PBXBuildFile; fileRef = 7C3B79701908757B00B47A2D /* UserMessageHandler.h */; settings = {ATTRIBUTES = (Private, ); }; };
</span><span class="cx">                 7C3E510A18DF8F3500C112F7 /* HTMLConverter.h in Headers */ = {isa = PBXBuildFile; fileRef = 7C3E510818DF8F3500C112F7 /* HTMLConverter.h */; settings = {ATTRIBUTES = (Private, ); }; };
</span><span class="lines">@@ -10369,6 +10370,7 @@
</span><span class="cx">                 7C33F3581B4A044800502CAF /* JSCharacterDataCustom.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSCharacterDataCustom.cpp; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 7C33F35C1B4A04CE00502CAF /* JSDocumentTypeCustom.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSDocumentTypeCustom.cpp; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 7C33F3601B4A050400502CAF /* JSDocumentFragmentCustom.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSDocumentFragmentCustom.cpp; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><ins>+                7C3A91E51C963B8800D1A7E3 /* ClipboardAccessPolicy.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ClipboardAccessPolicy.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</ins><span class="cx">                 7C3B796F1908757B00B47A2D /* UserMessageHandler.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = UserMessageHandler.cpp; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 7C3B79701908757B00B47A2D /* UserMessageHandler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UserMessageHandler.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 7C3E510818DF8F3500C112F7 /* HTMLConverter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HTMLConverter.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="lines">@@ -18844,6 +18846,7 @@
</span><span class="cx">                                 93309D8A099E64910056E581 /* ApplyStyleCommand.h */,
</span><span class="cx">                                 93309D8B099E64910056E581 /* BreakBlockquoteCommand.cpp */,
</span><span class="cx">                                 93309D8C099E64910056E581 /* BreakBlockquoteCommand.h */,
</span><ins>+                                7C3A91E51C963B8800D1A7E3 /* ClipboardAccessPolicy.h */,
</ins><span class="cx">                                 93309D8D099E64910056E581 /* CompositeEditCommand.cpp */,
</span><span class="cx">                                 93309D8E099E64910056E581 /* CompositeEditCommand.h */,
</span><span class="cx">                                 D0B0556709C6700100307E43 /* CreateLinkCommand.cpp */,
</span><span class="lines">@@ -26499,6 +26502,7 @@
</span><span class="cx">                                 BC46C1FB0C0DDC8F0020CFC3 /* JSCSSCharsetRule.h in Headers */,
</span><span class="cx">                                 409EBDC316B7F3A600CBA3FC /* JSCSSFontFaceLoadEvent.h in Headers */,
</span><span class="cx">                                 BC46C1FD0C0DDC8F0020CFC3 /* JSCSSFontFaceRule.h in Headers */,
</span><ins>+                                7C3A91E61C963B8800D1A7E3 /* ClipboardAccessPolicy.h in Headers */,
</ins><span class="cx">                                 BC46C1FF0C0DDC8F0020CFC3 /* JSCSSImportRule.h in Headers */,
</span><span class="cx">                                 316FE0720E6CCBEE00BF6088 /* JSCSSKeyframeRule.h in Headers */,
</span><span class="cx">                                 316FE0740E6CCBEE00BF6088 /* JSCSSKeyframesRule.h in Headers */,
</span></span></pre></div>
<a id="trunkSourceWebCoreeditingClipboardAccessPolicyh"></a>
<div class="addfile"><h4>Added: trunk/Source/WebCore/editing/ClipboardAccessPolicy.h (0 => 198092)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/editing/ClipboardAccessPolicy.h                                (rev 0)
+++ trunk/Source/WebCore/editing/ClipboardAccessPolicy.h        2016-03-14 04:43:58 UTC (rev 198092)
</span><span class="lines">@@ -0,0 +1,36 @@
</span><ins>+/*
+ * Copyright (C) 2016 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+namespace WebCore {
+
+enum class ClipboardAccessPolicy {
+    Allow,
+    Deny,
+    RequiresUserGesture
+};
+
+} // namespace WebCore
</ins></span></pre></div>
<a id="trunkSourceWebCoreeditingEditorCommandcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/editing/EditorCommand.cpp (198091 => 198092)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/editing/EditorCommand.cpp        2016-03-14 03:58:26 UTC (rev 198091)
+++ trunk/Source/WebCore/editing/EditorCommand.cpp        2016-03-14 04:43:58 UTC (rev 198092)
</span><span class="lines">@@ -57,6 +57,7 @@
</span><span class="cx"> #include &quot;StyleProperties.h&quot;
</span><span class="cx"> #include &quot;TypingCommand.h&quot;
</span><span class="cx"> #include &quot;UnlinkCommand.h&quot;
</span><ins>+#include &quot;UserGestureIndicator.h&quot;
</ins><span class="cx"> #include &quot;UserTypingGestureIndicator.h&quot;
</span><span class="cx"> #include &quot;htmlediting.h&quot;
</span><span class="cx"> #include &quot;markup.h&quot;
</span><span class="lines">@@ -1157,12 +1158,31 @@
</span><span class="cx">     return false;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+static bool defaultValueForSupportedCopyCut(Frame&amp; frame)
+{
+    auto&amp; settings = frame.settings();
+    if (settings.javaScriptCanAccessClipboard())
+        return true;
+    
+    switch (settings.clipboardAccessPolicy()) {
+    case ClipboardAccessPolicy::Allow:
+        return true;
+    case ClipboardAccessPolicy::Deny:
+        return false;
+    case ClipboardAccessPolicy::RequiresUserGesture:
+        return UserGestureIndicator::processingUserGesture();
+    }
+
+    ASSERT_NOT_REACHED();
+    return false;
+}
+
</ins><span class="cx"> static bool supportedCopyCut(Frame* frame)
</span><span class="cx"> {
</span><span class="cx">     if (!frame)
</span><span class="cx">         return false;
</span><span class="cx"> 
</span><del>-    bool defaultValue = frame-&gt;settings().javaScriptCanAccessClipboard();
</del><ins>+    bool defaultValue = defaultValueForSupportedCopyCut(*frame);
</ins><span class="cx"> 
</span><span class="cx">     EditorClient* client = frame-&gt;editor().client();
</span><span class="cx">     return client ? client-&gt;canCopyCut(frame, defaultValue) : defaultValue;
</span></span></pre></div>
<a id="trunkSourceWebCorepageSettingsh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/page/Settings.h (198091 => 198092)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/page/Settings.h        2016-03-14 03:58:26 UTC (rev 198091)
+++ trunk/Source/WebCore/page/Settings.h        2016-03-14 04:43:58 UTC (rev 198092)
</span><span class="lines">@@ -27,13 +27,14 @@
</span><span class="cx"> #ifndef Settings_h
</span><span class="cx"> #define Settings_h
</span><span class="cx"> 
</span><ins>+#include &quot;ClipboardAccessPolicy.h&quot;
</ins><span class="cx"> #include &quot;EditingBehaviorTypes.h&quot;
</span><span class="cx"> #include &quot;IntSize.h&quot;
</span><del>-#include &quot;URL.h&quot;
</del><span class="cx"> #include &quot;SecurityOrigin.h&quot;
</span><span class="cx"> #include &quot;SettingsMacros.h&quot;
</span><span class="cx"> #include &quot;TextFlags.h&quot;
</span><span class="cx"> #include &quot;Timer.h&quot;
</span><ins>+#include &quot;URL.h&quot;
</ins><span class="cx"> #include &lt;chrono&gt;
</span><span class="cx"> #include &lt;runtime/RuntimeFlags.h&gt;
</span><span class="cx"> #include &lt;unicode/uscript.h&gt;
</span></span></pre></div>
<a id="trunkSourceWebCorepageSettingsin"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/page/Settings.in (198091 => 198092)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/page/Settings.in        2016-03-14 03:58:26 UTC (rev 198091)
+++ trunk/Source/WebCore/page/Settings.in        2016-03-14 04:43:58 UTC (rev 198092)
</span><span class="lines">@@ -53,6 +53,7 @@
</span><span class="cx"> javaScriptCanAccessClipboard initial=false
</span><span class="cx"> shouldPrintBackgrounds initial=false
</span><span class="cx"> usesDashboardBackwardCompatibilityMode initial=false, conditional=DASHBOARD_SUPPORT
</span><ins>+clipboardAccessPolicy type=ClipboardAccessPolicy, initial=ClipboardAccessPolicy::RequiresUserGesture
</ins><span class="cx"> 
</span><span class="cx"> textAreasAreResizable initial=false, setNeedsStyleRecalcInAllFrames=1
</span><span class="cx"> authorAndUserStylesEnabled initial=true, setNeedsStyleRecalcInAllFrames=1
</span></span></pre>
</div>
</div>

</body>
</html>