Diff
Modified: trunk/LayoutTests/ChangeLog (198353 => 198354)
--- trunk/LayoutTests/ChangeLog 2016-03-17 21:02:07 UTC (rev 198353)
+++ trunk/LayoutTests/ChangeLog 2016-03-17 21:04:49 UTC (rev 198354)
@@ -1,3 +1,21 @@
+2016-03-17 Sam Weinig <s...@webkit.org>
+
+ Implement document.queryCommandSupported("copy")
+ https://bugs.webkit.org/show_bug.cgi?id=155548
+ <rdar://problem/25195295>
+
+ Reviewed by Enrica Casucci.
+
+ * editing/execCommand/clipboard-access-with-user-gesture-expected.txt:
+ * editing/execCommand/clipboard-access-with-user-gesture.html:
+ document.queryCommandSupported('copy') should be returning true.
+
+ * editing/pasteboard/can-read-in-copy-and-cut-events.html:
+ * editing/pasteboard/copy-cut-paste-events-fired-when-disabled.html:
+ * editing/pasteboard/pasting-empty-html-falls-back-to-text.html:
+ * editing/pasteboard/set_data_typeof_return.html:
+ Use testRunner.execCommand() to test the behavior of a user.
+
2016-03-17 Joseph Pecoraro <pecor...@apple.com>
Web Inspector: HeapSnapshots are slow and use too much memory
Modified: trunk/LayoutTests/editing/execCommand/clipboard-access-with-user-gesture-expected.txt (198353 => 198354)
--- trunk/LayoutTests/editing/execCommand/clipboard-access-with-user-gesture-expected.txt 2016-03-17 21:02:07 UTC (rev 198353)
+++ trunk/LayoutTests/editing/execCommand/clipboard-access-with-user-gesture-expected.txt 2016-03-17 21:04:49 UTC (rev 198354)
@@ -7,7 +7,7 @@
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 document.queryCommandSupported('copy') is true
PASS eventSeen['copy'] is false
PASS document.execCommand('copy') is false
PASS eventSeen['copy'] is false
@@ -15,7 +15,7 @@
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 document.queryCommandSupported('copy') is true
PASS eventSeen['copy'] is false
PASS document.execCommand('copy') is false
PASS eventSeen['copy'] is false
@@ -23,7 +23,7 @@
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 document.queryCommandSupported('copy') is true
PASS eventSeen['copy'] is false
PASS document.execCommand('copy') is false
PASS eventSeen['copy'] is false
@@ -31,7 +31,7 @@
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 document.queryCommandSupported('copy') is true
PASS eventSeen['copy'] is false
PASS document.execCommand('copy') is false
PASS eventSeen['copy'] is false
@@ -39,7 +39,7 @@
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 document.queryCommandSupported('copy') is true
PASS eventSeen['copy'] is false
PASS document.execCommand('copy') is false
PASS eventSeen['copy'] is false
@@ -47,7 +47,7 @@
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 document.queryCommandSupported('copy') is true
PASS eventSeen['copy'] is false
PASS document.execCommand('copy') is false
PASS eventSeen['copy'] is false
@@ -55,7 +55,7 @@
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 document.queryCommandSupported('copy') is true
PASS eventSeen['copy'] is false
PASS document.execCommand('copy') is false
PASS eventSeen['copy'] is false
@@ -63,7 +63,7 @@
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 document.queryCommandSupported('cut') is true
PASS eventSeen['cut'] is false
PASS document.execCommand('cut') is false
PASS eventSeen['cut'] is false
@@ -71,7 +71,7 @@
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 document.queryCommandSupported('cut') is true
PASS eventSeen['cut'] is false
PASS document.execCommand('cut') is false
PASS eventSeen['cut'] is false
@@ -79,7 +79,7 @@
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 document.queryCommandSupported('cut') is true
PASS eventSeen['cut'] is false
PASS document.execCommand('cut') is false
PASS eventSeen['cut'] is false
@@ -87,7 +87,7 @@
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 document.queryCommandSupported('cut') is true
PASS eventSeen['cut'] is false
PASS document.execCommand('cut') is false
PASS eventSeen['cut'] is false
@@ -95,7 +95,7 @@
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 document.queryCommandSupported('cut') is true
PASS eventSeen['cut'] is false
PASS document.execCommand('cut') is false
PASS eventSeen['cut'] is false
@@ -103,7 +103,7 @@
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 document.queryCommandSupported('cut') is true
PASS eventSeen['cut'] is false
PASS document.execCommand('cut') is false
PASS eventSeen['cut'] is false
@@ -111,7 +111,7 @@
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 document.queryCommandSupported('cut') is true
PASS eventSeen['cut'] is false
PASS document.execCommand('cut') is false
PASS eventSeen['cut'] is false
Modified: trunk/LayoutTests/editing/execCommand/clipboard-access-with-user-gesture.html (198353 => 198354)
--- trunk/LayoutTests/editing/execCommand/clipboard-access-with-user-gesture.html 2016-03-17 21:02:07 UTC (rev 198353)
+++ trunk/LayoutTests/editing/execCommand/clipboard-access-with-user-gesture.html 2016-03-17 21:04:49 UTC (rev 198354)
@@ -196,61 +196,61 @@
// First test copy/cut without user gestures.
header("Testing copying an editableParagraph range without a user gesture.")
makeSelection("editableParagraph", 0, 1);
-test("copy", false, false, false);
+test("copy", false, true, false);
header("Testing copying an editableParagraph caret without a user gesture.")
makeSelection("editableParagraph", 0, 0);
-test("copy", false, false, false);
+test("copy", false, true, false);
header("Testing copying an non-editable range without a user gesture.")
makeSelection("nonEditableParagraph", 0, 1);
-test("copy", false, false, false);
+test("copy", false, true, false);
header("Testing copying an non-editable caret without a user gesture.")
makeSelection("nonEditableParagraph", 0, 0);
-test("copy", false, false, false);
+test("copy", false, true, false);
header("Testing copying an editable plaint-text range without a user gesture.")
makeSelection("editablePlainTextParagraph", 0, 1);
-test("copy", false, false, false);
+test("copy", false, true, false);
header("Testing copying an editable plaint-text caret without a user gesture.")
makeSelection("editablePlainTextParagraph", 0, 0);
-test("copy", false, false, false);
+test("copy", false, true, false);
header("Testing copying when there is no selection without a user gesture.")
window.getSelection().removeAllRanges();
-test("copy", false, false, false);
+test("copy", false, true, false);
clearSelectionContainer();
header("Testing cutting an editableParagraph range without a user gesture.")
makeSelection("editableParagraph", 0, 1);
-test("cut", false, false, false);
+test("cut", false, true, false);
header("Testing cutting an editableParagraph caret without a user gesture.")
makeSelection("editableParagraph", 0, 0);
-test("cut", false, false, false);
+test("cut", false, true, false);
header("Testing cutting an non-editable range without a user gesture.")
makeSelection("nonEditableParagraph", 0, 1);
-test("cut", false, false, false);
+test("cut", false, true, false);
header("Testing cutting an non-editable caret without a user gesture.")
makeSelection("nonEditableParagraph", 0, 0);
-test("cut", false, false, false);
+test("cut", false, true, false);
header("Testing cutting an editable plaint-text range without a user gesture.")
makeSelection("editablePlainTextParagraph", 0, 1);
-test("cut", false, false, false);
+test("cut", false, true, false);
header("Testing cutting an editable plaint-text caret without a user gesture.")
makeSelection("editablePlainTextParagraph", 0, 0);
-test("cut", false, false, false);
+test("cut", false, true, false);
header("Testing cutting when there is no selection without a user gesture.")
window.getSelection().removeAllRanges();
-test("cut", false, false, false);
+test("cut", false, true, false);
clearSelectionContainer();
Modified: trunk/LayoutTests/editing/mac/pasteboard/text-precomposed.html (198353 => 198354)
--- trunk/LayoutTests/editing/mac/pasteboard/text-precomposed.html 2016-03-17 21:02:07 UTC (rev 198353)
+++ trunk/LayoutTests/editing/mac/pasteboard/text-precomposed.html 2016-03-17 21:04:49 UTC (rev 198354)
@@ -26,11 +26,11 @@
log("FAIL: text/plain data on the clipboard is \"" + data + "\"");
}, true);
- document.execCommand("Copy");
+ window.testRunner.execCommand("Copy");
var target = document.getElementById("paste-target");
target.focus();
- document.execCommand("Paste");
+ window.testRunner.execCommand("Paste");
var data = ""
if (data ="" "\u00e9")
log("PASS: pasted text is precomposed");
Modified: trunk/LayoutTests/editing/pasteboard/can-read-in-copy-and-cut-events.html (198353 => 198354)
--- trunk/LayoutTests/editing/pasteboard/can-read-in-copy-and-cut-events.html 2016-03-17 21:02:07 UTC (rev 198353)
+++ trunk/LayoutTests/editing/pasteboard/can-read-in-copy-and-cut-events.html 2016-03-17 21:04:49 UTC (rev 198354)
@@ -30,8 +30,8 @@
if (!window.testRunner)
return;
testRunner.dumpAsText();
- document.execCommand('copy');
- document.execCommand('cut');
+ testRunner.execCommand('copy');
+ testRunner.execCommand('cut');
}
</script>
</head>
Modified: trunk/LayoutTests/editing/pasteboard/copy-cut-paste-events-fired-when-disabled.html (198353 => 198354)
--- trunk/LayoutTests/editing/pasteboard/copy-cut-paste-events-fired-when-disabled.html 2016-03-17 21:02:07 UTC (rev 198353)
+++ trunk/LayoutTests/editing/pasteboard/copy-cut-paste-events-fired-when-disabled.html 2016-03-17 21:04:49 UTC (rev 198354)
@@ -9,10 +9,11 @@
console.appendChild(li);
li.appendChild(text);
}
-if (window.testRunner)
+if (window.testRunner) {
window.testRunner.dumpAsText();
-document.execCommand("Copy");
-document.execCommand("Cut");
-document.execCommand("Paste");
+ window.testRunner.execCommand("Copy");
+ window.testRunner.execCommand("Cut");
+ window.testRunner.execCommand("Paste");
+}
</script>
</body>
Modified: trunk/LayoutTests/editing/pasteboard/pasting-empty-html-falls-back-to-text.html (198353 => 198354)
--- trunk/LayoutTests/editing/pasteboard/pasting-empty-html-falls-back-to-text.html 2016-03-17 21:02:07 UTC (rev 198353)
+++ trunk/LayoutTests/editing/pasteboard/pasting-empty-html-falls-back-to-text.html 2016-03-17 21:04:49 UTC (rev 198354)
@@ -15,13 +15,13 @@
testRunner.dumpAsText();
document.body.addEventListener('copy', handleCopy);
- document.execCommand('copy');
+ testRunner.execCommand('copy');
var selection = window.getSelection();
var range = document.createRange();
range.selectNode(document.getElementById('description'));
selection.addRange(range);
selection.collapseToEnd();
- document.execCommand('paste');
+ testRunner.execCommand('paste');
}
</script>
<body _onload_="runTest()" contenteditable="true">
Modified: trunk/LayoutTests/editing/pasteboard/set_data_typeof_return.html (198353 => 198354)
--- trunk/LayoutTests/editing/pasteboard/set_data_typeof_return.html 2016-03-17 21:02:07 UTC (rev 198353)
+++ trunk/LayoutTests/editing/pasteboard/set_data_typeof_return.html 2016-03-17 21:04:49 UTC (rev 198354)
@@ -13,7 +13,8 @@
<script>
description("Simple test to validate the return type of setData(). To run the test manually, simply select any text and initiate a copy operation.");
-document.execCommand('copy');
+if (window.testRunner)
+ window.testRunner.execCommand('copy');
</script>
<script src=""
</body>
Modified: trunk/Source/WebCore/ChangeLog (198353 => 198354)
--- trunk/Source/WebCore/ChangeLog 2016-03-17 21:02:07 UTC (rev 198353)
+++ trunk/Source/WebCore/ChangeLog 2016-03-17 21:04:49 UTC (rev 198354)
@@ -1,3 +1,32 @@
+2016-03-17 Sam Weinig <s...@webkit.org>
+
+ Implement document.queryCommandSupported("copy")
+ https://bugs.webkit.org/show_bug.cgi?id=155548
+ <rdar://problem/25195295>
+
+ Reviewed by Enrica Casucci.
+
+ - document.queryCommandSupported("copy") and document.queryCommandSupported("cut") need
+ to return true if the ClipboardAccessPolicy is either Allow or RequiresUserGesture.
+ But, document.queryCommandEnabled("copy") and document.queryCommandEnabled("cut")
+ should still return false when there is no user gesture. I also had to maintain a weird
+ quirk that copy and cut should be allowed to execute, and thus fire the oncopy and oncut
+ events, even when disabled, if coming from a "MenuOrKeyBinding" source. To do this, I
+ upgraded the allowExecutionWhenDisabled bit to a function taking a source, and return true
+ only when the correct source is specified.
+
+ * editing/Editor.h:
+ * editing/EditorCommand.cpp:
+ (WebCore::defaultValueForSupportedCopyCut):
+ (WebCore::allowCopyCutFromDOM):
+ (WebCore::enabledCopy):
+ (WebCore::enabledCut):
+ (WebCore::allowExecutionWhenDisabled):
+ (WebCore::doNotAllowExecutionWhenDisabled):
+ (WebCore::allowExecutionWhenDisabledCopyCut):
+ (WebCore::Editor::Command::execute):
+ (WebCore::Editor::Command::allowExecutionWhenDisabled):
+
2016-03-17 Antti Koivisto <an...@apple.com>
DataURLDecoder::DecodingResultDispatcher may get deleted outside main thread
Modified: trunk/Source/WebCore/editing/Editor.h (198353 => 198354)
--- trunk/Source/WebCore/editing/Editor.h 2016-03-17 21:02:07 UTC (rev 198353)
+++ trunk/Source/WebCore/editing/Editor.h 2016-03-17 21:04:49 UTC (rev 198354)
@@ -215,6 +215,7 @@
String value(Event* triggeringEvent = nullptr) const;
WEBCORE_EXPORT bool isTextInsertion() const;
+ WEBCORE_EXPORT bool allowExecutionWhenDisabled() const;
private:
const EditorInternalCommand* m_command { nullptr };
Modified: trunk/Source/WebCore/editing/EditorCommand.cpp (198353 => 198354)
--- trunk/Source/WebCore/editing/EditorCommand.cpp 2016-03-17 21:02:07 UTC (rev 198353)
+++ trunk/Source/WebCore/editing/EditorCommand.cpp 2016-03-17 21:04:49 UTC (rev 198354)
@@ -75,7 +75,7 @@
TriState (*state)(Frame&, Event*);
String (*value)(Frame&, Event*);
bool isTextInsertion;
- bool allowExecutionWhenDisabled;
+ bool (*allowExecutionWhenDisabled)(EditorCommandSource);
};
typedef HashMap<String, const EditorInternalCommand*, ASCIICaseInsensitiveHash> CommandMap;
@@ -83,9 +83,6 @@
static const bool notTextInsertion = false;
static const bool isTextInsertion = true;
-static const bool allowExecutionWhenDisabled = true;
-static const bool doNotAllowExecutionWhenDisabled = false;
-
// Related to Editor::selectionForCommand.
// Certain operations continue to use the target control's selection even if the event handler
// already moved the selection outside of the text control.
@@ -1166,11 +1163,10 @@
switch (settings.clipboardAccessPolicy()) {
case ClipboardAccessPolicy::Allow:
+ case ClipboardAccessPolicy::RequiresUserGesture:
return true;
case ClipboardAccessPolicy::Deny:
return false;
- case ClipboardAccessPolicy::RequiresUserGesture:
- return UserGestureIndicator::processingUserGesture();
}
ASSERT_NOT_REACHED();
@@ -1239,16 +1235,51 @@
return selection.isCaret() && selection.isContentEditable();
}
-static bool enabledCopy(Frame& frame, Event*, EditorCommandSource)
+static bool allowCopyCutFromDOM(Frame& frame)
{
- return frame.editor().canDHTMLCopy() || frame.editor().canCopy();
+ auto& settings = frame.settings();
+ if (settings._javascript_CanAccessClipboard())
+ 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;
}
-static bool enabledCut(Frame& frame, Event*, EditorCommandSource)
+static bool enabledCopy(Frame& frame, Event*, EditorCommandSource source)
{
- return frame.editor().canDHTMLCut() || frame.editor().canCut();
+ switch (source) {
+ case CommandFromMenuOrKeyBinding:
+ return frame.editor().canDHTMLCopy() || frame.editor().canCopy();
+ case CommandFromDOM:
+ case CommandFromDOMWithUserInterface:
+ return allowCopyCutFromDOM(frame) && (frame.editor().canDHTMLCopy() || frame.editor().canCopy());
+ }
+ ASSERT_NOT_REACHED();
+ return false;
}
+static bool enabledCut(Frame& frame, Event*, EditorCommandSource source)
+{
+ switch (source) {
+ case CommandFromMenuOrKeyBinding:
+ return frame.editor().canDHTMLCut() || frame.editor().canCut();
+ case CommandFromDOM:
+ case CommandFromDOMWithUserInterface:
+ return allowCopyCutFromDOM(frame) && (frame.editor().canDHTMLCut() || frame.editor().canCut());
+ }
+ ASSERT_NOT_REACHED();
+ return false;
+}
+
static bool enabledClearText(Frame& frame, Event*, EditorCommandSource)
{
UNUSED_PARAM(frame);
@@ -1462,6 +1493,32 @@
return formatBlockElement->localName();
}
+// allowExecutionWhenDisabled functions
+
+static bool allowExecutionWhenDisabled(EditorCommandSource)
+{
+ return true;
+}
+
+static bool doNotAllowExecutionWhenDisabled(EditorCommandSource)
+{
+ return false;
+}
+
+static bool allowExecutionWhenDisabledCopyCut(EditorCommandSource source)
+{
+ switch (source) {
+ case CommandFromMenuOrKeyBinding:
+ return true;
+ case CommandFromDOM:
+ case CommandFromDOMWithUserInterface:
+ return false;
+ }
+
+ ASSERT_NOT_REACHED();
+ return false;
+}
+
// Map of functions
struct CommandEntry {
@@ -1479,9 +1536,9 @@
{ "BackColor", { executeBackColor, supported, enabledInRichlyEditableText, stateNone, valueBackColor, notTextInsertion, doNotAllowExecutionWhenDisabled } },
{ "Bold", { executeToggleBold, supported, enabledInRichlyEditableText, stateBold, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
{ "ClearText", { executeClearText, supported, enabledClearText, stateNone, valueNull, notTextInsertion, allowExecutionWhenDisabled } },
- { "Copy", { executeCopy, supportedCopyCut, enabledCopy, stateNone, valueNull, notTextInsertion, allowExecutionWhenDisabled } },
+ { "Copy", { executeCopy, supportedCopyCut, enabledCopy, stateNone, valueNull, notTextInsertion, allowExecutionWhenDisabledCopyCut } },
{ "CreateLink", { executeCreateLink, supported, enabledInRichlyEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
- { "Cut", { executeCut, supportedCopyCut, enabledCut, stateNone, valueNull, notTextInsertion, allowExecutionWhenDisabled } },
+ { "Cut", { executeCut, supportedCopyCut, enabledCut, stateNone, valueNull, notTextInsertion, allowExecutionWhenDisabledCopyCut } },
{ "DefaultParagraphSeparator", { executeDefaultParagraphSeparator, supported, enabled, stateNone, valueDefaultParagraphSeparator, notTextInsertion, doNotAllowExecutionWhenDisabled} },
{ "Delete", { executeDelete, supported, enabledDelete, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
{ "DeleteBackward", { executeDeleteBackward, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
@@ -1716,7 +1773,7 @@
{
if (!isEnabled(triggeringEvent)) {
// Let certain commands be executed when performed explicitly even if they are disabled.
- if (!isSupported() || !m_frame || !m_command->allowExecutionWhenDisabled)
+ if (!allowExecutionWhenDisabled())
return false;
}
m_frame->document()->updateLayoutIgnorePendingStylesheets();
@@ -1771,4 +1828,11 @@
return m_command && m_command->isTextInsertion;
}
+bool Editor::Command::allowExecutionWhenDisabled() const
+{
+ if (!isSupported() || !m_frame)
+ return false;
+ return m_command->allowExecutionWhenDisabled(m_source);
+}
+
} // namespace WebCore