#include "config.h"
-#include "jni_npobject.h"
+#include "JavaNPObjectV8.h"
#include "JNIUtility.h"
#include "JavaClassV8.h"
#include "JavaInstanceV8.h"
#include "jni_runtime.h"
-// This source file should be in bridge/jni, so it's OK to use the private
-// NPAPI header from here.
#include "npruntime_impl.h"
-namespace JSC { namespace Bindings {
+namespace JSC {
+
+namespace Bindings {
+
static NPObject* AllocJavaNPObject(NPP, NPClass*)
{
- JavaNPObject* obj =
- static_cast<JavaNPObject*>(malloc(sizeof(JavaNPObject)));
- if (obj == 0)
+ JavaNPObject* obj = static_cast<JavaNPObject*>(malloc(sizeof(JavaNPObject)));
+ if (!obj)
return 0;
bzero(obj, sizeof(JavaNPObject));
return reinterpret_cast<NPObject*>(obj);
static void FreeJavaNPObject(NPObject* npobj)
{
JavaNPObject* obj = reinterpret_cast<JavaNPObject*>(npobj);
- obj->_instance = 0; // free does not call the destructor
+ obj->m_instance = 0; // free does not call the destructor
free(obj);
}
NPObject* JavaInstanceToNPObject(JavaInstance* instance) {
JavaNPObject* object = reinterpret_cast<JavaNPObject*>(_NPN_CreateObject(0, &JavaNPObjectClass));
- object->_instance = instance;
+ object->m_instance = instance;
return reinterpret_cast<NPObject*>(object);
}
// Returns null if obj is not a wrapper of JavaInstance
JavaInstance* ExtractJavaInstance(NPObject* obj) {
if (obj->_class == &JavaNPObjectClass) {
- return reinterpret_cast<JavaNPObject*>(obj)->_instance.get();
+ return reinterpret_cast<JavaNPObject*>(obj)->m_instance.get();
}
return 0;
}
bool JavaNPObject_HasMethod(NPObject* obj, NPIdentifier identifier) {
JavaInstance* instance = ExtractJavaInstance(obj);
- if (instance == 0)
+ if (!instance)
return false;
NPUTF8* name = _NPN_UTF8FromIdentifier(identifier);
- if (name == 0)
+ if (!name)
return false;
instance->begin();
return result;
}
-bool JavaNPObject_Invoke(NPObject* obj, NPIdentifier identifier,
- const NPVariant* args, uint32_t argCount, NPVariant* result) {
+bool JavaNPObject_Invoke(NPObject* obj, NPIdentifier identifier, const NPVariant* args, uint32_t argCount, NPVariant* result) {
JavaInstance* instance = ExtractJavaInstance(obj);
- if (instance == 0)
+ if (!instance)
return false;
NPUTF8* name = _NPN_UTF8FromIdentifier(identifier);
- if (name == 0)
+ if (!name)
return false;
instance->begin();
// TODO: use NPN_MemFree
free(name);
return r;
-
}
bool JavaNPObject_HasProperty(NPObject* obj, NPIdentifier identifier) {
JavaInstance* instance = ExtractJavaInstance(obj);
- if (instance == 0)
+ if (!instance)
return false;
NPUTF8* name = _NPN_UTF8FromIdentifier(identifier);
- if (name == 0)
+ if (!name)
return false;
instance->begin();
- bool result = instance->getClass()->fieldNamed(name) != 0;
+ bool result = instance->getClass()->fieldNamed(name);
instance->end();
free(name);
return result;
bool JavaNPObject_GetProperty(NPObject* obj, NPIdentifier identifier, NPVariant* result) {
VOID_TO_NPVARIANT(*result);
JavaInstance* instance = ExtractJavaInstance(obj);
- if (instance == 0)
+ if (!instance)
return false;
NPUTF8* name = _NPN_UTF8FromIdentifier(identifier);
- if (name == 0)
+ if (!name)
return false;
instance->begin();
instance->end();
free(name); // TODO: use NPN_MemFree
- if (field == 0) {
+ if (!field)
return false;
- }
jvalue value = getJNIField(instance->javaInstance(),
field->getJNIType(),
return true;
}
-}} // namespace
+} // namespace Bindings
+
+} // namespace JSC
/*
- * Copyright 2009, The Android Open Source Project
+ * Copyright 2010, The Android Open Source Project
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#ifndef JNI_NPOBJECT_H_
-#define JNI_NPOBJECT_H_
+#ifndef JavaNPObjectV8_h
+#define JavaNPObjectV8_h
-#include "npruntime.h"
#include "jni_runtime.h"
-
-#include <wtf/RefPtr.h>
+#include "npruntime.h"
#include <JavaVM/jni.h>
+#include <wtf/RefPtr.h>
-namespace JSC { namespace Bindings {
+
+namespace JSC {
+
+namespace Bindings {
+
+class JavaInstance;
struct JavaNPObject {
- NPObject _object;
- RefPtr<JavaInstance> _instance;
+ NPObject m_object;
+ RefPtr<JavaInstance> m_instance;
};
-NPObject* JavaInstanceToNPObject(JavaInstance* instance);
-JavaInstance* ExtractJavaInstance(NPObject* obj);
+NPObject* JavaInstanceToNPObject(JavaInstance*);
+JavaInstance* ExtractJavaInstance(NPObject*);
+
+bool JavaNPObject_HasMethod(NPObject*, NPIdentifier name);
+bool JavaNPObject_Invoke(NPObject*, NPIdentifier methodName, const NPVariant* args, uint32_t argCount, NPVariant* result);
+bool JavaNPObject_HasProperty(NPObject*, NPIdentifier name);
+bool JavaNPObject_GetProperty(NPObject*, NPIdentifier name, NPVariant* result);
-bool JavaNPObject_HasMethod(NPObject* obj, NPIdentifier name);
-bool JavaNPObject_Invoke(NPObject* obj, NPIdentifier methodName, const NPVariant* args, uint32_t argCount, NPVariant* result);
-bool JavaNPObject_HasProperty(NPObject* obj, NPIdentifier name);
-bool JavaNPObject_GetProperty(NPObject* obj, NPIdentifier name, NPVariant* ressult);
+} // namespace Bindings
-} }
+} // namespace JSC
-#endif JNI_NPOBJECT_H_
+#endif // JavaNPObjectV8_h