Changeset 71169 in webkit
- Timestamp:
- Nov 2, 2010 2:18:18 PM (13 years ago)
- Location:
- trunk/WebKit2
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/WebKit2/ChangeLog
r71168 r71169 1 2010-11-02 Anders Carlsson <andersca@apple.com> 2 3 Reviewed by Dan Bernstein. 4 5 Add convenience functions for allocating NPAPI memory 6 https://bugs.webkit.org/show_bug.cgi?id=48870 7 8 Add npnMemAlloc, npnMemFree and createNPString functions and 9 npnMemNew, npnMemNewArray function templates. 10 11 * WebProcess/Plugins/Netscape/JSNPObject.cpp: 12 (WebKit::JSNPObject::getOwnPropertyNames): 13 Use npnMemFree. 14 15 * WebProcess/Plugins/Netscape/NPJSObject.cpp: 16 (WebKit::NPJSObject::enumerate): 17 Use npnMemNewArray. 18 19 * WebProcess/Plugins/Netscape/NPRuntimeObjectMap.cpp: 20 (WebKit::NPRuntimeObjectMap::convertJSValueToNPVariant): 21 Use createNPString. 22 23 * WebProcess/Plugins/Netscape/NPRuntimeUtilities.cpp: 24 (WebKit::npnMemAlloc): 25 Call malloc. 26 27 (WebKit::npnMemFree): 28 Call free. 29 30 (WebKit::createNPString): 31 Allocate the characters for a new NPString. 32 33 (WebKit::createNPObject): 34 Call npnMemNew. 35 36 (WebKit::deallocateNPObject): 37 Call npnMemFree. 38 39 (WebKit::releaseNPVariantValue): 40 Call npnMemFree. 41 42 * WebProcess/Plugins/Netscape/NPRuntimeUtilities.h: 43 (WebKit::npnMemNew): 44 (WebKit::npnMemNewArray): 45 Add new functions. 46 47 * WebProcess/Plugins/Netscape/NetscapeBrowserFuncs.cpp: 48 (WebKit::NPN_MemAlloc): 49 Call npnMemAlloc. 50 51 (WebKit::NPN_MemFree): 52 Call npnMemFree. 53 54 (WebKit::NPN_UTF8FromIdentifier): 55 Call npnMemNewArray. 56 57 (WebKit::copyCString): 58 Call npnMemNewArray. Correctly initialize the "len" out parameter. 59 1 60 2010-11-02 Jessie Berlin <jberlin@apple.com> 2 61 -
trunk/WebKit2/WebProcess/Plugins/Netscape/JSNPObject.cpp
r70898 r71169 356 356 } 357 357 358 // This should use NPN_MemFree, but we know that it uses free under the hood. 359 free(identifiers); 358 npnMemFree(identifiers); 360 359 } 361 360 -
trunk/WebKit2/WebProcess/Plugins/Netscape/NPJSObject.cpp
r71054 r71169 239 239 m_jsObject->getPropertyNames(exec, propertyNames); 240 240 241 // This should use NPN_MemAlloc, but we know that it uses malloc under the hood. 242 NPIdentifier* nameIdentifiers = static_cast<NPIdentifier*>(malloc(sizeof(NPIdentifier) * propertyNames.size())); 241 NPIdentifier* nameIdentifiers = npnMemNewArray<NPIdentifier>(propertyNames.size()); 243 242 244 243 for (size_t i = 0; i < propertyNames.size(); ++i) -
trunk/WebKit2/WebProcess/Plugins/Netscape/NPRuntimeObjectMap.cpp
r70898 r71169 166 166 167 167 if (value.isString()) { 168 CString utf8String = value.toString(exec).utf8(); 169 170 // This should use NPN_MemAlloc, but we know that it uses malloc under the hood. 171 char* utf8Characters = static_cast<char*>(malloc(utf8String.length())); 172 memcpy(utf8Characters, utf8String.data(), utf8String.length()); 173 174 STRINGN_TO_NPVARIANT(utf8Characters, utf8String.length(), variant); 168 NPString npString = createNPString(value.toString(exec).utf8()); 169 STRINGN_TO_NPVARIANT(npString.UTF8Characters, npString.UTF8Length, variant); 175 170 return; 176 171 } -
trunk/WebKit2/WebProcess/Plugins/Netscape/NPRuntimeUtilities.cpp
r70898 r71169 26 26 #include "NPRuntimeUtilities.h" 27 27 28 #include <wtf/text/CString.h> 29 28 30 namespace WebKit { 31 32 void* npnMemAlloc(uint32_t size) 33 { 34 // We could use fastMalloc here, but there might be plug-ins that mix NPN_MemAlloc/NPN_MemFree with malloc and free, 35 // so having them be equivalent seems like a good idea. 36 return malloc(size); 37 } 38 39 void npnMemFree(void* ptr) 40 { 41 // We could use fastFree here, but there might be plug-ins that mix NPN_MemAlloc/NPN_MemFree with malloc and free, 42 // so having them be equivalent seems like a good idea. 43 free(ptr); 44 } 45 46 NPString createNPString(const CString& string) 47 { 48 char* utf8Characters = npnMemNewArray<char>(string.length()); 49 memcpy(utf8Characters, string.data(), string.length()); 50 51 NPString npString; 52 npString.UTF8Characters = utf8Characters; 53 npString.UTF8Length = string.length(); 54 55 return npString; 56 } 29 57 30 58 NPObject* createNPObject(NPP npp, NPClass* npClass) … … 35 63 if (npClass->allocate) 36 64 npObject = npClass->allocate(npp, npClass); 37 else { 38 // This should use NPN_MemAlloc, but we know that it uses malloc under the hood. 39 npObject = static_cast<NPObject*>(malloc(sizeof(NPObject))); 40 } 65 else 66 npObject = npnMemNew<NPObject>(); 41 67 42 68 npObject->_class = npClass; … … 54 80 if (npObject->_class->deallocate) 55 81 npObject->_class->deallocate(npObject); 56 else { 57 // This should really call NPN_MemFree, but we know that it uses free 58 // under the hood so it's fine. 59 free(npObject); 60 } 82 else 83 npnMemFree(npObject); 61 84 } 62 85 … … 96 119 97 120 case NPVariantType_String: 98 free(const_cast<NPUTF8*>(variant->value.stringValue.UTF8Characters));121 npnMemFree(const_cast<NPUTF8*>(variant->value.stringValue.UTF8Characters)); 99 122 variant->value.stringValue.UTF8Characters = 0; 100 123 variant->value.stringValue.UTF8Length = 0; -
trunk/WebKit2/WebProcess/Plugins/Netscape/NPRuntimeUtilities.h
r70898 r71169 28 28 29 29 #include <WebCore/npruntime_internal.h> 30 #include <wtf/Forward.h> 30 31 31 32 struct NPClass; … … 33 34 34 35 namespace WebKit { 36 37 void* npnMemAlloc(uint32_t); 38 void npnMemFree(void*); 39 40 template<typename T> T* npnMemNew() 41 { 42 return static_cast<T*>(npnMemAlloc(sizeof(T))); 43 } 44 45 template<typename T> T* npnMemNewArray(size_t count) 46 { 47 return static_cast<T*>(npnMemAlloc(sizeof(T) * count)); 48 } 49 50 NPString createNPString(const CString&); 35 51 36 52 NPObject* createNPObject(NPP, NPClass*); -
trunk/WebKit2/WebProcess/Plugins/Netscape/NetscapeBrowserFuncs.cpp
r68962 r71169 337 337 static void* NPN_MemAlloc(uint32_t size) 338 338 { 339 // We could use fastMalloc here, but there might be plug-ins that mix NPN_MemAlloc/NPN_MemFree with malloc and free, 340 // so having them be equivalent seems like a good idea. 341 return malloc(size); 339 return npnMemAlloc(size); 342 340 } 343 341 344 342 static void NPN_MemFree(void* ptr) 345 343 { 346 // We could use fastFree here, but there might be plug-ins that mix NPN_MemAlloc/NPN_MemFree with malloc and free, 347 // so having them be equivalent seems like a good idea. 348 free(ptr); 344 npnMemFree(ptr); 349 345 } 350 346 … … 549 545 550 546 uint32_t stringLength = strlen(string); 551 char* utf8String = static_cast<char*>(NPN_MemAlloc(stringLength + 1));547 char* utf8String = npnMemNewArray<char>(stringLength + 1); 552 548 memcpy(utf8String, string, stringLength); 553 549 utf8String[stringLength] = '\0'; … … 688 684 ASSERT(len); 689 685 690 *value = static_cast<char*>(NPN_MemAlloc(string.length()));686 *value = npnMemNewArray<char>(string.length()); 691 687 if (!*value) 692 688 return NPERR_GENERIC_ERROR; 693 689 694 690 memcpy(*value, string.data(), string.length()); 691 *len = string.length(); 695 692 return NPERR_NO_ERROR; 696 693 }
Note: See TracChangeset
for help on using the changeset viewer.