diff options
Diffstat (limited to 'WebKit/android/nav/WebView.cpp')
-rw-r--r-- | WebKit/android/nav/WebView.cpp | 131 |
1 files changed, 36 insertions, 95 deletions
diff --git a/WebKit/android/nav/WebView.cpp b/WebKit/android/nav/WebView.cpp index 1c98b87..0dccbee 100644 --- a/WebKit/android/nav/WebView.cpp +++ b/WebKit/android/nav/WebView.cpp @@ -34,6 +34,7 @@ #include "CachedFrame.h" #include "CachedNode.h" #include "CachedRoot.h" +#include "CString.h" #include "FindCanvas.h" #include "Frame.h" #include "GraphicsJNI.h" @@ -98,7 +99,7 @@ enum FrameCachePermission { }; struct JavaGlue { - jobject m_obj; + jweak m_obj; jmethodID m_clearTextEntry; jmethodID m_overrideLoading; jmethodID m_scrollBy; @@ -127,7 +128,7 @@ WebView(JNIEnv* env, jobject javaWebView, int viewImpl) { jclass clazz = env->FindClass("android/webkit/WebView"); // m_javaGlue = new JavaGlue; - m_javaGlue.m_obj = adoptGlobalRef(env, javaWebView); + m_javaGlue.m_obj = env->NewWeakGlobalRef(javaWebView); m_javaGlue.m_scrollBy = GetJMethod(env, clazz, "setContentScrollBy", "(IIZ)Z"); m_javaGlue.m_clearTextEntry = GetJMethod(env, clazz, "clearTextEntry", "()V"); m_javaGlue.m_overrideLoading = GetJMethod(env, clazz, "overrideLoading", "(Ljava/lang/String;)V"); @@ -173,7 +174,7 @@ WebView(JNIEnv* env, jobject javaWebView, int viewImpl) if (m_javaGlue.m_obj) { JNIEnv* env = JSC::Bindings::getJNIEnv(); - env->DeleteGlobalRef(m_javaGlue.m_obj); + env->DeleteWeakGlobalRef(m_javaGlue.m_obj); m_javaGlue.m_obj = 0; } delete m_frameCacheUI; @@ -214,12 +215,7 @@ void clearTextEntry() { DEBUG_NAV_UI_LOGD("%s", __FUNCTION__); JNIEnv* env = JSC::Bindings::getJNIEnv(); - AutoJObject obj = m_javaGlue.object(env); - // if it is called during or after DESTROY is handled, the real object of - // WebView can be gone. Check before using it. - if (!obj.get()) - return; - env->CallVoidMethod(obj.get(), m_javaGlue.m_clearTextEntry); + env->CallVoidMethod(m_javaGlue.object(env).get(), m_javaGlue.m_clearTextEntry); checkException(env); } @@ -646,12 +642,7 @@ int getScaledMaxXScroll() { LOG_ASSERT(m_javaGlue.m_obj, "A java object was not associated with this native WebView!"); JNIEnv* env = JSC::Bindings::getJNIEnv(); - AutoJObject obj = m_javaGlue.object(env); - // if it is called during or after DESTROY is handled, the real object of - // WebView can be gone. Check before using it. - if (!obj.get()) - return 0; - int result = env->CallIntMethod(obj.get(), m_javaGlue.m_getScaledMaxXScroll); + int result = env->CallIntMethod(m_javaGlue.object(env).get(), m_javaGlue.m_getScaledMaxXScroll); checkException(env); return result; } @@ -660,12 +651,7 @@ int getScaledMaxYScroll() { LOG_ASSERT(m_javaGlue.m_obj, "A java object was not associated with this native WebView!"); JNIEnv* env = JSC::Bindings::getJNIEnv(); - AutoJObject obj = m_javaGlue.object(env); - // if it is called during or after DESTROY is handled, the real object of - // WebView can be gone. Check before using it. - if (!obj.get()) - return 0; - int result = env->CallIntMethod(obj.get(), m_javaGlue.m_getScaledMaxYScroll); + int result = env->CallIntMethod(m_javaGlue.object(env).get(), m_javaGlue.m_getScaledMaxYScroll); checkException(env); return result; } @@ -674,12 +660,7 @@ void getVisibleRect(WebCore::IntRect* rect) { LOG_ASSERT(m_javaGlue.m_obj, "A java object was not associated with this native WebView!"); JNIEnv* env = JSC::Bindings::getJNIEnv(); - AutoJObject obj = m_javaGlue.object(env); - // if it is called during or after DESTROY is handled, the real object of - // WebView can be gone. Check before using it. - if (!obj.get()) - return; - jobject jRect = env->CallObjectMethod(obj.get(), m_javaGlue.m_getVisibleRect); + jobject jRect = env->CallObjectMethod(m_javaGlue.object(env).get(), m_javaGlue.m_getVisibleRect); checkException(env); int left = (int) env->GetIntField(jRect, m_javaGlue.m_rectLeft); checkException(env); @@ -946,7 +927,7 @@ bool motionUp(int x, int y, int slop) if (!root) return 0; const CachedFrame* frame = 0; - const CachedNode* result = slop ? findAt(root, rect, &frame, &rx, &ry) : 0; + const CachedNode* result = findAt(root, rect, &frame, &rx, &ry); if (!result) { DBG_NAV_LOGD("no nodes found root=%p", root); setNavBounds(rect); @@ -998,13 +979,9 @@ int getBlockLeftEdge(int x, int y, float scale) void overrideUrlLoading(const WebCore::String& url) { JNIEnv* env = JSC::Bindings::getJNIEnv(); - AutoJObject obj = m_javaGlue.object(env); - // if it is called during or after DESTROY is handled, the real object of - // WebView can be gone. Check before using it. - if (!obj.get()) - return; jstring jName = env->NewString((jchar*) url.characters(), url.length()); - env->CallVoidMethod(obj.get(), m_javaGlue.m_overrideLoading, jName); + env->CallVoidMethod(m_javaGlue.object(env).get(), + m_javaGlue.m_overrideLoading, jName); env->DeleteLocalRef(jName); } @@ -1051,9 +1028,15 @@ void moveSelection(int x, int y, bool extendSelection) m_selEnd.fLeft, m_selEnd.fTop, m_selEnd.fRight, m_selEnd.fBottom); } -const SkRegion& getSelection() +const String getSelection() { - return m_selRegion; + WebCore::IntRect r; + getVisibleRect(&r); + SkIRect area; + area.set(r.x(), r.y(), r.right(), r.bottom()); + String result = CopyPaste::text(*m_navPictureUI, area, m_selRegion); + DBG_NAV_LOGD("text=%s", result.latin1().data()); + return result; } void drawSelectionRegion(SkCanvas* canvas) @@ -1128,15 +1111,10 @@ void getSelectionCaret(SkPath* path) void sendMoveFocus(WebCore::Frame* framePtr, WebCore::Node* nodePtr) { - DBG_NAV_LOGD("framePtr=%p nodePtr=%p x=%d y=%d", framePtr, nodePtr, x, y); + DBG_NAV_LOGD("framePtr=%p nodePtr=%p", framePtr, nodePtr); JNIEnv* env = JSC::Bindings::getJNIEnv(); - AutoJObject obj = m_javaGlue.object(env); - // if it is called during or after DESTROY is handled, the real object of - // WebView can be gone. Check before using it. - if (!obj.get()) - return; - env->CallVoidMethod(obj.get(), m_javaGlue.m_sendMoveFocus, (jint) framePtr, - (jint) nodePtr); + env->CallVoidMethod(m_javaGlue.object(env).get(), + m_javaGlue.m_sendMoveFocus, (jint) framePtr, (jint) nodePtr); checkException(env); } @@ -1144,12 +1122,7 @@ void sendMoveMouse(WebCore::Frame* framePtr, WebCore::Node* nodePtr, int x, int { DBG_NAV_LOGD("framePtr=%p nodePtr=%p x=%d y=%d", framePtr, nodePtr, x, y); JNIEnv* env = JSC::Bindings::getJNIEnv(); - AutoJObject obj = m_javaGlue.object(env); - // if it is called during or after DESTROY is handled, the real object of - // WebView can be gone. Check before using it. - if (!obj.get()) - return; - env->CallVoidMethod(obj.get(), m_javaGlue.m_sendMoveMouse, + env->CallVoidMethod(m_javaGlue.object(env).get(), m_javaGlue.m_sendMoveMouse, (jint) framePtr, (jint) nodePtr, x, y); checkException(env); } @@ -1158,12 +1131,8 @@ void sendMoveMouseIfLatest(bool disableFocusController) { LOG_ASSERT(m_javaGlue.m_obj, "A java object was not associated with this native WebView!"); JNIEnv* env = JSC::Bindings::getJNIEnv(); - AutoJObject obj = m_javaGlue.object(env); - // if it is called during or after DESTROY is handled, the real object of - // WebView can be gone. Check before using it. - if (!obj.get()) - return; - env->CallVoidMethod(obj.get(), m_javaGlue.m_sendMoveMouseIfLatest, disableFocusController); + env->CallVoidMethod(m_javaGlue.object(env).get(), + m_javaGlue.m_sendMoveMouseIfLatest, disableFocusController); checkException(env); } @@ -1175,12 +1144,7 @@ void sendMotionUp( m_generation, framePtr, nodePtr, x, y); LOG_ASSERT(m_javaGlue.m_obj, "A WebView was not associated with this WebViewNative!"); JNIEnv* env = JSC::Bindings::getJNIEnv(); - AutoJObject obj = m_javaGlue.object(env); - // if it is called during or after DESTROY is handled, the real object of - // WebView can be gone. Check before using it. - if (!obj.get()) - return; - env->CallVoidMethod(obj.get(), m_javaGlue.m_sendMotionUp, + env->CallVoidMethod(m_javaGlue.object(env).get(), m_javaGlue.m_sendMotionUp, m_generation, (jint) framePtr, (jint) nodePtr, x, y); checkException(env); } @@ -1249,12 +1213,7 @@ bool scrollBy(int dx, int dy) LOG_ASSERT(m_javaGlue.m_obj, "A java object was not associated with this native WebView!"); JNIEnv* env = JSC::Bindings::getJNIEnv(); - AutoJObject obj = m_javaGlue.object(env); - // if it is called during or after DESTROY is handled, the real object of - // WebView can be gone. Check before using it. - if (!obj.get()) - return false; - bool result = env->CallBooleanMethod(obj.get(), + bool result = env->CallBooleanMethod(m_javaGlue.object(env).get(), m_javaGlue.m_scrollBy, dx, dy, true); checkException(env); return result; @@ -1291,49 +1250,30 @@ bool hasFocusNode() void rebuildWebTextView() { JNIEnv* env = JSC::Bindings::getJNIEnv(); - AutoJObject obj = m_javaGlue.object(env); - // if it is called during or after DESTROY is handled, the real object of - // WebView can be gone. Check before using it. - if (!obj.get()) - return; - env->CallVoidMethod(obj.get(), m_javaGlue.m_rebuildWebTextView); + env->CallVoidMethod(m_javaGlue.object(env).get(), + m_javaGlue.m_rebuildWebTextView); checkException(env); } void viewInvalidate() { JNIEnv* env = JSC::Bindings::getJNIEnv(); - AutoJObject obj = m_javaGlue.object(env); - // if it is called during or after DESTROY is handled, the real object of - // WebView can be gone. Check before using it. - if (!obj.get()) - return; - env->CallVoidMethod(obj.get(), m_javaGlue.m_viewInvalidate); + env->CallVoidMethod(m_javaGlue.object(env).get(), m_javaGlue.m_viewInvalidate); checkException(env); } void viewInvalidateRect(int l, int t, int r, int b) { JNIEnv* env = JSC::Bindings::getJNIEnv(); - AutoJObject obj = m_javaGlue.object(env); - // if it is called during or after DESTROY is handled, the real object of - // WebView can be gone. Check before using it. - if (!obj.get()) - return; - env->CallVoidMethod(obj.get(), m_javaGlue.m_viewInvalidateRect, l, r, t, b); + env->CallVoidMethod(m_javaGlue.object(env).get(), m_javaGlue.m_viewInvalidateRect, l, r, t, b); checkException(env); } void postInvalidateDelayed(int64_t delay, const WebCore::IntRect& bounds) { JNIEnv* env = JSC::Bindings::getJNIEnv(); - AutoJObject obj = m_javaGlue.object(env); - // if it is called during or after DESTROY is handled, the real object of - // WebView can be gone. Check before using it. - if (!obj.get()) - return; - env->CallVoidMethod(obj.get(), m_javaGlue.m_postInvalidateDelayed, - delay, bounds.x(), bounds.y(), bounds.right(), bounds.bottom()); + env->CallVoidMethod(m_javaGlue.object(env).get(), m_javaGlue.m_postInvalidateDelayed, + delay, bounds.x(), bounds.y(), bounds.right(), bounds.bottom()); checkException(env); } @@ -2108,7 +2048,8 @@ static jobject nativeGetSelection(JNIEnv *env, jobject obj) { WebView* view = GET_NATIVE_VIEW(env, obj); LOG_ASSERT(view, "view not set in %s", __FUNCTION__); - return GraphicsJNI::createRegion(env, new SkRegion(view->getSelection())); + String selection = view->getSelection(); + return env->NewString((jchar*)selection.characters(), selection.length()); } #ifdef ANDROID_DUMP_DISPLAY_TREE @@ -2238,7 +2179,7 @@ static JNINativeMethod gJavaWebViewMethods[] = { (void*) nativeFocusNodePointer }, { "nativeGetCursorRingBounds", "()Landroid/graphics/Rect;", (void*) nativeGetCursorRingBounds }, - { "nativeGetSelection", "()Landroid/graphics/Region;", + { "nativeGetSelection", "()Ljava/lang/String;", (void*) nativeGetSelection }, { "nativeHasCursorNode", "()Z", (void*) nativeHasCursorNode }, |