| 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/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
| (...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 415 const FilePath& path, | 415 const FilePath& path, |
| 416 PluginDelegate::ModuleLifetime* lifetime_delegate) | 416 PluginDelegate::ModuleLifetime* lifetime_delegate) |
| 417 : lifetime_delegate_(lifetime_delegate), | 417 : lifetime_delegate_(lifetime_delegate), |
| 418 callback_tracker_(new CallbackTracker), | 418 callback_tracker_(new CallbackTracker), |
| 419 is_crashed_(false), | 419 is_crashed_(false), |
| 420 broker_(NULL), | 420 broker_(NULL), |
| 421 library_(NULL), | 421 library_(NULL), |
| 422 name_(name), | 422 name_(name), |
| 423 path_(path), | 423 path_(path), |
| 424 reserve_instance_id_(NULL) { | 424 reserve_instance_id_(NULL) { |
| 425 memset(&entry_points_, 0, sizeof(entry_points_)); |
| 425 pp_module_ = ResourceTracker::Get()->AddModule(this); | 426 pp_module_ = ResourceTracker::Get()->AddModule(this); |
| 426 GetMainThreadMessageLoop(); // Initialize the main thread message loop. | 427 GetMainThreadMessageLoop(); // Initialize the main thread message loop. |
| 427 GetLivePluginSet()->insert(this); | 428 GetLivePluginSet()->insert(this); |
| 428 } | 429 } |
| 429 | 430 |
| 430 PluginModule::~PluginModule() { | 431 PluginModule::~PluginModule() { |
| 431 // When the module is being deleted, there should be no more instances still | 432 // When the module is being deleted, there should be no more instances still |
| 432 // holding a reference to us. | 433 // holding a reference to us. |
| 433 DCHECK(instances_.empty()); | 434 DCHECK(instances_.empty()); |
| 434 | 435 |
| 435 GetLivePluginSet()->erase(this); | 436 GetLivePluginSet()->erase(this); |
| 436 | 437 |
| 437 callback_tracker_->AbortAll(); | 438 callback_tracker_->AbortAll(); |
| 438 | 439 |
| 439 if (entry_points_.shutdown_module) | 440 if (entry_points_.shutdown_module) |
| 440 entry_points_.shutdown_module(); | 441 entry_points_.shutdown_module(); |
| 441 | 442 |
| 442 if (library_) | 443 if (library_) |
| 443 base::UnloadNativeLibrary(library_); | 444 base::UnloadNativeLibrary(library_); |
| 444 | 445 |
| 445 ResourceTracker::Get()->ModuleDeleted(pp_module_); | 446 ResourceTracker::Get()->ModuleDeleted(pp_module_); |
| 446 | 447 |
| 447 // When the plugin crashes, we immediately tell the lifetime delegate that | 448 // When the plugin crashes, we immediately tell the lifetime delegate that |
| 448 // we're gone, so we don't want to tell it again. | 449 // we're gone, so we don't want to tell it again. |
| 449 if (!is_crashed_) | 450 if (!is_crashed_) |
| 450 lifetime_delegate_->PluginModuleDead(this); | 451 lifetime_delegate_->PluginModuleDead(this); |
| 451 } | 452 } |
| 452 | 453 |
| 453 bool PluginModule::InitAsInternalPlugin(const EntryPoints& entry_points) { | 454 bool PluginModule::InitAsInternalPlugin(const EntryPoints& entry_points) { |
| 454 entry_points_ = entry_points; | 455 if (InitializeModule(entry_points)) { |
| 455 return InitializeModule(); | 456 entry_points_ = entry_points; |
| 457 return true; |
| 458 } |
| 459 return false; |
| 456 } | 460 } |
| 457 | 461 |
| 458 bool PluginModule::InitAsLibrary(const FilePath& path) { | 462 bool PluginModule::InitAsLibrary(const FilePath& path) { |
| 459 base::NativeLibrary library = base::LoadNativeLibrary(path, NULL); | 463 base::NativeLibrary library = base::LoadNativeLibrary(path, NULL); |
| 460 if (!library) | 464 if (!library) |
| 461 return false; | 465 return false; |
| 462 | 466 |
| 463 if (!LoadEntryPointsFromLibrary(library, &entry_points_) || | 467 EntryPoints entry_points; |
| 464 !InitializeModule()) { | 468 |
| 469 if (!LoadEntryPointsFromLibrary(library, &entry_points) || |
| 470 !InitializeModule(entry_points)) { |
| 465 base::UnloadNativeLibrary(library); | 471 base::UnloadNativeLibrary(library); |
| 466 return false; | 472 return false; |
| 467 } | 473 } |
| 468 | 474 entry_points_ = entry_points; |
| 469 library_ = library; | 475 library_ = library; |
| 470 return true; | 476 return true; |
| 471 } | 477 } |
| 472 | 478 |
| 473 void PluginModule::InitAsProxied( | 479 void PluginModule::InitAsProxied( |
| 474 PluginDelegate::OutOfProcessProxy* out_of_process_proxy) { | 480 PluginDelegate::OutOfProcessProxy* out_of_process_proxy) { |
| 475 DCHECK(!out_of_process_proxy_.get()); | 481 DCHECK(!out_of_process_proxy_.get()); |
| 476 out_of_process_proxy_.reset(out_of_process_proxy); | 482 out_of_process_proxy_.reset(out_of_process_proxy); |
| 477 } | 483 } |
| 478 | 484 |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 569 PluginDelegate::PpapiBroker* PluginModule::GetBroker(){ | 575 PluginDelegate::PpapiBroker* PluginModule::GetBroker(){ |
| 570 return broker_; | 576 return broker_; |
| 571 } | 577 } |
| 572 | 578 |
| 573 ::ppapi::WebKitForwarding* PluginModule::GetWebKitForwarding() { | 579 ::ppapi::WebKitForwarding* PluginModule::GetWebKitForwarding() { |
| 574 if (!webkit_forwarding_.get()) | 580 if (!webkit_forwarding_.get()) |
| 575 webkit_forwarding_.reset(new WebKitForwardingImpl); | 581 webkit_forwarding_.reset(new WebKitForwardingImpl); |
| 576 return webkit_forwarding_.get(); | 582 return webkit_forwarding_.get(); |
| 577 } | 583 } |
| 578 | 584 |
| 579 bool PluginModule::InitializeModule() { | 585 bool PluginModule::InitializeModule(const EntryPoints& entry_points) { |
| 580 DCHECK(!out_of_process_proxy_.get()) << "Don't call for proxied modules."; | 586 DCHECK(!out_of_process_proxy_.get()) << "Don't call for proxied modules."; |
| 581 int retval = entry_points_.initialize_module(pp_module(), &GetInterface); | 587 DCHECK(entry_points.initialize_module != NULL); |
| 588 int retval = entry_points.initialize_module(pp_module(), &GetInterface); |
| 582 if (retval != 0) { | 589 if (retval != 0) { |
| 583 LOG(WARNING) << "PPP_InitializeModule returned failure " << retval; | 590 LOG(WARNING) << "PPP_InitializeModule returned failure " << retval; |
| 584 return false; | 591 return false; |
| 585 } | 592 } |
| 586 return true; | 593 return true; |
| 587 } | 594 } |
| 588 | 595 |
| 589 } // namespace ppapi | 596 } // namespace ppapi |
| 590 } // namespace webkit | 597 } // namespace webkit |
| OLD | NEW |