[SCM] WebKit Debian packaging branch, debian/experimental, updated. upstream/1.3.3-9427-gc2be6fc

andersca at apple.com andersca at apple.com
Wed Dec 22 11:32:30 UTC 2010


The following commit has been merged in the debian/experimental branch:
commit 5b2497cf10f599db7a038db9632f0e464c9a36f6
Author: andersca at apple.com <andersca at apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Wed Jul 28 21:30:11 2010 +0000

    Add support for calling NPObject methods
    https://bugs.webkit.org/show_bug.cgi?id=43145
    
    Reviewed by Sam Weinig.
    
    WebCore:
    
    * WebCore.exp.in:
    Export JSHTMLElement::s_info and pluginScriptObject.
    
    * WebCore.xcodeproj/project.pbxproj:
    Make JSHTMLElement.h and JSPluginElementFunctions.h private headers.
    
    * bindings/js/JSPluginElementFunctions.cpp:
    (WebCore::pluginScriptObject):
    * bindings/js/JSPluginElementFunctions.h:
    Make pluginScriptObject a public function.
    
    WebKit2:
    
    * WebKit2.xcodeproj/project.pbxproj:
    Add JSNPMethod.cpp and JSNPMethod.h
    
    * WebProcess/Plugins/JSNPMethod.cpp: Added.
    * WebProcess/Plugins/JSNPMethod.h: Added.
    * WebProcess/Plugins/JSNPObject.cpp:
    (WebKit::):
    Add a ClassInfo static variable for JSNPObject.
    
    (WebKit::JSNPObject::callMethod):
    Convert the passed in arguments, call the method and convert the result back.
    
    (WebKit::JSNPObject::getOwnPropertySlot):
    Check if the NPObject has a method.
    
    (WebKit::JSNPObject::methodGetter):
    Return a new JSNPMethod.
    
    * WebProcess/Plugins/JSNPObject.h:
    (WebKit::JSNPObject::classInfo):
    Return the s_info.
    
    * WebProcess/Plugins/NPJSObject.cpp:
    (WebKit::NPJSObject::getProperty):
    Get the property from the JSObject.
    
    * WebProcess/Plugins/NPRuntimeObjectMap.cpp:
    (WebKit::NPRuntimeObjectMap::convertJSValueToNPVariant):
    Convert the given JSValue to an NPVariant.
    
    * win/WebKit2.vcproj:
    Add JSNPMethod.cpp and JSNPMethod.h
    
    LayoutTests:
    
    * platform/mac-wk2/Skipped:
    Remove plugins/npruntime/get-int-identifier-special-values.html since it passes now.
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@64231 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/LayoutTests/ChangeLog b/LayoutTests/ChangeLog
index 4ccc48a..34c721b 100644
--- a/LayoutTests/ChangeLog
+++ b/LayoutTests/ChangeLog
@@ -1,3 +1,13 @@
+2010-07-28  Anders Carlsson  <andersca at apple.com>
+
+        Reviewed by Sam Weinig.
+
+        Add support for calling NPObject methods
+        https://bugs.webkit.org/show_bug.cgi?id=43145
+
+        * platform/mac-wk2/Skipped:
+        Remove plugins/npruntime/get-int-identifier-special-values.html since it passes now.
+
 2010-07-28  Victor Wang  <victorw at chromium.org>
 
         Unreviewed. Fix chromium test expectations:
diff --git a/LayoutTests/platform/mac-wk2/Skipped b/LayoutTests/platform/mac-wk2/Skipped
index 056abff..f5447e3 100644
--- a/LayoutTests/platform/mac-wk2/Skipped
+++ b/LayoutTests/platform/mac-wk2/Skipped
@@ -1413,7 +1413,6 @@ plugins/netscape-plugin-setwindow-size-2.html
 plugins/netscape-plugin-setwindow-size.html
 plugins/npruntime/bindings-test.html
 plugins/npruntime/enumerate.html
-plugins/npruntime/get-int-identifier-special-values.html
 plugins/npruntime/get-property-return-value.html
 plugins/npruntime/identifier-conversion.html
 plugins/npruntime/invoke-browserfuncs.html
diff --git a/WebCore/ChangeLog b/WebCore/ChangeLog
index b2b8aca..9b9e727 100644
--- a/WebCore/ChangeLog
+++ b/WebCore/ChangeLog
@@ -1,3 +1,21 @@
+2010-07-28  Anders Carlsson  <andersca at apple.com>
+
+        Reviewed by Sam Weinig.
+
+        Add support for calling NPObject methods
+        https://bugs.webkit.org/show_bug.cgi?id=43145
+
+        * WebCore.exp.in:
+        Export JSHTMLElement::s_info and pluginScriptObject.
+
+        * WebCore.xcodeproj/project.pbxproj:
+        Make JSHTMLElement.h and JSPluginElementFunctions.h private headers.
+
+        * bindings/js/JSPluginElementFunctions.cpp:
+        (WebCore::pluginScriptObject):
+        * bindings/js/JSPluginElementFunctions.h:
+        Make pluginScriptObject a public function.
+
 2010-07-28  James Robinson  <jamesr at chromium.org>
 
         Reviewed by Darin Fisher.
