OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 "content/renderer/pepper/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" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
13 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
14 #include "base/message_loop/message_loop_proxy.h" | 14 #include "base/message_loop/message_loop_proxy.h" |
15 #include "base/time/time.h" | 15 #include "base/time/time.h" |
| 16 #include "content/common/pepper_plugin_registry.h" |
| 17 #include "content/renderer/pepper/common.h" |
| 18 #include "content/renderer/pepper/host_globals.h" |
| 19 #include "content/renderer/pepper/ppapi_interface_factory.h" |
| 20 #include "content/renderer/pepper/ppapi_plugin_instance_impl.h" |
| 21 #include "content/renderer/pepper/ppb_gpu_blacklist_private_impl.h" |
| 22 #include "content/renderer/pepper/ppb_image_data_impl.h" |
| 23 #include "content/renderer/pepper/ppb_proxy_impl.h" |
| 24 #include "content/renderer/pepper/ppb_scrollbar_impl.h" |
| 25 #include "content/renderer/pepper/ppb_uma_private_impl.h" |
| 26 #include "content/renderer/pepper/ppb_var_deprecated_impl.h" |
| 27 #include "content/renderer/pepper/ppb_video_decoder_impl.h" |
16 #include "ppapi/c/dev/ppb_audio_input_dev.h" | 28 #include "ppapi/c/dev/ppb_audio_input_dev.h" |
17 #include "ppapi/c/dev/ppb_buffer_dev.h" | 29 #include "ppapi/c/dev/ppb_buffer_dev.h" |
18 #include "ppapi/c/dev/ppb_char_set_dev.h" | 30 #include "ppapi/c/dev/ppb_char_set_dev.h" |
19 #include "ppapi/c/dev/ppb_crypto_dev.h" | 31 #include "ppapi/c/dev/ppb_crypto_dev.h" |
20 #include "ppapi/c/dev/ppb_cursor_control_dev.h" | 32 #include "ppapi/c/dev/ppb_cursor_control_dev.h" |
21 #include "ppapi/c/dev/ppb_device_ref_dev.h" | 33 #include "ppapi/c/dev/ppb_device_ref_dev.h" |
22 #include "ppapi/c/dev/ppb_file_chooser_dev.h" | 34 #include "ppapi/c/dev/ppb_file_chooser_dev.h" |
23 #include "ppapi/c/dev/ppb_find_dev.h" | 35 #include "ppapi/c/dev/ppb_find_dev.h" |
24 #include "ppapi/c/dev/ppb_font_dev.h" | 36 #include "ppapi/c/dev/ppb_font_dev.h" |
25 #include "ppapi/c/dev/ppb_gles_chromium_texture_mapping_dev.h" | 37 #include "ppapi/c/dev/ppb_gles_chromium_texture_mapping_dev.h" |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 #include "ppapi/shared_impl/callback_tracker.h" | 125 #include "ppapi/shared_impl/callback_tracker.h" |
114 #include "ppapi/shared_impl/ppapi_switches.h" | 126 #include "ppapi/shared_impl/ppapi_switches.h" |
115 #include "ppapi/shared_impl/ppb_input_event_shared.h" | 127 #include "ppapi/shared_impl/ppb_input_event_shared.h" |
116 #include "ppapi/shared_impl/ppb_opengles2_shared.h" | 128 #include "ppapi/shared_impl/ppb_opengles2_shared.h" |
117 #include "ppapi/shared_impl/ppb_var_shared.h" | 129 #include "ppapi/shared_impl/ppb_var_shared.h" |
118 #include "ppapi/shared_impl/time_conversion.h" | 130 #include "ppapi/shared_impl/time_conversion.h" |
119 #include "ppapi/thunk/enter.h" | 131 #include "ppapi/thunk/enter.h" |
120 #include "ppapi/thunk/ppb_graphics_2d_api.h" | 132 #include "ppapi/thunk/ppb_graphics_2d_api.h" |
121 #include "ppapi/thunk/thunk.h" | 133 #include "ppapi/thunk/thunk.h" |
122 #include "webkit/plugins/plugin_switches.h" | 134 #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 |
135 using ppapi::InputEventData; | 136 using ppapi::InputEventData; |
136 using ppapi::PpapiGlobals; | 137 using ppapi::PpapiGlobals; |
137 using ppapi::TimeTicksToPPTimeTicks; | 138 using ppapi::TimeTicksToPPTimeTicks; |
138 using ppapi::TimeToPPTime; | 139 using ppapi::TimeToPPTime; |
139 using ppapi::thunk::EnterResource; | 140 using ppapi::thunk::EnterResource; |
140 using ppapi::thunk::PPB_Graphics2D_API; | 141 using ppapi::thunk::PPB_Graphics2D_API; |
141 using ppapi::thunk::PPB_InputEvent_API; | 142 using ppapi::thunk::PPB_InputEvent_API; |
142 | 143 |
143 namespace webkit { | 144 namespace webkit { |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
333 | 334 |
334 const void* GetInterface(const char* name) { | 335 const void* GetInterface(const char* name) { |
335 // All interfaces should be used on the main thread. | 336 // All interfaces should be used on the main thread. |
336 CHECK(IsMainThread()); | 337 CHECK(IsMainThread()); |
337 | 338 |
338 return InternalGetInterface(name); | 339 return InternalGetInterface(name); |
339 } | 340 } |
340 | 341 |
341 // Gets the PPAPI entry points from the given library and places them into the | 342 // Gets the PPAPI entry points from the given library and places them into the |
342 // given structure. Returns true on success. | 343 // given structure. Returns true on success. |
343 bool LoadEntryPointsFromLibrary(const base::NativeLibrary& library, | 344 bool LoadEntryPointsFromLibrary( |
344 PluginModule::EntryPoints* entry_points) { | 345 const base::NativeLibrary& library, |
| 346 content::PepperPluginInfo::EntryPoints* entry_points) { |
345 entry_points->get_interface = | 347 entry_points->get_interface = |
346 reinterpret_cast<PluginModule::GetInterfaceFunc>( | 348 reinterpret_cast<content::PepperPluginInfo::GetInterfaceFunc>( |
347 base::GetFunctionPointerFromNativeLibrary(library, | 349 base::GetFunctionPointerFromNativeLibrary(library, |
348 "PPP_GetInterface")); | 350 "PPP_GetInterface")); |
349 if (!entry_points->get_interface) { | 351 if (!entry_points->get_interface) { |
350 LOG(WARNING) << "No PPP_GetInterface in plugin library"; | 352 LOG(WARNING) << "No PPP_GetInterface in plugin library"; |
351 return false; | 353 return false; |
352 } | 354 } |
353 | 355 |
354 entry_points->initialize_module = | 356 entry_points->initialize_module = |
355 reinterpret_cast<PluginModule::PPP_InitializeModuleFunc>( | 357 reinterpret_cast<content::PepperPluginInfo::PPP_InitializeModuleFunc>( |
356 base::GetFunctionPointerFromNativeLibrary(library, | 358 base::GetFunctionPointerFromNativeLibrary(library, |
357 "PPP_InitializeModule")); | 359 "PPP_InitializeModule")); |
358 if (!entry_points->initialize_module) { | 360 if (!entry_points->initialize_module) { |
359 LOG(WARNING) << "No PPP_InitializeModule in plugin library"; | 361 LOG(WARNING) << "No PPP_InitializeModule in plugin library"; |
360 return false; | 362 return false; |
361 } | 363 } |
362 | 364 |
363 // It's okay for PPP_ShutdownModule to not be defined and shutdown_module to | 365 // It's okay for PPP_ShutdownModule to not be defined and shutdown_module to |
364 // be NULL. | 366 // be NULL. |
365 entry_points->shutdown_module = | 367 entry_points->shutdown_module = |
366 reinterpret_cast<PluginModule::PPP_ShutdownModuleFunc>( | 368 reinterpret_cast<content::PepperPluginInfo::PPP_ShutdownModuleFunc>( |
367 base::GetFunctionPointerFromNativeLibrary(library, | 369 base::GetFunctionPointerFromNativeLibrary(library, |
368 "PPP_ShutdownModule")); | 370 "PPP_ShutdownModule")); |
369 | 371 |
370 return true; | 372 return true; |
371 } | 373 } |
372 | 374 |
373 } // namespace | 375 } // namespace |
374 | 376 |
375 PluginModule::EntryPoints::EntryPoints() | |
376 : get_interface(NULL), | |
377 initialize_module(NULL), | |
378 shutdown_module(NULL) { | |
379 } | |
380 | |
381 // PluginModule ---------------------------------------------------------------- | 377 // PluginModule ---------------------------------------------------------------- |
382 | 378 |
383 PluginModule::PluginModule(const std::string& name, | 379 PluginModule::PluginModule(const std::string& name, |
384 const base::FilePath& path, | 380 const base::FilePath& path, |
385 PluginDelegate::ModuleLifetime* lifetime_delegate, | |
386 const ::ppapi::PpapiPermissions& perms) | 381 const ::ppapi::PpapiPermissions& perms) |
387 : lifetime_delegate_(lifetime_delegate), | 382 : callback_tracker_(new ::ppapi::CallbackTracker), |
388 callback_tracker_(new ::ppapi::CallbackTracker), | |
389 is_in_destructor_(false), | 383 is_in_destructor_(false), |
390 is_crashed_(false), | 384 is_crashed_(false), |
391 broker_(NULL), | 385 broker_(NULL), |
392 library_(NULL), | 386 library_(NULL), |
393 name_(name), | 387 name_(name), |
394 path_(path), | 388 path_(path), |
395 permissions_(perms), | 389 permissions_(perms), |
396 reserve_instance_id_(NULL) { | 390 reserve_instance_id_(NULL) { |
397 // Ensure the globals object is created. | 391 // Ensure the globals object is created. |
398 if (!host_globals) | 392 if (!host_globals) |
(...skipping 23 matching lines...) Expand all Loading... |
422 callback_tracker_->AbortAll(); | 416 callback_tracker_->AbortAll(); |
423 | 417 |
424 if (entry_points_.shutdown_module) | 418 if (entry_points_.shutdown_module) |
425 entry_points_.shutdown_module(); | 419 entry_points_.shutdown_module(); |
426 | 420 |
427 if (library_) | 421 if (library_) |
428 base::UnloadNativeLibrary(library_); | 422 base::UnloadNativeLibrary(library_); |
429 | 423 |
430 // Notifications that we've been deleted should be last. | 424 // Notifications that we've been deleted should be last. |
431 HostGlobals::Get()->ModuleDeleted(pp_module_); | 425 HostGlobals::Get()->ModuleDeleted(pp_module_); |
432 if (!is_crashed_ && lifetime_delegate_) { | 426 if (!is_crashed_) { |
433 // When the plugin crashes, we immediately tell the lifetime delegate that | 427 // When the plugin crashes, we immediately tell the lifetime delegate that |
434 // we're gone, so we don't want to tell it again. | 428 // we're gone, so we don't want to tell it again. |
435 lifetime_delegate_->PluginModuleDead(this); | 429 content::PepperPluginRegistry::GetInstance()->PluginModuleDead(this); |
436 } | 430 } |
437 | 431 |
438 // Don't add stuff here, the two notifications that the module object has | 432 // Don't add stuff here, the two notifications that the module object has |
439 // been deleted should be last. This allows, for example, | 433 // been deleted should be last. This allows, for example, |
440 // PPB_Proxy.IsInModuleDestructor to map PP_Module to this class during the | 434 // PPB_Proxy.IsInModuleDestructor to map PP_Module to this class during the |
441 // previous parts of the destructor. | 435 // previous parts of the destructor. |
442 } | 436 } |
443 | 437 |
444 void PluginModule::SetEmbedderState(scoped_ptr<EmbedderState> state) { | 438 void PluginModule::SetEmbedderState(scoped_ptr<EmbedderState> state) { |
445 embedder_state_ = state.Pass(); | 439 embedder_state_ = state.Pass(); |
446 } | 440 } |
447 | 441 |
448 PluginModule::EmbedderState* PluginModule::GetEmbedderState() { | 442 PluginModule::EmbedderState* PluginModule::GetEmbedderState() { |
449 return embedder_state_.get(); | 443 return embedder_state_.get(); |
450 } | 444 } |
451 | 445 |
452 bool PluginModule::InitAsInternalPlugin(const EntryPoints& entry_points) { | 446 bool PluginModule::InitAsInternalPlugin( |
| 447 const content::PepperPluginInfo::EntryPoints& entry_points) { |
453 if (InitializeModule(entry_points)) { | 448 if (InitializeModule(entry_points)) { |
454 entry_points_ = entry_points; | 449 entry_points_ = entry_points; |
455 return true; | 450 return true; |
456 } | 451 } |
457 return false; | 452 return false; |
458 } | 453 } |
459 | 454 |
460 bool PluginModule::InitAsLibrary(const base::FilePath& path) { | 455 bool PluginModule::InitAsLibrary(const base::FilePath& path) { |
461 base::NativeLibrary library = base::LoadNativeLibrary(path, NULL); | 456 base::NativeLibrary library = base::LoadNativeLibrary(path, NULL); |
462 if (!library) | 457 if (!library) |
463 return false; | 458 return false; |
464 | 459 |
465 EntryPoints entry_points; | 460 content::PepperPluginInfo::EntryPoints entry_points; |
466 | 461 |
467 if (!LoadEntryPointsFromLibrary(library, &entry_points) || | 462 if (!LoadEntryPointsFromLibrary(library, &entry_points) || |
468 !InitializeModule(entry_points)) { | 463 !InitializeModule(entry_points)) { |
469 base::UnloadNativeLibrary(library); | 464 base::UnloadNativeLibrary(library); |
470 return false; | 465 return false; |
471 } | 466 } |
472 entry_points_ = entry_points; | 467 entry_points_ = entry_points; |
473 library_ = library; | 468 library_ = library; |
474 return true; | 469 return true; |
475 } | 470 } |
476 | 471 |
477 void PluginModule::InitAsProxied( | 472 void PluginModule::InitAsProxied( |
478 PluginDelegate::OutOfProcessProxy* out_of_process_proxy) { | 473 PluginDelegate::OutOfProcessProxy* out_of_process_proxy) { |
479 DCHECK(!out_of_process_proxy_.get()); | 474 DCHECK(!out_of_process_proxy_.get()); |
480 out_of_process_proxy_.reset(out_of_process_proxy); | 475 out_of_process_proxy_.reset(out_of_process_proxy); |
481 } | 476 } |
482 | 477 |
483 scoped_refptr<PluginModule> | 478 scoped_refptr<PluginModule> |
484 PluginModule::CreateModuleForExternalPluginInstance() { | 479 PluginModule::CreateModuleForExternalPluginInstance() { |
485 // Create a new module, but don't set the lifetime delegate. This isn't a | 480 // 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. | 481 // plugin in the usual sense, so it isn't tracked by the browser. |
487 scoped_refptr<PluginModule> external_plugin_module( | 482 scoped_refptr<PluginModule> external_plugin_module( |
488 new PluginModule(name_, | 483 new PluginModule(name_, |
489 path_, | 484 path_, |
490 NULL, // no lifetime_delegate | |
491 permissions_)); | 485 permissions_)); |
492 return external_plugin_module; | 486 return external_plugin_module; |
493 } | 487 } |
494 | 488 |
495 PP_ExternalPluginResult PluginModule::InitAsProxiedExternalPlugin( | 489 PP_ExternalPluginResult PluginModule::InitAsProxiedExternalPlugin( |
496 PluginInstanceImpl* instance) { | 490 PluginInstanceImpl* instance) { |
497 DCHECK(out_of_process_proxy_.get()); | 491 DCHECK(out_of_process_proxy_.get()); |
498 // InitAsProxied (for the trusted/out-of-process case) initializes only the | 492 // 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 | 493 // 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 | 494 // PluginInstance was already created as in-process, so we missed the proxy |
(...skipping 20 matching lines...) Expand all Loading... |
521 return out_of_process_proxy_->GetPluginChildId(); | 515 return out_of_process_proxy_->GetPluginChildId(); |
522 return 0; | 516 return 0; |
523 } | 517 } |
524 | 518 |
525 // static | 519 // static |
526 const PPB_Core* PluginModule::GetCore() { | 520 const PPB_Core* PluginModule::GetCore() { |
527 return &core_interface; | 521 return &core_interface; |
528 } | 522 } |
529 | 523 |
530 // static | 524 // static |
531 PluginModule::GetInterfaceFunc PluginModule::GetLocalGetInterfaceFunc() { | 525 content::PepperPluginInfo::GetInterfaceFunc |
| 526 PluginModule::GetLocalGetInterfaceFunc() { |
532 return &GetInterface; | 527 return &GetInterface; |
533 } | 528 } |
534 | 529 |
535 // static | 530 // static |
536 bool PluginModule::SupportsInterface(const char* name) { | 531 bool PluginModule::SupportsInterface(const char* name) { |
537 return !!InternalGetInterface(name); | 532 return !!InternalGetInterface(name); |
538 } | 533 } |
539 | 534 |
540 PluginInstanceImpl* PluginModule::CreateInstance( | 535 PluginInstanceImpl* PluginModule::CreateInstance( |
541 PluginDelegate* delegate, | 536 PluginDelegate* delegate, |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
586 | 581 |
587 void PluginModule::PluginCrashed() { | 582 void PluginModule::PluginCrashed() { |
588 DCHECK(!is_crashed_); // Should only get one notification. | 583 DCHECK(!is_crashed_); // Should only get one notification. |
589 is_crashed_ = true; | 584 is_crashed_ = true; |
590 | 585 |
591 // Notify all instances that they crashed. | 586 // Notify all instances that they crashed. |
592 for (PluginInstanceSet::iterator i = instances_.begin(); | 587 for (PluginInstanceSet::iterator i = instances_.begin(); |
593 i != instances_.end(); ++i) | 588 i != instances_.end(); ++i) |
594 (*i)->InstanceCrashed(); | 589 (*i)->InstanceCrashed(); |
595 | 590 |
596 if (lifetime_delegate_) | 591 content::PepperPluginRegistry::GetInstance()->PluginModuleDead(this); |
597 lifetime_delegate_->PluginModuleDead(this); | |
598 } | 592 } |
599 | 593 |
600 void PluginModule::SetReserveInstanceIDCallback( | 594 void PluginModule::SetReserveInstanceIDCallback( |
601 PP_Bool (*reserve)(PP_Module, PP_Instance)) { | 595 PP_Bool (*reserve)(PP_Module, PP_Instance)) { |
602 DCHECK(!reserve_instance_id_) << "Only expect one set."; | 596 DCHECK(!reserve_instance_id_) << "Only expect one set."; |
603 reserve_instance_id_ = reserve; | 597 reserve_instance_id_ = reserve; |
604 } | 598 } |
605 | 599 |
606 bool PluginModule::ReserveInstanceID(PP_Instance instance) { | 600 bool PluginModule::ReserveInstanceID(PP_Instance instance) { |
607 if (reserve_instance_id_) | 601 if (reserve_instance_id_) |
608 return PPBoolToBool(reserve_instance_id_(pp_module_, instance)); | 602 return PPBoolToBool(reserve_instance_id_(pp_module_, instance)); |
609 return true; // Instance ID is usable. | 603 return true; // Instance ID is usable. |
610 } | 604 } |
611 | 605 |
612 void PluginModule::SetBroker(PluginDelegate::Broker* broker) { | 606 void PluginModule::SetBroker(PluginDelegate::Broker* broker) { |
613 DCHECK(!broker_ || !broker); | 607 DCHECK(!broker_ || !broker); |
614 broker_ = broker; | 608 broker_ = broker; |
615 } | 609 } |
616 | 610 |
617 PluginDelegate::Broker* PluginModule::GetBroker() { | 611 PluginDelegate::Broker* PluginModule::GetBroker() { |
618 return broker_; | 612 return broker_; |
619 } | 613 } |
620 | 614 |
621 // static | 615 // static |
622 void PluginModule::ResetHostGlobalsForTest() { | 616 void PluginModule::ResetHostGlobalsForTest() { |
623 delete host_globals; | 617 delete host_globals; |
624 host_globals = NULL; | 618 host_globals = NULL; |
625 } | 619 } |
626 | 620 |
627 bool PluginModule::InitializeModule(const EntryPoints& entry_points) { | 621 bool PluginModule::InitializeModule( |
| 622 const content::PepperPluginInfo::EntryPoints& entry_points) { |
628 DCHECK(!out_of_process_proxy_.get()) << "Don't call for proxied modules."; | 623 DCHECK(!out_of_process_proxy_.get()) << "Don't call for proxied modules."; |
629 DCHECK(entry_points.initialize_module != NULL); | 624 DCHECK(entry_points.initialize_module != NULL); |
630 int retval = entry_points.initialize_module(pp_module(), &GetInterface); | 625 int retval = entry_points.initialize_module(pp_module(), &GetInterface); |
631 if (retval != 0) { | 626 if (retval != 0) { |
632 LOG(WARNING) << "PPP_InitializeModule returned failure " << retval; | 627 LOG(WARNING) << "PPP_InitializeModule returned failure " << retval; |
633 return false; | 628 return false; |
634 } | 629 } |
635 return true; | 630 return true; |
636 } | 631 } |
637 | 632 |
638 } // namespace ppapi | 633 } // namespace ppapi |
639 } // namespace webkit | 634 } // namespace webkit |
OLD | NEW |