diff options
author | Steve Block <steveblock@google.com> | 2011-05-12 12:48:14 +0100 |
---|---|---|
committer | Steve Block <steveblock@google.com> | 2011-06-02 14:08:37 +0100 |
commit | b4d178df818e8b6e7a1cfbb0e34bbf7bb9d74ec9 (patch) | |
tree | 85bdbdf9e1873a443a8215103fb09d35bd420b33 /Source/WebCore/platform | |
parent | 1b22c7a9c33756726c60ab2c9c67d4bbeac153ce (diff) | |
download | external_webkit-b4d178df818e8b6e7a1cfbb0e34bbf7bb9d74ec9.zip external_webkit-b4d178df818e8b6e7a1cfbb0e34bbf7bb9d74ec9.tar.gz external_webkit-b4d178df818e8b6e7a1cfbb0e34bbf7bb9d74ec9.tar.bz2 |
Always check weak global references before using them
We hold weak references to Java objects from native code in several
places to avoid circular reference problems. These objects may become
weakly reachable at any time, after which the GC could null our weak
reference, so we have to null-check at every use.
Note that weak references are nulled before the referent is finalized,
so we can't rely on doing work in the finalizer to wait for the
currently executing message to complete and to remove other messages
from the queue.
This effectively reverts
https://android-git.corp.google.com/g/#change,30955
Bug: 4336862
Change-Id: I431fcac11220cb406c26e31aacb9bda7ea22776e
Diffstat (limited to 'Source/WebCore/platform')
-rw-r--r-- | Source/WebCore/platform/android/GeolocationServiceBridge.cpp | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/Source/WebCore/platform/android/GeolocationServiceBridge.cpp b/Source/WebCore/platform/android/GeolocationServiceBridge.cpp index 2e81b32..697b63b 100644 --- a/Source/WebCore/platform/android/GeolocationServiceBridge.cpp +++ b/Source/WebCore/platform/android/GeolocationServiceBridge.cpp @@ -87,21 +87,24 @@ GeolocationServiceBridge::~GeolocationServiceBridge() bool GeolocationServiceBridge::start() { - ASSERT(m_javaGeolocationServiceObject); + if (!m_javaGeolocationServiceObject) + return false; return getJNIEnv()->CallBooleanMethod(m_javaGeolocationServiceObject, javaGeolocationServiceClassMethodIDs[GeolocationServiceMethodStart]); } void GeolocationServiceBridge::stop() { - ASSERT(m_javaGeolocationServiceObject); + if (!m_javaGeolocationServiceObject) + return; getJNIEnv()->CallVoidMethod(m_javaGeolocationServiceObject, javaGeolocationServiceClassMethodIDs[GeolocationServiceMethodStop]); } void GeolocationServiceBridge::setEnableGps(bool enable) { - ASSERT(m_javaGeolocationServiceObject); + if (!m_javaGeolocationServiceObject) + return; getJNIEnv()->CallVoidMethod(m_javaGeolocationServiceObject, javaGeolocationServiceClassMethodIDs[GeolocationServiceMethodSetEnableGps], enable); @@ -185,10 +188,13 @@ void GeolocationServiceBridge::startJavaImplementation(Frame* frame) env->GetMethodID(javaGeolocationServiceClass, "setEnableGps", "(Z)V"); // Create the Java GeolocationService object. + jobject context = android::WebViewCore::getWebViewCore(frame->view())->getContext(); + if (!context) + return; jlong nativeObject = reinterpret_cast<jlong>(this); jobject object = env->NewObject(javaGeolocationServiceClass, javaGeolocationServiceClassMethodIDs[GeolocationServiceMethodInit], - android::WebViewCore::getWebViewCore(frame->view())->getContext(), + context, nativeObject); m_javaGeolocationServiceObject = getJNIEnv()->NewGlobalRef(object); @@ -232,7 +238,8 @@ void GeolocationServiceBridge::startJavaImplementation(Frame* frame) void GeolocationServiceBridge::stopJavaImplementation() { // Called by GeolocationServiceAndroid on WebKit thread. - ASSERT(m_javaGeolocationServiceObject); + if (!m_javaGeolocationServiceObject) + return; getJNIEnv()->DeleteGlobalRef(m_javaGeolocationServiceObject); } |