Changeset 64147 in webkit


Ignore:
Timestamp:
Jul 27, 2010 12:29:45 PM (14 years ago)
Author:
andersca@apple.com
Message:

Move NPJSObject out into separate files
https://bugs.webkit.org/show_bug.cgi?id=43068

Reviewed by Adam Roben.

  • WebKit2.xcodeproj/project.pbxproj:
  • WebProcess/Plugins/NPJSObject.cpp: Added.

(WebKit::NPJSObject::create):
(WebKit::NPJSObject::NPJSObject):
(WebKit::NPJSObject::~NPJSObject):
(WebKit::NPJSObject::isNPJSObject):
(WebKit::NPJSObject::initialize):
(WebKit::identifierFromIdentifierRep):
(WebKit::NPJSObject::hasProperty):
(WebKit::NPJSObject::getProperty):
(WebKit::NPJSObject::npClass):
(WebKit::NPJSObject::NP_Allocate):
(WebKit::NPJSObject::NP_Deallocate):
(WebKit::NPJSObject::NP_HasProperty):
(WebKit::NPJSObject::NP_GetProperty):

  • WebProcess/Plugins/NPJSObject.h: Added.

(WebKit::NPJSObject::jsObject):
(WebKit::NPJSObject::toNPJSObject):

  • WebProcess/Plugins/NPRuntimeObjectMap.cpp:

(WebKit::NPRuntimeObjectMap::npJSObjectDestroyed):
(WebKit::NPRuntimeObjectMap::globalExec):

  • WebProcess/Plugins/NPRuntimeObjectMap.h:
  • win/WebKit2.vcproj:
Location:
trunk/WebKit2
Files:
5 edited
2 copied

Legend:

