This patch makes code use the application context from GeckoAppShell
instead of the activity context. Enough changes are made to let headless
mode work.
When we queue native calls in GeckoThread, we try to deduce the
types of the arguments through Object.getClass(). However, there are
cases where this could fail. For example, the argument could be null,
or could be a String instance but the parameter type is really
CharSequence.
This patch introduces a way to optionally include parameter types for
the queued call. When a passed-in argument is a Class instance, it is
treated as the type for the next queued parameter, and the next argument
is treated as the value for the queued parameter. For example,
> // Queue a call with CharSequence parameter, using a String argument.
> GeckoThread.queueNativeCall(..., CharSequence.class, "123");
> // Queue a call with String parameter, using a null argument.
> GeckoThread.queueNativeCall(..., String.class, null);
Deduction is still performed when the type is missing:
> // Queue a call with int, String, and boolean parameter.
> GeckoThread.queueNativeCall(..., 42, "123", true);
> // Queue the same call but with a null argument.
> GeckoThread.queueNativeCall(..., 42, String.class, null, true);
When we queue native calls in GeckoThread, we try to deduce the
types of the arguments through Object.getClass(). However, there are
cases where this could fail. For example, the argument could be null,
or could be a String instance but the parameter type is really
CharSequence.
This patch introduces a way to optionally include parameter types for
the queued call. When a passed-in argument is a Class instance, it is
treated as the type for the next queued parameter, and the next argument
is treated as the value for the queued parameter. For example,
> // Queue a call with CharSequence parameter, using a String argument.
> GeckoThread.queueNativeCall(..., CharSequence.class, "123");
> // Queue a call with String parameter, using a null argument.
> GeckoThread.queueNativeCall(..., String.class, null);
Deduction is still performed when the type is missing:
> // Queue a call with int, String, and boolean parameter.
> GeckoThread.queueNativeCall(..., 42, "123", true);
> // Queue the same call but with a null argument.
> GeckoThread.queueNativeCall(..., 42, String.class, null, true);
When we queue native calls in GeckoThread, we try to deduce the
types of the arguments through Object.getClass(). However, there are
cases where this could fail. For example, the argument could be null,
or could be a String instance but the parameter type is really
CharSequence.
This patch introduces a way to optionally include parameter types for
the queued call. When a passed-in argument is a Class instance, it is
treated as the type for the next queued parameter, and the next argument
is treated as the value for the queued parameter. For example,
> // Queue a call with CharSequence parameter, using a String argument.
> GeckoThread.queueNativeCall(..., CharSequence.class, "123");
> // Queue a call with String parameter, using a null argument.
> GeckoThread.queueNativeCall(..., String.class, null);
Deduction is still performed when the type is missing:
> // Queue a call with int, String, and boolean parameter.
> GeckoThread.queueNativeCall(..., 42, "123", true);
> // Queue the same call but with a null argument.
> GeckoThread.queueNativeCall(..., 42, String.class, null, true);
Currently, BrowserCLH opens a single new window on startup. Now that
GeckoView is able to open windows through GeckoView.Window, we should
make GeckoView open its own window, which we can do earlier in startup,
and will make it possible to support multiple GeckoView's down the road.
One thing we do in the Fennec CLH is to make a speculative connection
based on the URI that's passed in. However, by the time the CLH runs,
we're far along into startup, and the advantage of a speculative
connection is reduced. This patch implements making speculative
connection as a method in GeckoThread, so that Fennec can make a
speculative connection without relying on the Fennec CLH.
Many Gecko operations depend on the profile being available. This
patch adds a PROFILE_READY Gecko state so that we can queue calls
until profile is loaded.
Many calls are associated with a Gecko state when they become available.
For example, calls that only depend on XPCOM become available very early
in startup, at the JNI_READY state. However, calls that depend on JS
components may only be available at the end of startup, at the RUNNING
state.
This patch adds an available state to every queued call, so that calls
can be made as soon as they become available, which is important for
calls like making speculative connections.
First we need to set the Gecko thread JNIEnv* in nsAndroidStartup, but
after that we can initialize and deinitialize the rest of JNI, including
AndroidBridge, in GeckoAppShell. This makes nsAppShell control the
AndroidBridge lifetime. Over time, parts of the AndroidBridge
functionality will be migrated to nsAppShell.
GeckoAppShell.runGecko really should be in GeckoThread because
GeckoThread already takes care of most of the preparation when running
Gecko. This patch merges runGecko into GeckoThread.run, but split the
argument-building code into its own method.
We cannot call native methods until Gecko is loaded. This patch adds a
mechanism in GeckoThread so that other code can queue up native method
calls and have those calls automatically delivered when Gecko is ready.
GeckoThread.LaunchState now covers the entire GeckoThread lifetime and
not just launch, so it's renamed to GeckoThread.State. More utility
methods are added to check for the current state.