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 DeclarativeUserScriptMaster* master = NULL; | |
Devlin
2014/08/06 15:59:25
Is there any risk with initializing these before t
Mark Dittmer
2014/08/06 22:08:18
I don't think so. These are only fetched in the co
Devlin
2014/08/07 15:46:31
It should be. Perhaps we should DCHECK that, thou
Mark Dittmer
2014/08/11 14:08:04
Done.
| |
509 for (ScopedVector<DeclarativeUserScriptMaster>::iterator it = | |
510 declarative_user_script_masters_.begin(); | |
511 it != declarative_user_script_masters_.end(); ++it) { | |
512 if ((*it)->extension_id() == extension_id) { | |
513 master = *it; | |
514 break; | |
515 } | |
516 } | |
517 if (!master) { | |
518 master = new DeclarativeUserScriptMaster(profile_, extension_id); | |
519 declarative_user_script_masters_.push_back(master); | |
520 } | |
521 return master; | |
522 } | |
523 | |
502 // | 524 // |
503 // ExtensionSystemImpl | 525 // ExtensionSystemImpl |
504 // | 526 // |
505 | 527 |
506 ExtensionSystemImpl::ExtensionSystemImpl(Profile* profile) | 528 ExtensionSystemImpl::ExtensionSystemImpl(Profile* profile) |
507 : profile_(profile) { | 529 : profile_(profile) { |
508 shared_ = ExtensionSystemSharedFactory::GetForBrowserContext(profile); | 530 shared_ = ExtensionSystemSharedFactory::GetForBrowserContext(profile); |
509 | 531 |
510 if (profile->IsOffTheRecord()) { | 532 if (profile->IsOffTheRecord()) { |
511 process_manager_.reset(ProcessManager::Create(profile)); | 533 process_manager_.reset(ProcessManager::Create(profile)); |
512 } else { | 534 } else { |
513 shared_->InitPrefs(); | 535 shared_->InitPrefs(); |
514 } | 536 } |
515 } | 537 } |
516 | 538 |
517 ExtensionSystemImpl::~ExtensionSystemImpl() { | 539 ExtensionSystemImpl::~ExtensionSystemImpl() { |
518 } | 540 } |
519 | 541 |
520 void ExtensionSystemImpl::Shutdown() { | 542 void ExtensionSystemImpl::Shutdown() { |
521 process_manager_.reset(); | 543 process_manager_.reset(); |
522 } | 544 } |
523 | 545 |
524 void ExtensionSystemImpl::InitForRegularProfile(bool extensions_enabled) { | 546 void ExtensionSystemImpl::InitForRegularProfile(bool extensions_enabled) { |
525 DCHECK(!profile_->IsOffTheRecord()); | 547 DCHECK(!profile_->IsOffTheRecord()); |
526 if (user_script_master() || extension_service()) | 548 if (shared_user_script_master() || extension_service()) |
527 return; // Already initialized. | 549 return; // Already initialized. |
528 | 550 |
529 // The InfoMap needs to be created before the ProcessManager. | 551 // The InfoMap needs to be created before the ProcessManager. |
530 shared_->info_map(); | 552 shared_->info_map(); |
531 | 553 |
532 process_manager_.reset(ProcessManager::Create(profile_)); | 554 process_manager_.reset(ProcessManager::Create(profile_)); |
533 | 555 |
534 shared_->Init(extensions_enabled); | 556 shared_->Init(extensions_enabled); |
535 } | 557 } |
536 | 558 |
537 ExtensionService* ExtensionSystemImpl::extension_service() { | 559 ExtensionService* ExtensionSystemImpl::extension_service() { |
538 return shared_->extension_service(); | 560 return shared_->extension_service(); |
539 } | 561 } |
540 | 562 |
541 RuntimeData* ExtensionSystemImpl::runtime_data() { | 563 RuntimeData* ExtensionSystemImpl::runtime_data() { |
542 return shared_->runtime_data(); | 564 return shared_->runtime_data(); |
543 } | 565 } |
544 | 566 |
545 ManagementPolicy* ExtensionSystemImpl::management_policy() { | 567 ManagementPolicy* ExtensionSystemImpl::management_policy() { |
546 return shared_->management_policy(); | 568 return shared_->management_policy(); |
547 } | 569 } |
548 | 570 |
549 UserScriptMaster* ExtensionSystemImpl::user_script_master() { | 571 SharedUserScriptMaster* ExtensionSystemImpl::shared_user_script_master() { |
550 return shared_->user_script_master(); | 572 return shared_->shared_user_script_master(); |
551 } | 573 } |
552 | 574 |
553 ProcessManager* ExtensionSystemImpl::process_manager() { | 575 ProcessManager* ExtensionSystemImpl::process_manager() { |
554 return process_manager_.get(); | 576 return process_manager_.get(); |
555 } | 577 } |
556 | 578 |
557 StateStore* ExtensionSystemImpl::state_store() { | 579 StateStore* ExtensionSystemImpl::state_store() { |
558 return shared_->state_store(); | 580 return shared_->state_store(); |
559 } | 581 } |
560 | 582 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
599 ContentVerifier* ExtensionSystemImpl::content_verifier() { | 621 ContentVerifier* ExtensionSystemImpl::content_verifier() { |
600 return shared_->content_verifier(); | 622 return shared_->content_verifier(); |
601 } | 623 } |
602 | 624 |
603 scoped_ptr<ExtensionSet> ExtensionSystemImpl::GetDependentExtensions( | 625 scoped_ptr<ExtensionSet> ExtensionSystemImpl::GetDependentExtensions( |
604 const Extension* extension) { | 626 const Extension* extension) { |
605 return extension_service()->shared_module_service()->GetDependentExtensions( | 627 return extension_service()->shared_module_service()->GetDependentExtensions( |
606 extension); | 628 extension); |
607 } | 629 } |
608 | 630 |
631 DeclarativeUserScriptMaster* | |
632 ExtensionSystemImpl::GetDeclarativeUserScriptMasterByExtension( | |
633 const ExtensionId& extension_id) { | |
634 return shared_->GetDeclarativeUserScriptMasterByExtension(extension_id); | |
635 } | |
636 | |
609 void ExtensionSystemImpl::RegisterExtensionWithRequestContexts( | 637 void ExtensionSystemImpl::RegisterExtensionWithRequestContexts( |
610 const Extension* extension) { | 638 const Extension* extension) { |
611 base::Time install_time; | 639 base::Time install_time; |
612 if (extension->location() != Manifest::COMPONENT) { | 640 if (extension->location() != Manifest::COMPONENT) { |
613 install_time = ExtensionPrefs::Get(profile_)-> | 641 install_time = ExtensionPrefs::Get(profile_)-> |
614 GetInstallTime(extension->id()); | 642 GetInstallTime(extension->id()); |
615 } | 643 } |
616 bool incognito_enabled = util::IsIncognitoEnabled(extension->id(), profile_); | 644 bool incognito_enabled = util::IsIncognitoEnabled(extension->id(), profile_); |
617 | 645 |
618 bool notifications_disabled = false; | 646 bool notifications_disabled = false; |
(...skipping 18 matching lines...) Expand all Loading... | |
637 void ExtensionSystemImpl::UnregisterExtensionWithRequestContexts( | 665 void ExtensionSystemImpl::UnregisterExtensionWithRequestContexts( |
638 const std::string& extension_id, | 666 const std::string& extension_id, |
639 const UnloadedExtensionInfo::Reason reason) { | 667 const UnloadedExtensionInfo::Reason reason) { |
640 BrowserThread::PostTask( | 668 BrowserThread::PostTask( |
641 BrowserThread::IO, | 669 BrowserThread::IO, |
642 FROM_HERE, | 670 FROM_HERE, |
643 base::Bind(&InfoMap::RemoveExtension, info_map(), extension_id, reason)); | 671 base::Bind(&InfoMap::RemoveExtension, info_map(), extension_id, reason)); |
644 } | 672 } |
645 | 673 |
646 } // namespace extensions | 674 } // namespace extensions |
OLD | NEW |