зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1335368 part 3. Stop using IsCallerChrome in nsContentUtils::IsCutCopyAllowed(). r=smaug
This commit is contained in:
Родитель
2b893326f8
Коммит
80365681f6
|
@ -6840,14 +6840,14 @@ nsContentUtils::IsRequestFullScreenAllowed()
|
|||
|
||||
/* static */
|
||||
bool
|
||||
nsContentUtils::IsCutCopyAllowed()
|
||||
nsContentUtils::IsCutCopyAllowed(nsIPrincipal* aSubjectPrincipal)
|
||||
{
|
||||
if ((!IsCutCopyRestricted() && EventStateManager::IsHandlingUserInput()) ||
|
||||
IsCallerChrome()) {
|
||||
IsSystemPrincipal(aSubjectPrincipal)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return BasePrincipal::Cast(SubjectPrincipal())->AddonHasPermission(NS_LITERAL_STRING("clipboardWrite"));
|
||||
return BasePrincipal::Cast(aSubjectPrincipal)->AddonHasPermission(NS_LITERAL_STRING("clipboardWrite"));
|
||||
}
|
||||
|
||||
/* static */
|
||||
|
|
|
@ -2013,10 +2013,10 @@ public:
|
|||
|
||||
/**
|
||||
* Returns true if calling execCommand with 'cut' or 'copy' arguments is
|
||||
* allowed in the current context. These are only allowed if the user initiated
|
||||
* them (like with a mouse-click or key press).
|
||||
* allowed for the given subject principal. These are only allowed if the user
|
||||
* initiated them (like with a mouse-click or key press).
|
||||
*/
|
||||
static bool IsCutCopyAllowed();
|
||||
static bool IsCutCopyAllowed(nsIPrincipal* aSubjectPrincipal);
|
||||
|
||||
/*
|
||||
* Returns true if the performance timing APIs are enabled.
|
||||
|
|
|
@ -2805,7 +2805,12 @@ nsHTMLDocument::EditingStateChanged()
|
|||
// restricted one.
|
||||
ErrorResult errorResult;
|
||||
Unused << ExecCommand(NS_LITERAL_STRING("insertBrOnReturn"), false,
|
||||
NS_LITERAL_STRING("false"), CallerType::NonSystem,
|
||||
NS_LITERAL_STRING("false"),
|
||||
// Principal doesn't matter here, because the
|
||||
// insertBrOnReturn command doesn't use it. Still
|
||||
// it's too bad we can't easily grab a nullprincipal
|
||||
// from somewhere without allocating one..
|
||||
*NodePrincipal(),
|
||||
errorResult);
|
||||
|
||||
if (errorResult.Failed()) {
|
||||
|
@ -3134,7 +3139,7 @@ bool
|
|||
nsHTMLDocument::ExecCommand(const nsAString& commandID,
|
||||
bool doShowUI,
|
||||
const nsAString& value,
|
||||
CallerType aCallerType,
|
||||
nsIPrincipal& aSubjectPrincipal,
|
||||
ErrorResult& rv)
|
||||
{
|
||||
// for optional parameters see dom/src/base/nsHistory.cpp: HistoryImpl::Go()
|
||||
|
@ -3164,7 +3169,7 @@ nsHTMLDocument::ExecCommand(const nsAString& commandID,
|
|||
// special case for cut & copy
|
||||
// cut & copy are allowed in non editable documents
|
||||
if (isCutCopy) {
|
||||
if (!nsContentUtils::IsCutCopyAllowed()) {
|
||||
if (!nsContentUtils::IsCutCopyAllowed(&aSubjectPrincipal)) {
|
||||
// We have rejected the event due to it not being performed in an
|
||||
// input-driven context therefore, we report the error to the console.
|
||||
nsContentUtils::ReportToConsole(nsIScriptError::warningFlag,
|
||||
|
@ -3194,7 +3199,7 @@ nsHTMLDocument::ExecCommand(const nsAString& commandID,
|
|||
}
|
||||
|
||||
bool restricted = commandID.LowerCaseEqualsLiteral("paste");
|
||||
if (restricted && aCallerType != CallerType::System) {
|
||||
if (restricted && !nsContentUtils::IsSystemPrincipal(&aSubjectPrincipal)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -3260,7 +3265,7 @@ nsHTMLDocument::ExecCommand(const nsAString& commandID,
|
|||
|
||||
bool
|
||||
nsHTMLDocument::QueryCommandEnabled(const nsAString& commandID,
|
||||
CallerType aCallerType,
|
||||
nsIPrincipal& aSubjectPrincipal,
|
||||
ErrorResult& rv)
|
||||
{
|
||||
nsAutoCString cmdToDispatch;
|
||||
|
@ -3272,12 +3277,12 @@ nsHTMLDocument::QueryCommandEnabled(const nsAString& commandID,
|
|||
bool isCutCopy = commandID.LowerCaseEqualsLiteral("cut") ||
|
||||
commandID.LowerCaseEqualsLiteral("copy");
|
||||
if (isCutCopy) {
|
||||
return nsContentUtils::IsCutCopyAllowed();
|
||||
return nsContentUtils::IsCutCopyAllowed(&aSubjectPrincipal);
|
||||
}
|
||||
|
||||
// Report false for restricted commands
|
||||
bool restricted = commandID.LowerCaseEqualsLiteral("paste");
|
||||
if (restricted && aCallerType != CallerType::System) {
|
||||
if (restricted && !nsContentUtils::IsSystemPrincipal(&aSubjectPrincipal)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -3460,6 +3465,9 @@ nsHTMLDocument::QueryCommandSupported(const nsAString& commandID,
|
|||
return false;
|
||||
}
|
||||
if (nsContentUtils::IsCutCopyRestricted()) {
|
||||
// XXXbz should we worry about correctly reporting "true" in the
|
||||
// "restricted, but we're an addon with clipboardWrite permissions" case?
|
||||
// See also nsContentUtils::IsCutCopyAllowed.
|
||||
if (commandID.LowerCaseEqualsLiteral("cut") ||
|
||||
commandID.LowerCaseEqualsLiteral("copy")) {
|
||||
return false;
|
||||
|
|
|
@ -218,10 +218,10 @@ public:
|
|||
mozilla::ErrorResult& rv);
|
||||
bool ExecCommand(const nsAString& aCommandID, bool aDoShowUI,
|
||||
const nsAString& aValue,
|
||||
mozilla::dom::CallerType aCallerType,
|
||||
nsIPrincipal& aSubjectPrincipal,
|
||||
mozilla::ErrorResult& rv);
|
||||
bool QueryCommandEnabled(const nsAString& aCommandID,
|
||||
mozilla::dom::CallerType aCallerType,
|
||||
nsIPrincipal& aSubjectPrincipal,
|
||||
mozilla::ErrorResult& rv);
|
||||
bool QueryCommandIndeterm(const nsAString& aCommandID,
|
||||
mozilla::ErrorResult& rv);
|
||||
|
|
|
@ -45,10 +45,10 @@ interface HTMLDocument : Document {
|
|||
|
||||
[SetterThrows, NeedsSubjectPrincipal]
|
||||
attribute DOMString designMode;
|
||||
[Throws, NeedsCallerType]
|
||||
[Throws, NeedsSubjectPrincipal]
|
||||
boolean execCommand(DOMString commandId, optional boolean showUI = false,
|
||||
optional DOMString value = "");
|
||||
[Throws, NeedsCallerType]
|
||||
[Throws, NeedsSubjectPrincipal]
|
||||
boolean queryCommandEnabled(DOMString commandId);
|
||||
[Throws]
|
||||
boolean queryCommandIndeterm(DOMString commandId);
|
||||
|
|
Загрузка…
Ссылка в новой задаче