Backed out changeset e14d08963786 (bug 1792138) for causing mochitest failures on browser_protocol_ask_dialog_permission.js. CLOSED TREE

This commit is contained in:
Stanca Serban 2022-11-17 14:57:36 +02:00
parent 195f45e30b
commit d7154c3939
7 changed files with 11 additions and 71 deletions

View File

@ -1128,13 +1128,6 @@ nsresult BasePrincipal::GetAddonPolicy(
return NS_OK;
}
nsresult BasePrincipal::GetContentScriptAddonPolicy(
extensions::WebExtensionPolicy** aResult) {
RefPtr<extensions::WebExtensionPolicy> policy(ContentScriptAddonPolicy());
policy.forget(aResult);
return NS_OK;
}
extensions::WebExtensionPolicy* BasePrincipal::AddonPolicy() {
if (Is<ContentPrincipal>()) {
return As<ContentPrincipal>()->AddonPolicy();

View File

@ -126,7 +126,6 @@ class BasePrincipal : public nsJSPrincipals {
bool allowIfInheritsPrincipal,
uint64_t innerWindowID) final;
NS_IMETHOD GetAddonPolicy(extensions::WebExtensionPolicy** aResult) final;
NS_IMETHOD GetContentScriptAddonPolicy(extensions::WebExtensionPolicy** aResult) final;
NS_IMETHOD GetIsNullPrincipal(bool* aResult) override;
NS_IMETHOD GetIsContentPrincipal(bool* aResult) override;
NS_IMETHOD GetIsExpandedPrincipal(bool* aResult) override;

View File

@ -446,7 +446,6 @@ interface nsIPrincipal : nsISupports
readonly attribute AString addonId;
readonly attribute WebExtensionPolicy addonPolicy;
readonly attribute WebExtensionPolicy contentScriptAddonPolicy;
/**
* Gets the id of the user context this principal is inside. If this

View File

@ -231,9 +231,6 @@ const INSTALL_AND_UPDATE_STARTUP_REASONS = new Set([
"ADDON_DOWNGRADE",
]);
const PROTOCOL_HANDLER_OPEN_PERM_KEY = "open-protocol-handler";
const PERMISSION_KEY_DELIMITER = "^";
// Returns true if the extension is owned by Mozilla (is either privileged,
// using one of the @mozilla.com/@mozilla.org protected addon id suffixes).
//
@ -569,16 +566,6 @@ var ExtensionAddonObserver = {
Services.perms.removeFromPrincipal(principal, "persistent-storage");
}
// Clear any protocol handler permissions granted to this add-on.
let permissions = Services.perms.getAllWithTypePrefix(
PROTOCOL_HANDLER_OPEN_PERM_KEY + PERMISSION_KEY_DELIMITER
);
for (let perm of permissions) {
if (perm.principal.equalsURI(baseURI)) {
Services.perms.removePermission(perm);
}
}
if (!Services.prefs.getBoolPref(LEAVE_UUID_PREF, false)) {
// Clear the entry in the UUID map
UUIDMap.remove(addon.id);

View File

@ -7,7 +7,6 @@
## $host - the hostname that is initiating the request
## $scheme - the type of link that's being opened.
## $appName - Name of the application that will be opened.
## $extension - Name of extension that initiated the request
permission-dialog-description =
Allow this site to open the { $scheme } link?
@ -18,9 +17,6 @@ permission-dialog-description-file =
permission-dialog-description-host =
Allow { $host } to open the { $scheme } link?
permission-dialog-description-extension =
Allow the extension { $extension } to open the { $scheme } link?
permission-dialog-description-app =
Allow this site to open the { $scheme } link with { $appName }?
@ -30,9 +26,6 @@ permission-dialog-description-host-app =
permission-dialog-description-file-app =
Allow this file to open the { $scheme } link with { $appName }?
permission-dialog-description-extension-app =
Allow the extension { $extension } to open the { $scheme } link with { $appName }?
## Please keep the emphasis around the hostname and scheme (ie the
## `<strong>` HTML tags). Please also keep the hostname as close to the start
## of the sentence as your language's grammar allows.
@ -43,9 +36,6 @@ permission-dialog-remember =
permission-dialog-remember-file =
Always allow this file to open <strong>{ $scheme }</strong> links
permission-dialog-remember-extension =
Always allow this extension to open <strong>{ $scheme }</strong> links
##
permission-dialog-btn-open-link =

View File

@ -293,6 +293,10 @@ class nsContentDispatchChooser {
return false;
}
if (aPrincipal.isAddonOrExpandedAddonPrincipal) {
return true;
}
let key = this._getSkipProtoDialogPermissionKey(scheme);
return (
Services.perms.testPermissionFromPrincipal(aPrincipal, key) ===
@ -392,28 +396,16 @@ class nsContentDispatchChooser {
return;
}
let principal = aPrincipal;
// If this action was triggered by an extension content script then set the
// permission on the extension's principal.
let addonPolicy = aPrincipal.contentScriptAddonPolicy;
if (addonPolicy) {
principal = Services.scriptSecurityManager.principalWithOA(
addonPolicy.extension.principal,
principal.originAttributes
);
}
let permKey = this._getSkipProtoDialogPermissionKey(aScheme);
if (aAllow) {
Services.perms.addFromPrincipal(
principal,
aPrincipal,
permKey,
Services.perms.ALLOW_ACTION,
Services.perms.EXPIRE_NEVER
);
} else {
Services.perms.removeFromPrincipal(principal, permKey);
Services.perms.removeFromPrincipal(aPrincipal, permKey);
}
}
@ -423,18 +415,11 @@ class nsContentDispatchChooser {
* @returns {boolean} - true if we can store permissions, false otherwise.
*/
_isSupportedPrincipal(aPrincipal) {
if (!aPrincipal) {
return false;
}
// If this is an add-on content script then we will be able to store
// permissions against the add-on's principal.
if (aPrincipal.contentScriptAddonPolicy) {
return true;
}
return ["http", "https", "moz-extension", "file"].some(scheme =>
aPrincipal.schemeIs(scheme)
return (
aPrincipal &&
["http", "https", "moz-extension", "file"].some(scheme =>
aPrincipal.schemeIs(scheme)
)
);
}
}

View File

@ -23,8 +23,6 @@ let dialog = {
this._handlerInfo = handler.QueryInterface(Ci.nsIHandlerInfo);
this._principal = principal?.QueryInterface(Ci.nsIPrincipal);
this._addonPolicy =
this._principal?.addonPolicy ?? this._principal?.contentScriptAddonPolicy;
this._browsingContext = browsingContext;
this._outArgs = outArgs.QueryInterface(Ci.nsIWritablePropertyBag);
this._preferredHandlerName = preferredHandlerName;
@ -84,13 +82,6 @@ let dialog = {
* the triggering principal and the preferred application handler.
*/
get l10nDescriptionId() {
if (this._addonPolicy) {
if (this._preferredHandlerName) {
return "permission-dialog-description-extension-app";
}
return "permission-dialog-description-extension";
}
if (this._principal?.schemeIs("file")) {
if (this._preferredHandlerName) {
return "permission-dialog-description-file-app";
@ -125,9 +116,6 @@ let dialog = {
return null;
}
if (this._addonPolicy) {
return "permission-dialog-remember-extension";
}
if (this._principal.schemeIs("file")) {
return "permission-dialog-remember-file";
}
@ -180,7 +168,6 @@ let dialog = {
document.l10n.setAttributes(description, this.l10nDescriptionId, {
host,
scheme,
extension: this._addonPolicy?.name,
appName: this._preferredHandlerName,
});