blob: 95ca0f3973e7ba4a8e2039a4f46e42c03816d31a [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
[email protected]62433d32011-10-12 22:33:1214#include "base/command_line.h"
rdevlin.cronin08ada0f2017-03-09 23:29:5215#include "base/debug/alias.h"
16#include "base/debug/dump_without_crashing.h"
skyostilf221b7de2015-06-11 20:36:3217#include "base/location.h"
rkaplowfca0f4dc52015-03-14 21:40:5718#include "base/metrics/histogram_macros.h"
skyostilf221b7de2015-06-11 20:36:3219#include "base/single_thread_task_runner.h"
tripta.g0ac673a2017-07-07 05:45:0920#include "base/stl_util.h"
[email protected]3ea1b182013-02-08 22:38:4121#include "base/strings/string_number_conversions.h"
catmullings98cd1942016-08-30 22:31:5922#include "base/strings/string_tokenizer.h"
[email protected]00e7bef2013-06-10 20:35:1723#include "base/strings/stringprintf.h"
[email protected]112158af2013-06-07 23:46:1824#include "base/strings/utf_string_conversions.h"
fdoray71c48e722017-05-17 22:37:0925#include "base/task_scheduler/post_task.h"
[email protected]34b99632011-01-01 01:01:0626#include "base/threading/thread_restrictions.h"
gabb15e19072016-05-11 20:45:4127#include "base/threading/thread_task_runner_handle.h"
[email protected]41a17c52013-06-28 00:27:5328#include "base/time/time.h"
rkaplowe65c2ff2015-02-14 16:29:5429#include "base/trace_event/trace_event.h"
avia2f4804a2015-12-24 23:11:1330#include "build/build_config.h"
[email protected]15730c42009-09-03 00:03:2031#include "chrome/browser/browser_process.h"
[email protected]9ea0cd32013-07-12 01:50:3632#include "chrome/browser/chrome_notification_types.h"
mukai87a8d402014-09-15 20:15:0933#include "chrome/browser/content_settings/content_settings_internal_extension_provider.h"
sunil.ratnu21b896c2014-11-24 10:09:2434#include "chrome/browser/extensions/api/content_settings/content_settings_custom_extension_provider.h"
mukai87a8d402014-09-15 20:15:0935#include "chrome/browser/extensions/api/content_settings/content_settings_service.h"
ryanackley48bedbd2015-01-27 23:12:1436#include "chrome/browser/extensions/app_data_migrator.h"
[email protected]d8c8f25f2011-11-02 18:18:0137#include "chrome/browser/extensions/component_loader.h"
[email protected]13e062e2014-08-09 10:21:5538#include "chrome/browser/extensions/crx_installer.h"
[email protected]d9ede582012-08-14 19:21:3839#include "chrome/browser/extensions/data_deleter.h"
rdevlin.cronin2813c1b2014-08-26 23:51:0840#include "chrome/browser/extensions/extension_action_storage_manager.h"
[email protected]5a145e82014-05-29 22:19:0741#include "chrome/browser/extensions/extension_assets_manager.h"
[email protected]62f051c2012-03-29 17:04:4442#include "chrome/browser/extensions/extension_disabled_ui.h"
[email protected]373daf972014-04-10 01:50:4443#include "chrome/browser/extensions/extension_error_controller.h"
[email protected]19eb80152011-02-26 00:28:4344#include "chrome/browser/extensions/extension_special_storage_policy.h"
[email protected]f8aefb132013-10-30 09:29:5245#include "chrome/browser/extensions/extension_sync_service.h"
[email protected]617342a42013-12-18 23:34:0346#include "chrome/browser/extensions/extension_util.h"
[email protected]2894a512014-06-26 19:03:5647#include "chrome/browser/extensions/external_install_manager.h"
[email protected]5df038b2012-07-16 19:03:2748#include "chrome/browser/extensions/external_provider_impl.h"
[email protected]ffd2f79e2013-11-14 00:11:4649#include "chrome/browser/extensions/install_verifier.h"
[email protected]d8c8f25f2011-11-02 18:18:0150#include "chrome/browser/extensions/installed_loader.h"
[email protected]f3d3b382014-03-14 21:19:2851#include "chrome/browser/extensions/pending_extension_manager.h"
[email protected]13e062e2014-08-09 10:21:5552#include "chrome/browser/extensions/permissions_updater.h"
[email protected]90878c52014-04-04 18:21:0253#include "chrome/browser/extensions/shared_module_service.h"
[email protected]13e062e2014-08-09 10:21:5554#include "chrome/browser/extensions/unpacked_installer.h"
rockotdb5192992014-09-16 21:27:0255#include "chrome/browser/extensions/updater/chrome_extension_downloader_factory.h"
[email protected]13e062e2014-08-09 10:21:5556#include "chrome/browser/extensions/updater/extension_updater.h"
rockotdb5192992014-09-16 21:27:0257#include "chrome/browser/google/google_brand.h"
[email protected]8ecad5e2010-12-02 21:18:3358#include "chrome/browser/profiles/profile.h"
dbeam8d57a012015-05-21 07:12:2059#include "chrome/browser/search/thumbnail_source.h"
[email protected]b5a507b22013-11-08 20:41:5760#include "chrome/browser/ui/webui/extensions/extension_icon_source.h"
[email protected]c8d407e2011-04-28 21:27:1761#include "chrome/browser/ui/webui/favicon_source.h"
[email protected]b07e606e2012-09-15 20:16:1562#include "chrome/browser/ui/webui/theme_source.h"
weidongg04695232017-06-09 00:01:0563#include "chrome/browser/upgrade_detector.h"
[email protected]e2eb43112009-05-29 21:19:5464#include "chrome/common/chrome_switches.h"
[email protected]f6431be82013-09-07 02:53:4565#include "chrome/common/crash_keys.h"
[email protected]9f4e4f082013-06-21 07:11:1966#include "chrome/common/extensions/extension_constants.h"
brettw9e85ef42016-11-01 21:01:2467#include "chrome/common/features.h"
[email protected]a57209872009-05-04 22:53:1468#include "chrome/common/url_constants.h"
mukai8eaec822014-10-25 17:53:1669#include "components/content_settings/core/browser/host_content_settings_map.h"
[email protected]fdd28372014-08-21 02:27:2670#include "components/crx_file/id_util.h"
[email protected]dccba4f82014-05-29 00:52:5671#include "content/public/browser/devtools_agent_host.h"
[email protected]05aad2da2011-10-28 10:12:3772#include "content/public/browser/notification_service.h"
[email protected]f3b1a082011-11-18 00:34:3073#include "content/public/browser/render_process_host.h"
[email protected]399583b2012-12-11 09:33:4274#include "content/public/browser/storage_partition.h"
treib926ee2d2015-08-06 10:55:4275#include "extensions/browser/app_sorting.h"
[email protected]34423532013-11-21 18:13:1076#include "extensions/browser/event_router.h"
Devlin Cronin40b4cbc2017-08-02 01:57:5977#include "extensions/browser/extension_file_task_runner.h"
[email protected]22401dc2014-03-21 01:38:5778#include "extensions/browser/extension_host.h"
[email protected]bb1bc9b32013-12-21 03:09:1479#include "extensions/browser/extension_registry.h"
[email protected]59b0e602014-01-30 00:41:2480#include "extensions/browser/extension_system.h"
Michael Giuffrida7efeed142017-06-07 06:29:2181#include "extensions/browser/extension_util.h"
rockotffa65b12014-10-14 17:19:0682#include "extensions/browser/extensions_browser_client.h"
lazyboye8634172016-01-28 00:10:4883#include "extensions/browser/external_install_info.h"
[email protected]4a1d9c0d2014-06-13 12:50:1184#include "extensions/browser/install_flag.h"
lazyboy75b9def2017-06-06 18:56:5985#include "extensions/browser/lazy_background_task_queue.h"
rdevlin.cronin5e510e802016-07-26 15:09:2086#include "extensions/browser/renderer_startup_helper.h"
[email protected]45f5b7d2014-01-22 23:47:1387#include "extensions/browser/runtime_data.h"
[email protected]e43c61f2014-07-20 21:46:3488#include "extensions/browser/uninstall_reason.h"
[email protected]a9aa62b312013-11-29 05:35:0689#include "extensions/browser/update_observer.h"
rockotffa65b12014-10-14 17:19:0690#include "extensions/browser/updater/extension_cache.h"
rockot05f40a922014-10-16 19:40:2591#include "extensions/browser/updater/extension_downloader.h"
[email protected]fb820c02014-03-13 15:07:0892#include "extensions/common/extension_messages.h"
rockot90659852014-09-18 19:31:5293#include "extensions/common/extension_urls.h"
[email protected]5ef835a2013-11-08 20:42:5794#include "extensions/common/feature_switch.h"
rdevlin.cronin41227532016-07-13 21:24:3495#include "extensions/common/features/feature_channel.h"
[email protected]85df9d12014-04-15 17:02:1496#include "extensions/common/file_util.h"
[email protected]0c3c9732013-09-16 08:53:4197#include "extensions/common/manifest_constants.h"
[email protected]558878cc82013-11-09 01:25:5198#include "extensions/common/manifest_handlers/background_info.h"
rockotd5546142014-10-15 00:29:0899#include "extensions/common/manifest_url_handlers.h"
[email protected]dccba4f82014-05-29 00:52:56100#include "extensions/common/one_shot_event.h"
treib2e0517f92015-05-07 23:15:36101#include "extensions/common/permissions/api_permission.h"
[email protected]c41003472013-10-19 15:37:25102#include "extensions/common/permissions/permission_message_provider.h"
[email protected]e4452d32013-11-15 23:07:41103#include "extensions/common/permissions/permissions_data.h"
Michael Giuffridab158f3f2017-07-17 19:53:44104#include "extensions/common/switches.h"
[email protected]79a60642012-10-20 21:03:18105
brettw9e85ef42016-11-01 21:01:24106#if BUILDFLAG(ENABLE_SUPERVISED_USERS)
treib8ecc1eb52015-03-04 18:29:06107#include "chrome/browser/supervised_user/supervised_user_service.h"
108#include "chrome/browser/supervised_user/supervised_user_service_factory.h"
109#endif
110
[email protected]eed367e2011-04-12 03:43:31111#if defined(OS_CHROMEOS)
[email protected]88e8ec9152013-01-17 04:05:18112#include "chrome/browser/chromeos/extensions/install_limiter.h"
achuithd3da4f02017-03-23 20:05:29113#include "chrome/browser/chromeos/profiles/profile_helper.h"
pilgrime92c5fcd2014-09-10 23:31:23114#include "storage/browser/fileapi/file_system_backend.h"
115#include "storage/browser/fileapi/file_system_context.h"
[email protected]eed367e2011-04-12 03:43:31116#endif
117
[email protected]55eb70e762012-02-20 17:38:39118using content::BrowserContext;
[email protected]631bb742011-11-02 11:29:39119using content::BrowserThread;
[email protected]98f66112012-12-25 12:59:36120using content::DevToolsAgentHost;
treib2e0517f92015-05-07 23:15:36121using extensions::APIPermission;
deepak.m14ba69e62015-11-17 05:42:12122using extensions::AppSorting;
[email protected]bf3d9df2012-07-24 23:20:27123using extensions::CrxInstaller;
[email protected]1c321ee52012-05-21 03:02:34124using extensions::Extension;
125using extensions::ExtensionIdSet;
126using extensions::ExtensionInfo;
[email protected]599539802014-01-07 23:06:00127using extensions::ExtensionRegistry;
[email protected]289c44b2013-12-17 03:26:57128using extensions::ExtensionSet;
lazyboye8634172016-01-28 00:10:48129using extensions::ExternalInstallInfoFile;
130using extensions::ExternalInstallInfoUpdateUrl;
131using extensions::ExternalProviderInterface;
[email protected]215a7be2012-10-22 19:53:42132using extensions::FeatureSwitch;
[email protected]ffd2f79e2013-11-14 00:11:46133using extensions::InstallVerifier;
[email protected]0d54b682013-11-05 14:15:36134using extensions::ManagementPolicy;
[email protected]1d5e58b2013-01-31 08:41:40135using extensions::Manifest;
treib2e0517f92015-05-07 23:15:36136using extensions::PermissionID;
137using extensions::PermissionIDSet;
[email protected]c2e66e12012-06-27 06:27:06138using extensions::PermissionSet;
[email protected]9f4e4f082013-06-21 07:11:19139using extensions::SharedModuleInfo;
[email protected]90878c52014-04-04 18:21:02140using extensions::SharedModuleService;
limasdf0deef2042017-05-03 19:17:17141using extensions::UnloadedExtensionReason;
[email protected]5ef47ec2010-01-28 05:58:05142
[email protected]b6ab96d2009-08-20 18:58:19143namespace {
144
[email protected]0db124b02012-11-07 04:55:05145// Wait this many seconds after an extensions becomes idle before updating it.
[email protected]ddc6a122014-06-27 04:52:32146const int kUpdateIdleDelay = 5;
[email protected]0db124b02012-11-07 04:55:05147
Takumi Fujimoto43c8c00f2017-07-26 22:48:56148// IDs of extensions that have been replaced by component extensions and need to
149// be uninstalled.
150const char* kMigratedExtensionIds[] = {
151 "boadgeojelhgndaghljhdicfkmllpafd", // Google Cast
152 "dliochdbjfkdbacpmhlcpmleaejidimm" // Google Cast (Beta)
153};
154
lazyboy75b9def2017-06-06 18:56:59155void DoNothingWithExtensionHost(extensions::ExtensionHost* host) {}
156
[email protected]c6d474f82009-12-16 21:11:06157} // namespace
[email protected]b6ab96d2009-08-20 18:58:19158
[email protected]eaa7dd182010-12-14 11:09:00159// ExtensionService.
[email protected]6014d672008-12-05 00:38:25160
[email protected]8e4560b62011-01-14 10:09:14161void ExtensionService::CheckExternalUninstall(const std::string& id) {
[email protected]a29a517a2011-01-21 21:11:12162 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]a8af9fdb2010-10-28 21:52:20163
[email protected]7a4c6852010-09-16 03:44:22164 // Check if the providers know about this extension.
achuith2f5578b2016-02-26 21:57:13165 for (const auto& provider : external_extension_providers_) {
166 DCHECK(provider->IsReady());
167 if (provider->HasExtension(id))
[email protected]0a60a2e2010-10-25 16:15:21168 return; // Yup, known extension, don't uninstall.
[email protected]7a4c6852010-09-16 03:44:22169 }
170
[email protected]0f48fca2011-05-19 18:46:35171 // We get the list of external extensions to check from preferences.
172 // It is possible that an extension has preferences but is not loaded.
173 // For example, an extension that requires experimental permissions
174 // will not be loaded if the experimental command line flag is not used.
175 // In this case, do not uninstall.
[email protected]31bb5ee62012-09-12 22:58:40176 if (!GetInstalledExtension(id)) {
[email protected]0f48fca2011-05-19 18:46:35177 // We can't call UninstallExtension with an unloaded/invalid
178 // extension ID.
179 LOG(WARNING) << "Attempted uninstallation of unloaded/invalid extension "
180 << "with id: " << id;
181 return;
182 }
[email protected]42d58f62014-07-31 01:32:45183 UninstallExtension(id,
184 extensions::UNINSTALL_REASON_ORPHANED_EXTERNAL_EXTENSION,
achuith2f5578b2016-02-26 21:57:13185 base::Bind(&base::DoNothing), nullptr);
[email protected]7a4c6852010-09-16 03:44:22186}
187
[email protected]8e4560b62011-01-14 10:09:14188void ExtensionService::ClearProvidersForTesting() {
[email protected]7a4c6852010-09-16 03:44:22189 external_extension_providers_.clear();
190}
191
[email protected]8e4560b62011-01-14 10:09:14192void ExtensionService::AddProviderForTesting(
lazyboyf33109d2016-08-31 00:37:08193 std::unique_ptr<ExternalProviderInterface> test_provider) {
[email protected]a29a517a2011-01-21 21:11:12194 CHECK(test_provider);
lazyboyf33109d2016-08-31 00:37:08195 external_extension_providers_.push_back(std::move(test_provider));
[email protected]7a4c6852010-09-16 03:44:22196}
197
[email protected]8f959f522014-08-06 06:26:28198void ExtensionService::BlacklistExtensionForTest(
199 const std::string& extension_id) {
mlerman6a37b6a42014-11-26 22:10:53200 ExtensionIdSet blacklisted;
[email protected]8f959f522014-08-06 06:26:28201 ExtensionIdSet unchanged;
mlerman6a37b6a42014-11-26 22:10:53202 blacklisted.insert(extension_id);
203 UpdateBlacklistedExtensions(blacklisted, unchanged);
[email protected]8f959f522014-08-06 06:26:28204}
205
[email protected]9060d8b02012-01-13 02:14:30206bool ExtensionService::OnExternalExtensionUpdateUrlFound(
lazyboye8634172016-01-28 00:10:48207 const ExternalInstallInfoUpdateUrl& info,
208 bool is_initial_load) {
[email protected]ab22ba42011-01-14 16:36:38209 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
lazyboye8634172016-01-28 00:10:48210 CHECK(crx_file::id_util::IdIsValid(info.extension_id));
[email protected]a8af9fdb2010-10-28 21:52:20211
lazyboye8634172016-01-28 00:10:48212 if (Manifest::IsExternalLocation(info.download_location)) {
[email protected]044e86992014-01-24 22:59:11213 // All extensions that are not user specific can be cached.
lazyboye8634172016-01-28 00:10:48214 extensions::ExtensionsBrowserClient::Get()
215 ->GetExtensionCache()
216 ->AllowCaching(info.extension_id);
[email protected]044e86992014-01-24 22:59:11217 }
218
lazyboye8634172016-01-28 00:10:48219 const Extension* extension = GetExtensionById(info.extension_id, true);
[email protected]8a87a5332011-08-11 17:54:59220 if (extension) {
asargent56282ab72016-09-09 16:58:03221 // Already installed. Skip this install if the current location has higher
222 // priority than |info.download_location|, and we aren't doing a
223 // reinstall of a corrupt policy force-installed extension.
[email protected]1d5e58b2013-01-31 08:41:40224 Manifest::Location current = extension->location();
asargent56282ab72016-09-09 16:58:03225 if (!pending_extension_manager_.IsPolicyReinstallForCorruptionExpected(
226 info.extension_id) &&
227 current == Manifest::GetHigherPriorityLocation(
228 current, info.download_location)) {
[email protected]9060d8b02012-01-13 02:14:30229 return false;
lazyboye8634172016-01-28 00:10:48230 }
[email protected]8a87a5332011-08-11 17:54:59231 // Otherwise, overwrite the current installation.
[email protected]7a4c6852010-09-16 03:44:22232 }
[email protected]9060d8b02012-01-13 02:14:30233
lazyboye8634172016-01-28 00:10:48234 // Add |info.extension_id| to the set of pending extensions. If it can not
235 // be added, then there is already a pending record from a higher-priority
236 // install source. In this case, signal that this extension will not be
[email protected]9060d8b02012-01-13 02:14:30237 // installed by returning false.
238 if (!pending_extension_manager()->AddFromExternalUpdateUrl(
lazyboye8634172016-01-28 00:10:48239 info.extension_id, info.install_parameter, *info.update_url,
240 info.download_location, info.creation_flags,
241 info.mark_acknowledged)) {
[email protected]9060d8b02012-01-13 02:14:30242 return false;
[email protected]31bb5ee62012-09-12 22:58:40243 }
[email protected]9060d8b02012-01-13 02:14:30244
lazyboye8634172016-01-28 00:10:48245 if (is_initial_load)
246 update_once_all_providers_are_ready_ = true;
[email protected]9060d8b02012-01-13 02:14:30247 return true;
[email protected]7a4c6852010-09-16 03:44:22248}
249
lazyboye8634172016-01-28 00:10:48250void ExtensionService::OnExternalProviderUpdateComplete(
251 const ExternalProviderInterface* provider,
lazyboy4aeef202016-09-07 21:28:59252 const std::vector<std::unique_ptr<ExternalInstallInfoUpdateUrl>>&
253 update_url_extensions,
254 const std::vector<std::unique_ptr<ExternalInstallInfoFile>>&
255 file_extensions,
lazyboye8634172016-01-28 00:10:48256 const std::set<std::string>& removed_extensions) {
257 // Update pending_extension_manager() with the new extensions first.
lazyboy4aeef202016-09-07 21:28:59258 for (const auto& extension : update_url_extensions)
lazyboye8634172016-01-28 00:10:48259 OnExternalExtensionUpdateUrlFound(*extension, false);
lazyboy4aeef202016-09-07 21:28:59260 for (const auto& extension : file_extensions)
lazyboye8634172016-01-28 00:10:48261 OnExternalExtensionFileFound(*extension);
262
263#if DCHECK_IS_ON()
264 for (const std::string& id : removed_extensions) {
lazyboy4aeef202016-09-07 21:28:59265 for (const auto& extension : update_url_extensions)
lazyboye8634172016-01-28 00:10:48266 DCHECK_NE(id, extension->extension_id);
lazyboy4aeef202016-09-07 21:28:59267 for (const auto& extension : file_extensions)
lazyboye8634172016-01-28 00:10:48268 DCHECK_NE(id, extension->extension_id);
269 }
270#endif
271
272 // Then uninstall before running |updater_|.
273 for (const std::string& id : removed_extensions)
274 CheckExternalUninstall(id);
275
276 if (!update_url_extensions.empty() && updater_) {
277 // Empty params will cause pending extensions to be updated.
278 extensions::ExtensionUpdater::CheckParams empty_params;
279 updater_->CheckNow(empty_params);
280 }
281
282 error_controller_->ShowErrorIfNeeded();
283 external_install_manager_->UpdateExternalExtensionAlert();
284}
285
[email protected]6aeac8342010-10-01 20:21:18286// static
[email protected]cc2f55c2014-07-08 02:19:04287// This function is used to uninstall an extension via sync. The LOG statements
288// within this function are used to inform the user if the uninstall cannot be
289// done.
[email protected]eaa7dd182010-12-14 11:09:00290bool ExtensionService::UninstallExtensionHelper(
291 ExtensionService* extensions_service,
[email protected]cc2f55c2014-07-08 02:19:04292 const std::string& extension_id,
[email protected]e43c61f2014-07-20 21:46:34293 extensions::UninstallReason reason) {
[email protected]d6ebc9792011-04-07 18:18:33294 // We can't call UninstallExtension with an invalid extension ID.
[email protected]31bb5ee62012-09-12 22:58:40295 if (!extensions_service->GetInstalledExtension(extension_id)) {
[email protected]6aeac8342010-10-01 20:21:18296 LOG(WARNING) << "Attempted uninstallation of non-existent extension with "
[email protected]95da88c42011-03-31 10:07:33297 << "id: " << extension_id;
298 return false;
[email protected]6aeac8342010-10-01 20:21:18299 }
300
[email protected]d6ebc9792011-04-07 18:18:33301 // The following call to UninstallExtension will not allow an uninstall of a
302 // policy-controlled extension.
[email protected]439f1e32013-12-09 20:09:09303 base::string16 error;
[email protected]42d58f62014-07-31 01:32:45304 if (!extensions_service->UninstallExtension(
305 extension_id, reason, base::Bind(&base::DoNothing), &error)) {
[email protected]d6ebc9792011-04-07 18:18:33306 LOG(WARNING) << "Cannot uninstall extension with id " << extension_id
307 << ": " << error;
308 return false;
309 }
[email protected]95da88c42011-03-31 10:07:33310
[email protected]6aeac8342010-10-01 20:21:18311 return true;
312}
313
[email protected]eaa7dd182010-12-14 11:09:00314ExtensionService::ExtensionService(Profile* profile,
avi3ef9ec9e2014-12-22 22:50:17315 const base::CommandLine* command_line,
[email protected]650b2d52013-02-10 03:41:45316 const base::FilePath& install_directory,
[email protected]45759612012-07-10 17:21:23317 extensions::ExtensionPrefs* extension_prefs,
[email protected]fdd679b2012-11-15 20:49:39318 extensions::Blacklist* blacklist,
[email protected]0436b102011-04-15 18:30:03319 bool autoupdate_enabled,
[email protected]4a10006a2013-05-17 23:18:35320 bool extensions_enabled,
321 extensions::OneShotEvent* ready)
[email protected]fdd679b2012-11-15 20:49:39322 : extensions::Blacklist::Observer(blacklist),
catmullings98cd1942016-08-30 22:31:59323 command_line_(command_line),
[email protected]fdd679b2012-11-15 20:49:39324 profile_(profile),
[email protected]bd306722012-07-11 20:43:59325 system_(extensions::ExtensionSystem::Get(profile)),
[email protected]73c47932010-12-06 18:13:43326 extension_prefs_(extension_prefs),
[email protected]695b5712012-12-06 23:55:28327 blacklist_(blacklist),
[email protected]5fdfa562013-12-27 17:43:59328 registry_(extensions::ExtensionRegistry::Get(profile)),
[email protected]6c9bedf2014-05-21 03:55:51329 pending_extension_manager_(profile),
[email protected]a9b00ac2009-06-25 21:03:23330 install_directory_(install_directory),
[email protected]0436b102011-04-15 18:30:03331 extensions_enabled_(extensions_enabled),
[email protected]4a10006a2013-05-17 23:18:35332 ready_(ready),
ryanackley48bedbd2015-01-27 23:12:14333 shared_module_service_(new extensions::SharedModuleService(profile_)),
rdevlin.cronin5e510e802016-07-26 15:09:20334 renderer_helper_(
335 extensions::RendererStartupHelperFactory::GetForBrowserContext(
336 profile_)),
ryanackley48bedbd2015-01-27 23:12:14337 app_data_migrator_(new extensions::AppDataMigrator(profile_, registry_)) {
[email protected]a29a517a2011-01-21 21:11:12338 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
rkaplowdd66a1342015-03-05 00:31:49339 TRACE_EVENT0("browser,startup", "ExtensionService::ExtensionService::ctor");
[email protected]a8af9fdb2010-10-28 21:52:20340
[email protected]36a784c2009-06-23 06:21:08341 // Figure out if extension installation should be enabled.
[email protected]367d9b172013-12-03 00:31:02342 if (extensions::ExtensionsBrowserClient::Get()->AreExtensionsDisabled(
343 *command_line, profile))
[email protected]6d60703b2009-08-29 01:29:23344 extensions_enabled_ = false;
[email protected]36a784c2009-06-23 06:21:08345
[email protected]3c4abc82012-10-22 22:25:54346 registrar_.Add(this, chrome::NOTIFICATION_APP_TERMINATING,
347 content::NotificationService::AllBrowserContextsAndSources());
[email protected]adf5a102014-07-31 12:44:06348 registrar_.Add(this,
349 extensions::NOTIFICATION_EXTENSION_PROCESS_TERMINATED,
[email protected]ad50def52011-10-19 23:17:07350 content::NotificationService::AllBrowserContextsAndSources());
[email protected]432115822011-07-10 15:52:27351 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_TERMINATED,
[email protected]ad50def52011-10-19 23:17:07352 content::NotificationService::AllBrowserContextsAndSources());
[email protected]ebe07772014-05-22 04:16:06353 registrar_.Add(this,
354 chrome::NOTIFICATION_PROFILE_DESTRUCTION_STARTED,
355 content::Source<Profile>(profile_));
binjin1569c9b2014-09-05 13:33:18356
weidongg04695232017-06-09 00:01:05357 UpgradeDetector::GetInstance()->AddObserver(this);
358
binjin1569c9b2014-09-05 13:33:18359 extensions::ExtensionManagementFactory::GetForBrowserContext(profile_)
360 ->AddObserver(this);
[email protected]4814b512009-11-07 00:12:29361
rkaplowdd66a1342015-03-05 00:31:49362 // Set up the ExtensionUpdater.
[email protected]93fd78f42009-07-10 16:43:17363 if (autoupdate_enabled) {
[email protected]501105b2013-09-26 05:42:02364 int update_frequency = extensions::kDefaultUpdateFrequencySeconds;
Catherine Mullings625803452017-06-29 22:29:10365 bool is_extensions_update_frequency_switch_used =
366 command_line->HasSwitch(switches::kExtensionsUpdateFrequency);
367 if (is_extensions_update_frequency_switch_used) {
[email protected]e83326f2010-07-31 17:29:25368 base::StringToInt(command_line->GetSwitchValueASCII(
369 switches::kExtensionsUpdateFrequency),
370 &update_frequency);
[email protected]93fd78f42009-07-10 16:43:17371 }
Catherine Mullings625803452017-06-29 22:29:10372 UMA_HISTOGRAM_BOOLEAN("Extensions.UpdateFrequencyCommandLineFlagIsUsed",
373 is_extensions_update_frequency_switch_used);
[email protected]044e86992014-01-24 22:59:11374 updater_.reset(new extensions::ExtensionUpdater(
375 this,
376 extension_prefs,
377 profile->GetPrefs(),
378 profile,
379 update_frequency,
rockotffa65b12014-10-14 17:19:06380 extensions::ExtensionsBrowserClient::Get()->GetExtensionCache(),
rockotdb5192992014-09-16 21:27:02381 base::Bind(ChromeExtensionDownloaderFactory::CreateForProfile,
382 profile)));
[email protected]93fd78f42009-07-10 16:43:17383 }
384
[email protected]25ae0152011-11-18 14:40:02385 component_loader_.reset(
386 new extensions::ComponentLoader(this,
387 profile->GetPrefs(),
[email protected]55e16cd2013-12-18 04:36:08388 g_browser_process->local_state(),
389 profile));
[email protected]8e4560b62011-01-14 10:09:14390
[email protected]0436b102011-04-15 18:30:03391 if (extensions_enabled_) {
[email protected]ae4c37e2012-12-21 01:16:25392 extensions::ExternalProviderImpl::CreateExternalProviders(
393 this, profile_, &external_extension_providers_);
[email protected]873531342011-03-09 12:16:05394 }
[email protected]b671760b2010-07-15 21:13:47395
[email protected]74474042013-11-21 12:03:54396 // Set this as the ExtensionService for app sorting to ensure it causes syncs
397 // if required.
[email protected]b3aa7182013-04-25 04:45:23398 is_first_run_ = !extension_prefs_->SetAlertSystemFirstRun();
399
[email protected]373daf972014-04-10 01:50:44400 error_controller_.reset(
401 new extensions::ExtensionErrorController(profile_, is_first_run_));
[email protected]374ceb6f2014-07-02 19:25:34402 external_install_manager_.reset(
403 new extensions::ExternalInstallManager(profile_, is_first_run_));
[email protected]373daf972014-04-10 01:50:44404
[email protected]c77f2352012-08-08 22:07:58405 extension_action_storage_manager_.reset(
406 new extensions::ExtensionActionStorageManager(profile_));
407
[email protected]cb0e50312011-05-09 15:03:07408 // How long is the path to the Extensions directory?
409 UMA_HISTOGRAM_CUSTOM_COUNTS("Extensions.ExtensionRootPathLength",
drbasicf0d1b262016-08-23 06:10:42410 install_directory_.value().length(), 1, 500, 100);
[email protected]6014d672008-12-05 00:38:25411}
412
[email protected]3f213ad2012-07-26 23:39:41413extensions::PendingExtensionManager*
414 ExtensionService::pending_extension_manager() {
[email protected]b2907fd2011-03-25 16:43:37415 return &pending_extension_manager_;
[email protected]ddb1e5a2010-12-13 20:10:45416}
417
[email protected]eaa7dd182010-12-14 11:09:00418ExtensionService::~ExtensionService() {
weidongg04695232017-06-09 00:01:05419 UpgradeDetector::GetInstance()->RemoveObserver(this);
[email protected]c8d407e2011-04-28 21:27:17420 // No need to unload extensions here because they are profile-scoped, and the
421 // profile is in the process of being deleted.
achuith2f5578b2016-02-26 21:57:13422 for (const auto& provider : external_extension_providers_)
[email protected]8e4560b62011-01-14 10:09:14423 provider->ServiceShutdown();
[email protected]6014d672008-12-05 00:38:25424}
425
[email protected]037228a2012-10-05 01:36:16426void ExtensionService::Shutdown() {
binjin1569c9b2014-09-05 13:33:18427 extensions::ExtensionManagementFactory::GetInstance()
428 ->GetForBrowserContext(profile())
429 ->RemoveObserver(this);
[email protected]037228a2012-10-05 01:36:16430}
431
[email protected]b2907fd2011-03-25 16:43:37432const Extension* ExtensionService::GetExtensionById(
433 const std::string& id, bool include_disabled) const {
[email protected]599539802014-01-07 23:06:00434 int include_mask = ExtensionRegistry::ENABLED;
[email protected]695b5712012-12-06 23:55:28435 if (include_disabled) {
mlerman6a37b6a42014-11-26 22:10:53436 // Include blacklisted and blocked extensions here because there are
437 // hundreds of callers of this function, and many might assume that this
438 // includes those that have been disabled due to blacklisting or blocking.
[email protected]599539802014-01-07 23:06:00439 include_mask |= ExtensionRegistry::DISABLED |
mlerman6a37b6a42014-11-26 22:10:53440 ExtensionRegistry::BLACKLISTED | ExtensionRegistry::BLOCKED;
[email protected]695b5712012-12-06 23:55:28441 }
[email protected]599539802014-01-07 23:06:00442 return registry_->GetExtensionById(id, include_mask);
[email protected]695b5712012-12-06 23:55:28443}
444
[email protected]eaa7dd182010-12-14 11:09:00445void ExtensionService::Init() {
[email protected]a29a517a2011-01-21 21:11:12446 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
rkaplowe65c2ff2015-02-14 16:29:54447 TRACE_EVENT0("browser,startup", "ExtensionService::Init");
rkaplowa8fd8d32015-02-25 21:27:56448 SCOPED_UMA_HISTOGRAM_TIMER("Extensions.ExtensionServiceInitTime");
[email protected]3350d712013-11-18 09:32:24449
[email protected]4a10006a2013-05-17 23:18:35450 DCHECK(!is_ready()); // Can't redo init.
[email protected]bb1bc9b32013-12-21 03:09:14451 DCHECK_EQ(registry_->enabled_extensions().size(), 0u);
[email protected]9f1087e2009-06-15 17:29:32452
benwells22ab8ee2015-08-21 02:55:08453 component_loader_->LoadAll();
achuithd3da4f02017-03-23 20:05:29454 bool load_saved_extensions = true;
emaxx35e8b822017-04-11 02:04:29455 bool load_command_line_extensions = extensions_enabled_;
achuithd3da4f02017-03-23 20:05:29456#if defined(OS_CHROMEOS)
tbarzicd2a741e2017-06-28 20:37:54457 if (chromeos::ProfileHelper::IsSigninProfile(profile_) ||
458 chromeos::ProfileHelper::IsLockScreenAppProfile(profile_)) {
achuithd3da4f02017-03-23 20:05:29459 load_saved_extensions = false;
emaxx35e8b822017-04-11 02:04:29460 load_command_line_extensions = false;
461 }
achuithd3da4f02017-03-23 20:05:29462#endif
rdevlin.croninf2e1cb012017-05-27 01:27:59463 if (load_saved_extensions)
achuithd3da4f02017-03-23 20:05:29464 extensions::InstalledLoader(this).LoadAllExtensions();
rdevlin.croninf2e1cb012017-05-27 01:27:59465
466 OnInstalledExtensionsLoaded();
467
catmullings98cd1942016-08-30 22:31:59468 LoadExtensionsFromCommandLineFlag(switches::kDisableExtensionsExcept);
emaxx35e8b822017-04-11 02:04:29469 if (load_command_line_extensions)
Michael Giuffridab158f3f2017-07-17 19:53:44470 LoadExtensionsFromCommandLineFlag(extensions::switches::kLoadExtension);
benwells22ab8ee2015-08-21 02:55:08471 EnabledReloadableExtensions();
472 MaybeFinishShutdownDelayed();
473 SetReadyAndNotifyListeners();
[email protected]ae4c37e2012-12-21 01:16:25474
Takumi Fujimoto43c8c00f2017-07-26 22:48:56475 UninstallMigratedExtensions();
476
benwells22ab8ee2015-08-21 02:55:08477 // TODO(erikkay): this should probably be deferred to a future point
478 // rather than running immediately at startup.
479 CheckForExternalUpdates();
[email protected]894bb502009-05-21 22:39:57480
benwells22ab8ee2015-08-21 02:55:08481 LoadGreylistFromPrefs();
rkaplowa8fd8d32015-02-25 21:27:56482}
[email protected]3350d712013-11-18 09:32:24483
rkaplowa8fd8d32015-02-25 21:27:56484void ExtensionService::EnabledReloadableExtensions() {
485 TRACE_EVENT0("browser,startup",
486 "ExtensionService::EnabledReloadableExtensions");
487
488 std::vector<std::string> extensions_to_enable;
achuith2f5578b2016-02-26 21:57:13489 for (const auto& e : registry_->disabled_extensions()) {
rkaplowa8fd8d32015-02-25 21:27:56490 if (extension_prefs_->GetDisableReasons(e->id()) ==
achuith2f5578b2016-02-26 21:57:13491 Extension::DISABLE_RELOAD)
rkaplowa8fd8d32015-02-25 21:27:56492 extensions_to_enable.push_back(e->id());
rkaplowa8fd8d32015-02-25 21:27:56493 }
494 for (const std::string& extension : extensions_to_enable) {
495 EnableExtension(extension);
496 }
497}
498
499void ExtensionService::MaybeFinishShutdownDelayed() {
500 TRACE_EVENT0("browser,startup",
501 "ExtensionService::MaybeFinishShutdownDelayed");
502
dchengc963c7142016-04-08 03:55:22503 std::unique_ptr<extensions::ExtensionPrefs::ExtensionsInfo> delayed_info(
rkaplowa8fd8d32015-02-25 21:27:56504 extension_prefs_->GetAllDelayedInstallInfo());
505 for (size_t i = 0; i < delayed_info->size(); ++i) {
506 ExtensionInfo* info = delayed_info->at(i).get();
achuith2f5578b2016-02-26 21:57:13507 scoped_refptr<const Extension> extension(nullptr);
rkaplowa8fd8d32015-02-25 21:27:56508 if (info->extension_manifest) {
509 std::string error;
510 extension = Extension::Create(
511 info->extension_path, info->extension_location,
512 *info->extension_manifest,
513 extension_prefs_->GetDelayedInstallCreationFlags(info->extension_id),
514 info->extension_id, &error);
515 if (extension.get())
516 delayed_installs_.Insert(extension);
517 }
518 }
519 MaybeFinishDelayedInstallations();
dchengc963c7142016-04-08 03:55:22520 std::unique_ptr<extensions::ExtensionPrefs::ExtensionsInfo> delayed_info2(
rkaplowa8fd8d32015-02-25 21:27:56521 extension_prefs_->GetAllDelayedInstallInfo());
522 UMA_HISTOGRAM_COUNTS_100("Extensions.UpdateOnLoad",
523 delayed_info2->size() - delayed_info->size());
[email protected]6014d672008-12-05 00:38:25524}
525
[email protected]2d19eb6e2014-01-27 17:30:00526void ExtensionService::LoadGreylistFromPrefs() {
rkaplowa8fd8d32015-02-25 21:27:56527 TRACE_EVENT0("browser,startup", "ExtensionService::LoadGreylistFromPrefs");
528
dchengc963c7142016-04-08 03:55:22529 std::unique_ptr<ExtensionSet> all_extensions =
[email protected]f47f7172014-03-19 19:27:10530 registry_->GenerateInstalledExtensionsSet();
[email protected]2d19eb6e2014-01-27 17:30:00531
achuith2f5578b2016-02-26 21:57:13532 for (const auto& extension : *all_extensions) {
533 const extensions::BlacklistState state =
534 extension_prefs_->GetExtensionBlacklistState(extension->id());
[email protected]2d19eb6e2014-01-27 17:30:00535 if (state == extensions::BLACKLISTED_SECURITY_VULNERABILITY ||
536 state == extensions::BLACKLISTED_POTENTIALLY_UNWANTED ||
537 state == extensions::BLACKLISTED_CWS_POLICY_VIOLATION)
achuith2f5578b2016-02-26 21:57:13538 greylist_.Insert(extension);
[email protected]2d19eb6e2014-01-27 17:30:00539 }
540}
541
ginkage553af3202015-02-04 12:39:09542bool ExtensionService::UpdateExtension(const extensions::CRXFileInfo& file,
[email protected]044e86992014-01-24 22:59:11543 bool file_ownership_passed,
[email protected]31bb5ee62012-09-12 22:58:40544 CrxInstaller** out_crx_installer) {
[email protected]a29a517a2011-01-21 21:11:12545 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]3c4abc82012-10-22 22:25:54546 if (browser_terminating_) {
547 LOG(WARNING) << "Skipping UpdateExtension due to browser shutdown";
548 // Leak the temp file at extension_path. We don't want to add to the disk
549 // I/O burden at shutdown, we can't rely on the I/O completing anyway, and
550 // the file is in the OS temp directory which should be cleaned up for us.
551 return false;
552 }
[email protected]a8af9fdb2010-10-28 21:52:20553
ginkage553af3202015-02-04 12:39:09554 const std::string& id = file.extension_id;
555
[email protected]3f213ad2012-07-26 23:39:41556 const extensions::PendingExtensionInfo* pending_extension_info =
[email protected]51a3bf8b2012-06-08 22:53:06557 pending_extension_manager()->GetById(id);
[email protected]8ef78fd2010-08-19 17:14:32558
[email protected]695b5712012-12-06 23:55:28559 const Extension* extension = GetInstalledExtension(id);
[email protected]51a3bf8b2012-06-08 22:53:06560 if (!pending_extension_info && !extension) {
[email protected]aa142702010-03-26 01:26:33561 LOG(WARNING) << "Will not update extension " << id
562 << " because it is not installed or pending";
563 // Delete extension_path since we're not creating a CrxInstaller
564 // that would do it for us.
asargentd50b18c2016-04-21 01:17:16565 if (file_ownership_passed &&
566 !GetFileTaskRunner()->PostTask(
tzik8d880ee2017-04-20 19:46:24567 FROM_HERE, base::BindOnce(&extensions::file_util::DeleteFile,
568 file.path, false)))
[email protected]14908b72011-04-20 06:54:36569 NOTREACHED();
[email protected]420a0ec2011-06-01 01:07:03570
571 return false;
[email protected]e957fe52009-06-23 16:51:05572 }
573
treibe960e282015-09-11 10:38:08574 scoped_refptr<CrxInstaller> installer(CrxInstaller::CreateSilent(this));
[email protected]6dfbbf82010-03-12 23:09:16575 installer->set_expected_id(id);
ginkage47e603e2015-02-27 08:42:41576 installer->set_expected_hash(file.expected_hash);
[email protected]464213a2013-10-15 01:06:48577 int creation_flags = Extension::NO_FLAGS;
[email protected]51a3bf8b2012-06-08 22:53:06578 if (pending_extension_info) {
579 installer->set_install_source(pending_extension_info->install_source());
pkotwicz31eb1e8ec2014-10-08 15:26:46580 installer->set_allow_silent_install(true);
treibe960e282015-09-11 10:38:08581 // If the extension came in disabled due to a permission increase, then
582 // don't grant it all the permissions. crbug.com/484214
583 bool has_permissions_increase =
584 extensions::ExtensionPrefs::Get(profile_)->HasDisableReason(
585 id, Extension::DISABLE_PERMISSIONS_INCREASE);
586 const base::Version& expected_version = pending_extension_info->version();
587 if (has_permissions_increase ||
588 pending_extension_info->remote_install() ||
589 !expected_version.IsValid()) {
[email protected]21db9ef2014-05-16 02:06:27590 installer->set_grant_permissions(false);
treibe960e282015-09-11 10:38:08591 } else {
592 installer->set_expected_version(expected_version,
593 false /* fail_install_if_unexpected */);
594 }
mamir0128d5a2016-07-15 20:55:48595 creation_flags = pending_extension_info->creation_flags();
[email protected]464213a2013-10-15 01:06:48596 if (pending_extension_info->mark_acknowledged())
[email protected]374ceb6f2014-07-02 19:25:34597 external_install_manager_->AcknowledgeExternalExtension(id);
[email protected]51a3bf8b2012-06-08 22:53:06598 } else if (extension) {
[email protected]5eb375e92010-11-26 07:50:41599 installer->set_install_source(extension->location());
[email protected]51a3bf8b2012-06-08 22:53:06600 }
[email protected]7d8b7072012-04-07 01:07:46601 // If the extension was installed from or has migrated to the webstore, or
[email protected]fcb2c2c2012-10-17 21:08:45602 // its auto-update URL is from the webstore, treat it as a webstore install.
603 // Note that we ignore some older extensions with blank auto-update URLs
604 // because we are mostly concerned with restrictions on NaCl extensions,
605 // which are newer.
[email protected]75764512011-12-19 19:54:28606 if ((extension && extension->from_webstore()) ||
[email protected]4a5fe3e22013-06-04 07:06:38607 (extension && extensions::ManifestURL::UpdatesFromGallery(extension)) ||
[email protected]963d13c2012-09-29 17:13:35608 (!extension && extension_urls::IsWebstoreUpdateUrl(
[email protected]51a3bf8b2012-06-08 22:53:06609 pending_extension_info->update_url()))) {
[email protected]a12ce8b22012-01-17 18:40:53610 creation_flags |= Extension::FROM_WEBSTORE;
611 }
612
613 // Bookmark apps being updated is kind of a contradiction, but that's because
614 // we mark the default apps as bookmark apps, and they're hosted in the web
615 // store, thus they can get updated. See http://crbug.com/101605 for more
616 // details.
617 if (extension && extension->from_bookmark())
618 creation_flags |= Extension::FROM_BOOKMARK;
619
[email protected]e33bbc22012-08-27 22:05:46620 if (extension && extension->was_installed_by_default())
621 creation_flags |= Extension::WAS_INSTALLED_BY_DEFAULT;
622
[email protected]acc3c7c22014-03-19 06:23:39623 if (extension && extension->was_installed_by_oem())
624 creation_flags |= Extension::WAS_INSTALLED_BY_OEM;
625
benwells1dd4acd2015-12-09 02:20:24626 if (extension)
[email protected]c30bda262014-06-19 04:10:13627 installer->set_do_not_sync(extension_prefs_->DoNotSync(id));
[email protected]ab6c7be42014-01-16 02:05:54628
[email protected]a12ce8b22012-01-17 18:40:53629 installer->set_creation_flags(creation_flags);
630
[email protected]044e86992014-01-24 22:59:11631 installer->set_delete_source(file_ownership_passed);
[email protected]cb0e50312011-05-09 15:03:07632 installer->set_install_cause(extension_misc::INSTALL_CAUSE_UPDATE);
ginkage553af3202015-02-04 12:39:09633 installer->InstallCrxFile(file);
[email protected]420a0ec2011-06-01 01:07:03634
635 if (out_crx_installer)
[email protected]dc24976f2013-06-02 21:15:09636 *out_crx_installer = installer.get();
[email protected]420a0ec2011-06-01 01:07:03637
638 return true;
[email protected]e957fe52009-06-23 16:51:05639}
640
catmullings98cd1942016-08-30 22:31:59641void ExtensionService::LoadExtensionsFromCommandLineFlag(
642 const char* switch_name) {
643 if (command_line_->HasSwitch(switch_name)) {
644 base::CommandLine::StringType path_list =
645 command_line_->GetSwitchValueNative(switch_name);
646 base::StringTokenizerT<base::CommandLine::StringType,
647 base::CommandLine::StringType::const_iterator>
648 t(path_list, FILE_PATH_LITERAL(","));
649 while (t.GetNext()) {
650 std::string extension_id;
651 extensions::UnpackedInstaller::Create(this)->LoadFromCommandLine(
652 base::FilePath(t.token()), &extension_id, false /*only-allow-apps*/);
653 // Extension id is added to whitelist after its extension is loaded
michaelpga8ea0372017-04-06 20:41:35654 // because code is executed asynchronously. TODO(michaelpg): Remove this
655 // assumption so loading extensions does not have to be asynchronous:
656 // crbug.com/708354.
catmullings98cd1942016-08-30 22:31:59657 if (switch_name == switches::kDisableExtensionsExcept)
658 disable_flag_exempted_extensions_.insert(extension_id);
659 }
660 }
661}
662
[email protected]bca4b832014-07-17 20:22:34663void ExtensionService::ReloadExtensionImpl(
[email protected]757d60a2014-05-23 00:11:44664 // "transient" because the process of reloading may cause the reference
665 // to become invalid. Instead, use |extension_id|, a copy.
[email protected]bca4b832014-07-17 20:22:34666 const std::string& transient_extension_id,
667 bool be_noisy) {
[email protected]a29a517a2011-01-21 21:11:12668 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]2a947202013-03-06 04:58:05669
670 // If the extension is already reloading, don't reload again.
[email protected]757d60a2014-05-23 00:11:44671 if (extension_prefs_->GetDisableReasons(transient_extension_id) &
[email protected]2a947202013-03-06 04:58:05672 Extension::DISABLE_RELOAD) {
673 return;
674 }
675
mlerman6a37b6a42014-11-26 22:10:53676 // Ignore attempts to reload a blacklisted or blocked extension. Sometimes
677 // this can happen in a convoluted reload sequence triggered by the
678 // termination of a blacklisted or blocked extension and a naive attempt to
679 // reload it. For an example see http://crbug.com/373842.
680 if (registry_->blacklisted_extensions().Contains(transient_extension_id) ||
681 registry_->blocked_extensions().Contains(transient_extension_id)) {
[email protected]757d60a2014-05-23 00:11:44682 return;
mlerman6a37b6a42014-11-26 22:10:53683 }
[email protected]757d60a2014-05-23 00:11:44684
[email protected]650b2d52013-02-10 03:41:45685 base::FilePath path;
[email protected]757d60a2014-05-23 00:11:44686
687 std::string extension_id = transient_extension_id;
688 const Extension* transient_current_extension =
689 GetExtensionById(extension_id, false);
[email protected]9cddd4702009-07-27 22:09:40690
[email protected]f17dbd42010-08-16 23:21:10691 // Disable the extension if it's loaded. It might not be loaded if it crashed.
[email protected]757d60a2014-05-23 00:11:44692 if (transient_current_extension) {
[email protected]4814b512009-11-07 00:12:29693 // If the extension has an inspector open for its background page, detach
694 // the inspector and hang onto a cookie for it, so that we can reattach
695 // later.
[email protected]31d8f5f22012-04-02 15:22:08696 // TODO(yoz): this is not incognito-safe!
reillyg0ea3fa902014-10-28 15:30:23697 extensions::ProcessManager* manager =
698 extensions::ProcessManager::Get(profile_);
[email protected]3a1dc572012-07-31 22:25:13699 extensions::ExtensionHost* host =
700 manager->GetBackgroundHostForExtension(extension_id);
[email protected]b3f957e62014-08-08 10:09:02701 if (host && DevToolsAgentHost::HasFor(host->host_contents())) {
[email protected]4814b512009-11-07 00:12:29702 // Look for an open inspector for the background page.
[email protected]04ea1bb2013-07-10 09:26:09703 scoped_refptr<DevToolsAgentHost> agent_host =
[email protected]b3f957e62014-08-08 10:09:02704 DevToolsAgentHost::GetOrCreateFor(host->host_contents());
705 agent_host->DisconnectWebContents();
[email protected]04ea1bb2013-07-10 09:26:09706 orphaned_dev_tools_[extension_id] = agent_host;
[email protected]4814b512009-11-07 00:12:29707 }
708
[email protected]757d60a2014-05-23 00:11:44709 path = transient_current_extension->path();
[email protected]58076192013-07-19 19:43:50710 // BeingUpgraded is set back to false when the extension is added.
rdevlin.cronin2c16c602014-11-21 01:35:49711 system_->runtime_data()->SetBeingUpgraded(transient_current_extension->id(),
[email protected]757d60a2014-05-23 00:11:44712 true);
[email protected]44d62b62012-04-11 00:06:03713 DisableExtension(extension_id, Extension::DISABLE_RELOAD);
rdevlin.cronin07f10c12017-02-08 19:37:58714 DCHECK(registry_->disabled_extensions().Contains(extension_id));
[email protected]b914e2952013-04-26 07:10:03715 reloading_extensions_.insert(extension_id);
[email protected]1eb175082010-02-10 09:26:16716 } else {
[email protected]d32c02a2014-06-16 22:58:36717 std::map<std::string, base::FilePath>::const_iterator iter =
718 unloaded_extension_paths_.find(extension_id);
719 if (iter == unloaded_extension_paths_.end()) {
720 return;
721 }
[email protected]1eb175082010-02-10 09:26:16722 path = unloaded_extension_paths_[extension_id];
[email protected]b65272f2009-08-31 15:47:06723 }
724
achuith2f5578b2016-02-26 21:57:13725 transient_current_extension = nullptr;
[email protected]757d60a2014-05-23 00:11:44726
[email protected]9f4e4f082013-06-21 07:11:19727 if (delayed_installs_.Contains(extension_id)) {
[email protected]6f6101832012-11-27 22:10:48728 FinishDelayedInstallation(extension_id);
[email protected]0db124b02012-11-07 04:55:05729 return;
730 }
731
[email protected]43ceb002012-02-10 23:19:15732 // If we're reloading a component extension, use the component extension
733 // loader's reloader.
734 if (component_loader_->Exists(extension_id)) {
735 component_loader_->Reload(extension_id);
736 return;
737 }
738
[email protected]e6090e42010-03-23 22:44:08739 // Check the installed extensions to see if what we're reloading was already
740 // installed.
dchengc963c7142016-04-08 03:55:22741 std::unique_ptr<ExtensionInfo> installed_extension(
[email protected]e6090e42010-03-23 22:44:08742 extension_prefs_->GetInstalledExtensionInfo(extension_id));
743 if (installed_extension.get() &&
744 installed_extension->extension_manifest.get()) {
[email protected]d8c8f25f2011-11-02 18:18:01745 extensions::InstalledLoader(this).Load(*installed_extension, false);
[email protected]e6090e42010-03-23 22:44:08746 } else {
[email protected]d8c8f25f2011-11-02 18:18:01747 // Otherwise, the extension is unpacked (location LOAD).
[email protected]e6090e42010-03-23 22:44:08748 // We should always be able to remember the extension's path. If it's not in
749 // the map, someone failed to update |unloaded_extension_paths_|.
750 CHECK(!path.empty());
[email protected]bca4b832014-07-17 20:22:34751 scoped_refptr<extensions::UnpackedInstaller> unpacked_installer =
752 extensions::UnpackedInstaller::Create(this);
753 unpacked_installer->set_be_noisy_on_failure(be_noisy);
754 unpacked_installer->Load(path);
[email protected]e6090e42010-03-23 22:44:08755 }
[email protected]9cddd4702009-07-27 22:09:40756}
757
[email protected]bca4b832014-07-17 20:22:34758void ExtensionService::ReloadExtension(const std::string& extension_id) {
asargentd50b18c2016-04-21 01:17:16759 ReloadExtensionImpl(extension_id, true); // be_noisy
[email protected]bca4b832014-07-17 20:22:34760}
761
762void ExtensionService::ReloadExtensionWithQuietFailure(
763 const std::string& extension_id) {
asargentd50b18c2016-04-21 01:17:16764 ReloadExtensionImpl(extension_id, false); // be_noisy
[email protected]bca4b832014-07-17 20:22:34765}
766
[email protected]757d60a2014-05-23 00:11:44767bool ExtensionService::UninstallExtension(
768 // "transient" because the process of uninstalling may cause the reference
769 // to become invalid. Instead, use |extenson->id()|.
770 const std::string& transient_extension_id,
[email protected]e43c61f2014-07-20 21:46:34771 extensions::UninstallReason reason,
[email protected]42d58f62014-07-31 01:32:45772 const base::Closure& deletion_done_callback,
[email protected]757d60a2014-05-23 00:11:44773 base::string16* error) {
[email protected]a29a517a2011-01-21 21:11:12774 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]a8af9fdb2010-10-28 21:52:20775
[email protected]757d60a2014-05-23 00:11:44776 scoped_refptr<const Extension> extension =
777 GetInstalledExtension(transient_extension_id);
[email protected]631cf822009-05-15 07:01:25778
[email protected]e7afe2452010-08-22 16:19:13779 // Callers should not send us nonexistent extensions.
[email protected]dc24976f2013-06-02 21:15:09780 CHECK(extension.get());
[email protected]9f1087e2009-06-15 17:29:32781
binjincccacef2014-10-13 19:00:20782 ManagementPolicy* by_policy = system_->management_policy();
[email protected]95da88c42011-03-31 10:07:33783 // Policy change which triggers an uninstall will always set
784 // |external_uninstall| to true so this is the only way to uninstall
785 // managed extensions.
[email protected]90878c52014-04-04 18:21:02786 // Shared modules being uninstalled will also set |external_uninstall| to true
787 // so that we can guarantee users don't uninstall a shared module.
788 // (crbug.com/273300)
789 // TODO(rdevlin.cronin): This is probably not right. We should do something
790 // else, like include an enum IS_INTERNAL_UNINSTALL or IS_USER_UNINSTALL so
791 // we don't do this.
[email protected]cc2f55c2014-07-08 02:19:04792 bool external_uninstall =
[email protected]e43c61f2014-07-20 21:46:34793 (reason == extensions::UNINSTALL_REASON_INTERNAL_MANAGEMENT) ||
dtseng9fb3d5b2015-02-23 17:24:17794 (reason == extensions::UNINSTALL_REASON_COMPONENT_REMOVED) ||
rdevlin.cronin5f6b69d2014-09-20 01:23:35795 (reason == extensions::UNINSTALL_REASON_REINSTALL) ||
[email protected]e43c61f2014-07-20 21:46:34796 (reason == extensions::UNINSTALL_REASON_ORPHANED_EXTERNAL_EXTENSION) ||
[email protected]6ef60012014-07-22 19:08:12797 (reason == extensions::UNINSTALL_REASON_ORPHANED_SHARED_MODULE) ||
798 (reason == extensions::UNINSTALL_REASON_SYNC &&
mamir192d7882016-06-22 17:10:16799 extensions::util::WasInstalledByCustodian(extension->id(), profile_));
[email protected]65187152012-06-02 13:14:14800 if (!external_uninstall &&
binjincccacef2014-10-13 19:00:20801 (!by_policy->UserMayModifySettings(extension.get(), error) ||
802 by_policy->MustRemainInstalled(extension.get(), error))) {
[email protected]ad50def52011-10-19 23:17:07803 content::NotificationService::current()->Notify(
[email protected]adf5a102014-07-31 12:44:06804 extensions::NOTIFICATION_EXTENSION_UNINSTALL_NOT_ALLOWED,
[email protected]6c2381d2011-10-19 02:52:53805 content::Source<Profile>(profile_),
[email protected]dc24976f2013-06-02 21:15:09806 content::Details<const Extension>(extension.get()));
[email protected]d6ebc9792011-04-07 18:18:33807 return false;
808 }
[email protected]95da88c42011-03-31 10:07:33809
juncai33e462102015-05-18 20:48:44810 InstallVerifier::Get(GetBrowserContext())->Remove(extension->id());
[email protected]ffd2f79e2013-11-14 00:11:46811
[email protected]9b217652010-10-08 22:04:23812 UMA_HISTOGRAM_ENUMERATION("Extensions.UninstallType",
[email protected]7fa19f82010-12-21 19:40:08813 extension->GetType(), 100);
treib2e0517f92015-05-07 23:15:36814 RecordPermissionMessagesHistogram(extension.get(), "Uninstall");
[email protected]9b217652010-10-08 22:04:23815
[email protected]831aa212010-03-26 13:55:19816 // Unload before doing more cleanup to ensure that nothing is hanging on to
817 // any of these resources.
limasdf0deef2042017-05-03 19:17:17818 UnloadExtension(extension->id(), UnloadedExtensionReason::UNINSTALL);
asargent96c7ec42016-05-27 02:45:47819 if (registry_->blacklisted_extensions().Contains(extension->id()))
820 registry_->RemoveBlacklisted(extension->id());
[email protected]831aa212010-03-26 13:55:19821
[email protected]9f1087e2009-06-15 17:29:32822 // Tell the backend to start deleting installed extensions on the file thread.
[email protected]12075d12013-02-27 05:38:05823 if (!Manifest::IsUnpackedLocation(extension->location())) {
[email protected]7f8f24f2012-11-15 19:40:14824 if (!GetFileTaskRunner()->PostTask(
825 FROM_HERE,
tzik8d880ee2017-04-20 19:46:24826 base::BindOnce(&ExtensionService::UninstallExtensionOnFileThread,
827 extension->id(), profile_, install_directory_,
828 extension->path())))
[email protected]14908b72011-04-20 06:54:36829 NOTREACHED();
[email protected]9f1087e2009-06-15 17:29:32830 }
831
[email protected]42d58f62014-07-31 01:32:45832 extensions::DataDeleter::StartDeleting(
833 profile_, extension.get(), deletion_done_callback);
[email protected]0d6ec3a72011-09-02 02:09:43834
[email protected]757d60a2014-05-23 00:11:44835 UntrackTerminatedExtension(extension->id());
[email protected]211030342010-09-30 18:41:06836
837 // Notify interested parties that we've uninstalled this extension.
[email protected]e43c61f2014-07-20 21:46:34838 ExtensionRegistry::Get(profile_)
839 ->TriggerOnUninstalled(extension.get(), reason);
[email protected]d6ebc9792011-04-07 18:18:33840
[email protected]757d60a2014-05-23 00:11:44841 delayed_installs_.Remove(extension->id());
[email protected]0db124b02012-11-07 04:55:05842
[email protected]757d60a2014-05-23 00:11:44843 extension_prefs_->OnExtensionUninstalled(
844 extension->id(), extension->location(), external_uninstall);
[email protected]d4eda592013-09-18 03:37:57845
[email protected]333b1de2011-09-12 18:28:50846 // Track the uninstallation.
[email protected]49098f702011-10-13 03:47:18847 UMA_HISTOGRAM_ENUMERATION("Extensions.ExtensionUninstalled", 1, 2);
848
[email protected]d6ebc9792011-04-07 18:18:33849 return true;
[email protected]c10da4b02010-03-25 14:38:32850}
851
[email protected]5a145e82014-05-29 22:19:07852// static
853void ExtensionService::UninstallExtensionOnFileThread(
854 const std::string& id,
855 Profile* profile,
856 const base::FilePath& install_dir,
857 const base::FilePath& extension_path) {
858 extensions::ExtensionAssetsManager* assets_manager =
859 extensions::ExtensionAssetsManager::GetInstance();
860 assets_manager->UninstallExtension(id, profile, install_dir, extension_path);
861}
862
[email protected]c3cfb012011-04-06 22:07:35863bool ExtensionService::IsExtensionEnabled(
864 const std::string& extension_id) const {
[email protected]bb1bc9b32013-12-21 03:09:14865 if (registry_->enabled_extensions().Contains(extension_id) ||
866 registry_->terminated_extensions().Contains(extension_id)) {
[email protected]36429da2011-07-11 20:25:18867 return true;
[email protected]dc9a74f72012-08-17 18:07:21868 }
[email protected]36429da2011-07-11 20:25:18869
[email protected]bb1bc9b32013-12-21 03:09:14870 if (registry_->disabled_extensions().Contains(extension_id) ||
mlerman6a37b6a42014-11-26 22:10:53871 registry_->blacklisted_extensions().Contains(extension_id) ||
872 registry_->blocked_extensions().Contains(extension_id)) {
[email protected]ad83ca242011-07-29 01:32:25873 return false;
[email protected]695b5712012-12-06 23:55:28874 }
[email protected]ad83ca242011-07-29 01:32:25875
mlerman3690e5be2014-12-01 22:57:44876 // Blocked extensions aren't marked as such in prefs, thus if
877 // |block_extensions_| is true then CanBlockExtension() must be called with an
878 // Extension object. If the |extension_id| is not loaded, assume not enabled.
879 if (block_extensions_) {
880 const Extension* extension = GetInstalledExtension(extension_id);
881 if (!extension || CanBlockExtension(extension))
882 return false;
883 }
mlerman6a37b6a42014-11-26 22:10:53884
[email protected]ad83ca242011-07-29 01:32:25885 // If the extension hasn't been loaded yet, check the prefs for it. Assume
886 // enabled unless otherwise noted.
887 return !extension_prefs_->IsExtensionDisabled(extension_id) &&
[email protected]27e528322014-05-27 20:54:30888 !extension_prefs_->IsExtensionBlacklisted(extension_id) &&
[email protected]f574c402012-12-04 23:20:31889 !extension_prefs_->IsExternalExtensionUninstalled(extension_id);
[email protected]c3cfb012011-04-06 22:07:35890}
891
[email protected]eaa7dd182010-12-14 11:09:00892void ExtensionService::EnableExtension(const std::string& extension_id) {
[email protected]a29a517a2011-01-21 21:11:12893 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]a8af9fdb2010-10-28 21:52:20894
rdevlin.croninf87d15f2017-01-26 22:57:19895 // If the extension is currently reloading, it will be enabled once the reload
896 // is complete.
897 if (reloading_extensions_.count(extension_id) > 0)
898 return;
899
asargent96c7ec42016-05-27 02:45:47900 if (IsExtensionEnabled(extension_id) ||
901 extension_prefs_->IsExtensionBlacklisted(extension_id))
[email protected]0c6da502009-08-14 22:32:39902 return;
[email protected]bb1bc9b32013-12-21 03:09:14903 const Extension* extension =
904 registry_->disabled_extensions().GetByID(extension_id);
[email protected]0d54b682013-11-05 14:15:36905
906 ManagementPolicy* policy = system_->management_policy();
achuith2f5578b2016-02-26 21:57:13907 if (extension && policy->MustRemainDisabled(extension, nullptr, nullptr)) {
[email protected]0d54b682013-11-05 14:15:36908 UMA_HISTOGRAM_COUNTS_100("Extensions.EnableDeniedByPolicy", 1);
909 return;
910 }
[email protected]0c6da502009-08-14 22:32:39911
treib8a6d9892015-08-26 10:23:19912 extension_prefs_->SetExtensionEnabled(extension_id);
[email protected]1784e83a2009-09-08 21:01:52913
treib8a6d9892015-08-26 10:23:19914 // This can happen if sync enables an extension that is not installed yet.
[email protected]06f92562011-04-29 19:27:31915 if (!extension)
916 return;
917
[email protected]0c6da502009-08-14 22:32:39918 // Move it over to the enabled list.
[email protected]bb1bc9b32013-12-21 03:09:14919 registry_->AddEnabled(make_scoped_refptr(extension));
920 registry_->RemoveDisabled(extension->id());
[email protected]0c6da502009-08-14 22:32:39921
[email protected]62d30f42009-10-01 22:36:06922 NotifyExtensionLoaded(extension);
[email protected]3bdba0d2011-08-23 07:17:30923
lazyboy75b9def2017-06-06 18:56:59924 MaybeSpinUpLazyBackgroundPage(extension);
[email protected]0c6da502009-08-14 22:32:39925}
926
treibc1192322015-05-20 12:56:07927void ExtensionService::DisableExtension(const std::string& extension_id,
928 int disable_reasons) {
[email protected]a29a517a2011-01-21 21:11:12929 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]a8af9fdb2010-10-28 21:52:20930
asargent96c7ec42016-05-27 02:45:47931 if (extension_prefs_->IsExtensionBlacklisted(extension_id))
932 return;
933
treib8a6d9892015-08-26 10:23:19934 // The extension may have been disabled already. Just add the disable reasons.
[email protected]8f959f522014-08-06 06:26:28935 if (!IsExtensionEnabled(extension_id)) {
treibc1192322015-05-20 12:56:07936 extension_prefs_->AddDisableReasons(extension_id, disable_reasons);
[email protected]1784e83a2009-09-08 21:01:52937 return;
[email protected]8f959f522014-08-06 06:26:28938 }
[email protected]1784e83a2009-09-08 21:01:52939
[email protected]06f92562011-04-29 19:27:31940 const Extension* extension = GetInstalledExtension(extension_id);
elijahtaylor49c09c5c2016-07-09 01:06:22941
rdevlin.cronin07f10c12017-02-08 19:37:58942 // Some extensions cannot be disabled by users:
943 // - |extension| can be null if sync disables an extension that is not
944 // installed yet; allow disablement in this case.
945 // - Shared modules are just resources used by other extensions, and are not
946 // user-controlled.
947 // - EXTERNAL_COMPONENT extensions are not generally modifiable by users, but
948 // can be uninstalled by the browser if the user sets extension-specific
949 // preferences.
950 bool is_controlled_extension =
951 extension && (SharedModuleInfo::IsSharedModule(extension) ||
952 (!system_->management_policy()->UserMayModifySettings(
953 extension, nullptr) &&
954 extension->location() != Manifest::EXTERNAL_COMPONENT));
elijahtaylor49c09c5c2016-07-09 01:06:22955
rdevlin.cronin07f10c12017-02-08 19:37:58956 // Certain disable reasons are always allowed, since they are more internal to
957 // chrome (rather than the user choosing to disable the extension).
958 int internal_disable_reason_mask =
959 Extension::DISABLE_RELOAD | Extension::DISABLE_CORRUPTED |
960 Extension::DISABLE_UPDATE_REQUIRED_BY_POLICY;
961 bool is_internal_disable =
962 (disable_reasons & internal_disable_reason_mask) > 0;
963
964 if (!is_internal_disable && is_controlled_extension)
[email protected]95da88c42011-03-31 10:07:33965 return;
966
treib8a6d9892015-08-26 10:23:19967 extension_prefs_->SetExtensionDisabled(extension_id, disable_reasons);
[email protected]1784e83a2009-09-08 21:01:52968
[email protected]599539802014-01-07 23:06:00969 int include_mask =
970 ExtensionRegistry::EVERYTHING & ~ExtensionRegistry::DISABLED;
971 extension = registry_->GetExtensionById(extension_id, include_mask);
[email protected]06f92562011-04-29 19:27:31972 if (!extension)
973 return;
974
[email protected]45f5b7d2014-01-22 23:47:13975 // The extension is either enabled or terminated.
976 DCHECK(registry_->enabled_extensions().Contains(extension->id()) ||
977 registry_->terminated_extensions().Contains(extension->id()));
[email protected]64742de32013-04-22 08:44:34978
[email protected]5c094792012-09-07 19:44:53979 // Move it over to the disabled list. Don't send a second unload notification
980 // for terminated extensions being disabled.
[email protected]bb1bc9b32013-12-21 03:09:14981 registry_->AddDisabled(make_scoped_refptr(extension));
982 if (registry_->enabled_extensions().Contains(extension->id())) {
983 registry_->RemoveEnabled(extension->id());
limasdf0deef2042017-05-03 19:17:17984 NotifyExtensionUnloaded(extension, UnloadedExtensionReason::DISABLE);
[email protected]5c094792012-09-07 19:44:53985 } else {
[email protected]bb1bc9b32013-12-21 03:09:14986 registry_->RemoveTerminated(extension->id());
[email protected]5c094792012-09-07 19:44:53987 }
[email protected]1784e83a2009-09-08 21:01:52988}
989
mtomasz294bb3e2017-01-24 02:17:52990void ExtensionService::DisableUserExtensionsExcept(
[email protected]1abf05e2013-07-09 17:04:36991 const std::vector<std::string>& except_ids) {
[email protected]e516e4c2013-06-12 17:41:14992 extensions::ManagementPolicy* management_policy =
993 system_->management_policy();
994 extensions::ExtensionList to_disable;
995
achuith2f5578b2016-02-26 21:57:13996 for (const auto& extension : registry_->enabled_extensions()) {
997 if (management_policy->UserMayModifySettings(extension.get(), nullptr))
998 to_disable.push_back(extension);
[email protected]e516e4c2013-06-12 17:41:14999 }
1000
achuith2f5578b2016-02-26 21:57:131001 for (const auto& extension : registry_->terminated_extensions()) {
1002 if (management_policy->UserMayModifySettings(extension.get(), nullptr))
1003 to_disable.push_back(extension);
1004 }
1005
1006 for (const auto& extension : to_disable) {
1007 if (extension->was_installed_by_default() &&
[email protected]3082fe32013-08-06 11:12:381008 extension_urls::IsWebstoreUpdateUrl(
achuith2f5578b2016-02-26 21:57:131009 extensions::ManifestURL::GetUpdateURL(extension.get())))
[email protected]3082fe32013-08-06 11:12:381010 continue;
achuith2f5578b2016-02-26 21:57:131011 const std::string& id = extension->id();
tripta.g0ac673a2017-07-07 05:45:091012 if (!base::ContainsValue(except_ids, id))
[email protected]1abf05e2013-07-09 17:04:361013 DisableExtension(id, extensions::Extension::DISABLE_USER_ACTION);
[email protected]e516e4c2013-06-12 17:41:141014 }
1015}
1016
mlerman6a37b6a42014-11-26 22:10:531017// Extensions that are not locked, components or forced by policy should be
1018// locked. Extensions are no longer considered enabled or disabled. Blacklisted
1019// extensions are now considered both blacklisted and locked.
1020void ExtensionService::BlockAllExtensions() {
1021 if (block_extensions_)
1022 return;
1023 block_extensions_ = true;
1024
1025 // Blacklisted extensions are already unloaded, need not be blocked.
dchengc963c7142016-04-08 03:55:221026 std::unique_ptr<ExtensionSet> extensions =
mlerman6a37b6a42014-11-26 22:10:531027 registry_->GenerateInstalledExtensionsSet(ExtensionRegistry::ENABLED |
1028 ExtensionRegistry::DISABLED |
1029 ExtensionRegistry::TERMINATED);
1030
achuith2f5578b2016-02-26 21:57:131031 for (const auto& extension : *extensions) {
mlerman6a37b6a42014-11-26 22:10:531032 const std::string& id = extension->id();
1033
1034 if (!CanBlockExtension(extension.get()))
1035 continue;
1036
1037 registry_->RemoveEnabled(id);
1038 registry_->RemoveDisabled(id);
1039 registry_->RemoveTerminated(id);
1040
1041 registry_->AddBlocked(extension.get());
limasdf0deef2042017-05-03 19:17:171042 UnloadExtension(id, extensions::UnloadedExtensionReason::LOCK_ALL);
mlerman6a37b6a42014-11-26 22:10:531043 }
1044}
1045
1046// All locked extensions should revert to being either enabled or disabled
1047// as appropriate.
1048void ExtensionService::UnblockAllExtensions() {
1049 block_extensions_ = false;
dchengc963c7142016-04-08 03:55:221050 std::unique_ptr<ExtensionSet> to_unblock =
mlerman6a37b6a42014-11-26 22:10:531051 registry_->GenerateInstalledExtensionsSet(ExtensionRegistry::BLOCKED);
1052
achuith2f5578b2016-02-26 21:57:131053 for (const auto& extension : *to_unblock) {
mlerman6a37b6a42014-11-26 22:10:531054 registry_->RemoveBlocked(extension->id());
1055 AddExtension(extension.get());
1056 }
1057}
1058
[email protected]eaa7dd182010-12-14 11:09:001059void ExtensionService::GrantPermissionsAndEnableExtension(
[email protected]009633c2013-03-07 22:08:281060 const Extension* extension) {
1061 GrantPermissions(extension);
treib2e0517f92015-05-07 23:15:361062 RecordPermissionMessagesHistogram(extension, "ReEnable");
[email protected]8d888c12010-11-30 00:00:251063 EnableExtension(extension->id());
1064}
1065
[email protected]009633c2013-03-07 22:08:281066void ExtensionService::GrantPermissions(const Extension* extension) {
[email protected]be083862012-09-01 03:53:451067 CHECK(extension);
[email protected]8d42db52014-06-20 21:50:501068 extensions::PermissionsUpdater(profile()).GrantActivePermissions(extension);
[email protected]be083862012-09-01 03:53:451069}
1070
[email protected]fe2dd7742011-04-19 22:52:491071// static
1072void ExtensionService::RecordPermissionMessagesHistogram(
[email protected]13c68b62013-05-17 11:29:051073 const Extension* extension, const char* histogram) {
[email protected]de415552013-01-23 04:12:171074 // Since this is called from multiple sources, and since the histogram macros
1075 // use statics, we need to manually lookup the histogram ourselves.
treib2e0517f92015-05-07 23:15:361076 base::HistogramBase* counter = base::LinearHistogram::FactoryGet(
1077 base::StringPrintf("Extensions.Permissions_%s3", histogram),
1078 1,
1079 APIPermission::kEnumBoundary,
1080 APIPermission::kEnumBoundary + 1,
1081 base::HistogramBase::kUmaTargetedHistogramFlag);
1082
1083 base::HistogramBase* counter_has_any = base::BooleanHistogram::FactoryGet(
1084 base::StringPrintf("Extensions.HasPermissions_%s3", histogram),
1085 base::HistogramBase::kUmaTargetedHistogramFlag);
1086
1087 PermissionIDSet permissions =
1088 extensions::PermissionMessageProvider::Get()->GetAllPermissionIDs(
rdevlin.cronine2d0fd02015-09-24 22:35:491089 extension->permissions_data()->active_permissions(),
treib2e0517f92015-05-07 23:15:361090 extension->GetType());
1091 counter_has_any->AddBoolean(!permissions.empty());
1092 for (const PermissionID& id : permissions)
1093 counter->Add(id.id());
[email protected]fe2dd7742011-04-19 22:52:491094}
1095
[email protected]eaa7dd182010-12-14 11:09:001096void ExtensionService::NotifyExtensionLoaded(const Extension* extension) {
[email protected]f9c8c7c72014-07-31 16:42:311097 // The URLRequestContexts need to be first to know that the extension
[email protected]62d30f42009-10-01 22:36:061098 // was loaded, otherwise a race can arise where a renderer that is created
1099 // for the extension may try to load an extension URL with an extension id
[email protected]57a777f72010-03-31 01:09:421100 // that the request context doesn't yet know about. The profile is responsible
1101 // for ensuring its URLRequestContexts appropriately discover the loaded
1102 // extension.
rockot494f0072015-07-29 17:58:071103 system_->RegisterExtensionWithRequestContexts(
1104 extension,
1105 base::Bind(&ExtensionService::OnExtensionRegisteredWithRequestContexts,
1106 AsWeakPtr(), make_scoped_refptr(extension)));
[email protected]62d30f42009-10-01 22:36:061107
rdevlin.cronin5e510e802016-07-26 15:09:201108 renderer_helper_->OnExtensionLoaded(*extension);
[email protected]77a6970c2011-04-23 16:58:561109
limasdf4e9e53092017-04-14 15:37:051110 // Tell subsystems that use the ExtensionRegistryObserver::OnExtensionLoaded
1111 // about the new extension.
[email protected]3442a662012-01-12 08:06:171112 //
1113 // NOTE: It is important that this happen after notifying the renderers about
1114 // the new extensions so that if we navigate to an extension URL in
limasdf4e9e53092017-04-14 15:37:051115 // ExtensionRegistryObserver::OnExtensionLoaded the renderer is guaranteed to
1116 // know about it.
[email protected]dcc47642014-03-26 22:03:491117 registry_->TriggerOnLoaded(extension);
1118
[email protected]dcc47642014-03-26 22:03:491119 // TODO(kalman): Convert ExtensionSpecialStoragePolicy to a
1120 // BrowserContextKeyedService and use ExtensionRegistryObserver.
[email protected]c8d407e2011-04-28 21:27:171121 profile_->GetExtensionSpecialStoragePolicy()->
rdevlin.croninbc8979a2014-09-30 01:08:501122 GrantRightsForExtension(extension, profile_);
[email protected]c8d407e2011-04-28 21:27:171123
[email protected]dcc47642014-03-26 22:03:491124 // TODO(kalman): This is broken. The crash reporter is process-wide so doesn't
1125 // work properly multi-profile. Besides which, it should be using
1126 // ExtensionRegistryObserver. See http://crbug.com/355029.
[email protected]c8d407e2011-04-28 21:27:171127 UpdateActiveExtensionsInCrashReporter();
1128
[email protected]d695bb12014-06-05 16:16:301129 const extensions::PermissionsData* permissions_data =
[email protected]a6910e72014-06-06 05:04:361130 extension->permissions_data();
[email protected]d695bb12014-06-05 16:16:301131
[email protected]c8d407e2011-04-28 21:27:171132 // If the extension has permission to load chrome://favicon/ resources we need
1133 // to make sure that the FaviconSource is registered with the
1134 // ChromeURLDataManager.
[email protected]d695bb12014-06-05 16:16:301135 if (permissions_data->HasHostPermission(GURL(chrome::kChromeUIFaviconURL))) {
pkotwiczd95aa6592017-05-11 02:26:211136 FaviconSource* favicon_source = new FaviconSource(profile_);
[email protected]24ea7a12013-01-27 23:54:531137 content::URLDataSource::Add(profile_, favicon_source);
[email protected]c8d407e2011-04-28 21:27:171138 }
[email protected]b07e606e2012-09-15 20:16:151139
[email protected]b07e606e2012-09-15 20:16:151140 // Same for chrome://theme/ resources.
[email protected]d695bb12014-06-05 16:16:301141 if (permissions_data->HasHostPermission(GURL(chrome::kChromeUIThemeURL))) {
[email protected]b07e606e2012-09-15 20:16:151142 ThemeSource* theme_source = new ThemeSource(profile_);
[email protected]24ea7a12013-01-27 23:54:531143 content::URLDataSource::Add(profile_, theme_source);
[email protected]b07e606e2012-09-15 20:16:151144 }
[email protected]b07e606e2012-09-15 20:16:151145
[email protected]5eddc3e2011-10-26 04:33:311146 // Same for chrome://thumb/ resources.
[email protected]d695bb12014-06-05 16:16:301147 if (permissions_data->HasHostPermission(
1148 GURL(chrome::kChromeUIThumbnailURL))) {
[email protected]420e6d92013-09-17 01:48:511149 ThumbnailSource* thumbnail_source = new ThumbnailSource(profile_, false);
[email protected]24ea7a12013-01-27 23:54:531150 content::URLDataSource::Add(profile_, thumbnail_source);
[email protected]5eddc3e2011-10-26 04:33:311151 }
[email protected]62d30f42009-10-01 22:36:061152}
1153
rockot494f0072015-07-29 17:58:071154void ExtensionService::OnExtensionRegisteredWithRequestContexts(
1155 scoped_refptr<const extensions::Extension> extension) {
1156 registry_->AddReady(extension);
1157 if (registry_->enabled_extensions().Contains(extension->id()))
1158 registry_->TriggerOnReady(extension.get());
1159}
1160
limasdf0deef2042017-05-03 19:17:171161void ExtensionService::NotifyExtensionUnloaded(const Extension* extension,
1162 UnloadedExtensionReason reason) {
[email protected]e51232f32014-04-18 20:05:361163 registry_->TriggerOnUnloaded(extension, reason);
1164
rdevlin.croninc40d39f2016-08-04 23:42:131165 renderer_helper_->OnExtensionUnloaded(*extension);
[email protected]77a6970c2011-04-23 16:58:561166
[email protected]31d8f5f22012-04-02 15:22:081167 system_->UnregisterExtensionWithRequestContexts(extension->id(), reason);
[email protected]dcc47642014-03-26 22:03:491168
1169 // TODO(kalman): Convert ExtensionSpecialStoragePolicy to a
1170 // BrowserContextKeyedService and use ExtensionRegistryObserver.
[email protected]c8d407e2011-04-28 21:27:171171 profile_->GetExtensionSpecialStoragePolicy()->
1172 RevokeRightsForExtension(extension);
1173
[email protected]b777b332011-04-16 04:01:081174#if defined(OS_CHROMEOS)
[email protected]ac66e452013-01-11 09:21:231175 // Revoke external file access for the extension from its file system context.
1176 // It is safe to access the extension's storage partition at this point. The
1177 // storage partition may get destroyed only after the extension gets unloaded.
[email protected]3a746ec2014-03-15 05:30:561178 GURL site =
1179 extensions::util::GetSiteForExtensionId(extension->id(), profile_);
[email protected]cd501a72014-08-22 19:58:311180 storage::FileSystemContext* filesystem_context =
1181 BrowserContext::GetStoragePartitionForSite(profile_, site)
1182 ->GetFileSystemContext();
[email protected]f19bbf62013-07-09 01:22:321183 if (filesystem_context && filesystem_context->external_backend()) {
1184 filesystem_context->external_backend()->
[email protected]c8d407e2011-04-28 21:27:171185 RevokeAccessForExtension(extension->id());
[email protected]62d30f42009-10-01 22:36:061186 }
[email protected]c8d407e2011-04-28 21:27:171187#endif
1188
[email protected]dcc47642014-03-26 22:03:491189 // TODO(kalman): This is broken. The crash reporter is process-wide so doesn't
1190 // work properly multi-profile. Besides which, it should be using
1191 // ExtensionRegistryObserver::OnExtensionLoaded. See http://crbug.com/355029.
[email protected]c8d407e2011-04-28 21:27:171192 UpdateActiveExtensionsInCrashReporter();
[email protected]62d30f42009-10-01 22:36:061193}
1194
[email protected]599539802014-01-07 23:06:001195content::BrowserContext* ExtensionService::GetBrowserContext() const {
1196 // Implemented in the .cc file to avoid adding a profile.h dependency to
1197 // extension_service.h.
1198 return profile_;
1199}
1200
[email protected]25ae0152011-11-18 14:40:021201bool ExtensionService::is_ready() {
[email protected]4a10006a2013-05-17 23:18:351202 return ready_->is_signaled();
[email protected]25ae0152011-11-18 14:40:021203}
1204
[email protected]4ee07c62012-08-21 12:40:421205void ExtensionService::CheckManagementPolicy() {
[email protected]0d54b682013-11-05 14:15:361206 std::vector<std::string> to_unload;
1207 std::map<std::string, Extension::DisableReason> to_disable;
binjin8e3d0182014-12-04 16:44:281208 std::vector<std::string> to_enable;
[email protected]695b5712012-12-06 23:55:281209
[email protected]0d54b682013-11-05 14:15:361210 // Loop through the extensions list, finding extensions we need to unload or
1211 // disable.
achuith2f5578b2016-02-26 21:57:131212 for (const auto& extension : registry_->enabled_extensions()) {
binjin8e3d0182014-12-04 16:44:281213 if (!system_->management_policy()->UserMayLoad(extension.get(), nullptr))
[email protected]0d54b682013-11-05 14:15:361214 to_unload.push_back(extension->id());
1215 Extension::DisableReason disable_reason = Extension::DISABLE_NONE;
1216 if (system_->management_policy()->MustRemainDisabled(
binjin8e3d0182014-12-04 16:44:281217 extension.get(), &disable_reason, nullptr))
[email protected]0d54b682013-11-05 14:15:361218 to_disable[extension->id()] = disable_reason;
[email protected]aa96d3a2010-08-21 08:45:251219 }
1220
binjin8e3d0182014-12-04 16:44:281221 extensions::ExtensionManagement* management =
1222 extensions::ExtensionManagementFactory::GetForBrowserContext(profile());
nrpetere33d2a5b2017-04-25 00:12:311223 extensions::PermissionsUpdater(profile()).SetDefaultPolicyHostRestrictions(
1224 management->GetDefaultRuntimeBlockedHosts(),
1225 management->GetDefaultRuntimeAllowedHosts());
1226 for (const auto& extension : registry_->enabled_extensions()) {
1227 bool uses_default =
1228 management->UsesDefaultRuntimeHostRestrictions(extension.get());
1229 if (uses_default) {
1230 extensions::PermissionsUpdater(profile()).SetUsesDefaultHostRestrictions(
1231 extension.get());
1232 } else {
1233 extensions::PermissionsUpdater(profile()).SetPolicyHostRestrictions(
1234 extension.get(), management->GetRuntimeBlockedHosts(extension.get()),
1235 management->GetRuntimeAllowedHosts(extension.get()));
1236 }
1237 }
binjin8e3d0182014-12-04 16:44:281238
1239 // Loop through the disabled extension list, find extensions to re-enable
1240 // automatically. These extensions are exclusive from the |to_disable| and
1241 // |to_unload| lists constructed above, since disabled_extensions() and
1242 // enabled_extensions() are supposed to be mutually exclusive.
achuith2f5578b2016-02-26 21:57:131243 for (const auto& extension : registry_->disabled_extensions()) {
binjin8e3d0182014-12-04 16:44:281244 // Find all disabled extensions disabled due to minimum version requirement,
1245 // but now satisfying it.
1246 if (management->CheckMinimumVersion(extension.get(), nullptr) &&
1247 extension_prefs_->HasDisableReason(
1248 extension->id(), Extension::DISABLE_UPDATE_REQUIRED_BY_POLICY)) {
1249 // Is DISABLE_UPDATE_REQUIRED_BY_POLICY the *only* reason?
1250 if (extension_prefs_->GetDisableReasons(extension->id()) ==
1251 Extension::DISABLE_UPDATE_REQUIRED_BY_POLICY) {
1252 // We need to enable those disabled *only* due to minimum version
1253 // requirement.
1254 to_enable.push_back(extension->id());
1255 }
1256 extension_prefs_->RemoveDisableReason(
1257 extension->id(), Extension::DISABLE_UPDATE_REQUIRED_BY_POLICY);
1258 }
1259 }
1260
1261 for (const std::string& id : to_unload)
limasdf0deef2042017-05-03 19:17:171262 UnloadExtension(id, UnloadedExtensionReason::DISABLE);
[email protected]0d54b682013-11-05 14:15:361263
achuith2f5578b2016-02-26 21:57:131264 for (const auto& i : to_disable)
1265 DisableExtension(i.first, i.second);
binjin8e3d0182014-12-04 16:44:281266
1267 // No extension is getting re-enabled here after disabling/unloading
1268 // because to_enable is mutually exclusive to to_disable + to_unload.
1269 for (const std::string& id : to_enable)
1270 EnableExtension(id);
1271
1272 if (updater_.get()) {
1273 // Find all extensions disabled due to minimum version requirement from
1274 // policy (including the ones that got disabled just now), and check
1275 // for update.
1276 extensions::ExtensionUpdater::CheckParams to_recheck;
achuith2f5578b2016-02-26 21:57:131277 for (const auto& extension : registry_->disabled_extensions()) {
binjin8e3d0182014-12-04 16:44:281278 if (extension_prefs_->GetDisableReasons(extension->id()) ==
1279 Extension::DISABLE_UPDATE_REQUIRED_BY_POLICY) {
1280 // The minimum version check is the only thing holding this extension
1281 // back, so check if it can be updated to fix that.
1282 to_recheck.ids.push_back(extension->id());
1283 }
1284 }
1285 if (!to_recheck.ids.empty())
1286 updater_->CheckNow(to_recheck);
1287 }
[email protected]aa96d3a2010-08-21 08:45:251288}
1289
[email protected]31206602011-04-13 23:07:321290void ExtensionService::CheckForUpdatesSoon() {
[email protected]90878c52014-04-04 18:21:021291 // This can legitimately happen in unit tests.
1292 if (!updater_.get())
1293 return;
1294
raphael.kubo.da.costa8527f942016-11-15 17:03:511295 updater_->CheckSoon();
[email protected]c3cfb012011-04-06 22:07:351296}
1297
[email protected]8e4560b62011-01-14 10:09:141298// Some extensions will autoupdate themselves externally from Chrome. These
rkaplowa8fd8d32015-02-25 21:27:561299// are typically part of some larger client application package. To support
1300// these, the extension will register its location in the preferences file
[email protected]8e4560b62011-01-14 10:09:141301// (and also, on Windows, in the registry) and this code will periodically
1302// check that location for a .crx file, which it will then install locally if
1303// a new version is available.
rkaplowa8fd8d32015-02-25 21:27:561304// Errors are reported through ExtensionErrorReporter. Success is not
[email protected]8e4560b62011-01-14 10:09:141305// reported.
[email protected]eaa7dd182010-12-14 11:09:001306void ExtensionService::CheckForExternalUpdates() {
lazyboy77214d3c2017-04-04 16:46:121307 if (external_updates_disabled_for_test_)
1308 return;
1309
[email protected]a29a517a2011-01-21 21:11:121310 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
rkaplowa8fd8d32015-02-25 21:27:561311 TRACE_EVENT0("browser,startup", "ExtensionService::CheckForExternalUpdates");
1312 SCOPED_UMA_HISTOGRAM_TIMER("Extensions.CheckForExternalUpdatesTime");
[email protected]8e4560b62011-01-14 10:09:141313
1314 // Note that this installation is intentionally silent (since it didn't
1315 // go through the front-end). Extensions that are registered in this
1316 // way are effectively considered 'pre-bundled', and so implicitly
1317 // trusted. In general, if something has HKLM or filesystem access,
1318 // they could install an extension manually themselves anyway.
[email protected]a29a517a2011-01-21 21:11:121319
[email protected]8e4560b62011-01-14 10:09:141320 // Ask each external extension provider to give us a call back for each
1321 // extension they know about. See OnExternalExtension(File|UpdateUrl)Found.
achuith2f5578b2016-02-26 21:57:131322 for (const auto& provider : external_extension_providers_)
[email protected]8e4560b62011-01-14 10:09:141323 provider->VisitRegisteredExtension();
[email protected]8e4560b62011-01-14 10:09:141324
[email protected]50067e52011-10-20 23:17:071325 // Do any required work that we would have done after completion of all
1326 // providers.
[email protected]373daf972014-04-10 01:50:441327 if (external_extension_providers_.empty())
[email protected]50067e52011-10-20 23:17:071328 OnAllExternalProvidersReady();
[email protected]9f1087e2009-06-15 17:29:321329}
1330
[email protected]50067e52011-10-20 23:17:071331void ExtensionService::OnExternalProviderReady(
lazyboye8634172016-01-28 00:10:481332 const ExternalProviderInterface* provider) {
[email protected]a29a517a2011-01-21 21:11:121333 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]50067e52011-10-20 23:17:071334 CHECK(provider->IsReady());
[email protected]a29a517a2011-01-21 21:11:121335
1336 // An external provider has finished loading. We only take action
[email protected]8e4560b62011-01-14 10:09:141337 // if all of them are finished. So we check them first.
[email protected]94fde232012-04-27 10:22:301338 if (AreAllExternalProvidersReady())
1339 OnAllExternalProvidersReady();
1340}
1341
1342bool ExtensionService::AreAllExternalProvidersReady() const {
achuith2f5578b2016-02-26 21:57:131343 for (const auto& provider : external_extension_providers_) {
1344 if (!provider->IsReady())
[email protected]94fde232012-04-27 10:22:301345 return false;
[email protected]8e4560b62011-01-14 10:09:141346 }
[email protected]94fde232012-04-27 10:22:301347 return true;
[email protected]50067e52011-10-20 23:17:071348}
1349
1350void ExtensionService::OnAllExternalProvidersReady() {
1351 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]94fde232012-04-27 10:22:301352 base::TimeDelta elapsed = base::Time::Now() - profile_->GetStartTime();
1353 UMA_HISTOGRAM_TIMES("Extension.ExternalProvidersReadyAfter", elapsed);
[email protected]50067e52011-10-20 23:17:071354
1355 // Install any pending extensions.
[email protected]94fde232012-04-27 10:22:301356 if (update_once_all_providers_are_ready_ && updater()) {
1357 update_once_all_providers_are_ready_ = false;
[email protected]4e9b59d2013-12-18 06:47:141358 extensions::ExtensionUpdater::CheckParams params;
1359 params.callback = external_updates_finished_callback_;
1360 updater()->CheckNow(params);
[email protected]8e4560b62011-01-14 10:09:141361 }
1362
1363 // Uninstall all the unclaimed extensions.
dchengc963c7142016-04-08 03:55:221364 std::unique_ptr<extensions::ExtensionPrefs::ExtensionsInfo> extensions_info(
[email protected]8e4560b62011-01-14 10:09:141365 extension_prefs_->GetInstalledExtensionsInfo());
1366 for (size_t i = 0; i < extensions_info->size(); ++i) {
1367 ExtensionInfo* info = extensions_info->at(i).get();
[email protected]1d5e58b2013-01-31 08:41:401368 if (Manifest::IsExternalLocation(info->extension_location))
[email protected]8e4560b62011-01-14 10:09:141369 CheckExternalUninstall(info->extension_id);
1370 }
[email protected]e5af875f2011-10-10 21:09:141371
[email protected]373daf972014-04-10 01:50:441372 error_controller_->ShowErrorIfNeeded();
[email protected]a9aa5932012-01-25 08:27:401373
[email protected]374ceb6f2014-07-02 19:25:341374 external_install_manager_->UpdateExternalExtensionAlert();
[email protected]e5af875f2011-10-10 21:09:141375}
1376
limasdf0deef2042017-05-03 19:17:171377void ExtensionService::UnloadExtension(const std::string& extension_id,
1378 UnloadedExtensionReason reason) {
[email protected]27e469a2010-01-11 20:35:091379 // Make sure the extension gets deleted after we return from this function.
[email protected]599539802014-01-07 23:06:001380 int include_mask =
1381 ExtensionRegistry::EVERYTHING & ~ExtensionRegistry::TERMINATED;
[email protected]9adb9692010-10-29 23:14:021382 scoped_refptr<const Extension> extension(
[email protected]599539802014-01-07 23:06:001383 registry_->GetExtensionById(extension_id, include_mask));
[email protected]631cf822009-05-15 07:01:251384
[email protected]fa0c96732010-11-17 00:14:231385 // This method can be called via PostTask, so the extension may have been
1386 // unloaded by the time this runs.
[email protected]dc24976f2013-06-02 21:15:091387 if (!extension.get()) {
[email protected]dd163fb02011-05-04 22:22:171388 // In case the extension may have crashed/uninstalled. Allow the profile to
1389 // clean up its RequestContexts.
[email protected]31d8f5f22012-04-02 15:22:081390 system_->UnregisterExtensionWithRequestContexts(extension_id, reason);
[email protected]fa0c96732010-11-17 00:14:231391 return;
[email protected]dd163fb02011-05-04 22:22:171392 }
[email protected]0c6da502009-08-14 22:32:391393
[email protected]1eb175082010-02-10 09:26:161394 // Keep information about the extension so that we can reload it later
1395 // even if it's not permanently installed.
1396 unloaded_extension_paths_[extension->id()] = extension->path();
1397
[email protected]f17dbd42010-08-16 23:21:101398 // Clean up if the extension is meant to be enabled after a reload.
[email protected]b914e2952013-04-26 07:10:031399 reloading_extensions_.erase(extension->id());
[email protected]f17dbd42010-08-16 23:21:101400
[email protected]bb1bc9b32013-12-21 03:09:141401 if (registry_->disabled_extensions().Contains(extension->id())) {
1402 registry_->RemoveDisabled(extension->id());
[email protected]dd163fb02011-05-04 22:22:171403 // Make sure the profile cleans up its RequestContexts when an already
1404 // disabled extension is unloaded (since they are also tracking the disabled
1405 // extensions).
[email protected]31d8f5f22012-04-02 15:22:081406 system_->UnregisterExtensionWithRequestContexts(extension_id, reason);
[email protected]45f5b7d2014-01-22 23:47:131407 // Don't send the unloaded notification. It was sent when the extension
1408 // was disabled.
[email protected]60a174a2013-08-02 20:29:281409 } else {
[email protected]bb1bc9b32013-12-21 03:09:141410 // Remove the extension from the enabled list.
1411 registry_->RemoveEnabled(extension->id());
[email protected]60a174a2013-08-02 20:29:281412 NotifyExtensionUnloaded(extension.get(), reason);
[email protected]0c6da502009-08-14 22:32:391413 }
1414
[email protected]fb789532013-08-27 02:40:211415 content::NotificationService::current()->Notify(
[email protected]adf5a102014-07-31 12:44:061416 extensions::NOTIFICATION_EXTENSION_REMOVED,
[email protected]fb789532013-08-27 02:40:211417 content::Source<Profile>(profile_),
1418 content::Details<const Extension>(extension.get()));
[email protected]631cf822009-05-15 07:01:251419}
1420
[email protected]8b1ec202013-09-05 02:09:501421void ExtensionService::RemoveComponentExtension(
1422 const std::string& extension_id) {
1423 scoped_refptr<const Extension> extension(
1424 GetExtensionById(extension_id, false));
limasdf0deef2042017-05-03 19:17:171425 UnloadExtension(extension_id, UnloadedExtensionReason::UNINSTALL);
[email protected]ebe07772014-05-22 04:16:061426 if (extension.get()) {
[email protected]e43c61f2014-07-20 21:46:341427 ExtensionRegistry::Get(profile_)->TriggerOnUninstalled(
dtseng9fb3d5b2015-02-23 17:24:171428 extension.get(), extensions::UNINSTALL_REASON_COMPONENT_REMOVED);
[email protected]ebe07772014-05-22 04:16:061429 }
[email protected]8b1ec202013-09-05 02:09:501430}
1431
[email protected]bb1bc9b32013-12-21 03:09:141432void ExtensionService::UnloadAllExtensionsForTest() {
1433 UnloadAllExtensionsInternal();
[email protected]9f1087e2009-06-15 17:29:321434}
1435
[email protected]bb1bc9b32013-12-21 03:09:141436void ExtensionService::ReloadExtensionsForTest() {
1437 // Calling UnloadAllExtensionsForTest here triggers a false-positive presubmit
1438 // warning about calling test code in production.
1439 UnloadAllExtensionsInternal();
[email protected]eac88332012-12-26 17:57:451440 component_loader_->LoadAll();
[email protected]d8c8f25f2011-11-02 18:18:011441 extensions::InstalledLoader(this).LoadAllExtensions();
rdevlin.croninf2e1cb012017-05-27 01:27:591442 OnInstalledExtensionsLoaded();
[email protected]4a10006a2013-05-17 23:18:351443 // Don't call SetReadyAndNotifyListeners() since tests call this multiple
1444 // times.
[email protected]9f1087e2009-06-15 17:29:321445}
1446
[email protected]820d9bd2013-04-03 03:46:031447void ExtensionService::SetReadyAndNotifyListeners() {
rkaplowa8fd8d32015-02-25 21:27:561448 TRACE_EVENT0("browser,startup",
1449 "ExtensionService::SetReadyAndNotifyListeners");
1450 SCOPED_UMA_HISTOGRAM_TIMER(
1451 "Extensions.ExtensionServiceNotifyReadyListenersTime");
1452
[email protected]4a10006a2013-05-17 23:18:351453 ready_->Signal();
[email protected]820d9bd2013-04-03 03:46:031454 content::NotificationService::current()->Notify(
[email protected]adf5a102014-07-31 12:44:061455 extensions::NOTIFICATION_EXTENSIONS_READY_DEPRECATED,
[email protected]820d9bd2013-04-03 03:46:031456 content::Source<Profile>(profile_),
1457 content::NotificationService::NoDetails());
1458}
1459
[email protected]fcb58a862012-05-01 01:03:151460void ExtensionService::AddExtension(const Extension* extension) {
rdevlin.cronin08ada0f2017-03-09 23:29:521461 if (!Manifest::IsValidLocation(extension->location())) {
1462 // TODO(devlin): We should *never* add an extension with an invalid
1463 // location, but some bugs (e.g. crbug.com/692069) seem to indicate we do.
1464 // Track down the cases when this can happen, and remove this
1465 // DumpWithoutCrashing() (possibly replacing it with a CHECK).
1466 NOTREACHED();
1467 char extension_id_copy[33];
1468 base::strlcpy(extension_id_copy, extension->id().c_str(),
1469 arraysize(extension_id_copy));
1470 Manifest::Location location = extension->location();
1471 int creation_flags = extension->creation_flags();
1472 Manifest::Type type = extension->manifest()->type();
1473 base::debug::Alias(extension_id_copy);
1474 base::debug::Alias(&location);
1475 base::debug::Alias(&creation_flags);
1476 base::debug::Alias(&type);
1477 base::debug::DumpWithoutCrashing();
1478 return;
1479 }
1480
[email protected]c8d407e2011-04-28 21:27:171481 // TODO(jstritar): We may be able to get rid of this branch by overriding the
1482 // default extension state to DISABLED when the --disable-extensions flag
1483 // is set (http://crbug.com/29067).
catmullings98cd1942016-08-30 22:31:591484 if (!extensions_enabled() && !extension->is_theme() &&
[email protected]1d5e58b2013-01-31 08:41:401485 extension->location() != Manifest::COMPONENT &&
catmullings98cd1942016-08-30 22:31:591486 !Manifest::IsExternalLocation(extension->location()) &&
1487 disable_flag_exempted_extensions_.count(extension->id()) == 0) {
[email protected]fcb58a862012-05-01 01:03:151488 return;
[email protected]330840c2012-08-29 22:21:011489 }
[email protected]c8d407e2011-04-28 21:27:171490
[email protected]b914e2952013-04-26 07:10:031491 bool is_extension_upgrade = false;
treib6e51bca2016-06-15 10:26:031492 bool is_extension_loaded = false;
[email protected]116d40e2013-08-08 17:23:171493 const Extension* old = GetInstalledExtension(extension->id());
1494 if (old) {
treib6e51bca2016-06-15 10:26:031495 is_extension_loaded = true;
[email protected]116d40e2013-08-08 17:23:171496 int version_compare_result =
1497 extension->version()->CompareTo(*(old->version()));
1498 is_extension_upgrade = version_compare_result > 0;
[email protected]b914e2952013-04-26 07:10:031499 // Other than for unpacked extensions, CrxInstaller should have guaranteed
1500 // that we aren't downgrading.
1501 if (!Manifest::IsUnpackedLocation(extension->location()))
[email protected]116d40e2013-08-08 17:23:171502 CHECK_GE(version_compare_result, 0);
[email protected]b914e2952013-04-26 07:10:031503 }
rdevlin.cronin2c16c602014-11-21 01:35:491504 // If the extension was disabled for a reload, then enable it.
1505 bool reloading = reloading_extensions_.erase(extension->id()) > 0;
1506
1507 // Set the upgraded bit; we consider reloads upgrades.
1508 system_->runtime_data()->SetBeingUpgraded(extension->id(),
1509 is_extension_upgrade || reloading);
[email protected]c8d407e2011-04-28 21:27:171510
[email protected]1eb175082010-02-10 09:26:161511 // The extension is now loaded, remove its data from unloaded extension map.
1512 unloaded_extension_paths_.erase(extension->id());
1513
[email protected]bb7f40952011-01-13 00:21:201514 // If a terminated extension is loaded, remove it from the terminated list.
1515 UntrackTerminatedExtension(extension->id());
1516
[email protected]b914e2952013-04-26 07:10:031517 // Check if the extension's privileges have changed and mark the
1518 // extension disabled if necessary.
treib6e51bca2016-06-15 10:26:031519 CheckPermissionsIncrease(extension, is_extension_loaded);
[email protected]b914e2952013-04-26 07:10:031520
treib6e51bca2016-06-15 10:26:031521 if (is_extension_loaded && !reloading) {
[email protected]ca2e82022013-04-29 16:48:411522 // To upgrade an extension in place, unload the old one and then load the
1523 // new one. ReloadExtension disables the extension, which is sufficient.
limasdf0deef2042017-05-03 19:17:171524 UnloadExtension(extension->id(), UnloadedExtensionReason::UPDATE);
[email protected]b914e2952013-04-26 07:10:031525 }
[email protected]0c6da502009-08-14 22:32:391526
[email protected]695b5712012-12-06 23:55:281527 if (extension_prefs_->IsExtensionBlacklisted(extension->id())) {
[email protected]ac875372013-02-28 04:36:091528 // Only prefs is checked for the blacklist. We rely on callers to check the
1529 // blacklist before calling into here, e.g. CrxInstaller checks before
[email protected]9f3c8532013-07-31 19:52:071530 // installation then threads through the install and pending install flow
1531 // of this class, and we check when loading installed extensions.
[email protected]bb1bc9b32013-12-21 03:09:141532 registry_->AddBlacklisted(extension);
mlerman6a37b6a42014-11-26 22:10:531533 } else if (block_extensions_ && CanBlockExtension(extension)) {
1534 registry_->AddBlocked(extension);
[email protected]ca2e82022013-04-29 16:48:411535 } else if (!reloading &&
1536 extension_prefs_->IsExtensionDisabled(extension->id())) {
[email protected]bb1bc9b32013-12-21 03:09:141537 registry_->AddDisabled(extension);
[email protected]44d62b62012-04-11 00:06:031538 content::NotificationService::current()->Notify(
[email protected]adf5a102014-07-31 12:44:061539 extensions::NOTIFICATION_EXTENSION_UPDATE_DISABLED,
[email protected]44d62b62012-04-11 00:06:031540 content::Source<Profile>(profile_),
1541 content::Details<const Extension>(extension));
[email protected]62f051c2012-03-29 17:04:441542
[email protected]21db9ef2014-05-16 02:06:271543 // Show the extension disabled error if a permissions increase or a remote
1544 // installation is the reason it was disabled, and no other reasons exist.
1545 int reasons = extension_prefs_->GetDisableReasons(extension->id());
1546 const int kReasonMask = Extension::DISABLE_PERMISSIONS_INCREASE |
1547 Extension::DISABLE_REMOTE_INSTALL;
1548 if (reasons & kReasonMask && !(reasons & ~kReasonMask)) {
1549 extensions::AddExtensionDisabledError(
1550 this,
1551 extension,
1552 extension_prefs_->HasDisableReason(
1553 extension->id(), Extension::DISABLE_REMOTE_INSTALL));
[email protected]62f051c2012-03-29 17:04:441554 }
[email protected]ca2e82022013-04-29 16:48:411555 } else if (reloading) {
1556 // Replace the old extension with the new version.
[email protected]bb1bc9b32013-12-21 03:09:141557 CHECK(!registry_->AddDisabled(extension));
[email protected]ca2e82022013-04-29 16:48:411558 EnableExtension(extension->id());
[email protected]695b5712012-12-06 23:55:281559 } else {
1560 // All apps that are displayed in the launcher are ordered by their ordinals
1561 // so we must ensure they have valid ordinals.
1562 if (extension->RequiresSortOrdinal()) {
deepak.m14ba69e62015-11-17 05:42:121563 AppSorting* app_sorting =
1564 extensions::ExtensionSystem::Get(GetBrowserContext())->app_sorting();
1565 app_sorting->SetExtensionVisible(
[email protected]db378322014-07-21 23:19:341566 extension->id(),
benwells1dd4acd2015-12-09 02:20:241567 extension->ShouldDisplayInNewTabPage());
1568 app_sorting->EnsureValidOrdinals(extension->id(),
1569 syncer::StringOrdinal());
[email protected]695b5712012-12-06 23:55:281570 }
1571
[email protected]bb1bc9b32013-12-21 03:09:141572 registry_->AddEnabled(extension);
[email protected]695b5712012-12-06 23:55:281573 NotifyExtensionLoaded(extension);
[email protected]f574c402012-12-04 23:20:311574 }
rdevlin.cronin2c16c602014-11-21 01:35:491575 system_->runtime_data()->SetBeingUpgraded(extension->id(), false);
[email protected]aab98a52009-12-02 03:22:351576}
1577
[email protected]8c484b742012-11-29 06:05:361578void ExtensionService::AddComponentExtension(const Extension* extension) {
1579 const std::string old_version_string(
1580 extension_prefs_->GetVersionString(extension->id()));
pwnallcbd73192016-08-22 18:59:171581 const base::Version old_version(old_version_string);
[email protected]8c484b742012-11-29 06:05:361582
[email protected]0181a7d2013-11-12 01:08:421583 VLOG(1) << "AddComponentExtension " << extension->name();
robpercivaldcd8b102016-01-25 19:39:001584 if (!old_version.IsValid() || old_version != *extension->version()) {
[email protected]8c484b742012-11-29 06:05:361585 VLOG(1) << "Component extension " << extension->name() << " ("
1586 << extension->id() << ") installing/upgrading from '"
1587 << old_version_string << "' to " << extension->version()->GetString();
1588
1589 AddNewOrUpdatedExtension(extension,
[email protected]9ae73962014-08-14 16:53:411590 Extension::ENABLED,
[email protected]4a1d9c0d2014-06-13 12:50:111591 extensions::kInstallFlagNone,
[email protected]d8fd0fd2014-03-24 13:16:061592 syncer::StringOrdinal(),
1593 std::string());
[email protected]8c484b742012-11-29 06:05:361594 return;
1595 }
1596
1597 AddExtension(extension);
1598}
1599
[email protected]b914e2952013-04-26 07:10:031600void ExtensionService::CheckPermissionsIncrease(const Extension* extension,
treib6e51bca2016-06-15 10:26:031601 bool is_extension_loaded) {
[email protected]23a85362014-07-07 23:26:191602 extensions::PermissionsUpdater(profile_).InitializePermissions(extension);
[email protected]902fd7b2011-07-27 18:42:311603
[email protected]8d888c12010-11-30 00:00:251604 // We keep track of all permissions the user has granted each extension.
1605 // This allows extensions to gracefully support backwards compatibility
1606 // by including unknown permissions in their manifests. When the user
1607 // installs the extension, only the recognized permissions are recorded.
1608 // When the unknown permissions become recognized (e.g., through browser
1609 // upgrade), we can prompt the user to accept these new permissions.
1610 // Extensions can also silently upgrade to less permissions, and then
1611 // silently upgrade to a version that adds these permissions back.
1612 //
1613 // For example, pretend that Chrome 10 includes a permission "omnibox"
1614 // for an API that adds suggestions to the omnibox. An extension can
1615 // maintain backwards compatibility while still having "omnibox" in the
1616 // manifest. If a user installs the extension on Chrome 9, the browser
1617 // will record the permissions it recognized, not including "omnibox."
1618 // When upgrading to Chrome 10, "omnibox" will be recognized and Chrome
1619 // will disable the extension and prompt the user to approve the increase
1620 // in privileges. The extension could then release a new version that
1621 // removes the "omnibox" permission. When the user upgrades, Chrome will
1622 // still remember that "omnibox" had been granted, so that if the
1623 // extension once again includes "omnibox" in an upgrade, the extension
1624 // can upgrade without requiring this user's approval.
[email protected]eb5e4f92012-08-15 23:33:281625 int disable_reasons = extension_prefs_->GetDisableReasons(extension->id());
[email protected]8d888c12010-11-30 00:00:251626
rockot1d4a06262015-02-17 19:39:281627 // Silently grant all active permissions to default apps and apps installed
1628 // in kiosk mode.
[email protected]211a3f32013-05-28 21:48:181629 bool auto_grant_permission =
rockot1d4a06262015-02-17 19:39:281630 extension->was_installed_by_default() ||
[email protected]45928b682013-11-28 08:20:271631 extensions::ExtensionsBrowserClient::Get()->IsRunningInForcedAppMode();
[email protected]211a3f32013-05-28 21:48:181632 if (auto_grant_permission)
[email protected]b914e2952013-04-26 07:10:031633 GrantPermissions(extension);
1634
1635 bool is_privilege_increase = false;
1636 // We only need to compare the granted permissions to the current permissions
rockot1d4a06262015-02-17 19:39:281637 // if the extension has not been auto-granted its permissions above and is
1638 // installed internally.
1639 if (extension->location() == Manifest::INTERNAL && !auto_grant_permission) {
[email protected]8d888c12010-11-30 00:00:251640 // Add all the recognized permissions if the granted permissions list
1641 // hasn't been initialized yet.
dchengc963c7142016-04-08 03:55:221642 std::unique_ptr<const PermissionSet> granted_permissions =
[email protected]902fd7b2011-07-27 18:42:311643 extension_prefs_->GetGrantedPermissions(extension->id());
[email protected]0d3e4a22011-06-23 19:02:521644 CHECK(granted_permissions.get());
[email protected]8d888c12010-11-30 00:00:251645
1646 // Here, we check if an extension's privileges have increased in a manner
1647 // that requires the user's approval. This could occur because the browser
1648 // upgraded and recognized additional privileges, or an extension upgrades
1649 // to a version that requires additional privileges.
[email protected]c41003472013-10-19 15:37:251650 is_privilege_increase =
1651 extensions::PermissionMessageProvider::Get()->IsPrivilegeIncrease(
rdevlin.cronind630c302015-09-30 20:19:331652 *granted_permissions,
rdevlin.cronine2d0fd02015-09-24 22:35:491653 extension->permissions_data()->active_permissions(),
[email protected]076ebeda2014-06-06 21:47:261654 extension->GetType());
treib2c20f9442016-05-18 19:50:281655
1656 // If there was no privilege increase, the extension might still have new
1657 // permissions (which either don't generate a warning message, or whose
1658 // warning messages are suppressed by existing permissions). Grant the new
1659 // permissions.
1660 if (!is_privilege_increase)
1661 GrantPermissions(extension);
[email protected]8d888c12010-11-30 00:00:251662 }
1663
treib6e51bca2016-06-15 10:26:031664 bool previously_disabled =
1665 extension_prefs_->IsExtensionDisabled(extension->id());
1666 // TODO(treib): Is the |is_extension_loaded| check needed here?
1667 if (is_extension_loaded && previously_disabled) {
treib8a6d9892015-08-26 10:23:191668 // Legacy disabled extensions do not have a disable reason. Infer that it
1669 // was likely disabled by the user.
treib6e51bca2016-06-15 10:26:031670 if (disable_reasons == Extension::DISABLE_NONE)
[email protected]7e9e2422012-12-13 19:54:191671 disable_reasons |= Extension::DISABLE_USER_ACTION;
treib8a6d9892015-08-26 10:23:191672
[email protected]7e9e2422012-12-13 19:54:191673 // Extensions that came to us disabled from sync need a similar inference,
1674 // except based on the new version's permissions.
treib3b91e9f2015-11-04 11:29:411675 // TODO(treib,devlin): Since M48, DISABLE_UNKNOWN_FROM_SYNC isn't used
1676 // anymore; this code is still here to migrate any existing old state.
1677 // Remove it after some grace period.
treib6e51bca2016-06-15 10:26:031678 if (disable_reasons & Extension::DEPRECATED_DISABLE_UNKNOWN_FROM_SYNC) {
[email protected]7e9e2422012-12-13 19:54:191679 // Remove the DISABLE_UNKNOWN_FROM_SYNC reason.
treib3b91e9f2015-11-04 11:29:411680 disable_reasons &= ~Extension::DEPRECATED_DISABLE_UNKNOWN_FROM_SYNC;
treib8a6d9892015-08-26 10:23:191681 extension_prefs_->RemoveDisableReason(
treib3b91e9f2015-11-04 11:29:411682 extension->id(), Extension::DEPRECATED_DISABLE_UNKNOWN_FROM_SYNC);
treib8a6d9892015-08-26 10:23:191683 // If there was no privilege increase, it was likely disabled by the user.
[email protected]7e9e2422012-12-13 19:54:191684 if (!is_privilege_increase)
1685 disable_reasons |= Extension::DISABLE_USER_ACTION;
1686 }
[email protected]8d888c12010-11-30 00:00:251687 }
1688
treib6e51bca2016-06-15 10:26:031689 // If the extension is disabled due to a permissions increase, but does in
1690 // fact have all permissions, remove that disable reason.
1691 // TODO(devlin): This was added to fix crbug.com/616474, but it's unclear
1692 // if this behavior should stay forever.
1693 if (disable_reasons & Extension::DISABLE_PERMISSIONS_INCREASE) {
1694 bool reset_permissions_increase = false;
1695 if (!is_privilege_increase) {
1696 reset_permissions_increase = true;
1697 disable_reasons &= ~Extension::DISABLE_PERMISSIONS_INCREASE;
1698 extension_prefs_->RemoveDisableReason(
1699 extension->id(), Extension::DISABLE_PERMISSIONS_INCREASE);
1700 }
1701 UMA_HISTOGRAM_BOOLEAN("Extensions.ResetPermissionsIncrease",
1702 reset_permissions_increase);
1703 }
1704
[email protected]8d888c12010-11-30 00:00:251705 // Extension has changed permissions significantly. Disable it. A
[email protected]21db9ef2014-05-16 02:06:271706 // notification should be sent by the caller. If the extension is already
1707 // disabled because it was installed remotely, don't add another disable
treibaac30ec2015-06-10 09:18:091708 // reason.
1709 if (is_privilege_increase &&
treib8a6d9892015-08-26 10:23:191710 !(disable_reasons & Extension::DISABLE_REMOTE_INSTALL)) {
[email protected]7e9e2422012-12-13 19:54:191711 disable_reasons |= Extension::DISABLE_PERMISSIONS_INCREASE;
treib8a6d9892015-08-26 10:23:191712 if (!extension_prefs_->DidExtensionEscalatePermissions(extension->id()))
treib2e0517f92015-05-07 23:15:361713 RecordPermissionMessagesHistogram(extension, "AutoDisable");
treib8ecc1eb52015-03-04 18:29:061714
brettw9e85ef42016-11-01 21:01:241715#if BUILDFLAG(ENABLE_SUPERVISED_USERS)
treib8ecc1eb52015-03-04 18:29:061716 // If a custodian-installed extension is disabled for a supervised user due
mamir51e05d02016-10-06 10:55:011717 // to a permissions increase, send a request to the custodian.
treib3202d592015-07-31 08:33:161718 if (extensions::util::IsExtensionSupervised(extension, profile_) &&
treib40d3ad92015-10-20 18:15:421719 !ExtensionSyncService::Get(profile_)->HasPendingReenable(
1720 extension->id(), *extension->version())) {
treib8ecc1eb52015-03-04 18:29:061721 SupervisedUserService* supervised_user_service =
1722 SupervisedUserServiceFactory::GetForProfile(profile_);
treib40d3ad92015-10-20 18:15:421723 supervised_user_service->AddExtensionUpdateRequest(extension->id(),
1724 *extension->version());
treib8ecc1eb52015-03-04 18:29:061725 }
1726#endif
[email protected]b914e2952013-04-26 07:10:031727 }
treib6e51bca2016-06-15 10:26:031728
1729 if (disable_reasons == Extension::DISABLE_NONE)
1730 extension_prefs_->SetExtensionEnabled(extension->id());
1731 else
treib8a6d9892015-08-26 10:23:191732 extension_prefs_->SetExtensionDisabled(extension->id(), disable_reasons);
[email protected]8d888c12010-11-30 00:00:251733}
1734
[email protected]eaa7dd182010-12-14 11:09:001735void ExtensionService::UpdateActiveExtensionsInCrashReporter() {
[email protected]c8865962009-12-16 07:47:391736 std::set<std::string> extension_ids;
achuith2f5578b2016-02-26 21:57:131737 for (const auto& extension : registry_->enabled_extensions()) {
[email protected]1d5e58b2013-01-31 08:41:401738 if (!extension->is_theme() && extension->location() != Manifest::COMPONENT)
[email protected]84df8332011-12-06 18:22:461739 extension_ids.insert(extension->id());
[email protected]aab98a52009-12-02 03:22:351740 }
1741
[email protected]dcc47642014-03-26 22:03:491742 // TODO(kalman): This is broken. ExtensionService is per-profile.
1743 // crash_keys::SetActiveExtensions is per-process. See
1744 // http://crbug.com/355029.
[email protected]f6431be82013-09-07 02:53:451745 crash_keys::SetActiveExtensions(extension_ids);
[email protected]6014d672008-12-05 00:38:251746}
1747
[email protected]8266d662011-07-12 21:53:261748void ExtensionService::OnExtensionInstalled(
[email protected]36a5c4c2011-12-14 16:34:501749 const Extension* extension,
[email protected]98270432012-09-11 20:51:241750 const syncer::StringOrdinal& page_ordinal,
[email protected]4a1d9c0d2014-06-13 12:50:111751 int install_flags) {
[email protected]a29a517a2011-01-21 21:11:121752 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]a8af9fdb2010-10-28 21:52:201753
[email protected]c3cfb012011-04-06 22:07:351754 const std::string& id = extension->id();
binjin47947f842014-11-18 12:10:241755 int disable_reasons = GetDisableReasonsOnInstalled(extension);
[email protected]d8fd0fd2014-03-24 13:16:061756 std::string install_parameter;
[email protected]96aebe22014-07-16 04:07:511757 const extensions::PendingExtensionInfo* pending_extension_info =
1758 pending_extension_manager()->GetById(id);
1759 if (pending_extension_info) {
[email protected]8f3bcbd2013-06-05 08:42:401760 if (!pending_extension_info->ShouldAllowInstall(extension)) {
treib227b2582015-12-09 09:28:261761 // Hack for crbug.com/558299, see comment on DeleteThemeDoNotUse.
1762 if (extension->is_theme() && pending_extension_info->is_from_sync())
1763 ExtensionSyncService::Get(profile_)->DeleteThemeDoNotUse(*extension);
1764
[email protected]51a3bf8b2012-06-08 22:53:061765 pending_extension_manager()->Remove(id);
[email protected]8ef78fd2010-08-19 17:14:321766
[email protected]31bb5ee62012-09-12 22:58:401767 LOG(WARNING) << "ShouldAllowInstall() returned false for "
1768 << id << " of type " << extension->GetType()
[email protected]65348062013-01-15 07:27:221769 << " and update URL "
1770 << extensions::ManifestURL::GetUpdateURL(extension).spec()
[email protected]31bb5ee62012-09-12 22:58:401771 << "; not installing";
[email protected]ae6cb3022011-04-04 20:11:541772
[email protected]4416c5a2010-06-26 01:28:571773 // Delete the extension directory since we're not going to
1774 // load it.
[email protected]7f8f24f2012-11-15 19:40:141775 if (!GetFileTaskRunner()->PostTask(
tzik8d880ee2017-04-20 19:46:241776 FROM_HERE, base::BindOnce(&extensions::file_util::DeleteFile,
1777 extension->path(), true))) {
[email protected]14908b72011-04-20 06:54:361778 NOTREACHED();
[email protected]31bb5ee62012-09-12 22:58:401779 }
[email protected]4416c5a2010-06-26 01:28:571780 return;
1781 }
[email protected]51a3bf8b2012-06-08 22:53:061782
[email protected]d8fd0fd2014-03-24 13:16:061783 install_parameter = pending_extension_info->install_parameter();
[email protected]51a3bf8b2012-06-08 22:53:061784 pending_extension_manager()->Remove(id);
[email protected]4416c5a2010-06-26 01:28:571785 } else {
[email protected]c3cfb012011-04-06 22:07:351786 // We explicitly want to re-enable an uninstalled external
1787 // extension; if we're here, that means the user is manually
1788 // installing the extension.
[email protected]46f3e102014-03-25 01:22:451789 if (extension_prefs_->IsExternalExtensionUninstalled(id)) {
binjin47947f842014-11-18 12:10:241790 disable_reasons = Extension::DISABLE_NONE;
[email protected]6cc7dbae2011-04-29 21:18:331791 }
[email protected]aa142702010-03-26 01:26:331792 }
1793
asargente4de9f92016-09-15 01:40:061794 // If the old version of the extension was disabled due to corruption, this
1795 // new install may correct the problem.
1796 disable_reasons &= ~Extension::DISABLE_CORRUPTED;
1797
[email protected]98270432012-09-11 20:51:241798 // Unsupported requirements overrides the management policy.
[email protected]4a1d9c0d2014-06-13 12:50:111799 if (install_flags & extensions::kInstallFlagHasRequirementErrors) {
binjin47947f842014-11-18 12:10:241800 disable_reasons |= Extension::DISABLE_UNSUPPORTED_REQUIREMENT;
binjin8e3d0182014-12-04 16:44:281801 } else {
1802 // Requirement is supported now, remove the corresponding disable reason
1803 // instead.
binjin8e3d0182014-12-04 16:44:281804 disable_reasons &= ~Extension::DISABLE_UNSUPPORTED_REQUIREMENT;
1805 }
1806
1807 // Check if the extension was disabled because of the minimum version
1808 // requirements from enterprise policy, and satisfies it now.
1809 if (extensions::ExtensionManagementFactory::GetForBrowserContext(profile())
1810 ->CheckMinimumVersion(extension, nullptr)) {
1811 // And remove the corresponding disable reason.
binjin8e3d0182014-12-04 16:44:281812 disable_reasons &= ~Extension::DISABLE_UPDATE_REQUIRED_BY_POLICY;
[email protected]98270432012-09-11 20:51:241813 }
1814
[email protected]4a1d9c0d2014-06-13 12:50:111815 if (install_flags & extensions::kInstallFlagIsBlacklistedForMalware) {
[email protected]9f3c8532013-07-31 19:52:071816 // Installation of a blacklisted extension can happen from sync, policy,
1817 // etc, where to maintain consistency we need to install it, just never
1818 // load it (see AddExtension). Usually it should be the job of callers to
treibaac30ec2015-06-10 09:18:091819 // intercept blacklisted extensions earlier (e.g. CrxInstaller, before even
[email protected]9f3c8532013-07-31 19:52:071820 // showing the install dialogue).
[email protected]7c82539c2014-02-19 06:09:171821 extension_prefs_->AcknowledgeBlacklistedExtension(id);
[email protected]9f3c8532013-07-31 19:52:071822 UMA_HISTOGRAM_ENUMERATION("ExtensionBlacklist.SilentInstall",
1823 extension->location(),
1824 Manifest::NUM_LOCATIONS);
1825 }
1826
[email protected]695b5712012-12-06 23:55:281827 if (!GetInstalledExtension(extension->id())) {
[email protected]07533022011-06-27 20:42:551828 UMA_HISTOGRAM_ENUMERATION("Extensions.InstallType",
1829 extension->GetType(), 100);
[email protected]69084dc2012-11-17 07:39:301830 UMA_HISTOGRAM_ENUMERATION("Extensions.InstallSource",
[email protected]1d5e58b2013-01-31 08:41:401831 extension->location(), Manifest::NUM_LOCATIONS);
treib2e0517f92015-05-07 23:15:361832 RecordPermissionMessagesHistogram(extension, "Install");
[email protected]69084dc2012-11-17 07:39:301833 } else {
1834 UMA_HISTOGRAM_ENUMERATION("Extensions.UpdateType",
1835 extension->GetType(), 100);
1836 UMA_HISTOGRAM_ENUMERATION("Extensions.UpdateSource",
[email protected]1d5e58b2013-01-31 08:41:401837 extension->location(), Manifest::NUM_LOCATIONS);
[email protected]07533022011-06-27 20:42:551838 }
1839
[email protected]399583b2012-12-11 09:33:421840 const Extension::State initial_state =
binjin47947f842014-11-18 12:10:241841 disable_reasons == Extension::DISABLE_NONE ? Extension::ENABLED
1842 : Extension::DISABLED;
treib8a6d9892015-08-26 10:23:191843 if (initial_state == Extension::ENABLED)
1844 extension_prefs_->SetExtensionEnabled(id);
1845 else
1846 extension_prefs_->SetExtensionDisabled(id, disable_reasons);
binjin47947f842014-11-18 12:10:241847
xiyuanf6a4c6a62016-04-19 18:14:541848 extensions::ExtensionPrefs::DelayReason delay_reason;
1849 extensions::InstallGate::Action action = ShouldDelayExtensionInstall(
1850 extension, !!(install_flags & extensions::kInstallFlagInstallImmediately),
1851 &delay_reason);
1852 switch (action) {
1853 case extensions::InstallGate::INSTALL:
1854 AddNewOrUpdatedExtension(extension, initial_state, install_flags,
1855 page_ordinal, install_parameter);
1856 return;
1857 case extensions::InstallGate::DELAY:
1858 extension_prefs_->SetDelayedInstallInfo(extension, initial_state,
1859 install_flags, delay_reason,
1860 page_ordinal, install_parameter);
[email protected]0db124b02012-11-07 04:55:051861
xiyuanf6a4c6a62016-04-19 18:14:541862 // Transfer ownership of |extension|.
[email protected]9f4e4f082013-06-21 07:11:191863 delayed_installs_.Insert(extension);
xiyuanf6a4c6a62016-04-19 18:14:541864
1865 if (delay_reason ==
1866 extensions::ExtensionPrefs::DELAY_REASON_WAIT_FOR_IDLE) {
1867 // Notify observers that app update is available.
ericwilligersb5f79de2016-10-19 04:15:101868 for (auto& observer : update_observers_)
1869 observer.OnAppUpdateAvailable(extension);
xiyuanf6a4c6a62016-04-19 18:14:541870 }
1871 return;
1872 case extensions::InstallGate::ABORT:
1873 // Do nothing to abort the install. One such case is the shared module
1874 // service gets IMPORT_STATUS_UNRECOVERABLE status for the pending
1875 // install.
1876 return;
[email protected]399583b2012-12-11 09:33:421877 }
xiyuanf6a4c6a62016-04-19 18:14:541878
1879 NOTREACHED() << "Unknown action for delayed install: " << action;
[email protected]8c484b742012-11-29 06:05:361880}
1881
binjin1569c9b2014-09-05 13:33:181882void ExtensionService::OnExtensionManagementSettingsChanged() {
1883 error_controller_->ShowErrorIfNeeded();
binjine6b58b52014-10-31 01:55:571884
1885 // Revokes blocked permissions from active_permissions for all extensions.
1886 extensions::ExtensionManagement* settings =
1887 extensions::ExtensionManagementFactory::GetForBrowserContext(profile());
1888 CHECK(settings);
dchengc963c7142016-04-08 03:55:221889 std::unique_ptr<ExtensionSet> all_extensions(
binjine6b58b52014-10-31 01:55:571890 registry_->GenerateInstalledExtensionsSet());
achuith2f5578b2016-02-26 21:57:131891 for (const auto& extension : *all_extensions) {
binjine6b58b52014-10-31 01:55:571892 if (!settings->IsPermissionSetAllowed(
binjin685ade82014-11-06 09:53:561893 extension.get(),
Nick Peterson0203be4a2017-07-19 00:25:141894 extension->permissions_data()->active_permissions()) &&
1895 CanBlockExtension(extension.get())) {
rdevlin.cronin77cb0ef2015-09-16 17:03:481896 extensions::PermissionsUpdater(profile()).RemovePermissionsUnsafe(
rdevlin.cronind630c302015-09-30 20:19:331897 extension.get(), *settings->GetBlockedPermissions(extension.get()));
binjine6b58b52014-10-31 01:55:571898 }
1899 }
1900
binjin1569c9b2014-09-05 13:33:181901 CheckManagementPolicy();
1902}
1903
[email protected]8c484b742012-11-29 06:05:361904void ExtensionService::AddNewOrUpdatedExtension(
1905 const Extension* extension,
[email protected]399583b2012-12-11 09:33:421906 Extension::State initial_state,
[email protected]4a1d9c0d2014-06-13 12:50:111907 int install_flags,
[email protected]d8fd0fd2014-03-24 13:16:061908 const syncer::StringOrdinal& page_ordinal,
1909 const std::string& install_parameter) {
[email protected]8c484b742012-11-29 06:05:361910 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]4a1d9c0d2014-06-13 12:50:111911 extension_prefs_->OnExtensionInstalled(
1912 extension, initial_state, page_ordinal, install_flags, install_parameter);
[email protected]9e9c1d12013-07-31 01:58:121913 delayed_installs_.Remove(extension->id());
[email protected]913ffca92014-03-27 15:26:161914 if (InstallVerifier::NeedsVerification(*extension))
juncai33e462102015-05-18 20:48:441915 InstallVerifier::Get(GetBrowserContext())->VerifyExtension(extension->id());
ryanackley48bedbd2015-01-27 23:12:141916
1917 const Extension* old = GetInstalledExtension(extension->id());
1918 if (extensions::AppDataMigrator::NeedsMigration(old, extension)) {
1919 app_data_migrator_->DoMigrationAndReply(
vmpstra34d11322016-03-21 20:28:471920 old, extension, base::Bind(&ExtensionService::FinishInstallation,
1921 AsWeakPtr(), base::RetainedRef(extension)));
ryanackley48bedbd2015-01-27 23:12:141922 return;
1923 }
1924
benwells1dd4acd2015-12-09 02:20:241925 FinishInstallation(extension);
[email protected]6f6101832012-11-27 22:10:481926}
1927
1928void ExtensionService::MaybeFinishDelayedInstallation(
1929 const std::string& extension_id) {
[email protected]9f4e4f082013-06-21 07:11:191930 // Check if the extension already got installed.
[email protected]9f4e4f082013-06-21 07:11:191931 const Extension* extension = delayed_installs_.GetByID(extension_id);
xiyuanf6a4c6a62016-04-19 18:14:541932 if (!extension)
1933 return;
1934
1935 extensions::ExtensionPrefs::DelayReason reason;
1936 const extensions::InstallGate::Action action = ShouldDelayExtensionInstall(
1937 extension, false /* install_immediately*/, &reason);
1938 switch (action) {
1939 case extensions::InstallGate::INSTALL:
1940 break;
1941 case extensions::InstallGate::DELAY:
1942 // Bail out and continue to delay the install.
[email protected]9f4e4f082013-06-21 07:11:191943 return;
xiyuanf6a4c6a62016-04-19 18:14:541944 case extensions::InstallGate::ABORT:
1945 delayed_installs_.Remove(extension_id);
1946 // Make sure no version of the extension is actually installed, (i.e.,
1947 // that this delayed install was not an update).
1948 CHECK(!extension_prefs_->GetInstalledExtensionInfo(extension_id).get());
1949 extension_prefs_->DeleteExtensionPrefs(extension_id);
1950 return;
[email protected]9f4e4f082013-06-21 07:11:191951 }
1952
[email protected]6f6101832012-11-27 22:10:481953 FinishDelayedInstallation(extension_id);
1954}
1955
1956void ExtensionService::FinishDelayedInstallation(
1957 const std::string& extension_id) {
1958 scoped_refptr<const Extension> extension(
1959 GetPendingExtensionUpdate(extension_id));
[email protected]dc24976f2013-06-02 21:15:091960 CHECK(extension.get());
[email protected]9f4e4f082013-06-21 07:11:191961 delayed_installs_.Remove(extension_id);
[email protected]6f6101832012-11-27 22:10:481962
[email protected]399583b2012-12-11 09:33:421963 if (!extension_prefs_->FinishDelayedInstallInfo(extension_id))
[email protected]6f6101832012-11-27 22:10:481964 NOTREACHED();
1965
benwells1dd4acd2015-12-09 02:20:241966 FinishInstallation(extension.get());
[email protected]6f6101832012-11-27 22:10:481967}
1968
[email protected]760f743b2014-05-28 13:52:021969void ExtensionService::FinishInstallation(
benwells1dd4acd2015-12-09 02:20:241970 const Extension* extension) {
[email protected]e7554c3f2013-05-29 00:36:561971 const extensions::Extension* existing_extension =
1972 GetInstalledExtension(extension->id());
1973 bool is_update = false;
1974 std::string old_name;
1975 if (existing_extension) {
1976 is_update = true;
1977 old_name = existing_extension->name();
1978 }
[email protected]bc44b5da2014-06-12 14:20:001979 registry_->TriggerOnWillBeInstalled(
benwells1dd4acd2015-12-09 02:20:241980 extension, is_update, old_name);
[email protected]17f07822014-05-22 08:45:151981
[email protected]399583b2012-12-11 09:33:421982 // Unpacked extensions default to allowing file access, but if that has been
1983 // overridden, don't reset the value.
[email protected]1d5e58b2013-01-31 08:41:401984 if (Manifest::ShouldAlwaysAllowFileAccess(extension->location()) &&
[email protected]399583b2012-12-11 09:33:421985 !extension_prefs_->HasAllowFileAccessSetting(extension->id())) {
1986 extension_prefs_->SetAllowFileAccess(extension->id(), true);
1987 }
1988
[email protected]6f6101832012-11-27 22:10:481989 AddExtension(extension);
[email protected]612a1cb12012-10-17 13:18:031990
[email protected]bc44b5da2014-06-12 14:20:001991 // Notify observers that need to know when an installation is complete.
[email protected]38e872532014-07-16 23:27:511992 registry_->TriggerOnInstalled(extension, is_update);
[email protected]bc44b5da2014-06-12 14:20:001993
[email protected]9f4e4f082013-06-21 07:11:191994 // Check extensions that may have been delayed only because this shared module
1995 // was not available.
[email protected]374ceb6f2014-07-02 19:25:341996 if (SharedModuleInfo::IsSharedModule(extension))
[email protected]9f4e4f082013-06-21 07:11:191997 MaybeFinishDelayedInstallations();
[email protected]4a190632009-05-09 01:07:421998}
1999
[email protected]76b65442012-11-17 14:11:482000const Extension* ExtensionService::GetPendingExtensionUpdate(
2001 const std::string& id) const {
[email protected]9f4e4f082013-06-21 07:11:192002 return delayed_installs_.GetByID(id);
[email protected]76b65442012-11-17 14:11:482003}
2004
mukai87a8d402014-09-15 20:15:092005void ExtensionService::RegisterContentSettings(
mmenkead5094ab2017-05-15 19:01:142006 HostContentSettingsMap* host_content_settings_map,
2007 Profile* profile) {
2008 // Most extension services key off of the original profile.
2009 Profile* original_profile = profile->GetOriginalProfile();
2010
rkaplowe65c2ff2015-02-14 16:29:542011 TRACE_EVENT0("browser,startup", "ExtensionService::RegisterContentSettings");
mukaia1aa3512014-10-22 20:14:112012 DCHECK_CURRENTLY_ON(BrowserThread::UI);
mukai87a8d402014-09-15 20:15:092013 host_content_settings_map->RegisterProvider(
2014 HostContentSettingsMap::INTERNAL_EXTENSION_PROVIDER,
dchengc963c7142016-04-08 03:55:222015 std::unique_ptr<content_settings::ObservableProvider>(
mmenkead5094ab2017-05-15 19:01:142016 new content_settings::InternalExtensionProvider(original_profile)));
mukai87a8d402014-09-15 20:15:092017
2018 host_content_settings_map->RegisterProvider(
2019 HostContentSettingsMap::CUSTOM_EXTENSION_PROVIDER,
dchengc963c7142016-04-08 03:55:222020 std::unique_ptr<content_settings::ObservableProvider>(
mukai87a8d402014-09-15 20:15:092021 new content_settings::CustomExtensionProvider(
mmenkead5094ab2017-05-15 19:01:142022 extensions::ContentSettingsService::Get(original_profile)
dchengc963c7142016-04-08 03:55:222023 ->content_settings_store(),
mmenkead5094ab2017-05-15 19:01:142024 // TODO(mmenke): CustomExtensionProvider expects this to be true
2025 // for incognito profiles.
2026 false)));
mukai87a8d402014-09-15 20:15:092027}
2028
xiyuane87def2e2015-06-04 22:50:222029void ExtensionService::TrackTerminatedExtension(
2030 const std::string& extension_id) {
2031 extensions_being_terminated_.erase(extension_id);
2032
2033 const Extension* extension = GetInstalledExtension(extension_id);
2034 if (!extension) {
xiyuane87def2e2015-06-04 22:50:222035 return;
2036 }
2037
[email protected]bb1bc9b32013-12-21 03:09:142038 // No need to check for duplicates; inserting a duplicate is a no-op.
2039 registry_->AddTerminated(make_scoped_refptr(extension));
limasdf0deef2042017-05-03 19:17:172040 UnloadExtension(extension->id(), UnloadedExtensionReason::TERMINATE);
[email protected]bb7f40952011-01-13 00:21:202041}
2042
[email protected]e9d7496e2014-04-18 01:25:462043void ExtensionService::TerminateExtension(const std::string& extension_id) {
xiyuana30a2092015-06-09 23:14:442044 TrackTerminatedExtension(extension_id);
[email protected]e9d7496e2014-04-18 01:25:462045}
2046
[email protected]bb7f40952011-01-13 00:21:202047void ExtensionService::UntrackTerminatedExtension(const std::string& id) {
brettwfce8d192015-08-10 19:07:512048 std::string lowercase_id = base::ToLowerASCII(id);
[email protected]bb1bc9b32013-12-21 03:09:142049 const Extension* extension =
2050 registry_->terminated_extensions().GetByID(lowercase_id);
2051 registry_->RemoveTerminated(lowercase_id);
[email protected]fb789532013-08-27 02:40:212052 if (extension) {
2053 content::NotificationService::current()->Notify(
[email protected]adf5a102014-07-31 12:44:062054 extensions::NOTIFICATION_EXTENSION_REMOVED,
[email protected]fb789532013-08-27 02:40:212055 content::Source<Profile>(profile_),
2056 content::Details<const Extension>(extension));
2057 }
[email protected]bb7f40952011-01-13 00:21:202058}
2059
[email protected]8001df22011-04-28 19:59:472060const Extension* ExtensionService::GetInstalledExtension(
2061 const std::string& id) const {
[email protected]599539802014-01-07 23:06:002062 return registry_->GetExtensionById(id, ExtensionRegistry::EVERYTHING);
[email protected]0dfe05c2011-02-23 23:03:362063}
2064
[email protected]9060d8b02012-01-13 02:14:302065bool ExtensionService::OnExternalExtensionFileFound(
lazyboye8634172016-01-28 00:10:482066 const ExternalInstallInfoFile& info) {
[email protected]ab22ba42011-01-14 16:36:382067 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
lazyboye8634172016-01-28 00:10:482068 CHECK(crx_file::id_util::IdIsValid(info.extension_id));
2069 if (extension_prefs_->IsExternalExtensionUninstalled(info.extension_id))
[email protected]9060d8b02012-01-13 02:14:302070 return false;
[email protected]a8af9fdb2010-10-28 21:52:202071
[email protected]7577a5c52009-07-30 06:21:582072 // Before even bothering to unpack, check and see if we already have this
[email protected]4c967932009-07-31 01:15:492073 // version. This is important because these extensions are going to get
[email protected]7577a5c52009-07-30 06:21:582074 // installed on every startup.
lazyboye8634172016-01-28 00:10:482075 const Extension* existing = GetExtensionById(info.extension_id, true);
[email protected]910f72ce2012-08-24 01:38:352076
[email protected]7577a5c52009-07-30 06:21:582077 if (existing) {
[email protected]910f72ce2012-08-24 01:38:352078 // The default apps will have the location set as INTERNAL. Since older
2079 // default apps are installed as EXTERNAL, we override them. However, if the
2080 // app is already installed as internal, then do the version check.
[email protected]31bb5ee62012-09-12 22:58:402081 // TODO(grv) : Remove after Q1-2013.
[email protected]910f72ce2012-08-24 01:38:352082 bool is_default_apps_migration =
lazyboye8634172016-01-28 00:10:482083 (info.crx_location == Manifest::INTERNAL &&
[email protected]1d5e58b2013-01-31 08:41:402084 Manifest::IsExternalLocation(existing->location()));
[email protected]910f72ce2012-08-24 01:38:352085
2086 if (!is_default_apps_migration) {
lazyboye8634172016-01-28 00:10:482087 DCHECK(info.version.get());
[email protected]910f72ce2012-08-24 01:38:352088
lazyboye8634172016-01-28 00:10:482089 switch (existing->version()->CompareTo(*info.version)) {
[email protected]910f72ce2012-08-24 01:38:352090 case -1: // existing version is older, we should upgrade
2091 break;
2092 case 0: // existing version is same, do nothing
2093 return false;
2094 case 1: // existing version is newer, uh-oh
lazyboye8634172016-01-28 00:10:482095 LOG(WARNING) << "Found external version of extension "
2096 << info.extension_id
[email protected]910f72ce2012-08-24 01:38:352097 << "that is older than current version. Current version "
2098 << "is: " << existing->VersionString() << ". New "
lazyboye8634172016-01-28 00:10:482099 << "version is: " << info.version->GetString()
[email protected]910f72ce2012-08-24 01:38:352100 << ". Keeping current version.";
2101 return false;
2102 }
[email protected]7577a5c52009-07-30 06:21:582103 }
2104 }
2105
[email protected]9060d8b02012-01-13 02:14:302106 // If the extension is already pending, don't start an install.
[email protected]e3987852012-05-04 10:06:302107 if (!pending_extension_manager()->AddFromExternalFile(
lazyboye8634172016-01-28 00:10:482108 info.extension_id, info.crx_location, *info.version,
2109 info.creation_flags, info.mark_acknowledged)) {
[email protected]9060d8b02012-01-13 02:14:302110 return false;
[email protected]e3987852012-05-04 10:06:302111 }
[email protected]9c635f22010-12-02 09:36:362112
[email protected]14908b72011-04-20 06:54:362113 // no client (silent install)
[email protected]f8636f92013-08-09 21:02:372114 scoped_refptr<CrxInstaller> installer(CrxInstaller::CreateSilent(this));
lazyboye8634172016-01-28 00:10:482115 installer->set_install_source(info.crx_location);
2116 installer->set_expected_id(info.extension_id);
2117 installer->set_expected_version(*info.version,
treibe960e282015-09-11 10:38:082118 true /* fail_install_if_unexpected */);
[email protected]cb0e50312011-05-09 15:03:072119 installer->set_install_cause(extension_misc::INSTALL_CAUSE_EXTERNAL_FILE);
lazyboye8634172016-01-28 00:10:482120 installer->set_install_immediately(info.install_immediately);
2121 installer->set_creation_flags(info.creation_flags);
[email protected]88e8ec9152013-01-17 04:05:182122#if defined(OS_CHROMEOS)
lazyboye8634172016-01-28 00:10:482123 extensions::InstallLimiter::Get(profile_)->Add(installer, info.path);
[email protected]88e8ec9152013-01-17 04:05:182124#else
lazyboye8634172016-01-28 00:10:482125 installer->InstallCrx(info.path);
[email protected]88e8ec9152013-01-17 04:05:182126#endif
[email protected]47fc70c2011-12-06 07:29:512127
2128 // Depending on the source, a new external extension might not need a user
2129 // notification on installation. For such extensions, mark them acknowledged
2130 // now to suppress the notification.
lazyboye8634172016-01-28 00:10:482131 if (info.mark_acknowledged)
2132 external_install_manager_->AcknowledgeExternalExtension(info.extension_id);
[email protected]9060d8b02012-01-13 02:14:302133
2134 return true;
[email protected]7577a5c52009-07-30 06:21:582135}
2136
[email protected]eaa7dd182010-12-14 11:09:002137void ExtensionService::DidCreateRenderViewForBackgroundPage(
[email protected]3a1dc572012-07-31 22:25:132138 extensions::ExtensionHost* host) {
[email protected]406027c02010-09-27 08:03:182139 OrphanedDevTools::iterator iter =
[email protected]2d2f6cfc2011-05-06 21:09:332140 orphaned_dev_tools_.find(host->extension_id());
[email protected]406027c02010-09-27 08:03:182141 if (iter == orphaned_dev_tools_.end())
2142 return;
2143
rockota34fed222015-09-25 21:56:312144 // Keepalive count is reset on extension reload. This re-establishes the
2145 // keepalive that was added when the DevTools agent was initially attached.
2146 extensions::ProcessManager::Get(profile_)->IncrementLazyKeepaliveCount(
2147 host->extension());
[email protected]b3f957e62014-08-08 10:09:022148 iter->second->ConnectWebContents(host->host_contents());
[email protected]406027c02010-09-27 08:03:182149 orphaned_dev_tools_.erase(iter);
2150}
2151
[email protected]432115822011-07-10 15:52:272152void ExtensionService::Observe(int type,
[email protected]6c2381d2011-10-19 02:52:532153 const content::NotificationSource& source,
2154 const content::NotificationDetails& details) {
[email protected]432115822011-07-10 15:52:272155 switch (type) {
[email protected]3c4abc82012-10-22 22:25:542156 case chrome::NOTIFICATION_APP_TERMINATING:
2157 // Shutdown has started. Don't start any more extension installs.
2158 // (We cannot use ExtensionService::Shutdown() for this because it
2159 // happens too late in browser teardown.)
2160 browser_terminating_ = true;
2161 break;
[email protected]adf5a102014-07-31 12:44:062162 case extensions::NOTIFICATION_EXTENSION_PROCESS_TERMINATED: {
[email protected]6c2381d2011-10-19 02:52:532163 if (profile_ !=
2164 content::Source<Profile>(source).ptr()->GetOriginalProfile()) {
[email protected]bc535ee52010-08-31 18:40:322165 break;
[email protected]6c2381d2011-10-19 02:52:532166 }
[email protected]a4ed6282009-12-14 20:51:162167
[email protected]3a1dc572012-07-31 22:25:132168 extensions::ExtensionHost* host =
2169 content::Details<extensions::ExtensionHost>(details).ptr();
[email protected]f128af42010-08-05 18:05:262170
[email protected]3964e572014-02-13 21:57:412171 // If the extension is already being terminated, there is nothing left to
2172 // do.
2173 if (!extensions_being_terminated_.insert(host->extension_id()).second)
2174 break;
2175
[email protected]fa2416f2011-05-03 08:41:202176 // Mark the extension as terminated and Unload it. We want it to
2177 // be in a consistent state: either fully working or not loaded
2178 // at all, but never half-crashed. We do it in a PostTask so
2179 // that other handlers of this notification will still have
2180 // access to the Extension and ExtensionHost.
skyostilf221b7de2015-06-11 20:36:322181 base::ThreadTaskRunnerHandle::Get()->PostTask(
tzik8d880ee2017-04-20 19:46:242182 FROM_HERE, base::BindOnce(&ExtensionService::TrackTerminatedExtension,
2183 AsWeakPtr(), host->extension()->id()));
[email protected]31f77262009-12-02 20:48:532184 break;
2185 }
[email protected]432115822011-07-10 15:52:272186 case content::NOTIFICATION_RENDERER_PROCESS_TERMINATED: {
[email protected]f3b1a082011-11-18 00:34:302187 content::RenderProcessHost* process =
2188 content::Source<content::RenderProcessHost>(source).ptr();
[email protected]fc30ef082011-08-18 04:07:192189 Profile* host_profile =
[email protected]f3b1a082011-11-18 00:34:302190 Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]fc30ef082011-08-18 04:07:192191 if (!profile_->IsSameProfile(host_profile->GetOriginalProfile()))
2192 break;
2193
[email protected]fafdc842014-01-17 18:09:082194 extensions::ProcessMap* process_map =
2195 extensions::ProcessMap::Get(profile_);
2196 if (process_map->Contains(process->GetID())) {
[email protected]52b76592013-11-02 17:59:032197 // An extension process was terminated, this might have resulted in an
2198 // app or extension becoming idle.
2199 std::set<std::string> extension_ids =
[email protected]fafdc842014-01-17 18:09:082200 process_map->GetExtensionsInProcess(process->GetID());
elijahtaylor0def4432014-10-06 18:15:112201 // In addition to the extensions listed in the process map, one of those
2202 // extensions could be referencing a shared module which is waiting for
2203 // idle to update. Check all imports of these extensions, too.
2204 std::set<std::string> import_ids;
2205 for (std::set<std::string>::const_iterator it = extension_ids.begin();
2206 it != extension_ids.end();
2207 ++it) {
2208 const Extension* extension = GetExtensionById(*it, true);
2209 if (!extension)
2210 continue;
2211 const std::vector<SharedModuleInfo::ImportInfo>& imports =
2212 SharedModuleInfo::GetImports(extension);
2213 std::vector<SharedModuleInfo::ImportInfo>::const_iterator import_it;
2214 for (import_it = imports.begin(); import_it != imports.end();
2215 import_it++) {
2216 import_ids.insert((*import_it).extension_id);
2217 }
2218 }
2219 extension_ids.insert(import_ids.begin(), import_ids.end());
2220
[email protected]52b76592013-11-02 17:59:032221 for (std::set<std::string>::const_iterator it = extension_ids.begin();
2222 it != extension_ids.end(); ++it) {
2223 if (delayed_installs_.Contains(*it)) {
skyostilf221b7de2015-06-11 20:36:322224 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
[email protected]52b76592013-11-02 17:59:032225 FROM_HERE,
tzik8d880ee2017-04-20 19:46:242226 base::BindOnce(
2227 &ExtensionService::MaybeFinishDelayedInstallation,
2228 AsWeakPtr(), *it),
[email protected]52b76592013-11-02 17:59:032229 base::TimeDelta::FromSeconds(kUpdateIdleDelay));
2230 }
2231 }
2232 }
2233
[email protected]fafdc842014-01-17 18:09:082234 process_map->RemoveAllFromProcess(process->GetID());
[email protected]6f371442011-11-09 06:45:462235 BrowserThread::PostTask(
tzik8d880ee2017-04-20 19:46:242236 BrowserThread::IO, FROM_HERE,
2237 base::BindOnce(&extensions::InfoMap::UnregisterAllExtensionsInProcess,
2238 system_->info_map(), process->GetID()));
[email protected]da5683db2011-04-23 17:12:212239 break;
2240 }
[email protected]ebe07772014-05-22 04:16:062241 case chrome::NOTIFICATION_PROFILE_DESTRUCTION_STARTED: {
2242 OnProfileDestructionStarted();
2243 break;
2244 }
[email protected]aa96d3a2010-08-21 08:45:252245
[email protected]4814b512009-11-07 00:12:292246 default:
2247 NOTREACHED() << "Unexpected notification type.";
2248 }
2249}
2250
binjin47947f842014-11-18 12:10:242251int ExtensionService::GetDisableReasonsOnInstalled(const Extension* extension) {
rdevlin.cronine1456712016-12-29 22:47:282252 bool is_update_from_same_type = false;
2253 {
2254 const Extension* existing_extension =
2255 GetInstalledExtension(extension->id());
2256 is_update_from_same_type =
2257 existing_extension &&
2258 existing_extension->manifest()->type() == extension->manifest()->type();
2259 }
2260 Extension::DisableReason disable_reason = Extension::DISABLE_NONE;
binjin47947f842014-11-18 12:10:242261 // Extensions disabled by management policy should always be disabled, even
2262 // if it's force-installed.
2263 if (system_->management_policy()->MustRemainDisabled(
2264 extension, &disable_reason, nullptr)) {
2265 // A specified reason is required to disable the extension.
2266 DCHECK(disable_reason != Extension::DISABLE_NONE);
2267 return disable_reason;
2268 }
2269
[email protected]612a1cb12012-10-17 13:18:032270 // Extensions installed by policy can't be disabled. So even if a previous
2271 // installation disabled the extension, make sure it is now enabled.
binjin47947f842014-11-18 12:10:242272 if (system_->management_policy()->MustRemainEnabled(extension, nullptr))
2273 return Extension::DISABLE_NONE;
[email protected]612a1cb12012-10-17 13:18:032274
binjin47947f842014-11-18 12:10:242275 // An already disabled extension should inherit the disable reasons and
2276 // remain disabled.
2277 if (extension_prefs_->IsExtensionDisabled(extension->id())) {
2278 int disable_reasons = extension_prefs_->GetDisableReasons(extension->id());
2279 // If an extension was disabled without specified reason, presume it's
2280 // disabled by user.
2281 return disable_reasons == Extension::DISABLE_NONE
2282 ? Extension::DISABLE_USER_ACTION
2283 : disable_reasons;
2284 }
[email protected]612a1cb12012-10-17 13:18:032285
rdevlin.cronin9d7ae4d2017-01-13 16:38:232286 if (extensions::ExternalInstallManager::IsPromptingEnabled()) {
[email protected]612a1cb12012-10-17 13:18:032287 // External extensions are initially disabled. We prompt the user before
[email protected]2c495c42013-01-04 21:49:542288 // enabling them. Hosted apps are excepted because they are not dangerous
rdevlin.cronine1456712016-12-29 22:47:282289 // (they need to be launched by the user anyway). We also don't prompt for
2290 // extensions updating; this is because the extension will be disabled from
2291 // the initial install if it is supposed to be, and this allows us to turn
2292 // this on for other platforms without disabling already-installed
2293 // extensions.
[email protected]1d5e58b2013-01-31 08:41:402294 if (extension->GetType() != Manifest::TYPE_HOSTED_APP &&
2295 Manifest::IsExternalLocation(extension->location()) &&
rdevlin.cronine1456712016-12-29 22:47:282296 !extension_prefs_->IsExternalExtensionAcknowledged(extension->id()) &&
2297 !is_update_from_same_type) {
binjin47947f842014-11-18 12:10:242298 return Extension::DISABLE_EXTERNAL_EXTENSION;
[email protected]612a1cb12012-10-17 13:18:032299 }
2300 }
[email protected]612a1cb12012-10-17 13:18:032301
binjin47947f842014-11-18 12:10:242302 return Extension::DISABLE_NONE;
[email protected]612a1cb12012-10-17 13:18:032303}
[email protected]0db124b02012-11-07 04:55:052304
mlerman6a37b6a42014-11-26 22:10:532305// Helper method to determine if an extension can be blocked.
2306bool ExtensionService::CanBlockExtension(const Extension* extension) const {
mlerman3690e5be2014-12-01 22:57:442307 DCHECK(extension);
mlerman6a37b6a42014-11-26 22:10:532308 return extension->location() != Manifest::COMPONENT &&
2309 extension->location() != Manifest::EXTERNAL_COMPONENT &&
achuith2f5578b2016-02-26 21:57:132310 !system_->management_policy()->MustRemainEnabled(extension, nullptr);
mlerman6a37b6a42014-11-26 22:10:532311}
2312
xiyuanf6a4c6a62016-04-19 18:14:542313extensions::InstallGate::Action ExtensionService::ShouldDelayExtensionInstall(
2314 const extensions::Extension* extension,
2315 bool install_immediately,
2316 extensions::ExtensionPrefs::DelayReason* reason) const {
2317 for (const auto& entry : install_delayer_registry_) {
2318 extensions::InstallGate* const delayer = entry.second;
2319 extensions::InstallGate::Action action =
2320 delayer->ShouldDelay(extension, install_immediately);
2321 if (action != extensions::InstallGate::INSTALL) {
2322 *reason = entry.first;
2323 return action;
2324 }
[email protected]e7aa7b7e2012-11-27 04:51:222325 }
[email protected]fdd679b2012-11-15 20:49:392326
xiyuanf6a4c6a62016-04-19 18:14:542327 return extensions::InstallGate::INSTALL;
[email protected]9f4e4f082013-06-21 07:11:192328}
2329
2330void ExtensionService::MaybeFinishDelayedInstallations() {
2331 std::vector<std::string> to_be_installed;
achuith2f5578b2016-02-26 21:57:132332 for (const auto& extension : delayed_installs_) {
2333 to_be_installed.push_back(extension->id());
[email protected]399583b2012-12-11 09:33:422334 }
achuith2f5578b2016-02-26 21:57:132335 for (const auto& extension_id : to_be_installed) {
2336 MaybeFinishDelayedInstallation(extension_id);
[email protected]399583b2012-12-11 09:33:422337 }
[email protected]399583b2012-12-11 09:33:422338}
2339
[email protected]fdd679b2012-11-15 20:49:392340void ExtensionService::OnBlacklistUpdated() {
[email protected]2d19eb6e2014-01-27 17:30:002341 blacklist_->GetBlacklistedIDs(
[email protected]f47f7172014-03-19 19:27:102342 registry_->GenerateInstalledExtensionsSet()->GetIDs(),
[email protected]3f2a2fa2013-09-24 02:55:252343 base::Bind(&ExtensionService::ManageBlacklist, AsWeakPtr()));
[email protected]695b5712012-12-06 23:55:282344}
2345
weidongg04695232017-06-09 00:01:052346void ExtensionService::OnUpgradeRecommended() {
2347 // Notify observers that chrome update is available.
2348 for (auto& observer : update_observers_)
2349 observer.OnChromeUpdateAvailable();
2350}
2351
[email protected]2d19eb6e2014-01-27 17:30:002352void ExtensionService::ManageBlacklist(
2353 const extensions::Blacklist::BlacklistStateMap& state_map) {
[email protected]54ee8192014-03-29 17:37:242354 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]695b5712012-12-06 23:55:282355
mlerman6a37b6a42014-11-26 22:10:532356 std::set<std::string> blacklisted;
[email protected]2d19eb6e2014-01-27 17:30:002357 ExtensionIdSet greylist;
2358 ExtensionIdSet unchanged;
achuith2f5578b2016-02-26 21:57:132359 for (const auto& it : state_map) {
2360 switch (it.second) {
[email protected]2d19eb6e2014-01-27 17:30:002361 case extensions::NOT_BLACKLISTED:
2362 break;
[email protected]695b5712012-12-06 23:55:282363
[email protected]2d19eb6e2014-01-27 17:30:002364 case extensions::BLACKLISTED_MALWARE:
achuith2f5578b2016-02-26 21:57:132365 blacklisted.insert(it.first);
[email protected]2d19eb6e2014-01-27 17:30:002366 break;
2367
2368 case extensions::BLACKLISTED_SECURITY_VULNERABILITY:
2369 case extensions::BLACKLISTED_CWS_POLICY_VIOLATION:
2370 case extensions::BLACKLISTED_POTENTIALLY_UNWANTED:
achuith2f5578b2016-02-26 21:57:132371 greylist.insert(it.first);
[email protected]2d19eb6e2014-01-27 17:30:002372 break;
2373
2374 case extensions::BLACKLISTED_UNKNOWN:
achuith2f5578b2016-02-26 21:57:132375 unchanged.insert(it.first);
[email protected]2d19eb6e2014-01-27 17:30:002376 break;
2377 }
2378 }
2379
mlerman6a37b6a42014-11-26 22:10:532380 UpdateBlacklistedExtensions(blacklisted, unchanged);
[email protected]2d19eb6e2014-01-27 17:30:002381 UpdateGreylistedExtensions(greylist, unchanged, state_map);
2382
[email protected]373daf972014-04-10 01:50:442383 error_controller_->ShowErrorIfNeeded();
[email protected]2d19eb6e2014-01-27 17:30:002384}
2385
2386namespace {
2387void Partition(const ExtensionIdSet& before,
2388 const ExtensionIdSet& after,
2389 const ExtensionIdSet& unchanged,
2390 ExtensionIdSet* no_longer,
2391 ExtensionIdSet* not_yet) {
2392 *not_yet = base::STLSetDifference<ExtensionIdSet>(after, before);
2393 *no_longer = base::STLSetDifference<ExtensionIdSet>(before, after);
2394 *no_longer = base::STLSetDifference<ExtensionIdSet>(*no_longer, unchanged);
2395}
2396} // namespace
2397
mlerman6a37b6a42014-11-26 22:10:532398void ExtensionService::UpdateBlacklistedExtensions(
2399 const ExtensionIdSet& blacklisted,
[email protected]2d19eb6e2014-01-27 17:30:002400 const ExtensionIdSet& unchanged) {
2401 ExtensionIdSet not_yet_blocked, no_longer_blocked;
mlerman6a37b6a42014-11-26 22:10:532402 Partition(registry_->blacklisted_extensions().GetIDs(), blacklisted,
2403 unchanged, &no_longer_blocked, &not_yet_blocked);
[email protected]2d19eb6e2014-01-27 17:30:002404
2405 for (ExtensionIdSet::iterator it = no_longer_blocked.begin();
2406 it != no_longer_blocked.end(); ++it) {
[email protected]695b5712012-12-06 23:55:282407 scoped_refptr<const Extension> extension =
[email protected]bb1bc9b32013-12-21 03:09:142408 registry_->blacklisted_extensions().GetByID(*it);
[email protected]3f2a2fa2013-09-24 02:55:252409 if (!extension.get()) {
mlerman6a37b6a42014-11-26 22:10:532410 NOTREACHED() << "Extension " << *it << " no longer blacklisted, "
2411 << "but it was never blacklisted.";
[email protected]695b5712012-12-06 23:55:282412 continue;
[email protected]3f2a2fa2013-09-24 02:55:252413 }
[email protected]bb1bc9b32013-12-21 03:09:142414 registry_->RemoveBlacklisted(*it);
atuchin6dc7c442016-07-20 07:04:342415 extension_prefs_->SetExtensionBlacklistState(extension->id(),
2416 extensions::NOT_BLACKLISTED);
[email protected]dc24976f2013-06-02 21:15:092417 AddExtension(extension.get());
[email protected]ac875372013-02-28 04:36:092418 UMA_HISTOGRAM_ENUMERATION("ExtensionBlacklist.UnblacklistInstalled",
[email protected]dc24976f2013-06-02 21:15:092419 extension->location(),
2420 Manifest::NUM_LOCATIONS);
[email protected]695b5712012-12-06 23:55:282421 }
2422
[email protected]2d19eb6e2014-01-27 17:30:002423 for (ExtensionIdSet::iterator it = not_yet_blocked.begin();
2424 it != not_yet_blocked.end(); ++it) {
[email protected]695b5712012-12-06 23:55:282425 scoped_refptr<const Extension> extension = GetInstalledExtension(*it);
[email protected]3f2a2fa2013-09-24 02:55:252426 if (!extension.get()) {
2427 NOTREACHED() << "Extension " << *it << " needs to be "
2428 << "blacklisted, but it's not installed.";
[email protected]695b5712012-12-06 23:55:282429 continue;
[email protected]3f2a2fa2013-09-24 02:55:252430 }
[email protected]bb1bc9b32013-12-21 03:09:142431 registry_->AddBlacklisted(extension);
[email protected]2d19eb6e2014-01-27 17:30:002432 extension_prefs_->SetExtensionBlacklistState(
2433 extension->id(), extensions::BLACKLISTED_MALWARE);
limasdf0deef2042017-05-03 19:17:172434 UnloadExtension(*it, UnloadedExtensionReason::BLACKLIST);
[email protected]ac875372013-02-28 04:36:092435 UMA_HISTOGRAM_ENUMERATION("ExtensionBlacklist.BlacklistInstalled",
2436 extension->location(), Manifest::NUM_LOCATIONS);
[email protected]695b5712012-12-06 23:55:282437 }
[email protected]2d19eb6e2014-01-27 17:30:002438}
[email protected]695b5712012-12-06 23:55:282439
[email protected]2d19eb6e2014-01-27 17:30:002440// TODO(oleg): UMA logging
2441void ExtensionService::UpdateGreylistedExtensions(
2442 const ExtensionIdSet& greylist,
2443 const ExtensionIdSet& unchanged,
2444 const extensions::Blacklist::BlacklistStateMap& state_map) {
2445 ExtensionIdSet not_yet_greylisted, no_longer_greylisted;
2446 Partition(greylist_.GetIDs(),
2447 greylist, unchanged,
2448 &no_longer_greylisted, &not_yet_greylisted);
2449
2450 for (ExtensionIdSet::iterator it = no_longer_greylisted.begin();
2451 it != no_longer_greylisted.end(); ++it) {
2452 scoped_refptr<const Extension> extension = greylist_.GetByID(*it);
2453 if (!extension.get()) {
2454 NOTREACHED() << "Extension " << *it << " no longer greylisted, "
2455 << "but it was not marked as greylisted.";
2456 continue;
2457 }
2458
2459 greylist_.Remove(*it);
2460 extension_prefs_->SetExtensionBlacklistState(extension->id(),
2461 extensions::NOT_BLACKLISTED);
2462 if (extension_prefs_->GetDisableReasons(extension->id()) &
2463 extensions::Extension::DISABLE_GREYLIST)
2464 EnableExtension(*it);
2465 }
2466
2467 for (ExtensionIdSet::iterator it = not_yet_greylisted.begin();
2468 it != not_yet_greylisted.end(); ++it) {
2469 scoped_refptr<const Extension> extension = GetInstalledExtension(*it);
2470 if (!extension.get()) {
2471 NOTREACHED() << "Extension " << *it << " needs to be "
2472 << "disabled, but it's not installed.";
2473 continue;
2474 }
2475 greylist_.Insert(extension);
2476 extension_prefs_->SetExtensionBlacklistState(extension->id(),
2477 state_map.find(*it)->second);
2478 if (registry_->enabled_extensions().Contains(extension->id()))
2479 DisableExtension(*it, extensions::Extension::DISABLE_GREYLIST);
2480 }
[email protected]fdd679b2012-11-15 20:49:392481}
[email protected]75bdcb872013-03-13 00:41:452482
2483void ExtensionService::AddUpdateObserver(extensions::UpdateObserver* observer) {
2484 update_observers_.AddObserver(observer);
2485}
2486
2487void ExtensionService::RemoveUpdateObserver(
2488 extensions::UpdateObserver* observer) {
2489 update_observers_.RemoveObserver(observer);
2490}
[email protected]bb1bc9b32013-12-21 03:09:142491
xiyuanf6a4c6a62016-04-19 18:14:542492void ExtensionService::RegisterInstallGate(
2493 extensions::ExtensionPrefs::DelayReason reason,
2494 extensions::InstallGate* install_delayer) {
2495 DCHECK(install_delayer_registry_.end() ==
2496 install_delayer_registry_.find(reason));
2497 install_delayer_registry_[reason] = install_delayer;
2498}
2499
2500void ExtensionService::UnregisterInstallGate(
2501 extensions::InstallGate* install_delayer) {
2502 for (auto it = install_delayer_registry_.begin();
2503 it != install_delayer_registry_.end(); ++it) {
2504 if (it->second == install_delayer) {
2505 install_delayer_registry_.erase(it);
2506 return;
2507 }
2508 }
2509}
2510
Devlin Cronin40b4cbc2017-08-02 01:57:592511base::SequencedTaskRunner* ExtensionService::GetFileTaskRunner() {
2512 // TODO(devlin): Update callers to use GetExtensionFileTaskRunner()
2513 // directly.
2514 return extensions::GetExtensionFileTaskRunner().get();
2515}
2516
[email protected]bb1bc9b32013-12-21 03:09:142517// Used only by test code.
2518void ExtensionService::UnloadAllExtensionsInternal() {
2519 profile_->GetExtensionSpecialStoragePolicy()->RevokeRightsForAllExtensions();
2520
2521 registry_->ClearAll();
[email protected]45f5b7d2014-01-22 23:47:132522 system_->runtime_data()->ClearAll();
[email protected]bb1bc9b32013-12-21 03:09:142523
2524 // TODO(erikkay) should there be a notification for this? We can't use
2525 // EXTENSION_UNLOADED since that implies that the extension has been disabled
2526 // or uninstalled.
2527}
[email protected]ebe07772014-05-22 04:16:062528
2529void ExtensionService::OnProfileDestructionStarted() {
2530 ExtensionIdSet ids_to_unload = registry_->enabled_extensions().GetIDs();
2531 for (ExtensionIdSet::iterator it = ids_to_unload.begin();
2532 it != ids_to_unload.end();
2533 ++it) {
limasdf0deef2042017-05-03 19:17:172534 UnloadExtension(*it, UnloadedExtensionReason::PROFILE_SHUTDOWN);
[email protected]ebe07772014-05-22 04:16:062535 }
2536}
rdevlin.croninf2e1cb012017-05-27 01:27:592537
2538void ExtensionService::OnInstalledExtensionsLoaded() {
2539 if (updater_)
2540 updater_->Start();
2541
2542 // Enable any Shared Modules that incorrectly got disabled previously.
2543 // This is temporary code to fix incorrect behavior from previous versions of
2544 // Chrome and can be removed after several releases (perhaps M60).
2545 extensions::ExtensionList to_enable;
2546 for (const auto& extension : registry_->disabled_extensions()) {
2547 if (SharedModuleInfo::IsSharedModule(extension.get()))
2548 to_enable.push_back(extension);
2549 }
2550 for (const auto& extension : to_enable) {
2551 EnableExtension(extension->id());
2552 }
2553
2554 OnBlacklistUpdated();
2555}
lazyboy75b9def2017-06-06 18:56:592556
2557void ExtensionService::MaybeSpinUpLazyBackgroundPage(
2558 const Extension* extension) {
2559 if (!extensions::BackgroundInfo::HasLazyBackgroundPage(extension))
2560 return;
2561
2562 // For orphaned devtools, we will reconnect devtools to it later in
2563 // DidCreateRenderViewForBackgroundPage().
2564 OrphanedDevTools::iterator iter = orphaned_dev_tools_.find(extension->id());
2565 bool has_orphaned_dev_tools = iter != orphaned_dev_tools_.end();
2566
2567 // Reloading component extension does not trigger install, so RuntimeAPI won't
2568 // be able to detect its loading. Therefore, we need to spin up its lazy
2569 // background page.
2570 bool is_component_extension =
2571 Manifest::IsComponentLocation(extension->location());
2572
2573 if (!has_orphaned_dev_tools && !is_component_extension)
2574 return;
2575
2576 // Wake up the event page by posting a dummy task.
2577 extensions::LazyBackgroundTaskQueue* queue =
2578 extensions::LazyBackgroundTaskQueue::Get(profile_);
2579 queue->AddPendingTask(profile_, extension->id(),
2580 base::Bind(&DoNothingWithExtensionHost));
2581}
Takumi Fujimoto43c8c00f2017-07-26 22:48:562582
2583void ExtensionService::UninstallMigratedExtensions() {
2584 std::unique_ptr<ExtensionSet> installed_extensions =
2585 registry_->GenerateInstalledExtensionsSet();
2586
2587 for (const std::string& extension_id : kMigratedExtensionIds) {
2588 if (installed_extensions->Contains(extension_id)) {
2589 UninstallExtension(extension_id, extensions::UNINSTALL_REASON_MIGRATED,
2590 base::Bind(&base::DoNothing), nullptr);
2591 }
2592 }
2593}