Bug 1312260 - Part 1: Allow access to execCommand("paste") with permission r=bz

MozReview-Commit-ID: B1sfhsQWWQa

--HG--
extra : rebase_source : 533fc39c52733cc9d3f0eb7ff0558dab36f6263d
This commit is contained in:
Tomislav Jovanovic 2017-02-09 15:09:22 +01:00
Родитель 89b57b3fb1
Коммит cfdba143c5
3 изменённых файлов: 17 добавлений и 7 удалений

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

@ -2076,15 +2076,22 @@ nsContentUtils::CanCallerAccess(nsPIDOMWindowInner* aWindow)
// static
bool
nsContentUtils::CallerHasPermission(JSContext* aCx, const nsAString& aPerm)
nsContentUtils::PrincipalHasPermission(nsIPrincipal* aPrincipal, const nsAString& aPerm)
{
// Chrome gets access by default.
if (IsSystemCaller(aCx)) {
if (IsSystemPrincipal(aPrincipal)) {
return true;
}
// Otherwise, only allow if caller is an addon with the permission.
return BasePrincipal::Cast(SubjectPrincipal(aCx))->AddonHasPermission(aPerm);
return BasePrincipal::Cast(aPrincipal)->AddonHasPermission(aPerm);
}
// static
bool
nsContentUtils::CallerHasPermission(JSContext* aCx, const nsAString& aPerm)
{
return PrincipalHasPermission(SubjectPrincipal(aCx), aPerm);
}
//static
@ -6894,12 +6901,11 @@ nsContentUtils::IsRequestFullScreenAllowed(CallerType aCallerType)
bool
nsContentUtils::IsCutCopyAllowed(nsIPrincipal* aSubjectPrincipal)
{
if ((!IsCutCopyRestricted() && EventStateManager::IsHandlingUserInput()) ||
IsSystemPrincipal(aSubjectPrincipal)) {
if (!IsCutCopyRestricted() && EventStateManager::IsHandlingUserInput()) {
return true;
}
return BasePrincipal::Cast(aSubjectPrincipal)->AddonHasPermission(NS_LITERAL_STRING("clipboardWrite"));
return PrincipalHasPermission(aSubjectPrincipal, NS_LITERAL_STRING("clipboardWrite"));
}
/* static */

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

@ -503,6 +503,9 @@ public:
// aWindow can be either outer or inner window.
static bool CanCallerAccess(nsPIDOMWindowInner* aWindow);
// Check if the principal is chrome or an addon with the permission.
static bool PrincipalHasPermission(nsIPrincipal* aPrincipal, const nsAString& aPerm);
// Check if the JS caller is chrome or an addon with the permission.
static bool CallerHasPermission(JSContext* aCx, const nsAString& aPerm);

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

@ -3201,7 +3201,8 @@ nsHTMLDocument::ExecCommand(const nsAString& commandID,
}
bool restricted = commandID.LowerCaseEqualsLiteral("paste");
if (restricted && !nsContentUtils::IsSystemPrincipal(&aSubjectPrincipal)) {
if (restricted && !nsContentUtils::PrincipalHasPermission(&aSubjectPrincipal,
NS_LITERAL_STRING("clipboardRead"))) {
return false;
}