diff --git a/WebCore/WebCore.exp.in b/WebCore/WebCore.exp.in
index 90461c7..c1079d5 100644
--- a/WebCore/WebCore.exp.in
+++ b/WebCore/WebCore.exp.in
@@ -285,6 +285,7 @@ __ZN7WebCore13HitTestResultC1ERKS0_
 __ZN7WebCore13HitTestResultD1Ev
 __ZN7WebCore13IdentifierRep3getEPKc
 __ZN7WebCore13IdentifierRep3getEi
+__ZN7WebCore13JSHTMLElement6s_infoE
 __ZN7WebCore13KeyboardEventC1ERKNS_12AtomicStringEbbPNS_9DOMWindowERKNS_6StringEjbbbbb
 __ZN7WebCore13TypingCommand39insertParagraphSeparatorInQuotedContentEPNS_8DocumentE
 __ZN7WebCore13toDeviceSpaceERKNS_9FloatRectEP8NSWindow
@@ -408,6 +409,7 @@ __ZN7WebCore17nameForCursorTypeENS_6Cursor4TypeE
 __ZN7WebCore17openTemporaryFileEPKcRi
 __ZN7WebCore18deprecatedParseURLERKNS_6StringE
 __ZN7WebCore18isStartOfParagraphERKNS_15VisiblePositionE
+__ZN7WebCore18pluginScriptObjectEPN3JSC9ExecStateEPNS_13JSHTMLElementE
 __ZN7WebCore19AnimationController16resumeAnimationsEPNS_8DocumentE
 __ZN7WebCore19AnimationController17suspendAnimationsEPNS_8DocumentE
 __ZN7WebCore19AnimationController20pauseAnimationAtTimeEPNS_12RenderObjectERKNS_6StringEd
diff --git a/WebCore/WebCore.xcodeproj/project.pbxproj b/WebCore/WebCore.xcodeproj/project.pbxproj
index 30c8196..7af6387 100644
--- a/WebCore/WebCore.xcodeproj/project.pbxproj
+++ b/WebCore/WebCore.xcodeproj/project.pbxproj
@@ -352,7 +352,7 @@
 		1A3417C90CECFF250049CBDE /* JSCustomVoidCallback.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A3417C70CECFF250049CBDE /* JSCustomVoidCallback.h */; };
 		1A3417CA0CECFF250049CBDE /* JSCustomVoidCallback.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1A3417C80CECFF250049CBDE /* JSCustomVoidCallback.cpp */; };
 		1A494BFA0A122F4400FDAFC1 /* JSHTMLElement.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1A494BF80A122F4400FDAFC1 /* JSHTMLElement.cpp */; };
-		1A494BFB0A122F4400FDAFC1 /* JSHTMLElement.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A494BF90A122F4400FDAFC1 /* JSHTMLElement.h */; };
+		1A494BFB0A122F4400FDAFC1 /* JSHTMLElement.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A494BF90A122F4400FDAFC1 /* JSHTMLElement.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		1A494E340A12358B00FDAFC1 /* JSHTMLDocument.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1A494E320A12358A00FDAFC1 /* JSHTMLDocument.cpp */; };
 		1A494E350A12358B00FDAFC1 /* JSHTMLDocument.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A494E330A12358B00FDAFC1 /* JSHTMLDocument.h */; };
 		1A494EDE0A123F4C00FDAFC1 /* JSDocumentFragment.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1A494EDC0A123F4C00FDAFC1 /* JSDocumentFragment.cpp */; };
@@ -2515,7 +2515,7 @@
 		93B70D6909EB0C7C009D8468 /* JSEventListener.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 93B70D4D09EB0C7C009D8468 /* JSEventListener.cpp */; };
 		93B70D6A09EB0C7C009D8468 /* JSEventListener.h in Headers */ = {isa = PBXBuildFile; fileRef = 93B70D4E09EB0C7C009D8468 /* JSEventListener.h */; };
 		93B70D6B09EB0C7C009D8468 /* JSPluginElementFunctions.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 93B70D4F09EB0C7C009D8468 /* JSPluginElementFunctions.cpp */; };
