[email protected] | 59b0e60 | 2014-01-30 00:41:24 | [diff] [blame] | 1 | // Copyright 2014 The Chromium Authors. All rights reserved. |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | 59b0e60 | 2014-01-30 00:41:24 | [diff] [blame] | 5 | #include "chrome/browser/extensions/extension_system_impl.h" |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 6 | |
asargent | 8380bd39 | 2016-03-21 23:47:33 | [diff] [blame] | 7 | #include <algorithm> |
| 8 | |
[email protected] | 53603d2 | 2012-11-14 08:31:11 | [diff] [blame] | 9 | #include "base/base_switches.h" |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 10 | #include "base/bind.h" |
| 11 | #include "base/command_line.h" |
[email protected] | 5799981 | 2013-02-24 05:40:52 | [diff] [blame] | 12 | #include "base/files/file_path.h" |
asargent | 631a99a | 2015-10-15 21:51:48 | [diff] [blame] | 13 | #include "base/files/file_util.h" |
[email protected] | f83bd43 | 2014-05-10 20:44:40 | [diff] [blame] | 14 | #include "base/memory/weak_ptr.h" |
[email protected] | f4ebe77 | 2013-02-02 00:21:39 | [diff] [blame] | 15 | #include "base/strings/string_tokenizer.h" |
rkaplow | e65c2ff | 2015-02-14 16:29:54 | [diff] [blame] | 16 | #include "base/trace_event/trace_event.h" |
avi | a2f4804a | 2015-12-24 23:11:13 | [diff] [blame] | 17 | #include "build/build_config.h" |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 18 | #include "chrome/browser/browser_process.h" |
treib | 926ee2d | 2015-08-06 10:55:42 | [diff] [blame] | 19 | #include "chrome/browser/extensions/chrome_app_sorting.h" |
juncai | e950b9e55 | 2015-06-11 20:25:31 | [diff] [blame] | 20 | #include "chrome/browser/extensions/chrome_content_verifier_delegate.h" |
[email protected] | 931186e0 | 2012-07-20 01:22:06 | [diff] [blame] | 21 | #include "chrome/browser/extensions/component_loader.h" |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 22 | #include "chrome/browser/extensions/extension_error_reporter.h" |
xiyuan | f6a4c6a6 | 2016-04-19 18:14:54 | [diff] [blame] | 23 | #include "chrome/browser/extensions/extension_garbage_collector.h" |
binjin | 1569c9b | 2014-09-05 13:33:18 | [diff] [blame] | 24 | #include "chrome/browser/extensions/extension_management.h" |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 25 | #include "chrome/browser/extensions/extension_service.h" |
treib | 8a6d989 | 2015-08-26 10:23:19 | [diff] [blame] | 26 | #include "chrome/browser/extensions/extension_sync_service.h" |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 27 | #include "chrome/browser/extensions/extension_system_factory.h" |
[email protected] | a7ff4b7 | 2013-10-17 20:56:02 | [diff] [blame] | 28 | #include "chrome/browser/extensions/extension_util.h" |
[email protected] | ffd2f79e | 2013-11-14 00:11:46 | [diff] [blame] | 29 | #include "chrome/browser/extensions/install_verifier.h" |
[email protected] | d9ede58 | 2012-08-14 19:21:38 | [diff] [blame] | 30 | #include "chrome/browser/extensions/navigation_observer.h" |
[email protected] | f698c16 | 2014-06-13 00:46:26 | [diff] [blame] | 31 | #include "chrome/browser/extensions/shared_module_service.h" |
[email protected] | 15ad2ee | 2014-08-15 19:15:26 | [diff] [blame] | 32 | #include "chrome/browser/extensions/shared_user_script_master.h" |
[email protected] | 479e392 | 2014-07-30 07:12:57 | [diff] [blame] | 33 | #include "chrome/browser/extensions/state_store_notification_observer.h" |
[email protected] | 13e062e | 2014-08-09 10:21:55 | [diff] [blame] | 34 | #include "chrome/browser/extensions/unpacked_installer.h" |
xiyuan | f6a4c6a6 | 2016-04-19 18:14:54 | [diff] [blame] | 35 | #include "chrome/browser/extensions/update_install_gate.h" |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 36 | #include "chrome/browser/profiles/profile.h" |
| 37 | #include "chrome/browser/profiles/profile_manager.h" |
[email protected] | 13e062e | 2014-08-09 10:21:55 | [diff] [blame] | 38 | #include "chrome/browser/ui/webui/extensions/extension_icon_source.h" |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 39 | #include "chrome/common/chrome_switches.h" |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 40 | #include "content/public/browser/browser_thread.h" |
[email protected] | 24ea7a1 | 2013-01-27 23:54:53 | [diff] [blame] | 41 | #include "content/public/browser/url_data_source.h" |
[email protected] | fd3df778 | 2014-05-08 23:54:27 | [diff] [blame] | 42 | #include "extensions/browser/content_verifier.h" |
[email protected] | 489db084 | 2014-01-22 18:20:03 | [diff] [blame] | 43 | #include "extensions/browser/extension_pref_store.h" |
| 44 | #include "extensions/browser/extension_pref_value_map.h" |
| 45 | #include "extensions/browser/extension_pref_value_map_factory.h" |
| 46 | #include "extensions/browser/extension_prefs.h" |
[email protected] | 45f5b7d | 2014-01-22 23:47:13 | [diff] [blame] | 47 | #include "extensions/browser/extension_registry.h" |
[email protected] | 38427a1 | 2013-11-09 17:34:20 | [diff] [blame] | 48 | #include "extensions/browser/info_map.h" |
[email protected] | aab2310 | 2014-02-05 18:57:55 | [diff] [blame] | 49 | #include "extensions/browser/quota_service.h" |
[email protected] | 45f5b7d | 2014-01-22 23:47:13 | [diff] [blame] | 50 | #include "extensions/browser/runtime_data.h" |
rdevlin.cronin | f5863da | 2015-09-10 19:21:45 | [diff] [blame] | 51 | #include "extensions/browser/service_worker_manager.h" |
[email protected] | daf3ffda | 2014-06-25 06:44:57 | [diff] [blame] | 52 | #include "extensions/browser/state_store.h" |
asargent | 8380bd39 | 2016-03-21 23:47:33 | [diff] [blame] | 53 | #include "extensions/browser/uninstall_ping_sender.h" |
cmumford | 6ae8d46 | 2016-03-24 20:35:27 | [diff] [blame] | 54 | #include "extensions/browser/value_store/value_store_factory_impl.h" |
[email protected] | 836e298 | 2013-05-16 08:07:42 | [diff] [blame] | 55 | #include "extensions/common/constants.h" |
rdevlin.cronin | 4122753 | 2016-07-13 21:24:34 | [diff] [blame] | 56 | #include "extensions/common/features/feature_channel.h" |
asargent | 8380bd39 | 2016-03-21 23:47:33 | [diff] [blame] | 57 | #include "extensions/common/manifest_url_handlers.h" |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 58 | |
[email protected] | 9afacd2 | 2013-11-13 20:23:31 | [diff] [blame] | 59 | #if defined(ENABLE_NOTIFICATIONS) |
peter | c400791 | 2015-07-31 21:13:37 | [diff] [blame] | 60 | #include "chrome/browser/notifications/notifier_state_tracker.h" |
| 61 | #include "chrome/browser/notifications/notifier_state_tracker_factory.h" |
[email protected] | 9afacd2 | 2013-11-13 20:23:31 | [diff] [blame] | 62 | #include "ui/message_center/notifier_settings.h" |
| 63 | #endif |
| 64 | |
[email protected] | bb12148 | 2012-12-08 06:49:38 | [diff] [blame] | 65 | #if defined(OS_CHROMEOS) |
[email protected] | 6ed2e0c | 2013-04-09 04:48:13 | [diff] [blame] | 66 | #include "chrome/browser/app_mode/app_mode_utils.h" |
xiyuan | a0a6aaaa | 2016-04-19 23:34:16 | [diff] [blame] | 67 | #include "chrome/browser/chromeos/app_mode/kiosk_app_update_install_gate.h" |
[email protected] | 1a643611 | 2013-10-09 02:49:58 | [diff] [blame] | 68 | #include "chrome/browser/chromeos/extensions/device_local_account_management_policy_provider.h" |
[email protected] | 1a643611 | 2013-10-09 02:49:58 | [diff] [blame] | 69 | #include "chrome/browser/chromeos/policy/device_local_account.h" |
[email protected] | 931d104 | 2013-04-05 17:50:44 | [diff] [blame] | 70 | #include "chromeos/chromeos_switches.h" |
[email protected] | c57397a | 2013-04-18 19:41:11 | [diff] [blame] | 71 | #include "chromeos/login/login_state.h" |
[email protected] | 2fda997 | 2014-07-23 14:51:59 | [diff] [blame] | 72 | #include "components/user_manager/user.h" |
[email protected] | 4d39078 | 2014-08-15 09:22:58 | [diff] [blame] | 73 | #include "components/user_manager/user_manager.h" |
[email protected] | bb12148 | 2012-12-08 06:49:38 | [diff] [blame] | 74 | #endif |
| 75 | |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 76 | using content::BrowserThread; |
| 77 | |
[email protected] | bd30672 | 2012-07-11 20:43:59 | [diff] [blame] | 78 | namespace extensions { |
| 79 | |
asargent | 8380bd39 | 2016-03-21 23:47:33 | [diff] [blame] | 80 | namespace { |
| 81 | |
| 82 | // Helper to serve as an UninstallPingSender::Filter callback. |
| 83 | UninstallPingSender::FilterResult ShouldSendUninstallPing( |
| 84 | const Extension* extension, |
| 85 | UninstallReason reason) { |
| 86 | if (extension && (extension->from_webstore() || |
| 87 | ManifestURL::UpdatesFromGallery(extension))) { |
| 88 | return UninstallPingSender::SEND_PING; |
| 89 | } |
| 90 | return UninstallPingSender::DO_NOT_SEND_PING; |
| 91 | } |
| 92 | |
| 93 | } // namespace |
| 94 | |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 95 | // |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 96 | // ExtensionSystemImpl::Shared |
| 97 | // |
| 98 | |
| 99 | ExtensionSystemImpl::Shared::Shared(Profile* profile) |
| 100 | : profile_(profile) { |
| 101 | } |
| 102 | |
| 103 | ExtensionSystemImpl::Shared::~Shared() { |
| 104 | } |
| 105 | |
| 106 | void ExtensionSystemImpl::Shared::InitPrefs() { |
cmumford | 6ae8d46 | 2016-03-24 20:35:27 | [diff] [blame] | 107 | store_factory_ = new ValueStoreFactoryImpl(profile_->GetPath()); |
| 108 | |
[email protected] | a690e29 | 2012-12-19 19:22:49 | [diff] [blame] | 109 | // Two state stores. The latter, which contains declarative rules, must be |
| 110 | // loaded immediately so that the rules are ready before we issue network |
| 111 | // requests. |
[email protected] | bd30672 | 2012-07-11 20:43:59 | [diff] [blame] | 112 | state_store_.reset(new StateStore( |
cmumford | 6ae8d46 | 2016-03-24 20:35:27 | [diff] [blame] | 113 | profile_, store_factory_, ValueStoreFrontend::BackendType::STATE, true)); |
[email protected] | 479e392 | 2014-07-30 07:12:57 | [diff] [blame] | 114 | state_store_notification_observer_.reset( |
| 115 | new StateStoreNotificationObserver(state_store_.get())); |
[email protected] | d3bd607 | 2013-07-26 18:32:14 | [diff] [blame] | 116 | |
[email protected] | a690e29 | 2012-12-19 19:22:49 | [diff] [blame] | 117 | rules_store_.reset(new StateStore( |
cmumford | 6ae8d46 | 2016-03-24 20:35:27 | [diff] [blame] | 118 | profile_, store_factory_, ValueStoreFrontend::BackendType::RULES, false)); |
[email protected] | cb610dc | 2012-08-31 17:16:56 | [diff] [blame] | 119 | |
[email protected] | 13e062e | 2014-08-09 10:21:55 | [diff] [blame] | 120 | #if defined(OS_CHROMEOS) |
[email protected] | 2fda997 | 2014-07-23 14:51:59 | [diff] [blame] | 121 | const user_manager::User* user = |
[email protected] | 4d39078 | 2014-08-15 09:22:58 | [diff] [blame] | 122 | user_manager::UserManager::Get()->GetActiveUser(); |
[email protected] | 1a643611 | 2013-10-09 02:49:58 | [diff] [blame] | 123 | policy::DeviceLocalAccount::Type device_local_account_type; |
alemate | 909aa58a | 2016-11-03 22:49:07 | [diff] [blame^] | 124 | if (user && |
| 125 | policy::IsDeviceLocalAccountUser(user->GetAccountId().GetUserEmail(), |
| 126 | &device_local_account_type)) { |
[email protected] | 1a643611 | 2013-10-09 02:49:58 | [diff] [blame] | 127 | device_local_account_management_policy_provider_.reset( |
| 128 | new chromeos::DeviceLocalAccountManagementPolicyProvider( |
| 129 | device_local_account_type)); |
| 130 | } |
[email protected] | 13e062e | 2014-08-09 10:21:55 | [diff] [blame] | 131 | #endif // defined(OS_CHROMEOS) |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 132 | } |
| 133 | |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 134 | void ExtensionSystemImpl::Shared::RegisterManagementPolicyProviders() { |
binjin | e6b58b5 | 2014-10-31 01:55:57 | [diff] [blame] | 135 | management_policy_->RegisterProviders( |
binjin | 1569c9b | 2014-09-05 13:33:18 | [diff] [blame] | 136 | ExtensionManagementFactory::GetForBrowserContext(profile_) |
binjin | e6b58b5 | 2014-10-31 01:55:57 | [diff] [blame] | 137 | ->GetProviders()); |
[email protected] | 1a643611 | 2013-10-09 02:49:58 | [diff] [blame] | 138 | |
[email protected] | 13e062e | 2014-08-09 10:21:55 | [diff] [blame] | 139 | #if defined(OS_CHROMEOS) |
[email protected] | 1a643611 | 2013-10-09 02:49:58 | [diff] [blame] | 140 | if (device_local_account_management_policy_provider_) { |
| 141 | management_policy_->RegisterProvider( |
| 142 | device_local_account_management_policy_provider_.get()); |
| 143 | } |
[email protected] | 13e062e | 2014-08-09 10:21:55 | [diff] [blame] | 144 | #endif // defined(OS_CHROMEOS) |
[email protected] | 1a643611 | 2013-10-09 02:49:58 | [diff] [blame] | 145 | |
juncai | 33e46210 | 2015-05-18 20:48:44 | [diff] [blame] | 146 | management_policy_->RegisterProvider(InstallVerifier::Get(profile_)); |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 147 | } |
| 148 | |
xiyuan | f6a4c6a6 | 2016-04-19 18:14:54 | [diff] [blame] | 149 | void ExtensionSystemImpl::Shared::InitInstallGates() { |
| 150 | update_install_gate_.reset(new UpdateInstallGate(extension_service_.get())); |
| 151 | extension_service_->RegisterInstallGate( |
| 152 | ExtensionPrefs::DELAY_REASON_WAIT_FOR_IDLE, update_install_gate_.get()); |
| 153 | extension_service_->RegisterInstallGate( |
| 154 | ExtensionPrefs::DELAY_REASON_GC, |
| 155 | ExtensionGarbageCollector::Get(profile_)); |
| 156 | extension_service_->RegisterInstallGate( |
| 157 | ExtensionPrefs::DELAY_REASON_WAIT_FOR_IMPORTS, |
| 158 | extension_service_->shared_module_service()); |
xiyuan | a0a6aaaa | 2016-04-19 23:34:16 | [diff] [blame] | 159 | #if defined(OS_CHROMEOS) |
| 160 | if (chrome::IsRunningInForcedAppMode()) { |
| 161 | kiosk_app_update_install_gate_.reset( |
| 162 | new chromeos::KioskAppUpdateInstallGate(profile_)); |
| 163 | extension_service_->RegisterInstallGate( |
| 164 | ExtensionPrefs::DELAY_REASON_WAIT_FOR_OS_UPDATE, |
| 165 | kiosk_app_update_install_gate_.get()); |
| 166 | } |
| 167 | #endif |
xiyuan | f6a4c6a6 | 2016-04-19 18:14:54 | [diff] [blame] | 168 | } |
| 169 | |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 170 | void ExtensionSystemImpl::Shared::Init(bool extensions_enabled) { |
rkaplow | e65c2ff | 2015-02-14 16:29:54 | [diff] [blame] | 171 | TRACE_EVENT0("browser,startup", "ExtensionSystemImpl::Shared::Init"); |
avi | 3ef9ec9e | 2014-12-22 22:50:17 | [diff] [blame] | 172 | const base::CommandLine* command_line = |
| 173 | base::CommandLine::ForCurrentProcess(); |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 174 | |
[email protected] | d9ede58 | 2012-08-14 19:21:38 | [diff] [blame] | 175 | navigation_observer_.reset(new NavigationObserver(profile_)); |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 176 | |
[email protected] | 53603d2 | 2012-11-14 08:31:11 | [diff] [blame] | 177 | bool allow_noisy_errors = !command_line->HasSwitch(switches::kNoErrorDialogs); |
| 178 | ExtensionErrorReporter::Init(allow_noisy_errors); |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 179 | |
asargent | 678123d2 | 2015-07-31 23:24:10 | [diff] [blame] | 180 | content_verifier_ = new ContentVerifier( |
| 181 | profile_, new ChromeContentVerifierDelegate(profile_)); |
| 182 | |
rdevlin.cronin | f5863da | 2015-09-10 19:21:45 | [diff] [blame] | 183 | service_worker_manager_.reset(new ServiceWorkerManager(profile_)); |
| 184 | |
[email protected] | 15ad2ee | 2014-08-15 19:15:26 | [diff] [blame] | 185 | shared_user_script_master_.reset(new SharedUserScriptMaster(profile_)); |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 186 | |
[email protected] | 45f5b7d | 2014-01-22 23:47:13 | [diff] [blame] | 187 | // ExtensionService depends on RuntimeData. |
| 188 | runtime_data_.reset(new RuntimeData(ExtensionRegistry::Get(profile_))); |
| 189 | |
mlerman | 7831f57d | 2015-05-25 11:40:15 | [diff] [blame] | 190 | bool autoupdate_enabled = !profile_->IsGuestSession() && |
| 191 | !profile_->IsSystemProfile(); |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 192 | #if defined(OS_CHROMEOS) |
| 193 | if (!extensions_enabled) |
| 194 | autoupdate_enabled = false; |
rkaplow | dd66a134 | 2015-03-05 00:31:49 | [diff] [blame] | 195 | #endif // defined(OS_CHROMEOS) |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 196 | extension_service_.reset(new ExtensionService( |
avi | 3ef9ec9e | 2014-12-22 22:50:17 | [diff] [blame] | 197 | profile_, base::CommandLine::ForCurrentProcess(), |
[email protected] | 836e298 | 2013-05-16 08:07:42 | [diff] [blame] | 198 | profile_->GetPath().AppendASCII(extensions::kInstallDirectoryName), |
avi | 3ef9ec9e | 2014-12-22 22:50:17 | [diff] [blame] | 199 | ExtensionPrefs::Get(profile_), Blacklist::Get(profile_), |
| 200 | autoupdate_enabled, extensions_enabled, &ready_)); |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 201 | |
asargent | 8380bd39 | 2016-03-21 23:47:33 | [diff] [blame] | 202 | uninstall_ping_sender_.reset(new UninstallPingSender( |
| 203 | ExtensionRegistry::Get(profile_), base::Bind(&ShouldSendUninstallPing))); |
| 204 | |
[email protected] | d7fbc09 | 2012-06-18 22:52:00 | [diff] [blame] | 205 | // These services must be registered before the ExtensionService tries to |
| 206 | // load any extensions. |
| 207 | { |
juncai | 33e46210 | 2015-05-18 20:48:44 | [diff] [blame] | 208 | InstallVerifier::Get(profile_)->Init(); |
[email protected] | 8bb6216 | 2014-06-23 09:45:50 | [diff] [blame] | 209 | ContentVerifierDelegate::Mode mode = |
juncai | e950b9e55 | 2015-06-11 20:25:31 | [diff] [blame] | 210 | ChromeContentVerifierDelegate::GetDefaultMode(); |
[email protected] | 8bb6216 | 2014-06-23 09:45:50 | [diff] [blame] | 211 | #if defined(OS_CHROMEOS) |
| 212 | mode = std::max(mode, ContentVerifierDelegate::BOOTSTRAP); |
rkaplow | dd66a134 | 2015-03-05 00:31:49 | [diff] [blame] | 213 | #endif // defined(OS_CHROMEOS) |
[email protected] | 6a5898e | 2014-07-22 23:33:54 | [diff] [blame] | 214 | if (mode >= ContentVerifierDelegate::BOOTSTRAP) |
[email protected] | 8bb6216 | 2014-06-23 09:45:50 | [diff] [blame] | 215 | content_verifier_->Start(); |
[email protected] | fd3df778 | 2014-05-08 23:54:27 | [diff] [blame] | 216 | info_map()->SetContentVerifier(content_verifier_.get()); |
[email protected] | ffd2f79e | 2013-11-14 00:11:46 | [diff] [blame] | 217 | |
[email protected] | bd30672 | 2012-07-11 20:43:59 | [diff] [blame] | 218 | management_policy_.reset(new ManagementPolicy); |
[email protected] | d7fbc09 | 2012-06-18 22:52:00 | [diff] [blame] | 219 | RegisterManagementPolicyProviders(); |
| 220 | } |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 221 | |
[email protected] | bb12148 | 2012-12-08 06:49:38 | [diff] [blame] | 222 | bool skip_session_extensions = false; |
| 223 | #if defined(OS_CHROMEOS) |
| 224 | // Skip loading session extensions if we are not in a user session. |
[email protected] | c57397a | 2013-04-18 19:41:11 | [diff] [blame] | 225 | skip_session_extensions = !chromeos::LoginState::Get()->IsUserLoggedIn(); |
[email protected] | 531593d | 2014-01-08 18:48:31 | [diff] [blame] | 226 | if (chrome::IsRunningInForcedAppMode()) { |
| 227 | extension_service_->component_loader()-> |
| 228 | AddDefaultComponentExtensionsForKioskMode(skip_session_extensions); |
| 229 | } else { |
[email protected] | 6ed2e0c | 2013-04-09 04:48:13 | [diff] [blame] | 230 | extension_service_->component_loader()->AddDefaultComponentExtensions( |
| 231 | skip_session_extensions); |
| 232 | } |
| 233 | #else |
[email protected] | bb12148 | 2012-12-08 06:49:38 | [diff] [blame] | 234 | extension_service_->component_loader()->AddDefaultComponentExtensions( |
| 235 | skip_session_extensions); |
[email protected] | 6ed2e0c | 2013-04-09 04:48:13 | [diff] [blame] | 236 | #endif |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 237 | if (command_line->HasSwitch(switches::kLoadComponentExtension)) { |
avi | 3ef9ec9e | 2014-12-22 22:50:17 | [diff] [blame] | 238 | base::CommandLine::StringType path_list = |
| 239 | command_line->GetSwitchValueNative(switches::kLoadComponentExtension); |
| 240 | base::StringTokenizerT<base::CommandLine::StringType, |
| 241 | base::CommandLine::StringType::const_iterator> |
| 242 | t(path_list, FILE_PATH_LITERAL(",")); |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 243 | while (t.GetNext()) { |
| 244 | // Load the component extension manifest synchronously. |
| 245 | // Blocking the UI thread is acceptable here since |
| 246 | // this flag designated for developers. |
| 247 | base::ThreadRestrictions::ScopedAllowIO allow_io; |
| 248 | extension_service_->component_loader()->AddOrReplace( |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 249 | base::FilePath(t.token())); |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 250 | } |
| 251 | } |
treib | 926ee2d | 2015-08-06 10:55:42 | [diff] [blame] | 252 | |
| 253 | app_sorting_.reset(new ChromeAppSorting(profile_)); |
| 254 | |
xiyuan | f6a4c6a6 | 2016-04-19 18:14:54 | [diff] [blame] | 255 | InitInstallGates(); |
| 256 | |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 257 | extension_service_->Init(); |
| 258 | |
treib | 8a6d989 | 2015-08-26 10:23:19 | [diff] [blame] | 259 | // Make sure ExtensionSyncService is created. |
| 260 | ExtensionSyncService::Get(profile_); |
| 261 | |
[email protected] | c1909afb | 2013-11-13 21:12:51 | [diff] [blame] | 262 | // Make the chrome://extension-icon/ resource available. |
| 263 | content::URLDataSource::Add(profile_, new ExtensionIconSource(profile_)); |
| 264 | |
[email protected] | aab2310 | 2014-02-05 18:57:55 | [diff] [blame] | 265 | quota_service_.reset(new QuotaService); |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 266 | } |
| 267 | |
[email protected] | 47b89656 | 2012-08-22 23:55:15 | [diff] [blame] | 268 | void ExtensionSystemImpl::Shared::Shutdown() { |
dcheng | c704794 | 2014-08-26 05:05:31 | [diff] [blame] | 269 | if (content_verifier_.get()) |
[email protected] | fd3df778 | 2014-05-08 23:54:27 | [diff] [blame] | 270 | content_verifier_->Shutdown(); |
[email protected] | 3eeddd89 | 2013-04-17 17:00:11 | [diff] [blame] | 271 | if (extension_service_) |
[email protected] | 47b89656 | 2012-08-22 23:55:15 | [diff] [blame] | 272 | extension_service_->Shutdown(); |
| 273 | } |
| 274 | |
rdevlin.cronin | f5863da | 2015-09-10 19:21:45 | [diff] [blame] | 275 | ServiceWorkerManager* ExtensionSystemImpl::Shared::service_worker_manager() { |
| 276 | return service_worker_manager_.get(); |
| 277 | } |
| 278 | |
[email protected] | bd30672 | 2012-07-11 20:43:59 | [diff] [blame] | 279 | StateStore* ExtensionSystemImpl::Shared::state_store() { |
[email protected] | 90e800c | 2012-06-12 23:11:00 | [diff] [blame] | 280 | return state_store_.get(); |
| 281 | } |
| 282 | |
[email protected] | a690e29 | 2012-12-19 19:22:49 | [diff] [blame] | 283 | StateStore* ExtensionSystemImpl::Shared::rules_store() { |
| 284 | return rules_store_.get(); |
| 285 | } |
| 286 | |
cmumford | 6ae8d46 | 2016-03-24 20:35:27 | [diff] [blame] | 287 | scoped_refptr<ValueStoreFactory> ExtensionSystemImpl::Shared::store_factory() |
| 288 | const { |
| 289 | return store_factory_; |
| 290 | } |
| 291 | |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 292 | ExtensionService* ExtensionSystemImpl::Shared::extension_service() { |
| 293 | return extension_service_.get(); |
| 294 | } |
| 295 | |
[email protected] | 45f5b7d | 2014-01-22 23:47:13 | [diff] [blame] | 296 | RuntimeData* ExtensionSystemImpl::Shared::runtime_data() { |
| 297 | return runtime_data_.get(); |
| 298 | } |
| 299 | |
[email protected] | bd30672 | 2012-07-11 20:43:59 | [diff] [blame] | 300 | ManagementPolicy* ExtensionSystemImpl::Shared::management_policy() { |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 301 | return management_policy_.get(); |
| 302 | } |
| 303 | |
[email protected] | 15ad2ee | 2014-08-15 19:15:26 | [diff] [blame] | 304 | SharedUserScriptMaster* |
| 305 | ExtensionSystemImpl::Shared::shared_user_script_master() { |
| 306 | return shared_user_script_master_.get(); |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 307 | } |
| 308 | |
[email protected] | 38427a1 | 2013-11-09 17:34:20 | [diff] [blame] | 309 | InfoMap* ExtensionSystemImpl::Shared::info_map() { |
[email protected] | dc24976f | 2013-06-02 21:15:09 | [diff] [blame] | 310 | if (!extension_info_map_.get()) |
[email protected] | 38427a1 | 2013-11-09 17:34:20 | [diff] [blame] | 311 | extension_info_map_ = new InfoMap(); |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 312 | return extension_info_map_.get(); |
| 313 | } |
| 314 | |
[email protected] | aab2310 | 2014-02-05 18:57:55 | [diff] [blame] | 315 | QuotaService* ExtensionSystemImpl::Shared::quota_service() { |
| 316 | return quota_service_.get(); |
| 317 | } |
| 318 | |
treib | 926ee2d | 2015-08-06 10:55:42 | [diff] [blame] | 319 | AppSorting* ExtensionSystemImpl::Shared::app_sorting() { |
| 320 | return app_sorting_.get(); |
| 321 | } |
| 322 | |
[email protected] | fd3df778 | 2014-05-08 23:54:27 | [diff] [blame] | 323 | ContentVerifier* ExtensionSystemImpl::Shared::content_verifier() { |
| 324 | return content_verifier_.get(); |
| 325 | } |
| 326 | |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 327 | // |
| 328 | // ExtensionSystemImpl |
| 329 | // |
| 330 | |
| 331 | ExtensionSystemImpl::ExtensionSystemImpl(Profile* profile) |
[email protected] | 98b67303 | 2012-12-11 10:26:02 | [diff] [blame] | 332 | : profile_(profile) { |
[email protected] | 59b0e60 | 2014-01-30 00:41:24 | [diff] [blame] | 333 | shared_ = ExtensionSystemSharedFactory::GetForBrowserContext(profile); |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 334 | |
reillyg | 0ea3fa90 | 2014-10-28 15:30:23 | [diff] [blame] | 335 | if (!profile->IsOffTheRecord()) { |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 336 | shared_->InitPrefs(); |
| 337 | } |
| 338 | } |
| 339 | |
| 340 | ExtensionSystemImpl::~ExtensionSystemImpl() { |
| 341 | } |
| 342 | |
| 343 | void ExtensionSystemImpl::Shutdown() { |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 344 | } |
| 345 | |
[email protected] | 7cf1ee4 | 2013-12-11 09:13:49 | [diff] [blame] | 346 | void ExtensionSystemImpl::InitForRegularProfile(bool extensions_enabled) { |
rkaplow | e65c2ff | 2015-02-14 16:29:54 | [diff] [blame] | 347 | TRACE_EVENT0("browser,startup", "ExtensionSystemImpl::InitForRegularProfile"); |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 348 | DCHECK(!profile_->IsOffTheRecord()); |
[email protected] | 15ad2ee | 2014-08-15 19:15:26 | [diff] [blame] | 349 | if (shared_user_script_master() || extension_service()) |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 350 | return; // Already initialized. |
| 351 | |
[email protected] | 98b6d94 | 2013-11-10 00:34:07 | [diff] [blame] | 352 | // The InfoMap needs to be created before the ProcessManager. |
[email protected] | 9656bc5 | 2012-08-13 17:05:33 | [diff] [blame] | 353 | shared_->info_map(); |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 354 | shared_->Init(extensions_enabled); |
| 355 | } |
| 356 | |
| 357 | ExtensionService* ExtensionSystemImpl::extension_service() { |
| 358 | return shared_->extension_service(); |
| 359 | } |
| 360 | |
[email protected] | 45f5b7d | 2014-01-22 23:47:13 | [diff] [blame] | 361 | RuntimeData* ExtensionSystemImpl::runtime_data() { |
| 362 | return shared_->runtime_data(); |
| 363 | } |
| 364 | |
[email protected] | bd30672 | 2012-07-11 20:43:59 | [diff] [blame] | 365 | ManagementPolicy* ExtensionSystemImpl::management_policy() { |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 366 | return shared_->management_policy(); |
| 367 | } |
| 368 | |
rdevlin.cronin | f5863da | 2015-09-10 19:21:45 | [diff] [blame] | 369 | ServiceWorkerManager* ExtensionSystemImpl::service_worker_manager() { |
| 370 | return shared_->service_worker_manager(); |
| 371 | } |
| 372 | |
[email protected] | 15ad2ee | 2014-08-15 19:15:26 | [diff] [blame] | 373 | SharedUserScriptMaster* ExtensionSystemImpl::shared_user_script_master() { |
| 374 | return shared_->shared_user_script_master(); |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 375 | } |
| 376 | |
[email protected] | bd30672 | 2012-07-11 20:43:59 | [diff] [blame] | 377 | StateStore* ExtensionSystemImpl::state_store() { |
[email protected] | 90e800c | 2012-06-12 23:11:00 | [diff] [blame] | 378 | return shared_->state_store(); |
| 379 | } |
| 380 | |
[email protected] | a690e29 | 2012-12-19 19:22:49 | [diff] [blame] | 381 | StateStore* ExtensionSystemImpl::rules_store() { |
| 382 | return shared_->rules_store(); |
| 383 | } |
| 384 | |
cmumford | 6ae8d46 | 2016-03-24 20:35:27 | [diff] [blame] | 385 | scoped_refptr<ValueStoreFactory> ExtensionSystemImpl::store_factory() { |
| 386 | return shared_->store_factory(); |
| 387 | } |
| 388 | |
[email protected] | 38427a1 | 2013-11-09 17:34:20 | [diff] [blame] | 389 | InfoMap* ExtensionSystemImpl::info_map() { return shared_->info_map(); } |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 390 | |
[email protected] | 4a10006a | 2013-05-17 23:18:35 | [diff] [blame] | 391 | const OneShotEvent& ExtensionSystemImpl::ready() const { |
| 392 | return shared_->ready(); |
| 393 | } |
| 394 | |
[email protected] | aab2310 | 2014-02-05 18:57:55 | [diff] [blame] | 395 | QuotaService* ExtensionSystemImpl::quota_service() { |
| 396 | return shared_->quota_service(); |
| 397 | } |
| 398 | |
treib | 926ee2d | 2015-08-06 10:55:42 | [diff] [blame] | 399 | AppSorting* ExtensionSystemImpl::app_sorting() { |
| 400 | return shared_->app_sorting(); |
| 401 | } |
| 402 | |
[email protected] | fd3df778 | 2014-05-08 23:54:27 | [diff] [blame] | 403 | ContentVerifier* ExtensionSystemImpl::content_verifier() { |
| 404 | return shared_->content_verifier(); |
| 405 | } |
| 406 | |
dcheng | c963c714 | 2016-04-08 03:55:22 | [diff] [blame] | 407 | std::unique_ptr<ExtensionSet> ExtensionSystemImpl::GetDependentExtensions( |
[email protected] | f698c16 | 2014-06-13 00:46:26 | [diff] [blame] | 408 | const Extension* extension) { |
| 409 | return extension_service()->shared_module_service()->GetDependentExtensions( |
| 410 | extension); |
| 411 | } |
| 412 | |
asargent | 631a99a | 2015-10-15 21:51:48 | [diff] [blame] | 413 | void ExtensionSystemImpl::InstallUpdate(const std::string& extension_id, |
| 414 | const base::FilePath& temp_dir) { |
| 415 | NOTREACHED() << "Not yet implemented"; |
| 416 | base::DeleteFile(temp_dir, true /* recursive */); |
| 417 | } |
| 418 | |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 419 | void ExtensionSystemImpl::RegisterExtensionWithRequestContexts( |
rockot | 494f007 | 2015-07-29 17:58:07 | [diff] [blame] | 420 | const Extension* extension, |
| 421 | const base::Closure& callback) { |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 422 | base::Time install_time; |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 423 | if (extension->location() != Manifest::COMPONENT) { |
[email protected] | 836e298 | 2013-05-16 08:07:42 | [diff] [blame] | 424 | install_time = ExtensionPrefs::Get(profile_)-> |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 425 | GetInstallTime(extension->id()); |
| 426 | } |
[email protected] | 1d5cf414 | 2014-01-24 18:25:22 | [diff] [blame] | 427 | bool incognito_enabled = util::IsIncognitoEnabled(extension->id(), profile_); |
[email protected] | 9afacd2 | 2013-11-13 20:23:31 | [diff] [blame] | 428 | |
| 429 | bool notifications_disabled = false; |
| 430 | #if defined(ENABLE_NOTIFICATIONS) |
| 431 | message_center::NotifierId notifier_id( |
| 432 | message_center::NotifierId::APPLICATION, |
| 433 | extension->id()); |
| 434 | |
peter | c400791 | 2015-07-31 21:13:37 | [diff] [blame] | 435 | NotifierStateTracker* notifier_state_tracker = |
| 436 | NotifierStateTrackerFactory::GetForProfile(profile_); |
[email protected] | 9afacd2 | 2013-11-13 20:23:31 | [diff] [blame] | 437 | notifications_disabled = |
peter | c400791 | 2015-07-31 21:13:37 | [diff] [blame] | 438 | !notifier_state_tracker->IsNotifierEnabled(notifier_id); |
[email protected] | 9afacd2 | 2013-11-13 20:23:31 | [diff] [blame] | 439 | #endif |
| 440 | |
rockot | 494f007 | 2015-07-29 17:58:07 | [diff] [blame] | 441 | BrowserThread::PostTaskAndReply( |
[email protected] | 9afacd2 | 2013-11-13 20:23:31 | [diff] [blame] | 442 | BrowserThread::IO, FROM_HERE, |
| 443 | base::Bind(&InfoMap::AddExtension, info_map(), |
vmpstr | a34d1132 | 2016-03-21 20:28:47 | [diff] [blame] | 444 | base::RetainedRef(extension), install_time, incognito_enabled, |
rockot | 494f007 | 2015-07-29 17:58:07 | [diff] [blame] | 445 | notifications_disabled), |
| 446 | callback); |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 447 | } |
| 448 | |
| 449 | void ExtensionSystemImpl::UnregisterExtensionWithRequestContexts( |
| 450 | const std::string& extension_id, |
[email protected] | b0af479 | 2013-10-23 09:12:13 | [diff] [blame] | 451 | const UnloadedExtensionInfo::Reason reason) { |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 452 | BrowserThread::PostTask( |
[email protected] | 38427a1 | 2013-11-09 17:34:20 | [diff] [blame] | 453 | BrowserThread::IO, |
| 454 | FROM_HERE, |
| 455 | base::Bind(&InfoMap::RemoveExtension, info_map(), extension_id, reason)); |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 456 | } |
[email protected] | bd30672 | 2012-07-11 20:43:59 | [diff] [blame] | 457 | |
| 458 | } // namespace extensions |