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/glue/plugins/pepper_plugin_module.h" | 5 #include "webkit/glue/plugins/pepper_plugin_module.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 | 8 |
| 9 #include "base/message_loop_proxy.h" |
9 #include "base/logging.h" | 10 #include "base/logging.h" |
10 #include "base/scoped_ptr.h" | 11 #include "base/scoped_ptr.h" |
| 12 #include "base/time.h" |
11 #include "third_party/ppapi/c/ppb_core.h" | 13 #include "third_party/ppapi/c/ppb_core.h" |
12 #include "third_party/ppapi/c/ppb_device_context_2d.h" | 14 #include "third_party/ppapi/c/ppb_device_context_2d.h" |
13 #include "third_party/ppapi/c/ppb_image_data.h" | 15 #include "third_party/ppapi/c/ppb_image_data.h" |
14 #include "third_party/ppapi/c/ppb_instance.h" | 16 #include "third_party/ppapi/c/ppb_instance.h" |
15 #include "third_party/ppapi/c/ppb_var.h" | 17 #include "third_party/ppapi/c/ppb_var.h" |
16 #include "third_party/ppapi/c/ppp.h" | 18 #include "third_party/ppapi/c/ppp.h" |
17 #include "third_party/ppapi/c/ppp_instance.h" | 19 #include "third_party/ppapi/c/ppp_instance.h" |
18 #include "third_party/ppapi/c/pp_module.h" | 20 #include "third_party/ppapi/c/pp_module.h" |
19 #include "third_party/ppapi/c/pp_resource.h" | 21 #include "third_party/ppapi/c/pp_resource.h" |
20 #include "third_party/ppapi/c/pp_var.h" | 22 #include "third_party/ppapi/c/pp_var.h" |
(...skipping 12 matching lines...) Expand all Loading... |
33 | 35 |
34 // Maintains all currently loaded plugin libs for validating PP_Module | 36 // Maintains all currently loaded plugin libs for validating PP_Module |
35 // identifiers. | 37 // identifiers. |
36 typedef std::set<PluginModule*> PluginModuleSet; | 38 typedef std::set<PluginModule*> PluginModuleSet; |
37 | 39 |
38 PluginModuleSet* GetLivePluginSet() { | 40 PluginModuleSet* GetLivePluginSet() { |
39 static PluginModuleSet live_plugin_libs; | 41 static PluginModuleSet live_plugin_libs; |
40 return &live_plugin_libs; | 42 return &live_plugin_libs; |
41 } | 43 } |
42 | 44 |
| 45 base::MessageLoopProxy* GetMainThreadMessageLoop() { |
| 46 static scoped_refptr<base::MessageLoopProxy> proxy( |
| 47 base::MessageLoopProxy::CreateForCurrentThread()); |
| 48 return proxy.get(); |
| 49 } |
| 50 |
43 // PPB_Core -------------------------------------------------------------------- | 51 // PPB_Core -------------------------------------------------------------------- |
44 | 52 |
45 void AddRefResource(PP_Resource resource) { | 53 void AddRefResource(PP_Resource resource) { |
46 Resource* res = ResourceTracker::Get()->GetResource(resource); | 54 Resource* res = ResourceTracker::Get()->GetResource(resource); |
47 if (!res) { | 55 if (!res) { |
48 DLOG(WARNING) << "AddRef()ing a nonexistent resource"; | 56 DLOG(WARNING) << "AddRef()ing a nonexistent resource"; |
49 return; | 57 return; |
50 } | 58 } |
51 res->AddRef(); | 59 res->AddRef(); |
52 } | 60 } |
53 | 61 |
54 void ReleaseResource(PP_Resource resource) { | 62 void ReleaseResource(PP_Resource resource) { |
55 Resource* res = ResourceTracker::Get()->GetResource(resource); | 63 Resource* res = ResourceTracker::Get()->GetResource(resource); |
56 if (!res) { | 64 if (!res) { |
57 DLOG(WARNING) << "Release()ing a nonexistent resource"; | 65 DLOG(WARNING) << "Release()ing a nonexistent resource"; |
58 return; | 66 return; |
59 } | 67 } |
60 res->Release(); | 68 res->Release(); |
61 } | 69 } |
62 | 70 |
| 71 void* MemAlloc(size_t num_bytes) { |
| 72 return malloc(num_bytes); |
| 73 } |
| 74 |
| 75 void MemFree(void* ptr) { |
| 76 free(ptr); |
| 77 } |
| 78 |
| 79 double GetTime() { |
| 80 return base::Time::Now().ToDoubleT(); |
| 81 } |
| 82 |
| 83 void CallOnMainThread(int delay_in_msec, void (*func)(void*), void* context) { |
| 84 GetMainThreadMessageLoop()->PostDelayedTask( |
| 85 FROM_HERE, |
| 86 NewRunnableFunction(func, context), |
| 87 delay_in_msec); |
| 88 } |
| 89 |
63 const PPB_Core core_interface = { | 90 const PPB_Core core_interface = { |
64 &AddRefResource, | 91 &AddRefResource, |
65 &ReleaseResource, | 92 &ReleaseResource, |
| 93 &MemAlloc, |
| 94 &MemFree, |
| 95 &GetTime, |
| 96 &CallOnMainThread |
66 }; | 97 }; |
67 | 98 |
68 // GetInterface ---------------------------------------------------------------- | 99 // GetInterface ---------------------------------------------------------------- |
69 | 100 |
70 const void* GetInterface(const char* name) { | 101 const void* GetInterface(const char* name) { |
71 if (strcmp(name, PPB_CORE_INTERFACE) == 0) | 102 if (strcmp(name, PPB_CORE_INTERFACE) == 0) |
72 return &core_interface; | 103 return &core_interface; |
73 if (strcmp(name, PPB_VAR_INTERFACE) == 0) | 104 if (strcmp(name, PPB_VAR_INTERFACE) == 0) |
74 return GetVarInterface(); | 105 return GetVarInterface(); |
75 if (strcmp(name, PPB_INSTANCE_INTERFACE) == 0) | 106 if (strcmp(name, PPB_INSTANCE_INTERFACE) == 0) |
76 return PluginInstance::GetInterface(); | 107 return PluginInstance::GetInterface(); |
77 if (strcmp(name, PPB_IMAGEDATA_INTERFACE) == 0) | 108 if (strcmp(name, PPB_IMAGEDATA_INTERFACE) == 0) |
78 return ImageData::GetInterface(); | 109 return ImageData::GetInterface(); |
79 if (strcmp(name, PPB_DEVICECONTEXT2D_INTERFACE) == 0) | 110 if (strcmp(name, PPB_DEVICECONTEXT2D_INTERFACE) == 0) |
80 return DeviceContext2D::GetInterface(); | 111 return DeviceContext2D::GetInterface(); |
81 return NULL; | 112 return NULL; |
82 } | 113 } |
83 | 114 |
84 } // namespace | 115 } // namespace |
85 | 116 |
86 PluginModule::PluginModule(const FilePath& filename) | 117 PluginModule::PluginModule(const FilePath& filename) |
87 : filename_(filename), | 118 : filename_(filename), |
88 initialized_(false), | 119 initialized_(false), |
89 library_(0), | 120 library_(0), |
90 ppp_get_interface_(NULL) { | 121 ppp_get_interface_(NULL) { |
| 122 GetMainThreadMessageLoop(); // Initialize the main thread message loop. |
91 GetLivePluginSet()->insert(this); | 123 GetLivePluginSet()->insert(this); |
92 } | 124 } |
93 | 125 |
94 PluginModule::~PluginModule() { | 126 PluginModule::~PluginModule() { |
95 // When the module is being deleted, there should be no more instances still | 127 // When the module is being deleted, there should be no more instances still |
96 // holding a reference to us. | 128 // holding a reference to us. |
97 DCHECK(instances_.empty()); | 129 DCHECK(instances_.empty()); |
98 | 130 |
99 GetLivePluginSet()->erase(this); | 131 GetLivePluginSet()->erase(this); |
100 | 132 |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 | 227 |
196 void PluginModule::InstanceCreated(PluginInstance* instance) { | 228 void PluginModule::InstanceCreated(PluginInstance* instance) { |
197 instances_.insert(instance); | 229 instances_.insert(instance); |
198 } | 230 } |
199 | 231 |
200 void PluginModule::InstanceDeleted(PluginInstance* instance) { | 232 void PluginModule::InstanceDeleted(PluginInstance* instance) { |
201 instances_.erase(instance); | 233 instances_.erase(instance); |
202 } | 234 } |
203 | 235 |
204 } // namespace pepper | 236 } // namespace pepper |
OLD | NEW |