public class WebExtensionController extends Object
Modifier and Type | Class and Description |
---|---|
static interface |
WebExtensionController.DebuggerDelegate |
static class |
WebExtensionController.EnableSource
Contains the possible values for the
source parameter in enable(org.mozilla.geckoview.WebExtension, int) and
disable(org.mozilla.geckoview.WebExtension, int) . |
static interface |
WebExtensionController.PromptDelegate
This 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 called
permissions.request |
Modifier and Type | Method and Description |
---|---|
WebExtension.Download |
createDownload(int id) |
GeckoResult<WebExtension> |
disable(WebExtension extension,
int source)
Disable an extension that is enabled.
|
GeckoResult<WebExtension> |
enable(WebExtension extension,
int source)
Enable an extension that has been disabled.
|
GeckoResult<WebExtension> |
ensureBuiltIn(String uri,
String id)
Ensure that a built-in extension is installed.
|
WebExtensionController.PromptDelegate |
getPromptDelegate() |
GeckoResult<WebExtension> |
install(String uri)
Install an extension.
|
GeckoResult<WebExtension> |
installBuiltIn(String uri)
Install a built-in extension.
|
GeckoResult<List<WebExtension>> |
list()
List installed extensions for this
GeckoRuntime . |
GeckoResult<WebExtension> |
setAllowedInPrivateBrowsing(WebExtension extension,
boolean allowed)
Set whether an extension should be allowed to run in private browsing or not.
|
void |
setDebuggerDelegate(WebExtensionController.DebuggerDelegate delegate)
Set the
WebExtensionController.DebuggerDelegate for this instance. |
void |
setPromptDelegate(WebExtensionController.PromptDelegate delegate)
Set the
WebExtensionController.PromptDelegate for this instance. |
void |
setTabActive(GeckoSession session,
boolean active)
Notifies extensions about a active tab change over the `tabs.onActivated` event.
|
GeckoResult<Void> |
uninstall(WebExtension extension)
Uninstall an extension.
|
GeckoResult<WebExtension> |
update(WebExtension extension)
Update a web extension.
|
@UiThread @Nullable public WebExtensionController.PromptDelegate getPromptDelegate()
WebExtensionController.PromptDelegate
instance.WebExtensionController.PromptDelegate
@UiThread public void setPromptDelegate(@Nullable WebExtensionController.PromptDelegate delegate)
WebExtensionController.PromptDelegate
for this instance. This delegate will be used
to be notified whenever an extension is being installed or needs new permissions.delegate
- the delegate instance.WebExtensionController.PromptDelegate
@UiThread public void setDebuggerDelegate(@NonNull WebExtensionController.DebuggerDelegate delegate)
WebExtensionController.DebuggerDelegate
for this instance. This delegate will receive updates
about extension changes using developer tools.delegate
- the Delegate instance@NonNull @AnyThread public GeckoResult<WebExtension> install(@NonNull String uri)
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
installPrompt(org.mozilla.gecko.util.GeckoBundle, org.mozilla.gecko.util.EventCallback)
, you can use this method to prompt the user if
appropriate.uri
- URI to the extension's .xpi
package. This can be a remote
https:
URI or a local file:
or resource:
URI. Note: the app needs the appropriate permissions for local URIs.GeckoResult
that will complete when the installation process finishes.
For successful installations, the GeckoResult will return the WebExtension
object that you can use to set delegates and retrieve information about the
WebExtension using WebExtension.metaData
.
If an error occurs during the installation process, the GeckoResult will complete
exceptionally with a
InstallException
that will contain
the relevant error code in
InstallException#code
.installPrompt(org.mozilla.gecko.util.GeckoBundle, org.mozilla.gecko.util.EventCallback)
,
WebExtension.InstallException.ErrorCodes
,
WebExtension.metaData
@NonNull @AnyThread public GeckoResult<WebExtension> setAllowedInPrivateBrowsing(@NonNull WebExtension extension, boolean allowed)
extension
- the WebExtension
instance to modify.allowed
- true if this extension should be allowed to run in private browsing pages,
false otherwise.WebExtension
instance.@NonNull @AnyThread public GeckoResult<WebExtension> installBuiltIn(@NonNull String uri)
controller.installBuiltIn("resource://android/assets/example/");
/assets/example/
in the app's APK.uri
- Folder where the extension is located. To ensure this folder
is inside the APK, only resource://android
URIs
are allowed.GeckoResult
that completes with the extension once
it's installed.WebExtension.MessageDelegate
@NonNull @AnyThread public GeckoResult<WebExtension> ensureBuiltIn(@NonNull String uri, @Nullable String id)
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");
/assets/example/
in the app's APK.uri
- Folder where the extension is located. To ensure this folder
is inside the APK, only resource://android
URIs
are allowed.id
- Extension ID as present in the manifest.json file.GeckoResult
that completes with the extension once
it's installed.WebExtension.MessageDelegate
@NonNull @AnyThread public GeckoResult<Void> uninstall(@NonNull WebExtension extension)
GeckoRuntime
instance,
delete all its data and trigger a request to close all extension pages currently open.extension
- The WebExtension
to be uninstalled.GeckoResult
that will complete when the uninstall process is completed.@AnyThread @NonNull public GeckoResult<WebExtension> enable(@NonNull WebExtension extension, int source)
extension
- The WebExtension
to be enabled.source
- The agent that initiated this action, e.g. if the action has been initiated
by the user,use WebExtensionController.EnableSource.USER
.WebExtension
instance, updated to reflect the enablement.@AnyThread @NonNull public GeckoResult<WebExtension> disable(@NonNull WebExtension extension, int source)
extension
- The WebExtension
to be disabled.source
- The agent that initiated this action, e.g. if the action has been initiated
by the user, use WebExtensionController.EnableSource.USER
.WebExtension
instance, updated to reflect the disablement.@AnyThread @NonNull public GeckoResult<List<WebExtension>> list()
GeckoRuntime
.
The returned list can be used to set delegates on the WebExtension
objects using
WebExtension.setActionDelegate(org.mozilla.geckoview.WebExtension.ActionDelegate)
, WebExtension.setMessageDelegate(org.mozilla.geckoview.WebExtension.MessageDelegate, java.lang.String)
.GeckoResult
that will resolve when the list of extensions is available.@AnyThread @NonNull public GeckoResult<WebExtension> update(@NonNull WebExtension extension)
updatePrompt(org.mozilla.gecko.util.GeckoBundle, org.mozilla.gecko.util.EventCallback)
will be triggered.
More information about the update manifest format is available
here.extension
- The extension to update.GeckoResult
that will complete when the update process finishes. If an
update is found and installed successfully, the GeckoResult will return the updated
WebExtension
. If no update is available, null will be returned. If the updated
extension requires new permissions, the installPrompt(org.mozilla.gecko.util.GeckoBundle, org.mozilla.gecko.util.EventCallback)
will be called.updatePrompt(org.mozilla.gecko.util.GeckoBundle, org.mozilla.gecko.util.EventCallback)
@AnyThread public void setTabActive(@NonNull GeckoSession session, boolean active)
session
- The GeckoSession
of the newly selected session/tab.active
- true if the tab became active, false if the tab became inactive.@Nullable @UiThread public WebExtension.Download createDownload(int id)