Unmodified
Added
Removed
  • trunk/WebKit2/ChangeLog

    r64145 r64147  
     12010-07-27  Anders Carlsson  <andersca@apple.com>
     2
     3        Reviewed by Adam Roben.
     4
     5        Move NPJSObject out into separate files
     6        https://bugs.webkit.org/show_bug.cgi?id=43068
     7
     8        * WebKit2.xcodeproj/project.pbxproj:
     9        * WebProcess/Plugins/NPJSObject.cpp: Added.
     10        (WebKit::NPJSObject::create):
     11        (WebKit::NPJSObject::NPJSObject):
     12        (WebKit::NPJSObject::~NPJSObject):
     13        (WebKit::NPJSObject::isNPJSObject):
     14        (WebKit::NPJSObject::initialize):
     15        (WebKit::identifierFromIdentifierRep):
     16        (WebKit::NPJSObject::hasProperty):
     17        (WebKit::NPJSObject::getProperty):
     18        (WebKit::NPJSObject::npClass):
     19        (WebKit::NPJSObject::NP_Allocate):
     20        (WebKit::NPJSObject::NP_Deallocate):
     21        (WebKit::NPJSObject::NP_HasProperty):
     22        (WebKit::NPJSObject::NP_GetProperty):
     23        * WebProcess/Plugins/NPJSObject.h: Added.
     24        (WebKit::NPJSObject::jsObject):
     25        (WebKit::NPJSObject::toNPJSObject):
     26        * WebProcess/Plugins/NPRuntimeObjectMap.cpp:
     27        (WebKit::NPRuntimeObjectMap::npJSObjectDestroyed):
     28        (WebKit::NPRuntimeObjectMap::globalExec):
     29        * WebProcess/Plugins/NPRuntimeObjectMap.h:
     30        * win/WebKit2.vcproj:
     31
    1322010-07-27  Anders Carlsson  <andersca@apple.com>
    233
  • trunk/WebKit2/WebKit2.xcodeproj/project.pbxproj

    r64145 r64147  
    7272                1AADE6FF10D855FC00D3D63D /* ApplicationServices.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1AADE6FE10D855FC00D3D63D /* ApplicationServices.framework */; };
    7373                1AE117F611DBB30900981615 /* ProcessLauncher.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1AE117F511DBB30900981615 /* ProcessLauncher.cpp */; };
     74                1AE4976811FF658E0048B464 /* NPJSObject.h in Headers */ = {isa = PBXBuildFile; fileRef = 1AE4976611FF658E0048B464 /* NPJSObject.h */; };
     75                1AE4976911FF658E0048B464 /* NPJSObject.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1AE4976711FF658E0048B464 /* NPJSObject.cpp */; };
    7476                1AE5B7FB11E7AED200BA6767 /* NetscapePluginMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1AE5B7F911E7AED200BA6767 /* NetscapePluginMac.mm */; };
    7577                1AEFCC1211D01F96008219D3 /* PluginInfoStore.h in Headers */ = {isa = PBXBuildFile; fileRef = 1AEFCC1011D01F96008219D3 /* PluginInfoStore.h */; };
     
    357359                1AADE6FE10D855FC00D3D63D /* ApplicationServices.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = ApplicationServices.framework; path = System/Library/Frameworks/ApplicationServices.framework; sourceTree = SDKROOT; };
    358360                1AE117F511DBB30900981615 /* ProcessLauncher.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ProcessLauncher.cpp; sourceTree = "<group>"; };
     361                1AE4976611FF658E0048B464 /* NPJSObject.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NPJSObject.h; sourceTree = "<group>"; };
     362                1AE4976711FF658E0048B464 /* NPJSObject.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = NPJSObject.cpp; sourceTree = "<group>"; };
    359363                1AE5B7F911E7AED200BA6767 /* NetscapePluginMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = NetscapePluginMac.mm; sourceTree = "<group>"; };
    360364                1AEFCC1011D01F96008219D3 /* PluginInfoStore.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PluginInfoStore.h; sourceTree = "<group>"; };
     
    674678                        children = (
    675679                                1A6FB90811E66FB100DB1371 /* Netscape */,
     680                                1AE4976711FF658E0048B464 /* NPJSObject.cpp */,
     681                                1AE4976611FF658E0048B464 /* NPJSObject.h */,
    676682                                1A2161AF11F37664008AD0F5 /* NPRuntimeObjectMap.cpp */,
    677683                                1A2161AE11F37664008AD0F5 /* NPRuntimeObjectMap.h */,
     
    12821288                                BCF049E611FE20F600F86A58 /* WKBundleFramePrivate.h in Headers */,
    12831289                                BCF049E711FE20F600F86A58 /* WKBundlePrivate.h in Headers */,
     1290                                1AE4976811FF658E0048B464 /* NPJSObject.h in Headers */,
    12841291                        );
    12851292                        runOnlyForDeploymentPostprocessing = 0;
     
    14791486                                E1EE55F811F8F1BC00CCBEE4 /* WKBundleRange.cpp in Sources */,
    14801487                                E1EE565611F8F71700CCBEE4 /* WKBundleNode.cpp in Sources */,
     1488                                1AE4976911FF658E0048B464 /* NPJSObject.cpp in Sources */,
    14811489                        );
    14821490                        runOnlyForDeploymentPostprocessing = 0;
  • trunk/WebKit2/WebProcess/Plugins/NPJSObject.cpp

    r64145 r64147  
    2424 */
    2525
     26#include "NPJSObject.h"
     27
    2628#include "NPRuntimeObjectMap.h"
    27 
    2829#include "NPRuntimeUtilities.h"
    2930#include "PluginView.h"
    30 #include <WebCore/Frame.h>
     31#include <JavaScriptCore/JSObject.h>
     32#include <WebCore/Frame.h> 
    3133#include <WebCore/IdentifierRep.h>
    32 #include <JavaScriptCore/JSObject.h>
    33 #include <JavaScriptCore/Protect.h>
    34 #include <WebKit/npruntime.h>
    35 #include <wtf/Noncopyable.h>
     34#include <WebCore/PlatformString.h>
    3635
    3736using namespace JSC;
     
    3938
    4039namespace WebKit {
    41 
    42 class NPJSObject : public NPObject, Noncopyable {
    43 public:
    44     static NPJSObject* create(NPRuntimeObjectMap* objectMap, JSObject* jsObject);
    45 
    46 private:
    47     NPJSObject()
    48         : m_objectMap(0)
    49     {
    50     }
    51 
    52     ~NPJSObject()
    53     {
    54         // Remove ourselves from the map.
    55         ASSERT(m_objectMap->m_objects.contains(m_jsObject.get()));
    56         m_objectMap->m_objects.remove(m_jsObject.get());
    57     }
    58 
    59     static bool isNPJSObject(NPObject*);
    60 
    61     static NPJSObject* toNPJSObject(NPObject* npObject)
    62     {
    63         ASSERT(isNPJSObject(npObject));
    64         return static_cast<NPJSObject*>(npObject);
    65     }
    66 
    67     void initialize(NPRuntimeObjectMap*, JSObject* jsObject);
    68 
    69     bool hasProperty(NPIdentifier);
    70     bool getProperty(NPIdentifier, NPVariant* result);
    71 
    72     static NPClass* npClass();
    73     static NPObject* NP_Allocate(NPP, NPClass*);
    74     static void NP_Deallocate(NPObject*);
    75     static bool NP_HasProperty(NPObject* npobj, NPIdentifier name);
    76     static bool NP_GetProperty(NPObject* npobj, NPIdentifier name, NPVariant* result);
    77    
    78     NPRuntimeObjectMap* m_objectMap;
    79     ProtectedPtr<JSObject> m_jsObject;
    80 };
    8140
    8241NPJSObject* NPJSObject::create(NPRuntimeObjectMap* objectMap, JSObject* jsObject)
     
    8645
    8746    return npJSObject;
     47}
     48
     49NPJSObject::NPJSObject()
     50    : m_objectMap(0)
     51{
     52}
     53
     54NPJSObject::~NPJSObject()
     55{
     56    m_objectMap->npJSObjectDestroyed(this);
    8857}
    8958
     
    11685    IdentifierRep* identifierRep = static_cast<IdentifierRep*>(identifier);
    11786   
    118     Frame* frame = m_objectMap->m_pluginView->frame();
    119     if (!frame)
     87    ExecState* exec = m_objectMap->globalExec();
     88    if (!exec)
    12089        return false;
    121 
     90   
    12291    bool result;
    123     ExecState* exec = frame->script()->globalObject(pluginWorld())->globalExec();
    12492    if (identifierRep->isString())
    12593        result = m_jsObject->hasProperty(exec, identifierFromIdentifierRep(exec, identifierRep));
     
    182150}
    183151
    184 NPRuntimeObjectMap::NPRuntimeObjectMap(PluginView* pluginView)
    185     : m_pluginView(pluginView)
    186 {
    187 }
    188 
    189 NPObject* NPRuntimeObjectMap::getOrCreateNPObject(JSObject* jsObject)
    190 {
    191     // First, check if we already know about this object.
    192     if (NPJSObject* npJSObject = m_objects.get(jsObject)) {
    193         retainNPObject(npJSObject);
    194         return npJSObject;
    195     }
    196 
    197     NPJSObject* npJSObject = NPJSObject::create(this, jsObject);
    198     m_objects.set(jsObject, npJSObject);
    199 
    200     return npJSObject;
    201 }
    202 
    203 void NPRuntimeObjectMap::invalidate()
    204 {
    205     Vector<NPJSObject*> npJSObjects;
    206     copyValuesToVector(m_objects, npJSObjects);
    207 
    208     // Deallocate all the object wrappers so we won't leak any JavaScript objects.
    209     for (size_t i = 0; i < npJSObjects.size(); ++i)
    210         deallocateNPObject(npJSObjects[i]);
    211    
    212     // We shouldn't have any objects left now.
    213     ASSERT(m_objects.isEmpty());
    214 }
    215 
    216152} // namespace WebKit
  • trunk/WebKit2/WebProcess/Plugins/NPJSObject.h

    r64145 r64147  
    2424 */
    2525
    26 #ifndef NPJSObjectWrapperMap_h
    27 #define NPJSObjectWrapperMap_h
     26#ifndef NPJSObject_h
     27#define NPJSObject_h
    2828
    29 #include <wtf/HashMap.h>
    30 
    31 struct NPObject;
     29#include <JavaScriptCore/Protect.h>
     30#include <WebCore/npruntime.h>
     31#include <wtf/Noncopyable.h>
    3232
    3333namespace JSC {
     
    3737namespace WebKit {
    3838
    39 class NPJSObject;
    40 class PluginView;
     39class NPRuntimeObjectMap;
     40   
     41// NPJSObject is an NPObject that wrappes a JavaScript object.
     42class NPJSObject : public NPObject, Noncopyable {
     43public:
     44    static NPJSObject* create(NPRuntimeObjectMap* objectMap, JSC::JSObject* jsObject);
    4145
    42 // A per plug-in map of NPObjects that wrap JavaScript objects.
    43 
    44 class NPRuntimeObjectMap {
    45 public:
    46     explicit NPRuntimeObjectMap(PluginView*);
    47 
    48     // Returns an NPObject that wraps the given JavaScript object. If there is already an NPObject that wraps this JSObject, it will
    49     // retain it and return it.
    50     NPObject* getOrCreateNPObject(JSC::JSObject*);
    51 
    52     void invalidate();
     46    JSC::JSObject* jsObject() const { return m_jsObject.get(); }
    5347
    5448private:
    55     friend class NPJSObject;
    56     PluginView* m_pluginView;
     49    NPJSObject();
     50    ~NPJSObject();
    5751
    58     HashMap<JSC::JSObject*, NPJSObject*> m_objects;
     52    static bool isNPJSObject(NPObject*);
     53
     54    static NPJSObject* toNPJSObject(NPObject* npObject)
     55    {
     56        ASSERT(isNPJSObject(npObject));
     57        return static_cast<NPJSObject*>(npObject);
     58    }
     59
     60    void initialize(NPRuntimeObjectMap*, JSC::JSObject* jsObject);
     61
     62    bool hasProperty(NPIdentifier);
     63    bool getProperty(NPIdentifier, NPVariant* result);
     64
     65    static NPClass* npClass();
     66    static NPObject* NP_Allocate(NPP, NPClass*);
     67    static void NP_Deallocate(NPObject*);
     68    static bool NP_HasProperty(NPObject* npobj, NPIdentifier name);
     69    static bool NP_GetProperty(NPObject* npobj, NPIdentifier name, NPVariant* result);
     70   
     71    NPRuntimeObjectMap* m_objectMap;
     72    JSC::ProtectedPtr<JSC::JSObject> m_jsObject;
    5973};
    6074
    6175} // namespace WebKit
    6276
    63 #endif // NPJSObjectWrapperMap_h
     77#endif // NPJSObject_h
  • trunk/WebKit2/WebProcess/Plugins/NPRuntimeObjectMap.cpp

    r64145 r64147  
    2626#include "NPRuntimeObjectMap.h"
    2727
     28#include "NPJSObject.h"
    2829#include "NPRuntimeUtilities.h"
    2930#include "PluginView.h"
    3031#include <WebCore/Frame.h>
    31 #include <WebCore/IdentifierRep.h>
    32 #include <JavaScriptCore/JSObject.h>
    33 #include <JavaScriptCore/Protect.h>
    34 #include <WebKit/npruntime.h>
    35 #include <wtf/Noncopyable.h>
    3632
    3733using namespace JSC;
     
    4036namespace WebKit {
    4137
    42 class NPJSObject : public NPObject, Noncopyable {
    43 public:
    44     static NPJSObject* create(NPRuntimeObjectMap* objectMap, JSObject* jsObject);
    45 
    46 private:
    47     NPJSObject()
    48         : m_objectMap(0)
    49     {
    50     }
    51 
    52     ~NPJSObject()
    53     {
    54         // Remove ourselves from the map.
    55         ASSERT(m_objectMap->m_objects.contains(m_jsObject.get()));
    56         m_objectMap->m_objects.remove(m_jsObject.get());
    57     }
    58 
    59     static bool isNPJSObject(NPObject*);
    60 
    61     static NPJSObject* toNPJSObject(NPObject* npObject)
    62     {
    63         ASSERT(isNPJSObject(npObject));
    64         return static_cast<NPJSObject*>(npObject);
    65     }
    66 
    67     void initialize(NPRuntimeObjectMap*, JSObject* jsObject);
    68 
    69     bool hasProperty(NPIdentifier);
    70     bool getProperty(NPIdentifier, NPVariant* result);
    71 
    72     static NPClass* npClass();
    73     static NPObject* NP_Allocate(NPP, NPClass*);
    74     static void NP_Deallocate(NPObject*);
    75     static bool NP_HasProperty(NPObject* npobj, NPIdentifier name);
    76     static bool NP_GetProperty(NPObject* npobj, NPIdentifier name, NPVariant* result);
    77    
    78     NPRuntimeObjectMap* m_objectMap;
    79     ProtectedPtr<JSObject> m_jsObject;
    80 };
    81 
    82 NPJSObject* NPJSObject::create(NPRuntimeObjectMap* objectMap, JSObject* jsObject)
    83 {
    84     NPJSObject* npJSObject = toNPJSObject(createNPObject(0, npClass()));
    85     npJSObject->initialize(objectMap, jsObject);
    86 
    87     return npJSObject;
    88 }
    89 
    90 bool NPJSObject::isNPJSObject(NPObject* npObject)
    91 {
    92     return npObject->_class == npClass();
    93 }
    94 
    95 void NPJSObject::initialize(NPRuntimeObjectMap* objectMap, JSObject* jsObject)
    96 {
    97     ASSERT(!m_objectMap);
    98     ASSERT(!m_jsObject);
    99 
    100     m_objectMap = objectMap;
    101     m_jsObject = jsObject;
    102 }
    103 
    104 static Identifier identifierFromIdentifierRep(ExecState* exec, IdentifierRep* identifierRep)
    105 {
    106     ASSERT(identifierRep->isString());
    107 
    108     const char* string = identifierRep->string();
    109     int length = strlen(string);
    110 
    111     return Identifier(exec, String::fromUTF8WithLatin1Fallback(string, length).impl());
    112 }
    113 
    114 bool NPJSObject::hasProperty(NPIdentifier identifier)
    115 {
    116     IdentifierRep* identifierRep = static_cast<IdentifierRep*>(identifier);
    117    
    118     Frame* frame = m_objectMap->m_pluginView->frame();
    119     if (!frame)
    120         return false;
    121 
    122     bool result;
    123     ExecState* exec = frame->script()->globalObject(pluginWorld())->globalExec();
    124     if (identifierRep->isString())
    125         result = m_jsObject->hasProperty(exec, identifierFromIdentifierRep(exec, identifierRep));
    126     else
    127         result = m_jsObject->hasProperty(exec, identifierRep->number());
    128 
    129     exec->clearException();
    130 
    131     return result;
    132 }
    133 
    134 bool NPJSObject::getProperty(NPIdentifier identifier, NPVariant* result)
    135 {
    136     // FIXME: Implement.
    137     return false;
    138 }
    139 
    140 NPClass* NPJSObject::npClass()
    141 {
    142     static NPClass npClass = {
    143         NP_CLASS_STRUCT_VERSION,
    144         NP_Allocate,
    145         NP_Deallocate,
    146         0,
    147         0,
    148         0,
    149         0,
    150         NP_HasProperty,
    151         NP_GetProperty,
    152         0,
    153         0,
    154         0,
    155         0
    156     };
    157 
    158     return &npClass;
    159 }
    160    
    161 NPObject* NPJSObject::NP_Allocate(NPP npp, NPClass* npClass)
    162 {
    163     ASSERT_UNUSED(npp, !npp);
    164 
    165     return new NPJSObject;
    166 }
    167 
    168 void NPJSObject::NP_Deallocate(NPObject* npObject)
    169 {
    170     NPJSObject* npJSObject = toNPJSObject(npObject);
    171     delete npJSObject;
    172 }
    173 
    174 bool NPJSObject::NP_HasProperty(NPObject* npObject, NPIdentifier propertyName)
    175 {
    176     return toNPJSObject(npObject)->hasProperty(propertyName);
    177 }
    178    
    179 bool NPJSObject::NP_GetProperty(NPObject* npObject, NPIdentifier propertyName, NPVariant* result)
    180 {
    181     return toNPJSObject(npObject)->getProperty(propertyName, result);
    182 }
    18338
    18439NPRuntimeObjectMap::NPRuntimeObjectMap(PluginView* pluginView)
     
    20156}
    20257
     58void NPRuntimeObjectMap::npJSObjectDestroyed(NPJSObject* npJSObject)
     59{
     60    // Remove the object from the map.
     61    ASSERT(m_objects.contains(npJSObject->jsObject()));
     62    m_objects.remove(npJSObject->jsObject());
     63}
     64
    20365void NPRuntimeObjectMap::invalidate()
    20466{
     
    21476}
    21577
     78ExecState* NPRuntimeObjectMap::globalExec() const
     79{
     80    Frame* frame = m_pluginView->frame();
     81    if (!frame)
     82        return 0;
     83   
     84    return frame->script()->globalObject(pluginWorld())->globalExec();
     85}
     86
     87
    21688} // namespace WebKit
  • trunk/WebKit2/WebProcess/Plugins/NPRuntimeObjectMap.h

    r64145 r64147  
    3232
    3333namespace JSC {
     34    class ExecState;
    3435    class JSObject;
    3536}
     
    4142
    4243// A per plug-in map of NPObjects that wrap JavaScript objects.
    43 
    4444class NPRuntimeObjectMap {
    4545public:
     
    5050    NPObject* getOrCreateNPObject(JSC::JSObject*);
    5151
     52    void npJSObjectDestroyed(NPJSObject*);
     53
     54    // Called when the plug-in is destroyed. Will invalidate all the NPObjects.
    5255    void invalidate();
    5356
     57    JSC::ExecState* globalExec() const;
     58
    5459private:
    55     friend class NPJSObject;
    5660    PluginView* m_pluginView;
    5761
  • trunk/WebKit2/win/WebKit2.vcproj

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