Index: third_party/WebKit/Source/core/editing/commands/EditorCommand.cpp |
diff --git a/third_party/WebKit/Source/core/editing/commands/EditorCommand.cpp b/third_party/WebKit/Source/core/editing/commands/EditorCommand.cpp |
index 06751912f7b45f7712fb6027065d2bdc52f1f136..56c859af2c6124e64270581560ade84d5da1baef 100644 |
--- a/third_party/WebKit/Source/core/editing/commands/EditorCommand.cpp |
+++ b/third_party/WebKit/Source/core/editing/commands/EditorCommand.cpp |
@@ -295,8 +295,19 @@ static bool executeBackColor(LocalFrame& frame, Event*, EditorCommandSource sour |
return executeApplyStyle(frame, source, EditActionSetBackgroundColor, CSSPropertyBackgroundColor, value); |
} |
-static bool executeCopy(LocalFrame& frame, Event*, EditorCommandSource, const String&) |
+static bool canWriteClipboard(LocalFrame& frame, EditorCommandSource source) |
{ |
+ if (source == CommandFromMenuOrKeyBinding) |
+ return true; |
+ Settings* settings = frame.settings(); |
+ bool defaultValue = (settings && settings->javaScriptCanAccessClipboard()) || UserGestureIndicator::processingUserGesture(); |
+ return frame.editor().client().canCopyCut(&frame, defaultValue); |
+} |
+ |
+static bool executeCopy(LocalFrame& frame, Event*, EditorCommandSource source, const String&) |
+{ |
+ if (!canWriteClipboard(frame, source)) |
dcheng
2015/10/14 16:47:37
How come we need to do another check here? It look
yosin_UTC9
2015/10/15 01:30:47
Copy/Cut/Paste are only commands executing even if
dcheng
2015/10/15 06:10:30
Let's add a comment that we need to do these check
yosin_UTC9
2015/10/15 08:18:55
Added comments.
|
+ return false; |
frame.editor().copy(); |
return true; |
} |
@@ -310,8 +321,10 @@ static bool executeCreateLink(LocalFrame& frame, Event*, EditorCommandSource, co |
return true; |
} |
-static bool executeCut(LocalFrame& frame, Event*, EditorCommandSource, const String&) |
+static bool executeCut(LocalFrame& frame, Event*, EditorCommandSource source, const String&) |
{ |
+ if (!canWriteClipboard(frame, source)) |
+ return false; |
frame.editor().cut(); |
return true; |
} |
@@ -941,14 +954,27 @@ static bool executeToggleOverwrite(LocalFrame& frame, Event*, EditorCommandSourc |
return true; |
} |
-static bool executePaste(LocalFrame& frame, Event*, EditorCommandSource, const String&) |
+static bool canReadClipboard(LocalFrame& frame, EditorCommandSource source) |
{ |
+ if (source == CommandFromMenuOrKeyBinding) |
+ return true; |
+ Settings* settings = frame.settings(); |
+ bool defaultValue = settings && settings->javaScriptCanAccessClipboard() && settings->DOMPasteAllowed(); |
+ return frame.editor().client().canPaste(&frame, defaultValue); |
+} |
+ |
+static bool executePaste(LocalFrame& frame, Event*, EditorCommandSource source, const String&) |
+{ |
+ if (!canReadClipboard(frame, source)) |
+ return false; |
frame.editor().paste(); |
return true; |
} |
static bool executePasteGlobalSelection(LocalFrame& frame, Event*, EditorCommandSource source, const String&) |
{ |
+ if (!canReadClipboard(frame, source)) |
+ return false; |
if (!frame.editor().behavior().supportsGlobalSelection()) |
return false; |
ASSERT_UNUSED(source, source == CommandFromMenuOrKeyBinding); |
@@ -1170,26 +1196,6 @@ static bool supportedFromMenuOrKeyBinding(LocalFrame*) |
return false; |
} |
-static bool supportedCopyCut(LocalFrame* frame) |
-{ |
- if (!frame) |
- return false; |
- |
- Settings* settings = frame->settings(); |
- bool defaultValue = (settings && settings->javaScriptCanAccessClipboard()) || UserGestureIndicator::processingUserGesture(); |
- return frame->editor().client().canCopyCut(frame, defaultValue); |
-} |
- |
-static bool supportedPaste(LocalFrame* frame) |
-{ |
- if (!frame) |
- return false; |
- |
- Settings* settings = frame->settings(); |
- bool defaultValue = settings && settings->javaScriptCanAccessClipboard() && settings->DOMPasteAllowed(); |
- return frame->editor().client().canPaste(frame, defaultValue); |
-} |
- |
// Enabled functions |
static bool enabled(LocalFrame&, Event*, EditorCommandSource) |
@@ -1230,13 +1236,17 @@ static bool enableCaretInEditableText(LocalFrame& frame, Event* event, EditorCom |
return selection.isCaret() && selection.isContentEditable(); |
} |
-static bool enabledCopy(LocalFrame& frame, Event*, EditorCommandSource) |
+static bool enabledCopy(LocalFrame& frame, Event*, EditorCommandSource source) |
{ |
+ if (!canWriteClipboard(frame, source)) |
+ return false; |
return frame.editor().canDHTMLCopy() || frame.editor().canCopy(); |
} |
-static bool enabledCut(LocalFrame& frame, Event*, EditorCommandSource) |
+static bool enabledCut(LocalFrame& frame, Event*, EditorCommandSource source) |
{ |
+ if (!canWriteClipboard(frame, source)) |
+ return false; |
return frame.editor().canDHTMLCut() || frame.editor().canCut(); |
} |
@@ -1270,8 +1280,10 @@ static bool enabledInRichlyEditableText(LocalFrame& frame, Event*, EditorCommand |
return frame.selection().isCaretOrRange() && frame.selection().isContentRichlyEditable() && frame.selection().rootEditableElement(); |
} |
-static bool enabledPaste(LocalFrame& frame, Event*, EditorCommandSource) |
+static bool enabledPaste(LocalFrame& frame, Event*, EditorCommandSource source) |
{ |
+ if (!canReadClipboard(frame, source)) |
+ return false; |
return frame.editor().canPaste(); |
} |
@@ -1457,9 +1469,9 @@ static const CommandMap& createCommandMap() |
{ "BackColor", {4, executeBackColor, supported, enabledInRichlyEditableText, stateNone, valueBackColor, notTextInsertion, doNotAllowExecutionWhenDisabled } }, |
{ "BackwardDelete", {5, executeDeleteBackward, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } }, // FIXME: remove BackwardDelete when Safari for Windows stops using it. |
{ "Bold", {6, executeToggleBold, supported, enabledInRichlyEditableText, stateBold, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } }, |
- { "Copy", {7, executeCopy, supportedCopyCut, enabledCopy, stateNone, valueNull, notTextInsertion, allowExecutionWhenDisabled } }, |
+ { "Copy", {7, executeCopy, supported, enabledCopy, stateNone, valueNull, notTextInsertion, allowExecutionWhenDisabled } }, |
{ "CreateLink", {8, executeCreateLink, supported, enabledInRichlyEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } }, |
- { "Cut", {9, executeCut, supportedCopyCut, enabledCut, stateNone, valueNull, notTextInsertion, allowExecutionWhenDisabled } }, |
+ { "Cut", {9, executeCut, supported, enabledCut, stateNone, valueNull, notTextInsertion, allowExecutionWhenDisabled } }, |
{ "DefaultParagraphSeparator", {10, executeDefaultParagraphSeparator, supported, enabled, stateNone, valueDefaultParagraphSeparator, notTextInsertion, doNotAllowExecutionWhenDisabled} }, |
{ "Delete", {11, executeDelete, supported, enabledDelete, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } }, |
{ "DeleteBackward", {12, executeDeleteBackward, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } }, |
@@ -1553,8 +1565,8 @@ static const CommandMap& createCommandMap() |
{ "MoveWordRightAndModifySelection", {100, executeMoveWordRightAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelectionOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } }, |
{ "Outdent", {101, executeOutdent, supported, enabledInRichlyEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } }, |
{ "OverWrite", {102, executeToggleOverwrite, supportedFromMenuOrKeyBinding, enabledInRichlyEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } }, |
- { "Paste", {103, executePaste, supportedPaste, enabledPaste, stateNone, valueNull, notTextInsertion, allowExecutionWhenDisabled } }, |
- { "PasteAndMatchStyle", {104, executePasteAndMatchStyle, supportedPaste, enabledPaste, stateNone, valueNull, notTextInsertion, allowExecutionWhenDisabled } }, |
+ { "Paste", {103, executePaste, supported, enabledPaste, stateNone, valueNull, notTextInsertion, allowExecutionWhenDisabled } }, |
+ { "PasteAndMatchStyle", {104, executePasteAndMatchStyle, supported, enabledPaste, stateNone, valueNull, notTextInsertion, allowExecutionWhenDisabled } }, |
{ "PasteGlobalSelection", {105, executePasteGlobalSelection, supportedFromMenuOrKeyBinding, enabledPaste, stateNone, valueNull, notTextInsertion, allowExecutionWhenDisabled } }, |
{ "Print", {106, executePrint, supported, enabled, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } }, |
{ "Redo", {107, executeRedo, supported, enabledRedo, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } }, |