зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1604222 - Implement disable(APP_DISABLED) for WebExtension. r=snorp
Differential Revision: https://phabricator.services.mozilla.com/D59223 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
96a8360027
Коммит
0d072a9009
|
@ -1484,8 +1484,9 @@ package org.mozilla.geckoview {
|
|||
|
||||
public static class WebExtension.DisabledFlags {
|
||||
ctor public DisabledFlags();
|
||||
field public static final int BLOCKLIST_DISABLED = 4;
|
||||
field public static final int USER_DISABLED = 2;
|
||||
field public static final int APP = 8;
|
||||
field public static final int BLOCKLIST = 4;
|
||||
field public static final int USER = 2;
|
||||
}
|
||||
|
||||
public static class WebExtension.Flags {
|
||||
|
@ -1587,6 +1588,7 @@ 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,6 +92,35 @@ 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")
|
||||
|
@ -110,40 +139,25 @@ class WebExtensionTest : BaseSessionTest() {
|
|||
|
||||
var borderify = sessionRule.waitForResult(
|
||||
controller.install("resource://android/assets/web_extensions/borderify.xpi"))
|
||||
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")
|
||||
checkDisabledState(borderify, userDisabled=false, appDisabled=false)
|
||||
|
||||
borderify = sessionRule.waitForResult(controller.disable(borderify, EnableSource.USER))
|
||||
mainSession.reload()
|
||||
sessionRule.waitForPageStop()
|
||||
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.disable(borderify, EnableSource.APP))
|
||||
checkDisabledState(borderify, userDisabled=true, appDisabled=true)
|
||||
|
||||
borderify = sessionRule.waitForResult(controller.enable(borderify, EnableSource.APP))
|
||||
checkDisabledState(borderify, userDisabled=true, appDisabled=false)
|
||||
|
||||
borderify = sessionRule.waitForResult(controller.enable(borderify, EnableSource.USER))
|
||||
mainSession.reload()
|
||||
sessionRule.waitForPageStop()
|
||||
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")
|
||||
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)
|
||||
|
||||
sessionRule.waitForResult(controller.uninstall(borderify))
|
||||
mainSession.reload()
|
||||
|
@ -171,7 +185,7 @@ class WebExtensionTest : BaseSessionTest() {
|
|||
assertEquals(extension.metaData!!.version, "1.0")
|
||||
// TODO: Bug 1601067
|
||||
// assertEquals(extension.isBuiltIn, false)
|
||||
assertEquals(extension.metaData!!.enabled, true)
|
||||
assertEquals(extension.metaData!!.enabled, false)
|
||||
assertEquals(extension.metaData!!.signedState,
|
||||
WebExtension.SignedStateFlags.SIGNED)
|
||||
assertEquals(extension.metaData!!.blocklistState,
|
||||
|
|
|
@ -1220,19 +1220,22 @@ public class WebExtension {
|
|||
|
||||
public static class DisabledFlags {
|
||||
/** The extension has been disabled by the user */
|
||||
public final static int USER_DISABLED = 1 << 1;
|
||||
public final static int USER = 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_DISABLED = 1 << 2;
|
||||
public final static int BLOCKLIST = 1 << 2;
|
||||
|
||||
// TODO: Bug 1604222
|
||||
final static int APP_DISABLED = 1 << 3;
|
||||
/** 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;
|
||||
}
|
||||
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
@IntDef(flag = true,
|
||||
value = { DisabledFlags.USER_DISABLED, DisabledFlags.BLOCKLIST_DISABLED })
|
||||
value = { DisabledFlags.USER, DisabledFlags.BLOCKLIST,
|
||||
DisabledFlags.APP })
|
||||
@interface EnabledFlags {}
|
||||
|
||||
/** Provides information about a {@link WebExtension}. */
|
||||
|
@ -1343,11 +1346,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_DISABLED} will be equal to <code>1</code>:
|
||||
* {@link DisabledFlags#USER} will be equal to <code>1</code>:
|
||||
*
|
||||
* <pre><code>
|
||||
* boolean isUserDisabled = metaData.disabledFlags
|
||||
* & DisabledFlags.USER_DISABLED > 0;
|
||||
* & DisabledFlags.USER > 0;
|
||||
* </code></pre>
|
||||
*/
|
||||
public final @EnabledFlags int disabledFlags;
|
||||
|
@ -1390,6 +1393,7 @@ 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) {
|
||||
|
@ -1401,13 +1405,14 @@ 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_DISABLED;
|
||||
disabledFlags |= DisabledFlags.USER;
|
||||
} else if (flag.equals("blocklistDisabled")) {
|
||||
disabledFlags |= DisabledFlags.BLOCKLIST_DISABLED;
|
||||
disabledFlags |= DisabledFlags.BLOCKLIST;
|
||||
} else if (flag.equals("appDisabled")) {
|
||||
disabledFlags |= DisabledFlags.APP;
|
||||
} else {
|
||||
Log.e(LOGTAG, "Unrecognized disabledFlag state: " + flag);
|
||||
}
|
||||
|
|
|
@ -424,14 +424,15 @@ 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. */
|
||||
final static int APP = 2;
|
||||
public 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]: 2434a7ef025c83277375987321b4182ed75ab948
|
||||
[api-version]: 34255117d007cf40a19b289285f00206f55ea792
|
||||
|
|
|
@ -253,6 +253,8 @@ function exportExtension(aAddon, aPermissions, aSourceURI) {
|
|||
isRecommended,
|
||||
blocklistState,
|
||||
userDisabled,
|
||||
embedderDisabled,
|
||||
isActive,
|
||||
isBuiltin,
|
||||
id,
|
||||
} = aAddon;
|
||||
|
@ -272,6 +274,9 @@ 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 : "",
|
||||
|
@ -280,6 +285,7 @@ function exportExtension(aAddon, aPermissions, aSourceURI) {
|
|||
permissions: aPermissions ? aPermissions.permissions : [],
|
||||
origins: aPermissions ? aPermissions.origins : [],
|
||||
description,
|
||||
enabled: isActive,
|
||||
disabledFlags,
|
||||
version,
|
||||
creatorName,
|
||||
|
@ -505,7 +511,9 @@ var GeckoViewWebExtension = {
|
|||
async enableWebExtension(aId, aSource) {
|
||||
const extension = await this.extensionById(aId);
|
||||
if (aSource === "user") {
|
||||
extension.enable();
|
||||
await extension.enable();
|
||||
} else if (aSource === "app") {
|
||||
await extension.setEmbedderDisabled(false);
|
||||
}
|
||||
return exportExtension(
|
||||
extension,
|
||||
|
@ -517,7 +525,9 @@ var GeckoViewWebExtension = {
|
|||
async disableWebExtension(aId, aSource) {
|
||||
const extension = await this.extensionById(aId);
|
||||
if (aSource === "user") {
|
||||
extension.disable();
|
||||
await extension.disable();
|
||||
} else if (aSource === "app") {
|
||||
await extension.setEmbedderDisabled(true);
|
||||
}
|
||||
return exportExtension(
|
||||
extension,
|
||||
|
@ -526,6 +536,7 @@ var GeckoViewWebExtension = {
|
|||
);
|
||||
},
|
||||
|
||||
/* eslint-disable complexity */
|
||||
async onEvent(aEvent, aData, aCallback) {
|
||||
debug`onEvent ${aEvent} ${aData}`;
|
||||
|
||||
|
@ -662,7 +673,7 @@ var GeckoViewWebExtension = {
|
|||
case "GeckoView:WebExtension:Enable": {
|
||||
try {
|
||||
const { source, webExtensionId } = aData;
|
||||
if (source !== "user") {
|
||||
if (source !== "user" && source !== "app") {
|
||||
throw new Error("Illegal source parameter");
|
||||
}
|
||||
const extension = await this.enableWebExtension(
|
||||
|
@ -680,7 +691,7 @@ var GeckoViewWebExtension = {
|
|||
case "GeckoView:WebExtension:Disable": {
|
||||
try {
|
||||
const { source, webExtensionId } = aData;
|
||||
if (source !== "user") {
|
||||
if (source !== "user" && source !== "app") {
|
||||
throw new Error("Illegal source parameter");
|
||||
}
|
||||
const extension = await this.disableWebExtension(
|
||||
|
|
Загрузка…
Ссылка в новой задаче