summaryrefslogtreecommitdiffstats
path: root/webkit
diff options
context:
space:
mode:
authorjorlow@chromium.org <jorlow@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-29 00:11:32 +0000
committerjorlow@chromium.org <jorlow@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-29 00:11:32 +0000
commit9fc081e3fdd83b0ab00159f0fb61eb59bdf577cd (patch)
treea8e2f5406ae08b497cd88d388c6e74147844ae9d /webkit
parentde8dbced341b19faeacb2fbc64ad467ee9c8d209 (diff)
downloadchromium_src-9fc081e3fdd83b0ab00159f0fb61eb59bdf577cd.zip
chromium_src-9fc081e3fdd83b0ab00159f0fb61eb59bdf577cd.tar.gz
chromium_src-9fc081e3fdd83b0ab00159f0fb61eb59bdf577cd.tar.bz2
Make webkit\glue\cpp_*.cc not depend on "config.h"
TEST=none BUG=none Review URL: http://codereview.chromium.org/159558 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@21927 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit')
-rw-r--r--webkit/api/public/WebBindings.h33
-rw-r--r--webkit/api/src/WebBindings.cpp76
-rw-r--r--webkit/glue/cpp_binding_example.cc2
-rw-r--r--webkit/glue/cpp_bound_class.cc33
-rw-r--r--webkit/glue/cpp_variant.cc44
5 files changed, 127 insertions, 61 deletions
diff --git a/webkit/api/public/WebBindings.h b/webkit/api/public/WebBindings.h
index f6eeb7d..00d055c 100644
--- a/webkit/api/public/WebBindings.h
+++ b/webkit/api/public/WebBindings.h
@@ -44,12 +44,41 @@ namespace WebKit {
// NPN Functions ------------------------------------------------------
// These are all defined in npruntime.h and are well documented.
- // NPN_GetStringIdentifier
- WEBKIT_API static NPIdentifier getStringIdentifier(const NPUTF8*);
+ // NPN_CreateObject
+ WEBKIT_API static NPObject* createObject(NPP npp, NPClass* npClass);
// NPN_GetIntIdentifier
WEBKIT_API static NPIdentifier getIntIdentifier(int32_t);
+ // NPN_GetProperty
+ WEBKIT_API static bool getProperty(NPP npp, NPObject* obj, NPIdentifier propertyName, NPVariant *result);
+
+ // NPN_GetStringIdentifier
+ WEBKIT_API static NPIdentifier getStringIdentifier(const NPUTF8*);
+
+ // NPN_HasMethod
+ WEBKIT_API static bool hasMethod(NPP npp, NPObject* npObject, NPIdentifier methodName);
+
+ // NPN_HasProperty
+ WEBKIT_API static bool hasProperty(NPP npp, NPObject* npObject, NPIdentifier propertyName);
+
+ // NPN_InitializeVariantWithStringCopy (though sometimes prefixed with an underscore)
+ WEBKIT_API static void initializeVariantWithStringCopy(NPVariant* variant, const NPString* value);
+
+ // NPN_Invoke
+ WEBKIT_API static bool invoke(NPP npp, NPObject* npObject, NPIdentifier methodName, const NPVariant* arguments, uint32_t argumentCount, NPVariant* result);
+
+ // NPN_ReleaseObject
+ WEBKIT_API static void releaseObject(NPObject* npObject);
+
+ // NPN_ReleaseVariantValue
+ WEBKIT_API static void releaseVariantValue(NPVariant* variant);
+
+ // NPN_RetainObject
+ WEBKIT_API static NPObject* retainObject(NPObject* npObject);
+
+ // _NPN_UnregisterObject
+ WEBKIT_API static void unregisterObject(NPObject* npObject);
// Miscellaneous utility functions ------------------------------------
diff --git a/webkit/api/src/WebBindings.cpp b/webkit/api/src/WebBindings.cpp
index da41c78..b3cf59a 100644
--- a/webkit/api/src/WebBindings.cpp
+++ b/webkit/api/src/WebBindings.cpp
@@ -54,6 +54,72 @@ using namespace WebCore;
namespace WebKit {
+NPObject* WebBindings::createObject(NPP npp, NPClass* npClass)
+{
+ return NPN_CreateObject(npp, npClass);
+}
+
+NPIdentifier WebBindings::getIntIdentifier(int32_t number)
+{
+ return NPN_GetIntIdentifier(number);
+}
+
+bool WebBindings::getProperty(NPP npp, NPObject* obj, NPIdentifier propertyName, NPVariant *result)
+{
+ return NPN_GetProperty(npp, obj, propertyName, result);
+}
+
+NPIdentifier WebBindings::getStringIdentifier(const NPUTF8* string)
+{
+ return NPN_GetStringIdentifier(string);
+}
+
+bool WebBindings::hasMethod(NPP npp, NPObject* npObject, NPIdentifier methodName)
+{
+ return NPN_HasMethod(npp, npObject, methodName);
+}
+
+bool WebBindings::hasProperty(NPP npp, NPObject* npObject, NPIdentifier propertyName)
+{
+ return NPN_HasProperty(npp, npObject, propertyName);
+}
+
+void WebBindings::initializeVariantWithStringCopy(NPVariant* variant, const NPString* value)
+{
+#if USE(V8)
+ _NPN_InitializeVariantWithStringCopy(variant, value);
+#else
+ NPN_InitializeVariantWithStringCopy(variant, value);
+#endif
+}
+
+bool WebBindings::invoke(NPP npp, NPObject* npObject, NPIdentifier methodName, const NPVariant* arguments, uint32_t argumentCount, NPVariant* result)
+{
+ return NPN_Invoke(npp, npObject, methodName, arguments, argumentCount, result);
+}
+
+void WebBindings::releaseObject(NPObject* npObject)
+{
+ return NPN_ReleaseObject(npObject);
+}
+
+void WebBindings::releaseVariantValue(NPVariant* variant)
+{
+ NPN_ReleaseVariantValue(variant);
+}
+
+NPObject* WebBindings::retainObject(NPObject* npObject)
+{
+ return NPN_RetainObject(npObject);
+}
+
+void WebBindings::unregisterObject(NPObject* npObject)
+{
+#if USE(V8)
+ _NPN_UnregisterObject(npObject);
+#endif
+}
+
void WebBindings::extractIdentifierData(const NPIdentifier& identifier, const NPUTF8*& string, int32_t& number, bool& isString)
{
PrivateIdentifier* priv = static_cast<PrivateIdentifier*>(identifier);
@@ -70,16 +136,6 @@ void WebBindings::extractIdentifierData(const NPIdentifier& identifier, const NP
number = priv->value.number;
}
-NPIdentifier WebBindings::getStringIdentifier(const NPUTF8* string)
-{
- return NPN_GetStringIdentifier(string);
-}
-
-NPIdentifier WebBindings::getIntIdentifier(int32_t number)
-{
- return NPN_GetIntIdentifier(number);
-}
-
#if USE(V8)
static v8::Local<v8::Value> getEvent(const v8::Handle<v8::Context>& context)
diff --git a/webkit/glue/cpp_binding_example.cc b/webkit/glue/cpp_binding_example.cc
index e89bac0..b71ffd3 100644
--- a/webkit/glue/cpp_binding_example.cc
+++ b/webkit/glue/cpp_binding_example.cc
@@ -5,8 +5,6 @@
// This file contains the definition for CppBindingExample, a usage example
// that is not actually used anywhere. See cpp_binding_example.h.
-#include "config.h"
-
#include "cpp_binding_example.h"
CppBindingExample::CppBindingExample() {
diff --git a/webkit/glue/cpp_bound_class.cc b/webkit/glue/cpp_bound_class.cc
index 151f070..ef0a72d6 100644
--- a/webkit/glue/cpp_bound_class.cc
+++ b/webkit/glue/cpp_bound_class.cc
@@ -12,25 +12,13 @@
// name in its internal map of methods, and then calls the appropriate
// method.
-#include "config.h"
-
#include "base/compiler_specific.h"
#include "base/logging.h"
-
+#include "webkit/api/public/WebBindings.h"
#include "webkit/glue/cpp_bound_class.h"
#include "webkit/glue/webframe.h"
-// This is required for the KJS build due to an artifact of the
-// npruntime_priv.h file from JavaScriptCore/bindings.
-MSVC_PUSH_DISABLE_WARNING(4067)
-#include "npruntime_priv.h"
-MSVC_POP_WARNING()
-
-#if USE(JSC)
-#pragma warning(push, 0)
-#include <runtime/JSLock.h>
-#pragma warning(pop)
-#endif
+using WebKit::WebBindings;
// Our special NPObject type. We extend an NPObject with a pointer to a
// CppBoundClass, which is just a C++ interface that we forward all NPObject
@@ -148,10 +136,8 @@ CppBoundClass::~CppBoundClass() {
delete i->second;
// Unregister ourselves if we were bound to a frame.
-#if USE(V8)
if (bound_to_frame_)
- _NPN_UnregisterObject(NPVARIANT_TO_OBJECT(self_variant_));
-#endif
+ WebBindings::unregisterObject(NPVARIANT_TO_OBJECT(self_variant_));
}
bool CppBoundClass::HasMethod(NPIdentifier ident) const {
@@ -215,7 +201,7 @@ bool CppBoundClass::SetProperty(NPIdentifier ident,
void CppBoundClass::BindCallback(std::string name, Callback* callback) {
// NPUTF8 is a typedef for char, so this cast is safe.
- NPIdentifier ident = NPN_GetStringIdentifier((const NPUTF8*)name.c_str());
+ NPIdentifier ident = WebBindings::getStringIdentifier((const NPUTF8*)name.c_str());
MethodList::iterator old_callback = methods_.find(ident);
if (old_callback != methods_.end())
delete old_callback->second;
@@ -224,13 +210,13 @@ void CppBoundClass::BindCallback(std::string name, Callback* callback) {
void CppBoundClass::BindProperty(std::string name, CppVariant* prop) {
// NPUTF8 is a typedef for char, so this cast is safe.
- NPIdentifier ident = NPN_GetStringIdentifier((const NPUTF8*)name.c_str());
+ NPIdentifier ident = WebBindings::getStringIdentifier((const NPUTF8*)name.c_str());
properties_[ident] = prop;
}
bool CppBoundClass::IsMethodRegistered(std::string name) const {
// NPUTF8 is a typedef for char, so this cast is safe.
- NPIdentifier ident = NPN_GetStringIdentifier((const NPUTF8*)name.c_str());
+ NPIdentifier ident = WebBindings::getStringIdentifier((const NPUTF8*)name.c_str());
MethodList::const_iterator callback = methods_.find(ident);
return (callback != methods_.end());
}
@@ -240,11 +226,11 @@ CppVariant* CppBoundClass::GetAsCppVariant() {
// Create an NPObject using our static NPClass. The first argument (a
// plugin's instance handle) is passed through to the allocate function
// directly, and we don't use it, so it's ok to be 0.
- NPObject* np_obj = NPN_CreateObject(0, &CppNPObject::np_class_);
+ NPObject* np_obj = WebBindings::createObject(0, &CppNPObject::np_class_);
CppNPObject* obj = reinterpret_cast<CppNPObject*>(np_obj);
obj->bound_class = this;
self_variant_.Set(np_obj);
- NPN_ReleaseObject(np_obj); // CppVariant takes the reference.
+ WebBindings::releaseObject(np_obj); // CppVariant takes the reference.
}
DCHECK(self_variant_.isObject());
return &self_variant_;
@@ -252,7 +238,8 @@ CppVariant* CppBoundClass::GetAsCppVariant() {
void CppBoundClass::BindToJavascript(WebFrame* frame,
const std::wstring& classname) {
-#if USE(JSC)
+#if WEBKIT_USING_JSC
+#error "This is not going to work anymore...but it's not clear what the solution is...or if it's still necessary."
JSC::JSLock lock(false);
#endif
diff --git a/webkit/glue/cpp_variant.cc b/webkit/glue/cpp_variant.cc
index 2f6be0c..9237cc9 100644
--- a/webkit/glue/cpp_variant.cc
+++ b/webkit/glue/cpp_variant.cc
@@ -5,16 +5,12 @@
// This file contains definitions for CppVariant.
#include <limits>
-#include "config.h"
+#include "webkit/api/public/WebBindings.h"
#include "webkit/glue/cpp_variant.h"
#include "base/logging.h"
#include "base/string_util.h"
-#include "npruntime_priv.h" // for NPN_InitializeVariantWithStringCopy
-
-#if USE(JSC)
-#define _NPN_InitializeVariantWithStringCopy NPN_InitializeVariantWithStringCopy
-#endif
+using WebKit::WebBindings;
CppVariant::CppVariant() {
type = NPVariantType_Null;
@@ -39,7 +35,7 @@ CppVariant::~CppVariant() {
}
void CppVariant::FreeData() {
- NPN_ReleaseVariantValue(this);
+ WebBindings::releaseVariantValue(this);
}
bool CppVariant::isEqual(const CppVariant& other) const {
@@ -91,7 +87,7 @@ void CppVariant::CopyToNPVariant(NPVariant* result) const {
result->value.doubleValue = value.doubleValue;
break;
case NPVariantType_String:
- _NPN_InitializeVariantWithStringCopy(result, &value.stringValue);
+ WebBindings::initializeVariantWithStringCopy(result, &value.stringValue);
break;
case NPVariantType_Null:
case NPVariantType_Void:
@@ -99,7 +95,7 @@ void CppVariant::CopyToNPVariant(NPVariant* result) const {
break;
case NPVariantType_Object:
result->type = NPVariantType_Object;
- result->value.objectValue = NPN_RetainObject(value.objectValue);
+ result->value.objectValue = WebBindings::retainObject(value.objectValue);
break;
}
}
@@ -158,7 +154,7 @@ void CppVariant::Set(const char* new_value) {
type = NPVariantType_String;
NPString new_string = {new_value,
static_cast<uint32_t>(strlen(new_value))};
- _NPN_InitializeVariantWithStringCopy(this, &new_string);
+ WebBindings::initializeVariantWithStringCopy(this, &new_string);
}
void CppVariant::Set(const std::string& new_value) {
@@ -166,18 +162,18 @@ void CppVariant::Set(const std::string& new_value) {
type = NPVariantType_String;
NPString new_string = {new_value.data(),
static_cast<uint32_t>(new_value.size())};
- _NPN_InitializeVariantWithStringCopy(this, &new_string);
+ WebBindings::initializeVariantWithStringCopy(this, &new_string);
}
void CppVariant::Set(const NPString& new_value) {
FreeData();
type = NPVariantType_String;
- _NPN_InitializeVariantWithStringCopy(this, &new_value);
+ WebBindings::initializeVariantWithStringCopy(this, &new_value);
}
void CppVariant::Set(NPObject* new_value) {
FreeData();
type = NPVariantType_Object;
- value.objectValue = NPN_RetainObject(new_value);
+ value.objectValue = WebBindings::retainObject(new_value);
}
std::string CppVariant::ToString() const {
@@ -218,35 +214,35 @@ std::vector<std::wstring> CppVariant::ToStringVector() const {
DCHECK(isObject());
std::vector<std::wstring> wstring_vector;
NPObject* np_value = value.objectValue;
- NPIdentifier length_id = NPN_GetStringIdentifier("length");
+ NPIdentifier length_id = WebBindings::getStringIdentifier("length");
- if (NPN_HasProperty(NULL, np_value, length_id)) {
+ if (WebBindings::hasProperty(NULL, np_value, length_id)) {
NPVariant length_value;
- if (NPN_GetProperty(NULL, np_value, length_id, &length_value)) {
+ if (WebBindings::getProperty(NULL, np_value, length_id, &length_value)) {
int length = 0;
// The length is a double in some cases.
if (NPVARIANT_IS_DOUBLE(length_value))
length = static_cast<int>(NPVARIANT_TO_DOUBLE(length_value));
else if (NPVARIANT_IS_INT32(length_value))
length = NPVARIANT_TO_INT32(length_value);
- NPN_ReleaseVariantValue(&length_value);
+ WebBindings::releaseVariantValue(&length_value);
// For sanity, only allow 100 items.
length = std::min(100, length);
for (int i = 0; i < length; ++i) {
// Get each of the items.
std::string index = StringPrintf("%d", i);
- NPIdentifier index_id = NPN_GetStringIdentifier(index.c_str());
- if (NPN_HasProperty(NULL, np_value, index_id)) {
+ NPIdentifier index_id = WebBindings::getStringIdentifier(index.c_str());
+ if (WebBindings::hasProperty(NULL, np_value, index_id)) {
NPVariant index_value;
- if (NPN_GetProperty(NULL, np_value, index_id, &index_value)) {
+ if (WebBindings::getProperty(NULL, np_value, index_id, &index_value)) {
if (NPVARIANT_IS_STRING(index_value)) {
std::string string(
NPVARIANT_TO_STRING(index_value).UTF8Characters,
NPVARIANT_TO_STRING(index_value).UTF8Length);
wstring_vector.push_back(UTF8ToWide(string));
}
- NPN_ReleaseVariantValue(&index_value);
+ WebBindings::releaseVariantValue(&index_value);
}
}
}
@@ -258,11 +254,11 @@ std::vector<std::wstring> CppVariant::ToStringVector() const {
bool CppVariant::Invoke(const std::string& method, const CppVariant* args,
uint32 arg_count, CppVariant& result) const {
DCHECK(isObject());
- NPIdentifier method_name = NPN_GetStringIdentifier(method.c_str());
+ NPIdentifier method_name = WebBindings::getStringIdentifier(method.c_str());
NPObject* np_object = value.objectValue;
- if (NPN_HasMethod(NULL, np_object, method_name)) {
+ if (WebBindings::hasMethod(NULL, np_object, method_name)) {
NPVariant r;
- bool status = NPN_Invoke(NULL, np_object, method_name, args, arg_count, &r);
+ bool status = WebBindings::invoke(NULL, np_object, method_name, args, arg_count, &r);
result.Set(r);
return status;
} else {