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