Hi All,
As you might have noticed, the GeckoSession#loadUri
API has grown in number of arguments, and we don’t really have a reason to believe that we won’t add more arguments in the future.
To make the API more ergonomic I’m proposing that we move the API to a builder-like API.
For example, a load call that today is written as
session.loadUri(
"https://mywebsite.com/...",
"http://my-referrer.com",
LOAD_FLAGS_NONE,
additionalHeaders);
would be written as
session.loader()
.url("https://mywebsite.com/...")
.referrer("http://my-referrer.com")
.flags(LOAD_FLAGS_NONE)
.additionalHeaders(headers)
.load();
This API change will follow the usual deprecation period of 3 releases before being removed completely.
What follows is the docs for the new API, please let me know if you have any concerns or comments.
Main entry point for loading URIs into a {@link GeckoSession}.
The simplest use case is loading a URIs with no extra options, this can
be accomplished by specifying the URI in {@link #uri} and then calling
{@link #load}, e.g.session.loader().uri("http://mozilla.org").load();
This class can also be used to load
data:
URIs, either from
abyte[]
array or aString
using {@link
#data}, e.g.session.loader().data("the data:1234,5678", "text/plain").load();
This class also allows you to specify some extra data, e.g. you can set
a referrer using {@link #referrer} which can either be a {@link
GeckoSession} or a plain URL string. You can also specify some Load
Flags using {@link #flags}.The class is structured as a Builder, so method calls can be easily
chained, e.g.session.loader() .url("http://mozilla.org") .referrer("http://my-referrer.com") .flags(...) .load();