summaryrefslogtreecommitdiffstats
path: root/WebKit/android/jni/WebViewCore.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'WebKit/android/jni/WebViewCore.cpp')
-rw-r--r--WebKit/android/jni/WebViewCore.cpp537
1 files changed, 112 insertions, 425 deletions
diff --git a/WebKit/android/jni/WebViewCore.cpp b/WebKit/android/jni/WebViewCore.cpp
index 5d2b8bb..15cef2b 100644
--- a/WebKit/android/jni/WebViewCore.cpp
+++ b/WebKit/android/jni/WebViewCore.cpp
@@ -147,6 +147,8 @@ FILE* gRenderTreeFile = 0;
namespace android {
+bool WebViewCore::s_isPaused = false;
+
static SkTDArray<WebViewCore*> gInstanceList;
void WebViewCore::addInstance(WebViewCore* inst) {
@@ -185,7 +187,7 @@ struct WebViewCoreFields {
// ----------------------------------------------------------------------------
struct WebViewCore::JavaGlue {
- jobject m_obj;
+ jweak m_obj;
jmethodID m_spawnScrollTo;
jmethodID m_scrollTo;
jmethodID m_scrollBy;
@@ -264,12 +266,13 @@ WebViewCore::WebViewCore(JNIEnv* env, jobject javaWebViewCore, WebCore::Frame* m
m_screenWidth = 320;
m_scale = 1;
m_screenWidthScale = 1;
+ m_touchEventListenerCount = 0;
LOG_ASSERT(m_mainFrame, "Uh oh, somehow a frameview was made without an initial frame!");
jclass clazz = env->GetObjectClass(javaWebViewCore);
m_javaGlue = new JavaGlue;
- m_javaGlue->m_obj = adoptGlobalRef(env, javaWebViewCore);
+ m_javaGlue->m_obj = env->NewWeakGlobalRef(javaWebViewCore);
m_javaGlue->m_spawnScrollTo = GetJMethod(env, clazz, "contentSpawnScrollTo", "(II)V");
m_javaGlue->m_scrollTo = GetJMethod(env, clazz, "contentScrollTo", "(II)V");
m_javaGlue->m_scrollBy = GetJMethod(env, clazz, "contentScrollBy", "(IIZ)V");
@@ -331,7 +334,7 @@ WebViewCore::~WebViewCore()
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_javaGlue;
@@ -346,6 +349,9 @@ WebViewCore* WebViewCore::getWebViewCore(const WebCore::FrameView* view)
WebViewCore* WebViewCore::getWebViewCore(const WebCore::ScrollView* view)
{
+ if (!view)
+ return 0;
+
WebFrameView* webFrameView = static_cast<WebFrameView*>(view->platformWidget());
if (!webFrameView)
return 0;
@@ -626,13 +632,11 @@ 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!");
JNIEnv* env = JSC::Bindings::getJNIEnv();
- AutoJObject obj = m_javaGlue->object(env);
- // if it is called during DESTROY is handled, the real object of WebViewCore
- // can be gone. Check before using it.
- if (!obj.get())
- return;
- env->CallVoidMethod(obj.get(), m_javaGlue->m_sendFindAgain);
+ env->CallVoidMethod(m_javaGlue->object(env).get(),
+ m_javaGlue->m_sendFindAgain);
checkException(env);
}
}
@@ -838,12 +842,9 @@ void WebViewCore::scrollTo(int x, int y, bool animate)
// LOGD("WebViewCore::scrollTo(%d %d)\n", x, y);
JNIEnv* env = JSC::Bindings::getJNIEnv();
- AutoJObject obj = m_javaGlue->object(env);
- // if it is called during DESTROY is handled, the real object of WebViewCore
- // can be gone. Check before using it.
- if (!obj.get())
- return;
- env->CallVoidMethod(obj.get(), animate ? m_javaGlue->m_spawnScrollTo : m_javaGlue->m_scrollTo, x, y);
+ env->CallVoidMethod(m_javaGlue->object(env).get(),
+ animate ? m_javaGlue->m_spawnScrollTo : m_javaGlue->m_scrollTo,
+ x, y);
checkException(env);
}
@@ -851,12 +852,7 @@ void WebViewCore::sendNotifyProgressFinished()
{
LOG_ASSERT(m_javaGlue->m_obj, "A Java widget was not associated with this view bridge!");
JNIEnv* env = JSC::Bindings::getJNIEnv();
- AutoJObject obj = m_javaGlue->object(env);
- // if it is called during DESTROY is handled, the real object of WebViewCore
- // can be gone. Check before using it.
- if (!obj.get())
- return;
- env->CallVoidMethod(obj.get(), m_javaGlue->m_sendNotifyProgressFinished);
+ env->CallVoidMethod(m_javaGlue->object(env).get(), m_javaGlue->m_sendNotifyProgressFinished);
checkException(env);
}
@@ -864,12 +860,7 @@ 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();
- AutoJObject obj = m_javaGlue->object(env);
- // if it is called during DESTROY is handled, the real object of WebViewCore
- // can be gone. Check before using it.
- if (!obj.get())
- return;
- env->CallVoidMethod(obj.get(),
+ env->CallVoidMethod(m_javaGlue->object(env).get(),
m_javaGlue->m_sendViewInvalidate,
rect.x(), rect.y(), rect.right(), rect.bottom());
checkException(env);
@@ -880,12 +871,7 @@ void WebViewCore::scrollBy(int dx, int dy, bool animate)
if (!(dx | dy))
return;
JNIEnv* env = JSC::Bindings::getJNIEnv();
- AutoJObject obj = m_javaGlue->object(env);
- // if it is called during DESTROY is handled, the real object of WebViewCore
- // can be gone. Check before using it.
- if (!obj.get())
- return;
- env->CallVoidMethod(obj.get(), m_javaGlue->m_scrollBy,
+ env->CallVoidMethod(m_javaGlue->object(env).get(), m_javaGlue->m_scrollBy,
dx, dy, animate);
checkException(env);
}
@@ -915,12 +901,7 @@ void WebViewCore::setRootLayer(int layer)
void WebViewCore::contentDraw()
{
JNIEnv* env = JSC::Bindings::getJNIEnv();
- AutoJObject obj = m_javaGlue->object(env);
- // if it is called during DESTROY is handled, the real object of WebViewCore
- // can be gone. Check before using it.
- if (!obj.get())
- return;
- env->CallVoidMethod(obj.get(), m_javaGlue->m_contentDraw);
+ env->CallVoidMethod(m_javaGlue->object(env).get(), m_javaGlue->m_contentDraw);
checkException(env);
}
@@ -969,18 +950,14 @@ void WebViewCore::didFirstLayout()
WebCore::FrameLoadType loadType = loader->loadType();
JNIEnv* env = JSC::Bindings::getJNIEnv();
- AutoJObject obj = m_javaGlue->object(env);
- // if it is called during DESTROY is handled, the real object of WebViewCore
- // can be gone. Check before using it.
- if (!obj.get())
- return;
- env->CallVoidMethod(obj.get(), m_javaGlue->m_didFirstLayout,
+ env->CallVoidMethod(m_javaGlue->object(env).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
// redirected to www.yahoo.com/?rs=1 on load.
|| loadType == WebCore::FrameLoadTypeRedirectWithLockedBackForwardList);
checkException(env);
+
DBG_NAV_LOG("call updateFrameCache");
m_check_domtree_version = false;
updateFrameCache();
@@ -993,12 +970,7 @@ void WebViewCore::updateViewport()
LOG_ASSERT(m_javaGlue->m_obj, "A Java widget was not associated with this view bridge!");
JNIEnv* env = JSC::Bindings::getJNIEnv();
- AutoJObject obj = m_javaGlue->object(env);
- // if it is called during DESTROY is handled, the real object of WebViewCore
- // can be gone. Check before using it.
- if (!obj.get())
- return;
- env->CallVoidMethod(obj.get(), m_javaGlue->m_updateViewport);
+ env->CallVoidMethod(m_javaGlue->object(env).get(), m_javaGlue->m_updateViewport);
checkException(env);
}
@@ -1008,12 +980,7 @@ void WebViewCore::restoreScale(int scale)
LOG_ASSERT(m_javaGlue->m_obj, "A Java widget was not associated with this view bridge!");
JNIEnv* env = JSC::Bindings::getJNIEnv();
- AutoJObject obj = m_javaGlue->object(env);
- // if it is called during DESTROY is handled, the real object of WebViewCore
- // can be gone. Check before using it.
- if (!obj.get())
- return;
- env->CallVoidMethod(obj.get(), m_javaGlue->m_restoreScale, scale);
+ env->CallVoidMethod(m_javaGlue->object(env).get(), m_javaGlue->m_restoreScale, scale);
checkException(env);
}
@@ -1023,29 +990,33 @@ void WebViewCore::restoreScreenWidthScale(int scale)
LOG_ASSERT(m_javaGlue->m_obj, "A Java widget was not associated with this view bridge!");
JNIEnv* env = JSC::Bindings::getJNIEnv();
- AutoJObject obj = m_javaGlue->object(env);
- // if it is called during DESTROY is handled, the real object of WebViewCore
- // can be gone. Check before using it.
- if (!obj.get())
- return;
- env->CallVoidMethod(obj.get(), m_javaGlue->m_restoreScreenWidthScale, scale);
+ env->CallVoidMethod(m_javaGlue->object(env).get(),
+ m_javaGlue->m_restoreScreenWidthScale, scale);
checkException(env);
}
-void WebViewCore::needTouchEvents(bool need)
+void WebViewCore::needTouchEvents(bool need, bool force)
{
DEBUG_NAV_UI_LOGD("%s", __FUNCTION__);
LOG_ASSERT(m_javaGlue->m_obj, "A Java widget was not associated with this view bridge!");
#if ENABLE(TOUCH_EVENTS) // Android
- JNIEnv* env = JSC::Bindings::getJNIEnv();
- AutoJObject obj = m_javaGlue->object(env);
- // if it is called during DESTROY is handled, the real object of WebViewCore
- // can be gone. Check before using it.
- if (!obj.get())
- return;
- env->CallVoidMethod(obj.get(), m_javaGlue->m_needTouchEvents, need);
- checkException(env);
+ bool needToUpdateJava = false;
+ if (need) {
+ if (++m_touchEventListenerCount == 1)
+ needToUpdateJava = true;
+ } else {
+ if (force)
+ m_touchEventListenerCount = 0;
+ else if (--m_touchEventListenerCount == 0)
+ needToUpdateJava = true;
+ }
+
+ if (needToUpdateJava || force) {
+ JNIEnv* env = JSC::Bindings::getJNIEnv();
+ env->CallVoidMethod(m_javaGlue->object(env).get(), m_javaGlue->m_needTouchEvents, need);
+ checkException(env);
+ }
#endif
}
@@ -1055,12 +1026,7 @@ void WebViewCore::requestKeyboard(bool showKeyboard, bool isTextView)
LOG_ASSERT(m_javaGlue->m_obj, "A Java widget was not associated with this view bridge!");
JNIEnv* env = JSC::Bindings::getJNIEnv();
- AutoJObject obj = m_javaGlue->object(env);
- // if it is called during DESTROY is handled, the real object of WebViewCore
- // can be gone. Check before using it.
- if (!obj.get())
- return;
- env->CallVoidMethod(obj.get(), m_javaGlue->m_requestKeyboard, showKeyboard,
+ env->CallVoidMethod(m_javaGlue->object(env).get(), m_javaGlue->m_requestKeyboard, showKeyboard,
isTextView);
checkException(env);
}
@@ -1588,209 +1554,6 @@ void WebViewCore::moveMouse(WebCore::Frame* frame, int x, int y)
updateCacheOnNodeChange();
}
-static int findTextBoxIndex(WebCore::Node* node, const WebCore::IntPoint& pt)
-{
- if (!node->isTextNode()) {
- DBG_NAV_LOGD("node=%p pt=(%d,%d) isText=false", node, pt.x(), pt.y());
- return -2; // error
- }
- WebCore::RenderText* renderText = (WebCore::RenderText*) node->renderer();
- if (!renderText) {
- DBG_NAV_LOGD("node=%p pt=(%d,%d) renderText=0", node, pt.x(), pt.y());
- return -3; // error
- }
- FloatPoint absPt = renderText->localToAbsolute();
- WebCore::InlineTextBox *textBox = renderText->firstTextBox();
- int globalX, globalY;
- CacheBuilder::GetGlobalOffset(node, &globalX, &globalY);
- int x = pt.x() - globalX;
- int y = pt.y() - globalY;
- do {
- int textBoxStart = textBox->start();
- int textBoxEnd = textBoxStart + textBox->len();
- if (textBoxEnd <= textBoxStart) {
- DBG_NAV_LOGD("textBoxStart=%d <= textBoxEnd=%d", textBoxStart,
- textBoxEnd);
- continue;
- }
- WebCore::IntRect bounds = textBox->selectionRect(absPt.x(), absPt.y(),
- textBoxStart, textBoxEnd);
- if (!bounds.contains(x, y)) {
- DBG_NAV_LOGD("[absPt=(%g,%g) textBoxStart=%d textBoxEnd=%d]"
- " !contains (x=%d, y=%d)",
- absPt.x(), absPt.y(), textBoxStart, textBoxEnd, x, y);
- continue;
- }
- int offset = textBox->offsetForPosition(x - absPt.x());
-#if DEBUG_NAV_UI
- int prior = offset > 0 ? textBox->positionForOffset(offset - 1) : -1;
- int current = textBox->positionForOffset(offset);
- int next = textBox->positionForOffset(offset + 1);
- DBG_NAV_LOGD("offset=%d pt.x=%d globalX=%d renderX=%g x=%d "
- "textBox->x()=%d textBox->start()=%d prior=%d current=%d next=%d",
- offset, pt.x(), globalX, absPt.x(), x,
- textBox->x(), textBox->start(), prior, current, next
- );
-#endif
- return textBox->start() + offset;
- } while ((textBox = textBox->nextTextBox()));
- return -1; // couldn't find point, may have walked off end
-}
-
-static inline bool isPunctuation(UChar c)
-{
- return WTF::Unicode::category(c) & (0
- | WTF::Unicode::Punctuation_Dash
- | WTF::Unicode::Punctuation_Open
- | WTF::Unicode::Punctuation_Close
- | WTF::Unicode::Punctuation_Connector
- | WTF::Unicode::Punctuation_Other
- | WTF::Unicode::Punctuation_InitialQuote
- | WTF::Unicode::Punctuation_FinalQuote
- );
-}
-
-static int centerX(const SkIRect& rect)
-{
- return (rect.fLeft + rect.fRight) >> 1;
-}
-
-static int centerY(const SkIRect& rect)
-{
- return (rect.fTop + rect.fBottom) >> 1;
-}
-
-static void ShowNode(Node* node)
-{
-#if DEBUG_NAV_UI
- WebCore::Node* match = node->document();
- int index = 1;
- while (match != node && (match = match->traverseNextNode()))
- index++;
- if (match != node)
- index = -1;
- const char* name = "text";
- WebCore::CString cstr;
- if (!node->isTextNode()) {
- cstr = node->localName().string().utf8();
- name = cstr.data();
- }
- node->getRect();
- const WebCore::IntRect& b = node->getRect();
- DBG_NAV_LOGD("%s %p (%d) (%d,%d,w=%d,h=%d)", name, node, index,
- b.x(), b.y(), b.width(), b.height());
-#endif
-}
-
-static WebCore::Node* ChildIsTextNode(WebCore::Node* node)
-{
- WebCore::Node* child = node;
- while (child && !child->isTextNode()) {
- ShowNode(child);
- child = child->traverseNextNode(node);
- }
- return child;
-}
-
-WebCore::String WebViewCore::getSelection(SkRegion* selRgn)
-{
- SkRegion::Iterator iter(*selRgn);
- // FIXME: switch this to use StringBuilder instead
- WebCore::String result;
- WebCore::Node* lastStartNode = 0;
- int lastStartEnd = -1;
- UChar lastChar = 0xffff;
- for (; !iter.done(); iter.next()) {
- const SkIRect& rect = iter.rect();
- DBG_NAV_LOGD("rect=(%d, %d, %d, %d)", rect.fLeft, rect.fTop,
- rect.fRight, rect.fBottom);
- int cy = centerY(rect);
- WebCore::IntPoint startPt, endPt;
- WebCore::Node* node, * endNode;
- for (int top = rect.fTop + 2; top != cy; top = cy) {
- startPt = WebCore::IntPoint(rect.fLeft + 1, top);
- WebCore::HitTestResult hitTestResult = m_mainFrame->eventHandler()->
- hitTestResultAtPoint(startPt, false);
- node = ChildIsTextNode(hitTestResult.innerNode());
- if (node)
- break;
- DBG_NAV_LOGD("node=%p (%s)", node, top != cy ? "top+1" : "cy");
- }
- if (!node) {
- DBG_NAV_LOG("!node");
- return result;
- }
- for (int bottom = rect.fBottom - 1; bottom != cy; bottom = cy) {
- for (int right = rect.fRight - 1; right != rect.fRight-2; --right) {
- endPt = WebCore::IntPoint(right, bottom);
- WebCore::HitTestResult hitTestResult = m_mainFrame->
- eventHandler()->hitTestResultAtPoint(endPt, false);
- endNode = ChildIsTextNode(hitTestResult.innerNode());
- if (endNode)
- break;
- DBG_NAV_LOGD("!endNode=%p (%s) (right-%d)", node,
- bottom != cy ? "bottom-1" : "cy", rect.fRight - right);
- }
- }
- if (!endNode) {
- DBG_NAV_LOG("!endNode");
- return result;
- }
- int start = findTextBoxIndex(node, startPt);
- if (start < 0)
- continue;
- int end = findTextBoxIndex(endNode, endPt);
- if (end < -1) // use node if endNode is not valid
- endNode = node;
- if (end <= 0)
- end = static_cast<WebCore::Text*>(endNode)->dataImpl()->length();
- DBG_NAV_LOGD("node=%p start=%d endNode=%p end=%d", node, start, endNode, end);
- WebCore::Node* startNode = node;
- do {
- if (!node->isTextNode())
- continue;
- if (node->getRect().isEmpty())
- continue;
- WebCore::Text* textNode = static_cast<WebCore::Text*>(node);
- WebCore::StringImpl* string = textNode->dataImpl();
- if (!string->length())
- continue;
- const UChar* chars = string->characters();
- int newLength = node == endNode ? end : string->length();
- if (node == startNode) {
- #if DEBUG_NAV_UI
- if (node == lastStartNode)
- DBG_NAV_LOGD("start=%d last=%d", start, lastStartEnd);
- #endif
- if (node == lastStartNode && start < lastStartEnd)
- break; // skip rect if text overlaps already written text
- lastStartNode = node;
- lastStartEnd = newLength - start;
- }
- if (newLength < start) {
- DBG_NAV_LOGD("newLen=%d < start=%d", newLength, start);
- break;
- }
- if (!isPunctuation(chars[start]))
- result.append(' ');
- result.append(chars + start, newLength - start);
- start = 0;
- } while (node != endNode && (node = node->traverseNextNode()));
- }
- result = result.simplifyWhiteSpace().stripWhiteSpace();
-#if DUMP_NAV_CACHE
- {
- char buffer[256];
- CacheBuilder::Debug debug;
- debug.init(buffer, sizeof(buffer));
- debug.print("copy: ");
- debug.wideString(result);
- DUMP_NAV_LOGD("%s", buffer);
- }
-#endif
- return result;
-}
-
void WebViewCore::setSelection(int start, int end)
{
WebCore::Node* focus = currentFocus();
@@ -2072,11 +1835,6 @@ void WebViewCore::listBoxRequest(WebCoreReply* reply, const uint16_t** labels, s
// Create an array of java Strings for the drop down.
JNIEnv* env = JSC::Bindings::getJNIEnv();
- AutoJObject obj = m_javaGlue->object(env);
- // if it is called during DESTROY is handled, the real object of WebViewCore
- // can be gone. Check before using it.
- if (!obj.get())
- return;
jobjectArray labelArray = makeLabelArray(env, labels, count);
// Create an array determining whether each item is enabled.
@@ -2101,11 +1859,15 @@ void WebViewCore::listBoxRequest(WebCoreReply* reply, const uint16_t** labels, s
}
env->ReleaseIntArrayElements(selectedArray, selArray, 0);
- env->CallVoidMethod(obj.get(), m_javaGlue->m_requestListBox, labelArray, enabledArray, selectedArray);
+ env->CallVoidMethod(m_javaGlue->object(env).get(),
+ m_javaGlue->m_requestListBox, labelArray, enabledArray,
+ selectedArray);
env->DeleteLocalRef(selectedArray);
} else {
// Pass up the single selection.
- env->CallVoidMethod(obj.get(), m_javaGlue->m_requestSingleListBox, labelArray, enabledArray, selectedCountOrSelection);
+ env->CallVoidMethod(m_javaGlue->object(env).get(),
+ m_javaGlue->m_requestSingleListBox, labelArray, enabledArray,
+ selectedCountOrSelection);
}
env->DeleteLocalRef(labelArray);
@@ -2165,29 +1927,47 @@ int WebViewCore::handleTouchEvent(int action, int x, int y)
#endif
#if ENABLE(TOUCH_EVENTS) // Android
- WebCore::TouchEventType type = WebCore::TouchEventCancel;
+ WebCore::TouchEventType type = WebCore::TouchStart;
+ WebCore::PlatformTouchPoint::State touchState = WebCore::PlatformTouchPoint::TouchPressed;
switch (action) {
case 0: // MotionEvent.ACTION_DOWN
- type = WebCore::TouchEventStart;
+ type = WebCore::TouchStart;
break;
case 1: // MotionEvent.ACTION_UP
- type = WebCore::TouchEventEnd;
+ type = WebCore::TouchEnd;
+ touchState = WebCore::PlatformTouchPoint::TouchReleased;
break;
case 2: // MotionEvent.ACTION_MOVE
- type = WebCore::TouchEventMove;
+ type = WebCore::TouchMove;
+ touchState = WebCore::PlatformTouchPoint::TouchMoved;
break;
case 3: // MotionEvent.ACTION_CANCEL
- type = WebCore::TouchEventCancel;
+ type = WebCore::TouchCancel;
+ touchState = WebCore::PlatformTouchPoint::TouchCancelled;
break;
case 0x100: // WebViewCore.ACTION_LONGPRESS
- type = WebCore::TouchEventLongPress;
+ type = WebCore::TouchLongPress;
+ touchState = WebCore::PlatformTouchPoint::TouchPressed;
break;
case 0x200: // WebViewCore.ACTION_DOUBLETAP
- type = WebCore::TouchEventDoubleTap;
+ type = WebCore::TouchDoubleTap;
+ touchState = WebCore::PlatformTouchPoint::TouchPressed;
+ break;
+ default:
+ type = WebCore::TouchCancel;
+ touchState = WebCore::PlatformTouchPoint::TouchCancelled;
break;
}
+
+ // Track previous touch and if stationary set the state.
WebCore::IntPoint pt(x - m_scrollOffsetX, y - m_scrollOffsetY);
- WebCore::PlatformTouchEvent te(pt, pt, type);
+
+ if (type == WebCore::TouchMove && pt == m_lastTouchPoint)
+ touchState = WebCore::PlatformTouchPoint::TouchStationary;
+
+ m_lastTouchPoint = pt;
+
+ WebCore::PlatformTouchEvent te(pt, pt, type, touchState);
preventDefault = m_mainFrame->eventHandler()->handleTouchEvent(te);
#endif
@@ -2325,14 +2105,11 @@ void WebViewCore::popupReply(const int* array, int count)
void WebViewCore::addMessageToConsole(const WebCore::String& message, unsigned int lineNumber, const WebCore::String& sourceID) {
JNIEnv* env = JSC::Bindings::getJNIEnv();
- AutoJObject obj = m_javaGlue->object(env);
- // if it is called during DESTROY is handled, the real object of WebViewCore
- // can be gone. Check before using it.
- if (!obj.get())
- return;
jstring jMessageStr = env->NewString((unsigned short *)message.characters(), message.length());
jstring jSourceIDStr = env->NewString((unsigned short *)sourceID.characters(), sourceID.length());
- env->CallVoidMethod(obj.get(), m_javaGlue->m_addMessageToConsole, jMessageStr, lineNumber, jSourceIDStr);
+ env->CallVoidMethod(m_javaGlue->object(env).get(),
+ m_javaGlue->m_addMessageToConsole, jMessageStr, lineNumber,
+ jSourceIDStr);
env->DeleteLocalRef(jMessageStr);
env->DeleteLocalRef(jSourceIDStr);
checkException(env);
@@ -2341,14 +2118,9 @@ void WebViewCore::addMessageToConsole(const WebCore::String& message, unsigned i
void WebViewCore::jsAlert(const WebCore::String& url, const WebCore::String& text)
{
JNIEnv* env = JSC::Bindings::getJNIEnv();
- AutoJObject obj = m_javaGlue->object(env);
- // if it is called during DESTROY is handled, the real object of WebViewCore
- // can be gone. Check before using it.
- if (!obj.get())
- return;
jstring jInputStr = env->NewString((unsigned short *)text.characters(), text.length());
jstring jUrlStr = env->NewString((unsigned short *)url.characters(), url.length());
- env->CallVoidMethod(obj.get(), m_javaGlue->m_jsAlert, jUrlStr, jInputStr);
+ env->CallVoidMethod(m_javaGlue->object(env).get(), m_javaGlue->m_jsAlert, jUrlStr, jInputStr);
env->DeleteLocalRef(jInputStr);
env->DeleteLocalRef(jUrlStr);
checkException(env);
@@ -2358,14 +2130,11 @@ void WebViewCore::exceededDatabaseQuota(const WebCore::String& url, const WebCor
{
#if ENABLE(DATABASE)
JNIEnv* env = JSC::Bindings::getJNIEnv();
- AutoJObject obj = m_javaGlue->object(env);
- // if it is called during DESTROY is handled, the real object of WebViewCore
- // can be gone. Check before using it.
- if (!obj.get())
- return;
jstring jDatabaseIdentifierStr = env->NewString((unsigned short *)databaseIdentifier.characters(), databaseIdentifier.length());
jstring jUrlStr = env->NewString((unsigned short *)url.characters(), url.length());
- env->CallVoidMethod(obj.get(), m_javaGlue->m_exceededDatabaseQuota, jUrlStr, jDatabaseIdentifierStr, currentQuota, estimatedSize);
+ env->CallVoidMethod(m_javaGlue->object(env).get(),
+ m_javaGlue->m_exceededDatabaseQuota, jUrlStr,
+ jDatabaseIdentifierStr, currentQuota, estimatedSize);
env->DeleteLocalRef(jDatabaseIdentifierStr);
env->DeleteLocalRef(jUrlStr);
checkException(env);
@@ -2376,12 +2145,8 @@ void WebViewCore::reachedMaxAppCacheSize(const unsigned long long spaceNeeded)
{
#if ENABLE(OFFLINE_WEB_APPLICATIONS)
JNIEnv* env = JSC::Bindings::getJNIEnv();
- AutoJObject obj = m_javaGlue->object(env);
- // if it is called during DESTROY is handled, the real object of WebViewCore
- // can be gone. Check before using it.
- if (!obj.get())
- return;
- env->CallVoidMethod(obj.get(), m_javaGlue->m_reachedMaxAppCacheSize, spaceNeeded);
+ env->CallVoidMethod(m_javaGlue->object(env).get(),
+ m_javaGlue->m_reachedMaxAppCacheSize, spaceNeeded);
checkException(env);
#endif
}
@@ -2390,25 +2155,15 @@ void WebViewCore::populateVisitedLinks(WebCore::PageGroup* group)
{
m_groupForVisitedLinks = group;
JNIEnv* env = JSC::Bindings::getJNIEnv();
- AutoJObject obj = m_javaGlue->object(env);
- // if it is called during DESTROY is handled, the real object of WebViewCore
- // can be gone. Check before using it.
- if (!obj.get())
- return;
- env->CallVoidMethod(obj.get(), m_javaGlue->m_populateVisitedLinks);
+ 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();
- AutoJObject obj = m_javaGlue->object(env);
- // if it is called during DESTROY is handled, the real object of WebViewCore
- // can be gone. Check before using it.
- if (!obj.get())
- return;
jstring originString = env->NewString((unsigned short *)origin.characters(), origin.length());
- env->CallVoidMethod(obj.get(),
+ env->CallVoidMethod(m_javaGlue->object(env).get(),
m_javaGlue->m_geolocationPermissionsShowPrompt,
originString);
env->DeleteLocalRef(originString);
@@ -2418,12 +2173,7 @@ void WebViewCore::geolocationPermissionsShowPrompt(const WebCore::String& origin
void WebViewCore::geolocationPermissionsHidePrompt()
{
JNIEnv* env = JSC::Bindings::getJNIEnv();
- AutoJObject obj = m_javaGlue->object(env);
- // if it is called during DESTROY is handled, the real object of WebViewCore
- // can be gone. Check before using it.
- if (!obj.get())
- return;
- env->CallVoidMethod(obj.get(),
+ env->CallVoidMethod(m_javaGlue->object(env).get(),
m_javaGlue->m_geolocationPermissionsHidePrompt);
checkException(env);
}
@@ -2431,14 +2181,9 @@ void WebViewCore::geolocationPermissionsHidePrompt()
bool WebViewCore::jsConfirm(const WebCore::String& url, const WebCore::String& text)
{
JNIEnv* env = JSC::Bindings::getJNIEnv();
- AutoJObject obj = m_javaGlue->object(env);
- // if it is called during DESTROY is handled, the real object of WebViewCore
- // can be gone. Check before using it.
- if (!obj.get())
- return false;
jstring jInputStr = env->NewString((unsigned short *)text.characters(), text.length());
jstring jUrlStr = env->NewString((unsigned short *)url.characters(), url.length());
- jboolean result = env->CallBooleanMethod(obj.get(), m_javaGlue->m_jsConfirm, jUrlStr, jInputStr);
+ jboolean result = env->CallBooleanMethod(m_javaGlue->object(env).get(), m_javaGlue->m_jsConfirm, jUrlStr, jInputStr);
env->DeleteLocalRef(jInputStr);
env->DeleteLocalRef(jUrlStr);
checkException(env);
@@ -2448,16 +2193,10 @@ bool WebViewCore::jsConfirm(const WebCore::String& url, const WebCore::String& t
bool WebViewCore::jsPrompt(const WebCore::String& url, const WebCore::String& text, const WebCore::String& defaultValue, WebCore::String& result)
{
JNIEnv* env = JSC::Bindings::getJNIEnv();
- AutoJObject obj = m_javaGlue->object(env);
- // if it is called during DESTROY is handled, the real object of WebViewCore
- // can be gone. Check before using it.
- if (!obj.get())
- return false;
-
jstring jInputStr = env->NewString((unsigned short *)text.characters(), text.length());
jstring jDefaultStr = env->NewString((unsigned short *)defaultValue.characters(), defaultValue.length());
jstring jUrlStr = env->NewString((unsigned short *)url.characters(), url.length());
- jstring returnVal = (jstring) env->CallObjectMethod(obj.get(), m_javaGlue->m_jsPrompt, jUrlStr, jInputStr, jDefaultStr);
+ jstring returnVal = (jstring) env->CallObjectMethod(m_javaGlue->object(env).get(), m_javaGlue->m_jsPrompt, jUrlStr, jInputStr, jDefaultStr);
// If returnVal is null, it means that the user cancelled the dialog.
if (!returnVal)
return false;
@@ -2473,14 +2212,9 @@ bool WebViewCore::jsPrompt(const WebCore::String& url, const WebCore::String& te
bool WebViewCore::jsUnload(const WebCore::String& url, const WebCore::String& message)
{
JNIEnv* env = JSC::Bindings::getJNIEnv();
- AutoJObject obj = m_javaGlue->object(env);
- // if it is called during DESTROY is handled, the real object of WebViewCore
- // can be gone. Check before using it.
- if (!obj.get())
- return false;
jstring jInputStr = env->NewString((unsigned short *)message.characters(), message.length());
jstring jUrlStr = env->NewString((unsigned short *)url.characters(), url.length());
- jboolean result = env->CallBooleanMethod(obj.get(), m_javaGlue->m_jsUnload, jUrlStr, jInputStr);
+ jboolean result = env->CallBooleanMethod(m_javaGlue->object(env).get(), m_javaGlue->m_jsUnload, jUrlStr, jInputStr);
env->DeleteLocalRef(jInputStr);
env->DeleteLocalRef(jUrlStr);
checkException(env);
@@ -2490,12 +2224,7 @@ bool WebViewCore::jsUnload(const WebCore::String& url, const WebCore::String& me
bool WebViewCore::jsInterrupt()
{
JNIEnv* env = JSC::Bindings::getJNIEnv();
- AutoJObject obj = m_javaGlue->object(env);
- // if it is called during DESTROY is handled, the real object of WebViewCore
- // can be gone. Check before using it.
- if (!obj.get())
- return true; // default to interrupt
- jboolean result = env->CallBooleanMethod(obj.get(), m_javaGlue->m_jsInterrupt);
+ jboolean result = env->CallBooleanMethod(m_javaGlue->object(env).get(), m_javaGlue->m_jsInterrupt);
checkException(env);
return result;
}
@@ -2510,12 +2239,7 @@ jobject
WebViewCore::getWebViewJavaObject()
{
JNIEnv* env = JSC::Bindings::getJNIEnv();
- AutoJObject obj = m_javaGlue->object(env);
- // if it is called during DESTROY is handled, the real object of WebViewCore
- // can be gone. Check before using it.
- if (!obj.get())
- return 0;
- return env->GetObjectField(obj.get(), gWebViewCoreFields.m_webView);
+ return env->GetObjectField(m_javaGlue->object(env).get(), gWebViewCoreFields.m_webView);
}
void WebViewCore::updateTextSelection() {
@@ -2527,12 +2251,7 @@ void WebViewCore::updateTextSelection() {
return;
RenderTextControl* rtc = static_cast<RenderTextControl*>(renderer);
JNIEnv* env = JSC::Bindings::getJNIEnv();
- AutoJObject obj = m_javaGlue->object(env);
- // if it is called during DESTROY is handled, the real object of WebViewCore
- // can be gone. Check before using it.
- if (!obj.get())
- return;
- env->CallVoidMethod(obj.get(),
+ env->CallVoidMethod(m_javaGlue->object(env).get(),
m_javaGlue->m_updateTextSelection, reinterpret_cast<int>(focusNode),
rtc->selectionStart(), rtc->selectionEnd(), m_textGeneration);
checkException(env);
@@ -2544,21 +2263,15 @@ void WebViewCore::updateTextfield(WebCore::Node* ptr, bool changeToPassword,
if (m_blockTextfieldUpdates)
return;
JNIEnv* env = JSC::Bindings::getJNIEnv();
- AutoJObject obj = m_javaGlue->object(env);
- // if it is called during DESTROY is handled, the real object of WebViewCore
- // can be gone. Check before using it.
- if (!obj.get())
- return;
-
if (changeToPassword) {
- env->CallVoidMethod(obj.get(), m_javaGlue->m_updateTextfield,
+ env->CallVoidMethod(m_javaGlue->object(env).get(), m_javaGlue->m_updateTextfield,
(int) ptr, true, 0, m_textGeneration);
checkException(env);
return;
}
int length = text.length();
jstring string = env->NewString((unsigned short *) text.characters(), length);
- env->CallVoidMethod(obj.get(), m_javaGlue->m_updateTextfield,
+ env->CallVoidMethod(m_javaGlue->object(env).get(), m_javaGlue->m_updateTextfield,
(int) ptr, false, string, m_textGeneration);
env->DeleteLocalRef(string);
checkException(env);
@@ -2567,13 +2280,8 @@ void WebViewCore::updateTextfield(WebCore::Node* ptr, bool changeToPassword,
void WebViewCore::clearTextEntry()
{
JNIEnv* env = JSC::Bindings::getJNIEnv();
- AutoJObject obj = m_javaGlue->object(env);
- // if it is called during DESTROY is handled, the real object of WebViewCore
- // 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);
}
void WebViewCore::setBackgroundColor(SkColor c)
@@ -2591,11 +2299,10 @@ void WebViewCore::setBackgroundColor(SkColor c)
jclass WebViewCore::getPluginClass(const WebCore::String& libName, const char* className)
{
JNIEnv* env = JSC::Bindings::getJNIEnv();
- AutoJObject obj = m_javaGlue->object(env);
jstring libString = env->NewString(libName.characters(), libName.length());
jstring classString = env->NewStringUTF(className);
- jobject pluginClass = env->CallObjectMethod(obj.get(),
+ jobject pluginClass = env->CallObjectMethod(m_javaGlue->object(env).get(),
m_javaGlue->m_getPluginClass,
libString, classString);
checkException(env);
@@ -2626,18 +2333,16 @@ void WebViewCore::showFullScreenPlugin(jobject childView, NPP npp, int x,
void WebViewCore::hideFullScreenPlugin()
{
JNIEnv* env = JSC::Bindings::getJNIEnv();
- AutoJObject obj = m_javaGlue->object(env);
-
- env->CallVoidMethod(obj.get(), m_javaGlue->m_hideFullScreenPlugin);
+ env->CallVoidMethod(m_javaGlue->object(env).get(),
+ m_javaGlue->m_hideFullScreenPlugin);
checkException(env);
}
void WebViewCore::updateFullScreenPlugin(int x, int y, int width, int height)
{
JNIEnv* env = JSC::Bindings::getJNIEnv();
- AutoJObject obj = m_javaGlue->object(env);
-
- env->CallVoidMethod(obj.get(), m_javaGlue->m_updateFullScreenPlugin, x, y,
+ env->CallVoidMethod(m_javaGlue->object(env).get(),
+ m_javaGlue->m_updateFullScreenPlugin, x, y,
width, height);
checkException(env);
}
@@ -2645,9 +2350,7 @@ void WebViewCore::updateFullScreenPlugin(int x, int y, int width, int height)
jobject WebViewCore::addSurface(jobject view, int x, int y, int width, int height)
{
JNIEnv* env = JSC::Bindings::getJNIEnv();
- AutoJObject obj = m_javaGlue->object(env);
-
- jobject result = env->CallObjectMethod(obj.get(),
+ jobject result = env->CallObjectMethod(m_javaGlue->object(env).get(),
m_javaGlue->m_addSurface,
view, x, y, width, height);
checkException(env);
@@ -2657,19 +2360,16 @@ 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();
- AutoJObject obj = m_javaGlue->object(env);
-
- env->CallVoidMethod(obj.get(), m_javaGlue->m_updateSurface, childView, x,
- y, width, height);
+ env->CallVoidMethod(m_javaGlue->object(env).get(),
+ m_javaGlue->m_updateSurface, childView,
+ x, y, width, height);
checkException(env);
}
void WebViewCore::destroySurface(jobject childView)
{
JNIEnv* env = JSC::Bindings::getJNIEnv();
- AutoJObject obj = m_javaGlue->object(env);
-
- env->CallVoidMethod(obj.get(), m_javaGlue->m_destroySurface, childView);
+ env->CallVoidMethod(m_javaGlue->object(env).get(), m_javaGlue->m_destroySurface, childView);
checkException(env);
}
@@ -3100,20 +2800,6 @@ static void SetBackgroundColor(JNIEnv *env, jobject obj, jint color)
viewImpl->setBackgroundColor((SkColor) color);
}
-static jstring GetSelection(JNIEnv *env, jobject obj, jobject selRgn)
-{
-#ifdef ANDROID_INSTRUMENT
- TimeCounterAuto counter(TimeCounter::WebViewCoreTimeCounter);
-#endif
- WebViewCore* viewImpl = GET_NATIVE_VIEW(env, obj);
- LOG_ASSERT(viewImpl, "viewImpl not set in %s", __FUNCTION__);
- SkRegion* selectionRegion = GraphicsJNI::getNativeRegion(env, selRgn);
- WebCore::String result = viewImpl->getSelection(selectionRegion);
- if (!result.isEmpty())
- return WebCoreStringToJString(env, result);
- return 0;
-}
-
static void DumpDomTree(JNIEnv *env, jobject obj, jboolean useFile)
{
WebViewCore* viewImpl = GET_NATIVE_VIEW(env, obj);
@@ -3240,6 +2926,8 @@ static void Pause(JNIEnv* env, jobject obj)
SkANP::InitEvent(&event, kLifecycle_ANPEventType);
event.data.lifecycle.action = kPause_ANPLifecycleAction;
GET_NATIVE_VIEW(env, obj)->sendPluginEvent(event);
+
+ WebViewCore::setIsPaused(true);
}
static void Resume(JNIEnv* env, jobject obj)
@@ -3255,6 +2943,8 @@ static void Resume(JNIEnv* env, jobject obj)
SkANP::InitEvent(&event, kLifecycle_ANPEventType);
event.data.lifecycle.action = kResume_ANPLifecycleAction;
GET_NATIVE_VIEW(env, obj)->sendPluginEvent(event);
+
+ WebViewCore::setIsPaused(false);
}
static void FreeMemory(JNIEnv* env, jobject obj)
@@ -3281,7 +2971,6 @@ static void ProvideVisitedHistory(JNIEnv *env, jobject obj, jobject hist)
env->ReleaseStringChars(item, str);
env->DeleteLocalRef(item);
}
- env->DeleteLocalRef(array);
}
// Notification from the UI thread that the plugin's full-screen surface has been discarded
@@ -3380,8 +3069,6 @@ static JNINativeMethod gJavaWebViewCoreMethods[] = {
(void*) SplitContent },
{ "nativeSetBackgroundColor", "(I)V",
(void*) SetBackgroundColor },
- { "nativeGetSelection", "(Landroid/graphics/Region;)Ljava/lang/String;",
- (void*) GetSelection },
{ "nativeRegisterURLSchemeAsLocal", "(Ljava/lang/String;)V",
(void*) RegisterURLSchemeAsLocal },
{ "nativeDumpDomTree", "(Z)V",