Commit b02f74f1 authored by steveblock@google.com's avatar steveblock@google.com

2011-03-02 Steve Block <steveblock@google.com>

        Reviewed by Jeremy Orlow.

        JObjectWrapper should be moved to its own file
        https://bugs.webkit.org/show_bug.cgi?id=55384

        No new tests, refactoring only.

        * Android.v8bindings.mk:
        * WebCore.gypi:
        * bridge/jni/v8/JNIBridgeV8.cpp:
        (JavaField::JavaField):
        * bridge/jni/v8/JNIBridgeV8.h:
        * bridge/jni/v8/JavaInstanceV8.cpp:
        (JavaInstance::JavaInstance):
        * bridge/jni/v8/JavaInstanceV8.h:
        * bridge/jni/v8/JobjectWrapper.cpp: Copied from Source/WebCore/bridge/jni/v8/JNIBridgeV8.h.
        (JobjectWrapper::JobjectWrapper):
        (JobjectWrapper::~JobjectWrapper):
        * bridge/jni/v8/JobjectWrapper.h: Copied from Source/WebCore/bridge/jni/v8/JNIBridgeV8.h.
        (JSC::Bindings::JobjectWrapper::instance):
        (JSC::Bindings::JobjectWrapper::setInstance):
        (JSC::Bindings::JobjectWrapper::ref):
        (JSC::Bindings::JobjectWrapper::deref):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@80103 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 3f15b338
