OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "webkit/plugins/npapi/plugin_host.h" | 5 #include "webkit/plugins/npapi/plugin_host.h" |
6 | 6 |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/scoped_ptr.h" | 9 #include "base/scoped_ptr.h" |
10 #include "base/string_piece.h" | 10 #include "base/string_piece.h" |
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
285 | 285 |
286 extern "C" { | 286 extern "C" { |
287 | 287 |
288 using webkit::npapi::FindInstance; | 288 using webkit::npapi::FindInstance; |
289 using webkit::npapi::PluginHost; | 289 using webkit::npapi::PluginHost; |
290 using webkit::npapi::PluginInstance; | 290 using webkit::npapi::PluginInstance; |
291 using webkit::npapi::WebPlugin; | 291 using webkit::npapi::WebPlugin; |
292 | 292 |
293 // Allocates memory from the host's memory space. | 293 // Allocates memory from the host's memory space. |
294 void* NPN_MemAlloc(uint32_t size) { | 294 void* NPN_MemAlloc(uint32_t size) { |
295 scoped_refptr<PluginHost> host(PluginHost::Singleton()); | 295 // Note: We must use the same allocator/deallocator |
296 if (host != NULL) { | 296 // that is used by the javascript library, as some of the |
297 // Note: We must use the same allocator/deallocator | 297 // JS APIs will pass memory to the plugin which the plugin |
298 // that is used by the javascript library, as some of the | 298 // will attempt to free. |
299 // JS APIs will pass memory to the plugin which the plugin | 299 return malloc(size); |
300 // will attempt to free. | |
301 return malloc(size); | |
302 } | |
303 return NULL; | |
304 } | 300 } |
305 | 301 |
306 // Deallocates memory from the host's memory space | 302 // Deallocates memory from the host's memory space |
307 void NPN_MemFree(void* ptr) { | 303 void NPN_MemFree(void* ptr) { |
308 scoped_refptr<PluginHost> host(PluginHost::Singleton()); | 304 if (ptr != NULL && ptr != reinterpret_cast<void*>(-1)) |
309 if (host != NULL) { | 305 free(ptr); |
310 if (ptr != NULL && ptr != reinterpret_cast<void*>(-1)) | |
311 free(ptr); | |
312 } | |
313 } | 306 } |
314 | 307 |
315 // Requests that the host free a specified amount of memory. | 308 // Requests that the host free a specified amount of memory. |
316 uint32_t NPN_MemFlush(uint32_t size) { | 309 uint32_t NPN_MemFlush(uint32_t size) { |
317 // This is not relevant on Windows; MAC specific | 310 // This is not relevant on Windows; MAC specific |
318 return size; | 311 return size; |
319 } | 312 } |
320 | 313 |
321 // This is for dynamic discovery of new plugins. | 314 // This is for dynamic discovery of new plugins. |
322 // Should force a re-scan of the plugins directory to load new ones. | 315 // Should force a re-scan of the plugins directory to load new ones. |
(...skipping 790 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1113 } | 1106 } |
1114 | 1107 |
1115 void NPN_URLRedirectResponse(NPP instance, void* notify_data, NPBool allow) { | 1108 void NPN_URLRedirectResponse(NPP instance, void* notify_data, NPBool allow) { |
1116 scoped_refptr<PluginInstance> plugin(FindInstance(instance)); | 1109 scoped_refptr<PluginInstance> plugin(FindInstance(instance)); |
1117 if (plugin.get()) { | 1110 if (plugin.get()) { |
1118 plugin->URLRedirectResponse(!!allow, notify_data); | 1111 plugin->URLRedirectResponse(!!allow, notify_data); |
1119 } | 1112 } |
1120 } | 1113 } |
1121 | 1114 |
1122 } // extern "C" | 1115 } // extern "C" |
OLD | NEW |