OLD | NEW |
| (Empty) |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "webkit/plugins/ppapi/plugin_module.h" | |
6 | |
7 #include <set> | |
8 | |
9 #include "base/bind.h" | |
10 #include "base/command_line.h" | |
11 #include "base/logging.h" | |
12 #include "base/memory/scoped_ptr.h" | |
13 #include "base/message_loop/message_loop.h" | |
14 #include "base/message_loop/message_loop_proxy.h" | |
15 #include "base/time/time.h" | |
16 #include "ppapi/c/dev/ppb_audio_input_dev.h" | |
17 #include "ppapi/c/dev/ppb_buffer_dev.h" | |
18 #include "ppapi/c/dev/ppb_char_set_dev.h" | |
19 #include "ppapi/c/dev/ppb_crypto_dev.h" | |
20 #include "ppapi/c/dev/ppb_cursor_control_dev.h" | |
21 #include "ppapi/c/dev/ppb_device_ref_dev.h" | |
22 #include "ppapi/c/dev/ppb_file_chooser_dev.h" | |
23 #include "ppapi/c/dev/ppb_find_dev.h" | |
24 #include "ppapi/c/dev/ppb_font_dev.h" | |
25 #include "ppapi/c/dev/ppb_gles_chromium_texture_mapping_dev.h" | |
26 #include "ppapi/c/dev/ppb_graphics_2d_dev.h" | |
27 #include "ppapi/c/dev/ppb_memory_dev.h" | |
28 #include "ppapi/c/dev/ppb_opengles2ext_dev.h" | |
29 #include "ppapi/c/dev/ppb_printing_dev.h" | |
30 #include "ppapi/c/dev/ppb_resource_array_dev.h" | |
31 #include "ppapi/c/dev/ppb_scrollbar_dev.h" | |
32 #include "ppapi/c/dev/ppb_testing_dev.h" | |
33 #include "ppapi/c/dev/ppb_text_input_dev.h" | |
34 #include "ppapi/c/dev/ppb_trace_event_dev.h" | |
35 #include "ppapi/c/dev/ppb_truetype_font_dev.h" | |
36 #include "ppapi/c/dev/ppb_url_util_dev.h" | |
37 #include "ppapi/c/dev/ppb_var_deprecated.h" | |
38 #include "ppapi/c/dev/ppb_video_capture_dev.h" | |
39 #include "ppapi/c/dev/ppb_video_decoder_dev.h" | |
40 #include "ppapi/c/dev/ppb_view_dev.h" | |
41 #include "ppapi/c/dev/ppb_widget_dev.h" | |
42 #include "ppapi/c/dev/ppb_zoom_dev.h" | |
43 #include "ppapi/c/extensions/dev/ppb_ext_alarms_dev.h" | |
44 #include "ppapi/c/extensions/dev/ppb_ext_socket_dev.h" | |
45 #include "ppapi/c/pp_module.h" | |
46 #include "ppapi/c/pp_resource.h" | |
47 #include "ppapi/c/pp_var.h" | |
48 #include "ppapi/c/ppb_audio.h" | |
49 #include "ppapi/c/ppb_audio_config.h" | |
50 #include "ppapi/c/ppb_console.h" | |
51 #include "ppapi/c/ppb_core.h" | |
52 #include "ppapi/c/ppb_file_io.h" | |
53 #include "ppapi/c/ppb_file_ref.h" | |
54 #include "ppapi/c/ppb_file_system.h" | |
55 #include "ppapi/c/ppb_fullscreen.h" | |
56 #include "ppapi/c/ppb_graphics_2d.h" | |
57 #include "ppapi/c/ppb_graphics_3d.h" | |
58 #include "ppapi/c/ppb_host_resolver.h" | |
59 #include "ppapi/c/ppb_image_data.h" | |
60 #include "ppapi/c/ppb_instance.h" | |
61 #include "ppapi/c/ppb_messaging.h" | |
62 #include "ppapi/c/ppb_mouse_cursor.h" | |
63 #include "ppapi/c/ppb_mouse_lock.h" | |
64 #include "ppapi/c/ppb_net_address.h" | |
65 #include "ppapi/c/ppb_network_proxy.h" | |
66 #include "ppapi/c/ppb_opengles2.h" | |
67 #include "ppapi/c/ppb_tcp_socket.h" | |
68 #include "ppapi/c/ppb_udp_socket.h" | |
69 #include "ppapi/c/ppb_url_loader.h" | |
70 #include "ppapi/c/ppb_url_request_info.h" | |
71 #include "ppapi/c/ppb_url_response_info.h" | |
72 #include "ppapi/c/ppb_var.h" | |
73 #include "ppapi/c/ppb_var_array.h" | |
74 #include "ppapi/c/ppb_var_array_buffer.h" | |
75 #include "ppapi/c/ppb_var_dictionary.h" | |
76 #include "ppapi/c/ppb_view.h" | |
77 #include "ppapi/c/ppp.h" | |
78 #include "ppapi/c/ppp_instance.h" | |
79 #include "ppapi/c/private/ppb_ext_crx_file_system_private.h" | |
80 #include "ppapi/c/private/ppb_file_io_private.h" | |
81 #include "ppapi/c/private/ppb_file_ref_private.h" | |
82 #include "ppapi/c/private/ppb_flash.h" | |
83 #include "ppapi/c/private/ppb_flash_clipboard.h" | |
84 #include "ppapi/c/private/ppb_flash_device_id.h" | |
85 #include "ppapi/c/private/ppb_flash_drm.h" | |
86 #include "ppapi/c/private/ppb_flash_file.h" | |
87 #include "ppapi/c/private/ppb_flash_font_file.h" | |
88 #include "ppapi/c/private/ppb_flash_fullscreen.h" | |
89 #include "ppapi/c/private/ppb_flash_menu.h" | |
90 #include "ppapi/c/private/ppb_flash_message_loop.h" | |
91 #include "ppapi/c/private/ppb_flash_print.h" | |
92 #include "ppapi/c/private/ppb_gpu_blacklist_private.h" | |
93 #include "ppapi/c/private/ppb_host_resolver_private.h" | |
94 #include "ppapi/c/private/ppb_instance_private.h" | |
95 #include "ppapi/c/private/ppb_network_list_private.h" | |
96 #include "ppapi/c/private/ppb_network_monitor_private.h" | |
97 #include "ppapi/c/private/ppb_pdf.h" | |
98 #include "ppapi/c/private/ppb_proxy_private.h" | |
99 #include "ppapi/c/private/ppb_talk_private.h" | |
100 #include "ppapi/c/private/ppb_tcp_server_socket_private.h" | |
101 #include "ppapi/c/private/ppb_tcp_socket_private.h" | |
102 #include "ppapi/c/private/ppb_udp_socket_private.h" | |
103 #include "ppapi/c/private/ppb_uma_private.h" | |
104 #include "ppapi/c/private/ppb_video_destination_private.h" | |
105 #include "ppapi/c/private/ppb_video_source_private.h" | |
106 #include "ppapi/c/private/ppb_x509_certificate_private.h" | |
107 #include "ppapi/c/trusted/ppb_broker_trusted.h" | |
108 #include "ppapi/c/trusted/ppb_browser_font_trusted.h" | |
109 #include "ppapi/c/trusted/ppb_char_set_trusted.h" | |
110 #include "ppapi/c/trusted/ppb_file_chooser_trusted.h" | |
111 #include "ppapi/c/trusted/ppb_file_io_trusted.h" | |
112 #include "ppapi/c/trusted/ppb_url_loader_trusted.h" | |
113 #include "ppapi/shared_impl/callback_tracker.h" | |
114 #include "ppapi/shared_impl/ppapi_switches.h" | |
115 #include "ppapi/shared_impl/ppb_input_event_shared.h" | |
116 #include "ppapi/shared_impl/ppb_opengles2_shared.h" | |
117 #include "ppapi/shared_impl/ppb_var_shared.h" | |
118 #include "ppapi/shared_impl/time_conversion.h" | |
119 #include "ppapi/thunk/enter.h" | |
120 #include "ppapi/thunk/ppb_graphics_2d_api.h" | |
121 #include "ppapi/thunk/thunk.h" | |
122 #include "webkit/plugins/plugin_switches.h" | |
123 #include "webkit/plugins/ppapi/common.h" | |
124 #include "webkit/plugins/ppapi/host_globals.h" | |
125 #include "webkit/plugins/ppapi/ppapi_interface_factory.h" | |
126 #include "webkit/plugins/ppapi/ppapi_plugin_instance_impl.h" | |
127 #include "webkit/plugins/ppapi/ppb_gpu_blacklist_private_impl.h" | |
128 #include "webkit/plugins/ppapi/ppb_image_data_impl.h" | |
129 #include "webkit/plugins/ppapi/ppb_proxy_impl.h" | |
130 #include "webkit/plugins/ppapi/ppb_scrollbar_impl.h" | |
131 #include "webkit/plugins/ppapi/ppb_uma_private_impl.h" | |
132 #include "webkit/plugins/ppapi/ppb_var_deprecated_impl.h" | |
133 #include "webkit/plugins/ppapi/ppb_video_decoder_impl.h" | |
134 | |
135 using ppapi::InputEventData; | |
136 using ppapi::PpapiGlobals; | |
137 using ppapi::TimeTicksToPPTimeTicks; | |
138 using ppapi::TimeToPPTime; | |
139 using ppapi::thunk::EnterResource; | |
140 using ppapi::thunk::PPB_Graphics2D_API; | |
141 using ppapi::thunk::PPB_InputEvent_API; | |
142 | |
143 namespace webkit { | |
144 namespace ppapi { | |
145 | |
146 namespace { | |
147 | |
148 // Global tracking info for PPAPI plugins. This is lazily created before the | |
149 // first plugin is allocated, and leaked on shutdown. | |
150 // | |
151 // Note that we don't want a Singleton here since destroying this object will | |
152 // try to free some stuff that requires WebKit, and Singletons are destroyed | |
153 // after WebKit. | |
154 // TODO(raymes): I'm not sure if it is completely necessary to leak the | |
155 // HostGlobals. Figure out the shutdown sequence and find a way to do this | |
156 // more elegantly. | |
157 webkit::ppapi::HostGlobals* host_globals = NULL; | |
158 | |
159 // Maintains all currently loaded plugin libs for validating PP_Module | |
160 // identifiers. | |
161 typedef std::set<PluginModule*> PluginModuleSet; | |
162 | |
163 PluginModuleSet* GetLivePluginSet() { | |
164 CR_DEFINE_STATIC_LOCAL(PluginModuleSet, live_plugin_libs, ()); | |
165 return &live_plugin_libs; | |
166 } | |
167 | |
168 // PPB_Core -------------------------------------------------------------------- | |
169 | |
170 void AddRefResource(PP_Resource resource) { | |
171 PpapiGlobals::Get()->GetResourceTracker()->AddRefResource(resource); | |
172 } | |
173 | |
174 void ReleaseResource(PP_Resource resource) { | |
175 PpapiGlobals::Get()->GetResourceTracker()->ReleaseResource(resource); | |
176 } | |
177 | |
178 PP_Time GetTime() { | |
179 return TimeToPPTime(base::Time::Now()); | |
180 } | |
181 | |
182 PP_TimeTicks GetTickTime() { | |
183 return TimeTicksToPPTimeTicks(base::TimeTicks::Now()); | |
184 } | |
185 | |
186 void CallOnMainThread(int delay_in_msec, | |
187 PP_CompletionCallback callback, | |
188 int32_t result) { | |
189 if (callback.func) { | |
190 PpapiGlobals::Get()->GetMainThreadMessageLoop()->PostDelayedTask( | |
191 FROM_HERE, | |
192 base::Bind(callback.func, callback.user_data, result), | |
193 base::TimeDelta::FromMilliseconds(delay_in_msec)); | |
194 } | |
195 } | |
196 | |
197 PP_Bool IsMainThread() { | |
198 return BoolToPPBool(PpapiGlobals::Get()-> | |
199 GetMainThreadMessageLoop()->BelongsToCurrentThread()); | |
200 } | |
201 | |
202 const PPB_Core core_interface = { | |
203 &AddRefResource, | |
204 &ReleaseResource, | |
205 &GetTime, | |
206 &GetTickTime, | |
207 &CallOnMainThread, | |
208 &IsMainThread | |
209 }; | |
210 | |
211 // PPB_Testing ----------------------------------------------------------------- | |
212 | |
213 PP_Bool ReadImageData(PP_Resource device_context_2d, | |
214 PP_Resource image, | |
215 const PP_Point* top_left) { | |
216 EnterResource<PPB_Graphics2D_API> enter(device_context_2d, true); | |
217 if (enter.failed()) | |
218 return PP_FALSE; | |
219 return BoolToPPBool(enter.object()->ReadImageData(image, top_left)); | |
220 } | |
221 | |
222 void RunMessageLoop(PP_Instance instance) { | |
223 base::MessageLoop::ScopedNestableTaskAllower allow( | |
224 base::MessageLoop::current()); | |
225 base::MessageLoop::current()->Run(); | |
226 } | |
227 | |
228 void QuitMessageLoop(PP_Instance instance) { | |
229 base::MessageLoop::current()->QuitNow(); | |
230 } | |
231 | |
232 uint32_t GetLiveObjectsForInstance(PP_Instance instance_id) { | |
233 return HostGlobals::Get()->GetResourceTracker()->GetLiveObjectsForInstance( | |
234 instance_id); | |
235 } | |
236 | |
237 PP_Bool IsOutOfProcess() { | |
238 return PP_FALSE; | |
239 } | |
240 | |
241 void SimulateInputEvent(PP_Instance instance, PP_Resource input_event) { | |
242 PluginInstanceImpl* plugin_instance = host_globals->GetInstance(instance); | |
243 if (!plugin_instance) | |
244 return; | |
245 | |
246 EnterResource<PPB_InputEvent_API> enter(input_event, false); | |
247 if (enter.failed()) | |
248 return; | |
249 | |
250 const InputEventData& input_event_data = enter.object()->GetInputEventData(); | |
251 plugin_instance->SimulateInputEvent(input_event_data); | |
252 } | |
253 | |
254 PP_Var GetDocumentURL(PP_Instance instance, PP_URLComponents_Dev* components) { | |
255 PluginInstanceImpl* plugin_instance = host_globals->GetInstance(instance); | |
256 if (!plugin_instance) | |
257 return PP_MakeUndefined(); | |
258 return plugin_instance->GetDocumentURL(instance, components); | |
259 } | |
260 | |
261 uint32_t GetLiveVars(PP_Var live_vars[], uint32_t array_size) { | |
262 std::vector<PP_Var> vars = | |
263 PpapiGlobals::Get()->GetVarTracker()->GetLiveVars(); | |
264 for (size_t i = 0u; | |
265 i < std::min(static_cast<size_t>(array_size), vars.size()); | |
266 ++i) | |
267 live_vars[i] = vars[i]; | |
268 return vars.size(); | |
269 } | |
270 | |
271 void SetMinimumArrayBufferSizeForShmem(PP_Instance /*instance*/, | |
272 uint32_t /*threshold*/) { | |
273 // Does nothing. Not needed in-process. | |
274 } | |
275 | |
276 const PPB_Testing_Dev testing_interface = { | |
277 &ReadImageData, | |
278 &RunMessageLoop, | |
279 &QuitMessageLoop, | |
280 &GetLiveObjectsForInstance, | |
281 &IsOutOfProcess, | |
282 &SimulateInputEvent, | |
283 &GetDocumentURL, | |
284 &GetLiveVars, | |
285 &SetMinimumArrayBufferSizeForShmem | |
286 }; | |
287 | |
288 // GetInterface ---------------------------------------------------------------- | |
289 | |
290 const void* InternalGetInterface(const char* name) { | |
291 // Allow custom interface factories first stab at the GetInterface call. | |
292 const void* custom_interface = | |
293 PpapiInterfaceFactoryManager::GetInstance()->GetInterface(name); | |
294 if (custom_interface) | |
295 return custom_interface; | |
296 | |
297 // TODO(brettw) put these in a hash map for better performance. | |
298 #define UNPROXIED_IFACE(api_name, iface_str, iface_struct) \ | |
299 if (strcmp(name, iface_str) == 0) \ | |
300 return ::ppapi::thunk::Get##iface_struct##_Thunk(); | |
301 #define PROXIED_IFACE(api_name, iface_str, iface_struct) \ | |
302 UNPROXIED_IFACE(api_name, iface_str, iface_struct) | |
303 | |
304 #include "ppapi/thunk/interfaces_ppb_public_stable.h" | |
305 #include "ppapi/thunk/interfaces_ppb_public_dev.h" | |
306 #include "ppapi/thunk/interfaces_ppb_private.h" | |
307 #include "ppapi/thunk/interfaces_ppb_private_no_permissions.h" | |
308 #include "ppapi/thunk/interfaces_ppb_private_flash.h" | |
309 | |
310 #undef UNPROXIED_API | |
311 #undef PROXIED_IFACE | |
312 | |
313 #define LEGACY_IFACE(iface_str, function_name) \ | |
314 if (strcmp(name, iface_str) == 0) \ | |
315 return function_name; | |
316 | |
317 #include "ppapi/thunk/interfaces_legacy.h" | |
318 | |
319 #undef LEGACY_IFACE | |
320 | |
321 // Only support the testing interface when the command line switch is | |
322 // specified. This allows us to prevent people from (ab)using this interface | |
323 // in production code. | |
324 if (CommandLine::ForCurrentProcess()->HasSwitch( | |
325 switches::kEnablePepperTesting)) { | |
326 if (strcmp(name, PPB_TESTING_DEV_INTERFACE) == 0 || | |
327 strcmp(name, PPB_TESTING_DEV_INTERFACE_0_9) == 0) { | |
328 return &testing_interface; | |
329 } | |
330 } | |
331 return NULL; | |
332 } | |
333 | |
334 const void* GetInterface(const char* name) { | |
335 // All interfaces should be used on the main thread. | |
336 CHECK(IsMainThread()); | |
337 | |
338 return InternalGetInterface(name); | |
339 } | |
340 | |
341 // Gets the PPAPI entry points from the given library and places them into the | |
342 // given structure. Returns true on success. | |
343 bool LoadEntryPointsFromLibrary(const base::NativeLibrary& library, | |
344 PluginModule::EntryPoints* entry_points) { | |
345 entry_points->get_interface = | |
346 reinterpret_cast<PluginModule::GetInterfaceFunc>( | |
347 base::GetFunctionPointerFromNativeLibrary(library, | |
348 "PPP_GetInterface")); | |
349 if (!entry_points->get_interface) { | |
350 LOG(WARNING) << "No PPP_GetInterface in plugin library"; | |
351 return false; | |
352 } | |
353 | |
354 entry_points->initialize_module = | |
355 reinterpret_cast<PluginModule::PPP_InitializeModuleFunc>( | |
356 base::GetFunctionPointerFromNativeLibrary(library, | |
357 "PPP_InitializeModule")); | |
358 if (!entry_points->initialize_module) { | |
359 LOG(WARNING) << "No PPP_InitializeModule in plugin library"; | |
360 return false; | |
361 } | |
362 | |
363 // It's okay for PPP_ShutdownModule to not be defined and shutdown_module to | |
364 // be NULL. | |
365 entry_points->shutdown_module = | |
366 reinterpret_cast<PluginModule::PPP_ShutdownModuleFunc>( | |
367 base::GetFunctionPointerFromNativeLibrary(library, | |
368 "PPP_ShutdownModule")); | |
369 | |
370 return true; | |
371 } | |
372 | |
373 } // namespace | |
374 | |
375 PluginModule::EntryPoints::EntryPoints() | |
376 : get_interface(NULL), | |
377 initialize_module(NULL), | |
378 shutdown_module(NULL) { | |
379 } | |
380 | |
381 // PluginModule ---------------------------------------------------------------- | |
382 | |
383 PluginModule::PluginModule(const std::string& name, | |
384 const base::FilePath& path, | |
385 PluginDelegate::ModuleLifetime* lifetime_delegate, | |
386 const ::ppapi::PpapiPermissions& perms) | |
387 : lifetime_delegate_(lifetime_delegate), | |
388 callback_tracker_(new ::ppapi::CallbackTracker), | |
389 is_in_destructor_(false), | |
390 is_crashed_(false), | |
391 broker_(NULL), | |
392 library_(NULL), | |
393 name_(name), | |
394 path_(path), | |
395 permissions_(perms), | |
396 reserve_instance_id_(NULL) { | |
397 // Ensure the globals object is created. | |
398 if (!host_globals) | |
399 host_globals = new HostGlobals; | |
400 | |
401 memset(&entry_points_, 0, sizeof(entry_points_)); | |
402 pp_module_ = HostGlobals::Get()->AddModule(this); | |
403 GetLivePluginSet()->insert(this); | |
404 } | |
405 | |
406 PluginModule::~PluginModule() { | |
407 // In the past there have been crashes reentering the plugin module | |
408 // destructor. Catch if that happens again earlier. | |
409 CHECK(!is_in_destructor_); | |
410 is_in_destructor_ = true; | |
411 | |
412 // When the module is being deleted, there should be no more instances still | |
413 // holding a reference to us. | |
414 DCHECK(instances_.empty()); | |
415 | |
416 // Some resources and other stuff are hung off of the embedder state, which | |
417 // should be torn down before the routing stuff below. | |
418 embedder_state_.reset(); | |
419 | |
420 GetLivePluginSet()->erase(this); | |
421 | |
422 callback_tracker_->AbortAll(); | |
423 | |
424 if (entry_points_.shutdown_module) | |
425 entry_points_.shutdown_module(); | |
426 | |
427 if (library_) | |
428 base::UnloadNativeLibrary(library_); | |
429 | |
430 // Notifications that we've been deleted should be last. | |
431 HostGlobals::Get()->ModuleDeleted(pp_module_); | |
432 if (!is_crashed_ && lifetime_delegate_) { | |
433 // When the plugin crashes, we immediately tell the lifetime delegate that | |
434 // we're gone, so we don't want to tell it again. | |
435 lifetime_delegate_->PluginModuleDead(this); | |
436 } | |
437 | |
438 // Don't add stuff here, the two notifications that the module object has | |
439 // been deleted should be last. This allows, for example, | |
440 // PPB_Proxy.IsInModuleDestructor to map PP_Module to this class during the | |
441 // previous parts of the destructor. | |
442 } | |
443 | |
444 void PluginModule::SetEmbedderState(scoped_ptr<EmbedderState> state) { | |
445 embedder_state_ = state.Pass(); | |
446 } | |
447 | |
448 PluginModule::EmbedderState* PluginModule::GetEmbedderState() { | |
449 return embedder_state_.get(); | |
450 } | |
451 | |
452 bool PluginModule::InitAsInternalPlugin(const EntryPoints& entry_points) { | |
453 if (InitializeModule(entry_points)) { | |
454 entry_points_ = entry_points; | |
455 return true; | |
456 } | |
457 return false; | |
458 } | |
459 | |
460 bool PluginModule::InitAsLibrary(const base::FilePath& path) { | |
461 base::NativeLibrary library = base::LoadNativeLibrary(path, NULL); | |
462 if (!library) | |
463 return false; | |
464 | |
465 EntryPoints entry_points; | |
466 | |
467 if (!LoadEntryPointsFromLibrary(library, &entry_points) || | |
468 !InitializeModule(entry_points)) { | |
469 base::UnloadNativeLibrary(library); | |
470 return false; | |
471 } | |
472 entry_points_ = entry_points; | |
473 library_ = library; | |
474 return true; | |
475 } | |
476 | |
477 void PluginModule::InitAsProxied( | |
478 PluginDelegate::OutOfProcessProxy* out_of_process_proxy) { | |
479 DCHECK(!out_of_process_proxy_.get()); | |
480 out_of_process_proxy_.reset(out_of_process_proxy); | |
481 } | |
482 | |
483 scoped_refptr<PluginModule> | |
484 PluginModule::CreateModuleForExternalPluginInstance() { | |
485 // Create a new module, but don't set the lifetime delegate. This isn't a | |
486 // plugin in the usual sense, so it isn't tracked by the browser. | |
487 scoped_refptr<PluginModule> external_plugin_module( | |
488 new PluginModule(name_, | |
489 path_, | |
490 NULL, // no lifetime_delegate | |
491 permissions_)); | |
492 return external_plugin_module; | |
493 } | |
494 | |
495 PP_ExternalPluginResult PluginModule::InitAsProxiedExternalPlugin( | |
496 PluginInstanceImpl* instance) { | |
497 DCHECK(out_of_process_proxy_.get()); | |
498 // InitAsProxied (for the trusted/out-of-process case) initializes only the | |
499 // module, and one or more instances are added later. In this case, the | |
500 // PluginInstance was already created as in-process, so we missed the proxy | |
501 // AddInstance step and must do it now. | |
502 out_of_process_proxy_->AddInstance(instance->pp_instance()); | |
503 // For external plugins, we need to tell the instance to reset itself as | |
504 // proxied. This will clear cached interface pointers and send DidCreate (etc) | |
505 // to the plugin side of the proxy. | |
506 return instance->ResetAsProxied(this); | |
507 } | |
508 | |
509 bool PluginModule::IsProxied() const { | |
510 return !!out_of_process_proxy_; | |
511 } | |
512 | |
513 base::ProcessId PluginModule::GetPeerProcessId() { | |
514 if (out_of_process_proxy_) | |
515 return out_of_process_proxy_->GetPeerProcessId(); | |
516 return base::kNullProcessId; | |
517 } | |
518 | |
519 int PluginModule::GetPluginChildId() { | |
520 if (out_of_process_proxy_) | |
521 return out_of_process_proxy_->GetPluginChildId(); | |
522 return 0; | |
523 } | |
524 | |
525 // static | |
526 const PPB_Core* PluginModule::GetCore() { | |
527 return &core_interface; | |
528 } | |
529 | |
530 // static | |
531 PluginModule::GetInterfaceFunc PluginModule::GetLocalGetInterfaceFunc() { | |
532 return &GetInterface; | |
533 } | |
534 | |
535 // static | |
536 bool PluginModule::SupportsInterface(const char* name) { | |
537 return !!InternalGetInterface(name); | |
538 } | |
539 | |
540 PluginInstanceImpl* PluginModule::CreateInstance( | |
541 PluginDelegate* delegate, | |
542 content::RenderView* render_view, | |
543 WebKit::WebPluginContainer* container, | |
544 const GURL& plugin_url) { | |
545 PluginInstanceImpl* instance = PluginInstanceImpl::Create( | |
546 delegate, render_view, this, container, plugin_url); | |
547 if (!instance) { | |
548 LOG(WARNING) << "Plugin doesn't support instance interface, failing."; | |
549 return NULL; | |
550 } | |
551 if (out_of_process_proxy_) | |
552 out_of_process_proxy_->AddInstance(instance->pp_instance()); | |
553 return instance; | |
554 } | |
555 | |
556 PluginInstanceImpl* PluginModule::GetSomeInstance() const { | |
557 // This will generally crash later if there is not actually any instance to | |
558 // return, so we force a crash now to make bugs easier to track down. | |
559 CHECK(!instances_.empty()); | |
560 return *instances_.begin(); | |
561 } | |
562 | |
563 const void* PluginModule::GetPluginInterface(const char* name) const { | |
564 if (out_of_process_proxy_) | |
565 return out_of_process_proxy_->GetProxiedInterface(name); | |
566 | |
567 // In-process plugins. | |
568 if (!entry_points_.get_interface) | |
569 return NULL; | |
570 return entry_points_.get_interface(name); | |
571 } | |
572 | |
573 void PluginModule::InstanceCreated(PluginInstanceImpl* instance) { | |
574 instances_.insert(instance); | |
575 } | |
576 | |
577 void PluginModule::InstanceDeleted(PluginInstanceImpl* instance) { | |
578 if (out_of_process_proxy_) | |
579 out_of_process_proxy_->RemoveInstance(instance->pp_instance()); | |
580 instances_.erase(instance); | |
581 } | |
582 | |
583 scoped_refptr< ::ppapi::CallbackTracker> PluginModule::GetCallbackTracker() { | |
584 return callback_tracker_; | |
585 } | |
586 | |
587 void PluginModule::PluginCrashed() { | |
588 DCHECK(!is_crashed_); // Should only get one notification. | |
589 is_crashed_ = true; | |
590 | |
591 // Notify all instances that they crashed. | |
592 for (PluginInstanceSet::iterator i = instances_.begin(); | |
593 i != instances_.end(); ++i) | |
594 (*i)->InstanceCrashed(); | |
595 | |
596 if (lifetime_delegate_) | |
597 lifetime_delegate_->PluginModuleDead(this); | |
598 } | |
599 | |
600 void PluginModule::SetReserveInstanceIDCallback( | |
601 PP_Bool (*reserve)(PP_Module, PP_Instance)) { | |
602 DCHECK(!reserve_instance_id_) << "Only expect one set."; | |
603 reserve_instance_id_ = reserve; | |
604 } | |
605 | |
606 bool PluginModule::ReserveInstanceID(PP_Instance instance) { | |
607 if (reserve_instance_id_) | |
608 return PPBoolToBool(reserve_instance_id_(pp_module_, instance)); | |
609 return true; // Instance ID is usable. | |
610 } | |
611 | |
612 void PluginModule::SetBroker(PluginDelegate::Broker* broker) { | |
613 DCHECK(!broker_ || !broker); | |
614 broker_ = broker; | |
615 } | |
616 | |
617 PluginDelegate::Broker* PluginModule::GetBroker() { | |
618 return broker_; | |
619 } | |
620 | |
621 // static | |
622 void PluginModule::ResetHostGlobalsForTest() { | |
623 delete host_globals; | |
624 host_globals = NULL; | |
625 } | |
626 | |
627 bool PluginModule::InitializeModule(const EntryPoints& entry_points) { | |
628 DCHECK(!out_of_process_proxy_.get()) << "Don't call for proxied modules."; | |
629 DCHECK(entry_points.initialize_module != NULL); | |
630 int retval = entry_points.initialize_module(pp_module(), &GetInterface); | |
631 if (retval != 0) { | |
632 LOG(WARNING) << "PPP_InitializeModule returned failure " << retval; | |
633 return false; | |
634 } | |
635 return true; | |
636 } | |
637 | |
638 } // namespace ppapi | |
639 } // namespace webkit | |
OLD | NEW |