From 14e3d9bdf2270d399bae78946e3efe62a6c6c373 Mon Sep 17 00:00:00 2001 From: Leon Clarke Date: Mon, 28 Sep 2009 11:17:08 +0100 Subject: [PATCH] Don't crash on java exception Link coloring - doing the database lookup in a separate thread Formatting Whitespace changes Re-ordered following review --- WebKit/android/jni/WebViewCore.cpp | 47 ++++++++++++++++++++++++++------------ WebKit/android/jni/WebViewCore.h | 14 ++++++++---- 2 files changed, 41 insertions(+), 20 deletions(-) diff --git a/WebKit/android/jni/WebViewCore.cpp b/WebKit/android/jni/WebViewCore.cpp index d41b3a826..ac47cbf44 100644 --- a/WebKit/android/jni/WebViewCore.cpp +++ b/WebKit/android/jni/WebViewCore.cpp @@ -257,7 +257,7 @@ WebViewCore::WebViewCore(JNIEnv* env, jobject javaWebViewCore, WebCore::Frame* m m_javaGlue->m_requestKeyboard = GetJMethod(env, clazz, "requestKeyboard", "(Z)V"); m_javaGlue->m_exceededDatabaseQuota = GetJMethod(env, clazz, "exceededDatabaseQuota", "(Ljava/lang/String;Ljava/lang/String;JJ)V"); m_javaGlue->m_reachedMaxAppCacheSize = GetJMethod(env, clazz, "reachedMaxAppCacheSize", "(J)V"); - m_javaGlue->m_populateVisitedLinks = GetJMethod(env, clazz, "populateVisitedLinks", "()[Ljava/lang/String;"); + m_javaGlue->m_populateVisitedLinks = GetJMethod(env, clazz, "populateVisitedLinks", "()V"); m_javaGlue->m_geolocationPermissionsShowPrompt = GetJMethod(env, clazz, "geolocationPermissionsShowPrompt", "(Ljava/lang/String;)V"); m_javaGlue->m_geolocationPermissionsHidePrompt = GetJMethod(env, clazz, "geolocationPermissionsHidePrompt", "()V"); m_javaGlue->m_addMessageToConsole = GetJMethod(env, clazz, "addMessageToConsole", "(Ljava/lang/String;ILjava/lang/String;)V"); @@ -336,6 +336,7 @@ void WebViewCore::reset(bool fromConstructor) m_scrollOffsetY = 0; m_screenWidth = 0; m_screenHeight = 0; + m_groupForVisitedLinks = NULL; } static bool layoutIfNeededRecursive(WebCore::Frame* f) @@ -2090,23 +2091,12 @@ void WebViewCore::reachedMaxAppCacheSize(const unsigned long long spaceNeeded) void WebViewCore::populateVisitedLinks(WebCore::PageGroup* group) { + m_groupForVisitedLinks = group; JNIEnv* env = JSC::Bindings::getJNIEnv(); - jobjectArray array = static_cast(env->CallObjectMethod(m_javaGlue->object(env).get(), m_javaGlue->m_populateVisitedLinks)); - if (!array) - return; - jsize len = env->GetArrayLength(array); - for (jsize i = 0; i < len; i++) { - jstring item = static_cast(env->GetObjectArrayElement(array, i)); - const UChar* str = static_cast(env->GetStringChars(item, NULL)); - jsize len = env->GetStringLength(item); - group->addVisitedLink(str, len); - env->ReleaseStringChars(item, str); - env->DeleteLocalRef(item); - } - env->DeleteLocalRef(array); + env->CallVoidMethod(m_javaGlue->object(env).get(), m_javaGlue->m_populateVisitedLinks); + checkException(env); } - void WebViewCore::geolocationPermissionsShowPrompt(const WebCore::String& origin) { JNIEnv* env = JSC::Bindings::getJNIEnv(); @@ -2434,6 +2424,12 @@ static void SaveDocumentState(JNIEnv *env, jobject obj, jint frame) viewImpl->saveDocumentState((WebCore::Frame*) frame); } +void WebViewCore::addVisitedLink(const UChar* string, int length) +{ + if (m_groupForVisitedLinks) + m_groupForVisitedLinks->addVisitedLink(string, length); +} + static bool RecordContent(JNIEnv *env, jobject obj, jobject region, jobject pt) { #ifdef ANDROID_INSTRUMENT @@ -2790,6 +2786,25 @@ static void FreeMemory(JNIEnv* env, jobject obj) GET_NATIVE_VIEW(env, obj)->sendPluginEvent(event); } +static void ProvideVisitedHistory(JNIEnv *env, jobject obj, jobject hist) +{ + WebViewCore* viewImpl = GET_NATIVE_VIEW(env, obj); + LOG_ASSERT(viewImpl, "viewImpl not set in %s", __FUNCTION__); + + jobjectArray array = static_cast(hist); + + jsize len = env->GetArrayLength(array); + for (jsize i = 0; i < len; i++) { + jstring item = static_cast(env->GetObjectArrayElement(array, i)); + const UChar* str = static_cast(env->GetStringChars(item, NULL)); + jsize len = env->GetStringLength(item); + viewImpl->addVisitedLink(str, len); + env->ReleaseStringChars(item, str); + env->DeleteLocalRef(item); + } + env->DeleteLocalRef(array); +} + // ---------------------------------------------------------------------------- /* @@ -2877,6 +2892,8 @@ static JNINativeMethod gJavaWebViewCoreMethods[] = { { "nativeUpdatePluginState", "(III)V", (void*) UpdatePluginState }, { "nativeUpdateFrameCacheIfLoading", "()V", (void*) UpdateFrameCacheIfLoading }, + { "nativeProvideVisitedHistory", "([Ljava/lang/String;)V", + (void*) ProvideVisitedHistory }, }; int register_webviewcore(JNIEnv* env) diff --git a/WebKit/android/jni/WebViewCore.h b/WebKit/android/jni/WebViewCore.h index ff5e175df..5d12158cf 100644 --- a/WebKit/android/jni/WebViewCore.h +++ b/WebKit/android/jni/WebViewCore.h @@ -217,11 +217,12 @@ namespace android { */ void reachedMaxAppCacheSize(const unsigned long long spaceNeeded); - /** - * Set up the PageGroup's idea of which links have been visited, with the browser history. - * @param group the object to deliver the links to. - */ - void populateVisitedLinks(WebCore::PageGroup*); + /** + * Set up the PageGroup's idea of which links have been visited, + * with the browser history. + * @param group the object to deliver the links to. + */ + void populateVisitedLinks(WebCore::PageGroup*); /** * Instruct the browser to show a Geolocation permission prompt for the @@ -324,6 +325,8 @@ namespace android { void saveDocumentState(WebCore::Frame* frame); + void addVisitedLink(const UChar*, int); + // TODO: I don't like this hack but I need to access the java object in // order to send it as a parameter to java AutoJObject getJavaObject(); @@ -483,6 +486,7 @@ namespace android { float m_screenWidthScale; unsigned m_domtree_version; bool m_check_domtree_version; + PageGroup* m_groupForVisitedLinks; SkTDArray m_plugins; WebCore::Timer m_pluginInvalTimer; -- 2.11.0