blob: e99ce6834afb43fa788154ff6bbd9300d757d448 [file] [log] [blame]
[email protected]098fa7a2013-03-08 22:11:171// Copyright (c) 2013 The Chromium Authors. All rights reserved.
[email protected]6014d672008-12-05 00:38:252// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]eaa7dd182010-12-14 11:09:005#include "chrome/browser/extensions/extension_service.h"
[email protected]6014d672008-12-05 00:38:256
avia2f4804a2015-12-24 23:11:137#include <stddef.h>
8
[email protected]695b5712012-12-06 23:55:289#include <iterator>
asargente4de9f92016-09-15 01:40:0610#include <memory>
[email protected]97d2f1d2011-01-15 00:41:0811#include <set>
asargente4de9f92016-09-15 01:40:0612#include <utility>
[email protected]654512b2010-09-01 02:09:4213
Sebastien Marchandf1349f52019-01-25 03:16:4114#include "base/bind.h"
[email protected]62433d32011-10-12 22:33:1215#include "base/command_line.h"
rdevlin.cronin08ada0f2017-03-09 23:29:5216#include "base/debug/alias.h"
17#include "base/debug/dump_without_crashing.h"
skyostilf221b7de2015-06-11 20:36:3218#include "base/location.h"
Ilya Sherman982457e62017-12-13 02:19:3619#include "base/metrics/histogram_functions.h"
rkaplowfca0f4dc52015-03-14 21:40:5720#include "base/metrics/histogram_macros.h"
Christopher Lamebb90202019-04-04 03:42:3621#include "base/one_shot_event.h"
skyostilf221b7de2015-06-11 20:36:3222#include "base/single_thread_task_runner.h"
tripta.g0ac673a2017-07-07 05:45:0923#include "base/stl_util.h"
[email protected]3ea1b182013-02-08 22:38:4124#include "base/strings/string_number_conversions.h"
catmullings98cd1942016-08-30 22:31:5925#include "base/strings/string_tokenizer.h"
[email protected]00e7bef2013-06-10 20:35:1726#include "base/strings/stringprintf.h"
[email protected]112158af2013-06-07 23:46:1827#include "base/strings/utf_string_conversions.h"
Alexander Nohe2c5402882019-04-11 21:56:3328#include "base/syslog_logging.h"
Gabriel Charette44db1422018-08-06 11:19:3329#include "base/task/post_task.h"
[email protected]34b99632011-01-01 01:01:0630#include "base/threading/thread_restrictions.h"
gabb15e19072016-05-11 20:45:4131#include "base/threading/thread_task_runner_handle.h"
[email protected]41a17c52013-06-28 00:27:5332#include "base/time/time.h"
rkaplowe65c2ff2015-02-14 16:29:5433#include "base/trace_event/trace_event.h"
avia2f4804a2015-12-24 23:11:1334#include "build/build_config.h"
Evan Staded89e11c2019-09-05 18:08:5635#include "chrome/browser/browser_process.h"
[email protected]9ea0cd32013-07-12 01:50:3636#include "chrome/browser/chrome_notification_types.h"
sunil.ratnu21b896c2014-11-24 10:09:2437#include "chrome/browser/extensions/api/content_settings/content_settings_custom_extension_provider.h"
mukai87a8d402014-09-15 20:15:0938#include "chrome/browser/extensions/api/content_settings/content_settings_service.h"
ryanackley48bedbd2015-01-27 23:12:1439#include "chrome/browser/extensions/app_data_migrator.h"
[email protected]d8c8f25f2011-11-02 18:18:0140#include "chrome/browser/extensions/component_loader.h"
[email protected]13e062e2014-08-09 10:21:5541#include "chrome/browser/extensions/crx_installer.h"
[email protected]d9ede582012-08-14 19:21:3842#include "chrome/browser/extensions/data_deleter.h"
rdevlin.cronin2813c1b2014-08-26 23:51:0843#include "chrome/browser/extensions/extension_action_storage_manager.h"
[email protected]5a145e82014-05-29 22:19:0744#include "chrome/browser/extensions/extension_assets_manager.h"
[email protected]62f051c2012-03-29 17:04:4445#include "chrome/browser/extensions/extension_disabled_ui.h"
[email protected]373daf972014-04-10 01:50:4446#include "chrome/browser/extensions/extension_error_controller.h"
[email protected]19eb80152011-02-26 00:28:4347#include "chrome/browser/extensions/extension_special_storage_policy.h"
[email protected]f8aefb132013-10-30 09:29:5248#include "chrome/browser/extensions/extension_sync_service.h"
[email protected]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"
Devlin Croninc9c4efe2020-01-07 21:04:0592#include "extensions/browser/unloaded_extension_reason.h"
[email protected]a9aa62b312013-11-29 05:35:0693#include "extensions/browser/update_observer.h"
rockotffa65b12014-10-14 17:19:0694#include "extensions/browser/updater/extension_cache.h"
rockot05f40a922014-10-16 19:40:2595#include "extensions/browser/updater/extension_downloader.h"
Oleg Davydov6541a64f2019-04-17 13:17:3396#include "extensions/browser/updater/manifest_fetch_data.h"
[email protected]fb820c02014-03-13 15:07:0897#include "extensions/common/extension_messages.h"
rockot90659852014-09-18 19:31:5298#include "extensions/common/extension_urls.h"
[email protected]5ef835a2013-11-08 20:42:5799#include "extensions/common/feature_switch.h"
rdevlin.cronin41227532016-07-13 21:24:34100#include "extensions/common/features/feature_channel.h"
[email protected]85df9d12014-04-15 17:02:14101#include "extensions/common/file_util.h"
[email protected]0c3c9732013-09-16 08:53:41102#include "extensions/common/manifest_constants.h"
Michael Giuffrida6397c592017-10-09 20:46:53103#include "extensions/common/manifest_handlers/shared_module_info.h"
rockotd5546142014-10-15 00:29:08104#include "extensions/common/manifest_url_handlers.h"
treib2e0517f92015-05-07 23:15:36105#include "extensions/common/permissions/api_permission.h"
[email protected]c41003472013-10-19 15:37:25106#include "extensions/common/permissions/permission_message_provider.h"
[email protected]e4452d32013-11-15 23:07:41107#include "extensions/common/permissions/permissions_data.h"
Michael Giuffridab158f3f2017-07-17 19:53:44108#include "extensions/common/switches.h"
[email protected]79a60642012-10-20 21:03:18109
[email protected]eed367e2011-04-12 03:43:31110#if defined(OS_CHROMEOS)
[email protected]88e8ec9152013-01-17 04:05:18111#include "chrome/browser/chromeos/extensions/install_limiter.h"
achuithd3da4f02017-03-23 20:05:29112#include "chrome/browser/chromeos/profiles/profile_helper.h"
DongJun Kimfebb3c22019-10-21 02:08:06113#include "storage/browser/file_system/file_system_backend.h"
114#include "storage/browser/file_system/file_system_context.h"
[email protected]eed367e2011-04-12 03:43:31115#endif
116
[email protected]55eb70e762012-02-20 17:38:39117using content::BrowserContext;
[email protected]631bb742011-11-02 11:29:39118using content::BrowserThread;
Devlin Cronineea1b7a2018-05-26 02:46:21119
120namespace extensions {
[email protected]5ef47ec2010-01-28 05:58:05121
Michael Giuffrida573992d2018-02-08 00:48:44122using LoadErrorBehavior = ExtensionRegistrar::LoadErrorBehavior;
123
[email protected]b6ab96d2009-08-20 18:58:19124namespace {
125
Lei Zhang15339152018-08-09 22:20:44126// Wait this long after an extensions becomes idle before updating it.
127constexpr base::TimeDelta kUpdateIdleDelay = base::TimeDelta::FromSeconds(5);
[email protected]0db124b02012-11-07 04:55:05128
Takumi Fujimoto43c8c00f2017-07-26 22:48:56129// IDs of extensions that have been replaced by component extensions and need to
130// be uninstalled.
Lei Zhang15339152018-08-09 22:20:44131const char* const kMigratedExtensionIds[] = {
Takumi Fujimoto43c8c00f2017-07-26 22:48:56132 "boadgeojelhgndaghljhdicfkmllpafd", // Google Cast
133 "dliochdbjfkdbacpmhlcpmleaejidimm" // Google Cast (Beta)
134};
135
[email protected]c6d474f82009-12-16 21:11:06136} // namespace
[email protected]b6ab96d2009-08-20 18:58:19137
[email protected]eaa7dd182010-12-14 11:09:00138// ExtensionService.
[email protected]6014d672008-12-05 00:38:25139
[email protected]8e4560b62011-01-14 10:09:14140void ExtensionService::CheckExternalUninstall(const std::string& id) {
[email protected]a29a517a2011-01-21 21:11:12141 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]a8af9fdb2010-10-28 21:52:20142
[email protected]7a4c6852010-09-16 03:44:22143 // Check if the providers know about this extension.
achuith2f5578b2016-02-26 21:57:13144 for (const auto& provider : external_extension_providers_) {
145 DCHECK(provider->IsReady());
146 if (provider->HasExtension(id))
[email protected]0a60a2e2010-10-25 16:15:21147 return; // Yup, known extension, don't uninstall.
[email protected]7a4c6852010-09-16 03:44:22148 }
149
Giovanni Ortuño Urquidi218522862018-08-28 12:48:04150 // Historically, the code under //chrome/browser/extensions has
151 // unsurprisingly managed all extensions. Later, Progressive Web Apps (PWAs)
152 // were implemented on top of extensions, more out of convenience than out of
153 // principle. As of mid 2018, there is work underway to separate PWAs's
154 // implementation details from the //c/b/e code. During the transition
155 // period, PWA-extensions are no longer managed solely by //c/b/e code. We
156 // add a special case here so that //c/b/e code doesn't uninstall
157 // PWA-extensions that it doesn't otherwise know about.
158 //
159 // Long term, PWAs will be completely separate from extensions, and we can
160 // remove this cross-link.
Alan Cutter6e963f02019-05-06 00:33:22161 if (web_app::ExternallyInstalledWebAppPrefs::HasAppId(profile_->GetPrefs(),
162 id)) {
Giovanni Ortuño Urquidi218522862018-08-28 12:48:04163 return;
164 }
165
[email protected]0f48fca2011-05-19 18:46:35166 // We get the list of external extensions to check from preferences.
167 // It is possible that an extension has preferences but is not loaded.
168 // For example, an extension that requires experimental permissions
169 // will not be loaded if the experimental command line flag is not used.
170 // In this case, do not uninstall.
David Bertoni9f897c92019-09-20 17:46:35171 if (!registry_->GetInstalledExtension(id)) {
[email protected]0f48fca2011-05-19 18:46:35172 // We can't call UninstallExtension with an unloaded/invalid
173 // extension ID.
174 LOG(WARNING) << "Attempted uninstallation of unloaded/invalid extension "
175 << "with id: " << id;
176 return;
177 }
Devlin Cronineea1b7a2018-05-26 02:46:21178 UninstallExtension(id, UNINSTALL_REASON_ORPHANED_EXTERNAL_EXTENSION, nullptr);
[email protected]7a4c6852010-09-16 03:44:22179}
180
[email protected]8e4560b62011-01-14 10:09:14181void ExtensionService::ClearProvidersForTesting() {
[email protected]7a4c6852010-09-16 03:44:22182 external_extension_providers_.clear();
183}
184
[email protected]8e4560b62011-01-14 10:09:14185void ExtensionService::AddProviderForTesting(
lazyboyf33109d2016-08-31 00:37:08186 std::unique_ptr<ExternalProviderInterface> test_provider) {
[email protected]a29a517a2011-01-21 21:11:12187 CHECK(test_provider);
lazyboyf33109d2016-08-31 00:37:08188 external_extension_providers_.push_back(std::move(test_provider));
[email protected]7a4c6852010-09-16 03:44:22189}
190
[email protected]8f959f522014-08-06 06:26:28191void ExtensionService::BlacklistExtensionForTest(
192 const std::string& extension_id) {
mlerman6a37b6a42014-11-26 22:10:53193 ExtensionIdSet blacklisted;
Ioana Pandelef1e0ecaf2020-01-31 09:40:38194 ExtensionIdSet unchanged;
mlerman6a37b6a42014-11-26 22:10:53195 blacklisted.insert(extension_id);
196 UpdateBlacklistedExtensions(blacklisted, unchanged);
[email protected]8f959f522014-08-06 06:26:28197}
198
[email protected]9060d8b02012-01-13 02:14:30199bool ExtensionService::OnExternalExtensionUpdateUrlFound(
lazyboye8634172016-01-28 00:10:48200 const ExternalInstallInfoUpdateUrl& info,
201 bool is_initial_load) {
Istiaque Ahmedf6e72622017-09-08 23:14:17202 DCHECK_CURRENTLY_ON(BrowserThread::UI);
lazyboye8634172016-01-28 00:10:48203 CHECK(crx_file::id_util::IdIsValid(info.extension_id));
[email protected]a8af9fdb2010-10-28 21:52:20204
lazyboye8634172016-01-28 00:10:48205 if (Manifest::IsExternalLocation(info.download_location)) {
[email protected]044e86992014-01-24 22:59:11206 // All extensions that are not user specific can be cached.
Devlin Cronineea1b7a2018-05-26 02:46:21207 ExtensionsBrowserClient::Get()->GetExtensionCache()->AllowCaching(
208 info.extension_id);
[email protected]044e86992014-01-24 22:59:11209 }
210
Oleg Davydov66246bd92019-09-26 16:31:51211 InstallationReporter* installation_reporter =
212 InstallationReporter::Get(profile_);
213
David Bertoni58c113a2019-08-02 19:53:26214 const Extension* extension = registry_->GetExtensionById(
David Bertonia0b34722019-09-30 20:51:26215 info.extension_id, ExtensionRegistry::EVERYTHING);
[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 Davydov66246bd92019-09-26 16:31:51225 installation_reporter->ReportFailure(
226 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 }
Swapnil314cb6d2020-01-23 10:49:15230 // If the installation is requested from a higher priority source, update
231 // its install location.
232 if (current !=
233 Manifest::GetHigherPriorityLocation(current, info.download_location)) {
234 UnloadExtension(info.extension_id, UnloadedExtensionReason::UPDATE);
235
236 // Fetch the installation info from the prefs, and reload the extension
237 // with a modified install location.
238 std::unique_ptr<ExtensionInfo> installed_extension(
239 extension_prefs_->GetInstalledExtensionInfo(info.extension_id));
240 installed_extension->extension_location = info.download_location;
241
242 // Load the extension with the new install location
243 InstalledLoader(this).Load(*installed_extension, false);
244 // Update the install location in the prefs.
245 extension_prefs_->SetInstallLocation(info.extension_id,
246 info.download_location);
247
248 // If the extension was disabled by user or was disabled due to
249 // a permissions increase, and it must remain enabled, remove those
250 // disable reasons.
251 if (registry_->disabled_extensions().GetByID(info.extension_id) &&
252 system_->management_policy()->MustRemainEnabled(
253 registry_->GetExtensionById(info.extension_id,
254 ExtensionRegistry::EVERYTHING),
255 nullptr)) {
256 int disable_reasons =
257 extension_prefs_->GetDisableReasons(extension->id());
258 disable_reasons &= (~(disable_reason::DISABLE_USER_ACTION |
259 disable_reason::DISABLE_PERMISSIONS_INCREASE));
260 extension_prefs_->ReplaceDisableReasons(info.extension_id,
261 disable_reasons);
262
263 // Only re-enable the extension if there are no other disable reasons.
264 if (extension_prefs_->GetDisableReasons(info.extension_id) ==
265 disable_reason::DISABLE_NONE) {
266 EnableExtension(info.extension_id);
267 }
268 }
269 return false;
270 }
[email protected]8a87a5332011-08-11 17:54:59271 // Otherwise, overwrite the current installation.
[email protected]7a4c6852010-09-16 03:44:22272 }
[email protected]9060d8b02012-01-13 02:14:30273
lazyboye8634172016-01-28 00:10:48274 // Add |info.extension_id| to the set of pending extensions. If it can not
275 // be added, then there is already a pending record from a higher-priority
276 // install source. In this case, signal that this extension will not be
[email protected]9060d8b02012-01-13 02:14:30277 // installed by returning false.
Oleg Davydov66246bd92019-09-26 16:31:51278 installation_reporter->ReportInstallationStage(
279 info.extension_id, InstallationReporter::Stage::PENDING);
[email protected]9060d8b02012-01-13 02:14:30280 if (!pending_extension_manager()->AddFromExternalUpdateUrl(
Devlin Cronind4c2a8f32017-09-29 17:08:30281 info.extension_id, info.install_parameter, info.update_url,
lazyboye8634172016-01-28 00:10:48282 info.download_location, info.creation_flags,
283 info.mark_acknowledged)) {
Oleg Davydov66246bd92019-09-26 16:31:51284 installation_reporter->ReportFailure(
285 info.extension_id,
Oleg Davydovc00866812019-04-04 10:47:27286 InstallationReporter::FailureReason::PENDING_ADD_FAILED);
[email protected]9060d8b02012-01-13 02:14:30287 return false;
[email protected]31bb5ee62012-09-12 22:58:40288 }
[email protected]9060d8b02012-01-13 02:14:30289
lazyboye8634172016-01-28 00:10:48290 if (is_initial_load)
291 update_once_all_providers_are_ready_ = true;
[email protected]9060d8b02012-01-13 02:14:30292 return true;
[email protected]7a4c6852010-09-16 03:44:22293}
294
lazyboye8634172016-01-28 00:10:48295void ExtensionService::OnExternalProviderUpdateComplete(
296 const ExternalProviderInterface* provider,
Devlin Cronin19f70b6a2017-10-01 04:14:05297 const std::vector<ExternalInstallInfoUpdateUrl>& update_url_extensions,
298 const std::vector<ExternalInstallInfoFile>& file_extensions,
lazyboye8634172016-01-28 00:10:48299 const std::set<std::string>& removed_extensions) {
300 // Update pending_extension_manager() with the new extensions first.
lazyboy4aeef202016-09-07 21:28:59301 for (const auto& extension : update_url_extensions)
Devlin Cronin19f70b6a2017-10-01 04:14:05302 OnExternalExtensionUpdateUrlFound(extension, false);
lazyboy4aeef202016-09-07 21:28:59303 for (const auto& extension : file_extensions)
Devlin Cronin19f70b6a2017-10-01 04:14:05304 OnExternalExtensionFileFound(extension);
lazyboye8634172016-01-28 00:10:48305
306#if DCHECK_IS_ON()
307 for (const std::string& id : removed_extensions) {
lazyboy4aeef202016-09-07 21:28:59308 for (const auto& extension : update_url_extensions)
Devlin Cronin19f70b6a2017-10-01 04:14:05309 DCHECK_NE(id, extension.extension_id);
lazyboy4aeef202016-09-07 21:28:59310 for (const auto& extension : file_extensions)
Devlin Cronin19f70b6a2017-10-01 04:14:05311 DCHECK_NE(id, extension.extension_id);
lazyboye8634172016-01-28 00:10:48312 }
313#endif
314
315 // Then uninstall before running |updater_|.
316 for (const std::string& id : removed_extensions)
317 CheckExternalUninstall(id);
318
319 if (!update_url_extensions.empty() && updater_) {
320 // Empty params will cause pending extensions to be updated.
Devlin Cronineea1b7a2018-05-26 02:46:21321 updater_->CheckNow(ExtensionUpdater::CheckParams());
lazyboye8634172016-01-28 00:10:48322 }
323
324 error_controller_->ShowErrorIfNeeded();
325 external_install_manager_->UpdateExternalExtensionAlert();
326}
327
[email protected]eaa7dd182010-12-14 11:09:00328ExtensionService::ExtensionService(Profile* profile,
avi3ef9ec9e2014-12-22 22:50:17329 const base::CommandLine* command_line,
[email protected]650b2d52013-02-10 03:41:45330 const base::FilePath& install_directory,
Devlin Cronineea1b7a2018-05-26 02:46:21331 ExtensionPrefs* extension_prefs,
332 Blacklist* blacklist,
[email protected]0436b102011-04-15 18:30:03333 bool autoupdate_enabled,
[email protected]4a10006a2013-05-17 23:18:35334 bool extensions_enabled,
Christopher Lamebb90202019-04-04 03:42:36335 base::OneShotEvent* ready)
Devlin Cronineea1b7a2018-05-26 02:46:21336 : Blacklist::Observer(blacklist),
catmullings98cd1942016-08-30 22:31:59337 command_line_(command_line),
[email protected]fdd679b2012-11-15 20:49:39338 profile_(profile),
Devlin Cronineea1b7a2018-05-26 02:46:21339 system_(ExtensionSystem::Get(profile)),
[email protected]73c47932010-12-06 18:13:43340 extension_prefs_(extension_prefs),
[email protected]695b5712012-12-06 23:55:28341 blacklist_(blacklist),
Devlin Cronineea1b7a2018-05-26 02:46:21342 registry_(ExtensionRegistry::Get(profile)),
[email protected]6c9bedf2014-05-21 03:55:51343 pending_extension_manager_(profile),
[email protected]a9b00ac2009-06-25 21:03:23344 install_directory_(install_directory),
[email protected]0436b102011-04-15 18:30:03345 extensions_enabled_(extensions_enabled),
[email protected]4a10006a2013-05-17 23:18:35346 ready_(ready),
Devlin Cronineea1b7a2018-05-26 02:46:21347 shared_module_service_(new SharedModuleService(profile_)),
348 app_data_migrator_(new AppDataMigrator(profile_, registry_)),
Sergey Poromov0360b9e72018-04-19 17:37:29349 extension_registrar_(profile_, this),
Sergey Poromov296de0a2018-10-11 21:44:08350 forced_extensions_tracker_(registry_, profile_) {
[email protected]a29a517a2011-01-21 21:11:12351 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
rkaplowdd66a1342015-03-05 00:31:49352 TRACE_EVENT0("browser,startup", "ExtensionService::ExtensionService::ctor");
[email protected]a8af9fdb2010-10-28 21:52:20353
[email protected]36a784c2009-06-23 06:21:08354 // Figure out if extension installation should be enabled.
Devlin Cronineea1b7a2018-05-26 02:46:21355 if (ExtensionsBrowserClient::Get()->AreExtensionsDisabled(*command_line,
356 profile))
[email protected]6d60703b2009-08-29 01:29:23357 extensions_enabled_ = false;
[email protected]36a784c2009-06-23 06:21:08358
[email protected]3c4abc82012-10-22 22:25:54359 registrar_.Add(this, chrome::NOTIFICATION_APP_TERMINATING,
360 content::NotificationService::AllBrowserContextsAndSources());
Devlin Cronineea1b7a2018-05-26 02:46:21361 registrar_.Add(this, NOTIFICATION_EXTENSION_PROCESS_TERMINATED,
[email protected]ad50def52011-10-19 23:17:07362 content::NotificationService::AllBrowserContextsAndSources());
[email protected]432115822011-07-10 15:52:27363 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_TERMINATED,
[email protected]ad50def52011-10-19 23:17:07364 content::NotificationService::AllBrowserContextsAndSources());
Evan Staded89e11c2019-09-05 18:08:56365 // The ProfileManager may be null in unit tests.
366 if (g_browser_process->profile_manager())
367 profile_manager_observer_.Add(g_browser_process->profile_manager());
binjin1569c9b2014-09-05 13:33:18368
weidongg04695232017-06-09 00:01:05369 UpgradeDetector::GetInstance()->AddObserver(this);
370
Devlin Cronineea1b7a2018-05-26 02:46:21371 ExtensionManagementFactory::GetForBrowserContext(profile_)->AddObserver(this);
[email protected]4814b512009-11-07 00:12:29372
rkaplowdd66a1342015-03-05 00:31:49373 // Set up the ExtensionUpdater.
[email protected]93fd78f42009-07-10 16:43:17374 if (autoupdate_enabled) {
Devlin Cronineea1b7a2018-05-26 02:46:21375 updater_.reset(new ExtensionUpdater(
David Bertonidccbd352018-03-20 00:31:04376 this, extension_prefs, profile->GetPrefs(), profile,
Devlin Cronineea1b7a2018-05-26 02:46:21377 kDefaultUpdateFrequencySeconds,
378 ExtensionsBrowserClient::Get()->GetExtensionCache(),
rockotdb5192992014-09-16 21:27:02379 base::Bind(ChromeExtensionDownloaderFactory::CreateForProfile,
380 profile)));
[email protected]93fd78f42009-07-10 16:43:17381 }
382
Michael Giuffridabe1f9202019-06-05 22:36:18383 component_loader_ = std::make_unique<ComponentLoader>(this, profile);
[email protected]8e4560b62011-01-14 10:09:14384
[email protected]0436b102011-04-15 18:30:03385 if (extensions_enabled_) {
Devlin Cronineea1b7a2018-05-26 02:46:21386 ExternalProviderImpl::CreateExternalProviders(
[email protected]ae4c37e2012-12-21 01:16:25387 this, profile_, &external_extension_providers_);
[email protected]873531342011-03-09 12:16:05388 }
[email protected]b671760b2010-07-15 21:13:47389
[email protected]74474042013-11-21 12:03:54390 // Set this as the ExtensionService for app sorting to ensure it causes syncs
391 // if required.
[email protected]b3aa7182013-04-25 04:45:23392 is_first_run_ = !extension_prefs_->SetAlertSystemFirstRun();
393
[email protected]373daf972014-04-10 01:50:44394 error_controller_.reset(
Devlin Cronineea1b7a2018-05-26 02:46:21395 new ExtensionErrorController(profile_, is_first_run_));
[email protected]374ceb6f2014-07-02 19:25:34396 external_install_manager_.reset(
Devlin Cronineea1b7a2018-05-26 02:46:21397 new ExternalInstallManager(profile_, is_first_run_));
[email protected]373daf972014-04-10 01:50:44398
[email protected]c77f2352012-08-08 22:07:58399 extension_action_storage_manager_.reset(
Devlin Cronineea1b7a2018-05-26 02:46:21400 new ExtensionActionStorageManager(profile_));
[email protected]c77f2352012-08-08 22:07:58401
[email protected]cb0e50312011-05-09 15:03:07402 // How long is the path to the Extensions directory?
403 UMA_HISTOGRAM_CUSTOM_COUNTS("Extensions.ExtensionRootPathLength",
drbasicf0d1b262016-08-23 06:10:42404 install_directory_.value().length(), 1, 500, 100);
[email protected]6014d672008-12-05 00:38:25405}
406
Devlin Cronineea1b7a2018-05-26 02:46:21407PendingExtensionManager* ExtensionService::pending_extension_manager() {
[email protected]b2907fd2011-03-25 16:43:37408 return &pending_extension_manager_;
[email protected]ddb1e5a2010-12-13 20:10:45409}
410
[email protected]eaa7dd182010-12-14 11:09:00411ExtensionService::~ExtensionService() {
weidongg04695232017-06-09 00:01:05412 UpgradeDetector::GetInstance()->RemoveObserver(this);
[email protected]c8d407e2011-04-28 21:27:17413 // No need to unload extensions here because they are profile-scoped, and the
414 // profile is in the process of being deleted.
achuith2f5578b2016-02-26 21:57:13415 for (const auto& provider : external_extension_providers_)
[email protected]8e4560b62011-01-14 10:09:14416 provider->ServiceShutdown();
[email protected]6014d672008-12-05 00:38:25417}
418
[email protected]037228a2012-10-05 01:36:16419void ExtensionService::Shutdown() {
Oleg Davydovbf103f92019-07-30 15:55:08420 ExtensionManagementFactory::GetForBrowserContext(profile())->RemoveObserver(
421 this);
Evan Stadeadf14bb2019-10-03 19:13:06422 external_install_manager_->Shutdown();
[email protected]037228a2012-10-05 01:36:16423}
424
[email protected]eaa7dd182010-12-14 11:09:00425void ExtensionService::Init() {
[email protected]a29a517a2011-01-21 21:11:12426 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
rkaplowe65c2ff2015-02-14 16:29:54427 TRACE_EVENT0("browser,startup", "ExtensionService::Init");
rkaplowa8fd8d32015-02-25 21:27:56428 SCOPED_UMA_HISTOGRAM_TIMER("Extensions.ExtensionServiceInitTime");
[email protected]3350d712013-11-18 09:32:24429
[email protected]4a10006a2013-05-17 23:18:35430 DCHECK(!is_ready()); // Can't redo init.
[email protected]bb1bc9b32013-12-21 03:09:14431 DCHECK_EQ(registry_->enabled_extensions().size(), 0u);
[email protected]9f1087e2009-06-15 17:29:32432
benwells22ab8ee2015-08-21 02:55:08433 component_loader_->LoadAll();
achuithd3da4f02017-03-23 20:05:29434 bool load_saved_extensions = true;
emaxx35e8b822017-04-11 02:04:29435 bool load_command_line_extensions = extensions_enabled_;
achuithd3da4f02017-03-23 20:05:29436#if defined(OS_CHROMEOS)
tbarzicd2a741e2017-06-28 20:37:54437 if (chromeos::ProfileHelper::IsSigninProfile(profile_) ||
438 chromeos::ProfileHelper::IsLockScreenAppProfile(profile_)) {
achuithd3da4f02017-03-23 20:05:29439 load_saved_extensions = false;
emaxx35e8b822017-04-11 02:04:29440 load_command_line_extensions = false;
441 }
achuithd3da4f02017-03-23 20:05:29442#endif
rdevlin.croninf2e1cb012017-05-27 01:27:59443 if (load_saved_extensions)
Devlin Cronineea1b7a2018-05-26 02:46:21444 InstalledLoader(this).LoadAllExtensions();
rdevlin.croninf2e1cb012017-05-27 01:27:59445
Nick Peterson8aa8e052019-05-22 23:17:01446 CheckManagementPolicy();
rdevlin.croninf2e1cb012017-05-27 01:27:59447 OnInstalledExtensionsLoaded();
448
Devlin Cronineea1b7a2018-05-26 02:46:21449 LoadExtensionsFromCommandLineFlag(::switches::kDisableExtensionsExcept);
emaxx35e8b822017-04-11 02:04:29450 if (load_command_line_extensions)
Devlin Cronineea1b7a2018-05-26 02:46:21451 LoadExtensionsFromCommandLineFlag(switches::kLoadExtension);
benwells22ab8ee2015-08-21 02:55:08452 EnabledReloadableExtensions();
453 MaybeFinishShutdownDelayed();
454 SetReadyAndNotifyListeners();
[email protected]ae4c37e2012-12-21 01:16:25455
Takumi Fujimoto43c8c00f2017-07-26 22:48:56456 UninstallMigratedExtensions();
457
benwells22ab8ee2015-08-21 02:55:08458 // TODO(erikkay): this should probably be deferred to a future point
459 // rather than running immediately at startup.
460 CheckForExternalUpdates();
[email protected]894bb502009-05-21 22:39:57461
benwells22ab8ee2015-08-21 02:55:08462 LoadGreylistFromPrefs();
rkaplowa8fd8d32015-02-25 21:27:56463}
[email protected]3350d712013-11-18 09:32:24464
rkaplowa8fd8d32015-02-25 21:27:56465void ExtensionService::EnabledReloadableExtensions() {
466 TRACE_EVENT0("browser,startup",
467 "ExtensionService::EnabledReloadableExtensions");
468
469 std::vector<std::string> extensions_to_enable;
achuith2f5578b2016-02-26 21:57:13470 for (const auto& e : registry_->disabled_extensions()) {
rkaplowa8fd8d32015-02-25 21:27:56471 if (extension_prefs_->GetDisableReasons(e->id()) ==
Devlin Cronineea1b7a2018-05-26 02:46:21472 disable_reason::DISABLE_RELOAD)
rkaplowa8fd8d32015-02-25 21:27:56473 extensions_to_enable.push_back(e->id());
rkaplowa8fd8d32015-02-25 21:27:56474 }
475 for (const std::string& extension : extensions_to_enable) {
476 EnableExtension(extension);
477 }
478}
479
480void ExtensionService::MaybeFinishShutdownDelayed() {
481 TRACE_EVENT0("browser,startup",
482 "ExtensionService::MaybeFinishShutdownDelayed");
483
Devlin Cronineea1b7a2018-05-26 02:46:21484 std::unique_ptr<ExtensionPrefs::ExtensionsInfo> delayed_info(
rkaplowa8fd8d32015-02-25 21:27:56485 extension_prefs_->GetAllDelayedInstallInfo());
486 for (size_t i = 0; i < delayed_info->size(); ++i) {
487 ExtensionInfo* info = delayed_info->at(i).get();
achuith2f5578b2016-02-26 21:57:13488 scoped_refptr<const Extension> extension(nullptr);
rkaplowa8fd8d32015-02-25 21:27:56489 if (info->extension_manifest) {
490 std::string error;
491 extension = Extension::Create(
492 info->extension_path, info->extension_location,
493 *info->extension_manifest,
494 extension_prefs_->GetDelayedInstallCreationFlags(info->extension_id),
495 info->extension_id, &error);
496 if (extension.get())
497 delayed_installs_.Insert(extension);
498 }
499 }
500 MaybeFinishDelayedInstallations();
Devlin Cronineea1b7a2018-05-26 02:46:21501 std::unique_ptr<ExtensionPrefs::ExtensionsInfo> delayed_info2(
rkaplowa8fd8d32015-02-25 21:27:56502 extension_prefs_->GetAllDelayedInstallInfo());
503 UMA_HISTOGRAM_COUNTS_100("Extensions.UpdateOnLoad",
504 delayed_info2->size() - delayed_info->size());
[email protected]6014d672008-12-05 00:38:25505}
506
[email protected]2d19eb6e2014-01-27 17:30:00507void ExtensionService::LoadGreylistFromPrefs() {
rkaplowa8fd8d32015-02-25 21:27:56508 TRACE_EVENT0("browser,startup", "ExtensionService::LoadGreylistFromPrefs");
509
dchengc963c7142016-04-08 03:55:22510 std::unique_ptr<ExtensionSet> all_extensions =
[email protected]f47f7172014-03-19 19:27:10511 registry_->GenerateInstalledExtensionsSet();
[email protected]2d19eb6e2014-01-27 17:30:00512
achuith2f5578b2016-02-26 21:57:13513 for (const auto& extension : *all_extensions) {
Devlin Cronineea1b7a2018-05-26 02:46:21514 const BlacklistState state =
achuith2f5578b2016-02-26 21:57:13515 extension_prefs_->GetExtensionBlacklistState(extension->id());
Devlin Cronineea1b7a2018-05-26 02:46:21516 if (state == BLACKLISTED_SECURITY_VULNERABILITY ||
517 state == BLACKLISTED_POTENTIALLY_UNWANTED ||
518 state == BLACKLISTED_CWS_POLICY_VIOLATION)
achuith2f5578b2016-02-26 21:57:13519 greylist_.Insert(extension);
[email protected]2d19eb6e2014-01-27 17:30:00520 }
521}
522
Devlin Cronineea1b7a2018-05-26 02:46:21523bool ExtensionService::UpdateExtension(const CRXFileInfo& file,
[email protected]044e86992014-01-24 22:59:11524 bool file_ownership_passed,
[email protected]31bb5ee62012-09-12 22:58:40525 CrxInstaller** out_crx_installer) {
[email protected]a29a517a2011-01-21 21:11:12526 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]3c4abc82012-10-22 22:25:54527 if (browser_terminating_) {
528 LOG(WARNING) << "Skipping UpdateExtension due to browser shutdown";
529 // Leak the temp file at extension_path. We don't want to add to the disk
530 // I/O burden at shutdown, we can't rely on the I/O completing anyway, and
531 // the file is in the OS temp directory which should be cleaned up for us.
532 return false;
533 }
[email protected]a8af9fdb2010-10-28 21:52:20534
ginkage553af3202015-02-04 12:39:09535 const std::string& id = file.extension_id;
536
Devlin Cronineea1b7a2018-05-26 02:46:21537 const PendingExtensionInfo* pending_extension_info =
[email protected]51a3bf8b2012-06-08 22:53:06538 pending_extension_manager()->GetById(id);
[email protected]8ef78fd2010-08-19 17:14:32539
David Bertoni9f897c92019-09-20 17:46:35540 const Extension* extension = registry_->GetInstalledExtension(id);
[email protected]51a3bf8b2012-06-08 22:53:06541 if (!pending_extension_info && !extension) {
[email protected]aa142702010-03-26 01:26:33542 LOG(WARNING) << "Will not update extension " << id
543 << " because it is not installed or pending";
544 // Delete extension_path since we're not creating a CrxInstaller
545 // that would do it for us.
asargentd50b18c2016-04-21 01:17:16546 if (file_ownership_passed &&
Devlin Cronineea1b7a2018-05-26 02:46:21547 !GetExtensionFileTaskRunner()->PostTask(
548 FROM_HERE,
549 base::BindOnce(&file_util::DeleteFile, file.path, false)))
[email protected]14908b72011-04-20 06:54:36550 NOTREACHED();
[email protected]420a0ec2011-06-01 01:07:03551
552 return false;
[email protected]e957fe52009-06-23 16:51:05553 }
Minh X. Nguyen30975342017-12-04 22:02:41554 // Either |pending_extension_info| or |extension| or both must not be null.
treibe960e282015-09-11 10:38:08555 scoped_refptr<CrxInstaller> installer(CrxInstaller::CreateSilent(this));
[email protected]6dfbbf82010-03-12 23:09:16556 installer->set_expected_id(id);
ginkage47e603e2015-02-27 08:42:41557 installer->set_expected_hash(file.expected_hash);
[email protected]464213a2013-10-15 01:06:48558 int creation_flags = Extension::NO_FLAGS;
[email protected]51a3bf8b2012-06-08 22:53:06559 if (pending_extension_info) {
560 installer->set_install_source(pending_extension_info->install_source());
pkotwicz31eb1e8ec2014-10-08 15:26:46561 installer->set_allow_silent_install(true);
treibe960e282015-09-11 10:38:08562 // If the extension came in disabled due to a permission increase, then
563 // don't grant it all the permissions. crbug.com/484214
564 bool has_permissions_increase =
Devlin Cronineea1b7a2018-05-26 02:46:21565 ExtensionPrefs::Get(profile_)->HasDisableReason(
566 id, disable_reason::DISABLE_PERMISSIONS_INCREASE);
treibe960e282015-09-11 10:38:08567 const base::Version& expected_version = pending_extension_info->version();
568 if (has_permissions_increase ||
569 pending_extension_info->remote_install() ||
570 !expected_version.IsValid()) {
[email protected]21db9ef2014-05-16 02:06:27571 installer->set_grant_permissions(false);
treibe960e282015-09-11 10:38:08572 } else {
573 installer->set_expected_version(expected_version,
574 false /* fail_install_if_unexpected */);
575 }
mamir0128d5a2016-07-15 20:55:48576 creation_flags = pending_extension_info->creation_flags();
[email protected]464213a2013-10-15 01:06:48577 if (pending_extension_info->mark_acknowledged())
[email protected]374ceb6f2014-07-02 19:25:34578 external_install_manager_->AcknowledgeExternalExtension(id);
Minh X. Nguyen30975342017-12-04 22:02:41579 // If the extension was installed from or has migrated to the webstore, or
580 // its auto-update URL is from the webstore, treat it as a webstore install.
581 // Note that we ignore some older extensions with blank auto-update URLs
582 // because we are mostly concerned with restrictions on NaCl extensions,
583 // which are newer.
584 if (!extension && extension_urls::IsWebstoreUpdateUrl(
585 pending_extension_info->update_url()))
586 creation_flags |= Extension::FROM_WEBSTORE;
587 } else {
588 // |extension| must not be null.
[email protected]5eb375e92010-11-26 07:50:41589 installer->set_install_source(extension->location());
[email protected]51a3bf8b2012-06-08 22:53:06590 }
[email protected]a12ce8b22012-01-17 18:40:53591
Minh X. Nguyen30975342017-12-04 22:02:41592 if (extension) {
593 installer->InitializeCreationFlagsForUpdate(extension, creation_flags);
[email protected]c30bda262014-06-19 04:10:13594 installer->set_do_not_sync(extension_prefs_->DoNotSync(id));
Minh X. Nguyen30975342017-12-04 22:02:41595 } else {
596 installer->set_creation_flags(creation_flags);
597 }
[email protected]044e86992014-01-24 22:59:11598 installer->set_delete_source(file_ownership_passed);
[email protected]cb0e50312011-05-09 15:03:07599 installer->set_install_cause(extension_misc::INSTALL_CAUSE_UPDATE);
ginkage553af3202015-02-04 12:39:09600 installer->InstallCrxFile(file);
[email protected]420a0ec2011-06-01 01:07:03601
602 if (out_crx_installer)
[email protected]dc24976f2013-06-02 21:15:09603 *out_crx_installer = installer.get();
[email protected]420a0ec2011-06-01 01:07:03604
605 return true;
[email protected]e957fe52009-06-23 16:51:05606}
607
catmullings98cd1942016-08-30 22:31:59608void ExtensionService::LoadExtensionsFromCommandLineFlag(
609 const char* switch_name) {
610 if (command_line_->HasSwitch(switch_name)) {
611 base::CommandLine::StringType path_list =
612 command_line_->GetSwitchValueNative(switch_name);
613 base::StringTokenizerT<base::CommandLine::StringType,
614 base::CommandLine::StringType::const_iterator>
615 t(path_list, FILE_PATH_LITERAL(","));
616 while (t.GetNext()) {
617 std::string extension_id;
Devlin Cronineea1b7a2018-05-26 02:46:21618 UnpackedInstaller::Create(this)->LoadFromCommandLine(
catmullings98cd1942016-08-30 22:31:59619 base::FilePath(t.token()), &extension_id, false /*only-allow-apps*/);
620 // Extension id is added to whitelist after its extension is loaded
michaelpga8ea0372017-04-06 20:41:35621 // because code is executed asynchronously. TODO(michaelpg): Remove this
622 // assumption so loading extensions does not have to be asynchronous:
623 // crbug.com/708354.
Devlin Cronineea1b7a2018-05-26 02:46:21624 if (switch_name == ::switches::kDisableExtensionsExcept)
catmullings98cd1942016-08-30 22:31:59625 disable_flag_exempted_extensions_.insert(extension_id);
626 }
627 }
628}
629
Michael Giuffrida573992d2018-02-08 00:48:44630// TODO(michaelpg): Group with other ExtensionRegistrar::Delegate overrides
631// according to header file once diffs have settled down.
632void ExtensionService::LoadExtensionForReload(
Devlin Cronineea1b7a2018-05-26 02:46:21633 const ExtensionId& extension_id,
Michael Giuffrida573992d2018-02-08 00:48:44634 const base::FilePath& path,
635 LoadErrorBehavior load_error_behavior) {
Toni Barzic667db0d32018-01-09 18:00:19636 if (delayed_installs_.Contains(extension_id) &&
637 FinishDelayedInstallationIfReady(extension_id,
638 true /*install_immediately*/)) {
[email protected]0db124b02012-11-07 04:55:05639 return;
640 }
641
[email protected]43ceb002012-02-10 23:19:15642 // If we're reloading a component extension, use the component extension
643 // loader's reloader.
644 if (component_loader_->Exists(extension_id)) {
645 component_loader_->Reload(extension_id);
646 return;
647 }
648
[email protected]e6090e42010-03-23 22:44:08649 // Check the installed extensions to see if what we're reloading was already
650 // installed.
dchengc963c7142016-04-08 03:55:22651 std::unique_ptr<ExtensionInfo> installed_extension(
[email protected]e6090e42010-03-23 22:44:08652 extension_prefs_->GetInstalledExtensionInfo(extension_id));
653 if (installed_extension.get() &&
654 installed_extension->extension_manifest.get()) {
Devlin Cronineea1b7a2018-05-26 02:46:21655 InstalledLoader(this).Load(*installed_extension, false);
[email protected]e6090e42010-03-23 22:44:08656 } else {
Michael Giuffrida573992d2018-02-08 00:48:44657 // Otherwise, the extension is unpacked (location LOAD). We must load it
658 // from the path.
659 CHECK(!path.empty()) << "ExtensionRegistrar should never ask to load an "
660 "unknown extension with no path";
Devlin Cronineea1b7a2018-05-26 02:46:21661 scoped_refptr<UnpackedInstaller> unpacked_installer =
662 UnpackedInstaller::Create(this);
Michael Giuffrida573992d2018-02-08 00:48:44663 unpacked_installer->set_be_noisy_on_failure(load_error_behavior ==
664 LoadErrorBehavior::kNoisy);
[email protected]bca4b832014-07-17 20:22:34665 unpacked_installer->Load(path);
[email protected]e6090e42010-03-23 22:44:08666 }
[email protected]9cddd4702009-07-27 22:09:40667}
668
[email protected]bca4b832014-07-17 20:22:34669void ExtensionService::ReloadExtension(const std::string& extension_id) {
Michael Giuffrida573992d2018-02-08 00:48:44670 extension_registrar_.ReloadExtension(extension_id, LoadErrorBehavior::kNoisy);
[email protected]bca4b832014-07-17 20:22:34671}
672
673void ExtensionService::ReloadExtensionWithQuietFailure(
674 const std::string& extension_id) {
Michael Giuffrida573992d2018-02-08 00:48:44675 extension_registrar_.ReloadExtension(extension_id, LoadErrorBehavior::kQuiet);
[email protected]bca4b832014-07-17 20:22:34676}
677
[email protected]757d60a2014-05-23 00:11:44678bool ExtensionService::UninstallExtension(
679 // "transient" because the process of uninstalling may cause the reference
680 // to become invalid. Instead, use |extenson->id()|.
681 const std::string& transient_extension_id,
Devlin Cronineea1b7a2018-05-26 02:46:21682 UninstallReason reason,
[email protected]757d60a2014-05-23 00:11:44683 base::string16* error) {
[email protected]a29a517a2011-01-21 21:11:12684 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]a8af9fdb2010-10-28 21:52:20685
[email protected]757d60a2014-05-23 00:11:44686 scoped_refptr<const Extension> extension =
David Bertoni9f897c92019-09-20 17:46:35687 registry_->GetInstalledExtension(transient_extension_id);
[email protected]631cf822009-05-15 07:01:25688
[email protected]e7afe2452010-08-22 16:19:13689 // Callers should not send us nonexistent extensions.
[email protected]dc24976f2013-06-02 21:15:09690 CHECK(extension.get());
[email protected]9f1087e2009-06-15 17:29:32691
binjincccacef2014-10-13 19:00:20692 ManagementPolicy* by_policy = system_->management_policy();
[email protected]95da88c42011-03-31 10:07:33693 // Policy change which triggers an uninstall will always set
694 // |external_uninstall| to true so this is the only way to uninstall
695 // managed extensions.
[email protected]90878c52014-04-04 18:21:02696 // Shared modules being uninstalled will also set |external_uninstall| to true
697 // so that we can guarantee users don't uninstall a shared module.
698 // (crbug.com/273300)
699 // TODO(rdevlin.cronin): This is probably not right. We should do something
700 // else, like include an enum IS_INTERNAL_UNINSTALL or IS_USER_UNINSTALL so
701 // we don't do this.
[email protected]cc2f55c2014-07-08 02:19:04702 bool external_uninstall =
Devlin Cronineea1b7a2018-05-26 02:46:21703 (reason == UNINSTALL_REASON_INTERNAL_MANAGEMENT) ||
704 (reason == UNINSTALL_REASON_COMPONENT_REMOVED) ||
705 (reason == UNINSTALL_REASON_REINSTALL) ||
706 (reason == UNINSTALL_REASON_ORPHANED_EXTERNAL_EXTENSION) ||
Toby Huangd7caf252019-10-30 01:11:16707 (reason == UNINSTALL_REASON_ORPHANED_SHARED_MODULE);
[email protected]65187152012-06-02 13:14:14708 if (!external_uninstall &&
binjincccacef2014-10-13 19:00:20709 (!by_policy->UserMayModifySettings(extension.get(), error) ||
710 by_policy->MustRemainInstalled(extension.get(), error))) {
[email protected]ad50def52011-10-19 23:17:07711 content::NotificationService::current()->Notify(
Devlin Cronineea1b7a2018-05-26 02:46:21712 NOTIFICATION_EXTENSION_UNINSTALL_NOT_ALLOWED,
[email protected]6c2381d2011-10-19 02:52:53713 content::Source<Profile>(profile_),
[email protected]dc24976f2013-06-02 21:15:09714 content::Details<const Extension>(extension.get()));
[email protected]d6ebc9792011-04-07 18:18:33715 return false;
716 }
[email protected]95da88c42011-03-31 10:07:33717
juncai33e462102015-05-18 20:48:44718 InstallVerifier::Get(GetBrowserContext())->Remove(extension->id());
[email protected]ffd2f79e2013-11-14 00:11:46719
[email protected]9b217652010-10-08 22:04:23720 UMA_HISTOGRAM_ENUMERATION("Extensions.UninstallType",
[email protected]7fa19f82010-12-21 19:40:08721 extension->GetType(), 100);
treib2e0517f92015-05-07 23:15:36722 RecordPermissionMessagesHistogram(extension.get(), "Uninstall");
[email protected]9b217652010-10-08 22:04:23723
[email protected]831aa212010-03-26 13:55:19724 // Unload before doing more cleanup to ensure that nothing is hanging on to
725 // any of these resources.
limasdf0deef2042017-05-03 19:17:17726 UnloadExtension(extension->id(), UnloadedExtensionReason::UNINSTALL);
asargent96c7ec42016-05-27 02:45:47727 if (registry_->blacklisted_extensions().Contains(extension->id()))
728 registry_->RemoveBlacklisted(extension->id());
[email protected]831aa212010-03-26 13:55:19729
[email protected]9f1087e2009-06-15 17:29:32730 // Tell the backend to start deleting installed extensions on the file thread.
[email protected]12075d12013-02-27 05:38:05731 if (!Manifest::IsUnpackedLocation(extension->location())) {
Devlin Cronineea1b7a2018-05-26 02:46:21732 if (!GetExtensionFileTaskRunner()->PostTask(
[email protected]7f8f24f2012-11-15 19:40:14733 FROM_HERE,
tzik8d880ee2017-04-20 19:46:24734 base::BindOnce(&ExtensionService::UninstallExtensionOnFileThread,
735 extension->id(), profile_, install_directory_,
736 extension->path())))
[email protected]14908b72011-04-20 06:54:36737 NOTREACHED();
[email protected]9f1087e2009-06-15 17:29:32738 }
739
Devlin Cronineea1b7a2018-05-26 02:46:21740 DataDeleter::StartDeleting(profile_, extension.get());
[email protected]0d6ec3a72011-09-02 02:09:43741
Michael Giuffridafcb420362017-10-11 21:50:26742 extension_registrar_.UntrackTerminatedExtension(extension->id());
[email protected]211030342010-09-30 18:41:06743
744 // Notify interested parties that we've uninstalled this extension.
[email protected]e43c61f2014-07-20 21:46:34745 ExtensionRegistry::Get(profile_)
746 ->TriggerOnUninstalled(extension.get(), reason);
[email protected]d6ebc9792011-04-07 18:18:33747
[email protected]757d60a2014-05-23 00:11:44748 delayed_installs_.Remove(extension->id());
[email protected]0db124b02012-11-07 04:55:05749
[email protected]757d60a2014-05-23 00:11:44750 extension_prefs_->OnExtensionUninstalled(
751 extension->id(), extension->location(), external_uninstall);
[email protected]d4eda592013-09-18 03:37:57752
[email protected]333b1de2011-09-12 18:28:50753 // Track the uninstallation.
[email protected]49098f702011-10-13 03:47:18754 UMA_HISTOGRAM_ENUMERATION("Extensions.ExtensionUninstalled", 1, 2);
755
[email protected]d6ebc9792011-04-07 18:18:33756 return true;
[email protected]c10da4b02010-03-25 14:38:32757}
758
[email protected]5a145e82014-05-29 22:19:07759// static
760void ExtensionService::UninstallExtensionOnFileThread(
761 const std::string& id,
762 Profile* profile,
763 const base::FilePath& install_dir,
764 const base::FilePath& extension_path) {
Devlin Cronineea1b7a2018-05-26 02:46:21765 ExtensionAssetsManager* assets_manager =
766 ExtensionAssetsManager::GetInstance();
[email protected]5a145e82014-05-29 22:19:07767 assets_manager->UninstallExtension(id, profile, install_dir, extension_path);
768}
769
[email protected]c3cfb012011-04-06 22:07:35770bool ExtensionService::IsExtensionEnabled(
771 const std::string& extension_id) const {
Michael Giuffrida6397c592017-10-09 20:46:53772 return extension_registrar_.IsExtensionEnabled(extension_id);
[email protected]c3cfb012011-04-06 22:07:35773}
774
[email protected]eaa7dd182010-12-14 11:09:00775void ExtensionService::EnableExtension(const std::string& extension_id) {
[email protected]a29a517a2011-01-21 21:11:12776 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
Michael Giuffrida6397c592017-10-09 20:46:53777 extension_registrar_.EnableExtension(extension_id);
[email protected]0c6da502009-08-14 22:32:39778}
779
treibc1192322015-05-20 12:56:07780void ExtensionService::DisableExtension(const std::string& extension_id,
781 int disable_reasons) {
[email protected]a29a517a2011-01-21 21:11:12782 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
Toby Huang0ff6496e72020-02-05 06:07:32783 DCHECK(disable_reasons != disable_reason::DISABLE_BLOCKED_MATURE ||
784 profile()->IsChild());
Michael Giuffrida6397c592017-10-09 20:46:53785 extension_registrar_.DisableExtension(extension_id, disable_reasons);
[email protected]1784e83a2009-09-08 21:01:52786}
787
Ivan Sandrk4a55dc22018-05-17 18:14:48788void ExtensionService::DisableExtensionWithSource(
789 const Extension* source_extension,
790 const std::string& extension_id,
Devlin Cronineea1b7a2018-05-26 02:46:21791 disable_reason::DisableReason disable_reasons) {
Ivan Sandrk4a55dc22018-05-17 18:14:48792 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
793
Devlin Cronineea1b7a2018-05-26 02:46:21794 DCHECK(disable_reasons == disable_reason::DISABLE_USER_ACTION ||
795 disable_reasons == disable_reason::DISABLE_BLOCKED_BY_POLICY);
796 if (disable_reasons == disable_reason::DISABLE_BLOCKED_BY_POLICY) {
Ivan Sandrk4a55dc22018-05-17 18:14:48797 DCHECK(Manifest::IsPolicyLocation(source_extension->location()) ||
798 Manifest::IsComponentLocation(source_extension->location()));
799 }
800
David Bertonia0b34722019-09-30 20:51:26801 const Extension* extension =
802 registry_->GetExtensionById(extension_id, ExtensionRegistry::EVERYTHING);
Ivan Sandrk4a55dc22018-05-17 18:14:48803 CHECK(system_->management_policy()->ExtensionMayModifySettings(
804 source_extension, extension, nullptr));
805 extension_registrar_.DisableExtension(extension_id, disable_reasons);
806}
807
mtomasz294bb3e2017-01-24 02:17:52808void ExtensionService::DisableUserExtensionsExcept(
[email protected]1abf05e2013-07-09 17:04:36809 const std::vector<std::string>& except_ids) {
Devlin Cronineea1b7a2018-05-26 02:46:21810 ManagementPolicy* management_policy = system_->management_policy();
811 ExtensionList to_disable;
[email protected]e516e4c2013-06-12 17:41:14812
achuith2f5578b2016-02-26 21:57:13813 for (const auto& extension : registry_->enabled_extensions()) {
814 if (management_policy->UserMayModifySettings(extension.get(), nullptr))
815 to_disable.push_back(extension);
[email protected]e516e4c2013-06-12 17:41:14816 }
817
achuith2f5578b2016-02-26 21:57:13818 for (const auto& extension : registry_->terminated_extensions()) {
819 if (management_policy->UserMayModifySettings(extension.get(), nullptr))
820 to_disable.push_back(extension);
821 }
822
823 for (const auto& extension : to_disable) {
824 if (extension->was_installed_by_default() &&
[email protected]3082fe32013-08-06 11:12:38825 extension_urls::IsWebstoreUpdateUrl(
Devlin Cronineea1b7a2018-05-26 02:46:21826 ManifestURL::GetUpdateURL(extension.get())))
[email protected]3082fe32013-08-06 11:12:38827 continue;
achuith2f5578b2016-02-26 21:57:13828 const std::string& id = extension->id();
Jan Wilken Dörrieade79222019-06-06 19:01:12829 if (!base::Contains(except_ids, id))
Devlin Cronineea1b7a2018-05-26 02:46:21830 DisableExtension(id, disable_reason::DISABLE_USER_ACTION);
[email protected]e516e4c2013-06-12 17:41:14831 }
832}
833
mlerman6a37b6a42014-11-26 22:10:53834// Extensions that are not locked, components or forced by policy should be
835// locked. Extensions are no longer considered enabled or disabled. Blacklisted
836// extensions are now considered both blacklisted and locked.
837void ExtensionService::BlockAllExtensions() {
838 if (block_extensions_)
839 return;
840 block_extensions_ = true;
841
842 // Blacklisted extensions are already unloaded, need not be blocked.
dchengc963c7142016-04-08 03:55:22843 std::unique_ptr<ExtensionSet> extensions =
mlerman6a37b6a42014-11-26 22:10:53844 registry_->GenerateInstalledExtensionsSet(ExtensionRegistry::ENABLED |
845 ExtensionRegistry::DISABLED |
846 ExtensionRegistry::TERMINATED);
847
achuith2f5578b2016-02-26 21:57:13848 for (const auto& extension : *extensions) {
mlerman6a37b6a42014-11-26 22:10:53849 const std::string& id = extension->id();
850
851 if (!CanBlockExtension(extension.get()))
852 continue;
853
854 registry_->RemoveEnabled(id);
855 registry_->RemoveDisabled(id);
856 registry_->RemoveTerminated(id);
857
858 registry_->AddBlocked(extension.get());
Devlin Cronineea1b7a2018-05-26 02:46:21859 UnloadExtension(id, UnloadedExtensionReason::LOCK_ALL);
mlerman6a37b6a42014-11-26 22:10:53860 }
861}
862
863// All locked extensions should revert to being either enabled or disabled
864// as appropriate.
865void ExtensionService::UnblockAllExtensions() {
866 block_extensions_ = false;
dchengc963c7142016-04-08 03:55:22867 std::unique_ptr<ExtensionSet> to_unblock =
mlerman6a37b6a42014-11-26 22:10:53868 registry_->GenerateInstalledExtensionsSet(ExtensionRegistry::BLOCKED);
869
achuith2f5578b2016-02-26 21:57:13870 for (const auto& extension : *to_unblock) {
mlerman6a37b6a42014-11-26 22:10:53871 registry_->RemoveBlocked(extension->id());
872 AddExtension(extension.get());
873 }
Owen Minb71016d2018-01-11 01:51:49874 // While extensions are blocked, we won't display any external install
875 // warnings. Now that they are unblocked, we should update the error.
876 external_install_manager_->UpdateExternalExtensionAlert();
mlerman6a37b6a42014-11-26 22:10:53877}
878
[email protected]eaa7dd182010-12-14 11:09:00879void ExtensionService::GrantPermissionsAndEnableExtension(
[email protected]009633c2013-03-07 22:08:28880 const Extension* extension) {
881 GrantPermissions(extension);
treib2e0517f92015-05-07 23:15:36882 RecordPermissionMessagesHistogram(extension, "ReEnable");
[email protected]8d888c12010-11-30 00:00:25883 EnableExtension(extension->id());
884}
885
[email protected]009633c2013-03-07 22:08:28886void ExtensionService::GrantPermissions(const Extension* extension) {
[email protected]be083862012-09-01 03:53:45887 CHECK(extension);
Devlin Cronineea1b7a2018-05-26 02:46:21888 PermissionsUpdater(profile()).GrantActivePermissions(extension);
[email protected]be083862012-09-01 03:53:45889}
890
[email protected]fe2dd7742011-04-19 22:52:49891// static
892void ExtensionService::RecordPermissionMessagesHistogram(
[email protected]13c68b62013-05-17 11:29:05893 const Extension* extension, const char* histogram) {
[email protected]de415552013-01-23 04:12:17894 // Since this is called from multiple sources, and since the histogram macros
895 // use statics, we need to manually lookup the histogram ourselves.
treib2e0517f92015-05-07 23:15:36896 base::HistogramBase* counter = base::LinearHistogram::FactoryGet(
897 base::StringPrintf("Extensions.Permissions_%s3", histogram),
898 1,
899 APIPermission::kEnumBoundary,
900 APIPermission::kEnumBoundary + 1,
901 base::HistogramBase::kUmaTargetedHistogramFlag);
902
903 base::HistogramBase* counter_has_any = base::BooleanHistogram::FactoryGet(
904 base::StringPrintf("Extensions.HasPermissions_%s3", histogram),
905 base::HistogramBase::kUmaTargetedHistogramFlag);
906
907 PermissionIDSet permissions =
Devlin Cronineea1b7a2018-05-26 02:46:21908 PermissionMessageProvider::Get()->GetAllPermissionIDs(
rdevlin.cronine2d0fd02015-09-24 22:35:49909 extension->permissions_data()->active_permissions(),
treib2e0517f92015-05-07 23:15:36910 extension->GetType());
911 counter_has_any->AddBoolean(!permissions.empty());
912 for (const PermissionID& id : permissions)
913 counter->Add(id.id());
[email protected]fe2dd7742011-04-19 22:52:49914}
915
Michael Giuffrida6397c592017-10-09 20:46:53916// TODO(michaelpg): Group with other ExtensionRegistrar::Delegate overrides
917// according to header file once diffs have settled down.
918void ExtensionService::PostActivateExtension(
Michael Giuffrida19a55982018-02-10 03:03:26919 scoped_refptr<const Extension> extension) {
[email protected]dcc47642014-03-26 22:03:49920 // TODO(kalman): Convert ExtensionSpecialStoragePolicy to a
921 // BrowserContextKeyedService and use ExtensionRegistryObserver.
Michael Giuffrida6397c592017-10-09 20:46:53922 profile_->GetExtensionSpecialStoragePolicy()->GrantRightsForExtension(
Devlin Croninb2be9a6a2019-06-14 20:08:19923 extension.get());
[email protected]c8d407e2011-04-28 21:27:17924
[email protected]dcc47642014-03-26 22:03:49925 // TODO(kalman): This is broken. The crash reporter is process-wide so doesn't
926 // work properly multi-profile. Besides which, it should be using
927 // ExtensionRegistryObserver. See http://crbug.com/355029.
[email protected]c8d407e2011-04-28 21:27:17928 UpdateActiveExtensionsInCrashReporter();
929
Devlin Cronineea1b7a2018-05-26 02:46:21930 const PermissionsData* permissions_data = extension->permissions_data();
[email protected]d695bb12014-06-05 16:16:30931
[email protected]c8d407e2011-04-28 21:27:17932 // If the extension has permission to load chrome://favicon/ resources we need
933 // to make sure that the FaviconSource is registered with the
934 // ChromeURLDataManager.
[email protected]d695bb12014-06-05 16:16:30935 if (permissions_data->HasHostPermission(GURL(chrome::kChromeUIFaviconURL))) {
Victor Hugo Vianna Silvaed441482019-06-27 12:40:40936 content::URLDataSource::Add(
937 profile_, std::make_unique<FaviconSource>(
938 profile_, chrome::FaviconUrlFormat::kFaviconLegacy));
[email protected]c8d407e2011-04-28 21:27:17939 }
[email protected]b07e606e2012-09-15 20:16:15940
[email protected]b07e606e2012-09-15 20:16:15941 // Same for chrome://theme/ resources.
[email protected]d695bb12014-06-05 16:16:30942 if (permissions_data->HasHostPermission(GURL(chrome::kChromeUIThemeURL))) {
Lei Zhangc77274da2018-08-28 23:14:00943 content::URLDataSource::Add(profile_,
944 std::make_unique<ThemeSource>(profile_));
[email protected]b07e606e2012-09-15 20:16:15945 }
[email protected]62d30f42009-10-01 22:36:06946}
947
Michael Giuffrida6397c592017-10-09 20:46:53948// TODO(michaelpg): Group with other ExtensionRegistrar::Delegate overrides
949// according to header file once diffs have settled down.
Michael Giuffrida023e3532017-09-28 23:21:21950void ExtensionService::PostDeactivateExtension(
951 scoped_refptr<const Extension> extension) {
[email protected]dcc47642014-03-26 22:03:49952 // TODO(kalman): Convert ExtensionSpecialStoragePolicy to a
953 // BrowserContextKeyedService and use ExtensionRegistryObserver.
Michael Giuffrida023e3532017-09-28 23:21:21954 profile_->GetExtensionSpecialStoragePolicy()->RevokeRightsForExtension(
955 extension.get());
[email protected]c8d407e2011-04-28 21:27:17956
[email protected]b777b332011-04-16 04:01:08957#if defined(OS_CHROMEOS)
[email protected]ac66e452013-01-11 09:21:23958 // Revoke external file access for the extension from its file system context.
959 // It is safe to access the extension's storage partition at this point. The
960 // storage partition may get destroyed only after the extension gets unloaded.
[email protected]cd501a72014-08-22 19:58:31961 storage::FileSystemContext* filesystem_context =
Aaron Colwell01b39762019-12-12 17:12:12962 util::GetStoragePartitionForExtensionId(extension->id(), profile_)
[email protected]cd501a72014-08-22 19:58:31963 ->GetFileSystemContext();
[email protected]f19bbf62013-07-09 01:22:32964 if (filesystem_context && filesystem_context->external_backend()) {
Michael Giuffrida6397c592017-10-09 20:46:53965 filesystem_context->external_backend()->RevokeAccessForExtension(
966 extension->id());
[email protected]62d30f42009-10-01 22:36:06967 }
[email protected]c8d407e2011-04-28 21:27:17968#endif
969
[email protected]dcc47642014-03-26 22:03:49970 // TODO(kalman): This is broken. The crash reporter is process-wide so doesn't
971 // work properly multi-profile. Besides which, it should be using
972 // ExtensionRegistryObserver::OnExtensionLoaded. See http://crbug.com/355029.
[email protected]c8d407e2011-04-28 21:27:17973 UpdateActiveExtensionsInCrashReporter();
[email protected]62d30f42009-10-01 22:36:06974}
975
[email protected]599539802014-01-07 23:06:00976content::BrowserContext* ExtensionService::GetBrowserContext() const {
977 // Implemented in the .cc file to avoid adding a profile.h dependency to
978 // extension_service.h.
979 return profile_;
980}
981
[email protected]25ae0152011-11-18 14:40:02982bool ExtensionService::is_ready() {
[email protected]4a10006a2013-05-17 23:18:35983 return ready_->is_signaled();
[email protected]25ae0152011-11-18 14:40:02984}
985
[email protected]4ee07c62012-08-21 12:40:42986void ExtensionService::CheckManagementPolicy() {
Devlin Cronineea1b7a2018-05-26 02:46:21987 std::map<std::string, disable_reason::DisableReason> to_disable;
binjin8e3d0182014-12-04 16:44:28988 std::vector<std::string> to_enable;
[email protected]695b5712012-12-06 23:55:28989
Karan Bhatia2a117232017-08-23 00:24:56990 // Loop through the extensions list, finding extensions we need to disable.
achuith2f5578b2016-02-26 21:57:13991 for (const auto& extension : registry_->enabled_extensions()) {
Devlin Cronineea1b7a2018-05-26 02:46:21992 disable_reason::DisableReason disable_reason = disable_reason::DISABLE_NONE;
[email protected]0d54b682013-11-05 14:15:36993 if (system_->management_policy()->MustRemainDisabled(
binjin8e3d0182014-12-04 16:44:28994 extension.get(), &disable_reason, nullptr))
[email protected]0d54b682013-11-05 14:15:36995 to_disable[extension->id()] = disable_reason;
[email protected]aa96d3a2010-08-21 08:45:25996 }
997
Devlin Cronineea1b7a2018-05-26 02:46:21998 ExtensionManagement* management =
999 ExtensionManagementFactory::GetForBrowserContext(profile());
Marc Grimmeefba8d22020-01-09 07:57:251000
Devlin Cronineea1b7a2018-05-26 02:46:211001 PermissionsUpdater(profile()).SetDefaultPolicyHostRestrictions(
Devlin Cronin7e0f41ff2018-05-16 17:19:361002 management->GetDefaultPolicyBlockedHosts(),
1003 management->GetDefaultPolicyAllowedHosts());
Marc Grimmeefba8d22020-01-09 07:57:251004
nrpetere33d2a5b2017-04-25 00:12:311005 for (const auto& extension : registry_->enabled_extensions()) {
Marc Grimmeefba8d22020-01-09 07:57:251006 SetPolicySettingsForExtension(extension.get());
nrpetere33d2a5b2017-04-25 00:12:311007 }
binjin8e3d0182014-12-04 16:44:281008
1009 // Loop through the disabled extension list, find extensions to re-enable
Karan Bhatia2a117232017-08-23 00:24:561010 // automatically. These extensions are exclusive from the |to_disable| list
1011 // constructed above, since disabled_extensions() and enabled_extensions() are
1012 // supposed to be mutually exclusive.
achuith2f5578b2016-02-26 21:57:131013 for (const auto& extension : registry_->disabled_extensions()) {
Karan Bhatia2a117232017-08-23 00:24:561014 int disable_reasons = extension_prefs_->GetDisableReasons(extension->id());
binjin8e3d0182014-12-04 16:44:281015
Karan Bhatia2a117232017-08-23 00:24:561016 // Find all extensions disabled due to minimum version requirement and
1017 // management policy but now satisfying it.
1018 if (management->CheckMinimumVersion(extension.get(), nullptr)) {
Devlin Cronineea1b7a2018-05-26 02:46:211019 disable_reasons &= (~disable_reason::DISABLE_UPDATE_REQUIRED_BY_POLICY);
Karan Bhatia2a117232017-08-23 00:24:561020 }
1021
1022 if (!system_->management_policy()->MustRemainDisabled(extension.get(),
1023 nullptr, nullptr)) {
Devlin Cronineea1b7a2018-05-26 02:46:211024 disable_reasons &= (~disable_reason::DISABLE_BLOCKED_BY_POLICY);
Karan Bhatia2a117232017-08-23 00:24:561025 }
1026
Toby Huangdb647e0f2020-02-04 22:34:571027 // If this profile is not supervised, then remove any supervised user
1028 // related disable reasons.
1029 if (!profile()->IsChild()) {
1030 disable_reasons &= (~disable_reason::DISABLE_CUSTODIAN_APPROVAL_REQUIRED);
Toby Huang0ff6496e72020-02-05 06:07:321031 disable_reasons &= (~disable_reason::DISABLE_BLOCKED_MATURE);
Toby Huangdb647e0f2020-02-04 22:34:571032 }
1033
Karan Bhatia2a117232017-08-23 00:24:561034 extension_prefs_->ReplaceDisableReasons(extension->id(), disable_reasons);
Devlin Cronineea1b7a2018-05-26 02:46:211035 if (disable_reasons == disable_reason::DISABLE_NONE)
Karan Bhatia2a117232017-08-23 00:24:561036 to_enable.push_back(extension->id());
1037 }
[email protected]0d54b682013-11-05 14:15:361038
achuith2f5578b2016-02-26 21:57:131039 for (const auto& i : to_disable)
1040 DisableExtension(i.first, i.second);
binjin8e3d0182014-12-04 16:44:281041
Karan Bhatia2a117232017-08-23 00:24:561042 // No extension is getting re-enabled here after disabling because |to_enable|
1043 // is mutually exclusive to |to_disable|.
binjin8e3d0182014-12-04 16:44:281044 for (const std::string& id : to_enable)
1045 EnableExtension(id);
1046
1047 if (updater_.get()) {
1048 // Find all extensions disabled due to minimum version requirement from
1049 // policy (including the ones that got disabled just now), and check
1050 // for update.
Devlin Cronineea1b7a2018-05-26 02:46:211051 ExtensionUpdater::CheckParams to_recheck;
achuith2f5578b2016-02-26 21:57:131052 for (const auto& extension : registry_->disabled_extensions()) {
binjin8e3d0182014-12-04 16:44:281053 if (extension_prefs_->GetDisableReasons(extension->id()) ==
Devlin Cronineea1b7a2018-05-26 02:46:211054 disable_reason::DISABLE_UPDATE_REQUIRED_BY_POLICY) {
binjin8e3d0182014-12-04 16:44:281055 // The minimum version check is the only thing holding this extension
1056 // back, so check if it can be updated to fix that.
1057 to_recheck.ids.push_back(extension->id());
1058 }
1059 }
1060 if (!to_recheck.ids.empty())
Minh X. Nguyen722b9682018-04-25 21:46:481061 updater_->CheckNow(std::move(to_recheck));
binjin8e3d0182014-12-04 16:44:281062 }
Alexander Nohe2c5402882019-04-11 21:56:331063
1064 // Check the disabled extensions to see if any should be force uninstalled.
1065 std::vector<ExtensionId> remove_list;
1066 for (const auto& extension : registry_->disabled_extensions()) {
1067 if (system_->management_policy()->ShouldForceUninstall(extension.get(),
1068 nullptr /*error*/)) {
1069 remove_list.push_back(extension->id());
1070 }
1071 }
1072 for (auto extension_id : remove_list) {
1073 base::string16 error;
1074 if (!UninstallExtension(extension_id, UNINSTALL_REASON_INTERNAL_MANAGEMENT,
1075 &error)) {
1076 SYSLOG(WARNING) << "Extension with id " << extension_id
1077 << " failed to be uninstalled via policy: " << error;
1078 }
1079 }
[email protected]aa96d3a2010-08-21 08:45:251080}
1081
[email protected]31206602011-04-13 23:07:321082void ExtensionService::CheckForUpdatesSoon() {
[email protected]90878c52014-04-04 18:21:021083 // This can legitimately happen in unit tests.
1084 if (!updater_.get())
1085 return;
1086
raphael.kubo.da.costa8527f942016-11-15 17:03:511087 updater_->CheckSoon();
[email protected]c3cfb012011-04-06 22:07:351088}
1089
[email protected]8e4560b62011-01-14 10:09:141090// Some extensions will autoupdate themselves externally from Chrome. These
rkaplowa8fd8d32015-02-25 21:27:561091// are typically part of some larger client application package. To support
1092// these, the extension will register its location in the preferences file
[email protected]8e4560b62011-01-14 10:09:141093// (and also, on Windows, in the registry) and this code will periodically
1094// check that location for a .crx file, which it will then install locally if
1095// a new version is available.
Devlin Cronin9722a722017-12-16 03:35:101096// Errors are reported through LoadErrorReporter. Success is not reported.
[email protected]eaa7dd182010-12-14 11:09:001097void ExtensionService::CheckForExternalUpdates() {
lazyboy77214d3c2017-04-04 16:46:121098 if (external_updates_disabled_for_test_)
1099 return;
1100
[email protected]a29a517a2011-01-21 21:11:121101 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
rkaplowa8fd8d32015-02-25 21:27:561102 TRACE_EVENT0("browser,startup", "ExtensionService::CheckForExternalUpdates");
1103 SCOPED_UMA_HISTOGRAM_TIMER("Extensions.CheckForExternalUpdatesTime");
[email protected]8e4560b62011-01-14 10:09:141104
1105 // Note that this installation is intentionally silent (since it didn't
1106 // go through the front-end). Extensions that are registered in this
1107 // way are effectively considered 'pre-bundled', and so implicitly
1108 // trusted. In general, if something has HKLM or filesystem access,
1109 // they could install an extension manually themselves anyway.
[email protected]a29a517a2011-01-21 21:11:121110
[email protected]8e4560b62011-01-14 10:09:141111 // Ask each external extension provider to give us a call back for each
1112 // extension they know about. See OnExternalExtension(File|UpdateUrl)Found.
achuith2f5578b2016-02-26 21:57:131113 for (const auto& provider : external_extension_providers_)
[email protected]8e4560b62011-01-14 10:09:141114 provider->VisitRegisteredExtension();
[email protected]8e4560b62011-01-14 10:09:141115
[email protected]50067e52011-10-20 23:17:071116 // Do any required work that we would have done after completion of all
1117 // providers.
[email protected]373daf972014-04-10 01:50:441118 if (external_extension_providers_.empty())
[email protected]50067e52011-10-20 23:17:071119 OnAllExternalProvidersReady();
[email protected]9f1087e2009-06-15 17:29:321120}
1121
[email protected]50067e52011-10-20 23:17:071122void ExtensionService::OnExternalProviderReady(
lazyboye8634172016-01-28 00:10:481123 const ExternalProviderInterface* provider) {
Istiaque Ahmedf6e72622017-09-08 23:14:171124 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]50067e52011-10-20 23:17:071125 CHECK(provider->IsReady());
[email protected]a29a517a2011-01-21 21:11:121126
1127 // An external provider has finished loading. We only take action
[email protected]8e4560b62011-01-14 10:09:141128 // if all of them are finished. So we check them first.
[email protected]94fde232012-04-27 10:22:301129 if (AreAllExternalProvidersReady())
1130 OnAllExternalProvidersReady();
1131}
1132
1133bool ExtensionService::AreAllExternalProvidersReady() const {
achuith2f5578b2016-02-26 21:57:131134 for (const auto& provider : external_extension_providers_) {
1135 if (!provider->IsReady())
[email protected]94fde232012-04-27 10:22:301136 return false;
[email protected]8e4560b62011-01-14 10:09:141137 }
[email protected]94fde232012-04-27 10:22:301138 return true;
[email protected]50067e52011-10-20 23:17:071139}
1140
1141void ExtensionService::OnAllExternalProvidersReady() {
Istiaque Ahmedf6e72622017-09-08 23:14:171142 DCHECK_CURRENTLY_ON(BrowserThread::UI);
Alexander Hendrich1918bfad2020-01-30 00:18:231143
1144#if defined(OS_CHROMEOS)
1145 InstallLimiter::Get(profile_)->OnAllExternalProvidersReady();
1146#endif // defined(OS_CHROMEOS)
1147
[email protected]50067e52011-10-20 23:17:071148 // Install any pending extensions.
[email protected]94fde232012-04-27 10:22:301149 if (update_once_all_providers_are_ready_ && updater()) {
1150 update_once_all_providers_are_ready_ = false;
Devlin Cronineea1b7a2018-05-26 02:46:211151 ExtensionUpdater::CheckParams params;
Minh X. Nguyen722b9682018-04-25 21:46:481152 params.callback =
1153 external_updates_finished_callback_.is_null()
1154 ? base::OnceClosure()
1155 : base::BindOnce(
1156 [](base::RepeatingClosure callback) { callback.Run(); },
1157 external_updates_finished_callback_);
Devlin Cronin2b3acda2019-05-30 19:11:371158 // We have to mark high-priority extensions (such as policy-forced
1159 // extensions or external component extensions) with foreground fetch
1160 // priority; otherwise their installation may be throttled by bandwidth
1161 // limits.
1162 // See https://crbug.com/904600 and https://crbug.com/965686.
1163 if (pending_extension_manager_.HasHighPriorityPendingExtension()) {
Oleg Davydov6541a64f2019-04-17 13:17:331164 params.fetch_priority = ManifestFetchData::FOREGROUND;
1165 }
Minh X. Nguyen722b9682018-04-25 21:46:481166 updater()->CheckNow(std::move(params));
[email protected]8e4560b62011-01-14 10:09:141167 }
1168
1169 // Uninstall all the unclaimed extensions.
Devlin Cronineea1b7a2018-05-26 02:46:211170 std::unique_ptr<ExtensionPrefs::ExtensionsInfo> extensions_info(
[email protected]8e4560b62011-01-14 10:09:141171 extension_prefs_->GetInstalledExtensionsInfo());
1172 for (size_t i = 0; i < extensions_info->size(); ++i) {
1173 ExtensionInfo* info = extensions_info->at(i).get();
[email protected]1d5e58b2013-01-31 08:41:401174 if (Manifest::IsExternalLocation(info->extension_location))
[email protected]8e4560b62011-01-14 10:09:141175 CheckExternalUninstall(info->extension_id);
1176 }
[email protected]e5af875f2011-10-10 21:09:141177
[email protected]373daf972014-04-10 01:50:441178 error_controller_->ShowErrorIfNeeded();
[email protected]a9aa5932012-01-25 08:27:401179
[email protected]374ceb6f2014-07-02 19:25:341180 external_install_manager_->UpdateExternalExtensionAlert();
[email protected]e5af875f2011-10-10 21:09:141181}
1182
limasdf0deef2042017-05-03 19:17:171183void ExtensionService::UnloadExtension(const std::string& extension_id,
1184 UnloadedExtensionReason reason) {
Devlin Cronin5b35a082017-10-05 20:44:361185 extension_registrar_.RemoveExtension(extension_id, reason);
[email protected]631cf822009-05-15 07:01:251186}
1187
[email protected]8b1ec202013-09-05 02:09:501188void ExtensionService::RemoveComponentExtension(
1189 const std::string& extension_id) {
1190 scoped_refptr<const Extension> extension(
David Bertonia0b34722019-09-30 20:51:261191 registry_->enabled_extensions().GetByID(extension_id));
limasdf0deef2042017-05-03 19:17:171192 UnloadExtension(extension_id, UnloadedExtensionReason::UNINSTALL);
[email protected]ebe07772014-05-22 04:16:061193 if (extension.get()) {
[email protected]e43c61f2014-07-20 21:46:341194 ExtensionRegistry::Get(profile_)->TriggerOnUninstalled(
Devlin Cronineea1b7a2018-05-26 02:46:211195 extension.get(), UNINSTALL_REASON_COMPONENT_REMOVED);
[email protected]ebe07772014-05-22 04:16:061196 }
[email protected]8b1ec202013-09-05 02:09:501197}
1198
[email protected]bb1bc9b32013-12-21 03:09:141199void ExtensionService::UnloadAllExtensionsForTest() {
1200 UnloadAllExtensionsInternal();
[email protected]9f1087e2009-06-15 17:29:321201}
1202
[email protected]bb1bc9b32013-12-21 03:09:141203void ExtensionService::ReloadExtensionsForTest() {
1204 // Calling UnloadAllExtensionsForTest here triggers a false-positive presubmit
1205 // warning about calling test code in production.
1206 UnloadAllExtensionsInternal();
[email protected]eac88332012-12-26 17:57:451207 component_loader_->LoadAll();
Devlin Cronineea1b7a2018-05-26 02:46:211208 InstalledLoader(this).LoadAllExtensions();
rdevlin.croninf2e1cb012017-05-27 01:27:591209 OnInstalledExtensionsLoaded();
[email protected]4a10006a2013-05-17 23:18:351210 // Don't call SetReadyAndNotifyListeners() since tests call this multiple
1211 // times.
[email protected]9f1087e2009-06-15 17:29:321212}
1213
[email protected]820d9bd2013-04-03 03:46:031214void ExtensionService::SetReadyAndNotifyListeners() {
rkaplowa8fd8d32015-02-25 21:27:561215 TRACE_EVENT0("browser,startup",
1216 "ExtensionService::SetReadyAndNotifyListeners");
1217 SCOPED_UMA_HISTOGRAM_TIMER(
1218 "Extensions.ExtensionServiceNotifyReadyListenersTime");
1219
[email protected]4a10006a2013-05-17 23:18:351220 ready_->Signal();
[email protected]820d9bd2013-04-03 03:46:031221 content::NotificationService::current()->Notify(
Devlin Cronineea1b7a2018-05-26 02:46:211222 NOTIFICATION_EXTENSIONS_READY_DEPRECATED,
[email protected]820d9bd2013-04-03 03:46:031223 content::Source<Profile>(profile_),
1224 content::NotificationService::NoDetails());
1225}
1226
[email protected]fcb58a862012-05-01 01:03:151227void ExtensionService::AddExtension(const Extension* extension) {
rdevlin.cronin08ada0f2017-03-09 23:29:521228 if (!Manifest::IsValidLocation(extension->location())) {
1229 // TODO(devlin): We should *never* add an extension with an invalid
1230 // location, but some bugs (e.g. crbug.com/692069) seem to indicate we do.
1231 // Track down the cases when this can happen, and remove this
1232 // DumpWithoutCrashing() (possibly replacing it with a CHECK).
1233 NOTREACHED();
Lukasz Anforowicz68c21772018-01-13 03:42:441234 DEBUG_ALIAS_FOR_CSTR(extension_id_copy, extension->id().c_str(), 33);
rdevlin.cronin08ada0f2017-03-09 23:29:521235 Manifest::Location location = extension->location();
1236 int creation_flags = extension->creation_flags();
1237 Manifest::Type type = extension->manifest()->type();
rdevlin.cronin08ada0f2017-03-09 23:29:521238 base::debug::Alias(&location);
1239 base::debug::Alias(&creation_flags);
1240 base::debug::Alias(&type);
1241 base::debug::DumpWithoutCrashing();
1242 return;
1243 }
1244
[email protected]c8d407e2011-04-28 21:27:171245 // TODO(jstritar): We may be able to get rid of this branch by overriding the
1246 // default extension state to DISABLED when the --disable-extensions flag
1247 // is set (http://crbug.com/29067).
Devlin Croninefe0c882018-04-20 00:06:481248 if (!extensions_enabled_ &&
1249 !Manifest::ShouldAlwaysLoadExtension(extension->location(),
Devlin Cronin8c23eec2018-05-01 18:42:281250 extension->is_theme()) &&
catmullings98cd1942016-08-30 22:31:591251 disable_flag_exempted_extensions_.count(extension->id()) == 0) {
[email protected]fcb58a862012-05-01 01:03:151252 return;
[email protected]330840c2012-08-29 22:21:011253 }
[email protected]c8d407e2011-04-28 21:27:171254
Michael Giuffrida573992d2018-02-08 00:48:441255 extension_registrar_.AddExtension(extension);
Michael Giuffrida023e3532017-09-28 23:21:211256
Michael Giuffrida573992d2018-02-08 00:48:441257 if (registry_->disabled_extensions().Contains(extension->id())) {
1258 // Show the extension disabled error if a permissions increase or a remote
1259 // installation is the reason it was disabled, and no other reasons exist.
1260 int reasons = extension_prefs_->GetDisableReasons(extension->id());
Devlin Cronineea1b7a2018-05-26 02:46:211261 const int kReasonMask = disable_reason::DISABLE_PERMISSIONS_INCREASE |
1262 disable_reason::DISABLE_REMOTE_INSTALL;
Michael Giuffrida573992d2018-02-08 00:48:441263 if (reasons & kReasonMask && !(reasons & ~kReasonMask)) {
1264 AddExtensionDisabledError(
1265 this, extension,
1266 extension_prefs_->HasDisableReason(
Devlin Cronineea1b7a2018-05-26 02:46:211267 extension->id(), disable_reason::DISABLE_REMOTE_INSTALL));
Michael Giuffrida6397c592017-10-09 20:46:531268 }
[email protected]f574c402012-12-04 23:20:311269 }
[email protected]aab98a52009-12-02 03:22:351270}
1271
[email protected]8c484b742012-11-29 06:05:361272void ExtensionService::AddComponentExtension(const Extension* extension) {
Samuel Huang7987ebd2019-04-08 13:01:371273 extension_prefs_->ClearInapplicableDisableReasonsForComponentExtension(
1274 extension->id());
[email protected]8c484b742012-11-29 06:05:361275 const std::string old_version_string(
1276 extension_prefs_->GetVersionString(extension->id()));
pwnallcbd73192016-08-22 18:59:171277 const base::Version old_version(old_version_string);
[email protected]8c484b742012-11-29 06:05:361278
[email protected]0181a7d2013-11-12 01:08:421279 VLOG(1) << "AddComponentExtension " << extension->name();
Devlin Cronin03bf2d22017-12-20 08:21:051280 if (!old_version.IsValid() || old_version != extension->version()) {
[email protected]8c484b742012-11-29 06:05:361281 VLOG(1) << "Component extension " << extension->name() << " ("
Devlin Cronin03bf2d22017-12-20 08:21:051282 << extension->id() << ") installing/upgrading from '"
1283 << old_version_string << "' to "
1284 << extension->version().GetString();
[email protected]8c484b742012-11-29 06:05:361285
Karandeep Bhatiaa8930652017-10-11 17:41:121286 // TODO(crbug.com/696822): If needed, add support for Declarative Net
1287 // Request to component extensions and pass the ruleset checksum here.
Devlin Cronineea1b7a2018-05-26 02:46:211288 AddNewOrUpdatedExtension(extension, Extension::ENABLED, kInstallFlagNone,
1289 syncer::StringOrdinal(), std::string(),
1290 base::nullopt);
[email protected]8c484b742012-11-29 06:05:361291 return;
1292 }
1293
1294 AddExtension(extension);
1295}
1296
[email protected]b914e292013-04-26 07:10:031297void ExtensionService::CheckPermissionsIncrease(const Extension* extension,
treib6e51bca2016-06-15 10:26:031298 bool is_extension_loaded) {
Devlin Cronineea1b7a2018-05-26 02:46:211299 PermissionsUpdater(profile_).InitializePermissions(extension);
[email protected]902fd7b2011-07-27 18:42:311300
[email protected]8d888c12010-11-30 00:00:251301 // We keep track of all permissions the user has granted each extension.
1302 // This allows extensions to gracefully support backwards compatibility
1303 // by including unknown permissions in their manifests. When the user
1304 // installs the extension, only the recognized permissions are recorded.
1305 // When the unknown permissions become recognized (e.g., through browser
1306 // upgrade), we can prompt the user to accept these new permissions.
1307 // Extensions can also silently upgrade to less permissions, and then
1308 // silently upgrade to a version that adds these permissions back.
1309 //
1310 // For example, pretend that Chrome 10 includes a permission "omnibox"
1311 // for an API that adds suggestions to the omnibox. An extension can
1312 // maintain backwards compatibility while still having "omnibox" in the
1313 // manifest. If a user installs the extension on Chrome 9, the browser
1314 // will record the permissions it recognized, not including "omnibox."
1315 // When upgrading to Chrome 10, "omnibox" will be recognized and Chrome
1316 // will disable the extension and prompt the user to approve the increase
1317 // in privileges. The extension could then release a new version that
1318 // removes the "omnibox" permission. When the user upgrades, Chrome will
1319 // still remember that "omnibox" had been granted, so that if the
1320 // extension once again includes "omnibox" in an upgrade, the extension
1321 // can upgrade without requiring this user's approval.
[email protected]eb5e4f92012-08-15 23:33:281322 int disable_reasons = extension_prefs_->GetDisableReasons(extension->id());
[email protected]8d888c12010-11-30 00:00:251323
rockot1d4a06262015-02-17 19:39:281324 // Silently grant all active permissions to default apps and apps installed
1325 // in kiosk mode.
[email protected]211a3f32013-05-28 21:48:181326 bool auto_grant_permission =
rockot1d4a06262015-02-17 19:39:281327 extension->was_installed_by_default() ||
Devlin Cronineea1b7a2018-05-26 02:46:211328 ExtensionsBrowserClient::Get()->IsRunningInForcedAppMode();
[email protected]211a3f32013-05-28 21:48:181329 if (auto_grant_permission)
[email protected]b914e292013-04-26 07:10:031330 GrantPermissions(extension);
1331
1332 bool is_privilege_increase = false;
1333 // We only need to compare the granted permissions to the current permissions
rockot1d4a06262015-02-17 19:39:281334 // if the extension has not been auto-granted its permissions above and is
1335 // installed internally.
1336 if (extension->location() == Manifest::INTERNAL && !auto_grant_permission) {
[email protected]8d888c12010-11-30 00:00:251337 // Add all the recognized permissions if the granted permissions list
1338 // hasn't been initialized yet.
dchengc963c7142016-04-08 03:55:221339 std::unique_ptr<const PermissionSet> granted_permissions =
[email protected]902fd7b2011-07-27 18:42:311340 extension_prefs_->GetGrantedPermissions(extension->id());
[email protected]0d3e4a22011-06-23 19:02:521341 CHECK(granted_permissions.get());
Tim Judkins1e98a2a2020-01-06 20:57:581342 // We check the union of both granted permissions and runtime granted
1343 // permissions as it is possible for permissions which were withheld during
1344 // installation to have never entered the granted set, but to have later
1345 // been granted as runtime permissions.
1346 std::unique_ptr<const PermissionSet> runtime_granted_permissions =
1347 extension_prefs_->GetRuntimeGrantedPermissions(extension->id());
1348 std::unique_ptr<const PermissionSet> total_permissions =
1349 PermissionSet::CreateUnion(*granted_permissions,
1350 *runtime_granted_permissions);
[email protected]8d888c12010-11-30 00:00:251351
1352 // Here, we check if an extension's privileges have increased in a manner
1353 // that requires the user's approval. This could occur because the browser
1354 // upgraded and recognized additional privileges, or an extension upgrades
1355 // to a version that requires additional privileges.
[email protected]c41003472013-10-19 15:37:251356 is_privilege_increase =
Devlin Cronineea1b7a2018-05-26 02:46:211357 PermissionMessageProvider::Get()->IsPrivilegeIncrease(
Tim Judkins1e98a2a2020-01-06 20:57:581358 *total_permissions,
rdevlin.cronine2d0fd02015-09-24 22:35:491359 extension->permissions_data()->active_permissions(),
[email protected]076ebeda2014-06-06 21:47:261360 extension->GetType());
treib2c20f9442016-05-18 19:50:281361
1362 // If there was no privilege increase, the extension might still have new
1363 // permissions (which either don't generate a warning message, or whose
1364 // warning messages are suppressed by existing permissions). Grant the new
1365 // permissions.
1366 if (!is_privilege_increase)
1367 GrantPermissions(extension);
[email protected]8d888c12010-11-30 00:00:251368 }
1369
Marc Treib4bdb790b2018-07-07 15:02:481370 // TODO(crbug.com/860198): Before M48, extensions that came to us from sync in
1371 // a disabled state got assigned disable_reason::DISABLE_UNKNOWN_FROM_SYNC.
1372 // That reason isn't used anymore since the actual disable reason(s) are now
1373 // synced. This code is here to migrate any existing old state.
1374 if (disable_reasons & disable_reason::DEPRECATED_DISABLE_UNKNOWN_FROM_SYNC) {
1375 // Remove the disable_reason::DEPRECATED_DISABLE_UNKNOWN_FROM_SYNC
1376 // reason.
1377 disable_reasons &= ~disable_reason::DEPRECATED_DISABLE_UNKNOWN_FROM_SYNC;
1378 extension_prefs_->RemoveDisableReason(
1379 extension->id(), disable_reason::DEPRECATED_DISABLE_UNKNOWN_FROM_SYNC);
1380 // If there was no privilege increase, it was likely disabled by the user.
1381 // (If there *was* a privilege increase, we'll add an appropriate reason
1382 // later on, so nothing needs to be done here.)
1383 if (!is_privilege_increase)
1384 disable_reasons |= disable_reason::DISABLE_USER_ACTION;
1385 }
1386
treib6e51bca2016-06-15 10:26:031387 bool previously_disabled =
1388 extension_prefs_->IsExtensionDisabled(extension->id());
Marc Treib4bdb790b2018-07-07 15:02:481389 // TODO(devlin): Is the |is_extension_loaded| check needed here?
treib6e51bca2016-06-15 10:26:031390 if (is_extension_loaded && previously_disabled) {
treib8a6d9892015-08-26 10:23:191391 // Legacy disabled extensions do not have a disable reason. Infer that it
1392 // was likely disabled by the user.
Devlin Cronineea1b7a2018-05-26 02:46:211393 if (disable_reasons == disable_reason::DISABLE_NONE)
1394 disable_reasons |= disable_reason::DISABLE_USER_ACTION;
[email protected]8d888c12010-11-30 00:00:251395 }
1396
treib6e51bca2016-06-15 10:26:031397 // If the extension is disabled due to a permissions increase, but does in
1398 // fact have all permissions, remove that disable reason.
1399 // TODO(devlin): This was added to fix crbug.com/616474, but it's unclear
1400 // if this behavior should stay forever.
Devlin Cronineea1b7a2018-05-26 02:46:211401 if (disable_reasons & disable_reason::DISABLE_PERMISSIONS_INCREASE) {
treib6e51bca2016-06-15 10:26:031402 bool reset_permissions_increase = false;
1403 if (!is_privilege_increase) {
1404 reset_permissions_increase = true;
Devlin Cronineea1b7a2018-05-26 02:46:211405 disable_reasons &= ~disable_reason::DISABLE_PERMISSIONS_INCREASE;
treib6e51bca2016-06-15 10:26:031406 extension_prefs_->RemoveDisableReason(
Devlin Cronineea1b7a2018-05-26 02:46:211407 extension->id(), disable_reason::DISABLE_PERMISSIONS_INCREASE);
treib6e51bca2016-06-15 10:26:031408 }
1409 UMA_HISTOGRAM_BOOLEAN("Extensions.ResetPermissionsIncrease",
1410 reset_permissions_increase);
1411 }
1412
[email protected]8d888c12010-11-30 00:00:251413 // Extension has changed permissions significantly. Disable it. A
[email protected]21db9ef2014-05-16 02:06:271414 // notification should be sent by the caller. If the extension is already
1415 // disabled because it was installed remotely, don't add another disable
treibaac30ec2015-06-10 09:18:091416 // reason.
1417 if (is_privilege_increase &&
Devlin Cronineea1b7a2018-05-26 02:46:211418 !(disable_reasons & disable_reason::DISABLE_REMOTE_INSTALL)) {
1419 disable_reasons |= disable_reason::DISABLE_PERMISSIONS_INCREASE;
treib8a6d9892015-08-26 10:23:191420 if (!extension_prefs_->DidExtensionEscalatePermissions(extension->id()))
treib2e0517f92015-05-07 23:15:361421 RecordPermissionMessagesHistogram(extension, "AutoDisable");
[email protected]b914e292013-04-26 07:10:031422 }
treib6e51bca2016-06-15 10:26:031423
Devlin Cronineea1b7a2018-05-26 02:46:211424 if (disable_reasons == disable_reason::DISABLE_NONE)
treib6e51bca2016-06-15 10:26:031425 extension_prefs_->SetExtensionEnabled(extension->id());
1426 else
treib8a6d9892015-08-26 10:23:191427 extension_prefs_->SetExtensionDisabled(extension->id(), disable_reasons);
[email protected]8d888c12010-11-30 00:00:251428}
1429
[email protected]eaa7dd182010-12-14 11:09:001430void ExtensionService::UpdateActiveExtensionsInCrashReporter() {
[email protected]c8865962009-12-16 07:47:391431 std::set<std::string> extension_ids;
achuith2f5578b2016-02-26 21:57:131432 for (const auto& extension : registry_->enabled_extensions()) {
[email protected]1d5e58b2013-01-31 08:41:401433 if (!extension->is_theme() && extension->location() != Manifest::COMPONENT)
[email protected]84df8332011-12-06 18:22:461434 extension_ids.insert(extension->id());
[email protected]aab98a52009-12-02 03:22:351435 }
1436
[email protected]dcc47642014-03-26 22:03:491437 // TODO(kalman): This is broken. ExtensionService is per-profile.
1438 // crash_keys::SetActiveExtensions is per-process. See
1439 // http://crbug.com/355029.
[email protected]f6431be82013-09-07 02:53:451440 crash_keys::SetActiveExtensions(extension_ids);
[email protected]6014d672008-12-05 00:38:251441}
1442
[email protected]8266d662011-07-12 21:53:261443void ExtensionService::OnExtensionInstalled(
[email protected]36a5c4c2011-12-14 16:34:501444 const Extension* extension,
[email protected]98270432012-09-11 20:51:241445 const syncer::StringOrdinal& page_ordinal,
Karandeep Bhatiaa8930652017-10-11 17:41:121446 int install_flags,
1447 const base::Optional<int>& dnr_ruleset_checksum) {
[email protected]a29a517a2011-01-21 21:11:121448 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]a8af9fdb2010-10-28 21:52:201449
[email protected]c3cfb012011-04-06 22:07:351450 const std::string& id = extension->id();
binjin47947f842014-11-18 12:10:241451 int disable_reasons = GetDisableReasonsOnInstalled(extension);
[email protected]d8fd0fd2014-03-24 13:16:061452 std::string install_parameter;
Devlin Cronineea1b7a2018-05-26 02:46:211453 const PendingExtensionInfo* pending_extension_info =
[email protected]96aebe22014-07-16 04:07:511454 pending_extension_manager()->GetById(id);
1455 if (pending_extension_info) {
[email protected]8f3bcbd2013-06-05 08:42:401456 if (!pending_extension_info->ShouldAllowInstall(extension)) {
Devlinec30d362018-07-13 18:13:391457 // Hack for crbug.com/558299, see comment on DeleteThemeDoNotUse.
1458 if (extension->is_theme() && pending_extension_info->is_from_sync())
1459 ExtensionSyncService::Get(profile_)->DeleteThemeDoNotUse(*extension);
1460
[email protected]51a3bf8b2012-06-08 22:53:061461 pending_extension_manager()->Remove(id);
[email protected]8ef78fd2010-08-19 17:14:321462
Devlin Cronineea1b7a2018-05-26 02:46:211463 LOG(WARNING) << "ShouldAllowInstall() returned false for " << id
1464 << " of type " << extension->GetType() << " and update URL "
1465 << ManifestURL::GetUpdateURL(extension).spec()
[email protected]31bb5ee62012-09-12 22:58:401466 << "; not installing";
[email protected]ae6cb3022011-04-04 20:11:541467
[email protected]4416c5a2010-06-26 01:28:571468 // Delete the extension directory since we're not going to
1469 // load it.
Devlin Cronineea1b7a2018-05-26 02:46:211470 if (!GetExtensionFileTaskRunner()->PostTask(
1471 FROM_HERE, base::BindOnce(&file_util::DeleteFile,
tzik8d880ee2017-04-20 19:46:241472 extension->path(), true))) {
[email protected]14908b72011-04-20 06:54:361473 NOTREACHED();
[email protected]31bb5ee62012-09-12 22:58:401474 }
[email protected]4416c5a2010-06-26 01:28:571475 return;
1476 }
[email protected]51a3bf8b2012-06-08 22:53:061477
[email protected]d8fd0fd2014-03-24 13:16:061478 install_parameter = pending_extension_info->install_parameter();
[email protected]51a3bf8b2012-06-08 22:53:061479 pending_extension_manager()->Remove(id);
[email protected]4416c5a2010-06-26 01:28:571480 } else {
[email protected]c3cfb012011-04-06 22:07:351481 // We explicitly want to re-enable an uninstalled external
1482 // extension; if we're here, that means the user is manually
1483 // installing the extension.
[email protected]46f3e102014-03-25 01:22:451484 if (extension_prefs_->IsExternalExtensionUninstalled(id)) {
Devlin Cronineea1b7a2018-05-26 02:46:211485 disable_reasons = disable_reason::DISABLE_NONE;
[email protected]6cc7dbae2011-04-29 21:18:331486 }
[email protected]aa142702010-03-26 01:26:331487 }
1488
asargente4de9f92016-09-15 01:40:061489 // If the old version of the extension was disabled due to corruption, this
1490 // new install may correct the problem.
Devlin Cronineea1b7a2018-05-26 02:46:211491 disable_reasons &= ~disable_reason::DISABLE_CORRUPTED;
asargente4de9f92016-09-15 01:40:061492
[email protected]98270432012-09-11 20:51:241493 // Unsupported requirements overrides the management policy.
Devlin Cronineea1b7a2018-05-26 02:46:211494 if (install_flags & kInstallFlagHasRequirementErrors) {
1495 disable_reasons |= disable_reason::DISABLE_UNSUPPORTED_REQUIREMENT;
binjin8e3d0182014-12-04 16:44:281496 } else {
1497 // Requirement is supported now, remove the corresponding disable reason
1498 // instead.
Devlin Cronineea1b7a2018-05-26 02:46:211499 disable_reasons &= ~disable_reason::DISABLE_UNSUPPORTED_REQUIREMENT;
binjin8e3d0182014-12-04 16:44:281500 }
1501
1502 // Check if the extension was disabled because of the minimum version
1503 // requirements from enterprise policy, and satisfies it now.
Devlin Cronineea1b7a2018-05-26 02:46:211504 if (ExtensionManagementFactory::GetForBrowserContext(profile())
binjin8e3d0182014-12-04 16:44:281505 ->CheckMinimumVersion(extension, nullptr)) {
1506 // And remove the corresponding disable reason.
Devlin Cronineea1b7a2018-05-26 02:46:211507 disable_reasons &= ~disable_reason::DISABLE_UPDATE_REQUIRED_BY_POLICY;
[email protected]98270432012-09-11 20:51:241508 }
1509
Devlin Cronineea1b7a2018-05-26 02:46:211510 if (install_flags & kInstallFlagIsBlacklistedForMalware) {
[email protected]9f3c8532013-07-31 19:52:071511 // Installation of a blacklisted extension can happen from sync, policy,
1512 // etc, where to maintain consistency we need to install it, just never
1513 // load it (see AddExtension). Usually it should be the job of callers to
treibaac30ec2015-06-10 09:18:091514 // intercept blacklisted extensions earlier (e.g. CrxInstaller, before even
[email protected]9f3c8532013-07-31 19:52:071515 // showing the install dialogue).
[email protected]7c82539c2014-02-19 06:09:171516 extension_prefs_->AcknowledgeBlacklistedExtension(id);
[email protected]9f3c8532013-07-31 19:52:071517 UMA_HISTOGRAM_ENUMERATION("ExtensionBlacklist.SilentInstall",
1518 extension->location(),
1519 Manifest::NUM_LOCATIONS);
1520 }
1521
David Bertoni9f897c92019-09-20 17:46:351522 if (!registry_->GetInstalledExtension(extension->id())) {
[email protected]07533022011-06-27 20:42:551523 UMA_HISTOGRAM_ENUMERATION("Extensions.InstallType",
1524 extension->GetType(), 100);
[email protected]69084dc2012-11-17 07:39:301525 UMA_HISTOGRAM_ENUMERATION("Extensions.InstallSource",
[email protected]1d5e58b2013-01-31 08:41:401526 extension->location(), Manifest::NUM_LOCATIONS);
treib2e0517f92015-05-07 23:15:361527 RecordPermissionMessagesHistogram(extension, "Install");
[email protected]69084dc2012-11-17 07:39:301528 } else {
1529 UMA_HISTOGRAM_ENUMERATION("Extensions.UpdateType",
1530 extension->GetType(), 100);
1531 UMA_HISTOGRAM_ENUMERATION("Extensions.UpdateSource",
[email protected]1d5e58b2013-01-31 08:41:401532 extension->location(), Manifest::NUM_LOCATIONS);
[email protected]07533022011-06-27 20:42:551533 }
1534
[email protected]399583b2012-12-11 09:33:421535 const Extension::State initial_state =
Devlin Cronineea1b7a2018-05-26 02:46:211536 disable_reasons == disable_reason::DISABLE_NONE ? Extension::ENABLED
1537 : Extension::DISABLED;
treib8a6d9892015-08-26 10:23:191538 if (initial_state == Extension::ENABLED)
1539 extension_prefs_->SetExtensionEnabled(id);
1540 else
1541 extension_prefs_->SetExtensionDisabled(id, disable_reasons);
binjin47947f842014-11-18 12:10:241542
Devlin Cronineea1b7a2018-05-26 02:46:211543 ExtensionPrefs::DelayReason delay_reason;
1544 InstallGate::Action action = ShouldDelayExtensionInstall(
1545 extension, !!(install_flags & kInstallFlagInstallImmediately),
xiyuanf6a4c6a62016-04-19 18:14:541546 &delay_reason);
1547 switch (action) {
Devlin Cronineea1b7a2018-05-26 02:46:211548 case InstallGate::INSTALL:
xiyuanf6a4c6a62016-04-19 18:14:541549 AddNewOrUpdatedExtension(extension, initial_state, install_flags,
Karandeep Bhatiaa8930652017-10-11 17:41:121550 page_ordinal, install_parameter,
1551 dnr_ruleset_checksum);
xiyuanf6a4c6a62016-04-19 18:14:541552 return;
Devlin Cronineea1b7a2018-05-26 02:46:211553 case InstallGate::DELAY:
Karandeep Bhatiaa8930652017-10-11 17:41:121554 extension_prefs_->SetDelayedInstallInfo(
1555 extension, initial_state, install_flags, delay_reason, page_ordinal,
1556 install_parameter, dnr_ruleset_checksum);
[email protected]0db124b02012-11-07 04:55:051557
xiyuanf6a4c6a62016-04-19 18:14:541558 // Transfer ownership of |extension|.
[email protected]9f4e4f082013-06-21 07:11:191559 delayed_installs_.Insert(extension);
xiyuanf6a4c6a62016-04-19 18:14:541560
Devlin Cronineea1b7a2018-05-26 02:46:211561 if (delay_reason == ExtensionPrefs::DELAY_REASON_WAIT_FOR_IDLE) {
xiyuanf6a4c6a62016-04-19 18:14:541562 // Notify observers that app update is available.
ericwilligersb5f79de2016-10-19 04:15:101563 for (auto& observer : update_observers_)
1564 observer.OnAppUpdateAvailable(extension);
xiyuanf6a4c6a62016-04-19 18:14:541565 }
1566 return;
Devlin Cronineea1b7a2018-05-26 02:46:211567 case InstallGate::ABORT:
xiyuanf6a4c6a62016-04-19 18:14:541568 // Do nothing to abort the install. One such case is the shared module
1569 // service gets IMPORT_STATUS_UNRECOVERABLE status for the pending
1570 // install.
1571 return;
[email protected]399583b2012-12-11 09:33:421572 }
xiyuanf6a4c6a62016-04-19 18:14:541573
1574 NOTREACHED() << "Unknown action for delayed install: " << action;
[email protected]8c484b742012-11-29 06:05:361575}
1576
binjin1569c9b2014-09-05 13:33:181577void ExtensionService::OnExtensionManagementSettingsChanged() {
1578 error_controller_->ShowErrorIfNeeded();
binjine6b58b52014-10-31 01:55:571579
1580 // Revokes blocked permissions from active_permissions for all extensions.
Devlin Cronineea1b7a2018-05-26 02:46:211581 ExtensionManagement* settings =
1582 ExtensionManagementFactory::GetForBrowserContext(profile());
binjine6b58b52014-10-31 01:55:571583 CHECK(settings);
dchengc963c7142016-04-08 03:55:221584 std::unique_ptr<ExtensionSet> all_extensions(
binjine6b58b52014-10-31 01:55:571585 registry_->GenerateInstalledExtensionsSet());
achuith2f5578b2016-02-26 21:57:131586 for (const auto& extension : *all_extensions) {
binjine6b58b52014-10-31 01:55:571587 if (!settings->IsPermissionSetAllowed(
binjin685ade82014-11-06 09:53:561588 extension.get(),
Nick Peterson0203be4a2017-07-19 00:25:141589 extension->permissions_data()->active_permissions()) &&
1590 CanBlockExtension(extension.get())) {
Devlin Cronineea1b7a2018-05-26 02:46:211591 PermissionsUpdater(profile()).RemovePermissionsUnsafe(
rdevlin.cronind630c302015-09-30 20:19:331592 extension.get(), *settings->GetBlockedPermissions(extension.get()));
binjine6b58b52014-10-31 01:55:571593 }
1594 }
1595
binjin1569c9b2014-09-05 13:33:181596 CheckManagementPolicy();
1597}
1598
[email protected]8c484b742012-11-29 06:05:361599void ExtensionService::AddNewOrUpdatedExtension(
1600 const Extension* extension,
[email protected]399583b2012-12-11 09:33:421601 Extension::State initial_state,
[email protected]4a1d9c0d2014-06-13 12:50:111602 int install_flags,
[email protected]d8fd0fd2014-03-24 13:16:061603 const syncer::StringOrdinal& page_ordinal,
Karandeep Bhatiaa8930652017-10-11 17:41:121604 const std::string& install_parameter,
1605 const base::Optional<int>& dnr_ruleset_checksum) {
[email protected]8c484b742012-11-29 06:05:361606 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
Karandeep Bhatiaa8930652017-10-11 17:41:121607 extension_prefs_->OnExtensionInstalled(extension, initial_state, page_ordinal,
1608 install_flags, install_parameter,
1609 dnr_ruleset_checksum);
[email protected]9e9c1d12013-07-31 01:58:121610 delayed_installs_.Remove(extension->id());
[email protected]913ffca92014-03-27 15:26:161611 if (InstallVerifier::NeedsVerification(*extension))
juncai33e462102015-05-18 20:48:441612 InstallVerifier::Get(GetBrowserContext())->VerifyExtension(extension->id());
ryanackley48bedbd2015-01-27 23:12:141613
David Bertoni9f897c92019-09-20 17:46:351614 const Extension* old = registry_->GetInstalledExtension(extension->id());
Devlin Cronineea1b7a2018-05-26 02:46:211615 if (AppDataMigrator::NeedsMigration(old, extension)) {
ryanackley48bedbd2015-01-27 23:12:141616 app_data_migrator_->DoMigrationAndReply(
Adrienne Walkerf56fc9fc2020-01-24 23:01:481617 old, extension,
1618 base::BindOnce(&ExtensionService::FinishInstallation, AsWeakPtr(),
1619 base::RetainedRef(extension)));
ryanackley48bedbd2015-01-27 23:12:141620 return;
1621 }
1622
benwells1dd4acd2015-12-09 02:20:241623 FinishInstallation(extension);
[email protected]6f6101832012-11-27 22:10:481624}
1625
Toni Barzic667db0d32018-01-09 18:00:191626bool ExtensionService::FinishDelayedInstallationIfReady(
1627 const std::string& extension_id,
1628 bool install_immediately) {
[email protected]9f4e4f082013-06-21 07:11:191629 // Check if the extension already got installed.
[email protected]9f4e4f082013-06-21 07:11:191630 const Extension* extension = delayed_installs_.GetByID(extension_id);
xiyuanf6a4c6a62016-04-19 18:14:541631 if (!extension)
Toni Barzic667db0d32018-01-09 18:00:191632 return false;
xiyuanf6a4c6a62016-04-19 18:14:541633
Devlin Cronineea1b7a2018-05-26 02:46:211634 ExtensionPrefs::DelayReason reason;
1635 const InstallGate::Action action =
Toni Barzic667db0d32018-01-09 18:00:191636 ShouldDelayExtensionInstall(extension, install_immediately, &reason);
xiyuanf6a4c6a62016-04-19 18:14:541637 switch (action) {
Devlin Cronineea1b7a2018-05-26 02:46:211638 case InstallGate::INSTALL:
xiyuanf6a4c6a62016-04-19 18:14:541639 break;
Devlin Cronineea1b7a2018-05-26 02:46:211640 case InstallGate::DELAY:
xiyuanf6a4c6a62016-04-19 18:14:541641 // Bail out and continue to delay the install.
Toni Barzic667db0d32018-01-09 18:00:191642 return false;
Devlin Cronineea1b7a2018-05-26 02:46:211643 case InstallGate::ABORT:
xiyuanf6a4c6a62016-04-19 18:14:541644 delayed_installs_.Remove(extension_id);
1645 // Make sure no version of the extension is actually installed, (i.e.,
1646 // that this delayed install was not an update).
1647 CHECK(!extension_prefs_->GetInstalledExtensionInfo(extension_id).get());
1648 extension_prefs_->DeleteExtensionPrefs(extension_id);
Toni Barzic667db0d32018-01-09 18:00:191649 return false;
[email protected]9f4e4f082013-06-21 07:11:191650 }
1651
Toni Barzic667db0d32018-01-09 18:00:191652 scoped_refptr<const Extension> delayed_install =
1653 GetPendingExtensionUpdate(extension_id);
1654 CHECK(delayed_install.get());
[email protected]9f4e4f082013-06-21 07:11:191655 delayed_installs_.Remove(extension_id);
[email protected]6f6101832012-11-27 22:10:481656
[email protected]399583b2012-12-11 09:33:421657 if (!extension_prefs_->FinishDelayedInstallInfo(extension_id))
[email protected]6f6101832012-11-27 22:10:481658 NOTREACHED();
1659
Toni Barzic667db0d32018-01-09 18:00:191660 FinishInstallation(delayed_install.get());
1661 return true;
[email protected]6f6101832012-11-27 22:10:481662}
1663
[email protected]760f743b2014-05-28 13:52:021664void ExtensionService::FinishInstallation(
benwells1dd4acd2015-12-09 02:20:241665 const Extension* extension) {
David Bertoni9f897c92019-09-20 17:46:351666 const Extension* existing_extension =
1667 registry_->GetInstalledExtension(extension->id());
[email protected]e7554c3f2013-05-29 00:36:561668 bool is_update = false;
1669 std::string old_name;
1670 if (existing_extension) {
1671 is_update = true;
1672 old_name = existing_extension->name();
1673 }
[email protected]bc44b5da2014-06-12 14:20:001674 registry_->TriggerOnWillBeInstalled(
benwells1dd4acd2015-12-09 02:20:241675 extension, is_update, old_name);
[email protected]17f07822014-05-22 08:45:151676
[email protected]399583b2012-12-11 09:33:421677 // Unpacked extensions default to allowing file access, but if that has been
1678 // overridden, don't reset the value.
[email protected]1d5e58b2013-01-31 08:41:401679 if (Manifest::ShouldAlwaysAllowFileAccess(extension->location()) &&
[email protected]399583b2012-12-11 09:33:421680 !extension_prefs_->HasAllowFileAccessSetting(extension->id())) {
1681 extension_prefs_->SetAllowFileAccess(extension->id(), true);
1682 }
1683
[email protected]6f6101832012-11-27 22:10:481684 AddExtension(extension);
[email protected]612a1cb12012-10-17 13:18:031685
[email protected]bc44b5da2014-06-12 14:20:001686 // Notify observers that need to know when an installation is complete.
[email protected]38e872532014-07-16 23:27:511687 registry_->TriggerOnInstalled(extension, is_update);
[email protected]bc44b5da2014-06-12 14:20:001688
[email protected]9f4e4f082013-06-21 07:11:191689 // Check extensions that may have been delayed only because this shared module
1690 // was not available.
[email protected]374ceb6f2014-07-02 19:25:341691 if (SharedModuleInfo::IsSharedModule(extension))
[email protected]9f4e4f082013-06-21 07:11:191692 MaybeFinishDelayedInstallations();
[email protected]4a190632009-05-09 01:07:421693}
1694
Marc Grimmeefba8d22020-01-09 07:57:251695void ExtensionService::SetPolicySettingsForExtension(
1696 const Extension* extension) {
1697 ExtensionManagement* management =
1698 ExtensionManagementFactory::GetForBrowserContext(profile());
1699 if (management->UsesDefaultPolicyHostRestrictions(extension)) {
1700 PermissionsUpdater(profile()).SetUsesDefaultHostRestrictions(extension);
1701 } else {
1702 PermissionsUpdater(profile()).SetPolicyHostRestrictions(
1703 extension, management->GetPolicyBlockedHosts(extension),
1704 management->GetPolicyAllowedHosts(extension));
1705 }
1706}
1707
[email protected]76b65442012-11-17 14:11:481708const Extension* ExtensionService::GetPendingExtensionUpdate(
1709 const std::string& id) const {
[email protected]9f4e4f082013-06-21 07:11:191710 return delayed_installs_.GetByID(id);
[email protected]76b65442012-11-17 14:11:481711}
1712
mukai87a8d402014-09-15 20:15:091713void ExtensionService::RegisterContentSettings(
mmenkead5094ab2017-05-15 19:01:141714 HostContentSettingsMap* host_content_settings_map,
1715 Profile* profile) {
1716 // Most extension services key off of the original profile.
1717 Profile* original_profile = profile->GetOriginalProfile();
1718
rkaplowe65c2ff2015-02-14 16:29:541719 TRACE_EVENT0("browser,startup", "ExtensionService::RegisterContentSettings");
mukaia1aa3512014-10-22 20:14:111720 DCHECK_CURRENTLY_ON(BrowserThread::UI);
mukai87a8d402014-09-15 20:15:091721 host_content_settings_map->RegisterProvider(
mukai87a8d402014-09-15 20:15:091722 HostContentSettingsMap::CUSTOM_EXTENSION_PROVIDER,
dchengc963c7142016-04-08 03:55:221723 std::unique_ptr<content_settings::ObservableProvider>(
mukai87a8d402014-09-15 20:15:091724 new content_settings::CustomExtensionProvider(
Devlin Cronineea1b7a2018-05-26 02:46:211725 ContentSettingsService::Get(original_profile)
dchengc963c7142016-04-08 03:55:221726 ->content_settings_store(),
mmenkead5094ab2017-05-15 19:01:141727 // TODO(mmenke): CustomExtensionProvider expects this to be true
1728 // for incognito profiles.
1729 false)));
mukai87a8d402014-09-15 20:15:091730}
1731
[email protected]e9d7496e2014-04-18 01:25:461732void ExtensionService::TerminateExtension(const std::string& extension_id) {
Michael Giuffridafcb420362017-10-11 21:50:261733 extension_registrar_.TerminateExtension(extension_id);
[email protected]bb7f40952011-01-13 00:21:201734}
1735
[email protected]9060d8b02012-01-13 02:14:301736bool ExtensionService::OnExternalExtensionFileFound(
lazyboye8634172016-01-28 00:10:481737 const ExternalInstallInfoFile& info) {
Istiaque Ahmedf6e72622017-09-08 23:14:171738 DCHECK_CURRENTLY_ON(BrowserThread::UI);
lazyboye8634172016-01-28 00:10:481739 CHECK(crx_file::id_util::IdIsValid(info.extension_id));
1740 if (extension_prefs_->IsExternalExtensionUninstalled(info.extension_id))
[email protected]9060d8b02012-01-13 02:14:301741 return false;
[email protected]a8af9fdb2010-10-28 21:52:201742
[email protected]7577a5c52009-07-30 06:21:581743 // Before even bothering to unpack, check and see if we already have this
[email protected]4c967932009-07-31 01:15:491744 // version. This is important because these extensions are going to get
[email protected]7577a5c52009-07-30 06:21:581745 // installed on every startup.
David Bertoni58c113a2019-08-02 19:53:261746 const Extension* existing = registry_->GetExtensionById(
David Bertonia0b34722019-09-30 20:51:261747 info.extension_id, ExtensionRegistry::EVERYTHING);
[email protected]910f72ce2012-08-24 01:38:351748
[email protected]7577a5c52009-07-30 06:21:581749 if (existing) {
[email protected]910f72ce2012-08-24 01:38:351750 // The default apps will have the location set as INTERNAL. Since older
1751 // default apps are installed as EXTERNAL, we override them. However, if the
1752 // app is already installed as internal, then do the version check.
[email protected]31bb5ee62012-09-12 22:58:401753 // TODO(grv) : Remove after Q1-2013.
[email protected]910f72ce2012-08-24 01:38:351754 bool is_default_apps_migration =
lazyboye8634172016-01-28 00:10:481755 (info.crx_location == Manifest::INTERNAL &&
[email protected]1d5e58b2013-01-31 08:41:401756 Manifest::IsExternalLocation(existing->location()));
[email protected]910f72ce2012-08-24 01:38:351757
1758 if (!is_default_apps_migration) {
Devlin Cronin03bf2d22017-12-20 08:21:051759 switch (existing->version().CompareTo(info.version)) {
[email protected]910f72ce2012-08-24 01:38:351760 case -1: // existing version is older, we should upgrade
1761 break;
1762 case 0: // existing version is same, do nothing
1763 return false;
1764 case 1: // existing version is newer, uh-oh
lazyboye8634172016-01-28 00:10:481765 LOG(WARNING) << "Found external version of extension "
1766 << info.extension_id
[email protected]910f72ce2012-08-24 01:38:351767 << "that is older than current version. Current version "
1768 << "is: " << existing->VersionString() << ". New "
Devlin Cronind4c2a8f32017-09-29 17:08:301769 << "version is: " << info.version.GetString()
[email protected]910f72ce2012-08-24 01:38:351770 << ". Keeping current version.";
1771 return false;
1772 }
[email protected]7577a5c52009-07-30 06:21:581773 }
1774 }
1775
[email protected]9060d8b02012-01-13 02:14:301776 // If the extension is already pending, don't start an install.
[email protected]e3987852012-05-04 10:06:301777 if (!pending_extension_manager()->AddFromExternalFile(
Devlin Cronind4c2a8f32017-09-29 17:08:301778 info.extension_id, info.crx_location, info.version,
lazyboye8634172016-01-28 00:10:481779 info.creation_flags, info.mark_acknowledged)) {
[email protected]9060d8b02012-01-13 02:14:301780 return false;
[email protected]e3987852012-05-04 10:06:301781 }
[email protected]9c635f22010-12-02 09:36:361782
[email protected]14908b72011-04-20 06:54:361783 // no client (silent install)
[email protected]f8636f92013-08-09 21:02:371784 scoped_refptr<CrxInstaller> installer(CrxInstaller::CreateSilent(this));
lazyboye8634172016-01-28 00:10:481785 installer->set_install_source(info.crx_location);
1786 installer->set_expected_id(info.extension_id);
Devlin Cronind4c2a8f32017-09-29 17:08:301787 installer->set_expected_version(info.version,
treibe960e282015-09-11 10:38:081788 true /* fail_install_if_unexpected */);
[email protected]cb0e50312011-05-09 15:03:071789 installer->set_install_cause(extension_misc::INSTALL_CAUSE_EXTERNAL_FILE);
lazyboye8634172016-01-28 00:10:481790 installer->set_install_immediately(info.install_immediately);
1791 installer->set_creation_flags(info.creation_flags);
Oleg Davydovfd848c02019-05-10 16:51:381792
Joshua Pawlickiafaa2922019-09-03 18:50:231793 CRXFileInfo file_info(info.path,
1794 info.crx_location == Manifest::EXTERNAL_POLICY
1795 ? GetPolicyVerifierFormat()
1796 : GetExternalVerifierFormat());
[email protected]88e8ec9152013-01-17 04:05:181797#if defined(OS_CHROMEOS)
Oleg Davydovfd848c02019-05-10 16:51:381798 InstallLimiter::Get(profile_)->Add(installer, file_info);
[email protected]88e8ec9152013-01-17 04:05:181799#else
Oleg Davydovfd848c02019-05-10 16:51:381800 installer->InstallCrxFile(file_info);
[email protected]88e8ec9152013-01-17 04:05:181801#endif
[email protected]47fc70c2011-12-06 07:29:511802
1803 // Depending on the source, a new external extension might not need a user
1804 // notification on installation. For such extensions, mark them acknowledged
1805 // now to suppress the notification.
lazyboye8634172016-01-28 00:10:481806 if (info.mark_acknowledged)
1807 external_install_manager_->AcknowledgeExternalExtension(info.extension_id);
[email protected]9060d8b02012-01-13 02:14:301808
1809 return true;
[email protected]7577a5c52009-07-30 06:21:581810}
1811
[email protected]eaa7dd182010-12-14 11:09:001812void ExtensionService::DidCreateRenderViewForBackgroundPage(
Devlin Cronineea1b7a2018-05-26 02:46:211813 ExtensionHost* host) {
Michael Giuffrida573992d2018-02-08 00:48:441814 extension_registrar_.DidCreateRenderViewForBackgroundPage(host);
[email protected]406027c02010-09-27 08:03:181815}
1816
[email protected]432115822011-07-10 15:52:271817void ExtensionService::Observe(int type,
[email protected]6c2381d2011-10-19 02:52:531818 const content::NotificationSource& source,
1819 const content::NotificationDetails& details) {
[email protected]432115822011-07-10 15:52:271820 switch (type) {
[email protected]3c4abc82012-10-22 22:25:541821 case chrome::NOTIFICATION_APP_TERMINATING:
1822 // Shutdown has started. Don't start any more extension installs.
1823 // (We cannot use ExtensionService::Shutdown() for this because it
1824 // happens too late in browser teardown.)
1825 browser_terminating_ = true;
1826 break;
Devlin Cronineea1b7a2018-05-26 02:46:211827 case NOTIFICATION_EXTENSION_PROCESS_TERMINATED: {
[email protected]6c2381d2011-10-19 02:52:531828 if (profile_ !=
1829 content::Source<Profile>(source).ptr()->GetOriginalProfile()) {
[email protected]bc535ee52010-08-31 18:40:321830 break;
[email protected]6c2381d2011-10-19 02:52:531831 }
[email protected]a4ed6282009-12-14 20:51:161832
Michael Giuffridafcb420362017-10-11 21:50:261833 // Mark the extension as terminated and deactivated. We want it to
[email protected]fa2416f2011-05-03 08:41:201834 // be in a consistent state: either fully working or not loaded
1835 // at all, but never half-crashed. We do it in a PostTask so
1836 // that other handlers of this notification will still have
1837 // access to the Extension and ExtensionHost.
Devlin Cronineea1b7a2018-05-26 02:46:211838 ExtensionHost* host = content::Details<ExtensionHost>(details).ptr();
skyostilf221b7de2015-06-11 20:36:321839 base::ThreadTaskRunnerHandle::Get()->PostTask(
Michael Giuffridafcb420362017-10-11 21:50:261840 FROM_HERE, base::BindOnce(&ExtensionService::TerminateExtension,
1841 AsWeakPtr(), host->extension_id()));
[email protected]31f77262009-12-02 20:48:531842 break;
1843 }
[email protected]432115822011-07-10 15:52:271844 case content::NOTIFICATION_RENDERER_PROCESS_TERMINATED: {
[email protected]f3b1a082011-11-18 00:34:301845 content::RenderProcessHost* process =
1846 content::Source<content::RenderProcessHost>(source).ptr();
[email protected]fc30ef082011-08-18 04:07:191847 Profile* host_profile =
[email protected]f3b1a082011-11-18 00:34:301848 Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]fc30ef082011-08-18 04:07:191849 if (!profile_->IsSameProfile(host_profile->GetOriginalProfile()))
1850 break;
1851
Devlin Cronineea1b7a2018-05-26 02:46:211852 ProcessMap* process_map = ProcessMap::Get(profile_);
[email protected]fafdc842014-01-17 18:09:081853 if (process_map->Contains(process->GetID())) {
[email protected]52b76592013-11-02 17:59:031854 // An extension process was terminated, this might have resulted in an
1855 // app or extension becoming idle.
1856 std::set<std::string> extension_ids =
[email protected]fafdc842014-01-17 18:09:081857 process_map->GetExtensionsInProcess(process->GetID());
elijahtaylor0def4432014-10-06 18:15:111858 // In addition to the extensions listed in the process map, one of those
1859 // extensions could be referencing a shared module which is waiting for
1860 // idle to update. Check all imports of these extensions, too.
1861 std::set<std::string> import_ids;
jdoerrie13cd648c82018-10-02 21:21:021862 for (auto it = extension_ids.begin(); it != extension_ids.end(); ++it) {
David Bertonia0b34722019-09-30 20:51:261863 const Extension* extension =
1864 registry_->GetExtensionById(*it, ExtensionRegistry::EVERYTHING);
elijahtaylor0def4432014-10-06 18:15:111865 if (!extension)
1866 continue;
1867 const std::vector<SharedModuleInfo::ImportInfo>& imports =
1868 SharedModuleInfo::GetImports(extension);
1869 std::vector<SharedModuleInfo::ImportInfo>::const_iterator import_it;
1870 for (import_it = imports.begin(); import_it != imports.end();
1871 import_it++) {
1872 import_ids.insert((*import_it).extension_id);
1873 }
1874 }
1875 extension_ids.insert(import_ids.begin(), import_ids.end());
1876
jdoerrie13cd648c82018-10-02 21:21:021877 for (auto it = extension_ids.begin(); it != extension_ids.end(); ++it) {
[email protected]52b76592013-11-02 17:59:031878 if (delayed_installs_.Contains(*it)) {
skyostilf221b7de2015-06-11 20:36:321879 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
[email protected]52b76592013-11-02 17:59:031880 FROM_HERE,
tzik8d880ee2017-04-20 19:46:241881 base::BindOnce(
Toni Barzic667db0d32018-01-09 18:00:191882 base::IgnoreResult(
1883 &ExtensionService::FinishDelayedInstallationIfReady),
1884 AsWeakPtr(), *it, false /*install_immediately*/),
Lei Zhang15339152018-08-09 22:20:441885 kUpdateIdleDelay);
[email protected]52b76592013-11-02 17:59:031886 }
1887 }
1888 }
1889
[email protected]fafdc842014-01-17 18:09:081890 process_map->RemoveAllFromProcess(process->GetID());
Sami Kyostila5db196cf2019-08-01 17:46:121891 base::PostTask(FROM_HERE, {BrowserThread::IO},
1892 base::BindOnce(&InfoMap::UnregisterAllExtensionsInProcess,
1893 system_->info_map(), process->GetID()));
[email protected]da5683db2011-04-23 17:12:211894 break;
1895 }
[email protected]aa96d3a2010-08-21 08:45:251896
[email protected]4814b512009-11-07 00:12:291897 default:
1898 NOTREACHED() << "Unexpected notification type.";
1899 }
1900}
1901
binjin47947f842014-11-18 12:10:241902int ExtensionService::GetDisableReasonsOnInstalled(const Extension* extension) {
rdevlin.cronine1456712016-12-29 22:47:281903 bool is_update_from_same_type = false;
1904 {
1905 const Extension* existing_extension =
David Bertoni9f897c92019-09-20 17:46:351906 registry_->GetInstalledExtension(extension->id());
rdevlin.cronine1456712016-12-29 22:47:281907 is_update_from_same_type =
1908 existing_extension &&
1909 existing_extension->manifest()->type() == extension->manifest()->type();
1910 }
Devlin Cronineea1b7a2018-05-26 02:46:211911 disable_reason::DisableReason disable_reason = disable_reason::DISABLE_NONE;
binjin47947f842014-11-18 12:10:241912 // Extensions disabled by management policy should always be disabled, even
1913 // if it's force-installed.
1914 if (system_->management_policy()->MustRemainDisabled(
1915 extension, &disable_reason, nullptr)) {
1916 // A specified reason is required to disable the extension.
Devlin Cronineea1b7a2018-05-26 02:46:211917 DCHECK(disable_reason != disable_reason::DISABLE_NONE);
binjin47947f842014-11-18 12:10:241918 return disable_reason;
1919 }
1920
[email protected]612a1cb12012-10-17 13:18:031921 // Extensions installed by policy can't be disabled. So even if a previous
1922 // installation disabled the extension, make sure it is now enabled.
binjin47947f842014-11-18 12:10:241923 if (system_->management_policy()->MustRemainEnabled(extension, nullptr))
Devlin Cronineea1b7a2018-05-26 02:46:211924 return disable_reason::DISABLE_NONE;
[email protected]612a1cb12012-10-17 13:18:031925
binjin47947f842014-11-18 12:10:241926 // An already disabled extension should inherit the disable reasons and
1927 // remain disabled.
1928 if (extension_prefs_->IsExtensionDisabled(extension->id())) {
1929 int disable_reasons = extension_prefs_->GetDisableReasons(extension->id());
1930 // If an extension was disabled without specified reason, presume it's
1931 // disabled by user.
Devlin Cronineea1b7a2018-05-26 02:46:211932 return disable_reasons == disable_reason::DISABLE_NONE
1933 ? disable_reason::DISABLE_USER_ACTION
binjin47947f842014-11-18 12:10:241934 : disable_reasons;
1935 }
[email protected]612a1cb12012-10-17 13:18:031936
Devlin Cronineea1b7a2018-05-26 02:46:211937 if (ExternalInstallManager::IsPromptingEnabled()) {
[email protected]612a1cb12012-10-17 13:18:031938 // External extensions are initially disabled. We prompt the user before
[email protected]2c495c42013-01-04 21:49:541939 // enabling them. Hosted apps are excepted because they are not dangerous
rdevlin.cronine1456712016-12-29 22:47:281940 // (they need to be launched by the user anyway). We also don't prompt for
1941 // extensions updating; this is because the extension will be disabled from
1942 // the initial install if it is supposed to be, and this allows us to turn
1943 // this on for other platforms without disabling already-installed
1944 // extensions.
[email protected]1d5e58b2013-01-31 08:41:401945 if (extension->GetType() != Manifest::TYPE_HOSTED_APP &&
1946 Manifest::IsExternalLocation(extension->location()) &&
rdevlin.cronine1456712016-12-29 22:47:281947 !extension_prefs_->IsExternalExtensionAcknowledged(extension->id()) &&
1948 !is_update_from_same_type) {
Devlin Cronineea1b7a2018-05-26 02:46:211949 return disable_reason::DISABLE_EXTERNAL_EXTENSION;
[email protected]612a1cb12012-10-17 13:18:031950 }
1951 }
[email protected]612a1cb12012-10-17 13:18:031952
Devlin Cronineea1b7a2018-05-26 02:46:211953 return disable_reason::DISABLE_NONE;
[email protected]612a1cb12012-10-17 13:18:031954}
[email protected]0db124b02012-11-07 04:55:051955
mlerman6a37b6a42014-11-26 22:10:531956// Helper method to determine if an extension can be blocked.
1957bool ExtensionService::CanBlockExtension(const Extension* extension) const {
mlerman3690e5be2014-12-01 22:57:441958 DCHECK(extension);
mlerman6a37b6a42014-11-26 22:10:531959 return extension->location() != Manifest::COMPONENT &&
1960 extension->location() != Manifest::EXTERNAL_COMPONENT &&
achuith2f5578b2016-02-26 21:57:131961 !system_->management_policy()->MustRemainEnabled(extension, nullptr);
mlerman6a37b6a42014-11-26 22:10:531962}
1963
Devlin Cronineea1b7a2018-05-26 02:46:211964InstallGate::Action ExtensionService::ShouldDelayExtensionInstall(
1965 const Extension* extension,
xiyuanf6a4c6a62016-04-19 18:14:541966 bool install_immediately,
Devlin Cronineea1b7a2018-05-26 02:46:211967 ExtensionPrefs::DelayReason* reason) const {
xiyuanf6a4c6a62016-04-19 18:14:541968 for (const auto& entry : install_delayer_registry_) {
Devlin Cronineea1b7a2018-05-26 02:46:211969 InstallGate* const delayer = entry.second;
1970 InstallGate::Action action =
xiyuanf6a4c6a62016-04-19 18:14:541971 delayer->ShouldDelay(extension, install_immediately);
Devlin Cronineea1b7a2018-05-26 02:46:211972 if (action != InstallGate::INSTALL) {
xiyuanf6a4c6a62016-04-19 18:14:541973 *reason = entry.first;
1974 return action;
1975 }
[email protected]e7aa7b7e2012-11-27 04:51:221976 }
[email protected]fdd679b2012-11-15 20:49:391977
Devlin Cronineea1b7a2018-05-26 02:46:211978 return InstallGate::INSTALL;
[email protected]9f4e4f082013-06-21 07:11:191979}
1980
1981void ExtensionService::MaybeFinishDelayedInstallations() {
1982 std::vector<std::string> to_be_installed;
achuith2f5578b2016-02-26 21:57:131983 for (const auto& extension : delayed_installs_) {
1984 to_be_installed.push_back(extension->id());
[email protected]399583b2012-12-11 09:33:421985 }
achuith2f5578b2016-02-26 21:57:131986 for (const auto& extension_id : to_be_installed) {
Toni Barzic667db0d32018-01-09 18:00:191987 FinishDelayedInstallationIfReady(extension_id,
1988 false /*install_immediately*/);
[email protected]399583b2012-12-11 09:33:421989 }
[email protected]399583b2012-12-11 09:33:421990}
1991
[email protected]fdd679b2012-11-15 20:49:391992void ExtensionService::OnBlacklistUpdated() {
[email protected]2d19eb6e2014-01-27 17:30:001993 blacklist_->GetBlacklistedIDs(
[email protected]f47f7172014-03-19 19:27:101994 registry_->GenerateInstalledExtensionsSet()->GetIDs(),
[email protected]3f2a2fa2013-09-24 02:55:251995 base::Bind(&ExtensionService::ManageBlacklist, AsWeakPtr()));
[email protected]695b5712012-12-06 23:55:281996}
1997
weidongg04695232017-06-09 00:01:051998void ExtensionService::OnUpgradeRecommended() {
1999 // Notify observers that chrome update is available.
2000 for (auto& observer : update_observers_)
2001 observer.OnChromeUpdateAvailable();
2002}
2003
Devlin Cronineea1b7a2018-05-26 02:46:212004void ExtensionService::PreAddExtension(const Extension* extension,
2005 const Extension* old_extension) {
Michael Giuffrida573992d2018-02-08 00:48:442006 // Check if the extension's privileges have changed and mark the
2007 // extension disabled if necessary.
2008 CheckPermissionsIncrease(extension, !!old_extension);
2009}
2010
Michael Giuffrida6397c592017-10-09 20:46:532011bool ExtensionService::CanEnableExtension(const Extension* extension) {
2012 return !system_->management_policy()->MustRemainDisabled(extension, nullptr,
2013 nullptr);
2014}
2015
2016bool ExtensionService::CanDisableExtension(const Extension* extension) {
2017 // Some extensions cannot be disabled by users:
2018 // - |extension| can be null if sync disables an extension that is not
2019 // installed yet; allow disablement in this case.
2020 if (!extension)
2021 return true;
2022
2023 // - Shared modules are just resources used by other extensions, and are not
2024 // user-controlled.
2025 if (SharedModuleInfo::IsSharedModule(extension))
2026 return false;
2027
2028 // - EXTERNAL_COMPONENT extensions are not generally modifiable by users, but
2029 // can be uninstalled by the browser if the user sets extension-specific
2030 // preferences.
2031 if (extension->location() == Manifest::EXTERNAL_COMPONENT)
2032 return true;
2033
2034 return system_->management_policy()->UserMayModifySettings(extension,
2035 nullptr);
2036}
2037
2038bool ExtensionService::ShouldBlockExtension(const Extension* extension) {
2039 if (!block_extensions_)
2040 return false;
2041
2042 // Blocked extensions aren't marked as such in prefs, thus if
2043 // |block_extensions_| is true then CanBlockExtension() must be called with an
2044 // Extension object. If |extension| is not loaded, assume it should be
2045 // blocked.
2046 return !extension || CanBlockExtension(extension);
2047}
2048
Evan Staded89e11c2019-09-05 18:08:562049void ExtensionService::OnProfileMarkedForPermanentDeletion(Profile* profile) {
2050 if (profile != profile_)
2051 return;
2052
2053 ExtensionIdSet ids_to_unload = registry_->enabled_extensions().GetIDs();
2054 for (auto it = ids_to_unload.begin(); it != ids_to_unload.end(); ++it)
2055 UnloadExtension(*it, UnloadedExtensionReason::PROFILE_SHUTDOWN);
2056}
2057
[email protected]2d19eb6e2014-01-27 17:30:002058void ExtensionService::ManageBlacklist(
Devlin Cronineea1b7a2018-05-26 02:46:212059 const Blacklist::BlacklistStateMap& state_map) {
[email protected]54ee8192014-03-29 17:37:242060 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]695b5712012-12-06 23:55:282061
mlerman6a37b6a42014-11-26 22:10:532062 std::set<std::string> blacklisted;
[email protected]2d19eb6e2014-01-27 17:30:002063 ExtensionIdSet greylist;
2064 ExtensionIdSet unchanged;
achuith2f5578b2016-02-26 21:57:132065 for (const auto& it : state_map) {
2066 switch (it.second) {
Devlin Cronineea1b7a2018-05-26 02:46:212067 case NOT_BLACKLISTED:
[email protected]2d19eb6e2014-01-27 17:30:002068 break;
[email protected]695b5712012-12-06 23:55:282069
Devlin Cronineea1b7a2018-05-26 02:46:212070 case BLACKLISTED_MALWARE:
achuith2f5578b2016-02-26 21:57:132071 blacklisted.insert(it.first);
[email protected]2d19eb6e2014-01-27 17:30:002072 break;
2073
Devlin Cronineea1b7a2018-05-26 02:46:212074 case BLACKLISTED_SECURITY_VULNERABILITY:
2075 case BLACKLISTED_CWS_POLICY_VIOLATION:
2076 case BLACKLISTED_POTENTIALLY_UNWANTED:
achuith2f5578b2016-02-26 21:57:132077 greylist.insert(it.first);
[email protected]2d19eb6e2014-01-27 17:30:002078 break;
2079
Devlin Cronineea1b7a2018-05-26 02:46:212080 case BLACKLISTED_UNKNOWN:
achuith2f5578b2016-02-26 21:57:132081 unchanged.insert(it.first);
[email protected]2d19eb6e2014-01-27 17:30:002082 break;
2083 }
2084 }
2085
mlerman6a37b6a42014-11-26 22:10:532086 UpdateBlacklistedExtensions(blacklisted, unchanged);
[email protected]2d19eb6e2014-01-27 17:30:002087 UpdateGreylistedExtensions(greylist, unchanged, state_map);
2088
[email protected]373daf972014-04-10 01:50:442089 error_controller_->ShowErrorIfNeeded();
[email protected]2d19eb6e2014-01-27 17:30:002090}
2091
2092namespace {
2093void Partition(const ExtensionIdSet& before,
2094 const ExtensionIdSet& after,
2095 const ExtensionIdSet& unchanged,
2096 ExtensionIdSet* no_longer,
2097 ExtensionIdSet* not_yet) {
2098 *not_yet = base::STLSetDifference<ExtensionIdSet>(after, before);
2099 *no_longer = base::STLSetDifference<ExtensionIdSet>(before, after);
2100 *no_longer = base::STLSetDifference<ExtensionIdSet>(*no_longer, unchanged);
2101}
2102} // namespace
2103
mlerman6a37b6a42014-11-26 22:10:532104void ExtensionService::UpdateBlacklistedExtensions(
2105 const ExtensionIdSet& blacklisted,
[email protected]2d19eb6e2014-01-27 17:30:002106 const ExtensionIdSet& unchanged) {
2107 ExtensionIdSet not_yet_blocked, no_longer_blocked;
mlerman6a37b6a42014-11-26 22:10:532108 Partition(registry_->blacklisted_extensions().GetIDs(), blacklisted,
2109 unchanged, &no_longer_blocked, &not_yet_blocked);
[email protected]2d19eb6e2014-01-27 17:30:002110
jdoerrie13cd648c82018-10-02 21:21:022111 for (auto it = no_longer_blocked.begin(); it != no_longer_blocked.end();
2112 ++it) {
[email protected]695b5712012-12-06 23:55:282113 scoped_refptr<const Extension> extension =
[email protected]bb1bc9b32013-12-21 03:09:142114 registry_->blacklisted_extensions().GetByID(*it);
[email protected]3f2a2fa2013-09-24 02:55:252115 if (!extension.get()) {
mlerman6a37b6a42014-11-26 22:10:532116 NOTREACHED() << "Extension " << *it << " no longer blacklisted, "
2117 << "but it was never blacklisted.";
[email protected]695b5712012-12-06 23:55:282118 continue;
[email protected]3f2a2fa2013-09-24 02:55:252119 }
[email protected]bb1bc9b32013-12-21 03:09:142120 registry_->RemoveBlacklisted(*it);
atuchin6dc7c442016-07-20 07:04:342121 extension_prefs_->SetExtensionBlacklistState(extension->id(),
Devlin Cronineea1b7a2018-05-26 02:46:212122 NOT_BLACKLISTED);
[email protected]dc24976f2013-06-02 21:15:092123 AddExtension(extension.get());
[email protected]ac875372013-02-28 04:36:092124 UMA_HISTOGRAM_ENUMERATION("ExtensionBlacklist.UnblacklistInstalled",
[email protected]dc24976f2013-06-02 21:15:092125 extension->location(),
2126 Manifest::NUM_LOCATIONS);
[email protected]695b5712012-12-06 23:55:282127 }
2128
jdoerrie13cd648c82018-10-02 21:21:022129 for (auto it = not_yet_blocked.begin(); it != not_yet_blocked.end(); ++it) {
David Bertoni9f897c92019-09-20 17:46:352130 scoped_refptr<const Extension> extension =
2131 registry_->GetInstalledExtension(*it);
[email protected]3f2a2fa2013-09-24 02:55:252132 if (!extension.get()) {
2133 NOTREACHED() << "Extension " << *it << " needs to be "
2134 << "blacklisted, but it's not installed.";
[email protected]695b5712012-12-06 23:55:282135 continue;
[email protected]3f2a2fa2013-09-24 02:55:252136 }
[email protected]bb1bc9b32013-12-21 03:09:142137 registry_->AddBlacklisted(extension);
Devlin Cronineea1b7a2018-05-26 02:46:212138 extension_prefs_->SetExtensionBlacklistState(extension->id(),
2139 BLACKLISTED_MALWARE);
limasdf0deef2042017-05-03 19:17:172140 UnloadExtension(*it, UnloadedExtensionReason::BLACKLIST);
[email protected]ac875372013-02-28 04:36:092141 UMA_HISTOGRAM_ENUMERATION("ExtensionBlacklist.BlacklistInstalled",
2142 extension->location(), Manifest::NUM_LOCATIONS);
[email protected]695b5712012-12-06 23:55:282143 }
[email protected]2d19eb6e2014-01-27 17:30:002144}
[email protected]695b5712012-12-06 23:55:282145
[email protected]2d19eb6e2014-01-27 17:30:002146// TODO(oleg): UMA logging
2147void ExtensionService::UpdateGreylistedExtensions(
2148 const ExtensionIdSet& greylist,
2149 const ExtensionIdSet& unchanged,
Devlin Cronineea1b7a2018-05-26 02:46:212150 const Blacklist::BlacklistStateMap& state_map) {
[email protected]2d19eb6e2014-01-27 17:30:002151 ExtensionIdSet not_yet_greylisted, no_longer_greylisted;
2152 Partition(greylist_.GetIDs(),
2153 greylist, unchanged,
2154 &no_longer_greylisted, &not_yet_greylisted);
2155
jdoerrie13cd648c82018-10-02 21:21:022156 for (auto it = no_longer_greylisted.begin(); it != no_longer_greylisted.end();
2157 ++it) {
[email protected]2d19eb6e2014-01-27 17:30:002158 scoped_refptr<const Extension> extension = greylist_.GetByID(*it);
2159 if (!extension.get()) {
2160 NOTREACHED() << "Extension " << *it << " no longer greylisted, "
2161 << "but it was not marked as greylisted.";
2162 continue;
2163 }
2164
2165 greylist_.Remove(*it);
2166 extension_prefs_->SetExtensionBlacklistState(extension->id(),
Devlin Cronineea1b7a2018-05-26 02:46:212167 NOT_BLACKLISTED);
[email protected]2d19eb6e2014-01-27 17:30:002168 if (extension_prefs_->GetDisableReasons(extension->id()) &
Devlin Cronineea1b7a2018-05-26 02:46:212169 disable_reason::DISABLE_GREYLIST)
[email protected]2d19eb6e2014-01-27 17:30:002170 EnableExtension(*it);
2171 }
2172
jdoerrie13cd648c82018-10-02 21:21:022173 for (auto it = not_yet_greylisted.begin(); it != not_yet_greylisted.end();
2174 ++it) {
David Bertoni9f897c92019-09-20 17:46:352175 scoped_refptr<const Extension> extension =
2176 registry_->GetInstalledExtension(*it);
[email protected]2d19eb6e2014-01-27 17:30:002177 if (!extension.get()) {
2178 NOTREACHED() << "Extension " << *it << " needs to be "
2179 << "disabled, but it's not installed.";
2180 continue;
2181 }
2182 greylist_.Insert(extension);
2183 extension_prefs_->SetExtensionBlacklistState(extension->id(),
2184 state_map.find(*it)->second);
2185 if (registry_->enabled_extensions().Contains(extension->id()))
Devlin Cronineea1b7a2018-05-26 02:46:212186 DisableExtension(*it, disable_reason::DISABLE_GREYLIST);
[email protected]2d19eb6e2014-01-27 17:30:002187 }
[email protected]fdd679b2012-11-15 20:49:392188}
[email protected]75bdcb872013-03-13 00:41:452189
Devlin Cronineea1b7a2018-05-26 02:46:212190void ExtensionService::AddUpdateObserver(UpdateObserver* observer) {
[email protected]75bdcb872013-03-13 00:41:452191 update_observers_.AddObserver(observer);
2192}
2193
Devlin Cronineea1b7a2018-05-26 02:46:212194void ExtensionService::RemoveUpdateObserver(UpdateObserver* observer) {
[email protected]75bdcb872013-03-13 00:41:452195 update_observers_.RemoveObserver(observer);
2196}
[email protected]bb1bc9b32013-12-21 03:09:142197
Devlin Cronineea1b7a2018-05-26 02:46:212198void ExtensionService::RegisterInstallGate(ExtensionPrefs::DelayReason reason,
2199 InstallGate* install_delayer) {
xiyuanf6a4c6a62016-04-19 18:14:542200 DCHECK(install_delayer_registry_.end() ==
2201 install_delayer_registry_.find(reason));
2202 install_delayer_registry_[reason] = install_delayer;
2203}
2204
Devlin Cronineea1b7a2018-05-26 02:46:212205void ExtensionService::UnregisterInstallGate(InstallGate* install_delayer) {
xiyuanf6a4c6a62016-04-19 18:14:542206 for (auto it = install_delayer_registry_.begin();
2207 it != install_delayer_registry_.end(); ++it) {
2208 if (it->second == install_delayer) {
2209 install_delayer_registry_.erase(it);
2210 return;
2211 }
2212 }
2213}
2214
[email protected]bb1bc9b32013-12-21 03:09:142215// Used only by test code.
2216void ExtensionService::UnloadAllExtensionsInternal() {
2217 profile_->GetExtensionSpecialStoragePolicy()->RevokeRightsForAllExtensions();
2218
2219 registry_->ClearAll();
[email protected]45f5b7d2014-01-22 23:47:132220 system_->runtime_data()->ClearAll();
[email protected]bb1bc9b32013-12-21 03:09:142221
2222 // TODO(erikkay) should there be a notification for this? We can't use
Devlin Cronineea1b7a2018-05-26 02:46:212223 // EXTENSION_UNLOADED since that implies that the extension has
Minh X. Nguyen45479012017-08-18 21:35:362224 // been disabled or uninstalled.
[email protected]bb1bc9b32013-12-21 03:09:142225}
[email protected]ebe07772014-05-22 04:16:062226
rdevlin.croninf2e1cb012017-05-27 01:27:592227void ExtensionService::OnInstalledExtensionsLoaded() {
2228 if (updater_)
2229 updater_->Start();
2230
2231 // Enable any Shared Modules that incorrectly got disabled previously.
2232 // This is temporary code to fix incorrect behavior from previous versions of
2233 // Chrome and can be removed after several releases (perhaps M60).
Devlin Cronineea1b7a2018-05-26 02:46:212234 ExtensionList to_enable;
rdevlin.croninf2e1cb012017-05-27 01:27:592235 for (const auto& extension : registry_->disabled_extensions()) {
2236 if (SharedModuleInfo::IsSharedModule(extension.get()))
2237 to_enable.push_back(extension);
2238 }
2239 for (const auto& extension : to_enable) {
2240 EnableExtension(extension->id());
2241 }
2242
2243 OnBlacklistUpdated();
2244}
lazyboy75b9def2017-06-06 18:56:592245
Takumi Fujimoto43c8c00f2017-07-26 22:48:562246void ExtensionService::UninstallMigratedExtensions() {
2247 std::unique_ptr<ExtensionSet> installed_extensions =
2248 registry_->GenerateInstalledExtensionsSet();
2249
2250 for (const std::string& extension_id : kMigratedExtensionIds) {
2251 if (installed_extensions->Contains(extension_id)) {
Devlin Cronineea1b7a2018-05-26 02:46:212252 UninstallExtension(extension_id, UNINSTALL_REASON_MIGRATED, nullptr);
Takumi Fujimoto43c8c00f2017-07-26 22:48:562253 }
2254 }
2255}
Devlin Cronineea1b7a2018-05-26 02:46:212256
2257} // namespace extensions