-		93B70D6C09EB0C7C009D8468 /* JSPluginElementFunctions.h in Headers */ = {isa = PBXBuildFile; fileRef = 93B70D5009EB0C7C009D8468 /* JSPluginElementFunctions.h */; };
+		93B70D6C09EB0C7C009D8468 /* JSPluginElementFunctions.h in Headers */ = {isa = PBXBuildFile; fileRef = 93B70D5009EB0C7C009D8468 /* JSPluginElementFunctions.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		93B70D6F09EB0C7C009D8468 /* ScriptController.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 93B70D5309EB0C7C009D8468 /* ScriptController.cpp */; };
 		93B70D7009EB0C7C009D8468 /* ScriptController.h in Headers */ = {isa = PBXBuildFile; fileRef = 93B70D5409EB0C7C009D8468 /* ScriptController.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		93B77A380ADD792500EA4B81 /* FrameLoaderTypes.h in Headers */ = {isa = PBXBuildFile; fileRef = 93B77A370ADD792500EA4B81 /* FrameLoaderTypes.h */; settings = {ATTRIBUTES = (Private, ); }; };
diff --git a/WebCore/bindings/js/JSPluginElementFunctions.cpp b/WebCore/bindings/js/JSPluginElementFunctions.cpp
index 6bdc440..cf43e91 100644
--- a/WebCore/bindings/js/JSPluginElementFunctions.cpp
+++ b/WebCore/bindings/js/JSPluginElementFunctions.cpp
@@ -49,7 +49,7 @@ Instance* pluginInstance(Node* node)
     return instance;
 }
 
-static JSObject* pluginScriptObject(ExecState* exec, JSHTMLElement* jsHTMLElement)
+JSObject* pluginScriptObject(ExecState* exec, JSHTMLElement* jsHTMLElement)
 {
     HTMLElement* element = jsHTMLElement->impl();
     if (!(element->hasTagName(objectTag) || element->hasTagName(embedTag) || element->hasTagName(appletTag)))
diff --git a/WebCore/bindings/js/JSPluginElementFunctions.h b/WebCore/bindings/js/JSPluginElementFunctions.h
index acd4965..15af59a 100644
--- a/WebCore/bindings/js/JSPluginElementFunctions.h
+++ b/WebCore/bindings/js/JSPluginElementFunctions.h
@@ -36,6 +36,7 @@ namespace WebCore {
 
     // Runtime object support code for JSHTMLAppletElement, JSHTMLEmbedElement and JSHTMLObjectElement.
     JSC::Bindings::Instance* pluginInstance(Node*);
+    JSC::JSObject* pluginScriptObject(JSC::ExecState* exec, JSHTMLElement* jsHTMLElement);
 
     JSC::JSValue runtimeObjectPropertyGetter(JSC::ExecState*, JSC::JSValue, const JSC::Identifier&);
     bool runtimeObjectCustomGetOwnPropertySlot(JSC::ExecState*, const JSC::Identifier&, JSC::PropertySlot&, JSHTMLElement*);
diff --git a/WebKit2/ChangeLog b/WebKit2/ChangeLog
index c654e1c..fba8ac5 100644
--- a/WebKit2/ChangeLog
+++ b/WebKit2/ChangeLog
@@ -1,3 +1,43 @@
+2010-07-28  Anders Carlsson  <andersca at apple.com>
+
+        Reviewed by Sam Weinig.
+
+        Add support for calling NPObject methods
+        https://bugs.webkit.org/show_bug.cgi?id=43145
+
+        * WebKit2.xcodeproj/project.pbxproj:
+        Add JSNPMethod.cpp and JSNPMethod.h
+    
+        * WebProcess/Plugins/JSNPMethod.cpp: Added.
+        * WebProcess/Plugins/JSNPMethod.h: Added.
+        * WebProcess/Plugins/JSNPObject.cpp:
+        (WebKit::):
+        Add a ClassInfo static variable for JSNPObject.
+
+        (WebKit::JSNPObject::callMethod):
+        Convert the passed in arguments, call the method and convert the result back.
+
+        (WebKit::JSNPObject::getOwnPropertySlot):
+        Check if the NPObject has a method.
+
+        (WebKit::JSNPObject::methodGetter):
+        Return a new JSNPMethod.
+
+        * WebProcess/Plugins/JSNPObject.h:
+        (WebKit::JSNPObject::classInfo):
+        Return the s_info.
+
+        * WebProcess/Plugins/NPJSObject.cpp:
+        (WebKit::NPJSObject::getProperty):
+        Get the property from the JSObject.
+
+        * WebProcess/Plugins/NPRuntimeObjectMap.cpp:
+        (WebKit::NPRuntimeObjectMap::convertJSValueToNPVariant):
+        Convert the given JSValue to an NPVariant.
+
+        * win/WebKit2.vcproj:
+        Add JSNPMethod.cpp and JSNPMethod.h
+
 2010-07-28  Adam Roben  <aroben at apple.com>
 
         Teach CoreIPC how to handle with a pipe closing during a write
diff --git a/WebKit2/WebKit2.xcodeproj/project.pbxproj b/WebKit2/WebKit2.xcodeproj/project.pbxproj
index 8dceb0e..9b6afb6 100644
--- a/WebKit2/WebKit2.xcodeproj/project.pbxproj
+++ b/WebKit2/WebKit2.xcodeproj/project.pbxproj
@@ -75,6 +75,8 @@
 		1AE4976911FF658E0048B464 /* NPJSObject.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1AE4976711FF658E0048B464 /* NPJSObject.cpp */; };
 		1AE4987811FF7FAA0048B464 /* JSNPObject.h in Headers */ = {isa = PBXBuildFile; fileRef = 1AE4987611FF7FAA0048B464 /* JSNPObject.h */; };
 		1AE4987911FF7FAA0048B464 /* JSNPObject.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1AE4987711FF7FAA0048B464 /* JSNPObject.cpp */; };