......@@ -178,4 +178,5 @@ LOCAL_SRC_FILES += \
bridge/jni/v8/JNIUtilityPrivate.cpp \
bridge/jni/v8/JavaClassV8.cpp \
bridge/jni/v8/JavaInstanceV8.cpp \
bridge/jni/v8/JavaNPObject.cpp
bridge/jni/v8/JavaNPObject.cpp \
bridge/jni/v8/JobjectWrapper.cpp
2011-03-02 Steve Block <steveblock@google.com>
Reviewed by Jeremy Orlow.
JObjectWrapper should be moved to its own file
https://bugs.webkit.org/show_bug.cgi?id=55384
No new tests, refactoring only.
* Android.v8bindings.mk:
* WebCore.gypi:
* bridge/jni/v8/JNIBridgeV8.cpp:
(JavaField::JavaField):
* bridge/jni/v8/JNIBridgeV8.h:
* bridge/jni/v8/JavaInstanceV8.cpp:
(JavaInstance::JavaInstance):
* bridge/jni/v8/JavaInstanceV8.h:
* bridge/jni/v8/JobjectWrapper.cpp: Copied from Source/WebCore/bridge/jni/v8/JNIBridgeV8.h.
(JobjectWrapper::JobjectWrapper):
(JobjectWrapper::~JobjectWrapper):
* bridge/jni/v8/JobjectWrapper.h: Copied from Source/WebCore/bridge/jni/v8/JNIBridgeV8.h.
(JSC::Bindings::JobjectWrapper::instance):
(JSC::Bindings::JobjectWrapper::setInstance):
(JSC::Bindings::JobjectWrapper::ref):
(JSC::Bindings::JobjectWrapper::deref):
2011-02-25 Andrey Kosyakov <caseq@chromium.org>
Reviewed by Pavel Feldman.
......
......@@ -1021,6 +1021,8 @@
'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',
......
......@@ -42,7 +42,7 @@ JavaField::JavaField(JNIEnv* env, jobject aField)
jstring fieldName = static_cast<jstring>(callJNIMethod<jobject>(aField, "getName", "()Ljava/lang/String;"));
m_name = JavaString(env, fieldName);
m_field = new JObjectWrapper(aField);
m_field = new JobjectWrapper(aField);
}
#endif // ENABLE(JAVA_BRIDGE)
......@@ -29,7 +29,7 @@
#if ENABLE(JAVA_BRIDGE)
#include "JNIBridge.h" // For JavaString
#include "JavaInstanceV8.h" // For JObjectWrapper
#include "JobjectWrapper.h"
namespace JSC {
......@@ -48,7 +48,7 @@ private:
JavaString m_name;
JavaString m_type;
JNIType m_JNIType;
RefPtr<JObjectWrapper> m_field;
RefPtr<JobjectWrapper> m_field;
};
} // namespace Bindings
......
......@@ -33,13 +33,11 @@
#include "JNIUtilityPrivate.h"
#include "JavaClassV8.h"
#include <assert.h>
using namespace JSC::Bindings;
JavaInstance::JavaInstance(jobject instance)
{
m_instance = new JObjectWrapper(instance);
m_instance = new JobjectWrapper(instance);
m_class = 0;
}
......@@ -154,24 +152,4 @@ bool JavaInstance::invokeMethod(const char* methodName, const NPVariant* args, i
return true;
}
JObjectWrapper::JObjectWrapper(jobject instance)
: m_refCount(0)
{
assert(instance);
// Cache the JNIEnv used to get the global ref for this java instanace.
// It'll be used to delete the reference.
m_env = getJNIEnv();
m_instance = m_env->NewGlobalRef(instance);
if (!m_instance)
fprintf(stderr, "%s: could not get GlobalRef for %p\n", __PRETTY_FUNCTION__, instance);
}
JObjectWrapper::~JObjectWrapper()
{
m_env->DeleteGlobalRef(m_instance);
}
#endif // ENABLE(JAVA_BRIDGE)
......@@ -30,6 +30,7 @@
#if ENABLE(JAVA_BRIDGE)
#include "JNIUtility.h"
#include "JobjectWrapper.h"
#include "npruntime.h"
#include <wtf/RefCounted.h>
......@@ -43,33 +44,6 @@ namespace Bindings {
class JavaClass;
class JObjectWrapper {
friend class RefPtr<JObjectWrapper>;
friend class JavaField;
friend class JavaInstance;
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);
~JObjectWrapper();
jobject m_instance;
private:
JNIEnv* m_env;
unsigned int m_refCount;
};
class JavaInstance : public RefCounted<JavaInstance> {
public:
JavaInstance(jobject instance);
......@@ -88,7 +62,7 @@ public:
void end() { virtualEnd(); }
protected:
RefPtr<JObjectWrapper> m_instance;
RefPtr<JobjectWrapper> m_instance;
mutable JavaClass* m_class;
virtual void virtualBegin();
......
/*
* Copyright 2011, The Android Open Source Project
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "config.h"
#include "JobjectWrapper.h"
#if ENABLE(JAVA_BRIDGE)
#include <assert.h>
using namespace JSC::Bindings;
JobjectWrapper::JobjectWrapper(jobject instance)
: m_refCount(0)
{
assert(instance);
// Cache the JNIEnv used to get the global ref for this java instanace.
// It'll be used to delete the reference.
m_env = getJNIEnv();
m_instance = m_env->NewGlobalRef(instance);
if (!m_instance)
fprintf(stderr, "%s: could not get GlobalRef for %p\n", __PRETTY_FUNCTION__, instance);
}
JobjectWrapper::~JobjectWrapper()
{
m_env->DeleteGlobalRef(m_instance);
}
#endif // ENABLE(JAVA_BRIDGE)
/*
* Copyright 2011, The Android Open Source Project
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef JobjectWrapper_h
#define JobjectWrapper_h
#if ENABLE(JAVA_BRIDGE)
#include "JNIUtility.h"
namespace JSC {
namespace Bindings {
class JobjectWrapper {
friend class JavaField;
friend class JavaInstance;
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);
~JobjectWrapper();
jobject m_instance;
private:
JNIEnv* m_env;
unsigned int m_refCount;
};
} // namespace Bindings
} // namespace JSC
#endif // ENABLE(JAVA_BRIDGE)
#endif // JobjectWrapper_h
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment