2018-11-30 22:52:05 +03:00
|
|
|
/* -*- Mode: c++; c-basic-offset: 2; tab-width: 20; indent-tabs-mode: nil; -*-
|
2012-05-21 15:12:37 +04:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2010-06-04 00:56:36 +04:00
|
|
|
|
|
|
|
#include <android/log.h>
|
2011-06-16 13:03:00 +04:00
|
|
|
#include <dlfcn.h>
|
2014-05-06 09:33:29 +04:00
|
|
|
#include <math.h>
|
2015-08-05 00:47:28 +03:00
|
|
|
#include <GLES2/gl2.h>
|
|
|
|
|
2016-03-22 21:08:38 +03:00
|
|
|
#include "mozilla/layers/CompositorBridgeChild.h"
|
|
|
|
#include "mozilla/layers/CompositorBridgeParent.h"
|
2010-06-04 00:56:36 +04:00
|
|
|
|
2011-11-02 19:35:11 +04:00
|
|
|
#include "mozilla/Hal.h"
|
2010-08-17 12:07:45 +04:00
|
|
|
#include "nsXULAppAPI.h"
|
2010-06-04 00:56:36 +04:00
|
|
|
#include <prthread.h>
|
|
|
|
#include "AndroidBridge.h"
|
2013-09-09 16:57:36 +04:00
|
|
|
#include "AndroidBridgeUtilities.h"
|
2015-12-03 18:56:04 +03:00
|
|
|
#include "nsAlertsUtils.h"
|
2010-06-15 06:17:37 +04:00
|
|
|
#include "nsAppShell.h"
|
2010-09-30 19:37:36 +04:00
|
|
|
#include "nsOSHelperAppService.h"
|
2011-04-12 00:41:03 +04:00
|
|
|
#include "nsWindow.h"
|
2011-06-07 11:38:00 +04:00
|
|
|
#include "mozilla/Preferences.h"
|
2011-08-04 11:32:57 +04:00
|
|
|
#include "nsThreadUtils.h"
|
2012-01-30 00:39:30 +04:00
|
|
|
#include "nsIThreadManager.h"
|
2013-10-15 07:23:20 +04:00
|
|
|
#include "gfxPlatform.h"
|
2012-02-04 10:48:26 +04:00
|
|
|
#include "gfxContext.h"
|
2013-10-15 07:23:20 +04:00
|
|
|
#include "mozilla/gfx/2D.h"
|
2013-07-24 17:18:05 +04:00
|
|
|
#include "gfxUtils.h"
|
2012-02-04 10:48:26 +04:00
|
|
|
#include "nsPresContext.h"
|
|
|
|
#include "nsIDocShell.h"
|
|
|
|
#include "nsPIDOMWindow.h"
|
2012-06-02 07:50:57 +04:00
|
|
|
#include "nsIDOMWindowUtils.h"
|
2012-11-07 01:32:07 +04:00
|
|
|
#include "mozilla/ClearOnShutdown.h"
|
2013-04-26 21:26:46 +04:00
|
|
|
#include "nsPrintfCString.h"
|
2014-04-04 20:33:49 +04:00
|
|
|
#include "nsContentUtils.h"
|
|
|
|
#include "nsIScriptError.h"
|
2014-05-06 09:33:29 +04:00
|
|
|
#include "nsIHttpChannel.h"
|
2014-11-13 21:47:24 +03:00
|
|
|
|
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 16:29:50 +03:00
|
|
|
#include "EventDispatcher.h"
|
2014-11-13 21:47:24 +03:00
|
|
|
#include "MediaCodec.h"
|
|
|
|
#include "SurfaceTexture.h"
|
2015-04-11 05:14:00 +03:00
|
|
|
#include "GLContextProvider.h"
|
2010-06-04 00:56:36 +04:00
|
|
|
|
2016-02-11 02:54:55 +03:00
|
|
|
#include "mozilla/TimeStamp.h"
|
|
|
|
#include "mozilla/UniquePtr.h"
|
2016-04-18 13:48:19 +03:00
|
|
|
#include "nsIObserverService.h"
|
2016-09-09 04:49:25 +03:00
|
|
|
#include "nsISupportsPrimitives.h"
|
2016-10-03 19:26:00 +03:00
|
|
|
#include "WidgetUtils.h"
|
2015-09-15 21:01:07 +03:00
|
|
|
|
2016-09-16 22:13:48 +03:00
|
|
|
#include "FennecJNIWrappers.h"
|
|
|
|
|
2010-06-04 00:56:36 +04:00
|
|
|
using namespace mozilla;
|
2013-10-15 07:23:20 +04:00
|
|
|
using namespace mozilla::gfx;
|
2016-07-21 20:49:04 +03:00
|
|
|
using namespace mozilla::java;
|
2010-06-04 00:56:36 +04:00
|
|
|
|
2015-02-19 00:50:31 +03:00
|
|
|
AndroidBridge* AndroidBridge::sBridge = nullptr;
|
2013-09-25 10:06:21 +04:00
|
|
|
static jobject sGlobalContext = nullptr;
|
2015-09-15 21:01:07 +03:00
|
|
|
nsDataHashtable<nsStringHashKey, nsString> AndroidBridge::sStoragePaths;
|
2010-06-04 00:56:36 +04:00
|
|
|
|
2013-09-09 16:57:36 +04:00
|
|
|
jmethodID AndroidBridge::GetMethodID(JNIEnv* env, jclass jClass,
|
|
|
|
const char* methodName,
|
|
|
|
const char* methodType) {
|
|
|
|
jmethodID methodID = env->GetMethodID(jClass, methodName, methodType);
|
|
|
|
if (!methodID) {
|
|
|
|
ALOG(
|
|
|
|
">>> FATAL JNI ERROR! GetMethodID(methodName=\"%s\", "
|
2013-11-19 05:30:00 +04:00
|
|
|
"methodType=\"%s\") failed. Did ProGuard optimize away something it "
|
|
|
|
"shouldn't have?",
|
|
|
|
methodName, methodType);
|
2013-09-09 16:57:36 +04:00
|
|
|
env->ExceptionDescribe();
|
|
|
|
MOZ_CRASH();
|
|
|
|
}
|
|
|
|
return methodID;
|
|
|
|
}
|
|
|
|
|
|
|
|
jmethodID AndroidBridge::GetStaticMethodID(JNIEnv* env, jclass jClass,
|
|
|
|
const char* methodName,
|
|
|
|
const char* methodType) {
|
|
|
|
jmethodID methodID = env->GetStaticMethodID(jClass, methodName, methodType);
|
|
|
|
if (!methodID) {
|
|
|
|
ALOG(
|
|
|
|
">>> FATAL JNI ERROR! GetStaticMethodID(methodName=\"%s\", "
|
2013-11-19 05:30:00 +04:00
|
|
|
"methodType=\"%s\") failed. Did ProGuard optimize away something it "
|
|
|
|
"shouldn't have?",
|
|
|
|
methodName, methodType);
|
2013-09-09 16:57:36 +04:00
|
|
|
env->ExceptionDescribe();
|
|
|
|
MOZ_CRASH();
|
|
|
|
}
|
|
|
|
return methodID;
|
|
|
|
}
|
|
|
|
|
|
|
|
jfieldID AndroidBridge::GetFieldID(JNIEnv* env, jclass jClass,
|
|
|
|
const char* fieldName,
|
|
|
|
const char* fieldType) {
|
|
|
|
jfieldID fieldID = env->GetFieldID(jClass, fieldName, fieldType);
|
|
|
|
if (!fieldID) {
|
|
|
|
ALOG(
|
|
|
|
">>> FATAL JNI ERROR! GetFieldID(fieldName=\"%s\", "
|
2013-11-19 05:30:00 +04:00
|
|
|
"fieldType=\"%s\") failed. Did ProGuard optimize away something it "
|
|
|
|
"shouldn't have?",
|
|
|
|
fieldName, fieldType);
|
2013-09-09 16:57:36 +04:00
|
|
|
env->ExceptionDescribe();
|
|
|
|
MOZ_CRASH();
|
|
|
|
}
|
|
|
|
return fieldID;
|
|
|
|
}
|
|
|
|
|
|
|
|
jfieldID AndroidBridge::GetStaticFieldID(JNIEnv* env, jclass jClass,
|
|
|
|
const char* fieldName,
|
|
|
|
const char* fieldType) {
|
|
|
|
jfieldID fieldID = env->GetStaticFieldID(jClass, fieldName, fieldType);
|
|
|
|
if (!fieldID) {
|
|
|
|
ALOG(
|
|
|
|
">>> FATAL JNI ERROR! GetStaticFieldID(fieldName=\"%s\", "
|
2013-11-19 05:30:00 +04:00
|
|
|
"fieldType=\"%s\") failed. Did ProGuard optimize away something it "
|
|
|
|
"shouldn't have?",
|
|
|
|
fieldName, fieldType);
|
2013-09-09 16:57:36 +04:00
|
|
|
env->ExceptionDescribe();
|
|
|
|
MOZ_CRASH();
|
|
|
|
}
|
|
|
|
return fieldID;
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-08-13 07:53:39 +03:00
|
|
|
void AndroidBridge::ConstructBridge() {
|
2010-06-04 00:56:36 +04:00
|
|
|
/* NSS hack -- bionic doesn't handle recursive unloads correctly,
|
|
|
|
* because library finalizer functions are called with the dynamic
|
|
|
|
* linker lock still held. This results in a deadlock when trying
|
|
|
|
* to call dlclose() while we're already inside dlclose().
|
|
|
|
* Conveniently, NSS has an env var that can prevent it from unloading.
|
|
|
|
*/
|
|
|
|
putenv(const_cast<char*>("NSS_DISABLE_UNLOAD=1"));
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-02-19 00:50:31 +03:00
|
|
|
MOZ_ASSERT(!sBridge);
|
2010-06-04 00:56:36 +04:00
|
|
|
sBridge = new AndroidBridge();
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2017-11-01 21:48:49 +03:00
|
|
|
void AndroidBridge::DeconstructBridge() {
|
2010-06-04 00:56:36 +04:00
|
|
|
if (sBridge) {
|
2015-08-13 07:53:39 +03:00
|
|
|
delete sBridge;
|
2010-06-04 00:56:36 +04:00
|
|
|
// AndroidBridge destruction requires sBridge to still be valid,
|
2015-02-19 00:50:31 +03:00
|
|
|
// so we set sBridge to nullptr after deleting it.
|
2015-08-13 07:53:39 +03:00
|
|
|
sBridge = nullptr;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-13 07:53:39 +03:00
|
|
|
AndroidBridge::~AndroidBridge() {}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-08-13 07:53:39 +03:00
|
|
|
AndroidBridge::AndroidBridge() {
|
2011-12-06 10:56:04 +04:00
|
|
|
ALOG_BRIDGE("AndroidBridge::Init");
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-08-13 07:53:39 +03:00
|
|
|
JNIEnv* const jEnv = jni::GetGeckoThreadEnv();
|
|
|
|
AutoLocalJNIFrame jniFrame(jEnv);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-08-13 07:53:39 +03:00
|
|
|
mMessageQueue = java::GeckoThread::MsgQueue();
|
2017-11-01 21:48:49 +03:00
|
|
|
auto msgQueueClass = jni::Class::LocalRef::Adopt(
|
2015-08-13 07:53:39 +03:00
|
|
|
jEnv, jEnv->GetObjectClass(mMessageQueue.Get()));
|
|
|
|
// mMessageQueueNext must not be null
|
|
|
|
mMessageQueueNext =
|
|
|
|
GetMethodID(jEnv, msgQueueClass.Get(), "next", "()Landroid/os/Message;");
|
|
|
|
// mMessageQueueMessages may be null (e.g. due to proguard optimization)
|
|
|
|
mMessageQueueMessages = jEnv->GetFieldID(msgQueueClass.Get(), "mMessages",
|
|
|
|
"Landroid/os/Message;");
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-08-13 07:53:39 +03:00
|
|
|
AutoJNIClass string(jEnv, "java/lang/String");
|
|
|
|
jStringClass = string.getGlobalRef();
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-08-13 07:53:39 +03:00
|
|
|
mAPIVersion = jni::GetAPIVersion();
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-01-10 03:33:56 +03:00
|
|
|
AutoJNIClass channels(jEnv, "java/nio/channels/Channels");
|
|
|
|
jChannels = channels.getGlobalRef();
|
|
|
|
jChannelCreate = channels.getStaticMethod(
|
|
|
|
"newChannel",
|
|
|
|
"(Ljava/io/InputStream;)Ljava/nio/channels/ReadableByteChannel;");
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-01-10 03:33:56 +03:00
|
|
|
AutoJNIClass readableByteChannel(jEnv,
|
|
|
|
"java/nio/channels/ReadableByteChannel");
|
2015-08-13 07:53:39 +03:00
|
|
|
jReadableByteChannel = readableByteChannel.getGlobalRef();
|
2015-01-10 03:33:56 +03:00
|
|
|
jByteBufferRead =
|
2015-08-13 07:53:39 +03:00
|
|
|
readableByteChannel.getMethod("read", "(Ljava/nio/ByteBuffer;)I");
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-08-13 07:53:39 +03:00
|
|
|
AutoJNIClass inputStream(jEnv, "java/io/InputStream");
|
2015-01-10 03:33:56 +03:00
|
|
|
jInputStream = inputStream.getGlobalRef();
|
2015-08-13 07:53:39 +03:00
|
|
|
jClose = inputStream.getMethod("close", "()V");
|
|
|
|
jAvailable = inputStream.getMethod("available", "()I");
|
|
|
|
}
|
|
|
|
|
2011-12-06 10:56:04 +04:00
|
|
|
static void getHandlersFromStringArray(
|
2015-08-13 07:53:39 +03:00
|
|
|
JNIEnv* aJNIEnv, jni::ObjectArray::Param aArr, size_t aLen,
|
|
|
|
nsIMutableArray* aHandlersArray, nsIHandlerApp** aDefaultApp,
|
2015-01-10 03:33:56 +03:00
|
|
|
const nsAString& aAction = EmptyString(),
|
|
|
|
const nsACString& aMimeType = EmptyCString()) {
|
|
|
|
nsString empty = EmptyString();
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-11-01 21:48:48 +03:00
|
|
|
auto getNormalizedString = [](jni::Object::Param obj) -> nsString {
|
|
|
|
nsString out;
|
|
|
|
if (!obj) {
|
|
|
|
out.SetIsVoid(true);
|
|
|
|
} else {
|
|
|
|
out.Assign(jni::String::Ref::From(obj)->ToString());
|
2010-09-30 19:37:36 +04:00
|
|
|
}
|
2017-11-01 21:48:48 +03:00
|
|
|
return out;
|
2018-11-30 13:46:48 +03:00
|
|
|
};
|
|
|
|
|
2017-11-01 21:48:48 +03:00
|
|
|
for (size_t i = 0; i < aLen; i += 4) {
|
|
|
|
nsString name(getNormalizedString(aArr->GetElement(i)));
|
|
|
|
nsString isDefault(getNormalizedString(aArr->GetElement(i + 1)));
|
|
|
|
nsString packageName(getNormalizedString(aArr->GetElement(i + 2)));
|
|
|
|
nsString className(getNormalizedString(aArr->GetElement(i + 3)));
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2010-09-30 19:37:36 +04:00
|
|
|
nsIHandlerApp* app = nsOSHelperAppService::CreateAndroidHandlerApp(
|
|
|
|
name, className, packageName, className, aMimeType, aAction);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-10-21 17:53:02 +03:00
|
|
|
aHandlersArray->AppendElement(app);
|
2010-09-30 19:37:36 +04:00
|
|
|
if (aDefaultApp && isDefault.Length() > 0) *aDefaultApp = app;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2010-09-30 19:37:36 +04:00
|
|
|
}
|
|
|
|
|
2013-09-09 16:57:36 +04:00
|
|
|
bool AndroidBridge::GetHandlersForMimeType(const nsAString& aMimeType,
|
2010-09-30 19:37:36 +04:00
|
|
|
nsIMutableArray* aHandlersArray,
|
|
|
|
nsIHandlerApp** aDefaultApp,
|
|
|
|
const nsAString& aAction) {
|
2011-03-01 07:25:11 +03:00
|
|
|
ALOG_BRIDGE("AndroidBridge::GetHandlersForMimeType");
|
|
|
|
|
2016-08-13 06:15:52 +03:00
|
|
|
auto arr = GeckoAppShell::GetHandlersForMimeType(aMimeType, aAction);
|
2011-10-17 18:59:28 +04:00
|
|
|
if (!arr) return false;
|
2010-06-30 06:22:08 +04:00
|
|
|
|
2015-01-10 03:33:57 +03:00
|
|
|
JNIEnv* const env = arr.Env();
|
2017-11-01 21:48:48 +03:00
|
|
|
size_t len = arr->Length();
|
2010-06-30 06:22:08 +04:00
|
|
|
|
2010-09-30 19:37:36 +04:00
|
|
|
if (!aHandlersArray) return len > 0;
|
2010-06-30 06:22:08 +04:00
|
|
|
|
2017-11-01 21:48:48 +03:00
|
|
|
getHandlersFromStringArray(env, arr, len, aHandlersArray, aDefaultApp,
|
2013-09-09 16:57:36 +04:00
|
|
|
aAction, NS_ConvertUTF16toUTF8(aMimeType));
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2010-06-30 06:22:08 +04:00
|
|
|
}
|
|
|
|
|
2015-07-24 22:45:55 +03:00
|
|
|
bool AndroidBridge::GetHWEncoderCapability() {
|
|
|
|
ALOG_BRIDGE("AndroidBridge::GetHWEncoderCapability");
|
|
|
|
|
|
|
|
bool value = GeckoAppShell::GetHWEncoderCapability();
|
|
|
|
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AndroidBridge::GetHWDecoderCapability() {
|
|
|
|
ALOG_BRIDGE("AndroidBridge::GetHWDecoderCapability");
|
|
|
|
|
|
|
|
bool value = GeckoAppShell::GetHWDecoderCapability();
|
|
|
|
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
2013-09-09 16:57:36 +04:00
|
|
|
bool AndroidBridge::GetHandlersForURL(const nsAString& aURL,
|
2011-09-30 11:00:48 +04:00
|
|
|
nsIMutableArray* aHandlersArray,
|
|
|
|
nsIHandlerApp** aDefaultApp,
|
|
|
|
const nsAString& aAction) {
|
2011-03-01 07:25:11 +03:00
|
|
|
ALOG_BRIDGE("AndroidBridge::GetHandlersForURL");
|
|
|
|
|
2016-08-13 06:15:52 +03:00
|
|
|
auto arr = GeckoAppShell::GetHandlersForURL(aURL, aAction);
|
2011-10-17 18:59:28 +04:00
|
|
|
if (!arr) return false;
|
2010-06-30 06:22:08 +04:00
|
|
|
|
2015-01-10 03:33:57 +03:00
|
|
|
JNIEnv* const env = arr.Env();
|
2017-11-01 21:48:48 +03:00
|
|
|
size_t len = arr->Length();
|
2010-06-30 06:22:08 +04:00
|
|
|
|
2010-09-30 19:37:36 +04:00
|
|
|
if (!aHandlersArray) return len > 0;
|
2010-06-30 06:22:08 +04:00
|
|
|
|
2017-11-01 21:48:48 +03:00
|
|
|
getHandlersFromStringArray(env, arr, len, aHandlersArray, aDefaultApp,
|
2010-09-30 19:37:36 +04:00
|
|
|
aAction);
|
2013-09-09 16:57:37 +04:00
|
|
|
return true;
|
2010-06-14 23:04:16 +04:00
|
|
|
}
|
|
|
|
|
2011-03-01 07:25:11 +03:00
|
|
|
void AndroidBridge::GetMimeTypeFromExtensions(const nsACString& aFileExt,
|
|
|
|
nsCString& aMimeType) {
|
|
|
|
ALOG_BRIDGE("AndroidBridge::GetMimeTypeFromExtensions");
|
|
|
|
|
2016-08-13 06:15:52 +03:00
|
|
|
auto jstrType = GeckoAppShell::GetMimeTypeFromExtensions(aFileExt);
|
2012-01-30 00:39:30 +04:00
|
|
|
|
2015-01-10 03:33:57 +03:00
|
|
|
if (jstrType) {
|
2016-02-10 01:27:28 +03:00
|
|
|
aMimeType = jstrType->ToCString();
|
2013-09-09 16:57:37 +04:00
|
|
|
}
|
2010-06-14 23:04:16 +04:00
|
|
|
}
|
|
|
|
|
2011-09-15 11:40:17 +04:00
|
|
|
void AndroidBridge::GetExtensionFromMimeType(const nsACString& aMimeType,
|
|
|
|
nsACString& aFileExt) {
|
2011-03-08 08:45:43 +03:00
|
|
|
ALOG_BRIDGE("AndroidBridge::GetExtensionFromMimeType");
|
|
|
|
|
2016-08-13 06:15:52 +03:00
|
|
|
auto jstrExt = GeckoAppShell::GetExtensionFromMimeType(aMimeType);
|
2012-01-30 00:39:30 +04:00
|
|
|
|
2015-01-10 03:33:57 +03:00
|
|
|
if (jstrExt) {
|
2016-02-10 01:27:28 +03:00
|
|
|
aFileExt = jstrExt->ToCString();
|
2013-09-09 16:57:37 +04:00
|
|
|
}
|
2010-06-16 21:20:54 +04:00
|
|
|
}
|
|
|
|
|
2013-07-04 17:53:25 +04:00
|
|
|
int AndroidBridge::GetScreenDepth() {
|
2013-09-09 16:57:37 +04:00
|
|
|
ALOG_BRIDGE("%s", __PRETTY_FUNCTION__);
|
|
|
|
|
2013-07-04 17:53:25 +04:00
|
|
|
static int sDepth = 0;
|
|
|
|
if (sDepth) return sDepth;
|
|
|
|
|
|
|
|
const int DEFAULT_DEPTH = 16;
|
|
|
|
|
2015-08-13 07:53:39 +03:00
|
|
|
if (jni::IsAvailable()) {
|
2016-08-13 06:15:52 +03:00
|
|
|
sDepth = GeckoAppShell::GetScreenDepth();
|
2014-01-18 09:32:24 +04:00
|
|
|
}
|
2013-07-04 17:53:25 +04:00
|
|
|
if (!sDepth) return DEFAULT_DEPTH;
|
|
|
|
|
|
|
|
return sDepth;
|
|
|
|
}
|
2018-07-27 21:24:49 +03:00
|
|
|
|
2013-09-09 16:57:37 +04:00
|
|
|
void AndroidBridge::Vibrate(const nsTArray<uint32_t>& aPattern) {
|
|
|
|
ALOG_BRIDGE("%s", __PRETTY_FUNCTION__);
|
2012-01-30 00:39:30 +04:00
|
|
|
|
2013-09-09 16:57:37 +04:00
|
|
|
uint32_t len = aPattern.Length();
|
|
|
|
if (!len) {
|
|
|
|
ALOG_BRIDGE(" invalid 0-length array");
|
2012-01-30 00:39:30 +04:00
|
|
|
return;
|
2013-09-09 16:57:37 +04:00
|
|
|
}
|
2012-01-30 00:39:30 +04:00
|
|
|
|
2011-09-30 11:00:48 +04:00
|
|
|
// It's clear if this worth special-casing, but it creates less
|
|
|
|
// java junk, so dodges the GC.
|
|
|
|
if (len == 1) {
|
|
|
|
jlong d = aPattern[0];
|
|
|
|
if (d < 0) {
|
|
|
|
ALOG_BRIDGE(" invalid vibration duration < 0");
|
2012-05-04 19:08:45 +04:00
|
|
|
return;
|
2011-09-30 11:00:48 +04:00
|
|
|
}
|
2016-08-13 06:15:52 +03:00
|
|
|
GeckoAppShell::Vibrate(d);
|
2018-11-30 13:46:48 +03:00
|
|
|
return;
|
|
|
|
}
|
2011-09-30 11:00:48 +04:00
|
|
|
|
|
|
|
// First element of the array vibrate() expects is how long to wait
|
|
|
|
// *before* vibrating. For us, this is always 0.
|
|
|
|
|
2015-08-13 07:53:39 +03:00
|
|
|
JNIEnv* const env = jni::GetGeckoThreadEnv();
|
2015-01-10 03:33:57 +03:00
|
|
|
AutoLocalJNIFrame jniFrame(env, 1);
|
|
|
|
|
2012-01-30 00:39:30 +04:00
|
|
|
jlongArray array = env->NewLongArray(len + 1);
|
2011-09-30 11:00:48 +04:00
|
|
|
if (!array) {
|
|
|
|
ALOG_BRIDGE(" failed to allocate array");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
jlong* elts = env->GetLongArrayElements(array, nullptr);
|
2011-09-30 11:00:48 +04:00
|
|
|
elts[0] = 0;
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint32_t i = 0; i < aPattern.Length(); ++i) {
|
2011-09-30 11:00:48 +04:00
|
|
|
jlong d = aPattern[i];
|
|
|
|
if (d < 0) {
|
|
|
|
ALOG_BRIDGE(" invalid vibration duration < 0");
|
2012-01-30 00:39:30 +04:00
|
|
|
env->ReleaseLongArrayElements(array, elts, JNI_ABORT);
|
2011-09-30 11:00:48 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
elts[i + 1] = d;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2012-01-30 00:39:30 +04:00
|
|
|
env->ReleaseLongArrayElements(array, elts, 0);
|
2011-09-30 11:00:48 +04:00
|
|
|
|
2017-11-01 21:48:49 +03:00
|
|
|
GeckoAppShell::Vibrate(jni::LongArray::Ref::From(array),
|
|
|
|
-1 /* don't repeat */);
|
2011-02-27 18:50:56 +03:00
|
|
|
}
|
|
|
|
|
2011-03-30 22:04:41 +04:00
|
|
|
void AndroidBridge::GetSystemColors(AndroidSystemColors* aColors) {
|
|
|
|
NS_ASSERTION(aColors != nullptr,
|
2012-07-30 18:20:58 +04:00
|
|
|
"AndroidBridge::GetSystemColors: aColors is null!");
|
2011-03-30 22:04:41 +04:00
|
|
|
if (!aColors) return;
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
auto arr = GeckoAppShell::GetSystemColors();
|
2011-03-30 22:04:41 +04:00
|
|
|
if (!arr) return;
|
|
|
|
|
2016-08-13 06:15:52 +03:00
|
|
|
JNIEnv* const env = arr.Env();
|
2015-01-10 03:33:57 +03:00
|
|
|
uint32_t len = static_cast<uint32_t>(env->GetArrayLength(arr.Get()));
|
2016-08-13 06:15:52 +03:00
|
|
|
jint* elements = env->GetIntArrayElements(arr.Get(), 0);
|
2011-03-30 22:04:41 +04:00
|
|
|
|
2015-01-10 03:33:57 +03:00
|
|
|
uint32_t colorsCount = sizeof(AndroidSystemColors) / sizeof(nscolor);
|
|
|
|
if (len < colorsCount) colorsCount = len;
|
2011-03-30 22:04:41 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
// Convert Android colors to nscolor by switching R and B in the ARGB 32 bit
|
2018-11-30 13:46:48 +03:00
|
|
|
// value
|
2011-03-30 22:04:41 +04:00
|
|
|
nscolor* colors = (nscolor*)aColors;
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint32_t i = 0; i < colorsCount; i++) {
|
|
|
|
uint32_t androidColor = static_cast<uint32_t>(elements[i]);
|
|
|
|
uint8_t r = (androidColor & 0x00ff0000) >> 16;
|
|
|
|
uint8_t b = (androidColor & 0x000000ff);
|
2012-07-12 20:52:52 +04:00
|
|
|
colors[i] = (androidColor & 0xff00ff00) | (b << 16) | r;
|
2011-03-30 22:04:41 +04:00
|
|
|
}
|
|
|
|
|
2015-01-10 03:33:57 +03:00
|
|
|
env->ReleaseIntArrayElements(arr.Get(), elements, 0);
|
2011-03-30 22:04:41 +04:00
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
void AndroidBridge::GetIconForExtension(const nsACString& aFileExt,
|
|
|
|
uint32_t aIconSize,
|
|
|
|
uint8_t* const aBuf) {
|
2011-06-14 01:02:13 +04:00
|
|
|
ALOG_BRIDGE("AndroidBridge::GetIconForExtension");
|
2012-07-30 18:20:58 +04:00
|
|
|
NS_ASSERTION(aBuf != nullptr,
|
|
|
|
"AndroidBridge::GetIconForExtension: aBuf is null!");
|
2011-06-14 01:02:13 +04:00
|
|
|
if (!aBuf) return;
|
|
|
|
|
2016-08-13 06:15:52 +03:00
|
|
|
auto arr = GeckoAppShell::GetIconForExtension(NS_ConvertUTF8toUTF16(aFileExt),
|
|
|
|
aIconSize);
|
2012-05-04 19:08:47 +04:00
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
NS_ASSERTION(
|
|
|
|
arr != nullptr,
|
|
|
|
"AndroidBridge::GetIconForExtension: Returned pixels array is null!");
|
2011-06-14 01:02:13 +04:00
|
|
|
if (!arr) return;
|
|
|
|
|
2015-01-10 03:33:57 +03:00
|
|
|
JNIEnv* const env = arr.Env();
|
|
|
|
uint32_t len = static_cast<uint32_t>(env->GetArrayLength(arr.Get()));
|
|
|
|
jbyte* elements = env->GetByteArrayElements(arr.Get(), 0);
|
2011-06-14 01:02:13 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t bufSize = aIconSize * aIconSize * 4;
|
2011-06-14 01:02:13 +04:00
|
|
|
NS_ASSERTION(
|
|
|
|
len == bufSize,
|
|
|
|
"AndroidBridge::GetIconForExtension: Pixels array is incomplete!");
|
|
|
|
if (len == bufSize) memcpy(aBuf, elements, bufSize);
|
|
|
|
|
2015-01-10 03:33:57 +03:00
|
|
|
env->ReleaseByteArrayElements(arr.Get(), elements, 0);
|
2011-06-14 01:02:13 +04:00
|
|
|
}
|
|
|
|
|
2013-09-09 16:57:36 +04:00
|
|
|
bool AndroidBridge::GetStaticIntField(const char* className,
|
|
|
|
const char* fieldName, int32_t* aInt,
|
|
|
|
JNIEnv* jEnv /* = nullptr */) {
|
2011-03-01 07:25:11 +03:00
|
|
|
ALOG_BRIDGE("AndroidBridge::GetStaticIntField %s", fieldName);
|
2012-04-28 00:04:47 +04:00
|
|
|
|
2013-09-09 16:57:36 +04:00
|
|
|
if (!jEnv) {
|
2015-08-13 07:53:39 +03:00
|
|
|
if (!jni::IsAvailable()) {
|
2014-01-18 09:32:24 +04:00
|
|
|
return false;
|
2012-04-28 00:04:47 +04:00
|
|
|
}
|
2015-08-13 07:53:39 +03:00
|
|
|
jEnv = jni::GetGeckoThreadEnv();
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2012-01-30 00:39:30 +04:00
|
|
|
|
2015-01-10 03:33:56 +03:00
|
|
|
AutoJNIClass cls(jEnv, className);
|
|
|
|
jfieldID field = cls.getStaticField(fieldName, "I");
|
2011-02-28 19:32:05 +03:00
|
|
|
|
2013-09-09 16:57:36 +04:00
|
|
|
if (!field) {
|
2011-02-28 19:32:05 +03:00
|
|
|
return false;
|
2013-09-09 16:57:36 +04:00
|
|
|
}
|
2011-02-28 19:32:05 +03:00
|
|
|
|
2015-01-10 03:33:56 +03:00
|
|
|
*aInt = static_cast<int32_t>(jEnv->GetStaticIntField(cls.getRawRef(), field));
|
2011-02-28 19:32:05 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-09-09 16:57:36 +04:00
|
|
|
bool AndroidBridge::GetStaticStringField(const char* className,
|
|
|
|
const char* fieldName,
|
|
|
|
nsAString& result,
|
|
|
|
JNIEnv* jEnv /* = nullptr */) {
|
2012-05-04 19:08:47 +04:00
|
|
|
ALOG_BRIDGE("AndroidBridge::GetStaticStringField %s", fieldName);
|
2011-03-01 07:25:11 +03:00
|
|
|
|
2013-09-09 16:57:36 +04:00
|
|
|
if (!jEnv) {
|
2015-08-13 07:53:39 +03:00
|
|
|
if (!jni::IsAvailable()) {
|
2014-01-18 09:32:24 +04:00
|
|
|
return false;
|
2012-04-28 00:04:47 +04:00
|
|
|
}
|
2015-08-13 07:53:39 +03:00
|
|
|
jEnv = jni::GetGeckoThreadEnv();
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2012-01-30 00:39:30 +04:00
|
|
|
|
2014-01-06 21:54:22 +04:00
|
|
|
AutoLocalJNIFrame jniFrame(jEnv, 1);
|
2015-01-10 03:33:56 +03:00
|
|
|
AutoJNIClass cls(jEnv, className);
|
|
|
|
jfieldID field = cls.getStaticField(fieldName, "Ljava/lang/String;");
|
2010-09-11 17:20:20 +04:00
|
|
|
|
2013-09-09 16:57:36 +04:00
|
|
|
if (!field) {
|
2010-09-11 17:20:20 +04:00
|
|
|
return false;
|
2013-09-09 16:57:36 +04:00
|
|
|
}
|
2010-09-11 17:20:20 +04:00
|
|
|
|
2015-01-10 03:33:56 +03:00
|
|
|
jstring jstr = (jstring)jEnv->GetStaticObjectField(cls.getRawRef(), field);
|
2010-09-11 17:20:20 +04:00
|
|
|
if (!jstr) return false;
|
|
|
|
|
2017-11-01 21:48:48 +03:00
|
|
|
result.Assign(jni::String::Ref::From(jstr)->ToString());
|
2010-09-11 17:20:20 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-08-04 11:32:57 +04:00
|
|
|
namespace mozilla {
|
2016-04-26 03:23:21 +03:00
|
|
|
class TracerRunnable : public Runnable {
|
2011-08-04 11:32:57 +04:00
|
|
|
public:
|
2017-06-12 22:34:10 +03:00
|
|
|
TracerRunnable() : Runnable("TracerRunnable") {
|
2011-08-04 11:32:57 +04:00
|
|
|
mTracerLock = new Mutex("TracerRunnable");
|
|
|
|
mTracerCondVar = new CondVar(*mTracerLock, "TracerRunnable");
|
|
|
|
mMainThread = do_GetMainThread();
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2011-08-04 11:32:57 +04:00
|
|
|
~TracerRunnable() {
|
|
|
|
delete mTracerCondVar;
|
|
|
|
delete mTracerLock;
|
|
|
|
mTracerLock = nullptr;
|
|
|
|
mTracerCondVar = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual nsresult Run() {
|
|
|
|
MutexAutoLock lock(*mTracerLock);
|
|
|
|
if (!AndroidBridge::Bridge()) return NS_OK;
|
|
|
|
|
|
|
|
mHasRun = true;
|
|
|
|
mTracerCondVar->Notify();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-07-02 23:32:34 +04:00
|
|
|
bool Fire() {
|
|
|
|
if (!mTracerLock || !mTracerCondVar) return false;
|
2011-08-04 11:32:57 +04:00
|
|
|
MutexAutoLock lock(*mTracerLock);
|
2012-07-02 23:32:34 +04:00
|
|
|
mHasRun = false;
|
|
|
|
mMainThread->Dispatch(this, NS_DISPATCH_NORMAL);
|
|
|
|
while (!mHasRun) mTracerCondVar->Wait();
|
|
|
|
return true;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2012-07-02 23:32:34 +04:00
|
|
|
void Signal() {
|
2011-08-04 11:32:57 +04:00
|
|
|
MutexAutoLock lock(*mTracerLock);
|
2012-04-04 13:15:10 +04:00
|
|
|
mHasRun = true;
|
2011-08-04 11:32:57 +04:00
|
|
|
mTracerCondVar->Notify();
|
2012-07-02 23:32:34 +04:00
|
|
|
}
|
2011-08-04 11:32:57 +04:00
|
|
|
|
2018-11-30 13:46:48 +03:00
|
|
|
private:
|
2011-08-04 11:32:57 +04:00
|
|
|
Mutex* mTracerLock;
|
|
|
|
CondVar* mTracerCondVar;
|
2012-04-04 13:15:10 +04:00
|
|
|
bool mHasRun;
|
2011-08-04 11:32:57 +04:00
|
|
|
nsCOMPtr<nsIThread> mMainThread;
|
2018-11-30 13:46:48 +03:00
|
|
|
};
|
2013-08-12 18:58:36 +04:00
|
|
|
StaticRefPtr<TracerRunnable> sTracerRunnable;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2011-08-04 11:32:57 +04:00
|
|
|
bool InitWidgetTracing() {
|
|
|
|
if (!sTracerRunnable) sTracerRunnable = new TracerRunnable();
|
|
|
|
return true;
|
|
|
|
}
|
2011-06-16 13:03:00 +04:00
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
void CleanUpWidgetTracing() { sTracerRunnable = nullptr; }
|
2011-06-16 13:03:00 +04:00
|
|
|
|
2011-11-02 19:35:11 +04:00
|
|
|
bool FireAndWaitForTracerEvent() {
|
|
|
|
if (sTracerRunnable) return sTracerRunnable->Fire();
|
|
|
|
return false;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2011-11-02 19:35:11 +04:00
|
|
|
|
|
|
|
void SignalTracerThread() {
|
2011-11-09 12:56:37 +04:00
|
|
|
if (sTracerRunnable) return sTracerRunnable->Signal();
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2015-01-10 03:33:57 +03:00
|
|
|
|
2011-08-04 11:32:57 +04:00
|
|
|
} // namespace mozilla
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2011-11-02 19:35:11 +04:00
|
|
|
void AndroidBridge::GetCurrentBatteryInformation(
|
|
|
|
hal::BatteryInformation* aBatteryInfo) {
|
2012-01-16 17:44:07 +04:00
|
|
|
ALOG_BRIDGE("AndroidBridge::GetCurrentBatteryInformation");
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2012-01-16 17:44:07 +04:00
|
|
|
// To prevent calling too many methods through JNI, the Java method returns
|
2014-03-05 13:42:42 +04:00
|
|
|
// an array of double even if we actually want a double and a boolean.
|
2016-08-13 06:15:52 +03:00
|
|
|
auto arr = GeckoAppShell::GetCurrentBatteryInformation();
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-01-10 03:33:57 +03:00
|
|
|
JNIEnv* const env = arr.Env();
|
|
|
|
if (!arr || env->GetArrayLength(arr.Get()) != 3) {
|
2011-11-02 19:35:11 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-01-10 03:33:57 +03:00
|
|
|
jdouble* info = env->GetDoubleArrayElements(arr.Get(), 0);
|
2011-11-02 19:35:11 +04:00
|
|
|
|
|
|
|
aBatteryInfo->level() = info[0];
|
|
|
|
aBatteryInfo->charging() = info[1] == 1.0f;
|
2011-11-09 18:13:37 +04:00
|
|
|
aBatteryInfo->remainingTime() = info[2];
|
2011-11-02 19:35:11 +04:00
|
|
|
|
2015-01-10 03:33:57 +03:00
|
|
|
env->ReleaseDoubleArrayElements(arr.Get(), info, 0);
|
2011-11-02 19:35:11 +04:00
|
|
|
}
|
|
|
|
|
2012-01-16 17:44:07 +04:00
|
|
|
void AndroidBridge::GetCurrentNetworkInformation(
|
|
|
|
hal::NetworkInformation* aNetworkInfo) {
|
|
|
|
ALOG_BRIDGE("AndroidBridge::GetCurrentNetworkInformation");
|
|
|
|
|
|
|
|
// To prevent calling too many methods through JNI, the Java method returns
|
2014-03-05 13:42:42 +04:00
|
|
|
// an array of double even if we actually want an integer, a boolean, and an
|
|
|
|
// integer.
|
2012-05-04 19:08:47 +04:00
|
|
|
|
2016-08-13 06:15:52 +03:00
|
|
|
auto arr = GeckoAppShell::GetCurrentNetworkInformation();
|
2015-01-10 03:33:57 +03:00
|
|
|
|
|
|
|
JNIEnv* const env = arr.Env();
|
|
|
|
if (!arr || env->GetArrayLength(arr.Get()) != 3) {
|
2012-01-16 17:44:07 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-01-10 03:33:57 +03:00
|
|
|
jdouble* info = env->GetDoubleArrayElements(arr.Get(), 0);
|
2012-01-16 17:44:07 +04:00
|
|
|
|
2014-03-05 13:42:42 +04:00
|
|
|
aNetworkInfo->type() = info[0];
|
|
|
|
aNetworkInfo->isWifi() = info[1] == 1.0f;
|
|
|
|
aNetworkInfo->dhcpGateway() = info[2];
|
2012-01-16 17:44:07 +04:00
|
|
|
|
2015-01-10 03:33:57 +03:00
|
|
|
env->ReleaseDoubleArrayElements(arr.Get(), info, 0);
|
2012-01-16 17:44:07 +04:00
|
|
|
}
|
|
|
|
|
2013-05-28 20:49:04 +04:00
|
|
|
jobject AndroidBridge::GetGlobalContextRef() {
|
2017-11-01 21:48:49 +03:00
|
|
|
// The context object can change, so get a fresh copy every time.
|
2017-06-02 23:13:41 +03:00
|
|
|
auto context = GeckoAppShell::GetApplicationContext();
|
2017-11-01 21:48:49 +03:00
|
|
|
sGlobalContext = jni::Object::GlobalRef(context).Forget();
|
2015-01-10 03:33:57 +03:00
|
|
|
MOZ_ASSERT(sGlobalContext);
|
2013-09-25 10:06:21 +04:00
|
|
|
return sGlobalContext;
|
2013-02-10 01:38:08 +04:00
|
|
|
}
|
|
|
|
|
2011-10-11 04:40:17 +04:00
|
|
|
/* Implementation file */
|
2016-11-22 01:24:36 +03:00
|
|
|
NS_IMPL_ISUPPORTS(nsAndroidBridge, nsIAndroidEventDispatcher, nsIAndroidBridge,
|
|
|
|
nsIObserver)
|
2011-10-11 04:40:17 +04:00
|
|
|
|
2017-03-27 05:59:04 +03:00
|
|
|
nsAndroidBridge::nsAndroidBridge() : mAudibleWindowsNum(0) {
|
2016-11-21 22:14:32 +03:00
|
|
|
if (jni::IsAvailable()) {
|
|
|
|
RefPtr<widget::EventDispatcher> dispatcher = new widget::EventDispatcher();
|
|
|
|
dispatcher->Attach(java::EventDispatcher::GetInstance(),
|
|
|
|
/* window */ nullptr);
|
|
|
|
mEventDispatcher = dispatcher;
|
|
|
|
}
|
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 16:29:50 +03:00
|
|
|
|
2016-04-18 13:48:19 +03:00
|
|
|
AddObservers();
|
2011-10-11 04:40:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsAndroidBridge::~nsAndroidBridge() {}
|
|
|
|
|
2016-10-03 19:26:00 +03:00
|
|
|
NS_IMETHODIMP nsAndroidBridge::ContentDocumentChanged(
|
|
|
|
mozIDOMWindowProxy* aWindow) {
|
|
|
|
AndroidBridge::Bridge()->ContentDocumentChanged(aWindow);
|
2013-05-30 17:55:23 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2016-10-03 19:26:00 +03:00
|
|
|
NS_IMETHODIMP nsAndroidBridge::IsContentDocumentDisplayed(
|
|
|
|
mozIDOMWindowProxy* aWindow, bool* aRet) {
|
|
|
|
*aRet = AndroidBridge::Bridge()->IsContentDocumentDisplayed(aWindow);
|
2013-05-30 17:55:23 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2016-04-18 13:48:19 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsAndroidBridge::Observe(nsISupports* aSubject, const char* aTopic,
|
|
|
|
const char16_t* aData) {
|
|
|
|
if (!strcmp(aTopic, "xpcom-shutdown")) {
|
|
|
|
RemoveObservers();
|
2017-03-27 05:59:04 +03:00
|
|
|
} else if (!strcmp(aTopic, "audio-playback")) {
|
|
|
|
ALOG_BRIDGE("nsAndroidBridge::Observe, get audio-playback event.");
|
2016-06-01 05:21:58 +03:00
|
|
|
|
2016-09-09 04:49:25 +03:00
|
|
|
nsAutoString activeStr(aData);
|
|
|
|
bool isPlaying = activeStr.EqualsLiteral("active");
|
2017-03-27 05:59:04 +03:00
|
|
|
UpdateAudioPlayingWindows(isPlaying);
|
2016-06-01 05:21:58 +03:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2017-03-27 05:59:04 +03:00
|
|
|
void nsAndroidBridge::UpdateAudioPlayingWindows(bool aPlaying) {
|
2016-06-01 05:21:58 +03:00
|
|
|
// Request audio focus for the first audio playing window and abandon focus
|
|
|
|
// for the last audio playing window.
|
2017-03-27 05:59:04 +03:00
|
|
|
MOZ_ASSERT(mAudibleWindowsNum >= 0);
|
|
|
|
if (aPlaying && mAudibleWindowsNum++ == 0) {
|
|
|
|
ALOG_BRIDGE("nsAndroidBridge, request audio focus.");
|
|
|
|
AudioFocusAgent::NotifyStartedPlaying();
|
|
|
|
} else if (!aPlaying && --mAudibleWindowsNum == 0) {
|
|
|
|
ALOG_BRIDGE("nsAndroidBridge, abandon audio focus.");
|
|
|
|
AudioFocusAgent::NotifyStoppedPlaying();
|
2016-04-18 13:48:19 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsAndroidBridge::AddObservers() {
|
|
|
|
nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
|
|
|
|
if (obs) {
|
|
|
|
obs->AddObserver(this, "xpcom-shutdown", false);
|
2016-09-29 06:49:25 +03:00
|
|
|
if (jni::IsFennec()) { // No AudioFocusAgent in non-Fennec environment.
|
2017-03-27 05:59:04 +03:00
|
|
|
obs->AddObserver(this, "audio-playback", false);
|
2016-09-29 06:49:25 +03:00
|
|
|
}
|
2016-04-18 13:48:19 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsAndroidBridge::RemoveObservers() {
|
|
|
|
nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
|
|
|
|
if (obs) {
|
|
|
|
obs->RemoveObserver(this, "xpcom-shutdown");
|
2016-09-29 06:49:25 +03:00
|
|
|
if (jni::IsFennec()) { // No AudioFocusAgent in non-Fennec environment.
|
2017-03-27 05:59:04 +03:00
|
|
|
obs->RemoveObserver(this, "audio-playback");
|
2016-09-29 06:49:25 +03:00
|
|
|
}
|
2016-04-18 13:48:19 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-09 01:36:07 +04:00
|
|
|
uint32_t AndroidBridge::GetScreenOrientation() {
|
2012-03-20 17:09:45 +04:00
|
|
|
ALOG_BRIDGE("AndroidBridge::GetScreenOrientation");
|
2012-05-04 19:08:47 +04:00
|
|
|
|
2016-08-13 06:15:52 +03:00
|
|
|
int16_t orientation = GeckoAppShell::GetScreenOrientation();
|
2012-05-04 19:08:47 +04:00
|
|
|
|
2018-08-29 23:54:56 +03:00
|
|
|
return static_cast<hal::ScreenOrientation>(orientation);
|
2012-03-20 17:09:45 +04:00
|
|
|
}
|
|
|
|
|
2015-08-19 00:55:15 +03:00
|
|
|
uint16_t AndroidBridge::GetScreenAngle() {
|
|
|
|
return GeckoAppShell::GetScreenAngle();
|
|
|
|
}
|
|
|
|
|
2012-11-13 23:25:18 +04:00
|
|
|
nsresult AndroidBridge::GetProxyForURI(const nsACString& aSpec,
|
|
|
|
const nsACString& aScheme,
|
|
|
|
const nsACString& aHost,
|
|
|
|
const int32_t aPort,
|
|
|
|
nsACString& aResult) {
|
2015-08-13 07:53:39 +03:00
|
|
|
if (!jni::IsAvailable()) {
|
2014-01-18 09:32:24 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2012-11-13 23:25:18 +04:00
|
|
|
|
2016-08-13 06:15:52 +03:00
|
|
|
auto jstrRet = GeckoAppShell::GetProxyForURI(aSpec, aScheme, aHost, aPort);
|
2012-11-13 23:25:18 +04:00
|
|
|
|
|
|
|
if (!jstrRet) return NS_ERROR_FAILURE;
|
|
|
|
|
2016-02-10 01:27:28 +03:00
|
|
|
aResult = jstrRet->ToCString();
|
2012-11-13 23:25:18 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-04-28 03:52:52 +03:00
|
|
|
bool AndroidBridge::PumpMessageLoop() {
|
2015-08-13 07:53:39 +03:00
|
|
|
JNIEnv* const env = jni::GetGeckoThreadEnv();
|
2015-04-28 03:52:52 +03:00
|
|
|
|
|
|
|
if (mMessageQueueMessages) {
|
2017-11-01 21:48:49 +03:00
|
|
|
auto msg = jni::Object::LocalRef::Adopt(
|
2015-04-28 03:52:52 +03:00
|
|
|
env, env->GetObjectField(mMessageQueue.Get(), mMessageQueueMessages));
|
|
|
|
// if queue.mMessages is null, queue.next() will block, which we don't
|
|
|
|
// want. It turns out to be an order of magnitude more performant to do
|
|
|
|
// this extra check here and block less vs. one fewer checks here and
|
|
|
|
// more blocking.
|
|
|
|
if (!msg) {
|
|
|
|
return false;
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2015-04-28 03:52:52 +03:00
|
|
|
|
2017-11-01 21:48:49 +03:00
|
|
|
auto msg = jni::Object::LocalRef::Adopt(
|
2015-08-13 07:53:39 +03:00
|
|
|
env, env->CallObjectMethod(mMessageQueue.Get(), mMessageQueueNext));
|
2015-04-28 03:52:52 +03:00
|
|
|
if (!msg) {
|
|
|
|
return false;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2015-08-13 07:53:39 +03:00
|
|
|
return GeckoThread::PumpMessageLoop(msg);
|
2015-04-28 03:52:52 +03:00
|
|
|
}
|
2012-11-13 23:25:18 +04:00
|
|
|
|
2018-10-31 21:56:08 +03:00
|
|
|
NS_IMETHODIMP nsAndroidBridge::GetIsFennec(bool* aIsFennec) {
|
|
|
|
*aIsFennec = jni::IsFennec();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-02-17 22:52:26 +04:00
|
|
|
NS_IMETHODIMP nsAndroidBridge::GetBrowserApp(
|
|
|
|
nsIAndroidBrowserApp** aBrowserApp) {
|
2015-12-24 06:03:35 +03:00
|
|
|
nsAppShell* const appShell = nsAppShell::Get();
|
2016-07-21 20:49:04 +03:00
|
|
|
if (appShell) NS_IF_ADDREF(*aBrowserApp = appShell->GetBrowserApp());
|
2012-02-17 22:52:26 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2012-05-04 19:08:47 +04:00
|
|
|
|
2012-02-17 22:52:26 +04:00
|
|
|
NS_IMETHODIMP nsAndroidBridge::SetBrowserApp(
|
|
|
|
nsIAndroidBrowserApp* aBrowserApp) {
|
2015-12-24 06:03:35 +03:00
|
|
|
nsAppShell* const appShell = nsAppShell::Get();
|
|
|
|
if (appShell) appShell->SetBrowserApp(aBrowserApp);
|
2012-02-17 22:52:26 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" __attribute__((visibility("default"))) jobject JNICALL
|
2012-05-04 19:08:47 +04:00
|
|
|
Java_org_mozilla_gecko_GeckoAppShell_allocateDirectBuffer(JNIEnv* env, jclass,
|
|
|
|
jlong size);
|
2012-02-17 22:52:26 +04:00
|
|
|
|
2016-10-03 19:26:00 +03:00
|
|
|
void AndroidBridge::ContentDocumentChanged(mozIDOMWindowProxy* aWindow) {
|
2018-11-16 20:31:58 +03:00
|
|
|
if (RefPtr<nsWindow> widget =
|
|
|
|
nsWindow::From(nsPIDOMWindowOuter::From(aWindow))) {
|
2017-11-22 22:12:22 +03:00
|
|
|
widget->SetContentDocumentDisplayed(false);
|
2013-11-12 22:41:01 +04:00
|
|
|
}
|
2013-05-30 17:55:23 +04:00
|
|
|
}
|
|
|
|
|
2016-10-03 19:26:00 +03:00
|
|
|
bool AndroidBridge::IsContentDocumentDisplayed(mozIDOMWindowProxy* aWindow) {
|
2018-11-16 20:31:58 +03:00
|
|
|
if (RefPtr<nsWindow> widget =
|
|
|
|
nsWindow::From(nsPIDOMWindowOuter::From(aWindow))) {
|
2017-11-22 22:12:22 +03:00
|
|
|
return widget->IsContentDocumentDisplayed();
|
2016-10-03 19:26:00 +03:00
|
|
|
}
|
2017-11-22 22:12:22 +03:00
|
|
|
return false;
|
2013-05-30 17:55:23 +04:00
|
|
|
}
|
|
|
|
|
2017-11-01 21:48:49 +03:00
|
|
|
jni::Object::LocalRef AndroidBridge::ChannelCreate(jni::Object::Param stream) {
|
|
|
|
JNIEnv* const env = jni::GetEnvForThread();
|
|
|
|
auto rv = jni::Object::LocalRef::Adopt(
|
|
|
|
env, env->CallStaticObjectMethod(sBridge->jChannels,
|
2015-09-24 21:53:05 +03:00
|
|
|
sBridge->jChannelCreate, stream.Get()));
|
2015-12-31 02:36:41 +03:00
|
|
|
MOZ_CATCH_JNI_EXCEPTION(env);
|
2015-01-10 03:33:57 +03:00
|
|
|
return rv;
|
2014-06-04 23:28:04 +04:00
|
|
|
}
|
|
|
|
|
2017-11-01 21:48:49 +03:00
|
|
|
void AndroidBridge::InputStreamClose(jni::Object::Param obj) {
|
|
|
|
JNIEnv* const env = jni::GetEnvForThread();
|
2015-01-10 03:33:57 +03:00
|
|
|
env->CallVoidMethod(obj.Get(), sBridge->jClose);
|
2015-12-31 02:36:41 +03:00
|
|
|
MOZ_CATCH_JNI_EXCEPTION(env);
|
2014-06-04 23:28:04 +04:00
|
|
|
}
|
|
|
|
|
2017-11-01 21:48:49 +03:00
|
|
|
uint32_t AndroidBridge::InputStreamAvailable(jni::Object::Param obj) {
|
|
|
|
JNIEnv* const env = jni::GetEnvForThread();
|
2015-01-10 03:33:57 +03:00
|
|
|
auto rv = env->CallIntMethod(obj.Get(), sBridge->jAvailable);
|
2015-12-31 02:36:41 +03:00
|
|
|
MOZ_CATCH_JNI_EXCEPTION(env);
|
2015-01-10 03:33:57 +03:00
|
|
|
return rv;
|
2014-06-04 23:28:04 +04:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-11-01 21:48:49 +03:00
|
|
|
nsresult AndroidBridge::InputStreamRead(jni::Object::Param obj, char* aBuf,
|
|
|
|
uint32_t aCount, uint32_t* aRead) {
|
|
|
|
JNIEnv* const env = jni::GetEnvForThread();
|
|
|
|
auto arr = jni::ByteBuffer::New(aBuf, aCount);
|
2015-01-10 03:33:57 +03:00
|
|
|
jint read =
|
|
|
|
env->CallIntMethod(obj.Get(), sBridge->jByteBufferRead, arr.Get());
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-06-04 23:28:04 +04:00
|
|
|
if (env->ExceptionCheck()) {
|
|
|
|
env->ExceptionClear();
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (read <= 0) {
|
|
|
|
*aRead = 0;
|
|
|
|
return NS_OK;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2014-06-04 23:28:04 +04:00
|
|
|
*aRead = read;
|
|
|
|
return NS_OK;
|
|
|
|
}
|