summaryrefslogtreecommitdiffstats
path: root/Source/WebKit/android/jni
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
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')
-rw-r--r--Source/WebKit/android/jni/DeviceMotionClientImpl.cpp30
-rw-r--r--Source/WebKit/android/jni/DeviceOrientationClientImpl.cpp30
-rw-r--r--Source/WebKit/android/jni/JavaBridge.cpp33
-rw-r--r--Source/WebKit/android/jni/WebCoreFrameBridge.cpp226
-rw-r--r--Source/WebKit/android/jni/WebViewCore.cpp320
-rw-r--r--Source/WebKit/android/jni/WebViewCore.h12
6 files changed, 463 insertions, 188 deletions
diff --git a/Source/WebKit/android/jni/DeviceMotionClientImpl.cpp b/Source/WebKit/android/jni/DeviceMotionClientImpl.cpp
index 82f3c35..8376de8 100644
--- a/Source/WebKit/android/jni/DeviceMotionClientImpl.cpp
+++ b/Source/WebKit/android/jni/DeviceMotionClientImpl.cpp
@@ -67,6 +67,8 @@ jobject DeviceMotionClientImpl::getJavaInstance()
ASSERT(m_webViewCore);
jobject object = m_webViewCore->getDeviceMotionService();
+ if (!object)
+ return 0;
// Get the Java DeviceMotionService class.
jclass javaServiceClass = env->GetObjectClass(object);
@@ -93,20 +95,24 @@ jobject DeviceMotionClientImpl::getJavaInstance()
void DeviceMotionClientImpl::releaseJavaInstance()
{
- ASSERT(m_javaServiceObject);
- getJNIEnv()->DeleteGlobalRef(m_javaServiceObject);
+ if (m_javaServiceObject)
+ getJNIEnv()->DeleteGlobalRef(m_javaServiceObject);
}
void DeviceMotionClientImpl::startUpdating()
{
- getJNIEnv()->CallVoidMethod(getJavaInstance(),
- javaServiceClassMethodIDs[ServiceMethodStart]);
+ jobject javaInstance = getJavaInstance();
+ if (!javaInstance)
+ return;
+ getJNIEnv()->CallVoidMethod(javaInstance, javaServiceClassMethodIDs[ServiceMethodStart]);
}
void DeviceMotionClientImpl::stopUpdating()
{
- getJNIEnv()->CallVoidMethod(getJavaInstance(),
- javaServiceClassMethodIDs[ServiceMethodStop]);
+ jobject javaInstance = getJavaInstance();
+ if (!javaInstance)
+ return;
+ getJNIEnv()->CallVoidMethod(javaInstance, javaServiceClassMethodIDs[ServiceMethodStop]);
}
void DeviceMotionClientImpl::onMotionChange(PassRefPtr<DeviceMotionData> motion)
@@ -117,14 +123,18 @@ void DeviceMotionClientImpl::onMotionChange(PassRefPtr<DeviceMotionData> motion)
void DeviceMotionClientImpl::suspend()
{
- getJNIEnv()->CallVoidMethod(getJavaInstance(),
- javaServiceClassMethodIDs[ServiceMethodSuspend]);
+ jobject javaInstance = getJavaInstance();
+ if (!javaInstance)
+ return;
+ getJNIEnv()->CallVoidMethod(javaInstance, javaServiceClassMethodIDs[ServiceMethodSuspend]);
}
void DeviceMotionClientImpl::resume()
{
- getJNIEnv()->CallVoidMethod(getJavaInstance(),
- javaServiceClassMethodIDs[ServiceMethodResume]);
+ jobject javaInstance = getJavaInstance();
+ if (!javaInstance)
+ return;
+ getJNIEnv()->CallVoidMethod(javaInstance, javaServiceClassMethodIDs[ServiceMethodResume]);
}
} // namespace android
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
diff --git a/Source/WebKit/android/jni/JavaBridge.cpp b/Source/WebKit/android/jni/JavaBridge.cpp
index 8c17c85..68eb367 100644
--- a/Source/WebKit/android/jni/JavaBridge.cpp
+++ b/Source/WebKit/android/jni/JavaBridge.cpp
@@ -185,6 +185,8 @@ JavaBridge::setSharedTimer(long long timemillis)
{
JNIEnv* env = JSC::Bindings::getJNIEnv();
AutoJObject obj = javaObject(env);
+ if (!obj.get())
+ return;
env->CallVoidMethod(obj.get(), mSetSharedTimer, timemillis);
}
@@ -193,6 +195,8 @@ JavaBridge::stopSharedTimer()
{
JNIEnv* env = JSC::Bindings::getJNIEnv();
AutoJObject obj = javaObject(env);
+ if (!obj.get())
+ return;
env->CallVoidMethod(obj.get(), mStopSharedTimer);
}
@@ -200,11 +204,14 @@ void
JavaBridge::setCookies(WebCore::KURL const& url, WTF::String const& value)
{
JNIEnv* env = JSC::Bindings::getJNIEnv();
+ AutoJObject obj = javaObject(env);
+ if (!obj.get())
+ return;
+
const WTF::String& urlStr = url.string();
jstring jUrlStr = wtfStringToJstring(env, urlStr);
jstring jValueStr = wtfStringToJstring(env, value);
- AutoJObject obj = javaObject(env);
env->CallVoidMethod(obj.get(), mSetCookies, jUrlStr, jValueStr);
env->DeleteLocalRef(jUrlStr);
env->DeleteLocalRef(jValueStr);
@@ -214,10 +221,12 @@ WTF::String
JavaBridge::cookies(WebCore::KURL const& url)
{
JNIEnv* env = JSC::Bindings::getJNIEnv();
+ AutoJObject obj = javaObject(env);
+ if (!obj.get())
+ return String();
+
const WTF::String& urlStr = url.string();
jstring jUrlStr = wtfStringToJstring(env, urlStr);
-
- AutoJObject obj = javaObject(env);
jstring string = (jstring)(env->CallObjectMethod(obj.get(), mCookies, jUrlStr));
WTF::String ret = jstringToWtfString(env, string);
@@ -231,6 +240,8 @@ JavaBridge::cookiesEnabled()
{
JNIEnv* env = JSC::Bindings::getJNIEnv();
AutoJObject obj = javaObject(env);
+ if (!obj.get())
+ return false;
jboolean ret = env->CallBooleanMethod(obj.get(), mCookiesEnabled);
return (ret != 0);
}
@@ -241,6 +252,8 @@ JavaBridge::getPluginDirectories()
WTF::Vector<WTF::String> directories;
JNIEnv* env = JSC::Bindings::getJNIEnv();
AutoJObject obj = javaObject(env);
+ if (!obj.get())
+ return directories;
jobjectArray array = (jobjectArray)
env->CallObjectMethod(obj.get(), mGetPluginDirectories);
int count = env->GetArrayLength(array);
@@ -259,6 +272,8 @@ JavaBridge::getPluginSharedDataDirectory()
{
JNIEnv* env = JSC::Bindings::getJNIEnv();
AutoJObject obj = javaObject(env);
+ if (!obj.get())
+ return String();
jstring ret = (jstring)env->CallObjectMethod(obj.get(), mGetPluginSharedDataDirectory);
WTF::String path = jstringToWtfString(env, ret);
checkException(env);
@@ -281,6 +296,8 @@ void JavaBridge::signalServiceFuncPtrQueue()
// environment is setup.
JNIEnv* env = JSC::Bindings::getJNIEnv();
AutoJObject obj = javaObject(env);
+ if (!obj.get())
+ return;
env->CallVoidMethod(obj.get(), mSignalFuncPtrQueue);
}
@@ -288,6 +305,8 @@ WTF::Vector<WTF::String>JavaBridge::getSupportedKeyStrengthList() {
WTF::Vector<WTF::String> list;
JNIEnv* env = JSC::Bindings::getJNIEnv();
AutoJObject obj = javaObject(env);
+ if (!obj.get())
+ return list;
jobjectArray array = (jobjectArray) env->CallObjectMethod(obj.get(),
mGetKeyStrengthList);
int count = env->GetArrayLength(array);
@@ -304,10 +323,12 @@ WTF::Vector<WTF::String>JavaBridge::getSupportedKeyStrengthList() {
WTF::String JavaBridge::getSignedPublicKeyAndChallengeString(unsigned index,
const WTF::String& challenge, const WebCore::KURL& url) {
JNIEnv* env = JSC::Bindings::getJNIEnv();
+ AutoJObject obj = javaObject(env);
+ if (!obj.get())
+ return String();
jstring jChallenge = wtfStringToJstring(env, challenge);
const WTF::String& urlStr = url.string();
jstring jUrl = wtfStringToJstring(env, urlStr);
- AutoJObject obj = javaObject(env);
jstring key = (jstring) env->CallObjectMethod(obj.get(),
mGetSignedPublicKey, index, jChallenge, jUrl);
WTF::String ret = jstringToWtfString(env, key);
@@ -319,8 +340,10 @@ WTF::String JavaBridge::getSignedPublicKeyAndChallengeString(unsigned index,
WTF::String JavaBridge::resolveFilePathForContentUri(const WTF::String& uri) {
JNIEnv* env = JSC::Bindings::getJNIEnv();
- jstring jUri = wtfStringToJstring(env, uri);
AutoJObject obj = javaObject(env);
+ if (!obj.get())
+ return String();
+ jstring jUri = wtfStringToJstring(env, uri);
jstring path = static_cast<jstring>(env->CallObjectMethod(obj.get(), mResolveFilePathForContentUri, jUri));
WTF::String ret = jstringToWtfString(env, path);
env->DeleteLocalRef(jUri);
diff --git a/Source/WebKit/android/jni/WebCoreFrameBridge.cpp b/Source/WebKit/android/jni/WebCoreFrameBridge.cpp
index 6d278f0..29cd17d 100644
--- a/Source/WebKit/android/jni/WebCoreFrameBridge.cpp
+++ b/Source/WebKit/android/jni/WebCoreFrameBridge.cpp
@@ -422,10 +422,14 @@ WebFrame::startLoadingResource(WebCore::ResourceHandle* loader,
LOGV("::WebCore:: startLoadingResource(%p, %s)",
loader, request.url().string().latin1().data());
+ JNIEnv* env = getJNIEnv();
+ AutoJObject javaFrame = mJavaFrame->frame(env);
+ if (!javaFrame.get())
+ return 0;
+
WTF::String method = request.httpMethod();
WebCore::HTTPHeaderMap headers = request.httpHeaderFields();
- JNIEnv* env = getJNIEnv();
WTF::String urlStr = request.url().string();
int colon = urlStr.find(':');
bool allLower = true;
@@ -475,7 +479,7 @@ WebFrame::startLoadingResource(WebCore::ResourceHandle* loader,
bool isUserGesture = UserGestureIndicator::processingUserGesture();
jobject jLoadListener =
- env->CallObjectMethod(mJavaFrame->frame(env).get(), mJavaFrame->mStartLoadingResource,
+ env->CallObjectMethod(javaFrame.get(), mJavaFrame->mStartLoadingResource,
(int)loader, jUrlStr, jMethodStr, jHeaderMap,
jPostDataStr, formdata ? formdata->identifier(): 0,
cacheMode, mainResource, isUserGesture,
@@ -488,7 +492,7 @@ WebFrame::startLoadingResource(WebCore::ResourceHandle* loader,
env->DeleteLocalRef(jUsernameString);
env->DeleteLocalRef(jPasswordString);
if (checkException(env))
- return NULL;
+ return 0;
PassRefPtr<WebCore::ResourceLoaderAndroid> h;
if (jLoadListener)
@@ -506,8 +510,12 @@ WebFrame::shouldInterceptRequest(const WTF::String& url)
LOGV("::WebCore:: shouldInterceptRequest(%s)", url.latin1().data());
JNIEnv* env = getJNIEnv();
+ AutoJObject javaFrame = mJavaFrame->frame(env);
+ if (!javaFrame.get())
+ return 0;
+
jstring urlStr = wtfStringToJstring(env, url);
- jobject response = env->CallObjectMethod(mJavaFrame->frame(env).get(), mJavaFrame->mShouldInterceptRequest, urlStr);
+ jobject response = env->CallObjectMethod(javaFrame.get(), mJavaFrame->mShouldInterceptRequest, urlStr);
env->DeleteLocalRef(urlStr);
if (response == 0)
return 0;
@@ -523,11 +531,13 @@ WebFrame::reportError(int errorCode, const WTF::String& description,
#endif
LOGV("::WebCore:: reportError(%d, %s)", errorCode, description.ascii().data());
JNIEnv* env = getJNIEnv();
+ AutoJObject javaFrame = mJavaFrame->frame(env);
+ if (!javaFrame.get())
+ return;
jstring descStr = wtfStringToJstring(env, description);
jstring failUrl = wtfStringToJstring(env, failingUrl);
- env->CallVoidMethod(mJavaFrame->frame(env).get(), mJavaFrame->mReportError,
- errorCode, descStr, failUrl);
+ env->CallVoidMethod(javaFrame.get(), mJavaFrame->mReportError, errorCode, descStr, failUrl);
env->DeleteLocalRef(descStr);
env->DeleteLocalRef(failUrl);
}
@@ -538,6 +548,11 @@ WebFrame::loadStarted(WebCore::Frame* frame)
#ifdef ANDROID_INSTRUMENT
TimeCounterAuto counter(TimeCounter::JavaCallbackTimeCounter);
#endif
+ JNIEnv* env = getJNIEnv();
+ AutoJObject javaFrame = mJavaFrame->frame(env);
+ if (!javaFrame.get())
+ return;
+
// activeDocumentLoader() can return null.
DocumentLoader* documentLoader = frame->loader()->activeDocumentLoader();
if (documentLoader == NULL)
@@ -556,7 +571,6 @@ WebFrame::loadStarted(WebCore::Frame* frame)
!isMainFrame))
return;
- JNIEnv* env = getJNIEnv();
const WTF::String& urlString = url.string();
// If this is the main frame and we already have a favicon in the database,
// send it along with the page started notification.
@@ -569,8 +583,7 @@ WebFrame::loadStarted(WebCore::Frame* frame)
}
jstring urlStr = wtfStringToJstring(env, urlString);
- env->CallVoidMethod(mJavaFrame->frame(env).get(), mJavaFrame->mLoadStarted, urlStr, favicon,
- (int)loadType, isMainFrame);
+ env->CallVoidMethod(javaFrame.get(), mJavaFrame->mLoadStarted, urlStr, favicon, static_cast<int>(loadType), isMainFrame);
checkException(env);
env->DeleteLocalRef(urlStr);
if (favicon)
@@ -594,10 +607,13 @@ WebFrame::transitionToCommitted(WebCore::Frame* frame)
TimeCounterAuto counter(TimeCounter::JavaCallbackTimeCounter);
#endif
JNIEnv* env = getJNIEnv();
+ AutoJObject javaFrame = mJavaFrame->frame(env);
+ if (!javaFrame.get())
+ return;
+
WebCore::FrameLoadType loadType = frame->loader()->loadType();
bool isMainFrame = (!frame->tree() || !frame->tree()->parent());
- env->CallVoidMethod(mJavaFrame->frame(env).get(), mJavaFrame->mTransitionToCommitted,
- (int)loadType, isMainFrame);
+ env->CallVoidMethod(javaFrame.get(), mJavaFrame->mTransitionToCommitted, static_cast<int>(loadType), isMainFrame);
checkException(env);
}
@@ -608,6 +624,9 @@ WebFrame::didFinishLoad(WebCore::Frame* frame)
TimeCounterAuto counter(TimeCounter::JavaCallbackTimeCounter);
#endif
JNIEnv* env = getJNIEnv();
+ AutoJObject javaFrame = mJavaFrame->frame(env);
+ if (!javaFrame.get())
+ return;
// activeDocumentLoader() can return null.
WebCore::FrameLoader* loader = frame->loader();
@@ -624,8 +643,7 @@ WebFrame::didFinishLoad(WebCore::Frame* frame)
WebCore::FrameLoadType loadType = loader->loadType();
const WTF::String& urlString = url.string();
jstring urlStr = wtfStringToJstring(env, urlString);
- env->CallVoidMethod(mJavaFrame->frame(env).get(), mJavaFrame->mLoadFinished, urlStr,
- (int)loadType, isMainFrame);
+ env->CallVoidMethod(javaFrame.get(), mJavaFrame->mLoadFinished, urlStr, static_cast<int>(loadType), isMainFrame);
checkException(env);
env->DeleteLocalRef(urlStr);
}
@@ -673,9 +691,13 @@ WebFrame::setTitle(const WTF::String& title)
LOGV("setTitle(%s)", title.ascii().data());
#endif
JNIEnv* env = getJNIEnv();
+ AutoJObject javaFrame = mJavaFrame->frame(env);
+ if (!javaFrame.get())
+ return;
+
jstring jTitleStr = wtfStringToJstring(env, title);
- env->CallVoidMethod(mJavaFrame->frame(env).get(), mJavaFrame->mSetTitle, jTitleStr);
+ env->CallVoidMethod(javaFrame.get(), mJavaFrame->mSetTitle, jTitleStr);
checkException(env);
env->DeleteLocalRef(jTitleStr);
}
@@ -688,8 +710,11 @@ WebFrame::windowObjectCleared(WebCore::Frame* frame)
#endif
LOGV("::WebCore:: windowObjectCleared");
JNIEnv* env = getJNIEnv();
+ AutoJObject javaFrame = mJavaFrame->frame(env);
+ if (!javaFrame.get())
+ return;
- env->CallVoidMethod(mJavaFrame->frame(env).get(), mJavaFrame->mWindowObjectCleared, (int)frame);
+ env->CallVoidMethod(javaFrame.get(), mJavaFrame->mWindowObjectCleared, (int)frame);
checkException(env);
}
@@ -700,8 +725,12 @@ WebFrame::setProgress(float newProgress)
TimeCounterAuto counter(TimeCounter::JavaCallbackTimeCounter);
#endif
JNIEnv* env = getJNIEnv();
- int progress = (int) (100 * newProgress);
- env->CallVoidMethod(mJavaFrame->frame(env).get(), mJavaFrame->mSetProgress, progress);
+ AutoJObject javaFrame = mJavaFrame->frame(env);
+ if (!javaFrame.get())
+ return;
+
+ int progress = static_cast<int>(100 * newProgress);
+ env->CallVoidMethod(javaFrame.get(), mJavaFrame->mSetProgress, progress);
checkException(env);
}
@@ -719,11 +748,15 @@ WebFrame::didReceiveIcon(WebCore::Image* icon)
#endif
LOG_ASSERT(icon, "DidReceiveIcon called without an image!");
JNIEnv* env = getJNIEnv();
+ AutoJObject javaFrame = mJavaFrame->frame(env);
+ if (!javaFrame.get())
+ return;
+
jobject bitmap = webcoreImageToJavaBitmap(env, icon);
if (!bitmap)
return;
- env->CallVoidMethod(mJavaFrame->frame(env).get(), mJavaFrame->mDidReceiveIcon, bitmap);
+ env->CallVoidMethod(javaFrame.get(), mJavaFrame->mDidReceiveIcon, bitmap);
env->DeleteLocalRef(bitmap);
checkException(env);
}
@@ -735,10 +768,13 @@ WebFrame::didReceiveTouchIconURL(const WTF::String& url, bool precomposed)
TimeCounterAuto counter(TimeCounter::JavaCallbackTimeCounter);
#endif
JNIEnv* env = getJNIEnv();
+ AutoJObject javaFrame = mJavaFrame->frame(env);
+ if (!javaFrame.get())
+ return;
+
jstring jUrlStr = wtfStringToJstring(env, url);
- env->CallVoidMethod(mJavaFrame->frame(env).get(),
- mJavaFrame->mDidReceiveTouchIconUrl, jUrlStr, precomposed);
+ env->CallVoidMethod(javaFrame.get(), mJavaFrame->mDidReceiveTouchIconUrl, jUrlStr, precomposed);
env->DeleteLocalRef(jUrlStr);
checkException(env);
}
@@ -749,11 +785,15 @@ WebFrame::updateVisitedHistory(const WebCore::KURL& url, bool reload)
#ifdef ANDROID_INSTRUMENT
TimeCounterAuto counter(TimeCounter::JavaCallbackTimeCounter);
#endif
- const WTF::String& urlStr = url.string();
JNIEnv* env = getJNIEnv();
+ AutoJObject javaFrame = mJavaFrame->frame(env);
+ if (!javaFrame.get())
+ return;
+
+ const WTF::String& urlStr = url.string();
jstring jUrlStr = wtfStringToJstring(env, urlStr);
- env->CallVoidMethod(mJavaFrame->frame(env).get(), mJavaFrame->mUpdateVisitedHistory, jUrlStr, reload);
+ env->CallVoidMethod(javaFrame.get(), mJavaFrame->mUpdateVisitedHistory, jUrlStr, reload);
env->DeleteLocalRef(jUrlStr);
checkException(env);
}
@@ -764,6 +804,11 @@ WebFrame::canHandleRequest(const WebCore::ResourceRequest& request)
#ifdef ANDROID_INSTRUMENT
TimeCounterAuto counter(TimeCounter::JavaCallbackTimeCounter);
#endif
+ JNIEnv* env = getJNIEnv();
+ AutoJObject javaFrame = mJavaFrame->frame(env);
+ if (!javaFrame.get())
+ return true;
+
// always handle "POST" in place
if (equalIgnoringCase(request.httpMethod(), "POST"))
return true;
@@ -778,12 +823,11 @@ WebFrame::canHandleRequest(const WebCore::ResourceRequest& request)
// Empty urls should not be sent to java
if (url.isEmpty())
return true;
- JNIEnv* env = getJNIEnv();
jstring jUrlStr = wtfStringToJstring(env, url);
// check to see whether browser app wants to hijack url loading.
// if browser app handles the url, we will return false to bail out WebCore loading
- jboolean ret = env->CallBooleanMethod(mJavaFrame->frame(env).get(), mJavaFrame->mHandleUrl, jUrlStr);
+ jboolean ret = env->CallBooleanMethod(javaFrame.get(), mJavaFrame->mHandleUrl, jUrlStr);
checkException(env);
env->DeleteLocalRef(jUrlStr);
return (ret == 0);
@@ -793,8 +837,10 @@ bool
WebFrame::shouldSaveFormData()
{
JNIEnv* env = getJNIEnv();
- jboolean ret = env->CallBooleanMethod(mJavaFrame->frame(env).get(),
- mJavaFrame->mShouldSaveFormData);
+ AutoJObject javaFrame = mJavaFrame->frame(env);
+ if (!javaFrame.get())
+ return false;
+ jboolean ret = env->CallBooleanMethod(javaFrame.get(), mJavaFrame->mShouldSaveFormData);
checkException(env);
return ret;
}
@@ -806,13 +852,13 @@ WebFrame::createWindow(bool dialog, bool userGesture)
TimeCounterAuto counter(TimeCounter::JavaCallbackTimeCounter);
#endif
JNIEnv* env = getJNIEnv();
- jobject obj = env->CallObjectMethod(mJavaFrame->frame(env).get(),
- mJavaFrame->mCreateWindow, dialog, userGesture);
- if (obj) {
- WebCore::Frame* frame = GET_NATIVE_FRAME(env, obj);
- return frame;
- }
- return NULL;
+ AutoJObject javaFrame = mJavaFrame->frame(env);
+ if (!javaFrame.get())
+ return 0;
+ jobject obj = env->CallObjectMethod(javaFrame.get(), mJavaFrame->mCreateWindow, dialog, userGesture);
+ if (!obj)
+ return 0;
+ return GET_NATIVE_FRAME(env, obj);
}
void
@@ -822,7 +868,10 @@ WebFrame::requestFocus() const
TimeCounterAuto counter(TimeCounter::JavaCallbackTimeCounter);
#endif
JNIEnv* env = getJNIEnv();
- env->CallVoidMethod(mJavaFrame->frame(env).get(), mJavaFrame->mRequestFocus);
+ AutoJObject javaFrame = mJavaFrame->frame(env);
+ if (!javaFrame.get())
+ return;
+ env->CallVoidMethod(javaFrame.get(), mJavaFrame->mRequestFocus);
checkException(env);
}
@@ -834,8 +883,13 @@ WebFrame::closeWindow(WebViewCore* webViewCore)
#endif
assert(webViewCore);
JNIEnv* env = getJNIEnv();
- env->CallVoidMethod(mJavaFrame->frame(env).get(), mJavaFrame->mCloseWindow,
- webViewCore->getJavaObject().get());
+ AutoJObject javaFrame = mJavaFrame->frame(env);
+ if (!javaFrame.get())
+ return;
+ AutoJObject javaObject = webViewCore->getJavaObject();
+ if (!javaObject.get())
+ return;
+ env->CallVoidMethod(javaFrame.get(), mJavaFrame->mCloseWindow, javaObject.get());
}
struct PolicyFunctionWrapper {
@@ -849,17 +903,22 @@ WebFrame::decidePolicyForFormResubmission(WebCore::FramePolicyFunction func)
TimeCounterAuto counter(TimeCounter::JavaCallbackTimeCounter);
#endif
JNIEnv* env = getJNIEnv();
+ AutoJObject javaFrame = mJavaFrame->frame(env);
+ if (!javaFrame.get())
+ return;
PolicyFunctionWrapper* p = new PolicyFunctionWrapper;
p->func = func;
- env->CallVoidMethod(mJavaFrame->frame(env).get(), mJavaFrame->mDecidePolicyForFormResubmission, p);
+ env->CallVoidMethod(javaFrame.get(), mJavaFrame->mDecidePolicyForFormResubmission, p);
}
WTF::String
WebFrame::getRawResourceFilename(WebCore::PlatformBridge::rawResId id) const
{
JNIEnv* env = getJNIEnv();
- jstring ret = (jstring) env->CallObjectMethod(mJavaFrame->frame(env).get(),
- mJavaFrame->mGetRawResFilename, (int)id);
+ AutoJObject javaFrame = mJavaFrame->frame(env);
+ if (!javaFrame.get())
+ return String();
+ jstring ret = (jstring) env->CallObjectMethod(javaFrame.get(), mJavaFrame->mGetRawResFilename, static_cast<int>(id));
return jstringToWtfString(env, ret);
}
@@ -868,7 +927,10 @@ float
WebFrame::density() const
{
JNIEnv* env = getJNIEnv();
- jfloat dpi = env->CallFloatMethod(mJavaFrame->frame(env).get(), mJavaFrame->mDensity);
+ AutoJObject javaFrame = mJavaFrame->frame(env);
+ if (!javaFrame.get())
+ return 0.0;
+ jfloat dpi = env->CallFloatMethod(javaFrame.get(), mJavaFrame->mDensity);
checkException(env);
return dpi;
}
@@ -881,12 +943,14 @@ WebFrame::didReceiveAuthenticationChallenge(WebUrlLoaderClient* client, const st
TimeCounterAuto counter(TimeCounter::JavaCallbackTimeCounter);
#endif
JNIEnv* env = getJNIEnv();
+ AutoJObject javaFrame = mJavaFrame->frame(env);
+ if (!javaFrame.get())
+ return;
int jHandle = reinterpret_cast<int>(client);
jstring jHost = stdStringToJstring(env, host, true);
jstring jRealm = stdStringToJstring(env, realm, true);
- env->CallVoidMethod(mJavaFrame->frame(env).get(),
- mJavaFrame->mDidReceiveAuthenticationChallenge, jHandle, jHost, jRealm, useCachedCredentials);
+ env->CallVoidMethod(javaFrame.get(), mJavaFrame->mDidReceiveAuthenticationChallenge, jHandle, jHost, jRealm, useCachedCredentials);
env->DeleteLocalRef(jHost);
env->DeleteLocalRef(jRealm);
checkException(env);
@@ -900,6 +964,9 @@ WebFrame::reportSslCertError(WebUrlLoaderClient* client, int cert_error, const s
TimeCounterAuto counter(TimeCounter::JavaCallbackTimeCounter);
#endif
JNIEnv* env = getJNIEnv();
+ AutoJObject javaFrame = mJavaFrame->frame(env);
+ if (!javaFrame.get())
+ return;
int jHandle = reinterpret_cast<int>(client);
int len = cert.length();
@@ -907,8 +974,7 @@ WebFrame::reportSslCertError(WebUrlLoaderClient* client, int cert_error, const s
jbyte* bytes = env->GetByteArrayElements(jCert, NULL);
cert.copy(reinterpret_cast<char*>(bytes), len);
- env->CallVoidMethod(mJavaFrame->frame(env).get(),
- mJavaFrame->mReportSslCertError, jHandle, cert_error, jCert);
+ env->CallVoidMethod(javaFrame.get(), mJavaFrame->mReportSslCertError, jHandle, cert_error, jCert);
env->DeleteLocalRef(jCert);
checkException(env);
}
@@ -921,13 +987,15 @@ WebFrame::downloadStart(const std::string& url, const std::string& userAgent, co
TimeCounterAuto counter(TimeCounter::JavaCallbackTimeCounter);
#endif
JNIEnv* env = getJNIEnv();
+ AutoJObject javaFrame = mJavaFrame->frame(env);
+ if (!javaFrame.get())
+ return;
jstring jUrl = stdStringToJstring(env, url, true);
jstring jUserAgent = stdStringToJstring(env, userAgent, true);
jstring jContentDisposition = stdStringToJstring(env, contentDisposition, true);
jstring jMimetype = stdStringToJstring(env, mimetype, true);
- env->CallVoidMethod(mJavaFrame->frame(env).get(),
- mJavaFrame->mDownloadStart, jUrl, jUserAgent, jContentDisposition, jMimetype, contentLength);
+ env->CallVoidMethod(javaFrame.get(), mJavaFrame->mDownloadStart, jUrl, jUserAgent, jContentDisposition, jMimetype, contentLength);
env->DeleteLocalRef(jUrl);
env->DeleteLocalRef(jUserAgent);
@@ -942,13 +1010,15 @@ WebFrame::didReceiveData(const char* data, int size) {
TimeCounterAuto counter(TimeCounter::JavaCallbackTimeCounter);
#endif
JNIEnv* env = getJNIEnv();
+ AutoJObject javaFrame = mJavaFrame->frame(env);
+ if (!javaFrame.get())
+ return;
jbyteArray jData = env->NewByteArray(size);
jbyte* bytes = env->GetByteArrayElements(jData, NULL);
memcpy(reinterpret_cast<char*>(bytes), data, size);
- env->CallVoidMethod(mJavaFrame->frame(env).get(),
- mJavaFrame->mDidReceiveData, jData, size);
+ env->CallVoidMethod(javaFrame.get(), mJavaFrame->mDidReceiveData, jData, size);
env->DeleteLocalRef(jData);
checkException(env);
}
@@ -959,8 +1029,11 @@ WebFrame::didFinishLoading() {
TimeCounterAuto counter(TimeCounter::JavaCallbackTimeCounter);
#endif
JNIEnv* env = getJNIEnv();
+ AutoJObject javaFrame = mJavaFrame->frame(env);
+ if (!javaFrame.get())
+ return;
- env->CallVoidMethod(mJavaFrame->frame(env).get(), mJavaFrame->mDidFinishLoading);
+ env->CallVoidMethod(javaFrame.get(), mJavaFrame->mDidFinishLoading);
checkException(env);
}
@@ -973,13 +1046,16 @@ void WebFrame::setCertificate(const std::string& cert)
TimeCounterAuto counter(TimeCounter::JavaCallbackTimeCounter);
#endif
JNIEnv* env = getJNIEnv();
+ AutoJObject javaFrame = mJavaFrame->frame(env);
+ if (!javaFrame.get())
+ return;
int len = cert.length();
jbyteArray jCert = env->NewByteArray(len);
jbyte* bytes = env->GetByteArrayElements(jCert, NULL);
cert.copy(reinterpret_cast<char*>(bytes), len);
- env->CallVoidMethod(mJavaFrame->frame(env).get(), mJavaFrame->mSetCertificate, jCert);
+ env->CallVoidMethod(javaFrame.get(), mJavaFrame->mSetCertificate, jCert);
env->DeleteLocalRef(jCert);
checkException(env);
@@ -991,6 +1067,11 @@ void WebFrame::autoLogin(const std::string& loginHeader)
#ifdef ANDROID_INSTRUMENT
TimeCounterAuto counter(TimerCoutner::JavaCallbackTimeCounter);
#endif
+ JNIEnv* env = getJNIEnv();
+ AutoJObject javaFrame = mJavaFrame->frame(env);
+ if (!javaFrame.get())
+ return;
+
WTF::String header(loginHeader.c_str(), loginHeader.length());
WTF::Vector<WTF::String> split;
header.split('&', split);
@@ -1022,17 +1103,20 @@ void WebFrame::autoLogin(const std::string& loginHeader)
if (realm.isEmpty() || args.isEmpty())
return;
- JNIEnv* env = getJNIEnv();
jstring jRealm = wtfStringToJstring(env, realm, true);
jstring jAccount = wtfStringToJstring(env, account);
jstring jArgs = wtfStringToJstring(env, args, true);
- env->CallVoidMethod(mJavaFrame->frame(env).get(),
- mJavaFrame->mAutoLogin, jRealm, jAccount, jArgs);
+ env->CallVoidMethod(javaFrame.get(), mJavaFrame->mAutoLogin, jRealm, jAccount, jArgs);
}
}
void WebFrame::maybeSavePassword(WebCore::Frame* frame, const WebCore::ResourceRequest& request)
{
+ JNIEnv* env = getJNIEnv();
+ AutoJObject javaFrame = mJavaFrame->frame(env);
+ if (!javaFrame.get())
+ return;
+
if (request.httpMethod() != "POST")
return;
@@ -1041,14 +1125,11 @@ void WebFrame::maybeSavePassword(WebCore::Frame* frame, const WebCore::ResourceR
if (!getUsernamePasswordFromDom(frame, username, password))
return;
- JNIEnv* env = getJNIEnv();
jstring jUsername = wtfStringToJstring(env, username);
jstring jPassword = wtfStringToJstring(env, password);
jbyteArray jPostData = getPostData(request);
- if (jPostData) {
- env->CallVoidMethod(mJavaFrame->frame(env).get(),
- mJavaFrame->mMaybeSavePassword, jPostData, jUsername, jPassword);
- }
+ if (jPostData)
+ env->CallVoidMethod(javaFrame.get(), mJavaFrame->mMaybeSavePassword, jPostData, jUsername, jPassword);
env->DeleteLocalRef(jPostData);
env->DeleteLocalRef(jUsername);
@@ -1087,12 +1168,14 @@ bool WebFrame::getUsernamePasswordFromDom(WebCore::Frame* frame, WTF::String& us
jbyteArray WebFrame::getPostData(const WebCore::ResourceRequest& request)
{
- jbyteArray jPostDataStr = NULL;
+ JNIEnv* env = getJNIEnv();
+ AutoJObject javaFrame = mJavaFrame->frame(env);
+ if (!javaFrame.get())
+ return 0;
+
+ jbyteArray jPostDataStr = 0;
WebCore::FormData* formdata = request.httpBody();
if (formdata) {
- JNIEnv* env = getJNIEnv();
- AutoJObject obj = mJavaFrame->frame(env);
-
// We can use the formdata->flatten() but it will result in two
// memcpys, first through loading up the vector with the form data
// then another to copy it out of the vector and into the java byte
@@ -1112,8 +1195,7 @@ jbyteArray WebFrame::getPostData(const WebCore::ResourceRequest& request)
size += e.m_data.size();
} else if (e.m_type == WebCore::FormDataElement::encodedFile) {
fileinfos[i] = new FileInfo(env, e.m_filename);
- int delta = env->CallIntMethod(obj.get(),
- mJavaFrame->mGetFileSize, fileinfos[i]->getUri());
+ int delta = env->CallIntMethod(javaFrame.get(), mJavaFrame->mGetFileSize, fileinfos[i]->getUri());
checkException(env);
fileinfos[i]->setSize(delta);
size += delta;
@@ -1135,11 +1217,10 @@ jbyteArray WebFrame::getPostData(const WebCore::ResourceRequest& request)
int delta = e.m_data.size();
memcpy(bytes + offset, e.m_data.data(), delta);
offset += delta;
- } else if (e.m_type
- == WebCore::FormDataElement::encodedFile) {
- int delta = env->CallIntMethod(obj.get(),
- mJavaFrame->mGetFile, fileinfos[i]->getUri(),
- jPostDataStr, offset, fileinfos[i]->getSize());
+ } else if (e.m_type == WebCore::FormDataElement::encodedFile) {
+ int delta = env->CallIntMethod(javaFrame.get(),
+ mJavaFrame->mGetFile, fileinfos[i]->getUri(),
+ jPostDataStr, offset, fileinfos[i]->getSize());
checkException(env);
offset += delta;
}
@@ -1942,6 +2023,11 @@ static void SetUsernamePassword(JNIEnv *env, jobject obj,
void
WebFrame::saveFormData(HTMLFormElement* form)
{
+ JNIEnv* env = getJNIEnv();
+ AutoJObject javaFrame = mJavaFrame->frame(env);
+ if (!javaFrame.get())
+ return;
+
if (form->autoComplete()) {
JNIEnv* env = getJNIEnv();
jclass mapClass = env->FindClass("java/util/HashMap");
@@ -1975,7 +2061,7 @@ WebFrame::saveFormData(HTMLFormElement* form)
}
}
}
- env->CallVoidMethod(mJavaFrame->frame(env).get(), mJavaFrame->mSaveFormData, hashMap);
+ env->CallVoidMethod(javaFrame.get(), mJavaFrame->mSaveFormData, hashMap);
env->DeleteLocalRef(hashMap);
env->DeleteLocalRef(mapClass);
}
diff --git a/Source/WebKit/android/jni/WebViewCore.cpp b/Source/WebKit/android/jni/WebViewCore.cpp
index 494ebea..ded3965 100644
--- a/Source/WebKit/android/jni/WebViewCore.cpp
+++ b/Source/WebKit/android/jni/WebViewCore.cpp
@@ -303,6 +303,13 @@ struct WebViewCore::JavaGlue {
jmethodID m_setWebTextViewAutoFillable;
jmethodID m_selectAt;
AutoJObject object(JNIEnv* env) {
+ // We hold a weak reference to the Java WebViewCore to avoid memeory
+ // leaks due to circular references when WebView.destroy() is not
+ // called manually. The WebView and hence the WebViewCore could become
+ // weakly reachable at any time, after which the GC could null our weak
+ // reference, so we have to check the return value of this method at
+ // every use. Note that our weak reference will be nulled before the
+ // WebViewCore is finalized.
return getRealObject(env, m_obj);
}
};
@@ -724,12 +731,13 @@ void WebViewCore::recordPictureSet(PictureSet* content)
DBG_NAV_LOG("call updateFrameCache");
updateFrameCache();
if (m_findIsUp) {
- LOG_ASSERT(m_javaGlue->m_obj,
- "A Java widget was not associated with this view bridge!");
+ LOG_ASSERT(m_javaGlue->m_obj, "A Java widget was not associated with this view bridge!");
JNIEnv* env = JSC::Bindings::getJNIEnv();
- env->CallVoidMethod(m_javaGlue->object(env).get(),
- m_javaGlue->m_sendFindAgain);
- checkException(env);
+ AutoJObject javaObject = m_javaGlue->object(env);
+ if (javaObject.get()) {
+ env->CallVoidMethod(javaObject.get(), m_javaGlue->m_sendFindAgain);
+ checkException(env);
+ }
}
}
@@ -947,7 +955,10 @@ void WebViewCore::scrollTo(int x, int y, bool animate)
// LOGD("WebViewCore::scrollTo(%d %d)\n", x, y);
JNIEnv* env = JSC::Bindings::getJNIEnv();
- env->CallVoidMethod(m_javaGlue->object(env).get(), m_javaGlue->m_scrollTo,
+ AutoJObject javaObject = m_javaGlue->object(env);
+ if (!javaObject.get())
+ return;
+ env->CallVoidMethod(javaObject.get(), m_javaGlue->m_scrollTo,
x, y, animate, false);
checkException(env);
}
@@ -956,7 +967,10 @@ void WebViewCore::sendNotifyProgressFinished()
{
LOG_ASSERT(m_javaGlue->m_obj, "A Java widget was not associated with this view bridge!");
JNIEnv* env = JSC::Bindings::getJNIEnv();
- env->CallVoidMethod(m_javaGlue->object(env).get(), m_javaGlue->m_sendNotifyProgressFinished);
+ AutoJObject javaObject = m_javaGlue->object(env);
+ if (!javaObject.get())
+ return;
+ env->CallVoidMethod(javaObject.get(), m_javaGlue->m_sendNotifyProgressFinished);
checkException(env);
}
@@ -964,7 +978,10 @@ void WebViewCore::viewInvalidate(const WebCore::IntRect& rect)
{
LOG_ASSERT(m_javaGlue->m_obj, "A Java widget was not associated with this view bridge!");
JNIEnv* env = JSC::Bindings::getJNIEnv();
- env->CallVoidMethod(m_javaGlue->object(env).get(),
+ AutoJObject javaObject = m_javaGlue->object(env);
+ if (!javaObject.get())
+ return;
+ env->CallVoidMethod(javaObject.get(),
m_javaGlue->m_sendViewInvalidate,
rect.x(), rect.y(), rect.maxX(), rect.maxY());
checkException(env);
@@ -973,14 +990,20 @@ void WebViewCore::viewInvalidate(const WebCore::IntRect& rect)
void WebViewCore::contentDraw()
{
JNIEnv* env = JSC::Bindings::getJNIEnv();
- env->CallVoidMethod(m_javaGlue->object(env).get(), m_javaGlue->m_contentDraw);
+ AutoJObject javaObject = m_javaGlue->object(env);
+ if (!javaObject.get())
+ return;
+ env->CallVoidMethod(javaObject.get(), m_javaGlue->m_contentDraw);
checkException(env);
}
void WebViewCore::layersDraw()
{
JNIEnv* env = JSC::Bindings::getJNIEnv();
- env->CallVoidMethod(m_javaGlue->object(env).get(), m_javaGlue->m_layersDraw);
+ AutoJObject javaObject = m_javaGlue->object(env);
+ if (!javaObject.get())
+ return;
+ env->CallVoidMethod(javaObject.get(), m_javaGlue->m_layersDraw);
checkException(env);
}
@@ -1027,6 +1050,11 @@ void WebViewCore::didFirstLayout()
DEBUG_NAV_UI_LOGD("%s", __FUNCTION__);
LOG_ASSERT(m_javaGlue->m_obj, "A Java widget was not associated with this view bridge!");
+ JNIEnv* env = JSC::Bindings::getJNIEnv();
+ AutoJObject javaObject = m_javaGlue->object(env);
+ if (!javaObject.get())
+ return;
+
const WebCore::KURL& url = m_mainFrame->document()->url();
if (url.isEmpty())
return;
@@ -1034,8 +1062,7 @@ void WebViewCore::didFirstLayout()
WebCore::FrameLoadType loadType = m_mainFrame->loader()->loadType();
- JNIEnv* env = JSC::Bindings::getJNIEnv();
- env->CallVoidMethod(m_javaGlue->object(env).get(), m_javaGlue->m_didFirstLayout,
+ env->CallVoidMethod(javaObject.get(), m_javaGlue->m_didFirstLayout,
loadType == WebCore::FrameLoadTypeStandard
// When redirect with locked history, we would like to reset the
// scale factor. This is important for www.yahoo.com as it is
@@ -1055,7 +1082,10 @@ void WebViewCore::updateViewport()
LOG_ASSERT(m_javaGlue->m_obj, "A Java widget was not associated with this view bridge!");
JNIEnv* env = JSC::Bindings::getJNIEnv();
- env->CallVoidMethod(m_javaGlue->object(env).get(), m_javaGlue->m_updateViewport);
+ AutoJObject javaObject = m_javaGlue->object(env);
+ if (!javaObject.get())
+ return;
+ env->CallVoidMethod(javaObject.get(), m_javaGlue->m_updateViewport);
checkException(env);
}
@@ -1065,7 +1095,10 @@ void WebViewCore::restoreScale(float scale, float textWrapScale)
LOG_ASSERT(m_javaGlue->m_obj, "A Java widget was not associated with this view bridge!");
JNIEnv* env = JSC::Bindings::getJNIEnv();
- env->CallVoidMethod(m_javaGlue->object(env).get(), m_javaGlue->m_restoreScale, scale, textWrapScale);
+ AutoJObject javaObject = m_javaGlue->object(env);
+ if (!javaObject.get())
+ return;
+ env->CallVoidMethod(javaObject.get(), m_javaGlue->m_restoreScale, scale, textWrapScale);
checkException(env);
}
@@ -1075,11 +1108,15 @@ void WebViewCore::needTouchEvents(bool need)
LOG_ASSERT(m_javaGlue->m_obj, "A Java widget was not associated with this view bridge!");
#if ENABLE(TOUCH_EVENTS)
+ JNIEnv* env = JSC::Bindings::getJNIEnv();
+ AutoJObject javaObject = m_javaGlue->object(env);
+ if (!javaObject.get())
+ return;
+
if (m_forwardingTouchEvents == need)
return;
- JNIEnv* env = JSC::Bindings::getJNIEnv();
- env->CallVoidMethod(m_javaGlue->object(env).get(), m_javaGlue->m_needTouchEvents, need);
+ env->CallVoidMethod(javaObject.get(), m_javaGlue->m_needTouchEvents, need);
checkException(env);
m_forwardingTouchEvents = need;
@@ -1093,7 +1130,10 @@ void WebViewCore::requestKeyboardWithSelection(const WebCore::Node* node,
LOG_ASSERT(m_javaGlue->m_obj, "A Java widget was not associated with this view bridge!");
JNIEnv* env = JSC::Bindings::getJNIEnv();
- env->CallVoidMethod(m_javaGlue->object(env).get(),
+ AutoJObject javaObject = m_javaGlue->object(env);
+ if (!javaObject.get())
+ return;
+ env->CallVoidMethod(javaObject.get(),
m_javaGlue->m_requestKeyboardWithSelection,
reinterpret_cast<int>(node), selStart, selEnd, m_textGeneration);
checkException(env);
@@ -1105,8 +1145,10 @@ void WebViewCore::requestKeyboard(bool showKeyboard)
LOG_ASSERT(m_javaGlue->m_obj, "A Java widget was not associated with this view bridge!");
JNIEnv* env = JSC::Bindings::getJNIEnv();
- env->CallVoidMethod(m_javaGlue->object(env).get(),
- m_javaGlue->m_requestKeyboard, showKeyboard);
+ AutoJObject javaObject = m_javaGlue->object(env);
+ if (!javaObject.get())
+ return;
+ env->CallVoidMethod(javaObject.get(), m_javaGlue->m_requestKeyboard, showKeyboard);
checkException(env);
}
@@ -2738,8 +2780,10 @@ String WebViewCore::formatMarkup(DOMSelection* selection)
void WebViewCore::selectAt(int x, int y)
{
JNIEnv* env = JSC::Bindings::getJNIEnv();
- env->CallVoidMethod(m_javaGlue->object(env).get(), m_javaGlue->m_selectAt,
- x, y);
+ AutoJObject javaObject = m_javaGlue->object(env);
+ if (!javaObject.get())
+ return;
+ env->CallVoidMethod(javaObject.get(), m_javaGlue->m_selectAt, x, y);
checkException(env);
}
@@ -2888,19 +2932,24 @@ static jobjectArray makeLabelArray(JNIEnv* env, const uint16_t** labels, size_t
return array;
}
-void WebViewCore::openFileChooser(PassRefPtr<WebCore::FileChooser> chooser) {
+void WebViewCore::openFileChooser(PassRefPtr<WebCore::FileChooser> chooser)
+{
+ JNIEnv* env = JSC::Bindings::getJNIEnv();
+ AutoJObject javaObject = m_javaGlue->object(env);
+ if (!javaObject.get())
+ return;
+
if (!chooser)
return;
- JNIEnv* env = JSC::Bindings::getJNIEnv();
WTF::String acceptType = chooser->acceptTypes();
jstring jAcceptType = wtfStringToJstring(env, acceptType, true);
jstring jName = (jstring) env->CallObjectMethod(
- m_javaGlue->object(env).get(), m_javaGlue->m_openFileChooser, jAcceptType);
+ javaObject.get(), m_javaGlue->m_openFileChooser, jAcceptType);
checkException(env);
env->DeleteLocalRef(jAcceptType);
- const UChar* string = static_cast<const UChar*>(env->GetStringChars(jName, NULL));
+ const UChar* string = static_cast<const UChar*>(env->GetStringChars(jName, 0));
if (!string)
return;
@@ -2915,14 +2964,18 @@ void WebViewCore::openFileChooser(PassRefPtr<WebCore::FileChooser> chooser) {
void WebViewCore::listBoxRequest(WebCoreReply* reply, const uint16_t** labels, size_t count, const int enabled[], size_t enabledCount,
bool multiple, const int selected[], size_t selectedCountOrSelection)
{
+ LOG_ASSERT(m_javaGlue->m_obj, "No java widget associated with this view!");
+
+ JNIEnv* env = JSC::Bindings::getJNIEnv();
+ AutoJObject javaObject = m_javaGlue->object(env);
+ if (!javaObject.get())
+ return;
+
// If m_popupReply is not null, then we already have a list showing.
if (m_popupReply != 0)
return;
- LOG_ASSERT(m_javaGlue->m_obj, "No java widget associated with this view!");
-
// Create an array of java Strings for the drop down.
- JNIEnv* env = JSC::Bindings::getJNIEnv();
jobjectArray labelArray = makeLabelArray(env, labels, count);
// Create an array determining whether each item is enabled.
@@ -2947,13 +3000,13 @@ void WebViewCore::listBoxRequest(WebCoreReply* reply, const uint16_t** labels, s
}
env->ReleaseIntArrayElements(selectedArray, selArray, 0);
- env->CallVoidMethod(m_javaGlue->object(env).get(),
+ env->CallVoidMethod(javaObject.get(),
m_javaGlue->m_requestListBox, labelArray, enabledArray,
selectedArray);
env->DeleteLocalRef(selectedArray);
} else {
// Pass up the single selection.
- env->CallVoidMethod(m_javaGlue->object(env).get(),
+ env->CallVoidMethod(javaObject.get(),
m_javaGlue->m_requestSingleListBox, labelArray, enabledArray,
selectedCountOrSelection);
}
@@ -3267,8 +3320,10 @@ void WebViewCore::focusNodeChanged(const WebCore::Node* newFocus)
m_shouldPaintCaret = true;
else if (m_blurringNodePointer) {
JNIEnv* env = JSC::Bindings::getJNIEnv();
- env->CallVoidMethod(m_javaGlue->object(env).get(),
- m_javaGlue->m_formDidBlur, m_blurringNodePointer);
+ AutoJObject javaObject = m_javaGlue->object(env);
+ if (!javaObject.get())
+ return;
+ env->CallVoidMethod(javaObject.get(), m_javaGlue->m_formDidBlur, m_blurringNodePointer);
checkException(env);
m_blurringNodePointer = 0;
}
@@ -3276,9 +3331,12 @@ void WebViewCore::focusNodeChanged(const WebCore::Node* newFocus)
void WebViewCore::addMessageToConsole(const WTF::String& message, unsigned int lineNumber, const WTF::String& sourceID, int msgLevel) {
JNIEnv* env = JSC::Bindings::getJNIEnv();
+ AutoJObject javaObject = m_javaGlue->object(env);
+ if (!javaObject.get())
+ return;
jstring jMessageStr = wtfStringToJstring(env, message);
jstring jSourceIDStr = wtfStringToJstring(env, sourceID);
- env->CallVoidMethod(m_javaGlue->object(env).get(),
+ env->CallVoidMethod(javaObject.get(),
m_javaGlue->m_addMessageToConsole, jMessageStr, lineNumber,
jSourceIDStr, msgLevel);
env->DeleteLocalRef(jMessageStr);
@@ -3289,52 +3347,68 @@ void WebViewCore::addMessageToConsole(const WTF::String& message, unsigned int l
void WebViewCore::jsAlert(const WTF::String& url, const WTF::String& text)
{
JNIEnv* env = JSC::Bindings::getJNIEnv();
+ AutoJObject javaObject = m_javaGlue->object(env);
+ if (!javaObject.get())
+ return;
jstring jInputStr = wtfStringToJstring(env, text);
jstring jUrlStr = wtfStringToJstring(env, url);
- env->CallVoidMethod(m_javaGlue->object(env).get(), m_javaGlue->m_jsAlert, jUrlStr, jInputStr);
+ env->CallVoidMethod(javaObject.get(), m_javaGlue->m_jsAlert, jUrlStr, jInputStr);
env->DeleteLocalRef(jInputStr);
env->DeleteLocalRef(jUrlStr);
checkException(env);
}
-void WebViewCore::exceededDatabaseQuota(const WTF::String& url, const WTF::String& databaseIdentifier, const unsigned long long currentQuota, unsigned long long estimatedSize)
+bool WebViewCore::exceededDatabaseQuota(const WTF::String& url, const WTF::String& databaseIdentifier, const unsigned long long currentQuota, unsigned long long estimatedSize)
{
#if ENABLE(DATABASE)
JNIEnv* env = JSC::Bindings::getJNIEnv();
+ AutoJObject javaObject = m_javaGlue->object(env);
+ if (!javaObject.get())
+ return false;
jstring jDatabaseIdentifierStr = wtfStringToJstring(env, databaseIdentifier);
jstring jUrlStr = wtfStringToJstring(env, url);
- env->CallVoidMethod(m_javaGlue->object(env).get(),
+ env->CallVoidMethod(javaObject.get(),
m_javaGlue->m_exceededDatabaseQuota, jUrlStr,
jDatabaseIdentifierStr, currentQuota, estimatedSize);
env->DeleteLocalRef(jDatabaseIdentifierStr);
env->DeleteLocalRef(jUrlStr);
checkException(env);
+ return true;
#endif
}
-void WebViewCore::reachedMaxAppCacheSize(const unsigned long long spaceNeeded)
+bool WebViewCore::reachedMaxAppCacheSize(const unsigned long long spaceNeeded)
{
#if ENABLE(OFFLINE_WEB_APPLICATIONS)
JNIEnv* env = JSC::Bindings::getJNIEnv();
- env->CallVoidMethod(m_javaGlue->object(env).get(),
- m_javaGlue->m_reachedMaxAppCacheSize, spaceNeeded);
+ AutoJObject javaObject = m_javaGlue->object(env);
+ if (!javaObject.get())
+ return false;
+ env->CallVoidMethod(javaObject.get(), m_javaGlue->m_reachedMaxAppCacheSize, spaceNeeded);
checkException(env);
+ return true;
#endif
}
void WebViewCore::populateVisitedLinks(WebCore::PageGroup* group)
{
- m_groupForVisitedLinks = group;
JNIEnv* env = JSC::Bindings::getJNIEnv();
- env->CallVoidMethod(m_javaGlue->object(env).get(), m_javaGlue->m_populateVisitedLinks);
+ AutoJObject javaObject = m_javaGlue->object(env);
+ if (!javaObject.get())
+ return;
+ m_groupForVisitedLinks = group;
+ env->CallVoidMethod(javaObject.get(), m_javaGlue->m_populateVisitedLinks);
checkException(env);
}
void WebViewCore::geolocationPermissionsShowPrompt(const WTF::String& origin)
{
JNIEnv* env = JSC::Bindings::getJNIEnv();
+ AutoJObject javaObject = m_javaGlue->object(env);
+ if (!javaObject.get())
+ return;
jstring originString = wtfStringToJstring(env, origin);
- env->CallVoidMethod(m_javaGlue->object(env).get(),
+ env->CallVoidMethod(javaObject.get(),
m_javaGlue->m_geolocationPermissionsShowPrompt,
originString);
env->DeleteLocalRef(originString);
@@ -3344,16 +3418,20 @@ void WebViewCore::geolocationPermissionsShowPrompt(const WTF::String& origin)
void WebViewCore::geolocationPermissionsHidePrompt()
{
JNIEnv* env = JSC::Bindings::getJNIEnv();
- env->CallVoidMethod(m_javaGlue->object(env).get(),
- m_javaGlue->m_geolocationPermissionsHidePrompt);
+ AutoJObject javaObject = m_javaGlue->object(env);
+ if (!javaObject.get())
+ return;
+ env->CallVoidMethod(javaObject.get(), m_javaGlue->m_geolocationPermissionsHidePrompt);
checkException(env);
}
jobject WebViewCore::getDeviceMotionService()
{
JNIEnv* env = JSC::Bindings::getJNIEnv();
- jobject object = env->CallObjectMethod(m_javaGlue->object(env).get(),
- m_javaGlue->m_getDeviceMotionService);
+ AutoJObject javaObject = m_javaGlue->object(env);
+ if (!javaObject.get())
+ return 0;
+ jobject object = env->CallObjectMethod(javaObject.get(), m_javaGlue->m_getDeviceMotionService);
checkException(env);
return object;
}
@@ -3361,8 +3439,10 @@ jobject WebViewCore::getDeviceMotionService()
jobject WebViewCore::getDeviceOrientationService()
{
JNIEnv* env = JSC::Bindings::getJNIEnv();
- jobject object = env->CallObjectMethod(m_javaGlue->object(env).get(),
- m_javaGlue->m_getDeviceOrientationService);
+ AutoJObject javaObject = m_javaGlue->object(env);
+ if (!javaObject.get())
+ return 0;
+ jobject object = env->CallObjectMethod(javaObject.get(), m_javaGlue->m_getDeviceOrientationService);
checkException(env);
return object;
}
@@ -3370,9 +3450,12 @@ jobject WebViewCore::getDeviceOrientationService()
bool WebViewCore::jsConfirm(const WTF::String& url, const WTF::String& text)
{
JNIEnv* env = JSC::Bindings::getJNIEnv();
+ AutoJObject javaObject = m_javaGlue->object(env);
+ if (!javaObject.get())
+ return false;
jstring jInputStr = wtfStringToJstring(env, text);
jstring jUrlStr = wtfStringToJstring(env, url);
- jboolean result = env->CallBooleanMethod(m_javaGlue->object(env).get(), m_javaGlue->m_jsConfirm, jUrlStr, jInputStr);
+ jboolean result = env->CallBooleanMethod(javaObject.get(), m_javaGlue->m_jsConfirm, jUrlStr, jInputStr);
env->DeleteLocalRef(jInputStr);
env->DeleteLocalRef(jUrlStr);
checkException(env);
@@ -3382,10 +3465,13 @@ bool WebViewCore::jsConfirm(const WTF::String& url, const WTF::String& text)
bool WebViewCore::jsPrompt(const WTF::String& url, const WTF::String& text, const WTF::String& defaultValue, WTF::String& result)
{
JNIEnv* env = JSC::Bindings::getJNIEnv();
+ AutoJObject javaObject = m_javaGlue->object(env);
+ if (!javaObject.get())
+ return false;
jstring jUrlStr = wtfStringToJstring(env, url);
jstring jInputStr = wtfStringToJstring(env, text);
jstring jDefaultStr = wtfStringToJstring(env, defaultValue);
- jstring returnVal = static_cast<jstring>(env->CallObjectMethod(m_javaGlue->object(env).get(), m_javaGlue->m_jsPrompt, jUrlStr, jInputStr, jDefaultStr));
+ jstring returnVal = static_cast<jstring>(env->CallObjectMethod(javaObject.get(), m_javaGlue->m_jsPrompt, jUrlStr, jInputStr, jDefaultStr));
env->DeleteLocalRef(jUrlStr);
env->DeleteLocalRef(jInputStr);
env->DeleteLocalRef(jDefaultStr);
@@ -3403,9 +3489,12 @@ bool WebViewCore::jsPrompt(const WTF::String& url, const WTF::String& text, cons
bool WebViewCore::jsUnload(const WTF::String& url, const WTF::String& message)
{
JNIEnv* env = JSC::Bindings::getJNIEnv();
+ AutoJObject javaObject = m_javaGlue->object(env);
+ if (!javaObject.get())
+ return false;
jstring jInputStr = wtfStringToJstring(env, message);
jstring jUrlStr = wtfStringToJstring(env, url);
- jboolean result = env->CallBooleanMethod(m_javaGlue->object(env).get(), m_javaGlue->m_jsUnload, jUrlStr, jInputStr);
+ jboolean result = env->CallBooleanMethod(javaObject.get(), m_javaGlue->m_jsUnload, jUrlStr, jInputStr);
env->DeleteLocalRef(jInputStr);
env->DeleteLocalRef(jUrlStr);
checkException(env);
@@ -3415,7 +3504,10 @@ bool WebViewCore::jsUnload(const WTF::String& url, const WTF::String& message)
bool WebViewCore::jsInterrupt()
{
JNIEnv* env = JSC::Bindings::getJNIEnv();
- jboolean result = env->CallBooleanMethod(m_javaGlue->object(env).get(), m_javaGlue->m_jsInterrupt);
+ AutoJObject javaObject = m_javaGlue->object(env);
+ if (!javaObject.get())
+ return false;
+ jboolean result = env->CallBooleanMethod(javaObject.get(), m_javaGlue->m_jsInterrupt);
checkException(env);
return result;
}
@@ -3430,10 +3522,18 @@ jobject
WebViewCore::getWebViewJavaObject()
{
JNIEnv* env = JSC::Bindings::getJNIEnv();
- return env->GetObjectField(m_javaGlue->object(env).get(), gWebViewCoreFields.m_webView);
+ AutoJObject javaObject = m_javaGlue->object(env);
+ if (!javaObject.get())
+ return 0;
+ return env->GetObjectField(javaObject.get(), gWebViewCoreFields.m_webView);
}
-void WebViewCore::updateTextSelection() {
+void WebViewCore::updateTextSelection()
+{
+ JNIEnv* env = JSC::Bindings::getJNIEnv();
+ AutoJObject javaObject = m_javaGlue->object(env);
+ if (!javaObject.get())
+ return;
WebCore::Node* focusNode = currentFocus();
if (!focusNode)
return;
@@ -3441,8 +3541,7 @@ void WebViewCore::updateTextSelection() {
if (!renderer || (!renderer->isTextArea() && !renderer->isTextField()))
return;
RenderTextControl* rtc = static_cast<RenderTextControl*>(renderer);
- JNIEnv* env = JSC::Bindings::getJNIEnv();
- env->CallVoidMethod(m_javaGlue->object(env).get(),
+ env->CallVoidMethod(javaObject.get(),
m_javaGlue->m_updateTextSelection, reinterpret_cast<int>(focusNode),
rtc->selectionStart(), rtc->selectionEnd(), m_textGeneration);
checkException(env);
@@ -3451,17 +3550,20 @@ void WebViewCore::updateTextSelection() {
void WebViewCore::updateTextfield(WebCore::Node* ptr, bool changeToPassword,
const WTF::String& text)
{
+ JNIEnv* env = JSC::Bindings::getJNIEnv();
+ AutoJObject javaObject = m_javaGlue->object(env);
+ if (!javaObject.get())
+ return;
if (m_blockTextfieldUpdates)
return;
- JNIEnv* env = JSC::Bindings::getJNIEnv();
if (changeToPassword) {
- env->CallVoidMethod(m_javaGlue->object(env).get(), m_javaGlue->m_updateTextfield,
+ env->CallVoidMethod(javaObject.get(), m_javaGlue->m_updateTextfield,
(int) ptr, true, 0, m_textGeneration);
checkException(env);
return;
}
jstring string = wtfStringToJstring(env, text);
- env->CallVoidMethod(m_javaGlue->object(env).get(), m_javaGlue->m_updateTextfield,
+ env->CallVoidMethod(javaObject.get(), m_javaGlue->m_updateTextfield,
(int) ptr, false, string, m_textGeneration);
env->DeleteLocalRef(string);
checkException(env);
@@ -3470,8 +3572,10 @@ void WebViewCore::updateTextfield(WebCore::Node* ptr, bool changeToPassword,
void WebViewCore::clearTextEntry()
{
JNIEnv* env = JSC::Bindings::getJNIEnv();
- env->CallVoidMethod(m_javaGlue->object(env).get(),
- m_javaGlue->m_clearTextEntry);
+ AutoJObject javaObject = m_javaGlue->object(env);
+ if (!javaObject.get())
+ return;
+ env->CallVoidMethod(javaObject.get(), m_javaGlue->m_clearTextEntry);
}
void WebViewCore::setBackgroundColor(SkColor c)
@@ -3493,10 +3597,13 @@ void WebViewCore::setBackgroundColor(SkColor c)
jclass WebViewCore::getPluginClass(const WTF::String& libName, const char* className)
{
JNIEnv* env = JSC::Bindings::getJNIEnv();
+ AutoJObject javaObject = m_javaGlue->object(env);
+ if (!javaObject.get())
+ return 0;
jstring libString = wtfStringToJstring(env, libName);
jstring classString = env->NewStringUTF(className);
- jobject pluginClass = env->CallObjectMethod(m_javaGlue->object(env).get(),
+ jobject pluginClass = env->CallObjectMethod(javaObject.get(),
m_javaGlue->m_getPluginClass,
libString, classString);
checkException(env);
@@ -3505,36 +3612,41 @@ jclass WebViewCore::getPluginClass(const WTF::String& libName, const char* class
env->DeleteLocalRef(libString);
env->DeleteLocalRef(classString);
- if (pluginClass != NULL) {
+ if (pluginClass != 0) {
return static_cast<jclass>(pluginClass);
} else {
- return NULL;
+ return 0;
}
}
void WebViewCore::showFullScreenPlugin(jobject childView, NPP npp)
{
JNIEnv* env = JSC::Bindings::getJNIEnv();
- AutoJObject obj = m_javaGlue->object(env);
+ AutoJObject javaObject = m_javaGlue->object(env);
+ if (!javaObject.get())
+ return;
- env->CallVoidMethod(obj.get(),
- m_javaGlue->m_showFullScreenPlugin, childView, (int)npp);
+ env->CallVoidMethod(javaObject.get(), m_javaGlue->m_showFullScreenPlugin, childView, reinterpret_cast<int>(npp));
checkException(env);
}
void WebViewCore::hideFullScreenPlugin()
{
JNIEnv* env = JSC::Bindings::getJNIEnv();
- env->CallVoidMethod(m_javaGlue->object(env).get(),
- m_javaGlue->m_hideFullScreenPlugin);
+ AutoJObject javaObject = m_javaGlue->object(env);
+ if (!javaObject.get())
+ return;
+ env->CallVoidMethod(javaObject.get(), m_javaGlue->m_hideFullScreenPlugin);
checkException(env);
}
jobject WebViewCore::createSurface(jobject view)
{
JNIEnv* env = JSC::Bindings::getJNIEnv();
- jobject result = env->CallObjectMethod(m_javaGlue->object(env).get(),
- m_javaGlue->m_createSurface, view);
+ AutoJObject javaObject = m_javaGlue->object(env);
+ if (!javaObject.get())
+ return 0;
+ jobject result = env->CallObjectMethod(javaObject.get(), m_javaGlue->m_createSurface, view);
checkException(env);
return result;
}
@@ -3542,7 +3654,10 @@ jobject WebViewCore::createSurface(jobject view)
jobject WebViewCore::addSurface(jobject view, int x, int y, int width, int height)
{
JNIEnv* env = JSC::Bindings::getJNIEnv();
- jobject result = env->CallObjectMethod(m_javaGlue->object(env).get(),
+ AutoJObject javaObject = m_javaGlue->object(env);
+ if (!javaObject.get())
+ return 0;
+ jobject result = env->CallObjectMethod(javaObject.get(),
m_javaGlue->m_addSurface,
view, x, y, width, height);
checkException(env);
@@ -3552,7 +3667,10 @@ jobject WebViewCore::addSurface(jobject view, int x, int y, int width, int heigh
void WebViewCore::updateSurface(jobject childView, int x, int y, int width, int height)
{
JNIEnv* env = JSC::Bindings::getJNIEnv();
- env->CallVoidMethod(m_javaGlue->object(env).get(),
+ AutoJObject javaObject = m_javaGlue->object(env);
+ if (!javaObject.get())
+ return;
+ env->CallVoidMethod(javaObject.get(),
m_javaGlue->m_updateSurface, childView,
x, y, width, height);
checkException(env);
@@ -3561,16 +3679,21 @@ void WebViewCore::updateSurface(jobject childView, int x, int y, int width, int
void WebViewCore::destroySurface(jobject childView)
{
JNIEnv* env = JSC::Bindings::getJNIEnv();
- env->CallVoidMethod(m_javaGlue->object(env).get(), m_javaGlue->m_destroySurface, childView);
+ AutoJObject javaObject = m_javaGlue->object(env);
+ if (!javaObject.get())
+ return;
+ env->CallVoidMethod(javaObject.get(), m_javaGlue->m_destroySurface, childView);
checkException(env);
}
jobject WebViewCore::getContext()
{
JNIEnv* env = JSC::Bindings::getJNIEnv();
- AutoJObject obj = m_javaGlue->object(env);
+ AutoJObject javaObject = m_javaGlue->object(env);
+ if (!javaObject.get())
+ return 0;
- jobject result = env->CallObjectMethod(obj.get(), m_javaGlue->m_getContext);
+ jobject result = env->CallObjectMethod(javaObject.get(), m_javaGlue->m_getContext);
checkException(env);
return result;
}
@@ -3578,7 +3701,10 @@ jobject WebViewCore::getContext()
void WebViewCore::keepScreenOn(bool screenOn) {
if ((screenOn && m_screenOnCounter == 0) || (!screenOn && m_screenOnCounter == 1)) {
JNIEnv* env = JSC::Bindings::getJNIEnv();
- env->CallVoidMethod(m_javaGlue->object(env).get(), m_javaGlue->m_keepScreenOn, screenOn);
+ AutoJObject javaObject = m_javaGlue->object(env);
+ if (!javaObject.get())
+ return;
+ env->CallVoidMethod(javaObject.get(), m_javaGlue->m_keepScreenOn, screenOn);
checkException(env);
}
@@ -3609,7 +3735,10 @@ void WebViewCore::showRect(int left, int top, int width, int height,
float xPercentInView, float yPercentInDoc, float yPercentInView)
{
JNIEnv* env = JSC::Bindings::getJNIEnv();
- env->CallVoidMethod(m_javaGlue->object(env).get(), m_javaGlue->m_showRect,
+ AutoJObject javaObject = m_javaGlue->object(env);
+ if (!javaObject.get())
+ return;
+ env->CallVoidMethod(javaObject.get(), m_javaGlue->m_showRect,
left, top, width, height, contentWidth, contentHeight,
xPercentInDoc, xPercentInView, yPercentInDoc, yPercentInView);
checkException(env);
@@ -3618,24 +3747,30 @@ void WebViewCore::showRect(int left, int top, int width, int height,
void WebViewCore::centerFitRect(int x, int y, int width, int height)
{
JNIEnv* env = JSC::Bindings::getJNIEnv();
- env->CallVoidMethod(m_javaGlue->object(env).get(),
- m_javaGlue->m_centerFitRect, x, y, width, height);
+ AutoJObject javaObject = m_javaGlue->object(env);
+ if (!javaObject.get())
+ return;
+ env->CallVoidMethod(javaObject.get(), m_javaGlue->m_centerFitRect, x, y, width, height);
checkException(env);
}
-
void WebViewCore::setScrollbarModes(ScrollbarMode horizontalMode, ScrollbarMode verticalMode)
{
JNIEnv* env = JSC::Bindings::getJNIEnv();
- env->CallVoidMethod(m_javaGlue->object(env).get(), m_javaGlue->m_setScrollbarModes,
- horizontalMode, verticalMode);
+ AutoJObject javaObject = m_javaGlue->object(env);
+ if (!javaObject.get())
+ return;
+ env->CallVoidMethod(javaObject.get(), m_javaGlue->m_setScrollbarModes, horizontalMode, verticalMode);
checkException(env);
}
void WebViewCore::notifyWebAppCanBeInstalled()
{
JNIEnv* env = JSC::Bindings::getJNIEnv();
- env->CallVoidMethod(m_javaGlue->object(env).get(), m_javaGlue->m_setInstallableWebApp);
+ AutoJObject javaObject = m_javaGlue->object(env);
+ if (!javaObject.get())
+ return;
+ env->CallVoidMethod(javaObject.get(), m_javaGlue->m_setInstallableWebApp);
checkException(env);
}
@@ -3643,9 +3778,11 @@ void WebViewCore::notifyWebAppCanBeInstalled()
void WebViewCore::enterFullscreenForVideoLayer(int layerId, const WTF::String& url)
{
JNIEnv* env = JSC::Bindings::getJNIEnv();
+ AutoJObject javaObject = m_javaGlue->object(env);
+ if (!javaObject.get())
+ return;
jstring jUrlStr = wtfStringToJstring(env, url);
- env->CallVoidMethod(m_javaGlue->object(env).get(),
- m_javaGlue->m_enterFullscreenForVideoLayer, layerId, jUrlStr);
+ env->CallVoidMethod(javaObject.get(), m_javaGlue->m_enterFullscreenForVideoLayer, layerId, jUrlStr);
checkException(env);
}
#endif
@@ -3654,8 +3791,11 @@ void WebViewCore::setWebTextViewAutoFillable(int queryId, const string16& previe
{
#if ENABLE(WEB_AUTOFILL)
JNIEnv* env = JSC::Bindings::getJNIEnv();
+ AutoJObject javaObject = m_javaGlue->object(env);
+ if (!javaObject.get())
+ return;
jstring preview = env->NewString(previewSummary.data(), previewSummary.length());
- env->CallVoidMethod(m_javaGlue->object(env).get(), m_javaGlue->m_setWebTextViewAutoFillable, queryId, preview);
+ env->CallVoidMethod(javaObject.get(), m_javaGlue->m_setWebTextViewAutoFillable, queryId, preview);
env->DeleteLocalRef(preview);
#endif
}
@@ -3663,8 +3803,10 @@ void WebViewCore::setWebTextViewAutoFillable(int queryId, const string16& previe
bool WebViewCore::drawIsPaused() const
{
JNIEnv* env = JSC::Bindings::getJNIEnv();
- return env->GetBooleanField(m_javaGlue->object(env).get(),
- gWebViewCoreFields.m_drawIsPaused);
+ AutoJObject javaObject = m_javaGlue->object(env);
+ if (!javaObject.get())
+ return false;
+ return env->GetBooleanField(javaObject.get(), gWebViewCoreFields.m_drawIsPaused);
}
#if USE(CHROME_NETWORK_STACK)
diff --git a/Source/WebKit/android/jni/WebViewCore.h b/Source/WebKit/android/jni/WebViewCore.h
index 8d8f303..0e9d80f 100644
--- a/Source/WebKit/android/jni/WebViewCore.h
+++ b/Source/WebKit/android/jni/WebViewCore.h
@@ -231,24 +231,28 @@ namespace android {
bool jsInterrupt();
/**
- * Tell the Java side that the origin has exceeded its database quota.
+ * Posts a message to the UI thread to inform the Java side that the
+ * origin has exceeded its database quota.
* @param url The URL of the page that caused the quota overflow
* @param databaseIdentifier the id of the database that caused the
* quota overflow.
* @param currentQuota The current quota for the origin
* @param estimatedSize The estimated size of the database
+ * @return Whether the message was successfully sent.
*/
- void exceededDatabaseQuota(const WTF::String& url,
+ bool exceededDatabaseQuota(const WTF::String& url,
const WTF::String& databaseIdentifier,
const unsigned long long currentQuota,
const unsigned long long estimatedSize);
/**
- * Tell the Java side that the appcache has exceeded its max size.
+ * Posts a message to the UI thread to inform the Java side that the
+ * appcache has exceeded its max size.
* @param spaceNeeded is the amount of disk space that would be needed
* in order for the last appcache operation to succeed.
+ * @return Whether the message was successfully sent.
*/
- void reachedMaxAppCacheSize(const unsigned long long spaceNeeded);
+ bool reachedMaxAppCacheSize(const unsigned long long spaceNeeded);
/**
* Set up the PageGroup's idea of which links have been visited,