2011-03-04 Steve Block <steveblock@google.com>
authorsteveblock@google.com <steveblock@google.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 4 Mar 2011 19:17:28 +0000 (19:17 +0000)
committersteveblock@google.com <steveblock@google.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 4 Mar 2011 19:17:28 +0000 (19:17 +0000)
        Reviewed by Jeremy Orlow.

        JSC and V8 versions of Java bridge should share JobjectWrapper
        https://bugs.webkit.org/show_bug.cgi?id=55763

        No new tests, refactoring only.

        * Android.jscbindings.mk:
        * Android.v8bindings.mk:
        * WebCore.gypi:
        * WebCore.order:
        * WebCore.xcodeproj/project.pbxproj:
        * bridge/jni/JobjectWrapper.cpp:
        (JobjectWrapper::JobjectWrapper):
        (JobjectWrapper::~JobjectWrapper):
        * bridge/jni/JobjectWrapper.h:
        (JSC::Bindings::JobjectWrapper::instance):
        (JSC::Bindings::JobjectWrapper::setInstance):
        (JSC::Bindings::JobjectWrapper::ref):
        (JSC::Bindings::JobjectWrapper::deref):
        * bridge/jni/jsc/JNIBridgeJSC.cpp:
        (JavaField::JavaField):
        (JavaArray::JavaArray):
        * bridge/jni/jsc/JNIBridgeJSC.h:
        * bridge/jni/jsc/JavaInstanceJSC.cpp:
        (JavaInstance::JavaInstance):
        * bridge/jni/jsc/JavaInstanceJSC.h:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@80367 268f45cc-cd09-0410-ab3c-d52691b4dbfc

12 files changed:
Source/WebCore/Android.jscbindings.mk
Source/WebCore/Android.v8bindings.mk
Source/WebCore/ChangeLog
Source/WebCore/WebCore.gypi
Source/WebCore/WebCore.order
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/bridge/jni/JobjectWrapper.cpp [moved from Source/WebCore/bridge/jni/v8/JobjectWrapper.cpp with 93% similarity]
Source/WebCore/bridge/jni/JobjectWrapper.h [moved from Source/WebCore/bridge/jni/v8/JobjectWrapper.h with 94% similarity]
Source/WebCore/bridge/jni/jsc/JNIBridgeJSC.cpp
Source/WebCore/bridge/jni/jsc/JNIBridgeJSC.h
Source/WebCore/bridge/jni/jsc/JavaInstanceJSC.cpp
Source/WebCore/bridge/jni/jsc/JavaInstanceJSC.h

index bfa67a8..e5ff603 100644 (file)
@@ -200,6 +200,7 @@ LOCAL_SRC_FILES += \
        bridge/c/c_utility.cpp \
        bridge/jni/JNIBridge.cpp \
        bridge/jni/JNIUtility.cpp \
+       bridge/jni/JobjectWrapper.cpp \
        bridge/jni/jsc/JNIBridgeJSC.cpp \
        bridge/jni/jsc/JNIUtilityPrivate.cpp \
        bridge/jni/jsc/JavaClassJSC.cpp \
index 05fe5f1..b230023 100644 (file)
@@ -174,6 +174,7 @@ LOCAL_SRC_FILES += \
 LOCAL_SRC_FILES += \
        bridge/jni/JNIBridge.cpp \
        bridge/jni/JNIUtility.cpp \
+       bridge/jni/JobjectWrapper.cpp \
        bridge/jni/v8/JNIBridgeV8.cpp \
        bridge/jni/v8/JNIUtilityPrivate.cpp \
        bridge/jni/v8/JavaClassV8.cpp \
