Class WebExtension

All Implemented Interfaces:
Initable, Proxy

@Generated("org.javagi.JavaGI") public final class WebExtension extends GObject implements Initable

Represents a WebExtension.

A WebKitWebExtension object encapsulates a web extension’s resources that are defined by a manifest.json file.

This class handles the reading and parsing of the manifest file along with the supporting resources like icons and localizations.

Since:
2.52
  • Constructor Details

    • WebExtension

      public WebExtension(MemorySegment address)
      Create a WebExtension instance for the provided memory address.
      Parameters:
      address - the memory address of the native object
    • WebExtension

      public WebExtension(String extensionPath) throws GErrorException
      Creates a new WebKitWebExtension from a folder containing the extension contents. The folder must contain a manifest.json file. If the manifest is invalid or missing, an error will be returned.
      Parameters:
      extensionPath - A string pointing to the folder containing the extension manifest and resources
      Throws:
      GErrorException - see GError
      Since:
      2.52
    • WebExtension

      public WebExtension()
      Create a new WebExtension.
  • Method Details

    • getType

      public static @Nullable Type getType()
      Get the GType of the WebExtension class.
      Returns:
      the GType
    • getMemoryLayout

      public static MemoryLayout getMemoryLayout()
      The memory layout of the native struct.
      Returns:
      the memory layout
    • asParent

      protected WebExtension asParent()
      Return this instance as if it were its parent type. Comparable to the Java super keyword, but ensures the parent typeclass is also used in native code.
      Overrides:
      asParent in class GObject
      Returns:
      the instance as if it were its parent type
    • getActionIcon

      public @Nullable Icon getActionIcon(double width, double height)
      Returns the extension's default action icon image for the specified size. This icon serves as a default and should be used to represent the extension in contexts like action sheets or toolbars prior to the extension being loaded into an extension context. Once the extension is loaded, use the actionForTab: API to get the tab-specific icon. The returned image will be the best match for the specified size that is available in the extension's action icon set. If no matching icon is available, the method will fall back to the extension's icon.
      Parameters:
      width - The width to use when looking up the icon.
      height - The height to use when looking up the icon.
      Returns:
      the icon image, or null if no icon could be loaded.
      Since:
      2.52
    • getAllRequestedMatchPatterns

      public WebExtensionMatchPattern[] getAllRequestedMatchPatterns()
      Get the set of websites that the extension requires access to for injected content and for receiving messages from websites.
      Returns:
      a null-terminated array of match patterns matching all requested websites.
      Since:
      2.52
    • getDefaultLocale

      public @Nullable String getDefaultLocale()
      Get the default locale for the extension.
      Returns:
      the default locale, or null if there was no default locale specified.
      Since:
      2.52
    • getDisplayActionLabel

      public @Nullable String getDisplayActionLabel()

      Get the localized display action label for the extension.

      This label serves as a default and should be used to represent the extension in contexts like action sheets or toolbars prior to the extension being loaded into an extension context. Once the extension is loaded, use the actionForTab: API to get the tab-specific label.

      Returns:
      the localized display action label, or null if there was no display action label specified.
      Since:
      2.52
    • getDisplayDescription

      public @Nullable String getDisplayDescription()
      Get the localized display description for the extension.
      Returns:
      the localized display description, or null if there was no display description specified.
      Since:
      2.52
    • getDisplayName

      public @Nullable String getDisplayName()
      Get the localized name for the extension.
      Returns:
      the localized name, or null if there was no name specified.
      Since:
      2.52
    • getDisplayShortName

      public @Nullable String getDisplayShortName()
      Get the localized short name for the extension.
      Returns:
      the localized name, or null if there was no short name specified.
      Since:
      2.52
    • getDisplayVersion

      public @Nullable String getDisplayVersion()
      Get the localized display version for the extension.
      Returns:
      the localized display version, or null if there was no display version specified.
      Since:
      2.52
    • getHasBackgroundContent

      public boolean getHasBackgroundContent()
      Get whether the extension has background content that can run when needed.
      Returns:
      TRUE if the extension can run in the background even when no webpages are open.
      Since:
      2.52
    • getHasCommands

      public boolean getHasCommands()

      Get whether the extension includes commands that users can invoke.

      These commands should be accessible via keyboard shortcuts, menu items, or other user interface elements provided by the app. The list of commands can be accessed via commands on an extension context, and invoked via performCommand:.

      Returns:
      TRUE if the extension contains one or more commands that can be performed by the user.
      Since:
      2.52
    • getHasContentModificationRules

      public boolean getHasContentModificationRules()
      Get whether the extension includes rules used for content modification or blocking.
      Returns:
      TRUE if the extension contains one or more rules for content modification.
      Since:
      2.52
    • getHasInjectedContent

      public boolean getHasInjectedContent()

      Get whether the extension has script or stylesheet content that can be injected into webpages.

      Once the extension is loaded, use the hasInjectedContent property on an extension context, as the injectable content can change after the extension is loaded.

      Returns:
      TRUE if the extension has content that can be injected by matching against the extension's requested match patterns.
      Since:
      2.52
    • getHasOptionsPage

      public boolean getHasOptionsPage()

      Get whether the extension has an options page.

      The app should provide access to this page through a user interface element, which can be accessed via optionsPageURL on an extension context.

      Returns:
      TRUE if the extension includes a dedicated options page where users can customize settings.
      Since:
      2.52
    • getHasOverrideNewTabPage

      public boolean getHasOverrideNewTabPage()

      Get whether the extension provides an alternative to the default new tab page.

      The app should prompt the user for permission to use the extension's new tab page as the default, which can be accessed via overrideNewTabPageURL on an extension context.

      Returns:
      TRUE if the extension can specify a custom page that can be displayed when a new tab is opened in the app, instead of the default new tab page.
      Since:
      2.52
    • getHasPersistentBackgroundContent

      public boolean getHasPersistentBackgroundContent()
      Get whether the extension has background content that stays in memory as long as the extension is loaded.
      Returns:
      TRUE if the extension can run in the background.
      Since:
      2.52
    • getIcon

      public @Nullable Icon getIcon(double width, double height)
      Returns the extension's icon image for the specified size. This icon should represent the extension in settings or other areas that show the extension. The returned image will be the best match for the specified size that is available in the extension's icon set. If no matching icon can be found, the method will return null.
      Parameters:
      width - The width to use when looking up the icon.
      height - The height to use when looking up the icon.
      Returns:
      the icon image, or null if no icon could be loaded.
      Since:
      2.52
    • getManifestVersion

      public double getManifestVersion()

      Get the parsed manifest version, or 0 if there is no version specified in the manifest.

      A WebKit.WebExtensionError.UNSUPPORTED_MANIFEST_VERSION error will be reported if the manifest version isn't specified.

      Returns:
      the parsed manifest version.
      Since:
      2.52
    • getOptionalPermissionMatchPatterns

      public WebExtensionMatchPattern[] getOptionalPermissionMatchPatterns()
      Get the set of websites that the extension may need access to for optional functionality. These match patterns can be requested by the extension at a later time.
      Returns:
      a null-terminated array of match patterns matching the optional websites.
      Since:
      2.52
    • getOptionalPermissions

      public @Nullable String @Nullable [] getOptionalPermissions()
      Get the set of permissions that the extension may need for optional functionality. These permissions can be requested by the extension at a later time.
      Returns:
      a null-terminated array of strings containing permission names, or null otherwise. This array and its contents are owned by WebKit and should not be modified or freed.
      Since:
      2.52
    • getPath

      public String getPath()
      Get the path pointing to the folder containing the extension manifest and resources
      Returns:
      the path of the extension folder
      Since:
      2.52
    • getRequestedPermissionMatchPatterns

      public WebExtensionMatchPattern[] getRequestedPermissionMatchPatterns()
      Get the set of websites that the extension requires access to for its base functionality.
      Returns:
      a null-terminated array of match patterns matching the required websites.
      Since:
      2.52
    • getRequestedPermissions

      public @Nullable String @Nullable [] getRequestedPermissions()
      Get the set of permissions that the extension requires for its base functionality.
      Returns:
      a null-terminated array of strings containing permission names, or null otherwise. This array and its contents are owned by WebKit and should not be modified or freed.
      Since:
      2.52
    • getVersion

      public @Nullable String getVersion()
      Get the version for the extension.
      Returns:
      the version, or null if there was no version specified.
      Since:
      2.52
    • supportsManifestVersion

      public boolean supportsManifestVersion(double manifestVersion)
      Checks if a manifest version is supported by the extension.
      Parameters:
      manifestVersion - the version number to check
      Returns:
      TRUE if the extension specified a manifest version that is greater than or equal to manifestVersion.
      Since:
      2.52
    • builder

      public static WebExtension.Builder<? extends WebExtension.Builder> builder()
      A WebExtension.Builder object constructs a WebExtension with the specified properties. Use the various set...() methods to set properties, and finish construction with WebExtension.Builder.build().
      Returns:
      the builder object