diff options
author | Steve Block <steveblock@google.com> | 2010-01-08 09:15:31 -0800 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2010-01-08 09:15:31 -0800 |
commit | ee0e4a35152a822ebac039808db1a4c33f02f7ee (patch) | |
tree | ee64aa110c91adb70d51dabe7a3c42470f4bd007 /WebKit | |
parent | 5cf18d3a4942dd7fba1f03621d53d66412b1b3df (diff) | |
parent | 88d4517612dafdcaff7a98f2a68ff071e2734ea6 (diff) | |
download | external_webkit-ee0e4a35152a822ebac039808db1a4c33f02f7ee.zip external_webkit-ee0e4a35152a822ebac039808db1a4c33f02f7ee.tar.gz external_webkit-ee0e4a35152a822ebac039808db1a4c33f02f7ee.tar.bz2 |
Merge "Updates the use of weak references in the script-to-Java bridge for V8." into eclair-mr2
Diffstat (limited to 'WebKit')
-rw-r--r-- | WebKit/android/jni/WebCoreFrameBridge.cpp | 31 |
1 files changed, 20 insertions, 11 deletions
diff --git a/WebKit/android/jni/WebCoreFrameBridge.cpp b/WebKit/android/jni/WebCoreFrameBridge.cpp index 85b0f34..ee39462 100644 --- a/WebKit/android/jni/WebCoreFrameBridge.cpp +++ b/WebKit/android/jni/WebCoreFrameBridge.cpp @@ -1195,20 +1195,30 @@ static jobject StringByEvaluatingJavaScriptFromString(JNIEnv *env, jobject obj, return env->NewString((unsigned short*)result.characters(), len); } -#if USE(JSC) // Wrap the JavaInstance used when binding custom javascript interfaces. Use a // weak reference so that the gc can collect the WebView. Override virtualBegin // and virtualEnd and swap the weak reference for the real object. class WeakJavaInstance : public JavaInstance { public: +#if USE(JSC) static PassRefPtr<WeakJavaInstance> create(jobject obj, PassRefPtr<RootObject> root) { return adoptRef(new WeakJavaInstance(obj, root)); } +#elif USE(V8) + static PassRefPtr<WeakJavaInstance> create(jobject obj) + { + return adoptRef(new WeakJavaInstance(obj)); + } +#endif -protected: +private: +#if USE(JSC) WeakJavaInstance(jobject instance, PassRefPtr<RootObject> rootObject) : JavaInstance(instance, rootObject) +#elif USE(V8) + WeakJavaInstance(jobject instance) : JavaInstance(instance) +#endif { JNIEnv* env = getJNIEnv(); // JavaInstance creates a global ref to instance in its constructor. @@ -1248,7 +1258,6 @@ private: jobject _realObject; jobject _weakRef; }; -#endif // USE(JSC) static void AddJavascriptInterface(JNIEnv *env, jobject obj, jint nativeFramePointer, jobject javascriptObj, jstring interfaceName) @@ -1288,19 +1297,19 @@ static void AddJavascriptInterface(JNIEnv *env, jobject obj, jint nativeFramePoi checkException(env); } } -#endif // USE(JSC) - -#if USE(V8) +#elif USE(V8) if (pFrame) { + PassRefPtr<JavaInstance> addedObject = WeakJavaInstance::create(javascriptObj); const char* name = getCharactersFromJStringInEnv(env, interfaceName); - NPObject* obj = JavaInstanceToNPObject(new JavaInstance(javascriptObj)); + // Pass ownership of the added object to bindToWindowObject. + NPObject* obj = JavaInstanceToNPObject(addedObject.releaseRef()); pFrame->script()->bindToWindowObject(pFrame, name, obj); - // JavaInstanceToNPObject calls NPN_RetainObject on the - // returned one (see CreateV8ObjectForNPObject in V8NPObject.cpp). - // BindToWindowObject also increases obj's ref count and decrease + // bindToWindowObject calls NPN_RetainObject on the + // returned one (see createV8ObjectForNPObject in V8NPObject.cpp). + // bindToWindowObject also increases obj's ref count and decreases // the ref count when the object is not reachable from JavaScript // side. Code here must release the reference count increased by - // JavaInstanceToNPObject. + // bindToWindowObject. // Note that while this function is declared in WebCore/bridge/npruntime.h, for V8 builds // we use WebCore/bindings/v8/npruntime.cpp (rather than |