Class WebExtensionController
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceThis delegate will be called whenever the state of an extension has changed.static interfaceDelegate for receiving debugger-related WebExtension events.static classContains the possible values for thesourceparameter inenable(org.mozilla.geckoview.WebExtension, int)anddisable(org.mozilla.geckoview.WebExtension, int).static @interfaceDefines the possible sources that can enable or disable a WebExtension.static interfaceThis delegate is used to notify of extension process state changes.static @interfaceThe method used by the embedder to install theWebExtension.static interfaceThis delegate will be called whenever an extension is about to be installed or it needs new permissions, e.g during an update or because it calledpermissions.request -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringIndicates theWebExtensionwas installed from a file.static final StringIndicates theWebExtensionwas installed using from the embedder's add-ons manager.static final StringIndicates theWebExtensionwas installed from the embedder's onboarding feature. -
Method Summary
Modifier and TypeMethodDescriptionaddOptionalPermissions(String extensionId, String[] permissions, String[] origins, String[] dataCollectionPermissions) Add the provided permissions to theWebExtensionwith the given id.createDownload(int id) Creates a new Download object with the specified ID for tracking WebExtension downloads.disable(WebExtension extension, int source) Disable an extension that is enabled.voidDisable extension process spawning.enable(WebExtension extension, int source) Enable an extension that has been disabled.voidEnable extension process spawning.ensureBuiltIn(String uri, String id) Ensure that a built-in extension is installed.Install an extension.Install an extension.installBuiltIn(String uri) Install a built-in extension.list()List installed extensions for thisGeckoRuntime.removeOptionalPermissions(String extensionId, String[] permissions, String[] origins, String[] dataCollectionPermissions) Remove the provided permissions from theWebExtensionwith the given id.voidSet theWebExtensionController.AddonManagerDelegatefor this instance.setAllowedInPrivateBrowsing(WebExtension extension, boolean allowed) Set whether an extension should be allowed to run in private browsing or not.voidSet theWebExtensionController.DebuggerDelegatefor this instance.voidSet theWebExtensionController.ExtensionProcessDelegatefor this instance.voidSet theWebExtensionController.PromptDelegatefor this instance.voidsetTabActive(GeckoSession session, boolean active) Notifies extensions about a active tab change over the `tabs.onActivated` event.uninstall(WebExtension extension) Uninstall an extension.update(WebExtension extension) Update a web extension.
-
Field Details
-
INSTALLATION_METHOD_MANAGER
Indicates theWebExtensionwas installed using from the embedder's add-ons manager.- See Also:
-
INSTALLATION_METHOD_FROM_FILE
Indicates theWebExtensionwas installed from a file.- See Also:
-
INSTALLATION_METHOD_ONBOARDING
Indicates theWebExtensionwas installed from the embedder's onboarding feature.- See Also:
-
-
Method Details
-
getPromptDelegate
- Returns:
- the current
WebExtensionController.PromptDelegateinstance. - See Also:
-
setPromptDelegate
Set theWebExtensionController.PromptDelegatefor this instance. This delegate will be used to be notified whenever an extension is being installed or needs new permissions.- Parameters:
delegate- the delegate instance.- See Also:
-
setDebuggerDelegate
@UiThread public void setDebuggerDelegate(@NonNull WebExtensionController.DebuggerDelegate delegate) Set theWebExtensionController.DebuggerDelegatefor this instance. This delegate will receive updates about extension changes using developer tools.- Parameters:
delegate- the Delegate instance
-
setAddonManagerDelegate
@UiThread public void setAddonManagerDelegate(@Nullable WebExtensionController.AddonManagerDelegate delegate) Set theWebExtensionController.AddonManagerDelegatefor this instance. This delegate will be used to be notified whenever the state of an extension has changed.- Parameters:
delegate- the delegate instance- See Also:
-
setExtensionProcessDelegate
@UiThread public void setExtensionProcessDelegate(@Nullable WebExtensionController.ExtensionProcessDelegate delegate) Set theWebExtensionController.ExtensionProcessDelegatefor this instance. This delegate will be used to notify when the state of the extension process has changed.- Parameters:
delegate- the extension process delegate- See Also:
-
enableExtensionProcessSpawning
@AnyThread public void enableExtensionProcessSpawning()Enable extension process spawning.Extension process spawning can be disabled when the extension process has been killed or crashed beyond the threshold set for Gecko. This method can be called to reset the threshold count and allow the spawning again. If the threshold is reached again,
WebExtensionController.ExtensionProcessDelegate.onDisabledProcessSpawning()will still be called. -
disableExtensionProcessSpawning
@AnyThread public void disableExtensionProcessSpawning()Disable extension process spawning.Extension process spawning can be re-enabled with
enableExtensionProcessSpawning(). This method does the opposite and stops the extension process. This method can be called when we no longer want to run extensions for the rest of the session. -
install
@NonNull @AnyThread public GeckoResult<WebExtension> install(@NonNull String uri, @Nullable String installationMethod) Install an extension.An installed extension will persist and will be available even when restarting the
GeckoRuntime.Installed extensions through this method need to be signed by Mozilla, see Distributing your add-on .
When calling this method, the GeckoView library will download the extension, validate its manifest and signature, and give you an opportunity to verify its permissions through
WebExtensionController.PromptDelegate.onInstallPromptRequest(org.mozilla.geckoview.WebExtension, java.lang.String[], java.lang.String[], java.lang.String[]), you can use this method to prompt the user if appropriate.- Parameters:
uri- URI to the extension's.xpipackage. This can be a remotehttps:URI or a localfile:orresource:URI. Note: the app needs the appropriate permissions for local URIs.installationMethod- The method used by the embedder to install theWebExtension.- Returns:
- A
GeckoResultthat will complete when the installation process finishes. For successful installations, the GeckoResult will return theWebExtensionobject that you can use to set delegates and retrieve information about the WebExtension usingWebExtension.metaData.If an error occurs during the installation process, the GeckoResult will complete exceptionally with a
InstallExceptionthat will contain the relevant error code inInstallException#code. - See Also:
-
install
Install an extension.An installed extension will persist and will be available even when restarting the
GeckoRuntime.Installed extensions through this method need to be signed by Mozilla, see Distributing your add-on .
When calling this method, the GeckoView library will download the extension, validate its manifest and signature, and give you an opportunity to verify its permissions through
installPromptRequest(GeckoBundle, EventCallback), you can use this method to prompt the user if appropriate. If you are looking to provide anWebExtensionController.InstallationMethod, please useinstall(String, String)- Parameters:
uri- URI to the extension's.xpipackage. This can be a remotehttps:URI or a localfile:orresource:URI. Note: the app needs the appropriate permissions for local URIs.- Returns:
- A
GeckoResultthat will complete when the installation process finishes. For successful installations, the GeckoResult will return theWebExtensionobject that you can use to set delegates and retrieve information about the WebExtension usingWebExtension.metaData.If an error occurs during the installation process, the GeckoResult will complete exceptionally with a
InstallExceptionthat will contain the relevant error code inInstallException#code. - See Also:
-
installPromptRequest(org.mozilla.gecko.util.GeckoBundle, org.mozilla.gecko.util.EventCallback)WebExtension.InstallException.ErrorCodesWebExtension.metaData
-
setAllowedInPrivateBrowsing
@NonNull @AnyThread public GeckoResult<WebExtension> setAllowedInPrivateBrowsing(@NonNull WebExtension extension, boolean allowed) Set whether an extension should be allowed to run in private browsing or not.- Parameters:
extension- theWebExtensioninstance to modify.allowed- true if this extension should be allowed to run in private browsing pages, false otherwise.- Returns:
- the updated
WebExtensioninstance.
-
addOptionalPermissions
@NonNull @AnyThread public GeckoResult<WebExtension> addOptionalPermissions(@NonNull String extensionId, @NonNull String[] permissions, @NonNull String[] origins, @NonNull String[] dataCollectionPermissions) Add the provided permissions to theWebExtensionwith the given id.- Parameters:
extensionId- the id ofWebExtensioninstance to modify.permissions- the permissions to add, pass an empty array to not update.origins- the origins to add, pass an empty array to not update.dataCollectionPermissions- the data collection permissions to add, pass an empty array to not update.- Returns:
- the updated
WebExtensioninstance.
-
removeOptionalPermissions
@NonNull @AnyThread public GeckoResult<WebExtension> removeOptionalPermissions(@NonNull String extensionId, @NonNull String[] permissions, @NonNull String[] origins, @NonNull String[] dataCollectionPermissions) Remove the provided permissions from theWebExtensionwith the given id.- Parameters:
extensionId- the id ofWebExtensioninstance to modify.permissions- the permissions to remove, pass an empty array to not update.origins- the origins to remove, pass an empty array to not update.dataCollectionPermissions- the data collection permissions to remove, pass an array to not update.- Returns:
- the updated
WebExtensioninstance.
-
installBuiltIn
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:
controller.installBuiltIn("resource://android/assets/example/");Will install the built-in extension located at/assets/example/in the app's APK.- Parameters:
uri- Folder where the extension is located. To ensure this folder is inside the APK, onlyresource://androidURIs are allowed.- Returns:
- A
GeckoResultthat completes with the extension once it's installed. - See Also:
-
ensureBuiltIn
@NonNull @AnyThread public GeckoResult<WebExtension> ensureBuiltIn(@NonNull String uri, @Nullable String id) Ensure that a built-in extension is installed.Similar to
installBuiltIn(java.lang.String), except the extension is not re-installed if it's already present and it has the same version.Example:
controller.ensureBuiltIn("resource://android/assets/example/", "example@example.com");Will install the built-in extension located at/assets/example/in the app's APK.- Parameters:
uri- Folder where the extension is located. To ensure this folder is inside the APK, onlyresource://androidURIs are allowed.id- Extension ID as present in the manifest.json file.- Returns:
- A
GeckoResultthat completes with the extension once it's installed. - See Also:
-
uninstall
Uninstall an extension.Uninstalling an extension will remove it from the current
GeckoRuntimeinstance, delete all its data and trigger a request to close all extension pages currently open.- Parameters:
extension- TheWebExtensionto be uninstalled.- Returns:
- A
GeckoResultthat will complete when the uninstall process is completed.
-
enable
@AnyThread @NonNull public GeckoResult<WebExtension> enable(@NonNull WebExtension extension, int source) Enable an extension that has been disabled. If the extension is already enabled, this method has no effect.- Parameters:
extension- TheWebExtensionto be enabled.source- The agent that initiated this action, e.g. if the action has been initiated by the user,useWebExtensionController.EnableSource.USER.- Returns:
- the new
WebExtensioninstance, updated to reflect the enablement.
-
disable
@AnyThread @NonNull public GeckoResult<WebExtension> disable(@NonNull WebExtension extension, int source) Disable an extension that is enabled. If the extension is already disabled, this method has no effect.- Parameters:
extension- TheWebExtensionto be disabled.source- The agent that initiated this action, e.g. if the action has been initiated by the user, useWebExtensionController.EnableSource.USER.- Returns:
- the new
WebExtensioninstance, updated to reflect the disablement.
-
list
List installed extensions for thisGeckoRuntime.The returned list can be used to set delegates on the
WebExtensionobjects usingWebExtension.setActionDelegate(org.mozilla.geckoview.WebExtension.ActionDelegate),WebExtension.setMessageDelegate(org.mozilla.geckoview.WebExtension.MessageDelegate, java.lang.String).- Returns:
- a
GeckoResultthat will resolve when the list of extensions is available.
-
update
Update a web extension.When checking for an update, GeckoView will download the update manifest that is defined by the web extension's manifest property browser_specific_settings.gecko.update_url. If an update is found it will be downloaded and installed. If the extension needs any new permissions the
updatePrompt(org.mozilla.gecko.util.GeckoBundle, org.mozilla.gecko.util.EventCallback)will be triggered.More information about the update manifest format is available here.
- Parameters:
extension- The extension to update.- Returns:
- A
GeckoResultthat will complete when the update process finishes. If an update is found and installed successfully, the GeckoResult will return the updatedWebExtension. If no update is available, null will be returned. If the updated extension requires new permissions, theinstallPromptRequest(org.mozilla.gecko.util.GeckoBundle, org.mozilla.gecko.util.EventCallback)will be called. - See Also:
-
updatePrompt(org.mozilla.gecko.util.GeckoBundle, org.mozilla.gecko.util.EventCallback)
-
setTabActive
Notifies extensions about a active tab change over the `tabs.onActivated` event.- Parameters:
session- TheGeckoSessionof the newly selected session/tab.active- true if the tab became active, false if the tab became inactive.
-
createDownload
Creates a new Download object with the specified ID for tracking WebExtension downloads.- Parameters:
id- The unique identifier for the download- Returns:
- A new Download object for the specified ID
- Throws:
IllegalArgumentException- if a download with this ID already exists
-