Bug 1560048 - Expose WebExtension baseURL to embedders. r=snorp,esawin

Differential Revision: https://phabricator.services.mozilla.com/D65399

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Agi Sferro 2020-03-07 00:59:46 +00:00
Родитель 18fa7b220b
Коммит f6f2f88fa3
5 изменённых файлов: 25 добавлений и 3 удалений

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

@ -1565,6 +1565,7 @@ package org.mozilla.geckoview {
public class WebExtension.MetaData {
ctor protected MetaData();
field @NonNull public final String baseUrl;
field public final int blocklistState;
field @Nullable public final String creatorName;
field @Nullable public final String creatorUrl;

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

@ -238,8 +238,10 @@ class WebExtensionTest : BaseSessionTest() {
val dummy = sessionRule.waitForResult(
controller.install("resource://android/assets/web_extensions/dummy.xpi"))
assertTrue((dummy.metaData!!.optionsPageUrl ?: "").matches("^moz-extension://.*/options.html$".toRegex()));
assertEquals(dummy.metaData!!.openOptionsPageInTab, true);
val metadata = dummy.metaData!!
assertTrue((metadata.optionsPageUrl ?: "").matches("^moz-extension://[0-9a-f\\-]*/options.html$".toRegex()));
assertEquals(metadata.openOptionsPageInTab, true);
assertTrue(metadata.baseUrl.matches("^moz-extension://[0-9a-f\\-]*/$".toRegex()))
sessionRule.waitForResult(controller.uninstall(dummy))
}

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

@ -1777,6 +1777,12 @@ public class WebExtension {
*/
public final @EnabledFlags int disabledFlags;
/**
* Root URL for this extension's pages. Can be used to determine if a given URL
* belongs to this extension.
*/
public final @NonNull String baseUrl;
/**
* Whether this extension is enabled or not.
*/
@ -1800,6 +1806,7 @@ public class WebExtension {
signedState = SignedStateFlags.UNKNOWN;
disabledFlags = 0;
enabled = true;
baseUrl = null;
}
/* package */ MetaData(final GeckoBundle bundle) {
@ -1816,6 +1823,7 @@ public class WebExtension {
isRecommended = bundle.getBoolean("isRecommended");
blocklistState = bundle.getInt("blocklistState", BlocklistStateFlags.NOT_BLOCKED);
enabled = bundle.getBoolean("enabled", false);
baseUrl = bundle.getString("baseURL");
int signedState = bundle.getInt("signedState", SignedStateFlags.UNKNOWN);
if (signedState <= SignedStateFlags.LAST) {

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

@ -53,6 +53,9 @@ exclude: true
- Added [`GeckoResult#cancel()`][75.22], [`GeckoResult#setCancellationDelegate()`][75.22],
and [`GeckoResult.CancellationDelegate`][75.23]. This adds the optional ability to cancel
an operation behind a pending `GeckoResult`.
- Added [`baseUrl`][75.24] to [`WebExtension.MetaData`][75.25] to expose the
base URL for all WebExtension pages for a given extension.
([bug 1560048]({{bugzilla}}1560048))
[75.1]: {{javadoc_uri}}/GeckoRuntimeSettings.Builder.html#useMultiprocess-boolean-
[75.2]: {{javadoc_uri}}/WebExtensionController.DebuggerDelegate.html#onExtensionListUpdated--
@ -77,6 +80,8 @@ exclude: true
[75.21]: {{javadoc_uri}}/GeckoResult.html#cancel--
[75.22]: {{javadoc_uri}}/GeckoResult.html#setCancellationDelegate-CancellationDelegate-
[75.23]: {{javadoc_uri}}/GeckoResult.CancellationDelegate.html
[75.24]: {{javadoc_uri}}/WebExtension.MetaData.html#baseUrl
[75.25]: {{javadoc_uri}}/WebExtension.MetaData.html
## v74
- Added [`WebExtensionController.enable`][74.1] and [`disable`][74.2] to
@ -640,4 +645,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]: a27452c94c0eafb6ace5de104476989671ca5250
[api-version]: 9a5f829b35bacd2c1f1a6f94c394ffb93b1b0513

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

@ -267,6 +267,11 @@ function exportExtension(aAddon, aPermissions, aSourceURI) {
if (embedderDisabled) {
disabledFlags.push("appDisabled");
}
let baseURL = "";
const policy = WebExtensionPolicy.getByID(id);
if (policy) {
baseURL = policy.getURL();
}
return {
webExtensionId: id,
locationURI: aSourceURI != null ? aSourceURI.spec : "",
@ -288,6 +293,7 @@ function exportExtension(aAddon, aPermissions, aSourceURI) {
blocklistState,
signedState,
icons,
baseURL,
},
};
}