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.
This commit is contained in:
Jim Chen
2016-08-12 23:15:52 -04:00
parent c405849f27
commit 4c84dd5b3f
7 changed files with 182 additions and 129 deletions

View File

@@ -7,6 +7,7 @@
#include "AndroidBridge.h"
#include "GeneratedJNIWrappers.h"
#include "nsAppShell.h"
#ifdef MOZ_CRASHREPORTER
#include "nsExceptionHandler.h"
@@ -143,7 +144,7 @@ bool HandleUncaughtException(JNIEnv* aEnv)
return false;
}
#ifdef DEBUG
#ifdef MOZ_CHECK_JNI
aEnv->ExceptionDescribe();
#endif
@@ -210,5 +211,26 @@ jclass GetClassGlobalRef(JNIEnv* aEnv, const char* aClassName)
return AndroidBridge::GetClassGlobalRef(aEnv, aClassName);
}
void DispatchToGeckoThread(UniquePtr<AbstractCall>&& aCall)
{
class AbstractCallEvent : public nsAppShell::Event
{
UniquePtr<AbstractCall> mCall;
public:
AbstractCallEvent(UniquePtr<AbstractCall>&& aCall)
: mCall(Move(aCall))
{}
void Run() override
{
(*mCall)();
}
};
nsAppShell::PostEvent(MakeUnique<AbstractCallEvent>(Move(aCall)));
}
} // jni
} // mozilla