Bug 1558674 - Allow chrome privileged documents to enable/disable copy/paste. r=Ehsan,bgrins

For content HTML/XHTML copy/paste should always be enabled, but for chrome
docs we can support enabling/disabling copy/paste.

Also, restores tests to how they were before copy/paste was always enabled.

Differential Revision: https://phabricator.services.mozilla.com/D34805

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Brendan Dahl 2019-06-18 20:40:19 +00:00
Родитель 1d7ac71577
Коммит ccb8b2f945
10 изменённых файлов: 64 добавлений и 53 удалений

Просмотреть файл

@ -46,12 +46,13 @@ add_task(async function checkMenuEntryStates() {
is(cmdUndo.getAttribute("disabled"), "true", "cmdUndo is disabled");
is(cmdDelete.getAttribute("disabled"), "true", "cmdDelete is disabled");
is(cmdSelectAll.getAttribute("disabled"), "true", "cmdSelectAll is disabled");
is(cmdCut.getAttribute("disabled"), "true", "cmdCut is disabled");
is(cmdCopy.getAttribute("disabled"), "true", "cmdCopy is disabled");
// Cut/Copy/Paste items are enabled in context menu even if there
// is no selection. See also Bug 1303033, and 1317322
is(cmdCut.getAttribute("disabled"), "", "cmdCut is enabled");
is(cmdCopy.getAttribute("disabled"), "", "cmdCopy is enabled");
is(cmdPaste.getAttribute("disabled"), "", "cmdPaste is enabled");
if (isWindows()) {
// emptyClipboard only works on Windows (666254), assert paste only for this OS.
is(cmdPaste.getAttribute("disabled"), "true", "cmdPaste is disabled");
}
const onContextMenuHidden = toolbox.once("menu-close");
EventUtils.sendKey("ESCAPE", toolbox.win);

Просмотреть файл

@ -44,11 +44,12 @@ add_task(async function() {
is(cmdDelete.getAttribute("disabled"), "true", "cmdDelete is disabled");
is(cmdSelectAll.getAttribute("disabled"), "true", "cmdSelectAll is disabled");
// Cut/Copy/Paste items are enabled in context menu even if there is no
// selection. See also Bug 1303033, and 1317322
is(cmdCut.getAttribute("disabled"), "", "cmdCut is enabled");
is(cmdCopy.getAttribute("disabled"), "", "cmdCopy is enabled");
is(cmdPaste.getAttribute("disabled"), "", "cmdPaste is enabled");
is(cmdCut.getAttribute("disabled"), "true", "cmdCut is disabled");
is(cmdCopy.getAttribute("disabled"), "true", "cmdCopy is disabled");
if (isWindows()) {
// emptyClipboard only works on Windows (666254), assert paste only for this OS.
is(cmdPaste.getAttribute("disabled"), "true", "cmdPaste is disabled");
}
info("Closing context menu");
let onContextMenuClose = toolbox.once("menu-close");

Просмотреть файл

@ -42,12 +42,13 @@ add_task(async function() {
is(cmdUndo.getAttribute("disabled"), "true", "cmdUndo is disabled");
is(cmdDelete.getAttribute("disabled"), "true", "cmdDelete is disabled");
is(cmdSelectAll.getAttribute("disabled"), "true", "cmdSelectAll is disabled");
is(cmdCut.getAttribute("disabled"), "true", "cmdCut is disabled");
is(cmdCopy.getAttribute("disabled"), "true", "cmdCopy is disabled");
// Cut/Copy/Paste items are enabled in context menu even if there is no
// selection. See also Bug 1303033, and 1317322
is(cmdCut.getAttribute("disabled"), "", "cmdCut is enabled");
is(cmdCopy.getAttribute("disabled"), "", "cmdCopy is enabled");
is(cmdPaste.getAttribute("disabled"), "", "cmdPaste is enabled");
if (isWindows()) {
// emptyClipboard only works on Windows (666254), assert paste only for this OS.
is(cmdPaste.getAttribute("disabled"), "true", "cmdPaste is disabled");
}
info("Closing context menu");
let onContextMenuClose = toolbox.once("menu-close");

Просмотреть файл

@ -39,12 +39,13 @@ add_task(async function() {
is(cmdUndo.getAttribute("disabled"), "true", "cmdUndo is disabled");
is(cmdDelete.getAttribute("disabled"), "true", "cmdDelete is disabled");
is(cmdSelectAll.getAttribute("disabled"), "true", "cmdSelectAll is disabled");
is(cmdCut.getAttribute("disabled"), "true", "cmdCut is disabled");
is(cmdCopy.getAttribute("disabled"), "true", "cmdCopy is disabled");
// Cut/Copy items are enabled in context menu even if there
// is no selection. See also Bug 1303033, and 1317322
is(cmdCut.getAttribute("disabled"), "", "cmdCut is enabled");
is(cmdCopy.getAttribute("disabled"), "", "cmdCopy is enabled");
is(cmdPaste.getAttribute("disabled"), "", "cmdPaste is enabled");
if (isWindows()) {
// emptyClipboard only works on Windows (666254), assert paste only for this OS.
is(cmdPaste.getAttribute("disabled"), "true", "cmdPaste is disabled");
}
info("Closing context menu");
let onContextMenuClose = toolbox.once("menu-close");

Просмотреть файл

@ -113,7 +113,7 @@ function runTests() {
};
const firstShow = function() {
ok(!cutItem.hasAttribute("disabled"), "cut menuitem is enabled");
ok(cutItem.hasAttribute("disabled"), "cut menuitem is disabled");
closeMenu(firstHide);
};
@ -143,7 +143,7 @@ function runTests() {
};
const showAfterCut = function() {
ok(!cutItem.hasAttribute("disabled"), "cut menuitem is enabled after cut");
ok(cutItem.hasAttribute("disabled"), "cut menuitem is disabled after cut");
ok(!pasteItem.hasAttribute("disabled"), "paste menuitem is enabled after cut");
closeMenu(hideAfterCut);
};
@ -161,7 +161,7 @@ function runTests() {
};
const showAfterPaste = function() {
ok(!cutItem.hasAttribute("disabled"), "cut menuitem is enabled after paste");
ok(cutItem.hasAttribute("disabled"), "cut menuitem is disabled after paste");
ok(!pasteItem.hasAttribute("disabled"), "paste menuitem is enabled after paste");
closeMenu(hideAfterPaste);
};

Просмотреть файл

@ -72,31 +72,31 @@ async function performTests() {
menuPopup = await openContextMenu(hud, hud.jsterm.node || hud.jsterm.inputNode);
expectedContextMenu = [
"#editmenu-undo (editmenu-undo) [disabled]",
"#editmenu-cut (editmenu-cut)",
"#editmenu-copy (editmenu-copy)",
"#editmenu-paste (editmenu-paste)",
"#editmenu-delete (editmenu-delete) [disabled]",
"#editmenu-selectAll (editmenu-select-all) [disabled]",
];
is(getL10NContextMenu(menuPopup).join("\n"), expectedContextMenu.join("\n"),
"The context menu has the correct edit menu items");
let actualEntries = getL10NContextMenu(menuPopup);
is(actualEntries.length, 6, "The context menu has the right number of entries.");
is(actualEntries[0], "#editmenu-undo (editmenu-undo) [disabled]");
is(actualEntries[1], "#editmenu-cut (editmenu-cut) [disabled]");
is(actualEntries[2], "#editmenu-copy (editmenu-copy) [disabled]");
// Paste may or may not be enabled depending on what ran before this.
// If emptyClipboard is fixed (666254) we could assert if it's enabled/disabled.
ok(actualEntries[3].startsWith("#editmenu-paste (editmenu-paste)"));
is(actualEntries[4], "#editmenu-delete (editmenu-delete) [disabled]");
is(actualEntries[5], "#editmenu-selectAll (editmenu-select-all) [disabled]");
const node = hud.jsterm.inputNode || hud.jsterm.node;
const inputContainer = node.closest(".jsterm-input-container");
await openContextMenu(hud, inputContainer);
expectedContextMenu = [
"#editmenu-undo (editmenu-undo) [disabled]",
"#editmenu-cut (editmenu-cut)",
"#editmenu-copy (editmenu-copy)",
"#editmenu-paste (editmenu-paste)",
"#editmenu-delete (editmenu-delete) [disabled]",
"#editmenu-selectAll (editmenu-select-all) [disabled]",
];
is(getL10NContextMenu(menuPopup).join("\n"), expectedContextMenu.join("\n"),
"The context menu has the required elements");
actualEntries = getL10NContextMenu(menuPopup);
is(actualEntries.length, 6, "The context menu has the right number of entries.");
is(actualEntries[0], "#editmenu-undo (editmenu-undo) [disabled]");
is(actualEntries[1], "#editmenu-cut (editmenu-cut) [disabled]");
is(actualEntries[2], "#editmenu-copy (editmenu-copy) [disabled]");
// Paste may or may not be enabled depending on what ran before this.
// If emptyClipboard is fixed (666254) we could assert if it's enabled/disabled.
ok(actualEntries[3].startsWith("#editmenu-paste (editmenu-paste)"));
is(actualEntries[4], "#editmenu-delete (editmenu-delete) [disabled]");
is(actualEntries[5], "#editmenu-selectAll (editmenu-select-all) [disabled]");
await hideContextMenu(hud);
// Close the browser console.

Просмотреть файл

@ -488,9 +488,9 @@ nsresult nsClipboardCommand::IsCommandEnabled(const char* aCommandName,
RefPtr<dom::Document> doc = window->GetExtantDoc();
NS_ENSURE_TRUE(doc, NS_ERROR_FAILURE);
if (doc->IsHTMLOrXHTML()) {
if (doc->IsHTMLOrXHTML() && !nsContentUtils::IsChromeDoc(doc)) {
// In HTML and XHTML documents, we always want the cut, copy and paste
// commands to be enabled.
// commands to be enabled, but if the document is chrome, let it control it.
*outCmdEnabled = true;
} else {
// Cut isn't enabled in xul documents which use nsClipboardCommand

Просмотреть файл

@ -1642,9 +1642,11 @@ static const char* textHtmlEditorFlavors[] = {kUnicodeMime, kHTMLMime,
kPNGImageMime, kGIFImageMime};
bool HTMLEditor::CanPaste(int32_t aClipboardType) const {
// Always enable the paste command when inside of a HTML or XHTML document.
// Always enable the paste command when inside of a HTML or XHTML document,
// but if the document is chrome, let it control it.
Document* document = GetDocument();
if (document && document->IsHTMLOrXHTML()) {
if (document && document->IsHTMLOrXHTML() &&
!nsContentUtils::IsChromeDoc(document)) {
return true;
}

Просмотреть файл

@ -1794,9 +1794,11 @@ bool TextEditor::CanCut() const {
return false;
}
// Cut is always enabled in HTML documents
// Cut is always enabled in HTML documents, but if the document is chrome,
// let it control it.
Document* document = GetDocument();
if (document && document->IsHTMLOrXHTML()) {
if (document && document->IsHTMLOrXHTML() &&
!nsContentUtils::IsChromeDoc(document)) {
return true;
}
@ -1823,9 +1825,11 @@ bool TextEditor::CanCopy() const {
return false;
}
// Copy is always enabled in HTML documents
// Copy is always enabled in HTML documents, but if the document is chrome,
// let it control it.
Document* document = GetDocument();
if (document && document->IsHTMLOrXHTML()) {
if (document && document->IsHTMLOrXHTML() &&
!nsContentUtils::IsChromeDoc(document)) {
return true;
}

Просмотреть файл

@ -443,9 +443,10 @@ nsresult TextEditor::PasteTransferableAsAction(nsITransferable* aTransferable,
}
bool TextEditor::CanPaste(int32_t aClipboardType) const {
// Always enable the paste command when inside of a HTML or XHTML document.
// Always enable the paste command when inside of a HTML or XHTML document,
// but if the document is chrome, let it control it.
RefPtr<Document> doc = GetDocument();
if (doc && doc->IsHTMLOrXHTML()) {
if (doc && doc->IsHTMLOrXHTML() && !nsContentUtils::IsChromeDoc(doc)) {
return true;
}