summaryrefslogtreecommitdiffstats
path: root/WebKit/android/jni/WebCoreFrameBridge.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'WebKit/android/jni/WebCoreFrameBridge.cpp')
-rw-r--r--WebKit/android/jni/WebCoreFrameBridge.cpp300
1 files changed, 156 insertions, 144 deletions
diff --git a/WebKit/android/jni/WebCoreFrameBridge.cpp b/WebKit/android/jni/WebCoreFrameBridge.cpp
index 567fb6f..afabde8 100644
--- a/WebKit/android/jni/WebCoreFrameBridge.cpp
+++ b/WebKit/android/jni/WebCoreFrameBridge.cpp
@@ -25,18 +25,17 @@
#define LOG_TAG "webcoreglue"
-#include <config.h>
-
-#include <wtf/Platform.h>
-#include <wtf/CurrentTime.h>
+#include "config.h"
+#include "WebCoreFrameBridge.h"
-#include "android_graphics.h"
#include "Arena.h"
#include "AtomicString.h"
+#include "BackForwardList.h"
#include "Cache.h"
+#include "CString.h"
+#include "Chrome.h"
#include "ChromeClientAndroid.h"
#include "ContextMenuClientAndroid.h"
-#include "CString.h"
#include "Document.h"
#include "DocumentLoader.h"
#include "DragClientAndroid.h"
@@ -60,16 +59,6 @@
#include "IconDatabase.h"
#include "Image.h"
#include "InspectorClientAndroid.h"
-
-#if USE(JSC)
-#include "GCController.h"
-#include "JSDOMWindow.h"
-#include <runtime/JSLock.h>
-#elif USE(V8)
-#include "jni_npobject.h"
-#include "jni_instance.h"
-#endif // USE(JSC)
-
#include "KURL.h"
#include "Page.h"
#include "PageCache.h"
@@ -85,32 +74,37 @@
#include "SelectionController.h"
#include "Settings.h"
#include "SubstituteData.h"
-#include "WebCoreFrameBridge.h"
#include "WebCoreJni.h"
#include "WebCoreResourceLoader.h"
#include "WebHistory.h"
#include "WebIconDatabase.h"
#include "WebFrameView.h"
#include "WebViewCore.h"
-#include "wds/DebugServer.h"
-
-#if USE(JSC)
-#include <runtime_root.h>
-#include <runtime_object.h>
-#endif // USE(JSC)
-
-#include <jni_utility.h>
+#include "android_graphics.h"
#include "jni.h"
+#include "wds/DebugServer.h"
-#if USE(JSC)
-#include "JavaInstanceJSC.h"
-#endif // USE(JSC)
-
+#include <JNIUtility.h>
#include <JNIHelp.h>
#include <SkGraphics.h>
+#include <android_runtime/android_util_AssetManager.h>
#include <utils/misc.h>
#include <utils/AssetManager.h>
-#include <android_runtime/android_util_AssetManager.h>
+#include <wtf/CurrentTime.h>
+#include <wtf/Platform.h>
+
+#if USE(JSC)
+#include "GCController.h"
+#include "JSDOMWindow.h"
+#include "JavaInstanceJSC.h"
+#include <runtime_object.h>
+#include <runtime_root.h>
+#include <runtime/JSLock.h>
+#elif USE(V8)
+#include "JavaNPObjectV8.h"
+#include "JavaInstanceV8.h"
+#include "V8Counters.h"
+#endif // USE(JSC)
#ifdef ANDROID_INSTRUMENT
#include "TimeCounter.h"
@@ -171,8 +165,8 @@ namespace android {
struct WebFrame::JavaBrowserFrame
{
- jobject mObj;
- jobject mHistoryList; // WebBackForwardList object
+ jweak mObj;
+ jweak mHistoryList; // WebBackForwardList object
jmethodID mStartLoadingResource;
jmethodID mLoadStarted;
jmethodID mTransitionToCommitted;
@@ -212,8 +206,8 @@ WebFrame::WebFrame(JNIEnv* env, jobject obj, jobject historyList, WebCore::Page*
{
jclass clazz = env->GetObjectClass(obj);
mJavaFrame = new JavaBrowserFrame;
- mJavaFrame->mObj = adoptGlobalRef(env, obj);
- mJavaFrame->mHistoryList = adoptGlobalRef(env, historyList);
+ mJavaFrame->mObj = env->NewWeakGlobalRef(obj);
+ mJavaFrame->mHistoryList = env->NewWeakGlobalRef(historyList);
mJavaFrame->mStartLoadingResource = env->GetMethodID(clazz, "startLoadingResource",
"(ILjava/lang/String;Ljava/lang/String;Ljava/util/HashMap;[BJIZZZ)Landroid/webkit/LoadListener;");
mJavaFrame->mLoadStarted = env->GetMethodID(clazz, "loadStarted",
@@ -281,8 +275,8 @@ WebFrame::~WebFrame()
{
if (mJavaFrame->mObj) {
JNIEnv* env = getJNIEnv();
- env->DeleteGlobalRef(mJavaFrame->mObj);
- env->DeleteGlobalRef(mJavaFrame->mHistoryList);
+ env->DeleteWeakGlobalRef(mJavaFrame->mObj);
+ env->DeleteWeakGlobalRef(mJavaFrame->mHistoryList);
mJavaFrame->mObj = 0;
}
delete mJavaFrame;
@@ -381,10 +375,6 @@ WebFrame::startLoadingResource(WebCore::ResourceHandle* loader,
WebCore::HTTPHeaderMap headers = request.httpHeaderFields();
JNIEnv* env = getJNIEnv();
- AutoJObject obj = mJavaFrame->frame(env);
- if (!obj.get())
- return 0;
-
WebCore::String urlStr = request.url().string();
int colon = urlStr.find(':');
bool allLower = true;
@@ -405,6 +395,7 @@ WebFrame::startLoadingResource(WebCore::ResourceHandle* loader,
jMethodStr = env->NewString(method.characters(), method.length());
jbyteArray jPostDataStr = NULL;
WebCore::FormData* formdata = request.httpBody();
+ AutoJObject obj = mJavaFrame->frame(env);
if (formdata) {
// We can use the formdata->flatten() but it will result in two
// memcpys, first through loading up the vector with the form data
@@ -487,10 +478,10 @@ WebFrame::startLoadingResource(WebCore::ResourceHandle* loader,
jobject jLoadListener =
env->CallObjectMethod(obj.get(), mJavaFrame->mStartLoadingResource,
- (int)loader, jUrlStr, jMethodStr, jHeaderMap,
- jPostDataStr, formdata ? formdata->identifier(): 0,
- cacheMode, mainResource, request.getUserGesture(),
- synchronous);
+ (int)loader, jUrlStr, jMethodStr, jHeaderMap,
+ jPostDataStr, formdata ? formdata->identifier(): 0,
+ cacheMode, mainResource, request.getUserGesture(),
+ synchronous);
env->DeleteLocalRef(jUrlStr);
env->DeleteLocalRef(jMethodStr);
@@ -515,13 +506,11 @@ WebFrame::reportError(int errorCode, const WebCore::String& description,
#endif
LOGV("::WebCore:: reportError(%d, %s)", errorCode, description.ascii().data());
JNIEnv* env = getJNIEnv();
- AutoJObject obj = mJavaFrame->frame(env);
- if (!obj.get())
- return;
jstring descStr = env->NewString((unsigned short*)description.characters(), description.length());
jstring failUrl = env->NewString((unsigned short*)failingUrl.characters(), failingUrl.length());
- env->CallVoidMethod(obj.get(), mJavaFrame->mReportError, errorCode, descStr, failUrl);
+ env->CallVoidMethod(mJavaFrame->frame(env).get(), mJavaFrame->mReportError,
+ errorCode, descStr, failUrl);
env->DeleteLocalRef(descStr);
env->DeleteLocalRef(failUrl);
}
@@ -547,9 +536,6 @@ WebFrame::loadStarted(WebCore::Frame* frame)
return;
JNIEnv* env = getJNIEnv();
- AutoJObject obj = mJavaFrame->frame(env);
- if (!obj.get())
- return;
WebCore::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.
@@ -562,7 +548,7 @@ WebFrame::loadStarted(WebCore::Frame* frame)
}
jstring urlStr = env->NewString((unsigned short*)urlString.characters(), urlString.length());
- env->CallVoidMethod(obj.get(), mJavaFrame->mLoadStarted, urlStr, favicon,
+ env->CallVoidMethod(mJavaFrame->frame(env).get(), mJavaFrame->mLoadStarted, urlStr, favicon,
(int)loadType, isMainFrame);
checkException(env);
env->DeleteLocalRef(urlStr);
@@ -587,12 +573,9 @@ WebFrame::transitionToCommitted(WebCore::Frame* frame)
TimeCounterAuto counter(TimeCounter::JavaCallbackTimeCounter);
#endif
JNIEnv* env = getJNIEnv();
- AutoJObject obj = mJavaFrame->frame(env);
- if (!obj.get())
- return;
WebCore::FrameLoadType loadType = frame->loader()->loadType();
bool isMainFrame = (!frame->tree() || !frame->tree()->parent());
- env->CallVoidMethod(obj.get(), mJavaFrame->mTransitionToCommitted,
+ env->CallVoidMethod(mJavaFrame->frame(env).get(), mJavaFrame->mTransitionToCommitted,
(int)loadType, isMainFrame);
checkException(env);
}
@@ -604,9 +587,6 @@ WebFrame::didFinishLoad(WebCore::Frame* frame)
TimeCounterAuto counter(TimeCounter::JavaCallbackTimeCounter);
#endif
JNIEnv* env = getJNIEnv();
- AutoJObject obj = mJavaFrame->frame(env);
- if (!obj.get())
- return;
WebCore::FrameLoader* loader = frame->loader();
const WebCore::KURL& url = loader->activeDocumentLoader()->url();
if (url.isEmpty())
@@ -617,7 +597,7 @@ WebFrame::didFinishLoad(WebCore::Frame* frame)
WebCore::FrameLoadType loadType = loader->loadType();
WebCore::String urlString(url.string());
jstring urlStr = env->NewString((unsigned short*)urlString.characters(), urlString.length());
- env->CallVoidMethod(obj.get(), mJavaFrame->mLoadFinished, urlStr,
+ env->CallVoidMethod(mJavaFrame->frame(env).get(), mJavaFrame->mLoadFinished, urlStr,
(int)loadType, isMainFrame);
checkException(env);
env->DeleteLocalRef(urlStr);
@@ -666,12 +646,9 @@ WebFrame::setTitle(const WebCore::String& title)
LOGV("setTitle(%s)", title.ascii().data());
#endif
JNIEnv* env = getJNIEnv();
- AutoJObject obj = mJavaFrame->frame(env);
- if (!obj.get())
- return;
jstring jTitleStr = env->NewString((unsigned short *)title.characters(), title.length());
- env->CallVoidMethod(obj.get(), mJavaFrame->mSetTitle,
+ env->CallVoidMethod(mJavaFrame->frame(env).get(), mJavaFrame->mSetTitle,
jTitleStr);
checkException(env);
env->DeleteLocalRef(jTitleStr);
@@ -685,11 +662,8 @@ WebFrame::windowObjectCleared(WebCore::Frame* frame)
#endif
LOGV("::WebCore:: windowObjectCleared");
JNIEnv* env = getJNIEnv();
- AutoJObject obj = mJavaFrame->frame(env);
- if (!obj.get())
- return;
- env->CallVoidMethod(obj.get(), mJavaFrame->mWindowObjectCleared, (int)frame);
+ env->CallVoidMethod(mJavaFrame->frame(env).get(), mJavaFrame->mWindowObjectCleared, (int)frame);
checkException(env);
}
@@ -700,11 +674,8 @@ WebFrame::setProgress(float newProgress)
TimeCounterAuto counter(TimeCounter::JavaCallbackTimeCounter);
#endif
JNIEnv* env = getJNIEnv();
- AutoJObject obj = mJavaFrame->frame(env);
- if (!obj.get())
- return;
int progress = (int) (100 * newProgress);
- env->CallVoidMethod(obj.get(), mJavaFrame->mSetProgress, progress);
+ env->CallVoidMethod(mJavaFrame->frame(env).get(), mJavaFrame->mSetProgress, progress);
checkException(env);
}
@@ -722,14 +693,11 @@ WebFrame::didReceiveIcon(WebCore::Image* icon)
#endif
LOG_ASSERT(icon, "DidReceiveIcon called without an image!");
JNIEnv* env = getJNIEnv();
- AutoJObject obj = mJavaFrame->frame(env);
- if (!obj.get())
- return;
jobject bitmap = webcoreImageToJavaBitmap(env, icon);
if (!bitmap)
return;
- env->CallVoidMethod(obj.get(), mJavaFrame->mDidReceiveIcon, bitmap);
+ env->CallVoidMethod(mJavaFrame->frame(env).get(), mJavaFrame->mDidReceiveIcon, bitmap);
env->DeleteLocalRef(bitmap);
checkException(env);
}
@@ -741,13 +709,10 @@ WebFrame::didReceiveTouchIconURL(const WebCore::String& url, bool precomposed)
TimeCounterAuto counter(TimeCounter::JavaCallbackTimeCounter);
#endif
JNIEnv* env = getJNIEnv();
- AutoJObject obj = mJavaFrame->frame(env);
- if (!obj.get())
- return;
jstring jUrlStr = env->NewString((unsigned short*)url.characters(),
url.length());
- env->CallVoidMethod(obj.get(),
+ env->CallVoidMethod(mJavaFrame->frame(env).get(),
mJavaFrame->mDidReceiveTouchIconUrl, jUrlStr, precomposed);
checkException(env);
}
@@ -760,13 +725,9 @@ WebFrame::updateVisitedHistory(const WebCore::KURL& url, bool reload)
#endif
WebCore::String urlStr(url.string());
JNIEnv* env = getJNIEnv();
- AutoJObject obj = mJavaFrame->frame(env);
- if (!obj.get())
- return;
-
jstring jUrlStr = env->NewString((unsigned short*)urlStr.characters(), urlStr.length());
- env->CallVoidMethod(obj.get(), mJavaFrame->mUpdateVisitedHistory, jUrlStr, reload);
+ env->CallVoidMethod(mJavaFrame->frame(env).get(), mJavaFrame->mUpdateVisitedHistory, jUrlStr, reload);
checkException(env);
}
@@ -790,14 +751,11 @@ WebFrame::canHandleRequest(const WebCore::ResourceRequest& request)
if (url.isEmpty())
return true;
JNIEnv* env = getJNIEnv();
- AutoJObject obj = mJavaFrame->frame(env);
- if (!obj.get())
- return true;
jstring jUrlStr = env->NewString((unsigned short *)url.characters(), url.length());
// 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(obj.get(), mJavaFrame->mHandleUrl, jUrlStr);
+ jboolean ret = env->CallBooleanMethod(mJavaFrame->frame(env).get(), mJavaFrame->mHandleUrl, jUrlStr);
checkException(env);
return (ret == 0);
}
@@ -809,13 +767,10 @@ WebFrame::createWindow(bool dialog, bool userGesture)
TimeCounterAuto counter(TimeCounter::JavaCallbackTimeCounter);
#endif
JNIEnv* env = getJNIEnv();
- AutoJObject obj = mJavaFrame->frame(env);
- if (!obj.get())
- return NULL;
- jobject jobj = env->CallObjectMethod(obj.get(),
+ jobject obj = env->CallObjectMethod(mJavaFrame->frame(env).get(),
mJavaFrame->mCreateWindow, dialog, userGesture);
- if (jobj) {
- WebCore::Frame* frame = GET_NATIVE_FRAME(env, jobj);
+ if (obj) {
+ WebCore::Frame* frame = GET_NATIVE_FRAME(env, obj);
return frame;
}
return NULL;
@@ -828,10 +783,7 @@ WebFrame::requestFocus() const
TimeCounterAuto counter(TimeCounter::JavaCallbackTimeCounter);
#endif
JNIEnv* env = getJNIEnv();
- AutoJObject obj = mJavaFrame->frame(env);
- if (!obj.get())
- return;
- env->CallVoidMethod(obj.get(), mJavaFrame->mRequestFocus);
+ env->CallVoidMethod(mJavaFrame->frame(env).get(), mJavaFrame->mRequestFocus);
checkException(env);
}
@@ -843,10 +795,7 @@ WebFrame::closeWindow(WebViewCore* webViewCore)
#endif
assert(webViewCore);
JNIEnv* env = getJNIEnv();
- AutoJObject obj = mJavaFrame->frame(env);
- if (!obj.get())
- return;
- env->CallVoidMethod(obj.get(), mJavaFrame->mCloseWindow,
+ env->CallVoidMethod(mJavaFrame->frame(env).get(), mJavaFrame->mCloseWindow,
webViewCore->getJavaObject().get());
}
@@ -861,22 +810,16 @@ WebFrame::decidePolicyForFormResubmission(WebCore::FramePolicyFunction func)
TimeCounterAuto counter(TimeCounter::JavaCallbackTimeCounter);
#endif
JNIEnv* env = getJNIEnv();
- AutoJObject obj = mJavaFrame->frame(env);
- if (!obj.get())
- return;
PolicyFunctionWrapper* p = new PolicyFunctionWrapper;
p->func = func;
- env->CallVoidMethod(obj.get(), mJavaFrame->mDecidePolicyForFormResubmission, p);
+ env->CallVoidMethod(mJavaFrame->frame(env).get(), mJavaFrame->mDecidePolicyForFormResubmission, p);
}
WebCore::String
WebFrame::getRawResourceFilename(WebCore::PlatformBridge::rawResId id) const
{
JNIEnv* env = getJNIEnv();
- AutoJObject obj = mJavaFrame->frame(env);
- if (!obj.get())
- return WebCore::String();
- jstring ret = (jstring) env->CallObjectMethod(obj.get(),
+ jstring ret = (jstring) env->CallObjectMethod(mJavaFrame->frame(env).get(),
mJavaFrame->mGetRawResFilename, (int)id);
return to_string(env, ret);
@@ -886,10 +829,7 @@ float
WebFrame::density() const
{
JNIEnv* env = getJNIEnv();
- AutoJObject obj = mJavaFrame->frame(env);
- if (!obj.get())
- return 1.0;
- jfloat dpi = env->CallFloatMethod(obj.get(), mJavaFrame->mDensity);
+ jfloat dpi = env->CallFloatMethod(mJavaFrame->frame(env).get(), mJavaFrame->mDensity);
checkException(env);
return dpi;
}
@@ -917,6 +857,9 @@ static void CreateFrame(JNIEnv* env, jobject obj, jobject javaview, jobject jAss
ScriptController::initializeThreading();
#ifdef ANDROID_INSTRUMENT
+#if USE(V8)
+ V8Counters::initCounters();
+#endif
TimeCounterAuto counter(TimeCounter::NativeCallbackTimeCounter);
#endif
ChromeClientAndroid* chromeC = new ChromeClientAndroid;
@@ -925,7 +868,13 @@ static void CreateFrame(JNIEnv* env, jobject obj, jobject javaview, jobject jAss
WebCore::DragClient* dragC = new DragClientAndroid;
InspectorClientAndroid* inspectorC = new InspectorClientAndroid;
// Create a new page
- WebCore::Page* page = new WebCore::Page(chromeC, contextMenuC, editorC, dragC, inspectorC, 0);
+ WebCore::Page* page = new WebCore::Page(chromeC,
+ contextMenuC,
+ editorC,
+ dragC,
+ inspectorC,
+ 0, // PluginHalterClient
+ 0); // GeolocationControllerClient
// css files without explicit MIMETYPE is treated as generic text files in
// the Java side. So we can't enforce CSS MIMETYPE.
page->settings()->setEnforceCSSMIMETypeInStrictMode(false);
@@ -1015,7 +964,7 @@ static void DestroyFrame(JNIEnv* env, jobject obj)
#endif
}
-static void LoadUrl(JNIEnv *env, jobject obj, jstring url)
+static void LoadUrl(JNIEnv *env, jobject obj, jstring url, jobject headers)
{
#ifdef ANDROID_INSTRUMENT
TimeCounterAuto counter(TimeCounter::NativeCallbackTimeCounter);
@@ -1026,6 +975,45 @@ static void LoadUrl(JNIEnv *env, jobject obj, jstring url)
WebCore::String webcoreUrl = to_string(env, url);
WebCore::KURL kurl(WebCore::KURL(), webcoreUrl);
WebCore::ResourceRequest request(kurl);
+ if (headers) {
+ // dalvikvm will raise exception if any of these fail
+ jclass mapClass = env->FindClass("java/util/Map");
+ jmethodID entrySet = env->GetMethodID(mapClass, "entrySet",
+ "()Ljava/util/Set;");
+ jobject set = env->CallObjectMethod(headers, entrySet);
+
+ jclass setClass = env->FindClass("java/util/Set");
+ jmethodID iterator = env->GetMethodID(setClass, "iterator",
+ "()Ljava/util/Iterator;");
+ jobject iter = env->CallObjectMethod(set, iterator);
+
+ jclass iteratorClass = env->FindClass("java/util/Iterator");
+ jmethodID hasNext = env->GetMethodID(iteratorClass, "hasNext", "()Z");
+ jmethodID next = env->GetMethodID(iteratorClass, "next",
+ "()Ljava/lang/Object;");
+ jclass entryClass = env->FindClass("java/util/Map$Entry");
+ jmethodID getKey = env->GetMethodID(entryClass, "getKey",
+ "()Ljava/lang/Object;");
+ jmethodID getValue = env->GetMethodID(entryClass, "getValue",
+ "()Ljava/lang/Object;");
+
+ while (env->CallBooleanMethod(iter, hasNext)) {
+ jobject entry = env->CallObjectMethod(iter, next);
+ jstring key = (jstring) env->CallObjectMethod(entry, getKey);
+ jstring value = (jstring) env->CallObjectMethod(entry, getValue);
+ request.setHTTPHeaderField(to_string(env, key), to_string(env, value));
+ env->DeleteLocalRef(entry);
+ env->DeleteLocalRef(key);
+ env->DeleteLocalRef(value);
+ }
+
+ env->DeleteLocalRef(entryClass);
+ env->DeleteLocalRef(iteratorClass);
+ env->DeleteLocalRef(iter);
+ env->DeleteLocalRef(setClass);
+ env->DeleteLocalRef(set);
+ env->DeleteLocalRef(mapClass);
+ }
LOGV("LoadUrl %s", kurl.string().latin1().data());
pFrame->loader()->load(request, false);
}
@@ -1182,11 +1170,7 @@ static jobject StringByEvaluatingJavaScriptFromString(JNIEnv *env, jobject obj,
WebCore::ScriptValue value =
pFrame->script()->executeScript(to_string(env, script), true);
WebCore::String result = WebCore::String();
-#if USE(JSC)
- ScriptState* scriptState = pFrame->script()->globalObject(mainThreadNormalWorld())->globalExec();
-#elif USE(V8)
- ScriptState* scriptState = pFrame->script()->mainWorldScriptState();
-#endif
+ ScriptState* scriptState = mainWorldScriptState(pFrame);
if (!value.getString(scriptState, result))
return NULL;
unsigned len = result.length();
@@ -1217,46 +1201,67 @@ private:
WeakJavaInstance(jobject instance, PassRefPtr<RootObject> rootObject)
: JavaInstance(instance, rootObject)
#elif USE(V8)
- WeakJavaInstance(jobject instance) : JavaInstance(instance)
+ WeakJavaInstance(jobject instance)
+ : JavaInstance(instance)
#endif
+ , m_beginEndDepth(0)
{
JNIEnv* env = getJNIEnv();
// JavaInstance creates a global ref to instance in its constructor.
env->DeleteGlobalRef(m_instance->instance());
- // Set the object to our WeakReference wrapper.
- m_instance->setInstance(adoptGlobalRef(env, instance));
+ // Set the object to a weak reference.
+ m_instance->setInstance(env->NewWeakGlobalRef(instance));
+ }
+ ~WeakJavaInstance()
+ {
+ JNIEnv* env = getJNIEnv();
+ // Store the weak reference so we can delete it later.
+ jweak weak = m_instance->instance();
+ // The JavaInstance destructor attempts to delete the global ref stored
+ // in m_instance. Since we replaced it in our constructor with a weak
+ // reference, restore the global ref here so the vm will not complain.
+ m_instance->setInstance(env->NewGlobalRef(
+ getRealObject(env, m_instance->instance()).get()));
+ // Delete the weak reference.
+ env->DeleteWeakGlobalRef(weak);
}
virtual void virtualBegin()
{
- _weakRef = m_instance->instance();
+ if (m_beginEndDepth++ > 0)
+ return;
+ m_weakRef = m_instance->instance();
JNIEnv* env = getJNIEnv();
// This is odd. getRealObject returns an AutoJObject which is used to
// cleanly create and delete a local reference. But, here we need to
// maintain the local reference across calls to virtualBegin() and
// virtualEnd(). So, release the local reference from the AutoJObject
// and delete the local reference in virtualEnd().
- _realObject = getRealObject(env, _weakRef).release();
+ m_realObject = getRealObject(env, m_weakRef).release();
// Point to the real object
- m_instance->setInstance(_realObject);
+ m_instance->setInstance(m_realObject);
// Call the base class method
INHERITED::virtualBegin();
}
virtual void virtualEnd()
{
+ if (--m_beginEndDepth > 0)
+ return;
// Call the base class method first to pop the local frame.
INHERITED::virtualEnd();
// Get rid of the local reference to the real object.
- getJNIEnv()->DeleteLocalRef(_realObject);
+ getJNIEnv()->DeleteLocalRef(m_realObject);
// Point back to the WeakReference.
- m_instance->setInstance(_weakRef);
+ m_instance->setInstance(m_weakRef);
}
private:
typedef JavaInstance INHERITED;
- jobject _realObject;
- jobject _weakRef;
+ jobject m_realObject;
+ jweak m_weakRef;
+ // The current depth of nested calls to virtualBegin and virtualEnd.
+ int m_beginEndDepth;
};
static void AddJavascriptInterface(JNIEnv *env, jobject obj, jint nativeFramePointer,
@@ -1302,8 +1307,8 @@ static void AddJavascriptInterface(JNIEnv *env, jobject obj, jint nativeFramePoi
PassRefPtr<JavaInstance> addedObject = WeakJavaInstance::create(javascriptObj);
const char* name = getCharactersFromJStringInEnv(env, interfaceName);
// Pass ownership of the added object to bindToWindowObject.
- NPObject* obj = JavaInstanceToNPObject(addedObject.releaseRef());
- pFrame->script()->bindToWindowObject(pFrame, name, obj);
+ NPObject* npObject = JavaInstanceToNPObject(addedObject.releaseRef());
+ pFrame->script()->bindToWindowObject(pFrame, name, npObject);
// bindToWindowObject calls NPN_RetainObject on the
// returned one (see createV8ObjectForNPObject in V8NPObject.cpp).
// bindToWindowObject also increases obj's ref count and decreases
@@ -1315,7 +1320,7 @@ static void AddJavascriptInterface(JNIEnv *env, jobject obj, jint nativeFramePoi
// we use WebCore/bindings/v8/npruntime.cpp (rather than
// WebCore/bridge/npruntime.cpp), so the function is implemented there.
// TODO: Combine the two versions of these NPAPI files.
- NPN_ReleaseObject(obj);
+ NPN_ReleaseObject(npObject);
releaseCharactersForJString(interfaceName, name);
}
#endif
@@ -1396,8 +1401,11 @@ static jboolean HasPasswordField(JNIEnv *env, jobject obj)
bool found = false;
WTF::PassRefPtr<WebCore::HTMLCollection> form = pFrame->document()->forms();
WebCore::Node* node = form->firstItem();
- while (node && !found) {
- WTF::Vector<WebCore::HTMLFormControlElement*> elements =
+ // Null/Empty namespace means that node is not created in HTMLFormElement
+ // class, but just normal Element class.
+ while (node && !found && !node->namespaceURI().isNull() &&
+ !node->namespaceURI().isEmpty()) {
+ WTF::Vector<WebCore::HTMLFormControlElement*>& elements =
((WebCore::HTMLFormElement*)node)->formElements;
size_t size = elements.size();
for (size_t i = 0; i< size && !found; i++) {
@@ -1426,8 +1434,9 @@ static jobjectArray GetUsernamePassword(JNIEnv *env, jobject obj)
bool found = false;
WTF::PassRefPtr<WebCore::HTMLCollection> form = pFrame->document()->forms();
WebCore::Node* node = form->firstItem();
- while (node && !found) {
- WTF::Vector<WebCore::HTMLFormControlElement*> elements =
+ while (node && !found && !node->namespaceURI().isNull() &&
+ !node->namespaceURI().isEmpty()) {
+ WTF::Vector<WebCore::HTMLFormControlElement*>& elements =
((WebCore::HTMLFormElement*)node)->formElements;
size_t size = elements.size();
for (size_t i = 0; i< size && !found; i++) {
@@ -1471,8 +1480,9 @@ static void SetUsernamePassword(JNIEnv *env, jobject obj,
bool found = false;
WTF::PassRefPtr<WebCore::HTMLCollection> form = pFrame->document()->forms();
WebCore::Node* node = form->firstItem();
- while (node && !found) {
- WTF::Vector<WebCore::HTMLFormControlElement*> elements =
+ while (node && !found && !node->namespaceURI().isNull() &&
+ !node->namespaceURI().isEmpty()) {
+ WTF::Vector<WebCore::HTMLFormControlElement*>& elements =
((WebCore::HTMLFormElement*)node)->formElements;
size_t size = elements.size();
for (size_t i = 0; i< size && !found; i++) {
@@ -1520,7 +1530,9 @@ static jobject GetFormTextData(JNIEnv *env, jobject obj)
WebCore::HTMLFormElement* form;
WebCore::HTMLInputElement* input;
- for (WebCore::Node* node = collection->firstItem(); node; node = collection->nextItem()) {
+ for (WebCore::Node* node = collection->firstItem();
+ node && !node->namespaceURI().isNull() && !node->namespaceURI().isEmpty();
+ node = collection->nextItem()) {
form = static_cast<WebCore::HTMLFormElement*>(node);
if (form->autoComplete()) {
WTF::Vector<WebCore::HTMLFormControlElement*> elements = form->formElements;
@@ -1559,7 +1571,7 @@ static void OrientationChanged(JNIEnv *env, jobject obj, int orientation)
TimeCounterAuto counter(TimeCounter::NativeCallbackTimeCounter);
#endif
WebCore::Frame* pFrame = GET_NATIVE_FRAME(env, obj);
- LOGE("Sending orientation: %d", orientation);
+ LOGV("Sending orientation: %d", orientation);
pFrame->sendOrientationChangeEvent(orientation);
}
@@ -1578,7 +1590,7 @@ static JNINativeMethod gBrowserFrameNativeMethods[] = {
(void*) DestroyFrame },
{ "nativeStopLoading", "()V",
(void*) StopLoading },
- { "nativeLoadUrl", "(Ljava/lang/String;)V",
+ { "nativeLoadUrl", "(Ljava/lang/String;Ljava/util/Map;)V",
(void*) LoadUrl },
{ "nativePostUrl", "(Ljava/lang/String;[B)V",
(void*) PostUrl },