OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/ppapi/plugin_module.h" | 5 #include "webkit/plugins/ppapi/plugin_module.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 #include "ppapi/c/trusted/ppb_graphics_3d_trusted.h" | 83 #include "ppapi/c/trusted/ppb_graphics_3d_trusted.h" |
84 #include "ppapi/c/trusted/ppb_image_data_trusted.h" | 84 #include "ppapi/c/trusted/ppb_image_data_trusted.h" |
85 #include "ppapi/c/trusted/ppb_url_loader_trusted.h" | 85 #include "ppapi/c/trusted/ppb_url_loader_trusted.h" |
86 #include "ppapi/shared_impl/input_event_impl.h" | 86 #include "ppapi/shared_impl/input_event_impl.h" |
87 #include "ppapi/shared_impl/time_conversion.h" | 87 #include "ppapi/shared_impl/time_conversion.h" |
88 #include "ppapi/thunk/enter.h" | 88 #include "ppapi/thunk/enter.h" |
89 #include "ppapi/thunk/thunk.h" | 89 #include "ppapi/thunk/thunk.h" |
90 #include "webkit/plugins/plugin_switches.h" | 90 #include "webkit/plugins/plugin_switches.h" |
91 #include "webkit/plugins/ppapi/callbacks.h" | 91 #include "webkit/plugins/ppapi/callbacks.h" |
92 #include "webkit/plugins/ppapi/common.h" | 92 #include "webkit/plugins/ppapi/common.h" |
93 #include "webkit/plugins/ppapi/host_globals.h" | |
94 #include "webkit/plugins/ppapi/ppapi_interface_factory.h" | 93 #include "webkit/plugins/ppapi/ppapi_interface_factory.h" |
95 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" | 94 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" |
96 #include "webkit/plugins/ppapi/ppb_directory_reader_impl.h" | 95 #include "webkit/plugins/ppapi/ppb_directory_reader_impl.h" |
97 #include "webkit/plugins/ppapi/ppb_flash_clipboard_impl.h" | 96 #include "webkit/plugins/ppapi/ppb_flash_clipboard_impl.h" |
98 #include "webkit/plugins/ppapi/ppb_flash_file_impl.h" | 97 #include "webkit/plugins/ppapi/ppb_flash_file_impl.h" |
99 #include "webkit/plugins/ppapi/ppb_flash_impl.h" | 98 #include "webkit/plugins/ppapi/ppb_flash_impl.h" |
100 #include "webkit/plugins/ppapi/ppb_flash_menu_impl.h" | 99 #include "webkit/plugins/ppapi/ppb_flash_menu_impl.h" |
101 #include "webkit/plugins/ppapi/ppb_flash_net_connector_impl.h" | 100 #include "webkit/plugins/ppapi/ppb_flash_net_connector_impl.h" |
102 #include "webkit/plugins/ppapi/ppb_font_impl.h" | 101 #include "webkit/plugins/ppapi/ppb_font_impl.h" |
103 #include "webkit/plugins/ppapi/ppb_gpu_blacklist_private_impl.h" | 102 #include "webkit/plugins/ppapi/ppb_gpu_blacklist_private_impl.h" |
104 #include "webkit/plugins/ppapi/ppb_graphics_2d_impl.h" | 103 #include "webkit/plugins/ppapi/ppb_graphics_2d_impl.h" |
105 #include "webkit/plugins/ppapi/ppb_image_data_impl.h" | 104 #include "webkit/plugins/ppapi/ppb_image_data_impl.h" |
106 #include "webkit/plugins/ppapi/ppb_layer_compositor_impl.h" | 105 #include "webkit/plugins/ppapi/ppb_layer_compositor_impl.h" |
107 #include "webkit/plugins/ppapi/ppb_opengles_impl.h" | 106 #include "webkit/plugins/ppapi/ppb_opengles_impl.h" |
108 #include "webkit/plugins/ppapi/ppb_proxy_impl.h" | 107 #include "webkit/plugins/ppapi/ppb_proxy_impl.h" |
109 #include "webkit/plugins/ppapi/ppb_scrollbar_impl.h" | 108 #include "webkit/plugins/ppapi/ppb_scrollbar_impl.h" |
110 #include "webkit/plugins/ppapi/ppb_uma_private_impl.h" | 109 #include "webkit/plugins/ppapi/ppb_uma_private_impl.h" |
111 #include "webkit/plugins/ppapi/ppb_var_impl.h" | 110 #include "webkit/plugins/ppapi/ppb_var_impl.h" |
112 #include "webkit/plugins/ppapi/ppb_video_capture_impl.h" | 111 #include "webkit/plugins/ppapi/ppb_video_capture_impl.h" |
113 #include "webkit/plugins/ppapi/ppb_video_decoder_impl.h" | 112 #include "webkit/plugins/ppapi/ppb_video_decoder_impl.h" |
114 #include "webkit/plugins/ppapi/ppb_video_layer_impl.h" | 113 #include "webkit/plugins/ppapi/ppb_video_layer_impl.h" |
115 #include "webkit/plugins/ppapi/resource_tracker.h" | 114 #include "webkit/plugins/ppapi/resource_tracker.h" |
116 #include "webkit/plugins/ppapi/webkit_forwarding_impl.h" | 115 #include "webkit/plugins/ppapi/webkit_forwarding_impl.h" |
117 | 116 |
118 using ppapi::PpapiGlobals; | |
119 using ppapi::TimeTicksToPPTimeTicks; | 117 using ppapi::TimeTicksToPPTimeTicks; |
120 using ppapi::TimeToPPTime; | 118 using ppapi::TimeToPPTime; |
121 using ppapi::thunk::EnterResource; | 119 using ppapi::thunk::EnterResource; |
122 using ppapi::thunk::PPB_Graphics2D_API; | 120 using ppapi::thunk::PPB_Graphics2D_API; |
123 | 121 |
124 namespace webkit { | 122 namespace webkit { |
125 namespace ppapi { | 123 namespace ppapi { |
126 | 124 |
127 namespace { | 125 namespace { |
128 | 126 |
129 // Global tracking info for PPAPI plugins. This is lazily created before the | |
130 // first plugin is allocated, and leaked on shutdown. | |
131 // | |
132 // Note that we don't want a Singleton here since destroying this object will | |
133 // try to free some stuff that requires WebKit, and Singletons are destroyed | |
134 // after WebKit. | |
135 webkit::ppapi::HostGlobals* host_globals = NULL; | |
136 | |
137 // Maintains all currently loaded plugin libs for validating PP_Module | 127 // Maintains all currently loaded plugin libs for validating PP_Module |
138 // identifiers. | 128 // identifiers. |
139 typedef std::set<PluginModule*> PluginModuleSet; | 129 typedef std::set<PluginModule*> PluginModuleSet; |
140 | 130 |
141 PluginModuleSet* GetLivePluginSet() { | 131 PluginModuleSet* GetLivePluginSet() { |
142 static PluginModuleSet live_plugin_libs; | 132 static PluginModuleSet live_plugin_libs; |
143 return &live_plugin_libs; | 133 return &live_plugin_libs; |
144 } | 134 } |
145 | 135 |
146 base::MessageLoopProxy* GetMainThreadMessageLoop() { | 136 base::MessageLoopProxy* GetMainThreadMessageLoop() { |
147 static scoped_refptr<base::MessageLoopProxy> proxy( | 137 static scoped_refptr<base::MessageLoopProxy> proxy( |
148 base::MessageLoopProxy::current()); | 138 base::MessageLoopProxy::current()); |
149 return proxy.get(); | 139 return proxy.get(); |
150 } | 140 } |
151 | 141 |
152 // PPB_Core -------------------------------------------------------------------- | 142 // PPB_Core -------------------------------------------------------------------- |
153 | 143 |
154 void AddRefResource(PP_Resource resource) { | 144 void AddRefResource(PP_Resource resource) { |
155 PpapiGlobals::Get()->GetResourceTracker()->AddRefResource(resource); | 145 ResourceTracker::Get()->AddRefResource(resource); |
156 } | 146 } |
157 | 147 |
158 void ReleaseResource(PP_Resource resource) { | 148 void ReleaseResource(PP_Resource resource) { |
159 PpapiGlobals::Get()->GetResourceTracker()->ReleaseResource(resource); | 149 ResourceTracker::Get()->ReleaseResource(resource); |
160 } | 150 } |
161 | 151 |
162 PP_Time GetTime() { | 152 PP_Time GetTime() { |
163 return TimeToPPTime(base::Time::Now()); | 153 return TimeToPPTime(base::Time::Now()); |
164 } | 154 } |
165 | 155 |
166 PP_TimeTicks GetTickTime() { | 156 PP_TimeTicks GetTickTime() { |
167 return TimeTicksToPPTimeTicks(base::TimeTicks::Now()); | 157 return TimeTicksToPPTimeTicks(base::TimeTicks::Now()); |
168 } | 158 } |
169 | 159 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
208 MessageLoop::current()->SetNestableTasksAllowed(true); | 198 MessageLoop::current()->SetNestableTasksAllowed(true); |
209 MessageLoop::current()->Run(); | 199 MessageLoop::current()->Run(); |
210 MessageLoop::current()->SetNestableTasksAllowed(old_state); | 200 MessageLoop::current()->SetNestableTasksAllowed(old_state); |
211 } | 201 } |
212 | 202 |
213 void QuitMessageLoop(PP_Instance instance) { | 203 void QuitMessageLoop(PP_Instance instance) { |
214 MessageLoop::current()->QuitNow(); | 204 MessageLoop::current()->QuitNow(); |
215 } | 205 } |
216 | 206 |
217 uint32_t GetLiveObjectsForInstance(PP_Instance instance_id) { | 207 uint32_t GetLiveObjectsForInstance(PP_Instance instance_id) { |
218 return HostGlobals::Get()->host_resource_tracker()->GetLiveObjectsForInstance( | 208 return ResourceTracker::Get()->GetLiveObjectsForInstance(instance_id); |
219 instance_id); | |
220 } | 209 } |
221 | 210 |
222 PP_Bool IsOutOfProcess() { | 211 PP_Bool IsOutOfProcess() { |
223 return PP_FALSE; | 212 return PP_FALSE; |
224 } | 213 } |
225 | 214 |
226 const PPB_Testing_Dev testing_interface = { | 215 const PPB_Testing_Dev testing_interface = { |
227 &ReadImageData, | 216 &ReadImageData, |
228 &RunMessageLoop, | 217 &RunMessageLoop, |
229 &QuitMessageLoop, | 218 &QuitMessageLoop, |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
375 PluginDelegate::ModuleLifetime* lifetime_delegate) | 364 PluginDelegate::ModuleLifetime* lifetime_delegate) |
376 : lifetime_delegate_(lifetime_delegate), | 365 : lifetime_delegate_(lifetime_delegate), |
377 callback_tracker_(new CallbackTracker), | 366 callback_tracker_(new CallbackTracker), |
378 is_in_destructor_(false), | 367 is_in_destructor_(false), |
379 is_crashed_(false), | 368 is_crashed_(false), |
380 broker_(NULL), | 369 broker_(NULL), |
381 library_(NULL), | 370 library_(NULL), |
382 name_(name), | 371 name_(name), |
383 path_(path), | 372 path_(path), |
384 reserve_instance_id_(NULL) { | 373 reserve_instance_id_(NULL) { |
385 // Ensure the globals object is created. | |
386 if (!host_globals) | |
387 host_globals = new HostGlobals; | |
388 | |
389 memset(&entry_points_, 0, sizeof(entry_points_)); | 374 memset(&entry_points_, 0, sizeof(entry_points_)); |
390 pp_module_ = HostGlobals::Get()->host_resource_tracker()->AddModule(this); | 375 pp_module_ = ResourceTracker::Get()->AddModule(this); |
391 GetMainThreadMessageLoop(); // Initialize the main thread message loop. | 376 GetMainThreadMessageLoop(); // Initialize the main thread message loop. |
392 GetLivePluginSet()->insert(this); | 377 GetLivePluginSet()->insert(this); |
393 } | 378 } |
394 | 379 |
395 PluginModule::~PluginModule() { | 380 PluginModule::~PluginModule() { |
396 // In the past there have been crashes reentering the plugin module | 381 // In the past there have been crashes reentering the plugin module |
397 // destructor. Catch if that happens again earlier. | 382 // destructor. Catch if that happens again earlier. |
398 CHECK(!is_in_destructor_); | 383 CHECK(!is_in_destructor_); |
399 is_in_destructor_ = true; | 384 is_in_destructor_ = true; |
400 | 385 |
401 // When the module is being deleted, there should be no more instances still | 386 // When the module is being deleted, there should be no more instances still |
402 // holding a reference to us. | 387 // holding a reference to us. |
403 DCHECK(instances_.empty()); | 388 DCHECK(instances_.empty()); |
404 | 389 |
405 GetLivePluginSet()->erase(this); | 390 GetLivePluginSet()->erase(this); |
406 | 391 |
407 callback_tracker_->AbortAll(); | 392 callback_tracker_->AbortAll(); |
408 | 393 |
409 if (entry_points_.shutdown_module) | 394 if (entry_points_.shutdown_module) |
410 entry_points_.shutdown_module(); | 395 entry_points_.shutdown_module(); |
411 | 396 |
412 if (library_) | 397 if (library_) |
413 base::UnloadNativeLibrary(library_); | 398 base::UnloadNativeLibrary(library_); |
414 | 399 |
415 // Notifications that we've been deleted should be last. | 400 // Notifications that we've been deleted should be last. |
416 HostGlobals::Get()->host_resource_tracker()->ModuleDeleted(pp_module_); | 401 ResourceTracker::Get()->ModuleDeleted(pp_module_); |
417 if (!is_crashed_) { | 402 if (!is_crashed_) { |
418 // When the plugin crashes, we immediately tell the lifetime delegate that | 403 // When the plugin crashes, we immediately tell the lifetime delegate that |
419 // we're gone, so we don't want to tell it again. | 404 // we're gone, so we don't want to tell it again. |
420 lifetime_delegate_->PluginModuleDead(this); | 405 lifetime_delegate_->PluginModuleDead(this); |
421 } | 406 } |
422 | 407 |
423 // Don't add stuff here, the two notifications that the module object has | 408 // Don't add stuff here, the two notifications that the module object has |
424 // been deleted should be last. This allows, for example, | 409 // been deleted should be last. This allows, for example, |
425 // PPB_Proxy.IsInModuleDestructor to map PP_Module to this class during the | 410 // PPB_Proxy.IsInModuleDestructor to map PP_Module to this class during the |
426 // previous parts of the destructor. | 411 // previous parts of the destructor. |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
557 int retval = entry_points.initialize_module(pp_module(), &GetInterface); | 542 int retval = entry_points.initialize_module(pp_module(), &GetInterface); |
558 if (retval != 0) { | 543 if (retval != 0) { |
559 LOG(WARNING) << "PPP_InitializeModule returned failure " << retval; | 544 LOG(WARNING) << "PPP_InitializeModule returned failure " << retval; |
560 return false; | 545 return false; |
561 } | 546 } |
562 return true; | 547 return true; |
563 } | 548 } |
564 | 549 |
565 } // namespace ppapi | 550 } // namespace ppapi |
566 } // namespace webkit | 551 } // namespace webkit |
OLD | NEW |