Bug 1192077 - Convert AndroidBridge JNIEnv calls; r=esawin

This commit is contained in:
Jim Chen 2015-08-13 00:53:39 -04:00
parent 2fb5d313bd
commit 25353fa7f4
21 changed files with 94 additions and 88 deletions

View File

@ -206,7 +206,7 @@ public:
AudioDataDecoder(const AudioInfo& aConfig, MediaFormat::Param aFormat, MediaDataDecoderCallback* aCallback)
: MediaCodecDataDecoder(MediaData::Type::AUDIO_DATA, aConfig.mMimeType, aFormat, aCallback)
{
JNIEnv* env = GetJNIForThread();
JNIEnv* const env = jni::GetEnvForThread();
jni::Object::LocalRef buffer(env);
NS_ENSURE_SUCCESS_VOID(aFormat->GetByteBuffer(NS_LITERAL_STRING("csd-0"), &buffer));
@ -427,7 +427,7 @@ void MediaCodecDataDecoder::DecoderLoop()
bool draining = false;
bool waitingEOF = false;
AutoLocalJNIFrame frame(GetJNIForThread(), 1);
AutoLocalJNIFrame frame(jni::GetEnvForThread(), 1);
nsRefPtr<MediaRawData> sample;
MediaFormat::LocalRef outputFormat(frame.GetEnv());

View File

@ -130,7 +130,9 @@ MediaEngineWebRTC::EnumerateVideoDevices(dom::MediaSourceEnum aMediaSource,
#ifdef MOZ_WIDGET_ANDROID
// get the JVM
JavaVM *jvm = mozilla::AndroidBridge::Bridge()->GetVM();
JavaVM* jvm;
JNIEnv* const env = jni::GetEnvForThread();
MOZ_ALWAYS_TRUE(!env->GetJavaVM(&jvm));
if (webrtc::VideoEngine::SetAndroidObjects(jvm) != 0) {
LOG(("VieCapture:SetAndroidObjects Failed"));
@ -302,8 +304,9 @@ MediaEngineWebRTC::EnumerateAudioDevices(dom::MediaSourceEnum aMediaSource,
jobject context = mozilla::AndroidBridge::Bridge()->GetGlobalContextRef();
// get the JVM
JavaVM *jvm = mozilla::AndroidBridge::Bridge()->GetVM();
JNIEnv *env = GetJNIForThread();
JavaVM* jvm;
JNIEnv* const env = jni::GetEnvForThread();
MOZ_ALWAYS_TRUE(!env->GetJavaVM(&jvm));
if (webrtc::VoiceEngine::SetAndroidObjects(jvm, env, (void*)context) != 0) {
LOG(("VoiceEngine:SetAndroidObjects Failed"));

View File

@ -37,7 +37,7 @@ nsresult
PluginPRLibrary::NP_Initialize(NPNetscapeFuncs* bFuncs,
NPPluginFuncs* pFuncs, NPError* error)
{
JNIEnv* env = GetJNIForThread();
JNIEnv* env = jni::GetEnvForThread();
mozilla::AutoLocalJNIFrame jniFrame(env);

View File

@ -124,7 +124,7 @@ AudioRunnable::Run()
{
PR_SetCurrentThreadName("Android Audio");
JNIEnv* jenv = GetJNIForThread();
JNIEnv* const jenv = mozilla::jni::GetEnvForThread();
mozilla::AutoLocalJNIFrame autoFrame(jenv, 2);
@ -207,7 +207,7 @@ anp_audio_newTrack(uint32_t sampleRate, // sampling rate in Hz
return nullptr;
}
JNIEnv *jenv = GetJNIForThread();
JNIEnv* const jenv = mozilla::jni::GetEnvForThread();
s->at_class = init_jni_bindings(jenv);
s->rate = sampleRate;
@ -303,7 +303,7 @@ anp_audio_start(ANPAudioTrack* s)
return;
}
JNIEnv *jenv = GetJNIForThread();
JNIEnv* const jenv = mozilla::jni::GetEnvForThread();
mozilla::AutoLocalJNIFrame autoFrame(jenv, 0);
jenv->CallVoidMethod(s->output_unit, at.play);
@ -331,7 +331,7 @@ anp_audio_pause(ANPAudioTrack* s)
return;
}
JNIEnv *jenv = GetJNIForThread();
JNIEnv* const jenv = mozilla::jni::GetEnvForThread();
mozilla::AutoLocalJNIFrame autoFrame(jenv, 0);
jenv->CallVoidMethod(s->output_unit, at.pause);
@ -345,7 +345,7 @@ anp_audio_stop(ANPAudioTrack* s)
}
s->isStopped = true;
JNIEnv *jenv = GetJNIForThread();
JNIEnv* const jenv = mozilla::jni::GetEnvForThread();
mozilla::AutoLocalJNIFrame autoFrame(jenv, 0);
jenv->CallVoidMethod(s->output_unit, at.stop);

View File

@ -1393,7 +1393,7 @@ bool nsPluginInstanceOwner::AddPluginView(const LayoutDeviceRect& aRect /* = Lay
if (!mJavaView)
return false;
mJavaView = (void*)AndroidBridge::GetJNIEnv()->NewGlobalRef((jobject)mJavaView);
mJavaView = (void*)jni::GetGeckoThreadEnv()->NewGlobalRef((jobject)mJavaView);
}
if (AndroidBridge::Bridge())
@ -1412,7 +1412,7 @@ void nsPluginInstanceOwner::RemovePluginView()
widget::GeckoAppShell::RemovePluginView(
jni::Object::Ref::From(jobject(mJavaView)), mFullScreen);
AndroidBridge::GetJNIEnv()->DeleteGlobalRef((jobject)mJavaView);
jni::GetGeckoThreadEnv()->DeleteGlobalRef((jobject)mJavaView);
mJavaView = nullptr;
if (mFullScreen)
@ -1493,7 +1493,7 @@ void nsPluginInstanceOwner::ExitFullScreen() {
}
void nsPluginInstanceOwner::ExitFullScreen(jobject view) {
JNIEnv* env = AndroidBridge::GetJNIEnv();
JNIEnv* env = jni::GetGeckoThreadEnv();
if (sFullScreenInstance && sFullScreenInstance->mInstance &&
env->IsSameObject(view, (jobject)sFullScreenInstance->mInstance->GetJavaSurface())) {

View File

@ -166,7 +166,7 @@ AndroidSurfaceTexture::Init(GLContext* aContext, GLuint aTexture)
return false;
}
mNativeWindow = AndroidNativeWindow::CreateFromSurface(GetJNIForThread(),
mNativeWindow = AndroidNativeWindow::CreateFromSurface(jni::GetEnvForThread(),
mSurface.Get());
MOZ_ASSERT(mNativeWindow, "Failed to create native window from surface");
@ -207,7 +207,7 @@ AndroidSurfaceTexture::UpdateTexImage()
void
AndroidSurfaceTexture::GetTransformMatrix(gfx::Matrix4x4& aMatrix)
{
JNIEnv* env = GetJNIForThread();
JNIEnv* const env = jni::GetEnvForThread();
auto jarray = FloatArray::LocalRef::Adopt(env, env->NewFloatArray(16));
mSurfaceTexture->GetTransformMatrix(jarray);

View File

@ -257,7 +257,6 @@ public class GeckoAppShell
// Initialization methods
public static native void registerJavaUiThread();
public static native void nativeInit(ClassLoader clsLoader, MessageQueue msgQueue);
// helper methods
public static native void onResume();

View File

@ -31,8 +31,7 @@ public @interface WrapForJNI {
/**
* If set, the generated method stub will support being called from any thread via the use of
* GetJNIForThread. This is rarely useful, at time of writing, as well as possibly risky.
* See information in AndroidBridge.cpp regarding GetJNIForThread.
* GetEnvForThread. This is rarely useful, at time of writing, as well as possibly risky.
*
* Did I mention use of this function is discouraged?
*/

View File

@ -76,7 +76,7 @@ nsAndroidHistory::RegisterVisitedCallback(nsIURI *aURI, Link *aContent)
}
list->AppendElement(aContent);
if (AndroidBridge::HasEnv()) {
if (jni::IsAvailable()) {
widget::GeckoAppShell::CheckURIVisited(uriString);
}
@ -199,7 +199,7 @@ nsAndroidHistory::SaveVisitURI(nsIURI* aURI) {
// Add the URI to our cache so we can take a fast path later
AppendToRecentlyVisitedURIs(aURI);
if (AndroidBridge::HasEnv()) {
if (jni::IsAvailable()) {
// Save this URI in our history
nsAutoCString spec;
(void)aURI->GetSpec(spec);
@ -283,7 +283,7 @@ nsAndroidHistory::SetURITitle(nsIURI *aURI, const nsAString& aTitle)
return NS_OK;
}
if (AndroidBridge::HasEnv()) {
if (jni::IsAvailable()) {
nsAutoCString uri;
nsresult rv = aURI->GetSpec(uri);
if (NS_FAILED(rv)) return rv;

View File

@ -13,7 +13,8 @@
#include "nsThreadUtils.h"
#include "prnetdb.h"
#include "AndroidBridge.h"
#include "mozilla/jni/Utils.h"
#include "GeneratedJNIWrappers.h"
namespace mozilla {
namespace net {
@ -80,7 +81,7 @@ Tickler::Init()
MOZ_ASSERT(!mThread);
MOZ_ASSERT(!mFD);
if (AndroidBridge::HasEnv()) {
if (jni::IsAvailable()) {
widget::GeckoAppShell::EnableNetworkNotifications();
}

View File

@ -13,7 +13,7 @@ NS_IMPL_ISUPPORTS(nsParentalControlsService, nsIParentalControlsService)
nsParentalControlsService::nsParentalControlsService() :
mEnabled(false)
{
if (mozilla::AndroidBridge::HasEnv()) {
if (mozilla::jni::IsAvailable()) {
mEnabled = mozilla::widget::RestrictedProfiles::IsUserRestricted();
}
}
@ -85,7 +85,7 @@ nsParentalControlsService::IsAllowed(int16_t aAction,
return rv;
}
if (mozilla::AndroidBridge::HasEnv()) {
if (mozilla::jni::IsAvailable()) {
nsAutoCString url;
if (aUri) {
rv = aUri->GetSpec(url);

View File

@ -315,7 +315,7 @@ void AutoGlobalWrappedJavaObject::Dispose() {
return;
}
GetJNIForThread()->DeleteGlobalRef(wrapped_obj);
GetEnvForThread()->DeleteGlobalRef(wrapped_obj);
wrapped_obj = nullptr;
}
@ -564,7 +564,7 @@ AndroidBridge::GetScreenDepth()
const int DEFAULT_DEPTH = 16;
if (HasEnv()) {
if (jni::IsAvailable()) {
sDepth = GeckoAppShell::GetScreenDepthWrapper();
}
if (!sDepth)
@ -598,7 +598,7 @@ AndroidBridge::Vibrate(const nsTArray<uint32_t>& aPattern)
// First element of the array vibrate() expects is how long to wait
// *before* vibrating. For us, this is always 0.
JNIEnv *env = GetJNIEnv();
JNIEnv* const env = jni::GetGeckoThreadEnv();
AutoLocalJNIFrame jniFrame(env, 1);
jlongArray array = env->NewLongArray(len + 1);
@ -727,7 +727,7 @@ AndroidBridge::CreateEGLSurfaceForCompositor()
return nullptr;
}
JNIEnv* const env = GetJNIForThread(); // called on the compositor thread
JNIEnv* const env = GetEnvForThread(); // called on the compositor thread
return reinterpret_cast<EGLSurface>(mAPIVersion >= 20 ?
env->GetLongField(eglSurface.Get(), jEGLSurfacePointerField) :
env->GetIntField(eglSurface.Get(), jEGLSurfacePointerField));
@ -739,10 +739,10 @@ AndroidBridge::GetStaticIntField(const char *className, const char *fieldName, i
ALOG_BRIDGE("AndroidBridge::GetStaticIntField %s", fieldName);
if (!jEnv) {
if (!HasEnv()) {
if (!jni::IsAvailable()) {
return false;
}
jEnv = GetJNIEnv();
jEnv = jni::GetGeckoThreadEnv();
}
AutoJNIClass cls(jEnv, className);
@ -762,10 +762,10 @@ AndroidBridge::GetStaticStringField(const char *className, const char *fieldName
ALOG_BRIDGE("AndroidBridge::GetStaticStringField %s", fieldName);
if (!jEnv) {
if (!HasEnv()) {
if (!jni::IsAvailable()) {
return false;
}
jEnv = GetJNIEnv();
jEnv = jni::GetGeckoThreadEnv();
}
AutoLocalJNIFrame jniFrame(jEnv, 1);
@ -966,7 +966,7 @@ AndroidBridge::ValidateBitmap(jobject bitmap, int width, int height)
int err;
struct BitmapInfo info = { 0, };
JNIEnv *env = GetJNIEnv();
JNIEnv* const env = jni::GetGeckoThreadEnv();
if ((err = AndroidBitmap_getInfo(env, bitmap, &info)) != 0) {
ALOG_BRIDGE("AndroidBitmap_getInfo failed! (error %d)", err);
@ -1045,7 +1045,7 @@ AndroidBridge::GetSegmentInfoForText(const nsAString& aText,
int32_t segments, charsPerSegment, charsAvailableInLastSegment;
JNIEnv *env = GetJNIEnv();
JNIEnv* const env = jni::GetGeckoThreadEnv();
AutoLocalJNIFrame jniFrame(env, 2);
jstring jText = NewJavaString(&jniFrame, aText);
@ -1119,7 +1119,7 @@ AndroidBridge::CreateMessageList(const dom::mobilemessage::SmsFilterData& aFilte
{
ALOG_BRIDGE("AndroidBridge::CreateMessageList");
JNIEnv *env = GetJNIEnv();
JNIEnv* const env = jni::GetGeckoThreadEnv();
uint32_t requestId;
if (!QueueSmsRequest(aRequest, &requestId))
@ -1223,7 +1223,7 @@ AndroidBridge::GetCurrentNetworkInformation(hal::NetworkInformation* aNetworkInf
void *
AndroidBridge::LockBitmap(jobject bitmap)
{
JNIEnv *env = GetJNIEnv();
JNIEnv* const env = jni::GetGeckoThreadEnv();
int err;
void *buf;
@ -1239,7 +1239,7 @@ AndroidBridge::LockBitmap(jobject bitmap)
void
AndroidBridge::UnlockBitmap(jobject bitmap)
{
JNIEnv *env = GetJNIEnv();
JNIEnv* const env = jni::GetGeckoThreadEnv();
int err;
@ -1397,7 +1397,7 @@ AndroidBridge::GetGlobalContextRef() {
return sGlobalContext;
}
JNIEnv* const env = GetJNIForThread();
JNIEnv* const env = GetEnvForThread();
AutoLocalJNIFrame jniFrame(env, 4);
auto context = GeckoAppShell::GetContext();
@ -1625,7 +1625,7 @@ AndroidBridge::GetProxyForURI(const nsACString & aSpec,
const int32_t aPort,
nsACString & aResult)
{
if (!HasEnv()) {
if (!jni::IsAvailable()) {
return NS_ERROR_FAILURE;
}
@ -1641,7 +1641,7 @@ AndroidBridge::GetProxyForURI(const nsACString & aSpec,
bool
AndroidBridge::PumpMessageLoop()
{
JNIEnv* const env = GetJNIEnv();
JNIEnv* const env = jni::GetGeckoThreadEnv();
if (mMessageQueueMessages) {
auto msg = Object::LocalRef::Adopt(env,
@ -1740,7 +1740,7 @@ AndroidBridge::CaptureZoomedView(nsIDOMWindow *window, nsIntRect zoomedViewRect,
if (!utils)
return NS_ERROR_FAILURE;
JNIEnv* env = GetJNIEnv();
JNIEnv* const env = jni::GetGeckoThreadEnv();
AutoLocalJNIFrame jniFrame(env, 0);
@ -1846,7 +1846,7 @@ nsresult AndroidBridge::CaptureThumbnail(nsIDOMWindow *window, int32_t bufW, int
srcH = height;
}
JNIEnv* env = GetJNIEnv();
JNIEnv* const env = jni::GetGeckoThreadEnv();
AutoLocalJNIFrame jniFrame(env, 0);
@ -1917,7 +1917,7 @@ AndroidBridge::GetDisplayPort(bool aPageSizeUpdate, bool aIsBrowserContentDispla
return;
}
JNIEnv* const env = GetJNIEnv();
JNIEnv* const env = jni::GetGeckoThreadEnv();
AutoLocalJNIFrame jniFrame(env, 1);
float x, y, width, height,
@ -2103,7 +2103,7 @@ AndroidBridge::SetPresentationSurface(EGLSurface aPresentationSurface)
}
Object::LocalRef AndroidBridge::ChannelCreate(Object::Param stream) {
JNIEnv* const env = GetJNIForThread();
JNIEnv* const env = GetEnvForThread();
auto rv = Object::LocalRef::Adopt(env, env->CallStaticObjectMethod(
sBridge->jReadableByteChannel, sBridge->jChannelCreate, stream.Get()));
HandleUncaughtException(env);
@ -2111,20 +2111,20 @@ Object::LocalRef AndroidBridge::ChannelCreate(Object::Param stream) {
}
void AndroidBridge::InputStreamClose(Object::Param obj) {
JNIEnv* const env = GetJNIForThread();
JNIEnv* const env = GetEnvForThread();
env->CallVoidMethod(obj.Get(), sBridge->jClose);
HandleUncaughtException(env);
}
uint32_t AndroidBridge::InputStreamAvailable(Object::Param obj) {
JNIEnv* const env = GetJNIForThread();
JNIEnv* const env = GetEnvForThread();
auto rv = env->CallIntMethod(obj.Get(), sBridge->jAvailable);
HandleUncaughtException(env);
return rv;
}
nsresult AndroidBridge::InputStreamRead(Object::Param obj, char *aBuf, uint32_t aCount, uint32_t *aRead) {
JNIEnv* const env = GetJNIForThread();
JNIEnv* const env = GetEnvForThread();
auto arr = Object::LocalRef::Adopt(env, env->NewDirectByteBuffer(aBuf, aCount));
jint read = env->CallIntMethod(obj.Get(), sBridge->jByteBufferRead, arr.Get());

View File

@ -463,12 +463,12 @@ class AutoJObject {
public:
AutoJObject(JNIEnv* aJNIEnv = nullptr) : mObject(nullptr)
{
mJNIEnv = aJNIEnv ? aJNIEnv : AndroidBridge::GetJNIEnv();
mJNIEnv = aJNIEnv ? aJNIEnv : jni::GetGeckoThreadEnv();
}
AutoJObject(JNIEnv* aJNIEnv, jobject aObject)
{
mJNIEnv = aJNIEnv ? aJNIEnv : AndroidBridge::GetJNIEnv();
mJNIEnv = aJNIEnv ? aJNIEnv : jni::GetGeckoThreadEnv();
mObject = aObject;
}
@ -497,7 +497,7 @@ class AutoLocalJNIFrame {
public:
AutoLocalJNIFrame(int nEntries = 15)
: mEntries(nEntries)
, mJNIEnv(AndroidBridge::GetJNIEnv())
, mJNIEnv(jni::GetGeckoThreadEnv())
, mHasFrameBeenPushed(false)
{
MOZ_ASSERT(mJNIEnv);
@ -506,7 +506,7 @@ public:
AutoLocalJNIFrame(JNIEnv* aJNIEnv, int nEntries = 15)
: mEntries(nEntries)
, mJNIEnv(aJNIEnv ? aJNIEnv : AndroidBridge::GetJNIEnv())
, mJNIEnv(aJNIEnv ? aJNIEnv : jni::GetGeckoThreadEnv())
, mHasFrameBeenPushed(false)
{
MOZ_ASSERT(mJNIEnv);

View File

@ -84,7 +84,7 @@ Java_org_mozilla_gecko_GeckoAppShell_notifyGeckoObservers(JNIEnv *aEnv, jclass,
jstring aTopic, jstring aData)
{
if (!NS_IsMainThread()) {
AndroidBridge::ThrowException(aEnv,
jni::ThrowException(aEnv,
"java/lang/IllegalThreadStateException", "Not on Gecko main thread");
return;
}
@ -92,7 +92,7 @@ Java_org_mozilla_gecko_GeckoAppShell_notifyGeckoObservers(JNIEnv *aEnv, jclass,
nsCOMPtr<nsIObserverService> obsServ =
mozilla::services::GetObserverService();
if (!obsServ) {
AndroidBridge::ThrowException(aEnv,
jni::ThrowException(aEnv,
"java/lang/IllegalStateException", "No observer service");
return;
}
@ -827,7 +827,7 @@ Java_org_mozilla_gecko_GeckoAppShell_onFullScreenPluginHidden(JNIEnv* jenv, jcla
ExitFullScreenRunnable(jobject view) : mView(view) {}
NS_IMETHODIMP Run() {
JNIEnv* env = AndroidBridge::GetJNIEnv();
JNIEnv* const env = jni::GetGeckoThreadEnv();
nsPluginInstanceOwner::ExitFullScreen(mView);
env->DeleteGlobalRef(mView);
return NS_OK;

View File

@ -37,14 +37,14 @@ extern "C" {
// FindClass outside the main thread will run into problems due
// to missing the classpath
MOZ_ASSERT(NS_IsMainThread());
JNIEnv *env = mozilla::AndroidBridge::GetJNIEnv();
JNIEnv *env = mozilla::jni::GetGeckoThreadEnv();
return env->FindClass(className);
}
jclass
__jsjni_GetGlobalClassRef(const char *className) {
// root class globally
JNIEnv *env = mozilla::AndroidBridge::GetJNIEnv();
JNIEnv *env = mozilla::jni::GetGeckoThreadEnv();
jclass globalRef = static_cast<jclass>(env->NewGlobalRef(env->FindClass(className)));
if (!globalRef)
return nullptr;
@ -80,14 +80,14 @@ extern "C" {
jsjni_GetStaticMethodID(jclass methodClass,
const char *methodName,
const char *signature) {
JNIEnv *env = mozilla::AndroidBridge::GetJNIEnv();
JNIEnv *env = mozilla::jni::GetGeckoThreadEnv();
return env->GetStaticMethodID(methodClass, methodName, signature);
}
__attribute__ ((visibility("default")))
bool
jsjni_ExceptionCheck() {
JNIEnv *env = mozilla::AndroidBridge::GetJNIEnv();
JNIEnv *env = mozilla::jni::GetGeckoThreadEnv();
return env->ExceptionCheck();
}
@ -96,7 +96,7 @@ extern "C" {
jsjni_CallStaticVoidMethodA(jclass cls,
jmethodID method,
jvalue *values) {
JNIEnv *env = mozilla::AndroidBridge::GetJNIEnv();
JNIEnv *env = mozilla::jni::GetGeckoThreadEnv();
mozilla::AutoLocalJNIFrame jniFrame(env);
env->CallStaticVoidMethodA(cls, method, values);
@ -107,7 +107,7 @@ extern "C" {
jsjni_CallStaticIntMethodA(jclass cls,
jmethodID method,
jvalue *values) {
JNIEnv *env = mozilla::AndroidBridge::GetJNIEnv();
JNIEnv *env = mozilla::jni::GetGeckoThreadEnv();
mozilla::AutoLocalJNIFrame jniFrame(env);
return env->CallStaticIntMethodA(cls, method, values);
@ -120,12 +120,15 @@ extern "C" {
__attribute__ ((visibility("default")))
JavaVM* jsjni_GetVM() {
return mozilla::AndroidBridge::GetVM();
JavaVM* jvm;
JNIEnv* const env = mozilla::jni::GetGeckoThreadEnv();
MOZ_ALWAYS_TRUE(!env->GetJavaVM(&jvm));
return jvm;
}
__attribute__ ((visibility("default")))
JNIEnv* jsjni_GetJNIForThread() {
return GetJNIForThread();
return mozilla::jni::GetEnvForThread();
}
// For compatibility with JNI.jsm; some addons bundle their own JNI.jsm,

View File

@ -105,7 +105,7 @@ jmethodID AndroidLayerRendererFrame::jEndDrawingMethod = 0;
RefCountedJavaObject::~RefCountedJavaObject() {
if (mObject)
GetJNIForThread()->DeleteGlobalRef(mObject);
GetEnvForThread()->DeleteGlobalRef(mObject);
mObject = nullptr;
}
@ -1036,7 +1036,7 @@ nsJNIString::nsJNIString(jstring jstr, JNIEnv *jenv)
}
JNIEnv *jni = jenv;
if (!jni) {
jni = AndroidBridge::GetJNIEnv();
jni = jni::GetGeckoThreadEnv();
}
const jchar* jCharPtr = jni->GetStringChars(jstr, nullptr);
@ -1063,7 +1063,7 @@ nsJNICString::nsJNICString(jstring jstr, JNIEnv *jenv)
}
JNIEnv *jni = jenv;
if (!jni) {
jni = AndroidBridge::GetJNIEnv();
jni = jni::GetGeckoThreadEnv();
}
const char* jCharPtr = jni->GetStringUTFChars(jstr, nullptr);

View File

@ -5,6 +5,7 @@
#include "mozilla/jni/Refs.h"
#include "mozilla/jni/Types.h"
#include "mozilla/jni/Utils.h"
#include "AndroidBridge.h"
namespace mozilla {
@ -60,7 +61,7 @@ protected:
static JNIEnv* BeginAccess()
{
JNIEnv* const env = Traits::isMultithreaded
? GetJNIForThread() : AndroidBridge::GetJNIEnv();
? GetEnvForThread() : GetGeckoThreadEnv();
EnsureClassRef<class Traits::Owner>(env);
return env;
@ -150,7 +151,7 @@ class Method<Traits, void> : public Method<Traits, bool>
public:
template<typename... Args>
static void Call(const Owner* cls, nsresult* rv,
const Args&... args) override
const Args&... args)
{
JNIEnv* const env = Base::BeginAccess();
@ -179,7 +180,7 @@ class Constructor : protected Method<Traits, typename Traits::ReturnType> {
public:
template<typename... Args>
static ReturnType Call(const Owner* cls, nsresult* rv,
const Args&... args) override
const Args&... args)
{
JNIEnv* const env = Base::BeginAccess();

View File

@ -348,7 +348,7 @@ public:
if (sInited) {
return;
}
JNIEnv* const env = GetJNIForThread();
JNIEnv* const env = GetEnvForThread();
MOZ_ALWAYS_TRUE(!env->RegisterNatives(
Accessor::EnsureClassRef<Cls>(env),
Natives::methods,

View File

@ -157,7 +157,7 @@ public:
{
// Treat two references of the same object as being the same.
return Cls::mInstance == other.mInstance &&
GetJNIForThread()->IsSameObject(
GetEnvForThread()->IsSameObject(
Cls::mInstance, other.mInstance) != JNI_FALSE;
}
@ -321,7 +321,7 @@ public:
// when going out of scope.
static LocalRef Adopt(jobject instance)
{
return LocalRef(GetJNIForThread(), instance);
return LocalRef(GetEnvForThread(), instance);
}
static LocalRef Adopt(JNIEnv* env, jobject instance)
@ -343,7 +343,7 @@ public:
ref.mInstance = nullptr;
}
explicit LocalRef(JNIEnv* env = GetJNIForThread())
explicit LocalRef(JNIEnv* env = GetEnvForThread())
: Ref<Cls>(nullptr)
, mEnv(env)
{}
@ -352,7 +352,7 @@ public:
// which means creating a new local reference.
MOZ_IMPLICIT LocalRef(const Ref<Cls>& ref)
: Ref<Cls>(nullptr)
, mEnv(GetJNIForThread())
, mEnv(GetEnvForThread())
{
Ref<Cls>::mInstance = mEnv->NewLocalRef(ref.mInstance);
}
@ -377,7 +377,7 @@ public:
// Implicitly converts nullptr to LocalRef.
MOZ_IMPLICIT LocalRef(decltype(nullptr))
: Ref<Cls>(nullptr)
, mEnv(GetJNIForThread())
, mEnv(GetEnvForThread())
{}
~LocalRef()
@ -445,7 +445,7 @@ private:
return nullptr;
}
if (!env) {
env = GetJNIForThread();
env = GetEnvForThread();
}
return env->NewGlobalRef(instance);
}
@ -491,7 +491,7 @@ public:
~GlobalRef()
{
if (Ref<Cls>::mInstance) {
JNIEnv* const env = GetJNIForThread();
JNIEnv* const env = GetEnvForThread();
env->DeleteGlobalRef(Ref<Cls>::mInstance);
Ref<Cls>::mInstance = nullptr;
}
@ -547,7 +547,7 @@ public:
// Get the length of the jstring.
size_t Length() const
{
JNIEnv* const env = GetJNIForThread();
JNIEnv* const env = GetEnvForThread();
return env->GetStringLength(Get());
}
@ -556,7 +556,7 @@ public:
{
MOZ_ASSERT(String::mInstance);
JNIEnv* const env = GetJNIForThread();
JNIEnv* const env = GetEnvForThread();
const jchar* const str = env->GetStringChars(Get(), nullptr);
const jsize len = env->GetStringLength(Get());
@ -596,22 +596,22 @@ public:
, mEnv(nullptr)
{}
MOZ_IMPLICIT Type(const nsAString& str, JNIEnv* env = GetJNIForThread())
MOZ_IMPLICIT Type(const nsAString& str, JNIEnv* env = GetEnvForThread())
: Ref<String>(GetString(env, str))
, mEnv(env)
{}
MOZ_IMPLICIT Type(const char16_t* str, JNIEnv* env = GetJNIForThread())
MOZ_IMPLICIT Type(const char16_t* str, JNIEnv* env = GetEnvForThread())
: Ref<String>(GetString(env, nsDependentString(str)))
, mEnv(env)
{}
MOZ_IMPLICIT Type(const nsACString& str, JNIEnv* env = GetJNIForThread())
MOZ_IMPLICIT Type(const nsACString& str, JNIEnv* env = GetEnvForThread())
: Ref<String>(GetString(env, NS_ConvertUTF8toUTF16(str)))
, mEnv(env)
{}
MOZ_IMPLICIT Type(const char* str, JNIEnv* env = GetJNIForThread())
MOZ_IMPLICIT Type(const char* str, JNIEnv* env = GetEnvForThread())
: Ref<String>(GetString(env, NS_ConvertUTF8toUTF16(str)))
, mEnv(env)
{}
@ -625,7 +625,7 @@ public:
operator String::LocalRef() const
{
JNIEnv* const env = mEnv ? mEnv : GetJNIForThread();
JNIEnv* const env = mEnv ? mEnv : GetEnvForThread();
// We can't return our existing ref because the returned
// LocalRef could be freed first, so we need a new local ref.
return String::LocalRef::Adopt(env, env->NewLocalRef(Get()));

View File

@ -45,12 +45,12 @@ inline bool ThrowException(JNIEnv *aEnv, const char *aMessage)
inline bool ThrowException(const char *aClass, const char *aMessage)
{
return ThrowException(GetJNIForThread(), aClass, aMessage);
return ThrowException(GetEnvForThread(), aClass, aMessage);
}
inline bool ThrowException(const char *aMessage)
{
return ThrowException(GetJNIForThread(), aMessage);
return ThrowException(GetEnvForThread(), aMessage);
}
void HandleUncaughtException(JNIEnv *aEnv);

View File

@ -245,7 +245,7 @@ nsAppShell::ProcessNextNativeEvent(bool mayWait)
// (bug 750713). Looper messages effectively have the lowest
// priority because we only process them before we're about to
// wait for new events.
if (AndroidBridge::HasEnv() &&
if (jni::IsAvailable() &&
AndroidBridge::Bridge()->PumpMessageLoop()) {
return true;
}