Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "chrome/browser/extensions/extension_system_impl.h" | 5 #include "chrome/browser/extensions/extension_system_impl.h" |
| 6 | 6 |
| 7 #include "base/base_switches.h" | 7 #include "base/base_switches.h" |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| 11 #include "base/memory/weak_ptr.h" | 11 #include "base/memory/weak_ptr.h" |
| 12 #include "base/metrics/field_trial.h" | 12 #include "base/metrics/field_trial.h" |
| 13 #include "base/metrics/histogram.h" | 13 #include "base/metrics/histogram.h" |
| 14 #include "base/strings/string_tokenizer.h" | 14 #include "base/strings/string_tokenizer.h" |
| 15 #include "base/strings/string_util.h" | |
| 15 #include "chrome/browser/browser_process.h" | 16 #include "chrome/browser/browser_process.h" |
| 16 #include "chrome/browser/content_settings/cookie_settings.h" | 17 #include "chrome/browser/content_settings/cookie_settings.h" |
| 17 #include "chrome/browser/extensions/blacklist.h" | 18 #include "chrome/browser/extensions/blacklist.h" |
| 18 #include "chrome/browser/extensions/component_loader.h" | 19 #include "chrome/browser/extensions/component_loader.h" |
| 20 #include "chrome/browser/extensions/declarative_user_script_master.h" | |
| 19 #include "chrome/browser/extensions/error_console/error_console.h" | 21 #include "chrome/browser/extensions/error_console/error_console.h" |
| 20 #include "chrome/browser/extensions/extension_error_reporter.h" | 22 #include "chrome/browser/extensions/extension_error_reporter.h" |
| 21 #include "chrome/browser/extensions/extension_service.h" | 23 #include "chrome/browser/extensions/extension_service.h" |
| 22 #include "chrome/browser/extensions/extension_system_factory.h" | 24 #include "chrome/browser/extensions/extension_system_factory.h" |
| 23 #include "chrome/browser/extensions/extension_util.h" | 25 #include "chrome/browser/extensions/extension_util.h" |
| 24 #include "chrome/browser/extensions/extension_warning_badge_service.h" | 26 #include "chrome/browser/extensions/extension_warning_badge_service.h" |
| 25 #include "chrome/browser/extensions/extension_warning_set.h" | 27 #include "chrome/browser/extensions/extension_warning_set.h" |
| 26 #include "chrome/browser/extensions/install_verifier.h" | 28 #include "chrome/browser/extensions/install_verifier.h" |
| 27 #include "chrome/browser/extensions/navigation_observer.h" | 29 #include "chrome/browser/extensions/navigation_observer.h" |
| 28 #include "chrome/browser/extensions/shared_module_service.h" | 30 #include "chrome/browser/extensions/shared_module_service.h" |
| 31 #include "chrome/browser/extensions/shared_user_script_master.h" | |
| 29 #include "chrome/browser/extensions/standard_management_policy_provider.h" | 32 #include "chrome/browser/extensions/standard_management_policy_provider.h" |
| 30 #include "chrome/browser/extensions/state_store_notification_observer.h" | 33 #include "chrome/browser/extensions/state_store_notification_observer.h" |
| 31 #include "chrome/browser/extensions/updater/manifest_fetch_data.h" | 34 #include "chrome/browser/extensions/updater/manifest_fetch_data.h" |
| 32 #include "chrome/browser/extensions/user_script_master.h" | |
| 33 #include "chrome/browser/profiles/profile.h" | 35 #include "chrome/browser/profiles/profile.h" |
| 34 #include "chrome/browser/profiles/profile_manager.h" | 36 #include "chrome/browser/profiles/profile_manager.h" |
| 35 #include "chrome/common/chrome_switches.h" | 37 #include "chrome/common/chrome_switches.h" |
| 36 #include "chrome/common/chrome_version_info.h" | 38 #include "chrome/common/chrome_version_info.h" |
| 37 #include "chrome/common/extensions/extension_constants.h" | 39 #include "chrome/common/extensions/extension_constants.h" |
| 38 #include "chrome/common/extensions/extension_file_util.h" | 40 #include "chrome/common/extensions/extension_file_util.h" |
| 39 #include "chrome/common/extensions/features/feature_channel.h" | 41 #include "chrome/common/extensions/features/feature_channel.h" |
| 40 #include "chrome/common/extensions/manifest_url_handler.h" | 42 #include "chrome/common/extensions/manifest_url_handler.h" |
| 41 #include "content/public/browser/browser_thread.h" | 43 #include "content/public/browser/browser_thread.h" |
| 42 #include "content/public/browser/url_data_source.h" | 44 #include "content/public/browser/url_data_source.h" |
| (...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 309 } // namespace | 311 } // namespace |
| 310 | 312 |
| 311 void ExtensionSystemImpl::Shared::Init(bool extensions_enabled) { | 313 void ExtensionSystemImpl::Shared::Init(bool extensions_enabled) { |
| 312 const CommandLine* command_line = CommandLine::ForCurrentProcess(); | 314 const CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 313 | 315 |
| 314 navigation_observer_.reset(new NavigationObserver(profile_)); | 316 navigation_observer_.reset(new NavigationObserver(profile_)); |
| 315 | 317 |
| 316 bool allow_noisy_errors = !command_line->HasSwitch(switches::kNoErrorDialogs); | 318 bool allow_noisy_errors = !command_line->HasSwitch(switches::kNoErrorDialogs); |
| 317 ExtensionErrorReporter::Init(allow_noisy_errors); | 319 ExtensionErrorReporter::Init(allow_noisy_errors); |
| 318 | 320 |
| 319 user_script_master_.reset(new UserScriptMaster(profile_)); | 321 shared_user_script_master_.reset(new SharedUserScriptMaster(profile_)); |
| 320 | 322 |
| 321 // ExtensionService depends on RuntimeData. | 323 // ExtensionService depends on RuntimeData. |
| 322 runtime_data_.reset(new RuntimeData(ExtensionRegistry::Get(profile_))); | 324 runtime_data_.reset(new RuntimeData(ExtensionRegistry::Get(profile_))); |
| 323 | 325 |
| 324 bool autoupdate_enabled = !profile_->IsGuestSession(); | 326 bool autoupdate_enabled = !profile_->IsGuestSession(); |
| 325 #if defined(OS_CHROMEOS) | 327 #if defined(OS_CHROMEOS) |
| 326 if (!extensions_enabled) | 328 if (!extensions_enabled) |
| 327 autoupdate_enabled = false; | 329 autoupdate_enabled = false; |
| 328 #endif | 330 #endif |
| 329 extension_service_.reset(new ExtensionService( | 331 extension_service_.reset(new ExtensionService( |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 449 } | 451 } |
| 450 | 452 |
| 451 RuntimeData* ExtensionSystemImpl::Shared::runtime_data() { | 453 RuntimeData* ExtensionSystemImpl::Shared::runtime_data() { |
| 452 return runtime_data_.get(); | 454 return runtime_data_.get(); |
| 453 } | 455 } |
| 454 | 456 |
| 455 ManagementPolicy* ExtensionSystemImpl::Shared::management_policy() { | 457 ManagementPolicy* ExtensionSystemImpl::Shared::management_policy() { |
| 456 return management_policy_.get(); | 458 return management_policy_.get(); |
| 457 } | 459 } |
| 458 | 460 |
| 459 UserScriptMaster* ExtensionSystemImpl::Shared::user_script_master() { | 461 SharedUserScriptMaster* |
| 460 return user_script_master_.get(); | 462 ExtensionSystemImpl::Shared::shared_user_script_master() { |
| 463 return shared_user_script_master_.get(); | |
| 461 } | 464 } |
| 462 | 465 |
| 463 InfoMap* ExtensionSystemImpl::Shared::info_map() { | 466 InfoMap* ExtensionSystemImpl::Shared::info_map() { |
| 464 if (!extension_info_map_.get()) | 467 if (!extension_info_map_.get()) |
| 465 extension_info_map_ = new InfoMap(); | 468 extension_info_map_ = new InfoMap(); |
| 466 return extension_info_map_.get(); | 469 return extension_info_map_.get(); |
| 467 } | 470 } |
| 468 | 471 |
| 469 LazyBackgroundTaskQueue* | 472 LazyBackgroundTaskQueue* |
| 470 ExtensionSystemImpl::Shared::lazy_background_task_queue() { | 473 ExtensionSystemImpl::Shared::lazy_background_task_queue() { |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 492 } | 495 } |
| 493 | 496 |
| 494 QuotaService* ExtensionSystemImpl::Shared::quota_service() { | 497 QuotaService* ExtensionSystemImpl::Shared::quota_service() { |
| 495 return quota_service_.get(); | 498 return quota_service_.get(); |
| 496 } | 499 } |
| 497 | 500 |
| 498 ContentVerifier* ExtensionSystemImpl::Shared::content_verifier() { | 501 ContentVerifier* ExtensionSystemImpl::Shared::content_verifier() { |
| 499 return content_verifier_.get(); | 502 return content_verifier_.get(); |
| 500 } | 503 } |
| 501 | 504 |
| 505 DeclarativeUserScriptMaster* | |
| 506 ExtensionSystemImpl::Shared::GetDeclarativeUserScriptMasterByExtension( | |
| 507 const ExtensionId& extension_id) { | |
| 508 if (!declarative_user_script_masters_.get(extension_id)) { | |
|
Devlin
2014/08/05 21:47:26
This will be moot if we make this a scoped vector,
Mark Dittmer
2014/08/06 15:32:25
Done.
| |
| 509 declarative_user_script_masters_.set(extension_id, make_scoped_ptr( | |
| 510 new DeclarativeUserScriptMaster(profile_, extension_id))); | |
| 511 } | |
| 512 return declarative_user_script_masters_.get(extension_id); | |
| 513 } | |
| 514 | |
| 502 // | 515 // |
| 503 // ExtensionSystemImpl | 516 // ExtensionSystemImpl |
| 504 // | 517 // |
| 505 | 518 |
| 506 ExtensionSystemImpl::ExtensionSystemImpl(Profile* profile) | 519 ExtensionSystemImpl::ExtensionSystemImpl(Profile* profile) |
| 507 : profile_(profile) { | 520 : profile_(profile) { |
| 508 shared_ = ExtensionSystemSharedFactory::GetForBrowserContext(profile); | 521 shared_ = ExtensionSystemSharedFactory::GetForBrowserContext(profile); |
| 509 | 522 |
| 510 if (profile->IsOffTheRecord()) { | 523 if (profile->IsOffTheRecord()) { |
| 511 process_manager_.reset(ProcessManager::Create(profile)); | 524 process_manager_.reset(ProcessManager::Create(profile)); |
| 512 } else { | 525 } else { |
| 513 shared_->InitPrefs(); | 526 shared_->InitPrefs(); |
| 514 } | 527 } |
| 515 } | 528 } |
| 516 | 529 |
| 517 ExtensionSystemImpl::~ExtensionSystemImpl() { | 530 ExtensionSystemImpl::~ExtensionSystemImpl() { |
| 518 } | 531 } |
| 519 | 532 |
| 520 void ExtensionSystemImpl::Shutdown() { | 533 void ExtensionSystemImpl::Shutdown() { |
| 521 process_manager_.reset(); | 534 process_manager_.reset(); |
| 522 } | 535 } |
| 523 | 536 |
| 524 void ExtensionSystemImpl::InitForRegularProfile(bool extensions_enabled) { | 537 void ExtensionSystemImpl::InitForRegularProfile(bool extensions_enabled) { |
| 525 DCHECK(!profile_->IsOffTheRecord()); | 538 DCHECK(!profile_->IsOffTheRecord()); |
| 526 if (user_script_master() || extension_service()) | 539 if (shared_user_script_master() || extension_service()) |
| 527 return; // Already initialized. | 540 return; // Already initialized. |
| 528 | 541 |
| 529 // The InfoMap needs to be created before the ProcessManager. | 542 // The InfoMap needs to be created before the ProcessManager. |
| 530 shared_->info_map(); | 543 shared_->info_map(); |
| 531 | 544 |
| 532 process_manager_.reset(ProcessManager::Create(profile_)); | 545 process_manager_.reset(ProcessManager::Create(profile_)); |
| 533 | 546 |
| 534 shared_->Init(extensions_enabled); | 547 shared_->Init(extensions_enabled); |
| 535 } | 548 } |
| 536 | 549 |
| 537 ExtensionService* ExtensionSystemImpl::extension_service() { | 550 ExtensionService* ExtensionSystemImpl::extension_service() { |
| 538 return shared_->extension_service(); | 551 return shared_->extension_service(); |
| 539 } | 552 } |
| 540 | 553 |
| 541 RuntimeData* ExtensionSystemImpl::runtime_data() { | 554 RuntimeData* ExtensionSystemImpl::runtime_data() { |
| 542 return shared_->runtime_data(); | 555 return shared_->runtime_data(); |
| 543 } | 556 } |
| 544 | 557 |
| 545 ManagementPolicy* ExtensionSystemImpl::management_policy() { | 558 ManagementPolicy* ExtensionSystemImpl::management_policy() { |
| 546 return shared_->management_policy(); | 559 return shared_->management_policy(); |
| 547 } | 560 } |
| 548 | 561 |
| 549 UserScriptMaster* ExtensionSystemImpl::user_script_master() { | 562 SharedUserScriptMaster* ExtensionSystemImpl::shared_user_script_master() { |
| 550 return shared_->user_script_master(); | 563 return shared_->shared_user_script_master(); |
| 551 } | 564 } |
| 552 | 565 |
| 553 ProcessManager* ExtensionSystemImpl::process_manager() { | 566 ProcessManager* ExtensionSystemImpl::process_manager() { |
| 554 return process_manager_.get(); | 567 return process_manager_.get(); |
| 555 } | 568 } |
| 556 | 569 |
| 557 StateStore* ExtensionSystemImpl::state_store() { | 570 StateStore* ExtensionSystemImpl::state_store() { |
| 558 return shared_->state_store(); | 571 return shared_->state_store(); |
| 559 } | 572 } |
| 560 | 573 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 599 ContentVerifier* ExtensionSystemImpl::content_verifier() { | 612 ContentVerifier* ExtensionSystemImpl::content_verifier() { |
| 600 return shared_->content_verifier(); | 613 return shared_->content_verifier(); |
| 601 } | 614 } |
| 602 | 615 |
| 603 scoped_ptr<ExtensionSet> ExtensionSystemImpl::GetDependentExtensions( | 616 scoped_ptr<ExtensionSet> ExtensionSystemImpl::GetDependentExtensions( |
| 604 const Extension* extension) { | 617 const Extension* extension) { |
| 605 return extension_service()->shared_module_service()->GetDependentExtensions( | 618 return extension_service()->shared_module_service()->GetDependentExtensions( |
| 606 extension); | 619 extension); |
| 607 } | 620 } |
| 608 | 621 |
| 622 DeclarativeUserScriptMaster* | |
| 623 ExtensionSystemImpl::GetDeclarativeUserScriptMasterByExtension( | |
| 624 const ExtensionId& extension_id) { | |
| 625 return shared_->GetDeclarativeUserScriptMasterByExtension(extension_id); | |
| 626 } | |
| 627 | |
| 609 void ExtensionSystemImpl::RegisterExtensionWithRequestContexts( | 628 void ExtensionSystemImpl::RegisterExtensionWithRequestContexts( |
| 610 const Extension* extension) { | 629 const Extension* extension) { |
| 611 base::Time install_time; | 630 base::Time install_time; |
| 612 if (extension->location() != Manifest::COMPONENT) { | 631 if (extension->location() != Manifest::COMPONENT) { |
| 613 install_time = ExtensionPrefs::Get(profile_)-> | 632 install_time = ExtensionPrefs::Get(profile_)-> |
| 614 GetInstallTime(extension->id()); | 633 GetInstallTime(extension->id()); |
| 615 } | 634 } |
| 616 bool incognito_enabled = util::IsIncognitoEnabled(extension->id(), profile_); | 635 bool incognito_enabled = util::IsIncognitoEnabled(extension->id(), profile_); |
| 617 | 636 |
| 618 bool notifications_disabled = false; | 637 bool notifications_disabled = false; |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 637 void ExtensionSystemImpl::UnregisterExtensionWithRequestContexts( | 656 void ExtensionSystemImpl::UnregisterExtensionWithRequestContexts( |
| 638 const std::string& extension_id, | 657 const std::string& extension_id, |
| 639 const UnloadedExtensionInfo::Reason reason) { | 658 const UnloadedExtensionInfo::Reason reason) { |
| 640 BrowserThread::PostTask( | 659 BrowserThread::PostTask( |
| 641 BrowserThread::IO, | 660 BrowserThread::IO, |
| 642 FROM_HERE, | 661 FROM_HERE, |
| 643 base::Bind(&InfoMap::RemoveExtension, info_map(), extension_id, reason)); | 662 base::Bind(&InfoMap::RemoveExtension, info_map(), extension_id, reason)); |
| 644 } | 663 } |
| 645 | 664 |
| 646 } // namespace extensions | 665 } // namespace extensions |
| OLD | NEW |