| 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 ::ppapi::PpapiPermissions& perms) | 412 const ::ppapi::PpapiPermissions& perms) |
| 413 : lifetime_delegate_(lifetime_delegate), | 413 : lifetime_delegate_(lifetime_delegate), |
| 414 callback_tracker_(new ::ppapi::CallbackTracker), | 414 callback_tracker_(new ::ppapi::CallbackTracker), |
| 415 is_in_destructor_(false), | 415 is_in_destructor_(false), |
| 416 is_crashed_(false), | 416 is_crashed_(false), |
| 417 broker_(NULL), | 417 broker_(NULL), |
| 418 library_(NULL), | 418 library_(NULL), |
| 419 name_(name), | 419 name_(name), |
| 420 path_(path), | 420 path_(path), |
| 421 permissions_(perms), | 421 permissions_(perms), |
| 422 reserve_instance_id_(NULL), | 422 reserve_instance_id_(NULL) { |
| 423 nacl_ipc_proxy_(false) { | |
| 424 // Ensure the globals object is created. | 423 // Ensure the globals object is created. |
| 425 if (!host_globals) | 424 if (!host_globals) |
| 426 host_globals = new HostGlobals; | 425 host_globals = new HostGlobals; |
| 427 | 426 |
| 428 memset(&entry_points_, 0, sizeof(entry_points_)); | 427 memset(&entry_points_, 0, sizeof(entry_points_)); |
| 429 pp_module_ = HostGlobals::Get()->AddModule(this); | 428 pp_module_ = HostGlobals::Get()->AddModule(this); |
| 430 GetLivePluginSet()->insert(this); | 429 GetLivePluginSet()->insert(this); |
| 431 } | 430 } |
| 432 | 431 |
| 433 PluginModule::~PluginModule() { | 432 PluginModule::~PluginModule() { |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 496 library_ = library; | 495 library_ = library; |
| 497 return true; | 496 return true; |
| 498 } | 497 } |
| 499 | 498 |
| 500 void PluginModule::InitAsProxied( | 499 void PluginModule::InitAsProxied( |
| 501 PluginDelegate::OutOfProcessProxy* out_of_process_proxy) { | 500 PluginDelegate::OutOfProcessProxy* out_of_process_proxy) { |
| 502 DCHECK(!out_of_process_proxy_.get()); | 501 DCHECK(!out_of_process_proxy_.get()); |
| 503 out_of_process_proxy_.reset(out_of_process_proxy); | 502 out_of_process_proxy_.reset(out_of_process_proxy); |
| 504 } | 503 } |
| 505 | 504 |
| 505 scoped_refptr<PluginModule> PluginModule::CreateModuleForNaClInstance() { |
| 506 // Create a new module, but don't set the lifetime delegate. This isn't a |
| 507 // plugin in the usual sense, so it isn't tracked by the browser. |
| 508 scoped_refptr<PluginModule> nacl_module( |
| 509 new PluginModule(name_, |
| 510 path_, |
| 511 NULL, // no lifetime_delegate |
| 512 permissions_)); |
| 513 return nacl_module; |
| 514 } |
| 515 |
| 506 void PluginModule::InitAsProxiedNaCl( | 516 void PluginModule::InitAsProxiedNaCl( |
| 507 scoped_ptr<PluginDelegate::OutOfProcessProxy> out_of_process_proxy, | 517 scoped_ptr<PluginDelegate::OutOfProcessProxy> out_of_process_proxy, |
| 508 PP_Instance instance) { | 518 PP_Instance instance) { |
| 509 // TODO(bbudge) We need to switch the mode of the PluginModule on a | |
| 510 // per-instance basis. Fix this so out_of_process_proxy and other | |
| 511 // state is stored in a map, indexed by instance. | |
| 512 nacl_ipc_proxy_ = true; | |
| 513 InitAsProxied(out_of_process_proxy.release()); | 519 InitAsProxied(out_of_process_proxy.release()); |
| 514 // InitAsProxied (for the trusted/out-of-process case) initializes only the | 520 // InitAsProxied (for the trusted/out-of-process case) initializes only the |
| 515 // module, and one or more instances are added later. In this case, the | 521 // module, and one or more instances are added later. In this case, the |
| 516 // PluginInstance was already created as in-process, so we missed the proxy | 522 // PluginInstance was already created as in-process, so we missed the proxy |
| 517 // AddInstance step and must do it now. | 523 // AddInstance step and must do it now. |
| 518 out_of_process_proxy_->AddInstance(instance); | 524 out_of_process_proxy_->AddInstance(instance); |
| 519 | |
| 520 // In NaCl, we need to tell the instance to reset itself as proxied. This will | 525 // In NaCl, we need to tell the instance to reset itself as proxied. This will |
| 521 // clear cached interface pointers and send DidCreate (etc) to the plugin | 526 // clear cached interface pointers and send DidCreate (etc) to the plugin |
| 522 // side of the proxy. | 527 // side of the proxy. |
| 523 PluginInstance* plugin_instance = host_globals->GetInstance(instance); | 528 PluginInstance* plugin_instance = host_globals->GetInstance(instance); |
| 524 if (!plugin_instance) | 529 if (!plugin_instance) |
| 525 return; | 530 return; |
| 526 plugin_instance->ResetAsProxied(); | 531 plugin_instance->ResetAsProxied(this); |
| 527 } | 532 } |
| 528 | 533 |
| 529 // static | 534 // static |
| 530 const PPB_Core* PluginModule::GetCore() { | 535 const PPB_Core* PluginModule::GetCore() { |
| 531 return &core_interface; | 536 return &core_interface; |
| 532 } | 537 } |
| 533 | 538 |
| 534 // static | 539 // static |
| 535 PluginModule::GetInterfaceFunc PluginModule::GetLocalGetInterfaceFunc() { | 540 PluginModule::GetInterfaceFunc PluginModule::GetLocalGetInterfaceFunc() { |
| 536 return &GetInterface; | 541 return &GetInterface; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 570 } | 575 } |
| 571 | 576 |
| 572 void PluginModule::InstanceCreated(PluginInstance* instance) { | 577 void PluginModule::InstanceCreated(PluginInstance* instance) { |
| 573 instances_.insert(instance); | 578 instances_.insert(instance); |
| 574 } | 579 } |
| 575 | 580 |
| 576 void PluginModule::InstanceDeleted(PluginInstance* instance) { | 581 void PluginModule::InstanceDeleted(PluginInstance* instance) { |
| 577 if (out_of_process_proxy_.get()) | 582 if (out_of_process_proxy_.get()) |
| 578 out_of_process_proxy_->RemoveInstance(instance->pp_instance()); | 583 out_of_process_proxy_->RemoveInstance(instance->pp_instance()); |
| 579 instances_.erase(instance); | 584 instances_.erase(instance); |
| 580 | |
| 581 if (nacl_ipc_proxy_) { | |
| 582 out_of_process_proxy_.reset(); | |
| 583 reserve_instance_id_ = NULL; | |
| 584 } | |
| 585 } | 585 } |
| 586 | 586 |
| 587 scoped_refptr< ::ppapi::CallbackTracker> PluginModule::GetCallbackTracker() { | 587 scoped_refptr< ::ppapi::CallbackTracker> PluginModule::GetCallbackTracker() { |
| 588 return callback_tracker_; | 588 return callback_tracker_; |
| 589 } | 589 } |
| 590 | 590 |
| 591 void PluginModule::PluginCrashed() { | 591 void PluginModule::PluginCrashed() { |
| 592 DCHECK(!is_crashed_); // Should only get one notification. | 592 DCHECK(!is_crashed_); // Should only get one notification. |
| 593 is_crashed_ = true; | 593 is_crashed_ = true; |
| 594 | 594 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 628 int retval = entry_points.initialize_module(pp_module(), &GetInterface); | 628 int retval = entry_points.initialize_module(pp_module(), &GetInterface); |
| 629 if (retval != 0) { | 629 if (retval != 0) { |
| 630 LOG(WARNING) << "PPP_InitializeModule returned failure " << retval; | 630 LOG(WARNING) << "PPP_InitializeModule returned failure " << retval; |
| 631 return false; | 631 return false; |
| 632 } | 632 } |
| 633 return true; | 633 return true; |
| 634 } | 634 } |
| 635 | 635 |
| 636 } // namespace ppapi | 636 } // namespace ppapi |
| 637 } // namespace webkit | 637 } // namespace webkit |
| OLD | NEW |