diff options
Diffstat (limited to 'webkit')
-rw-r--r-- | webkit/port/bindings/v8/V8NPObject.cpp | 355 | ||||
-rw-r--r-- | webkit/port/bindings/v8/V8NPObject.h | 85 | ||||
-rw-r--r-- | webkit/port/bindings/v8/V8NPUtils.cpp | 2 | ||||
-rw-r--r-- | webkit/port/bindings/v8/npruntime.cpp | 4 |
4 files changed, 231 insertions, 215 deletions
diff --git a/webkit/port/bindings/v8/V8NPObject.cpp b/webkit/port/bindings/v8/V8NPObject.cpp index 508502b..8d3a518 100644 --- a/webkit/port/bindings/v8/V8NPObject.cpp +++ b/webkit/port/bindings/v8/V8NPObject.cpp @@ -1,46 +1,49 @@ -// Copyright (c) 2008, 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. +/* +* 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 "v8_custom.h" -#include "v8_helpers.h" #include "V8NPObject.h" -#include "V8NPUtils.h" -#include "NPV8Object.h" + +#include "HTMLPlugInElement.h" #include "npruntime_priv.h" -#include "v8_proxy.h" +#include "NPV8Object.h" +#include "V8CustomBinding.h" #include "V8DOMMap.h" -#include "HTMLPlugInElement.h" #include "V8HTMLAppletElement.h" #include "V8HTMLEmbedElement.h" #include "V8HTMLObjectElement.h" +#include "V8NPUtils.h" +#include "V8Proxy.h" +#include "v8_helpers.h" +#include "wtf/OwnArrayPtr.h" using namespace WebCore; @@ -50,275 +53,263 @@ enum InvokeFunctionType { INVOKE_DEFAULT = 3 }; -// TODO(mbelshe): need comments. +// FIXME: need comments. // Params: holder could be HTMLEmbedElement or NPObject -static v8::Handle<v8::Value> NPObjectInvokeImpl(const v8::Arguments& args, InvokeFunctionType funcId) +static v8::Handle<v8::Value> npObjectInvokeImpl(const v8::Arguments& args, InvokeFunctionType functionId) { - NPObject* npobject; + NPObject* npObject; // These three types are subtypes of HTMLPlugInElement. - if (V8HTMLAppletElement::HasInstance(args.Holder()) || - V8HTMLEmbedElement::HasInstance(args.Holder()) || - V8HTMLObjectElement::HasInstance(args.Holder())) { + if (V8HTMLAppletElement::HasInstance(args.Holder()) || V8HTMLEmbedElement::HasInstance(args.Holder()) + || V8HTMLObjectElement::HasInstance(args.Holder())) { // The holder object is a subtype of HTMLPlugInElement. - HTMLPlugInElement* imp = V8Proxy::DOMWrapperToNode<HTMLPlugInElement>(args.Holder()); - ScriptInstance scriptInstance = imp->getInstance(); + HTMLPlugInElement* element = V8Proxy::DOMWrapperToNode<HTMLPlugInElement>(args.Holder()); + ScriptInstance scriptInstance = element->getInstance(); if (scriptInstance) - npobject = V8Proxy::ToNativeObject<NPObject>(V8ClassIndex::NPOBJECT, scriptInstance->instance()); + npObject = V8Proxy::ToNativeObject<NPObject>(V8ClassIndex::NPOBJECT, scriptInstance->instance()); else - npobject = NULL; + 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) { - V8Proxy::ThrowError(V8Proxy::REFERENCE_ERROR, "NPMethod called on non-NPObject"); - return v8::Undefined(); - } - npobject = V8Proxy::ToNativeObject<NPObject>(V8ClassIndex::NPOBJECT, args.Holder()); + if (args.Holder()->InternalFieldCount() != V8Custom::kNPObjectInternalFieldCount) + return throwError("NPMethod called on non-NPObject", V8Proxy::REFERENCE_ERROR); + + npObject = V8Proxy::ToNativeObject<NPObject>(V8ClassIndex::NPOBJECT, args.Holder()); } // Verify that our wrapper wasn't using a NPObject which // has already been deleted. - if (!npobject || !_NPN_IsAlive(npobject)) { - V8Proxy::ThrowError(V8Proxy::REFERENCE_ERROR, "NPObject deleted"); - return v8::Undefined(); - } + if (!npObject || !_NPN_IsAlive(npObject)) + return throwError("NPObject deleted", V8Proxy::REFERENCE_ERROR); - // wrap up parameters - int argc = args.Length(); - NPVariant* npArgs = new NPVariant[argc]; + // Wrap up parameters. + int numArgs = args.Length(); + OwnArrayPtr<NPVariant> npArgs(new NPVariant[numArgs]); - for (int i = 0; i < argc; i++) - convertV8ObjectToNPVariant(args[i], npobject, &npArgs[i]); + for (int i = 0; i < numArgs; i++) + convertV8ObjectToNPVariant(args[i], npObject, &npArgs[i]); NPVariant result; VOID_TO_NPVARIANT(result); - switch (funcId) { + switch (functionId) { case INVOKE_METHOD: - if (npobject->_class->invoke) { - v8::Handle<v8::String> function_name(v8::String::Cast(*args.Data())); - NPIdentifier ident = getStringIdentifier(function_name); - npobject->_class->invoke(npobject, ident, npArgs, argc, &result); + 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, argc, &result); + 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, argc, &result); + if (npObject->_class->invokeDefault) + npObject->_class->invokeDefault(npObject, npArgs.get(), numArgs, &result); break; default: break; } - for (int i=0; i < argc; i++) + for (int i=0; i < numArgs; i++) NPN_ReleaseVariantValue(&npArgs[i]); - delete[] npArgs; - // unwrap return values - v8::Handle<v8::Value> rv = convertNPVariantToV8Object(&result, npobject); + // Unwrap return values. + v8::Handle<v8::Value> returnValue = convertNPVariantToV8Object(&result, npObject); NPN_ReleaseVariantValue(&result); - return rv; + return returnValue; } -v8::Handle<v8::Value> NPObjectMethodHandler(const v8::Arguments& args) +v8::Handle<v8::Value> npObjectMethodHandler(const v8::Arguments& args) { - return NPObjectInvokeImpl(args, INVOKE_METHOD); + return npObjectInvokeImpl(args, INVOKE_METHOD); } -v8::Handle<v8::Value> NPObjectInvokeDefaultHandler(const v8::Arguments& args) +v8::Handle<v8::Value> npObjectInvokeDefaultHandler(const v8::Arguments& args) { if (args.IsConstructCall()) - return NPObjectInvokeImpl(args, INVOKE_CONSTRUCT); + return npObjectInvokeImpl(args, INVOKE_CONSTRUCT); else - return NPObjectInvokeImpl(args, INVOKE_DEFAULT); + return npObjectInvokeImpl(args, INVOKE_DEFAULT); } -static void WeakTemplateCallback(v8::Persistent<v8::Value> obj, void* param); +static void weakTemplateCallback(v8::Persistent<v8::Value>, void* parameter); // NPIdentifier is PrivateIdentifier*. -static WeakReferenceMap<PrivateIdentifier, v8::FunctionTemplate> \ - static_template_map(&WeakTemplateCallback); +static WeakReferenceMap<PrivateIdentifier, v8::FunctionTemplate> staticTemplateMap(&weakTemplateCallback); -static void WeakTemplateCallback(v8::Persistent<v8::Value> obj, void* param) +static void weakTemplateCallback(v8::Persistent<v8::Value> object, void* parameter) { - PrivateIdentifier* iden = static_cast<PrivateIdentifier*>(param); - ASSERT(iden != NULL); - ASSERT(static_template_map.contains(iden)); + PrivateIdentifier* identifier = static_cast<PrivateIdentifier*>(parameter); + ASSERT(identifier); + ASSERT(staticTemplateMap.contains(identifier)); - static_template_map.forget(iden); + staticTemplateMap.forget(identifier); } -static v8::Handle<v8::Value> NPObjectGetProperty(v8::Local<v8::Object> self, - NPIdentifier ident, +static v8::Handle<v8::Value> npObjectGetProperty(v8::Local<v8::Object> self, + NPIdentifier identifier, v8::Local<v8::Value> key) { - NPObject* npobject = V8Proxy::ToNativeObject<NPObject>(V8ClassIndex::NPOBJECT, self); + NPObject* npObject = V8Proxy::ToNativeObject<NPObject>(V8ClassIndex::NPOBJECT, self); // Verify that our wrapper wasn't using a NPObject which // has already been deleted. - if (!npobject || !_NPN_IsAlive(npobject)) { - V8Proxy::ThrowError(V8Proxy::REFERENCE_ERROR, "NPObject deleted"); - return v8::Handle<v8::Value>(); - } + if (!npObject || !_NPN_IsAlive(npObject)) + return throwError("NPObject deleted", V8Proxy::REFERENCE_ERROR); + - if (npobject->_class->hasProperty && - npobject->_class->hasProperty(npobject, ident) && - npobject->_class->getProperty) { + if (npObject->_class->hasProperty && npObject->_class->hasProperty(npObject, identifier) + && npObject->_class->getProperty) { NPVariant result; VOID_TO_NPVARIANT(result); - if (!npobject->_class->getProperty(npobject, ident, &result)) + if (!npObject->_class->getProperty(npObject, identifier, &result)) return v8::Handle<v8::Value>(); - v8::Handle<v8::Value> rv = convertNPVariantToV8Object(&result, npobject); + v8::Handle<v8::Value> returnValue = convertNPVariantToV8Object(&result, npObject); NPN_ReleaseVariantValue(&result); - return rv; + return returnValue; - } else if (key->IsString() && - npobject->_class->hasMethod && - npobject->_class->hasMethod(npobject, ident)) { - - PrivateIdentifier* id = static_cast<PrivateIdentifier*>(ident); - v8::Persistent<v8::FunctionTemplate> desc = static_template_map.get(id); + } 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 (desc.IsEmpty()) { - // Create a new template + if (functionTemplate.IsEmpty()) { + // Create a new template. v8::Local<v8::FunctionTemplate> temp = v8::FunctionTemplate::New(); - temp->SetCallHandler(NPObjectMethodHandler, key); - desc = v8::Persistent<v8::FunctionTemplate>::New(temp); - static_template_map.set(id, desc); + 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> func = desc->GetFunction(); - func->SetName(v8::Handle<v8::String>::Cast(key)); - return func; + 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, +v8::Handle<v8::Value> npObjectNamedPropertyGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info) { - NPIdentifier ident = getStringIdentifier(name); - return NPObjectGetProperty(info.Holder(), ident, name); + NPIdentifier identifier = getStringIdentifier(name); + return npObjectGetProperty(info.Holder(), identifier, name); } -v8::Handle<v8::Value> NPObjectIndexedPropertyGetter(uint32_t index, +v8::Handle<v8::Value> npObjectIndexedPropertyGetter(uint32_t index, const v8::AccessorInfo& info) { - NPIdentifier ident = NPN_GetIntIdentifier(index); - return NPObjectGetProperty(info.Holder(), ident, v8::Number::New(index)); + 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::Handle<v8::Value> npObjectGetNamedProperty(v8::Local<v8::Object> self, v8::Local<v8::String> name) { - NPIdentifier ident = getStringIdentifier(name); - return NPObjectGetProperty(self, ident, name); + NPIdentifier identifier = getStringIdentifier(name); + return npObjectGetProperty(self, identifier, name); } -v8::Handle<v8::Value> NPObjectGetIndexedProperty(v8::Local<v8::Object> self, +v8::Handle<v8::Value> npObjectGetIndexedProperty(v8::Local<v8::Object> self, uint32_t index) { - NPIdentifier ident = NPN_GetIntIdentifier(index); - return NPObjectGetProperty(self, ident, v8::Number::New(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 ident, +static v8::Handle<v8::Value> npObjectSetProperty(v8::Local<v8::Object> self, + NPIdentifier identifier, v8::Local<v8::Value> value) { - NPObject* npobject = V8Proxy::ToNativeObject<NPObject>(V8ClassIndex::NPOBJECT, self); + NPObject* npObject = V8Proxy::ToNativeObject<NPObject>(V8ClassIndex::NPOBJECT, self); // Verify that our wrapper wasn't using a NPObject which // has already been deleted. - if (!npobject || !_NPN_IsAlive(npobject)) { - V8Proxy::ThrowError(V8Proxy::REFERENCE_ERROR, "NPObject deleted"); - return value; // intercepted, but an exception was thrown + if (!npObject || !_NPN_IsAlive(npObject)) { + throwError("NPObject deleted", V8Proxy::REFERENCE_ERROR); + return value; // Intercepted, but an exception was thrown. } - if (npobject->_class->hasProperty && - npobject->_class->hasProperty(npobject, ident) && - npobject->_class->setProperty) { - - NPVariant npvalue; - VOID_TO_NPVARIANT(npvalue); - convertV8ObjectToNPVariant(value, npobject, &npvalue); - bool succ = npobject->_class->setProperty(npobject, ident, &npvalue); - NPN_ReleaseVariantValue(&npvalue); - if (succ) - return value; // intercept the call + 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 + return v8::Local<v8::Value>(); // Do not intercept the call. } -v8::Handle<v8::Value> NPObjectNamedPropertySetter(v8::Local<v8::String> name, +v8::Handle<v8::Value> npObjectNamedPropertySetter(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::AccessorInfo& info) { - NPIdentifier ident = getStringIdentifier(name); - return NPObjectSetProperty(info.Holder(), ident, value); + NPIdentifier identifier = getStringIdentifier(name); + return npObjectSetProperty(info.Holder(), identifier, value); } -v8::Handle<v8::Value> NPObjectIndexedPropertySetter(uint32_t index, +v8::Handle<v8::Value> npObjectIndexedPropertySetter(uint32_t index, v8::Local<v8::Value> value, const v8::AccessorInfo& info) { - NPIdentifier ident = NPN_GetIntIdentifier(index); - return NPObjectSetProperty(info.Holder(), ident, value); + NPIdentifier identifier = NPN_GetIntIdentifier(index); + return npObjectSetProperty(info.Holder(), identifier, value); } -v8::Handle<v8::Value> NPObjectSetNamedProperty(v8::Local<v8::Object> self, +v8::Handle<v8::Value> npObjectSetNamedProperty(v8::Local<v8::Object> self, v8::Local<v8::String> name, v8::Local<v8::Value> value) { - NPIdentifier ident = getStringIdentifier(name); - return NPObjectSetProperty(self, ident, value); + NPIdentifier identifier = getStringIdentifier(name); + return npObjectSetProperty(self, identifier, value); } -v8::Handle<v8::Value> NPObjectSetIndexedProperty(v8::Local<v8::Object> self, +v8::Handle<v8::Value> npObjectSetIndexedProperty(v8::Local<v8::Object> self, uint32_t index, v8::Local<v8::Value> value) { - NPIdentifier ident = NPN_GetIntIdentifier(index); - return NPObjectSetProperty(self, ident, value); + NPIdentifier identifier = NPN_GetIntIdentifier(index); + return npObjectSetProperty(self, identifier, value); } -static void WeakNPObjectCallback(v8::Persistent<v8::Value> obj, void* param); +static void weakNPObjectCallback(v8::Persistent<v8::Value>, void* parameter); -static DOMWrapperMap<NPObject> staticNpobjectMap(&WeakNPObjectCallback); +static DOMWrapperMap<NPObject> staticNPObjectMap(&weakNPObjectCallback); -static void WeakNPObjectCallback(v8::Persistent<v8::Value> obj, void* param) +static void weakNPObjectCallback(v8::Persistent<v8::Value> object, void* parameter) { - NPObject* npobject = static_cast<NPObject*>(param); - ASSERT(staticNpobjectMap.contains(npobject)); - ASSERT(npobject != NULL); + 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); + staticNPObjectMap.forget(npObject); - if (_NPN_IsAlive(npobject)) - NPN_ReleaseObject(npobject); + if (_NPN_IsAlive(npObject)) + NPN_ReleaseObject(npObject); } -v8::Local<v8::Object> CreateV8ObjectForNPObject(NPObject* object, NPObject* root) +v8::Local<v8::Object> createV8ObjectForNPObject(NPObject* object, NPObject* root) { static v8::Persistent<v8::FunctionTemplate> npObjectDesc; @@ -326,15 +317,15 @@ v8::Local<v8::Object> CreateV8ObjectForNPObject(NPObject* object, NPObject* root // 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); + 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)); + if (staticNPObjectMap.contains(object)) + return v8::Local<v8::Object>::New(staticNPObjectMap.get(object)); - // TODO: we should create a Wrapper type as a subclass of JSObject. + // 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. @@ -342,40 +333,40 @@ v8::Local<v8::Object> CreateV8ObjectForNPObject(NPObject* object, NPObject* root 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); + npObjectDesc->InstanceTemplate()->SetNamedPropertyHandler(npObjectNamedPropertyGetter, npObjectNamedPropertySetter); + npObjectDesc->InstanceTemplate()->SetIndexedPropertyHandler(npObjectIndexedPropertyGetter, npObjectIndexedPropertySetter); + npObjectDesc->InstanceTemplate()->SetCallAsFunctionHandler(npObjectInvokeDefaultHandler); } - v8::Handle<v8::Function> func = npObjectDesc->GetFunction(); - v8::Local<v8::Object> value = SafeAllocation::NewInstance(func); + 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 + // 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) + // 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); + staticNPObjectMap.set(object, weakRef); return value; } -void ForgetV8ObjectForNPObject(NPObject* object) +void forgetV8ObjectForNPObject(NPObject* object) { - if (staticNpobjectMap.contains(object)) { + if (staticNPObjectMap.contains(object)) { v8::HandleScope scope; - v8::Persistent<v8::Object> handle(staticNpobjectMap.get(object)); - WebCore::V8Proxy::SetDOMWrapper(handle, WebCore::V8ClassIndex::NPOBJECT, NULL); - staticNpobjectMap.forget(object); + v8::Persistent<v8::Object> handle(staticNPObjectMap.get(object)); + WebCore::V8Proxy::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 index c236c60..607cb0c 100644 --- a/webkit/port/bindings/v8/V8NPObject.h +++ b/webkit/port/bindings/v8/V8NPObject.h @@ -1,38 +1,63 @@ -// 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. +/* + * 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 v8_npobject_h -#define v8_npobject_h +#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& info); -v8::Handle<v8::Value> NPObjectIndexedPropertyGetter(uint32_t index, - const v8::AccessorInfo& info); -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); +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> value, - const v8::AccessorInfo& info); -v8::Handle<v8::Value> NPObjectIndexedPropertySetter(uint32_t index, - const v8::AccessorInfo& info); -v8::Handle<v8::Value> NPObjectSetNamedProperty(v8::Local<v8::Object> self, - v8::Local<v8::String> name, - v8::Local<v8::Value> value); -v8::Handle<v8::Value> NPObjectSetIndexedProperty(v8::Local<v8::Object> self, - uint32_t index, - v8::Local<v8::Value> value); - -v8::Handle<v8::Value> NPObjectInvokeDefaultHandler(const v8::Arguments& args); +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 @@ -40,14 +65,14 @@ v8::Handle<v8::Value> NPObjectInvokeDefaultHandler(const v8::Arguments& args); // 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* object, NPObject *root); +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 +// 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*object); +void forgetV8ObjectForNPObject(NPObject*); -#endif // v8_npobject_h +#endif // V8NPObject_h diff --git a/webkit/port/bindings/v8/V8NPUtils.cpp b/webkit/port/bindings/v8/V8NPUtils.cpp index 04e6ede..3a68288 100644 --- a/webkit/port/bindings/v8/V8NPUtils.cpp +++ b/webkit/port/bindings/v8/V8NPUtils.cpp @@ -99,7 +99,7 @@ v8::Handle<v8::Value> convertNPVariantToV8Object(const NPVariant* variant, NPObj NPObject* obj = NPVARIANT_TO_OBJECT(*variant); if (obj->_class == npScriptObjectClass) return reinterpret_cast<V8NPObject*>(obj)->v8Object; - return CreateV8ObjectForNPObject(obj, npobject); + return createV8ObjectForNPObject(obj, npobject); } return v8::Undefined(); } diff --git a/webkit/port/bindings/v8/npruntime.cpp b/webkit/port/bindings/v8/npruntime.cpp index c120959..6a2faeb 100644 --- a/webkit/port/bindings/v8/npruntime.cpp +++ b/webkit/port/bindings/v8/npruntime.cpp @@ -411,7 +411,7 @@ void _NPN_UnregisterObject(NPObject* obj) { g_live_objects.remove(sub_object); // Remove the JS references to the object. - ForgetV8ObjectForNPObject(sub_object); + forgetV8ObjectForNPObject(sub_object); ASSERT(set->size() < size); } @@ -427,7 +427,7 @@ void _NPN_UnregisterObject(NPObject* obj) { } g_live_objects.remove(obj); - ForgetV8ObjectForNPObject(obj); + forgetV8ObjectForNPObject(obj); } bool _NPN_IsAlive(NPObject* obj) { |