summaryrefslogtreecommitdiffstats
path: root/Source/WebKit/android/jni/DeviceOrientationClientImpl.cpp
diff options
context:
space:
mode:
authorSteve Block <steveblock@google.com>2011-05-12 12:48:14 +0100
committerSteve Block <steveblock@google.com>2011-06-02 14:08:37 +0100
commitb4d178df818e8b6e7a1cfbb0e34bbf7bb9d74ec9 (patch)
tree85bdbdf9e1873a443a8215103fb09d35bd420b33 /Source/WebKit/android/jni/DeviceOrientationClientImpl.cpp
parent1b22c7a9c33756726c60ab2c9c67d4bbeac153ce (diff)
downloadexternal_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/WebKit/android/jni/DeviceOrientationClientImpl.cpp')
-rw-r--r--Source/WebKit/android/jni/DeviceOrientationClientImpl.cpp30
1 files changed, 20 insertions, 10 deletions
diff --git a/Source/WebKit/android/jni/DeviceOrientationClientImpl.cpp b/Source/WebKit/android/jni/DeviceOrientationClientImpl.cpp
index bf3b3c3..718389f 100644
--- a/Source/WebKit/android/jni/DeviceOrientationClientImpl.cpp
+++ b/Source/WebKit/android/jni/DeviceOrientationClientImpl.cpp
@@ -67,6 +67,8 @@ jobject DeviceOrientationClientImpl::getJavaInstance()
ASSERT(m_webViewCore);
jobject object = m_webViewCore->getDeviceOrientationService();
+ if (!object)
+ return 0;
// Get the Java DeviceOrientationService class.
jclass javaDeviceOrientationServiceClass = env->GetObjectClass(object);
@@ -93,20 +95,24 @@ jobject DeviceOrientationClientImpl::getJavaInstance()
void DeviceOrientationClientImpl::releaseJavaInstance()
{
- ASSERT(m_javaDeviceOrientationServiceObject);
- getJNIEnv()->DeleteGlobalRef(m_javaDeviceOrientationServiceObject);
+ if (m_javaDeviceOrientationServiceObject)
+ getJNIEnv()->DeleteGlobalRef(m_javaDeviceOrientationServiceObject);
}
void DeviceOrientationClientImpl::startUpdating()
{
- getJNIEnv()->CallVoidMethod(getJavaInstance(),
- javaDeviceOrientationServiceClassMethodIDs[DeviceOrientationServiceMethodStart]);
+ jobject javaInstance = getJavaInstance();
+ if (!javaInstance)
+ return;
+ getJNIEnv()->CallVoidMethod(javaInstance, javaDeviceOrientationServiceClassMethodIDs[DeviceOrientationServiceMethodStart]);
}
void DeviceOrientationClientImpl::stopUpdating()
{
- getJNIEnv()->CallVoidMethod(getJavaInstance(),
- javaDeviceOrientationServiceClassMethodIDs[DeviceOrientationServiceMethodStop]);
+ jobject javaInstance = getJavaInstance();
+ if (!javaInstance)
+ return;
+ getJNIEnv()->CallVoidMethod(javaInstance, javaDeviceOrientationServiceClassMethodIDs[DeviceOrientationServiceMethodStop]);
}
void DeviceOrientationClientImpl::onOrientationChange(PassRefPtr<DeviceOrientation> orientation)
@@ -117,14 +123,18 @@ void DeviceOrientationClientImpl::onOrientationChange(PassRefPtr<DeviceOrientati
void DeviceOrientationClientImpl::suspend()
{
- getJNIEnv()->CallVoidMethod(getJavaInstance(),
- javaDeviceOrientationServiceClassMethodIDs[DeviceOrientationServiceMethodSuspend]);
+ jobject javaInstance = getJavaInstance();
+ if (!javaInstance)
+ return;
+ getJNIEnv()->CallVoidMethod(javaInstance, javaDeviceOrientationServiceClassMethodIDs[DeviceOrientationServiceMethodSuspend]);
}
void DeviceOrientationClientImpl::resume()
{
- getJNIEnv()->CallVoidMethod(getJavaInstance(),
- javaDeviceOrientationServiceClassMethodIDs[DeviceOrientationServiceMethodResume]);
+ jobject javaInstance = getJavaInstance();
+ if (!javaInstance)
+ return;
+ getJNIEnv()->CallVoidMethod(javaInstance, javaDeviceOrientationServiceClassMethodIDs[DeviceOrientationServiceMethodResume]);
}
} // namespace android