From 9fc081e3fdd83b0ab00159f0fb61eb59bdf577cd Mon Sep 17 00:00:00 2001
From: "jorlow@chromium.org"
 <jorlow@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>
Date: Wed, 29 Jul 2009 00:11:32 +0000
Subject: 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
---
 webkit/glue/cpp_binding_example.cc |  2 --
 webkit/glue/cpp_bound_class.cc     | 33 +++++++++-------------------
 webkit/glue/cpp_variant.cc         | 44 +++++++++++++++++---------------------
 3 files changed, 30 insertions(+), 49 deletions(-)

(limited to 'webkit/glue')

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 {
-- 
cgit v1.1