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" | 35 #include "chrome/browser/extensions/user_script_master_manager.h" |
33 #include "chrome/browser/profiles/profile.h" | 36 #include "chrome/browser/profiles/profile.h" |
34 #include "chrome/browser/profiles/profile_manager.h" | 37 #include "chrome/browser/profiles/profile_manager.h" |
35 #include "chrome/common/chrome_switches.h" | 38 #include "chrome/common/chrome_switches.h" |
36 #include "chrome/common/chrome_version_info.h" | 39 #include "chrome/common/chrome_version_info.h" |
37 #include "chrome/common/extensions/extension_constants.h" | 40 #include "chrome/common/extensions/extension_constants.h" |
38 #include "chrome/common/extensions/extension_file_util.h" | 41 #include "chrome/common/extensions/extension_file_util.h" |
39 #include "chrome/common/extensions/features/feature_channel.h" | 42 #include "chrome/common/extensions/features/feature_channel.h" |
40 #include "chrome/common/extensions/manifest_url_handler.h" | 43 #include "chrome/common/extensions/manifest_url_handler.h" |
41 #include "content/public/browser/browser_thread.h" | 44 #include "content/public/browser/browser_thread.h" |
42 #include "content/public/browser/url_data_source.h" | 45 #include "content/public/browser/url_data_source.h" |
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
309 } // namespace | 312 } // namespace |
310 | 313 |
311 void ExtensionSystemImpl::Shared::Init(bool extensions_enabled) { | 314 void ExtensionSystemImpl::Shared::Init(bool extensions_enabled) { |
312 const CommandLine* command_line = CommandLine::ForCurrentProcess(); | 315 const CommandLine* command_line = CommandLine::ForCurrentProcess(); |
313 | 316 |
314 navigation_observer_.reset(new NavigationObserver(profile_)); | 317 navigation_observer_.reset(new NavigationObserver(profile_)); |
315 | 318 |
316 bool allow_noisy_errors = !command_line->HasSwitch(switches::kNoErrorDialogs); | 319 bool allow_noisy_errors = !command_line->HasSwitch(switches::kNoErrorDialogs); |
317 ExtensionErrorReporter::Init(allow_noisy_errors); | 320 ExtensionErrorReporter::Init(allow_noisy_errors); |
318 | 321 |
319 user_script_master_.reset(new UserScriptMaster(profile_)); | 322 user_script_master_manager_.reset(new UserScriptMasterManager(profile_)); |
Mark Dittmer
2014/08/05 20:33:18
user_script_master_manager_ instantiated here.
| |
320 | 323 |
321 // ExtensionService depends on RuntimeData. | 324 // ExtensionService depends on RuntimeData. |
322 runtime_data_.reset(new RuntimeData(ExtensionRegistry::Get(profile_))); | 325 runtime_data_.reset(new RuntimeData(ExtensionRegistry::Get(profile_))); |
323 | 326 |
324 bool autoupdate_enabled = !profile_->IsGuestSession(); | 327 bool autoupdate_enabled = !profile_->IsGuestSession(); |
325 #if defined(OS_CHROMEOS) | 328 #if defined(OS_CHROMEOS) |
326 if (!extensions_enabled) | 329 if (!extensions_enabled) |
327 autoupdate_enabled = false; | 330 autoupdate_enabled = false; |
328 #endif | 331 #endif |
329 extension_service_.reset(new ExtensionService( | 332 extension_service_.reset(new ExtensionService( |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
449 } | 452 } |
450 | 453 |
451 RuntimeData* ExtensionSystemImpl::Shared::runtime_data() { | 454 RuntimeData* ExtensionSystemImpl::Shared::runtime_data() { |
452 return runtime_data_.get(); | 455 return runtime_data_.get(); |
453 } | 456 } |
454 | 457 |
455 ManagementPolicy* ExtensionSystemImpl::Shared::management_policy() { | 458 ManagementPolicy* ExtensionSystemImpl::Shared::management_policy() { |
456 return management_policy_.get(); | 459 return management_policy_.get(); |
457 } | 460 } |
458 | 461 |
459 UserScriptMaster* ExtensionSystemImpl::Shared::user_script_master() { | 462 SharedUserScriptMaster* |
460 return user_script_master_.get(); | 463 ExtensionSystemImpl::Shared::shared_user_script_master() { |
464 return user_script_master_manager_.get() | |
465 ? user_script_master_manager_->shared_master() | |
466 : NULL; | |
461 } | 467 } |
462 | 468 |
463 InfoMap* ExtensionSystemImpl::Shared::info_map() { | 469 InfoMap* ExtensionSystemImpl::Shared::info_map() { |
464 if (!extension_info_map_.get()) | 470 if (!extension_info_map_.get()) |
465 extension_info_map_ = new InfoMap(); | 471 extension_info_map_ = new InfoMap(); |
466 return extension_info_map_.get(); | 472 return extension_info_map_.get(); |
467 } | 473 } |
468 | 474 |
469 LazyBackgroundTaskQueue* | 475 LazyBackgroundTaskQueue* |
470 ExtensionSystemImpl::Shared::lazy_background_task_queue() { | 476 ExtensionSystemImpl::Shared::lazy_background_task_queue() { |
(...skipping 21 matching lines...) Expand all Loading... | |
492 } | 498 } |
493 | 499 |
494 QuotaService* ExtensionSystemImpl::Shared::quota_service() { | 500 QuotaService* ExtensionSystemImpl::Shared::quota_service() { |
495 return quota_service_.get(); | 501 return quota_service_.get(); |
496 } | 502 } |
497 | 503 |
498 ContentVerifier* ExtensionSystemImpl::Shared::content_verifier() { | 504 ContentVerifier* ExtensionSystemImpl::Shared::content_verifier() { |
499 return content_verifier_.get(); | 505 return content_verifier_.get(); |
500 } | 506 } |
501 | 507 |
508 DeclarativeUserScriptMaster* | |
509 ExtensionSystemImpl::Shared::GetDeclarativeUserScriptMasterByExtension( | |
510 const ExtensionId& extension_id) { | |
511 return user_script_master_manager_.get() | |
Devlin
2014/08/04 18:33:24
I might be missing it... but when are these create
Mark Dittmer
2014/08/05 20:33:18
See comment on line 322.
| |
512 ? user_script_master_manager_->GetDeclarativeMasterByExtension( | |
513 extension_id) | |
514 : NULL; | |
515 } | |
516 | |
502 // | 517 // |
503 // ExtensionSystemImpl | 518 // ExtensionSystemImpl |
504 // | 519 // |
505 | 520 |
506 ExtensionSystemImpl::ExtensionSystemImpl(Profile* profile) | 521 ExtensionSystemImpl::ExtensionSystemImpl(Profile* profile) |
507 : profile_(profile) { | 522 : profile_(profile) { |
508 shared_ = ExtensionSystemSharedFactory::GetForBrowserContext(profile); | 523 shared_ = ExtensionSystemSharedFactory::GetForBrowserContext(profile); |
509 | 524 |
510 if (profile->IsOffTheRecord()) { | 525 if (profile->IsOffTheRecord()) { |
511 process_manager_.reset(ProcessManager::Create(profile)); | 526 process_manager_.reset(ProcessManager::Create(profile)); |
512 } else { | 527 } else { |
513 shared_->InitPrefs(); | 528 shared_->InitPrefs(); |
514 } | 529 } |
515 } | 530 } |
516 | 531 |
517 ExtensionSystemImpl::~ExtensionSystemImpl() { | 532 ExtensionSystemImpl::~ExtensionSystemImpl() { |
518 } | 533 } |
519 | 534 |
520 void ExtensionSystemImpl::Shutdown() { | 535 void ExtensionSystemImpl::Shutdown() { |
521 process_manager_.reset(); | 536 process_manager_.reset(); |
522 } | 537 } |
523 | 538 |
524 void ExtensionSystemImpl::InitForRegularProfile(bool extensions_enabled) { | 539 void ExtensionSystemImpl::InitForRegularProfile(bool extensions_enabled) { |
525 DCHECK(!profile_->IsOffTheRecord()); | 540 DCHECK(!profile_->IsOffTheRecord()); |
526 if (user_script_master() || extension_service()) | 541 if (shared_user_script_master() || extension_service()) |
527 return; // Already initialized. | 542 return; // Already initialized. |
528 | 543 |
529 // The InfoMap needs to be created before the ProcessManager. | 544 // The InfoMap needs to be created before the ProcessManager. |
530 shared_->info_map(); | 545 shared_->info_map(); |
531 | 546 |
532 process_manager_.reset(ProcessManager::Create(profile_)); | 547 process_manager_.reset(ProcessManager::Create(profile_)); |
533 | 548 |
534 shared_->Init(extensions_enabled); | 549 shared_->Init(extensions_enabled); |
535 } | 550 } |
536 | 551 |
537 ExtensionService* ExtensionSystemImpl::extension_service() { | 552 ExtensionService* ExtensionSystemImpl::extension_service() { |
538 return shared_->extension_service(); | 553 return shared_->extension_service(); |
539 } | 554 } |
540 | 555 |
541 RuntimeData* ExtensionSystemImpl::runtime_data() { | 556 RuntimeData* ExtensionSystemImpl::runtime_data() { |
542 return shared_->runtime_data(); | 557 return shared_->runtime_data(); |
543 } | 558 } |
544 | 559 |
545 ManagementPolicy* ExtensionSystemImpl::management_policy() { | 560 ManagementPolicy* ExtensionSystemImpl::management_policy() { |
546 return shared_->management_policy(); | 561 return shared_->management_policy(); |
547 } | 562 } |
548 | 563 |
549 UserScriptMaster* ExtensionSystemImpl::user_script_master() { | 564 SharedUserScriptMaster* ExtensionSystemImpl::shared_user_script_master() { |
550 return shared_->user_script_master(); | 565 return shared_->shared_user_script_master(); |
551 } | 566 } |
552 | 567 |
553 ProcessManager* ExtensionSystemImpl::process_manager() { | 568 ProcessManager* ExtensionSystemImpl::process_manager() { |
554 return process_manager_.get(); | 569 return process_manager_.get(); |
555 } | 570 } |
556 | 571 |
557 StateStore* ExtensionSystemImpl::state_store() { | 572 StateStore* ExtensionSystemImpl::state_store() { |
558 return shared_->state_store(); | 573 return shared_->state_store(); |
559 } | 574 } |
560 | 575 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
599 ContentVerifier* ExtensionSystemImpl::content_verifier() { | 614 ContentVerifier* ExtensionSystemImpl::content_verifier() { |
600 return shared_->content_verifier(); | 615 return shared_->content_verifier(); |
601 } | 616 } |
602 | 617 |
603 scoped_ptr<ExtensionSet> ExtensionSystemImpl::GetDependentExtensions( | 618 scoped_ptr<ExtensionSet> ExtensionSystemImpl::GetDependentExtensions( |
604 const Extension* extension) { | 619 const Extension* extension) { |
605 return extension_service()->shared_module_service()->GetDependentExtensions( | 620 return extension_service()->shared_module_service()->GetDependentExtensions( |
606 extension); | 621 extension); |
607 } | 622 } |
608 | 623 |
624 DeclarativeUserScriptMaster* | |
625 ExtensionSystemImpl::GetDeclarativeUserScriptMasterByExtension( | |
626 const ExtensionId& extension_id) { | |
627 return shared_->GetDeclarativeUserScriptMasterByExtension(extension_id); | |
628 } | |
629 | |
609 void ExtensionSystemImpl::RegisterExtensionWithRequestContexts( | 630 void ExtensionSystemImpl::RegisterExtensionWithRequestContexts( |
610 const Extension* extension) { | 631 const Extension* extension) { |
611 base::Time install_time; | 632 base::Time install_time; |
612 if (extension->location() != Manifest::COMPONENT) { | 633 if (extension->location() != Manifest::COMPONENT) { |
613 install_time = ExtensionPrefs::Get(profile_)-> | 634 install_time = ExtensionPrefs::Get(profile_)-> |
614 GetInstallTime(extension->id()); | 635 GetInstallTime(extension->id()); |
615 } | 636 } |
616 bool incognito_enabled = util::IsIncognitoEnabled(extension->id(), profile_); | 637 bool incognito_enabled = util::IsIncognitoEnabled(extension->id(), profile_); |
617 | 638 |
618 bool notifications_disabled = false; | 639 bool notifications_disabled = false; |
(...skipping 18 matching lines...) Expand all Loading... | |
637 void ExtensionSystemImpl::UnregisterExtensionWithRequestContexts( | 658 void ExtensionSystemImpl::UnregisterExtensionWithRequestContexts( |
638 const std::string& extension_id, | 659 const std::string& extension_id, |
639 const UnloadedExtensionInfo::Reason reason) { | 660 const UnloadedExtensionInfo::Reason reason) { |
640 BrowserThread::PostTask( | 661 BrowserThread::PostTask( |
641 BrowserThread::IO, | 662 BrowserThread::IO, |
642 FROM_HERE, | 663 FROM_HERE, |
643 base::Bind(&InfoMap::RemoveExtension, info_map(), extension_id, reason)); | 664 base::Bind(&InfoMap::RemoveExtension, info_map(), extension_id, reason)); |
644 } | 665 } |
645 | 666 |
646 } // namespace extensions | 667 } // namespace extensions |
OLD | NEW |