Class WebViewFactory<WebViewType>Abstract

A partial implementation of IWebViewProvider that includes creating WebViewControllers for each web view served by the web view provider. This class handles registering, disposing, and making sure there is only one web view controller for each web view for you.

You can create a new class extending this abstract class to create a web view provider that serves web views and web view controllers of a specific webViewType to facilitate interaction between those web views and other extensions. You can register it with the PAPI using papi.webViewProviders.register.

If you want to change your existing IWebViewProvider from a plain object to extending this class, you will need to change your object's existing method named getWebView (IWebViewProvider.getWebView) to be named getWebViewDefinition (WebViewFactory.getWebViewDefinition), which is a drop-in replacement. You likely do NOT want to overwrite this class's getWebView because that will eliminate most of the benefits associated with using this class.

IWebViewProvider for more information on extending this class.

Type Parameters

Implements

Constructors

Properties

webViewType: WebViewType

Methods

  • Creates a WebViewController that corresponds to the WebViewDefinition provided. WebViewFactory calls this as part of its getWebView. WebViewFactory will automatically register this controller with the web view provider service (papi.webViewProviders.registerWebViewController), run its dispose when the web view is closed or this WebViewFactory is disposed, and make sure just one web view controller is created for each web view.

    Alternatively, if you do not want to create web view controllers (or a controller for a specific web view), feel free to return undefined from this method.

    Parameters

    • webViewDefinition: WebViewDefinition

      The definition for the web view for which to create a web view controller

    • webViewNonce: string

      Nonce used to perform privileged interactions with the web view created from the webViewDefinition parameter such as papi.webViewProviders.postMessageToWebView. The web view service generates this nonce and sends it only here to this web view provider that creates the web view with this id. It is generally recommended that this web view provider not share this nonce with anyone else but only use it within itself and here in the web view controller created for this web view.

    Returns Promise<WebViewControllers[WebViewType]>

    Web view controller for the web view with the webViewDefinition provided. Or undefined if you do not want to create a web view controller for this web view.

  • Disposes of all WVCs that were created by this provider

    Returns Promise<boolean>

  • Receives a SavedWebViewDefinition and fills it out into a full WebViewDefinition, providing the contents of the web view and other properties that are important for displaying the web view.

    WebViewFactory calls this as part of its getWebView, which is called by the PAPI as part of opening a new web view. It will also create a web view controller after running this if applicable.

    See IWebViewProvider.getWebView for more information on how this method works.

    Parameters

    • savedWebViewDefinition: SavedWebViewDefinition

      The saved web view information from which to build a complete web view definition. Filled out with all SavedWebViewDefinition properties of the existing web view if an existing webview is being called for (matched by ID). Just provides the minimal properties required on SavedWebViewDefinition if this is a new request or if the web view with the existing ID was not found.

    • getWebViewOptions: GetWebViewOptions

      Various options that affect what calling papi.webViews.openWebView should do. When options are passed to papi.webViews.openWebView, some defaults are set up on the options, then those options are passed directly through to this method. That way, if you want to adjust what this method does based on the contents of the options passed to papi.WebViews.openWebView, you can. You can even read other properties on these options if someone passes options with other properties to papi.webViews.openWebView.

    • webViewNonce: string

      Nonce used to perform privileged interactions with the web view created from this method's returned WebViewDefinition such as papi.webViewProviders.postMessageToWebView. The web view service generates this nonce and sends it only here to this web view provider that creates the web view with this id. It is generally recommended that this web view provider not share this nonce with anyone else but only use it within itself and in the web view controller created for this web view if applicable (See papi.webViewProviders.registerWebViewController).

    Returns Promise<undefined | WebViewDefinition>

    Full WebViewDefinition including the content and other important display properties based on the SavedWebViewDefinition provided