diff --git a/ipc/glue/MessagePump.cpp b/ipc/glue/MessagePump.cpp index edaf734b9c4..5a492246047 100644 --- a/ipc/glue/MessagePump.cpp +++ b/ipc/glue/MessagePump.cpp @@ -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 - did_work |= GeckoAppShell::PumpMessageLoop(); + if (MOZ_LIKELY(AndroidBridge::HasEnv())) { + did_work |= GeckoAppShell::PumpMessageLoop(); + } #endif did_work |= aDelegate->DoDelayedWork(&delayed_work_time_); diff --git a/mobile/android/components/build/nsAndroidHistory.cpp b/mobile/android/components/build/nsAndroidHistory.cpp index fc3dce338ec..7a563bde271 100644 --- a/mobile/android/components/build/nsAndroidHistory.cpp +++ b/mobile/android/components/build/nsAndroidHistory.cpp @@ -62,7 +62,9 @@ nsAndroidHistory::RegisterVisitedCallback(nsIURI *aURI, Link *aContent) } list->AppendElement(aContent); - GeckoAppShell::CheckURIVisited(uriString); + 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; - nsAutoCString uri; - rv = aURI->GetSpec(uri); - if (NS_FAILED(rv)) return rv; - NS_ConvertUTF8toUTF16 uriString(uri); - GeckoAppShell::MarkURIVisited(uriString); + 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; diff --git a/netwerk/base/src/Tickler.cpp b/netwerk/base/src/Tickler.cpp index 0a6bfdefef9..d9099a318d9 100644 --- a/netwerk/base/src/Tickler.cpp +++ b/netwerk/base/src/Tickler.cpp @@ -80,7 +80,9 @@ Tickler::Init() MOZ_ASSERT(!mThread); MOZ_ASSERT(!mFD); - GeckoAppShell::EnableNetworkNotifications(); + if (AndroidBridge::HasEnv()) { + GeckoAppShell::EnableNetworkNotifications(); + } mFD = PR_OpenUDPSocket(PR_AF_INET); if (!mFD) diff --git a/widget/android/AndroidBridge.cpp b/widget/android/AndroidBridge.cpp index e9c44009d5e..5bbbe732667 100644 --- a/widget/android/AndroidBridge.cpp +++ b/widget/android/AndroidBridge.cpp @@ -474,7 +474,9 @@ AndroidBridge::GetScreenDepth() const int DEFAULT_DEPTH = 16; - sDepth = GeckoAppShell::GetScreenDepthWrapper(); + 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); diff --git a/widget/android/AndroidBridge.h b/widget/android/AndroidBridge.h index bd6ce754c21..deb2cd9dc8b 100644 --- a/widget/android/AndroidBridge.h +++ b/widget/android/AndroidBridge.h @@ -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