Граф коммитов

24 Коммитов

Автор SHA1 Сообщение Дата
Jim Chen ff3982e634 Bug 1307820 - Implement per-GeckoView messaging; r=snorp r=sebastian
Bug 1307820 - 1a. Move GeckoApp EventDispatcher to GeckoView; r=snorp

Make it a GeckoView-specific EventDispatcher instead of
GeckoApp-specific, so that GeckoView consumers can benefit from a
per-view EventDispatcher. In addition, a few events like Gecko:Ready are
moved back to the global EventDispatcher because that makes more sense.

Bug 1307820 - 1b. Don't use GeckoApp EventDispatcher during inflation; r=snorp

During layout inflation, we don't yet have GeckoView and therefore the
GeckoView EventDispatcher, so we should not register events until later,
typically during onAttachedToWindow.

Bug 1307820 - 2. Introduce GeckoBundle; r=snorp

The Android Bundle class has several disadvantages when used for holding
structured data from JS.

The most obvious one is the differentiation between int and double,
which doesn't exist in JS. So when a JS number is converted to either a
Bundle int or double, we run the risk of making a wrong conversion,
resulting in a type mismatch exception when Java uses the Bundle. This
extends to number arrays from JS.

There is one more gotcha when using arrays. When we receive an empty
array from JS, there is no way for us to determine the type of the
array, because even empty arrays in Java have types. We are forced to
pick an arbitrary type like boolean[], which can easily result in a type
mismatch exception when using the array on the Java side.

In addition, Bundle is fairly cumbersome, and we cannot access the inner
structures of Bundle from Java or JNI, making it harder to use.

With these factors in mind, this patch introduces GeckoBundle as a
better choice for Gecko/Java communication. It is almost fully
API-compatible with the Android Bundle; only the Bundle array methods
are different. It resolves the numbers problem by performing conversions
if necessary, and it is a lot more lightweight than Bundle.

Bug 1307820 - 3. Convert BundleEventListener to use GeckoBundle; r=snorp

Convert BundleEventListener from using Bundle to using GeckoBundle.
Because NativeJSContainer still only supports Bundle, we do an extra
conversion when sending Bundle messages, but eventually, as we eliminate
the use of NativeJSContainer, that will go away as well.

Bug 1307820 - 4. Introduce EventDispatcher interfaces; r=snorp

Introduce several new XPCOM interfaces for the new EventDispatcher API,
these interfaces are mostly mirrored after their Java counterparts.

* nsIAndroidEventDispatcher is the main interface for
  registering/unregistering listeners and for dispatching events from
  JS/C++.

* nsIAndroidEventListener is the interface that JS/C++ clients implement
  to receive events.

* nsIAndroidEventCallback is the interface that JS/C++ clients implement
  to receive responses from dispatched events.

* nsIAndroidView is the new interface that every window receives
  that is specific to the window/GeckoView pair. It is passed to chrome
  scripts through window arguments.

Bug 1307820 - 5. Remove EventDispatcher references from gfx code; r=snorp

EventDispatcher was used for JPZC, but NPZC doesn't use it anymore.

Bug 1307820 - 6. General JNI template improvements; r=snorp

This patch includes several improvements to the JNI templates.

* Context::RawClassRef is removed to avoid misuse, as Context::ClassRef
  should be used instead.

* Fix a compile error, in certain usages, in the DisposeNative overload
  in NativeStub.

* Add Ref::IsInstanceOf and Context::IsInstanceOf to mirror the
  JNIEnv::IsInstanceOf call.

* Add Ref::operator* and Context::operator* to provide an easy way to
  get a Context object.

* Add built-in declarations for boxed Java objects (e.g. Boolean,
  Integer, etc).

* Add ObjectArray::New for creating new object arrays of specific types.