index 5ecf041..ba4289a 100644 (file)
@@ -1,3 +1,33 @@
+2011-03-04  Steve Block  <steveblock@google.com>
+
+        Reviewed by Jeremy Orlow.
+
+        JSC and V8 versions of Java bridge should share JobjectWrapper
+        https://bugs.webkit.org/show_bug.cgi?id=55763
+
+        No new tests, refactoring only.
+
+        * Android.jscbindings.mk:
+        * Android.v8bindings.mk:
+        * WebCore.gypi:
+        * WebCore.order:
+        * WebCore.xcodeproj/project.pbxproj:
+        * bridge/jni/JobjectWrapper.cpp:
+        (JobjectWrapper::JobjectWrapper):
+        (JobjectWrapper::~JobjectWrapper):
+        * bridge/jni/JobjectWrapper.h:
+        (JSC::Bindings::JobjectWrapper::instance):
+        (JSC::Bindings::JobjectWrapper::setInstance):
+        (JSC::Bindings::JobjectWrapper::ref):
+        (JSC::Bindings::JobjectWrapper::deref):
+        * bridge/jni/jsc/JNIBridgeJSC.cpp:
+        (JavaField::JavaField):
+        (JavaArray::JavaArray):
+        * bridge/jni/jsc/JNIBridgeJSC.h:
+        * bridge/jni/jsc/JavaInstanceJSC.cpp:
+        (JavaInstance::JavaInstance):
+        * bridge/jni/jsc/JavaInstanceJSC.h:
+
 2011-03-04  Patrick Gansterer  <paroga@webkit.org>
 
         Reviewed by Nikolas Zimmermann.
index 9477c8c..e81a3ae 100644 (file)
             'bridge/jni/JNIBridge.h',
             'bridge/jni/JNIUtility.cpp',
             'bridge/jni/JNIUtility.h',
+            'bridge/jni/JobjectWrapper.cpp',
+            'bridge/jni/JobjectWrapper.h',
             'bridge/jni/v8/JNIBridgeV8.cpp',
             'bridge/jni/v8/JNIBridgeV8.h',
             'bridge/jni/v8/JNIUtilityPrivate.cpp',
             'bridge/jni/v8/JavaNPObjectV8.cpp',
             'bridge/jni/v8/JavaNPObjectV8.h',
             'bridge/jni/v8/JavaStringV8.h',
-            'bridge/jni/v8/JobjectWrapper.cpp',
-            'bridge/jni/v8/JobjectWrapper.h',
             'css/CSSBorderImageValue.cpp',
             'css/CSSBorderImageValue.h',
             'css/CSSCanvasValue.cpp',
index 83a7f77..bc8ea3b 100644 (file)
@@ -11539,8 +11539,8 @@ __ZN7WebCore19JSHTMLAppletElement26getOwnPropertySlotDelegateEPN3JSC9ExecStateER
 __ZNK7WebCore17HTMLAppletElement25renderWidgetForJSBindingsEv
 __ZN3JSC8Bindings12JavaInstanceC1EP8_jobjectN3WTF10PassRefPtrINS0_10RootObjectEEE
 __ZN3JSC8Bindings12JavaInstanceC2EP8_jobjectN3WTF10PassRefPtrINS0_10RootObjectEEE
-__ZN3JSC8Bindings14JObjectWrapperC1EP8_jobject
-__ZN3JSC8Bindings14JObjectWrapperC2EP8_jobject
+__ZN3JSC8Bindings14JobjectWrapperC1EP8_jobject
+__ZN3JSC8Bindings14JobjectWrapperC2EP8_jobject
 __ZN3JSC8Bindings9getJNIEnvEv
 __ZN3JSC8Bindings9getJavaVMEv
 __ZN3JSC8BindingsL20KJSGetCreatedJavaVMsEPP7JavaVM_iPi
@@ -11588,8 +11588,8 @@ __ZN3JSC8Bindings12JavaInstanceD0Ev
 __ZN3JSC8Bindings9JavaClassD0Ev
 __ZN3WTF20deleteAllPairSecondsIPN3JSC8Bindings5FieldEKNS_7HashMapINS_6RefPtrIN7WebCore10StringImplEEES4_NS7_10StringHashENS_10H
 __ZN3JSC8Bindings9JavaFieldD0Ev