+		1AE49A4911FFA8CE0048B464 /* JSNPMethod.h in Headers */ = {isa = PBXBuildFile; fileRef = 1AE49A4711FFA8CE0048B464 /* JSNPMethod.h */; };
+		1AE49A4A11FFA8CE0048B464 /* JSNPMethod.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1AE49A4811FFA8CE0048B464 /* JSNPMethod.cpp */; };
 		1AE5B7FB11E7AED200BA6767 /* NetscapePluginMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1AE5B7F911E7AED200BA6767 /* NetscapePluginMac.mm */; };
 		1AEFCC1211D01F96008219D3 /* PluginInfoStore.h in Headers */ = {isa = PBXBuildFile; fileRef = 1AEFCC1011D01F96008219D3 /* PluginInfoStore.h */; };
 		1AEFCC1311D01F96008219D3 /* PluginInfoStore.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1AEFCC1111D01F96008219D3 /* PluginInfoStore.cpp */; };
@@ -364,6 +366,8 @@
 		1AE4976711FF658E0048B464 /* NPJSObject.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = NPJSObject.cpp; sourceTree = "<group>"; };
 		1AE4987611FF7FAA0048B464 /* JSNPObject.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSNPObject.h; sourceTree = "<group>"; };
 		1AE4987711FF7FAA0048B464 /* JSNPObject.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSNPObject.cpp; sourceTree = "<group>"; };
+		1AE49A4711FFA8CE0048B464 /* JSNPMethod.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSNPMethod.h; sourceTree = "<group>"; };
+		1AE49A4811FFA8CE0048B464 /* JSNPMethod.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSNPMethod.cpp; sourceTree = "<group>"; };
 		1AE5B7F911E7AED200BA6767 /* NetscapePluginMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = NetscapePluginMac.mm; sourceTree = "<group>"; };
 		1AEFCC1011D01F96008219D3 /* PluginInfoStore.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PluginInfoStore.h; sourceTree = "<group>"; };
 		1AEFCC1111D01F96008219D3 /* PluginInfoStore.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PluginInfoStore.cpp; sourceTree = "<group>"; };
@@ -681,6 +685,8 @@
 			isa = PBXGroup;
 			children = (
 				1A6FB90811E66FB100DB1371 /* Netscape */,
+				1AE49A4811FFA8CE0048B464 /* JSNPMethod.cpp */,
+				1AE49A4711FFA8CE0048B464 /* JSNPMethod.h */,
 				1AE4987711FF7FAA0048B464 /* JSNPObject.cpp */,
 				1AE4987611FF7FAA0048B464 /* JSNPObject.h */,
 				1AE4976711FF658E0048B464 /* NPJSObject.cpp */,
@@ -1295,6 +1301,7 @@
 				BCF049E711FE20F600F86A58 /* WKBundlePrivate.h in Headers */,
 				1AE4976811FF658E0048B464 /* NPJSObject.h in Headers */,
 				1AE4987811FF7FAA0048B464 /* JSNPObject.h in Headers */,
+				1AE49A4911FFA8CE0048B464 /* JSNPMethod.h in Headers */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};
@@ -1494,6 +1501,7 @@
 				E1EE565611F8F71700CCBEE4 /* WKBundleNode.cpp in Sources */,
 				1AE4976911FF658E0048B464 /* NPJSObject.cpp in Sources */,
 				1AE4987911FF7FAA0048B464 /* JSNPObject.cpp in Sources */,
