Bug 959237 - Add AndroidBridge::HasEnv checks; r=blassey

For certain tests, the AndroidBridge is not initialized, but some GeckoAppShell functions are still called indirectly. For now, this patch adds checks to skip these calls if there's no AndroidBridge. However, in the future, most of the affected code should be refactored to not require these checks.
This commit is contained in:
Jim Chen 2014-01-17 23:32:24 -06:00
parent 8cf891bd76
commit 57092e14bb
5 changed files with 33 additions and 10 deletions

View File

@ -105,7 +105,9 @@ MessagePump::Run(MessagePump::Delegate* aDelegate)
// This processes messages in the Android Looper. Note that we only
// get here if the normal Gecko event loop has been awoken above.
// Bug 750713
if (MOZ_LIKELY(AndroidBridge::HasEnv())) {
did_work |= GeckoAppShell::PumpMessageLoop();
}
#endif
did_work |= aDelegate->DoDelayedWork(&delayed_work_time_);

View File

@ -62,7 +62,9 @@ nsAndroidHistory::RegisterVisitedCallback(nsIURI *aURI, Link *aContent)
}
list->AppendElement(aContent);
if (AndroidBridge::HasEnv()) {
GeckoAppShell::CheckURIVisited(uriString);
}
return NS_OK;
}
@ -173,11 +175,13 @@ nsAndroidHistory::VisitURI(nsIURI *aURI, nsIURI *aLastVisitedURI, uint32_t aFlag
if (aFlags & VisitFlags::UNRECOVERABLE_ERROR)
return NS_OK;
if (AndroidBridge::HasEnv()) {
nsAutoCString uri;
rv = aURI->GetSpec(uri);
if (NS_FAILED(rv)) return rv;
NS_ConvertUTF8toUTF16 uriString(uri);
GeckoAppShell::MarkURIVisited(uriString);
}
AppendToRecentlyVisitedURIs(aURI);
@ -206,7 +210,7 @@ nsAndroidHistory::SetURITitle(nsIURI *aURI, const nsAString& aTitle)
return NS_OK;
}
if (AndroidBridge::Bridge()) {
if (AndroidBridge::HasEnv()) {
nsAutoCString uri;
nsresult rv = aURI->GetSpec(uri);
if (NS_FAILED(rv)) return rv;

View File

@ -80,7 +80,9 @@ Tickler::Init()
MOZ_ASSERT(!mThread);
MOZ_ASSERT(!mFD);
if (AndroidBridge::HasEnv()) {
GeckoAppShell::EnableNetworkNotifications();
}
mFD = PR_OpenUDPSocket(PR_AF_INET);
if (!mFD)

View File

@ -474,7 +474,9 @@ AndroidBridge::GetScreenDepth()
const int DEFAULT_DEPTH = 16;
if (HasEnv()) {
sDepth = GeckoAppShell::GetScreenDepthWrapper();
}
if (!sDepth)
return DEFAULT_DEPTH;
@ -699,6 +701,9 @@ AndroidBridge::GetStaticIntField(const char *className, const char *fieldName, i
ALOG_BRIDGE("AndroidBridge::GetStaticIntField %s", fieldName);
if (!jEnv) {
if (!HasEnv()) {
return false;
}
jEnv = GetJNIEnv();
}
@ -723,6 +728,9 @@ AndroidBridge::GetStaticStringField(const char *className, const char *fieldName
ALOG_BRIDGE("AndroidBridge::GetStaticStringField %s", fieldName);
if (!jEnv) {
if (!HasEnv()) {
return false;
}
jEnv = GetJNIEnv();
}
@ -1589,6 +1597,9 @@ AndroidBridge::GetProxyForURI(const nsACString & aSpec,
const int32_t aPort,
nsACString & aResult)
{
if (!HasEnv()) {
return NS_ERROR_FAILURE;
}
JNIEnv* env = GetJNIEnv();
AutoLocalJNIFrame jniFrame(env, 1);

View File

@ -155,6 +155,10 @@ public:
return sBridge->mJNIEnv;
}
static bool HasEnv() {
return sBridge && sBridge->mJNIEnv;
}
// The bridge needs to be constructed via ConstructBridge first,
// and then once the Gecko main thread is spun up (Gecko side),
// SetMainThread should be called which will create the JNIEnv for