Changeset 64231 in webkit


Ignore:
Timestamp:
Jul 28, 2010 2:30:11 PM (14 years ago)
Author:
andersca@apple.com
Message:

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.

Location:
trunk
Files:
1 added
15 edited
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r64228 r64231  
     12010-07-28  Anders Carlsson  <andersca@apple.com>
     2
     3        Reviewed by Sam Weinig.
     4
     5        Add support for calling NPObject methods
     6        https://bugs.webkit.org/show_bug.cgi?id=43145
     7
     8        * platform/mac-wk2/Skipped:
     9        Remove plugins/npruntime/get-int-identifier-special-values.html since it passes now.
     10
    1112010-07-28  Victor Wang  <victorw@chromium.org>
    212
  • trunk/LayoutTests/platform/mac-wk2/Skipped

    r64174 r64231  
    14141414plugins/npruntime/bindings-test.html
    14151415plugins/npruntime/enumerate.html
    1416 plugins/npruntime/get-int-identifier-special-values.html
    14171416plugins/npruntime/get-property-return-value.html
    14181417plugins/npruntime/identifier-conversion.html
  • trunk/WebCore/ChangeLog

    r64230 r64231  
     12010-07-28  Anders Carlsson  <andersca@apple.com>
     2
     3        Reviewed by Sam Weinig.
     4
     5        Add support for calling NPObject methods
     6        https://bugs.webkit.org/show_bug.cgi?id=43145
     7
     8        * WebCore.exp.in:
     9        Export JSHTMLElement::s_info and pluginScriptObject.
     10
     11        * WebCore.xcodeproj/project.pbxproj:
     12        Make JSHTMLElement.h and JSPluginElementFunctions.h private headers.
     13
     14        * bindings/js/JSPluginElementFunctions.cpp:
     15        (WebCore::pluginScriptObject):
     16        * bindings/js/JSPluginElementFunctions.h:
     17        Make pluginScriptObject a public function.
     18
    1192010-07-28  James Robinson  <jamesr@chromium.org>
    220
  • trunk/WebCore/WebCore.exp.in

    r64208 r64231  
    286286__ZN7WebCore13IdentifierRep3getEPKc
    287287__ZN7WebCore13IdentifierRep3getEi
     288__ZN7WebCore13JSHTMLElement6s_infoE
    288289__ZN7WebCore13KeyboardEventC1ERKNS_12AtomicStringEbbPNS_9DOMWindowERKNS_6StringEjbbbbb
    289290__ZN7WebCore13TypingCommand39insertParagraphSeparatorInQuotedContentEPNS_8DocumentE
     
    409410__ZN7WebCore18deprecatedParseURLERKNS_6StringE
    410411__ZN7WebCore18isStartOfParagraphERKNS_15VisiblePositionE
     412__ZN7WebCore18pluginScriptObjectEPN3JSC9ExecStateEPNS_13JSHTMLElementE
    411413__ZN7WebCore19AnimationController16resumeAnimationsEPNS_8DocumentE
    412414__ZN7WebCore19AnimationController17suspendAnimationsEPNS_8DocumentE
  • trunk/WebCore/WebCore.xcodeproj/project.pbxproj

    r64196 r64231  
    353353                1A3417CA0CECFF250049CBDE /* JSCustomVoidCallback.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1A3417C80CECFF250049CBDE /* JSCustomVoidCallback.cpp */; };
    354354                1A494BFA0A122F4400FDAFC1 /* JSHTMLElement.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1A494BF80A122F4400FDAFC1 /* JSHTMLElement.cpp */; };
    355                 1A494BFB0A122F4400FDAFC1 /* JSHTMLElement.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A494BF90A122F4400FDAFC1 /* JSHTMLElement.h */; };
     355                1A494BFB0A122F4400FDAFC1 /* JSHTMLElement.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A494BF90A122F4400FDAFC1 /* JSHTMLElement.h */; settings = {ATTRIBUTES = (Private, ); }; };
    356356                1A494E340A12358B00FDAFC1 /* JSHTMLDocument.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1A494E320A12358A00FDAFC1 /* JSHTMLDocument.cpp */; };
    357357                1A494E350A12358B00FDAFC1 /* JSHTMLDocument.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A494E330A12358B00FDAFC1 /* JSHTMLDocument.h */; };
     
    25162516                93B70D6A09EB0C7C009D8468 /* JSEventListener.h in Headers */ = {isa = PBXBuildFile; fileRef = 93B70D4E09EB0C7C009D8468 /* JSEventListener.h */; };
    25172517                93B70D6B09EB0C7C009D8468 /* JSPluginElementFunctions.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 93B70D4F09EB0C7C009D8468 /* JSPluginElementFunctions.cpp */; };
    2518                 93B70D6C09EB0C7C009D8468 /* JSPluginElementFunctions.h in Headers */ = {isa = PBXBuildFile; fileRef = 93B70D5009EB0C7C009D8468 /* JSPluginElementFunctions.h */; };
     2518                93B70D6C09EB0C7C009D8468 /* JSPluginElementFunctions.h in Headers */ = {isa = PBXBuildFile; fileRef = 93B70D5009EB0C7C009D8468 /* JSPluginElementFunctions.h */; settings = {ATTRIBUTES = (Private, ); }; };
    25192519                93B70D6F09EB0C7C009D8468 /* ScriptController.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 93B70D5309EB0C7C009D8468 /* ScriptController.cpp */; };
    25202520                93B70D7009EB0C7C009D8468 /* ScriptController.h in Headers */ = {isa = PBXBuildFile; fileRef = 93B70D5409EB0C7C009D8468 /* ScriptController.h */; settings = {ATTRIBUTES = (Private, ); }; };
  • trunk/WebCore/bindings/js/JSPluginElementFunctions.cpp

    r64093 r64231  
    5050}
    5151
    52 static JSObject* pluginScriptObject(ExecState* exec, JSHTMLElement* jsHTMLElement)
     52JSObject* pluginScriptObject(ExecState* exec, JSHTMLElement* jsHTMLElement)
    5353{
    5454    HTMLElement* element = jsHTMLElement->impl();
  • trunk/WebCore/bindings/js/JSPluginElementFunctions.h

    r64093 r64231  
    3737    // Runtime object support code for JSHTMLAppletElement, JSHTMLEmbedElement and JSHTMLObjectElement.
    3838    JSC::Bindings::Instance* pluginInstance(Node*);
     39    JSC::JSObject* pluginScriptObject(JSC::ExecState* exec, JSHTMLElement* jsHTMLElement);
    3940
    4041    JSC::JSValue runtimeObjectPropertyGetter(JSC::ExecState*, JSC::JSValue, const JSC::Identifier&);
  • trunk/WebKit2/ChangeLog

    r64224 r64231  
     12010-07-28  Anders Carlsson  <andersca@apple.com>
     2
     3        Reviewed by Sam Weinig.
     4
     5        Add support for calling NPObject methods
     6        https://bugs.webkit.org/show_bug.cgi?id=43145
     7
     8        * WebKit2.xcodeproj/project.pbxproj:
     9        Add JSNPMethod.cpp and JSNPMethod.h
     10   
     11        * WebProcess/Plugins/JSNPMethod.cpp: Added.
     12        * WebProcess/Plugins/JSNPMethod.h: Added.
     13        * WebProcess/Plugins/JSNPObject.cpp:
     14        (WebKit::):
     15        Add a ClassInfo static variable for JSNPObject.
     16
     17        (WebKit::JSNPObject::callMethod):
     18        Convert the passed in arguments, call the method and convert the result back.
     19
     20        (WebKit::JSNPObject::getOwnPropertySlot):
     21        Check if the NPObject has a method.
     22
     23        (WebKit::JSNPObject::methodGetter):
     24        Return a new JSNPMethod.
     25
     26        * WebProcess/Plugins/JSNPObject.h:
     27        (WebKit::JSNPObject::classInfo):
     28        Return the s_info.
     29
     30        * WebProcess/Plugins/NPJSObject.cpp:
     31        (WebKit::NPJSObject::getProperty):
     32        Get the property from the JSObject.
     33
     34        * WebProcess/Plugins/NPRuntimeObjectMap.cpp:
     35        (WebKit::NPRuntimeObjectMap::convertJSValueToNPVariant):
     36        Convert the given JSValue to an NPVariant.
     37
     38        * win/WebKit2.vcproj:
     39        Add JSNPMethod.cpp and JSNPMethod.h
     40
    1412010-07-28  Adam Roben  <aroben@apple.com>
    242
  • trunk/WebKit2/WebKit2.xcodeproj/project.pbxproj

    r64167 r64231  
    7676                1AE4987811FF7FAA0048B464 /* JSNPObject.h in Headers */ = {isa = PBXBuildFile; fileRef = 1AE4987611FF7FAA0048B464 /* JSNPObject.h */; };
    7777                1AE4987911FF7FAA0048B464 /* JSNPObject.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1AE4987711FF7FAA0048B464 /* JSNPObject.cpp */; };
     78                1AE49A4911FFA8CE0048B464 /* JSNPMethod.h in Headers */ = {isa = PBXBuildFile; fileRef = 1AE49A4711FFA8CE0048B464 /* JSNPMethod.h */; };
     79                1AE49A4A11FFA8CE0048B464 /* JSNPMethod.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1AE49A4811FFA8CE0048B464 /* JSNPMethod.cpp */; };
    7880                1AE5B7FB11E7AED200BA6767 /* NetscapePluginMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1AE5B7F911E7AED200BA6767 /* NetscapePluginMac.mm */; };
    7981                1AEFCC1211D01F96008219D3 /* PluginInfoStore.h in Headers */ = {isa = PBXBuildFile; fileRef = 1AEFCC1011D01F96008219D3 /* PluginInfoStore.h */; };
     
    365367                1AE4987611FF7FAA0048B464 /* JSNPObject.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSNPObject.h; sourceTree = "<group>"; };
    366368                1AE4987711FF7FAA0048B464 /* JSNPObject.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSNPObject.cpp; sourceTree = "<group>"; };
     369                1AE49A4711FFA8CE0048B464 /* JSNPMethod.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSNPMethod.h; sourceTree = "<group>"; };
     370                1AE49A4811FFA8CE0048B464 /* JSNPMethod.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSNPMethod.cpp; sourceTree = "<group>"; };
    367371                1AE5B7F911E7AED200BA6767 /* NetscapePluginMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = NetscapePluginMac.mm; sourceTree = "<group>"; };
    368372                1AEFCC1011D01F96008219D3 /* PluginInfoStore.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PluginInfoStore.h; sourceTree = "<group>"; };
     
    682686                        children = (
    683687                                1A6FB90811E66FB100DB1371 /* Netscape */,
     688                                1AE49A4811FFA8CE0048B464 /* JSNPMethod.cpp */,
     689                                1AE49A4711FFA8CE0048B464 /* JSNPMethod.h */,
    684690                                1AE4987711FF7FAA0048B464 /* JSNPObject.cpp */,
    685691                                1AE4987611FF7FAA0048B464 /* JSNPObject.h */,
     
    12961302                                1AE4976811FF658E0048B464 /* NPJSObject.h in Headers */,
    12971303                                1AE4987811FF7FAA0048B464 /* JSNPObject.h in Headers */,
     1304                                1AE49A4911FFA8CE0048B464 /* JSNPMethod.h in Headers */,
    12981305                        );
    12991306                        runOnlyForDeploymentPostprocessing = 0;
     
    14951502                                1AE4976911FF658E0048B464 /* NPJSObject.cpp in Sources */,
    14961503                                1AE4987911FF7FAA0048B464 /* JSNPObject.cpp in Sources */,
     1504                                1AE49A4A11FFA8CE0048B464 /* JSNPMethod.cpp in Sources */,
    14971505                        );
    14981506                        runOnlyForDeploymentPostprocessing = 0;
  • trunk/WebKit2/WebProcess/Plugins/JSNPMethod.h

    r64230 r64231  
    2424 */
    2525
    26 #ifndef JSNPObject_h
    27 #define JSNPObject_h
     26#ifndef JSNPMethod_h
     27#define JSNPMethod_h
    2828
    29 #include <JavaScriptCore/JSObjectWithGlobalObject.h>
     29#include <JavaScriptCore/InternalFunction.h>
    3030
    31 struct NPObject;
     31typedef void* NPIdentifier;
    3232
    3333namespace WebKit {
    3434
    35 class NPRuntimeObjectMap;
    36    
    37 // JSNPObject is a JSObject that wraps an NPObject.
     35// A JSObject that wraps an NPMethod.
     36class JSNPMethod : public JSC::InternalFunction {
     37public:
     38    JSNPMethod(JSC::ExecState*, JSC::JSGlobalObject*, const JSC::Identifier&, NPIdentifier);
    3839
    39 class JSNPObject : public JSC::JSObjectWithGlobalObject {
    40 public:
    41     JSNPObject(JSC::ExecState*, JSC::JSGlobalObject*, NPRuntimeObjectMap* objectMap, NPObject* npObject);
    42     ~JSNPObject();
     40    static const JSC::ClassInfo s_info;
    4341
    44 private:
    45     static const unsigned StructureFlags = JSC::OverridesGetOwnPropertySlot | JSObject::StructureFlags;
    46    
     42    NPIdentifier npIdentifier() const { return m_npIdentifier; }
     43
     44private:   
    4745    static PassRefPtr<JSC::Structure> createStructure(JSC::JSValue prototype)
    4846    {
     
    5048    }
    5149
    52     virtual bool getOwnPropertySlot(JSC::ExecState*, const JSC::Identifier& propertyName, JSC::PropertySlot&);
     50    virtual JSC::CallType getCallData(JSC::CallData&);
     51    virtual const JSC::ClassInfo* classInfo() const { return &s_info; }
     52   
     53    NPIdentifier m_npIdentifier;
     54};
    5355
    54     static JSC::JSValue propertyGetter(JSC::ExecState*, JSC::JSValue, const JSC::Identifier&);
    55     static JSC::JSObject* throwInvalidAccessError(JSC::ExecState*);
    56 
    57     NPRuntimeObjectMap* m_objectMap;
    58     NPObject* m_npObject;
    59 };
    6056
    6157} // namespace WebKit
    6258
    63 #endif // JSNPObject_h
     59#endif // JSNPMethod_h
  • trunk/WebKit2/WebProcess/Plugins/JSNPObject.cpp

    r64181 r64231  
    2626#include "JSNPObject.h"
    2727
     28#include "JSNPMethod.h"
    2829#include "NPRuntimeObjectMap.h"
    2930#include "NPRuntimeUtilities.h"
    3031#include <JavaScriptCore/Error.h>
    3132#include <JavaScriptCore/JSGlobalObject.h>
     33#include <JavaScriptCore/ObjectPrototype.h>
    3234#include <JavaScriptCore/JSLock.h>
    33 #include <JavaScriptCore/ObjectPrototype.h>
    3435#include <WebCore/IdentifierRep.h>
    3536
     
    4344    return static_cast<NPIdentifier>(IdentifierRep::get(identifier.ascii()));
    4445}
    45    
     46
     47const ClassInfo JSNPObject::s_info = { "NPObject", 0, 0, 0 };
     48
    4649JSNPObject::JSNPObject(ExecState*, JSGlobalObject* globalObject, NPRuntimeObjectMap* objectMap, NPObject* npObject)
    4750    : JSObjectWithGlobalObject(globalObject, createStructure(globalObject->objectPrototype()))
     
    5760}
    5861
     62JSValue JSNPObject::callMethod(ExecState* exec, NPIdentifier methodName)
     63{
     64    if (!m_npObject->_class->hasMethod(m_npObject, methodName))
     65        return jsUndefined();
     66
     67    size_t argumentCount = exec->argumentCount();
     68    Vector<NPVariant, 8> arguments(argumentCount);
     69
     70    // Convert all arguments to NPVariants.
     71    for (size_t i = 0; i < argumentCount; ++i)
     72        m_objectMap->convertJSValueToNPVariant(exec, exec->argument(i), arguments[i]);
     73
     74    bool returnValue;
     75    NPVariant result;
     76    VOID_TO_NPVARIANT(result);
     77   
     78    {
     79        JSLock::DropAllLocks dropAllLocks(SilenceAssertionsOnly);
     80        returnValue = m_npObject->_class->invoke(m_npObject, methodName, arguments.data(), argumentCount, &result);
     81
     82        // FIXME: Handle invoke setting an exception.
     83        // FIXME: Find out what happens if calling invoke causes the plug-in to go away.
     84    }
     85
     86    // Release all arguments;
     87    for (size_t i = 0; i < argumentCount; ++i)
     88        releaseNPVariantValue(&arguments[i]);
     89
     90    if (!returnValue)
     91        throwError(exec, createError(exec, "Error calling method on NPObject."));
     92
     93    JSValue propertyValue = m_objectMap->convertNPVariantToJSValue(exec, result);
     94    releaseNPVariantValue(&result);
     95    return propertyValue;
     96}
     97
    5998bool JSNPObject::getOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot)
    6099{
     
    65104   
    66105    NPIdentifier npIdentifier = npIdentifierFromIdentifier(propertyName);
     106
     107    // First, check if the NPObject has a property with this name.
    67108    if (m_npObject->_class->hasProperty && m_npObject->_class->hasProperty(m_npObject, npIdentifier)) {
    68109        slot.setCustom(this, propertyGetter);
     
    70111    }
    71112
    72     // FIXME: Check methods.
     113    // Second, check is the NPObject has a method with this name.
     114    if (m_npObject->_class->hasMethod && m_npObject->_class->hasMethod(m_npObject, npIdentifier)) {
     115        slot.setCustom(this, methodGetter);
     116        return true;
     117    }
     118   
    73119    return false;
    74120}
     
    84130        return jsUndefined();
    85131
    86     NPVariant property;
    87     VOID_TO_NPVARIANT(property);
     132    NPVariant result;
     133    VOID_TO_NPVARIANT(result);
    88134
    89     bool result;
     135    bool returnValue;
    90136    {
    91137        JSLock::DropAllLocks dropAllLocks(SilenceAssertionsOnly);
    92138        NPIdentifier npIdentifier = npIdentifierFromIdentifier(propertyName);
    93         result = thisObj->m_npObject->_class->getProperty(thisObj->m_npObject, npIdentifier, &property);
     139        returnValue = thisObj->m_npObject->_class->getProperty(thisObj->m_npObject, npIdentifier, &result);
    94140       
    95141        // FIXME: Handle getProperty setting an exception.
     
    97143    }
    98144
    99     if (!result)
     145    if (!returnValue)
    100146        return jsUndefined();
    101147
    102     return thisObj->m_objectMap->convertNPVariantToValue(exec, property);
     148    JSValue propertyValue = thisObj->m_objectMap->convertNPVariantToJSValue(exec, result);
     149    releaseNPVariantValue(&result);
     150    return propertyValue;
     151}
     152
     153JSValue JSNPObject::methodGetter(ExecState* exec, JSValue slotBase, const Identifier& methodName)
     154{
     155    JSNPObject* thisObj = static_cast<JSNPObject*>(asObject(slotBase));
     156   
     157    if (!thisObj->m_npObject)
     158        return throwInvalidAccessError(exec);
     159
     160    NPIdentifier npIdentifier = npIdentifierFromIdentifier(methodName);
     161    return new (exec) JSNPMethod(exec, thisObj->globalObject(), methodName, npIdentifier);
    103162}
    104163
  • trunk/WebKit2/WebProcess/Plugins/JSNPObject.h

    r64167 r64231  
    2929#include <JavaScriptCore/JSObjectWithGlobalObject.h>
    3030
     31typedef void* NPIdentifier;
    3132struct NPObject;
    3233
     
    4243    ~JSNPObject();
    4344
     45    JSC::JSValue callMethod(JSC::ExecState*, NPIdentifier methodName);
     46
     47    static const JSC::ClassInfo s_info;
     48
    4449private:
    4550    static const unsigned StructureFlags = JSC::OverridesGetOwnPropertySlot | JSObject::StructureFlags;
     
    5358
    5459    static JSC::JSValue propertyGetter(JSC::ExecState*, JSC::JSValue, const JSC::Identifier&);
     60    static JSC::JSValue methodGetter(JSC::ExecState*, JSC::JSValue, const JSC::Identifier&);
    5561    static JSC::JSObject* throwInvalidAccessError(JSC::ExecState*);
     62
     63    virtual const JSC::ClassInfo* classInfo() const { return &s_info; }
    5664
    5765    NPRuntimeObjectMap* m_objectMap;
  • trunk/WebKit2/WebProcess/Plugins/NPJSObject.cpp

    r64147 r64231  
    2828#include "NPRuntimeObjectMap.h"
    2929#include "NPRuntimeUtilities.h"
     30#include "NotImplemented.h"
    3031#include "PluginView.h"
     32#include <JavaScriptCore/JSLock.h>
    3133#include <JavaScriptCore/JSObject.h>
    3234#include <WebCore/Frame.h> 
     
    9698
    9799    exec->clearException();
    98 
    99100    return result;
    100101}
    101102
    102 bool NPJSObject::getProperty(NPIdentifier identifier, NPVariant* result)
     103bool NPJSObject::getProperty(NPIdentifier propertyName, NPVariant* result)
    103104{
    104     // FIXME: Implement.
    105     return false;
     105    IdentifierRep* identifierRep = static_cast<IdentifierRep*>(propertyName);
     106   
     107    ExecState* exec = m_objectMap->globalExec();
     108    if (!exec)
     109        return false;
     110
     111    JSLock lock(SilenceAssertionsOnly);
     112    JSValue jsResult;
     113    if (identifierRep->isString())
     114        jsResult = m_jsObject->get(exec, identifierFromIdentifierRep(exec, identifierRep));
     115    else
     116        jsResult = m_jsObject->get(exec, identifierRep->number());
     117   
     118    m_objectMap->convertJSValueToNPVariant(exec, jsResult, *result);
     119    exec->clearException();
     120    return true;
    106121}
    107122
  • trunk/WebKit2/WebProcess/Plugins/NPRuntimeObjectMap.cpp

    r64174 r64231  
    2525
    2626#include "NPRuntimeObjectMap.h"
     27
     28#include <JavaScriptCore/JSLock.h>
    2729
    2830#include "JSNPObject.h"
     
    7678}
    7779
    78 JSValue NPRuntimeObjectMap::convertNPVariantToValue(JSC::ExecState* exec, const NPVariant& variant)
     80JSValue NPRuntimeObjectMap::convertNPVariantToJSValue(JSC::ExecState* exec, const NPVariant& variant)
    7981{
    8082    switch (variant.type) {
     
    106108}
    107109
     110void NPRuntimeObjectMap::convertJSValueToNPVariant(ExecState* exec, JSValue value, NPVariant& variant)
     111{
     112    JSLock lock(SilenceAssertionsOnly);
     113
     114    VOID_TO_NPVARIANT(variant);
     115   
     116    if (value.isNull()) {
     117        NULL_TO_NPVARIANT(variant);
     118        return;
     119    }
     120
     121    if (value.isUndefined()) {
     122        VOID_TO_NPVARIANT(variant);
     123        return;
     124    }
     125
     126    if (value.isBoolean()) {
     127        BOOLEAN_TO_NPVARIANT(value.toBoolean(exec), variant);
     128        return;
     129    }
     130
     131    if (value.isNumber()) {
     132        DOUBLE_TO_NPVARIANT(value.toNumber(exec), variant);
     133        return;
     134    }
     135
     136    if (value.isString()) {
     137        CString utf8String = value.toString(exec).UTF8String();
     138
     139        // This should use NPN_MemAlloc, but we know that it uses malloc under the hood.
     140        char* utf8Characters = static_cast<char*>(malloc(utf8String.length()));
     141        memcpy(utf8Characters, utf8String.data(), utf8String.length());
     142       
     143        STRINGN_TO_NPVARIANT(utf8Characters, utf8String.length(), variant);
     144        return;
     145    }
     146
     147    if (value.isObject()) {
     148        JSObject* jsObject = asObject(value);
     149
     150        if (jsObject->classInfo() == &JSNPObject::s_info) {
     151            notImplemented();
     152            return;
     153        }
     154
     155        NPObject* npObject = getOrCreateNPObject(jsObject);
     156        OBJECT_TO_NPVARIANT(npObject, variant);
     157        return;
     158    }
     159
     160    ASSERT_NOT_REACHED();
     161}
     162
    108163void NPRuntimeObjectMap::invalidate()
    109164{
  • trunk/WebKit2/WebProcess/Plugins/NPRuntimeObjectMap.h

    r64174 r64231  
    6161    void jsNPObjectDestroyed(JSNPObject*);
    6262
    63     JSC::JSValue convertNPVariantToValue(JSC::ExecState*, const NPVariant&);
     63    void convertJSValueToNPVariant(JSC::ExecState*, JSC::JSValue, NPVariant&);
     64    JSC::JSValue convertNPVariantToJSValue(JSC::ExecState*, const NPVariant&);
    6465
    6566    // Called when the plug-in is destroyed. Will invalidate all the NPObjects.
  • trunk/WebKit2/win/WebKit2.vcproj

    r64167 r64231  
    753753                                >
    754754                                <File
     755                                        RelativePath="..\WebProcess\Plugins\JSNPMethod.cpp"
     756                                        >
     757                                </File>
     758                                <File
     759                                        RelativePath="..\WebProcess\Plugins\JSNPMethod.h"
     760                                        >
     761                                </File>
     762                                <File
    755763                                        RelativePath="..\WebProcess\Plugins\JSNPObject.cpp"
    756764                                        >
Note: See TracChangeset for help on using the changeset viewer.