+				1AE49A4A11FFA8CE0048B464 /* JSNPMethod.cpp in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};
diff --git a/WebKit2/WebProcess/Plugins/JSNPMethod.cpp b/WebKit2/WebProcess/Plugins/JSNPMethod.cpp
new file mode 100644
index 0000000..0c0e2a4
--- /dev/null
+++ b/WebKit2/WebProcess/Plugins/JSNPMethod.cpp
@@ -0,0 +1,79 @@
+/*
+ * 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. AND ITS 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 APPLE INC. OR ITS 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 "JSNPMethod.h"
+
+#include "JSNPObject.h"
+#include "NotImplemented.h"
+#include <JavaScriptCore/Error.h>
+#include <JavaScriptCore/FunctionPrototype.h>
+#include <JavaScriptCore/JSGlobalObject.h>
+#include <WebCore/JSHTMLElement.h>
+#include <WebCore/JSPluginElementFunctions.h>
+
+using namespace JSC;
+using namespace WebCore;
+
+namespace WebKit {
+
+const ClassInfo JSNPMethod::s_info = { "NPMethod", 0, 0, 0 };
+
+JSNPMethod::JSNPMethod(ExecState* exec, JSGlobalObject* globalObject, const Identifier& name, NPIdentifier npIdentifier)
+    : InternalFunction(&exec->globalData(), globalObject, createStructure(globalObject->functionPrototype()), name)
+    , m_npIdentifier(npIdentifier)
+{
+}
+
+static EncodedJSValue JSC_HOST_CALL callMethod(ExecState* exec)
+{
+    JSNPMethod* jsNPMethod = static_cast<JSNPMethod*>(exec->callee());
+
+    JSValue thisValue = exec->hostThisValue();
+
+    // Check if we're calling a method on the plug-in script object.
+    if (thisValue.inherits(&JSHTMLElement::s_info)) {
+        JSHTMLElement* element = static_cast<JSHTMLElement*>(asObject(thisValue));
+
+        // Try to get the script object from the element
+        if (JSObject* scriptObject = pluginScriptObject(exec, element))
+            thisValue = scriptObject;
+    }
+
+    if (thisValue.inherits(&JSNPObject::s_info)) {
+        JSNPObject* jsNPObject = static_cast<JSNPObject*>(asObject(thisValue));
+
+        return JSValue::encode(jsNPObject->callMethod(exec, jsNPMethod->npIdentifier()));
+    }
+
+    return throwVMTypeError(exec);
+}
+
+CallType JSNPMethod::getCallData(CallData& callData)
+{
+    callData.native.function = callMethod;
+    return CallTypeHost;
+}
+
+} // namespace WebKit
diff --git a/WebKit2/WebProcess/Plugins/JSNPMethod.h b/WebKit2/WebProcess/Plugins/JSNPMethod.h
new file mode 100644
index 0000000..9a8578c
--- /dev/null
+++ b/WebKit2/WebProcess/Plugins/JSNPMethod.h
@@ -0,0 +1,59 @@
+/*
+ * 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. AND ITS 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 APPLE INC. OR ITS 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 JSNPMethod_h
+#define JSNPMethod_h
+
+#include <JavaScriptCore/InternalFunction.h>
+
+typedef void* NPIdentifier;
+
+namespace WebKit {
+
+// A JSObject that wraps an NPMethod.
+class JSNPMethod : public JSC::InternalFunction {
+public:
+    JSNPMethod(JSC::ExecState*, JSC::JSGlobalObject*, const JSC::Identifier&, NPIdentifier);
+
+    static const JSC::ClassInfo s_info;
+
+    NPIdentifier npIdentifier() const { return m_npIdentifier; }
+
+private:    
+    static PassRefPtr<JSC::Structure> createStructure(JSC::JSValue prototype)
+    {
+        return JSC::Structure::create(prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), AnonymousSlotCount);
+    }
+
+    virtual JSC::CallType getCallData(JSC::CallData&);
+    virtual const JSC::ClassInfo* classInfo() const { return &s_info; }
+    
+    NPIdentifier m_npIdentifier;
+};
+
+
+} // namespace WebKit
+
+#endif // JSNPMethod_h
diff --git a/WebKit2/WebProcess/Plugins/JSNPObject.cpp b/WebKit2/WebProcess/Plugins/JSNPObject.cpp
index a82fab8..4a93636 100644
--- a/WebKit2/WebProcess/Plugins/JSNPObject.cpp
+++ b/WebKit2/WebProcess/Plugins/JSNPObject.cpp
@@ -25,12 +25,13 @@
 
 #include "JSNPObject.h"
 
+#include "JSNPMethod.h"
 #include "NPRuntimeObjectMap.h"
 #include "NPRuntimeUtilities.h"
 #include <JavaScriptCore/Error.h>
 #include <JavaScriptCore/JSGlobalObject.h>
-#include <JavaScriptCore/JSLock.h>
 #include <JavaScriptCore/ObjectPrototype.h>
+#include <JavaScriptCore/JSLock.h>
 #include <WebCore/IdentifierRep.h>
 
 using namespace WebCore;
@@ -42,7 +43,9 @@ static NPIdentifier npIdentifierFromIdentifier(const Identifier& identifier)
 {
     return static_cast<NPIdentifier>(IdentifierRep::get(identifier.ascii()));
 }
-    
+
+const ClassInfo JSNPObject::s_info = { "NPObject", 0, 0, 0 };
+
 JSNPObject::JSNPObject(ExecState*, JSGlobalObject* globalObject, NPRuntimeObjectMap* objectMap, NPObject* npObject)
     : JSObjectWithGlobalObject(globalObject, createStructure(globalObject->objectPrototype()))
     , m_objectMap(objectMap)
@@ -56,6 +59,42 @@ JSNPObject::~JSNPObject()
     // FIXME: Implement.
 }
 
+JSValue JSNPObject::callMethod(ExecState* exec, NPIdentifier methodName)
+{
+    if (!m_npObject->_class->hasMethod(m_npObject, methodName))
+        return jsUndefined();
+
+    size_t argumentCount = exec->argumentCount();
+    Vector<NPVariant, 8> arguments(argumentCount);
+
+    // Convert all arguments to NPVariants.
+    for (size_t i = 0; i < argumentCount; ++i)
+        m_objectMap->convertJSValueToNPVariant(exec, exec->argument(i), arguments[i]);
+
+    bool returnValue;
+    NPVariant result;
+    VOID_TO_NPVARIANT(result);
+    
+    {
+        JSLock::DropAllLocks dropAllLocks(SilenceAssertionsOnly);
+        returnValue = m_npObject->_class->invoke(m_npObject, methodName, arguments.data(), argumentCount, &result);
+
+        // FIXME: Handle invoke setting an exception.
+        // FIXME: Find out what happens if calling invoke causes the plug-in to go away.
+    }
+
+    // Release all arguments;
+    for (size_t i = 0; i < argumentCount; ++i)
+        releaseNPVariantValue(&arguments[i]);
+
+    if (!returnValue)
+        throwError(exec, createError(exec, "Error calling method on NPObject."));
+
+    JSValue propertyValue = m_objectMap->convertNPVariantToJSValue(exec, result);
+    releaseNPVariantValue(&result);
+    return propertyValue;
+}
+
 bool JSNPObject::getOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot)
 {
     if (!m_npObject) {
@@ -64,12 +103,19 @@ bool JSNPObject::getOwnPropertySlot(ExecState* exec, const Identifier& propertyN
     }
     
     NPIdentifier npIdentifier = npIdentifierFromIdentifier(propertyName);
+
+    // First, check if the NPObject has a property with this name.
     if (m_npObject->_class->hasProperty && m_npObject->_class->hasProperty(m_npObject, npIdentifier)) {
         slot.setCustom(this, propertyGetter);
         return true;
     }
 
-    // FIXME: Check methods.
+    // Second, check is the NPObject has a method with this name.
+    if (m_npObject->_class->hasMethod && m_npObject->_class->hasMethod(m_npObject, npIdentifier)) {
+        slot.setCustom(this, methodGetter);
+        return true;
+    }
+    
     return false;
 }
 
@@ -83,23 +129,36 @@ JSValue JSNPObject::propertyGetter(ExecState* exec, JSValue slotBase, const Iden
     if (!thisObj->m_npObject->_class->getProperty)
         return jsUndefined();
 
-    NPVariant property;
-    VOID_TO_NPVARIANT(property);
+    NPVariant result;
+    VOID_TO_NPVARIANT(result);
 
-    bool result;
+    bool returnValue;
     {
         JSLock::DropAllLocks dropAllLocks(SilenceAssertionsOnly);
         NPIdentifier npIdentifier = npIdentifierFromIdentifier(propertyName);
-        result = thisObj->m_npObject->_class->getProperty(thisObj->m_npObject, npIdentifier, &property);
+        returnValue = thisObj->m_npObject->_class->getProperty(thisObj->m_npObject, npIdentifier, &result);
         
         // FIXME: Handle getProperty setting an exception.
         // FIXME: Find out what happens if calling getProperty causes the plug-in to go away.
     }
 
-    if (!result)
+    if (!returnValue)
         return jsUndefined();
 
-    return thisObj->m_objectMap->convertNPVariantToValue(exec, property);
+    JSValue propertyValue = thisObj->m_objectMap->convertNPVariantToJSValue(exec, result);
+    releaseNPVariantValue(&result);
+    return propertyValue;
+}
+
+JSValue JSNPObject::methodGetter(ExecState* exec, JSValue slotBase, const Identifier& methodName)
+{
+    JSNPObject* thisObj = static_cast<JSNPObject*>(asObject(slotBase));
+    
+    if (!thisObj->m_npObject)
+        return throwInvalidAccessError(exec);
+
+    NPIdentifier npIdentifier = npIdentifierFromIdentifier(methodName);
+    return new (exec) JSNPMethod(exec, thisObj->globalObject(), methodName, npIdentifier);
 }
 
 JSObject* JSNPObject::throwInvalidAccessError(ExecState* exec)
diff --git a/WebKit2/WebProcess/Plugins/JSNPObject.h b/WebKit2/WebProcess/Plugins/JSNPObject.h
index 6dc3617..7419ad1 100644
--- a/WebKit2/WebProcess/Plugins/JSNPObject.h
+++ b/WebKit2/WebProcess/Plugins/JSNPObject.h
@@ -28,6 +28,7 @@
 
 #include <JavaScriptCore/JSObjectWithGlobalObject.h>
 
+typedef void* NPIdentifier;
 struct NPObject;
 
 namespace WebKit {
@@ -41,6 +42,10 @@ public:
     JSNPObject(JSC::ExecState*, JSC::JSGlobalObject*, NPRuntimeObjectMap* objectMap, NPObject* npObject);
     ~JSNPObject();
 
+    JSC::JSValue callMethod(JSC::ExecState*, NPIdentifier methodName);
+
+    static const JSC::ClassInfo s_info;
+
 private:
     static const unsigned StructureFlags = JSC::OverridesGetOwnPropertySlot | JSObject::StructureFlags;
     
@@ -52,8 +57,11 @@ private:
     virtual bool getOwnPropertySlot(JSC::ExecState*, const JSC::Identifier& propertyName, JSC::PropertySlot&);
 
     static JSC::JSValue propertyGetter(JSC::ExecState*, JSC::JSValue, const JSC::Identifier&);
+    static JSC::JSValue methodGetter(JSC::ExecState*, JSC::JSValue, const JSC::Identifier&);
     static JSC::JSObject* throwInvalidAccessError(JSC::ExecState*);
 
+    virtual const JSC::ClassInfo* classInfo() const { return &s_info; }
+
     NPRuntimeObjectMap* m_objectMap;
     NPObject* m_npObject;
 };
diff --git a/WebKit2/WebProcess/Plugins/NPJSObject.cpp b/WebKit2/WebProcess/Plugins/NPJSObject.cpp
index afe6da3..c40bf6e 100644
--- a/WebKit2/WebProcess/Plugins/NPJSObject.cpp
+++ b/WebKit2/WebProcess/Plugins/NPJSObject.cpp
@@ -27,7 +27,9 @@
 
 #include "NPRuntimeObjectMap.h"
 #include "NPRuntimeUtilities.h"
+#include "NotImplemented.h"
 #include "PluginView.h"
+#include <JavaScriptCore/JSLock.h>
 #include <JavaScriptCore/JSObject.h>
 #include <WebCore/Frame.h>  
 #include <WebCore/IdentifierRep.h>
@@ -95,14 +97,27 @@ bool NPJSObject::hasProperty(NPIdentifier identifier)
         result = m_jsObject->hasProperty(exec, identifierRep->number());
 
     exec->clearException();
-
     return result;
 }
 
-bool NPJSObject::getProperty(NPIdentifier identifier, NPVariant* result)
+bool NPJSObject::getProperty(NPIdentifier propertyName, NPVariant* result)
 {
-    // FIXME: Implement.
-    return false;
+    IdentifierRep* identifierRep = static_cast<IdentifierRep*>(propertyName);
+    
+    ExecState* exec = m_objectMap->globalExec();
+    if (!exec)
+        return false;
+
+    JSLock lock(SilenceAssertionsOnly);
+    JSValue jsResult;
+    if (identifierRep->isString())
+        jsResult = m_jsObject->get(exec, identifierFromIdentifierRep(exec, identifierRep));
+    else
+        jsResult = m_jsObject->get(exec, identifierRep->number());
+    
+    m_objectMap->convertJSValueToNPVariant(exec, jsResult, *result);
+    exec->clearException();
+    return true;
 }
 
 NPClass* NPJSObject::npClass()
diff --git a/WebKit2/WebProcess/Plugins/NPRuntimeObjectMap.cpp b/WebKit2/WebProcess/Plugins/NPRuntimeObjectMap.cpp
index a59e069..b5f93e9 100644
--- a/WebKit2/WebProcess/Plugins/NPRuntimeObjectMap.cpp
+++ b/WebKit2/WebProcess/Plugins/NPRuntimeObjectMap.cpp
@@ -25,6 +25,8 @@
 
 #include "NPRuntimeObjectMap.h"
 
+#include <JavaScriptCore/JSLock.h>
+
 #include "JSNPObject.h"
 #include "NPJSObject.h"
 #include "NPRuntimeUtilities.h"
@@ -75,7 +77,7 @@ void NPRuntimeObjectMap::jsNPObjectDestroyed(JSNPObject* jsNPObject)
     // FIXME: Implement.
 }
 
-JSValue NPRuntimeObjectMap::convertNPVariantToValue(JSC::ExecState* exec, const NPVariant& variant)
+JSValue NPRuntimeObjectMap::convertNPVariantToJSValue(JSC::ExecState* exec, const NPVariant& variant)
 {
     switch (variant.type) {
     case NPVariantType_Void:
@@ -105,6 +107,59 @@ JSValue NPRuntimeObjectMap::convertNPVariantToValue(JSC::ExecState* exec, const
     return jsUndefined();
 }
 
+void NPRuntimeObjectMap::convertJSValueToNPVariant(ExecState* exec, JSValue value, NPVariant& variant)
+{
+    JSLock lock(SilenceAssertionsOnly);
+
+    VOID_TO_NPVARIANT(variant);
+    
+    if (value.isNull()) {
+        NULL_TO_NPVARIANT(variant);
+        return;
+    }
+
+    if (value.isUndefined()) {
+        VOID_TO_NPVARIANT(variant);
+        return;
+    }
+
+    if (value.isBoolean()) {
+        BOOLEAN_TO_NPVARIANT(value.toBoolean(exec), variant);
+        return;
+    }
+
+    if (value.isNumber()) {
+        DOUBLE_TO_NPVARIANT(value.toNumber(exec), variant);
+        return;
+    }
+
+    if (value.isString()) {
+        CString utf8String = value.toString(exec).UTF8String();
+
+        // This should use NPN_MemAlloc, but we know that it uses malloc under the hood.
+        char* utf8Characters = static_cast<char*>(malloc(utf8String.length()));
+        memcpy(utf8Characters, utf8String.data(), utf8String.length());
+        
+        STRINGN_TO_NPVARIANT(utf8Characters, utf8String.length(), variant);
+        return;
+    }
+
+    if (value.isObject()) {
+        JSObject* jsObject = asObject(value);
+
+        if (jsObject->classInfo() == &JSNPObject::s_info) {
+            notImplemented();
+            return;
+        }
+
+        NPObject* npObject = getOrCreateNPObject(jsObject);
+        OBJECT_TO_NPVARIANT(npObject, variant);
+        return;
+    }
+
+    ASSERT_NOT_REACHED();
+}
+
 void NPRuntimeObjectMap::invalidate()
 {
     Vector<NPJSObject*> npJSObjects;
diff --git a/WebKit2/WebProcess/Plugins/NPRuntimeObjectMap.h b/WebKit2/WebProcess/Plugins/NPRuntimeObjectMap.h
index 021157c..c4e2a9b 100644
--- a/WebKit2/WebProcess/Plugins/NPRuntimeObjectMap.h
+++ b/WebKit2/WebProcess/Plugins/NPRuntimeObjectMap.h
@@ -60,7 +60,8 @@ public:
 
     void jsNPObjectDestroyed(JSNPObject*);
 
-    JSC::JSValue convertNPVariantToValue(JSC::ExecState*, const NPVariant&);
+    void convertJSValueToNPVariant(JSC::ExecState*, JSC::JSValue, NPVariant&);
+    JSC::JSValue convertNPVariantToJSValue(JSC::ExecState*, const NPVariant&);
 
     // Called when the plug-in is destroyed. Will invalidate all the NPObjects.
     void invalidate();
diff --git a/WebKit2/win/WebKit2.vcproj b/WebKit2/win/WebKit2.vcproj
index db6818e..c156d45 100755
--- a/WebKit2/win/WebKit2.vcproj
+++ b/WebKit2/win/WebKit2.vcproj
@@ -752,6 +752,14 @@
 				Name="Plugins"
 				>
 				<File
+					RelativePath="..\WebProcess\Plugins\JSNPMethod.cpp"
+					>
+				</File>
+				<File
+					RelativePath="..\WebProcess\Plugins\JSNPMethod.h"
+					>
+				</File>
+				<File
 					RelativePath="..\WebProcess\Plugins\JSNPObject.cpp"
 					>
 				</File>

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list