зеркало из https://github.com/mozilla/gecko-dev.git
Backed out 3 changesets (bug 1604222) for gv-junit perma fails. CLOSED TREE
Backed out changeset a135f610a311 (bug 1604222) Backed out changeset 34eace2047b4 (bug 1604222) Backed out changeset 15bf31fa86b9 (bug 1604222)
This commit is contained in:
Родитель
261d5d5628
Коммит
c743b59ecb
|
@ -1484,9 +1484,8 @@ package org.mozilla.geckoview {
|
|||
|
||||
public static class WebExtension.DisabledFlags {
|
||||
ctor public DisabledFlags();
|
||||
field public static final int APP = 8;
|
||||
field public static final int BLOCKLIST = 4;
|
||||
field public static final int USER = 2;
|
||||
field public static final int BLOCKLIST_DISABLED = 4;
|
||||
field public static final int USER_DISABLED = 2;
|
||||
}
|
||||
|
||||
public static class WebExtension.Flags {
|
||||
|
@ -1588,7 +1587,6 @@ package org.mozilla.geckoview {
|
|||
|
||||
public static class WebExtensionController.EnableSource {
|
||||
ctor public EnableSource();
|
||||
field public static final int APP = 2;
|
||||
field public static final int USER = 1;
|
||||
}
|
||||
|
||||
|
|
|
@ -92,35 +92,6 @@ class WebExtensionTest : BaseSessionTest() {
|
|||
color as String, equalTo(expected))
|
||||
}
|
||||
|
||||
private fun checkDisabledState(extension: WebExtension,
|
||||
userDisabled: Boolean = false, appDisabled: Boolean = false,
|
||||
blocklistDisabled: Boolean = false) {
|
||||
|
||||
val enabled = !userDisabled && !appDisabled && !blocklistDisabled
|
||||
|
||||
mainSession.reload()
|
||||
sessionRule.waitForPageStop()
|
||||
|
||||
if (!enabled) {
|
||||
// Border should be empty because the extension is disabled
|
||||
assertBodyBorderEqualTo("")
|
||||
} else {
|
||||
assertBodyBorderEqualTo("red")
|
||||
}
|
||||
|
||||
assertThat("enabled should match",
|
||||
extension.metaData!!.enabled, equalTo(enabled))
|
||||
assertThat("userDisabled should match",
|
||||
extension.metaData!!.disabledFlags and DisabledFlags.USER > 0,
|
||||
equalTo(userDisabled))
|
||||
assertThat("appDisabled should match",
|
||||
extension.metaData!!.disabledFlags and DisabledFlags.APP > 0,
|
||||
equalTo(appDisabled))
|
||||
assertThat("blocklistDisabled should match",
|
||||
extension.metaData!!.disabledFlags and DisabledFlags.BLOCKLIST > 0,
|
||||
equalTo(blocklistDisabled))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun enableDisable() {
|
||||
mainSession.loadUri("example.com")
|
||||
|
@ -139,25 +110,40 @@ class WebExtensionTest : BaseSessionTest() {
|
|||
|
||||
var borderify = sessionRule.waitForResult(
|
||||
controller.install("resource://android/assets/web_extensions/borderify.xpi"))
|
||||
checkDisabledState(borderify, userDisabled=false, appDisabled=false)
|
||||
mainSession.reload()
|
||||
sessionRule.waitForPageStop()
|
||||
|
||||
assertThat("Extension should be enabled after installing", borderify.metaData!!.enabled,
|
||||
equalTo(true))
|
||||
assertThat("Extension should be user disabled after calling disable",
|
||||
borderify.metaData!!.disabledFlags, equalTo(0))
|
||||
// Border should be ready because the extension is enabled
|
||||
assertBodyBorderEqualTo("red")
|
||||
|
||||
borderify = sessionRule.waitForResult(controller.disable(borderify, EnableSource.USER))
|
||||
checkDisabledState(borderify, userDisabled=true, appDisabled=false)
|
||||
mainSession.reload()
|
||||
sessionRule.waitForPageStop()
|
||||
|
||||
borderify = sessionRule.waitForResult(controller.disable(borderify, EnableSource.APP))
|
||||
checkDisabledState(borderify, userDisabled=true, appDisabled=true)
|
||||
|
||||
borderify = sessionRule.waitForResult(controller.enable(borderify, EnableSource.APP))
|
||||
checkDisabledState(borderify, userDisabled=true, appDisabled=false)
|
||||
assertThat("Extension should be user disabled after calling disable",
|
||||
borderify.metaData!!.enabled, equalTo(false))
|
||||
assertThat("Extension should be user disabled after calling disable",
|
||||
borderify.metaData!!.disabledFlags and DisabledFlags.USER_DISABLED > 0,
|
||||
equalTo(true))
|
||||
assertThat("Extension should not be blocklist disabled after calling disable",
|
||||
borderify.metaData!!.disabledFlags and DisabledFlags.BLOCKLIST_DISABLED > 0,
|
||||
equalTo(false))
|
||||
// Border should be empty because the extension is disabled
|
||||
assertBodyBorderEqualTo("")
|
||||
|
||||
borderify = sessionRule.waitForResult(controller.enable(borderify, EnableSource.USER))
|
||||
checkDisabledState(borderify, userDisabled=false, appDisabled=false)
|
||||
mainSession.reload()
|
||||
sessionRule.waitForPageStop()
|
||||
|
||||
borderify = sessionRule.waitForResult(controller.disable(borderify, EnableSource.APP))
|
||||
checkDisabledState(borderify, userDisabled=false, appDisabled=true)
|
||||
|
||||
borderify = sessionRule.waitForResult(controller.enable(borderify, EnableSource.APP))
|
||||
checkDisabledState(borderify, userDisabled=false, appDisabled=false)
|
||||
assertThat("Extension should be user disabled after calling disable",
|
||||
borderify.metaData!!.enabled, equalTo(true))
|
||||
assertThat("Extension should be user disabled after calling disable",
|
||||
borderify.metaData!!.disabledFlags, equalTo(0))
|
||||
assertBodyBorderEqualTo("red")
|
||||
|
||||
sessionRule.waitForResult(controller.uninstall(borderify))
|
||||
mainSession.reload()
|
||||
|
@ -185,7 +171,7 @@ class WebExtensionTest : BaseSessionTest() {
|
|||
assertEquals(extension.metaData!!.version, "1.0")
|
||||
// TODO: Bug 1601067
|
||||
// assertEquals(extension.isBuiltIn, false)
|
||||
assertEquals(extension.metaData!!.enabled, false)
|
||||
assertEquals(extension.metaData!!.enabled, true)
|
||||
assertEquals(extension.metaData!!.signedState,
|
||||
WebExtension.SignedStateFlags.SIGNED)
|
||||
assertEquals(extension.metaData!!.blocklistState,
|
||||
|
|
|
@ -1220,22 +1220,19 @@ public class WebExtension {
|
|||
|
||||
public static class DisabledFlags {
|
||||
/** The extension has been disabled by the user */
|
||||
public final static int USER = 1 << 1;
|
||||
public final static int USER_DISABLED = 1 << 1;
|
||||
|
||||
/** The extension has been disabled by the blocklist. The details of why this extension
|
||||
* was blocked can be found in {@link MetaData#blocklistState}. */
|
||||
public final static int BLOCKLIST = 1 << 2;
|
||||
public final static int BLOCKLIST_DISABLED = 1 << 2;
|
||||
|
||||
/** The extension has been disabled by the application. To enable the extension you can use
|
||||
* {@link WebExtensionController#enable} passing in
|
||||
* {@link WebExtensionController.EnableSource#APP} as <code>source</code>. */
|
||||
public final static int APP = 1 << 3;
|
||||
// TODO: Bug 1604222
|
||||
final static int APP_DISABLED = 1 << 3;
|
||||
}
|
||||
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
@IntDef(flag = true,
|
||||
value = { DisabledFlags.USER, DisabledFlags.BLOCKLIST,
|
||||
DisabledFlags.APP })
|
||||
value = { DisabledFlags.USER_DISABLED, DisabledFlags.BLOCKLIST_DISABLED })
|
||||
@interface EnabledFlags {}
|
||||
|
||||
/** Provides information about a {@link WebExtension}. */
|
||||
|
@ -1346,11 +1343,11 @@ public class WebExtension {
|
|||
* is enabled or will contain one or more flags from {@link DisabledFlags}.
|
||||
*
|
||||
* e.g. if the extension has been disabled by the user, the value in
|
||||
* {@link DisabledFlags#USER} will be equal to <code>1</code>:
|
||||
* {@link DisabledFlags#USER_DISABLED} will be equal to <code>1</code>:
|
||||
*
|
||||
* <pre><code>
|
||||
* boolean isUserDisabled = metaData.disabledFlags
|
||||
* & DisabledFlags.USER > 0;
|
||||
* & DisabledFlags.USER_DISABLED > 0;
|
||||
* </code></pre>
|
||||
*/
|
||||
public final @EnabledFlags int disabledFlags;
|
||||
|
@ -1393,7 +1390,6 @@ public class WebExtension {
|
|||
openOptionsPageInTab = bundle.getBoolean("openOptionsPageInTab");
|
||||
isRecommended = bundle.getBoolean("isRecommended");
|
||||
blocklistState = bundle.getInt("blocklistState", BlocklistStateFlags.NOT_BLOCKED);
|
||||
enabled = bundle.getBoolean("enabled", false);
|
||||
|
||||
int signedState = bundle.getInt("signedState", SignedStateFlags.UNKNOWN);
|
||||
if (signedState <= SignedStateFlags.LAST) {
|
||||
|
@ -1405,14 +1401,13 @@ public class WebExtension {
|
|||
|
||||
int disabledFlags = 0;
|
||||
final String[] disabledFlagsString = bundle.getStringArray("disabledFlags");
|
||||
this.enabled = disabledFlagsString.length == 0;
|
||||
|
||||
for (final String flag : disabledFlagsString) {
|
||||
if (flag.equals("userDisabled")) {
|
||||
disabledFlags |= DisabledFlags.USER;
|
||||
disabledFlags |= DisabledFlags.USER_DISABLED;
|
||||
} else if (flag.equals("blocklistDisabled")) {
|
||||
disabledFlags |= DisabledFlags.BLOCKLIST;
|
||||
} else if (flag.equals("appDisabled")) {
|
||||
disabledFlags |= DisabledFlags.APP;
|
||||
disabledFlags |= DisabledFlags.BLOCKLIST_DISABLED;
|
||||
} else {
|
||||
Log.e(LOGTAG, "Unrecognized disabledFlag state: " + flag);
|
||||
}
|
||||
|
|
|
@ -424,15 +424,14 @@ public class WebExtensionController {
|
|||
/** Action has been requested by the user. */
|
||||
public final static int USER = 1;
|
||||
|
||||
// TODO: Bug 1604222
|
||||
/** Action requested by the app itself, e.g. to disable an extension that is
|
||||
* not supported in this version of the app. */
|
||||
public final static int APP = 2;
|
||||
final static int APP = 2;
|
||||
|
||||
static String toString(final @EnableSources int flag) {
|
||||
if (flag == USER) {
|
||||
return "user";
|
||||
} else if (flag == APP) {
|
||||
return "app";
|
||||
} else {
|
||||
throw new IllegalArgumentException("Value provided in flags is not valid.");
|
||||
}
|
||||
|
|
|
@ -546,4 +546,4 @@ exclude: true
|
|||
[65.24]: {{javadoc_uri}}/CrashReporter.html#sendCrashReport-android.content.Context-android.os.Bundle-java.lang.String-
|
||||
[65.25]: {{javadoc_uri}}/GeckoResult.html
|
||||
|
||||
[api-version]: 34255117d007cf40a19b289285f00206f55ea792
|
||||
[api-version]: 2434a7ef025c83277375987321b4182ed75ab948
|
||||
|
|
|
@ -253,8 +253,6 @@ function exportExtension(aAddon, aPermissions, aSourceURI) {
|
|||
isRecommended,
|
||||
blocklistState,
|
||||
userDisabled,
|
||||
embedderDisabled,
|
||||
isActive,
|
||||
isBuiltin,
|
||||
id,
|
||||
} = aAddon;
|
||||
|
@ -274,9 +272,6 @@ function exportExtension(aAddon, aPermissions, aSourceURI) {
|
|||
if (blocklistState !== Ci.nsIBlocklistService.STATE_NOT_BLOCKED) {
|
||||
disabledFlags.push("blocklistDisabled");
|
||||
}
|
||||
if (embedderDisabled) {
|
||||
disabledFlags.push("appDisabled");
|
||||
}
|
||||
return {
|
||||
webExtensionId: id,
|
||||
locationURI: aSourceURI != null ? aSourceURI.spec : "",
|
||||
|
@ -285,7 +280,6 @@ function exportExtension(aAddon, aPermissions, aSourceURI) {
|
|||
permissions: aPermissions ? aPermissions.permissions : [],
|
||||
origins: aPermissions ? aPermissions.origins : [],
|
||||
description,
|
||||
enabled: isActive,
|
||||
disabledFlags,
|
||||
version,
|
||||
creatorName,
|
||||
|
@ -511,9 +505,7 @@ var GeckoViewWebExtension = {
|
|||
async enableWebExtension(aId, aSource) {
|
||||
const extension = await this.extensionById(aId);
|
||||
if (aSource === "user") {
|
||||
await extension.enable();
|
||||
} else if (aSource === "app") {
|
||||
await extension.setEmbedderDisabled(false);
|
||||
extension.enable();
|
||||
}
|
||||
return exportExtension(
|
||||
extension,
|
||||
|
@ -525,9 +517,7 @@ var GeckoViewWebExtension = {
|
|||
async disableWebExtension(aId, aSource) {
|
||||
const extension = await this.extensionById(aId);
|
||||
if (aSource === "user") {
|
||||
await extension.disable();
|
||||
} else if (aSource === "app") {
|
||||
await extension.setEmbedderDisabled(true);
|
||||
extension.disable();
|
||||
}
|
||||
return exportExtension(
|
||||
extension,
|
||||
|
@ -536,7 +526,6 @@ var GeckoViewWebExtension = {
|
|||
);
|
||||
},
|
||||
|
||||
/* eslint-disable complexity */
|
||||
async onEvent(aEvent, aData, aCallback) {
|
||||
debug`onEvent ${aEvent} ${aData}`;
|
||||
|
||||
|
@ -673,7 +662,7 @@ var GeckoViewWebExtension = {
|
|||
case "GeckoView:WebExtension:Enable": {
|
||||
try {
|
||||
const { source, webExtensionId } = aData;
|
||||
if (source !== "user" && source !== "app") {
|
||||
if (source !== "user") {
|
||||
throw new Error("Illegal source parameter");
|
||||
}
|
||||
const extension = await this.enableWebExtension(
|
||||
|
@ -691,7 +680,7 @@ var GeckoViewWebExtension = {
|
|||
case "GeckoView:WebExtension:Disable": {
|
||||
try {
|
||||
const { source, webExtensionId } = aData;
|
||||
if (source !== "user" && source !== "app") {
|
||||
if (source !== "user") {
|
||||
throw new Error("Illegal source parameter");
|
||||
}
|
||||
const extension = await this.disableWebExtension(
|
||||
|
|
|
@ -16,7 +16,6 @@ const { AppConstants } = ChromeUtils.import(
|
|||
const PREF_SIGNATURES_REQUIRED = "xpinstall.signatures.required";
|
||||
const PREF_LANGPACK_SIGNATURES = "extensions.langpacks.signatures.required";
|
||||
const PREF_ALLOW_LEGACY = "extensions.legacy.enabled";
|
||||
const PREF_IS_EMBEDDED = "extensions.isembedded";
|
||||
|
||||
var AddonSettings = {};
|
||||
|
||||
|
@ -49,18 +48,6 @@ if (AppConstants.MOZ_REQUIRE_SIGNING && !Cu.isInAutomation) {
|
|||
);
|
||||
}
|
||||
|
||||
// Whether or not we're running in GeckoView embedded in an Android app
|
||||
if (Cu.isInAutomation) {
|
||||
XPCOMUtils.defineLazyPreferenceGetter(
|
||||
AddonSettings,
|
||||
"IS_EMBEDDED",
|
||||
PREF_IS_EMBEDDED,
|
||||
false
|
||||
);
|
||||
} else {
|
||||
makeConstant("IS_EMBEDDED", AppConstants.platform === "android");
|
||||
}
|
||||
|
||||
if (AppConstants.MOZ_ALLOW_LEGACY_EXTENSIONS || Cu.isInAutomation) {
|
||||
XPCOMUtils.defineLazyPreferenceGetter(
|
||||
AddonSettings,
|
||||
|
|
|
@ -103,7 +103,6 @@ const PENDING_INSTALL_METADATA = [
|
|||
"targetApplications",
|
||||
"userDisabled",
|
||||
"softDisabled",
|
||||
"embedderDisabled",
|
||||
"existingAddonID",
|
||||
"sourceURI",
|
||||
"releaseNotesURI",
|
||||
|
@ -130,7 +129,6 @@ const PROP_JSON_FIELDS = [
|
|||
"active",
|
||||
"userDisabled",
|
||||
"appDisabled",
|
||||
"embedderDisabled",
|
||||
"pendingUninstall",
|
||||
"installDate",
|
||||
"updateDate",
|
||||
|
@ -277,7 +275,6 @@ class AddonInternal {
|
|||
this.userDisabled = false;
|
||||
this.appDisabled = false;
|
||||
this.softDisabled = false;
|
||||
this.embedderDisabled = false;
|
||||
this.blocklistState = Ci.nsIBlocklistService.STATE_NOT_BLOCKED;
|
||||
this.blocklistURL = null;
|
||||
this.sourceURI = null;
|
||||
|
@ -456,12 +453,7 @@ class AddonInternal {
|
|||
}
|
||||
|
||||
get disabled() {
|
||||
return (
|
||||
this.userDisabled ||
|
||||
this.appDisabled ||
|
||||
this.softDisabled ||
|
||||
this.embedderDisabled
|
||||
);
|
||||
return this.userDisabled || this.appDisabled || this.softDisabled;
|
||||
}
|
||||
|
||||
get isPlatformCompatible() {
|
||||
|
@ -595,10 +587,7 @@ class AddonInternal {
|
|||
}
|
||||
|
||||
if (this.inDatabase && updateDatabase) {
|
||||
XPIDatabase.updateAddonDisabledState(this, {
|
||||
userDisabled,
|
||||
softDisabled,
|
||||
});
|
||||
XPIDatabase.updateAddonDisabledState(this, userDisabled, softDisabled);
|
||||
XPIDatabase.saveChanges();
|
||||
} else {
|
||||
this.appDisabled = !XPIDatabase.isUsableAddon(this);
|
||||
|
@ -622,7 +611,7 @@ class AddonInternal {
|
|||
if (this.location.isSystem && !allowSystemAddons) {
|
||||
throw new Error(`Cannot disable system add-on ${this.id}`);
|
||||
}
|
||||
await XPIDatabase.updateAddonDisabledState(this, { userDisabled: val });
|
||||
await XPIDatabase.updateAddonDisabledState(this, val);
|
||||
} else {
|
||||
this.userDisabled = val;
|
||||
// When enabling remove the softDisabled flag
|
||||
|
@ -750,7 +739,6 @@ class AddonInternal {
|
|||
propagateDisabledState(oldAddon) {
|
||||
if (oldAddon) {
|
||||
this.userDisabled = oldAddon.userDisabled;
|
||||
this.embedderDisabled = oldAddon.embedderDisabled;
|
||||
this.softDisabled = oldAddon.softDisabled;
|
||||
this.blocklistState = oldAddon.blocklistState;
|
||||
}
|
||||
|
@ -1077,57 +1065,6 @@ AddonWrapper = class {
|
|||
return addon.softDisabled || addon.userDisabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the embedderDisabled property for this addon.
|
||||
*
|
||||
* This is intended for embedders of Gecko like GeckoView apps to control
|
||||
* which addons are usable on their app.
|
||||
*
|
||||
* @returns {boolean}
|
||||
*/
|
||||
get embedderDisabled() {
|
||||
if (!AddonSettings.IS_EMBEDDED) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return addonFor(this).embedderDisabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the embedderDisabled property for this addon.
|
||||
*
|
||||
* This is intended for embedders of Gecko like GeckoView apps to control
|
||||
* which addons are usable on their app.
|
||||
*
|
||||
* Embedders can disable addons for various reasons, e.g. the addon is not
|
||||
* compatible with their implementation of the WebExtension API.
|
||||
*
|
||||
* When an addon is embedderDisabled it will behave like it was appDisabled.
|
||||
*
|
||||
* @param {boolean} val
|
||||
* whether this addon should be embedder disabled or not.
|
||||
*/
|
||||
async setEmbedderDisabled(val) {
|
||||
if (!AddonSettings.IS_EMBEDDED) {
|
||||
throw new Error("Setting embedder disabled while not embedding.");
|
||||
}
|
||||
|
||||
let addon = addonFor(this);
|
||||
if (addon.embedderDisabled == val) {
|
||||
return val;
|
||||
}
|
||||
|
||||
if (addon.inDatabase) {
|
||||
await XPIDatabase.updateAddonDisabledState(addon, {
|
||||
embedderDisabled: val,
|
||||
});
|
||||
} else {
|
||||
addon.embedderDisabled = val;
|
||||
}
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
enable(options = {}) {
|
||||
const { allowSystemAddons = false } = options;
|
||||
return addonFor(this).setUserDisabled(false, allowSystemAddons);
|
||||
|
@ -1148,10 +1085,10 @@ AddonWrapper = class {
|
|||
// When softDisabling a theme just enable the active theme
|
||||
if (addon.type === "theme" && val && !addon.userDisabled) {
|
||||
if (addon.isWebExtension) {
|
||||
XPIDatabase.updateAddonDisabledState(addon, { softDisabled: val });
|
||||
XPIDatabase.updateAddonDisabledState(addon, undefined, val);
|
||||
}
|
||||
} else {
|
||||
XPIDatabase.updateAddonDisabledState(addon, { softDisabled: val });
|
||||
XPIDatabase.updateAddonDisabledState(addon, undefined, val);
|
||||
}
|
||||
} else if (!addon.userDisabled) {
|
||||
// Only set softDisabled if not already disabled
|
||||
|
@ -1236,10 +1173,8 @@ AddonWrapper = class {
|
|||
logger.debug(`reloading add-on ${addon.id}`);
|
||||
|
||||
if (!this.temporarilyInstalled) {
|
||||
await XPIDatabase.updateAddonDisabledState(addon, { userDisabled: true });
|
||||
await XPIDatabase.updateAddonDisabledState(addon, {
|
||||
userDisabled: false,
|
||||
});
|
||||
await XPIDatabase.updateAddonDisabledState(addon, true);
|
||||
await XPIDatabase.updateAddonDisabledState(addon, false);
|
||||
} else {
|
||||
// This function supports re-installing an existing add-on.
|
||||
await AddonManager.installTemporaryAddon(addon._sourceBundle);
|
||||
|
@ -1921,19 +1856,13 @@ this.XPIDatabase = {
|
|||
if (!aId && theme.id == DEFAULT_THEME_ID) {
|
||||
enableTheme = theme;
|
||||
} else if (theme.id != aId && !theme.pendingUninstall) {
|
||||
this.updateAddonDisabledState(theme, {
|
||||
userDisabled: true,
|
||||
becauseSelecting: true,
|
||||
});
|
||||
this.updateAddonDisabledState(theme, true, undefined, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (enableTheme) {
|
||||
await this.updateAddonDisabledState(enableTheme, {
|
||||
userDisabled: false,
|
||||
becauseSelecting: true,
|
||||
});
|
||||
await this.updateAddonDisabledState(enableTheme, false, undefined, true);
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -2459,17 +2388,13 @@ this.XPIDatabase = {
|
|||
*
|
||||
* @param {AddonInternal} aAddon
|
||||
* The AddonInternal to update
|
||||
* @param {Object} properties - Properties to set on the addon
|
||||
* @param {boolean?} [properties.userDisabled]
|
||||
* @param {boolean?} [aUserDisabled]
|
||||
* Value for the userDisabled property. If undefined the value will
|
||||
* not change
|
||||
* @param {boolean?} [properties.softDisabled]
|
||||
* @param {boolean?} [aSoftDisabled]
|
||||
* Value for the softDisabled property. If undefined the value will
|
||||
* not change. If true this will force userDisabled to be true
|
||||
* @param {boolean?} [properties.embedderDisabled]
|
||||
* Value for the embedderDisabled property. If undefined the value will
|
||||
* not change.
|
||||
* @param {boolean?} [properties.becauseSelecting]
|
||||
* @param {boolean?} [aBecauseSelecting]
|
||||
* True if we're disabling this add-on because we're selecting
|
||||
* another.
|
||||
* @returns {Promise<boolean?>}
|
||||
|
@ -2481,52 +2406,44 @@ this.XPIDatabase = {
|
|||
*/
|
||||
async updateAddonDisabledState(
|
||||
aAddon,
|
||||
{ userDisabled, softDisabled, embedderDisabled, becauseSelecting } = {}
|
||||
aUserDisabled,
|
||||
aSoftDisabled,
|
||||
aBecauseSelecting
|
||||
) {
|
||||
if (!aAddon.inDatabase) {
|
||||
throw new Error("Can only update addon states for installed addons.");
|
||||
}
|
||||
if (userDisabled !== undefined && softDisabled !== undefined) {
|
||||
if (aUserDisabled !== undefined && aSoftDisabled !== undefined) {
|
||||
throw new Error(
|
||||
"Cannot change userDisabled and softDisabled at the same time"
|
||||
);
|
||||
}
|
||||
|
||||
if (userDisabled === undefined) {
|
||||
userDisabled = aAddon.userDisabled;
|
||||
} else if (!userDisabled) {
|
||||
if (aUserDisabled === undefined) {
|
||||
aUserDisabled = aAddon.userDisabled;
|
||||
} else if (!aUserDisabled) {
|
||||
// If enabling the add-on then remove softDisabled
|
||||
softDisabled = false;
|
||||
aSoftDisabled = false;
|
||||
}
|
||||
|
||||
// If not changing softDisabled or the add-on is already userDisabled then
|
||||
// use the existing value for softDisabled
|
||||
if (softDisabled === undefined || userDisabled) {
|
||||
softDisabled = aAddon.softDisabled;
|
||||
}
|
||||
|
||||
if (!AddonSettings.IS_EMBEDDED) {
|
||||
// If embedderDisabled was accidentally set somehow, this will revert it
|
||||
// back to false.
|
||||
embedderDisabled = false;
|
||||
} else if (embedderDisabled === undefined) {
|
||||
embedderDisabled = aAddon.embedderDisabled;
|
||||
if (aSoftDisabled === undefined || aUserDisabled) {
|
||||
aSoftDisabled = aAddon.softDisabled;
|
||||
}
|
||||
|
||||
let appDisabled = !this.isUsableAddon(aAddon);
|
||||
// No change means nothing to do here
|
||||
if (
|
||||
aAddon.userDisabled == userDisabled &&
|
||||
aAddon.userDisabled == aUserDisabled &&
|
||||
aAddon.appDisabled == appDisabled &&
|
||||
aAddon.softDisabled == softDisabled &&
|
||||
aAddon.embedderDisabled == embedderDisabled
|
||||
aAddon.softDisabled == aSoftDisabled
|
||||
) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
let wasDisabled = aAddon.disabled;
|
||||
let isDisabled =
|
||||
userDisabled || softDisabled || appDisabled || embedderDisabled;
|
||||
let isDisabled = aUserDisabled || aSoftDisabled || appDisabled;
|
||||
|
||||
// If appDisabled changes but addon.disabled doesn't,
|
||||
// no onDisabling/onEnabling is sent - so send a onPropertyChanged.
|
||||
|
@ -2534,10 +2451,9 @@ this.XPIDatabase = {
|
|||
|
||||
// Update the properties in the database.
|
||||
this.setAddonProperties(aAddon, {
|
||||
userDisabled,
|
||||
userDisabled: aUserDisabled,
|
||||
appDisabled,
|
||||
softDisabled,
|
||||
embedderDisabled,
|
||||
softDisabled: aSoftDisabled,
|
||||
});
|
||||
|
||||
let wrapper = aAddon.wrapper;
|
||||
|
@ -2586,7 +2502,7 @@ this.XPIDatabase = {
|
|||
if (!isDisabled) {
|
||||
AddonManagerPrivate.notifyAddonChanged(aAddon.id, aAddon.type);
|
||||
this.updateXPIStates(aAddon);
|
||||
} else if (isDisabled && !becauseSelecting) {
|
||||
} else if (isDisabled && !aBecauseSelecting) {
|
||||
AddonManagerPrivate.notifyAddonChanged(null, "theme");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1725,9 +1725,7 @@ class AddonInstall {
|
|||
this.existingAddon.userDisabled &&
|
||||
!this.existingAddon.pendingUninstall
|
||||
) {
|
||||
await XPIDatabase.updateAddonDisabledState(this.existingAddon, {
|
||||
userDisabled: false,
|
||||
});
|
||||
await XPIDatabase.updateAddonDisabledState(this.existingAddon, false);
|
||||
this.state = AddonManager.STATE_INSTALLED;
|
||||
this._callInstallListeners("onInstallEnded", this.existingAddon.wrapper);
|
||||
return;
|
||||
|
|
|
@ -1,128 +0,0 @@
|
|||
/* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/
|
||||
*/
|
||||
|
||||
const ADDON_ID = "embedder-disabled@tests.mozilla.org";
|
||||
const PREF_IS_EMBEDDED = "extensions.isembedded";
|
||||
|
||||
createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "49");
|
||||
|
||||
// Setting PREF_DISABLE_SECURITY tells the policy engine that we are in testing
|
||||
// mode and enables restarting the policy engine without restarting the browser.
|
||||
registerCleanupFunction(() => {
|
||||
Services.prefs.clearUserPref(PREF_DISABLE_SECURITY);
|
||||
Services.prefs.clearUserPref(PREF_IS_EMBEDDED);
|
||||
});
|
||||
|
||||
async function installExtension() {
|
||||
return promiseInstallWebExtension({
|
||||
manifest: {
|
||||
applications: { gecko: { id: ADDON_ID } },
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
add_task(async function test_setup() {
|
||||
Services.prefs.setBoolPref(PREF_DISABLE_SECURITY, true);
|
||||
await promiseStartupManager();
|
||||
});
|
||||
|
||||
add_task(async function embedder_disabled_while_not_embedding() {
|
||||
const addon = await installExtension();
|
||||
let exceptionThrown = false;
|
||||
try {
|
||||
await addon.setEmbedderDisabled(true);
|
||||
} catch (exception) {
|
||||
exceptionThrown = true;
|
||||
}
|
||||
|
||||
equal(exceptionThrown, true);
|
||||
|
||||
// Verify that the addon is not affected
|
||||
equal(addon.isActive, true);
|
||||
equal(addon.embedderDisabled, undefined);
|
||||
|
||||
await addon.uninstall();
|
||||
});
|
||||
|
||||
add_task(async function unset_embedder_disabled_while_not_embedding() {
|
||||
Services.prefs.setBoolPref(PREF_IS_EMBEDDED, true);
|
||||
|
||||
const addon = await installExtension();
|
||||
await addon.setEmbedderDisabled(true);
|
||||
|
||||
// Verify the addon is not active anymore
|
||||
equal(addon.isActive, false);
|
||||
equal(addon.embedderDisabled, true);
|
||||
|
||||
Services.prefs.setBoolPref(PREF_IS_EMBEDDED, false);
|
||||
|
||||
// Verify that embedder disabled cannot be read if not embedding
|
||||
equal(addon.embedderDisabled, undefined);
|
||||
|
||||
await addon.disable();
|
||||
await addon.enable();
|
||||
|
||||
// Verify that embedder disabled can be removed
|
||||
equal(addon.isActive, true);
|
||||
equal(addon.embedderDisabled, undefined);
|
||||
|
||||
await addon.uninstall();
|
||||
});
|
||||
|
||||
add_task(async function embedder_disabled_while_embedding() {
|
||||
Services.prefs.setBoolPref(PREF_IS_EMBEDDED, true);
|
||||
|
||||
const addon = await installExtension();
|
||||
await addon.setEmbedderDisabled(true);
|
||||
|
||||
// Verify the addon is not active anymore
|
||||
equal(addon.embedderDisabled, true);
|
||||
equal(addon.isActive, false);
|
||||
|
||||
await addon.setEmbedderDisabled(false);
|
||||
|
||||
// Verify that the addon is now enabled again
|
||||
equal(addon.isActive, true);
|
||||
equal(addon.embedderDisabled, false);
|
||||
await addon.uninstall();
|
||||
|
||||
Services.prefs.setBoolPref(PREF_IS_EMBEDDED, false);
|
||||
});
|
||||
|
||||
add_task(async function embedder_disabled_while_user_disabled() {
|
||||
Services.prefs.setBoolPref(PREF_IS_EMBEDDED, true);
|
||||
|
||||
const addon = await installExtension();
|
||||
await addon.disable();
|
||||
|
||||
// Verify that the addon is userDisabled
|
||||
equal(addon.isActive, false);
|
||||
equal(addon.userDisabled, true);
|
||||
equal(addon.embedderDisabled, false);
|
||||
|
||||
await addon.setEmbedderDisabled(true);
|
||||
|
||||
// Verify that the addon can be userDisabled and embedderDisabled
|
||||
equal(addon.isActive, false);
|
||||
equal(addon.userDisabled, true);
|
||||
equal(addon.embedderDisabled, true);
|
||||
|
||||
await addon.setEmbedderDisabled(false);
|
||||
|
||||
// Verify that unsetting embedderDisabled doesn't enable the addon
|
||||
equal(addon.isActive, false);
|
||||
equal(addon.userDisabled, true);
|
||||
equal(addon.embedderDisabled, false);
|
||||
|
||||
await addon.enable();
|
||||
|
||||
// Verify that the addon can be enabled after unsetting userDisabled
|
||||
equal(addon.isActive, true);
|
||||
equal(addon.userDisabled, false);
|
||||
equal(addon.embedderDisabled, false);
|
||||
|
||||
await addon.uninstall();
|
||||
|
||||
Services.prefs.setBoolPref(PREF_IS_EMBEDDED, false);
|
||||
});
|
|
@ -35,7 +35,6 @@ tags = webextensions
|
|||
[test_duplicateplugins.js]
|
||||
run-if = appname == "firefox"
|
||||
reason = PluginProvider.jsm is only shipped with desktop Firefox
|
||||
[test_embedderDisabled.js]
|
||||
[test_error.js]
|
||||
# Bug 1508482
|
||||
skip-if = os == "win"
|
||||
|
|
Загрузка…
Ссылка в новой задаче