Changeset 64312 in webkit


Ignore:
Timestamp:
Jul 29, 2010 3:21:43 PM (14 years ago)
Author:
andersca@apple.com
Message:

Implement NPN_Enumerate
https://bugs.webkit.org/show_bug.cgi?id=43215

Reviewed by Sam Weinig.

  • WebProcess/Plugins/JSNPObject.cpp:

(WebKit::npIdentifierFromIdentifier):
Get the UTF-8 string representation instead of the lossy ASCII representation.

(WebKit::JSNPObject::getOwnPropertyNames):
Implement by calling the NPClass::enumerate function.

  • WebProcess/Plugins/JSNPObject.h:
  • WebProcess/Plugins/NPJSObject.cpp:

(WebKit::NPJSObject::enumerate):
Implement by calling JSObject::getPropertyNames.

(WebKit::NPJSObject::npClass):
(WebKit::NPJSObject::NP_Enumerate):
Call NPJSObject::enumerate.

  • WebProcess/Plugins/NPJSObject.h:
  • WebProcess/Plugins/NPRuntimeUtilities.cpp:

(WebKit::createNPObject):
Fix a comment.

  • WebProcess/Plugins/Netscape/NetscapeBrowserFuncs.cpp:

(WebKit::NPN_Enumerate):
Call the NPClass::enumerate function.

