blob: 3ea9b0cd444e463dbcd00e36a2b3ecac26200b16 [file] [log] [blame]
[email protected]098fa7a2013-03-08 22:11:171// Copyright (c) 2013 The Chromium Authors. All rights reserved.
[email protected]6014d672008-12-05 00:38:252// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]eaa7dd182010-12-14 11:09:005#include "chrome/browser/extensions/extension_service.h"
[email protected]6014d672008-12-05 00:38:256
avia2f4804a2015-12-24 23:11:137#include <stddef.h>
8
[email protected]695b5712012-12-06 23:55:289#include <iterator>
asargente4de9f92016-09-15 01:40:0610#include <memory>
[email protected]97d2f1d2011-01-15 00:41:0811#include <set>
asargente4de9f92016-09-15 01:40:0612#include <utility>
[email protected]654512b2010-09-01 02:09:4213
Sebastien Marchandf1349f52019-01-25 03:16:4114#include "base/bind.h"
[email protected]62433d32011-10-12 22:33:1215#include "base/command_line.h"
rdevlin.cronin08ada0f2017-03-09 23:29:5216#include "base/debug/alias.h"
17#include "base/debug/dump_without_crashing.h"
skyostilf221b7de2015-06-11 20:36:3218#include "base/location.h"
Ilya Sherman982457e62017-12-13 02:19:3619#include "base/metrics/histogram_functions.h"
rkaplowfca0f4dc52015-03-14 21:40:5720#include "base/metrics/histogram_macros.h"
Christopher Lamebb90202019-04-04 03:42:3621#include "base/one_shot_event.h"
skyostilf221b7de2015-06-11 20:36:3222#include "base/single_thread_task_runner.h"
tripta.g0ac673a2017-07-07 05:45:0923#include "base/stl_util.h"
[email protected]3ea1b182013-02-08 22:38:4124#include "base/strings/string_number_conversions.h"
catmullings98cd1942016-08-30 22:31:5925#include "base/strings/string_tokenizer.h"
[email protected]00e7bef2013-06-10 20:35:1726#include "base/strings/stringprintf.h"
[email protected]112158af2013-06-07 23:46:1827#include "base/strings/utf_string_conversions.h"
Alexander Nohe2c5402882019-04-11 21:56:3328#include "base/syslog_logging.h"
Gabriel Charette44db1422018-08-06 11:19:3329#include "base/task/post_task.h"
[email protected]34b99632011-01-01 01:01:0630#include "base/threading/thread_restrictions.h"
gabb15e19072016-05-11 20:45:4131#include "base/threading/thread_task_runner_handle.h"
[email protected]41a17c52013-06-28 00:27:5332#include "base/time/time.h"
rkaplowe65c2ff2015-02-14 16:29:5433#include "base/trace_event/trace_event.h"
avia2f4804a2015-12-24 23:11:1334#include "build/build_config.h"
Evan Staded89e11c2019-09-05 18:08:5635#include "chrome/browser/browser_process.h"
[email protected]9ea0cd32013-07-12 01:50:3636#include "chrome/browser/chrome_notification_types.h"
sunil.ratnu21b896c2014-11-24 10:09:2437#include "chrome/browser/extensions/api/content_settings/content_settings_custom_extension_provider.h"
mukai87a8d402014-09-15 20:15:0938#include "chrome/browser/extensions/api/content_settings/content_settings_service.h"
ryanackley48bedbd2015-01-27 23:12:1439#include "chrome/browser/extensions/app_data_migrator.h"
[email protected]d8c8f25f2011-11-02 18:18:0140#include "chrome/browser/extensions/component_loader.h"
[email protected]13e062e2014-08-09 10:21:5541#include "chrome/browser/extensions/crx_installer.h"
[email protected]d9ede582012-08-14 19:21:3842#include "chrome/browser/extensions/data_deleter.h"
rdevlin.cronin2813c1b2014-08-26 23:51:0843#include "chrome/browser/extensions/extension_action_storage_manager.h"
[email protected]5a145e82014-05-29 22:19:0744#include "chrome/browser/extensions/extension_assets_manager.h"
[email protected]62f051c2012-03-29 17:04:4445#include "chrome/browser/extensions/extension_disabled_ui.h"
[email protected]373daf972014-04-10 01:50:4446#include "chrome/browser/extensions/extension_error_controller.h"
[email protected]19eb80152011-02-26 00:28:4347#include "chrome/browser/extensions/extension_special_storage_policy.h"
[email protected]f8aefb132013-10-30 09:29:5248#include "chrome/browser/extensions/extension_sync_service.h"
[email protected]617342a42013-12-18 23:34:0349#include "chrome/browser/extensions/extension_util.h"
[email protected]2894a512014-06-26 19:03:5650#include "chrome/browser/extensions/external_install_manager.h"
[email protected]5df038b2012-07-16 19:03:2751#include "chrome/browser/extensions/external_provider_impl.h"
Oleg Davydovc00866812019-04-04 10:47:2752#include "chrome/browser/extensions/forced_extensions/installation_reporter.h"
[email protected]ffd2f79e2013-11-14 00:11:4653#include "chrome/browser/extensions/install_verifier.h"
[email protected]d8c8f25f2011-11-02 18:18:0154#include "chrome/browser/extensions/installed_loader.h"
[email protected]f3d3b382014-03-14 21:19:2855#include "chrome/browser/extensions/pending_extension_manager.h"
[email protected]13e062e2014-08-09 10:21:5556#include "chrome/browser/extensions/permissions_updater.h"
[email protected]90878c52014-04-04 18:21:0257#include "chrome/browser/extensions/shared_module_service.h"
[email protected]13e062e2014-08-09 10:21:5558#include "chrome/browser/extensions/unpacked_installer.h"
rockotdb5192992014-09-16 21:27:0259#include "chrome/browser/extensions/updater/chrome_extension_downloader_factory.h"
[email protected]13e062e2014-08-09 10:21:5560#include "chrome/browser/extensions/updater/extension_updater.h"
rockotdb5192992014-09-16 21:27:0261#include "chrome/browser/google/google_brand.h"
[email protected]8ecad5e2010-12-02 21:18:3362#include "chrome/browser/profiles/profile.h"
[email protected]b5a507b22013-11-08 20:41:5763#include "chrome/browser/ui/webui/extensions/extension_icon_source.h"
[email protected]c8d407e2011-04-28 21:27:1764#include "chrome/browser/ui/webui/favicon_source.h"
[email protected]b07e606e2012-09-15 20:16:1565#include "chrome/browser/ui/webui/theme_source.h"
Greg Thompson8bcd799b2018-08-10 09:49:3366#include "chrome/browser/upgrade_detector/upgrade_detector.h"
Alan Cutter6e963f02019-05-06 00:33:2267#include "chrome/browser/web_applications/components/externally_installed_web_app_prefs.h"
Scott Violet6200d332018-02-23 21:29:2368#include "chrome/common/buildflags.h"
[email protected]e2eb43112009-05-29 21:19:5469#include "chrome/common/chrome_switches.h"
[email protected]f6431be82013-09-07 02:53:4570#include "chrome/common/crash_keys.h"
[email protected]9f4e4f082013-06-21 07:11:1971#include "chrome/common/extensions/extension_constants.h"
[email protected]a57209872009-05-04 22:53:1472#include "chrome/common/url_constants.h"
mukai8eaec822014-10-25 17:53:1673#include "components/content_settings/core/browser/host_content_settings_map.h"
[email protected]fdd28372014-08-21 02:27:2674#include "components/crx_file/id_util.h"
Victor Hugo Vianna Silvaed441482019-06-27 12:40:4075#include "components/favicon_base/favicon_url_parser.h"
Eric Seckler8652dcd52018-09-20 10:42:2876#include "content/public/browser/browser_task_traits.h"
Gabriel Charette790754c2018-03-16 21:32:5977#include "content/public/browser/browser_thread.h"
[email protected]05aad2da2011-10-28 10:12:3778#include "content/public/browser/notification_service.h"
[email protected]f3b1a082011-11-18 00:34:3079#include "content/public/browser/render_process_host.h"
[email protected]399583b2012-12-11 09:33:4280#include "content/public/browser/storage_partition.h"
[email protected]34423532013-11-21 18:13:1081#include "extensions/browser/event_router.h"
Devlin Cronin40b4cbc2017-08-02 01:57:5982#include "extensions/browser/extension_file_task_runner.h"
[email protected]22401dc2014-03-21 01:38:5783#include "extensions/browser/extension_host.h"
[email protected]bb1bc9b32013-12-21 03:09:1484#include "extensions/browser/extension_registry.h"
[email protected]59b0e602014-01-30 00:41:2485#include "extensions/browser/extension_system.h"
Michael Giuffrida7efeed142017-06-07 06:29:2186#include "extensions/browser/extension_util.h"
rockotffa65b12014-10-14 17:19:0687#include "extensions/browser/extensions_browser_client.h"
lazyboye8634172016-01-28 00:10:4888#include "extensions/browser/external_install_info.h"
[email protected]4a1d9c0d2014-06-13 12:50:1189#include "extensions/browser/install_flag.h"
Michael Giuffrida6397c592017-10-09 20:46:5390#include "extensions/browser/management_policy.h"
[email protected]45f5b7d2014-01-22 23:47:1391#include "extensions/browser/runtime_data.h"
[email protected]e43c61f2014-07-20 21:46:3492#include "extensions/browser/uninstall_reason.h"
[email protected]a9aa62b312013-11-29 05:35:0693#include "extensions/browser/update_observer.h"
rockotffa65b12014-10-14 17:19:0694#include "extensions/browser/updater/extension_cache.h"
rockot05f40a922014-10-16 19:40:2595#include "extensions/browser/updater/extension_downloader.h"
Oleg Davydov6541a64f2019-04-17 13:17:3396#include "extensions/browser/updater/manifest_fetch_data.h"
[email protected]fb820c02014-03-13 15:07:0897#include "extensions/common/extension_messages.h"
rockot90659852014-09-18 19:31:5298#include "extensions/common/extension_urls.h"
[email protected]5ef835a2013-11-08 20:42:5799#include "extensions/common/feature_switch.h"
rdevlin.cronin41227532016-07-13 21:24:34100#include "extensions/common/features/feature_channel.h"
[email protected]85df9d12014-04-15 17:02:14101#include "extensions/common/file_util.h"
[email protected]0c3c9732013-09-16 08:53:41102#include "extensions/common/manifest_constants.h"
Michael Giuffrida6397c592017-10-09 20:46:53103#include "extensions/common/manifest_handlers/shared_module_info.h"
rockotd5546142014-10-15 00:29:08104#include "extensions/common/manifest_url_handlers.h"
treib2e0517f92015-05-07 23:15:36105#include "extensions/common/permissions/api_permission.h"
[email protected]c41003472013-10-19 15:37:25106#include "extensions/common/permissions/permission_message_provider.h"
[email protected]e4452d32013-11-15 23:07:41107#include "extensions/common/permissions/permissions_data.h"
Michael Giuffridab158f3f2017-07-17 19:53:44108#include "extensions/common/switches.h"
[email protected]79a60642012-10-20 21:03:18109
brettw9e85ef42016-11-01 21:01:24110#if BUILDFLAG(ENABLE_SUPERVISED_USERS)
treib8ecc1eb52015-03-04 18:29:06111#include "chrome/browser/supervised_user/supervised_user_service.h"
112#include "chrome/browser/supervised_user/supervised_user_service_factory.h"
113#endif
114
[email protected]eed367e2011-04-12 03:43:31115#if defined(OS_CHROMEOS)
[email protected]88e8ec9152013-01-17 04:05:18116#include "chrome/browser/chromeos/extensions/install_limiter.h"
achuithd3da4f02017-03-23 20:05:29117#include "chrome/browser/chromeos/profiles/profile_helper.h"
pilgrime92c5fcd2014-09-10 23:31:23118#include "storage/browser/fileapi/file_system_backend.h"
119#include "storage/browser/fileapi/file_system_context.h"
[email protected]eed367e2011-04-12 03:43:31120#endif
121
[email protected]55eb70e762012-02-20 17:38:39122using content::BrowserContext;
[email protected]631bb742011-11-02 11:29:39123using content::BrowserThread;
Devlin Cronineea1b7a2018-05-26 02:46:21124
125namespace extensions {
[email protected]5ef47ec2010-01-28 05:58:05126
Michael Giuffrida573992d2018-02-08 00:48:44127using LoadErrorBehavior = ExtensionRegistrar::LoadErrorBehavior;
128
[email protected]b6ab96d2009-08-20 18:58:19129namespace {
130
Lei Zhang15339152018-08-09 22:20:44131// Wait this long after an extensions becomes idle before updating it.
132constexpr base::TimeDelta kUpdateIdleDelay = base::TimeDelta::FromSeconds(5);
[email protected]0db124b02012-11-07 04:55:05133
Takumi Fujimoto43c8c00f2017-07-26 22:48:56134// IDs of extensions that have been replaced by component extensions and need to
135// be uninstalled.
Lei Zhang15339152018-08-09 22:20:44136const char* const kMigratedExtensionIds[] = {
Takumi Fujimoto43c8c00f2017-07-26 22:48:56137 "boadgeojelhgndaghljhdicfkmllpafd", // Google Cast
138 "dliochdbjfkdbacpmhlcpmleaejidimm" // Google Cast (Beta)
139};
140
[email protected]c6d474f82009-12-16 21:11:06141} // namespace
[email protected]b6ab96d2009-08-20 18:58:19142
[email protected]eaa7dd182010-12-14 11:09:00143// ExtensionService.
[email protected]6014d672008-12-05 00:38:25144
[email protected]8e4560b62011-01-14 10:09:14145void ExtensionService::CheckExternalUninstall(const std::string& id) {
[email protected]a29a517a2011-01-21 21:11:12146 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]a8af9fdb2010-10-28 21:52:20147
[email protected]7a4c6852010-09-16 03:44:22148 // Check if the providers know about this extension.
achuith2f5578b2016-02-26 21:57:13149 for (const auto& provider : external_extension_providers_) {
150 DCHECK(provider->IsReady());
151 if (provider->HasExtension(id))
[email protected]0a60a2e2010-10-25 16:15:21152 return; // Yup, known extension, don't uninstall.
[email protected]7a4c6852010-09-16 03:44:22153 }
154
Giovanni Ortuño Urquidi218522862018-08-28 12:48:04155 // Historically, the code under //chrome/browser/extensions has
156 // unsurprisingly managed all extensions. Later, Progressive Web Apps (PWAs)
157 // were implemented on top of extensions, more out of convenience than out of
158 // principle. As of mid 2018, there is work underway to separate PWAs's
159 // implementation details from the //c/b/e code. During the transition
160 // period, PWA-extensions are no longer managed solely by //c/b/e code. We
161 // add a special case here so that //c/b/e code doesn't uninstall
162 // PWA-extensions that it doesn't otherwise know about.
163 //
164 // Long term, PWAs will be completely separate from extensions, and we can
165 // remove this cross-link.
Alan Cutter6e963f02019-05-06 00:33:22166 if (web_app::ExternallyInstalledWebAppPrefs::HasAppId(profile_->GetPrefs(),
167 id)) {
Giovanni Ortuño Urquidi218522862018-08-28 12:48:04168 return;
169 }
170
[email protected]0f48fca2011-05-19 18:46:35171 // We get the list of external extensions to check from preferences.
172 // It is possible that an extension has preferences but is not loaded.
173 // For example, an extension that requires experimental permissions
174 // will not be loaded if the experimental command line flag is not used.
175 // In this case, do not uninstall.
[email protected]31bb5ee62012-09-12 22:58:40176 if (!GetInstalledExtension(id)) {
[email protected]0f48fca2011-05-19 18:46:35177 // We can't call UninstallExtension with an unloaded/invalid
178 // extension ID.
179 LOG(WARNING) << "Attempted uninstallation of unloaded/invalid extension "
180 << "with id: " << id;
181 return;
182 }
Devlin Cronineea1b7a2018-05-26 02:46:21183 UninstallExtension(id, UNINSTALL_REASON_ORPHANED_EXTERNAL_EXTENSION, nullptr);
[email protected]7a4c6852010-09-16 03:44:22184}
185
[email protected]8e4560b62011-01-14 10:09:14186void ExtensionService::ClearProvidersForTesting() {
[email protected]7a4c6852010-09-16 03:44:22187 external_extension_providers_.clear();
188}
189
[email protected]8e4560b62011-01-14 10:09:14190void ExtensionService::AddProviderForTesting(
lazyboyf33109d2016-08-31 00:37:08191 std::unique_ptr<ExternalProviderInterface> test_provider) {
[email protected]a29a517a2011-01-21 21:11:12192 CHECK(test_provider);
lazyboyf33109d2016-08-31 00:37:08193 external_extension_providers_.push_back(std::move(test_provider));
[email protected]7a4c6852010-09-16 03:44:22194}
195
[email protected]8f959f522014-08-06 06:26:28196void ExtensionService::BlacklistExtensionForTest(
197 const std::string& extension_id) {
mlerman6a37b6a42014-11-26 22:10:53198 ExtensionIdSet blacklisted;
[email protected]8f959f522014-08-06 06:26:28199 ExtensionIdSet unchanged;
mlerman6a37b6a42014-11-26 22:10:53200 blacklisted.insert(extension_id);
201 UpdateBlacklistedExtensions(blacklisted, unchanged);
[email protected]8f959f522014-08-06 06:26:28202}
203
[email protected]9060d8b02012-01-13 02:14:30204bool ExtensionService::OnExternalExtensionUpdateUrlFound(
lazyboye8634172016-01-28 00:10:48205 const ExternalInstallInfoUpdateUrl& info,
206 bool is_initial_load) {
Istiaque Ahmedf6e72622017-09-08 23:14:17207 DCHECK_CURRENTLY_ON(BrowserThread::UI);
lazyboye8634172016-01-28 00:10:48208 CHECK(crx_file::id_util::IdIsValid(info.extension_id));
[email protected]a8af9fdb2010-10-28 21:52:20209
lazyboye8634172016-01-28 00:10:48210 if (Manifest::IsExternalLocation(info.download_location)) {
[email protected]044e86992014-01-24 22:59:11211 // All extensions that are not user specific can be cached.
Devlin Cronineea1b7a2018-05-26 02:46:21212 ExtensionsBrowserClient::Get()->GetExtensionCache()->AllowCaching(
213 info.extension_id);
[email protected]044e86992014-01-24 22:59:11214 }
215
David Bertoni58c113a2019-08-02 19:53:26216 const Extension* extension = registry_->GetExtensionById(
217 info.extension_id, ExtensionRegistry::COMPATIBILITY);
[email protected]8a87a5332011-08-11 17:54:59218 if (extension) {
asargent56282ab72016-09-09 16:58:03219 // Already installed. Skip this install if the current location has higher
220 // priority than |info.download_location|, and we aren't doing a
221 // reinstall of a corrupt policy force-installed extension.
[email protected]1d5e58b2013-01-31 08:41:40222 Manifest::Location current = extension->location();
asargent56282ab72016-09-09 16:58:03223 if (!pending_extension_manager_.IsPolicyReinstallForCorruptionExpected(
224 info.extension_id) &&
225 current == Manifest::GetHigherPriorityLocation(
226 current, info.download_location)) {
Oleg Davydovc00866812019-04-04 10:47:27227 InstallationReporter::ReportFailure(
Sergey Poromov296de0a2018-10-11 21:44:08228 profile_, info.extension_id,
Oleg Davydovc00866812019-04-04 10:47:27229 InstallationReporter::FailureReason::ALREADY_INSTALLED);
[email protected]9060d8b02012-01-13 02:14:30230 return false;
lazyboye8634172016-01-28 00:10:48231 }
[email protected]8a87a5332011-08-11 17:54:59232 // Otherwise, overwrite the current installation.
[email protected]7a4c6852010-09-16 03:44:22233 }
[email protected]9060d8b02012-01-13 02:14:30234
lazyboye8634172016-01-28 00:10:48235 // Add |info.extension_id| to the set of pending extensions. If it can not
236 // be added, then there is already a pending record from a higher-priority
237 // install source. In this case, signal that this extension will not be
[email protected]9060d8b02012-01-13 02:14:30238 // installed by returning false.
Oleg Davydovc00866812019-04-04 10:47:27239 InstallationReporter::ReportInstallationStage(
240 profile_, info.extension_id, InstallationReporter::Stage::PENDING);
[email protected]9060d8b02012-01-13 02:14:30241 if (!pending_extension_manager()->AddFromExternalUpdateUrl(
Devlin Cronind4c2a8f32017-09-29 17:08:30242 info.extension_id, info.install_parameter, info.update_url,
lazyboye8634172016-01-28 00:10:48243 info.download_location, info.creation_flags,
244 info.mark_acknowledged)) {
Oleg Davydovc00866812019-04-04 10:47:27245 InstallationReporter::ReportFailure(
246 profile_, info.extension_id,
247 InstallationReporter::FailureReason::PENDING_ADD_FAILED);
[email protected]9060d8b02012-01-13 02:14:30248 return false;
[email protected]31bb5ee62012-09-12 22:58:40249 }
[email protected]9060d8b02012-01-13 02:14:30250
lazyboye8634172016-01-28 00:10:48251 if (is_initial_load)
252 update_once_all_providers_are_ready_ = true;
[email protected]9060d8b02012-01-13 02:14:30253 return true;
[email protected]7a4c6852010-09-16 03:44:22254}
255
lazyboye8634172016-01-28 00:10:48256void ExtensionService::OnExternalProviderUpdateComplete(
257 const ExternalProviderInterface* provider,
Devlin Cronin19f70b6a2017-10-01 04:14:05258 const std::vector<ExternalInstallInfoUpdateUrl>& update_url_extensions,
259 const std::vector<ExternalInstallInfoFile>& file_extensions,
lazyboye8634172016-01-28 00:10:48260 const std::set<std::string>& removed_extensions) {
261 // Update pending_extension_manager() with the new extensions first.
lazyboy4aeef202016-09-07 21:28:59262 for (const auto& extension : update_url_extensions)
Devlin Cronin19f70b6a2017-10-01 04:14:05263 OnExternalExtensionUpdateUrlFound(extension, false);
lazyboy4aeef202016-09-07 21:28:59264 for (const auto& extension : file_extensions)
Devlin Cronin19f70b6a2017-10-01 04:14:05265 OnExternalExtensionFileFound(extension);
lazyboye8634172016-01-28 00:10:48266
267#if DCHECK_IS_ON()
268 for (const std::string& id : removed_extensions) {
lazyboy4aeef202016-09-07 21:28:59269 for (const auto& extension : update_url_extensions)
Devlin Cronin19f70b6a2017-10-01 04:14:05270 DCHECK_NE(id, extension.extension_id);
lazyboy4aeef202016-09-07 21:28:59271 for (const auto& extension : file_extensions)
Devlin Cronin19f70b6a2017-10-01 04:14:05272 DCHECK_NE(id, extension.extension_id);
lazyboye8634172016-01-28 00:10:48273 }
274#endif
275
276 // Then uninstall before running |updater_|.
277 for (const std::string& id : removed_extensions)
278 CheckExternalUninstall(id);
279
280 if (!update_url_extensions.empty() && updater_) {
281 // Empty params will cause pending extensions to be updated.
Devlin Cronineea1b7a2018-05-26 02:46:21282 updater_->CheckNow(ExtensionUpdater::CheckParams());
lazyboye8634172016-01-28 00:10:48283 }
284
285 error_controller_->ShowErrorIfNeeded();
286 external_install_manager_->UpdateExternalExtensionAlert();
287}
288
[email protected]eaa7dd182010-12-14 11:09:00289ExtensionService::ExtensionService(Profile* profile,
avi3ef9ec9e2014-12-22 22:50:17290 const base::CommandLine* command_line,
[email protected]650b2d52013-02-10 03:41:45291 const base::FilePath& install_directory,
Devlin Cronineea1b7a2018-05-26 02:46:21292 ExtensionPrefs* extension_prefs,
293 Blacklist* blacklist,
[email protected]0436b102011-04-15 18:30:03294 bool autoupdate_enabled,
[email protected]4a10006a2013-05-17 23:18:35295 bool extensions_enabled,
Christopher Lamebb90202019-04-04 03:42:36296 base::OneShotEvent* ready)
Devlin Cronineea1b7a2018-05-26 02:46:21297 : Blacklist::Observer(blacklist),
catmullings98cd1942016-08-30 22:31:59298 command_line_(command_line),
[email protected]fdd679b2012-11-15 20:49:39299 profile_(profile),
Devlin Cronineea1b7a2018-05-26 02:46:21300 system_(ExtensionSystem::Get(profile)),
[email protected]73c47932010-12-06 18:13:43301 extension_prefs_(extension_prefs),
[email protected]695b5712012-12-06 23:55:28302 blacklist_(blacklist),
Devlin Cronineea1b7a2018-05-26 02:46:21303 registry_(ExtensionRegistry::Get(profile)),
[email protected]6c9bedf2014-05-21 03:55:51304 pending_extension_manager_(profile),
[email protected]a9b00ac2009-06-25 21:03:23305 install_directory_(install_directory),
[email protected]0436b102011-04-15 18:30:03306 extensions_enabled_(extensions_enabled),
[email protected]4a10006a2013-05-17 23:18:35307 ready_(ready),
Devlin Cronineea1b7a2018-05-26 02:46:21308 shared_module_service_(new SharedModuleService(profile_)),
309 app_data_migrator_(new AppDataMigrator(profile_, registry_)),
Sergey Poromov0360b9e72018-04-19 17:37:29310 extension_registrar_(profile_, this),
Sergey Poromov296de0a2018-10-11 21:44:08311 forced_extensions_tracker_(registry_, profile_) {
[email protected]a29a517a2011-01-21 21:11:12312 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
rkaplowdd66a1342015-03-05 00:31:49313 TRACE_EVENT0("browser,startup", "ExtensionService::ExtensionService::ctor");
[email protected]a8af9fdb2010-10-28 21:52:20314
[email protected]36a784c2009-06-23 06:21:08315 // Figure out if extension installation should be enabled.
Devlin Cronineea1b7a2018-05-26 02:46:21316 if (ExtensionsBrowserClient::Get()->AreExtensionsDisabled(*command_line,
317 profile))
[email protected]6d60703b2009-08-29 01:29:23318 extensions_enabled_ = false;
[email protected]36a784c2009-06-23 06:21:08319
[email protected]3c4abc82012-10-22 22:25:54320 registrar_.Add(this, chrome::NOTIFICATION_APP_TERMINATING,
321 content::NotificationService::AllBrowserContextsAndSources());
Devlin Cronineea1b7a2018-05-26 02:46:21322 registrar_.Add(this, NOTIFICATION_EXTENSION_PROCESS_TERMINATED,
[email protected]ad50def52011-10-19 23:17:07323 content::NotificationService::AllBrowserContextsAndSources());
[email protected]432115822011-07-10 15:52:27324 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_TERMINATED,
[email protected]ad50def52011-10-19 23:17:07325 content::NotificationService::AllBrowserContextsAndSources());
Evan Staded89e11c2019-09-05 18:08:56326 // The ProfileManager may be null in unit tests.
327 if (g_browser_process->profile_manager())
328 profile_manager_observer_.Add(g_browser_process->profile_manager());
binjin1569c9b2014-09-05 13:33:18329
weidongg04695232017-06-09 00:01:05330 UpgradeDetector::GetInstance()->AddObserver(this);
331
Devlin Cronineea1b7a2018-05-26 02:46:21332 ExtensionManagementFactory::GetForBrowserContext(profile_)->AddObserver(this);
[email protected]4814b512009-11-07 00:12:29333
rkaplowdd66a1342015-03-05 00:31:49334 // Set up the ExtensionUpdater.
[email protected]93fd78f42009-07-10 16:43:17335 if (autoupdate_enabled) {
Devlin Cronineea1b7a2018-05-26 02:46:21336 updater_.reset(new ExtensionUpdater(
David Bertonidccbd352018-03-20 00:31:04337 this, extension_prefs, profile->GetPrefs(), profile,
Devlin Cronineea1b7a2018-05-26 02:46:21338 kDefaultUpdateFrequencySeconds,
339 ExtensionsBrowserClient::Get()->GetExtensionCache(),
rockotdb5192992014-09-16 21:27:02340 base::Bind(ChromeExtensionDownloaderFactory::CreateForProfile,
341 profile)));
[email protected]93fd78f42009-07-10 16:43:17342 }
343
Michael Giuffridabe1f9202019-06-05 22:36:18344 component_loader_ = std::make_unique<ComponentLoader>(this, profile);
[email protected]8e4560b62011-01-14 10:09:14345
[email protected]0436b102011-04-15 18:30:03346 if (extensions_enabled_) {
Devlin Cronineea1b7a2018-05-26 02:46:21347 ExternalProviderImpl::CreateExternalProviders(
[email protected]ae4c37e2012-12-21 01:16:25348 this, profile_, &external_extension_providers_);
[email protected]873531342011-03-09 12:16:05349 }
[email protected]b671760b2010-07-15 21:13:47350
[email protected]74474042013-11-21 12:03:54351 // Set this as the ExtensionService for app sorting to ensure it causes syncs
352 // if required.
[email protected]b3aa7182013-04-25 04:45:23353 is_first_run_ = !extension_prefs_->SetAlertSystemFirstRun();
354
[email protected]373daf972014-04-10 01:50:44355 error_controller_.reset(
Devlin Cronineea1b7a2018-05-26 02:46:21356 new ExtensionErrorController(profile_, is_first_run_));
[email protected]374ceb6f2014-07-02 19:25:34357 external_install_manager_.reset(
Devlin Cronineea1b7a2018-05-26 02:46:21358 new ExternalInstallManager(profile_, is_first_run_));
[email protected]373daf972014-04-10 01:50:44359
[email protected]c77f2352012-08-08 22:07:58360 extension_action_storage_manager_.reset(
Devlin Cronineea1b7a2018-05-26 02:46:21361 new ExtensionActionStorageManager(profile_));
[email protected]c77f2352012-08-08 22:07:58362
[email protected]cb0e50312011-05-09 15:03:07363 // How long is the path to the Extensions directory?
364 UMA_HISTOGRAM_CUSTOM_COUNTS("Extensions.ExtensionRootPathLength",
drbasicf0d1b262016-08-23 06:10:42365 install_directory_.value().length(), 1, 500, 100);
[email protected]6014d672008-12-05 00:38:25366}
367
Devlin Cronineea1b7a2018-05-26 02:46:21368PendingExtensionManager* ExtensionService::pending_extension_manager() {
[email protected]b2907fd2011-03-25 16:43:37369 return &pending_extension_manager_;
[email protected]ddb1e5a2010-12-13 20:10:45370}
371
[email protected]eaa7dd182010-12-14 11:09:00372ExtensionService::~ExtensionService() {
weidongg04695232017-06-09 00:01:05373 UpgradeDetector::GetInstance()->RemoveObserver(this);
[email protected]c8d407e2011-04-28 21:27:17374 // No need to unload extensions here because they are profile-scoped, and the
375 // profile is in the process of being deleted.
achuith2f5578b2016-02-26 21:57:13376 for (const auto& provider : external_extension_providers_)
[email protected]8e4560b62011-01-14 10:09:14377 provider->ServiceShutdown();
[email protected]6014d672008-12-05 00:38:25378}
379
[email protected]037228a2012-10-05 01:36:16380void ExtensionService::Shutdown() {
Oleg Davydovbf103f92019-07-30 15:55:08381 ExtensionManagementFactory::GetForBrowserContext(profile())->RemoveObserver(
382 this);
[email protected]037228a2012-10-05 01:36:16383}
384
[email protected]eaa7dd182010-12-14 11:09:00385void ExtensionService::Init() {
[email protected]a29a517a2011-01-21 21:11:12386 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
rkaplowe65c2ff2015-02-14 16:29:54387 TRACE_EVENT0("browser,startup", "ExtensionService::Init");
rkaplowa8fd8d32015-02-25 21:27:56388 SCOPED_UMA_HISTOGRAM_TIMER("Extensions.ExtensionServiceInitTime");
[email protected]3350d712013-11-18 09:32:24389
[email protected]4a10006a2013-05-17 23:18:35390 DCHECK(!is_ready()); // Can't redo init.
[email protected]bb1bc9b32013-12-21 03:09:14391 DCHECK_EQ(registry_->enabled_extensions().size(), 0u);
[email protected]9f1087e2009-06-15 17:29:32392
benwells22ab8ee2015-08-21 02:55:08393 component_loader_->LoadAll();
achuithd3da4f02017-03-23 20:05:29394 bool load_saved_extensions = true;
emaxx35e8b822017-04-11 02:04:29395 bool load_command_line_extensions = extensions_enabled_;
achuithd3da4f02017-03-23 20:05:29396#if defined(OS_CHROMEOS)
tbarzicd2a741e2017-06-28 20:37:54397 if (chromeos::ProfileHelper::IsSigninProfile(profile_) ||
398 chromeos::ProfileHelper::IsLockScreenAppProfile(profile_)) {
achuithd3da4f02017-03-23 20:05:29399 load_saved_extensions = false;
emaxx35e8b822017-04-11 02:04:29400 load_command_line_extensions = false;
401 }
achuithd3da4f02017-03-23 20:05:29402#endif
rdevlin.croninf2e1cb012017-05-27 01:27:59403 if (load_saved_extensions)
Devlin Cronineea1b7a2018-05-26 02:46:21404 InstalledLoader(this).LoadAllExtensions();
rdevlin.croninf2e1cb012017-05-27 01:27:59405
Nick Peterson8aa8e052019-05-22 23:17:01406 CheckManagementPolicy();
rdevlin.croninf2e1cb012017-05-27 01:27:59407 OnInstalledExtensionsLoaded();
408
Devlin Cronineea1b7a2018-05-26 02:46:21409 LoadExtensionsFromCommandLineFlag(::switches::kDisableExtensionsExcept);
emaxx35e8b822017-04-11 02:04:29410 if (load_command_line_extensions)
Devlin Cronineea1b7a2018-05-26 02:46:21411 LoadExtensionsFromCommandLineFlag(switches::kLoadExtension);
benwells22ab8ee2015-08-21 02:55:08412 EnabledReloadableExtensions();
413 MaybeFinishShutdownDelayed();
414 SetReadyAndNotifyListeners();
[email protected]ae4c37e2012-12-21 01:16:25415
Takumi Fujimoto43c8c00f2017-07-26 22:48:56416 UninstallMigratedExtensions();
417
benwells22ab8ee2015-08-21 02:55:08418 // TODO(erikkay): this should probably be deferred to a future point
419 // rather than running immediately at startup.
420 CheckForExternalUpdates();
[email protected]894bb502009-05-21 22:39:57421
benwells22ab8ee2015-08-21 02:55:08422 LoadGreylistFromPrefs();
rkaplowa8fd8d32015-02-25 21:27:56423}
[email protected]3350d712013-11-18 09:32:24424
rkaplowa8fd8d32015-02-25 21:27:56425void ExtensionService::EnabledReloadableExtensions() {
426 TRACE_EVENT0("browser,startup",
427 "ExtensionService::EnabledReloadableExtensions");
428
429 std::vector<std::string> extensions_to_enable;
achuith2f5578b2016-02-26 21:57:13430 for (const auto& e : registry_->disabled_extensions()) {
rkaplowa8fd8d32015-02-25 21:27:56431 if (extension_prefs_->GetDisableReasons(e->id()) ==
Devlin Cronineea1b7a2018-05-26 02:46:21432 disable_reason::DISABLE_RELOAD)
rkaplowa8fd8d32015-02-25 21:27:56433 extensions_to_enable.push_back(e->id());
rkaplowa8fd8d32015-02-25 21:27:56434 }
435 for (const std::string& extension : extensions_to_enable) {
436 EnableExtension(extension);
437 }
438}
439
440void ExtensionService::MaybeFinishShutdownDelayed() {
441 TRACE_EVENT0("browser,startup",
442 "ExtensionService::MaybeFinishShutdownDelayed");
443
Devlin Cronineea1b7a2018-05-26 02:46:21444 std::unique_ptr<ExtensionPrefs::ExtensionsInfo> delayed_info(
rkaplowa8fd8d32015-02-25 21:27:56445 extension_prefs_->GetAllDelayedInstallInfo());
446 for (size_t i = 0; i < delayed_info->size(); ++i) {
447 ExtensionInfo* info = delayed_info->at(i).get();
achuith2f5578b2016-02-26 21:57:13448 scoped_refptr<const Extension> extension(nullptr);
rkaplowa8fd8d32015-02-25 21:27:56449 if (info->extension_manifest) {
450 std::string error;
451 extension = Extension::Create(
452 info->extension_path, info->extension_location,
453 *info->extension_manifest,
454 extension_prefs_->GetDelayedInstallCreationFlags(info->extension_id),
455 info->extension_id, &error);
456 if (extension.get())
457 delayed_installs_.Insert(extension);
458 }
459 }
460 MaybeFinishDelayedInstallations();
Devlin Cronineea1b7a2018-05-26 02:46:21461 std::unique_ptr<ExtensionPrefs::ExtensionsInfo> delayed_info2(
rkaplowa8fd8d32015-02-25 21:27:56462 extension_prefs_->GetAllDelayedInstallInfo());
463 UMA_HISTOGRAM_COUNTS_100("Extensions.UpdateOnLoad",
464 delayed_info2->size() - delayed_info->size());
[email protected]6014d672008-12-05 00:38:25465}
466
[email protected]2d19eb6e2014-01-27 17:30:00467void ExtensionService::LoadGreylistFromPrefs() {
rkaplowa8fd8d32015-02-25 21:27:56468 TRACE_EVENT0("browser,startup", "ExtensionService::LoadGreylistFromPrefs");
469
dchengc963c7142016-04-08 03:55:22470 std::unique_ptr<ExtensionSet> all_extensions =
[email protected]f47f7172014-03-19 19:27:10471 registry_->GenerateInstalledExtensionsSet();
[email protected]2d19eb6e2014-01-27 17:30:00472
achuith2f5578b2016-02-26 21:57:13473 for (const auto& extension : *all_extensions) {
Devlin Cronineea1b7a2018-05-26 02:46:21474 const BlacklistState state =
achuith2f5578b2016-02-26 21:57:13475 extension_prefs_->GetExtensionBlacklistState(extension->id());
Devlin Cronineea1b7a2018-05-26 02:46:21476 if (state == BLACKLISTED_SECURITY_VULNERABILITY ||
477 state == BLACKLISTED_POTENTIALLY_UNWANTED ||
478 state == BLACKLISTED_CWS_POLICY_VIOLATION)
achuith2f5578b2016-02-26 21:57:13479 greylist_.Insert(extension);
[email protected]2d19eb6e2014-01-27 17:30:00480 }
481}
482
Devlin Cronineea1b7a2018-05-26 02:46:21483bool ExtensionService::UpdateExtension(const CRXFileInfo& file,
[email protected]044e86992014-01-24 22:59:11484 bool file_ownership_passed,
[email protected]31bb5ee62012-09-12 22:58:40485 CrxInstaller** out_crx_installer) {
[email protected]a29a517a2011-01-21 21:11:12486 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]3c4abc82012-10-22 22:25:54487 if (browser_terminating_) {
488 LOG(WARNING) << "Skipping UpdateExtension due to browser shutdown";
489 // Leak the temp file at extension_path. We don't want to add to the disk
490 // I/O burden at shutdown, we can't rely on the I/O completing anyway, and
491 // the file is in the OS temp directory which should be cleaned up for us.
492 return false;
493 }
[email protected]a8af9fdb2010-10-28 21:52:20494
ginkage553af3202015-02-04 12:39:09495 const std::string& id = file.extension_id;
496
Devlin Cronineea1b7a2018-05-26 02:46:21497 const PendingExtensionInfo* pending_extension_info =
[email protected]51a3bf8b2012-06-08 22:53:06498 pending_extension_manager()->GetById(id);
[email protected]8ef78fd2010-08-19 17:14:32499
[email protected]695b5712012-12-06 23:55:28500 const Extension* extension = GetInstalledExtension(id);
[email protected]51a3bf8b2012-06-08 22:53:06501 if (!pending_extension_info && !extension) {
[email protected]aa142702010-03-26 01:26:33502 LOG(WARNING) << "Will not update extension " << id
503 << " because it is not installed or pending";
504 // Delete extension_path since we're not creating a CrxInstaller
505 // that would do it for us.
asargentd50b18c2016-04-21 01:17:16506 if (file_ownership_passed &&
Devlin Cronineea1b7a2018-05-26 02:46:21507 !GetExtensionFileTaskRunner()->PostTask(
508 FROM_HERE,
509 base::BindOnce(&file_util::DeleteFile, file.path, false)))
[email protected]14908b72011-04-20 06:54:36510 NOTREACHED();
[email protected]420a0ec2011-06-01 01:07:03511
512 return false;
[email protected]e957fe52009-06-23 16:51:05513 }
Minh X. Nguyen30975342017-12-04 22:02:41514 // Either |pending_extension_info| or |extension| or both must not be null.
treibe960e282015-09-11 10:38:08515 scoped_refptr<CrxInstaller> installer(CrxInstaller::CreateSilent(this));
[email protected]6dfbbf82010-03-12 23:09:16516 installer->set_expected_id(id);
ginkage47e603e2015-02-27 08:42:41517 installer->set_expected_hash(file.expected_hash);
[email protected]464213a2013-10-15 01:06:48518 int creation_flags = Extension::NO_FLAGS;
[email protected]51a3bf8b2012-06-08 22:53:06519 if (pending_extension_info) {
520 installer->set_install_source(pending_extension_info->install_source());
pkotwicz31eb1e8ec2014-10-08 15:26:46521 installer->set_allow_silent_install(true);
treibe960e282015-09-11 10:38:08522 // If the extension came in disabled due to a permission increase, then
523 // don't grant it all the permissions. crbug.com/484214
524 bool has_permissions_increase =
Devlin Cronineea1b7a2018-05-26 02:46:21525 ExtensionPrefs::Get(profile_)->HasDisableReason(
526 id, disable_reason::DISABLE_PERMISSIONS_INCREASE);
treibe960e282015-09-11 10:38:08527 const base::Version& expected_version = pending_extension_info->version();
528 if (has_permissions_increase ||
529 pending_extension_info->remote_install() ||
530 !expected_version.IsValid()) {
[email protected]21db9ef2014-05-16 02:06:27531 installer->set_grant_permissions(false);
treibe960e282015-09-11 10:38:08532 } else {
533 installer->set_expected_version(expected_version,
534 false /* fail_install_if_unexpected */);
535 }
mamir0128d5a2016-07-15 20:55:48536 creation_flags = pending_extension_info->creation_flags();
[email protected]464213a2013-10-15 01:06:48537 if (pending_extension_info->mark_acknowledged())
[email protected]374ceb6f2014-07-02 19:25:34538 external_install_manager_->AcknowledgeExternalExtension(id);
Minh X. Nguyen30975342017-12-04 22:02:41539 // If the extension was installed from or has migrated to the webstore, or
540 // its auto-update URL is from the webstore, treat it as a webstore install.
541 // Note that we ignore some older extensions with blank auto-update URLs
542 // because we are mostly concerned with restrictions on NaCl extensions,
543 // which are newer.
544 if (!extension && extension_urls::IsWebstoreUpdateUrl(
545 pending_extension_info->update_url()))
546 creation_flags |= Extension::FROM_WEBSTORE;
547 } else {
548 // |extension| must not be null.
[email protected]5eb375e92010-11-26 07:50:41549 installer->set_install_source(extension->location());
[email protected]51a3bf8b2012-06-08 22:53:06550 }
[email protected]a12ce8b22012-01-17 18:40:53551
Minh X. Nguyen30975342017-12-04 22:02:41552 if (extension) {
553 installer->InitializeCreationFlagsForUpdate(extension, creation_flags);
[email protected]c30bda262014-06-19 04:10:13554 installer->set_do_not_sync(extension_prefs_->DoNotSync(id));
Minh X. Nguyen30975342017-12-04 22:02:41555 } else {
556 installer->set_creation_flags(creation_flags);
557 }
[email protected]044e86992014-01-24 22:59:11558 installer->set_delete_source(file_ownership_passed);
[email protected]cb0e50312011-05-09 15:03:07559 installer->set_install_cause(extension_misc::INSTALL_CAUSE_UPDATE);
ginkage553af3202015-02-04 12:39:09560 installer->InstallCrxFile(file);
[email protected]420a0ec2011-06-01 01:07:03561
562 if (out_crx_installer)
[email protected]dc24976f2013-06-02 21:15:09563 *out_crx_installer = installer.get();
[email protected]420a0ec2011-06-01 01:07:03564
565 return true;
[email protected]e957fe52009-06-23 16:51:05566}
567
catmullings98cd1942016-08-30 22:31:59568void ExtensionService::LoadExtensionsFromCommandLineFlag(
569 const char* switch_name) {
570 if (command_line_->HasSwitch(switch_name)) {
571 base::CommandLine::StringType path_list =
572 command_line_->GetSwitchValueNative(switch_name);
573 base::StringTokenizerT<base::CommandLine::StringType,
574 base::CommandLine::StringType::const_iterator>
575 t(path_list, FILE_PATH_LITERAL(","));
576 while (t.GetNext()) {
577 std::string extension_id;
Devlin Cronineea1b7a2018-05-26 02:46:21578 UnpackedInstaller::Create(this)->LoadFromCommandLine(
catmullings98cd1942016-08-30 22:31:59579 base::FilePath(t.token()), &extension_id, false /*only-allow-apps*/);
580 // Extension id is added to whitelist after its extension is loaded
michaelpga8ea0372017-04-06 20:41:35581 // because code is executed asynchronously. TODO(michaelpg): Remove this
582 // assumption so loading extensions does not have to be asynchronous:
583 // crbug.com/708354.
Devlin Cronineea1b7a2018-05-26 02:46:21584 if (switch_name == ::switches::kDisableExtensionsExcept)
catmullings98cd1942016-08-30 22:31:59585 disable_flag_exempted_extensions_.insert(extension_id);
586 }
587 }
588}
589
Michael Giuffrida573992d2018-02-08 00:48:44590// TODO(michaelpg): Group with other ExtensionRegistrar::Delegate overrides
591// according to header file once diffs have settled down.
592void ExtensionService::LoadExtensionForReload(
Devlin Cronineea1b7a2018-05-26 02:46:21593 const ExtensionId& extension_id,
Michael Giuffrida573992d2018-02-08 00:48:44594 const base::FilePath& path,
595 LoadErrorBehavior load_error_behavior) {
Toni Barzic667db0d32018-01-09 18:00:19596 if (delayed_installs_.Contains(extension_id) &&
597 FinishDelayedInstallationIfReady(extension_id,
598 true /*install_immediately*/)) {
[email protected]0db124b02012-11-07 04:55:05599 return;
600 }
601
[email protected]43ceb002012-02-10 23:19:15602 // If we're reloading a component extension, use the component extension
603 // loader's reloader.
604 if (component_loader_->Exists(extension_id)) {
605 component_loader_->Reload(extension_id);
606 return;
607 }
608
[email protected]e6090e42010-03-23 22:44:08609 // Check the installed extensions to see if what we're reloading was already
610 // installed.
dchengc963c7142016-04-08 03:55:22611 std::unique_ptr<ExtensionInfo> installed_extension(
[email protected]e6090e42010-03-23 22:44:08612 extension_prefs_->GetInstalledExtensionInfo(extension_id));
613 if (installed_extension.get() &&
614 installed_extension->extension_manifest.get()) {
Devlin Cronineea1b7a2018-05-26 02:46:21615 InstalledLoader(this).Load(*installed_extension, false);
[email protected]e6090e42010-03-23 22:44:08616 } else {
Michael Giuffrida573992d2018-02-08 00:48:44617 // Otherwise, the extension is unpacked (location LOAD). We must load it
618 // from the path.
619 CHECK(!path.empty()) << "ExtensionRegistrar should never ask to load an "
620 "unknown extension with no path";
Devlin Cronineea1b7a2018-05-26 02:46:21621 scoped_refptr<UnpackedInstaller> unpacked_installer =
622 UnpackedInstaller::Create(this);
Michael Giuffrida573992d2018-02-08 00:48:44623 unpacked_installer->set_be_noisy_on_failure(load_error_behavior ==
624 LoadErrorBehavior::kNoisy);
[email protected]bca4b832014-07-17 20:22:34625 unpacked_installer->Load(path);
[email protected]e6090e42010-03-23 22:44:08626 }
[email protected]9cddd4702009-07-27 22:09:40627}
628
[email protected]bca4b832014-07-17 20:22:34629void ExtensionService::ReloadExtension(const std::string& extension_id) {
Michael Giuffrida573992d2018-02-08 00:48:44630 extension_registrar_.ReloadExtension(extension_id, LoadErrorBehavior::kNoisy);
[email protected]bca4b832014-07-17 20:22:34631}
632
633void ExtensionService::ReloadExtensionWithQuietFailure(
634 const std::string& extension_id) {
Michael Giuffrida573992d2018-02-08 00:48:44635 extension_registrar_.ReloadExtension(extension_id, LoadErrorBehavior::kQuiet);
[email protected]bca4b832014-07-17 20:22:34636}
637
[email protected]757d60a2014-05-23 00:11:44638bool ExtensionService::UninstallExtension(
639 // "transient" because the process of uninstalling may cause the reference
640 // to become invalid. Instead, use |extenson->id()|.
641 const std::string& transient_extension_id,
Devlin Cronineea1b7a2018-05-26 02:46:21642 UninstallReason reason,
[email protected]757d60a2014-05-23 00:11:44643 base::string16* error) {
[email protected]a29a517a2011-01-21 21:11:12644 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]a8af9fdb2010-10-28 21:52:20645
[email protected]757d60a2014-05-23 00:11:44646 scoped_refptr<const Extension> extension =
647 GetInstalledExtension(transient_extension_id);
[email protected]631cf822009-05-15 07:01:25648
[email protected]e7afe2452010-08-22 16:19:13649 // Callers should not send us nonexistent extensions.
[email protected]dc24976f2013-06-02 21:15:09650 CHECK(extension.get());
[email protected]9f1087e2009-06-15 17:29:32651
binjincccacef2014-10-13 19:00:20652 ManagementPolicy* by_policy = system_->management_policy();
[email protected]95da88c42011-03-31 10:07:33653 // Policy change which triggers an uninstall will always set
654 // |external_uninstall| to true so this is the only way to uninstall
655 // managed extensions.
[email protected]90878c52014-04-04 18:21:02656 // Shared modules being uninstalled will also set |external_uninstall| to true
657 // so that we can guarantee users don't uninstall a shared module.
658 // (crbug.com/273300)
659 // TODO(rdevlin.cronin): This is probably not right. We should do something
660 // else, like include an enum IS_INTERNAL_UNINSTALL or IS_USER_UNINSTALL so
661 // we don't do this.
[email protected]cc2f55c2014-07-08 02:19:04662 bool external_uninstall =
Devlin Cronineea1b7a2018-05-26 02:46:21663 (reason == UNINSTALL_REASON_INTERNAL_MANAGEMENT) ||
664 (reason == UNINSTALL_REASON_COMPONENT_REMOVED) ||
665 (reason == UNINSTALL_REASON_REINSTALL) ||
666 (reason == UNINSTALL_REASON_ORPHANED_EXTERNAL_EXTENSION) ||
667 (reason == UNINSTALL_REASON_ORPHANED_SHARED_MODULE) ||
668 (reason == UNINSTALL_REASON_SYNC &&
669 util::WasInstalledByCustodian(extension->id(), profile_));
[email protected]65187152012-06-02 13:14:14670 if (!external_uninstall &&
binjincccacef2014-10-13 19:00:20671 (!by_policy->UserMayModifySettings(extension.get(), error) ||
672 by_policy->MustRemainInstalled(extension.get(), error))) {
[email protected]ad50def52011-10-19 23:17:07673 content::NotificationService::current()->Notify(
Devlin Cronineea1b7a2018-05-26 02:46:21674 NOTIFICATION_EXTENSION_UNINSTALL_NOT_ALLOWED,
[email protected]6c2381d2011-10-19 02:52:53675 content::Source<Profile>(profile_),
[email protected]dc24976f2013-06-02 21:15:09676 content::Details<const Extension>(extension.get()));
[email protected]d6ebc9792011-04-07 18:18:33677 return false;
678 }
[email protected]95da88c42011-03-31 10:07:33679
juncai33e462102015-05-18 20:48:44680 InstallVerifier::Get(GetBrowserContext())->Remove(extension->id());
[email protected]ffd2f79e2013-11-14 00:11:46681
[email protected]9b217652010-10-08 22:04:23682 UMA_HISTOGRAM_ENUMERATION("Extensions.UninstallType",
[email protected]7fa19f82010-12-21 19:40:08683 extension->GetType(), 100);
treib2e0517f92015-05-07 23:15:36684 RecordPermissionMessagesHistogram(extension.get(), "Uninstall");
[email protected]9b217652010-10-08 22:04:23685
[email protected]831aa212010-03-26 13:55:19686 // Unload before doing more cleanup to ensure that nothing is hanging on to
687 // any of these resources.
limasdf0deef2042017-05-03 19:17:17688 UnloadExtension(extension->id(), UnloadedExtensionReason::UNINSTALL);
asargent96c7ec42016-05-27 02:45:47689 if (registry_->blacklisted_extensions().Contains(extension->id()))
690 registry_->RemoveBlacklisted(extension->id());
[email protected]831aa212010-03-26 13:55:19691
[email protected]9f1087e2009-06-15 17:29:32692 // Tell the backend to start deleting installed extensions on the file thread.
[email protected]12075d12013-02-27 05:38:05693 if (!Manifest::IsUnpackedLocation(extension->location())) {
Devlin Cronineea1b7a2018-05-26 02:46:21694 if (!GetExtensionFileTaskRunner()->PostTask(
[email protected]7f8f24f2012-11-15 19:40:14695 FROM_HERE,
tzik8d880ee2017-04-20 19:46:24696 base::BindOnce(&ExtensionService::UninstallExtensionOnFileThread,
697 extension->id(), profile_, install_directory_,
698 extension->path())))
[email protected]14908b72011-04-20 06:54:36699 NOTREACHED();
[email protected]9f1087e2009-06-15 17:29:32700 }
701
Devlin Cronineea1b7a2018-05-26 02:46:21702 DataDeleter::StartDeleting(profile_, extension.get());
[email protected]0d6ec3a72011-09-02 02:09:43703
Michael Giuffridafcb420362017-10-11 21:50:26704 extension_registrar_.UntrackTerminatedExtension(extension->id());
[email protected]211030342010-09-30 18:41:06705
706 // Notify interested parties that we've uninstalled this extension.
[email protected]e43c61f2014-07-20 21:46:34707 ExtensionRegistry::Get(profile_)
708 ->TriggerOnUninstalled(extension.get(), reason);
[email protected]d6ebc9792011-04-07 18:18:33709
[email protected]757d60a2014-05-23 00:11:44710 delayed_installs_.Remove(extension->id());
[email protected]0db124b02012-11-07 04:55:05711
[email protected]757d60a2014-05-23 00:11:44712 extension_prefs_->OnExtensionUninstalled(
713 extension->id(), extension->location(), external_uninstall);
[email protected]d4eda592013-09-18 03:37:57714
[email protected]333b1de2011-09-12 18:28:50715 // Track the uninstallation.
[email protected]49098f702011-10-13 03:47:18716 UMA_HISTOGRAM_ENUMERATION("Extensions.ExtensionUninstalled", 1, 2);
717
[email protected]d6ebc9792011-04-07 18:18:33718 return true;
[email protected]c10da4b02010-03-25 14:38:32719}
720
[email protected]5a145e82014-05-29 22:19:07721// static
722void ExtensionService::UninstallExtensionOnFileThread(
723 const std::string& id,
724 Profile* profile,
725 const base::FilePath& install_dir,
726 const base::FilePath& extension_path) {
Devlin Cronineea1b7a2018-05-26 02:46:21727 ExtensionAssetsManager* assets_manager =
728 ExtensionAssetsManager::GetInstance();
[email protected]5a145e82014-05-29 22:19:07729 assets_manager->UninstallExtension(id, profile, install_dir, extension_path);
730}
731
[email protected]c3cfb012011-04-06 22:07:35732bool ExtensionService::IsExtensionEnabled(
733 const std::string& extension_id) const {
Michael Giuffrida6397c592017-10-09 20:46:53734 return extension_registrar_.IsExtensionEnabled(extension_id);
[email protected]c3cfb012011-04-06 22:07:35735}
736
[email protected]eaa7dd182010-12-14 11:09:00737void ExtensionService::EnableExtension(const std::string& extension_id) {
[email protected]a29a517a2011-01-21 21:11:12738 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
Michael Giuffrida6397c592017-10-09 20:46:53739 extension_registrar_.EnableExtension(extension_id);
[email protected]0c6da502009-08-14 22:32:39740}
741
treibc1192322015-05-20 12:56:07742void ExtensionService::DisableExtension(const std::string& extension_id,
743 int disable_reasons) {
[email protected]a29a517a2011-01-21 21:11:12744 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
Michael Giuffrida6397c592017-10-09 20:46:53745 extension_registrar_.DisableExtension(extension_id, disable_reasons);
[email protected]1784e83a2009-09-08 21:01:52746}
747
Ivan Sandrk4a55dc22018-05-17 18:14:48748void ExtensionService::DisableExtensionWithSource(
749 const Extension* source_extension,
750 const std::string& extension_id,
Devlin Cronineea1b7a2018-05-26 02:46:21751 disable_reason::DisableReason disable_reasons) {
Ivan Sandrk4a55dc22018-05-17 18:14:48752 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
753
Devlin Cronineea1b7a2018-05-26 02:46:21754 DCHECK(disable_reasons == disable_reason::DISABLE_USER_ACTION ||
755 disable_reasons == disable_reason::DISABLE_BLOCKED_BY_POLICY);
756 if (disable_reasons == disable_reason::DISABLE_BLOCKED_BY_POLICY) {
Ivan Sandrk4a55dc22018-05-17 18:14:48757 DCHECK(Manifest::IsPolicyLocation(source_extension->location()) ||
758 Manifest::IsComponentLocation(source_extension->location()));
759 }
760
David Bertoni58c113a2019-08-02 19:53:26761 const Extension* extension = registry_->GetExtensionById(
762 extension_id, ExtensionRegistry::COMPATIBILITY);
Ivan Sandrk4a55dc22018-05-17 18:14:48763 CHECK(system_->management_policy()->ExtensionMayModifySettings(
764 source_extension, extension, nullptr));
765 extension_registrar_.DisableExtension(extension_id, disable_reasons);
766}
767
mtomasz294bb3e2017-01-24 02:17:52768void ExtensionService::DisableUserExtensionsExcept(
[email protected]1abf05e2013-07-09 17:04:36769 const std::vector<std::string>& except_ids) {
Devlin Cronineea1b7a2018-05-26 02:46:21770 ManagementPolicy* management_policy = system_->management_policy();
771 ExtensionList to_disable;
[email protected]e516e4c2013-06-12 17:41:14772
achuith2f5578b2016-02-26 21:57:13773 for (const auto& extension : registry_->enabled_extensions()) {
774 if (management_policy->UserMayModifySettings(extension.get(), nullptr))
775 to_disable.push_back(extension);
[email protected]e516e4c2013-06-12 17:41:14776 }
777
achuith2f5578b2016-02-26 21:57:13778 for (const auto& extension : registry_->terminated_extensions()) {
779 if (management_policy->UserMayModifySettings(extension.get(), nullptr))
780 to_disable.push_back(extension);
781 }
782
783 for (const auto& extension : to_disable) {
784 if (extension->was_installed_by_default() &&
[email protected]3082fe32013-08-06 11:12:38785 extension_urls::IsWebstoreUpdateUrl(
Devlin Cronineea1b7a2018-05-26 02:46:21786 ManifestURL::GetUpdateURL(extension.get())))
[email protected]3082fe32013-08-06 11:12:38787 continue;
achuith2f5578b2016-02-26 21:57:13788 const std::string& id = extension->id();
Jan Wilken Dörrieade79222019-06-06 19:01:12789 if (!base::Contains(except_ids, id))
Devlin Cronineea1b7a2018-05-26 02:46:21790 DisableExtension(id, disable_reason::DISABLE_USER_ACTION);
[email protected]e516e4c2013-06-12 17:41:14791 }
792}
793
mlerman6a37b6a42014-11-26 22:10:53794// Extensions that are not locked, components or forced by policy should be
795// locked. Extensions are no longer considered enabled or disabled. Blacklisted
796// extensions are now considered both blacklisted and locked.
797void ExtensionService::BlockAllExtensions() {
798 if (block_extensions_)
799 return;
800 block_extensions_ = true;
801
802 // Blacklisted extensions are already unloaded, need not be blocked.
dchengc963c7142016-04-08 03:55:22803 std::unique_ptr<ExtensionSet> extensions =
mlerman6a37b6a42014-11-26 22:10:53804 registry_->GenerateInstalledExtensionsSet(ExtensionRegistry::ENABLED |
805 ExtensionRegistry::DISABLED |
806 ExtensionRegistry::TERMINATED);
807
achuith2f5578b2016-02-26 21:57:13808 for (const auto& extension : *extensions) {
mlerman6a37b6a42014-11-26 22:10:53809 const std::string& id = extension->id();
810
811 if (!CanBlockExtension(extension.get()))
812 continue;
813
814 registry_->RemoveEnabled(id);
815 registry_->RemoveDisabled(id);
816 registry_->RemoveTerminated(id);
817
818 registry_->AddBlocked(extension.get());
Devlin Cronineea1b7a2018-05-26 02:46:21819 UnloadExtension(id, UnloadedExtensionReason::LOCK_ALL);
mlerman6a37b6a42014-11-26 22:10:53820 }
821}
822
823// All locked extensions should revert to being either enabled or disabled
824// as appropriate.
825void ExtensionService::UnblockAllExtensions() {
826 block_extensions_ = false;
dchengc963c7142016-04-08 03:55:22827 std::unique_ptr<ExtensionSet> to_unblock =
mlerman6a37b6a42014-11-26 22:10:53828 registry_->GenerateInstalledExtensionsSet(ExtensionRegistry::BLOCKED);
829
achuith2f5578b2016-02-26 21:57:13830 for (const auto& extension : *to_unblock) {
mlerman6a37b6a42014-11-26 22:10:53831 registry_->RemoveBlocked(extension->id());
832 AddExtension(extension.get());
833 }
Owen Minb71016d2018-01-11 01:51:49834 // While extensions are blocked, we won't display any external install
835 // warnings. Now that they are unblocked, we should update the error.
836 external_install_manager_->UpdateExternalExtensionAlert();
mlerman6a37b6a42014-11-26 22:10:53837}
838
[email protected]eaa7dd182010-12-14 11:09:00839void ExtensionService::GrantPermissionsAndEnableExtension(
[email protected]009633c2013-03-07 22:08:28840 const Extension* extension) {
841 GrantPermissions(extension);
treib2e0517f92015-05-07 23:15:36842 RecordPermissionMessagesHistogram(extension, "ReEnable");
[email protected]8d888c12010-11-30 00:00:25843 EnableExtension(extension->id());
844}
845
[email protected]009633c2013-03-07 22:08:28846void ExtensionService::GrantPermissions(const Extension* extension) {
[email protected]be083862012-09-01 03:53:45847 CHECK(extension);
Devlin Cronineea1b7a2018-05-26 02:46:21848 PermissionsUpdater(profile()).GrantActivePermissions(extension);
[email protected]be083862012-09-01 03:53:45849}
850
[email protected]fe2dd7742011-04-19 22:52:49851// static
852void ExtensionService::RecordPermissionMessagesHistogram(
[email protected]13c68b62013-05-17 11:29:05853 const Extension* extension, const char* histogram) {
[email protected]de415552013-01-23 04:12:17854 // Since this is called from multiple sources, and since the histogram macros
855 // use statics, we need to manually lookup the histogram ourselves.
treib2e0517f92015-05-07 23:15:36856 base::HistogramBase* counter = base::LinearHistogram::FactoryGet(
857 base::StringPrintf("Extensions.Permissions_%s3", histogram),
858 1,
859 APIPermission::kEnumBoundary,
860 APIPermission::kEnumBoundary + 1,
861 base::HistogramBase::kUmaTargetedHistogramFlag);
862
863 base::HistogramBase* counter_has_any = base::BooleanHistogram::FactoryGet(
864 base::StringPrintf("Extensions.HasPermissions_%s3", histogram),
865 base::HistogramBase::kUmaTargetedHistogramFlag);
866
867 PermissionIDSet permissions =
Devlin Cronineea1b7a2018-05-26 02:46:21868 PermissionMessageProvider::Get()->GetAllPermissionIDs(
rdevlin.cronine2d0fd02015-09-24 22:35:49869 extension->permissions_data()->active_permissions(),
treib2e0517f92015-05-07 23:15:36870 extension->GetType());
871 counter_has_any->AddBoolean(!permissions.empty());
872 for (const PermissionID& id : permissions)
873 counter->Add(id.id());
[email protected]fe2dd7742011-04-19 22:52:49874}
875
Michael Giuffrida6397c592017-10-09 20:46:53876// TODO(michaelpg): Group with other ExtensionRegistrar::Delegate overrides
877// according to header file once diffs have settled down.
878void ExtensionService::PostActivateExtension(
Michael Giuffrida19a55982018-02-10 03:03:26879 scoped_refptr<const Extension> extension) {
[email protected]dcc47642014-03-26 22:03:49880 // TODO(kalman): Convert ExtensionSpecialStoragePolicy to a
881 // BrowserContextKeyedService and use ExtensionRegistryObserver.
Michael Giuffrida6397c592017-10-09 20:46:53882 profile_->GetExtensionSpecialStoragePolicy()->GrantRightsForExtension(
Devlin Croninb2be9a6a2019-06-14 20:08:19883 extension.get());
[email protected]c8d407e2011-04-28 21:27:17884
[email protected]dcc47642014-03-26 22:03:49885 // TODO(kalman): This is broken. The crash reporter is process-wide so doesn't
886 // work properly multi-profile. Besides which, it should be using
887 // ExtensionRegistryObserver. See http://crbug.com/355029.
[email protected]c8d407e2011-04-28 21:27:17888 UpdateActiveExtensionsInCrashReporter();
889
Devlin Cronineea1b7a2018-05-26 02:46:21890 const PermissionsData* permissions_data = extension->permissions_data();
[email protected]d695bb12014-06-05 16:16:30891
[email protected]c8d407e2011-04-28 21:27:17892 // If the extension has permission to load chrome://favicon/ resources we need
893 // to make sure that the FaviconSource is registered with the
894 // ChromeURLDataManager.
[email protected]d695bb12014-06-05 16:16:30895 if (permissions_data->HasHostPermission(GURL(chrome::kChromeUIFaviconURL))) {
Victor Hugo Vianna Silvaed441482019-06-27 12:40:40896 content::URLDataSource::Add(
897 profile_, std::make_unique<FaviconSource>(
898 profile_, chrome::FaviconUrlFormat::kFaviconLegacy));
[email protected]c8d407e2011-04-28 21:27:17899 }
[email protected]b07e606e2012-09-15 20:16:15900
[email protected]b07e606e2012-09-15 20:16:15901 // Same for chrome://theme/ resources.
[email protected]d695bb12014-06-05 16:16:30902 if (permissions_data->HasHostPermission(GURL(chrome::kChromeUIThemeURL))) {
Lei Zhangc77274da2018-08-28 23:14:00903 content::URLDataSource::Add(profile_,
904 std::make_unique<ThemeSource>(profile_));
[email protected]b07e606e2012-09-15 20:16:15905 }
[email protected]62d30f42009-10-01 22:36:06906}
907
Michael Giuffrida6397c592017-10-09 20:46:53908// TODO(michaelpg): Group with other ExtensionRegistrar::Delegate overrides
909// according to header file once diffs have settled down.
Michael Giuffrida023e3532017-09-28 23:21:21910void ExtensionService::PostDeactivateExtension(
911 scoped_refptr<const Extension> extension) {
[email protected]dcc47642014-03-26 22:03:49912 // TODO(kalman): Convert ExtensionSpecialStoragePolicy to a
913 // BrowserContextKeyedService and use ExtensionRegistryObserver.
Michael Giuffrida023e3532017-09-28 23:21:21914 profile_->GetExtensionSpecialStoragePolicy()->RevokeRightsForExtension(
915 extension.get());
[email protected]c8d407e2011-04-28 21:27:17916
[email protected]b777b332011-04-16 04:01:08917#if defined(OS_CHROMEOS)
[email protected]ac66e452013-01-11 09:21:23918 // Revoke external file access for the extension from its file system context.
919 // It is safe to access the extension's storage partition at this point. The
920 // storage partition may get destroyed only after the extension gets unloaded.
Devlin Cronineea1b7a2018-05-26 02:46:21921 GURL site = util::GetSiteForExtensionId(extension->id(), profile_);
[email protected]cd501a72014-08-22 19:58:31922 storage::FileSystemContext* filesystem_context =
923 BrowserContext::GetStoragePartitionForSite(profile_, site)
924 ->GetFileSystemContext();
[email protected]f19bbf62013-07-09 01:22:32925 if (filesystem_context && filesystem_context->external_backend()) {
Michael Giuffrida6397c592017-10-09 20:46:53926 filesystem_context->external_backend()->RevokeAccessForExtension(
927 extension->id());
[email protected]62d30f42009-10-01 22:36:06928 }
[email protected]c8d407e2011-04-28 21:27:17929#endif
930
[email protected]dcc47642014-03-26 22:03:49931 // TODO(kalman): This is broken. The crash reporter is process-wide so doesn't
932 // work properly multi-profile. Besides which, it should be using
933 // ExtensionRegistryObserver::OnExtensionLoaded. See http://crbug.com/355029.
[email protected]c8d407e2011-04-28 21:27:17934 UpdateActiveExtensionsInCrashReporter();
[email protected]62d30f42009-10-01 22:36:06935}
936
[email protected]599539802014-01-07 23:06:00937content::BrowserContext* ExtensionService::GetBrowserContext() const {
938 // Implemented in the .cc file to avoid adding a profile.h dependency to
939 // extension_service.h.
940 return profile_;
941}
942
[email protected]25ae0152011-11-18 14:40:02943bool ExtensionService::is_ready() {
[email protected]4a10006a2013-05-17 23:18:35944 return ready_->is_signaled();
[email protected]25ae0152011-11-18 14:40:02945}
946
[email protected]4ee07c62012-08-21 12:40:42947void ExtensionService::CheckManagementPolicy() {
Devlin Cronineea1b7a2018-05-26 02:46:21948 std::map<std::string, disable_reason::DisableReason> to_disable;
binjin8e3d0182014-12-04 16:44:28949 std::vector<std::string> to_enable;
[email protected]695b5712012-12-06 23:55:28950
Karan Bhatia2a117232017-08-23 00:24:56951 // Loop through the extensions list, finding extensions we need to disable.
achuith2f5578b2016-02-26 21:57:13952 for (const auto& extension : registry_->enabled_extensions()) {
Devlin Cronineea1b7a2018-05-26 02:46:21953 disable_reason::DisableReason disable_reason = disable_reason::DISABLE_NONE;
[email protected]0d54b682013-11-05 14:15:36954 if (system_->management_policy()->MustRemainDisabled(
binjin8e3d0182014-12-04 16:44:28955 extension.get(), &disable_reason, nullptr))
[email protected]0d54b682013-11-05 14:15:36956 to_disable[extension->id()] = disable_reason;
[email protected]aa96d3a2010-08-21 08:45:25957 }
958
Devlin Cronineea1b7a2018-05-26 02:46:21959 ExtensionManagement* management =
960 ExtensionManagementFactory::GetForBrowserContext(profile());
961 PermissionsUpdater(profile()).SetDefaultPolicyHostRestrictions(
Devlin Cronin7e0f41ff2018-05-16 17:19:36962 management->GetDefaultPolicyBlockedHosts(),
963 management->GetDefaultPolicyAllowedHosts());
nrpetere33d2a5b2017-04-25 00:12:31964 for (const auto& extension : registry_->enabled_extensions()) {
965 bool uses_default =
Devlin Cronin7e0f41ff2018-05-16 17:19:36966 management->UsesDefaultPolicyHostRestrictions(extension.get());
nrpetere33d2a5b2017-04-25 00:12:31967 if (uses_default) {
Devlin Cronineea1b7a2018-05-26 02:46:21968 PermissionsUpdater(profile()).SetUsesDefaultHostRestrictions(
nrpetere33d2a5b2017-04-25 00:12:31969 extension.get());
970 } else {
Devlin Cronineea1b7a2018-05-26 02:46:21971 PermissionsUpdater(profile()).SetPolicyHostRestrictions(
Devlin Cronin7e0f41ff2018-05-16 17:19:36972 extension.get(), management->GetPolicyBlockedHosts(extension.get()),
973 management->GetPolicyAllowedHosts(extension.get()));
nrpetere33d2a5b2017-04-25 00:12:31974 }
975 }
binjin8e3d0182014-12-04 16:44:28976
977 // Loop through the disabled extension list, find extensions to re-enable
Karan Bhatia2a117232017-08-23 00:24:56978 // automatically. These extensions are exclusive from the |to_disable| list
979 // constructed above, since disabled_extensions() and enabled_extensions() are
980 // supposed to be mutually exclusive.
achuith2f5578b2016-02-26 21:57:13981 for (const auto& extension : registry_->disabled_extensions()) {
Karan Bhatia2a117232017-08-23 00:24:56982 int disable_reasons = extension_prefs_->GetDisableReasons(extension->id());
binjin8e3d0182014-12-04 16:44:28983
Karan Bhatia2a117232017-08-23 00:24:56984 // Find all extensions disabled due to minimum version requirement and
985 // management policy but now satisfying it.
986 if (management->CheckMinimumVersion(extension.get(), nullptr)) {
Devlin Cronineea1b7a2018-05-26 02:46:21987 disable_reasons &= (~disable_reason::DISABLE_UPDATE_REQUIRED_BY_POLICY);
Karan Bhatia2a117232017-08-23 00:24:56988 }
989
990 if (!system_->management_policy()->MustRemainDisabled(extension.get(),
991 nullptr, nullptr)) {
Devlin Cronineea1b7a2018-05-26 02:46:21992 disable_reasons &= (~disable_reason::DISABLE_BLOCKED_BY_POLICY);
Karan Bhatia2a117232017-08-23 00:24:56993 }
994
995 extension_prefs_->ReplaceDisableReasons(extension->id(), disable_reasons);
Devlin Cronineea1b7a2018-05-26 02:46:21996 if (disable_reasons == disable_reason::DISABLE_NONE)
Karan Bhatia2a117232017-08-23 00:24:56997 to_enable.push_back(extension->id());
998 }
[email protected]0d54b682013-11-05 14:15:36999
achuith2f5578b2016-02-26 21:57:131000 for (const auto& i : to_disable)
1001 DisableExtension(i.first, i.second);
binjin8e3d0182014-12-04 16:44:281002
Karan Bhatia2a117232017-08-23 00:24:561003 // No extension is getting re-enabled here after disabling because |to_enable|
1004 // is mutually exclusive to |to_disable|.
binjin8e3d0182014-12-04 16:44:281005 for (const std::string& id : to_enable)
1006 EnableExtension(id);
1007
1008 if (updater_.get()) {
1009 // Find all extensions disabled due to minimum version requirement from
1010 // policy (including the ones that got disabled just now), and check
1011 // for update.
Devlin Cronineea1b7a2018-05-26 02:46:211012 ExtensionUpdater::CheckParams to_recheck;
achuith2f5578b2016-02-26 21:57:131013 for (const auto& extension : registry_->disabled_extensions()) {
binjin8e3d0182014-12-04 16:44:281014 if (extension_prefs_->GetDisableReasons(extension->id()) ==
Devlin Cronineea1b7a2018-05-26 02:46:211015 disable_reason::DISABLE_UPDATE_REQUIRED_BY_POLICY) {
binjin8e3d0182014-12-04 16:44:281016 // The minimum version check is the only thing holding this extension
1017 // back, so check if it can be updated to fix that.
1018 to_recheck.ids.push_back(extension->id());
1019 }
1020 }
1021 if (!to_recheck.ids.empty())
Minh X. Nguyen722b9682018-04-25 21:46:481022 updater_->CheckNow(std::move(to_recheck));
binjin8e3d0182014-12-04 16:44:281023 }
Alexander Nohe2c5402882019-04-11 21:56:331024
1025 // Check the disabled extensions to see if any should be force uninstalled.
1026 std::vector<ExtensionId> remove_list;
1027 for (const auto& extension : registry_->disabled_extensions()) {
1028 if (system_->management_policy()->ShouldForceUninstall(extension.get(),
1029 nullptr /*error*/)) {
1030 remove_list.push_back(extension->id());
1031 }
1032 }
1033 for (auto extension_id : remove_list) {
1034 base::string16 error;
1035 if (!UninstallExtension(extension_id, UNINSTALL_REASON_INTERNAL_MANAGEMENT,
1036 &error)) {
1037 SYSLOG(WARNING) << "Extension with id " << extension_id
1038 << " failed to be uninstalled via policy: " << error;
1039 }
1040 }
[email protected]aa96d3a2010-08-21 08:45:251041}
1042
[email protected]31206602011-04-13 23:07:321043void ExtensionService::CheckForUpdatesSoon() {
[email protected]90878c52014-04-04 18:21:021044 // This can legitimately happen in unit tests.
1045 if (!updater_.get())
1046 return;
1047
raphael.kubo.da.costa8527f942016-11-15 17:03:511048 updater_->CheckSoon();
[email protected]c3cfb012011-04-06 22:07:351049}
1050
[email protected]8e4560b62011-01-14 10:09:141051// Some extensions will autoupdate themselves externally from Chrome. These
rkaplowa8fd8d32015-02-25 21:27:561052// are typically part of some larger client application package. To support
1053// these, the extension will register its location in the preferences file
[email protected]8e4560b62011-01-14 10:09:141054// (and also, on Windows, in the registry) and this code will periodically
1055// check that location for a .crx file, which it will then install locally if
1056// a new version is available.
Devlin Cronin9722a722017-12-16 03:35:101057// Errors are reported through LoadErrorReporter. Success is not reported.
[email protected]eaa7dd182010-12-14 11:09:001058void ExtensionService::CheckForExternalUpdates() {
lazyboy77214d3c2017-04-04 16:46:121059 if (external_updates_disabled_for_test_)
1060 return;
1061
[email protected]a29a517a2011-01-21 21:11:121062 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
rkaplowa8fd8d32015-02-25 21:27:561063 TRACE_EVENT0("browser,startup", "ExtensionService::CheckForExternalUpdates");
1064 SCOPED_UMA_HISTOGRAM_TIMER("Extensions.CheckForExternalUpdatesTime");
[email protected]8e4560b62011-01-14 10:09:141065
1066 // Note that this installation is intentionally silent (since it didn't
1067 // go through the front-end). Extensions that are registered in this
1068 // way are effectively considered 'pre-bundled', and so implicitly
1069 // trusted. In general, if something has HKLM or filesystem access,
1070 // they could install an extension manually themselves anyway.
[email protected]a29a517a2011-01-21 21:11:121071
[email protected]8e4560b62011-01-14 10:09:141072 // Ask each external extension provider to give us a call back for each
1073 // extension they know about. See OnExternalExtension(File|UpdateUrl)Found.
achuith2f5578b2016-02-26 21:57:131074 for (const auto& provider : external_extension_providers_)
[email protected]8e4560b62011-01-14 10:09:141075 provider->VisitRegisteredExtension();
[email protected]8e4560b62011-01-14 10:09:141076
[email protected]50067e52011-10-20 23:17:071077 // Do any required work that we would have done after completion of all
1078 // providers.
[email protected]373daf972014-04-10 01:50:441079 if (external_extension_providers_.empty())
[email protected]50067e52011-10-20 23:17:071080 OnAllExternalProvidersReady();
[email protected]9f1087e2009-06-15 17:29:321081}
1082
[email protected]50067e52011-10-20 23:17:071083void ExtensionService::OnExternalProviderReady(
lazyboye8634172016-01-28 00:10:481084 const ExternalProviderInterface* provider) {
Istiaque Ahmedf6e72622017-09-08 23:14:171085 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]50067e52011-10-20 23:17:071086 CHECK(provider->IsReady());
[email protected]a29a517a2011-01-21 21:11:121087
1088 // An external provider has finished loading. We only take action
[email protected]8e4560b62011-01-14 10:09:141089 // if all of them are finished. So we check them first.
[email protected]94fde232012-04-27 10:22:301090 if (AreAllExternalProvidersReady())
1091 OnAllExternalProvidersReady();
1092}
1093
1094bool ExtensionService::AreAllExternalProvidersReady() const {
achuith2f5578b2016-02-26 21:57:131095 for (const auto& provider : external_extension_providers_) {
1096 if (!provider->IsReady())
[email protected]94fde232012-04-27 10:22:301097 return false;
[email protected]8e4560b62011-01-14 10:09:141098 }
[email protected]94fde232012-04-27 10:22:301099 return true;
[email protected]50067e52011-10-20 23:17:071100}
1101
1102void ExtensionService::OnAllExternalProvidersReady() {
Istiaque Ahmedf6e72622017-09-08 23:14:171103 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]50067e52011-10-20 23:17:071104 // Install any pending extensions.
[email protected]94fde232012-04-27 10:22:301105 if (update_once_all_providers_are_ready_ && updater()) {
1106 update_once_all_providers_are_ready_ = false;
Devlin Cronineea1b7a2018-05-26 02:46:211107 ExtensionUpdater::CheckParams params;
Minh X. Nguyen722b9682018-04-25 21:46:481108 params.callback =
1109 external_updates_finished_callback_.is_null()
1110 ? base::OnceClosure()
1111 : base::BindOnce(
1112 [](base::RepeatingClosure callback) { callback.Run(); },
1113 external_updates_finished_callback_);
Devlin Cronin2b3acda2019-05-30 19:11:371114 // We have to mark high-priority extensions (such as policy-forced
1115 // extensions or external component extensions) with foreground fetch
1116 // priority; otherwise their installation may be throttled by bandwidth
1117 // limits.
1118 // See https://crbug.com/904600 and https://crbug.com/965686.
1119 if (pending_extension_manager_.HasHighPriorityPendingExtension()) {
Oleg Davydov6541a64f2019-04-17 13:17:331120 params.fetch_priority = ManifestFetchData::FOREGROUND;
1121 }
Minh X. Nguyen722b9682018-04-25 21:46:481122 updater()->CheckNow(std::move(params));
[email protected]8e4560b62011-01-14 10:09:141123 }
1124
1125 // Uninstall all the unclaimed extensions.
Devlin Cronineea1b7a2018-05-26 02:46:211126 std::unique_ptr<ExtensionPrefs::ExtensionsInfo> extensions_info(
[email protected]8e4560b62011-01-14 10:09:141127 extension_prefs_->GetInstalledExtensionsInfo());
1128 for (size_t i = 0; i < extensions_info->size(); ++i) {
1129 ExtensionInfo* info = extensions_info->at(i).get();
[email protected]1d5e58b2013-01-31 08:41:401130 if (Manifest::IsExternalLocation(info->extension_location))
[email protected]8e4560b62011-01-14 10:09:141131 CheckExternalUninstall(info->extension_id);
1132 }
[email protected]e5af875f2011-10-10 21:09:141133
[email protected]373daf972014-04-10 01:50:441134 error_controller_->ShowErrorIfNeeded();
[email protected]a9aa5932012-01-25 08:27:401135
[email protected]374ceb6f2014-07-02 19:25:341136 external_install_manager_->UpdateExternalExtensionAlert();
[email protected]e5af875f2011-10-10 21:09:141137}
1138
limasdf0deef2042017-05-03 19:17:171139void ExtensionService::UnloadExtension(const std::string& extension_id,
1140 UnloadedExtensionReason reason) {
Devlin Cronin5b35a082017-10-05 20:44:361141 extension_registrar_.RemoveExtension(extension_id, reason);
[email protected]631cf822009-05-15 07:01:251142}
1143
[email protected]8b1ec202013-09-05 02:09:501144void ExtensionService::RemoveComponentExtension(
1145 const std::string& extension_id) {
1146 scoped_refptr<const Extension> extension(
David Bertoni58c113a2019-08-02 19:53:261147 registry_->GetExtensionById(extension_id, ExtensionRegistry::ENABLED));
limasdf0deef2042017-05-03 19:17:171148 UnloadExtension(extension_id, UnloadedExtensionReason::UNINSTALL);
[email protected]ebe07772014-05-22 04:16:061149 if (extension.get()) {
[email protected]e43c61f2014-07-20 21:46:341150 ExtensionRegistry::Get(profile_)->TriggerOnUninstalled(
Devlin Cronineea1b7a2018-05-26 02:46:211151 extension.get(), UNINSTALL_REASON_COMPONENT_REMOVED);
[email protected]ebe07772014-05-22 04:16:061152 }
[email protected]8b1ec202013-09-05 02:09:501153}
1154
[email protected]bb1bc9b32013-12-21 03:09:141155void ExtensionService::UnloadAllExtensionsForTest() {
1156 UnloadAllExtensionsInternal();
[email protected]9f1087e2009-06-15 17:29:321157}
1158
[email protected]bb1bc9b32013-12-21 03:09:141159void ExtensionService::ReloadExtensionsForTest() {
1160 // Calling UnloadAllExtensionsForTest here triggers a false-positive presubmit
1161 // warning about calling test code in production.
1162 UnloadAllExtensionsInternal();
[email protected]eac88332012-12-26 17:57:451163 component_loader_->LoadAll();
Devlin Cronineea1b7a2018-05-26 02:46:211164 InstalledLoader(this).LoadAllExtensions();
rdevlin.croninf2e1cb012017-05-27 01:27:591165 OnInstalledExtensionsLoaded();
[email protected]4a10006a2013-05-17 23:18:351166 // Don't call SetReadyAndNotifyListeners() since tests call this multiple
1167 // times.
[email protected]9f1087e2009-06-15 17:29:321168}
1169
[email protected]820d9bd2013-04-03 03:46:031170void ExtensionService::SetReadyAndNotifyListeners() {
rkaplowa8fd8d32015-02-25 21:27:561171 TRACE_EVENT0("browser,startup",
1172 "ExtensionService::SetReadyAndNotifyListeners");
1173 SCOPED_UMA_HISTOGRAM_TIMER(
1174 "Extensions.ExtensionServiceNotifyReadyListenersTime");
1175
[email protected]4a10006a2013-05-17 23:18:351176 ready_->Signal();
[email protected]820d9bd2013-04-03 03:46:031177 content::NotificationService::current()->Notify(
Devlin Cronineea1b7a2018-05-26 02:46:211178 NOTIFICATION_EXTENSIONS_READY_DEPRECATED,
[email protected]820d9bd2013-04-03 03:46:031179 content::Source<Profile>(profile_),
1180 content::NotificationService::NoDetails());
1181}
1182
[email protected]fcb58a862012-05-01 01:03:151183void ExtensionService::AddExtension(const Extension* extension) {
rdevlin.cronin08ada0f2017-03-09 23:29:521184 if (!Manifest::IsValidLocation(extension->location())) {
1185 // TODO(devlin): We should *never* add an extension with an invalid
1186 // location, but some bugs (e.g. crbug.com/692069) seem to indicate we do.
1187 // Track down the cases when this can happen, and remove this
1188 // DumpWithoutCrashing() (possibly replacing it with a CHECK).
1189 NOTREACHED();
Lukasz Anforowicz68c21772018-01-13 03:42:441190 DEBUG_ALIAS_FOR_CSTR(extension_id_copy, extension->id().c_str(), 33);
rdevlin.cronin08ada0f2017-03-09 23:29:521191 Manifest::Location location = extension->location();
1192 int creation_flags = extension->creation_flags();
1193 Manifest::Type type = extension->manifest()->type();
rdevlin.cronin08ada0f2017-03-09 23:29:521194 base::debug::Alias(&location);
1195 base::debug::Alias(&creation_flags);
1196 base::debug::Alias(&type);
1197 base::debug::DumpWithoutCrashing();
1198 return;
1199 }
1200
[email protected]c8d407e2011-04-28 21:27:171201 // TODO(jstritar): We may be able to get rid of this branch by overriding the
1202 // default extension state to DISABLED when the --disable-extensions flag
1203 // is set (http://crbug.com/29067).
Devlin Croninefe0c882018-04-20 00:06:481204 if (!extensions_enabled_ &&
1205 !Manifest::ShouldAlwaysLoadExtension(extension->location(),
Devlin Cronin8c23eec2018-05-01 18:42:281206 extension->is_theme()) &&
catmullings98cd1942016-08-30 22:31:591207 disable_flag_exempted_extensions_.count(extension->id()) == 0) {
[email protected]fcb58a862012-05-01 01:03:151208 return;
[email protected]330840c2012-08-29 22:21:011209 }
[email protected]c8d407e2011-04-28 21:27:171210
Michael Giuffrida573992d2018-02-08 00:48:441211 extension_registrar_.AddExtension(extension);
Michael Giuffrida023e3532017-09-28 23:21:211212
Michael Giuffrida573992d2018-02-08 00:48:441213 if (registry_->disabled_extensions().Contains(extension->id())) {
1214 // Show the extension disabled error if a permissions increase or a remote
1215 // installation is the reason it was disabled, and no other reasons exist.
1216 int reasons = extension_prefs_->GetDisableReasons(extension->id());
Devlin Cronineea1b7a2018-05-26 02:46:211217 const int kReasonMask = disable_reason::DISABLE_PERMISSIONS_INCREASE |
1218 disable_reason::DISABLE_REMOTE_INSTALL;
Michael Giuffrida573992d2018-02-08 00:48:441219 if (reasons & kReasonMask && !(reasons & ~kReasonMask)) {
1220 AddExtensionDisabledError(
1221 this, extension,
1222 extension_prefs_->HasDisableReason(
Devlin Cronineea1b7a2018-05-26 02:46:211223 extension->id(), disable_reason::DISABLE_REMOTE_INSTALL));
Michael Giuffrida6397c592017-10-09 20:46:531224 }
[email protected]f574c402012-12-04 23:20:311225 }
[email protected]aab98a52009-12-02 03:22:351226}
1227
[email protected]8c484b742012-11-29 06:05:361228void ExtensionService::AddComponentExtension(const Extension* extension) {
Samuel Huang7987ebd2019-04-08 13:01:371229 extension_prefs_->ClearInapplicableDisableReasonsForComponentExtension(
1230 extension->id());
[email protected]8c484b742012-11-29 06:05:361231 const std::string old_version_string(
1232 extension_prefs_->GetVersionString(extension->id()));
pwnallcbd73192016-08-22 18:59:171233 const base::Version old_version(old_version_string);
[email protected]8c484b742012-11-29 06:05:361234
[email protected]0181a7d2013-11-12 01:08:421235 VLOG(1) << "AddComponentExtension " << extension->name();
Devlin Cronin03bf2d22017-12-20 08:21:051236 if (!old_version.IsValid() || old_version != extension->version()) {
[email protected]8c484b742012-11-29 06:05:361237 VLOG(1) << "Component extension " << extension->name() << " ("
Devlin Cronin03bf2d22017-12-20 08:21:051238 << extension->id() << ") installing/upgrading from '"
1239 << old_version_string << "' to "
1240 << extension->version().GetString();
[email protected]8c484b742012-11-29 06:05:361241
Karandeep Bhatiaa8930652017-10-11 17:41:121242 // TODO(crbug.com/696822): If needed, add support for Declarative Net
1243 // Request to component extensions and pass the ruleset checksum here.
Devlin Cronineea1b7a2018-05-26 02:46:211244 AddNewOrUpdatedExtension(extension, Extension::ENABLED, kInstallFlagNone,
1245 syncer::StringOrdinal(), std::string(),
1246 base::nullopt);
[email protected]8c484b742012-11-29 06:05:361247 return;
1248 }
1249
1250 AddExtension(extension);
1251}
1252
[email protected]b914e2952013-04-26 07:10:031253void ExtensionService::CheckPermissionsIncrease(const Extension* extension,
treib6e51bca2016-06-15 10:26:031254 bool is_extension_loaded) {
Devlin Cronineea1b7a2018-05-26 02:46:211255 PermissionsUpdater(profile_).InitializePermissions(extension);
[email protected]902fd7b2011-07-27 18:42:311256
[email protected]8d888c12010-11-30 00:00:251257 // We keep track of all permissions the user has granted each extension.
1258 // This allows extensions to gracefully support backwards compatibility
1259 // by including unknown permissions in their manifests. When the user
1260 // installs the extension, only the recognized permissions are recorded.
1261 // When the unknown permissions become recognized (e.g., through browser
1262 // upgrade), we can prompt the user to accept these new permissions.
1263 // Extensions can also silently upgrade to less permissions, and then
1264 // silently upgrade to a version that adds these permissions back.
1265 //
1266 // For example, pretend that Chrome 10 includes a permission "omnibox"
1267 // for an API that adds suggestions to the omnibox. An extension can
1268 // maintain backwards compatibility while still having "omnibox" in the
1269 // manifest. If a user installs the extension on Chrome 9, the browser
1270 // will record the permissions it recognized, not including "omnibox."
1271 // When upgrading to Chrome 10, "omnibox" will be recognized and Chrome
1272 // will disable the extension and prompt the user to approve the increase
1273 // in privileges. The extension could then release a new version that
1274 // removes the "omnibox" permission. When the user upgrades, Chrome will
1275 // still remember that "omnibox" had been granted, so that if the
1276 // extension once again includes "omnibox" in an upgrade, the extension
1277 // can upgrade without requiring this user's approval.
[email protected]eb5e4f92012-08-15 23:33:281278 int disable_reasons = extension_prefs_->GetDisableReasons(extension->id());
[email protected]8d888c12010-11-30 00:00:251279
rockot1d4a06262015-02-17 19:39:281280 // Silently grant all active permissions to default apps and apps installed
1281 // in kiosk mode.
[email protected]211a3f32013-05-28 21:48:181282 bool auto_grant_permission =
rockot1d4a06262015-02-17 19:39:281283 extension->was_installed_by_default() ||
Devlin Cronineea1b7a2018-05-26 02:46:211284 ExtensionsBrowserClient::Get()->IsRunningInForcedAppMode();
[email protected]211a3f32013-05-28 21:48:181285 if (auto_grant_permission)
[email protected]b914e2952013-04-26 07:10:031286 GrantPermissions(extension);
1287
1288 bool is_privilege_increase = false;
1289 // We only need to compare the granted permissions to the current permissions
rockot1d4a06262015-02-17 19:39:281290 // if the extension has not been auto-granted its permissions above and is
1291 // installed internally.
1292 if (extension->location() == Manifest::INTERNAL && !auto_grant_permission) {
[email protected]8d888c12010-11-30 00:00:251293 // Add all the recognized permissions if the granted permissions list
1294 // hasn't been initialized yet.
dchengc963c7142016-04-08 03:55:221295 std::unique_ptr<const PermissionSet> granted_permissions =
[email protected]902fd7b2011-07-27 18:42:311296 extension_prefs_->GetGrantedPermissions(extension->id());
[email protected]0d3e4a22011-06-23 19:02:521297 CHECK(granted_permissions.get());
[email protected]8d888c12010-11-30 00:00:251298
1299 // Here, we check if an extension's privileges have increased in a manner
1300 // that requires the user's approval. This could occur because the browser
1301 // upgraded and recognized additional privileges, or an extension upgrades
1302 // to a version that requires additional privileges.
[email protected]c41003472013-10-19 15:37:251303 is_privilege_increase =
Devlin Cronineea1b7a2018-05-26 02:46:211304 PermissionMessageProvider::Get()->IsPrivilegeIncrease(
rdevlin.cronind630c302015-09-30 20:19:331305 *granted_permissions,
rdevlin.cronine2d0fd02015-09-24 22:35:491306 extension->permissions_data()->active_permissions(),
[email protected]076ebeda2014-06-06 21:47:261307 extension->GetType());
treib2c20f9442016-05-18 19:50:281308
1309 // If there was no privilege increase, the extension might still have new
1310 // permissions (which either don't generate a warning message, or whose
1311 // warning messages are suppressed by existing permissions). Grant the new
1312 // permissions.
1313 if (!is_privilege_increase)
1314 GrantPermissions(extension);
[email protected]8d888c12010-11-30 00:00:251315 }
1316
Marc Treib4bdb790b2018-07-07 15:02:481317 // TODO(crbug.com/860198): Before M48, extensions that came to us from sync in
1318 // a disabled state got assigned disable_reason::DISABLE_UNKNOWN_FROM_SYNC.
1319 // That reason isn't used anymore since the actual disable reason(s) are now
1320 // synced. This code is here to migrate any existing old state.
1321 if (disable_reasons & disable_reason::DEPRECATED_DISABLE_UNKNOWN_FROM_SYNC) {
1322 // Remove the disable_reason::DEPRECATED_DISABLE_UNKNOWN_FROM_SYNC
1323 // reason.
1324 disable_reasons &= ~disable_reason::DEPRECATED_DISABLE_UNKNOWN_FROM_SYNC;
1325 extension_prefs_->RemoveDisableReason(
1326 extension->id(), disable_reason::DEPRECATED_DISABLE_UNKNOWN_FROM_SYNC);
1327 // If there was no privilege increase, it was likely disabled by the user.
1328 // (If there *was* a privilege increase, we'll add an appropriate reason
1329 // later on, so nothing needs to be done here.)
1330 if (!is_privilege_increase)
1331 disable_reasons |= disable_reason::DISABLE_USER_ACTION;
1332 }
1333
treib6e51bca2016-06-15 10:26:031334 bool previously_disabled =
1335 extension_prefs_->IsExtensionDisabled(extension->id());
Marc Treib4bdb790b2018-07-07 15:02:481336 // TODO(devlin): Is the |is_extension_loaded| check needed here?
treib6e51bca2016-06-15 10:26:031337 if (is_extension_loaded && previously_disabled) {
treib8a6d9892015-08-26 10:23:191338 // Legacy disabled extensions do not have a disable reason. Infer that it
1339 // was likely disabled by the user.
Devlin Cronineea1b7a2018-05-26 02:46:211340 if (disable_reasons == disable_reason::DISABLE_NONE)
1341 disable_reasons |= disable_reason::DISABLE_USER_ACTION;
[email protected]8d888c12010-11-30 00:00:251342 }
1343
treib6e51bca2016-06-15 10:26:031344 // If the extension is disabled due to a permissions increase, but does in
1345 // fact have all permissions, remove that disable reason.
1346 // TODO(devlin): This was added to fix crbug.com/616474, but it's unclear
1347 // if this behavior should stay forever.
Devlin Cronineea1b7a2018-05-26 02:46:211348 if (disable_reasons & disable_reason::DISABLE_PERMISSIONS_INCREASE) {
treib6e51bca2016-06-15 10:26:031349 bool reset_permissions_increase = false;
1350 if (!is_privilege_increase) {
1351 reset_permissions_increase = true;
Devlin Cronineea1b7a2018-05-26 02:46:211352 disable_reasons &= ~disable_reason::DISABLE_PERMISSIONS_INCREASE;
treib6e51bca2016-06-15 10:26:031353 extension_prefs_->RemoveDisableReason(
Devlin Cronineea1b7a2018-05-26 02:46:211354 extension->id(), disable_reason::DISABLE_PERMISSIONS_INCREASE);
treib6e51bca2016-06-15 10:26:031355 }
1356 UMA_HISTOGRAM_BOOLEAN("Extensions.ResetPermissionsIncrease",
1357 reset_permissions_increase);
1358 }
1359
[email protected]8d888c12010-11-30 00:00:251360 // Extension has changed permissions significantly. Disable it. A
[email protected]21db9ef2014-05-16 02:06:271361 // notification should be sent by the caller. If the extension is already
1362 // disabled because it was installed remotely, don't add another disable
treibaac30ec2015-06-10 09:18:091363 // reason.
1364 if (is_privilege_increase &&
Devlin Cronineea1b7a2018-05-26 02:46:211365 !(disable_reasons & disable_reason::DISABLE_REMOTE_INSTALL)) {
1366 disable_reasons |= disable_reason::DISABLE_PERMISSIONS_INCREASE;
treib8a6d9892015-08-26 10:23:191367 if (!extension_prefs_->DidExtensionEscalatePermissions(extension->id()))
treib2e0517f92015-05-07 23:15:361368 RecordPermissionMessagesHistogram(extension, "AutoDisable");
treib8ecc1eb52015-03-04 18:29:061369
brettw9e85ef42016-11-01 21:01:241370#if BUILDFLAG(ENABLE_SUPERVISED_USERS)
treib8ecc1eb52015-03-04 18:29:061371 // If a custodian-installed extension is disabled for a supervised user due
mamir51e05d02016-10-06 10:55:011372 // to a permissions increase, send a request to the custodian.
Devlin Cronineea1b7a2018-05-26 02:46:211373 if (util::IsExtensionSupervised(extension, profile_) &&
treib40d3ad92015-10-20 18:15:421374 !ExtensionSyncService::Get(profile_)->HasPendingReenable(
Devlin Cronin03bf2d22017-12-20 08:21:051375 extension->id(), extension->version())) {
treib8ecc1eb52015-03-04 18:29:061376 SupervisedUserService* supervised_user_service =
1377 SupervisedUserServiceFactory::GetForProfile(profile_);
treib40d3ad92015-10-20 18:15:421378 supervised_user_service->AddExtensionUpdateRequest(extension->id(),
Devlin Cronin03bf2d22017-12-20 08:21:051379 extension->version());
treib8ecc1eb52015-03-04 18:29:061380 }
1381#endif
[email protected]b914e2952013-04-26 07:10:031382 }
treib6e51bca2016-06-15 10:26:031383
Devlin Cronineea1b7a2018-05-26 02:46:211384 if (disable_reasons == disable_reason::DISABLE_NONE)
treib6e51bca2016-06-15 10:26:031385 extension_prefs_->SetExtensionEnabled(extension->id());
1386 else
treib8a6d9892015-08-26 10:23:191387 extension_prefs_->SetExtensionDisabled(extension->id(), disable_reasons);
[email protected]8d888c12010-11-30 00:00:251388}
1389
[email protected]eaa7dd182010-12-14 11:09:001390void ExtensionService::UpdateActiveExtensionsInCrashReporter() {
[email protected]c8865962009-12-16 07:47:391391 std::set<std::string> extension_ids;
achuith2f5578b2016-02-26 21:57:131392 for (const auto& extension : registry_->enabled_extensions()) {
[email protected]1d5e58b2013-01-31 08:41:401393 if (!extension->is_theme() && extension->location() != Manifest::COMPONENT)
[email protected]84df8332011-12-06 18:22:461394 extension_ids.insert(extension->id());
[email protected]aab98a52009-12-02 03:22:351395 }
1396
[email protected]dcc47642014-03-26 22:03:491397 // TODO(kalman): This is broken. ExtensionService is per-profile.
1398 // crash_keys::SetActiveExtensions is per-process. See
1399 // http://crbug.com/355029.
[email protected]f6431be82013-09-07 02:53:451400 crash_keys::SetActiveExtensions(extension_ids);
[email protected]6014d672008-12-05 00:38:251401}
1402
[email protected]8266d662011-07-12 21:53:261403void ExtensionService::OnExtensionInstalled(
[email protected]36a5c4c2011-12-14 16:34:501404 const Extension* extension,
[email protected]98270432012-09-11 20:51:241405 const syncer::StringOrdinal& page_ordinal,
Karandeep Bhatiaa8930652017-10-11 17:41:121406 int install_flags,
1407 const base::Optional<int>& dnr_ruleset_checksum) {
[email protected]a29a517a2011-01-21 21:11:121408 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]a8af9fdb2010-10-28 21:52:201409
[email protected]c3cfb012011-04-06 22:07:351410 const std::string& id = extension->id();
binjin47947f842014-11-18 12:10:241411 int disable_reasons = GetDisableReasonsOnInstalled(extension);
[email protected]d8fd0fd2014-03-24 13:16:061412 std::string install_parameter;
Devlin Cronineea1b7a2018-05-26 02:46:211413 const PendingExtensionInfo* pending_extension_info =
[email protected]96aebe22014-07-16 04:07:511414 pending_extension_manager()->GetById(id);
1415 if (pending_extension_info) {
[email protected]8f3bcbd2013-06-05 08:42:401416 if (!pending_extension_info->ShouldAllowInstall(extension)) {
Devlinec30d362018-07-13 18:13:391417 // Hack for crbug.com/558299, see comment on DeleteThemeDoNotUse.
1418 if (extension->is_theme() && pending_extension_info->is_from_sync())
1419 ExtensionSyncService::Get(profile_)->DeleteThemeDoNotUse(*extension);
1420
[email protected]51a3bf8b2012-06-08 22:53:061421 pending_extension_manager()->Remove(id);
[email protected]8ef78fd2010-08-19 17:14:321422
Devlin Cronineea1b7a2018-05-26 02:46:211423 LOG(WARNING) << "ShouldAllowInstall() returned false for " << id
1424 << " of type " << extension->GetType() << " and update URL "
1425 << ManifestURL::GetUpdateURL(extension).spec()
[email protected]31bb5ee62012-09-12 22:58:401426 << "; not installing";
[email protected]ae6cb3022011-04-04 20:11:541427
[email protected]4416c5a2010-06-26 01:28:571428 // Delete the extension directory since we're not going to
1429 // load it.
Devlin Cronineea1b7a2018-05-26 02:46:211430 if (!GetExtensionFileTaskRunner()->PostTask(
1431 FROM_HERE, base::BindOnce(&file_util::DeleteFile,
tzik8d880ee2017-04-20 19:46:241432 extension->path(), true))) {
[email protected]14908b72011-04-20 06:54:361433 NOTREACHED();
[email protected]31bb5ee62012-09-12 22:58:401434 }
[email protected]4416c5a2010-06-26 01:28:571435 return;
1436 }
[email protected]51a3bf8b2012-06-08 22:53:061437
[email protected]d8fd0fd2014-03-24 13:16:061438 install_parameter = pending_extension_info->install_parameter();
[email protected]51a3bf8b2012-06-08 22:53:061439 pending_extension_manager()->Remove(id);
[email protected]4416c5a2010-06-26 01:28:571440 } else {
[email protected]c3cfb012011-04-06 22:07:351441 // We explicitly want to re-enable an uninstalled external
1442 // extension; if we're here, that means the user is manually
1443 // installing the extension.
[email protected]46f3e102014-03-25 01:22:451444 if (extension_prefs_->IsExternalExtensionUninstalled(id)) {
Devlin Cronineea1b7a2018-05-26 02:46:211445 disable_reasons = disable_reason::DISABLE_NONE;
[email protected]6cc7dbae2011-04-29 21:18:331446 }
[email protected]aa142702010-03-26 01:26:331447 }
1448
asargente4de9f92016-09-15 01:40:061449 // If the old version of the extension was disabled due to corruption, this
1450 // new install may correct the problem.
Devlin Cronineea1b7a2018-05-26 02:46:211451 disable_reasons &= ~disable_reason::DISABLE_CORRUPTED;
asargente4de9f92016-09-15 01:40:061452
[email protected]98270432012-09-11 20:51:241453 // Unsupported requirements overrides the management policy.
Devlin Cronineea1b7a2018-05-26 02:46:211454 if (install_flags & kInstallFlagHasRequirementErrors) {
1455 disable_reasons |= disable_reason::DISABLE_UNSUPPORTED_REQUIREMENT;
binjin8e3d0182014-12-04 16:44:281456 } else {
1457 // Requirement is supported now, remove the corresponding disable reason
1458 // instead.
Devlin Cronineea1b7a2018-05-26 02:46:211459 disable_reasons &= ~disable_reason::DISABLE_UNSUPPORTED_REQUIREMENT;
binjin8e3d0182014-12-04 16:44:281460 }
1461
1462 // Check if the extension was disabled because of the minimum version
1463 // requirements from enterprise policy, and satisfies it now.
Devlin Cronineea1b7a2018-05-26 02:46:211464 if (ExtensionManagementFactory::GetForBrowserContext(profile())
binjin8e3d0182014-12-04 16:44:281465 ->CheckMinimumVersion(extension, nullptr)) {
1466 // And remove the corresponding disable reason.
Devlin Cronineea1b7a2018-05-26 02:46:211467 disable_reasons &= ~disable_reason::DISABLE_UPDATE_REQUIRED_BY_POLICY;
[email protected]98270432012-09-11 20:51:241468 }
1469
Devlin Cronineea1b7a2018-05-26 02:46:211470 if (install_flags & kInstallFlagIsBlacklistedForMalware) {
[email protected]9f3c8532013-07-31 19:52:071471 // Installation of a blacklisted extension can happen from sync, policy,
1472 // etc, where to maintain consistency we need to install it, just never
1473 // load it (see AddExtension). Usually it should be the job of callers to
treibaac30ec2015-06-10 09:18:091474 // intercept blacklisted extensions earlier (e.g. CrxInstaller, before even
[email protected]9f3c8532013-07-31 19:52:071475 // showing the install dialogue).
[email protected]7c82539c2014-02-19 06:09:171476 extension_prefs_->AcknowledgeBlacklistedExtension(id);
[email protected]9f3c8532013-07-31 19:52:071477 UMA_HISTOGRAM_ENUMERATION("ExtensionBlacklist.SilentInstall",
1478 extension->location(),
1479 Manifest::NUM_LOCATIONS);
1480 }
1481
[email protected]695b5712012-12-06 23:55:281482 if (!GetInstalledExtension(extension->id())) {
[email protected]07533022011-06-27 20:42:551483 UMA_HISTOGRAM_ENUMERATION("Extensions.InstallType",
1484 extension->GetType(), 100);
[email protected]69084dc2012-11-17 07:39:301485 UMA_HISTOGRAM_ENUMERATION("Extensions.InstallSource",
[email protected]1d5e58b2013-01-31 08:41:401486 extension->location(), Manifest::NUM_LOCATIONS);
treib2e0517f92015-05-07 23:15:361487 RecordPermissionMessagesHistogram(extension, "Install");
[email protected]69084dc2012-11-17 07:39:301488 } else {
1489 UMA_HISTOGRAM_ENUMERATION("Extensions.UpdateType",
1490 extension->GetType(), 100);
1491 UMA_HISTOGRAM_ENUMERATION("Extensions.UpdateSource",
[email protected]1d5e58b2013-01-31 08:41:401492 extension->location(), Manifest::NUM_LOCATIONS);
[email protected]07533022011-06-27 20:42:551493 }
1494
[email protected]399583b2012-12-11 09:33:421495 const Extension::State initial_state =
Devlin Cronineea1b7a2018-05-26 02:46:211496 disable_reasons == disable_reason::DISABLE_NONE ? Extension::ENABLED
1497 : Extension::DISABLED;
treib8a6d9892015-08-26 10:23:191498 if (initial_state == Extension::ENABLED)
1499 extension_prefs_->SetExtensionEnabled(id);
1500 else
1501 extension_prefs_->SetExtensionDisabled(id, disable_reasons);
binjin47947f842014-11-18 12:10:241502
Devlin Cronineea1b7a2018-05-26 02:46:211503 ExtensionPrefs::DelayReason delay_reason;
1504 InstallGate::Action action = ShouldDelayExtensionInstall(
1505 extension, !!(install_flags & kInstallFlagInstallImmediately),
xiyuanf6a4c6a62016-04-19 18:14:541506 &delay_reason);
1507 switch (action) {
Devlin Cronineea1b7a2018-05-26 02:46:211508 case InstallGate::INSTALL:
xiyuanf6a4c6a62016-04-19 18:14:541509 AddNewOrUpdatedExtension(extension, initial_state, install_flags,
Karandeep Bhatiaa8930652017-10-11 17:41:121510 page_ordinal, install_parameter,
1511 dnr_ruleset_checksum);
xiyuanf6a4c6a62016-04-19 18:14:541512 return;
Devlin Cronineea1b7a2018-05-26 02:46:211513 case InstallGate::DELAY:
Karandeep Bhatiaa8930652017-10-11 17:41:121514 extension_prefs_->SetDelayedInstallInfo(
1515 extension, initial_state, install_flags, delay_reason, page_ordinal,
1516 install_parameter, dnr_ruleset_checksum);
[email protected]0db124b02012-11-07 04:55:051517
xiyuanf6a4c6a62016-04-19 18:14:541518 // Transfer ownership of |extension|.
[email protected]9f4e4f082013-06-21 07:11:191519 delayed_installs_.Insert(extension);
xiyuanf6a4c6a62016-04-19 18:14:541520
Devlin Cronineea1b7a2018-05-26 02:46:211521 if (delay_reason == ExtensionPrefs::DELAY_REASON_WAIT_FOR_IDLE) {
xiyuanf6a4c6a62016-04-19 18:14:541522 // Notify observers that app update is available.
ericwilligersb5f79de2016-10-19 04:15:101523 for (auto& observer : update_observers_)
1524 observer.OnAppUpdateAvailable(extension);
xiyuanf6a4c6a62016-04-19 18:14:541525 }
1526 return;
Devlin Cronineea1b7a2018-05-26 02:46:211527 case InstallGate::ABORT:
xiyuanf6a4c6a62016-04-19 18:14:541528 // Do nothing to abort the install. One such case is the shared module
1529 // service gets IMPORT_STATUS_UNRECOVERABLE status for the pending
1530 // install.
1531 return;
[email protected]399583b2012-12-11 09:33:421532 }
xiyuanf6a4c6a62016-04-19 18:14:541533
1534 NOTREACHED() << "Unknown action for delayed install: " << action;
[email protected]8c484b742012-11-29 06:05:361535}
1536
binjin1569c9b2014-09-05 13:33:181537void ExtensionService::OnExtensionManagementSettingsChanged() {
1538 error_controller_->ShowErrorIfNeeded();
binjine6b58b52014-10-31 01:55:571539
1540 // Revokes blocked permissions from active_permissions for all extensions.
Devlin Cronineea1b7a2018-05-26 02:46:211541 ExtensionManagement* settings =
1542 ExtensionManagementFactory::GetForBrowserContext(profile());
binjine6b58b52014-10-31 01:55:571543 CHECK(settings);
dchengc963c7142016-04-08 03:55:221544 std::unique_ptr<ExtensionSet> all_extensions(
binjine6b58b52014-10-31 01:55:571545 registry_->GenerateInstalledExtensionsSet());
achuith2f5578b2016-02-26 21:57:131546 for (const auto& extension : *all_extensions) {
binjine6b58b52014-10-31 01:55:571547 if (!settings->IsPermissionSetAllowed(
binjin685ade82014-11-06 09:53:561548 extension.get(),
Nick Peterson0203be4a2017-07-19 00:25:141549 extension->permissions_data()->active_permissions()) &&
1550 CanBlockExtension(extension.get())) {
Devlin Cronineea1b7a2018-05-26 02:46:211551 PermissionsUpdater(profile()).RemovePermissionsUnsafe(
rdevlin.cronind630c302015-09-30 20:19:331552 extension.get(), *settings->GetBlockedPermissions(extension.get()));
binjine6b58b52014-10-31 01:55:571553 }
1554 }
1555
binjin1569c9b2014-09-05 13:33:181556 CheckManagementPolicy();
1557}
1558
[email protected]8c484b742012-11-29 06:05:361559void ExtensionService::AddNewOrUpdatedExtension(
1560 const Extension* extension,
[email protected]399583b2012-12-11 09:33:421561 Extension::State initial_state,
[email protected]4a1d9c0d2014-06-13 12:50:111562 int install_flags,
[email protected]d8fd0fd2014-03-24 13:16:061563 const syncer::StringOrdinal& page_ordinal,
Karandeep Bhatiaa8930652017-10-11 17:41:121564 const std::string& install_parameter,
1565 const base::Optional<int>& dnr_ruleset_checksum) {
[email protected]8c484b742012-11-29 06:05:361566 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
Karandeep Bhatiaa8930652017-10-11 17:41:121567 extension_prefs_->OnExtensionInstalled(extension, initial_state, page_ordinal,
1568 install_flags, install_parameter,
1569 dnr_ruleset_checksum);
[email protected]9e9c1d12013-07-31 01:58:121570 delayed_installs_.Remove(extension->id());
[email protected]913ffca92014-03-27 15:26:161571 if (InstallVerifier::NeedsVerification(*extension))
juncai33e462102015-05-18 20:48:441572 InstallVerifier::Get(GetBrowserContext())->VerifyExtension(extension->id());
ryanackley48bedbd2015-01-27 23:12:141573
1574 const Extension* old = GetInstalledExtension(extension->id());
Devlin Cronineea1b7a2018-05-26 02:46:211575 if (AppDataMigrator::NeedsMigration(old, extension)) {
ryanackley48bedbd2015-01-27 23:12:141576 app_data_migrator_->DoMigrationAndReply(
vmpstra34d11322016-03-21 20:28:471577 old, extension, base::Bind(&ExtensionService::FinishInstallation,
1578 AsWeakPtr(), base::RetainedRef(extension)));
ryanackley48bedbd2015-01-27 23:12:141579 return;
1580 }
1581
benwells1dd4acd2015-12-09 02:20:241582 FinishInstallation(extension);
[email protected]6f6101832012-11-27 22:10:481583}
1584
Toni Barzic667db0d32018-01-09 18:00:191585bool ExtensionService::FinishDelayedInstallationIfReady(
1586 const std::string& extension_id,
1587 bool install_immediately) {
[email protected]9f4e4f082013-06-21 07:11:191588 // Check if the extension already got installed.
[email protected]9f4e4f082013-06-21 07:11:191589 const Extension* extension = delayed_installs_.GetByID(extension_id);
xiyuanf6a4c6a62016-04-19 18:14:541590 if (!extension)
Toni Barzic667db0d32018-01-09 18:00:191591 return false;
xiyuanf6a4c6a62016-04-19 18:14:541592
Devlin Cronineea1b7a2018-05-26 02:46:211593 ExtensionPrefs::DelayReason reason;
1594 const InstallGate::Action action =
Toni Barzic667db0d32018-01-09 18:00:191595 ShouldDelayExtensionInstall(extension, install_immediately, &reason);
xiyuanf6a4c6a62016-04-19 18:14:541596 switch (action) {
Devlin Cronineea1b7a2018-05-26 02:46:211597 case InstallGate::INSTALL:
xiyuanf6a4c6a62016-04-19 18:14:541598 break;
Devlin Cronineea1b7a2018-05-26 02:46:211599 case InstallGate::DELAY:
xiyuanf6a4c6a62016-04-19 18:14:541600 // Bail out and continue to delay the install.
Toni Barzic667db0d32018-01-09 18:00:191601 return false;
Devlin Cronineea1b7a2018-05-26 02:46:211602 case InstallGate::ABORT:
xiyuanf6a4c6a62016-04-19 18:14:541603 delayed_installs_.Remove(extension_id);
1604 // Make sure no version of the extension is actually installed, (i.e.,
1605 // that this delayed install was not an update).
1606 CHECK(!extension_prefs_->GetInstalledExtensionInfo(extension_id).get());
1607 extension_prefs_->DeleteExtensionPrefs(extension_id);
Toni Barzic667db0d32018-01-09 18:00:191608 return false;
[email protected]9f4e4f082013-06-21 07:11:191609 }
1610
Toni Barzic667db0d32018-01-09 18:00:191611 scoped_refptr<const Extension> delayed_install =
1612 GetPendingExtensionUpdate(extension_id);
1613 CHECK(delayed_install.get());
[email protected]9f4e4f082013-06-21 07:11:191614 delayed_installs_.Remove(extension_id);
[email protected]6f6101832012-11-27 22:10:481615
[email protected]399583b2012-12-11 09:33:421616 if (!extension_prefs_->FinishDelayedInstallInfo(extension_id))
[email protected]6f6101832012-11-27 22:10:481617 NOTREACHED();
1618
Toni Barzic667db0d32018-01-09 18:00:191619 FinishInstallation(delayed_install.get());
1620 return true;
[email protected]6f6101832012-11-27 22:10:481621}
1622
[email protected]760f743b2014-05-28 13:52:021623void ExtensionService::FinishInstallation(
benwells1dd4acd2015-12-09 02:20:241624 const Extension* extension) {
Devlin Cronineea1b7a2018-05-26 02:46:211625 const Extension* existing_extension = GetInstalledExtension(extension->id());
[email protected]e7554c3f2013-05-29 00:36:561626 bool is_update = false;
1627 std::string old_name;
1628 if (existing_extension) {
1629 is_update = true;
1630 old_name = existing_extension->name();
1631 }
[email protected]bc44b5da2014-06-12 14:20:001632 registry_->TriggerOnWillBeInstalled(
benwells1dd4acd2015-12-09 02:20:241633 extension, is_update, old_name);
[email protected]17f07822014-05-22 08:45:151634
[email protected]399583b2012-12-11 09:33:421635 // Unpacked extensions default to allowing file access, but if that has been
1636 // overridden, don't reset the value.
[email protected]1d5e58b2013-01-31 08:41:401637 if (Manifest::ShouldAlwaysAllowFileAccess(extension->location()) &&
[email protected]399583b2012-12-11 09:33:421638 !extension_prefs_->HasAllowFileAccessSetting(extension->id())) {
1639 extension_prefs_->SetAllowFileAccess(extension->id(), true);
1640 }
1641
[email protected]6f6101832012-11-27 22:10:481642 AddExtension(extension);
[email protected]612a1cb12012-10-17 13:18:031643
[email protected]bc44b5da2014-06-12 14:20:001644 // Notify observers that need to know when an installation is complete.
[email protected]38e872532014-07-16 23:27:511645 registry_->TriggerOnInstalled(extension, is_update);
[email protected]bc44b5da2014-06-12 14:20:001646
[email protected]9f4e4f082013-06-21 07:11:191647 // Check extensions that may have been delayed only because this shared module
1648 // was not available.
[email protected]374ceb6f2014-07-02 19:25:341649 if (SharedModuleInfo::IsSharedModule(extension))
[email protected]9f4e4f082013-06-21 07:11:191650 MaybeFinishDelayedInstallations();
[email protected]4a190632009-05-09 01:07:421651}
1652
[email protected]76b65442012-11-17 14:11:481653const Extension* ExtensionService::GetPendingExtensionUpdate(
1654 const std::string& id) const {
[email protected]9f4e4f082013-06-21 07:11:191655 return delayed_installs_.GetByID(id);
[email protected]76b65442012-11-17 14:11:481656}
1657
mukai87a8d402014-09-15 20:15:091658void ExtensionService::RegisterContentSettings(
mmenkead5094ab2017-05-15 19:01:141659 HostContentSettingsMap* host_content_settings_map,
1660 Profile* profile) {
1661 // Most extension services key off of the original profile.
1662 Profile* original_profile = profile->GetOriginalProfile();
1663
rkaplowe65c2ff2015-02-14 16:29:541664 TRACE_EVENT0("browser,startup", "ExtensionService::RegisterContentSettings");
mukaia1aa3512014-10-22 20:14:111665 DCHECK_CURRENTLY_ON(BrowserThread::UI);
mukai87a8d402014-09-15 20:15:091666 host_content_settings_map->RegisterProvider(
mukai87a8d402014-09-15 20:15:091667 HostContentSettingsMap::CUSTOM_EXTENSION_PROVIDER,
dchengc963c7142016-04-08 03:55:221668 std::unique_ptr<content_settings::ObservableProvider>(
mukai87a8d402014-09-15 20:15:091669 new content_settings::CustomExtensionProvider(
Devlin Cronineea1b7a2018-05-26 02:46:211670 ContentSettingsService::Get(original_profile)
dchengc963c7142016-04-08 03:55:221671 ->content_settings_store(),
mmenkead5094ab2017-05-15 19:01:141672 // TODO(mmenke): CustomExtensionProvider expects this to be true
1673 // for incognito profiles.
1674 false)));
mukai87a8d402014-09-15 20:15:091675}
1676
[email protected]e9d7496e2014-04-18 01:25:461677void ExtensionService::TerminateExtension(const std::string& extension_id) {
Michael Giuffridafcb420362017-10-11 21:50:261678 extension_registrar_.TerminateExtension(extension_id);
[email protected]bb7f40952011-01-13 00:21:201679}
1680
[email protected]8001df22011-04-28 19:59:471681const Extension* ExtensionService::GetInstalledExtension(
1682 const std::string& id) const {
[email protected]599539802014-01-07 23:06:001683 return registry_->GetExtensionById(id, ExtensionRegistry::EVERYTHING);
[email protected]0dfe05c2011-02-23 23:03:361684}
1685
[email protected]9060d8b02012-01-13 02:14:301686bool ExtensionService::OnExternalExtensionFileFound(
lazyboye8634172016-01-28 00:10:481687 const ExternalInstallInfoFile& info) {
Istiaque Ahmedf6e72622017-09-08 23:14:171688 DCHECK_CURRENTLY_ON(BrowserThread::UI);
lazyboye8634172016-01-28 00:10:481689 CHECK(crx_file::id_util::IdIsValid(info.extension_id));
1690 if (extension_prefs_->IsExternalExtensionUninstalled(info.extension_id))
[email protected]9060d8b02012-01-13 02:14:301691 return false;
[email protected]a8af9fdb2010-10-28 21:52:201692
[email protected]7577a5c52009-07-30 06:21:581693 // Before even bothering to unpack, check and see if we already have this
[email protected]4c967932009-07-31 01:15:491694 // version. This is important because these extensions are going to get
[email protected]7577a5c52009-07-30 06:21:581695 // installed on every startup.
David Bertoni58c113a2019-08-02 19:53:261696 const Extension* existing = registry_->GetExtensionById(
1697 info.extension_id, ExtensionRegistry::COMPATIBILITY);
[email protected]910f72ce2012-08-24 01:38:351698
[email protected]7577a5c52009-07-30 06:21:581699 if (existing) {
[email protected]910f72ce2012-08-24 01:38:351700 // The default apps will have the location set as INTERNAL. Since older
1701 // default apps are installed as EXTERNAL, we override them. However, if the
1702 // app is already installed as internal, then do the version check.
[email protected]31bb5ee62012-09-12 22:58:401703 // TODO(grv) : Remove after Q1-2013.
[email protected]910f72ce2012-08-24 01:38:351704 bool is_default_apps_migration =
lazyboye8634172016-01-28 00:10:481705 (info.crx_location == Manifest::INTERNAL &&
[email protected]1d5e58b2013-01-31 08:41:401706 Manifest::IsExternalLocation(existing->location()));
[email protected]910f72ce2012-08-24 01:38:351707
1708 if (!is_default_apps_migration) {
Devlin Cronin03bf2d22017-12-20 08:21:051709 switch (existing->version().CompareTo(info.version)) {
[email protected]910f72ce2012-08-24 01:38:351710 case -1: // existing version is older, we should upgrade
1711 break;
1712 case 0: // existing version is same, do nothing
1713 return false;
1714 case 1: // existing version is newer, uh-oh
lazyboye8634172016-01-28 00:10:481715 LOG(WARNING) << "Found external version of extension "
1716 << info.extension_id
[email protected]910f72ce2012-08-24 01:38:351717 << "that is older than current version. Current version "
1718 << "is: " << existing->VersionString() << ". New "
Devlin Cronind4c2a8f32017-09-29 17:08:301719 << "version is: " << info.version.GetString()
[email protected]910f72ce2012-08-24 01:38:351720 << ". Keeping current version.";
1721 return false;
1722 }
[email protected]7577a5c52009-07-30 06:21:581723 }
1724 }
1725
[email protected]9060d8b02012-01-13 02:14:301726 // If the extension is already pending, don't start an install.
[email protected]e3987852012-05-04 10:06:301727 if (!pending_extension_manager()->AddFromExternalFile(
Devlin Cronind4c2a8f32017-09-29 17:08:301728 info.extension_id, info.crx_location, info.version,
lazyboye8634172016-01-28 00:10:481729 info.creation_flags, info.mark_acknowledged)) {
[email protected]9060d8b02012-01-13 02:14:301730 return false;
[email protected]e3987852012-05-04 10:06:301731 }
[email protected]9c635f22010-12-02 09:36:361732
[email protected]14908b72011-04-20 06:54:361733 // no client (silent install)
[email protected]f8636f92013-08-09 21:02:371734 scoped_refptr<CrxInstaller> installer(CrxInstaller::CreateSilent(this));
lazyboye8634172016-01-28 00:10:481735 installer->set_install_source(info.crx_location);
1736 installer->set_expected_id(info.extension_id);
Devlin Cronind4c2a8f32017-09-29 17:08:301737 installer->set_expected_version(info.version,
treibe960e282015-09-11 10:38:081738 true /* fail_install_if_unexpected */);
[email protected]cb0e50312011-05-09 15:03:071739 installer->set_install_cause(extension_misc::INSTALL_CAUSE_EXTERNAL_FILE);
lazyboye8634172016-01-28 00:10:481740 installer->set_install_immediately(info.install_immediately);
1741 installer->set_creation_flags(info.creation_flags);
Oleg Davydovfd848c02019-05-10 16:51:381742
Joshua Pawlickiafaa2922019-09-03 18:50:231743 CRXFileInfo file_info(info.path,
1744 info.crx_location == Manifest::EXTERNAL_POLICY
1745 ? GetPolicyVerifierFormat()
1746 : GetExternalVerifierFormat());
[email protected]88e8ec9152013-01-17 04:05:181747#if defined(OS_CHROMEOS)
Oleg Davydovfd848c02019-05-10 16:51:381748 InstallLimiter::Get(profile_)->Add(installer, file_info);
[email protected]88e8ec9152013-01-17 04:05:181749#else
Oleg Davydovfd848c02019-05-10 16:51:381750 installer->InstallCrxFile(file_info);
[email protected]88e8ec9152013-01-17 04:05:181751#endif
[email protected]47fc70c2011-12-06 07:29:511752
1753 // Depending on the source, a new external extension might not need a user
1754 // notification on installation. For such extensions, mark them acknowledged
1755 // now to suppress the notification.
lazyboye8634172016-01-28 00:10:481756 if (info.mark_acknowledged)
1757 external_install_manager_->AcknowledgeExternalExtension(info.extension_id);
[email protected]9060d8b02012-01-13 02:14:301758
1759 return true;
[email protected]7577a5c52009-07-30 06:21:581760}
1761
[email protected]eaa7dd182010-12-14 11:09:001762void ExtensionService::DidCreateRenderViewForBackgroundPage(
Devlin Cronineea1b7a2018-05-26 02:46:211763 ExtensionHost* host) {
Michael Giuffrida573992d2018-02-08 00:48:441764 extension_registrar_.DidCreateRenderViewForBackgroundPage(host);
[email protected]406027c02010-09-27 08:03:181765}
1766
[email protected]432115822011-07-10 15:52:271767void ExtensionService::Observe(int type,
[email protected]6c2381d2011-10-19 02:52:531768 const content::NotificationSource& source,
1769 const content::NotificationDetails& details) {
[email protected]432115822011-07-10 15:52:271770 switch (type) {
[email protected]3c4abc82012-10-22 22:25:541771 case chrome::NOTIFICATION_APP_TERMINATING:
1772 // Shutdown has started. Don't start any more extension installs.
1773 // (We cannot use ExtensionService::Shutdown() for this because it
1774 // happens too late in browser teardown.)
1775 browser_terminating_ = true;
1776 break;
Devlin Cronineea1b7a2018-05-26 02:46:211777 case NOTIFICATION_EXTENSION_PROCESS_TERMINATED: {
[email protected]6c2381d2011-10-19 02:52:531778 if (profile_ !=
1779 content::Source<Profile>(source).ptr()->GetOriginalProfile()) {
[email protected]bc535ee52010-08-31 18:40:321780 break;
[email protected]6c2381d2011-10-19 02:52:531781 }
[email protected]a4ed6282009-12-14 20:51:161782
Michael Giuffridafcb420362017-10-11 21:50:261783 // Mark the extension as terminated and deactivated. We want it to
[email protected]fa2416f2011-05-03 08:41:201784 // be in a consistent state: either fully working or not loaded
1785 // at all, but never half-crashed. We do it in a PostTask so
1786 // that other handlers of this notification will still have
1787 // access to the Extension and ExtensionHost.
Devlin Cronineea1b7a2018-05-26 02:46:211788 ExtensionHost* host = content::Details<ExtensionHost>(details).ptr();
skyostilf221b7de2015-06-11 20:36:321789 base::ThreadTaskRunnerHandle::Get()->PostTask(
Michael Giuffridafcb420362017-10-11 21:50:261790 FROM_HERE, base::BindOnce(&ExtensionService::TerminateExtension,
1791 AsWeakPtr(), host->extension_id()));
[email protected]31f77262009-12-02 20:48:531792 break;
1793 }
[email protected]432115822011-07-10 15:52:271794 case content::NOTIFICATION_RENDERER_PROCESS_TERMINATED: {
[email protected]f3b1a082011-11-18 00:34:301795 content::RenderProcessHost* process =
1796 content::Source<content::RenderProcessHost>(source).ptr();
[email protected]fc30ef082011-08-18 04:07:191797 Profile* host_profile =
[email protected]f3b1a082011-11-18 00:34:301798 Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]fc30ef082011-08-18 04:07:191799 if (!profile_->IsSameProfile(host_profile->GetOriginalProfile()))
1800 break;
1801
Devlin Cronineea1b7a2018-05-26 02:46:211802 ProcessMap* process_map = ProcessMap::Get(profile_);
[email protected]fafdc842014-01-17 18:09:081803 if (process_map->Contains(process->GetID())) {
[email protected]52b76592013-11-02 17:59:031804 // An extension process was terminated, this might have resulted in an
1805 // app or extension becoming idle.
1806 std::set<std::string> extension_ids =
[email protected]fafdc842014-01-17 18:09:081807 process_map->GetExtensionsInProcess(process->GetID());
elijahtaylor0def4432014-10-06 18:15:111808 // In addition to the extensions listed in the process map, one of those
1809 // extensions could be referencing a shared module which is waiting for
1810 // idle to update. Check all imports of these extensions, too.
1811 std::set<std::string> import_ids;
jdoerrie13cd648c82018-10-02 21:21:021812 for (auto it = extension_ids.begin(); it != extension_ids.end(); ++it) {
David Bertoni58c113a2019-08-02 19:53:261813 const Extension* extension = registry_->GetExtensionById(
1814 *it, ExtensionRegistry::COMPATIBILITY);
elijahtaylor0def4432014-10-06 18:15:111815 if (!extension)
1816 continue;
1817 const std::vector<SharedModuleInfo::ImportInfo>& imports =
1818 SharedModuleInfo::GetImports(extension);
1819 std::vector<SharedModuleInfo::ImportInfo>::const_iterator import_it;
1820 for (import_it = imports.begin(); import_it != imports.end();
1821 import_it++) {
1822 import_ids.insert((*import_it).extension_id);
1823 }
1824 }
1825 extension_ids.insert(import_ids.begin(), import_ids.end());
1826
jdoerrie13cd648c82018-10-02 21:21:021827 for (auto it = extension_ids.begin(); it != extension_ids.end(); ++it) {
[email protected]52b76592013-11-02 17:59:031828 if (delayed_installs_.Contains(*it)) {
skyostilf221b7de2015-06-11 20:36:321829 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
[email protected]52b76592013-11-02 17:59:031830 FROM_HERE,
tzik8d880ee2017-04-20 19:46:241831 base::BindOnce(
Toni Barzic667db0d32018-01-09 18:00:191832 base::IgnoreResult(
1833 &ExtensionService::FinishDelayedInstallationIfReady),
1834 AsWeakPtr(), *it, false /*install_immediately*/),
Lei Zhang15339152018-08-09 22:20:441835 kUpdateIdleDelay);
[email protected]52b76592013-11-02 17:59:031836 }
1837 }
1838 }
1839
[email protected]fafdc842014-01-17 18:09:081840 process_map->RemoveAllFromProcess(process->GetID());
Sami Kyostila5db196cf2019-08-01 17:46:121841 base::PostTask(FROM_HERE, {BrowserThread::IO},
1842 base::BindOnce(&InfoMap::UnregisterAllExtensionsInProcess,
1843 system_->info_map(), process->GetID()));
[email protected]da5683db2011-04-23 17:12:211844 break;
1845 }
[email protected]aa96d3a2010-08-21 08:45:251846
[email protected]4814b512009-11-07 00:12:291847 default:
1848 NOTREACHED() << "Unexpected notification type.";
1849 }
1850}
1851
binjin47947f842014-11-18 12:10:241852int ExtensionService::GetDisableReasonsOnInstalled(const Extension* extension) {
rdevlin.cronine1456712016-12-29 22:47:281853 bool is_update_from_same_type = false;
1854 {
1855 const Extension* existing_extension =
1856 GetInstalledExtension(extension->id());
1857 is_update_from_same_type =
1858 existing_extension &&
1859 existing_extension->manifest()->type() == extension->manifest()->type();
1860 }
Devlin Cronineea1b7a2018-05-26 02:46:211861 disable_reason::DisableReason disable_reason = disable_reason::DISABLE_NONE;
binjin47947f842014-11-18 12:10:241862 // Extensions disabled by management policy should always be disabled, even
1863 // if it's force-installed.
1864 if (system_->management_policy()->MustRemainDisabled(
1865 extension, &disable_reason, nullptr)) {
1866 // A specified reason is required to disable the extension.
Devlin Cronineea1b7a2018-05-26 02:46:211867 DCHECK(disable_reason != disable_reason::DISABLE_NONE);
binjin47947f842014-11-18 12:10:241868 return disable_reason;
1869 }
1870
[email protected]612a1cb12012-10-17 13:18:031871 // Extensions installed by policy can't be disabled. So even if a previous
1872 // installation disabled the extension, make sure it is now enabled.
binjin47947f842014-11-18 12:10:241873 if (system_->management_policy()->MustRemainEnabled(extension, nullptr))
Devlin Cronineea1b7a2018-05-26 02:46:211874 return disable_reason::DISABLE_NONE;
[email protected]612a1cb12012-10-17 13:18:031875
binjin47947f842014-11-18 12:10:241876 // An already disabled extension should inherit the disable reasons and
1877 // remain disabled.
1878 if (extension_prefs_->IsExtensionDisabled(extension->id())) {
1879 int disable_reasons = extension_prefs_->GetDisableReasons(extension->id());
1880 // If an extension was disabled without specified reason, presume it's
1881 // disabled by user.
Devlin Cronineea1b7a2018-05-26 02:46:211882 return disable_reasons == disable_reason::DISABLE_NONE
1883 ? disable_reason::DISABLE_USER_ACTION
binjin47947f842014-11-18 12:10:241884 : disable_reasons;
1885 }
[email protected]612a1cb12012-10-17 13:18:031886
Devlin Cronineea1b7a2018-05-26 02:46:211887 if (ExternalInstallManager::IsPromptingEnabled()) {
[email protected]612a1cb12012-10-17 13:18:031888 // External extensions are initially disabled. We prompt the user before
[email protected]2c495c42013-01-04 21:49:541889 // enabling them. Hosted apps are excepted because they are not dangerous
rdevlin.cronine1456712016-12-29 22:47:281890 // (they need to be launched by the user anyway). We also don't prompt for
1891 // extensions updating; this is because the extension will be disabled from
1892 // the initial install if it is supposed to be, and this allows us to turn
1893 // this on for other platforms without disabling already-installed
1894 // extensions.
[email protected]1d5e58b2013-01-31 08:41:401895 if (extension->GetType() != Manifest::TYPE_HOSTED_APP &&
1896 Manifest::IsExternalLocation(extension->location()) &&
rdevlin.cronine1456712016-12-29 22:47:281897 !extension_prefs_->IsExternalExtensionAcknowledged(extension->id()) &&
1898 !is_update_from_same_type) {
Devlin Cronineea1b7a2018-05-26 02:46:211899 return disable_reason::DISABLE_EXTERNAL_EXTENSION;
[email protected]612a1cb12012-10-17 13:18:031900 }
1901 }
[email protected]612a1cb12012-10-17 13:18:031902
Devlin Cronineea1b7a2018-05-26 02:46:211903 return disable_reason::DISABLE_NONE;
[email protected]612a1cb12012-10-17 13:18:031904}
[email protected]0db124b02012-11-07 04:55:051905
mlerman6a37b6a42014-11-26 22:10:531906// Helper method to determine if an extension can be blocked.
1907bool ExtensionService::CanBlockExtension(const Extension* extension) const {
mlerman3690e5be2014-12-01 22:57:441908 DCHECK(extension);
mlerman6a37b6a42014-11-26 22:10:531909 return extension->location() != Manifest::COMPONENT &&
1910 extension->location() != Manifest::EXTERNAL_COMPONENT &&
achuith2f5578b2016-02-26 21:57:131911 !system_->management_policy()->MustRemainEnabled(extension, nullptr);
mlerman6a37b6a42014-11-26 22:10:531912}
1913
Devlin Cronineea1b7a2018-05-26 02:46:211914InstallGate::Action ExtensionService::ShouldDelayExtensionInstall(
1915 const Extension* extension,
xiyuanf6a4c6a62016-04-19 18:14:541916 bool install_immediately,
Devlin Cronineea1b7a2018-05-26 02:46:211917 ExtensionPrefs::DelayReason* reason) const {
xiyuanf6a4c6a62016-04-19 18:14:541918 for (const auto& entry : install_delayer_registry_) {
Devlin Cronineea1b7a2018-05-26 02:46:211919 InstallGate* const delayer = entry.second;
1920 InstallGate::Action action =
xiyuanf6a4c6a62016-04-19 18:14:541921 delayer->ShouldDelay(extension, install_immediately);
Devlin Cronineea1b7a2018-05-26 02:46:211922 if (action != InstallGate::INSTALL) {
xiyuanf6a4c6a62016-04-19 18:14:541923 *reason = entry.first;
1924 return action;
1925 }
[email protected]e7aa7b7e2012-11-27 04:51:221926 }
[email protected]fdd679b2012-11-15 20:49:391927
Devlin Cronineea1b7a2018-05-26 02:46:211928 return InstallGate::INSTALL;
[email protected]9f4e4f082013-06-21 07:11:191929}
1930
1931void ExtensionService::MaybeFinishDelayedInstallations() {
1932 std::vector<std::string> to_be_installed;
achuith2f5578b2016-02-26 21:57:131933 for (const auto& extension : delayed_installs_) {
1934 to_be_installed.push_back(extension->id());
[email protected]399583b2012-12-11 09:33:421935 }
achuith2f5578b2016-02-26 21:57:131936 for (const auto& extension_id : to_be_installed) {
Toni Barzic667db0d32018-01-09 18:00:191937 FinishDelayedInstallationIfReady(extension_id,
1938 false /*install_immediately*/);
[email protected]399583b2012-12-11 09:33:421939 }
[email protected]399583b2012-12-11 09:33:421940}
1941
[email protected]fdd679b2012-11-15 20:49:391942void ExtensionService::OnBlacklistUpdated() {
[email protected]2d19eb6e2014-01-27 17:30:001943 blacklist_->GetBlacklistedIDs(
[email protected]f47f7172014-03-19 19:27:101944 registry_->GenerateInstalledExtensionsSet()->GetIDs(),
[email protected]3f2a2fa2013-09-24 02:55:251945 base::Bind(&ExtensionService::ManageBlacklist, AsWeakPtr()));
[email protected]695b5712012-12-06 23:55:281946}
1947
weidongg04695232017-06-09 00:01:051948void ExtensionService::OnUpgradeRecommended() {
1949 // Notify observers that chrome update is available.
1950 for (auto& observer : update_observers_)
1951 observer.OnChromeUpdateAvailable();
1952}
1953
Devlin Cronineea1b7a2018-05-26 02:46:211954void ExtensionService::PreAddExtension(const Extension* extension,
1955 const Extension* old_extension) {
Michael Giuffrida573992d2018-02-08 00:48:441956 // Check if the extension's privileges have changed and mark the
1957 // extension disabled if necessary.
1958 CheckPermissionsIncrease(extension, !!old_extension);
1959}
1960
Michael Giuffrida6397c592017-10-09 20:46:531961bool ExtensionService::CanEnableExtension(const Extension* extension) {
1962 return !system_->management_policy()->MustRemainDisabled(extension, nullptr,
1963 nullptr);
1964}
1965
1966bool ExtensionService::CanDisableExtension(const Extension* extension) {
1967 // Some extensions cannot be disabled by users:
1968 // - |extension| can be null if sync disables an extension that is not
1969 // installed yet; allow disablement in this case.
1970 if (!extension)
1971 return true;
1972
1973 // - Shared modules are just resources used by other extensions, and are not
1974 // user-controlled.
1975 if (SharedModuleInfo::IsSharedModule(extension))
1976 return false;
1977
1978 // - EXTERNAL_COMPONENT extensions are not generally modifiable by users, but
1979 // can be uninstalled by the browser if the user sets extension-specific
1980 // preferences.
1981 if (extension->location() == Manifest::EXTERNAL_COMPONENT)
1982 return true;
1983
1984 return system_->management_policy()->UserMayModifySettings(extension,
1985 nullptr);
1986}
1987
1988bool ExtensionService::ShouldBlockExtension(const Extension* extension) {
1989 if (!block_extensions_)
1990 return false;
1991
1992 // Blocked extensions aren't marked as such in prefs, thus if
1993 // |block_extensions_| is true then CanBlockExtension() must be called with an
1994 // Extension object. If |extension| is not loaded, assume it should be
1995 // blocked.
1996 return !extension || CanBlockExtension(extension);
1997}
1998
Evan Staded89e11c2019-09-05 18:08:561999void ExtensionService::OnProfileMarkedForPermanentDeletion(Profile* profile) {
2000 if (profile != profile_)
2001 return;
2002
2003 ExtensionIdSet ids_to_unload = registry_->enabled_extensions().GetIDs();
2004 for (auto it = ids_to_unload.begin(); it != ids_to_unload.end(); ++it)
2005 UnloadExtension(*it, UnloadedExtensionReason::PROFILE_SHUTDOWN);
2006}
2007
[email protected]2d19eb6e2014-01-27 17:30:002008void ExtensionService::ManageBlacklist(
Devlin Cronineea1b7a2018-05-26 02:46:212009 const Blacklist::BlacklistStateMap& state_map) {
[email protected]54ee8192014-03-29 17:37:242010 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]695b5712012-12-06 23:55:282011
mlerman6a37b6a42014-11-26 22:10:532012 std::set<std::string> blacklisted;
[email protected]2d19eb6e2014-01-27 17:30:002013 ExtensionIdSet greylist;
2014 ExtensionIdSet unchanged;
achuith2f5578b2016-02-26 21:57:132015 for (const auto& it : state_map) {
2016 switch (it.second) {
Devlin Cronineea1b7a2018-05-26 02:46:212017 case NOT_BLACKLISTED:
[email protected]2d19eb6e2014-01-27 17:30:002018 break;
[email protected]695b5712012-12-06 23:55:282019
Devlin Cronineea1b7a2018-05-26 02:46:212020 case BLACKLISTED_MALWARE:
achuith2f5578b2016-02-26 21:57:132021 blacklisted.insert(it.first);
[email protected]2d19eb6e2014-01-27 17:30:002022 break;
2023
Devlin Cronineea1b7a2018-05-26 02:46:212024 case BLACKLISTED_SECURITY_VULNERABILITY:
2025 case BLACKLISTED_CWS_POLICY_VIOLATION:
2026 case BLACKLISTED_POTENTIALLY_UNWANTED:
achuith2f5578b2016-02-26 21:57:132027 greylist.insert(it.first);
[email protected]2d19eb6e2014-01-27 17:30:002028 break;
2029
Devlin Cronineea1b7a2018-05-26 02:46:212030 case BLACKLISTED_UNKNOWN:
achuith2f5578b2016-02-26 21:57:132031 unchanged.insert(it.first);
[email protected]2d19eb6e2014-01-27 17:30:002032 break;
2033 }
2034 }
2035
mlerman6a37b6a42014-11-26 22:10:532036 UpdateBlacklistedExtensions(blacklisted, unchanged);
[email protected]2d19eb6e2014-01-27 17:30:002037 UpdateGreylistedExtensions(greylist, unchanged, state_map);
2038
[email protected]373daf972014-04-10 01:50:442039 error_controller_->ShowErrorIfNeeded();
[email protected]2d19eb6e2014-01-27 17:30:002040}
2041
2042namespace {
2043void Partition(const ExtensionIdSet& before,
2044 const ExtensionIdSet& after,
2045 const ExtensionIdSet& unchanged,
2046 ExtensionIdSet* no_longer,
2047 ExtensionIdSet* not_yet) {
2048 *not_yet = base::STLSetDifference<ExtensionIdSet>(after, before);
2049 *no_longer = base::STLSetDifference<ExtensionIdSet>(before, after);
2050 *no_longer = base::STLSetDifference<ExtensionIdSet>(*no_longer, unchanged);
2051}
2052} // namespace
2053
mlerman6a37b6a42014-11-26 22:10:532054void ExtensionService::UpdateBlacklistedExtensions(
2055 const ExtensionIdSet& blacklisted,
[email protected]2d19eb6e2014-01-27 17:30:002056 const ExtensionIdSet& unchanged) {
2057 ExtensionIdSet not_yet_blocked, no_longer_blocked;
mlerman6a37b6a42014-11-26 22:10:532058 Partition(registry_->blacklisted_extensions().GetIDs(), blacklisted,
2059 unchanged, &no_longer_blocked, &not_yet_blocked);
[email protected]2d19eb6e2014-01-27 17:30:002060
jdoerrie13cd648c82018-10-02 21:21:022061 for (auto it = no_longer_blocked.begin(); it != no_longer_blocked.end();
2062 ++it) {
[email protected]695b5712012-12-06 23:55:282063 scoped_refptr<const Extension> extension =
[email protected]bb1bc9b32013-12-21 03:09:142064 registry_->blacklisted_extensions().GetByID(*it);
[email protected]3f2a2fa2013-09-24 02:55:252065 if (!extension.get()) {
mlerman6a37b6a42014-11-26 22:10:532066 NOTREACHED() << "Extension " << *it << " no longer blacklisted, "
2067 << "but it was never blacklisted.";
[email protected]695b5712012-12-06 23:55:282068 continue;
[email protected]3f2a2fa2013-09-24 02:55:252069 }
[email protected]bb1bc9b32013-12-21 03:09:142070 registry_->RemoveBlacklisted(*it);
atuchin6dc7c442016-07-20 07:04:342071 extension_prefs_->SetExtensionBlacklistState(extension->id(),
Devlin Cronineea1b7a2018-05-26 02:46:212072 NOT_BLACKLISTED);
[email protected]dc24976f2013-06-02 21:15:092073 AddExtension(extension.get());
[email protected]ac875372013-02-28 04:36:092074 UMA_HISTOGRAM_ENUMERATION("ExtensionBlacklist.UnblacklistInstalled",
[email protected]dc24976f2013-06-02 21:15:092075 extension->location(),
2076 Manifest::NUM_LOCATIONS);
[email protected]695b5712012-12-06 23:55:282077 }
2078
jdoerrie13cd648c82018-10-02 21:21:022079 for (auto it = not_yet_blocked.begin(); it != not_yet_blocked.end(); ++it) {
[email protected]695b5712012-12-06 23:55:282080 scoped_refptr<const Extension> extension = GetInstalledExtension(*it);
[email protected]3f2a2fa2013-09-24 02:55:252081 if (!extension.get()) {
2082 NOTREACHED() << "Extension " << *it << " needs to be "
2083 << "blacklisted, but it's not installed.";
[email protected]695b5712012-12-06 23:55:282084 continue;
[email protected]3f2a2fa2013-09-24 02:55:252085 }
[email protected]bb1bc9b32013-12-21 03:09:142086 registry_->AddBlacklisted(extension);
Devlin Cronineea1b7a2018-05-26 02:46:212087 extension_prefs_->SetExtensionBlacklistState(extension->id(),
2088 BLACKLISTED_MALWARE);
limasdf0deef2042017-05-03 19:17:172089 UnloadExtension(*it, UnloadedExtensionReason::BLACKLIST);
[email protected]ac875372013-02-28 04:36:092090 UMA_HISTOGRAM_ENUMERATION("ExtensionBlacklist.BlacklistInstalled",
2091 extension->location(), Manifest::NUM_LOCATIONS);
[email protected]695b5712012-12-06 23:55:282092 }
[email protected]2d19eb6e2014-01-27 17:30:002093}
[email protected]695b5712012-12-06 23:55:282094
[email protected]2d19eb6e2014-01-27 17:30:002095// TODO(oleg): UMA logging
2096void ExtensionService::UpdateGreylistedExtensions(
2097 const ExtensionIdSet& greylist,
2098 const ExtensionIdSet& unchanged,
Devlin Cronineea1b7a2018-05-26 02:46:212099 const Blacklist::BlacklistStateMap& state_map) {
[email protected]2d19eb6e2014-01-27 17:30:002100 ExtensionIdSet not_yet_greylisted, no_longer_greylisted;
2101 Partition(greylist_.GetIDs(),
2102 greylist, unchanged,
2103 &no_longer_greylisted, &not_yet_greylisted);
2104
jdoerrie13cd648c82018-10-02 21:21:022105 for (auto it = no_longer_greylisted.begin(); it != no_longer_greylisted.end();
2106 ++it) {
[email protected]2d19eb6e2014-01-27 17:30:002107 scoped_refptr<const Extension> extension = greylist_.GetByID(*it);
2108 if (!extension.get()) {
2109 NOTREACHED() << "Extension " << *it << " no longer greylisted, "
2110 << "but it was not marked as greylisted.";
2111 continue;
2112 }
2113
2114 greylist_.Remove(*it);
2115 extension_prefs_->SetExtensionBlacklistState(extension->id(),
Devlin Cronineea1b7a2018-05-26 02:46:212116 NOT_BLACKLISTED);
[email protected]2d19eb6e2014-01-27 17:30:002117 if (extension_prefs_->GetDisableReasons(extension->id()) &
Devlin Cronineea1b7a2018-05-26 02:46:212118 disable_reason::DISABLE_GREYLIST)
[email protected]2d19eb6e2014-01-27 17:30:002119 EnableExtension(*it);
2120 }
2121
jdoerrie13cd648c82018-10-02 21:21:022122 for (auto it = not_yet_greylisted.begin(); it != not_yet_greylisted.end();
2123 ++it) {
[email protected]2d19eb6e2014-01-27 17:30:002124 scoped_refptr<const Extension> extension = GetInstalledExtension(*it);
2125 if (!extension.get()) {
2126 NOTREACHED() << "Extension " << *it << " needs to be "
2127 << "disabled, but it's not installed.";
2128 continue;
2129 }
2130 greylist_.Insert(extension);
2131 extension_prefs_->SetExtensionBlacklistState(extension->id(),
2132 state_map.find(*it)->second);
2133 if (registry_->enabled_extensions().Contains(extension->id()))
Devlin Cronineea1b7a2018-05-26 02:46:212134 DisableExtension(*it, disable_reason::DISABLE_GREYLIST);
[email protected]2d19eb6e2014-01-27 17:30:002135 }
[email protected]fdd679b2012-11-15 20:49:392136}
[email protected]75bdcb872013-03-13 00:41:452137
Devlin Cronineea1b7a2018-05-26 02:46:212138void ExtensionService::AddUpdateObserver(UpdateObserver* observer) {
[email protected]75bdcb872013-03-13 00:41:452139 update_observers_.AddObserver(observer);
2140}
2141
Devlin Cronineea1b7a2018-05-26 02:46:212142void ExtensionService::RemoveUpdateObserver(UpdateObserver* observer) {
[email protected]75bdcb872013-03-13 00:41:452143 update_observers_.RemoveObserver(observer);
2144}
[email protected]bb1bc9b32013-12-21 03:09:142145
Devlin Cronineea1b7a2018-05-26 02:46:212146void ExtensionService::RegisterInstallGate(ExtensionPrefs::DelayReason reason,
2147 InstallGate* install_delayer) {
xiyuanf6a4c6a62016-04-19 18:14:542148 DCHECK(install_delayer_registry_.end() ==
2149 install_delayer_registry_.find(reason));
2150 install_delayer_registry_[reason] = install_delayer;
2151}
2152
Devlin Cronineea1b7a2018-05-26 02:46:212153void ExtensionService::UnregisterInstallGate(InstallGate* install_delayer) {
xiyuanf6a4c6a62016-04-19 18:14:542154 for (auto it = install_delayer_registry_.begin();
2155 it != install_delayer_registry_.end(); ++it) {
2156 if (it->second == install_delayer) {
2157 install_delayer_registry_.erase(it);
2158 return;
2159 }
2160 }
2161}
2162
[email protected]bb1bc9b32013-12-21 03:09:142163// Used only by test code.
2164void ExtensionService::UnloadAllExtensionsInternal() {
2165 profile_->GetExtensionSpecialStoragePolicy()->RevokeRightsForAllExtensions();
2166
2167 registry_->ClearAll();
[email protected]45f5b7d2014-01-22 23:47:132168 system_->runtime_data()->ClearAll();
[email protected]bb1bc9b32013-12-21 03:09:142169
2170 // TODO(erikkay) should there be a notification for this? We can't use
Devlin Cronineea1b7a2018-05-26 02:46:212171 // EXTENSION_UNLOADED since that implies that the extension has
Minh X. Nguyen45479012017-08-18 21:35:362172 // been disabled or uninstalled.
[email protected]bb1bc9b32013-12-21 03:09:142173}
[email protected]ebe07772014-05-22 04:16:062174
rdevlin.croninf2e1cb012017-05-27 01:27:592175void ExtensionService::OnInstalledExtensionsLoaded() {
2176 if (updater_)
2177 updater_->Start();
2178
2179 // Enable any Shared Modules that incorrectly got disabled previously.
2180 // This is temporary code to fix incorrect behavior from previous versions of
2181 // Chrome and can be removed after several releases (perhaps M60).
Devlin Cronineea1b7a2018-05-26 02:46:212182 ExtensionList to_enable;
rdevlin.croninf2e1cb012017-05-27 01:27:592183 for (const auto& extension : registry_->disabled_extensions()) {
2184 if (SharedModuleInfo::IsSharedModule(extension.get()))
2185 to_enable.push_back(extension);
2186 }
2187 for (const auto& extension : to_enable) {
2188 EnableExtension(extension->id());
2189 }
2190
2191 OnBlacklistUpdated();
2192}
lazyboy75b9def2017-06-06 18:56:592193
Takumi Fujimoto43c8c00f2017-07-26 22:48:562194void ExtensionService::UninstallMigratedExtensions() {
2195 std::unique_ptr<ExtensionSet> installed_extensions =
2196 registry_->GenerateInstalledExtensionsSet();
2197
2198 for (const std::string& extension_id : kMigratedExtensionIds) {
2199 if (installed_extensions->Contains(extension_id)) {
Devlin Cronineea1b7a2018-05-26 02:46:212200 UninstallExtension(extension_id, UNINSTALL_REASON_MIGRATED, nullptr);
Takumi Fujimoto43c8c00f2017-07-26 22:48:562201 }
2202 }
2203}
Devlin Cronineea1b7a2018-05-26 02:46:212204
2205} // namespace extensions