Changeset 64147 in webkit
- Timestamp:
- Jul 27, 2010 12:29:45 PM (14 years ago)
- Location:
- trunk/WebKit2
- Files:
-
- 5 edited
- 2 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/WebKit2/ChangeLog
r64145 r64147 1 2010-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 1 32 2010-07-27 Anders Carlsson <andersca@apple.com> 2 33 -
trunk/WebKit2/WebKit2.xcodeproj/project.pbxproj
r64145 r64147 72 72 1AADE6FF10D855FC00D3D63D /* ApplicationServices.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1AADE6FE10D855FC00D3D63D /* ApplicationServices.framework */; }; 73 73 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 */; }; 74 76 1AE5B7FB11E7AED200BA6767 /* NetscapePluginMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1AE5B7F911E7AED200BA6767 /* NetscapePluginMac.mm */; }; 75 77 1AEFCC1211D01F96008219D3 /* PluginInfoStore.h in Headers */ = {isa = PBXBuildFile; fileRef = 1AEFCC1011D01F96008219D3 /* PluginInfoStore.h */; }; … … 357 359 1AADE6FE10D855FC00D3D63D /* ApplicationServices.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = ApplicationServices.framework; path = System/Library/Frameworks/ApplicationServices.framework; sourceTree = SDKROOT; }; 358 360 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>"; }; 359 363 1AE5B7F911E7AED200BA6767 /* NetscapePluginMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = NetscapePluginMac.mm; sourceTree = "<group>"; }; 360 364 1AEFCC1011D01F96008219D3 /* PluginInfoStore.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PluginInfoStore.h; sourceTree = "<group>"; }; … … 674 678 children = ( 675 679 1A6FB90811E66FB100DB1371 /* Netscape */, 680 1AE4976711FF658E0048B464 /* NPJSObject.cpp */, 681 1AE4976611FF658E0048B464 /* NPJSObject.h */, 676 682 1A2161AF11F37664008AD0F5 /* NPRuntimeObjectMap.cpp */, 677 683 1A2161AE11F37664008AD0F5 /* NPRuntimeObjectMap.h */, … … 1282 1288 BCF049E611FE20F600F86A58 /* WKBundleFramePrivate.h in Headers */, 1283 1289 BCF049E711FE20F600F86A58 /* WKBundlePrivate.h in Headers */, 1290 1AE4976811FF658E0048B464 /* NPJSObject.h in Headers */, 1284 1291 ); 1285 1292 runOnlyForDeploymentPostprocessing = 0; … … 1479 1486 E1EE55F811F8F1BC00CCBEE4 /* WKBundleRange.cpp in Sources */, 1480 1487 E1EE565611F8F71700CCBEE4 /* WKBundleNode.cpp in Sources */, 1488 1AE4976911FF658E0048B464 /* NPJSObject.cpp in Sources */, 1481 1489 ); 1482 1490 runOnlyForDeploymentPostprocessing = 0; -
trunk/WebKit2/WebProcess/Plugins/NPJSObject.cpp
r64145 r64147 24 24 */ 25 25 26 #include "NPJSObject.h" 27 26 28 #include "NPRuntimeObjectMap.h" 27 28 29 #include "NPRuntimeUtilities.h" 29 30 #include "PluginView.h" 30 #include <WebCore/Frame.h> 31 #include <JavaScriptCore/JSObject.h> 32 #include <WebCore/Frame.h> 31 33 #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> 36 35 37 36 using namespace JSC; … … 39 38 40 39 namespace 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 };81 40 82 41 NPJSObject* NPJSObject::create(NPRuntimeObjectMap* objectMap, JSObject* jsObject) … … 86 45 87 46 return npJSObject; 47 } 48 49 NPJSObject::NPJSObject() 50 : m_objectMap(0) 51 { 52 } 53 54 NPJSObject::~NPJSObject() 55 { 56 m_objectMap->npJSObjectDestroyed(this); 88 57 } 89 58 … … 116 85 IdentifierRep* identifierRep = static_cast<IdentifierRep*>(identifier); 117 86 118 Frame* frame = m_objectMap->m_pluginView->frame();119 if (! frame)87 ExecState* exec = m_objectMap->globalExec(); 88 if (!exec) 120 89 return false; 121 90 122 91 bool result; 123 ExecState* exec = frame->script()->globalObject(pluginWorld())->globalExec();124 92 if (identifierRep->isString()) 125 93 result = m_jsObject->hasProperty(exec, identifierFromIdentifierRep(exec, identifierRep)); … … 182 150 } 183 151 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 216 152 } // namespace WebKit -
trunk/WebKit2/WebProcess/Plugins/NPJSObject.h
r64145 r64147 24 24 */ 25 25 26 #ifndef NPJSObject WrapperMap_h27 #define NPJSObject WrapperMap_h26 #ifndef NPJSObject_h 27 #define NPJSObject_h 28 28 29 #include < wtf/HashMap.h>30 31 struct NPObject; 29 #include <JavaScriptCore/Protect.h> 30 #include <WebCore/npruntime.h> 31 #include <wtf/Noncopyable.h> 32 32 33 33 namespace JSC { … … 37 37 namespace WebKit { 38 38 39 class NPJSObject; 40 class PluginView; 39 class NPRuntimeObjectMap; 40 41 // NPJSObject is an NPObject that wrappes a JavaScript object. 42 class NPJSObject : public NPObject, Noncopyable { 43 public: 44 static NPJSObject* create(NPRuntimeObjectMap* objectMap, JSC::JSObject* jsObject); 41 45 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(); } 53 47 54 48 private: 55 friend class NPJSObject;56 PluginView* m_pluginView;49 NPJSObject(); 50 ~NPJSObject(); 57 51 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; 59 73 }; 60 74 61 75 } // namespace WebKit 62 76 63 #endif // NPJSObject WrapperMap_h77 #endif // NPJSObject_h -
trunk/WebKit2/WebProcess/Plugins/NPRuntimeObjectMap.cpp
r64145 r64147 26 26 #include "NPRuntimeObjectMap.h" 27 27 28 #include "NPJSObject.h" 28 29 #include "NPRuntimeUtilities.h" 29 30 #include "PluginView.h" 30 31 #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>36 32 37 33 using namespace JSC; … … 40 36 namespace WebKit { 41 37 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 else127 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 0156 };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 }183 38 184 39 NPRuntimeObjectMap::NPRuntimeObjectMap(PluginView* pluginView) … … 201 56 } 202 57 58 void 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 203 65 void NPRuntimeObjectMap::invalidate() 204 66 { … … 214 76 } 215 77 78 ExecState* 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 216 88 } // namespace WebKit -
trunk/WebKit2/WebProcess/Plugins/NPRuntimeObjectMap.h
r64145 r64147 32 32 33 33 namespace JSC { 34 class ExecState; 34 35 class JSObject; 35 36 } … … 41 42 42 43 // A per plug-in map of NPObjects that wrap JavaScript objects. 43 44 44 class NPRuntimeObjectMap { 45 45 public: … … 50 50 NPObject* getOrCreateNPObject(JSC::JSObject*); 51 51 52 void npJSObjectDestroyed(NPJSObject*); 53 54 // Called when the plug-in is destroyed. Will invalidate all the NPObjects. 52 55 void invalidate(); 53 56 57 JSC::ExecState* globalExec() const; 58 54 59 private: 55 friend class NPJSObject;56 60 PluginView* m_pluginView; 57 61 -
trunk/WebKit2/win/WebKit2.vcproj
r64145 r64147 753 753 > 754 754 <File 755 RelativePath="..\WebProcess\Plugins\NPJSObject.cpp" 756 > 757 </File> 758 <File 759 RelativePath="..\WebProcess\Plugins\NPJSObject.h" 760 > 761 </File> 762 <File 755 763 RelativePath="..\WebProcess\Plugins\NPRuntimeObjectMap.cpp" 756 764 >
Note: See TracChangeset
for help on using the changeset viewer.