-__ZN3JSC8Bindings14JObjectWrapperD1Ev
-__ZN3JSC8Bindings14JObjectWrapperD2Ev
+__ZN3JSC8Bindings14JobjectWrapperD1Ev
+__ZN3JSC8Bindings14JobjectWrapperD2Ev
 __ZN3WTF15deleteAllValuesIPN3JSC8Bindings6MethodELm0EEEvRKNS_6VectorIT_XT0_EEE
 __ZN3JSC8Bindings10JavaMethodD0Ev
 __ZN3JSC8Bindings13JavaParameterD1Ev
index 41634f0..46cda2a 100644 (file)
                59309A1311F4AE6A00250603 /* DeviceOrientationClientMock.h in Headers */ = {isa = PBXBuildFile; fileRef = 59309A1211F4AE6A00250603 /* DeviceOrientationClientMock.h */; settings = {ATTRIBUTES = (Private, ); }; };
                596229781133EFD700DC4CBB /* GeolocationPositionCache.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 596229771133EFD700DC4CBB /* GeolocationPositionCache.cpp */; };
                5962297A1133EFE200DC4CBB /* GeolocationPositionCache.h in Headers */ = {isa = PBXBuildFile; fileRef = 596229791133EFE200DC4CBB /* GeolocationPositionCache.h */; settings = {ATTRIBUTES = (Private, ); }; };
