Bug 1601067 - Implement installBuiltIn. r=mixedpuppy,owlish,snorp

Differential Revision: https://phabricator.services.mozilla.com/D72978
This commit is contained in:
Agi Sferro 2020-05-05 22:19:26 +00:00
Родитель b86a9bfbf5
Коммит 859bdae8a8
5 изменённых файлов: 79 добавлений и 7 удалений

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

@ -1613,6 +1613,7 @@ package org.mozilla.geckoview {
method @UiThread @Nullable public WebExtensionController.PromptDelegate getPromptDelegate();
method @UiThread @Nullable @Deprecated public WebExtensionController.TabDelegate getTabDelegate();
method @NonNull @AnyThread public GeckoResult<WebExtension> install(@NonNull String);
method @NonNull @AnyThread public GeckoResult<WebExtension> installBuiltIn(@NonNull String);
method @AnyThread @NonNull public GeckoResult<List<WebExtension>> list();
method @NonNull @AnyThread public GeckoResult<WebExtension> setAllowedInPrivateBrowsing(@NonNull WebExtension, boolean);
method @UiThread public void setDebuggerDelegate(@NonNull WebExtensionController.DebuggerDelegate);

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

@ -590,8 +590,31 @@ public class WebExtensionController {
});
}
// TODO: Bug 1601067 make public
GeckoResult<WebExtension> installBuiltIn(final String uri) {
/**
* Install a built-in extension.
*
* Built-in extensions have access to native messaging, don't need to be
* signed and are installed from a folder in the APK instead of a .xpi
* bundle.
*
* Example: <p><code>
* controller.installBuiltIn("resource://android/assets/example/");
* </code></p>
*
* Will install the built-in extension located at
* <code>/assets/example/</code> in the app's APK.
*
* @param uri Folder where the extension is located. To ensure this folder
* is inside the APK, only <code>resource://android</code> URIs
* are allowed.
*
* @see WebExtension.MessageDelegate
* @return A {@link GeckoResult} that completes with the extension once
* it's installed.
*/
@NonNull
@AnyThread
public GeckoResult<WebExtension> installBuiltIn(final @NonNull String uri) {
WebExtensionInstallResult result = new WebExtensionInstallResult();
final GeckoBundle bundle = new GeckoBundle(2);
bundle.putString("locationUri", uri);

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

@ -13,6 +13,13 @@ exclude: true
⚠️ breaking change
## v78
- Added [`WebExtensionController.installBuiltIn`][78.1] that allows installing an
extension that is bundled with the APK. This method is meant as a replacement
for [`GeckoRuntime.registerWebExtension`][67.15].
[78.1]: {{javadoc_uri}}/WebExtensionController.html#installBuiltIn-java.lang.String-
## v77
- Added [`GeckoRuntime.appendAppNotesToCrashReport`][77.1] For adding app notes to the crash report.
([bug 1626979]({{bugzilla}}1626979))
@ -675,4 +682,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]: 562c75192093098207d596f83a159dcb9df2d3e6
[api-version]: 7332ffcb19b3367e8ac43466f7aae13094fbb1fe

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

@ -652,6 +652,12 @@ var GeckoViewWebExtension = {
return scope.extension;
},
async installBuiltIn(aUri) {
const addon = await AddonManager.installBuiltinAddon(aUri.spec);
const exported = await exportExtension(addon, addon.userPermissions, aUri);
return { extension: exported };
},
async installWebExtension(aInstallId, aUri) {
const install = await AddonManager.getInstallForURL(aUri.spec, {
telemetryInfo: {
@ -945,8 +951,41 @@ var GeckoViewWebExtension = {
}
case "GeckoView:WebExtension:InstallBuiltIn": {
// TODO
aCallback.onError(`Not implemented`);
const { locationUri } = aData;
let uri;
try {
uri = Services.io.newURI(locationUri);
} catch (ex) {
aCallback.onError(
`Could not parse uri: ${locationUri}. Error: ${ex}`
);
return;
}
if (uri.scheme !== "resource" || uri.host !== "android") {
aCallback.onError(`Only resource://android/... URIs are allowed.`);
return;
}
if (uri.fileName !== "") {
aCallback.onError(
`This URI does not point to a folder. Note: folders URIs must end with a "/".`
);
return;
}
try {
const result = await this.installBuiltIn(uri);
if (result.extension) {
aCallback.onSuccess(result);
} else {
aCallback.onError(result);
}
} catch (ex) {
debug`Install exception error ${ex}`;
aCallback.onError(`Unexpected error: ${ex}`);
}
break;
}

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

@ -4262,8 +4262,9 @@ var XPIInstall = {
*
* @param {string} base
* A string containing the base URL. Must be a resource: URL.
* @returns {Promise}
* A Promise that resolves when the addon is installed.
* @returns {Promise<Addon>}
* A Promise that resolves to an Addon object when the addon is
* installed.
*/
async installBuiltinAddon(base) {
if (lastLightweightTheme === null) {
@ -4309,6 +4310,7 @@ var XPIInstall = {
}
}
await this._activateAddon(addon);
return addon.wrapper;
},
/**