* Add lvalue qualifiers to LocalRef::operator= and GlobalRef::operator=,
  to prevent accidentally assigning to rvalues. (e.g.
  `objectArray->GetElement(0) = newObject;`, which won't work as intended.)

Bug 1307820 - 7. Support ownership through RefPtr for native JNI objects; r=snorp

In addition to direct ownership and weak pointer ownership, add a third
ownership model where a native JNI object owns a RefPtr that holds a
strong reference to the actual C++ object. This ownership model works
well with ref-counted objects such as XPCOM objects, and is activated
through the presence of public members AddRef() and Release() in the C++
object.

Bug 1307820 - 8. Implement Gecko-side EventDispatcher; r=snorp

Add a skeletal implementation of EventDispatcher on the Gecko side.
Each widget::EventDispatcher will be associated with a Java
EventDispatcher, so events can be dispatched from Gecko to Java and vice
versa. AndroidBridge and nsWindow will implement
nsIAndroidEventDispatcher through widget::EventDispatcher.

Other patches will add more complete functionality such as
GeckoBundle/JSObject translation and support for callbacks.

Bug 1307820 - 9. Implement dispatching between Gecko/Java; r=snorp

Implement translation between JSObject and GeckoBundle, and use that for
dispatching events from Gecko to Java and vice versa.

Bug 1307820 - 10. Implement callback support; r=snorp

Implement callback support for both Gecko-to-Java events and
Java-to-Gecko events.

For Gecko-to-Java, we translate nsIAndroidEventCallback to a Java
EventCallback through NativeCallbackDelegate and pass it to the Java
listener.

For Java-to-Gecko, we translate EventCallback to a
nsIAndroidEventCallback through JavaCallbackDelegate and pass it to the
Gecko listener.  There is another JavaCallbackDelegate on the Java side
that redirects the callback to a particular thread. For example, if the
event was dispatched from the UI thread, we make sure the callback
happens on the UI thread as well.

Bug 1307820 - 11. Add BundleEventListener support for Gecko thread; r=snorp

Add support for BundleEventListener on the Gecko thread, so that we can
use it to replace any existing GeckoEventListener or NativeEventListener
implementations that require the listener be run synchronously on the
Gecko thread.

Bug 1307820 - 12. Add global EventDispatcher in AndroidBridge; r=snorp

Add an instance of EventDispatcher to AndroidBridge to act as a global
event dispatcher.

Bug 1307820 - 13. Add per-nsWindow EventDispatcher; r=snorp

Add an instance of EventDispatcher to each nsWindow through an
AndroidView object, which implements nsIAndroidView. The nsIAndroidView
is passed to the chrome script through the window argument when opening
the window.

Bug 1307820 - 14. Update auto-generated bindings; r=me

Bug 1307820 - 15. Update testEventDispatcher; r=snorp

Update testEventDispatcher to include new functionalities in
EventDisptcher.

* Add tests for dispatching events to UI/background thread through
  nsIAndroidEventDispatcher::dispatch.

* Add tests for dispatching events to UI/background thread through
  EventDispatcher.dispatch.

* Add tests for dispatching events to Gecko thread through
  EventDispatcher.dispatch.

Each kind of test exercises both the global EventDispatcher through
EventDispatcher.getInstance() and the per-GeckoView EventDispatcher
through GeckoApp.getEventDispatcher().
2016-11-14 21:29:50 +08:00
Jim Chen 3f0f41aeb3 Bug 1305271 - 2. Add and use jni::IsFennec() for Fennec-only code; r=snorp
Add jni::IsFennec() that returns whether we're in a Fennec environment
(defined as the presence of the GeckoApp class). Then, add
jni::IsFennec() checks to places where we use JNI for Fennec-only classes.
2016-09-28 23:49:25 -04:00
Jim Chen 39ed66e9ec Bug 1305271 - 1. Move GetClassGlobalRef out of AndroidBridge; r=snorp
Move GetClassGlobalRef in AndroidBridge to GetClassRef in jni/Utils. The
new function now returns a local reference instead of a global
reference.
2016-09-28 23:49:25 -04:00
Jim Chen 5a0ee6a6ba Bug 1297462 - Report OutOfMemoryError exception as OOM crash; r=snorp
Detect OutOfMemoryError exceptions and report them as OOM crashes in the
crash report.
2016-08-26 12:25:57 -04:00
Jim Chen da50d1a62c Bug 1297462 - Combine Java exception stack code paths; r=snorp
Right now we report Java exception stacks through two code paths:
- GeckoAppShell.reportJavaCrash for exceptions caught by Java code
- jni::HandleUncaughtException for exceptions caught by native code

This patch combines the code for reporting the Java stack trace into
ReportException, to make it easier to add new features such as reporting
OOM exceptions.
2016-08-26 12:25:57 -04:00
Jim Chen c25482dbd4 Bug 1297462 - Always handle uncaught Java exception in native code if possible; r=snorp
We used to only handle certain exceptions in native code, and otherwise
forward the exception to Java handling code. Handling exceptions in
native code gives us better native stack traces in crash reports, so
this patch makes us always handle uncaught Java exceptions in native
code if possible, and only forward to Java as a fallback.
2016-08-26 12:25:57 -04:00
Jim Chen 36628f0198 Bug 1292323 - Implement JNI thread checking and dispatching; r=snorp
Implement checking the calling thread of a JNI call based on the
calledFrom attribute set in WrapForJNI. Also implement automatic call
dispatching based on the dispatchTo attribute set in WrapForJNI. This
eliminates the use of UsesNativeCallProxy and UsesGeckoThreadProxy.
2016-08-12 23:15:52 -04:00
Jim Chen ce45a595ab Bug 1287946 - Update existing code to use mozilla::java; r=me 2016-07-21 13:49:04 -04:00
Jim Chen fe52fe774b Bug 1286663 - Add JNI wrapper class for ByteBuffer; r=snorp
Add a wrapper class for ByteBuffer and its associated calls in JNI.
2016-07-21 13:49:04 -04:00
Carsten "Tomcat" Book eaf9acf7d5 Backed out changeset f623f6ccca25 (Bug 1286663) for another bustage on android on a CLOSED TREE 2016-07-21 08:14:27 +02:00
Carsten "Tomcat" Book e8bc59a87a Backed out changeset 684888aeee81 (bug 1287946) 2016-07-21 08:07:12 +02:00
Jim Chen 78f67d1f6f Bug 1287946 - Update existing code to use mozilla::java; r=me 2016-07-21 00:42:26 -04:00
Jim Chen bf5b43ab73 Bug 1286663 - Add JNI wrapper class for ByteBuffer; r=snorp
Add a wrapper class for ByteBuffer and its associated calls in JNI.
2016-07-21 00:41:12 -04:00
Jim Chen 9177a4b375 Bug 1277624 - Move JNI class name out of Context; r=snorp
Move the class name strings into ObjectBase, so that the strings can be
overridden by derived classes in other namespaces.
2016-06-27 14:49:55 -04:00
Jim Chen 46edf980e0 Bug 1244875 - Refactor JNI templates; r=snorp
Improve the performance of JNI calls by making JNI calls require a
Context object. LocalRef inherits from Context and can make calls
directly. Non-local Ref classes will generate a Context object when
making a call. The patch also makes the template design cleaner in
several cases.
2016-02-09 17:27:28 -05:00
Jim Chen bd5c7ad120 Bug 1238761 - Add specializations of jni::Ref for primitive arrays; r=snorp
This patch adds specializations of jni::Ref for primitive arrays like
IntArray and FloatArray, so that the arrays can be accessed through the
GetElement, GetElements, and Length members.
2016-01-15 13:05:44 -05:00
Jim Chen dd04b2cada Bug 1235475 - Crash at the exception source when an exception is in native code; r=snorp
When we have a Java exception in native code, the Java stack in the
exception will not be very useful because the top frame is the native
entry point. In this case, the native stack is more useful. However,
currently we don't get a good native stack in this situation because we
go through Java when handling the exception, and the native stack we get
will have a lot of unknown frames inside libdvm or libart. This patch
makes us stay in native code when handling an uncaught exception from
native code, so that we get a good native stack.
2015-12-30 18:36:41 -05:00
Nathan Froyd 5108c14a08 Bug 1194806 - part 5 - mark function pointer-to-members with JNICALL appropriately; r=snorp,jchen 2015-08-14 23:03:45 -04:00
Jim Chen 3599e8ef4f Bug 1192077 - Move AndroidBridge JNIEnv calls to jni/Utils; r=esawin
Calls like GetJNIForThread should now belong in jni/Utils. Moving the
calls also reduce clutter in AndroidBridge.
2015-08-13 00:53:39 -04:00
Jim Chen 81d1a5cdea Bug 1187552 - Support direct ownership of C++ objects by Java objects; r=snorp
Add a direct ownership model where the Java object owns the
corresponding C++ object directly, in addition to the WeakPtr model
where the Java object owns a WeakPtr to the C++ object. The WeakPtr
model is chosen when the implementing C++ class inherits from
SupportsWeakPtr. Otherwise, the direct ownership model is chosen. Under
the direct ownership model, a UniquePtr object must be used to attach
the containing C++ object to a Java object, to ensure ownership is
passed on to the Java object.
2015-08-04 17:47:28 -04:00
Jim Chen d836e4a08d Bug 1186467 - Add some JNI utilities for convenience; r=snorp
This patch adds:
* Conversion operator from String::Param to String::LocalRef.
* More overloads of the jni::ThrowException function.
* name members to built-in types like jni::Object, jni::String, etc.
  This allows using jni::Accessors::EnsureClassRef on built-in types
  to get built-in class refs (e.g. jclass for java/lang/String).
* Ability to implicitly convert LocalRef<Cls> to LocalRef<Object>
* Fixes for bugs in LocalRef/GlobalRef where new refs are not created.
* Fixes for inaccurate uses of mozilla::Forward in favor of mozilla::Move
2015-08-04 17:47:28 -04:00
Jim Chen 2003ec14dd Bug 1186530 - Fix compile error when using native methods with ref parameters; r=snorp
We use Ref::From() inside TypeAdapter<Ref>::ToNative to convert a raw JNI
ref argument to a Ref argument for the C++ function. However, that
generates a compile error, unless we make TypeAdapter<Ref> a friend of
Ref, because we intentionally made Ref's copy constructor private and
returning from TypeAdapter<Ref>::ToNative requires the copy constructor.
2015-07-29 15:11:15 -04:00
Jim Chen 7ec24cf6cd Bug 1186530 - Add support for instance native pointers; r=snorp
Introduce a JNIObject class that serves as a base class for classes
that wish to use per-instance native methods. JNIObject includes a long
native pointer field that the C++ code accesses to associate the Java
object instance with a C++ object instance.
2015-07-29 15:11:15 -04:00
Jim Chen 52b4f608fa Bug 1116868 - Add templated JNI classes; r=snorp 2015-01-09 19:33:57 -05:00