diff options
author | The Android Open Source Project <initial-contribution@android.com> | 2009-03-03 18:28:41 -0800 |
---|---|---|
committer | The Android Open Source Project <initial-contribution@android.com> | 2009-03-03 18:28:41 -0800 |
commit | 648161bb0edfc3d43db63caed5cc5213bc6cb78f (patch) | |
tree | 4b825dc642cb6eb9a060e54bf8d69288fbee4904 /WebCore/bridge/c | |
parent | a65af38181ac7d34544586bdb5cd004de93897ad (diff) | |
download | external_webkit-648161bb0edfc3d43db63caed5cc5213bc6cb78f.zip external_webkit-648161bb0edfc3d43db63caed5cc5213bc6cb78f.tar.gz external_webkit-648161bb0edfc3d43db63caed5cc5213bc6cb78f.tar.bz2 |
auto import from //depot/cupcake/@135843
Diffstat (limited to 'WebCore/bridge/c')
-rw-r--r-- | WebCore/bridge/c/c_class.cpp | 124 | ||||
-rw-r--r-- | WebCore/bridge/c/c_class.h | 61 | ||||
-rw-r--r-- | WebCore/bridge/c/c_instance.cpp | 246 | ||||
-rw-r--r-- | WebCore/bridge/c/c_instance.h | 86 | ||||
-rw-r--r-- | WebCore/bridge/c/c_runtime.cpp | 145 | ||||
-rw-r--r-- | WebCore/bridge/c/c_runtime.h | 72 | ||||
-rw-r--r-- | WebCore/bridge/c/c_utility.cpp | 152 | ||||
-rw-r--r-- | WebCore/bridge/c/c_utility.h | 76 |
8 files changed, 0 insertions, 962 deletions
diff --git a/WebCore/bridge/c/c_class.cpp b/WebCore/bridge/c/c_class.cpp deleted file mode 100644 index 1b72476..0000000 --- a/WebCore/bridge/c/c_class.cpp +++ /dev/null @@ -1,124 +0,0 @@ -/* - * Copyright (C) 2003, 2006 Apple Computer, 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" - -#if ENABLE(NETSCAPE_PLUGIN_API) - -#include "c_class.h" - -#include "c_instance.h" -#include "c_runtime.h" -#include "npruntime_impl.h" -#include <kjs/identifier.h> -#include <runtime/JSLock.h> - -namespace JSC { namespace Bindings { - -CClass::CClass(NPClass* aClass) -{ - _isa = aClass; -} - -CClass::~CClass() -{ - JSLock lock(false); - - deleteAllValues(_methods); - _methods.clear(); - - deleteAllValues(_fields); - _fields.clear(); -} - -typedef HashMap<NPClass*, CClass*> ClassesByIsAMap; -static ClassesByIsAMap* classesByIsA = 0; - -CClass* CClass::classForIsA(NPClass* isa) -{ - if (!classesByIsA) - classesByIsA = new ClassesByIsAMap; - - CClass* aClass = classesByIsA->get(isa); - if (!aClass) { - aClass = new CClass(isa); - classesByIsA->set(isa, aClass); - } - - return aClass; -} - -const char* CClass::name() const -{ - return ""; -} - -MethodList CClass::methodsNamed(const Identifier& identifier, Instance* instance) const -{ - MethodList methodList; - - Method* method = _methods.get(identifier.ustring().rep()); - if (method) { - methodList.append(method); - return methodList; - } - - NPIdentifier ident = _NPN_GetStringIdentifier(identifier.ascii()); - const CInstance* inst = static_cast<const CInstance*>(instance); - NPObject* obj = inst->getObject(); - if (_isa->hasMethod && _isa->hasMethod(obj, ident)){ - Method* aMethod = new CMethod(ident); // deleted in the CClass destructor - { - JSLock lock(false); - _methods.set(identifier.ustring().rep(), aMethod); - } - methodList.append(aMethod); - } - - return methodList; -} - -Field* CClass::fieldNamed(const Identifier& identifier, Instance* instance) const -{ - Field* aField = _fields.get(identifier.ustring().rep()); - if (aField) - return aField; - - NPIdentifier ident = _NPN_GetStringIdentifier(identifier.ascii()); - const CInstance* inst = static_cast<const CInstance*>(instance); - NPObject* obj = inst->getObject(); - if (_isa->hasProperty && _isa->hasProperty(obj, ident)){ - aField = new CField(ident); // deleted in the CClass destructor - { - JSLock lock(false); - _fields.set(identifier.ustring().rep(), aField); - } - } - return aField; -} - -} } // namespace JSC::Bindings - -#endif // ENABLE(NETSCAPE_PLUGIN_API) diff --git a/WebCore/bridge/c/c_class.h b/WebCore/bridge/c/c_class.h deleted file mode 100644 index 9a08605..0000000 --- a/WebCore/bridge/c/c_class.h +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright (C) 2003 Apple Computer, 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. - */ - -#ifndef BINDINGS_C_CLASS_H_ -#define BINDINGS_C_CLASS_H_ - -#if ENABLE(NETSCAPE_PLUGIN_API) - -#include "npruntime_internal.h" -#include "runtime.h" -#include <wtf/HashMap.h> - -namespace JSC { -namespace Bindings { - -class CClass : public Class { -protected: - CClass(NPClass*); // Use classForIsA to create a CClass. - -public: - static CClass* classForIsA(NPClass*); - virtual ~CClass(); - - virtual const char* name() const; - virtual MethodList methodsNamed(const Identifier&, Instance*) const; - virtual Field* fieldNamed(const Identifier&, Instance*) const; - -private: - NPClass* _isa; - mutable MethodMap _methods; - mutable FieldMap _fields; -}; - -} // namespace Bindings -} // namespace JSC - -#endif // ENABLE(NETSCAPE_PLUGIN_API) - -#endif diff --git a/WebCore/bridge/c/c_instance.cpp b/WebCore/bridge/c/c_instance.cpp deleted file mode 100644 index 79ae520..0000000 --- a/WebCore/bridge/c/c_instance.cpp +++ /dev/null @@ -1,246 +0,0 @@ -/* - * Copyright (C) 2003, 2006 Apple Computer, 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" - -#if ENABLE(NETSCAPE_PLUGIN_API) - -#include "c_instance.h" - -#include "c_class.h" -#include "c_runtime.h" -#include "c_utility.h" -#include "npruntime_impl.h" -#include "runtime_root.h" -#include <runtime/ArgList.h> -#include <runtime/ExecState.h> -#include <runtime/JSLock.h> -#include <runtime/JSNumberCell.h> -#include <runtime/PropertyNameArray.h> -#include <wtf/Assertions.h> -#include <wtf/StringExtras.h> -#include <wtf/Vector.h> - -namespace JSC { -namespace Bindings { - -CInstance::CInstance(NPObject* o, PassRefPtr<RootObject> rootObject) - : Instance(rootObject) -{ - _object = _NPN_RetainObject(o); - _class = 0; -} - -CInstance::~CInstance() -{ - _NPN_ReleaseObject(_object); -} - -Class *CInstance::getClass() const -{ - if (!_class) - _class = CClass::classForIsA(_object->_class); - return _class; -} - -bool CInstance::supportsInvokeDefaultMethod() const -{ - return _object->_class->invokeDefault; -} - -JSValue* CInstance::invokeMethod(ExecState* exec, const MethodList& methodList, const ArgList& args) -{ - // Overloading methods are not allowed by NPObjects. Should only be one - // name match for a particular method. - ASSERT(methodList.size() == 1); - - CMethod* method = static_cast<CMethod*>(methodList[0]); - - NPIdentifier ident = _NPN_GetStringIdentifier(method->name()); - if (!_object->_class->hasMethod(_object, ident)) - return jsUndefined(); - - unsigned count = args.size(); - Vector<NPVariant, 8> cArgs(count); - - unsigned i; - for (i = 0; i < count; i++) - convertValueToNPVariant(exec, args.at(exec, i), &cArgs[i]); - - // Invoke the 'C' method. -#ifdef ANDROID_NPN_SETEXCEPTION - SetGlobalException(0); -#endif - NPVariant resultVariant; - VOID_TO_NPVARIANT(resultVariant); - - { - JSLock::DropAllLocks dropAllLocks(false); - _object->_class->invoke(_object, ident, cArgs.data(), count, &resultVariant); - } - - for (i = 0; i < count; i++) - _NPN_ReleaseVariantValue(&cArgs[i]); - - JSValue* resultValue = convertNPVariantToValue(exec, &resultVariant, _rootObject.get()); - _NPN_ReleaseVariantValue(&resultVariant); -#ifdef ANDROID_NPN_SETEXCEPTION - MoveGlobalExceptionToExecState(exec); -#endif - return resultValue; -} - - -JSValue* CInstance::invokeDefaultMethod(ExecState* exec, const ArgList& args) -{ - if (!_object->_class->invokeDefault) - return jsUndefined(); - - unsigned count = args.size(); - Vector<NPVariant, 8> cArgs(count); - - unsigned i; - for (i = 0; i < count; i++) - convertValueToNPVariant(exec, args.at(exec, i), &cArgs[i]); - - // Invoke the 'C' method. -#ifdef ANDROID_NPN_SETEXCEPTION - SetGlobalException(0); -#endif - NPVariant resultVariant; - VOID_TO_NPVARIANT(resultVariant); - { - JSLock::DropAllLocks dropAllLocks(false); - _object->_class->invokeDefault(_object, cArgs.data(), count, &resultVariant); - } - - for (i = 0; i < count; i++) - _NPN_ReleaseVariantValue(&cArgs[i]); - - JSValue* resultValue = convertNPVariantToValue(exec, &resultVariant, _rootObject.get()); - _NPN_ReleaseVariantValue(&resultVariant); -#ifdef ANDROID_NPN_SETEXCEPTION - MoveGlobalExceptionToExecState(exec); -#endif - return resultValue; -} - -bool CInstance::supportsConstruct() const -{ - return _object->_class->construct; -} - -JSValue* CInstance::invokeConstruct(ExecState* exec, const ArgList& args) -{ - if (!_object->_class->construct) - return jsUndefined(); - - unsigned count = args.size(); - Vector<NPVariant, 8> cArgs(count); - - unsigned i; - for (i = 0; i < count; i++) - convertValueToNPVariant(exec, args.at(exec, i), &cArgs[i]); - - // Invoke the 'C' method. - NPVariant resultVariant; - VOID_TO_NPVARIANT(resultVariant); - { - JSLock::DropAllLocks dropAllLocks(false); - _object->_class->construct(_object, cArgs.data(), count, &resultVariant); - } - - for (i = 0; i < count; i++) - _NPN_ReleaseVariantValue(&cArgs[i]); - - JSValue* resultValue = convertNPVariantToValue(exec, &resultVariant, _rootObject.get()); - _NPN_ReleaseVariantValue(&resultVariant); - return resultValue; -} - -JSValue* CInstance::defaultValue(ExecState* exec, PreferredPrimitiveType hint) const -{ - if (hint == PreferString) - return stringValue(exec); - if (hint == PreferNumber) - return numberValue(exec); - return valueOf(exec); -} - -JSValue* CInstance::stringValue(ExecState* exec) const -{ - char buf[1024]; - snprintf(buf, sizeof(buf), "NPObject %p, NPClass %p", _object, _object->_class); - return jsString(exec, buf); -} - -JSValue* CInstance::numberValue(ExecState* exec) const -{ - // FIXME: Implement something sensible. - return jsNumber(exec, 0); -} - -JSValue* CInstance::booleanValue() const -{ - // FIXME: Implement something sensible. - return jsBoolean(false); -} - -JSValue* CInstance::valueOf(ExecState* exec) const -{ - return stringValue(exec); -} - -void CInstance::getPropertyNames(ExecState* exec, PropertyNameArray& nameArray) -{ - if (!NP_CLASS_STRUCT_VERSION_HAS_ENUM(_object->_class) || !_object->_class->enumerate) - return; - - uint32_t count; - NPIdentifier* identifiers; - - { - JSLock::DropAllLocks dropAllLocks(false); - if (!_object->_class->enumerate(_object, &identifiers, &count)) - return; - } - - for (uint32_t i = 0; i < count; i++) { - PrivateIdentifier* identifier = static_cast<PrivateIdentifier*>(identifiers[i]); - - if (identifier->isString) - nameArray.add(identifierFromNPIdentifier(identifier->value.string)); - else - nameArray.add(Identifier::from(exec, identifier->value.number)); - } - - // FIXME: This should really call NPN_MemFree but that's in WebKit - free(identifiers); -} - -} -} - -#endif // ENABLE(NETSCAPE_PLUGIN_API) diff --git a/WebCore/bridge/c/c_instance.h b/WebCore/bridge/c/c_instance.h deleted file mode 100644 index 6cc4b8d..0000000 --- a/WebCore/bridge/c/c_instance.h +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright (C) 2003 Apple Computer, 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. - */ - -#ifndef BINDINGS_C_INSTANCE_H_ -#define BINDINGS_C_INSTANCE_H_ - -#if ENABLE(NETSCAPE_PLUGIN_API) - -#include "runtime.h" -#include <wtf/PassRefPtr.h> -#include "runtime_root.h" - -typedef struct NPObject NPObject; - -namespace JSC { - -namespace Bindings { - -class CClass; - -class CInstance : public Instance { -public: - static PassRefPtr<CInstance> create(NPObject* object, PassRefPtr<RootObject> rootObject) - { - return adoptRef(new CInstance(object, rootObject)); - } - ~CInstance (); - - virtual Class *getClass() const; - - virtual JSValue* valueOf(ExecState*) const; - virtual JSValue* defaultValue(ExecState*, PreferredPrimitiveType) const; - - virtual JSValue* invokeMethod(ExecState*, const MethodList&, const ArgList&); - virtual bool supportsInvokeDefaultMethod() const; - virtual JSValue* invokeDefaultMethod(ExecState*, const ArgList&); - - virtual bool supportsConstruct() const; - virtual JSValue* invokeConstruct(ExecState*, const ArgList&); - - virtual void getPropertyNames(ExecState*, PropertyNameArray&); - - JSValue* stringValue(ExecState*) const; - JSValue* numberValue(ExecState*) const; - JSValue* booleanValue() const; - - NPObject *getObject() const { return _object; } - - virtual BindingLanguage getBindingLanguage() const { return CLanguage; } - -private: - CInstance(NPObject*, PassRefPtr<RootObject>); - - mutable CClass *_class; - NPObject *_object; -}; - -} // namespace Bindings - -} // namespace JSC - -#endif // ENABLE(NETSCAPE_PLUGIN_API) - -#endif diff --git a/WebCore/bridge/c/c_runtime.cpp b/WebCore/bridge/c/c_runtime.cpp deleted file mode 100644 index 7cf5dc9..0000000 --- a/WebCore/bridge/c/c_runtime.cpp +++ /dev/null @@ -1,145 +0,0 @@ -/* - * Copyright (C) 2004 Apple Computer, 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" - -#if ENABLE(NETSCAPE_PLUGIN_API) - -#include "c_runtime.h" - -#include "c_instance.h" -#include "c_utility.h" -#include "npruntime_impl.h" -#ifdef ANDROID_NPN_SETEXCEPTION -#include "runtime/Error.h" -#endif // ANDROID_NPN_SETEXCEPTION -#include <runtime/JSLock.h> - -namespace JSC { -namespace Bindings { - -#ifdef ANDROID_NPN_SETEXCEPTION -/* - * When throwing an exception, we need to use the current ExecState. - * The following two methods implement a similar solution to the - * Objective-C implementation, where _NPN_SetException set a global - * exception (using SetGlobalException). - * We then test (using MoveGlobalExceptionToExecState) if the exception - * is set, after each javascript call that might result in an exception. - * If the exception is set we throw it with the passed ExecState. - */ - -static UString* globalLastException = 0; - -void SetGlobalException(const NPUTF8* exception) -{ - if (globalLastException != 0) { - delete globalLastException; - globalLastException = 0; - } - if (exception != 0) - globalLastException = new UString(exception); -} - -void MoveGlobalExceptionToExecState(ExecState* exec) -{ - if (!globalLastException) - return; - JSLock lock(exec); - throwError(exec, GeneralError, *globalLastException); - SetGlobalException(0); -} -#endif // ANDROID_NPN_SETEXCEPTION - -// ---------------------- CMethod ---------------------- - -const char* CMethod::name() const -{ - PrivateIdentifier *i = (PrivateIdentifier *)_methodIdentifier; - return i->isString ? i->value.string : 0; -} - -// ---------------------- CField ---------------------- - -const char* CField::name() const -{ - PrivateIdentifier *i = (PrivateIdentifier *)_fieldIdentifier; - return i->isString ? i->value.string : 0; -} - -JSValue* CField::valueFromInstance(ExecState* exec, const Instance* inst) const -{ - const CInstance* instance = static_cast<const CInstance*>(inst); - NPObject* obj = instance->getObject(); - if (obj->_class->getProperty) { - NPVariant property; - VOID_TO_NPVARIANT(property); - -#ifdef ANDROID_NPN_SETEXCEPTION - SetGlobalException(0); -#endif // ANDROID_NPN_SETEXCEPTION - bool result; - { - JSLock::DropAllLocks dropAllLocks(false); - result = obj->_class->getProperty(obj, _fieldIdentifier, &property); - } -#ifdef ANDROID_NPN_SETEXCEPTION - MoveGlobalExceptionToExecState(exec); -#endif // ANDROID_NPN_SETEXCEPTION - if (result) { - JSValue* result = convertNPVariantToValue(exec, &property, instance->rootObject()); - _NPN_ReleaseVariantValue(&property); - return result; - } - } - return jsUndefined(); -} - -void CField::setValueToInstance(ExecState *exec, const Instance *inst, JSValue* aValue) const -{ - const CInstance* instance = static_cast<const CInstance*>(inst); - NPObject* obj = instance->getObject(); - if (obj->_class->setProperty) { - NPVariant variant; - convertValueToNPVariant(exec, aValue, &variant); - -#ifdef ANDROID_NPN_SETEXCEPTION - SetGlobalException(0); -#endif // ANDROID_NPN_SETEXCEPTION - { - JSLock::DropAllLocks dropAllLocks(false); - obj->_class->setProperty(obj, _fieldIdentifier, &variant); - } - - _NPN_ReleaseVariantValue(&variant); -#ifdef ANDROID_NPN_SETEXCEPTION - MoveGlobalExceptionToExecState(exec); -#endif // ANDROID_NPN_SETEXCEPTION - } -} - -} } - -#endif // ENABLE(NETSCAPE_PLUGIN_API) diff --git a/WebCore/bridge/c/c_runtime.h b/WebCore/bridge/c/c_runtime.h deleted file mode 100644 index 998e6d4..0000000 --- a/WebCore/bridge/c/c_runtime.h +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright (C) 2004, 2006 Apple Computer, 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. - */ - -#ifndef BINDINGS_C_RUNTIME_H_ -#define BINDINGS_C_RUNTIME_H_ - -#if ENABLE(NETSCAPE_PLUGIN_API) - -#include "npruntime_internal.h" -#include "runtime.h" - -namespace JSC { -namespace Bindings { - -class CField : public Field { -public: - CField(NPIdentifier ident) : _fieldIdentifier(ident) { } - - virtual JSValue* valueFromInstance(ExecState*, const Instance*) const; - virtual void setValueToInstance(ExecState*, const Instance*, JSValue*) const; - virtual const char* name() const; - -private: - NPIdentifier _fieldIdentifier; -}; - - -class CMethod : public Method -{ -public: - CMethod(NPIdentifier ident) : _methodIdentifier(ident) { } - - virtual const char* name() const; - virtual int numParameters() const { return 0; } - -private: - NPIdentifier _methodIdentifier; -}; - -#ifdef ANDROID_NPN_SETEXCEPTION -void SetGlobalException(const NPUTF8* exception); -void MoveGlobalExceptionToExecState(ExecState* exec); -#endif // ANDROID_NPN_SETEXCEPTION - -} // namespace Bindings -} // namespace JSC - -#endif // ENABLE(NETSCAPE_PLUGIN_API) - -#endif diff --git a/WebCore/bridge/c/c_utility.cpp b/WebCore/bridge/c/c_utility.cpp deleted file mode 100644 index dced048..0000000 --- a/WebCore/bridge/c/c_utility.cpp +++ /dev/null @@ -1,152 +0,0 @@ -/* - * Copyright (C) 2004, 2006 Apple Computer, Inc. All rights reserved. - * Copyright (C) 2006 Alexey Proskuryakov (ap@nypop.com) - * - * 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" - -#if ENABLE(NETSCAPE_PLUGIN_API) - -#include "c_utility.h" - -#include "JSDOMWindow.h" -#include "NP_jsobject.h" -#include "c_instance.h" -#include <runtime/JSGlobalObject.h> -#include <runtime/JSLock.h> -#include "PlatformString.h" -#include "npruntime_impl.h" -#include "npruntime_priv.h" -#include "runtime_object.h" -#include "runtime_root.h" -#include <wtf/Assertions.h> - -using WebCore::String; - -namespace JSC { namespace Bindings { - -static String convertUTF8ToUTF16WithLatin1Fallback(const NPUTF8* UTF8Chars, int UTF8Length) -{ - ASSERT(UTF8Chars || UTF8Length == 0); - - if (UTF8Length == -1) - UTF8Length = static_cast<int>(strlen(UTF8Chars)); - - String result = String::fromUTF8(UTF8Chars, UTF8Length); - - // If we got back a null string indicating an unsuccessful conversion, fall back to latin 1. - // Some plugins return invalid UTF-8 in NPVariantType_String, see <http://bugs.webkit.org/show_bug.cgi?id=5163> - // There is no "bad data" for latin1. It is unlikely that the plugin was really sending text in this encoding, - // but it should have used UTF-8, and now we are simply avoiding a crash. - if (result.isNull()) - result = String(UTF8Chars, UTF8Length); - - return result; -} - -// Variant value must be released with NPReleaseVariantValue() -void convertValueToNPVariant(ExecState* exec, JSValue* value, NPVariant* result) -{ - JSLock lock(false); - - VOID_TO_NPVARIANT(*result); - - if (value->isString()) { - UString ustring = value->toString(exec); - CString cstring = ustring.UTF8String(); - NPString string = { (const NPUTF8*)cstring.c_str(), static_cast<uint32_t>(cstring.size()) }; - NPN_InitializeVariantWithStringCopy(result, &string); - } else if (value->isNumber()) { - DOUBLE_TO_NPVARIANT(value->toNumber(exec), *result); - } else if (value->isBoolean()) { - BOOLEAN_TO_NPVARIANT(value->toBoolean(exec), *result); - } else if (value->isNull()) { - NULL_TO_NPVARIANT(*result); - } else if (value->isObject()) { - JSObject* object = asObject(value); - if (object->classInfo() == &RuntimeObjectImp::s_info) { - RuntimeObjectImp* imp = static_cast<RuntimeObjectImp*>(object); - CInstance* instance = static_cast<CInstance*>(imp->getInternalInstance()); - if (instance) { - NPObject* obj = instance->getObject(); - _NPN_RetainObject(obj); - OBJECT_TO_NPVARIANT(obj, *result); - } - } else { - JSGlobalObject* globalObject = exec->dynamicGlobalObject(); - - RootObject* rootObject = findRootObject(globalObject); - if (rootObject) { - NPObject* npObject = _NPN_CreateScriptObject(0, object, rootObject); - OBJECT_TO_NPVARIANT(npObject, *result); - } - } - } -} - -JSValue* convertNPVariantToValue(ExecState* exec, const NPVariant* variant, RootObject* rootObject) -{ - JSLock lock(false); - - NPVariantType type = variant->type; - - if (type == NPVariantType_Bool) - return jsBoolean(NPVARIANT_TO_BOOLEAN(*variant)); - if (type == NPVariantType_Null) - return jsNull(); - if (type == NPVariantType_Void) - return jsUndefined(); - if (type == NPVariantType_Int32) - return jsNumber(exec, NPVARIANT_TO_INT32(*variant)); - if (type == NPVariantType_Double) - return jsNumber(exec, NPVARIANT_TO_DOUBLE(*variant)); - if (type == NPVariantType_String) - return jsString(exec, convertNPStringToUTF16(&variant->value.stringValue)); - if (type == NPVariantType_Object) { - NPObject* obj = variant->value.objectValue; - - if (obj->_class == NPScriptObjectClass) - // Get JSObject from NP_JavaScriptObject. - return ((JavaScriptObject*)obj)->imp; - - // Wrap NPObject in a CInstance. - return Instance::createRuntimeObject(exec, CInstance::create(obj, rootObject)); - } - - return jsUndefined(); -} - -String convertNPStringToUTF16(const NPString* string) -{ - return convertUTF8ToUTF16WithLatin1Fallback(string->UTF8Characters, string->UTF8Length); -} - -Identifier identifierFromNPIdentifier(const NPUTF8* name) -{ - return Identifier(WebCore::JSDOMWindow::commonJSGlobalData(), convertUTF8ToUTF16WithLatin1Fallback(name, -1)); -} - -} } - -#endif // ENABLE(NETSCAPE_PLUGIN_API) diff --git a/WebCore/bridge/c/c_utility.h b/WebCore/bridge/c/c_utility.h deleted file mode 100644 index 1e0dd22..0000000 --- a/WebCore/bridge/c/c_utility.h +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright (C) 2004 Apple Computer, 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. - */ - -#ifndef C_UTILITY_H_ -#define C_UTILITY_H_ - -#if ENABLE(NETSCAPE_PLUGIN_API) - -#include "npruntime_internal.h" -#include <runtime/JSValue.h> - -namespace WebCore { - class String; -} - -namespace JSC { - -class ExecState; -class Identifier; - -namespace Bindings { - -class RootObject; - -typedef uint16_t NPUTF16; - -enum NP_ValueType { - NP_NumberValueType, - NP_StringValueType, - NP_BooleanValueType, - NP_NullValueType, - NP_UndefinedValueType, - NP_ObjectValueType, - NP_InvalidValueType -}; - -WebCore::String convertNPStringToUTF16(const NPString *string); -void convertValueToNPVariant(ExecState*, JSValue*, NPVariant* result); -JSValue* convertNPVariantToValue(ExecState*, const NPVariant*, RootObject*); -Identifier identifierFromNPIdentifier(const NPUTF8* name); - -struct PrivateIdentifier { - union { - const NPUTF8* string; - int32_t number; - } value; - bool isString; -}; - -} } - -#endif // ENABLE(NETSCAPE_PLUGIN_API) - -#endif |