Class GeckoSession.Loader

Object
org.mozilla.geckoview.GeckoSession.Loader
Enclosing class:
GeckoSession

@AnyThread public static class GeckoSession.Loader extends Object
Main entry point for loading URIs into a GeckoSession.

The simplest use case is loading a URIs with no extra options, this can be accomplished by specifying the URI in uri(java.lang.String) and then calling GeckoSession.load(org.mozilla.geckoview.GeckoSession.Loader), e.g.


     session.load(new Loader().uri("http://mozilla.org"));
 
This class can also be used to load data: URIs, either from a byte[] array or a String using data(byte[], java.lang.String), e.g.

     session.load(new Loader().data("the data:1234,5678", "text/plain"));
 
This class also allows you to specify some extra data, e.g. you can set a referrer using referrer(org.mozilla.geckoview.GeckoSession) which can either be a GeckoSession or a plain URL string. You can also specify some Load Flags using flags(int).

The class is structured as a Builder, so method calls can be easily chained, e.g.


     session.load(new Loader()
          .url("http://mozilla.org")
          .referrer("http://my-referrer.com")
          .flags(...));
 
  • Constructor Details

    • Loader

      public Loader()
  • Method Details

    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(@Nullable Object obj)
      Overrides:
      equals in class Object
    • uri

      @NonNull public GeckoSession.Loader uri(@NonNull String uri)
      Set the URI of the resource to load.
      Parameters:
      uri - a String containg the URI
      Returns:
      this GeckoSession.Loader instance.
    • uri

      @NonNull public GeckoSession.Loader uri(@NonNull Uri uri)
      Set the URI of the resource to load.
      Parameters:
      uri - a Uri instance
      Returns:
      this GeckoSession.Loader instance.
    • data

      @NonNull public GeckoSession.Loader data(@NonNull byte[] bytes, @Nullable String mimeType)
      Set the data URI of the resource to load.
      Parameters:
      bytes - a byte array containing the data to load.
      mimeType - a String containing the mime type for this data URI, e.g. "text/plain"
      Returns:
      this GeckoSession.Loader instance.
    • data

      @NonNull public GeckoSession.Loader data(@NonNull String data, @Nullable String mimeType)
      Set the data URI of the resource to load.
      Parameters:
      data - a String array containing the data to load.
      mimeType - a String containing the mime type for this data URI, e.g. "text/plain"
      Returns:
      this GeckoSession.Loader instance.
    • referrer

      @NonNull public GeckoSession.Loader referrer(@NonNull GeckoSession referrer)
      Set the referrer for this load.
      Parameters:
      referrer - a GeckoSession that will be used as the referrer
      Returns:
      this GeckoSession.Loader instance.
    • referrer

      @NonNull public GeckoSession.Loader referrer(@NonNull Uri referrerUri)
      Set the referrer for this load.
      Parameters:
      referrerUri - a Uri that will be used as the referrer
      Returns:
      this GeckoSession.Loader instance.
    • referrer

      @NonNull public GeckoSession.Loader referrer(@NonNull String referrerUri)
      Set the referrer for this load.
      Parameters:
      referrerUri - a String containing the URI that will be used as the referrer
      Returns:
      this GeckoSession.Loader instance.
    • additionalHeaders

      @NonNull public GeckoSession.Loader additionalHeaders(@NonNull Map<String,String> headers)
      Add headers for this load.

      Note: only CORS safelisted headers are allowed by default. To modify this behavior use headerFilter(int).

      See CORS-safelisted request header .

      Parameters:
      headers - a Map containing headers that will be added to this load.
      Returns:
      this GeckoSession.Loader instance.
    • headerFilter

      @NonNull public GeckoSession.Loader headerFilter(int filter)
      Modify the header filter behavior. By default only CORS safelisted headers are allowed.
      Parameters:
      filter - one of the HEADER_FILTER_* constants.
      Returns:
      this GeckoSession.Loader instance.
    • flags

      @NonNull public GeckoSession.Loader flags(int flags)
      Set the load flags for this load.
      Parameters:
      flags - the load flags to use, an OR-ed value of LOAD_FLAGS_* that will be used as the referrer
      Returns:
      this GeckoSession.Loader instance.