+               596950821321059900C3ED18 /* JobjectWrapper.h in Headers */ = {isa = PBXBuildFile; fileRef = 596950811321059900C3ED18 /* JobjectWrapper.h */; };
+               59695084132105A500C3ED18 /* JobjectWrapper.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 59695083132105A500C3ED18 /* JobjectWrapper.cpp */; };
                599E759011055A1F00D904FA /* Bridge.h in Headers */ = {isa = PBXBuildFile; fileRef = 599E758F11055A1F00D904FA /* Bridge.h */; settings = {ATTRIBUTES = (Private, ); }; };
                59A85EA2119D68D900DEF1EF /* DeviceOrientationEvent.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 59A85EA1119D68D900DEF1EF /* DeviceOrientationEvent.cpp */; };
                59A85EA4119D68EC00DEF1EF /* DeviceOrientationEvent.h in Headers */ = {isa = PBXBuildFile; fileRef = 59A85EA3119D68EC00DEF1EF /* DeviceOrientationEvent.h */; };
                59309A1211F4AE6A00250603 /* DeviceOrientationClientMock.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = DeviceOrientationClientMock.h; path = mock/DeviceOrientationClientMock.h; sourceTree = "<group>"; };
                596229771133EFD700DC4CBB /* GeolocationPositionCache.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = GeolocationPositionCache.cpp; sourceTree = "<group>"; };
                596229791133EFE200DC4CBB /* GeolocationPositionCache.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GeolocationPositionCache.h; sourceTree = "<group>"; };
+               596950811321059900C3ED18 /* JobjectWrapper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JobjectWrapper.h; sourceTree = "<group>"; };
+               59695083132105A500C3ED18 /* JobjectWrapper.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JobjectWrapper.cpp; sourceTree = "<group>"; };
                5980B03312EF3D8400DF5F85 /* XMLViewer.xsl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; path = XMLViewer.xsl; sourceTree = "<group>"; };
                599E758F11055A1F00D904FA /* Bridge.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Bridge.h; path = bridge/Bridge.h; sourceTree = "<group>"; };
                59A85EA1119D68D900DEF1EF /* DeviceOrientationEvent.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DeviceOrientationEvent.cpp; sourceTree = "<group>"; };
                1A569CCE0D7E2B82007C3983 /* jni */ = {
                        isa = PBXGroup;
                        children = (
+                               59695083132105A500C3ED18 /* JobjectWrapper.cpp */,
+                               596950811321059900C3ED18 /* JobjectWrapper.h */,
                                1A569CD40D7E2B82007C3983 /* jni_jsobject.h */,
                                1A569CD30D7E2B82007C3983 /* jni_jsobject.mm */,
                                1A569CD50D7E2B82007C3983 /* jni_objc.mm */,
                                5A574F29131DB96D00471B88 /* QuotesData.h in Headers */,
                                339B5B63131DAA3200F48D02 /* CookiesStrategy.h in Headers */,
                                33D0212D131DB37B004091A8 /* CookieStorage.h in Headers */,
+                               596950821321059900C3ED18 /* JobjectWrapper.h in Headers */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };
                                977E2E0E12F0FC9C00C13379 /* XSSFilter.cpp in Sources */,
                                5A574F24131DB93900471B88 /* RenderQuote.cpp in Sources */,
                                5A574F28131DB96D00471B88 /* QuotesData.cpp in Sources */,
+                               59695084132105A500C3ED18 /* JobjectWrapper.cpp in Sources */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };
@@ -1,4 +1,5 @@
 /*
+ * Copyright (C) 2003, 2008, 2010 Apple Inc. All rights reserved.
  * Copyright 2011, The Android Open Source Project
  *
  * Redistribution and use in source and binary forms, with or without
@@ -44,7 +45,7 @@ JobjectWrapper::JobjectWrapper(jobject instance)
     m_instance = m_env->NewGlobalRef(instance);
 
     if (!m_instance)
-        fprintf(stderr, "%s:  could not get GlobalRef for %p\n", __PRETTY_FUNCTION__, instance);
+        LOG_ERROR("Could not get GlobalRef for %p", instance);
 }
 
 JobjectWrapper::~JobjectWrapper()
similarity index 94%
rename from Source/WebCore/bridge/jni/v8/JobjectWrapper.h
rename to Source/WebCore/bridge/jni/JobjectWrapper.h
index b1da833..28ce56e 100644 (file)
@@ -1,4 +1,5 @@
 /*
+ * Copyright (C) 2003 Apple Computer, Inc.  All rights reserved.
  * Copyright 2011, The Android Open Source Project
  *
  * Redistribution and use in source and binary forms, with or without
@@ -35,6 +36,7 @@ namespace JSC {
 namespace Bindings {
 
 class JobjectWrapper {
+friend class JavaArray;
 friend class JavaField;
 friend class JavaInstance;
 
@@ -45,7 +47,7 @@ public:
     void ref() { m_refCount++; }
     void deref()
     {
-        if (!(--m_refCount))
+        if (!--m_refCount)
             delete this;
     }
 
@@ -65,4 +67,5 @@ private:
 } // namespace JSC
 
 #endif // ENABLE(JAVA_BRIDGE)
+
 #endif // JobjectWrapper_h
index f4dab20..8f45b5a 100644 (file)
@@ -30,6 +30,7 @@
 #if ENABLE(JAVA_BRIDGE)
 
 #include "JNIUtilityPrivate.h"
+#include "JobjectWrapper.h"
 #include "Logging.h"
 #include "runtime_array.h"
 #include "runtime_object.h"
@@ -57,7 +58,7 @@ JavaField::JavaField(JNIEnv* env, jobject aField)
         fieldName = env->NewStringUTF("<Unknown>");
     m_name = JavaString(env, fieldName);
 
-    m_field = new JObjectWrapper(aField);
+    m_field = new JobjectWrapper(aField);
 }
 
 JSValue JavaArray::convertJObjectToArray(ExecState* exec, jobject anObject, const char* type, PassRefPtr<RootObject> rootObject)
@@ -251,7 +252,7 @@ void JavaField::setValueToInstance(ExecState* exec, const Instance* i, JSValue a
 JavaArray::JavaArray(jobject array, const char* type, PassRefPtr<RootObject> rootObject)
     : Array(rootObject)
 {
-    m_array = new JObjectWrapper(array);
+    m_array = new JobjectWrapper(array);
     // Java array are fixed length, so we can cache length.
     JNIEnv* env = getJNIEnv();
     m_length = env->GetArrayLength(static_cast<jarray>(m_array->m_instance));
index c376bb9..14d06ad 100644 (file)
@@ -32,6 +32,7 @@
 #include "BridgeJSC.h"
 #include "JNIBridge.h"
 #include "JNIUtility.h"
+#include "JobjectWrapper.h"
 
 namespace JSC {
 
@@ -56,7 +57,7 @@ private:
     JavaString m_name;
     JavaString m_type;
     JNIType m_JNIType;
-    RefPtr<JObjectWrapper> m_field;
+    RefPtr<JobjectWrapper> m_field;
 };
 
 class JavaArray : public Array {
@@ -75,7 +76,7 @@ public:
     static JSValue convertJObjectToArray(ExecState*, jobject, const char* type, PassRefPtr<RootObject>);
 
 private:
-    RefPtr<JObjectWrapper> m_array;
+    RefPtr<JobjectWrapper> m_array;
     unsigned int m_length;
     const char* m_type;
 };
index 0b89c48..624da7d 100644 (file)
@@ -51,7 +51,7 @@ using namespace WebCore;
 JavaInstance::JavaInstance(jobject instance, PassRefPtr<RootObject> rootObject)
     : Instance(rootObject)
 {
-    m_instance = new JObjectWrapper(instance);
+    m_instance = new JobjectWrapper(instance);
     m_class = 0;
 }
 
@@ -366,27 +366,4 @@ JSValue JavaInstance::valueOf(ExecState* exec) const
     return stringValue(exec);
 }
 
-JObjectWrapper::JObjectWrapper(jobject instance)
-    : m_refCount(0)
-{
-    ASSERT(instance);
-
-    // Cache the JNIEnv used to get the global ref for this java instance.
-    // It'll be used to delete the reference.
-    m_env = getJNIEnv();
-
-    m_instance = m_env->NewGlobalRef(instance);
-
-    LOG(LiveConnect, "JObjectWrapper ctor new global ref %p for %p", m_instance, instance);
-
-    if (!m_instance)
-        LOG_ERROR("Could not get GlobalRef for %p", instance);
-}
-
-JObjectWrapper::~JObjectWrapper()
-{
-    LOG(LiveConnect, "JObjectWrapper dtor deleting global ref %p", m_instance);
-    m_env->DeleteGlobalRef(m_instance);
-}
-
 #endif // ENABLE(JAVA_BRIDGE)
index 7690cee..937e49c 100644 (file)
@@ -30,6 +30,7 @@
 
 #include "BridgeJSC.h"
 #include "JNIUtility.h"
+#include "JobjectWrapper.h"
 #include "runtime_root.h"
 
 namespace JSC {
@@ -38,35 +39,6 @@ namespace Bindings {
 
 class JavaClass;
 
-class JObjectWrapper {
-friend class RefPtr<JObjectWrapper>;
-friend class JavaArray;
-friend class JavaField;
-friend class JavaInstance;
-friend class JavaMethod;
-
-public:
-    jobject instance() const { return m_instance; }
-    void setInstance(jobject instance) { m_instance = instance; }
-
-    void ref() { m_refCount++; }
-    void deref()
-    {
-        if (!(--m_refCount))
-            delete this;
-    }
-
-protected:
-    JObjectWrapper(jobject instance);
-    ~JObjectWrapper();
-
-    jobject m_instance;
-
-private:
-    JNIEnv* m_env;
-    unsigned int m_refCount;
-};
-
 class JavaInstance : public Instance {
 public:
     static PassRefPtr<JavaInstance> create(jobject instance, PassRefPtr<RootObject> rootObject)
@@ -98,7 +70,7 @@ protected:
     virtual void virtualBegin();
     virtual void virtualEnd();
 
-    RefPtr<JObjectWrapper> m_instance;
+    RefPtr<JobjectWrapper> m_instance;
     mutable JavaClass* m_class;
 };