diff options
author | japhet@chromium.org <japhet@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-17 00:56:03 +0000 |
---|---|---|
committer | japhet@chromium.org <japhet@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-17 00:56:03 +0000 |
commit | e2304b0549b35420d17819ede170d06edc339f37 (patch) | |
tree | 31dd55c8649ce065dda37b3981caac60db603638 /webkit | |
parent | 9a96d729a2dbe40bac29ff0fbda0602ea4bf50d5 (diff) | |
download | chromium_src-e2304b0549b35420d17819ede170d06edc339f37.zip chromium_src-e2304b0549b35420d17819ede170d06edc339f37.tar.gz chromium_src-e2304b0549b35420d17819ede170d06edc339f37.tar.bz2 |
Use upstreamed NPV8Object, V8NPObject, and V8NPUtils. And delete webkit/port.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/149779
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@20923 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit')
-rw-r--r-- | webkit/port/bindings/v8/NPV8Object.cpp | 508 | ||||
-rw-r--r-- | webkit/port/bindings/v8/NPV8Object.h | 60 | ||||
-rw-r--r-- | webkit/port/bindings/v8/V8NPObject.cpp | 372 | ||||
-rw-r--r-- | webkit/port/bindings/v8/V8NPObject.h | 78 | ||||
-rw-r--r-- | webkit/port/bindings/v8/V8NPUtils.cpp | 129 | ||||
-rw-r--r-- | webkit/port/bindings/v8/V8NPUtils.h | 46 | ||||
-rw-r--r-- | webkit/port/bindings/v8/v8_npobject.h | 7 | ||||
-rw-r--r-- | webkit/webkit.gyp | 16 |
8 files changed, 0 insertions, 1216 deletions
diff --git a/webkit/port/bindings/v8/NPV8Object.cpp b/webkit/port/bindings/v8/NPV8Object.cpp deleted file mode 100644 index 21501b9..0000000 --- a/webkit/port/bindings/v8/NPV8Object.cpp +++ /dev/null @@ -1,508 +0,0 @@ -/* - * Copyright (C) 2004, 2006 Apple Computer, Inc. All rights reserved. - * Copyright (C) 2007, 2008, 2009 Google, Inc. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. 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 APPLE COMPUTER, INC. ``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 APPLE COMPUTER, INC. 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 "NPV8Object.h" - -#include "ChromiumBridge.h" -#include "DOMWindow.h" -#include "Frame.h" -#include "OwnArrayPtr.h" -#include "PlatformString.h" -#include "ScriptController.h" -#include "V8CustomBinding.h" -#include "V8GCController.h" -#include "V8Helpers.h" -#include "V8NPUtils.h" -#include "V8Proxy.h" -#include "bindings/npruntime.h" -#include "npruntime_priv.h" -#include "wtf/StringExtras.h" - -#include <stdio.h> -#include <v8.h> - -using WebCore::toV8Context; -using WebCore::toV8Proxy; -using WebCore::V8ClassIndex; -using WebCore::V8Custom; -using WebCore::V8DOMWrapper; -using WebCore::V8GCController; -using WebCore::V8Proxy; - -// FIXME: Comments on why use malloc and free. -static NPObject* allocV8NPObject(NPP, NPClass*) -{ - return static_cast<NPObject*>(malloc(sizeof(V8NPObject))); -} - -static void freeV8NPObject(NPObject* npObject) -{ - V8NPObject* v8NpObject = reinterpret_cast<V8NPObject*>(npObject); -#ifndef NDEBUG - V8GCController::unregisterGlobalHandle(v8NpObject, v8NpObject->v8Object); -#endif - v8NpObject->v8Object.Dispose(); - free(v8NpObject); -} - -static v8::Handle<v8::Value>* createValueListFromVariantArgs(const NPVariant* arguments, uint32_t argumentCount, NPObject* owner) -{ - v8::Handle<v8::Value>* argv = new v8::Handle<v8::Value>[argumentCount]; - for (uint32_t index = 0; index < argumentCount; index++) { - const NPVariant* arg = &arguments[index]; - argv[index] = convertNPVariantToV8Object(arg, owner); - } - return argv; -} - -// Create an identifier (null terminated utf8 char*) from the NPIdentifier. -static v8::Local<v8::String> npIdentifierToV8Identifier(NPIdentifier name) -{ - PrivateIdentifier* identifier = static_cast<PrivateIdentifier*>(name); - if (identifier->isString) - return v8::String::New(static_cast<const char*>(identifier->value.string)); - - char buffer[32]; - snprintf(buffer, sizeof(buffer), "%d", identifier->value.number); - return v8::String::New(buffer); -} - -static NPClass V8NPObjectClass = { NP_CLASS_STRUCT_VERSION, - allocV8NPObject, - freeV8NPObject, - 0, 0, 0, 0, 0, 0, 0, 0, 0 }; - -// NPAPI's npruntime functions. -NPClass* npScriptObjectClass = &V8NPObjectClass; - -NPObject* npCreateV8ScriptObject(NPP npp, v8::Handle<v8::Object> object, WebCore::DOMWindow* root) -{ - // Check to see if this object is already wrapped. - if (object->InternalFieldCount() == V8Custom::kNPObjectInternalFieldCount) { - v8::Local<v8::Value> typeIndex = object->GetInternalField(V8Custom::kDOMWrapperTypeIndex); - if (typeIndex->IsNumber() && typeIndex->Uint32Value() == V8ClassIndex::NPOBJECT) { - - NPObject* returnValue = V8DOMWrapper::convertToNativeObject<NPObject>(V8ClassIndex::NPOBJECT, object); - NPN_RetainObject(returnValue); - return returnValue; - } - } - - V8NPObject* v8npObject = reinterpret_cast<V8NPObject*>(NPN_CreateObject(npp, &V8NPObjectClass)); - v8npObject->v8Object = v8::Persistent<v8::Object>::New(object); -#ifndef NDEBUG - V8GCController::registerGlobalHandle(WebCore::NPOBJECT, v8npObject, v8npObject->v8Object); -#endif - v8npObject->rootObject = root; - return reinterpret_cast<NPObject*>(v8npObject); -} - -bool NPN_Invoke(NPP npp, NPObject* npObject, NPIdentifier methodName, const NPVariant* arguments, uint32_t argumentCount, NPVariant* result) -{ - if (!npObject) - return false; - - if (npObject->_class != npScriptObjectClass) { - if (npObject->_class->invoke) - return npObject->_class->invoke(npObject, methodName, arguments, argumentCount, result); - - VOID_TO_NPVARIANT(*result); - return true; - } - - V8NPObject* v8NpObject = reinterpret_cast<V8NPObject*>(npObject); - - PrivateIdentifier* identifier = static_cast<PrivateIdentifier*>(methodName); - if (!identifier->isString) - return false; - - v8::HandleScope handleScope; - // FIXME: should use the plugin's owner frame as the security context. - v8::Handle<v8::Context> context = toV8Context(npp, npObject); - if (context.IsEmpty()) - return false; - - v8::Context::Scope scope(context); - - if (methodName == NPN_GetStringIdentifier("eval")) { - if (argumentCount != 1) - return false; - if (arguments[0].type != NPVariantType_String) - return false; - return NPN_Evaluate(npp, npObject, const_cast<NPString*>(&arguments[0].value.stringValue), result); - } - - v8::Handle<v8::Value> functionObject = v8NpObject->v8Object->Get(v8::String::New(identifier->value.string)); - if (functionObject.IsEmpty() || functionObject->IsNull()) { - NULL_TO_NPVARIANT(*result); - return false; - } - if (functionObject->IsUndefined()) { - VOID_TO_NPVARIANT(*result); - return false; - } - - V8Proxy* proxy = toV8Proxy(npObject); - ASSERT(proxy); - - // Call the function object. - v8::Handle<v8::Function> function = v8::Handle<v8::Function>::Cast(functionObject); - OwnArrayPtr<v8::Handle<v8::Value> > argv(createValueListFromVariantArgs(arguments, argumentCount, npObject)); - v8::Local<v8::Value> resultObject = proxy->callFunction(function, v8NpObject->v8Object, argumentCount, argv.get()); - - // If we had an error, return false. The spec is a little unclear here, but says "Returns true if the method was - // successfully invoked". If we get an error return value, was that successfully invoked? - if (resultObject.IsEmpty()) - return false; - - convertV8ObjectToNPVariant(resultObject, npObject, result); - return true; -} - -// FIXME: Fix it same as NPN_Invoke (HandleScope and such). -bool NPN_InvokeDefault(NPP npp, NPObject* npObject, const NPVariant* arguments, uint32_t argumentCount, NPVariant* result) -{ - if (!npObject) - return false; - - if (npObject->_class != npScriptObjectClass) { - if (npObject->_class->invokeDefault) - return npObject->_class->invokeDefault(npObject, arguments, argumentCount, result); - - VOID_TO_NPVARIANT(*result); - return true; - } - - V8NPObject* v8NpObject = reinterpret_cast<V8NPObject*>(npObject); - - VOID_TO_NPVARIANT(*result); - - v8::HandleScope handleScope; - v8::Handle<v8::Context> context = toV8Context(npp, npObject); - if (context.IsEmpty()) - return false; - - v8::Context::Scope scope(context); - - // Lookup the function object and call it. - v8::Handle<v8::Object> functionObject(v8NpObject->v8Object); - if (!functionObject->IsFunction()) - return false; - - v8::Local<v8::Value> resultObject; - v8::Handle<v8::Function> function(v8::Function::Cast(*functionObject)); - if (!function->IsNull()) { - V8Proxy* proxy = toV8Proxy(npObject); - ASSERT(proxy); - - OwnArrayPtr<v8::Handle<v8::Value> > argv(createValueListFromVariantArgs(arguments, argumentCount, npObject)); - resultObject = proxy->callFunction(function, functionObject, argumentCount, argv.get()); - } - // If we had an error, return false. The spec is a little unclear here, but says "Returns true if the method was - // successfully invoked". If we get an error return value, was that successfully invoked? - if (resultObject.IsEmpty()) - return false; - - convertV8ObjectToNPVariant(resultObject, npObject, result); - return true; -} - -bool NPN_Evaluate(NPP npp, NPObject* npObject, NPString* npScript, NPVariant* result) -{ - bool popupsAllowed = WebCore::ChromiumBridge::popupsAllowed(npp); - return NPN_EvaluateHelper(npp, popupsAllowed, npObject, npScript, result); -} - -bool NPN_EvaluateHelper(NPP npp, bool popupsAllowed, NPObject* npObject, NPString* npScript, NPVariant* result) -{ - VOID_TO_NPVARIANT(*result); - if (!npObject) - return false; - - if (npObject->_class != npScriptObjectClass) - return false; - - v8::HandleScope handleScope; - v8::Handle<v8::Context> context = toV8Context(npp, npObject); - if (context.IsEmpty()) - return false; - - V8Proxy* proxy = toV8Proxy(npObject); - ASSERT(proxy); - - v8::Context::Scope scope(context); - - WebCore::String filename; - if (!popupsAllowed) - filename = "npscript"; - - WebCore::String script = WebCore::String::fromUTF8(npScript->UTF8Characters, npScript->UTF8Length); - v8::Local<v8::Value> v8result = proxy->evaluate(WebCore::ScriptSourceCode(script, WebCore::KURL(filename)), 0); - - if (v8result.IsEmpty()) - return false; - - convertV8ObjectToNPVariant(v8result, npObject, result); - return true; -} - -bool NPN_GetProperty(NPP npp, NPObject* npObject, NPIdentifier propertyName, NPVariant* result) -{ - if (!npObject) - return false; - - if (npObject->_class == npScriptObjectClass) { - V8NPObject* object = reinterpret_cast<V8NPObject*>(npObject); - - v8::HandleScope handleScope; - v8::Handle<v8::Context> context = toV8Context(npp, npObject); - if (context.IsEmpty()) - return false; - - v8::Context::Scope scope(context); - - v8::Handle<v8::Object> obj(object->v8Object); - v8::Local<v8::Value> v8result = obj->Get(npIdentifierToV8Identifier(propertyName)); - - convertV8ObjectToNPVariant(v8result, npObject, result); - return true; - } - - if (npObject->_class->hasProperty && npObject->_class->getProperty) { - if (npObject->_class->hasProperty(npObject, propertyName)) - return npObject->_class->getProperty(npObject, propertyName, result); - } - - VOID_TO_NPVARIANT(*result); - return false; -} - -bool NPN_SetProperty(NPP npp, NPObject* npObject, NPIdentifier propertyName, const NPVariant* value) -{ - if (!npObject) - return false; - - if (npObject->_class == npScriptObjectClass) { - V8NPObject* object = reinterpret_cast<V8NPObject*>(npObject); - - v8::HandleScope handleScope; - v8::Handle<v8::Context> context = toV8Context(npp, npObject); - if (context.IsEmpty()) - return false; - - v8::Context::Scope scope(context); - - v8::Handle<v8::Object> obj(object->v8Object); - obj->Set(npIdentifierToV8Identifier(propertyName), - convertNPVariantToV8Object(value, object->rootObject->frame()->script()->windowScriptNPObject())); - return true; - } - - if (npObject->_class->setProperty) - return npObject->_class->setProperty(npObject, propertyName, value); - - return false; -} - -bool NPN_RemoveProperty(NPP npp, NPObject* npObject, NPIdentifier propertyName) -{ - if (!npObject) - return false; - if (npObject->_class != npScriptObjectClass) - return false; - - V8NPObject* object = reinterpret_cast<V8NPObject*>(npObject); - - v8::HandleScope handleScope; - v8::Handle<v8::Context> context = toV8Context(npp, npObject); - if (context.IsEmpty()) - return false; - v8::Context::Scope scope(context); - - v8::Handle<v8::Object> obj(object->v8Object); - // FIXME: Verify that setting to undefined is right. - obj->Set(npIdentifierToV8Identifier(propertyName), v8::Undefined()); - return true; -} - -bool NPN_HasProperty(NPP npp, NPObject* npObject, NPIdentifier propertyName) -{ - if (!npObject) - return false; - - if (npObject->_class == npScriptObjectClass) { - V8NPObject* object = reinterpret_cast<V8NPObject*>(npObject); - - v8::HandleScope handleScope; - v8::Handle<v8::Context> context = toV8Context(npp, npObject); - if (context.IsEmpty()) - return false; - v8::Context::Scope scope(context); - - v8::Handle<v8::Object> obj(object->v8Object); - return obj->Has(npIdentifierToV8Identifier(propertyName)); - } - - if (npObject->_class->hasProperty) - return npObject->_class->hasProperty(npObject, propertyName); - return false; -} - -bool NPN_HasMethod(NPP npp, NPObject* npObject, NPIdentifier methodName) -{ - if (!npObject) - return false; - - if (npObject->_class == npScriptObjectClass) { - V8NPObject* object = reinterpret_cast<V8NPObject*>(npObject); - - v8::HandleScope handleScope; - v8::Handle<v8::Context> context = toV8Context(npp, npObject); - if (context.IsEmpty()) - return false; - v8::Context::Scope scope(context); - - v8::Handle<v8::Object> obj(object->v8Object); - v8::Handle<v8::Value> prop = obj->Get(npIdentifierToV8Identifier(methodName)); - return prop->IsFunction(); - } - - if (npObject->_class->hasMethod) - return npObject->_class->hasMethod(npObject, methodName); - return false; -} - -void NPN_SetException(NPObject* npObject, const NPUTF8 *message) -{ - if (npObject->_class != npScriptObjectClass) - return; - v8::HandleScope handleScope; - v8::Handle<v8::Context> context = toV8Context(0, npObject); - if (context.IsEmpty()) - return; - - v8::Context::Scope scope(context); - V8Proxy::throwError(V8Proxy::GeneralError, message); -} - -bool NPN_Enumerate(NPP npp, NPObject* npObject, NPIdentifier** identifier, uint32_t* count) -{ - if (!npObject) - return false; - - if (npObject->_class == npScriptObjectClass) { - V8NPObject* object = reinterpret_cast<V8NPObject*>(npObject); - - v8::HandleScope handleScope; - v8::Handle<v8::Context> context = toV8Context(npp, npObject); - if (context.IsEmpty()) - return false; - v8::Context::Scope scope(context); - - v8::Handle<v8::Object> obj(object->v8Object); - - // FIXME: http://b/issue?id=1210340: Use a v8::Object::Keys() method when it exists, instead of evaluating javascript. - - // FIXME: Figure out how to cache this helper function. Run a helper function that collects the properties - // on the object into an array. - const char enumeratorCode[] = - "(function (obj) {" - " var props = [];" - " for (var prop in obj) {" - " props[props.length] = prop;" - " }" - " return props;" - "});"; - v8::Handle<v8::String> source = v8::String::New(enumeratorCode); - v8::Handle<v8::Script> script = v8::Script::Compile(source, 0); - v8::Handle<v8::Value> enumeratorObj = script->Run(); - v8::Handle<v8::Function> enumerator = v8::Handle<v8::Function>::Cast(enumeratorObj); - v8::Handle<v8::Value> argv[] = { obj }; - v8::Local<v8::Value> propsObj = enumerator->Call(v8::Handle<v8::Object>::Cast(enumeratorObj), ARRAYSIZE_UNSAFE(argv), argv); - if (propsObj.IsEmpty()) - return false; - - // Convert the results into an array of NPIdentifiers. - v8::Handle<v8::Array> props = v8::Handle<v8::Array>::Cast(propsObj); - *count = props->Length(); - *identifier = static_cast<NPIdentifier*>(malloc(sizeof(NPIdentifier*) * *count)); - for (uint32_t i = 0; i < *count; ++i) { - v8::Local<v8::Value> name = props->Get(v8::Integer::New(i)); - (*identifier)[i] = getStringIdentifier(v8::Local<v8::String>::Cast(name)); - } - return true; - } - - if (NP_CLASS_STRUCT_VERSION_HAS_ENUM(npObject->_class) && npObject->_class->enumerate) - return npObject->_class->enumerate(npObject, identifier, count); - - return false; -} - -bool NPN_Construct(NPP npp, NPObject* npObject, const NPVariant* arguments, uint32_t argumentCount, NPVariant* result) -{ - if (!npObject) - return false; - - if (npObject->_class == npScriptObjectClass) { - V8NPObject* object = reinterpret_cast<V8NPObject*>(npObject); - - v8::HandleScope handleScope; - v8::Handle<v8::Context> context = toV8Context(npp, npObject); - if (context.IsEmpty()) - return false; - v8::Context::Scope scope(context); - - // Lookup the constructor function. - v8::Handle<v8::Object> ctorObj(object->v8Object); - if (!ctorObj->IsFunction()) - return false; - - // Call the constructor. - v8::Local<v8::Value> resultObject; - v8::Handle<v8::Function> ctor(v8::Function::Cast(*ctorObj)); - if (!ctor->IsNull()) { - V8Proxy* proxy = toV8Proxy(npObject); - ASSERT(proxy); - - OwnArrayPtr<v8::Handle<v8::Value> > argv(createValueListFromVariantArgs(arguments, argumentCount, npObject)); - resultObject = proxy->newInstance(ctor, argumentCount, argv.get()); - } - - if (resultObject.IsEmpty()) - return false; - - convertV8ObjectToNPVariant(resultObject, npObject, result); - return true; - } - - if (NP_CLASS_STRUCT_VERSION_HAS_CTOR(npObject->_class) && npObject->_class->construct) - return npObject->_class->construct(npObject, arguments, argumentCount, result); - - return false; -} diff --git a/webkit/port/bindings/v8/NPV8Object.h b/webkit/port/bindings/v8/NPV8Object.h deleted file mode 100644 index 65a7ccf..0000000 --- a/webkit/port/bindings/v8/NPV8Object.h +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright (C) 2006, 2007, 2008, 2009 Google Inc. All rights reserved. - * - * 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. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "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 NPV8Object_h -#define NPV8Object_h - -#include "bindings/npruntime.h" -#include <v8.h> - -namespace WebCore { - class DOMWindow; -} - -extern NPClass* npScriptObjectClass; - -// A V8NPObject is a NPObject which carries additional V8-specific information. It is allocated and deallocated by -// AllocV8NPObject() and FreeV8NPObject() methods. -struct V8NPObject { - NPObject object; - v8::Persistent<v8::Object> v8Object; - WebCore::DOMWindow* rootObject; -}; - -struct PrivateIdentifier { - union { - const NPUTF8* string; - int32_t number; - } value; - bool isString; -}; - -NPObject* npCreateV8ScriptObject(NPP, v8::Handle<v8::Object>, WebCore::DOMWindow*); - -#endif // NPV8Object_h diff --git a/webkit/port/bindings/v8/V8NPObject.cpp b/webkit/port/bindings/v8/V8NPObject.cpp deleted file mode 100644 index 572290c..0000000 --- a/webkit/port/bindings/v8/V8NPObject.cpp +++ /dev/null @@ -1,372 +0,0 @@ -/* -* Copyright (C) 2006, 2007, 2008, 2009 Google Inc. All rights reserved. -* -* 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. -* * Neither the name of Google Inc. nor the names of its -* contributors may be used to endorse or promote products derived from -* this software without specific prior written permission. -* -* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -* "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 "V8NPObject.h" - -#include "HTMLPlugInElement.h" -#include "npruntime_priv.h" -#include "NPV8Object.h" -#include "V8CustomBinding.h" -#include "V8DOMMap.h" -#include "V8Helpers.h" -#include "V8HTMLAppletElement.h" -#include "V8HTMLEmbedElement.h" -#include "V8HTMLObjectElement.h" -#include "V8NPUtils.h" -#include "V8Proxy.h" -#include "wtf/OwnArrayPtr.h" - -using namespace WebCore; - -enum InvokeFunctionType { - INVOKE_METHOD = 1, - INVOKE_CONSTRUCT = 2, - INVOKE_DEFAULT = 3 -}; - -// FIXME: need comments. -// Params: holder could be HTMLEmbedElement or NPObject -static v8::Handle<v8::Value> npObjectInvokeImpl(const v8::Arguments& args, InvokeFunctionType functionId) -{ - NPObject* npObject; - - // These three types are subtypes of HTMLPlugInElement. - if (V8HTMLAppletElement::HasInstance(args.Holder()) || V8HTMLEmbedElement::HasInstance(args.Holder()) - || V8HTMLObjectElement::HasInstance(args.Holder())) { - // The holder object is a subtype of HTMLPlugInElement. - HTMLPlugInElement* element = V8DOMWrapper::convertDOMWrapperToNode<HTMLPlugInElement>(args.Holder()); - ScriptInstance scriptInstance = element->getInstance(); - if (scriptInstance) - npObject = V8DOMWrapper::convertToNativeObject<NPObject>(V8ClassIndex::NPOBJECT, scriptInstance->instance()); - else - npObject = 0; - } else { - // The holder object is not a subtype of HTMLPlugInElement, it - // must be an NPObject which has three internal fields. - if (args.Holder()->InternalFieldCount() != V8Custom::kNPObjectInternalFieldCount) - return throwError("NPMethod called on non-NPObject", V8Proxy::ReferenceError); - - npObject = V8DOMWrapper::convertToNativeObject<NPObject>(V8ClassIndex::NPOBJECT, args.Holder()); - } - - // Verify that our wrapper wasn't using a NPObject which - // has already been deleted. - if (!npObject || !_NPN_IsAlive(npObject)) - return throwError("NPObject deleted", V8Proxy::ReferenceError); - - // Wrap up parameters. - int numArgs = args.Length(); - OwnArrayPtr<NPVariant> npArgs(new NPVariant[numArgs]); - - for (int i = 0; i < numArgs; i++) - convertV8ObjectToNPVariant(args[i], npObject, &npArgs[i]); - - NPVariant result; - VOID_TO_NPVARIANT(result); - - switch (functionId) { - case INVOKE_METHOD: - if (npObject->_class->invoke) { - v8::Handle<v8::String> functionName(v8::String::Cast(*args.Data())); - NPIdentifier identifier = getStringIdentifier(functionName); - npObject->_class->invoke(npObject, identifier, npArgs.get(), numArgs, &result); - } - break; - case INVOKE_CONSTRUCT: - if (npObject->_class->construct) - npObject->_class->construct(npObject, npArgs.get(), numArgs, &result); - break; - case INVOKE_DEFAULT: - if (npObject->_class->invokeDefault) - npObject->_class->invokeDefault(npObject, npArgs.get(), numArgs, &result); - break; - default: - break; - } - - for (int i=0; i < numArgs; i++) - NPN_ReleaseVariantValue(&npArgs[i]); - - // Unwrap return values. - v8::Handle<v8::Value> returnValue = convertNPVariantToV8Object(&result, npObject); - NPN_ReleaseVariantValue(&result); - - return returnValue; -} - - -v8::Handle<v8::Value> npObjectMethodHandler(const v8::Arguments& args) -{ - return npObjectInvokeImpl(args, INVOKE_METHOD); -} - - -v8::Handle<v8::Value> npObjectInvokeDefaultHandler(const v8::Arguments& args) -{ - if (args.IsConstructCall()) - return npObjectInvokeImpl(args, INVOKE_CONSTRUCT); - else - return npObjectInvokeImpl(args, INVOKE_DEFAULT); -} - - -static void weakTemplateCallback(v8::Persistent<v8::Value>, void* parameter); - -// NPIdentifier is PrivateIdentifier*. -static WeakReferenceMap<PrivateIdentifier, v8::FunctionTemplate> staticTemplateMap(&weakTemplateCallback); - -static void weakTemplateCallback(v8::Persistent<v8::Value> object, void* parameter) -{ - PrivateIdentifier* identifier = static_cast<PrivateIdentifier*>(parameter); - ASSERT(identifier); - ASSERT(staticTemplateMap.contains(identifier)); - - staticTemplateMap.forget(identifier); -} - - -static v8::Handle<v8::Value> npObjectGetProperty(v8::Local<v8::Object> self, - NPIdentifier identifier, - v8::Local<v8::Value> key) -{ - NPObject* npObject = V8DOMWrapper::convertToNativeObject<NPObject>(V8ClassIndex::NPOBJECT, self); - - // Verify that our wrapper wasn't using a NPObject which - // has already been deleted. - if (!npObject || !_NPN_IsAlive(npObject)) - return throwError("NPObject deleted", V8Proxy::ReferenceError); - - - if (npObject->_class->hasProperty && npObject->_class->hasProperty(npObject, identifier) - && npObject->_class->getProperty) { - - NPVariant result; - VOID_TO_NPVARIANT(result); - if (!npObject->_class->getProperty(npObject, identifier, &result)) - return v8::Handle<v8::Value>(); - - v8::Handle<v8::Value> returnValue = convertNPVariantToV8Object(&result, npObject); - NPN_ReleaseVariantValue(&result); - return returnValue; - - } else if (key->IsString() && npObject->_class->hasMethod && npObject->_class->hasMethod(npObject, identifier)) { - PrivateIdentifier* id = static_cast<PrivateIdentifier*>(identifier); - v8::Persistent<v8::FunctionTemplate> functionTemplate = staticTemplateMap.get(id); - // Cache templates using identifier as the key. - if (functionTemplate.IsEmpty()) { - // Create a new template. - v8::Local<v8::FunctionTemplate> temp = v8::FunctionTemplate::New(); - temp->SetCallHandler(npObjectMethodHandler, key); - functionTemplate = v8::Persistent<v8::FunctionTemplate>::New(temp); - staticTemplateMap.set(id, functionTemplate); - } - - // FunctionTemplate caches function for each context. - v8::Local<v8::Function> v8Function = functionTemplate->GetFunction(); - v8Function->SetName(v8::Handle<v8::String>::Cast(key)); - return v8Function; - } - - return v8::Handle<v8::Value>(); -} - -v8::Handle<v8::Value> npObjectNamedPropertyGetter(v8::Local<v8::String> name, - const v8::AccessorInfo& info) -{ - NPIdentifier identifier = getStringIdentifier(name); - return npObjectGetProperty(info.Holder(), identifier, name); -} - -v8::Handle<v8::Value> npObjectIndexedPropertyGetter(uint32_t index, - const v8::AccessorInfo& info) -{ - NPIdentifier identifier = NPN_GetIntIdentifier(index); - return npObjectGetProperty(info.Holder(), identifier, v8::Number::New(index)); -} - -v8::Handle<v8::Value> npObjectGetNamedProperty(v8::Local<v8::Object> self, - v8::Local<v8::String> name) -{ - NPIdentifier identifier = getStringIdentifier(name); - return npObjectGetProperty(self, identifier, name); -} - -v8::Handle<v8::Value> npObjectGetIndexedProperty(v8::Local<v8::Object> self, - uint32_t index) -{ - NPIdentifier identifier = NPN_GetIntIdentifier(index); - return npObjectGetProperty(self, identifier, v8::Number::New(index)); -} - -static v8::Handle<v8::Value> npObjectSetProperty(v8::Local<v8::Object> self, - NPIdentifier identifier, - v8::Local<v8::Value> value) -{ - NPObject* npObject = V8DOMWrapper::convertToNativeObject<NPObject>(V8ClassIndex::NPOBJECT, self); - - // Verify that our wrapper wasn't using a NPObject which - // has already been deleted. - if (!npObject || !_NPN_IsAlive(npObject)) { - throwError("NPObject deleted", V8Proxy::ReferenceError); - return value; // Intercepted, but an exception was thrown. - } - - if (npObject->_class->hasProperty && npObject->_class->hasProperty(npObject, identifier) - && npObject->_class->setProperty) { - - NPVariant npValue; - VOID_TO_NPVARIANT(npValue); - convertV8ObjectToNPVariant(value, npObject, &npValue); - bool success = npObject->_class->setProperty(npObject, identifier, &npValue); - NPN_ReleaseVariantValue(&npValue); - if (success) - return value; // Intercept the call. - } - return v8::Local<v8::Value>(); // Do not intercept the call. -} - - -v8::Handle<v8::Value> npObjectNamedPropertySetter(v8::Local<v8::String> name, - v8::Local<v8::Value> value, - const v8::AccessorInfo& info) -{ - NPIdentifier identifier = getStringIdentifier(name); - return npObjectSetProperty(info.Holder(), identifier, value); -} - - -v8::Handle<v8::Value> npObjectIndexedPropertySetter(uint32_t index, - v8::Local<v8::Value> value, - const v8::AccessorInfo& info) -{ - NPIdentifier identifier = NPN_GetIntIdentifier(index); - return npObjectSetProperty(info.Holder(), identifier, value); -} - -v8::Handle<v8::Value> npObjectSetNamedProperty(v8::Local<v8::Object> self, - v8::Local<v8::String> name, - v8::Local<v8::Value> value) -{ - NPIdentifier identifier = getStringIdentifier(name); - return npObjectSetProperty(self, identifier, value); -} - -v8::Handle<v8::Value> npObjectSetIndexedProperty(v8::Local<v8::Object> self, - uint32_t index, - v8::Local<v8::Value> value) -{ - NPIdentifier identifier = NPN_GetIntIdentifier(index); - return npObjectSetProperty(self, identifier, value); -} - - -static void weakNPObjectCallback(v8::Persistent<v8::Value>, void* parameter); - -static DOMWrapperMap<NPObject> staticNPObjectMap(&weakNPObjectCallback); - -static void weakNPObjectCallback(v8::Persistent<v8::Value> object, void* parameter) -{ - NPObject* npObject = static_cast<NPObject*>(parameter); - ASSERT(staticNPObjectMap.contains(npObject)); - ASSERT(npObject); - - // Must remove from our map before calling NPN_ReleaseObject(). - // NPN_ReleaseObject can call ForgetV8ObjectForNPObject, which - // uses the table as well. - staticNPObjectMap.forget(npObject); - - if (_NPN_IsAlive(npObject)) - NPN_ReleaseObject(npObject); -} - - -v8::Local<v8::Object> createV8ObjectForNPObject(NPObject* object, NPObject* root) -{ - static v8::Persistent<v8::FunctionTemplate> npObjectDesc; - - ASSERT(v8::Context::InContext()); - - // If this is a v8 object, just return it. - if (object->_class == npScriptObjectClass) { - V8NPObject* v8NPObject = reinterpret_cast<V8NPObject*>(object); - return v8::Local<v8::Object>::New(v8NPObject->v8Object); - } - - // If we've already wrapped this object, just return it. - if (staticNPObjectMap.contains(object)) - return v8::Local<v8::Object>::New(staticNPObjectMap.get(object)); - - // FIXME: we should create a Wrapper type as a subclass of JSObject. - // It has two internal fields, field 0 is the wrapped pointer, - // and field 1 is the type. There should be an api function that - // returns unused type id. - // The same Wrapper type can be used by DOM bindings. - if (npObjectDesc.IsEmpty()) { - npObjectDesc = v8::Persistent<v8::FunctionTemplate>::New(v8::FunctionTemplate::New()); - npObjectDesc->InstanceTemplate()->SetInternalFieldCount(V8Custom::kNPObjectInternalFieldCount); - npObjectDesc->InstanceTemplate()->SetNamedPropertyHandler(npObjectNamedPropertyGetter, npObjectNamedPropertySetter); - npObjectDesc->InstanceTemplate()->SetIndexedPropertyHandler(npObjectIndexedPropertyGetter, npObjectIndexedPropertySetter); - npObjectDesc->InstanceTemplate()->SetCallAsFunctionHandler(npObjectInvokeDefaultHandler); - } - - v8::Handle<v8::Function> v8Function = npObjectDesc->GetFunction(); - v8::Local<v8::Object> value = SafeAllocation::newInstance(v8Function); - - // If we were unable to allocate the instance, we avoid wrapping - // and registering the NP object. - if (value.IsEmpty()) - return value; - - wrapNPObject(value, object); - - // KJS retains the object as part of its wrapper (see Bindings::CInstance). - NPN_RetainObject(object); - - _NPN_RegisterObject(object, root); - - // Maintain a weak pointer for v8 so we can cleanup the object. - v8::Persistent<v8::Object> weakRef = v8::Persistent<v8::Object>::New(value); - staticNPObjectMap.set(object, weakRef); - - return value; -} - -void forgetV8ObjectForNPObject(NPObject* object) -{ - if (staticNPObjectMap.contains(object)) { - v8::HandleScope scope; - v8::Persistent<v8::Object> handle(staticNPObjectMap.get(object)); - V8DOMWrapper::setDOMWrapper(handle, WebCore::V8ClassIndex::NPOBJECT, 0); - staticNPObjectMap.forget(object); - NPN_ReleaseObject(object); - } -} diff --git a/webkit/port/bindings/v8/V8NPObject.h b/webkit/port/bindings/v8/V8NPObject.h deleted file mode 100644 index 607cb0c..0000000 --- a/webkit/port/bindings/v8/V8NPObject.h +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright (C) 2006, 2007, 2008, 2009 Google Inc. All rights reserved. - * - * 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. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "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 V8NPObject_h -#define V8NPObject_h - -#include <v8.h> -#include "third_party/npapi/bindings/npruntime.h" - -// FIXME: Remove these #defines when upstreamed. They are needed to compile -// some currently upstreamed files which will need to be modified when this -// file is upstreamed. -#define NPObjectGetNamedProperty npObjectGetNamedProperty -#define NPObjectSetNamedProperty npObjectSetNamedProperty -#define NPObjectInvokeDefaultHandler npObjectInvokeDefaultHandler -#define NPObjectGetIndexedProperty npObjectGetIndexedProperty -#define NPObjectSetIndexedProperty npObjectSetIndexedProperty -#define CreateV8ObjectForNPObject createV8ObjectForNPObject - -// These functions can be replaced by normal JS operation. -// Getters -v8::Handle<v8::Value> npObjectNamedPropertyGetter(v8::Local<v8::String> name, const v8::AccessorInfo&); -v8::Handle<v8::Value> npObjectIndexedPropertyGetter(uint32_t index, const v8::AccessorInfo&); -v8::Handle<v8::Value> npObjectGetNamedProperty(v8::Local<v8::Object> self, v8::Local<v8::String> name); -v8::Handle<v8::Value> npObjectGetIndexedProperty(v8::Local<v8::Object> self, uint32_t index); - -// Setters -v8::Handle<v8::Value> npObjectNamedPropertySetter(v8::Local<v8::String> name, v8::Local<v8::Value>, const v8::AccessorInfo&); -v8::Handle<v8::Value> npObjectIndexedPropertySetter(uint32_t index, const v8::AccessorInfo&); -v8::Handle<v8::Value> npObjectSetNamedProperty(v8::Local<v8::Object> self, v8::Local<v8::String> name, v8::Local<v8::Value>); -v8::Handle<v8::Value> npObjectSetIndexedProperty(v8::Local<v8::Object> self, uint32_t index, v8::Local<v8::Value>); - -v8::Handle<v8::Value> npObjectInvokeDefaultHandler(const v8::Arguments&); - -// Get a wrapper for a NPObject. -// If the object is already wrapped, the pre-existing wrapper -// will be returned. -// If the object is not wrapped, wrap it, and give V8 a weak -// reference to the wrapper which will cleanup when there are -// no more JS references to the object. -v8::Local<v8::Object> createV8ObjectForNPObject(NPObject*, NPObject* root); - -// Tell V8 to forcibly remove an object. -// This is used at plugin teardown so that the caller can -// aggressively unload the plugin library. After calling this -// function, the persistent handle to the wrapper will be -// gone, and the wrapped NPObject will be removed so that -// it cannot be referred to. -void forgetV8ObjectForNPObject(NPObject*); - -#endif // V8NPObject_h diff --git a/webkit/port/bindings/v8/V8NPUtils.cpp b/webkit/port/bindings/v8/V8NPUtils.cpp deleted file mode 100644 index e92db12..0000000 --- a/webkit/port/bindings/v8/V8NPUtils.cpp +++ /dev/null @@ -1,129 +0,0 @@ -/* - * Copyright (C) 2008, 2009 Google Inc. All rights reserved. - * - * 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. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "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 "V8NPUtils.h" - -#include "DOMWindow.h" -#include "Frame.h" -#include "PlatformString.h" -#undef LOG - -#include "NPV8Object.h" -#include "V8NPObject.h" -#include "V8Proxy.h" -#include "npruntime_priv.h" - -void convertV8ObjectToNPVariant(v8::Local<v8::Value> object, NPObject* owner, NPVariant* result) -{ - VOID_TO_NPVARIANT(*result); - - // It is really the caller's responsibility to deal with the empty handle case because there could be different actions to - // take in different contexts. - ASSERT(!object.IsEmpty()); - - if (object.IsEmpty()) - return; - - if (object->IsInt32()) - INT32_TO_NPVARIANT(object->NumberValue(), *result); - else if (object->IsNumber()) - DOUBLE_TO_NPVARIANT(object->NumberValue(), *result); - else if (object->IsBoolean()) - BOOLEAN_TO_NPVARIANT(object->BooleanValue(), *result); - else if (object->IsNull()) - NULL_TO_NPVARIANT(*result); - else if (object->IsUndefined()) - VOID_TO_NPVARIANT(*result); - else if (object->IsString()) { - v8::String::Utf8Value utf8(object); - char* utf8_chars = strdup(*utf8); - STRINGN_TO_NPVARIANT(utf8_chars, utf8.length(), *result); - } else if (object->IsObject()) { - WebCore::DOMWindow* window = WebCore::V8Proxy::retrieveWindow(); - NPObject* npobject = npCreateV8ScriptObject(0, v8::Handle<v8::Object>::Cast(object), window); - if (npobject) - _NPN_RegisterObject(npobject, owner); - OBJECT_TO_NPVARIANT(npobject, *result); - } -} - - -v8::Handle<v8::Value> convertNPVariantToV8Object(const NPVariant* variant, NPObject* npobject) -{ - NPVariantType type = variant->type; - - switch (type) { - case NPVariantType_Int32: - return v8::Integer::New(NPVARIANT_TO_INT32(*variant)); - case NPVariantType_Double: - return v8::Number::New(NPVARIANT_TO_DOUBLE(*variant)); - case NPVariantType_Bool: - return NPVARIANT_TO_BOOLEAN(*variant) ? v8::True() : v8::False(); - case NPVariantType_Null: - return v8::Null(); - case NPVariantType_Void: - return v8::Undefined(); - case NPVariantType_String: { - NPString src = NPVARIANT_TO_STRING(*variant); - return v8::String::New(src.UTF8Characters, src.UTF8Length); - } - case NPVariantType_Object: { - NPObject* obj = NPVARIANT_TO_OBJECT(*variant); - if (obj->_class == npScriptObjectClass) - return reinterpret_cast<V8NPObject*>(obj)->v8Object; - return createV8ObjectForNPObject(obj, npobject); - } - default: - return v8::Undefined(); - } -} - -// Helper function to create an NPN String Identifier from a v8 string. -NPIdentifier getStringIdentifier(v8::Handle<v8::String> str) -{ - const int kStackBufferSize = 100; - - int bufferLength = str->Length() + 1; - if (bufferLength <= kStackBufferSize) { - // Use local stack buffer to avoid heap allocations for small strings. Here we should only use the stack space for - // stackBuffer when it's used, not when we use the heap. - // - // WriteAscii is guaranteed to generate a null-terminated string because bufferLength is constructed to be one greater - // than the string length. - char stackBuffer[kStackBufferSize]; - str->WriteAscii(stackBuffer, 0, bufferLength); - return NPN_GetStringIdentifier(stackBuffer); - } - - v8::String::AsciiValue ascii(str); - return NPN_GetStringIdentifier(*ascii); -} diff --git a/webkit/port/bindings/v8/V8NPUtils.h b/webkit/port/bindings/v8/V8NPUtils.h deleted file mode 100644 index 82a74b3..0000000 --- a/webkit/port/bindings/v8/V8NPUtils.h +++ /dev/null @@ -1,46 +0,0 @@ -/* Copyright (C) 2006, 2007, 2008, 2009 Google Inc. All rights reserved. - * - * 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. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "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 V8NPUtils_h -#define V8NPUtils_h - -#include <v8.h> -#include "third_party/npapi/bindings/npruntime.h" - -// Convert a V8 Value of any type (string, bool, object, etc) to a NPVariant. -void convertV8ObjectToNPVariant(v8::Local<v8::Value>, NPObject*, NPVariant*); - -// Convert a NPVariant (string, bool, object, etc) back to a V8 Value. The owner object is the NPObject which relates to the -// object, if the object is an Object. The created NPObject will be tied to the lifetime of the owner. -v8::Handle<v8::Value> convertNPVariantToV8Object(const NPVariant*, NPObject*); - -// Helper function to create an NPN String Identifier from a v8 string. -NPIdentifier getStringIdentifier(v8::Handle<v8::String>); - -#endif // V8NPUtils_h diff --git a/webkit/port/bindings/v8/v8_npobject.h b/webkit/port/bindings/v8/v8_npobject.h deleted file mode 100644 index c2d8550..0000000 --- a/webkit/port/bindings/v8/v8_npobject.h +++ /dev/null @@ -1,7 +0,0 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// This is a temporary file until V8HTMLPlugInElementCustom.cpp in WebKit -// includes the new name of this file. -#include "V8NPObject.h" diff --git a/webkit/webkit.gyp b/webkit/webkit.gyp index 52c33ff..db0c323 100644 --- a/webkit/webkit.gyp +++ b/webkit/webkit.gyp @@ -557,7 +557,6 @@ '<(INTERMEDIATE_DIR)', '<(SHARED_INTERMEDIATE_DIR)/webkit', '<(SHARED_INTERMEDIATE_DIR)/webkit/bindings', - 'port/bindings/v8', '<@(webcore_include_dirs)', ], 'sources': [ @@ -587,12 +586,6 @@ 'extensions/v8/profiler_extension.h', 'extensions/v8/benchmarking_extension.cc', 'extensions/v8/benchmarking_extension.h', - 'port/bindings/v8/NPV8Object.cpp', - 'port/bindings/v8/NPV8Object.h', - 'port/bindings/v8/V8NPUtils.cpp', - 'port/bindings/v8/V8NPUtils.h', - 'port/bindings/v8/V8NPObject.cpp', - 'port/bindings/v8/V8NPObject.h', # For WebCoreSystemInterface, Mac-only. '../third_party/WebKit/WebKit/mac/WebCoreSupport/WebSystemInterface.m', @@ -716,20 +709,11 @@ '../third_party/WebKit/WebCore/platform/graphics/RenderLayerBacking.cpp', '../third_party/WebKit/WebCore/platform/graphics/RenderLayerCompositor.cpp', - # Temporary exclusion to avoid needing a 2-sided commit. - # TODO(ajwong): Delete after we roll-down the WebCore.gypi update. - '../third_party/WebKit/WebCore/bindings/v8/NPV8Object.cpp', - '../third_party/WebKit/WebCore/bindings/v8/NPV8Object.h', - '../third_party/WebKit/WebCore/bindings/v8/V8NPUtils.cpp', - '../third_party/WebKit/WebCore/bindings/v8/V8NPUtils.h', - '../third_party/WebKit/WebCore/bindings/v8/V8NPObject.cpp', - '../third_party/WebKit/WebCore/bindings/v8/V8NPObject.h', ], 'direct_dependent_settings': { 'include_dirs': [ '<(SHARED_INTERMEDIATE_DIR)/webkit', '<(SHARED_INTERMEDIATE_DIR)/webkit/bindings', - 'port/bindings/v8', '<@(webcore_include_dirs)', ], 'mac_framework_dirs': [ |