Bug 1161721 - Return false from document.queryCommandSupported for restricted commands. r=ehsan

This commit is contained in:
Michael Layzell 2015-05-21 06:37:00 -04:00
parent 6a35b44e1b
commit c748c62a51
4 changed files with 44 additions and 0 deletions

View File

@ -3534,6 +3534,14 @@ nsHTMLDocument::QueryCommandSupported(const nsAString & commandID,
bool
nsHTMLDocument::QueryCommandSupported(const nsAString& commandID)
{
// Gecko technically supports the paste command, but non-privileged content
// will be unable to call it. For that reason, we report that paste is
// not supported to this non-privileged content (as it effectively is).
bool restricted = commandID.LowerCaseEqualsLiteral("paste");
if (restricted && !nsContentUtils::IsCallerChrome()) {
return false;
}
// commandID is supported if it can be converted to a Midas command
nsAutoCString cmdToDispatch;
return ConvertToMidasInternalCommand(commandID, cmdToDispatch);

View File

@ -100,3 +100,4 @@ skip-if = (buildapp == 'b2g' && toolkit != 'gonk') #Bug 931116, b2g desktop spec
skip-if = (buildapp == 'b2g' && toolkit != 'gonk') #Bug 931116, b2g desktop specific, initial triage
[test_navigation_timing.html]
skip-if = buildapp == 'b2g' || buildapp == 'mulet'
[test_bug1161721.html]

View File

@ -0,0 +1,32 @@
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=1161721
-->
<head>
<title>Test for Bug 1161721</title>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
<script type="text/javascript" src="/tests/SimpleTest/WindowSnapshot.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1161721">Mozilla Bug 1161721</a>
<p id="display"></p>
<div id="content">
</div>
<pre id="test">
<script type="application/javascript">
ok(!document.queryCommandSupported("paste"), "Paste isn't supported in non-privilged JavaScript");
ok(document.queryCommandSupported("copy"), "Copy is supported in non-privilged JavaScript");
ok(document.queryCommandSupported("cut"), "Cut is supported in non-privilged JavaScript");
ok(SpecialPowers.wrap(document).queryCommandSupported("paste"), "Paste is supported in privilged JavaScript");
ok(SpecialPowers.wrap(document).queryCommandSupported("copy"), "Copy is supported in privilged JavaScript");
ok(SpecialPowers.wrap(document).queryCommandSupported("cut"), "Cut is supported in privilged JavaScript");
</script>
</pre>
</body>
</html>

View File

@ -289,6 +289,9 @@ const knownFailures = {
"Q-Proposed-UNBOOKMARK_TEXT-1-dM": true,
"Q-Proposed-UNBOOKMARK_TEXT-1-body": true,
"Q-Proposed-UNBOOKMARK_TEXT-1-div": true,
"Q-Proposed-PASTE_TEXT-1-dM": true,
"Q-Proposed-PASTE_TEXT-1-body": true,
"Q-Proposed-PASTE_TEXT-1-div": true,
"QE-Proposed-UNSELECT_TEXT-1-dM": true,
"QE-Proposed-UNSELECT_TEXT-1-body": true,
"QE-Proposed-UNSELECT_TEXT-1-div": true,