[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> |
Jinho Bang | b5216cec | 2018-01-17 19:43:11 | [diff] [blame] | 8 | #include <memory> |
asargent | 8380bd39 | 2016-03-21 23:47:33 | [diff] [blame] | 9 | |
[email protected] | 53603d2 | 2012-11-14 08:31:11 | [diff] [blame] | 10 | #include "base/base_switches.h" |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 11 | #include "base/bind.h" |
| 12 | #include "base/command_line.h" |
[email protected] | 5799981 | 2013-02-24 05:40:52 | [diff] [blame] | 13 | #include "base/files/file_path.h" |
asargent | 631a99a | 2015-10-15 21:51:48 | [diff] [blame] | 14 | #include "base/files/file_util.h" |
[email protected] | f83bd43 | 2014-05-10 20:44:40 | [diff] [blame] | 15 | #include "base/memory/weak_ptr.h" |
[email protected] | f4ebe77 | 2013-02-02 00:21:39 | [diff] [blame] | 16 | #include "base/strings/string_tokenizer.h" |
rkaplow | e65c2ff | 2015-02-14 16:29:54 | [diff] [blame] | 17 | #include "base/trace_event/trace_event.h" |
avi | a2f4804a | 2015-12-24 23:11:13 | [diff] [blame] | 18 | #include "build/build_config.h" |
michaelpg | dbdcdcc | 2017-04-06 01:40:56 | [diff] [blame] | 19 | #include "chrome/browser/apps/browser_context_keyed_service_factories.h" |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 20 | #include "chrome/browser/browser_process.h" |
michaelpg | 2fc6af9 | 2017-01-13 19:54:18 | [diff] [blame] | 21 | #include "chrome/browser/chrome_notification_types.h" |
treib | 926ee2d | 2015-08-06 10:55:42 | [diff] [blame] | 22 | #include "chrome/browser/extensions/chrome_app_sorting.h" |
juncai | e950b9e55 | 2015-06-11 20:25:31 | [diff] [blame] | 23 | #include "chrome/browser/extensions/chrome_content_verifier_delegate.h" |
[email protected] | 931186e0 | 2012-07-20 01:22:06 | [diff] [blame] | 24 | #include "chrome/browser/extensions/component_loader.h" |
Minh X. Nguyen | 3097534 | 2017-12-04 22:02:41 | [diff] [blame] | 25 | #include "chrome/browser/extensions/crx_installer.h" |
xiyuan | f6a4c6a6 | 2016-04-19 18:14:54 | [diff] [blame] | 26 | #include "chrome/browser/extensions/extension_garbage_collector.h" |
binjin | 1569c9b | 2014-09-05 13:33:18 | [diff] [blame] | 27 | #include "chrome/browser/extensions/extension_management.h" |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 28 | #include "chrome/browser/extensions/extension_service.h" |
treib | 8a6d989 | 2015-08-26 10:23:19 | [diff] [blame] | 29 | #include "chrome/browser/extensions/extension_sync_service.h" |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 30 | #include "chrome/browser/extensions/extension_system_factory.h" |
[email protected] | ffd2f79e | 2013-11-14 00:11:46 | [diff] [blame] | 31 | #include "chrome/browser/extensions/install_verifier.h" |
Devlin Cronin | 9722a72 | 2017-12-16 03:35:10 | [diff] [blame] | 32 | #include "chrome/browser/extensions/load_error_reporter.h" |
[email protected] | d9ede58 | 2012-08-14 19:21:38 | [diff] [blame] | 33 | #include "chrome/browser/extensions/navigation_observer.h" |
[email protected] | f698c16 | 2014-06-13 00:46:26 | [diff] [blame] | 34 | #include "chrome/browser/extensions/shared_module_service.h" |
[email protected] | 479e392 | 2014-07-30 07:12:57 | [diff] [blame] | 35 | #include "chrome/browser/extensions/state_store_notification_observer.h" |
[email protected] | 13e062e | 2014-08-09 10:21:55 | [diff] [blame] | 36 | #include "chrome/browser/extensions/unpacked_installer.h" |
xiyuan | f6a4c6a6 | 2016-04-19 18:14:54 | [diff] [blame] | 37 | #include "chrome/browser/extensions/update_install_gate.h" |
brettw | 1f92eed | 2016-12-07 01:12:58 | [diff] [blame] | 38 | #include "chrome/browser/notifications/notifier_state_tracker.h" |
| 39 | #include "chrome/browser/notifications/notifier_state_tracker_factory.h" |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 40 | #include "chrome/browser/profiles/profile.h" |
| 41 | #include "chrome/browser/profiles/profile_manager.h" |
[email protected] | 13e062e | 2014-08-09 10:21:55 | [diff] [blame] | 42 | #include "chrome/browser/ui/webui/extensions/extension_icon_source.h" |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 43 | #include "chrome/common/chrome_switches.h" |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 44 | #include "content/public/browser/browser_thread.h" |
michaelpg | 2fc6af9 | 2017-01-13 19:54:18 | [diff] [blame] | 45 | #include "content/public/browser/notification_service.h" |
[email protected] | 24ea7a1 | 2013-01-27 23:54:53 | [diff] [blame] | 46 | #include "content/public/browser/url_data_source.h" |
[email protected] | fd3df778 | 2014-05-08 23:54:27 | [diff] [blame] | 47 | #include "extensions/browser/content_verifier.h" |
[email protected] | 489db084 | 2014-01-22 18:20:03 | [diff] [blame] | 48 | #include "extensions/browser/extension_pref_store.h" |
| 49 | #include "extensions/browser/extension_pref_value_map.h" |
| 50 | #include "extensions/browser/extension_pref_value_map_factory.h" |
| 51 | #include "extensions/browser/extension_prefs.h" |
[email protected] | 45f5b7d | 2014-01-22 23:47:13 | [diff] [blame] | 52 | #include "extensions/browser/extension_registry.h" |
karandeepb | 810e3340 | 2017-04-05 23:41:22 | [diff] [blame] | 53 | #include "extensions/browser/extension_util.h" |
[email protected] | 38427a1 | 2013-11-09 17:34:20 | [diff] [blame] | 54 | #include "extensions/browser/info_map.h" |
[email protected] | aab2310 | 2014-02-05 18:57:55 | [diff] [blame] | 55 | #include "extensions/browser/quota_service.h" |
[email protected] | 45f5b7d | 2014-01-22 23:47:13 | [diff] [blame] | 56 | #include "extensions/browser/runtime_data.h" |
rdevlin.cronin | f5863da | 2015-09-10 19:21:45 | [diff] [blame] | 57 | #include "extensions/browser/service_worker_manager.h" |
Albert Chaulk | b96abb85 | 2018-03-02 00:53:13 | [diff] [blame] | 58 | #include "extensions/browser/shared_user_script_master.h" |
[email protected] | daf3ffda | 2014-06-25 06:44:57 | [diff] [blame] | 59 | #include "extensions/browser/state_store.h" |
asargent | 8380bd39 | 2016-03-21 23:47:33 | [diff] [blame] | 60 | #include "extensions/browser/uninstall_ping_sender.h" |
cmumford | 6ae8d46 | 2016-03-24 20:35:27 | [diff] [blame] | 61 | #include "extensions/browser/value_store/value_store_factory_impl.h" |
[email protected] | 836e298 | 2013-05-16 08:07:42 | [diff] [blame] | 62 | #include "extensions/common/constants.h" |
rdevlin.cronin | 4122753 | 2016-07-13 21:24:34 | [diff] [blame] | 63 | #include "extensions/common/features/feature_channel.h" |
asargent | 8380bd39 | 2016-03-21 23:47:33 | [diff] [blame] | 64 | #include "extensions/common/manifest_url_handlers.h" |
Evan Stade | 889ce471 | 2018-01-28 15:26:26 | [diff] [blame] | 65 | #include "ui/message_center/public/cpp/notifier_id.h" |
[email protected] | 9afacd2 | 2013-11-13 20:23:31 | [diff] [blame] | 66 | |
[email protected] | bb12148 | 2012-12-08 06:49:38 | [diff] [blame] | 67 | #if defined(OS_CHROMEOS) |
[email protected] | 6ed2e0c | 2013-04-09 04:48:13 | [diff] [blame] | 68 | #include "chrome/browser/app_mode/app_mode_utils.h" |
xiyuan | a0a6aaaa | 2016-04-19 23:34:16 | [diff] [blame] | 69 | #include "chrome/browser/chromeos/app_mode/kiosk_app_update_install_gate.h" |
[email protected] | 1a643611 | 2013-10-09 02:49:58 | [diff] [blame] | 70 | #include "chrome/browser/chromeos/extensions/device_local_account_management_policy_provider.h" |
antrim | 5876956 | 2016-11-14 14:48:41 | [diff] [blame] | 71 | #include "chrome/browser/chromeos/extensions/signin_screen_policy_provider.h" |
[email protected] | 1a643611 | 2013-10-09 02:49:58 | [diff] [blame] | 72 | #include "chrome/browser/chromeos/policy/device_local_account.h" |
antrim | 5876956 | 2016-11-14 14:48:41 | [diff] [blame] | 73 | #include "chrome/browser/chromeos/profiles/profile_helper.h" |
[email protected] | 931d104 | 2013-04-05 17:50:44 | [diff] [blame] | 74 | #include "chromeos/chromeos_switches.h" |
[email protected] | c57397a | 2013-04-18 19:41:11 | [diff] [blame] | 75 | #include "chromeos/login/login_state.h" |
[email protected] | 4d39078 | 2014-08-15 09:22:58 | [diff] [blame] | 76 | #include "components/user_manager/user_manager.h" |
[email protected] | bb12148 | 2012-12-08 06:49:38 | [diff] [blame] | 77 | #endif |
| 78 | |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 79 | using content::BrowserThread; |
| 80 | |
[email protected] | bd30672 | 2012-07-11 20:43:59 | [diff] [blame] | 81 | namespace extensions { |
| 82 | |
asargent | 8380bd39 | 2016-03-21 23:47:33 | [diff] [blame] | 83 | namespace { |
| 84 | |
| 85 | // Helper to serve as an UninstallPingSender::Filter callback. |
| 86 | UninstallPingSender::FilterResult ShouldSendUninstallPing( |
| 87 | const Extension* extension, |
| 88 | UninstallReason reason) { |
| 89 | if (extension && (extension->from_webstore() || |
| 90 | ManifestURL::UpdatesFromGallery(extension))) { |
| 91 | return UninstallPingSender::SEND_PING; |
| 92 | } |
| 93 | return UninstallPingSender::DO_NOT_SEND_PING; |
| 94 | } |
| 95 | |
| 96 | } // namespace |
| 97 | |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 98 | // |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 99 | // ExtensionSystemImpl::Shared |
| 100 | // |
| 101 | |
| 102 | ExtensionSystemImpl::Shared::Shared(Profile* profile) |
| 103 | : profile_(profile) { |
michaelpg | 2fc6af9 | 2017-01-13 19:54:18 | [diff] [blame] | 104 | registrar_.Add(this, chrome::NOTIFICATION_APP_TERMINATING, |
| 105 | content::NotificationService::AllSources()); |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | ExtensionSystemImpl::Shared::~Shared() { |
| 109 | } |
| 110 | |
| 111 | void ExtensionSystemImpl::Shared::InitPrefs() { |
cmumford | 6ae8d46 | 2016-03-24 20:35:27 | [diff] [blame] | 112 | store_factory_ = new ValueStoreFactoryImpl(profile_->GetPath()); |
| 113 | |
[email protected] | a690e29 | 2012-12-19 19:22:49 | [diff] [blame] | 114 | // Two state stores. The latter, which contains declarative rules, must be |
| 115 | // loaded immediately so that the rules are ready before we issue network |
| 116 | // requests. |
[email protected] | bd30672 | 2012-07-11 20:43:59 | [diff] [blame] | 117 | state_store_.reset(new StateStore( |
cmumford | 6ae8d46 | 2016-03-24 20:35:27 | [diff] [blame] | 118 | profile_, store_factory_, ValueStoreFrontend::BackendType::STATE, true)); |
[email protected] | 479e392 | 2014-07-30 07:12:57 | [diff] [blame] | 119 | state_store_notification_observer_.reset( |
| 120 | new StateStoreNotificationObserver(state_store_.get())); |
[email protected] | d3bd607 | 2013-07-26 18:32:14 | [diff] [blame] | 121 | |
[email protected] | a690e29 | 2012-12-19 19:22:49 | [diff] [blame] | 122 | rules_store_.reset(new StateStore( |
cmumford | 6ae8d46 | 2016-03-24 20:35:27 | [diff] [blame] | 123 | profile_, store_factory_, ValueStoreFrontend::BackendType::RULES, false)); |
[email protected] | cb610dc | 2012-08-31 17:16:56 | [diff] [blame] | 124 | |
[email protected] | 13e062e | 2014-08-09 10:21:55 | [diff] [blame] | 125 | #if defined(OS_CHROMEOS) |
antrim | 5876956 | 2016-11-14 14:48:41 | [diff] [blame] | 126 | // We can not perform check for Signin Profile here, as it would result in |
| 127 | // recursive call upon creation of Signin Profile, so we will create |
| 128 | // SigninScreenPolicyProvider lazily in RegisterManagementPolicyProviders. |
| 129 | |
[email protected] | 2fda997 | 2014-07-23 14:51:59 | [diff] [blame] | 130 | const user_manager::User* user = |
[email protected] | 4d39078 | 2014-08-15 09:22:58 | [diff] [blame] | 131 | user_manager::UserManager::Get()->GetActiveUser(); |
[email protected] | 1a643611 | 2013-10-09 02:49:58 | [diff] [blame] | 132 | policy::DeviceLocalAccount::Type device_local_account_type; |
alemate | 909aa58a | 2016-11-03 22:49:07 | [diff] [blame] | 133 | if (user && |
| 134 | policy::IsDeviceLocalAccountUser(user->GetAccountId().GetUserEmail(), |
| 135 | &device_local_account_type)) { |
[email protected] | 1a643611 | 2013-10-09 02:49:58 | [diff] [blame] | 136 | device_local_account_management_policy_provider_.reset( |
| 137 | new chromeos::DeviceLocalAccountManagementPolicyProvider( |
| 138 | device_local_account_type)); |
| 139 | } |
antrim | 5876956 | 2016-11-14 14:48:41 | [diff] [blame] | 140 | #endif |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 141 | } |
| 142 | |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 143 | void ExtensionSystemImpl::Shared::RegisterManagementPolicyProviders() { |
binjin | e6b58b5 | 2014-10-31 01:55:57 | [diff] [blame] | 144 | management_policy_->RegisterProviders( |
binjin | 1569c9b | 2014-09-05 13:33:18 | [diff] [blame] | 145 | ExtensionManagementFactory::GetForBrowserContext(profile_) |
binjin | e6b58b5 | 2014-10-31 01:55:57 | [diff] [blame] | 146 | ->GetProviders()); |
[email protected] | 1a643611 | 2013-10-09 02:49:58 | [diff] [blame] | 147 | |
[email protected] | 13e062e | 2014-08-09 10:21:55 | [diff] [blame] | 148 | #if defined(OS_CHROMEOS) |
antrim | 5876956 | 2016-11-14 14:48:41 | [diff] [blame] | 149 | // Lazy creation of SigninScreenPolicyProvider. |
| 150 | if (!signin_screen_policy_provider_) { |
| 151 | if (chromeos::ProfileHelper::IsSigninProfile(profile_)) { |
| 152 | signin_screen_policy_provider_.reset( |
| 153 | new chromeos::SigninScreenPolicyProvider()); |
| 154 | } |
| 155 | } |
| 156 | |
[email protected] | 1a643611 | 2013-10-09 02:49:58 | [diff] [blame] | 157 | if (device_local_account_management_policy_provider_) { |
| 158 | management_policy_->RegisterProvider( |
| 159 | device_local_account_management_policy_provider_.get()); |
| 160 | } |
antrim | 5876956 | 2016-11-14 14:48:41 | [diff] [blame] | 161 | if (signin_screen_policy_provider_) |
| 162 | management_policy_->RegisterProvider(signin_screen_policy_provider_.get()); |
[email protected] | 13e062e | 2014-08-09 10:21:55 | [diff] [blame] | 163 | #endif // defined(OS_CHROMEOS) |
[email protected] | 1a643611 | 2013-10-09 02:49:58 | [diff] [blame] | 164 | |
juncai | 33e46210 | 2015-05-18 20:48:44 | [diff] [blame] | 165 | management_policy_->RegisterProvider(InstallVerifier::Get(profile_)); |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 166 | } |
| 167 | |
xiyuan | f6a4c6a6 | 2016-04-19 18:14:54 | [diff] [blame] | 168 | void ExtensionSystemImpl::Shared::InitInstallGates() { |
| 169 | update_install_gate_.reset(new UpdateInstallGate(extension_service_.get())); |
| 170 | extension_service_->RegisterInstallGate( |
| 171 | ExtensionPrefs::DELAY_REASON_WAIT_FOR_IDLE, update_install_gate_.get()); |
| 172 | extension_service_->RegisterInstallGate( |
| 173 | ExtensionPrefs::DELAY_REASON_GC, |
| 174 | ExtensionGarbageCollector::Get(profile_)); |
| 175 | extension_service_->RegisterInstallGate( |
| 176 | ExtensionPrefs::DELAY_REASON_WAIT_FOR_IMPORTS, |
| 177 | extension_service_->shared_module_service()); |
xiyuan | a0a6aaaa | 2016-04-19 23:34:16 | [diff] [blame] | 178 | #if defined(OS_CHROMEOS) |
| 179 | if (chrome::IsRunningInForcedAppMode()) { |
| 180 | kiosk_app_update_install_gate_.reset( |
| 181 | new chromeos::KioskAppUpdateInstallGate(profile_)); |
| 182 | extension_service_->RegisterInstallGate( |
| 183 | ExtensionPrefs::DELAY_REASON_WAIT_FOR_OS_UPDATE, |
| 184 | kiosk_app_update_install_gate_.get()); |
| 185 | } |
| 186 | #endif |
xiyuan | f6a4c6a6 | 2016-04-19 18:14:54 | [diff] [blame] | 187 | } |
| 188 | |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 189 | void ExtensionSystemImpl::Shared::Init(bool extensions_enabled) { |
rkaplow | e65c2ff | 2015-02-14 16:29:54 | [diff] [blame] | 190 | TRACE_EVENT0("browser,startup", "ExtensionSystemImpl::Shared::Init"); |
avi | 3ef9ec9e | 2014-12-22 22:50:17 | [diff] [blame] | 191 | const base::CommandLine* command_line = |
| 192 | base::CommandLine::ForCurrentProcess(); |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 193 | |
[email protected] | d9ede58 | 2012-08-14 19:21:38 | [diff] [blame] | 194 | navigation_observer_.reset(new NavigationObserver(profile_)); |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 195 | |
Oscar Johansson | 7f4c1b93 | 2018-06-12 06:11:58 | [diff] [blame^] | 196 | bool allow_noisy_errors = |
| 197 | !command_line->HasSwitch(::switches::kNoErrorDialogs); |
Devlin Cronin | 9722a72 | 2017-12-16 03:35:10 | [diff] [blame] | 198 | LoadErrorReporter::Init(allow_noisy_errors); |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 199 | |
asargent | 678123d2 | 2015-07-31 23:24:10 | [diff] [blame] | 200 | content_verifier_ = new ContentVerifier( |
Jinho Bang | b5216cec | 2018-01-17 19:43:11 | [diff] [blame] | 201 | profile_, std::make_unique<ChromeContentVerifierDelegate>(profile_)); |
asargent | 678123d2 | 2015-07-31 23:24:10 | [diff] [blame] | 202 | |
rdevlin.cronin | f5863da | 2015-09-10 19:21:45 | [diff] [blame] | 203 | service_worker_manager_.reset(new ServiceWorkerManager(profile_)); |
| 204 | |
[email protected] | 15ad2ee | 2014-08-15 19:15:26 | [diff] [blame] | 205 | shared_user_script_master_.reset(new SharedUserScriptMaster(profile_)); |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 206 | |
[email protected] | 45f5b7d | 2014-01-22 23:47:13 | [diff] [blame] | 207 | // ExtensionService depends on RuntimeData. |
| 208 | runtime_data_.reset(new RuntimeData(ExtensionRegistry::Get(profile_))); |
| 209 | |
mlerman | 7831f57d | 2015-05-25 11:40:15 | [diff] [blame] | 210 | bool autoupdate_enabled = !profile_->IsGuestSession() && |
| 211 | !profile_->IsSystemProfile(); |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 212 | #if defined(OS_CHROMEOS) |
tbarzic | d2a741e | 2017-06-28 20:37:54 | [diff] [blame] | 213 | if (!extensions_enabled || |
| 214 | chromeos::ProfileHelper::IsLockScreenAppProfile(profile_)) { |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 215 | autoupdate_enabled = false; |
tbarzic | d2a741e | 2017-06-28 20:37:54 | [diff] [blame] | 216 | } |
rkaplow | dd66a134 | 2015-03-05 00:31:49 | [diff] [blame] | 217 | #endif // defined(OS_CHROMEOS) |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 218 | extension_service_.reset(new ExtensionService( |
avi | 3ef9ec9e | 2014-12-22 22:50:17 | [diff] [blame] | 219 | profile_, base::CommandLine::ForCurrentProcess(), |
[email protected] | 836e298 | 2013-05-16 08:07:42 | [diff] [blame] | 220 | profile_->GetPath().AppendASCII(extensions::kInstallDirectoryName), |
avi | 3ef9ec9e | 2014-12-22 22:50:17 | [diff] [blame] | 221 | ExtensionPrefs::Get(profile_), Blacklist::Get(profile_), |
| 222 | autoupdate_enabled, extensions_enabled, &ready_)); |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 223 | |
asargent | 8380bd39 | 2016-03-21 23:47:33 | [diff] [blame] | 224 | uninstall_ping_sender_.reset(new UninstallPingSender( |
| 225 | ExtensionRegistry::Get(profile_), base::Bind(&ShouldSendUninstallPing))); |
| 226 | |
[email protected] | d7fbc09 | 2012-06-18 22:52:00 | [diff] [blame] | 227 | // These services must be registered before the ExtensionService tries to |
| 228 | // load any extensions. |
| 229 | { |
juncai | 33e46210 | 2015-05-18 20:48:44 | [diff] [blame] | 230 | InstallVerifier::Get(profile_)->Init(); |
[email protected] | 8bb6216 | 2014-06-23 09:45:50 | [diff] [blame] | 231 | ContentVerifierDelegate::Mode mode = |
juncai | e950b9e55 | 2015-06-11 20:25:31 | [diff] [blame] | 232 | ChromeContentVerifierDelegate::GetDefaultMode(); |
[email protected] | 8bb6216 | 2014-06-23 09:45:50 | [diff] [blame] | 233 | #if defined(OS_CHROMEOS) |
| 234 | mode = std::max(mode, ContentVerifierDelegate::BOOTSTRAP); |
rkaplow | dd66a134 | 2015-03-05 00:31:49 | [diff] [blame] | 235 | #endif // defined(OS_CHROMEOS) |
[email protected] | 6a5898e | 2014-07-22 23:33:54 | [diff] [blame] | 236 | if (mode >= ContentVerifierDelegate::BOOTSTRAP) |
[email protected] | 8bb6216 | 2014-06-23 09:45:50 | [diff] [blame] | 237 | content_verifier_->Start(); |
[email protected] | fd3df778 | 2014-05-08 23:54:27 | [diff] [blame] | 238 | info_map()->SetContentVerifier(content_verifier_.get()); |
tbarzic | d2a741e | 2017-06-28 20:37:54 | [diff] [blame] | 239 | #if defined(OS_CHROMEOS) |
| 240 | if (chromeos::ProfileHelper::IsLockScreenAppProfile(profile_)) |
| 241 | info_map()->SetIsLockScreenContext(true); |
| 242 | #endif |
[email protected] | bd30672 | 2012-07-11 20:43:59 | [diff] [blame] | 243 | management_policy_.reset(new ManagementPolicy); |
[email protected] | d7fbc09 | 2012-06-18 22:52:00 | [diff] [blame] | 244 | RegisterManagementPolicyProviders(); |
| 245 | } |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 246 | |
lazyboy | a885afc | 2016-11-22 22:43:42 | [diff] [blame] | 247 | // Extension API calls require QuotaService, so create it before loading any |
| 248 | // extensions. |
| 249 | quota_service_.reset(new QuotaService); |
| 250 | |
[email protected] | bb12148 | 2012-12-08 06:49:38 | [diff] [blame] | 251 | bool skip_session_extensions = false; |
| 252 | #if defined(OS_CHROMEOS) |
emaxx | 095cadb | 2017-04-11 17:07:09 | [diff] [blame] | 253 | // Skip loading session extensions if we are not in a user session or if the |
tbarzic | d2a741e | 2017-06-28 20:37:54 | [diff] [blame] | 254 | // profile is the sign-in or lock screen app profile, which don't correspond |
| 255 | // to a user session. |
| 256 | skip_session_extensions = |
| 257 | !chromeos::LoginState::Get()->IsUserLoggedIn() || |
| 258 | chromeos::ProfileHelper::IsSigninProfile(profile_) || |
| 259 | chromeos::ProfileHelper::IsLockScreenAppProfile(profile_); |
[email protected] | 531593d | 2014-01-08 18:48:31 | [diff] [blame] | 260 | if (chrome::IsRunningInForcedAppMode()) { |
| 261 | extension_service_->component_loader()-> |
| 262 | AddDefaultComponentExtensionsForKioskMode(skip_session_extensions); |
| 263 | } else { |
[email protected] | 6ed2e0c | 2013-04-09 04:48:13 | [diff] [blame] | 264 | extension_service_->component_loader()->AddDefaultComponentExtensions( |
| 265 | skip_session_extensions); |
| 266 | } |
| 267 | #else |
[email protected] | bb12148 | 2012-12-08 06:49:38 | [diff] [blame] | 268 | extension_service_->component_loader()->AddDefaultComponentExtensions( |
| 269 | skip_session_extensions); |
[email protected] | 6ed2e0c | 2013-04-09 04:48:13 | [diff] [blame] | 270 | #endif |
treib | 926ee2d | 2015-08-06 10:55:42 | [diff] [blame] | 271 | |
| 272 | app_sorting_.reset(new ChromeAppSorting(profile_)); |
| 273 | |
xiyuan | f6a4c6a6 | 2016-04-19 18:14:54 | [diff] [blame] | 274 | InitInstallGates(); |
| 275 | |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 276 | extension_service_->Init(); |
| 277 | |
treib | 8a6d989 | 2015-08-26 10:23:19 | [diff] [blame] | 278 | // Make sure ExtensionSyncService is created. |
| 279 | ExtensionSyncService::Get(profile_); |
| 280 | |
[email protected] | c1909afb | 2013-11-13 21:12:51 | [diff] [blame] | 281 | // Make the chrome://extension-icon/ resource available. |
| 282 | content::URLDataSource::Add(profile_, new ExtensionIconSource(profile_)); |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 283 | } |
| 284 | |
[email protected] | 47b89656 | 2012-08-22 23:55:15 | [diff] [blame] | 285 | void ExtensionSystemImpl::Shared::Shutdown() { |
dcheng | c704794 | 2014-08-26 05:05:31 | [diff] [blame] | 286 | if (content_verifier_.get()) |
[email protected] | fd3df778 | 2014-05-08 23:54:27 | [diff] [blame] | 287 | content_verifier_->Shutdown(); |
[email protected] | 3eeddd89 | 2013-04-17 17:00:11 | [diff] [blame] | 288 | if (extension_service_) |
[email protected] | 47b89656 | 2012-08-22 23:55:15 | [diff] [blame] | 289 | extension_service_->Shutdown(); |
| 290 | } |
| 291 | |
rdevlin.cronin | f5863da | 2015-09-10 19:21:45 | [diff] [blame] | 292 | ServiceWorkerManager* ExtensionSystemImpl::Shared::service_worker_manager() { |
| 293 | return service_worker_manager_.get(); |
| 294 | } |
| 295 | |
[email protected] | bd30672 | 2012-07-11 20:43:59 | [diff] [blame] | 296 | StateStore* ExtensionSystemImpl::Shared::state_store() { |
[email protected] | 90e800c | 2012-06-12 23:11:00 | [diff] [blame] | 297 | return state_store_.get(); |
| 298 | } |
| 299 | |
[email protected] | a690e29 | 2012-12-19 19:22:49 | [diff] [blame] | 300 | StateStore* ExtensionSystemImpl::Shared::rules_store() { |
| 301 | return rules_store_.get(); |
| 302 | } |
| 303 | |
cmumford | 6ae8d46 | 2016-03-24 20:35:27 | [diff] [blame] | 304 | scoped_refptr<ValueStoreFactory> ExtensionSystemImpl::Shared::store_factory() |
| 305 | const { |
| 306 | return store_factory_; |
| 307 | } |
| 308 | |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 309 | ExtensionService* ExtensionSystemImpl::Shared::extension_service() { |
| 310 | return extension_service_.get(); |
| 311 | } |
| 312 | |
[email protected] | 45f5b7d | 2014-01-22 23:47:13 | [diff] [blame] | 313 | RuntimeData* ExtensionSystemImpl::Shared::runtime_data() { |
| 314 | return runtime_data_.get(); |
| 315 | } |
| 316 | |
[email protected] | bd30672 | 2012-07-11 20:43:59 | [diff] [blame] | 317 | ManagementPolicy* ExtensionSystemImpl::Shared::management_policy() { |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 318 | return management_policy_.get(); |
| 319 | } |
| 320 | |
[email protected] | 15ad2ee | 2014-08-15 19:15:26 | [diff] [blame] | 321 | SharedUserScriptMaster* |
| 322 | ExtensionSystemImpl::Shared::shared_user_script_master() { |
| 323 | return shared_user_script_master_.get(); |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 324 | } |
| 325 | |
[email protected] | 38427a1 | 2013-11-09 17:34:20 | [diff] [blame] | 326 | InfoMap* ExtensionSystemImpl::Shared::info_map() { |
[email protected] | dc24976f | 2013-06-02 21:15:09 | [diff] [blame] | 327 | if (!extension_info_map_.get()) |
[email protected] | 38427a1 | 2013-11-09 17:34:20 | [diff] [blame] | 328 | extension_info_map_ = new InfoMap(); |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 329 | return extension_info_map_.get(); |
| 330 | } |
| 331 | |
[email protected] | aab2310 | 2014-02-05 18:57:55 | [diff] [blame] | 332 | QuotaService* ExtensionSystemImpl::Shared::quota_service() { |
| 333 | return quota_service_.get(); |
| 334 | } |
| 335 | |
treib | 926ee2d | 2015-08-06 10:55:42 | [diff] [blame] | 336 | AppSorting* ExtensionSystemImpl::Shared::app_sorting() { |
| 337 | return app_sorting_.get(); |
| 338 | } |
| 339 | |
[email protected] | fd3df778 | 2014-05-08 23:54:27 | [diff] [blame] | 340 | ContentVerifier* ExtensionSystemImpl::Shared::content_verifier() { |
| 341 | return content_verifier_.get(); |
| 342 | } |
| 343 | |
michaelpg | 2fc6af9 | 2017-01-13 19:54:18 | [diff] [blame] | 344 | void ExtensionSystemImpl::Shared::Observe( |
| 345 | int type, |
| 346 | const content::NotificationSource& source, |
| 347 | const content::NotificationDetails& details) { |
| 348 | DCHECK_EQ(chrome::NOTIFICATION_APP_TERMINATING, type); |
michaelpg | dbdcdcc | 2017-04-06 01:40:56 | [diff] [blame] | 349 | chrome_apps::NotifyApplicationTerminating(profile_); |
michaelpg | 2fc6af9 | 2017-01-13 19:54:18 | [diff] [blame] | 350 | } |
| 351 | |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 352 | // |
| 353 | // ExtensionSystemImpl |
| 354 | // |
| 355 | |
| 356 | ExtensionSystemImpl::ExtensionSystemImpl(Profile* profile) |
[email protected] | 98b67303 | 2012-12-11 10:26:02 | [diff] [blame] | 357 | : profile_(profile) { |
[email protected] | 59b0e60 | 2014-01-30 00:41:24 | [diff] [blame] | 358 | shared_ = ExtensionSystemSharedFactory::GetForBrowserContext(profile); |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 359 | |
reillyg | 0ea3fa90 | 2014-10-28 15:30:23 | [diff] [blame] | 360 | if (!profile->IsOffTheRecord()) { |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 361 | shared_->InitPrefs(); |
| 362 | } |
| 363 | } |
| 364 | |
| 365 | ExtensionSystemImpl::~ExtensionSystemImpl() { |
| 366 | } |
| 367 | |
| 368 | void ExtensionSystemImpl::Shutdown() { |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 369 | } |
| 370 | |
[email protected] | 7cf1ee4 | 2013-12-11 09:13:49 | [diff] [blame] | 371 | void ExtensionSystemImpl::InitForRegularProfile(bool extensions_enabled) { |
rkaplow | e65c2ff | 2015-02-14 16:29:54 | [diff] [blame] | 372 | TRACE_EVENT0("browser,startup", "ExtensionSystemImpl::InitForRegularProfile"); |
Randy Smith | 64399d6 | 2017-12-20 04:33:40 | [diff] [blame] | 373 | cookie_notifier_ = std::make_unique<ExtensionCookieNotifier>(profile_); |
| 374 | |
[email protected] | 15ad2ee | 2014-08-15 19:15:26 | [diff] [blame] | 375 | if (shared_user_script_master() || extension_service()) |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 376 | return; // Already initialized. |
| 377 | |
[email protected] | 98b6d94 | 2013-11-10 00:34:07 | [diff] [blame] | 378 | // The InfoMap needs to be created before the ProcessManager. |
[email protected] | 9656bc5 | 2012-08-13 17:05:33 | [diff] [blame] | 379 | shared_->info_map(); |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 380 | shared_->Init(extensions_enabled); |
| 381 | } |
| 382 | |
Randy Smith | 64399d6 | 2017-12-20 04:33:40 | [diff] [blame] | 383 | void ExtensionSystemImpl::InitForIncognitoProfile() { |
| 384 | cookie_notifier_ = std::make_unique<ExtensionCookieNotifier>(profile_); |
| 385 | } |
| 386 | |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 387 | ExtensionService* ExtensionSystemImpl::extension_service() { |
| 388 | return shared_->extension_service(); |
| 389 | } |
| 390 | |
[email protected] | 45f5b7d | 2014-01-22 23:47:13 | [diff] [blame] | 391 | RuntimeData* ExtensionSystemImpl::runtime_data() { |
| 392 | return shared_->runtime_data(); |
| 393 | } |
| 394 | |
[email protected] | bd30672 | 2012-07-11 20:43:59 | [diff] [blame] | 395 | ManagementPolicy* ExtensionSystemImpl::management_policy() { |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 396 | return shared_->management_policy(); |
| 397 | } |
| 398 | |
rdevlin.cronin | f5863da | 2015-09-10 19:21:45 | [diff] [blame] | 399 | ServiceWorkerManager* ExtensionSystemImpl::service_worker_manager() { |
| 400 | return shared_->service_worker_manager(); |
| 401 | } |
| 402 | |
[email protected] | 15ad2ee | 2014-08-15 19:15:26 | [diff] [blame] | 403 | SharedUserScriptMaster* ExtensionSystemImpl::shared_user_script_master() { |
| 404 | return shared_->shared_user_script_master(); |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 405 | } |
| 406 | |
[email protected] | bd30672 | 2012-07-11 20:43:59 | [diff] [blame] | 407 | StateStore* ExtensionSystemImpl::state_store() { |
[email protected] | 90e800c | 2012-06-12 23:11:00 | [diff] [blame] | 408 | return shared_->state_store(); |
| 409 | } |
| 410 | |
[email protected] | a690e29 | 2012-12-19 19:22:49 | [diff] [blame] | 411 | StateStore* ExtensionSystemImpl::rules_store() { |
| 412 | return shared_->rules_store(); |
| 413 | } |
| 414 | |
cmumford | 6ae8d46 | 2016-03-24 20:35:27 | [diff] [blame] | 415 | scoped_refptr<ValueStoreFactory> ExtensionSystemImpl::store_factory() { |
| 416 | return shared_->store_factory(); |
| 417 | } |
| 418 | |
[email protected] | 38427a1 | 2013-11-09 17:34:20 | [diff] [blame] | 419 | InfoMap* ExtensionSystemImpl::info_map() { return shared_->info_map(); } |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 420 | |
[email protected] | 4a10006a | 2013-05-17 23:18:35 | [diff] [blame] | 421 | const OneShotEvent& ExtensionSystemImpl::ready() const { |
| 422 | return shared_->ready(); |
| 423 | } |
| 424 | |
[email protected] | aab2310 | 2014-02-05 18:57:55 | [diff] [blame] | 425 | QuotaService* ExtensionSystemImpl::quota_service() { |
| 426 | return shared_->quota_service(); |
| 427 | } |
| 428 | |
treib | 926ee2d | 2015-08-06 10:55:42 | [diff] [blame] | 429 | AppSorting* ExtensionSystemImpl::app_sorting() { |
| 430 | return shared_->app_sorting(); |
| 431 | } |
| 432 | |
[email protected] | fd3df778 | 2014-05-08 23:54:27 | [diff] [blame] | 433 | ContentVerifier* ExtensionSystemImpl::content_verifier() { |
| 434 | return shared_->content_verifier(); |
| 435 | } |
| 436 | |
dcheng | c963c714 | 2016-04-08 03:55:22 | [diff] [blame] | 437 | std::unique_ptr<ExtensionSet> ExtensionSystemImpl::GetDependentExtensions( |
[email protected] | f698c16 | 2014-06-13 00:46:26 | [diff] [blame] | 438 | const Extension* extension) { |
| 439 | return extension_service()->shared_module_service()->GetDependentExtensions( |
| 440 | extension); |
| 441 | } |
| 442 | |
Minh X. Nguyen | 3097534 | 2017-12-04 22:02:41 | [diff] [blame] | 443 | void ExtensionSystemImpl::InstallUpdate( |
| 444 | const std::string& extension_id, |
| 445 | const std::string& public_key, |
| 446 | const base::FilePath& unpacked_dir, |
| 447 | InstallUpdateCallback install_update_callback) { |
| 448 | DCHECK(!install_update_callback.is_null()); |
| 449 | |
| 450 | ExtensionService* service = extension_service(); |
| 451 | DCHECK(service); |
| 452 | |
| 453 | scoped_refptr<CrxInstaller> installer = CrxInstaller::CreateSilent(service); |
| 454 | installer->set_delete_source(true); |
| 455 | installer->set_installer_callback(std::move(install_update_callback)); |
| 456 | installer->UpdateExtensionFromUnpackedCrx(extension_id, public_key, |
| 457 | unpacked_dir); |
asargent | 631a99a | 2015-10-15 21:51:48 | [diff] [blame] | 458 | } |
| 459 | |
Minh X. Nguyen | b4fbf92 | 2018-01-29 18:28:10 | [diff] [blame] | 460 | bool ExtensionSystemImpl::FinishDelayedInstallationIfReady( |
| 461 | const std::string& extension_id, |
| 462 | bool install_immediately) { |
| 463 | ExtensionService* service = extension_service(); |
| 464 | DCHECK(service); |
| 465 | return service->GetPendingExtensionUpdate(extension_id) && |
| 466 | service->FinishDelayedInstallationIfReady(extension_id, |
| 467 | install_immediately); |
| 468 | } |
| 469 | |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 470 | void ExtensionSystemImpl::RegisterExtensionWithRequestContexts( |
rockot | 494f007 | 2015-07-29 17:58:07 | [diff] [blame] | 471 | const Extension* extension, |
| 472 | const base::Closure& callback) { |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 473 | base::Time install_time; |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 474 | if (extension->location() != Manifest::COMPONENT) { |
[email protected] | 836e298 | 2013-05-16 08:07:42 | [diff] [blame] | 475 | install_time = ExtensionPrefs::Get(profile_)-> |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 476 | GetInstallTime(extension->id()); |
| 477 | } |
[email protected] | 1d5cf414 | 2014-01-24 18:25:22 | [diff] [blame] | 478 | bool incognito_enabled = util::IsIncognitoEnabled(extension->id(), profile_); |
[email protected] | 9afacd2 | 2013-11-13 20:23:31 | [diff] [blame] | 479 | |
| 480 | bool notifications_disabled = false; |
[email protected] | 9afacd2 | 2013-11-13 20:23:31 | [diff] [blame] | 481 | message_center::NotifierId notifier_id( |
| 482 | message_center::NotifierId::APPLICATION, |
| 483 | extension->id()); |
| 484 | |
peter | c400791 | 2015-07-31 21:13:37 | [diff] [blame] | 485 | NotifierStateTracker* notifier_state_tracker = |
| 486 | NotifierStateTrackerFactory::GetForProfile(profile_); |
[email protected] | 9afacd2 | 2013-11-13 20:23:31 | [diff] [blame] | 487 | notifications_disabled = |
peter | c400791 | 2015-07-31 21:13:37 | [diff] [blame] | 488 | !notifier_state_tracker->IsNotifierEnabled(notifier_id); |
[email protected] | 9afacd2 | 2013-11-13 20:23:31 | [diff] [blame] | 489 | |
rockot | 494f007 | 2015-07-29 17:58:07 | [diff] [blame] | 490 | BrowserThread::PostTaskAndReply( |
[email protected] | 9afacd2 | 2013-11-13 20:23:31 | [diff] [blame] | 491 | BrowserThread::IO, FROM_HERE, |
tzik | 8d880ee | 2017-04-20 19:46:24 | [diff] [blame] | 492 | base::BindOnce(&InfoMap::AddExtension, info_map(), |
| 493 | base::RetainedRef(extension), install_time, |
| 494 | incognito_enabled, notifications_disabled), |
rockot | 494f007 | 2015-07-29 17:58:07 | [diff] [blame] | 495 | callback); |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 496 | } |
| 497 | |
| 498 | void ExtensionSystemImpl::UnregisterExtensionWithRequestContexts( |
| 499 | const std::string& extension_id, |
limasdf | 0deef204 | 2017-05-03 19:17:17 | [diff] [blame] | 500 | const UnloadedExtensionReason reason) { |
tzik | 8d880ee | 2017-04-20 19:46:24 | [diff] [blame] | 501 | BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
| 502 | base::BindOnce(&InfoMap::RemoveExtension, info_map(), |
| 503 | extension_id, reason)); |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 504 | } |
[email protected] | bd30672 | 2012-07-11 20:43:59 | [diff] [blame] | 505 | |
| 506 | } // namespace extensions |