blob: 8e931b2ad6af2b6620bb22789129e0f0b60ee8fe [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"
[email protected]9ea0cd32013-07-12 01:50:3635#include "chrome/browser/chrome_notification_types.h"
sunil.ratnu21b896c2014-11-24 10:09:2436#include "chrome/browser/extensions/api/content_settings/content_settings_custom_extension_provider.h"
mukai87a8d402014-09-15 20:15:0937#include "chrome/browser/extensions/api/content_settings/content_settings_service.h"
ryanackley48bedbd2015-01-27 23:12:1438#include "chrome/browser/extensions/app_data_migrator.h"
[email protected]d8c8f25f2011-11-02 18:18:0139#include "chrome/browser/extensions/component_loader.h"
[email protected]13e062e2014-08-09 10:21:5540#include "chrome/browser/extensions/crx_installer.h"
[email protected]d9ede582012-08-14 19:21:3841#include "chrome/browser/extensions/data_deleter.h"
rdevlin.cronin2813c1b2014-08-26 23:51:0842#include "chrome/browser/extensions/extension_action_storage_manager.h"
[email protected]5a145e82014-05-29 22:19:0743#include "chrome/browser/extensions/extension_assets_manager.h"
[email protected]62f051c2012-03-29 17:04:4444#include "chrome/browser/extensions/extension_disabled_ui.h"
[email protected]373daf972014-04-10 01:50:4445#include "chrome/browser/extensions/extension_error_controller.h"
[email protected]19eb80152011-02-26 00:28:4346#include "chrome/browser/extensions/extension_special_storage_policy.h"
[email protected]f8aefb132013-10-30 09:29:5247#include "chrome/browser/extensions/extension_sync_service.h"
[email protected]617342a42013-12-18 23:34:0348#include "chrome/browser/extensions/extension_util.h"
[email protected]2894a512014-06-26 19:03:5649#include "chrome/browser/extensions/external_install_manager.h"
[email protected]5df038b2012-07-16 19:03:2750#include "chrome/browser/extensions/external_provider_impl.h"
Oleg Davydovc00866812019-04-04 10:47:2751#include "chrome/browser/extensions/forced_extensions/installation_reporter.h"
[email protected]ffd2f79e2013-11-14 00:11:4652#include "chrome/browser/extensions/install_verifier.h"
[email protected]d8c8f25f2011-11-02 18:18:0153#include "chrome/browser/extensions/installed_loader.h"
[email protected]f3d3b382014-03-14 21:19:2854#include "chrome/browser/extensions/pending_extension_manager.h"
[email protected]13e062e2014-08-09 10:21:5555#include "chrome/browser/extensions/permissions_updater.h"
[email protected]90878c52014-04-04 18:21:0256#include "chrome/browser/extensions/shared_module_service.h"
[email protected]13e062e2014-08-09 10:21:5557#include "chrome/browser/extensions/unpacked_installer.h"
rockotdb5192992014-09-16 21:27:0258#include "chrome/browser/extensions/updater/chrome_extension_downloader_factory.h"
[email protected]13e062e2014-08-09 10:21:5559#include "chrome/browser/extensions/updater/extension_updater.h"
rockotdb5192992014-09-16 21:27:0260#include "chrome/browser/google/google_brand.h"
[email protected]8ecad5e2010-12-02 21:18:3361#include "chrome/browser/profiles/profile.h"
[email protected]b5a507b22013-11-08 20:41:5762#include "chrome/browser/ui/webui/extensions/extension_icon_source.h"
[email protected]c8d407e2011-04-28 21:27:1763#include "chrome/browser/ui/webui/favicon_source.h"
[email protected]b07e606e2012-09-15 20:16:1564#include "chrome/browser/ui/webui/theme_source.h"
Greg Thompson8bcd799b2018-08-10 09:49:3365#include "chrome/browser/upgrade_detector/upgrade_detector.h"
Alan Cutter6e963f02019-05-06 00:33:2266#include "chrome/browser/web_applications/components/externally_installed_web_app_prefs.h"
Scott Violet6200d332018-02-23 21:29:2367#include "chrome/common/buildflags.h"
[email protected]e2eb43112009-05-29 21:19:5468#include "chrome/common/chrome_switches.h"
[email protected]f6431be82013-09-07 02:53:4569#include "chrome/common/crash_keys.h"
[email protected]9f4e4f082013-06-21 07:11:1970#include "chrome/common/extensions/extension_constants.h"
[email protected]a57209872009-05-04 22:53:1471#include "chrome/common/url_constants.h"
mukai8eaec822014-10-25 17:53:1672#include "components/content_settings/core/browser/host_content_settings_map.h"
[email protected]fdd28372014-08-21 02:27:2673#include "components/crx_file/id_util.h"
Victor Hugo Vianna Silvaed441482019-06-27 12:40:4074#include "components/favicon_base/favicon_url_parser.h"
Eric Seckler8652dcd52018-09-20 10:42:2875#include "content/public/browser/browser_task_traits.h"
Gabriel Charette790754c2018-03-16 21:32:5976#include "content/public/browser/browser_thread.h"
[email protected]05aad2da2011-10-28 10:12:3777#include "content/public/browser/notification_service.h"
[email protected]f3b1a082011-11-18 00:34:3078#include "content/public/browser/render_process_host.h"
[email protected]399583b2012-12-11 09:33:4279#include "content/public/browser/storage_partition.h"
[email protected]34423532013-11-21 18:13:1080#include "extensions/browser/event_router.h"
Devlin Cronin40b4cbc2017-08-02 01:57:5981#include "extensions/browser/extension_file_task_runner.h"
[email protected]22401dc2014-03-21 01:38:5782#include "extensions/browser/extension_host.h"
[email protected]bb1bc9b32013-12-21 03:09:1483#include "extensions/browser/extension_registry.h"
[email protected]59b0e602014-01-30 00:41:2484#include "extensions/browser/extension_system.h"
Michael Giuffrida7efeed142017-06-07 06:29:2185#include "extensions/browser/extension_util.h"
rockotffa65b12014-10-14 17:19:0686#include "extensions/browser/extensions_browser_client.h"
lazyboye8634172016-01-28 00:10:4887#include "extensions/browser/external_install_info.h"
[email protected]4a1d9c0d2014-06-13 12:50:1188#include "extensions/browser/install_flag.h"
Michael Giuffrida6397c592017-10-09 20:46:5389#include "extensions/browser/management_policy.h"
[email protected]45f5b7d2014-01-22 23:47:1390#include "extensions/browser/runtime_data.h"
[email protected]e43c61f2014-07-20 21:46:3491#include "extensions/browser/uninstall_reason.h"
[email protected]a9aa62b312013-11-29 05:35:0692#include "extensions/browser/update_observer.h"
rockotffa65b12014-10-14 17:19:0693#include "extensions/browser/updater/extension_cache.h"
rockot05f40a922014-10-16 19:40:2594#include "extensions/browser/updater/extension_downloader.h"
Oleg Davydov6541a64f2019-04-17 13:17:3395#include "extensions/browser/updater/manifest_fetch_data.h"
[email protected]fb820c02014-03-13 15:07:0896#include "extensions/common/extension_messages.h"
rockot90659852014-09-18 19:31:5297#include "extensions/common/extension_urls.h"
[email protected]5ef835a2013-11-08 20:42:5798#include "extensions/common/feature_switch.h"
rdevlin.cronin41227532016-07-13 21:24:3499#include "extensions/common/features/feature_channel.h"
[email protected]85df9d12014-04-15 17:02:14100#include "extensions/common/file_util.h"
[email protected]0c3c9732013-09-16 08:53:41101#include "extensions/common/manifest_constants.h"
Michael Giuffrida6397c592017-10-09 20:46:53102#include "extensions/common/manifest_handlers/shared_module_info.h"
rockotd5546142014-10-15 00:29:08103#include "extensions/common/manifest_url_handlers.h"
treib2e0517f92015-05-07 23:15:36104#include "extensions/common/permissions/api_permission.h"
[email protected]c41003472013-10-19 15:37:25105#include "extensions/common/permissions/permission_message_provider.h"
[email protected]e4452d32013-11-15 23:07:41106#include "extensions/common/permissions/permissions_data.h"
Michael Giuffridab158f3f2017-07-17 19:53:44107#include "extensions/common/switches.h"
[email protected]79a60642012-10-20 21:03:18108
brettw9e85ef42016-11-01 21:01:24109#if BUILDFLAG(ENABLE_SUPERVISED_USERS)
treib8ecc1eb52015-03-04 18:29:06110#include "chrome/browser/supervised_user/supervised_user_service.h"
111#include "chrome/browser/supervised_user/supervised_user_service_factory.h"
112#endif
113
[email protected]eed367e2011-04-12 03:43:31114#if defined(OS_CHROMEOS)
[email protected]88e8ec9152013-01-17 04:05:18115#include "chrome/browser/chromeos/extensions/install_limiter.h"
achuithd3da4f02017-03-23 20:05:29116#include "chrome/browser/chromeos/profiles/profile_helper.h"
pilgrime92c5fcd2014-09-10 23:31:23117#include "storage/browser/fileapi/file_system_backend.h"
118#include "storage/browser/fileapi/file_system_context.h"
[email protected]eed367e2011-04-12 03:43:31119#endif
120
[email protected]55eb70e762012-02-20 17:38:39121using content::BrowserContext;
[email protected]631bb742011-11-02 11:29:39122using content::BrowserThread;
Devlin Cronineea1b7a2018-05-26 02:46:21123
124namespace extensions {
[email protected]5ef47ec2010-01-28 05:58:05125
Michael Giuffrida573992d2018-02-08 00:48:44126using LoadErrorBehavior = ExtensionRegistrar::LoadErrorBehavior;
127
[email protected]b6ab96d2009-08-20 18:58:19128namespace {
129
Lei Zhang15339152018-08-09 22:20:44130// Wait this long after an extensions becomes idle before updating it.
131constexpr base::TimeDelta kUpdateIdleDelay = base::TimeDelta::FromSeconds(5);
[email protected]0db124b02012-11-07 04:55:05132
Takumi Fujimoto43c8c00f2017-07-26 22:48:56133// IDs of extensions that have been replaced by component extensions and need to
134// be uninstalled.
Lei Zhang15339152018-08-09 22:20:44135const char* const kMigratedExtensionIds[] = {
Takumi Fujimoto43c8c00f2017-07-26 22:48:56136 "boadgeojelhgndaghljhdicfkmllpafd", // Google Cast
137 "dliochdbjfkdbacpmhlcpmleaejidimm" // Google Cast (Beta)
138};
139
[email protected]c6d474f82009-12-16 21:11:06140} // namespace
[email protected]b6ab96d2009-08-20 18:58:19141
[email protected]eaa7dd182010-12-14 11:09:00142// ExtensionService.
[email protected]6014d672008-12-05 00:38:25143
[email protected]8e4560b62011-01-14 10:09:14144void ExtensionService::CheckExternalUninstall(const std::string& id) {
[email protected]a29a517a2011-01-21 21:11:12145 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]a8af9fdb2010-10-28 21:52:20146
[email protected]7a4c6852010-09-16 03:44:22147 // Check if the providers know about this extension.
achuith2f5578b2016-02-26 21:57:13148 for (const auto& provider : external_extension_providers_) {
149 DCHECK(provider->IsReady());
150 if (provider->HasExtension(id))
[email protected]0a60a2e2010-10-25 16:15:21151 return; // Yup, known extension, don't uninstall.
[email protected]7a4c6852010-09-16 03:44:22152 }
153
Giovanni Ortuño Urquidi218522862018-08-28 12:48:04154 // Historically, the code under //chrome/browser/extensions has
155 // unsurprisingly managed all extensions. Later, Progressive Web Apps (PWAs)
156 // were implemented on top of extensions, more out of convenience than out of
157 // principle. As of mid 2018, there is work underway to separate PWAs's
158 // implementation details from the //c/b/e code. During the transition
159 // period, PWA-extensions are no longer managed solely by //c/b/e code. We
160 // add a special case here so that //c/b/e code doesn't uninstall
161 // PWA-extensions that it doesn't otherwise know about.
162 //
163 // Long term, PWAs will be completely separate from extensions, and we can
164 // remove this cross-link.
Alan Cutter6e963f02019-05-06 00:33:22165 if (web_app::ExternallyInstalledWebAppPrefs::HasAppId(profile_->GetPrefs(),
166 id)) {
Giovanni Ortuño Urquidi218522862018-08-28 12:48:04167 return;
168 }
169
[email protected]0f48fca2011-05-19 18:46:35170 // We get the list of external extensions to check from preferences.
171 // It is possible that an extension has preferences but is not loaded.
172 // For example, an extension that requires experimental permissions
173 // will not be loaded if the experimental command line flag is not used.
174 // In this case, do not uninstall.
[email protected]31bb5ee62012-09-12 22:58:40175 if (!GetInstalledExtension(id)) {
[email protected]0f48fca2011-05-19 18:46:35176 // We can't call UninstallExtension with an unloaded/invalid
177 // extension ID.
178 LOG(WARNING) << "Attempted uninstallation of unloaded/invalid extension "
179 << "with id: " << id;
180 return;
181 }
Devlin Cronineea1b7a2018-05-26 02:46:21182 UninstallExtension(id, UNINSTALL_REASON_ORPHANED_EXTERNAL_EXTENSION, nullptr);
[email protected]7a4c6852010-09-16 03:44:22183}
184
[email protected]8e4560b62011-01-14 10:09:14185void ExtensionService::ClearProvidersForTesting() {
[email protected]7a4c6852010-09-16 03:44:22186 external_extension_providers_.clear();
187}
188
[email protected]8e4560b62011-01-14 10:09:14189void ExtensionService::AddProviderForTesting(
lazyboyf33109d2016-08-31 00:37:08190 std::unique_ptr<ExternalProviderInterface> test_provider) {
[email protected]a29a517a2011-01-21 21:11:12191 CHECK(test_provider);
lazyboyf33109d2016-08-31 00:37:08192 external_extension_providers_.push_back(std::move(test_provider));
[email protected]7a4c6852010-09-16 03:44:22193}
194
[email protected]8f959f522014-08-06 06:26:28195void ExtensionService::BlacklistExtensionForTest(
196 const std::string& extension_id) {
mlerman6a37b6a42014-11-26 22:10:53197 ExtensionIdSet blacklisted;
[email protected]8f959f522014-08-06 06:26:28198 ExtensionIdSet unchanged;
mlerman6a37b6a42014-11-26 22:10:53199 blacklisted.insert(extension_id);
200 UpdateBlacklistedExtensions(blacklisted, unchanged);
[email protected]8f959f522014-08-06 06:26:28201}
202
[email protected]9060d8b02012-01-13 02:14:30203bool ExtensionService::OnExternalExtensionUpdateUrlFound(
lazyboye8634172016-01-28 00:10:48204 const ExternalInstallInfoUpdateUrl& info,
205 bool is_initial_load) {
Istiaque Ahmedf6e72622017-09-08 23:14:17206 DCHECK_CURRENTLY_ON(BrowserThread::UI);
lazyboye8634172016-01-28 00:10:48207 CHECK(crx_file::id_util::IdIsValid(info.extension_id));
[email protected]a8af9fdb2010-10-28 21:52:20208
lazyboye8634172016-01-28 00:10:48209 if (Manifest::IsExternalLocation(info.download_location)) {
[email protected]044e86992014-01-24 22:59:11210 // All extensions that are not user specific can be cached.
Devlin Cronineea1b7a2018-05-26 02:46:21211 ExtensionsBrowserClient::Get()->GetExtensionCache()->AllowCaching(
212 info.extension_id);
[email protected]044e86992014-01-24 22:59:11213 }
214
lazyboye8634172016-01-28 00:10:48215 const Extension* extension = GetExtensionById(info.extension_id, true);
[email protected]8a87a5332011-08-11 17:54:59216 if (extension) {
asargent56282ab72016-09-09 16:58:03217 // Already installed. Skip this install if the current location has higher
218 // priority than |info.download_location|, and we aren't doing a
219 // reinstall of a corrupt policy force-installed extension.
[email protected]1d5e58b2013-01-31 08:41:40220 Manifest::Location current = extension->location();
asargent56282ab72016-09-09 16:58:03221 if (!pending_extension_manager_.IsPolicyReinstallForCorruptionExpected(
222 info.extension_id) &&
223 current == Manifest::GetHigherPriorityLocation(
224 current, info.download_location)) {
Oleg Davydovc00866812019-04-04 10:47:27225 InstallationReporter::ReportFailure(
Sergey Poromov296de0a2018-10-11 21:44:08226 profile_, info.extension_id,
Oleg Davydovc00866812019-04-04 10:47:27227 InstallationReporter::FailureReason::ALREADY_INSTALLED);
[email protected]9060d8b02012-01-13 02:14:30228 return false;
lazyboye8634172016-01-28 00:10:48229 }
[email protected]8a87a5332011-08-11 17:54:59230 // Otherwise, overwrite the current installation.
[email protected]7a4c6852010-09-16 03:44:22231 }
[email protected]9060d8b02012-01-13 02:14:30232
lazyboye8634172016-01-28 00:10:48233 // Add |info.extension_id| to the set of pending extensions. If it can not
234 // be added, then there is already a pending record from a higher-priority
235 // install source. In this case, signal that this extension will not be
[email protected]9060d8b02012-01-13 02:14:30236 // installed by returning false.
Oleg Davydovc00866812019-04-04 10:47:27237 InstallationReporter::ReportInstallationStage(
238 profile_, info.extension_id, InstallationReporter::Stage::PENDING);
[email protected]9060d8b02012-01-13 02:14:30239 if (!pending_extension_manager()->AddFromExternalUpdateUrl(
Devlin Cronind4c2a8f32017-09-29 17:08:30240 info.extension_id, info.install_parameter, info.update_url,
lazyboye8634172016-01-28 00:10:48241 info.download_location, info.creation_flags,
242 info.mark_acknowledged)) {
Oleg Davydovc00866812019-04-04 10:47:27243 InstallationReporter::ReportFailure(
244 profile_, info.extension_id,
245 InstallationReporter::FailureReason::PENDING_ADD_FAILED);
[email protected]9060d8b02012-01-13 02:14:30246 return false;
[email protected]31bb5ee62012-09-12 22:58:40247 }
[email protected]9060d8b02012-01-13 02:14:30248
lazyboye8634172016-01-28 00:10:48249 if (is_initial_load)
250 update_once_all_providers_are_ready_ = true;
[email protected]9060d8b02012-01-13 02:14:30251 return true;
[email protected]7a4c6852010-09-16 03:44:22252}
253
lazyboye8634172016-01-28 00:10:48254void ExtensionService::OnExternalProviderUpdateComplete(
255 const ExternalProviderInterface* provider,
Devlin Cronin19f70b6a2017-10-01 04:14:05256 const std::vector<ExternalInstallInfoUpdateUrl>& update_url_extensions,
257 const std::vector<ExternalInstallInfoFile>& file_extensions,
lazyboye8634172016-01-28 00:10:48258 const std::set<std::string>& removed_extensions) {
259 // Update pending_extension_manager() with the new extensions first.
lazyboy4aeef202016-09-07 21:28:59260 for (const auto& extension : update_url_extensions)
Devlin Cronin19f70b6a2017-10-01 04:14:05261 OnExternalExtensionUpdateUrlFound(extension, false);
lazyboy4aeef202016-09-07 21:28:59262 for (const auto& extension : file_extensions)
Devlin Cronin19f70b6a2017-10-01 04:14:05263 OnExternalExtensionFileFound(extension);
lazyboye8634172016-01-28 00:10:48264
265#if DCHECK_IS_ON()
266 for (const std::string& id : removed_extensions) {
lazyboy4aeef202016-09-07 21:28:59267 for (const auto& extension : update_url_extensions)
Devlin Cronin19f70b6a2017-10-01 04:14:05268 DCHECK_NE(id, extension.extension_id);
lazyboy4aeef202016-09-07 21:28:59269 for (const auto& extension : file_extensions)
Devlin Cronin19f70b6a2017-10-01 04:14:05270 DCHECK_NE(id, extension.extension_id);
lazyboye8634172016-01-28 00:10:48271 }
272#endif
273
274 // Then uninstall before running |updater_|.
275 for (const std::string& id : removed_extensions)
276 CheckExternalUninstall(id);
277
278 if (!update_url_extensions.empty() && updater_) {
279 // Empty params will cause pending extensions to be updated.
Devlin Cronineea1b7a2018-05-26 02:46:21280 updater_->CheckNow(ExtensionUpdater::CheckParams());
lazyboye8634172016-01-28 00:10:48281 }
282
283 error_controller_->ShowErrorIfNeeded();
284 external_install_manager_->UpdateExternalExtensionAlert();
285}
286
[email protected]eaa7dd182010-12-14 11:09:00287ExtensionService::ExtensionService(Profile* profile,
avi3ef9ec9e2014-12-22 22:50:17288 const base::CommandLine* command_line,
[email protected]650b2d52013-02-10 03:41:45289 const base::FilePath& install_directory,
Devlin Cronineea1b7a2018-05-26 02:46:21290 ExtensionPrefs* extension_prefs,
291 Blacklist* blacklist,
[email protected]0436b102011-04-15 18:30:03292 bool autoupdate_enabled,
[email protected]4a10006a2013-05-17 23:18:35293 bool extensions_enabled,
Christopher Lamebb90202019-04-04 03:42:36294 base::OneShotEvent* ready)
Devlin Cronineea1b7a2018-05-26 02:46:21295 : Blacklist::Observer(blacklist),
catmullings98cd1942016-08-30 22:31:59296 command_line_(command_line),
[email protected]fdd679b2012-11-15 20:49:39297 profile_(profile),
Devlin Cronineea1b7a2018-05-26 02:46:21298 system_(ExtensionSystem::Get(profile)),
[email protected]73c47932010-12-06 18:13:43299 extension_prefs_(extension_prefs),
[email protected]695b5712012-12-06 23:55:28300 blacklist_(blacklist),
Devlin Cronineea1b7a2018-05-26 02:46:21301 registry_(ExtensionRegistry::Get(profile)),
[email protected]6c9bedf2014-05-21 03:55:51302 pending_extension_manager_(profile),
[email protected]a9b00ac2009-06-25 21:03:23303 install_directory_(install_directory),
[email protected]0436b102011-04-15 18:30:03304 extensions_enabled_(extensions_enabled),
[email protected]4a10006a2013-05-17 23:18:35305 ready_(ready),
Devlin Cronineea1b7a2018-05-26 02:46:21306 shared_module_service_(new SharedModuleService(profile_)),
307 app_data_migrator_(new AppDataMigrator(profile_, registry_)),
Sergey Poromov0360b9e72018-04-19 17:37:29308 extension_registrar_(profile_, this),
Sergey Poromov296de0a2018-10-11 21:44:08309 forced_extensions_tracker_(registry_, profile_) {
[email protected]a29a517a2011-01-21 21:11:12310 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
rkaplowdd66a1342015-03-05 00:31:49311 TRACE_EVENT0("browser,startup", "ExtensionService::ExtensionService::ctor");
[email protected]a8af9fdb2010-10-28 21:52:20312
[email protected]36a784c2009-06-23 06:21:08313 // Figure out if extension installation should be enabled.
Devlin Cronineea1b7a2018-05-26 02:46:21314 if (ExtensionsBrowserClient::Get()->AreExtensionsDisabled(*command_line,
315 profile))
[email protected]6d60703b2009-08-29 01:29:23316 extensions_enabled_ = false;
[email protected]36a784c2009-06-23 06:21:08317
[email protected]3c4abc82012-10-22 22:25:54318 registrar_.Add(this, chrome::NOTIFICATION_APP_TERMINATING,
319 content::NotificationService::AllBrowserContextsAndSources());
Devlin Cronineea1b7a2018-05-26 02:46:21320 registrar_.Add(this, NOTIFICATION_EXTENSION_PROCESS_TERMINATED,
[email protected]ad50def52011-10-19 23:17:07321 content::NotificationService::AllBrowserContextsAndSources());
[email protected]432115822011-07-10 15:52:27322 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_TERMINATED,
[email protected]ad50def52011-10-19 23:17:07323 content::NotificationService::AllBrowserContextsAndSources());
[email protected]ebe07772014-05-22 04:16:06324 registrar_.Add(this,
325 chrome::NOTIFICATION_PROFILE_DESTRUCTION_STARTED,
326 content::Source<Profile>(profile_));
binjin1569c9b2014-09-05 13:33:18327
weidongg04695232017-06-09 00:01:05328 UpgradeDetector::GetInstance()->AddObserver(this);
329
Devlin Cronineea1b7a2018-05-26 02:46:21330 ExtensionManagementFactory::GetForBrowserContext(profile_)->AddObserver(this);
[email protected]4814b512009-11-07 00:12:29331
rkaplowdd66a1342015-03-05 00:31:49332 // Set up the ExtensionUpdater.
[email protected]93fd78f42009-07-10 16:43:17333 if (autoupdate_enabled) {
Devlin Cronineea1b7a2018-05-26 02:46:21334 updater_.reset(new ExtensionUpdater(
David Bertonidccbd352018-03-20 00:31:04335 this, extension_prefs, profile->GetPrefs(), profile,
Devlin Cronineea1b7a2018-05-26 02:46:21336 kDefaultUpdateFrequencySeconds,
337 ExtensionsBrowserClient::Get()->GetExtensionCache(),
rockotdb5192992014-09-16 21:27:02338 base::Bind(ChromeExtensionDownloaderFactory::CreateForProfile,
339 profile)));
[email protected]93fd78f42009-07-10 16:43:17340 }
341
Michael Giuffridabe1f9202019-06-05 22:36:18342 component_loader_ = std::make_unique<ComponentLoader>(this, profile);
[email protected]8e4560b62011-01-14 10:09:14343
[email protected]0436b102011-04-15 18:30:03344 if (extensions_enabled_) {
Devlin Cronineea1b7a2018-05-26 02:46:21345 ExternalProviderImpl::CreateExternalProviders(
[email protected]ae4c37e2012-12-21 01:16:25346 this, profile_, &external_extension_providers_);
[email protected]873531342011-03-09 12:16:05347 }
[email protected]b671760b2010-07-15 21:13:47348
[email protected]74474042013-11-21 12:03:54349 // Set this as the ExtensionService for app sorting to ensure it causes syncs
350 // if required.
[email protected]b3aa7182013-04-25 04:45:23351 is_first_run_ = !extension_prefs_->SetAlertSystemFirstRun();
352
[email protected]373daf972014-04-10 01:50:44353 error_controller_.reset(
Devlin Cronineea1b7a2018-05-26 02:46:21354 new ExtensionErrorController(profile_, is_first_run_));
[email protected]374ceb6f2014-07-02 19:25:34355 external_install_manager_.reset(
Devlin Cronineea1b7a2018-05-26 02:46:21356 new ExternalInstallManager(profile_, is_first_run_));
[email protected]373daf972014-04-10 01:50:44357
[email protected]c77f2352012-08-08 22:07:58358 extension_action_storage_manager_.reset(
Devlin Cronineea1b7a2018-05-26 02:46:21359 new ExtensionActionStorageManager(profile_));
[email protected]c77f2352012-08-08 22:07:58360
[email protected]cb0e50312011-05-09 15:03:07361 // How long is the path to the Extensions directory?
362 UMA_HISTOGRAM_CUSTOM_COUNTS("Extensions.ExtensionRootPathLength",
drbasicf0d1b262016-08-23 06:10:42363 install_directory_.value().length(), 1, 500, 100);
[email protected]6014d672008-12-05 00:38:25364}
365
Devlin Cronineea1b7a2018-05-26 02:46:21366PendingExtensionManager* ExtensionService::pending_extension_manager() {
[email protected]b2907fd2011-03-25 16:43:37367 return &pending_extension_manager_;
[email protected]ddb1e5a2010-12-13 20:10:45368}
369
[email protected]eaa7dd182010-12-14 11:09:00370ExtensionService::~ExtensionService() {
weidongg04695232017-06-09 00:01:05371 UpgradeDetector::GetInstance()->RemoveObserver(this);
[email protected]c8d407e2011-04-28 21:27:17372 // No need to unload extensions here because they are profile-scoped, and the
373 // profile is in the process of being deleted.
achuith2f5578b2016-02-26 21:57:13374 for (const auto& provider : external_extension_providers_)
[email protected]8e4560b62011-01-14 10:09:14375 provider->ServiceShutdown();
[email protected]6014d672008-12-05 00:38:25376}
377
[email protected]037228a2012-10-05 01:36:16378void ExtensionService::Shutdown() {
Oleg Davydovbf103f92019-07-30 15:55:08379 ExtensionManagementFactory::GetForBrowserContext(profile())->RemoveObserver(
380 this);
[email protected]037228a2012-10-05 01:36:16381}
382
[email protected]b2907fd2011-03-25 16:43:37383const Extension* ExtensionService::GetExtensionById(
384 const std::string& id, bool include_disabled) const {
[email protected]599539802014-01-07 23:06:00385 int include_mask = ExtensionRegistry::ENABLED;
[email protected]695b5712012-12-06 23:55:28386 if (include_disabled) {
mlerman6a37b6a42014-11-26 22:10:53387 // Include blacklisted and blocked extensions here because there are
388 // hundreds of callers of this function, and many might assume that this
389 // includes those that have been disabled due to blacklisting or blocking.
[email protected]599539802014-01-07 23:06:00390 include_mask |= ExtensionRegistry::DISABLED |
mlerman6a37b6a42014-11-26 22:10:53391 ExtensionRegistry::BLACKLISTED | ExtensionRegistry::BLOCKED;
[email protected]695b5712012-12-06 23:55:28392 }
[email protected]599539802014-01-07 23:06:00393 return registry_->GetExtensionById(id, include_mask);
[email protected]695b5712012-12-06 23:55:28394}
395
[email protected]eaa7dd182010-12-14 11:09:00396void ExtensionService::Init() {
[email protected]a29a517a2011-01-21 21:11:12397 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
rkaplowe65c2ff2015-02-14 16:29:54398 TRACE_EVENT0("browser,startup", "ExtensionService::Init");
rkaplowa8fd8d32015-02-25 21:27:56399 SCOPED_UMA_HISTOGRAM_TIMER("Extensions.ExtensionServiceInitTime");
[email protected]3350d712013-11-18 09:32:24400
[email protected]4a10006a2013-05-17 23:18:35401 DCHECK(!is_ready()); // Can't redo init.
[email protected]bb1bc9b32013-12-21 03:09:14402 DCHECK_EQ(registry_->enabled_extensions().size(), 0u);
[email protected]9f1087e2009-06-15 17:29:32403
benwells22ab8ee2015-08-21 02:55:08404 component_loader_->LoadAll();
achuithd3da4f02017-03-23 20:05:29405 bool load_saved_extensions = true;
emaxx35e8b822017-04-11 02:04:29406 bool load_command_line_extensions = extensions_enabled_;
achuithd3da4f02017-03-23 20:05:29407#if defined(OS_CHROMEOS)
tbarzicd2a741e2017-06-28 20:37:54408 if (chromeos::ProfileHelper::IsSigninProfile(profile_) ||
409 chromeos::ProfileHelper::IsLockScreenAppProfile(profile_)) {
achuithd3da4f02017-03-23 20:05:29410 load_saved_extensions = false;
emaxx35e8b822017-04-11 02:04:29411 load_command_line_extensions = false;
412 }
achuithd3da4f02017-03-23 20:05:29413#endif
rdevlin.croninf2e1cb012017-05-27 01:27:59414 if (load_saved_extensions)
Devlin Cronineea1b7a2018-05-26 02:46:21415 InstalledLoader(this).LoadAllExtensions();
rdevlin.croninf2e1cb012017-05-27 01:27:59416
Nick Peterson8aa8e052019-05-22 23:17:01417 CheckManagementPolicy();
rdevlin.croninf2e1cb012017-05-27 01:27:59418 OnInstalledExtensionsLoaded();
419
Devlin Cronineea1b7a2018-05-26 02:46:21420 LoadExtensionsFromCommandLineFlag(::switches::kDisableExtensionsExcept);
emaxx35e8b822017-04-11 02:04:29421 if (load_command_line_extensions)
Devlin Cronineea1b7a2018-05-26 02:46:21422 LoadExtensionsFromCommandLineFlag(switches::kLoadExtension);
benwells22ab8ee2015-08-21 02:55:08423 EnabledReloadableExtensions();
424 MaybeFinishShutdownDelayed();
425 SetReadyAndNotifyListeners();
[email protected]ae4c37e2012-12-21 01:16:25426
Takumi Fujimoto43c8c00f2017-07-26 22:48:56427 UninstallMigratedExtensions();
428
benwells22ab8ee2015-08-21 02:55:08429 // TODO(erikkay): this should probably be deferred to a future point
430 // rather than running immediately at startup.
431 CheckForExternalUpdates();
[email protected]894bb502009-05-21 22:39:57432
benwells22ab8ee2015-08-21 02:55:08433 LoadGreylistFromPrefs();
rkaplowa8fd8d32015-02-25 21:27:56434}
[email protected]3350d712013-11-18 09:32:24435
rkaplowa8fd8d32015-02-25 21:27:56436void ExtensionService::EnabledReloadableExtensions() {
437 TRACE_EVENT0("browser,startup",
438 "ExtensionService::EnabledReloadableExtensions");
439
440 std::vector<std::string> extensions_to_enable;
achuith2f5578b2016-02-26 21:57:13441 for (const auto& e : registry_->disabled_extensions()) {
rkaplowa8fd8d32015-02-25 21:27:56442 if (extension_prefs_->GetDisableReasons(e->id()) ==
Devlin Cronineea1b7a2018-05-26 02:46:21443 disable_reason::DISABLE_RELOAD)
rkaplowa8fd8d32015-02-25 21:27:56444 extensions_to_enable.push_back(e->id());
rkaplowa8fd8d32015-02-25 21:27:56445 }
446 for (const std::string& extension : extensions_to_enable) {
447 EnableExtension(extension);
448 }
449}
450
451void ExtensionService::MaybeFinishShutdownDelayed() {
452 TRACE_EVENT0("browser,startup",
453 "ExtensionService::MaybeFinishShutdownDelayed");
454
Devlin Cronineea1b7a2018-05-26 02:46:21455 std::unique_ptr<ExtensionPrefs::ExtensionsInfo> delayed_info(
rkaplowa8fd8d32015-02-25 21:27:56456 extension_prefs_->GetAllDelayedInstallInfo());
457 for (size_t i = 0; i < delayed_info->size(); ++i) {
458 ExtensionInfo* info = delayed_info->at(i).get();
achuith2f5578b2016-02-26 21:57:13459 scoped_refptr<const Extension> extension(nullptr);
rkaplowa8fd8d32015-02-25 21:27:56460 if (info->extension_manifest) {
461 std::string error;
462 extension = Extension::Create(
463 info->extension_path, info->extension_location,
464 *info->extension_manifest,
465 extension_prefs_->GetDelayedInstallCreationFlags(info->extension_id),
466 info->extension_id, &error);
467 if (extension.get())
468 delayed_installs_.Insert(extension);
469 }
470 }
471 MaybeFinishDelayedInstallations();
Devlin Cronineea1b7a2018-05-26 02:46:21472 std::unique_ptr<ExtensionPrefs::ExtensionsInfo> delayed_info2(
rkaplowa8fd8d32015-02-25 21:27:56473 extension_prefs_->GetAllDelayedInstallInfo());
474 UMA_HISTOGRAM_COUNTS_100("Extensions.UpdateOnLoad",
475 delayed_info2->size() - delayed_info->size());
[email protected]6014d672008-12-05 00:38:25476}
477
[email protected]2d19eb6e2014-01-27 17:30:00478void ExtensionService::LoadGreylistFromPrefs() {
rkaplowa8fd8d32015-02-25 21:27:56479 TRACE_EVENT0("browser,startup", "ExtensionService::LoadGreylistFromPrefs");
480
dchengc963c7142016-04-08 03:55:22481 std::unique_ptr<ExtensionSet> all_extensions =
[email protected]f47f7172014-03-19 19:27:10482 registry_->GenerateInstalledExtensionsSet();
[email protected]2d19eb6e2014-01-27 17:30:00483
achuith2f5578b2016-02-26 21:57:13484 for (const auto& extension : *all_extensions) {
Devlin Cronineea1b7a2018-05-26 02:46:21485 const BlacklistState state =
achuith2f5578b2016-02-26 21:57:13486 extension_prefs_->GetExtensionBlacklistState(extension->id());
Devlin Cronineea1b7a2018-05-26 02:46:21487 if (state == BLACKLISTED_SECURITY_VULNERABILITY ||
488 state == BLACKLISTED_POTENTIALLY_UNWANTED ||
489 state == BLACKLISTED_CWS_POLICY_VIOLATION)
achuith2f5578b2016-02-26 21:57:13490 greylist_.Insert(extension);
[email protected]2d19eb6e2014-01-27 17:30:00491 }
492}
493
Devlin Cronineea1b7a2018-05-26 02:46:21494bool ExtensionService::UpdateExtension(const CRXFileInfo& file,
[email protected]044e86992014-01-24 22:59:11495 bool file_ownership_passed,
[email protected]31bb5ee62012-09-12 22:58:40496 CrxInstaller** out_crx_installer) {
[email protected]a29a517a2011-01-21 21:11:12497 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]3c4abc82012-10-22 22:25:54498 if (browser_terminating_) {
499 LOG(WARNING) << "Skipping UpdateExtension due to browser shutdown";
500 // Leak the temp file at extension_path. We don't want to add to the disk
501 // I/O burden at shutdown, we can't rely on the I/O completing anyway, and
502 // the file is in the OS temp directory which should be cleaned up for us.
503 return false;
504 }
[email protected]a8af9fdb2010-10-28 21:52:20505
ginkage553af3202015-02-04 12:39:09506 const std::string& id = file.extension_id;
507
Devlin Cronineea1b7a2018-05-26 02:46:21508 const PendingExtensionInfo* pending_extension_info =
[email protected]51a3bf8b2012-06-08 22:53:06509 pending_extension_manager()->GetById(id);
[email protected]8ef78fd2010-08-19 17:14:32510
[email protected]695b5712012-12-06 23:55:28511 const Extension* extension = GetInstalledExtension(id);
[email protected]51a3bf8b2012-06-08 22:53:06512 if (!pending_extension_info && !extension) {
[email protected]aa142702010-03-26 01:26:33513 LOG(WARNING) << "Will not update extension " << id
514 << " because it is not installed or pending";
515 // Delete extension_path since we're not creating a CrxInstaller
516 // that would do it for us.
asargentd50b18c2016-04-21 01:17:16517 if (file_ownership_passed &&
Devlin Cronineea1b7a2018-05-26 02:46:21518 !GetExtensionFileTaskRunner()->PostTask(
519 FROM_HERE,
520 base::BindOnce(&file_util::DeleteFile, file.path, false)))
[email protected]14908b72011-04-20 06:54:36521 NOTREACHED();
[email protected]420a0ec2011-06-01 01:07:03522
523 return false;
[email protected]e957fe52009-06-23 16:51:05524 }
Minh X. Nguyen30975342017-12-04 22:02:41525 // Either |pending_extension_info| or |extension| or both must not be null.
treibe960e282015-09-11 10:38:08526 scoped_refptr<CrxInstaller> installer(CrxInstaller::CreateSilent(this));
[email protected]6dfbbf82010-03-12 23:09:16527 installer->set_expected_id(id);
ginkage47e603e2015-02-27 08:42:41528 installer->set_expected_hash(file.expected_hash);
[email protected]464213a2013-10-15 01:06:48529 int creation_flags = Extension::NO_FLAGS;
[email protected]51a3bf8b2012-06-08 22:53:06530 if (pending_extension_info) {
531 installer->set_install_source(pending_extension_info->install_source());
pkotwicz31eb1e8ec2014-10-08 15:26:46532 installer->set_allow_silent_install(true);
treibe960e282015-09-11 10:38:08533 // If the extension came in disabled due to a permission increase, then
534 // don't grant it all the permissions. crbug.com/484214
535 bool has_permissions_increase =
Devlin Cronineea1b7a2018-05-26 02:46:21536 ExtensionPrefs::Get(profile_)->HasDisableReason(
537 id, disable_reason::DISABLE_PERMISSIONS_INCREASE);
treibe960e282015-09-11 10:38:08538 const base::Version& expected_version = pending_extension_info->version();
539 if (has_permissions_increase ||
540 pending_extension_info->remote_install() ||
541 !expected_version.IsValid()) {
[email protected]21db9ef2014-05-16 02:06:27542 installer->set_grant_permissions(false);
treibe960e282015-09-11 10:38:08543 } else {
544 installer->set_expected_version(expected_version,
545 false /* fail_install_if_unexpected */);
546 }
mamir0128d5a2016-07-15 20:55:48547 creation_flags = pending_extension_info->creation_flags();
[email protected]464213a2013-10-15 01:06:48548 if (pending_extension_info->mark_acknowledged())
[email protected]374ceb6f2014-07-02 19:25:34549 external_install_manager_->AcknowledgeExternalExtension(id);
Minh X. Nguyen30975342017-12-04 22:02:41550 // If the extension was installed from or has migrated to the webstore, or
551 // its auto-update URL is from the webstore, treat it as a webstore install.
552 // Note that we ignore some older extensions with blank auto-update URLs
553 // because we are mostly concerned with restrictions on NaCl extensions,
554 // which are newer.
555 if (!extension && extension_urls::IsWebstoreUpdateUrl(
556 pending_extension_info->update_url()))
557 creation_flags |= Extension::FROM_WEBSTORE;
558 } else {
559 // |extension| must not be null.
[email protected]5eb375e92010-11-26 07:50:41560 installer->set_install_source(extension->location());
[email protected]51a3bf8b2012-06-08 22:53:06561 }
[email protected]a12ce8b22012-01-17 18:40:53562
Minh X. Nguyen30975342017-12-04 22:02:41563 if (extension) {
564 installer->InitializeCreationFlagsForUpdate(extension, creation_flags);
[email protected]c30bda262014-06-19 04:10:13565 installer->set_do_not_sync(extension_prefs_->DoNotSync(id));
Minh X. Nguyen30975342017-12-04 22:02:41566 } else {
567 installer->set_creation_flags(creation_flags);
568 }
[email protected]044e86992014-01-24 22:59:11569 installer->set_delete_source(file_ownership_passed);
[email protected]cb0e50312011-05-09 15:03:07570 installer->set_install_cause(extension_misc::INSTALL_CAUSE_UPDATE);
ginkage553af3202015-02-04 12:39:09571 installer->InstallCrxFile(file);
[email protected]420a0ec2011-06-01 01:07:03572
573 if (out_crx_installer)
[email protected]dc24976f2013-06-02 21:15:09574 *out_crx_installer = installer.get();
[email protected]420a0ec2011-06-01 01:07:03575
576 return true;
[email protected]e957fe52009-06-23 16:51:05577}
578
catmullings98cd1942016-08-30 22:31:59579void ExtensionService::LoadExtensionsFromCommandLineFlag(
580 const char* switch_name) {
581 if (command_line_->HasSwitch(switch_name)) {
582 base::CommandLine::StringType path_list =
583 command_line_->GetSwitchValueNative(switch_name);
584 base::StringTokenizerT<base::CommandLine::StringType,
585 base::CommandLine::StringType::const_iterator>
586 t(path_list, FILE_PATH_LITERAL(","));
587 while (t.GetNext()) {
588 std::string extension_id;
Devlin Cronineea1b7a2018-05-26 02:46:21589 UnpackedInstaller::Create(this)->LoadFromCommandLine(
catmullings98cd1942016-08-30 22:31:59590 base::FilePath(t.token()), &extension_id, false /*only-allow-apps*/);
591 // Extension id is added to whitelist after its extension is loaded
michaelpga8ea0372017-04-06 20:41:35592 // because code is executed asynchronously. TODO(michaelpg): Remove this
593 // assumption so loading extensions does not have to be asynchronous:
594 // crbug.com/708354.
Devlin Cronineea1b7a2018-05-26 02:46:21595 if (switch_name == ::switches::kDisableExtensionsExcept)
catmullings98cd1942016-08-30 22:31:59596 disable_flag_exempted_extensions_.insert(extension_id);
597 }
598 }
599}
600
Michael Giuffrida573992d2018-02-08 00:48:44601// TODO(michaelpg): Group with other ExtensionRegistrar::Delegate overrides
602// according to header file once diffs have settled down.
603void ExtensionService::LoadExtensionForReload(
Devlin Cronineea1b7a2018-05-26 02:46:21604 const ExtensionId& extension_id,
Michael Giuffrida573992d2018-02-08 00:48:44605 const base::FilePath& path,
606 LoadErrorBehavior load_error_behavior) {
Toni Barzic667db0d32018-01-09 18:00:19607 if (delayed_installs_.Contains(extension_id) &&
608 FinishDelayedInstallationIfReady(extension_id,
609 true /*install_immediately*/)) {
[email protected]0db124b02012-11-07 04:55:05610 return;
611 }
612
[email protected]43ceb002012-02-10 23:19:15613 // If we're reloading a component extension, use the component extension
614 // loader's reloader.
615 if (component_loader_->Exists(extension_id)) {
616 component_loader_->Reload(extension_id);
617 return;
618 }
619
[email protected]e6090e42010-03-23 22:44:08620 // Check the installed extensions to see if what we're reloading was already
621 // installed.
dchengc963c7142016-04-08 03:55:22622 std::unique_ptr<ExtensionInfo> installed_extension(
[email protected]e6090e42010-03-23 22:44:08623 extension_prefs_->GetInstalledExtensionInfo(extension_id));
624 if (installed_extension.get() &&
625 installed_extension->extension_manifest.get()) {
Devlin Cronineea1b7a2018-05-26 02:46:21626 InstalledLoader(this).Load(*installed_extension, false);
[email protected]e6090e42010-03-23 22:44:08627 } else {
Michael Giuffrida573992d2018-02-08 00:48:44628 // Otherwise, the extension is unpacked (location LOAD). We must load it
629 // from the path.
630 CHECK(!path.empty()) << "ExtensionRegistrar should never ask to load an "
631 "unknown extension with no path";
Devlin Cronineea1b7a2018-05-26 02:46:21632 scoped_refptr<UnpackedInstaller> unpacked_installer =
633 UnpackedInstaller::Create(this);
Michael Giuffrida573992d2018-02-08 00:48:44634 unpacked_installer->set_be_noisy_on_failure(load_error_behavior ==
635 LoadErrorBehavior::kNoisy);
[email protected]bca4b832014-07-17 20:22:34636 unpacked_installer->Load(path);
[email protected]e6090e42010-03-23 22:44:08637 }
[email protected]9cddd4702009-07-27 22:09:40638}
639
[email protected]bca4b832014-07-17 20:22:34640void ExtensionService::ReloadExtension(const std::string& extension_id) {
Michael Giuffrida573992d2018-02-08 00:48:44641 extension_registrar_.ReloadExtension(extension_id, LoadErrorBehavior::kNoisy);
[email protected]bca4b832014-07-17 20:22:34642}
643
644void ExtensionService::ReloadExtensionWithQuietFailure(
645 const std::string& extension_id) {
Michael Giuffrida573992d2018-02-08 00:48:44646 extension_registrar_.ReloadExtension(extension_id, LoadErrorBehavior::kQuiet);
[email protected]bca4b832014-07-17 20:22:34647}
648
[email protected]757d60a2014-05-23 00:11:44649bool ExtensionService::UninstallExtension(
650 // "transient" because the process of uninstalling may cause the reference
651 // to become invalid. Instead, use |extenson->id()|.
652 const std::string& transient_extension_id,
Devlin Cronineea1b7a2018-05-26 02:46:21653 UninstallReason reason,
[email protected]757d60a2014-05-23 00:11:44654 base::string16* error) {
[email protected]a29a517a2011-01-21 21:11:12655 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]a8af9fdb2010-10-28 21:52:20656
[email protected]757d60a2014-05-23 00:11:44657 scoped_refptr<const Extension> extension =
658 GetInstalledExtension(transient_extension_id);
[email protected]631cf822009-05-15 07:01:25659
[email protected]e7afe2452010-08-22 16:19:13660 // Callers should not send us nonexistent extensions.
[email protected]dc24976f2013-06-02 21:15:09661 CHECK(extension.get());
[email protected]9f1087e2009-06-15 17:29:32662
binjincccacef2014-10-13 19:00:20663 ManagementPolicy* by_policy = system_->management_policy();
[email protected]95da88c42011-03-31 10:07:33664 // Policy change which triggers an uninstall will always set
665 // |external_uninstall| to true so this is the only way to uninstall
666 // managed extensions.
[email protected]90878c52014-04-04 18:21:02667 // Shared modules being uninstalled will also set |external_uninstall| to true
668 // so that we can guarantee users don't uninstall a shared module.
669 // (crbug.com/273300)
670 // TODO(rdevlin.cronin): This is probably not right. We should do something
671 // else, like include an enum IS_INTERNAL_UNINSTALL or IS_USER_UNINSTALL so
672 // we don't do this.
[email protected]cc2f55c2014-07-08 02:19:04673 bool external_uninstall =
Devlin Cronineea1b7a2018-05-26 02:46:21674 (reason == UNINSTALL_REASON_INTERNAL_MANAGEMENT) ||
675 (reason == UNINSTALL_REASON_COMPONENT_REMOVED) ||
676 (reason == UNINSTALL_REASON_REINSTALL) ||
677 (reason == UNINSTALL_REASON_ORPHANED_EXTERNAL_EXTENSION) ||
678 (reason == UNINSTALL_REASON_ORPHANED_SHARED_MODULE) ||
679 (reason == UNINSTALL_REASON_SYNC &&
680 util::WasInstalledByCustodian(extension->id(), profile_));
[email protected]65187152012-06-02 13:14:14681 if (!external_uninstall &&
binjincccacef2014-10-13 19:00:20682 (!by_policy->UserMayModifySettings(extension.get(), error) ||
683 by_policy->MustRemainInstalled(extension.get(), error))) {
[email protected]ad50def52011-10-19 23:17:07684 content::NotificationService::current()->Notify(
Devlin Cronineea1b7a2018-05-26 02:46:21685 NOTIFICATION_EXTENSION_UNINSTALL_NOT_ALLOWED,
[email protected]6c2381d2011-10-19 02:52:53686 content::Source<Profile>(profile_),
[email protected]dc24976f2013-06-02 21:15:09687 content::Details<const Extension>(extension.get()));
[email protected]d6ebc9792011-04-07 18:18:33688 return false;
689 }
[email protected]95da88c42011-03-31 10:07:33690
juncai33e462102015-05-18 20:48:44691 InstallVerifier::Get(GetBrowserContext())->Remove(extension->id());
[email protected]ffd2f79e2013-11-14 00:11:46692
[email protected]9b217652010-10-08 22:04:23693 UMA_HISTOGRAM_ENUMERATION("Extensions.UninstallType",
[email protected]7fa19f82010-12-21 19:40:08694 extension->GetType(), 100);
treib2e0517f92015-05-07 23:15:36695 RecordPermissionMessagesHistogram(extension.get(), "Uninstall");
[email protected]9b217652010-10-08 22:04:23696
[email protected]831aa212010-03-26 13:55:19697 // Unload before doing more cleanup to ensure that nothing is hanging on to
698 // any of these resources.
limasdf0deef2042017-05-03 19:17:17699 UnloadExtension(extension->id(), UnloadedExtensionReason::UNINSTALL);
asargent96c7ec42016-05-27 02:45:47700 if (registry_->blacklisted_extensions().Contains(extension->id()))
701 registry_->RemoveBlacklisted(extension->id());
[email protected]831aa212010-03-26 13:55:19702
[email protected]9f1087e2009-06-15 17:29:32703 // Tell the backend to start deleting installed extensions on the file thread.
[email protected]12075d12013-02-27 05:38:05704 if (!Manifest::IsUnpackedLocation(extension->location())) {
Devlin Cronineea1b7a2018-05-26 02:46:21705 if (!GetExtensionFileTaskRunner()->PostTask(
[email protected]7f8f24f2012-11-15 19:40:14706 FROM_HERE,
tzik8d880ee2017-04-20 19:46:24707 base::BindOnce(&ExtensionService::UninstallExtensionOnFileThread,
708 extension->id(), profile_, install_directory_,
709 extension->path())))
[email protected]14908b72011-04-20 06:54:36710 NOTREACHED();
[email protected]9f1087e2009-06-15 17:29:32711 }
712
Devlin Cronineea1b7a2018-05-26 02:46:21713 DataDeleter::StartDeleting(profile_, extension.get());
[email protected]0d6ec3a72011-09-02 02:09:43714
Michael Giuffridafcb420362017-10-11 21:50:26715 extension_registrar_.UntrackTerminatedExtension(extension->id());
[email protected]211030342010-09-30 18:41:06716
717 // Notify interested parties that we've uninstalled this extension.
[email protected]e43c61f2014-07-20 21:46:34718 ExtensionRegistry::Get(profile_)
719 ->TriggerOnUninstalled(extension.get(), reason);
[email protected]d6ebc9792011-04-07 18:18:33720
[email protected]757d60a2014-05-23 00:11:44721 delayed_installs_.Remove(extension->id());
[email protected]0db124b02012-11-07 04:55:05722
[email protected]757d60a2014-05-23 00:11:44723 extension_prefs_->OnExtensionUninstalled(
724 extension->id(), extension->location(), external_uninstall);
[email protected]d4eda592013-09-18 03:37:57725
[email protected]333b1de2011-09-12 18:28:50726 // Track the uninstallation.
[email protected]49098f702011-10-13 03:47:18727 UMA_HISTOGRAM_ENUMERATION("Extensions.ExtensionUninstalled", 1, 2);
728
[email protected]d6ebc9792011-04-07 18:18:33729 return true;
[email protected]c10da4b02010-03-25 14:38:32730}
731
[email protected]5a145e82014-05-29 22:19:07732// static
733void ExtensionService::UninstallExtensionOnFileThread(
734 const std::string& id,
735 Profile* profile,
736 const base::FilePath& install_dir,
737 const base::FilePath& extension_path) {
Devlin Cronineea1b7a2018-05-26 02:46:21738 ExtensionAssetsManager* assets_manager =
739 ExtensionAssetsManager::GetInstance();
[email protected]5a145e82014-05-29 22:19:07740 assets_manager->UninstallExtension(id, profile, install_dir, extension_path);
741}
742
[email protected]c3cfb012011-04-06 22:07:35743bool ExtensionService::IsExtensionEnabled(
744 const std::string& extension_id) const {
Michael Giuffrida6397c592017-10-09 20:46:53745 return extension_registrar_.IsExtensionEnabled(extension_id);
[email protected]c3cfb012011-04-06 22:07:35746}
747
[email protected]eaa7dd182010-12-14 11:09:00748void ExtensionService::EnableExtension(const std::string& extension_id) {
[email protected]a29a517a2011-01-21 21:11:12749 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
Michael Giuffrida6397c592017-10-09 20:46:53750 extension_registrar_.EnableExtension(extension_id);
[email protected]0c6da502009-08-14 22:32:39751}
752
treibc1192322015-05-20 12:56:07753void ExtensionService::DisableExtension(const std::string& extension_id,
754 int disable_reasons) {
[email protected]a29a517a2011-01-21 21:11:12755 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
Michael Giuffrida6397c592017-10-09 20:46:53756 extension_registrar_.DisableExtension(extension_id, disable_reasons);
[email protected]1784e83a2009-09-08 21:01:52757}
758
Ivan Sandrk4a55dc22018-05-17 18:14:48759void ExtensionService::DisableExtensionWithSource(
760 const Extension* source_extension,
761 const std::string& extension_id,
Devlin Cronineea1b7a2018-05-26 02:46:21762 disable_reason::DisableReason disable_reasons) {
Ivan Sandrk4a55dc22018-05-17 18:14:48763 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
764
Devlin Cronineea1b7a2018-05-26 02:46:21765 DCHECK(disable_reasons == disable_reason::DISABLE_USER_ACTION ||
766 disable_reasons == disable_reason::DISABLE_BLOCKED_BY_POLICY);
767 if (disable_reasons == disable_reason::DISABLE_BLOCKED_BY_POLICY) {
Ivan Sandrk4a55dc22018-05-17 18:14:48768 DCHECK(Manifest::IsPolicyLocation(source_extension->location()) ||
769 Manifest::IsComponentLocation(source_extension->location()));
770 }
771
772 const Extension* extension = GetExtensionById(extension_id, true);
773 CHECK(system_->management_policy()->ExtensionMayModifySettings(
774 source_extension, extension, nullptr));
775 extension_registrar_.DisableExtension(extension_id, disable_reasons);
776}
777
mtomasz294bb3e2017-01-24 02:17:52778void ExtensionService::DisableUserExtensionsExcept(
[email protected]1abf05e2013-07-09 17:04:36779 const std::vector<std::string>& except_ids) {
Devlin Cronineea1b7a2018-05-26 02:46:21780 ManagementPolicy* management_policy = system_->management_policy();
781 ExtensionList to_disable;
[email protected]e516e4c2013-06-12 17:41:14782
achuith2f5578b2016-02-26 21:57:13783 for (const auto& extension : registry_->enabled_extensions()) {
784 if (management_policy->UserMayModifySettings(extension.get(), nullptr))
785 to_disable.push_back(extension);
[email protected]e516e4c2013-06-12 17:41:14786 }
787
achuith2f5578b2016-02-26 21:57:13788 for (const auto& extension : registry_->terminated_extensions()) {
789 if (management_policy->UserMayModifySettings(extension.get(), nullptr))
790 to_disable.push_back(extension);
791 }
792
793 for (const auto& extension : to_disable) {
794 if (extension->was_installed_by_default() &&
[email protected]3082fe32013-08-06 11:12:38795 extension_urls::IsWebstoreUpdateUrl(
Devlin Cronineea1b7a2018-05-26 02:46:21796 ManifestURL::GetUpdateURL(extension.get())))
[email protected]3082fe32013-08-06 11:12:38797 continue;
achuith2f5578b2016-02-26 21:57:13798 const std::string& id = extension->id();
Jan Wilken Dörrieade79222019-06-06 19:01:12799 if (!base::Contains(except_ids, id))
Devlin Cronineea1b7a2018-05-26 02:46:21800 DisableExtension(id, disable_reason::DISABLE_USER_ACTION);
[email protected]e516e4c2013-06-12 17:41:14801 }
802}
803
mlerman6a37b6a42014-11-26 22:10:53804// Extensions that are not locked, components or forced by policy should be
805// locked. Extensions are no longer considered enabled or disabled. Blacklisted
806// extensions are now considered both blacklisted and locked.
807void ExtensionService::BlockAllExtensions() {
808 if (block_extensions_)
809 return;
810 block_extensions_ = true;
811
812 // Blacklisted extensions are already unloaded, need not be blocked.
dchengc963c7142016-04-08 03:55:22813 std::unique_ptr<ExtensionSet> extensions =
mlerman6a37b6a42014-11-26 22:10:53814 registry_->GenerateInstalledExtensionsSet(ExtensionRegistry::ENABLED |
815 ExtensionRegistry::DISABLED |
816 ExtensionRegistry::TERMINATED);
817
achuith2f5578b2016-02-26 21:57:13818 for (const auto& extension : *extensions) {
mlerman6a37b6a42014-11-26 22:10:53819 const std::string& id = extension->id();
820
821 if (!CanBlockExtension(extension.get()))
822 continue;
823
824 registry_->RemoveEnabled(id);
825 registry_->RemoveDisabled(id);
826 registry_->RemoveTerminated(id);
827
828 registry_->AddBlocked(extension.get());
Devlin Cronineea1b7a2018-05-26 02:46:21829 UnloadExtension(id, UnloadedExtensionReason::LOCK_ALL);
mlerman6a37b6a42014-11-26 22:10:53830 }
831}
832
833// All locked extensions should revert to being either enabled or disabled
834// as appropriate.
835void ExtensionService::UnblockAllExtensions() {
836 block_extensions_ = false;
dchengc963c7142016-04-08 03:55:22837 std::unique_ptr<ExtensionSet> to_unblock =
mlerman6a37b6a42014-11-26 22:10:53838 registry_->GenerateInstalledExtensionsSet(ExtensionRegistry::BLOCKED);
839
achuith2f5578b2016-02-26 21:57:13840 for (const auto& extension : *to_unblock) {
mlerman6a37b6a42014-11-26 22:10:53841 registry_->RemoveBlocked(extension->id());
842 AddExtension(extension.get());
843 }
Owen Minb71016d2018-01-11 01:51:49844 // While extensions are blocked, we won't display any external install
845 // warnings. Now that they are unblocked, we should update the error.
846 external_install_manager_->UpdateExternalExtensionAlert();
mlerman6a37b6a42014-11-26 22:10:53847}
848
[email protected]eaa7dd182010-12-14 11:09:00849void ExtensionService::GrantPermissionsAndEnableExtension(
[email protected]009633c2013-03-07 22:08:28850 const Extension* extension) {
851 GrantPermissions(extension);
treib2e0517f92015-05-07 23:15:36852 RecordPermissionMessagesHistogram(extension, "ReEnable");
[email protected]8d888c12010-11-30 00:00:25853 EnableExtension(extension->id());
854}
855
[email protected]009633c2013-03-07 22:08:28856void ExtensionService::GrantPermissions(const Extension* extension) {
[email protected]be083862012-09-01 03:53:45857 CHECK(extension);
Devlin Cronineea1b7a2018-05-26 02:46:21858 PermissionsUpdater(profile()).GrantActivePermissions(extension);
[email protected]be083862012-09-01 03:53:45859}
860
[email protected]fe2dd7742011-04-19 22:52:49861// static
862void ExtensionService::RecordPermissionMessagesHistogram(
[email protected]13c68b62013-05-17 11:29:05863 const Extension* extension, const char* histogram) {
[email protected]de415552013-01-23 04:12:17864 // Since this is called from multiple sources, and since the histogram macros
865 // use statics, we need to manually lookup the histogram ourselves.
treib2e0517f92015-05-07 23:15:36866 base::HistogramBase* counter = base::LinearHistogram::FactoryGet(
867 base::StringPrintf("Extensions.Permissions_%s3", histogram),
868 1,
869 APIPermission::kEnumBoundary,
870 APIPermission::kEnumBoundary + 1,
871 base::HistogramBase::kUmaTargetedHistogramFlag);
872
873 base::HistogramBase* counter_has_any = base::BooleanHistogram::FactoryGet(
874 base::StringPrintf("Extensions.HasPermissions_%s3", histogram),
875 base::HistogramBase::kUmaTargetedHistogramFlag);
876
877 PermissionIDSet permissions =
Devlin Cronineea1b7a2018-05-26 02:46:21878 PermissionMessageProvider::Get()->GetAllPermissionIDs(
rdevlin.cronine2d0fd02015-09-24 22:35:49879 extension->permissions_data()->active_permissions(),
treib2e0517f92015-05-07 23:15:36880 extension->GetType());
881 counter_has_any->AddBoolean(!permissions.empty());
882 for (const PermissionID& id : permissions)
883 counter->Add(id.id());
[email protected]fe2dd7742011-04-19 22:52:49884}
885
Michael Giuffrida6397c592017-10-09 20:46:53886// TODO(michaelpg): Group with other ExtensionRegistrar::Delegate overrides
887// according to header file once diffs have settled down.
888void ExtensionService::PostActivateExtension(
Michael Giuffrida19a55982018-02-10 03:03:26889 scoped_refptr<const Extension> extension) {
[email protected]dcc47642014-03-26 22:03:49890 // TODO(kalman): Convert ExtensionSpecialStoragePolicy to a
891 // BrowserContextKeyedService and use ExtensionRegistryObserver.
Michael Giuffrida6397c592017-10-09 20:46:53892 profile_->GetExtensionSpecialStoragePolicy()->GrantRightsForExtension(
Devlin Croninb2be9a6a2019-06-14 20:08:19893 extension.get());
[email protected]c8d407e2011-04-28 21:27:17894
[email protected]dcc47642014-03-26 22:03:49895 // TODO(kalman): This is broken. The crash reporter is process-wide so doesn't
896 // work properly multi-profile. Besides which, it should be using
897 // ExtensionRegistryObserver. See http://crbug.com/355029.
[email protected]c8d407e2011-04-28 21:27:17898 UpdateActiveExtensionsInCrashReporter();
899
Devlin Cronineea1b7a2018-05-26 02:46:21900 const PermissionsData* permissions_data = extension->permissions_data();
[email protected]d695bb12014-06-05 16:16:30901
[email protected]c8d407e2011-04-28 21:27:17902 // If the extension has permission to load chrome://favicon/ resources we need
903 // to make sure that the FaviconSource is registered with the
904 // ChromeURLDataManager.
[email protected]d695bb12014-06-05 16:16:30905 if (permissions_data->HasHostPermission(GURL(chrome::kChromeUIFaviconURL))) {
Victor Hugo Vianna Silvaed441482019-06-27 12:40:40906 content::URLDataSource::Add(
907 profile_, std::make_unique<FaviconSource>(
908 profile_, chrome::FaviconUrlFormat::kFaviconLegacy));
[email protected]c8d407e2011-04-28 21:27:17909 }
[email protected]b07e606e2012-09-15 20:16:15910
[email protected]b07e606e2012-09-15 20:16:15911 // Same for chrome://theme/ resources.
[email protected]d695bb12014-06-05 16:16:30912 if (permissions_data->HasHostPermission(GURL(chrome::kChromeUIThemeURL))) {
Lei Zhangc77274da2018-08-28 23:14:00913 content::URLDataSource::Add(profile_,
914 std::make_unique<ThemeSource>(profile_));
[email protected]b07e606e2012-09-15 20:16:15915 }
[email protected]62d30f42009-10-01 22:36:06916}
917
Michael Giuffrida6397c592017-10-09 20:46:53918// TODO(michaelpg): Group with other ExtensionRegistrar::Delegate overrides
919// according to header file once diffs have settled down.
Michael Giuffrida023e3532017-09-28 23:21:21920void ExtensionService::PostDeactivateExtension(
921 scoped_refptr<const Extension> extension) {
[email protected]dcc47642014-03-26 22:03:49922 // TODO(kalman): Convert ExtensionSpecialStoragePolicy to a
923 // BrowserContextKeyedService and use ExtensionRegistryObserver.
Michael Giuffrida023e3532017-09-28 23:21:21924 profile_->GetExtensionSpecialStoragePolicy()->RevokeRightsForExtension(
925 extension.get());
[email protected]c8d407e2011-04-28 21:27:17926
[email protected]b777b332011-04-16 04:01:08927#if defined(OS_CHROMEOS)
[email protected]ac66e452013-01-11 09:21:23928 // Revoke external file access for the extension from its file system context.
929 // It is safe to access the extension's storage partition at this point. The
930 // storage partition may get destroyed only after the extension gets unloaded.
Devlin Cronineea1b7a2018-05-26 02:46:21931 GURL site = util::GetSiteForExtensionId(extension->id(), profile_);
[email protected]cd501a72014-08-22 19:58:31932 storage::FileSystemContext* filesystem_context =
933 BrowserContext::GetStoragePartitionForSite(profile_, site)
934 ->GetFileSystemContext();
[email protected]f19bbf62013-07-09 01:22:32935 if (filesystem_context && filesystem_context->external_backend()) {
Michael Giuffrida6397c592017-10-09 20:46:53936 filesystem_context->external_backend()->RevokeAccessForExtension(
937 extension->id());
[email protected]62d30f42009-10-01 22:36:06938 }
[email protected]c8d407e2011-04-28 21:27:17939#endif
940
[email protected]dcc47642014-03-26 22:03:49941 // TODO(kalman): This is broken. The crash reporter is process-wide so doesn't
942 // work properly multi-profile. Besides which, it should be using
943 // ExtensionRegistryObserver::OnExtensionLoaded. See http://crbug.com/355029.
[email protected]c8d407e2011-04-28 21:27:17944 UpdateActiveExtensionsInCrashReporter();
[email protected]62d30f42009-10-01 22:36:06945}
946
[email protected]599539802014-01-07 23:06:00947content::BrowserContext* ExtensionService::GetBrowserContext() const {
948 // Implemented in the .cc file to avoid adding a profile.h dependency to
949 // extension_service.h.
950 return profile_;
951}
952
[email protected]25ae0152011-11-18 14:40:02953bool ExtensionService::is_ready() {
[email protected]4a10006a2013-05-17 23:18:35954 return ready_->is_signaled();
[email protected]25ae0152011-11-18 14:40:02955}
956
[email protected]4ee07c62012-08-21 12:40:42957void ExtensionService::CheckManagementPolicy() {
Devlin Cronineea1b7a2018-05-26 02:46:21958 std::map<std::string, disable_reason::DisableReason> to_disable;
binjin8e3d0182014-12-04 16:44:28959 std::vector<std::string> to_enable;
[email protected]695b5712012-12-06 23:55:28960
Karan Bhatia2a117232017-08-23 00:24:56961 // Loop through the extensions list, finding extensions we need to disable.
achuith2f5578b2016-02-26 21:57:13962 for (const auto& extension : registry_->enabled_extensions()) {
Devlin Cronineea1b7a2018-05-26 02:46:21963 disable_reason::DisableReason disable_reason = disable_reason::DISABLE_NONE;
[email protected]0d54b682013-11-05 14:15:36964 if (system_->management_policy()->MustRemainDisabled(
binjin8e3d0182014-12-04 16:44:28965 extension.get(), &disable_reason, nullptr))
[email protected]0d54b682013-11-05 14:15:36966 to_disable[extension->id()] = disable_reason;
[email protected]aa96d3a2010-08-21 08:45:25967 }
968
Devlin Cronineea1b7a2018-05-26 02:46:21969 ExtensionManagement* management =
970 ExtensionManagementFactory::GetForBrowserContext(profile());
971 PermissionsUpdater(profile()).SetDefaultPolicyHostRestrictions(
Devlin Cronin7e0f41ff2018-05-16 17:19:36972 management->GetDefaultPolicyBlockedHosts(),
973 management->GetDefaultPolicyAllowedHosts());
nrpetere33d2a5b2017-04-25 00:12:31974 for (const auto& extension : registry_->enabled_extensions()) {
975 bool uses_default =
Devlin Cronin7e0f41ff2018-05-16 17:19:36976 management->UsesDefaultPolicyHostRestrictions(extension.get());
nrpetere33d2a5b2017-04-25 00:12:31977 if (uses_default) {
Devlin Cronineea1b7a2018-05-26 02:46:21978 PermissionsUpdater(profile()).SetUsesDefaultHostRestrictions(
nrpetere33d2a5b2017-04-25 00:12:31979 extension.get());
980 } else {
Devlin Cronineea1b7a2018-05-26 02:46:21981 PermissionsUpdater(profile()).SetPolicyHostRestrictions(
Devlin Cronin7e0f41ff2018-05-16 17:19:36982 extension.get(), management->GetPolicyBlockedHosts(extension.get()),
983 management->GetPolicyAllowedHosts(extension.get()));
nrpetere33d2a5b2017-04-25 00:12:31984 }
985 }
binjin8e3d0182014-12-04 16:44:28986
987 // Loop through the disabled extension list, find extensions to re-enable
Karan Bhatia2a117232017-08-23 00:24:56988 // automatically. These extensions are exclusive from the |to_disable| list
989 // constructed above, since disabled_extensions() and enabled_extensions() are
990 // supposed to be mutually exclusive.
achuith2f5578b2016-02-26 21:57:13991 for (const auto& extension : registry_->disabled_extensions()) {
Karan Bhatia2a117232017-08-23 00:24:56992 int disable_reasons = extension_prefs_->GetDisableReasons(extension->id());
binjin8e3d0182014-12-04 16:44:28993
Karan Bhatia2a117232017-08-23 00:24:56994 // Find all extensions disabled due to minimum version requirement and
995 // management policy but now satisfying it.
996 if (management->CheckMinimumVersion(extension.get(), nullptr)) {
Devlin Cronineea1b7a2018-05-26 02:46:21997 disable_reasons &= (~disable_reason::DISABLE_UPDATE_REQUIRED_BY_POLICY);
Karan Bhatia2a117232017-08-23 00:24:56998 }
999
1000 if (!system_->management_policy()->MustRemainDisabled(extension.get(),
1001 nullptr, nullptr)) {
Devlin Cronineea1b7a2018-05-26 02:46:211002 disable_reasons &= (~disable_reason::DISABLE_BLOCKED_BY_POLICY);
Karan Bhatia2a117232017-08-23 00:24:561003 }
1004
1005 extension_prefs_->ReplaceDisableReasons(extension->id(), disable_reasons);
Devlin Cronineea1b7a2018-05-26 02:46:211006 if (disable_reasons == disable_reason::DISABLE_NONE)
Karan Bhatia2a117232017-08-23 00:24:561007 to_enable.push_back(extension->id());
1008 }
[email protected]0d54b682013-11-05 14:15:361009
achuith2f5578b2016-02-26 21:57:131010 for (const auto& i : to_disable)
1011 DisableExtension(i.first, i.second);
binjin8e3d0182014-12-04 16:44:281012
Karan Bhatia2a117232017-08-23 00:24:561013 // No extension is getting re-enabled here after disabling because |to_enable|
1014 // is mutually exclusive to |to_disable|.
binjin8e3d0182014-12-04 16:44:281015 for (const std::string& id : to_enable)
1016 EnableExtension(id);
1017
1018 if (updater_.get()) {
1019 // Find all extensions disabled due to minimum version requirement from
1020 // policy (including the ones that got disabled just now), and check
1021 // for update.
Devlin Cronineea1b7a2018-05-26 02:46:211022 ExtensionUpdater::CheckParams to_recheck;
achuith2f5578b2016-02-26 21:57:131023 for (const auto& extension : registry_->disabled_extensions()) {
binjin8e3d0182014-12-04 16:44:281024 if (extension_prefs_->GetDisableReasons(extension->id()) ==
Devlin Cronineea1b7a2018-05-26 02:46:211025 disable_reason::DISABLE_UPDATE_REQUIRED_BY_POLICY) {
binjin8e3d0182014-12-04 16:44:281026 // The minimum version check is the only thing holding this extension
1027 // back, so check if it can be updated to fix that.
1028 to_recheck.ids.push_back(extension->id());
1029 }
1030 }
1031 if (!to_recheck.ids.empty())
Minh X. Nguyen722b9682018-04-25 21:46:481032 updater_->CheckNow(std::move(to_recheck));
binjin8e3d0182014-12-04 16:44:281033 }
Alexander Nohe2c5402882019-04-11 21:56:331034
1035 // Check the disabled extensions to see if any should be force uninstalled.
1036 std::vector<ExtensionId> remove_list;
1037 for (const auto& extension : registry_->disabled_extensions()) {
1038 if (system_->management_policy()->ShouldForceUninstall(extension.get(),
1039 nullptr /*error*/)) {
1040 remove_list.push_back(extension->id());
1041 }
1042 }
1043 for (auto extension_id : remove_list) {
1044 base::string16 error;
1045 if (!UninstallExtension(extension_id, UNINSTALL_REASON_INTERNAL_MANAGEMENT,
1046 &error)) {
1047 SYSLOG(WARNING) << "Extension with id " << extension_id
1048 << " failed to be uninstalled via policy: " << error;
1049 }
1050 }
[email protected]aa96d3a2010-08-21 08:45:251051}
1052
[email protected]31206602011-04-13 23:07:321053void ExtensionService::CheckForUpdatesSoon() {
[email protected]90878c52014-04-04 18:21:021054 // This can legitimately happen in unit tests.
1055 if (!updater_.get())
1056 return;
1057
raphael.kubo.da.costa8527f942016-11-15 17:03:511058 updater_->CheckSoon();
[email protected]c3cfb012011-04-06 22:07:351059}
1060
[email protected]8e4560b62011-01-14 10:09:141061// Some extensions will autoupdate themselves externally from Chrome. These
rkaplowa8fd8d32015-02-25 21:27:561062// are typically part of some larger client application package. To support
1063// these, the extension will register its location in the preferences file
[email protected]8e4560b62011-01-14 10:09:141064// (and also, on Windows, in the registry) and this code will periodically
1065// check that location for a .crx file, which it will then install locally if
1066// a new version is available.
Devlin Cronin9722a722017-12-16 03:35:101067// Errors are reported through LoadErrorReporter. Success is not reported.
[email protected]eaa7dd182010-12-14 11:09:001068void ExtensionService::CheckForExternalUpdates() {
lazyboy77214d3c2017-04-04 16:46:121069 if (external_updates_disabled_for_test_)
1070 return;
1071
[email protected]a29a517a2011-01-21 21:11:121072 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
rkaplowa8fd8d32015-02-25 21:27:561073 TRACE_EVENT0("browser,startup", "ExtensionService::CheckForExternalUpdates");
1074 SCOPED_UMA_HISTOGRAM_TIMER("Extensions.CheckForExternalUpdatesTime");
[email protected]8e4560b62011-01-14 10:09:141075
1076 // Note that this installation is intentionally silent (since it didn't
1077 // go through the front-end). Extensions that are registered in this
1078 // way are effectively considered 'pre-bundled', and so implicitly
1079 // trusted. In general, if something has HKLM or filesystem access,
1080 // they could install an extension manually themselves anyway.
[email protected]a29a517a2011-01-21 21:11:121081
[email protected]8e4560b62011-01-14 10:09:141082 // Ask each external extension provider to give us a call back for each
1083 // extension they know about. See OnExternalExtension(File|UpdateUrl)Found.
achuith2f5578b2016-02-26 21:57:131084 for (const auto& provider : external_extension_providers_)
[email protected]8e4560b62011-01-14 10:09:141085 provider->VisitRegisteredExtension();
[email protected]8e4560b62011-01-14 10:09:141086
[email protected]50067e52011-10-20 23:17:071087 // Do any required work that we would have done after completion of all
1088 // providers.
[email protected]373daf972014-04-10 01:50:441089 if (external_extension_providers_.empty())
[email protected]50067e52011-10-20 23:17:071090 OnAllExternalProvidersReady();
[email protected]9f1087e2009-06-15 17:29:321091}
1092
[email protected]50067e52011-10-20 23:17:071093void ExtensionService::OnExternalProviderReady(
lazyboye8634172016-01-28 00:10:481094 const ExternalProviderInterface* provider) {
Istiaque Ahmedf6e72622017-09-08 23:14:171095 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]50067e52011-10-20 23:17:071096 CHECK(provider->IsReady());
[email protected]a29a517a2011-01-21 21:11:121097
1098 // An external provider has finished loading. We only take action
[email protected]8e4560b62011-01-14 10:09:141099 // if all of them are finished. So we check them first.
[email protected]94fde232012-04-27 10:22:301100 if (AreAllExternalProvidersReady())
1101 OnAllExternalProvidersReady();
1102}
1103
1104bool ExtensionService::AreAllExternalProvidersReady() const {
achuith2f5578b2016-02-26 21:57:131105 for (const auto& provider : external_extension_providers_) {
1106 if (!provider->IsReady())
[email protected]94fde232012-04-27 10:22:301107 return false;
[email protected]8e4560b62011-01-14 10:09:141108 }
[email protected]94fde232012-04-27 10:22:301109 return true;
[email protected]50067e52011-10-20 23:17:071110}
1111
1112void ExtensionService::OnAllExternalProvidersReady() {
Istiaque Ahmedf6e72622017-09-08 23:14:171113 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]50067e52011-10-20 23:17:071114 // Install any pending extensions.
[email protected]94fde232012-04-27 10:22:301115 if (update_once_all_providers_are_ready_ && updater()) {
1116 update_once_all_providers_are_ready_ = false;
Devlin Cronineea1b7a2018-05-26 02:46:211117 ExtensionUpdater::CheckParams params;
Minh X. Nguyen722b9682018-04-25 21:46:481118 params.callback =
1119 external_updates_finished_callback_.is_null()
1120 ? base::OnceClosure()
1121 : base::BindOnce(
1122 [](base::RepeatingClosure callback) { callback.Run(); },
1123 external_updates_finished_callback_);
Devlin Cronin2b3acda2019-05-30 19:11:371124 // We have to mark high-priority extensions (such as policy-forced
1125 // extensions or external component extensions) with foreground fetch
1126 // priority; otherwise their installation may be throttled by bandwidth
1127 // limits.
1128 // See https://crbug.com/904600 and https://crbug.com/965686.
1129 if (pending_extension_manager_.HasHighPriorityPendingExtension()) {
Oleg Davydov6541a64f2019-04-17 13:17:331130 params.fetch_priority = ManifestFetchData::FOREGROUND;
1131 }
Minh X. Nguyen722b9682018-04-25 21:46:481132 updater()->CheckNow(std::move(params));
[email protected]8e4560b62011-01-14 10:09:141133 }
1134
1135 // Uninstall all the unclaimed extensions.
Devlin Cronineea1b7a2018-05-26 02:46:211136 std::unique_ptr<ExtensionPrefs::ExtensionsInfo> extensions_info(
[email protected]8e4560b62011-01-14 10:09:141137 extension_prefs_->GetInstalledExtensionsInfo());
1138 for (size_t i = 0; i < extensions_info->size(); ++i) {
1139 ExtensionInfo* info = extensions_info->at(i).get();
[email protected]1d5e58b2013-01-31 08:41:401140 if (Manifest::IsExternalLocation(info->extension_location))
[email protected]8e4560b62011-01-14 10:09:141141 CheckExternalUninstall(info->extension_id);
1142 }
[email protected]e5af875f2011-10-10 21:09:141143
[email protected]373daf972014-04-10 01:50:441144 error_controller_->ShowErrorIfNeeded();
[email protected]a9aa5932012-01-25 08:27:401145
[email protected]374ceb6f2014-07-02 19:25:341146 external_install_manager_->UpdateExternalExtensionAlert();
[email protected]e5af875f2011-10-10 21:09:141147}
1148
limasdf0deef2042017-05-03 19:17:171149void ExtensionService::UnloadExtension(const std::string& extension_id,
1150 UnloadedExtensionReason reason) {
Devlin Cronin5b35a082017-10-05 20:44:361151 extension_registrar_.RemoveExtension(extension_id, reason);
[email protected]631cf822009-05-15 07:01:251152}
1153
[email protected]8b1ec202013-09-05 02:09:501154void ExtensionService::RemoveComponentExtension(
1155 const std::string& extension_id) {
1156 scoped_refptr<const Extension> extension(
1157 GetExtensionById(extension_id, false));
limasdf0deef2042017-05-03 19:17:171158 UnloadExtension(extension_id, UnloadedExtensionReason::UNINSTALL);
[email protected]ebe07772014-05-22 04:16:061159 if (extension.get()) {
[email protected]e43c61f2014-07-20 21:46:341160 ExtensionRegistry::Get(profile_)->TriggerOnUninstalled(
Devlin Cronineea1b7a2018-05-26 02:46:211161 extension.get(), UNINSTALL_REASON_COMPONENT_REMOVED);
[email protected]ebe07772014-05-22 04:16:061162 }
[email protected]8b1ec202013-09-05 02:09:501163}
1164
[email protected]bb1bc9b32013-12-21 03:09:141165void ExtensionService::UnloadAllExtensionsForTest() {
1166 UnloadAllExtensionsInternal();
[email protected]9f1087e2009-06-15 17:29:321167}
1168
[email protected]bb1bc9b32013-12-21 03:09:141169void ExtensionService::ReloadExtensionsForTest() {
1170 // Calling UnloadAllExtensionsForTest here triggers a false-positive presubmit
1171 // warning about calling test code in production.
1172 UnloadAllExtensionsInternal();
[email protected]eac88332012-12-26 17:57:451173 component_loader_->LoadAll();
Devlin Cronineea1b7a2018-05-26 02:46:211174 InstalledLoader(this).LoadAllExtensions();
rdevlin.croninf2e1cb012017-05-27 01:27:591175 OnInstalledExtensionsLoaded();
[email protected]4a10006a2013-05-17 23:18:351176 // Don't call SetReadyAndNotifyListeners() since tests call this multiple
1177 // times.
[email protected]9f1087e2009-06-15 17:29:321178}
1179
[email protected]820d9bd2013-04-03 03:46:031180void ExtensionService::SetReadyAndNotifyListeners() {
rkaplowa8fd8d32015-02-25 21:27:561181 TRACE_EVENT0("browser,startup",
1182 "ExtensionService::SetReadyAndNotifyListeners");
1183 SCOPED_UMA_HISTOGRAM_TIMER(
1184 "Extensions.ExtensionServiceNotifyReadyListenersTime");
1185
[email protected]4a10006a2013-05-17 23:18:351186 ready_->Signal();
[email protected]820d9bd2013-04-03 03:46:031187 content::NotificationService::current()->Notify(
Devlin Cronineea1b7a2018-05-26 02:46:211188 NOTIFICATION_EXTENSIONS_READY_DEPRECATED,
[email protected]820d9bd2013-04-03 03:46:031189 content::Source<Profile>(profile_),
1190 content::NotificationService::NoDetails());
1191}
1192
[email protected]fcb58a862012-05-01 01:03:151193void ExtensionService::AddExtension(const Extension* extension) {
rdevlin.cronin08ada0f2017-03-09 23:29:521194 if (!Manifest::IsValidLocation(extension->location())) {
1195 // TODO(devlin): We should *never* add an extension with an invalid
1196 // location, but some bugs (e.g. crbug.com/692069) seem to indicate we do.
1197 // Track down the cases when this can happen, and remove this
1198 // DumpWithoutCrashing() (possibly replacing it with a CHECK).
1199 NOTREACHED();
Lukasz Anforowicz68c21772018-01-13 03:42:441200 DEBUG_ALIAS_FOR_CSTR(extension_id_copy, extension->id().c_str(), 33);
rdevlin.cronin08ada0f2017-03-09 23:29:521201 Manifest::Location location = extension->location();
1202 int creation_flags = extension->creation_flags();
1203 Manifest::Type type = extension->manifest()->type();
rdevlin.cronin08ada0f2017-03-09 23:29:521204 base::debug::Alias(&location);
1205 base::debug::Alias(&creation_flags);
1206 base::debug::Alias(&type);
1207 base::debug::DumpWithoutCrashing();
1208 return;
1209 }
1210
[email protected]c8d407e2011-04-28 21:27:171211 // TODO(jstritar): We may be able to get rid of this branch by overriding the
1212 // default extension state to DISABLED when the --disable-extensions flag
1213 // is set (http://crbug.com/29067).
Devlin Croninefe0c882018-04-20 00:06:481214 if (!extensions_enabled_ &&
1215 !Manifest::ShouldAlwaysLoadExtension(extension->location(),
Devlin Cronin8c23eec2018-05-01 18:42:281216 extension->is_theme()) &&
catmullings98cd1942016-08-30 22:31:591217 disable_flag_exempted_extensions_.count(extension->id()) == 0) {
[email protected]fcb58a862012-05-01 01:03:151218 return;
[email protected]330840c2012-08-29 22:21:011219 }
[email protected]c8d407e2011-04-28 21:27:171220
Michael Giuffrida573992d2018-02-08 00:48:441221 extension_registrar_.AddExtension(extension);
Michael Giuffrida023e3532017-09-28 23:21:211222
Michael Giuffrida573992d2018-02-08 00:48:441223 if (registry_->disabled_extensions().Contains(extension->id())) {
1224 // Show the extension disabled error if a permissions increase or a remote
1225 // installation is the reason it was disabled, and no other reasons exist.
1226 int reasons = extension_prefs_->GetDisableReasons(extension->id());
Devlin Cronineea1b7a2018-05-26 02:46:211227 const int kReasonMask = disable_reason::DISABLE_PERMISSIONS_INCREASE |
1228 disable_reason::DISABLE_REMOTE_INSTALL;
Michael Giuffrida573992d2018-02-08 00:48:441229 if (reasons & kReasonMask && !(reasons & ~kReasonMask)) {
1230 AddExtensionDisabledError(
1231 this, extension,
1232 extension_prefs_->HasDisableReason(
Devlin Cronineea1b7a2018-05-26 02:46:211233 extension->id(), disable_reason::DISABLE_REMOTE_INSTALL));
Michael Giuffrida6397c592017-10-09 20:46:531234 }
[email protected]f574c402012-12-04 23:20:311235 }
[email protected]aab98a52009-12-02 03:22:351236}
1237
[email protected]8c484b742012-11-29 06:05:361238void ExtensionService::AddComponentExtension(const Extension* extension) {
Samuel Huang7987ebd2019-04-08 13:01:371239 extension_prefs_->ClearInapplicableDisableReasonsForComponentExtension(
1240 extension->id());
[email protected]8c484b742012-11-29 06:05:361241 const std::string old_version_string(
1242 extension_prefs_->GetVersionString(extension->id()));
pwnallcbd73192016-08-22 18:59:171243 const base::Version old_version(old_version_string);
[email protected]8c484b742012-11-29 06:05:361244
[email protected]0181a7d2013-11-12 01:08:421245 VLOG(1) << "AddComponentExtension " << extension->name();
Devlin Cronin03bf2d22017-12-20 08:21:051246 if (!old_version.IsValid() || old_version != extension->version()) {
[email protected]8c484b742012-11-29 06:05:361247 VLOG(1) << "Component extension " << extension->name() << " ("
Devlin Cronin03bf2d22017-12-20 08:21:051248 << extension->id() << ") installing/upgrading from '"
1249 << old_version_string << "' to "
1250 << extension->version().GetString();
[email protected]8c484b742012-11-29 06:05:361251
Karandeep Bhatiaa8930652017-10-11 17:41:121252 // TODO(crbug.com/696822): If needed, add support for Declarative Net
1253 // Request to component extensions and pass the ruleset checksum here.
Devlin Cronineea1b7a2018-05-26 02:46:211254 AddNewOrUpdatedExtension(extension, Extension::ENABLED, kInstallFlagNone,
1255 syncer::StringOrdinal(), std::string(),
1256 base::nullopt);
[email protected]8c484b742012-11-29 06:05:361257 return;
1258 }
1259
1260 AddExtension(extension);
1261}
1262
[email protected]b914e2952013-04-26 07:10:031263void ExtensionService::CheckPermissionsIncrease(const Extension* extension,
treib6e51bca2016-06-15 10:26:031264 bool is_extension_loaded) {
Devlin Cronineea1b7a2018-05-26 02:46:211265 PermissionsUpdater(profile_).InitializePermissions(extension);
[email protected]902fd7b2011-07-27 18:42:311266
[email protected]8d888c12010-11-30 00:00:251267 // We keep track of all permissions the user has granted each extension.
1268 // This allows extensions to gracefully support backwards compatibility
1269 // by including unknown permissions in their manifests. When the user
1270 // installs the extension, only the recognized permissions are recorded.
1271 // When the unknown permissions become recognized (e.g., through browser
1272 // upgrade), we can prompt the user to accept these new permissions.
1273 // Extensions can also silently upgrade to less permissions, and then
1274 // silently upgrade to a version that adds these permissions back.
1275 //
1276 // For example, pretend that Chrome 10 includes a permission "omnibox"
1277 // for an API that adds suggestions to the omnibox. An extension can
1278 // maintain backwards compatibility while still having "omnibox" in the
1279 // manifest. If a user installs the extension on Chrome 9, the browser
1280 // will record the permissions it recognized, not including "omnibox."
1281 // When upgrading to Chrome 10, "omnibox" will be recognized and Chrome
1282 // will disable the extension and prompt the user to approve the increase
1283 // in privileges. The extension could then release a new version that
1284 // removes the "omnibox" permission. When the user upgrades, Chrome will
1285 // still remember that "omnibox" had been granted, so that if the
1286 // extension once again includes "omnibox" in an upgrade, the extension
1287 // can upgrade without requiring this user's approval.
[email protected]eb5e4f92012-08-15 23:33:281288 int disable_reasons = extension_prefs_->GetDisableReasons(extension->id());
[email protected]8d888c12010-11-30 00:00:251289
rockot1d4a06262015-02-17 19:39:281290 // Silently grant all active permissions to default apps and apps installed
1291 // in kiosk mode.
[email protected]211a3f32013-05-28 21:48:181292 bool auto_grant_permission =
rockot1d4a06262015-02-17 19:39:281293 extension->was_installed_by_default() ||
Devlin Cronineea1b7a2018-05-26 02:46:211294 ExtensionsBrowserClient::Get()->IsRunningInForcedAppMode();
[email protected]211a3f32013-05-28 21:48:181295 if (auto_grant_permission)
[email protected]b914e2952013-04-26 07:10:031296 GrantPermissions(extension);
1297
1298 bool is_privilege_increase = false;
1299 // We only need to compare the granted permissions to the current permissions
rockot1d4a06262015-02-17 19:39:281300 // if the extension has not been auto-granted its permissions above and is
1301 // installed internally.
1302 if (extension->location() == Manifest::INTERNAL && !auto_grant_permission) {
[email protected]8d888c12010-11-30 00:00:251303 // Add all the recognized permissions if the granted permissions list
1304 // hasn't been initialized yet.
dchengc963c7142016-04-08 03:55:221305 std::unique_ptr<const PermissionSet> granted_permissions =
[email protected]902fd7b2011-07-27 18:42:311306 extension_prefs_->GetGrantedPermissions(extension->id());
[email protected]0d3e4a22011-06-23 19:02:521307 CHECK(granted_permissions.get());
[email protected]8d888c12010-11-30 00:00:251308
1309 // Here, we check if an extension's privileges have increased in a manner
1310 // that requires the user's approval. This could occur because the browser
1311 // upgraded and recognized additional privileges, or an extension upgrades
1312 // to a version that requires additional privileges.
[email protected]c41003472013-10-19 15:37:251313 is_privilege_increase =
Devlin Cronineea1b7a2018-05-26 02:46:211314 PermissionMessageProvider::Get()->IsPrivilegeIncrease(
rdevlin.cronind630c302015-09-30 20:19:331315 *granted_permissions,
rdevlin.cronine2d0fd02015-09-24 22:35:491316 extension->permissions_data()->active_permissions(),
[email protected]076ebeda2014-06-06 21:47:261317 extension->GetType());
treib2c20f9442016-05-18 19:50:281318
1319 // If there was no privilege increase, the extension might still have new
1320 // permissions (which either don't generate a warning message, or whose
1321 // warning messages are suppressed by existing permissions). Grant the new
1322 // permissions.
1323 if (!is_privilege_increase)
1324 GrantPermissions(extension);
[email protected]8d888c12010-11-30 00:00:251325 }
1326
Marc Treib4bdb790b2018-07-07 15:02:481327 // TODO(crbug.com/860198): Before M48, extensions that came to us from sync in
1328 // a disabled state got assigned disable_reason::DISABLE_UNKNOWN_FROM_SYNC.
1329 // That reason isn't used anymore since the actual disable reason(s) are now
1330 // synced. This code is here to migrate any existing old state.
1331 if (disable_reasons & disable_reason::DEPRECATED_DISABLE_UNKNOWN_FROM_SYNC) {
1332 // Remove the disable_reason::DEPRECATED_DISABLE_UNKNOWN_FROM_SYNC
1333 // reason.
1334 disable_reasons &= ~disable_reason::DEPRECATED_DISABLE_UNKNOWN_FROM_SYNC;
1335 extension_prefs_->RemoveDisableReason(
1336 extension->id(), disable_reason::DEPRECATED_DISABLE_UNKNOWN_FROM_SYNC);
1337 // If there was no privilege increase, it was likely disabled by the user.
1338 // (If there *was* a privilege increase, we'll add an appropriate reason
1339 // later on, so nothing needs to be done here.)
1340 if (!is_privilege_increase)
1341 disable_reasons |= disable_reason::DISABLE_USER_ACTION;
1342 }
1343
treib6e51bca2016-06-15 10:26:031344 bool previously_disabled =
1345 extension_prefs_->IsExtensionDisabled(extension->id());
Marc Treib4bdb790b2018-07-07 15:02:481346 // TODO(devlin): Is the |is_extension_loaded| check needed here?
treib6e51bca2016-06-15 10:26:031347 if (is_extension_loaded && previously_disabled) {
treib8a6d9892015-08-26 10:23:191348 // Legacy disabled extensions do not have a disable reason. Infer that it
1349 // was likely disabled by the user.
Devlin Cronineea1b7a2018-05-26 02:46:211350 if (disable_reasons == disable_reason::DISABLE_NONE)
1351 disable_reasons |= disable_reason::DISABLE_USER_ACTION;
[email protected]8d888c12010-11-30 00:00:251352 }
1353
treib6e51bca2016-06-15 10:26:031354 // If the extension is disabled due to a permissions increase, but does in
1355 // fact have all permissions, remove that disable reason.
1356 // TODO(devlin): This was added to fix crbug.com/616474, but it's unclear
1357 // if this behavior should stay forever.
Devlin Cronineea1b7a2018-05-26 02:46:211358 if (disable_reasons & disable_reason::DISABLE_PERMISSIONS_INCREASE) {
treib6e51bca2016-06-15 10:26:031359 bool reset_permissions_increase = false;
1360 if (!is_privilege_increase) {
1361 reset_permissions_increase = true;
Devlin Cronineea1b7a2018-05-26 02:46:211362 disable_reasons &= ~disable_reason::DISABLE_PERMISSIONS_INCREASE;
treib6e51bca2016-06-15 10:26:031363 extension_prefs_->RemoveDisableReason(
Devlin Cronineea1b7a2018-05-26 02:46:211364 extension->id(), disable_reason::DISABLE_PERMISSIONS_INCREASE);
treib6e51bca2016-06-15 10:26:031365 }
1366 UMA_HISTOGRAM_BOOLEAN("Extensions.ResetPermissionsIncrease",
1367 reset_permissions_increase);
1368 }
1369
[email protected]8d888c12010-11-30 00:00:251370 // Extension has changed permissions significantly. Disable it. A
[email protected]21db9ef2014-05-16 02:06:271371 // notification should be sent by the caller. If the extension is already
1372 // disabled because it was installed remotely, don't add another disable
treibaac30ec2015-06-10 09:18:091373 // reason.
1374 if (is_privilege_increase &&
Devlin Cronineea1b7a2018-05-26 02:46:211375 !(disable_reasons & disable_reason::DISABLE_REMOTE_INSTALL)) {
1376 disable_reasons |= disable_reason::DISABLE_PERMISSIONS_INCREASE;
treib8a6d9892015-08-26 10:23:191377 if (!extension_prefs_->DidExtensionEscalatePermissions(extension->id()))
treib2e0517f92015-05-07 23:15:361378 RecordPermissionMessagesHistogram(extension, "AutoDisable");
treib8ecc1eb52015-03-04 18:29:061379
brettw9e85ef42016-11-01 21:01:241380#if BUILDFLAG(ENABLE_SUPERVISED_USERS)
treib8ecc1eb52015-03-04 18:29:061381 // If a custodian-installed extension is disabled for a supervised user due
mamir51e05d02016-10-06 10:55:011382 // to a permissions increase, send a request to the custodian.
Devlin Cronineea1b7a2018-05-26 02:46:211383 if (util::IsExtensionSupervised(extension, profile_) &&
treib40d3ad92015-10-20 18:15:421384 !ExtensionSyncService::Get(profile_)->HasPendingReenable(
Devlin Cronin03bf2d22017-12-20 08:21:051385 extension->id(), extension->version())) {
treib8ecc1eb52015-03-04 18:29:061386 SupervisedUserService* supervised_user_service =
1387 SupervisedUserServiceFactory::GetForProfile(profile_);
treib40d3ad92015-10-20 18:15:421388 supervised_user_service->AddExtensionUpdateRequest(extension->id(),
Devlin Cronin03bf2d22017-12-20 08:21:051389 extension->version());
treib8ecc1eb52015-03-04 18:29:061390 }
1391#endif
[email protected]b914e2952013-04-26 07:10:031392 }
treib6e51bca2016-06-15 10:26:031393
Devlin Cronineea1b7a2018-05-26 02:46:211394 if (disable_reasons == disable_reason::DISABLE_NONE)
treib6e51bca2016-06-15 10:26:031395 extension_prefs_->SetExtensionEnabled(extension->id());
1396 else
treib8a6d9892015-08-26 10:23:191397 extension_prefs_->SetExtensionDisabled(extension->id(), disable_reasons);
[email protected]8d888c12010-11-30 00:00:251398}
1399
[email protected]eaa7dd182010-12-14 11:09:001400void ExtensionService::UpdateActiveExtensionsInCrashReporter() {
[email protected]c8865962009-12-16 07:47:391401 std::set<std::string> extension_ids;
achuith2f5578b2016-02-26 21:57:131402 for (const auto& extension : registry_->enabled_extensions()) {
[email protected]1d5e58b2013-01-31 08:41:401403 if (!extension->is_theme() && extension->location() != Manifest::COMPONENT)
[email protected]84df8332011-12-06 18:22:461404 extension_ids.insert(extension->id());
[email protected]aab98a52009-12-02 03:22:351405 }
1406
[email protected]dcc47642014-03-26 22:03:491407 // TODO(kalman): This is broken. ExtensionService is per-profile.
1408 // crash_keys::SetActiveExtensions is per-process. See
1409 // http://crbug.com/355029.
[email protected]f6431be82013-09-07 02:53:451410 crash_keys::SetActiveExtensions(extension_ids);
[email protected]6014d672008-12-05 00:38:251411}
1412
[email protected]8266d662011-07-12 21:53:261413void ExtensionService::OnExtensionInstalled(
[email protected]36a5c4c2011-12-14 16:34:501414 const Extension* extension,
[email protected]98270432012-09-11 20:51:241415 const syncer::StringOrdinal& page_ordinal,
Karandeep Bhatiaa8930652017-10-11 17:41:121416 int install_flags,
1417 const base::Optional<int>& dnr_ruleset_checksum) {
[email protected]a29a517a2011-01-21 21:11:121418 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]a8af9fdb2010-10-28 21:52:201419
[email protected]c3cfb012011-04-06 22:07:351420 const std::string& id = extension->id();
binjin47947f842014-11-18 12:10:241421 int disable_reasons = GetDisableReasonsOnInstalled(extension);
[email protected]d8fd0fd2014-03-24 13:16:061422 std::string install_parameter;
Devlin Cronineea1b7a2018-05-26 02:46:211423 const PendingExtensionInfo* pending_extension_info =
[email protected]96aebe22014-07-16 04:07:511424 pending_extension_manager()->GetById(id);
1425 if (pending_extension_info) {
[email protected]8f3bcbd2013-06-05 08:42:401426 if (!pending_extension_info->ShouldAllowInstall(extension)) {
Devlinec30d362018-07-13 18:13:391427 // Hack for crbug.com/558299, see comment on DeleteThemeDoNotUse.
1428 if (extension->is_theme() && pending_extension_info->is_from_sync())
1429 ExtensionSyncService::Get(profile_)->DeleteThemeDoNotUse(*extension);
1430
[email protected]51a3bf8b2012-06-08 22:53:061431 pending_extension_manager()->Remove(id);
[email protected]8ef78fd2010-08-19 17:14:321432
Devlin Cronineea1b7a2018-05-26 02:46:211433 LOG(WARNING) << "ShouldAllowInstall() returned false for " << id
1434 << " of type " << extension->GetType() << " and update URL "
1435 << ManifestURL::GetUpdateURL(extension).spec()
[email protected]31bb5ee62012-09-12 22:58:401436 << "; not installing";
[email protected]ae6cb3022011-04-04 20:11:541437
[email protected]4416c5a2010-06-26 01:28:571438 // Delete the extension directory since we're not going to
1439 // load it.
Devlin Cronineea1b7a2018-05-26 02:46:211440 if (!GetExtensionFileTaskRunner()->PostTask(
1441 FROM_HERE, base::BindOnce(&file_util::DeleteFile,
tzik8d880ee2017-04-20 19:46:241442 extension->path(), true))) {
[email protected]14908b72011-04-20 06:54:361443 NOTREACHED();
[email protected]31bb5ee62012-09-12 22:58:401444 }
[email protected]4416c5a2010-06-26 01:28:571445 return;
1446 }
[email protected]51a3bf8b2012-06-08 22:53:061447
[email protected]d8fd0fd2014-03-24 13:16:061448 install_parameter = pending_extension_info->install_parameter();
[email protected]51a3bf8b2012-06-08 22:53:061449 pending_extension_manager()->Remove(id);
[email protected]4416c5a2010-06-26 01:28:571450 } else {
[email protected]c3cfb012011-04-06 22:07:351451 // We explicitly want to re-enable an uninstalled external
1452 // extension; if we're here, that means the user is manually
1453 // installing the extension.
[email protected]46f3e102014-03-25 01:22:451454 if (extension_prefs_->IsExternalExtensionUninstalled(id)) {
Devlin Cronineea1b7a2018-05-26 02:46:211455 disable_reasons = disable_reason::DISABLE_NONE;
[email protected]6cc7dbae2011-04-29 21:18:331456 }
[email protected]aa142702010-03-26 01:26:331457 }
1458
asargente4de9f92016-09-15 01:40:061459 // If the old version of the extension was disabled due to corruption, this
1460 // new install may correct the problem.
Devlin Cronineea1b7a2018-05-26 02:46:211461 disable_reasons &= ~disable_reason::DISABLE_CORRUPTED;
asargente4de9f92016-09-15 01:40:061462
[email protected]98270432012-09-11 20:51:241463 // Unsupported requirements overrides the management policy.
Devlin Cronineea1b7a2018-05-26 02:46:211464 if (install_flags & kInstallFlagHasRequirementErrors) {
1465 disable_reasons |= disable_reason::DISABLE_UNSUPPORTED_REQUIREMENT;
binjin8e3d0182014-12-04 16:44:281466 } else {
1467 // Requirement is supported now, remove the corresponding disable reason
1468 // instead.
Devlin Cronineea1b7a2018-05-26 02:46:211469 disable_reasons &= ~disable_reason::DISABLE_UNSUPPORTED_REQUIREMENT;
binjin8e3d0182014-12-04 16:44:281470 }
1471
1472 // Check if the extension was disabled because of the minimum version
1473 // requirements from enterprise policy, and satisfies it now.
Devlin Cronineea1b7a2018-05-26 02:46:211474 if (ExtensionManagementFactory::GetForBrowserContext(profile())
binjin8e3d0182014-12-04 16:44:281475 ->CheckMinimumVersion(extension, nullptr)) {
1476 // And remove the corresponding disable reason.
Devlin Cronineea1b7a2018-05-26 02:46:211477 disable_reasons &= ~disable_reason::DISABLE_UPDATE_REQUIRED_BY_POLICY;
[email protected]98270432012-09-11 20:51:241478 }
1479
Devlin Cronineea1b7a2018-05-26 02:46:211480 if (install_flags & kInstallFlagIsBlacklistedForMalware) {
[email protected]9f3c8532013-07-31 19:52:071481 // Installation of a blacklisted extension can happen from sync, policy,
1482 // etc, where to maintain consistency we need to install it, just never
1483 // load it (see AddExtension). Usually it should be the job of callers to
treibaac30ec2015-06-10 09:18:091484 // intercept blacklisted extensions earlier (e.g. CrxInstaller, before even
[email protected]9f3c8532013-07-31 19:52:071485 // showing the install dialogue).
[email protected]7c82539c2014-02-19 06:09:171486 extension_prefs_->AcknowledgeBlacklistedExtension(id);
[email protected]9f3c8532013-07-31 19:52:071487 UMA_HISTOGRAM_ENUMERATION("ExtensionBlacklist.SilentInstall",
1488 extension->location(),
1489 Manifest::NUM_LOCATIONS);
1490 }
1491
[email protected]695b5712012-12-06 23:55:281492 if (!GetInstalledExtension(extension->id())) {
[email protected]07533022011-06-27 20:42:551493 UMA_HISTOGRAM_ENUMERATION("Extensions.InstallType",
1494 extension->GetType(), 100);
[email protected]69084dc2012-11-17 07:39:301495 UMA_HISTOGRAM_ENUMERATION("Extensions.InstallSource",
[email protected]1d5e58b2013-01-31 08:41:401496 extension->location(), Manifest::NUM_LOCATIONS);
treib2e0517f92015-05-07 23:15:361497 RecordPermissionMessagesHistogram(extension, "Install");
[email protected]69084dc2012-11-17 07:39:301498 } else {
1499 UMA_HISTOGRAM_ENUMERATION("Extensions.UpdateType",
1500 extension->GetType(), 100);
1501 UMA_HISTOGRAM_ENUMERATION("Extensions.UpdateSource",
[email protected]1d5e58b2013-01-31 08:41:401502 extension->location(), Manifest::NUM_LOCATIONS);
[email protected]07533022011-06-27 20:42:551503 }
1504
[email protected]399583b2012-12-11 09:33:421505 const Extension::State initial_state =
Devlin Cronineea1b7a2018-05-26 02:46:211506 disable_reasons == disable_reason::DISABLE_NONE ? Extension::ENABLED
1507 : Extension::DISABLED;
treib8a6d9892015-08-26 10:23:191508 if (initial_state == Extension::ENABLED)
1509 extension_prefs_->SetExtensionEnabled(id);
1510 else
1511 extension_prefs_->SetExtensionDisabled(id, disable_reasons);
binjin47947f842014-11-18 12:10:241512
Devlin Cronineea1b7a2018-05-26 02:46:211513 ExtensionPrefs::DelayReason delay_reason;
1514 InstallGate::Action action = ShouldDelayExtensionInstall(
1515 extension, !!(install_flags & kInstallFlagInstallImmediately),
xiyuanf6a4c6a62016-04-19 18:14:541516 &delay_reason);
1517 switch (action) {
Devlin Cronineea1b7a2018-05-26 02:46:211518 case InstallGate::INSTALL:
xiyuanf6a4c6a62016-04-19 18:14:541519 AddNewOrUpdatedExtension(extension, initial_state, install_flags,
Karandeep Bhatiaa8930652017-10-11 17:41:121520 page_ordinal, install_parameter,
1521 dnr_ruleset_checksum);
xiyuanf6a4c6a62016-04-19 18:14:541522 return;
Devlin Cronineea1b7a2018-05-26 02:46:211523 case InstallGate::DELAY:
Karandeep Bhatiaa8930652017-10-11 17:41:121524 extension_prefs_->SetDelayedInstallInfo(
1525 extension, initial_state, install_flags, delay_reason, page_ordinal,
1526 install_parameter, dnr_ruleset_checksum);
[email protected]0db124b02012-11-07 04:55:051527
xiyuanf6a4c6a62016-04-19 18:14:541528 // Transfer ownership of |extension|.
[email protected]9f4e4f082013-06-21 07:11:191529 delayed_installs_.Insert(extension);
xiyuanf6a4c6a62016-04-19 18:14:541530
Devlin Cronineea1b7a2018-05-26 02:46:211531 if (delay_reason == ExtensionPrefs::DELAY_REASON_WAIT_FOR_IDLE) {
xiyuanf6a4c6a62016-04-19 18:14:541532 // Notify observers that app update is available.
ericwilligersb5f79de2016-10-19 04:15:101533 for (auto& observer : update_observers_)
1534 observer.OnAppUpdateAvailable(extension);
xiyuanf6a4c6a62016-04-19 18:14:541535 }
1536 return;
Devlin Cronineea1b7a2018-05-26 02:46:211537 case InstallGate::ABORT:
xiyuanf6a4c6a62016-04-19 18:14:541538 // Do nothing to abort the install. One such case is the shared module
1539 // service gets IMPORT_STATUS_UNRECOVERABLE status for the pending
1540 // install.
1541 return;
[email protected]399583b2012-12-11 09:33:421542 }
xiyuanf6a4c6a62016-04-19 18:14:541543
1544 NOTREACHED() << "Unknown action for delayed install: " << action;
[email protected]8c484b742012-11-29 06:05:361545}
1546
binjin1569c9b2014-09-05 13:33:181547void ExtensionService::OnExtensionManagementSettingsChanged() {
1548 error_controller_->ShowErrorIfNeeded();
binjine6b58b52014-10-31 01:55:571549
1550 // Revokes blocked permissions from active_permissions for all extensions.
Devlin Cronineea1b7a2018-05-26 02:46:211551 ExtensionManagement* settings =
1552 ExtensionManagementFactory::GetForBrowserContext(profile());
binjine6b58b52014-10-31 01:55:571553 CHECK(settings);
dchengc963c7142016-04-08 03:55:221554 std::unique_ptr<ExtensionSet> all_extensions(
binjine6b58b52014-10-31 01:55:571555 registry_->GenerateInstalledExtensionsSet());
achuith2f5578b2016-02-26 21:57:131556 for (const auto& extension : *all_extensions) {
binjine6b58b52014-10-31 01:55:571557 if (!settings->IsPermissionSetAllowed(
binjin685ade82014-11-06 09:53:561558 extension.get(),
Nick Peterson0203be4a2017-07-19 00:25:141559 extension->permissions_data()->active_permissions()) &&
1560 CanBlockExtension(extension.get())) {
Devlin Cronineea1b7a2018-05-26 02:46:211561 PermissionsUpdater(profile()).RemovePermissionsUnsafe(
rdevlin.cronind630c302015-09-30 20:19:331562 extension.get(), *settings->GetBlockedPermissions(extension.get()));
binjine6b58b52014-10-31 01:55:571563 }
1564 }
1565
binjin1569c9b2014-09-05 13:33:181566 CheckManagementPolicy();
1567}
1568
[email protected]8c484b742012-11-29 06:05:361569void ExtensionService::AddNewOrUpdatedExtension(
1570 const Extension* extension,
[email protected]399583b2012-12-11 09:33:421571 Extension::State initial_state,
[email protected]4a1d9c0d2014-06-13 12:50:111572 int install_flags,
[email protected]d8fd0fd2014-03-24 13:16:061573 const syncer::StringOrdinal& page_ordinal,
Karandeep Bhatiaa8930652017-10-11 17:41:121574 const std::string& install_parameter,
1575 const base::Optional<int>& dnr_ruleset_checksum) {
[email protected]8c484b742012-11-29 06:05:361576 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
Karandeep Bhatiaa8930652017-10-11 17:41:121577 extension_prefs_->OnExtensionInstalled(extension, initial_state, page_ordinal,
1578 install_flags, install_parameter,
1579 dnr_ruleset_checksum);
[email protected]9e9c1d12013-07-31 01:58:121580 delayed_installs_.Remove(extension->id());
[email protected]913ffca92014-03-27 15:26:161581 if (InstallVerifier::NeedsVerification(*extension))
juncai33e462102015-05-18 20:48:441582 InstallVerifier::Get(GetBrowserContext())->VerifyExtension(extension->id());
ryanackley48bedbd2015-01-27 23:12:141583
1584 const Extension* old = GetInstalledExtension(extension->id());
Devlin Cronineea1b7a2018-05-26 02:46:211585 if (AppDataMigrator::NeedsMigration(old, extension)) {
ryanackley48bedbd2015-01-27 23:12:141586 app_data_migrator_->DoMigrationAndReply(
vmpstra34d11322016-03-21 20:28:471587 old, extension, base::Bind(&ExtensionService::FinishInstallation,
1588 AsWeakPtr(), base::RetainedRef(extension)));
ryanackley48bedbd2015-01-27 23:12:141589 return;
1590 }
1591
benwells1dd4acd2015-12-09 02:20:241592 FinishInstallation(extension);
[email protected]6f6101832012-11-27 22:10:481593}
1594
Toni Barzic667db0d32018-01-09 18:00:191595bool ExtensionService::FinishDelayedInstallationIfReady(
1596 const std::string& extension_id,
1597 bool install_immediately) {
[email protected]9f4e4f082013-06-21 07:11:191598 // Check if the extension already got installed.
[email protected]9f4e4f082013-06-21 07:11:191599 const Extension* extension = delayed_installs_.GetByID(extension_id);
xiyuanf6a4c6a62016-04-19 18:14:541600 if (!extension)
Toni Barzic667db0d32018-01-09 18:00:191601 return false;
xiyuanf6a4c6a62016-04-19 18:14:541602
Devlin Cronineea1b7a2018-05-26 02:46:211603 ExtensionPrefs::DelayReason reason;
1604 const InstallGate::Action action =
Toni Barzic667db0d32018-01-09 18:00:191605 ShouldDelayExtensionInstall(extension, install_immediately, &reason);
xiyuanf6a4c6a62016-04-19 18:14:541606 switch (action) {
Devlin Cronineea1b7a2018-05-26 02:46:211607 case InstallGate::INSTALL:
xiyuanf6a4c6a62016-04-19 18:14:541608 break;
Devlin Cronineea1b7a2018-05-26 02:46:211609 case InstallGate::DELAY:
xiyuanf6a4c6a62016-04-19 18:14:541610 // Bail out and continue to delay the install.
Toni Barzic667db0d32018-01-09 18:00:191611 return false;
Devlin Cronineea1b7a2018-05-26 02:46:211612 case InstallGate::ABORT:
xiyuanf6a4c6a62016-04-19 18:14:541613 delayed_installs_.Remove(extension_id);
1614 // Make sure no version of the extension is actually installed, (i.e.,
1615 // that this delayed install was not an update).
1616 CHECK(!extension_prefs_->GetInstalledExtensionInfo(extension_id).get());
1617 extension_prefs_->DeleteExtensionPrefs(extension_id);
Toni Barzic667db0d32018-01-09 18:00:191618 return false;
[email protected]9f4e4f082013-06-21 07:11:191619 }
1620
Toni Barzic667db0d32018-01-09 18:00:191621 scoped_refptr<const Extension> delayed_install =
1622 GetPendingExtensionUpdate(extension_id);
1623 CHECK(delayed_install.get());
[email protected]9f4e4f082013-06-21 07:11:191624 delayed_installs_.Remove(extension_id);
[email protected]6f6101832012-11-27 22:10:481625
[email protected]399583b2012-12-11 09:33:421626 if (!extension_prefs_->FinishDelayedInstallInfo(extension_id))
[email protected]6f6101832012-11-27 22:10:481627 NOTREACHED();
1628
Toni Barzic667db0d32018-01-09 18:00:191629 FinishInstallation(delayed_install.get());
1630 return true;
[email protected]6f6101832012-11-27 22:10:481631}
1632
[email protected]760f743b2014-05-28 13:52:021633void ExtensionService::FinishInstallation(
benwells1dd4acd2015-12-09 02:20:241634 const Extension* extension) {
Devlin Cronineea1b7a2018-05-26 02:46:211635 const Extension* existing_extension = GetInstalledExtension(extension->id());
[email protected]e7554c3f2013-05-29 00:36:561636 bool is_update = false;
1637 std::string old_name;
1638 if (existing_extension) {
1639 is_update = true;
1640 old_name = existing_extension->name();
1641 }
[email protected]bc44b5da2014-06-12 14:20:001642 registry_->TriggerOnWillBeInstalled(
benwells1dd4acd2015-12-09 02:20:241643 extension, is_update, old_name);
[email protected]17f07822014-05-22 08:45:151644
[email protected]399583b2012-12-11 09:33:421645 // Unpacked extensions default to allowing file access, but if that has been
1646 // overridden, don't reset the value.
[email protected]1d5e58b2013-01-31 08:41:401647 if (Manifest::ShouldAlwaysAllowFileAccess(extension->location()) &&
[email protected]399583b2012-12-11 09:33:421648 !extension_prefs_->HasAllowFileAccessSetting(extension->id())) {
1649 extension_prefs_->SetAllowFileAccess(extension->id(), true);
1650 }
1651
[email protected]6f6101832012-11-27 22:10:481652 AddExtension(extension);
[email protected]612a1cb12012-10-17 13:18:031653
[email protected]bc44b5da2014-06-12 14:20:001654 // Notify observers that need to know when an installation is complete.
[email protected]38e872532014-07-16 23:27:511655 registry_->TriggerOnInstalled(extension, is_update);
[email protected]bc44b5da2014-06-12 14:20:001656
[email protected]9f4e4f082013-06-21 07:11:191657 // Check extensions that may have been delayed only because this shared module
1658 // was not available.
[email protected]374ceb6f2014-07-02 19:25:341659 if (SharedModuleInfo::IsSharedModule(extension))
[email protected]9f4e4f082013-06-21 07:11:191660 MaybeFinishDelayedInstallations();
[email protected]4a190632009-05-09 01:07:421661}
1662
[email protected]76b65442012-11-17 14:11:481663const Extension* ExtensionService::GetPendingExtensionUpdate(
1664 const std::string& id) const {
[email protected]9f4e4f082013-06-21 07:11:191665 return delayed_installs_.GetByID(id);
[email protected]76b65442012-11-17 14:11:481666}
1667
mukai87a8d402014-09-15 20:15:091668void ExtensionService::RegisterContentSettings(
mmenkead5094ab2017-05-15 19:01:141669 HostContentSettingsMap* host_content_settings_map,
1670 Profile* profile) {
1671 // Most extension services key off of the original profile.
1672 Profile* original_profile = profile->GetOriginalProfile();
1673
rkaplowe65c2ff2015-02-14 16:29:541674 TRACE_EVENT0("browser,startup", "ExtensionService::RegisterContentSettings");
mukaia1aa3512014-10-22 20:14:111675 DCHECK_CURRENTLY_ON(BrowserThread::UI);
mukai87a8d402014-09-15 20:15:091676 host_content_settings_map->RegisterProvider(
mukai87a8d402014-09-15 20:15:091677 HostContentSettingsMap::CUSTOM_EXTENSION_PROVIDER,
dchengc963c7142016-04-08 03:55:221678 std::unique_ptr<content_settings::ObservableProvider>(
mukai87a8d402014-09-15 20:15:091679 new content_settings::CustomExtensionProvider(
Devlin Cronineea1b7a2018-05-26 02:46:211680 ContentSettingsService::Get(original_profile)
dchengc963c7142016-04-08 03:55:221681 ->content_settings_store(),
mmenkead5094ab2017-05-15 19:01:141682 // TODO(mmenke): CustomExtensionProvider expects this to be true
1683 // for incognito profiles.
1684 false)));
mukai87a8d402014-09-15 20:15:091685}
1686
[email protected]e9d7496e2014-04-18 01:25:461687void ExtensionService::TerminateExtension(const std::string& extension_id) {
Michael Giuffridafcb420362017-10-11 21:50:261688 extension_registrar_.TerminateExtension(extension_id);
[email protected]bb7f40952011-01-13 00:21:201689}
1690
[email protected]8001df22011-04-28 19:59:471691const Extension* ExtensionService::GetInstalledExtension(
1692 const std::string& id) const {
[email protected]599539802014-01-07 23:06:001693 return registry_->GetExtensionById(id, ExtensionRegistry::EVERYTHING);
[email protected]0dfe05c2011-02-23 23:03:361694}
1695
[email protected]9060d8b02012-01-13 02:14:301696bool ExtensionService::OnExternalExtensionFileFound(
lazyboye8634172016-01-28 00:10:481697 const ExternalInstallInfoFile& info) {
Istiaque Ahmedf6e72622017-09-08 23:14:171698 DCHECK_CURRENTLY_ON(BrowserThread::UI);
lazyboye8634172016-01-28 00:10:481699 CHECK(crx_file::id_util::IdIsValid(info.extension_id));
1700 if (extension_prefs_->IsExternalExtensionUninstalled(info.extension_id))
[email protected]9060d8b02012-01-13 02:14:301701 return false;
[email protected]a8af9fdb2010-10-28 21:52:201702
[email protected]7577a5c52009-07-30 06:21:581703 // Before even bothering to unpack, check and see if we already have this
[email protected]4c967932009-07-31 01:15:491704 // version. This is important because these extensions are going to get
[email protected]7577a5c52009-07-30 06:21:581705 // installed on every startup.
lazyboye8634172016-01-28 00:10:481706 const Extension* existing = GetExtensionById(info.extension_id, true);
[email protected]910f72ce2012-08-24 01:38:351707
[email protected]7577a5c52009-07-30 06:21:581708 if (existing) {
[email protected]910f72ce2012-08-24 01:38:351709 // The default apps will have the location set as INTERNAL. Since older
1710 // default apps are installed as EXTERNAL, we override them. However, if the
1711 // app is already installed as internal, then do the version check.
[email protected]31bb5ee62012-09-12 22:58:401712 // TODO(grv) : Remove after Q1-2013.
[email protected]910f72ce2012-08-24 01:38:351713 bool is_default_apps_migration =
lazyboye8634172016-01-28 00:10:481714 (info.crx_location == Manifest::INTERNAL &&
[email protected]1d5e58b2013-01-31 08:41:401715 Manifest::IsExternalLocation(existing->location()));
[email protected]910f72ce2012-08-24 01:38:351716
1717 if (!is_default_apps_migration) {
Devlin Cronin03bf2d22017-12-20 08:21:051718 switch (existing->version().CompareTo(info.version)) {
[email protected]910f72ce2012-08-24 01:38:351719 case -1: // existing version is older, we should upgrade
1720 break;
1721 case 0: // existing version is same, do nothing
1722 return false;
1723 case 1: // existing version is newer, uh-oh
lazyboye8634172016-01-28 00:10:481724 LOG(WARNING) << "Found external version of extension "
1725 << info.extension_id
[email protected]910f72ce2012-08-24 01:38:351726 << "that is older than current version. Current version "
1727 << "is: " << existing->VersionString() << ". New "
Devlin Cronind4c2a8f32017-09-29 17:08:301728 << "version is: " << info.version.GetString()
[email protected]910f72ce2012-08-24 01:38:351729 << ". Keeping current version.";
1730 return false;
1731 }
[email protected]7577a5c52009-07-30 06:21:581732 }
1733 }
1734
[email protected]9060d8b02012-01-13 02:14:301735 // If the extension is already pending, don't start an install.
[email protected]e3987852012-05-04 10:06:301736 if (!pending_extension_manager()->AddFromExternalFile(
Devlin Cronind4c2a8f32017-09-29 17:08:301737 info.extension_id, info.crx_location, info.version,
lazyboye8634172016-01-28 00:10:481738 info.creation_flags, info.mark_acknowledged)) {
[email protected]9060d8b02012-01-13 02:14:301739 return false;
[email protected]e3987852012-05-04 10:06:301740 }
[email protected]9c635f22010-12-02 09:36:361741
[email protected]14908b72011-04-20 06:54:361742 // no client (silent install)
[email protected]f8636f92013-08-09 21:02:371743 scoped_refptr<CrxInstaller> installer(CrxInstaller::CreateSilent(this));
lazyboye8634172016-01-28 00:10:481744 installer->set_install_source(info.crx_location);
1745 installer->set_expected_id(info.extension_id);
Devlin Cronind4c2a8f32017-09-29 17:08:301746 installer->set_expected_version(info.version,
treibe960e282015-09-11 10:38:081747 true /* fail_install_if_unexpected */);
[email protected]cb0e50312011-05-09 15:03:071748 installer->set_install_cause(extension_misc::INSTALL_CAUSE_EXTERNAL_FILE);
lazyboye8634172016-01-28 00:10:481749 installer->set_install_immediately(info.install_immediately);
1750 installer->set_creation_flags(info.creation_flags);
Oleg Davydovfd848c02019-05-10 16:51:381751
1752 CRXFileInfo file_info(
1753 info.path,
1754 info.crx_location == Manifest::EXTERNAL_POLICY
1755 ? GetPolicyVerifierFormat(ExtensionPrefs::Get(profile_)
1756 ->InsecureExtensionUpdatesEnabled())
1757 : GetExternalVerifierFormat());
[email protected]88e8ec9152013-01-17 04:05:181758#if defined(OS_CHROMEOS)
Oleg Davydovfd848c02019-05-10 16:51:381759 InstallLimiter::Get(profile_)->Add(installer, file_info);
[email protected]88e8ec9152013-01-17 04:05:181760#else
Oleg Davydovfd848c02019-05-10 16:51:381761 installer->InstallCrxFile(file_info);
[email protected]88e8ec9152013-01-17 04:05:181762#endif
[email protected]47fc70c2011-12-06 07:29:511763
1764 // Depending on the source, a new external extension might not need a user
1765 // notification on installation. For such extensions, mark them acknowledged
1766 // now to suppress the notification.
lazyboye8634172016-01-28 00:10:481767 if (info.mark_acknowledged)
1768 external_install_manager_->AcknowledgeExternalExtension(info.extension_id);
[email protected]9060d8b02012-01-13 02:14:301769
1770 return true;
[email protected]7577a5c52009-07-30 06:21:581771}
1772
[email protected]eaa7dd182010-12-14 11:09:001773void ExtensionService::DidCreateRenderViewForBackgroundPage(
Devlin Cronineea1b7a2018-05-26 02:46:211774 ExtensionHost* host) {
Michael Giuffrida573992d2018-02-08 00:48:441775 extension_registrar_.DidCreateRenderViewForBackgroundPage(host);
[email protected]406027c02010-09-27 08:03:181776}
1777
[email protected]432115822011-07-10 15:52:271778void ExtensionService::Observe(int type,
[email protected]6c2381d2011-10-19 02:52:531779 const content::NotificationSource& source,
1780 const content::NotificationDetails& details) {
[email protected]432115822011-07-10 15:52:271781 switch (type) {
[email protected]3c4abc82012-10-22 22:25:541782 case chrome::NOTIFICATION_APP_TERMINATING:
1783 // Shutdown has started. Don't start any more extension installs.
1784 // (We cannot use ExtensionService::Shutdown() for this because it
1785 // happens too late in browser teardown.)
1786 browser_terminating_ = true;
1787 break;
Devlin Cronineea1b7a2018-05-26 02:46:211788 case NOTIFICATION_EXTENSION_PROCESS_TERMINATED: {
[email protected]6c2381d2011-10-19 02:52:531789 if (profile_ !=
1790 content::Source<Profile>(source).ptr()->GetOriginalProfile()) {
[email protected]bc535ee52010-08-31 18:40:321791 break;
[email protected]6c2381d2011-10-19 02:52:531792 }
[email protected]a4ed6282009-12-14 20:51:161793
Michael Giuffridafcb420362017-10-11 21:50:261794 // Mark the extension as terminated and deactivated. We want it to
[email protected]fa2416f2011-05-03 08:41:201795 // be in a consistent state: either fully working or not loaded
1796 // at all, but never half-crashed. We do it in a PostTask so
1797 // that other handlers of this notification will still have
1798 // access to the Extension and ExtensionHost.
Devlin Cronineea1b7a2018-05-26 02:46:211799 ExtensionHost* host = content::Details<ExtensionHost>(details).ptr();
skyostilf221b7de2015-06-11 20:36:321800 base::ThreadTaskRunnerHandle::Get()->PostTask(
Michael Giuffridafcb420362017-10-11 21:50:261801 FROM_HERE, base::BindOnce(&ExtensionService::TerminateExtension,
1802 AsWeakPtr(), host->extension_id()));
[email protected]31f77262009-12-02 20:48:531803 break;
1804 }
[email protected]432115822011-07-10 15:52:271805 case content::NOTIFICATION_RENDERER_PROCESS_TERMINATED: {
[email protected]f3b1a082011-11-18 00:34:301806 content::RenderProcessHost* process =
1807 content::Source<content::RenderProcessHost>(source).ptr();
[email protected]fc30ef082011-08-18 04:07:191808 Profile* host_profile =
[email protected]f3b1a082011-11-18 00:34:301809 Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]fc30ef082011-08-18 04:07:191810 if (!profile_->IsSameProfile(host_profile->GetOriginalProfile()))
1811 break;
1812
Devlin Cronineea1b7a2018-05-26 02:46:211813 ProcessMap* process_map = ProcessMap::Get(profile_);
[email protected]fafdc842014-01-17 18:09:081814 if (process_map->Contains(process->GetID())) {
[email protected]52b76592013-11-02 17:59:031815 // An extension process was terminated, this might have resulted in an
1816 // app or extension becoming idle.
1817 std::set<std::string> extension_ids =
[email protected]fafdc842014-01-17 18:09:081818 process_map->GetExtensionsInProcess(process->GetID());
elijahtaylor0def4432014-10-06 18:15:111819 // In addition to the extensions listed in the process map, one of those
1820 // extensions could be referencing a shared module which is waiting for
1821 // idle to update. Check all imports of these extensions, too.
1822 std::set<std::string> import_ids;
jdoerrie13cd648c82018-10-02 21:21:021823 for (auto it = extension_ids.begin(); it != extension_ids.end(); ++it) {
elijahtaylor0def4432014-10-06 18:15:111824 const Extension* extension = GetExtensionById(*it, true);
1825 if (!extension)
1826 continue;
1827 const std::vector<SharedModuleInfo::ImportInfo>& imports =
1828 SharedModuleInfo::GetImports(extension);
1829 std::vector<SharedModuleInfo::ImportInfo>::const_iterator import_it;
1830 for (import_it = imports.begin(); import_it != imports.end();
1831 import_it++) {
1832 import_ids.insert((*import_it).extension_id);
1833 }
1834 }
1835 extension_ids.insert(import_ids.begin(), import_ids.end());
1836
jdoerrie13cd648c82018-10-02 21:21:021837 for (auto it = extension_ids.begin(); it != extension_ids.end(); ++it) {
[email protected]52b76592013-11-02 17:59:031838 if (delayed_installs_.Contains(*it)) {
skyostilf221b7de2015-06-11 20:36:321839 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
[email protected]52b76592013-11-02 17:59:031840 FROM_HERE,
tzik8d880ee2017-04-20 19:46:241841 base::BindOnce(
Toni Barzic667db0d32018-01-09 18:00:191842 base::IgnoreResult(
1843 &ExtensionService::FinishDelayedInstallationIfReady),
1844 AsWeakPtr(), *it, false /*install_immediately*/),
Lei Zhang15339152018-08-09 22:20:441845 kUpdateIdleDelay);
[email protected]52b76592013-11-02 17:59:031846 }
1847 }
1848 }
1849
[email protected]fafdc842014-01-17 18:09:081850 process_map->RemoveAllFromProcess(process->GetID());
Eric Seckler8652dcd52018-09-20 10:42:281851 base::PostTaskWithTraits(
1852 FROM_HERE, {BrowserThread::IO},
Devlin Cronineea1b7a2018-05-26 02:46:211853 base::BindOnce(&InfoMap::UnregisterAllExtensionsInProcess,
tzik8d880ee2017-04-20 19:46:241854 system_->info_map(), process->GetID()));
[email protected]da5683db2011-04-23 17:12:211855 break;
1856 }
[email protected]ebe07772014-05-22 04:16:061857 case chrome::NOTIFICATION_PROFILE_DESTRUCTION_STARTED: {
1858 OnProfileDestructionStarted();
1859 break;
1860 }
[email protected]aa96d3a2010-08-21 08:45:251861
[email protected]4814b512009-11-07 00:12:291862 default:
1863 NOTREACHED() << "Unexpected notification type.";
1864 }
1865}
1866
binjin47947f842014-11-18 12:10:241867int ExtensionService::GetDisableReasonsOnInstalled(const Extension* extension) {
rdevlin.cronine1456712016-12-29 22:47:281868 bool is_update_from_same_type = false;
1869 {
1870 const Extension* existing_extension =
1871 GetInstalledExtension(extension->id());
1872 is_update_from_same_type =
1873 existing_extension &&
1874 existing_extension->manifest()->type() == extension->manifest()->type();
1875 }
Devlin Cronineea1b7a2018-05-26 02:46:211876 disable_reason::DisableReason disable_reason = disable_reason::DISABLE_NONE;
binjin47947f842014-11-18 12:10:241877 // Extensions disabled by management policy should always be disabled, even
1878 // if it's force-installed.
1879 if (system_->management_policy()->MustRemainDisabled(
1880 extension, &disable_reason, nullptr)) {
1881 // A specified reason is required to disable the extension.
Devlin Cronineea1b7a2018-05-26 02:46:211882 DCHECK(disable_reason != disable_reason::DISABLE_NONE);
binjin47947f842014-11-18 12:10:241883 return disable_reason;
1884 }
1885
[email protected]612a1cb12012-10-17 13:18:031886 // Extensions installed by policy can't be disabled. So even if a previous
1887 // installation disabled the extension, make sure it is now enabled.
binjin47947f842014-11-18 12:10:241888 if (system_->management_policy()->MustRemainEnabled(extension, nullptr))
Devlin Cronineea1b7a2018-05-26 02:46:211889 return disable_reason::DISABLE_NONE;
[email protected]612a1cb12012-10-17 13:18:031890
binjin47947f842014-11-18 12:10:241891 // An already disabled extension should inherit the disable reasons and
1892 // remain disabled.
1893 if (extension_prefs_->IsExtensionDisabled(extension->id())) {
1894 int disable_reasons = extension_prefs_->GetDisableReasons(extension->id());
1895 // If an extension was disabled without specified reason, presume it's
1896 // disabled by user.
Devlin Cronineea1b7a2018-05-26 02:46:211897 return disable_reasons == disable_reason::DISABLE_NONE
1898 ? disable_reason::DISABLE_USER_ACTION
binjin47947f842014-11-18 12:10:241899 : disable_reasons;
1900 }
[email protected]612a1cb12012-10-17 13:18:031901
Devlin Cronineea1b7a2018-05-26 02:46:211902 if (ExternalInstallManager::IsPromptingEnabled()) {
[email protected]612a1cb12012-10-17 13:18:031903 // External extensions are initially disabled. We prompt the user before
[email protected]2c495c42013-01-04 21:49:541904 // enabling them. Hosted apps are excepted because they are not dangerous
rdevlin.cronine1456712016-12-29 22:47:281905 // (they need to be launched by the user anyway). We also don't prompt for
1906 // extensions updating; this is because the extension will be disabled from
1907 // the initial install if it is supposed to be, and this allows us to turn
1908 // this on for other platforms without disabling already-installed
1909 // extensions.
[email protected]1d5e58b2013-01-31 08:41:401910 if (extension->GetType() != Manifest::TYPE_HOSTED_APP &&
1911 Manifest::IsExternalLocation(extension->location()) &&
rdevlin.cronine1456712016-12-29 22:47:281912 !extension_prefs_->IsExternalExtensionAcknowledged(extension->id()) &&
1913 !is_update_from_same_type) {
Devlin Cronineea1b7a2018-05-26 02:46:211914 return disable_reason::DISABLE_EXTERNAL_EXTENSION;
[email protected]612a1cb12012-10-17 13:18:031915 }
1916 }
[email protected]612a1cb12012-10-17 13:18:031917
Devlin Cronineea1b7a2018-05-26 02:46:211918 return disable_reason::DISABLE_NONE;
[email protected]612a1cb12012-10-17 13:18:031919}
[email protected]0db124b02012-11-07 04:55:051920
mlerman6a37b6a42014-11-26 22:10:531921// Helper method to determine if an extension can be blocked.
1922bool ExtensionService::CanBlockExtension(const Extension* extension) const {
mlerman3690e5be2014-12-01 22:57:441923 DCHECK(extension);
mlerman6a37b6a42014-11-26 22:10:531924 return extension->location() != Manifest::COMPONENT &&
1925 extension->location() != Manifest::EXTERNAL_COMPONENT &&
achuith2f5578b2016-02-26 21:57:131926 !system_->management_policy()->MustRemainEnabled(extension, nullptr);
mlerman6a37b6a42014-11-26 22:10:531927}
1928
Devlin Cronineea1b7a2018-05-26 02:46:211929InstallGate::Action ExtensionService::ShouldDelayExtensionInstall(
1930 const Extension* extension,
xiyuanf6a4c6a62016-04-19 18:14:541931 bool install_immediately,
Devlin Cronineea1b7a2018-05-26 02:46:211932 ExtensionPrefs::DelayReason* reason) const {
xiyuanf6a4c6a62016-04-19 18:14:541933 for (const auto& entry : install_delayer_registry_) {
Devlin Cronineea1b7a2018-05-26 02:46:211934 InstallGate* const delayer = entry.second;
1935 InstallGate::Action action =
xiyuanf6a4c6a62016-04-19 18:14:541936 delayer->ShouldDelay(extension, install_immediately);
Devlin Cronineea1b7a2018-05-26 02:46:211937 if (action != InstallGate::INSTALL) {
xiyuanf6a4c6a62016-04-19 18:14:541938 *reason = entry.first;
1939 return action;
1940 }
[email protected]e7aa7b7e2012-11-27 04:51:221941 }
[email protected]fdd679b2012-11-15 20:49:391942
Devlin Cronineea1b7a2018-05-26 02:46:211943 return InstallGate::INSTALL;
[email protected]9f4e4f082013-06-21 07:11:191944}
1945
1946void ExtensionService::MaybeFinishDelayedInstallations() {
1947 std::vector<std::string> to_be_installed;
achuith2f5578b2016-02-26 21:57:131948 for (const auto& extension : delayed_installs_) {
1949 to_be_installed.push_back(extension->id());
[email protected]399583b2012-12-11 09:33:421950 }
achuith2f5578b2016-02-26 21:57:131951 for (const auto& extension_id : to_be_installed) {
Toni Barzic667db0d32018-01-09 18:00:191952 FinishDelayedInstallationIfReady(extension_id,
1953 false /*install_immediately*/);
[email protected]399583b2012-12-11 09:33:421954 }
[email protected]399583b2012-12-11 09:33:421955}
1956
[email protected]fdd679b2012-11-15 20:49:391957void ExtensionService::OnBlacklistUpdated() {
[email protected]2d19eb6e2014-01-27 17:30:001958 blacklist_->GetBlacklistedIDs(
[email protected]f47f7172014-03-19 19:27:101959 registry_->GenerateInstalledExtensionsSet()->GetIDs(),
[email protected]3f2a2fa2013-09-24 02:55:251960 base::Bind(&ExtensionService::ManageBlacklist, AsWeakPtr()));
[email protected]695b5712012-12-06 23:55:281961}
1962
weidongg04695232017-06-09 00:01:051963void ExtensionService::OnUpgradeRecommended() {
1964 // Notify observers that chrome update is available.
1965 for (auto& observer : update_observers_)
1966 observer.OnChromeUpdateAvailable();
1967}
1968
Devlin Cronineea1b7a2018-05-26 02:46:211969void ExtensionService::PreAddExtension(const Extension* extension,
1970 const Extension* old_extension) {
Michael Giuffrida573992d2018-02-08 00:48:441971 // Check if the extension's privileges have changed and mark the
1972 // extension disabled if necessary.
1973 CheckPermissionsIncrease(extension, !!old_extension);
1974}
1975
Michael Giuffrida6397c592017-10-09 20:46:531976bool ExtensionService::CanEnableExtension(const Extension* extension) {
1977 return !system_->management_policy()->MustRemainDisabled(extension, nullptr,
1978 nullptr);
1979}
1980
1981bool ExtensionService::CanDisableExtension(const Extension* extension) {
1982 // Some extensions cannot be disabled by users:
1983 // - |extension| can be null if sync disables an extension that is not
1984 // installed yet; allow disablement in this case.
1985 if (!extension)
1986 return true;
1987
1988 // - Shared modules are just resources used by other extensions, and are not
1989 // user-controlled.
1990 if (SharedModuleInfo::IsSharedModule(extension))
1991 return false;
1992
1993 // - EXTERNAL_COMPONENT extensions are not generally modifiable by users, but
1994 // can be uninstalled by the browser if the user sets extension-specific
1995 // preferences.
1996 if (extension->location() == Manifest::EXTERNAL_COMPONENT)
1997 return true;
1998
1999 return system_->management_policy()->UserMayModifySettings(extension,
2000 nullptr);
2001}
2002
2003bool ExtensionService::ShouldBlockExtension(const Extension* extension) {
2004 if (!block_extensions_)
2005 return false;
2006
2007 // Blocked extensions aren't marked as such in prefs, thus if
2008 // |block_extensions_| is true then CanBlockExtension() must be called with an
2009 // Extension object. If |extension| is not loaded, assume it should be
2010 // blocked.
2011 return !extension || CanBlockExtension(extension);
2012}
2013
[email protected]2d19eb6e2014-01-27 17:30:002014void ExtensionService::ManageBlacklist(
Devlin Cronineea1b7a2018-05-26 02:46:212015 const Blacklist::BlacklistStateMap& state_map) {
[email protected]54ee8192014-03-29 17:37:242016 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]695b5712012-12-06 23:55:282017
mlerman6a37b6a42014-11-26 22:10:532018 std::set<std::string> blacklisted;
[email protected]2d19eb6e2014-01-27 17:30:002019 ExtensionIdSet greylist;
2020 ExtensionIdSet unchanged;
achuith2f5578b2016-02-26 21:57:132021 for (const auto& it : state_map) {
2022 switch (it.second) {
Devlin Cronineea1b7a2018-05-26 02:46:212023 case NOT_BLACKLISTED:
[email protected]2d19eb6e2014-01-27 17:30:002024 break;
[email protected]695b5712012-12-06 23:55:282025
Devlin Cronineea1b7a2018-05-26 02:46:212026 case BLACKLISTED_MALWARE:
achuith2f5578b2016-02-26 21:57:132027 blacklisted.insert(it.first);
[email protected]2d19eb6e2014-01-27 17:30:002028 break;
2029
Devlin Cronineea1b7a2018-05-26 02:46:212030 case BLACKLISTED_SECURITY_VULNERABILITY:
2031 case BLACKLISTED_CWS_POLICY_VIOLATION:
2032 case BLACKLISTED_POTENTIALLY_UNWANTED:
achuith2f5578b2016-02-26 21:57:132033 greylist.insert(it.first);
[email protected]2d19eb6e2014-01-27 17:30:002034 break;
2035
Devlin Cronineea1b7a2018-05-26 02:46:212036 case BLACKLISTED_UNKNOWN:
achuith2f5578b2016-02-26 21:57:132037 unchanged.insert(it.first);
[email protected]2d19eb6e2014-01-27 17:30:002038 break;
2039 }
2040 }
2041
mlerman6a37b6a42014-11-26 22:10:532042 UpdateBlacklistedExtensions(blacklisted, unchanged);
[email protected]2d19eb6e2014-01-27 17:30:002043 UpdateGreylistedExtensions(greylist, unchanged, state_map);
2044
[email protected]373daf972014-04-10 01:50:442045 error_controller_->ShowErrorIfNeeded();
[email protected]2d19eb6e2014-01-27 17:30:002046}
2047
2048namespace {
2049void Partition(const ExtensionIdSet& before,
2050 const ExtensionIdSet& after,
2051 const ExtensionIdSet& unchanged,
2052 ExtensionIdSet* no_longer,
2053 ExtensionIdSet* not_yet) {
2054 *not_yet = base::STLSetDifference<ExtensionIdSet>(after, before);
2055 *no_longer = base::STLSetDifference<ExtensionIdSet>(before, after);
2056 *no_longer = base::STLSetDifference<ExtensionIdSet>(*no_longer, unchanged);
2057}
2058} // namespace
2059
mlerman6a37b6a42014-11-26 22:10:532060void ExtensionService::UpdateBlacklistedExtensions(
2061 const ExtensionIdSet& blacklisted,
[email protected]2d19eb6e2014-01-27 17:30:002062 const ExtensionIdSet& unchanged) {
2063 ExtensionIdSet not_yet_blocked, no_longer_blocked;
mlerman6a37b6a42014-11-26 22:10:532064 Partition(registry_->blacklisted_extensions().GetIDs(), blacklisted,
2065 unchanged, &no_longer_blocked, &not_yet_blocked);
[email protected]2d19eb6e2014-01-27 17:30:002066
jdoerrie13cd648c82018-10-02 21:21:022067 for (auto it = no_longer_blocked.begin(); it != no_longer_blocked.end();
2068 ++it) {
[email protected]695b5712012-12-06 23:55:282069 scoped_refptr<const Extension> extension =
[email protected]bb1bc9b32013-12-21 03:09:142070 registry_->blacklisted_extensions().GetByID(*it);
[email protected]3f2a2fa2013-09-24 02:55:252071 if (!extension.get()) {
mlerman6a37b6a42014-11-26 22:10:532072 NOTREACHED() << "Extension " << *it << " no longer blacklisted, "
2073 << "but it was never blacklisted.";
[email protected]695b5712012-12-06 23:55:282074 continue;
[email protected]3f2a2fa2013-09-24 02:55:252075 }
[email protected]bb1bc9b32013-12-21 03:09:142076 registry_->RemoveBlacklisted(*it);
atuchin6dc7c442016-07-20 07:04:342077 extension_prefs_->SetExtensionBlacklistState(extension->id(),
Devlin Cronineea1b7a2018-05-26 02:46:212078 NOT_BLACKLISTED);
[email protected]dc24976f2013-06-02 21:15:092079 AddExtension(extension.get());
[email protected]ac875372013-02-28 04:36:092080 UMA_HISTOGRAM_ENUMERATION("ExtensionBlacklist.UnblacklistInstalled",
[email protected]dc24976f2013-06-02 21:15:092081 extension->location(),
2082 Manifest::NUM_LOCATIONS);
[email protected]695b5712012-12-06 23:55:282083 }
2084
jdoerrie13cd648c82018-10-02 21:21:022085 for (auto it = not_yet_blocked.begin(); it != not_yet_blocked.end(); ++it) {
[email protected]695b5712012-12-06 23:55:282086 scoped_refptr<const Extension> extension = GetInstalledExtension(*it);
[email protected]3f2a2fa2013-09-24 02:55:252087 if (!extension.get()) {
2088 NOTREACHED() << "Extension " << *it << " needs to be "
2089 << "blacklisted, but it's not installed.";
[email protected]695b5712012-12-06 23:55:282090 continue;
[email protected]3f2a2fa2013-09-24 02:55:252091 }
[email protected]bb1bc9b32013-12-21 03:09:142092 registry_->AddBlacklisted(extension);
Devlin Cronineea1b7a2018-05-26 02:46:212093 extension_prefs_->SetExtensionBlacklistState(extension->id(),
2094 BLACKLISTED_MALWARE);
limasdf0deef2042017-05-03 19:17:172095 UnloadExtension(*it, UnloadedExtensionReason::BLACKLIST);
[email protected]ac875372013-02-28 04:36:092096 UMA_HISTOGRAM_ENUMERATION("ExtensionBlacklist.BlacklistInstalled",
2097 extension->location(), Manifest::NUM_LOCATIONS);
[email protected]695b5712012-12-06 23:55:282098 }
[email protected]2d19eb6e2014-01-27 17:30:002099}
[email protected]695b5712012-12-06 23:55:282100
[email protected]2d19eb6e2014-01-27 17:30:002101// TODO(oleg): UMA logging
2102void ExtensionService::UpdateGreylistedExtensions(
2103 const ExtensionIdSet& greylist,
2104 const ExtensionIdSet& unchanged,
Devlin Cronineea1b7a2018-05-26 02:46:212105 const Blacklist::BlacklistStateMap& state_map) {
[email protected]2d19eb6e2014-01-27 17:30:002106 ExtensionIdSet not_yet_greylisted, no_longer_greylisted;
2107 Partition(greylist_.GetIDs(),
2108 greylist, unchanged,
2109 &no_longer_greylisted, &not_yet_greylisted);
2110
jdoerrie13cd648c82018-10-02 21:21:022111 for (auto it = no_longer_greylisted.begin(); it != no_longer_greylisted.end();
2112 ++it) {
[email protected]2d19eb6e2014-01-27 17:30:002113 scoped_refptr<const Extension> extension = greylist_.GetByID(*it);
2114 if (!extension.get()) {
2115 NOTREACHED() << "Extension " << *it << " no longer greylisted, "
2116 << "but it was not marked as greylisted.";
2117 continue;
2118 }
2119
2120 greylist_.Remove(*it);
2121 extension_prefs_->SetExtensionBlacklistState(extension->id(),
Devlin Cronineea1b7a2018-05-26 02:46:212122 NOT_BLACKLISTED);
[email protected]2d19eb6e2014-01-27 17:30:002123 if (extension_prefs_->GetDisableReasons(extension->id()) &
Devlin Cronineea1b7a2018-05-26 02:46:212124 disable_reason::DISABLE_GREYLIST)
[email protected]2d19eb6e2014-01-27 17:30:002125 EnableExtension(*it);
2126 }
2127
jdoerrie13cd648c82018-10-02 21:21:022128 for (auto it = not_yet_greylisted.begin(); it != not_yet_greylisted.end();
2129 ++it) {
[email protected]2d19eb6e2014-01-27 17:30:002130 scoped_refptr<const Extension> extension = GetInstalledExtension(*it);
2131 if (!extension.get()) {
2132 NOTREACHED() << "Extension " << *it << " needs to be "
2133 << "disabled, but it's not installed.";
2134 continue;
2135 }
2136 greylist_.Insert(extension);
2137 extension_prefs_->SetExtensionBlacklistState(extension->id(),
2138 state_map.find(*it)->second);
2139 if (registry_->enabled_extensions().Contains(extension->id()))
Devlin Cronineea1b7a2018-05-26 02:46:212140 DisableExtension(*it, disable_reason::DISABLE_GREYLIST);
[email protected]2d19eb6e2014-01-27 17:30:002141 }
[email protected]fdd679b2012-11-15 20:49:392142}
[email protected]75bdcb872013-03-13 00:41:452143
Devlin Cronineea1b7a2018-05-26 02:46:212144void ExtensionService::AddUpdateObserver(UpdateObserver* observer) {
[email protected]75bdcb872013-03-13 00:41:452145 update_observers_.AddObserver(observer);
2146}
2147
Devlin Cronineea1b7a2018-05-26 02:46:212148void ExtensionService::RemoveUpdateObserver(UpdateObserver* observer) {
[email protected]75bdcb872013-03-13 00:41:452149 update_observers_.RemoveObserver(observer);
2150}
[email protected]bb1bc9b32013-12-21 03:09:142151
Devlin Cronineea1b7a2018-05-26 02:46:212152void ExtensionService::RegisterInstallGate(ExtensionPrefs::DelayReason reason,
2153 InstallGate* install_delayer) {
xiyuanf6a4c6a62016-04-19 18:14:542154 DCHECK(install_delayer_registry_.end() ==
2155 install_delayer_registry_.find(reason));
2156 install_delayer_registry_[reason] = install_delayer;
2157}
2158
Devlin Cronineea1b7a2018-05-26 02:46:212159void ExtensionService::UnregisterInstallGate(InstallGate* install_delayer) {
xiyuanf6a4c6a62016-04-19 18:14:542160 for (auto it = install_delayer_registry_.begin();
2161 it != install_delayer_registry_.end(); ++it) {
2162 if (it->second == install_delayer) {
2163 install_delayer_registry_.erase(it);
2164 return;
2165 }
2166 }
2167}
2168
[email protected]bb1bc9b32013-12-21 03:09:142169// Used only by test code.
2170void ExtensionService::UnloadAllExtensionsInternal() {
2171 profile_->GetExtensionSpecialStoragePolicy()->RevokeRightsForAllExtensions();
2172
2173 registry_->ClearAll();
[email protected]45f5b7d2014-01-22 23:47:132174 system_->runtime_data()->ClearAll();
[email protected]bb1bc9b32013-12-21 03:09:142175
2176 // TODO(erikkay) should there be a notification for this? We can't use
Devlin Cronineea1b7a2018-05-26 02:46:212177 // EXTENSION_UNLOADED since that implies that the extension has
Minh X. Nguyen45479012017-08-18 21:35:362178 // been disabled or uninstalled.
[email protected]bb1bc9b32013-12-21 03:09:142179}
[email protected]ebe07772014-05-22 04:16:062180
2181void ExtensionService::OnProfileDestructionStarted() {
2182 ExtensionIdSet ids_to_unload = registry_->enabled_extensions().GetIDs();
jdoerrie13cd648c82018-10-02 21:21:022183 for (auto it = ids_to_unload.begin(); it != ids_to_unload.end(); ++it) {
limasdf0deef2042017-05-03 19:17:172184 UnloadExtension(*it, UnloadedExtensionReason::PROFILE_SHUTDOWN);
[email protected]ebe07772014-05-22 04:16:062185 }
2186}
rdevlin.croninf2e1cb012017-05-27 01:27:592187
2188void ExtensionService::OnInstalledExtensionsLoaded() {
2189 if (updater_)
2190 updater_->Start();
2191
2192 // Enable any Shared Modules that incorrectly got disabled previously.
2193 // This is temporary code to fix incorrect behavior from previous versions of
2194 // Chrome and can be removed after several releases (perhaps M60).
Devlin Cronineea1b7a2018-05-26 02:46:212195 ExtensionList to_enable;
rdevlin.croninf2e1cb012017-05-27 01:27:592196 for (const auto& extension : registry_->disabled_extensions()) {
2197 if (SharedModuleInfo::IsSharedModule(extension.get()))
2198 to_enable.push_back(extension);
2199 }
2200 for (const auto& extension : to_enable) {
2201 EnableExtension(extension->id());
2202 }
2203
2204 OnBlacklistUpdated();
2205}
lazyboy75b9def2017-06-06 18:56:592206
Takumi Fujimoto43c8c00f2017-07-26 22:48:562207void ExtensionService::UninstallMigratedExtensions() {
2208 std::unique_ptr<ExtensionSet> installed_extensions =
2209 registry_->GenerateInstalledExtensionsSet();
2210
2211 for (const std::string& extension_id : kMigratedExtensionIds) {
2212 if (installed_extensions->Contains(extension_id)) {
Devlin Cronineea1b7a2018-05-26 02:46:212213 UninstallExtension(extension_id, UNINSTALL_REASON_MIGRATED, nullptr);
Takumi Fujimoto43c8c00f2017-07-26 22:48:562214 }
2215 }
2216}
Devlin Cronineea1b7a2018-05-26 02:46:212217
2218} // namespace extensions