Chromium Code Reviews| 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 "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 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 412 const FilePath& path, | 412 const FilePath& path, |
| 413 PluginDelegate::ModuleLifetime* lifetime_delegate) | 413 PluginDelegate::ModuleLifetime* lifetime_delegate) |
| 414 : lifetime_delegate_(lifetime_delegate), | 414 : lifetime_delegate_(lifetime_delegate), |
| 415 callback_tracker_(new ::ppapi::CallbackTracker), | 415 callback_tracker_(new ::ppapi::CallbackTracker), |
| 416 is_in_destructor_(false), | 416 is_in_destructor_(false), |
| 417 is_crashed_(false), | 417 is_crashed_(false), |
| 418 broker_(NULL), | 418 broker_(NULL), |
| 419 library_(NULL), | 419 library_(NULL), |
| 420 name_(name), | 420 name_(name), |
| 421 path_(path), | 421 path_(path), |
| 422 reserve_instance_id_(NULL) { | 422 reserve_instance_id_(NULL), |
| 423 nacl_ipc_proxy_(false) { | |
| 423 // Ensure the globals object is created. | 424 // Ensure the globals object is created. |
| 424 if (!host_globals) | 425 if (!host_globals) |
| 425 host_globals = new HostGlobals; | 426 host_globals = new HostGlobals; |
| 426 | 427 |
| 427 memset(&entry_points_, 0, sizeof(entry_points_)); | 428 memset(&entry_points_, 0, sizeof(entry_points_)); |
| 428 pp_module_ = HostGlobals::Get()->AddModule(this); | 429 pp_module_ = HostGlobals::Get()->AddModule(this); |
| 429 GetMainThreadMessageLoop(); // Initialize the main thread message loop. | 430 GetMainThreadMessageLoop(); // Initialize the main thread message loop. |
| 430 GetLivePluginSet()->insert(this); | 431 GetLivePluginSet()->insert(this); |
| 431 } | 432 } |
| 432 | 433 |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 489 return true; | 490 return true; |
| 490 } | 491 } |
| 491 | 492 |
| 492 void PluginModule::InitAsProxied( | 493 void PluginModule::InitAsProxied( |
| 493 PluginDelegate::OutOfProcessProxy* out_of_process_proxy) { | 494 PluginDelegate::OutOfProcessProxy* out_of_process_proxy) { |
| 494 DCHECK(!out_of_process_proxy_.get()); | 495 DCHECK(!out_of_process_proxy_.get()); |
| 495 out_of_process_proxy_.reset(out_of_process_proxy); | 496 out_of_process_proxy_.reset(out_of_process_proxy); |
| 496 } | 497 } |
| 497 | 498 |
| 498 void PluginModule::InitAsProxiedNaCl( | 499 void PluginModule::InitAsProxiedNaCl( |
| 499 PluginDelegate::OutOfProcessProxy* out_of_process_proxy, | 500 scoped_ptr<PluginDelegate::OutOfProcessProxy> out_of_process_proxy, |
| 500 PP_Instance instance) { | 501 PP_Instance instance) { |
| 501 InitAsProxied(out_of_process_proxy); | 502 nacl_ipc_proxy_ = true; |
| 503 InitAsProxied(out_of_process_proxy.release()); | |
| 502 // InitAsProxied (for the trusted/out-of-process case) initializes only the | 504 // InitAsProxied (for the trusted/out-of-process case) initializes only the |
| 503 // module, and one or more instances are added later. In this case, the | 505 // module, and one or more instances are added later. In this case, the |
| 504 // PluginInstance was already created as in-process, so we missed the proxy | 506 // PluginInstance was already created as in-process, so we missed the proxy |
| 505 // AddInstance step and must do it now. | 507 // AddInstance step and must do it now. |
| 506 out_of_process_proxy_->AddInstance(instance); | 508 out_of_process_proxy_->AddInstance(instance); |
| 507 | 509 |
| 508 // In NaCl, we need to tell the instance to reset itself as proxied. This will | 510 // In NaCl, we need to tell the instance to reset itself as proxied. This will |
| 509 // clear cached interface pointers and send DidCreate (etc) to the plugin | 511 // clear cached interface pointers and send DidCreate (etc) to the plugin |
| 510 // side of the proxy. | 512 // side of the proxy. |
| 511 PluginInstance* plugin_instance = host_globals->GetInstance(instance); | 513 PluginInstance* plugin_instance = host_globals->GetInstance(instance); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 553 } | 555 } |
| 554 | 556 |
| 555 void PluginModule::InstanceCreated(PluginInstance* instance) { | 557 void PluginModule::InstanceCreated(PluginInstance* instance) { |
| 556 instances_.insert(instance); | 558 instances_.insert(instance); |
| 557 } | 559 } |
| 558 | 560 |
| 559 void PluginModule::InstanceDeleted(PluginInstance* instance) { | 561 void PluginModule::InstanceDeleted(PluginInstance* instance) { |
| 560 if (out_of_process_proxy_.get()) | 562 if (out_of_process_proxy_.get()) |
| 561 out_of_process_proxy_->RemoveInstance(instance->pp_instance()); | 563 out_of_process_proxy_->RemoveInstance(instance->pp_instance()); |
| 562 instances_.erase(instance); | 564 instances_.erase(instance); |
| 565 | |
| 566 if (nacl_ipc_proxy_) { | |
| 567 out_of_process_proxy_.reset(); | |
| 568 reserve_instance_id_ = NULL; | |
| 569 } | |
|
dmichael (off chromium)
2012/06/21 18:18:16
As we discussed, this is not going to work for mul
bbudge
2012/06/21 19:28:18
I'll add a TODO for this. PluginModule is already
| |
| 563 } | 570 } |
| 564 | 571 |
| 565 scoped_refptr< ::ppapi::CallbackTracker> PluginModule::GetCallbackTracker() { | 572 scoped_refptr< ::ppapi::CallbackTracker> PluginModule::GetCallbackTracker() { |
| 566 return callback_tracker_; | 573 return callback_tracker_; |
| 567 } | 574 } |
| 568 | 575 |
| 569 void PluginModule::PluginCrashed() { | 576 void PluginModule::PluginCrashed() { |
| 570 DCHECK(!is_crashed_); // Should only get one notification. | 577 DCHECK(!is_crashed_); // Should only get one notification. |
| 571 is_crashed_ = true; | 578 is_crashed_ = true; |
| 572 | 579 |
| 573 // Notify all instances that they crashed. | 580 // Notify all instances that they crashed. |
| 574 for (PluginInstanceSet::iterator i = instances_.begin(); | 581 for (PluginInstanceSet::iterator i = instances_.begin(); |
| 575 i != instances_.end(); ++i) | 582 i != instances_.end(); ++i) |
| 576 (*i)->InstanceCrashed(); | 583 (*i)->InstanceCrashed(); |
| 577 | 584 |
| 578 if (lifetime_delegate_) | 585 if (lifetime_delegate_) |
| 579 lifetime_delegate_->PluginModuleDead(this); | 586 lifetime_delegate_->PluginModuleDead(this); |
| 580 } | 587 } |
| 581 | 588 |
| 582 void PluginModule::SetReserveInstanceIDCallback( | 589 void PluginModule::SetReserveInstanceIDCallback( |
| 583 PP_Bool (*reserve)(PP_Module, PP_Instance)) { | 590 PP_Bool (*reserve)(PP_Module, PP_Instance)) { |
| 584 DCHECK(!reserve_instance_id_) << "Only expect one set."; | |
| 585 reserve_instance_id_ = reserve; | 591 reserve_instance_id_ = reserve; |
| 586 } | 592 } |
| 587 | 593 |
| 588 bool PluginModule::ReserveInstanceID(PP_Instance instance) { | 594 bool PluginModule::ReserveInstanceID(PP_Instance instance) { |
| 595 DCHECK(!reserve_instance_id_) << "Only expect one set."; | |
|
dmichael (off chromium)
2012/06/21 18:18:16
Why did you move this check? It doesn't make sense
bbudge
2012/06/21 19:28:18
The HostDispatcher sets it and it can be set multi
dmichael (off chromium)
2012/06/21 19:42:30
So that would argue for simply removing the check.
| |
| 589 if (reserve_instance_id_) | 596 if (reserve_instance_id_) |
| 590 return PPBoolToBool(reserve_instance_id_(pp_module_, instance)); | 597 return PPBoolToBool(reserve_instance_id_(pp_module_, instance)); |
| 591 return true; // Instance ID is usable. | 598 return true; // Instance ID is usable. |
| 592 } | 599 } |
| 593 | 600 |
| 594 void PluginModule::SetBroker(PluginDelegate::Broker* broker) { | 601 void PluginModule::SetBroker(PluginDelegate::Broker* broker) { |
| 595 DCHECK(!broker_ || !broker); | 602 DCHECK(!broker_ || !broker); |
| 596 broker_ = broker; | 603 broker_ = broker; |
| 597 } | 604 } |
| 598 | 605 |
| 599 PluginDelegate::Broker* PluginModule::GetBroker() { | 606 PluginDelegate::Broker* PluginModule::GetBroker() { |
| 600 return broker_; | 607 return broker_; |
| 601 } | 608 } |
| 602 | 609 |
| 603 bool PluginModule::InitializeModule(const EntryPoints& entry_points) { | 610 bool PluginModule::InitializeModule(const EntryPoints& entry_points) { |
| 604 DCHECK(!out_of_process_proxy_.get()) << "Don't call for proxied modules."; | 611 DCHECK(!out_of_process_proxy_.get()) << "Don't call for proxied modules."; |
| 605 DCHECK(entry_points.initialize_module != NULL); | 612 DCHECK(entry_points.initialize_module != NULL); |
| 606 int retval = entry_points.initialize_module(pp_module(), &GetInterface); | 613 int retval = entry_points.initialize_module(pp_module(), &GetInterface); |
| 607 if (retval != 0) { | 614 if (retval != 0) { |
| 608 LOG(WARNING) << "PPP_InitializeModule returned failure " << retval; | 615 LOG(WARNING) << "PPP_InitializeModule returned failure " << retval; |
| 609 return false; | 616 return false; |
| 610 } | 617 } |
| 611 return true; | 618 return true; |
| 612 } | 619 } |
| 613 | 620 |
| 614 } // namespace ppapi | 621 } // namespace ppapi |
| 615 } // namespace webkit | 622 } // namespace webkit |
| OLD | NEW |