Class NetworkSession

All Implemented Interfaces:
Proxy

@Generated("org.javagi.JavaGI") public final class NetworkSession extends GObject
Manages network configuration.
Since:
2.40
  • Constructor Details

    • NetworkSession

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

      public NetworkSession(@Nullable String dataDirectory, @Nullable String cacheDirectory)

      Creates a new WebKitNetworkSession with a persistent WebKitWebsiteDataManager. The parameters dataDirectory and cacheDirectory will be used as construct properties of the WebKitWebsiteDataManager of the network session. Note that if null is passed, the default directory will be passed to WebKitWebsiteDataManager so that webkit_website_data_manager_get_base_data_directory() and webkit_website_data_manager_get_base_cache_directory() always return a value for non ephemeral sessions.

      It must be passed as construct parameter of a WebKitWebView.

      Parameters:
      dataDirectory - a base directory for data, or null
      cacheDirectory - a base directory for caches, or null
      Since:
      2.40
    • NetworkSession

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

    • getType

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

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

      protected NetworkSession 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
    • ephemeral

      public static NetworkSession ephemeral()
      Creates a new WebKitNetworkSession with an ephemeral WebKitWebsiteDataManager.
      Returns:
      a new ephemeral WebKitNetworkSession.
      Since:
      2.40
    • getDefault

      public static NetworkSession getDefault()
      Get the default network session. The default network session is created using webkit_network_session_new() and passing null as data and cache directories.
      Returns:
      a WebKitNetworkSession
      Since:
      2.40
    • setMemoryPressureSettings

      public static void setMemoryPressureSettings(MemoryPressureSettings settings)

      Sets settings as the WebKitMemoryPressureSettings.

      Sets settings as the WebKitMemoryPressureSettings to be used by the network process created by any instance of WebKitNetworkSession after this function is called.

      Be sure to call this function before creating any WebKitNetworkSession.

      The periodic check for used memory is disabled by default on network processes. This will be enabled only if custom settings have been set using this function. After that, in order to remove the custom settings and disable the periodic check, this function must be called passing null as the value of settings.

      Parameters:
      settings - a WebKitMemoryPressureSettings.
      Since:
      2.40
    • allowTlsCertificateForHost

      public void allowTlsCertificateForHost(TlsCertificate certificate, String host)

      Ignore further TLS errors on the host for the certificate present in info.

      If host is an IPv6 address, it should not be surrounded by brackets. This expectation matches g_uri_get_host().

      Parameters:
      certificate - a GTlsCertificate
      host - the host for which a certificate is to be allowed
      Since:
      2.40
    • downloadUri

      public Download downloadUri(String uri)

      Requests downloading of the specified URI string.

      The download operation will not be associated to any WebKitWebView, if you are interested in starting a download from a particular WebKitWebView use webkit_web_view_download_uri() instead.

      Parameters:
      uri - the URI to download
      Returns:
      a new WebKitDownload representing the download operation.
      Since:
      2.40
    • getCookieManager

      public CookieManager getCookieManager()
      Get the WebKitCookieManager of session.
      Returns:
      a WebKitCookieManager
      Since:
      2.40
    • getItpEnabled

      public boolean getItpEnabled()
      Get whether Intelligent Tracking Prevention (ITP) is enabled or not.
      Returns:
      true if ITP is enabled, or false otherwise.
      Since:
      2.40
    • getItpSummary

      public void getItpSummary(@Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback)

      Asynchronously get the list of WebKitITPThirdParty seen for session.

      Every WebKitITPThirdParty contains the list of WebKitITPFirstParty under which it has been seen.

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

      Parameters:
      cancellable - a GCancellable or null to ignore
      callback - a GAsyncReadyCallback to call when the request is satisfied
      Since:
      2.40
    • getItpSummaryFinish

      public List<ITPThirdParty> getItpSummaryFinish(AsyncResult result) throws GErrorException
      Finish an asynchronous operation started with webkit_network_session_get_itp_summary().
      Parameters:
      result - a GAsyncResult
      Returns:
      a GList of WebKitITPThirdParty. You must free the GList with g_list_free() and unref the WebKitITPThirdPartys with webkit_itp_third_party_unref() when you're done with them.
      Throws:
      GErrorException - see GError
      Since:
      2.40
    • getPersistentCredentialStorageEnabled

      public boolean getPersistentCredentialStorageEnabled()

      Get whether persistent credential storage is enabled or not.

      See also webkit_network_session_set_persistent_credential_storage_enabled().

      Returns:
      true if persistent credential storage is enabled, or false otherwise.
      Since:
      2.40
    • getTlsErrorsPolicy

      public TLSErrorsPolicy getTlsErrorsPolicy()
      Get the TLS errors policy of session.
      Returns:
      a WebKitTLSErrorsPolicy
      Since:
      2.40
    • getWebsiteDataManager

      public WebsiteDataManager getWebsiteDataManager()
      Get the WebKitWebsiteDataManager of session.
      Returns:
      a WebKitWebsiteDataManager
      Since:
      2.40
    • isEphemeral

      public boolean isEphemeral()
      Get whether this NetworkSession is ephemeral. A WebKitNetworkSession is ephemeral when its WebKitWebsiteDataManager is ephemeral. See WebKitWebsiteDataManager:is-ephemeral for more details.
      Returns:
      true if this NetworkSession is pehmeral, or false otherwise
      Since:
      2.40
    • prefetchDns

      public void prefetchDns(String hostname)
      Resolve the domain name of the given hostname in advance, so that if a URI of hostname is requested the load will be performed more quickly.
      Parameters:
      hostname - a hostname to be resolved
      Since:
      2.40
    • setItpEnabled

      public void setItpEnabled(boolean enabled)

      Enable or disable Intelligent Tracking Prevention (ITP).

      When ITP is enabled resource load statistics are collected and used to decide whether to allow or block third-party cookies and prevent user tracking. Note that while ITP is enabled the accept policy CookieAcceptPolicy.NO_THIRD_PARTY is ignored and CookieAcceptPolicy.ALWAYS is used instead. See also webkit_cookie_session_set_accept_policy().

      Parameters:
      enabled - value to set
      Since:
      2.40
    • setPersistentCredentialStorageEnabled

      public void setPersistentCredentialStorageEnabled(boolean enabled)

      Enable or disable persistent credential storage.

      When enabled, which is the default for non-ephemeral sessions, the network process will try to read and write HTTP authentiacation credentials from persistent storage.

      Parameters:
      enabled - value to set
      Since:
      2.40
    • setProxySettings

      public void setProxySettings(NetworkProxyMode proxyMode, @Nullable NetworkProxySettings proxySettings)

      Set the network proxy settings to be used by connections started in this NetworkSession session.

      By default NetworkProxyMode.DEFAULT is used, which means that the system settings will be used (g_proxy_resolver_get_default()). If you want to override the system default settings, you can either use NetworkProxyMode.NO_PROXY to make sure no proxies are used at all, or NetworkProxyMode.CUSTOM to provide your own proxy settings. When proxyMode is NetworkProxyMode.CUSTOM proxySettings must be a valid WebKitNetworkProxySettings; otherwise, proxySettings must be null.

      Parameters:
      proxyMode - a WebKitNetworkProxyMode
      proxySettings - a WebKitNetworkProxySettings, or null
      Since:
      2.40
    • setTlsErrorsPolicy

      public void setTlsErrorsPolicy(TLSErrorsPolicy policy)
      Set the TLS errors policy of this NetworkSession as policy.
      Parameters:
      policy - a WebKitTLSErrorsPolicy
      Since:
      2.40
    • onDownloadStarted

      This signal is emitted when a new download request is made.
      Parameters:
      handler - the signal handler
      Returns:
      a signal handler ID to keep track of the signal connection
      Since:
      2.40
      See Also:
    • emitDownloadStarted

      public void emitDownloadStarted(@Nullable Download download)
      Emits the "download-started" signal. See onDownloadStarted(NetworkSession.DownloadStartedCallback).
    • builder

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