Class WebView

All Implemented Interfaces:
Accessible, Buildable, ConstraintTarget, Proxy

@Generated("org.javagi.JavaGI") public class WebView extends WebViewBase implements Accessible, Buildable, ConstraintTarget

The central class of the WPE WebKit and WebKitGTK APIs.

WebKitWebView is the central class of the WPE WebKit and WebKitGTK APIs. It is responsible for managing the drawing of the content and forwarding of events. You can load any URI into the WebKitWebView or a data string. With WebKitSettings you can control various aspects of the rendering and loading of the content.

Note that in WebKitGTK, WebKitWebView is scrollable by itself, so you don't need to embed it in a GtkScrolledWindow.

  • Constructor Details

    • WebView

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

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

    • getType

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

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

      protected WebView 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 WebViewBase
      Returns:
      the instance as if it were its parent type
    • callAsyncJavascriptFunction

      public void callAsyncJavascriptFunction(String body, long length, @Nullable Variant arguments, @Nullable String worldName, @Nullable String sourceUri, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback)

      Asynchronously call body with arguments in the script world with name worldName of the main frame current context in webView. The arguments values must be one of the following types, or contain only the following GVariant types: number, string and dictionary. The result of the operation can be a Promise that will be properly passed to the callback. If worldName is null, the default world is used. Any value that is not null is a distin ct world. The sourceUri will be shown in exceptions and doesn't affect the behavior of the script. When not provided, the document URL is used.

      Note that if WebKitSettings:enable-javascript is false, this method will do nothing. If you want to use this method but still prevent web content from executing its own JavaScript, then use WebKitSettings:enable-javascript-markup.

      When the operation is finished, callback will be called. You can then call webkit_web_view_call_async_javascript_function_finish() to get the result of the operation.

      This is an example that shows how to pass arguments to a JS function that returns a Promise that resolves with the passed argument:

      static void
      web_view_javascript_finished (GObject      *object,
                                    GAsyncResult *result,
                                    gpointer      user_data)
      {
          JSCValue               *value;
          GError                 *error = NULL;
      
          value = webkit_web_view_call_async_javascript_function_finish (WEBKIT_WEB_VIEW (object), result, &error);
          if (!value) {
              g_warning ("Error running javascript: %s", error->message);
              g_error_free (error);
              return;
          }
      
          if (jsc_value_is_number (value)) {
              gint32        int_value = jsc_value_to_string (value);
              JSCException *exception = jsc_context_get_exception (jsc_value_get_context (value));
              if (exception)
                  g_warning ("Error running javascript: %s", jsc_exception_get_message (exception));
              else
                  g_print ("Script result: %d\\n", int_value);
              g_free (str_value);
          } else {
              g_warning ("Error running javascript: unexpected return value");
          }
          g_object_unref (value);
      }
      
      static void
      web_view_evaluate_promise (WebKitWebView *web_view)
      {
          GVariantDict dict;
          g_variant_dict_init (&dict, NULL);
          g_variant_dict_insert (&dict, "count", "u", 42);
          GVariant *args = g_variant_dict_end (&dict);
          const gchar *body = "return new Promise((resolve) => { resolve(count); });";
          webkit_web_view_call_async_javascript_function (web_view, body, -1, arguments, NULL, NULL, NULL, web_view_javascript_finished, NULL);
      }
      
      Parameters:
      body - the function body
      length - length of body, or -1 if body is a nul-terminated string
      arguments - a GVariant with format a{sv} storing the function arguments, or null
      worldName - the name of a WebKitScriptWorld or null to use the default
      sourceUri - the source URI
      cancellable - a GCancellable or null to ignore
      callback - a GAsyncReadyCallback to call when the script finished
      Since:
      2.40
    • callAsyncJavascriptFunctionFinish

      public Value callAsyncJavascriptFunctionFinish(AsyncResult result) throws GErrorException
      Finish an asynchronous operation started with webkit_web_view_call_async_javascript_function().
      Parameters:
      result - a GAsyncResult
      Returns:
      a JSCValue with the return value of the async function or null in case of error
      Throws:
      GErrorException - see GError
      Since:
      2.40
    • canExecuteEditingCommand

      public void canExecuteEditingCommand(String command, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback)

      Asynchronously check if it is possible to execute the given editing command.

      When the operation is finished, callback will be called. You can then call webkit_web_view_can_execute_editing_command_finish() to get the result of the operation.

      Parameters:
      command - the command to check
      cancellable - a GCancellable or null to ignore
      callback - a GAsyncReadyCallback to call when the request is satisfied
    • canExecuteEditingCommandFinish

      public boolean canExecuteEditingCommandFinish(AsyncResult result) throws GErrorException
      Finish an asynchronous operation started with webkit_web_view_can_execute_editing_command().
      Parameters:
      result - a GAsyncResult
      Returns:
      true if the editing command can be executed or false otherwise
      Throws:
      GErrorException - see GError
    • canGoBack

      public boolean canGoBack()
      Determines whether this WebView has a previous history item.
      Returns:
      true if able to move back or false otherwise.
    • canGoForward

      public boolean canGoForward()
      Determines whether this WebView has a next history item.
      Returns:
      true if able to move forward or false otherwise.
    • canShowMimeType

      public boolean canShowMimeType(String mimeType)
      Whether or not a MIME type can be displayed in webView.
      Parameters:
      mimeType - a MIME type
      Returns:
      true if the MIME type mimeType can be displayed or false otherwise
    • downloadUri

      public Download downloadUri(String uri)
      Requests downloading of the specified URI string for webView.
      Parameters:
      uri - the URI to download
      Returns:
      a new WebKitDownload representing the download operation.
    • evaluateJavascript

      public void evaluateJavascript(String script, long length, @Nullable String worldName, @Nullable String sourceUri, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback)

      Asynchronously evaluate script in the script world with name worldName of the main frame current context in webView. If worldName is null, the default world is used. Any value that is not null is a distinct world. The sourceUri will be shown in exceptions and doesn't affect the behavior of the script. When not provided, the document URL is used.

      Note that if WebKitSettings:enable-javascript is false, this method will do nothing. If you want to use this method but still prevent web content from executing its own JavaScript, then use WebKitSettings:enable-javascript-markup.

      When the operation is finished, callback will be called. You can then call webkit_web_view_evaluate_javascript_finish() to get the result of the operation.

      This is an example of using webkit_web_view_evaluate_javascript() with a script returning a string:

      static void
      web_view_javascript_finished (GObject      *object,
                                    GAsyncResult *result,
                                    gpointer      user_data)
      {
          JSCValue               *value;
          GError                 *error = NULL;
      
          value = webkit_web_view_evaluate_javascript_finish (WEBKIT_WEB_VIEW (object), result, &error);
          if (!value) {
              g_warning ("Error running javascript: %s", error->message);
              g_error_free (error);
              return;
          }
      
          if (jsc_value_is_string (value)) {
              gchar        *str_value = jsc_value_to_string (value);
              JSCException *exception = jsc_context_get_exception (jsc_value_get_context (value));
              if (exception)
                  g_warning ("Error running javascript: %s", jsc_exception_get_message (exception));
              else
                  g_print ("Script result: %s\\n", str_value);
              g_free (str_value);
          } else {
              g_warning ("Error running javascript: unexpected return value");
          }
          g_object_unref (value);
      }
      
      static void
      web_view_get_link_url (WebKitWebView *web_view,
                             const gchar   *link_id)
      {
          gchar *script = g_strdup_printf ("window.document.getElementById('%s').href;", link_id);
          webkit_web_view_evaluate_javascript (web_view, script, -1, NULL, NULL, NULL, web_view_javascript_finished, NULL);
          g_free (script);
      }
      
      Parameters:
      script - the script to evaluate
      length - length of script, or -1 if script is a nul-terminated string
      worldName - the name of a WebKitScriptWorld or null to use the default
      sourceUri - the source URI
      cancellable - a GCancellable or null to ignore
      callback - a GAsyncReadyCallback to call when the script finished
      Since:
      2.40
    • evaluateJavascriptFinish

      public Value evaluateJavascriptFinish(AsyncResult result) throws GErrorException
      Finish an asynchronous operation started with webkit_web_view_evaluate_javascript().
      Parameters:
      result - a GAsyncResult
      Returns:
      a JSCValue with the result of the last executed statement in script or null in case of error
      Throws:
      GErrorException - see GError
      Since:
      2.40
    • executeEditingCommand

      public void executeEditingCommand(String command)

      Request to execute the given command for webView.

      You can use webkit_web_view_can_execute_editing_command() to check whether it's possible to execute the command.

      Parameters:
      command - the command to execute
    • executeEditingCommandWithArgument

      public void executeEditingCommandWithArgument(String command, String argument)

      Request to execute the given command with argument for webView.

      You can use webkit_web_view_can_execute_editing_command() to check whether it's possible to execute the command.

      Parameters:
      command - the command to execute
      argument - the command argument
      Since:
      2.10
    • getAutomationPresentationType

      public AutomationBrowsingContextPresentation getAutomationPresentationType()
      Get the presentation type of WebKitWebView when created for automation.
      Returns:
      a WebKitAutomationBrowsingContextPresentation.
      Since:
      2.28
    • getBackForwardList

      public BackForwardList getBackForwardList()

      Obtains the WebKitBackForwardList associated with the given WebKitWebView.

      The WebKitBackForwardList is owned by the WebKitWebView.

      Returns:
      the WebKitBackForwardList
    • getBackgroundColor

      public void getBackgroundColor(RGBA rgba)

      Gets the color that is used to draw the this WebView background.

      Gets the color that is used to draw the this WebView background before the actual contents are rendered. For more information see also webkit_web_view_set_background_color()

      Parameters:
      rgba - a GdkRGBA to fill in with the background color
      Since:
      2.8
    • getCameraCaptureState

      public MediaCaptureState getCameraCaptureState()
      Get the camera capture state of a WebKitWebView.
      Returns:
      The WebKitMediaCaptureState of the camera device. If WebKitSettings:enable-mediastream is false, this method will return MediaCaptureState.NONE.
      Since:
      2.34
    • getContext

      public WebContext getContext()
      Gets the web context of webView.
      Returns:
      the WebKitWebContext of the view
    • getCustomCharset

      public String getCustomCharset()
      Returns the current custom character encoding name of webView.
      Returns:
      the current custom character encoding name or null if no custom character encoding has been set.
    • getDefaultContentSecurityPolicy

      public @Nullable String getDefaultContentSecurityPolicy()
      Gets the configured default Content-Security-Policy.
      Returns:
      The default policy or null
      Since:
      2.38
    • getDisplayCaptureState

      public MediaCaptureState getDisplayCaptureState()
      Get the display capture state of a WebKitWebView.
      Returns:
      The WebKitMediaCaptureState of the display device. If WebKitSettings:enable-mediastream is false, this method will return MediaCaptureState.NONE.
      Since:
      2.34
    • getEditorState

      public EditorState getEditorState()
      Gets the web editor state of webView.
      Returns:
      the WebKitEditorState of the view
      Since:
      2.10
    • getEstimatedLoadProgress

      public double getEstimatedLoadProgress()

      Gets the value of the WebKitWebView:estimated-load-progress property.

      You can monitor the estimated progress of a load operation by connecting to the notify::estimated-load-progress signal of webView.

      Returns:
      an estimate of the of the percent complete for a document load as a range from 0.0 to 1.0.
    • getFavicon

      public Texture getFavicon()

      Returns favicon currently associated to webView.

      Returns favicon currently associated to webView, if any. You can connect to notify::favicon signal of this WebView to be notified when the favicon is available.

      Returns:
      the favicon image or null if there's no icon associated with webView.
    • getFindController

      public FindController getFindController()

      Gets the WebKitFindController.

      Gets the WebKitFindController that will allow the caller to query the WebKitWebView for the text to look for.

      Returns:
      the WebKitFindController associated to this particular WebKitWebView.
    • getInputMethodContext

      public @Nullable InputMethodContext getInputMethodContext()

      Get the WebKitInputMethodContext currently in use by webView.

      Get the WebKitInputMethodContext currently in use by webView, or null if no input method is being used.

      Returns:
      a WebKitInputMethodContext, or null
      Since:
      2.28
    • getInspector

      public WebInspector getInspector()
      Get the WebKitWebInspector associated to this WebView
      Returns:
      the WebKitWebInspector of this WebView
    • getIsMuted

      public boolean getIsMuted()
      Gets the mute state of webView.
      Returns:
      true if this WebView audio is muted or false is audio is not muted.
      Since:
      2.30
    • getIsWebProcessResponsive

      public boolean getIsWebProcessResponsive()
      Get whether the current web process of a WebKitWebView is responsive.
      Returns:
      true if the web process attached to this WebView is responsive, or false otherwise.
      Since:
      2.34
    • getMainResource

      public WebResource getMainResource()
      Return the main resource of webView.
      Returns:
      the main WebKitWebResource of the view or null if nothing has been loaded.
    • getMicrophoneCaptureState

      public MediaCaptureState getMicrophoneCaptureState()
      Get the microphone capture state of a WebKitWebView.
      Returns:
      The WebKitMediaCaptureState of the microphone device. If WebKitSettings:enable-mediastream is false, this method will return MediaCaptureState.NONE.
      Since:
      2.34
    • getNetworkSession

      public NetworkSession getNetworkSession()
      Get the WebKitNetworkSession associated to webView.
      Returns:
      a WebKitNetworkSession
      Since:
      2.40
    • getPageId

      public long getPageId()
      Get the identifier of the WebKitWebPage corresponding to the WebKitWebView
      Returns:
      the page ID of webView.
    • getSessionState

      public WebViewSessionState getSessionState()
      Gets the current session state of this WebView
      Returns:
      a WebKitWebViewSessionState
      Since:
      2.12
    • getWebViewSettings

      public Settings getWebViewSettings()

      Gets the WebKitSettings currently applied to webView.

      If no other WebKitSettings have been explicitly applied to this WebView with webkit_web_view_set_settings(), the default WebKitSettings will be returned. This method always returns a valid WebKitSettings object. To modify any of the this WebView settings, you can either create a new WebKitSettings object with webkit_settings_new(), setting the desired preferences, and then replace the existing this WebView settings with webkit_web_view_set_settings() or get the existing this WebView settings and update it directly. WebKitSettings objects can be shared by multiple WebKitWebViews, so modifying the settings of a WebKitWebView would affect other WebKitWebViews using the same WebKitSettings.

      Returns:
      the WebKitSettings attached to this WebView
    • getSnapshot

      public void getSnapshot(SnapshotRegion region, Set<SnapshotOptions> options, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback)

      Asynchronously retrieves a snapshot of this WebView for region.

      options specifies how the snapshot should be rendered.

      When the operation is finished, callback will be called. You must call webkit_web_view_get_snapshot_finish() to get the result of the operation.

      Parameters:
      region - the WebKitSnapshotRegion for this snapshot
      options - WebKitSnapshotOptions for the snapshot
      cancellable - a GCancellable
      callback - a GAsyncReadyCallback
    • getSnapshot

      public void getSnapshot(SnapshotRegion region, SnapshotOptions options, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback)

      Asynchronously retrieves a snapshot of this WebView for region.

      options specifies how the snapshot should be rendered.

      When the operation is finished, callback will be called. You must call webkit_web_view_get_snapshot_finish() to get the result of the operation.

      Parameters:
      region - the WebKitSnapshotRegion for this snapshot
      options - WebKitSnapshotOptions for the snapshot
      cancellable - a GCancellable
      callback - a GAsyncReadyCallback
    • getSnapshotFinish

      public Texture getSnapshotFinish(AsyncResult result) throws GErrorException
      Finishes an asynchronous operation started with webkit_web_view_get_snapshot(), producing an image of the snapshot using the BGRA8888 pixel format.
      Parameters:
      result - a GAsyncResult
      Returns:
      an image with the retrieved snapshot, or null in case of error.
      Throws:
      GErrorException - see GError
    • getThemeColor

      public boolean getThemeColor(RGBA rgba)
      Gets the theme color that is specified by the content in the webView. If the this WebView doesn't have a theme color it will fill the rgba with transparent black content.
      Parameters:
      rgba - a GdkRGBA to fill in with the theme color
      Returns:
      Whether the currently loaded page defines a theme color.
      Since:
      2.50
    • getTitle

      public String getTitle()

      Gets the value of the WebKitWebView:title property.

      You can connect to notify::title signal of this WebView to be notified when the title has been received.

      Returns:
      The main frame document title of webView.
    • getTlsInfo

      public boolean getTlsInfo(Out<TlsCertificate> certificate, Out<Set<TlsCertificateFlags>> errors)

      Retrieves the GTlsCertificate associated with the main resource of webView.

      Retrieves the GTlsCertificate associated with the main resource of webView, and the GTlsCertificateFlags showing what problems, if any, have been found with that certificate. If the connection is not HTTPS, this function returns false. This function should be called after a response has been received from the server, so you can connect to WebKitWebView::load-changed and call this function when it's emitted with LoadEvent.COMMITTED event.

      Note that this function provides no information about the security of the web page if the current WebKitTLSErrorsPolicy is TLSErrorsPolicy.IGNORE, as subresources of the page may be controlled by an attacker. This function may safely be used to determine the security status of the current page only if the current WebKitTLSErrorsPolicy is TLSErrorsPolicy.FAIL, in which case subresources that fail certificate verification will be blocked.

      Parameters:
      certificate - return location for a GTlsCertificate
      errors - return location for a GTlsCertificateFlags the verification status of certificate
      Returns:
      true if the this WebView connection uses HTTPS and a response has been received from the server, or false otherwise.
    • getUri

      public String getUri()

      Returns the current active URI of webView.

      The active URI might change during a load operation:

      When nothing has been loaded yet on this WebView the active URI is `null`. When a new load operation starts the active URI is the requested URI: If the load operation was started by webkit_web_view_load_uri(), the requested URI is the given one. If the load operation was started by webkit_web_view_load_html(), the requested URI is "about:blank". If the load operation was started by webkit_web_view_load_alternate_html(), the requested URI is content URI provided. If the load operation was started by webkit_web_view_go_back() or webkit_web_view_go_forward(), the requested URI is the original URI of the previous/next item in the `WebKitBackForwardList` of `webView.` If the load operation was started by webkit_web_view_go_to_back_forward_list_item(), the requested URI is the opriginal URI of the given `WebKitBackForwardListItem`. If there is a server redirection during the load operation, the active URI is the redirected URI. When the signal `WebKitWebView`::load-changed is emitted with [org.webkitgtk.LoadEvent#REDIRECTED] event, the active URI is already updated to the redirected URI. When the signal `WebKitWebView`::load-changed is emitted with [org.webkitgtk.LoadEvent#COMMITTED] event, the active URI is the final one and it will not change unless a new load operation is started or a navigation action within the same page is performed.

      You can monitor the active URI by connecting to the notify::uri signal of webView.

      Returns:
      the current active URI of this WebView or null if nothing has been loaded yet.
    • getUserContentManager

      public UserContentManager getUserContentManager()
      Gets the user content manager associated to webView.
      Returns:
      the WebKitUserContentManager associated with the view
      Since:
      2.6
    • getWebExtensionMode

      public WebExtensionMode getWebExtensionMode()
      Get the view's WebKitWebExtensionMode.
      Returns:
      the WebKitWebExtensionMode
      Since:
      2.38
    • getWebsitePolicies

      public WebsitePolicies getWebsitePolicies()

      Gets the default website policies.

      Gets the default website policies set on construction in the webView. These can be overridden on a per-origin basis via the WebKitWebView::decide-policy signal handler.

      See also webkit_policy_decision_use_with_policies().

      Returns:
      the default WebKitWebsitePolicies associated with the view.
      Since:
      2.30
    • getWindowProperties

      public WindowProperties getWindowProperties()

      Get the WebKitWindowProperties object.

      Get the WebKitWindowProperties object containing the properties that the window containing this WebView should have.

      Returns:
      the WebKitWindowProperties of this WebView
    • getZoomLevel

      public double getZoomLevel()

      Set the zoom level of webView.

      Get the zoom level of webView, i.e. the factor by which the view contents are scaled with respect to their original size.

      Returns:
      the current zoom level of this WebView
    • goBack

      public void goBack()

      Loads the previous history item.

      You can monitor the load operation by connecting to WebKitWebView::load-changed signal.

    • goForward

      public void goForward()

      Loads the next history item.

      You can monitor the load operation by connecting to WebKitWebView::load-changed signal.

    • goToBackForwardListItem

      public void goToBackForwardListItem(BackForwardListItem listItem)

      Loads the specific history item listItem.

      You can monitor the load operation by connecting to WebKitWebView::load-changed signal.

      Parameters:
      listItem - a WebKitBackForwardListItem
    • isControlledByAutomation

      public boolean isControlledByAutomation()

      Get whether a WebKitWebView was created with WebKitWebView:is-controlled-by-automation property enabled.

      Only WebKitWebViews controlled by automation can be used in an automation session.

      Returns:
      true if this WebView is controlled by automation, or false otherwise.
      Since:
      2.18
    • isEditable

      public boolean isEditable()

      Gets whether the user is allowed to edit the HTML document.

      When this WebView is not editable an element in the HTML document can only be edited if the CONTENTEDITABLE attribute has been set on the element or one of its parent elements. By default a WebKitWebView is not editable.

      Returns:
      true if the user is allowed to edit the HTML document, or false otherwise.
      Since:
      2.8
    • isImmersiveModeEnabled

      public boolean isImmersiveModeEnabled()

      Gets whether this WebView is in immersive mode.

      An immersive session is a mode in which the user is presented with a fully immersive XR experience (such as VR or AR), typically rendered via a headset.

      Note that if WebXR is disabled or OPENXR is not used, this API always returns false.

      Returns:
      true if the this WebView is in immersive mode, or false otherwise.
      Since:
      2.52
    • isLoading

      public boolean isLoading()

      Gets the value of the WebKitWebView:is-loading property.

      You can monitor when a WebKitWebView is loading a page by connecting to notify::is-loading signal of webView. This is useful when you are interesting in knowing when the view is loading something but not in the details about the status of the load operation, for example to start a spinner when the view is loading a page and stop it when it finishes.

      Returns:
      true if this WebView is loading a page or false otherwise.
    • isPlayingAudio

      public boolean isPlayingAudio()

      Gets the value of the WebKitWebView:is-playing-audio property.

      You can monitor when a page in a WebKitWebView is playing audio by connecting to the notify::is-playing-audio signal of webView. This is useful when the application wants to provide visual feedback when a page is producing sound.

      Returns:
      true if a page in this WebView is playing audio or false otherwise.
      Since:
      2.8
    • leaveImmersiveMode

      public void leaveImmersiveMode()

      Requests to leave the immersive mode this WebKitWebView is in.

      Users interact with web content to start XR sessions, and can typically end the sessions themselves, but applications might need to end a session on their own based on application or platform logic.

      Note that if WebXR is disabled, or if it is enabled but the this WebView is not in immersive mode, this API does nothing. See also webkit_web_view_is_immersive_mode_enabled().

      Since:
      2.52
    • loadAlternateHtml

      public void loadAlternateHtml(String content, String contentUri, @Nullable String baseUri)

      Load the given content string for the URI contentUri.

      This allows clients to display page-loading errors in the WebKitWebView itself. When this method is called from WebKitWebView::load-failed signal to show an error page, then the back-forward list is maintained appropriately. For everything else this method works the same way as webkit_web_view_load_html().

      Parameters:
      content - the new content to display as the main page of the this WebView
      contentUri - the URI for the alternate page content
      baseUri - the base URI for relative locations or null
    • loadBytes

      public void loadBytes(byte[] bytes, @Nullable String mimeType, @Nullable String encoding, @Nullable String baseUri)

      Load the specified bytes into this WebView using the given mimeType and encoding.

      When mimeType is null, it defaults to "text/html". When encoding is null, it defaults to "UTF-8". When baseUri is null, it defaults to "about:blank". You can monitor the load operation by connecting to WebKitWebView::load-changed signal.

      Parameters:
      bytes - input data to load
      mimeType - the MIME type of bytes, or null
      encoding - the character encoding of bytes, or null
      baseUri - the base URI for relative locations or null
      Since:
      2.6
    • loadHtml

      public void loadHtml(String content, @Nullable String baseUri)

      Load the given content string with the specified baseUri.

      If baseUri is not null, relative URLs in the content will be resolved against baseUri and absolute local paths must be children of the baseUri. For security reasons absolute local paths that are not children of baseUri will cause the web process to terminate. If you need to include URLs in content that are local paths in a different directory than baseUri you can build a data URI for them. When baseUri is null, it defaults to "about:blank". The mime type of the document will be "text/html". You can monitor the load operation by connecting to WebKitWebView::load-changed signal.

      Parameters:
      content - The HTML string to load
      baseUri - The base URI for relative locations or null
    • loadPlainText

      public void loadPlainText(String plainText)

      Load the specified plainText string into webView.

      The mime type of document will be "text/plain". You can monitor the load operation by connecting to WebKitWebView::load-changed signal.

      Parameters:
      plainText - The plain text to load
    • loadRequest

      public void loadRequest(URIRequest request)

      Requests loading of the specified WebKitURIRequest.

      You can monitor the load operation by connecting to WebKitWebView::load-changed signal.

      Parameters:
      request - a WebKitURIRequest to load
    • loadUri

      public void loadUri(String uri)

      Requests loading of the specified URI string.

      You can monitor the load operation by connecting to WebKitWebView::load-changed signal.

      Parameters:
      uri - an URI string
    • reload

      public void reload()

      Reloads the current contents of webView.

      See also webkit_web_view_reload_bypass_cache().

    • reloadBypassCache

      public void reloadBypassCache()
      Reloads the current contents of this WebView without using any cached data.
    • restoreSessionState

      public void restoreSessionState(WebViewSessionState state)
      Restore the this WebView session state from state
      Parameters:
      state - a WebKitWebViewSessionState
      Since:
      2.12
    • save

      public void save(SaveMode saveMode, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback)

      Asynchronously save the current web page.

      Asynchronously save the current web page associated to the WebKitWebView into a self-contained format using the mode specified in saveMode.

      When the operation is finished, callback will be called. You can then call webkit_web_view_save_finish() to get the result of the operation.

      Parameters:
      saveMode - the WebKitSaveMode specifying how the web page should be saved.
      cancellable - a GCancellable or null to ignore
      callback - a GAsyncReadyCallback to call when the request is satisfied
    • saveFinish

      public InputStream saveFinish(AsyncResult result) throws GErrorException
      Finish an asynchronous operation started with webkit_web_view_save().
      Parameters:
      result - a GAsyncResult
      Returns:
      a GInputStream with the result of saving the current web page or null in case of error.
      Throws:
      GErrorException - see GError
    • saveToFile

      public void saveToFile(File file, SaveMode saveMode, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback)

      Asynchronously save the current web page.

      Asynchronously save the current web page associated to the WebKitWebView into a self-contained format using the mode specified in saveMode and writing it to file.

      When the operation is finished, callback will be called. You can then call webkit_web_view_save_to_file_finish() to get the result of the operation.

      Parameters:
      file - the GFile where the current web page should be saved to.
      saveMode - the WebKitSaveMode specifying how the web page should be saved.
      cancellable - a GCancellable or null to ignore
      callback - a GAsyncReadyCallback to call when the request is satisfied
    • saveToFileFinish

      public boolean saveToFileFinish(AsyncResult result) throws GErrorException
      Finish an asynchronous operation started with webkit_web_view_save_to_file().
      Parameters:
      result - a GAsyncResult
      Returns:
      true if the web page was successfully saved to a file or false otherwise.
      Throws:
      GErrorException - see GError
    • sendMessageToPage

      public void sendMessageToPage(UserMessage message, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback)

      Send message to the WebKitWebPage corresponding to webView.

      If message is floating, it's consumed. If you don't expect any reply, or you simply want to ignore it, you can pass null as callback. When the operation is finished, callback will be called. You can then call webkit_web_view_send_message_to_page_finish() to get the message reply.

      Parameters:
      message - a WebKitUserMessage
      cancellable - a GCancellable or null to ignore
      callback - (nullable): A GAsyncReadyCallback to call when the request is satisfied or null
      Since:
      2.28
    • sendMessageToPageFinish

      public UserMessage sendMessageToPageFinish(AsyncResult result) throws GErrorException
      Finish an asynchronous operation started with webkit_web_view_send_message_to_page().
      Parameters:
      result - a GAsyncResult
      Returns:
      a WebKitUserMessage with the reply or null in case of error.
      Throws:
      GErrorException - see GError
      Since:
      2.28
    • setBackgroundColor

      public void setBackgroundColor(RGBA rgba)

      Sets the color that will be used to draw the this WebView background.

      Sets the color that will be used to draw the this WebView background before the actual contents are rendered. Note that if the web page loaded in this WebView specifies a background color, it will take precedence over the rgba color. By default the this WebView background color is opaque white.

      Parameters:
      rgba - a GdkRGBA
      Since:
      2.8
    • setCameraCaptureState

      public void setCameraCaptureState(MediaCaptureState state)

      Set the camera capture state of a WebKitWebView.

      If WebKitSettings:enable-mediastream is false, this method will have no visible effect. Once the state of the device has been set to MediaCaptureState.NONE it cannot be changed anymore. The page can however request capture again using the mediaDevices API.

      Parameters:
      state - a WebKitMediaCaptureState
      Since:
      2.34
    • setCorsAllowlist

      public void setCorsAllowlist(@Nullable String @Nullable [] allowlist)

      Sets the allowlist for CORS.

      Sets the allowlist for which Cross-Origin Resource Sharing checks are disabled in webView. URI patterns must be of the form [protocol]://[host]/[path], each component may contain the wildcard character (*) to represent zero or more other characters. All three components are required and must not be omitted from the URI patterns.

      Disabling CORS checks permits resources from other origins to load allowlisted resources. It does not permit the allowlisted resources to load resources from other origins.

      If this function is called multiple times, only the allowlist set by the most recent call will be effective.

      Parameters:
      allowlist - an allowlist of URI patterns, or null
      Since:
      2.34
    • setCustomCharset

      public void setCustomCharset(@Nullable String charset)

      Sets the current custom character encoding override of webView.

      The custom character encoding will override any text encoding detected via HTTP headers or META tags. Calling this method will stop any current load operation and reload the current page. Setting the custom character encoding to null removes the character encoding override.

      Parameters:
      charset - a character encoding name or null
    • setDisplayCaptureState

      public void setDisplayCaptureState(MediaCaptureState state)

      Set the display capture state of a WebKitWebView.

      If WebKitSettings:enable-mediastream is false, this method will have no visible effect. Once the state of the device has been set to MediaCaptureState.NONE it cannot be changed anymore. The page can however request capture again using the mediaDevices API.

      Parameters:
      state - a WebKitMediaCaptureState
      Since:
      2.34
    • setEditable

      public void setEditable(boolean editable)

      Sets whether the user is allowed to edit the HTML document.

      If editable is true, this WebView allows the user to edit the HTML document. If editable is false, an element in webView's document can only be edited if the CONTENTEDITABLE attribute has been set on the element or one of its parent elements. By default a WebKitWebView is not editable.

      Normally, a HTML document is not editable unless the elements within the document are editable. This function provides a way to make the contents of a WebKitWebView editable without altering the document or DOM structure.

      Parameters:
      editable - a gboolean indicating the editable state
      Since:
      2.8
    • setInputMethodContext

      public void setInputMethodContext(@Nullable InputMethodContext context)

      Set the WebKitInputMethodContext to be used by webView.

      Set the WebKitInputMethodContext to be used by webView, or null to not use any input method. Note that the same WebKitInputMethodContext can't be set on more than one WebKitWebView at the same time.

      Parameters:
      context - the WebKitInputMethodContext to set, or null
      Since:
      2.28
    • setIsMuted

      public void setIsMuted(boolean muted)
      Sets the mute state of webView.
      Parameters:
      muted - mute flag
      Since:
      2.30
    • setMicrophoneCaptureState

      public void setMicrophoneCaptureState(MediaCaptureState state)

      Set the microphone capture state of a WebKitWebView.

      If WebKitSettings:enable-mediastream is false, this method will have no visible effect. Once the state of the device has been set to MediaCaptureState.NONE it cannot be changed anymore. The page can however request capture again using the mediaDevices API.

      Parameters:
      state - a WebKitMediaCaptureState
      Since:
      2.34
    • setSettings

      public void setSettings(Settings settings)

      Sets the WebKitSettings to be applied to webView.

      The existing WebKitSettings of this WebView will be replaced by settings. New settings are applied immediately on webView. The same WebKitSettings object can be shared by multiple WebKitWebViews.

      Parameters:
      settings - a WebKitSettings
    • setZoomLevel

      public void setZoomLevel(double zoomLevel)

      Set the zoom level of webView.

      Set the zoom level of webView, i.e. the factor by which the view contents are scaled with respect to their original size.

      Parameters:
      zoomLevel - the zoom level
    • stopLoading

      public void stopLoading()

      Stops any ongoing loading operation in webView.

      This method does nothing if no content is being loaded. If there is a loading operation in progress, it will be cancelled and WebKitWebView::load-failed signal will be emitted with NetworkError.CANCELLED error.

    • terminateWebProcess

      public void terminateWebProcess()

      Terminates the web process associated to webView.

      When the web process gets terminated using this method, the WebKitWebView::web-process-terminated signal is emitted with WebProcessTerminationReason.TERMINATED_BY_API as the reason for termination.

      Since:
      2.34
    • tryClose

      public void tryClose()

      Tries to close the webView.

      This will fire the onbeforeunload event to ask the user for confirmation to close the page. If there isn't an onbeforeunload event handler or the user confirms to close the page, the WebKitWebView::close signal is emitted, otherwise nothing happens.

      Since:
      2.12
    • authenticate

      protected boolean authenticate(AuthenticationRequest request)
    • close

      protected void close()
    • contextMenu

      protected boolean contextMenu(ContextMenu contextMenu, HitTestResult hitTestResult)
    • contextMenuDismissed

      protected void contextMenuDismissed()
    • create

      protected Widget create(NavigationAction navigationAction)
    • decidePolicy

      protected boolean decidePolicy(PolicyDecision decision, PolicyDecisionType type)
    • enterFullscreen

      protected boolean enterFullscreen()
    • insecureContentDetected

      protected void insecureContentDetected(InsecureContentEvent event)
    • leaveFullscreen

      protected boolean leaveFullscreen()
    • loadChanged

      protected void loadChanged(LoadEvent loadEvent)
    • loadFailed

      protected boolean loadFailed(LoadEvent loadEvent, String failingUri, GError error)
    • loadFailedWithTlsErrors

      protected boolean loadFailedWithTlsErrors(String failingUri, TlsCertificate certificate, Set<TlsCertificateFlags> errors)
    • mouseTargetChanged

      protected void mouseTargetChanged(HitTestResult hitTestResult, int modifiers)
    • permissionRequest

      protected boolean permissionRequest(PermissionRequest permissionRequest)
    • print

      protected boolean print(PrintOperation printOperation)
    • queryPermissionState

      protected boolean queryPermissionState(PermissionStateQuery query)
    • readyToShow

      protected void readyToShow()
    • resourceLoadStarted

      protected void resourceLoadStarted(WebResource resource, URIRequest request)
    • runAsModal

      protected void runAsModal()
    • runColorChooser

      protected boolean runColorChooser(ColorChooserRequest request)
    • runFileChooser

      protected boolean runFileChooser(FileChooserRequest request)
    • scriptDialog

      protected boolean scriptDialog(ScriptDialog dialog)
    • showNotification

      protected boolean showNotification(Notification notification)
    • showOptionMenu

      protected boolean showOptionMenu(OptionMenu menu, Rectangle rectangle)
    • submitForm

      protected void submitForm(FormSubmissionRequest request)
    • userMessageReceived

      protected boolean userMessageReceived(UserMessage message)
    • webProcessCrashed

      protected boolean webProcessCrashed()
    • webProcessTerminated

      protected void webProcessTerminated(WebProcessTerminationReason reason)
    • onAuthenticate

      This signal is emitted when the user is challenged with HTTP authentication. To let the application access or supply the credentials as well as to allow the client application to either cancel the request or perform the authentication, the signal will pass an instance of the WebKitAuthenticationRequest in the request argument. To handle this signal asynchronously you should keep a ref of the request and return true. To disable HTTP authentication entirely, connect to this signal and simply return true.

      The default signal handler will run a default authentication dialog asynchronously for the user to interact with.

      Parameters:
      handler - the signal handler
      Returns:
      a signal handler ID to keep track of the signal connection
      Since:
      2.2
      See Also:
    • emitAuthenticate

      public boolean emitAuthenticate(@Nullable AuthenticationRequest request)
      Emits the "authenticate" signal. See onAuthenticate(WebView.AuthenticateCallback).
    • onClose

      Emitted when closing a WebKitWebView is requested. This occurs when a call is made from JavaScript's window.close function or after trying to close the webView with webkit_web_view_try_close(). It is the owner's responsibility to handle this signal to hide or destroy the WebKitWebView, if necessary.
      Parameters:
      handler - the signal handler
      Returns:
      a signal handler ID to keep track of the signal connection
      See Also:
    • emitClose

      public void emitClose()
      Emits the "close" signal. See onClose(WebView.CloseCallback).
    • onContextMenu

      Emitted when a context menu is about to be displayed to give the application a chance to customize the proposed menu, prevent the menu from being displayed, or build its own context menu. To customize the proposed menu you can use webkit_context_menu_prepend(), webkit_context_menu_append() or webkit_context_menu_insert() to add new WebKitContextMenuItems to contextMenu, webkit_context_menu_move_item() to reorder existing items, or webkit_context_menu_remove() to remove an existing item. The signal handler should return false, and the menu represented by contextMenu will be shown. To prevent the menu from being displayed you can just connect to this signal and return true so that the proposed menu will not be shown. To build your own menu, you can remove all items from the proposed menu with webkit_context_menu_remove_all(), add your own items and return false so that the menu will be shown. You can also ignore the proposed WebKitContextMenu, build your own GtkMenu and return true to prevent the proposed menu from being shown. If you just want the default menu to be shown always, simply don't connect to this signal because showing the proposed context menu is the default behaviour.

      If the signal handler returns false the context menu represented by contextMenu will be shown, if it return true the context menu will not be shown.

      The proposed WebKitContextMenu passed in contextMenu argument is only valid during the signal emission.

      Parameters:
      handler - the signal handler
      Returns:
      a signal handler ID to keep track of the signal connection
      See Also:
    • emitContextMenu

      public boolean emitContextMenu(@Nullable ContextMenu contextMenu, @Nullable HitTestResult hitTestResult)
      Emits the "context-menu" signal. See onContextMenu(WebView.ContextMenuCallback).
    • onContextMenuDismissed

      Emitted after WebKitWebView::context-menu signal, if the context menu is shown, to notify that the context menu is dismissed.
      Parameters:
      handler - the signal handler
      Returns:
      a signal handler ID to keep track of the signal connection
      See Also:
    • emitContextMenuDismissed

      public void emitContextMenuDismissed()
      Emits the "context-menu-dismissed" signal. See onContextMenuDismissed(WebView.ContextMenuDismissedCallback).
    • onCreate

      Emitted when the creation of a new WebKitWebView is requested. If this signal is handled the signal handler should return the newly created WebKitWebView.

      The WebKitNavigationAction parameter contains information about the navigation action that triggered this signal.

      The new WebKitWebView must be related to webView, see WebKitWebView:related-view for more details.

      The new WebKitWebView should not be displayed to the user until the WebKitWebView::ready-to-show signal is emitted.

      For creating views as response to automation tools requests, see the WebKitAutomationSession::create-web-view signal.

      Parameters:
      handler - the signal handler
      Returns:
      a signal handler ID to keep track of the signal connection
      See Also:
    • emitCreate

      public Widget emitCreate(@Nullable NavigationAction navigationAction)
      Emits the "create" signal. See onCreate(WebView.CreateCallback).
    • onDecidePolicy

      This signal is emitted when WebKit is requesting the client to decide a policy decision, such as whether to navigate to a page, open a new window or whether or not to download a resource. The WebKitNavigationPolicyDecision passed in the decision argument is a generic type, but should be casted to a more specific type when making the decision. For example:

      static gboolean
      decide_policy_cb (WebKitWebView *web_view,
                        WebKitPolicyDecision *decision,
                        WebKitPolicyDecisionType type)
      {
          switch (type) {
          case WEBKIT_POLICY_DECISION_TYPE_NAVIGATION_ACTION: {
              WebKitNavigationPolicyDecision *navigation_decision = WEBKIT_NAVIGATION_POLICY_DECISION (decision);
              // Make a policy decision here
              break;
          }
          case WEBKIT_POLICY_DECISION_TYPE_NEW_WINDOW_ACTION: {
              WebKitNavigationPolicyDecision *navigation_decision = WEBKIT_NAVIGATION_POLICY_DECISION (decision);
              // Make a policy decision here
              break;
          }
          case WEBKIT_POLICY_DECISION_TYPE_RESPONSE:
              WebKitResponsePolicyDecision *response = WEBKIT_RESPONSE_POLICY_DECISION (decision);
              // Make a policy decision here
              break;
          default:
              // Making no decision results in webkit_policy_decision_use()
              return FALSE;
          }
          return TRUE;
      }
      

      It is possible to make policy decision asynchronously, by simply calling g_object_ref() on the decision argument and returning true to block the default signal handler. If the last reference is removed on a WebKitPolicyDecision and no decision has been made explicitly, webkit_policy_decision_use() will be the default policy decision. The default signal handler will simply call webkit_policy_decision_use(). Only the first policy decision chosen for a given WebKitPolicyDecision will have any affect.

      Parameters:
      handler - the signal handler
      Returns:
      a signal handler ID to keep track of the signal connection
      See Also:
    • emitDecidePolicy

      public boolean emitDecidePolicy(@Nullable PolicyDecision decision, PolicyDecisionType decisionType)
      Emits the "decide-policy" signal. See onDecidePolicy(WebView.DecidePolicyCallback).
    • onEnterFullscreen

      Emitted when JavaScript code calls element.webkitRequestFullScreen. If the signal is not handled the WebKitWebView will proceed to full screen its top level window. This signal can be used by client code to request permission to the user prior doing the full screen transition and eventually prepare the top-level window (e.g. hide some widgets that would otherwise be part of the full screen window).
      Parameters:
      handler - the signal handler
      Returns:
      a signal handler ID to keep track of the signal connection
      See Also:
    • emitEnterFullscreen

      public boolean emitEnterFullscreen()
      Emits the "enter-fullscreen" signal. See onEnterFullscreen(WebView.EnterFullscreenCallback).
    • onInsecureContentDetected

      Deprecated.
      Prior to 2.46, this signal was emitted when insecure content was loaded in a secure content. Since 2.46, this signal is generally no longer emitted.
      Parameters:
      handler - the signal handler
      Returns:
      a signal handler ID to keep track of the signal connection
      See Also:
    • emitInsecureContentDetected

      @Deprecated public void emitInsecureContentDetected(InsecureContentEvent event)
      Deprecated.
      Emits the "insecure-content-detected" signal. See onInsecureContentDetected(WebView.InsecureContentDetectedCallback).
    • onLeaveFullscreen

      Emitted when the WebKitWebView is about to restore its top level window out of its full screen state. This signal can be used by client code to restore widgets hidden during the WebKitWebView::enter-fullscreen stage for instance.
      Parameters:
      handler - the signal handler
      Returns:
      a signal handler ID to keep track of the signal connection
      See Also:
    • emitLeaveFullscreen

      public boolean emitLeaveFullscreen()
      Emits the "leave-fullscreen" signal. See onLeaveFullscreen(WebView.LeaveFullscreenCallback).
    • onLoadChanged

      Emitted when a load operation in webView changes. The signal is always emitted with LoadEvent.STARTED when a new load request is made and LoadEvent.FINISHED when the load finishes successfully or due to an error. When the ongoing load operation fails WebKitWebView::load-failed signal is emitted before WebKitWebView::load-changed is emitted with LoadEvent.FINISHED. If a redirection is received from the server, this signal is emitted with LoadEvent.REDIRECTED after the initial emission with LoadEvent.STARTED and before LoadEvent.COMMITTED. When the page content starts arriving the signal is emitted with LoadEvent.COMMITTED event.

      You can handle this signal and use a switch to track any ongoing load operation.

      static void web_view_load_changed (WebKitWebView  *web_view,
                                         WebKitLoadEvent load_event,
                                         gpointer        user_data)
      {
          switch (load_event) {
          case WEBKIT_LOAD_STARTED:
              // New load, we have now a provisional URI
              provisional_uri = webkit_web_view_get_uri (web_view);
              // Here we could start a spinner or update the
              // location bar with the provisional URI
              break;
          case WEBKIT_LOAD_REDIRECTED:
              redirected_uri = webkit_web_view_get_uri (web_view);
              break;
          case WEBKIT_LOAD_COMMITTED:
              // The load is being performed. Current URI is
              // the final one and it won't change unless a new
              // load is requested or a navigation within the
              // same page is performed
              uri = webkit_web_view_get_uri (web_view);
              break;
          case WEBKIT_LOAD_FINISHED:
              // Load finished, we can now stop the spinner
              break;
          }
      }
      
      Parameters:
      handler - the signal handler
      Returns:
      a signal handler ID to keep track of the signal connection
      See Also:
    • emitLoadChanged

      public void emitLoadChanged(LoadEvent loadEvent)
      Emits the "load-changed" signal. See onLoadChanged(WebView.LoadChangedCallback).
    • onLoadFailed

      Emitted when an error occurs during a load operation. If the error happened when starting to load data for a page loadEvent will be LoadEvent.STARTED. If it happened while loading a committed data source loadEvent will be LoadEvent.COMMITTED. Since a load error causes the load operation to finish, the signal WebKitWebView::load-changed will always be emitted with LoadEvent.FINISHED event right after this one.

      By default, if the signal is not handled, a stock error page will be displayed. You need to handle the signal if you want to provide your own error page.

      Parameters:
      handler - the signal handler
      Returns:
      a signal handler ID to keep track of the signal connection
      See Also:
    • emitLoadFailed

      public boolean emitLoadFailed(LoadEvent loadEvent, String failingUri, @Nullable GError error)
      Emits the "load-failed" signal. See onLoadFailed(WebView.LoadFailedCallback).
    • onLoadFailedWithTlsErrors

      Emitted when a TLS error occurs during a load operation. To allow an exception for this certificate and the host of failingUri use webkit_web_context_allow_tls_certificate_for_host().

      To handle this signal asynchronously you should call g_object_ref() on certificate and return true.

      If false is returned, WebKitWebView::load-failed will be emitted. The load will finish regardless of the returned value.

      Parameters:
      handler - the signal handler
      Returns:
      a signal handler ID to keep track of the signal connection
      Since:
      2.6
      See Also:
    • emitLoadFailedWithTlsErrors

      public boolean emitLoadFailedWithTlsErrors(String failingUri, @Nullable TlsCertificate certificate, Set<TlsCertificateFlags> errors)
      Emits the "load-failed-with-tls-errors" signal. See onLoadFailedWithTlsErrors(WebView.LoadFailedWithTlsErrorsCallback).
    • onMouseTargetChanged

      This signal is emitted when the mouse cursor moves over an element such as a link, image or a media element. To determine what type of element the mouse cursor is over, a Hit Test is performed on the current mouse coordinates and the result is passed in the hitTestResult argument. The modifiers argument is a bitmask of GdkModifierType flags indicating the state of modifier keys. The signal is emitted again when the mouse is moved out of the current element with a new hitTestResult.
      Parameters:
      handler - the signal handler
      Returns:
      a signal handler ID to keep track of the signal connection
      See Also:
    • emitMouseTargetChanged

      public void emitMouseTargetChanged(@Nullable HitTestResult hitTestResult, int modifiers)
      Emits the "mouse-target-changed" signal. See onMouseTargetChanged(WebView.MouseTargetChangedCallback).
    • onPermissionRequest

      This signal is emitted when WebKit is requesting the client to decide about a permission request, such as allowing the browser to switch to fullscreen mode, sharing its location or similar operations.

      A possible way to use this signal could be through a dialog allowing the user decide what to do with the request:

      static gboolean permission_request_cb (WebKitWebView *web_view,
                                             WebKitPermissionRequest *request,
                                             GtkWindow *parent_window)
      {
          GtkWidget *dialog = gtk_message_dialog_new (parent_window,
                                                      GTK_DIALOG_MODAL,
                                                      GTK_MESSAGE_QUESTION,
                                                      GTK_BUTTONS_YES_NO,
                                                      "Allow Permission Request?");
          gtk_widget_show (dialog);
          gint result = gtk_dialog_run (GTK_DIALOG (dialog));
      
          switch (result) {
          case GTK_RESPONSE_YES:
              webkit_permission_request_allow (request);
              break;
          default:
              webkit_permission_request_deny (request);
              break;
          }
          gtk_widget_destroy (dialog);
      
          return TRUE;
      }
      

      It is possible to handle permission requests asynchronously, by simply calling g_object_ref() on the request argument and returning true to block the default signal handler. If the last reference is removed on a WebKitPermissionRequest and the request has not been handled, webkit_permission_request_deny() will be the default action.

      If the signal is not handled, the request will be completed automatically by the specific WebKitPermissionRequest that could allow or deny it. Check the documentation of classes implementing WebKitPermissionRequest interface to know their default action.

      Parameters:
      handler - the signal handler
      Returns:
      a signal handler ID to keep track of the signal connection
      See Also:
    • emitPermissionRequest

      public boolean emitPermissionRequest(@Nullable PermissionRequest request)
      Emits the "permission-request" signal. See onPermissionRequest(WebView.PermissionRequestCallback).
    • onPrint

      Emitted when printing is requested on webView, usually by a JavaScript call, before the print dialog is shown. This signal can be used to set the initial print settings and page setup of printOperation to be used as default values in the print dialog. You can call webkit_print_operation_set_print_settings() and webkit_print_operation_set_page_setup() and then return false to propagate the event so that the print dialog is shown.

      You can connect to this signal and return true to cancel the print operation or implement your own print dialog.

      Parameters:
      handler - the signal handler
      Returns:
      a signal handler ID to keep track of the signal connection
      See Also:
    • emitPrint

      public boolean emitPrint(@Nullable PrintOperation printOperation)
      Emits the "print" signal. See onPrint(WebView.PrintCallback).
    • onQueryPermissionState

      This signal allows the User-Agent to respond to permission requests for powerful features, as specified by the Permissions W3C Specification. You can reply to the query using webkit_permission_state_query_finish().

      You can handle the query asynchronously by calling webkit_permission_state_query_ref() on query and returning true. If the last reference of query is removed and the query has not been handled, the query result will be set to WEBKIT_QUERY_PERMISSION_PROMPT.

      Parameters:
      handler - the signal handler
      Returns:
      a signal handler ID to keep track of the signal connection
      Since:
      2.40
      See Also:
    • emitQueryPermissionState

      public boolean emitQueryPermissionState(@Nullable PermissionStateQuery query)
      Emits the "query-permission-state" signal. See onQueryPermissionState(WebView.QueryPermissionStateCallback).
    • onReadyToShow

      Emitted after WebKitWebView::create on the newly created WebKitWebView when it should be displayed to the user. When this signal is emitted all the information about how the window should look, including size, position, whether the location, status and scrollbars should be displayed, is already set on the WebKitWindowProperties of webView. See also webkit_web_view_get_window_properties().
      Parameters:
      handler - the signal handler
      Returns:
      a signal handler ID to keep track of the signal connection
      See Also:
    • emitReadyToShow

      public void emitReadyToShow()
      Emits the "ready-to-show" signal. See onReadyToShow(WebView.ReadyToShowCallback).
    • onResourceLoadStarted

      Emitted when a new resource is going to be loaded. The request parameter contains the WebKitURIRequest that will be sent to the server. You can monitor the load operation by connecting to the different signals of resource.
      Parameters:
      handler - the signal handler
      Returns:
      a signal handler ID to keep track of the signal connection
      See Also:
    • emitResourceLoadStarted

      public void emitResourceLoadStarted(@Nullable WebResource resource, @Nullable URIRequest request)
      Emits the "resource-load-started" signal. See onResourceLoadStarted(WebView.ResourceLoadStartedCallback).
    • onRunAsModal

      Emitted after WebKitWebView::ready-to-show on the newly created WebKitWebView when JavaScript code calls window.showModalDialog. The purpose of this signal is to allow the client application to prepare the new view to behave as modal. Once the signal is emitted a new main loop will be run to block user interaction in the parent WebKitWebView until the new dialog is closed.
      Parameters:
      handler - the signal handler
      Returns:
      a signal handler ID to keep track of the signal connection
      See Also:
    • emitRunAsModal

      public void emitRunAsModal()
      Emits the "run-as-modal" signal. See onRunAsModal(WebView.RunAsModalCallback).
    • onRunColorChooser

      This signal is emitted when the user interacts with a HTML element, requesting from WebKit to show a dialog to select a color. To let the application know the details of the color chooser, as well as to allow the client application to either cancel the request or perform an actual color selection, the signal will pass an instance of the WebKitColorChooserRequest in the request argument.

      It is possible to handle this request asynchronously by increasing the reference count of the request.

      The default signal handler will asynchronously run a regular GtkColorChooser for the user to interact with.

      Parameters:
      handler - the signal handler
      Returns:
      a signal handler ID to keep track of the signal connection
      Since:
      2.8
      See Also:
    • emitRunColorChooser

      public boolean emitRunColorChooser(@Nullable ColorChooserRequest request)
      Emits the "run-color-chooser" signal. See onRunColorChooser(WebView.RunColorChooserCallback).
    • onRunFileChooser

      This signal is emitted when the user interacts with a HTML element, requesting from WebKit to show a dialog to select one or more files to be uploaded. To let the application know the details of the file chooser, as well as to allow the client application to either cancel the request or perform an actual selection of files, the signal will pass an instance of the WebKitFileChooserRequest in the request argument.

      The default signal handler will asynchronously run a regular GtkFileChooserDialog for the user to interact with.

      Parameters:
      handler - the signal handler
      Returns:
      a signal handler ID to keep track of the signal connection
      See Also:
    • emitRunFileChooser

      public boolean emitRunFileChooser(@Nullable FileChooserRequest request)
      Emits the "run-file-chooser" signal. See onRunFileChooser(WebView.RunFileChooserCallback).
    • onScriptDialog

      Emitted when JavaScript code calls window.alert, window.confirm or window.prompt, or when onbeforeunload event is fired. The dialog parameter should be used to build the dialog. If the signal is not handled a different dialog will be built and shown depending on the dialog type: ScriptDialogType.ALERT: message dialog with a single Close button. ScriptDialogType.CONFIRM: message dialog with OK and Cancel buttons. ScriptDialogType.PROMPT: message dialog with OK and Cancel buttons and a text entry with the default text. ScriptDialogType.BEFORE_UNLOAD_CONFIRM: message dialog with Stay and Leave buttons.

      It is possible to handle the script dialog request asynchronously, by simply caling webkit_script_dialog_ref() on the dialog argument and calling webkit_script_dialog_close() when done. If the last reference is removed on a WebKitScriptDialog and the dialog has not been closed, webkit_script_dialog_close() will be called.

      Parameters:
      handler - the signal handler
      Returns:
      a signal handler ID to keep track of the signal connection
      See Also:
    • emitScriptDialog

      public boolean emitScriptDialog(@Nullable ScriptDialog dialog)
      Emits the "script-dialog" signal. See onScriptDialog(WebView.ScriptDialogCallback).
    • onShowNotification

      This signal is emitted when a notification should be presented to the user. The notification is kept alive until either: 1) the web page cancels it or 2) a navigation happens.

      The default handler will emit a notification using libnotify, if built with support for it.

      Parameters:
      handler - the signal handler
      Returns:
      a signal handler ID to keep track of the signal connection
      Since:
      2.8
      See Also:
    • emitShowNotification

      public boolean emitShowNotification(@Nullable Notification notification)
      Emits the "show-notification" signal. See onShowNotification(WebView.ShowNotificationCallback).
    • onShowOptionMenu

      This signal is emitted when a select element in webView needs to display a dropdown menu. This signal can be used to show a custom menu, using menu to get the details of all items that should be displayed. The area of the element in the WebKitWebView is given as rectangle parameter, it can be used to position the menu. To handle this signal asynchronously you should keep a ref of the menu.

      The default signal handler will pop up a GtkMenu.

      Parameters:
      handler - the signal handler
      Returns:
      a signal handler ID to keep track of the signal connection
      Since:
      2.18
      See Also:
    • emitShowOptionMenu

      public boolean emitShowOptionMenu(@Nullable OptionMenu menu, @Nullable Rectangle rectangle)
      Emits the "show-option-menu" signal. See onShowOptionMenu(WebView.ShowOptionMenuCallback).
    • onSubmitForm

      This signal is emitted when a form is about to be submitted. The request argument passed contains information about the text fields of the form. This is typically used to store login information that can be used later to pre-fill the form. The form will not be submitted until webkit_form_submission_request_submit() is called.

      It is possible to handle the form submission request asynchronously, by simply calling g_object_ref() on the request argument and calling webkit_form_submission_request_submit() when done to continue with the form submission. If the last reference is removed on a WebKitFormSubmissionRequest and the form has not been submitted, webkit_form_submission_request_submit() will be called.

      Parameters:
      handler - the signal handler
      Returns:
      a signal handler ID to keep track of the signal connection
      See Also:
    • emitSubmitForm

      public void emitSubmitForm(@Nullable FormSubmissionRequest request)
      Emits the "submit-form" signal. See onSubmitForm(WebView.SubmitFormCallback).
    • onUserMessageReceived

      This signal is emitted when a WebKitUserMessage is received from the WebKitWebPage corresponding to webView. You can reply to the message using webkit_user_message_send_reply().

      You can handle the user message asynchronously by calling g_object_ref() on message and returning true. If the last reference of message is removed and the message has not been replied to, the operation in the WebKitWebPage will finish with error UserMessageError.USER_MESSAGE_UNHANDLED_MESSAGE.

      Parameters:
      handler - the signal handler
      Returns:
      a signal handler ID to keep track of the signal connection
      Since:
      2.28
      See Also:
    • emitUserMessageReceived

      public boolean emitUserMessageReceived(@Nullable UserMessage message)
      Emits the "user-message-received" signal. See onUserMessageReceived(WebView.UserMessageReceivedCallback).
    • onWebProcessTerminated

      This signal is emitted when the web process terminates abnormally due to reason.
      Parameters:
      handler - the signal handler
      Returns:
      a signal handler ID to keep track of the signal connection
      Since:
      2.20
      See Also:
    • emitWebProcessTerminated

      public void emitWebProcessTerminated(WebProcessTerminationReason reason)
      Emits the "web-process-terminated" signal. See onWebProcessTerminated(WebView.WebProcessTerminatedCallback).
    • builder

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