Class CookieManager

All Implemented Interfaces:
Proxy

@Generated("org.javagi.JavaGI") public final class CookieManager extends GObject

Defines how to handle cookies in a WebKitWebContext.

The WebKitCookieManager defines how to set up and handle cookies. You can get it from a WebKitWebsiteDataManager with webkit_website_data_manager_get_cookie_manager(), and use it to set where to store cookies with webkit_cookie_manager_set_persistent_storage(), or to set the acceptance policy, with webkit_cookie_manager_get_accept_policy().

  • Constructor Details

    • CookieManager

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

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

    • getType

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

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

      protected CookieManager 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
    • addCookie

      public void addCookie(Cookie cookie, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback)

      Asynchronously add a SoupCookie to the underlying storage.

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

      Parameters:
      cookie - the SoupCookie to be added
      cancellable - a GCancellable or null to ignore
      callback - a GAsyncReadyCallback to call when the request is satisfied
      Since:
      2.20
    • addCookieFinish

      public boolean addCookieFinish(AsyncResult result) throws GErrorException
      Finish an asynchronous operation started with webkit_cookie_manager_add_cookie().
      Parameters:
      result - a GAsyncResult
      Returns:
      true if the cookie was added or false in case of error.
      Throws:
      GErrorException - see GError
      Since:
      2.20
    • deleteCookie

      public void deleteCookie(Cookie cookie, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback)

      Asynchronously delete a SoupCookie from the current session.

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

      Parameters:
      cookie - the SoupCookie to be deleted
      cancellable - a GCancellable or null to ignore
      callback - a GAsyncReadyCallback to call when the request is satisfied
      Since:
      2.20
    • deleteCookieFinish

      public boolean deleteCookieFinish(AsyncResult result) throws GErrorException
      Finish an asynchronous operation started with webkit_cookie_manager_delete_cookie().
      Parameters:
      result - a GAsyncResult
      Returns:
      true if the cookie was deleted or false in case of error.
      Throws:
      GErrorException - see GError
      Since:
      2.20
    • getAcceptPolicy

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

      Asynchronously get the cookie acceptance policy of cookieManager.

      Note that when policy was set to CookieAcceptPolicy.NO_THIRD_PARTY and ITP is enabled, this will return CookieAcceptPolicy.ALWAYS. See also webkit_website_data_manager_set_itp_enabled().

      When the operation is finished, callback will be called. You can then call webkit_cookie_manager_get_accept_policy_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
    • getAcceptPolicyFinish

      public CookieAcceptPolicy getAcceptPolicyFinish(AsyncResult result) throws GErrorException
      Finish an asynchronous operation started with webkit_cookie_manager_get_accept_policy().
      Parameters:
      result - a GAsyncResult
      Returns:
      the cookie acceptance policy of this CookieManager as a WebKitCookieAcceptPolicy.
      Throws:
      GErrorException - see GError
    • getAllCookies

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

      Asynchronously get a list of SoupCookie from cookieManager.

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

      Parameters:
      cancellable - a GCancellable or null to ignore
      callback - (closure user_data): a GAsyncReadyCallback to call when the request is satisfied
      Since:
      2.42
    • getAllCookiesFinish

      public List<Cookie> getAllCookiesFinish(AsyncResult result) throws GErrorException

      Finish an asynchronous operation started with webkit_cookie_manager_get_all_cookies().

      The return value is a GList of SoupCookie instances which should be released with g_list_free_full() and soup_cookie_free().

      Parameters:
      result - a GAsyncResult
      Returns:
      A GList of SoupCookie instances.
      Throws:
      GErrorException - see GError
      Since:
      2.42
    • getCookies

      public void getCookies(String uri, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback)

      Asynchronously get a list of SoupCookie from cookieManager.

      Asynchronously get a list of SoupCookie from this CookieManager associated with uri, which must be either an HTTP or an HTTPS URL.

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

      Parameters:
      uri - the URI associated to the cookies to be retrieved
      cancellable - a GCancellable or null to ignore
      callback - a GAsyncReadyCallback to call when the request is satisfied
      Since:
      2.20
    • getCookiesFinish

      public List<Cookie> getCookiesFinish(AsyncResult result) throws GErrorException

      Finish an asynchronous operation started with webkit_cookie_manager_get_cookies().

      The return value is a GList of SoupCookie instances which should be released with g_list_free_full() and soup_cookie_free().

      Parameters:
      result - a GAsyncResult
      Returns:
      A GList of SoupCookie instances.
      Throws:
      GErrorException - see GError
      Since:
      2.20
    • replaceCookies

      public void replaceCookies(List<Cookie> cookies, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback)

      Asynchronously replace all cookies in this CookieManager with the given list of cookies.

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

      Parameters:
      cookies - a GList of SoupCookie to be added
      cancellable - a GCancellable or null to ignore
      callback - (closure user_data): a GAsyncReadyCallback to call when the request is satisfied
      Since:
      2.42
    • replaceCookiesFinish

      public boolean replaceCookiesFinish(AsyncResult result) throws GErrorException
      Finish an asynchronous operation started with webkit_cookie_manager_replace_cookies().
      Parameters:
      result - a GAsyncResult
      Returns:
      true if the cookies were added or false in case of error.
      Throws:
      GErrorException - see GError
      Since:
      2.42
    • setAcceptPolicy

      public void setAcceptPolicy(CookieAcceptPolicy policy)

      Set the cookie acceptance policy of this CookieManager as policy.

      Note that ITP has its own way to handle third-party cookies, so when it's enabled, and policy is set to CookieAcceptPolicy.NO_THIRD_PARTY, CookieAcceptPolicy.ALWAYS will be used instead. Once disabled, the policy will be set back to CookieAcceptPolicy.NO_THIRD_PARTY. See also webkit_website_data_manager_set_itp_enabled().

      Parameters:
      policy - a WebKitCookieAcceptPolicy
    • setPersistentStorage

      public void setPersistentStorage(String filename, CookiePersistentStorage storage)

      Set non-session cookies.

      Set the filename where non-session cookies are stored persistently using storage as the format to read/write the cookies. Cookies are initially read from filename to create an initial set of cookies. Then, non-session cookies will be written to filename when the WebKitCookieManager::changed signal is emitted. By default, this CookieManager doesn't store the cookies persistently, so you need to call this method to keep cookies saved across sessions.

      This method should never be called on a WebKitCookieManager associated to an ephemeral WebKitWebsiteDataManager.

      Parameters:
      filename - the filename to read to/write from
      storage - a WebKitCookiePersistentStorage
    • onChanged

      This signal is emitted when cookies are added, removed or modified.
      Parameters:
      handler - the signal handler
      Returns:
      a signal handler ID to keep track of the signal connection
      See Also:
    • emitChanged

      public void emitChanged()
      Emits the "changed" signal. See onChanged(CookieManager.ChangedCallback).
    • builder

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