summaryrefslogtreecommitdiffstats
path: root/WebCore/bridge/c
diff options
context:
space:
mode:
authorSteve Block <steveblock@google.com>2010-04-27 16:31:00 +0100
committerSteve Block <steveblock@google.com>2010-05-11 14:42:12 +0100
commitdcc8cf2e65d1aa555cce12431a16547e66b469ee (patch)
tree92a8d65cd5383bca9749f5327fb5e440563926e6 /WebCore/bridge/c
parentccac38a6b48843126402088a309597e682f40fe6 (diff)
downloadexternal_webkit-dcc8cf2e65d1aa555cce12431a16547e66b469ee.zip
external_webkit-dcc8cf2e65d1aa555cce12431a16547e66b469ee.tar.gz
external_webkit-dcc8cf2e65d1aa555cce12431a16547e66b469ee.tar.bz2
Merge webkit.org at r58033 : Initial merge by git
Change-Id: If006c38561af287c50cd578d251629b51e4d8cd1
Diffstat (limited to 'WebCore/bridge/c')
-rw-r--r--WebCore/bridge/c/CRuntimeObject.cpp56
-rw-r--r--WebCore/bridge/c/CRuntimeObject.h55
-rw-r--r--WebCore/bridge/c/c_class.cpp1
-rw-r--r--WebCore/bridge/c/c_instance.cpp40
-rw-r--r--WebCore/bridge/c/c_instance.h5
-rw-r--r--WebCore/bridge/c/c_utility.cpp13
-rw-r--r--WebCore/bridge/c/c_utility.h2
7 files changed, 160 insertions, 12 deletions
diff --git a/WebCore/bridge/c/CRuntimeObject.cpp b/WebCore/bridge/c/CRuntimeObject.cpp
new file mode 100644
index 0000000..47425a2
--- /dev/null
+++ b/WebCore/bridge/c/CRuntimeObject.cpp
@@ -0,0 +1,56 @@
+/*
+ * Copyright (C) 2010 Apple 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 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 "CRuntimeObject.h"
+#include "c_instance.h"
+
+namespace JSC {
+namespace Bindings {
+
+const ClassInfo CRuntimeObject::s_info = { "CRuntimeObject", &RuntimeObject::s_info, 0, 0 };
+
+CRuntimeObject::CRuntimeObject(ExecState* exec, PassRefPtr<CInstance> instance)
+ : RuntimeObject(exec, instance)
+{
+}
+
+CRuntimeObject::~CRuntimeObject()
+{
+}
+
+CInstance* CRuntimeObject::getInternalCInstance() const
+{
+ return static_cast<CInstance*>(getInternalInstance());
+}
+
+
+}
+}
+
+#endif
diff --git a/WebCore/bridge/c/CRuntimeObject.h b/WebCore/bridge/c/CRuntimeObject.h
new file mode 100644
index 0000000..b53387a
--- /dev/null
+++ b/WebCore/bridge/c/CRuntimeObject.h
@@ -0,0 +1,55 @@
+/*
+ * Copyright (C) 2010 Apple 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 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 CRuntimeObject_h
+#define CRuntimeObject_h
+
+#if ENABLE(NETSCAPE_PLUGIN_API)
+
+#include "runtime_object.h"
+
+namespace JSC {
+namespace Bindings {
+
+class CInstance;
+
+class CRuntimeObject : public RuntimeObject {
+public:
+ CRuntimeObject(ExecState*, PassRefPtr<CInstance>);
+ virtual ~CRuntimeObject();
+
+ CInstance* getInternalCInstance() const;
+
+ static const ClassInfo s_info;
+
+private:
+ virtual const ClassInfo* classInfo() const { return &s_info; }
+};
+
+}
+}
+
+#endif
+#endif
diff --git a/WebCore/bridge/c/c_class.cpp b/WebCore/bridge/c/c_class.cpp
index e8499cb..ea71638 100644
--- a/WebCore/bridge/c/c_class.cpp
+++ b/WebCore/bridge/c/c_class.cpp
@@ -34,6 +34,7 @@
#include "npruntime_impl.h"
#include <runtime/Identifier.h>
#include <runtime/JSLock.h>
+#include <wtf/text/StringHash.h>
namespace JSC { namespace Bindings {
diff --git a/WebCore/bridge/c/c_instance.cpp b/WebCore/bridge/c/c_instance.cpp
index 1b05259..7dbc1d9 100644
--- a/WebCore/bridge/c/c_instance.cpp
+++ b/WebCore/bridge/c/c_instance.cpp
@@ -29,15 +29,17 @@
#include "c_instance.h"
+#include "CRuntimeObject.h"
+#include "IdentifierRep.h"
#include "c_class.h"
#include "c_runtime.h"
#include "c_utility.h"
-#include "IdentifierRep.h"
#include "npruntime_impl.h"
+#include "runtime_method.h"
#include "runtime_root.h"
+#include <interpreter/CallFrame.h>
#include <runtime/ArgList.h>
#include <runtime/Error.h>
-#include <interpreter/CallFrame.h>
#include <runtime/JSLock.h>
#include <runtime/JSNumberCell.h>
#include <runtime/PropertyNameArray.h>
@@ -89,6 +91,11 @@ CInstance::~CInstance()
_NPN_ReleaseObject(_object);
}
+RuntimeObject* CInstance::newRuntimeObject(ExecState* exec)
+{
+ return new (exec) CRuntimeObject(exec, this);
+}
+
Class *CInstance::getClass() const
{
if (!_class)
@@ -101,8 +108,33 @@ bool CInstance::supportsInvokeDefaultMethod() const
return _object->_class->invokeDefault;
}
-JSValue CInstance::invokeMethod(ExecState* exec, const MethodList& methodList, const ArgList& args)
+class CRuntimeMethod : public RuntimeMethod {
+public:
+ CRuntimeMethod(ExecState* exec, const Identifier& name, Bindings::MethodList& list)
+ : RuntimeMethod(exec, name, list)
+ {
+ }
+
+ virtual const ClassInfo* classInfo() const { return &s_info; }
+
+ static const ClassInfo s_info;
+};
+
+const ClassInfo CRuntimeMethod::s_info = { "CRuntimeMethod", &RuntimeMethod::s_info, 0, 0 };
+
+JSValue CInstance::getMethod(ExecState* exec, const Identifier& propertyName)
+{
+ MethodList methodList = getClass()->methodsNamed(propertyName, this);
+ return new (exec) CRuntimeMethod(exec, propertyName, methodList);
+}
+
+JSValue CInstance::invokeMethod(ExecState* exec, RuntimeMethod* runtimeMethod, const ArgList& args)
{
+ if (!asObject(runtimeMethod)->inherits(&CRuntimeMethod::s_info))
+ return throwError(exec, TypeError, "Attempt to invoke non-plug-in method on plug-in object.");
+
+ const MethodList& methodList = *runtimeMethod->methods();
+
// Overloading methods are not allowed by NPObjects. Should only be one
// name match for a particular method.
ASSERT(methodList.size() == 1);
@@ -271,7 +303,7 @@ void CInstance::getPropertyNames(ExecState* exec, PropertyNameArray& nameArray)
IdentifierRep* identifier = static_cast<IdentifierRep*>(identifiers[i]);
if (identifier->isString())
- nameArray.add(identifierFromNPIdentifier(identifier->string()));
+ nameArray.add(identifierFromNPIdentifier(exec, identifier->string()));
else
nameArray.add(Identifier::from(exec, identifier->number()));
}
diff --git a/WebCore/bridge/c/c_instance.h b/WebCore/bridge/c/c_instance.h
index abbabad..be4a4cb 100644
--- a/WebCore/bridge/c/c_instance.h
+++ b/WebCore/bridge/c/c_instance.h
@@ -59,7 +59,8 @@ public:
virtual JSValue valueOf(ExecState*) const;
virtual JSValue defaultValue(ExecState*, PreferredPrimitiveType) const;
- virtual JSValue invokeMethod(ExecState*, const MethodList&, const ArgList&);
+ virtual JSValue getMethod(ExecState* exec, const Identifier& propertyName);
+ virtual JSValue invokeMethod(ExecState*, RuntimeMethod* method, const ArgList&);
virtual bool supportsInvokeDefaultMethod() const;
virtual JSValue invokeDefaultMethod(ExecState*, const ArgList&);
@@ -77,6 +78,8 @@ public:
private:
CInstance(NPObject*, PassRefPtr<RootObject>);
+ virtual RuntimeObject* newRuntimeObject(ExecState*);
+
mutable CClass *_class;
NPObject *_object;
};
diff --git a/WebCore/bridge/c/c_utility.cpp b/WebCore/bridge/c/c_utility.cpp
index 7ff77e7..3e65eb9 100644
--- a/WebCore/bridge/c/c_utility.cpp
+++ b/WebCore/bridge/c/c_utility.cpp
@@ -30,6 +30,7 @@
#include "c_utility.h"
+#include "CRuntimeObject.h"
#include "JSDOMWindow.h"
#include "NP_jsobject.h"
#include "c_instance.h"
@@ -75,7 +76,7 @@ void convertValueToNPVariant(ExecState* exec, JSValue value, 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()) };
+ NPString string = { (const NPUTF8*)cstring.data(), static_cast<uint32_t>(cstring.length()) };
NPN_InitializeVariantWithStringCopy(result, &string);
} else if (value.isNumber()) {
DOUBLE_TO_NPVARIANT(value.toNumber(exec), *result);
@@ -85,9 +86,9 @@ void convertValueToNPVariant(ExecState* exec, JSValue value, NPVariant* result)
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 (object->classInfo() == &CRuntimeObject::s_info) {
+ CRuntimeObject* runtimeObject = static_cast<CRuntimeObject*>(object);
+ CInstance* instance = runtimeObject->getInternalCInstance();
if (instance) {
NPObject* obj = instance->getObject();
_NPN_RetainObject(obj);
@@ -142,9 +143,9 @@ String convertNPStringToUTF16(const NPString* string)
return String::fromUTF8WithLatin1Fallback(string->UTF8Characters, string->UTF8Length);
}
-Identifier identifierFromNPIdentifier(const NPUTF8* name)
+Identifier identifierFromNPIdentifier(ExecState* exec, const NPUTF8* name)
{
- return Identifier(WebCore::JSDOMWindow::commonJSGlobalData(), convertUTF8ToUTF16WithLatin1Fallback(name, -1));
+ return Identifier(exec, stringToUString(convertUTF8ToUTF16WithLatin1Fallback(name, -1)));
}
} }
diff --git a/WebCore/bridge/c/c_utility.h b/WebCore/bridge/c/c_utility.h
index f69bba6..6af8fb6 100644
--- a/WebCore/bridge/c/c_utility.h
+++ b/WebCore/bridge/c/c_utility.h
@@ -49,7 +49,7 @@ typedef uint16_t NPUTF16;
WebCore::String convertNPStringToUTF16(const NPString *string);
void convertValueToNPVariant(ExecState*, JSValue, NPVariant* result);
JSValue convertNPVariantToValue(ExecState*, const NPVariant*, RootObject*);
-Identifier identifierFromNPIdentifier(const NPUTF8* name);
+Identifier identifierFromNPIdentifier(ExecState*, const NPUTF8* name);
} }