Location:
trunk/WebKit2
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebKit2/ChangeLog

    r64306 r64312  
     12010-07-29  Anders Carlsson  <andersca@apple.com>
     2
     3        Reviewed by Sam Weinig.
     4
     5        Implement NPN_Enumerate
     6        https://bugs.webkit.org/show_bug.cgi?id=43215
     7
     8        * WebProcess/Plugins/JSNPObject.cpp:
     9        (WebKit::npIdentifierFromIdentifier):
     10        Get the UTF-8 string representation instead of the lossy ASCII representation.
     11       
     12        (WebKit::JSNPObject::getOwnPropertyNames):
     13        Implement by calling the NPClass::enumerate function.
     14
     15        * WebProcess/Plugins/JSNPObject.h:
     16        * WebProcess/Plugins/NPJSObject.cpp:
     17        (WebKit::NPJSObject::enumerate):
     18        Implement by calling JSObject::getPropertyNames.
     19
     20        (WebKit::NPJSObject::npClass):
     21        (WebKit::NPJSObject::NP_Enumerate):
     22        Call NPJSObject::enumerate.
     23
     24        * WebProcess/Plugins/NPJSObject.h:
     25        * WebProcess/Plugins/NPRuntimeUtilities.cpp:
     26        (WebKit::createNPObject):
     27        Fix a comment.
     28
     29        * WebProcess/Plugins/Netscape/NetscapeBrowserFuncs.cpp:
     30        (WebKit::NPN_Enumerate):
     31        Call the NPClass::enumerate function.
     32
    1332010-07-29  John Sullivan  <sullivan@apple.com>
    234
  • trunk/WebKit2/WebProcess/Plugins/JSNPObject.cpp

    r64300 r64312  
    3434#include <JavaScriptCore/JSLock.h>
    3535#include <WebCore/IdentifierRep.h>
     36#include <WebCore/PlatformString.h>
    3637
    3738using namespace WebCore;
     
    4243static NPIdentifier npIdentifierFromIdentifier(const Identifier& identifier)
    4344{
    44     return static_cast<NPIdentifier>(IdentifierRep::get(identifier.ascii()));
     45    return static_cast<NPIdentifier>(IdentifierRep::get(identifier.ustring().UTF8String().data()));
    4546}
    4647
     
    228229}
    229230
     231void JSNPObject::getOwnPropertyNames(ExecState* exec, PropertyNameArray& propertyNameArray, EnumerationMode mode)
     232{
     233    if (!m_npObject) {
     234        throwInvalidAccessError(exec);
     235        return;
     236    }
     237
     238    if (!NP_CLASS_STRUCT_VERSION_HAS_ENUM(m_npObject->_class) || !m_npObject->_class->enumerate)
     239        return;
     240
     241    NPIdentifier* identifiers = 0;
     242    uint32_t identifierCount = 0;
     243   
     244    {
     245        JSLock::DropAllLocks dropAllLocks(SilenceAssertionsOnly);
     246
     247        // FIXME: Handle enumerate setting an exception.
     248        // FIXME: Find out what happens if calling enumerate causes the plug-in to go away.
     249        // FIXME: Should we throw an exception if enumerate returns false?
     250        if (!m_npObject->_class->enumerate(m_npObject, &identifiers, &identifierCount))
     251            return;
     252    }
     253
     254    for (uint32_t i = 0; i < identifierCount; ++i) {
     255        IdentifierRep* identifierRep = static_cast<IdentifierRep*>(identifiers[i]);
     256       
     257        Identifier identifier;
     258        if (identifierRep->isString()) {
     259            const char* string = identifierRep->string();
     260            int length = strlen(string);
     261           
     262            identifier = Identifier(exec, String::fromUTF8WithLatin1Fallback(string, length).impl());
     263        } else
     264            identifier = Identifier::from(exec, identifierRep->number());
     265
     266        propertyNameArray.add(identifier);
     267    }
     268
     269    // This should use NPN_MemFree, but we know that it uses free under the hood.
     270    free(identifiers);
     271}
     272
    230273JSValue JSNPObject::propertyGetter(ExecState* exec, JSValue slotBase, const Identifier& propertyName)
    231274{
  • trunk/WebKit2/WebProcess/Plugins/JSNPObject.h

    r64300 r64312  
    6262    virtual void put(JSC::ExecState*, const JSC::Identifier& propertyName, JSC::JSValue, JSC::PutPropertySlot&);
    6363
     64    virtual void getOwnPropertyNames(JSC::ExecState*, JSC::PropertyNameArray&, JSC::EnumerationMode mode = JSC::ExcludeDontEnumProperties);
     65
    6466    static JSC::JSValue propertyGetter(JSC::ExecState*, JSC::JSValue, const JSC::Identifier&);
    6567    static JSC::JSValue methodGetter(JSC::ExecState*, JSC::JSValue, const JSC::Identifier&);
  • trunk/WebKit2/WebProcess/Plugins/NPJSObject.cpp

    r64300 r64312  
    172172}
    173173
     174bool NPJSObject::enumerate(NPIdentifier** identifiers, uint32_t* identifierCount)
     175{
     176    ExecState* exec = m_objectMap->globalExec();
     177    if (!exec)
     178        return false;
     179   
     180    JSLock lock(SilenceAssertionsOnly);
     181
     182    PropertyNameArray propertyNames(exec);
     183    m_jsObject->getPropertyNames(exec, propertyNames);
     184
     185    // This should use NPN_MemAlloc, but we know that it uses malloc under the hood.
     186    NPIdentifier* nameIdentifiers = static_cast<NPIdentifier*>(malloc(sizeof(NPIdentifier) * propertyNames.size()));
     187
     188    for (size_t i = 0; i < propertyNames.size(); ++i)
     189        nameIdentifiers[i] = static_cast<NPIdentifier>(IdentifierRep::get(propertyNames[i].ustring().UTF8String().data()));
     190
     191    *identifiers = nameIdentifiers;
     192    *identifierCount = propertyNames.size();
     193
     194    return true;
     195}
     196
    174197bool NPJSObject::construct(const NPVariant *arguments, uint32_t argumentCount, NPVariant *result)
    175198{
     
    238261        NP_SetProperty,
    239262        0,
    240         0,
     263        NP_Enumerate,
    241264        NP_Construct
    242265    };
     
    289312}
    290313
     314bool NPJSObject::NP_Enumerate(NPObject* npObject, NPIdentifier** identifiers, uint32_t* identifierCount)
     315{
     316    return toNPJSObject(npObject)->enumerate(identifiers, identifierCount);
     317}
     318
    291319bool NPJSObject::NP_Construct(NPObject* npObject, const NPVariant* arguments, uint32_t argumentCount, NPVariant* result)
    292320{
  • trunk/WebKit2/WebProcess/Plugins/NPJSObject.h

    r64300 r64312  
    6666    bool hasProperty(NPIdentifier propertyName);
    6767    bool getProperty(NPIdentifier propertyName, NPVariant* result);
     68    bool enumerate(NPIdentifier** identifiers, uint32_t* identifierCount);
    6869    bool construct(const NPVariant* arguments, uint32_t argumentCount, NPVariant* result);
    6970
     
    7980    static bool NP_GetProperty(NPObject*, NPIdentifier propertyName, NPVariant* result);
    8081    static bool NP_SetProperty(NPObject*, NPIdentifier propertyName, const NPVariant* value);
     82    static bool NP_Enumerate(NPObject*, NPIdentifier** identifiers, uint32_t* identifierCount);
    8183    static bool NP_Construct(NPObject*, const NPVariant* arguments, uint32_t argumentCount, NPVariant* result);
    8284   
  • trunk/WebKit2/WebProcess/Plugins/NPRuntimeUtilities.cpp

    r63636 r64312  
    3636        npObject = npClass->allocate(npp, npClass);
    3737    else {
    38         // This should really call NPN_MemAlloc, but we know that it uses malloc
    39         // under the hood so it's fine.
     38        // This should use NPN_MemAlloc, but we know that it uses malloc under the hood.
    4039        npObject = static_cast<NPObject*>(malloc(sizeof(NPObject)));
    4140    }
  • trunk/WebKit2/WebProcess/Plugins/Netscape/NetscapeBrowserFuncs.cpp

    r64304 r64312  
    632632}
    633633   
    634 static bool NPN_Enumerate(NPP npp, NPObject* npobj, NPIdentifier** identifier, uint32_t* count)
    635 {
    636     notImplemented();
     634static bool NPN_Enumerate(NPP, NPObject* npObject, NPIdentifier** identifiers, uint32_t* identifierCount)
     635{
     636    if (NP_CLASS_STRUCT_VERSION_HAS_ENUM(npObject->_class) && npObject->_class->enumerate)
     637        return npObject->_class->enumerate(npObject, identifiers, identifierCount);
     638
    637639    return false;
    638640}
Note: See TracChangeset for help on using the changeset viewer.