blob: 3eeead6aebffa750e33fe13a02f6b5c84500a9f3 [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"
Ilya Sherman982457e62017-12-13 02:19:3618#include "base/metrics/histogram_functions.h"
rkaplowfca0f4dc52015-03-14 21:40:5719#include "base/metrics/histogram_macros.h"
skyostilf221b7de2015-06-11 20:36:3220#include "base/single_thread_task_runner.h"
tripta.g0ac673a2017-07-07 05:45:0921#include "base/stl_util.h"
[email protected]3ea1b182013-02-08 22:38:4122#include "base/strings/string_number_conversions.h"
catmullings98cd1942016-08-30 22:31:5923#include "base/strings/string_tokenizer.h"
[email protected]00e7bef2013-06-10 20:35:1724#include "base/strings/stringprintf.h"
[email protected]112158af2013-06-07 23:46:1825#include "base/strings/utf_string_conversions.h"
fdoray71c48e722017-05-17 22:37:0926#include "base/task_scheduler/post_task.h"
[email protected]34b99632011-01-01 01:01:0627#include "base/threading/thread_restrictions.h"
gabb15e19072016-05-11 20:45:4128#include "base/threading/thread_task_runner_handle.h"
[email protected]41a17c52013-06-28 00:27:5329#include "base/time/time.h"
rkaplowe65c2ff2015-02-14 16:29:5430#include "base/trace_event/trace_event.h"
avia2f4804a2015-12-24 23:11:1331#include "build/build_config.h"
[email protected]15730c42009-09-03 00:03:2032#include "chrome/browser/browser_process.h"
[email protected]9ea0cd32013-07-12 01:50:3633#include "chrome/browser/chrome_notification_types.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"
Scott Violet6200d332018-02-23 21:29:2364#include "chrome/common/buildflags.h"
[email protected]e2eb43112009-05-29 21:19:5465#include "chrome/common/chrome_switches.h"
[email protected]f6431be82013-09-07 02:53:4566#include "chrome/common/crash_keys.h"
[email protected]9f4e4f082013-06-21 07:11:1967#include "chrome/common/extensions/extension_constants.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"
Gabriel Charette790754c2018-03-16 21:32:5971#include "content/public/browser/browser_thread.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"
[email protected]34423532013-11-21 18:13:1075#include "extensions/browser/event_router.h"
Devlin Cronin40b4cbc2017-08-02 01:57:5976#include "extensions/browser/extension_file_task_runner.h"
[email protected]22401dc2014-03-21 01:38:5777#include "extensions/browser/extension_host.h"
[email protected]bb1bc9b32013-12-21 03:09:1478#include "extensions/browser/extension_registry.h"
[email protected]59b0e602014-01-30 00:41:2479#include "extensions/browser/extension_system.h"
Michael Giuffrida7efeed142017-06-07 06:29:2180#include "extensions/browser/extension_util.h"
rockotffa65b12014-10-14 17:19:0681#include "extensions/browser/extensions_browser_client.h"
lazyboye8634172016-01-28 00:10:4882#include "extensions/browser/external_install_info.h"
[email protected]4a1d9c0d2014-06-13 12:50:1183#include "extensions/browser/install_flag.h"
Michael Giuffrida6397c592017-10-09 20:46:5384#include "extensions/browser/management_policy.h"
[email protected]45f5b7d2014-01-22 23:47:1385#include "extensions/browser/runtime_data.h"
[email protected]e43c61f2014-07-20 21:46:3486#include "extensions/browser/uninstall_reason.h"
[email protected]a9aa62b312013-11-29 05:35:0687#include "extensions/browser/update_observer.h"
rockotffa65b12014-10-14 17:19:0688#include "extensions/browser/updater/extension_cache.h"
rockot05f40a922014-10-16 19:40:2589#include "extensions/browser/updater/extension_downloader.h"
[email protected]fb820c02014-03-13 15:07:0890#include "extensions/common/extension_messages.h"
rockot90659852014-09-18 19:31:5291#include "extensions/common/extension_urls.h"
[email protected]5ef835a2013-11-08 20:42:5792#include "extensions/common/feature_switch.h"
rdevlin.cronin41227532016-07-13 21:24:3493#include "extensions/common/features/feature_channel.h"
[email protected]85df9d12014-04-15 17:02:1494#include "extensions/common/file_util.h"
[email protected]0c3c9732013-09-16 08:53:4195#include "extensions/common/manifest_constants.h"
Michael Giuffrida6397c592017-10-09 20:46:5396#include "extensions/common/manifest_handlers/shared_module_info.h"
rockotd5546142014-10-15 00:29:0897#include "extensions/common/manifest_url_handlers.h"
[email protected]dccba4f82014-05-29 00:52:5698#include "extensions/common/one_shot_event.h"
treib2e0517f92015-05-07 23:15:3699#include "extensions/common/permissions/api_permission.h"
[email protected]c41003472013-10-19 15:37:25100#include "extensions/common/permissions/permission_message_provider.h"
[email protected]e4452d32013-11-15 23:07:41101#include "extensions/common/permissions/permissions_data.h"
Michael Giuffridab158f3f2017-07-17 19:53:44102#include "extensions/common/switches.h"
[email protected]79a60642012-10-20 21:03:18103
brettw9e85ef42016-11-01 21:01:24104#if BUILDFLAG(ENABLE_SUPERVISED_USERS)
treib8ecc1eb52015-03-04 18:29:06105#include "chrome/browser/supervised_user/supervised_user_service.h"
106#include "chrome/browser/supervised_user/supervised_user_service_factory.h"
107#endif
108
[email protected]eed367e2011-04-12 03:43:31109#if defined(OS_CHROMEOS)
[email protected]88e8ec9152013-01-17 04:05:18110#include "chrome/browser/chromeos/extensions/install_limiter.h"
achuithd3da4f02017-03-23 20:05:29111#include "chrome/browser/chromeos/profiles/profile_helper.h"
pilgrime92c5fcd2014-09-10 23:31:23112#include "storage/browser/fileapi/file_system_backend.h"
113#include "storage/browser/fileapi/file_system_context.h"
[email protected]eed367e2011-04-12 03:43:31114#endif
115
[email protected]55eb70e762012-02-20 17:38:39116using content::BrowserContext;
[email protected]631bb742011-11-02 11:29:39117using content::BrowserThread;
Devlin Cronineea1b7a2018-05-26 02:46:21118
119namespace extensions {
[email protected]5ef47ec2010-01-28 05:58:05120
Michael Giuffrida573992d2018-02-08 00:48:44121using LoadErrorBehavior = ExtensionRegistrar::LoadErrorBehavior;
122
[email protected]b6ab96d2009-08-20 18:58:19123namespace {
124
[email protected]0db124b02012-11-07 04:55:05125// Wait this many seconds after an extensions becomes idle before updating it.
[email protected]ddc6a122014-06-27 04:52:32126const int kUpdateIdleDelay = 5;
[email protected]0db124b02012-11-07 04:55:05127
Takumi Fujimoto43c8c00f2017-07-26 22:48:56128// IDs of extensions that have been replaced by component extensions and need to
129// be uninstalled.
130const char* kMigratedExtensionIds[] = {
131 "boadgeojelhgndaghljhdicfkmllpafd", // Google Cast
132 "dliochdbjfkdbacpmhlcpmleaejidimm" // Google Cast (Beta)
133};
134
[email protected]c6d474f82009-12-16 21:11:06135} // namespace
[email protected]b6ab96d2009-08-20 18:58:19136
[email protected]eaa7dd182010-12-14 11:09:00137// ExtensionService.
[email protected]6014d672008-12-05 00:38:25138
[email protected]8e4560b62011-01-14 10:09:14139void ExtensionService::CheckExternalUninstall(const std::string& id) {
[email protected]a29a517a2011-01-21 21:11:12140 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]a8af9fdb2010-10-28 21:52:20141
[email protected]7a4c6852010-09-16 03:44:22142 // Check if the providers know about this extension.
achuith2f5578b2016-02-26 21:57:13143 for (const auto& provider : external_extension_providers_) {
144 DCHECK(provider->IsReady());
145 if (provider->HasExtension(id))
[email protected]0a60a2e2010-10-25 16:15:21146 return; // Yup, known extension, don't uninstall.
[email protected]7a4c6852010-09-16 03:44:22147 }
148
[email protected]0f48fca2011-05-19 18:46:35149 // We get the list of external extensions to check from preferences.
150 // It is possible that an extension has preferences but is not loaded.
151 // For example, an extension that requires experimental permissions
152 // will not be loaded if the experimental command line flag is not used.
153 // In this case, do not uninstall.
[email protected]31bb5ee62012-09-12 22:58:40154 if (!GetInstalledExtension(id)) {
[email protected]0f48fca2011-05-19 18:46:35155 // We can't call UninstallExtension with an unloaded/invalid
156 // extension ID.
157 LOG(WARNING) << "Attempted uninstallation of unloaded/invalid extension "
158 << "with id: " << id;
159 return;
160 }
Devlin Cronineea1b7a2018-05-26 02:46:21161 UninstallExtension(id, UNINSTALL_REASON_ORPHANED_EXTERNAL_EXTENSION, nullptr);
[email protected]7a4c6852010-09-16 03:44:22162}
163
[email protected]8e4560b62011-01-14 10:09:14164void ExtensionService::ClearProvidersForTesting() {
[email protected]7a4c6852010-09-16 03:44:22165 external_extension_providers_.clear();
166}
167
[email protected]8e4560b62011-01-14 10:09:14168void ExtensionService::AddProviderForTesting(
lazyboyf33109d2016-08-31 00:37:08169 std::unique_ptr<ExternalProviderInterface> test_provider) {
[email protected]a29a517a2011-01-21 21:11:12170 CHECK(test_provider);
lazyboyf33109d2016-08-31 00:37:08171 external_extension_providers_.push_back(std::move(test_provider));
[email protected]7a4c6852010-09-16 03:44:22172}
173
[email protected]8f959f522014-08-06 06:26:28174void ExtensionService::BlacklistExtensionForTest(
175 const std::string& extension_id) {
mlerman6a37b6a42014-11-26 22:10:53176 ExtensionIdSet blacklisted;
[email protected]8f959f522014-08-06 06:26:28177 ExtensionIdSet unchanged;
mlerman6a37b6a42014-11-26 22:10:53178 blacklisted.insert(extension_id);
179 UpdateBlacklistedExtensions(blacklisted, unchanged);
[email protected]8f959f522014-08-06 06:26:28180}
181
[email protected]9060d8b02012-01-13 02:14:30182bool ExtensionService::OnExternalExtensionUpdateUrlFound(
lazyboye8634172016-01-28 00:10:48183 const ExternalInstallInfoUpdateUrl& info,
184 bool is_initial_load) {
Istiaque Ahmedf6e72622017-09-08 23:14:17185 DCHECK_CURRENTLY_ON(BrowserThread::UI);
lazyboye8634172016-01-28 00:10:48186 CHECK(crx_file::id_util::IdIsValid(info.extension_id));
[email protected]a8af9fdb2010-10-28 21:52:20187
lazyboye8634172016-01-28 00:10:48188 if (Manifest::IsExternalLocation(info.download_location)) {
[email protected]044e86992014-01-24 22:59:11189 // All extensions that are not user specific can be cached.
Devlin Cronineea1b7a2018-05-26 02:46:21190 ExtensionsBrowserClient::Get()->GetExtensionCache()->AllowCaching(
191 info.extension_id);
[email protected]044e86992014-01-24 22:59:11192 }
193
lazyboye8634172016-01-28 00:10:48194 const Extension* extension = GetExtensionById(info.extension_id, true);
[email protected]8a87a5332011-08-11 17:54:59195 if (extension) {
asargent56282ab72016-09-09 16:58:03196 // Already installed. Skip this install if the current location has higher
197 // priority than |info.download_location|, and we aren't doing a
198 // reinstall of a corrupt policy force-installed extension.
[email protected]1d5e58b2013-01-31 08:41:40199 Manifest::Location current = extension->location();
asargent56282ab72016-09-09 16:58:03200 if (!pending_extension_manager_.IsPolicyReinstallForCorruptionExpected(
201 info.extension_id) &&
202 current == Manifest::GetHigherPriorityLocation(
203 current, info.download_location)) {
[email protected]9060d8b02012-01-13 02:14:30204 return false;
lazyboye8634172016-01-28 00:10:48205 }
[email protected]8a87a5332011-08-11 17:54:59206 // Otherwise, overwrite the current installation.
[email protected]7a4c6852010-09-16 03:44:22207 }
[email protected]9060d8b02012-01-13 02:14:30208
lazyboye8634172016-01-28 00:10:48209 // Add |info.extension_id| to the set of pending extensions. If it can not
210 // be added, then there is already a pending record from a higher-priority
211 // install source. In this case, signal that this extension will not be
[email protected]9060d8b02012-01-13 02:14:30212 // installed by returning false.
213 if (!pending_extension_manager()->AddFromExternalUpdateUrl(
Devlin Cronind4c2a8f32017-09-29 17:08:30214 info.extension_id, info.install_parameter, info.update_url,
lazyboye8634172016-01-28 00:10:48215 info.download_location, info.creation_flags,
216 info.mark_acknowledged)) {
[email protected]9060d8b02012-01-13 02:14:30217 return false;
[email protected]31bb5ee62012-09-12 22:58:40218 }
[email protected]9060d8b02012-01-13 02:14:30219
lazyboye8634172016-01-28 00:10:48220 if (is_initial_load)
221 update_once_all_providers_are_ready_ = true;
[email protected]9060d8b02012-01-13 02:14:30222 return true;
[email protected]7a4c6852010-09-16 03:44:22223}
224
lazyboye8634172016-01-28 00:10:48225void ExtensionService::OnExternalProviderUpdateComplete(
226 const ExternalProviderInterface* provider,
Devlin Cronin19f70b6a2017-10-01 04:14:05227 const std::vector<ExternalInstallInfoUpdateUrl>& update_url_extensions,
228 const std::vector<ExternalInstallInfoFile>& file_extensions,
lazyboye8634172016-01-28 00:10:48229 const std::set<std::string>& removed_extensions) {
230 // Update pending_extension_manager() with the new extensions first.
lazyboy4aeef202016-09-07 21:28:59231 for (const auto& extension : update_url_extensions)
Devlin Cronin19f70b6a2017-10-01 04:14:05232 OnExternalExtensionUpdateUrlFound(extension, false);
lazyboy4aeef202016-09-07 21:28:59233 for (const auto& extension : file_extensions)
Devlin Cronin19f70b6a2017-10-01 04:14:05234 OnExternalExtensionFileFound(extension);
lazyboye8634172016-01-28 00:10:48235
236#if DCHECK_IS_ON()
237 for (const std::string& id : removed_extensions) {
lazyboy4aeef202016-09-07 21:28:59238 for (const auto& extension : update_url_extensions)
Devlin Cronin19f70b6a2017-10-01 04:14:05239 DCHECK_NE(id, extension.extension_id);
lazyboy4aeef202016-09-07 21:28:59240 for (const auto& extension : file_extensions)
Devlin Cronin19f70b6a2017-10-01 04:14:05241 DCHECK_NE(id, extension.extension_id);
lazyboye8634172016-01-28 00:10:48242 }
243#endif
244
245 // Then uninstall before running |updater_|.
246 for (const std::string& id : removed_extensions)
247 CheckExternalUninstall(id);
248
249 if (!update_url_extensions.empty() && updater_) {
250 // Empty params will cause pending extensions to be updated.
Devlin Cronineea1b7a2018-05-26 02:46:21251 updater_->CheckNow(ExtensionUpdater::CheckParams());
lazyboye8634172016-01-28 00:10:48252 }
253
254 error_controller_->ShowErrorIfNeeded();
255 external_install_manager_->UpdateExternalExtensionAlert();
256}
257
[email protected]eaa7dd182010-12-14 11:09:00258ExtensionService::ExtensionService(Profile* profile,
avi3ef9ec9e2014-12-22 22:50:17259 const base::CommandLine* command_line,
[email protected]650b2d52013-02-10 03:41:45260 const base::FilePath& install_directory,
Devlin Cronineea1b7a2018-05-26 02:46:21261 ExtensionPrefs* extension_prefs,
262 Blacklist* blacklist,
[email protected]0436b102011-04-15 18:30:03263 bool autoupdate_enabled,
[email protected]4a10006a2013-05-17 23:18:35264 bool extensions_enabled,
Devlin Cronineea1b7a2018-05-26 02:46:21265 OneShotEvent* ready)
266 : Blacklist::Observer(blacklist),
catmullings98cd1942016-08-30 22:31:59267 command_line_(command_line),
[email protected]fdd679b2012-11-15 20:49:39268 profile_(profile),
Devlin Cronineea1b7a2018-05-26 02:46:21269 system_(ExtensionSystem::Get(profile)),
[email protected]73c47932010-12-06 18:13:43270 extension_prefs_(extension_prefs),
[email protected]695b5712012-12-06 23:55:28271 blacklist_(blacklist),
Devlin Cronineea1b7a2018-05-26 02:46:21272 registry_(ExtensionRegistry::Get(profile)),
[email protected]6c9bedf2014-05-21 03:55:51273 pending_extension_manager_(profile),
[email protected]a9b00ac2009-06-25 21:03:23274 install_directory_(install_directory),
[email protected]0436b102011-04-15 18:30:03275 extensions_enabled_(extensions_enabled),
[email protected]4a10006a2013-05-17 23:18:35276 ready_(ready),
Devlin Cronineea1b7a2018-05-26 02:46:21277 shared_module_service_(new SharedModuleService(profile_)),
278 app_data_migrator_(new AppDataMigrator(profile_, registry_)),
Sergey Poromov0360b9e72018-04-19 17:37:29279 extension_registrar_(profile_, this),
280 forced_extensions_tracker_(registry_, profile_->GetPrefs()) {
[email protected]a29a517a2011-01-21 21:11:12281 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
rkaplowdd66a1342015-03-05 00:31:49282 TRACE_EVENT0("browser,startup", "ExtensionService::ExtensionService::ctor");
[email protected]a8af9fdb2010-10-28 21:52:20283
[email protected]36a784c2009-06-23 06:21:08284 // Figure out if extension installation should be enabled.
Devlin Cronineea1b7a2018-05-26 02:46:21285 if (ExtensionsBrowserClient::Get()->AreExtensionsDisabled(*command_line,
286 profile))
[email protected]6d60703b2009-08-29 01:29:23287 extensions_enabled_ = false;
[email protected]36a784c2009-06-23 06:21:08288
[email protected]3c4abc82012-10-22 22:25:54289 registrar_.Add(this, chrome::NOTIFICATION_APP_TERMINATING,
290 content::NotificationService::AllBrowserContextsAndSources());
Devlin Cronineea1b7a2018-05-26 02:46:21291 registrar_.Add(this, NOTIFICATION_EXTENSION_PROCESS_TERMINATED,
[email protected]ad50def52011-10-19 23:17:07292 content::NotificationService::AllBrowserContextsAndSources());
[email protected]432115822011-07-10 15:52:27293 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_TERMINATED,
[email protected]ad50def52011-10-19 23:17:07294 content::NotificationService::AllBrowserContextsAndSources());
[email protected]ebe07772014-05-22 04:16:06295 registrar_.Add(this,
296 chrome::NOTIFICATION_PROFILE_DESTRUCTION_STARTED,
297 content::Source<Profile>(profile_));
binjin1569c9b2014-09-05 13:33:18298
weidongg04695232017-06-09 00:01:05299 UpgradeDetector::GetInstance()->AddObserver(this);
300
Devlin Cronineea1b7a2018-05-26 02:46:21301 ExtensionManagementFactory::GetForBrowserContext(profile_)->AddObserver(this);
[email protected]4814b512009-11-07 00:12:29302
rkaplowdd66a1342015-03-05 00:31:49303 // Set up the ExtensionUpdater.
[email protected]93fd78f42009-07-10 16:43:17304 if (autoupdate_enabled) {
Devlin Cronineea1b7a2018-05-26 02:46:21305 updater_.reset(new ExtensionUpdater(
David Bertonidccbd352018-03-20 00:31:04306 this, extension_prefs, profile->GetPrefs(), profile,
Devlin Cronineea1b7a2018-05-26 02:46:21307 kDefaultUpdateFrequencySeconds,
308 ExtensionsBrowserClient::Get()->GetExtensionCache(),
rockotdb5192992014-09-16 21:27:02309 base::Bind(ChromeExtensionDownloaderFactory::CreateForProfile,
310 profile)));
[email protected]93fd78f42009-07-10 16:43:17311 }
312
Devlin Cronineea1b7a2018-05-26 02:46:21313 component_loader_.reset(new ComponentLoader(
314 this, profile->GetPrefs(), g_browser_process->local_state(), profile));
[email protected]8e4560b62011-01-14 10:09:14315
[email protected]0436b102011-04-15 18:30:03316 if (extensions_enabled_) {
Devlin Cronineea1b7a2018-05-26 02:46:21317 ExternalProviderImpl::CreateExternalProviders(
[email protected]ae4c37e2012-12-21 01:16:25318 this, profile_, &external_extension_providers_);
[email protected]873531342011-03-09 12:16:05319 }
[email protected]b671760b2010-07-15 21:13:47320
[email protected]74474042013-11-21 12:03:54321 // Set this as the ExtensionService for app sorting to ensure it causes syncs
322 // if required.
[email protected]b3aa7182013-04-25 04:45:23323 is_first_run_ = !extension_prefs_->SetAlertSystemFirstRun();
324
[email protected]373daf972014-04-10 01:50:44325 error_controller_.reset(
Devlin Cronineea1b7a2018-05-26 02:46:21326 new ExtensionErrorController(profile_, is_first_run_));
[email protected]374ceb6f2014-07-02 19:25:34327 external_install_manager_.reset(
Devlin Cronineea1b7a2018-05-26 02:46:21328 new ExternalInstallManager(profile_, is_first_run_));
[email protected]373daf972014-04-10 01:50:44329
[email protected]c77f2352012-08-08 22:07:58330 extension_action_storage_manager_.reset(
Devlin Cronineea1b7a2018-05-26 02:46:21331 new ExtensionActionStorageManager(profile_));
[email protected]c77f2352012-08-08 22:07:58332
[email protected]cb0e50312011-05-09 15:03:07333 // How long is the path to the Extensions directory?
334 UMA_HISTOGRAM_CUSTOM_COUNTS("Extensions.ExtensionRootPathLength",
drbasicf0d1b262016-08-23 06:10:42335 install_directory_.value().length(), 1, 500, 100);
[email protected]6014d672008-12-05 00:38:25336}
337
Devlin Cronineea1b7a2018-05-26 02:46:21338PendingExtensionManager* ExtensionService::pending_extension_manager() {
[email protected]b2907fd2011-03-25 16:43:37339 return &pending_extension_manager_;
[email protected]ddb1e5a2010-12-13 20:10:45340}
341
[email protected]eaa7dd182010-12-14 11:09:00342ExtensionService::~ExtensionService() {
weidongg04695232017-06-09 00:01:05343 UpgradeDetector::GetInstance()->RemoveObserver(this);
[email protected]c8d407e2011-04-28 21:27:17344 // No need to unload extensions here because they are profile-scoped, and the
345 // profile is in the process of being deleted.
achuith2f5578b2016-02-26 21:57:13346 for (const auto& provider : external_extension_providers_)
[email protected]8e4560b62011-01-14 10:09:14347 provider->ServiceShutdown();
[email protected]6014d672008-12-05 00:38:25348}
349
[email protected]037228a2012-10-05 01:36:16350void ExtensionService::Shutdown() {
Devlin Cronineea1b7a2018-05-26 02:46:21351 ExtensionManagementFactory::GetInstance()
binjin1569c9b2014-09-05 13:33:18352 ->GetForBrowserContext(profile())
353 ->RemoveObserver(this);
[email protected]037228a2012-10-05 01:36:16354}
355
[email protected]b2907fd2011-03-25 16:43:37356const Extension* ExtensionService::GetExtensionById(
357 const std::string& id, bool include_disabled) const {
[email protected]599539802014-01-07 23:06:00358 int include_mask = ExtensionRegistry::ENABLED;
[email protected]695b5712012-12-06 23:55:28359 if (include_disabled) {
mlerman6a37b6a42014-11-26 22:10:53360 // Include blacklisted and blocked extensions here because there are
361 // hundreds of callers of this function, and many might assume that this
362 // includes those that have been disabled due to blacklisting or blocking.
[email protected]599539802014-01-07 23:06:00363 include_mask |= ExtensionRegistry::DISABLED |
mlerman6a37b6a42014-11-26 22:10:53364 ExtensionRegistry::BLACKLISTED | ExtensionRegistry::BLOCKED;
[email protected]695b5712012-12-06 23:55:28365 }
[email protected]599539802014-01-07 23:06:00366 return registry_->GetExtensionById(id, include_mask);
[email protected]695b5712012-12-06 23:55:28367}
368
[email protected]eaa7dd182010-12-14 11:09:00369void ExtensionService::Init() {
[email protected]a29a517a2011-01-21 21:11:12370 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
rkaplowe65c2ff2015-02-14 16:29:54371 TRACE_EVENT0("browser,startup", "ExtensionService::Init");
rkaplowa8fd8d32015-02-25 21:27:56372 SCOPED_UMA_HISTOGRAM_TIMER("Extensions.ExtensionServiceInitTime");
[email protected]3350d712013-11-18 09:32:24373
[email protected]4a10006a2013-05-17 23:18:35374 DCHECK(!is_ready()); // Can't redo init.
[email protected]bb1bc9b32013-12-21 03:09:14375 DCHECK_EQ(registry_->enabled_extensions().size(), 0u);
[email protected]9f1087e2009-06-15 17:29:32376
benwells22ab8ee2015-08-21 02:55:08377 component_loader_->LoadAll();
achuithd3da4f02017-03-23 20:05:29378 bool load_saved_extensions = true;
emaxx35e8b822017-04-11 02:04:29379 bool load_command_line_extensions = extensions_enabled_;
achuithd3da4f02017-03-23 20:05:29380#if defined(OS_CHROMEOS)
tbarzicd2a741e2017-06-28 20:37:54381 if (chromeos::ProfileHelper::IsSigninProfile(profile_) ||
382 chromeos::ProfileHelper::IsLockScreenAppProfile(profile_)) {
achuithd3da4f02017-03-23 20:05:29383 load_saved_extensions = false;
emaxx35e8b822017-04-11 02:04:29384 load_command_line_extensions = false;
385 }
achuithd3da4f02017-03-23 20:05:29386#endif
rdevlin.croninf2e1cb012017-05-27 01:27:59387 if (load_saved_extensions)
Devlin Cronineea1b7a2018-05-26 02:46:21388 InstalledLoader(this).LoadAllExtensions();
rdevlin.croninf2e1cb012017-05-27 01:27:59389
390 OnInstalledExtensionsLoaded();
391
Devlin Cronineea1b7a2018-05-26 02:46:21392 LoadExtensionsFromCommandLineFlag(::switches::kDisableExtensionsExcept);
emaxx35e8b822017-04-11 02:04:29393 if (load_command_line_extensions)
Devlin Cronineea1b7a2018-05-26 02:46:21394 LoadExtensionsFromCommandLineFlag(switches::kLoadExtension);
Tatsuhisa Yamaguchi5ed1aece32017-10-26 10:18:56395 EnableZipUnpackerExtension();
benwells22ab8ee2015-08-21 02:55:08396 EnabledReloadableExtensions();
397 MaybeFinishShutdownDelayed();
398 SetReadyAndNotifyListeners();
[email protected]ae4c37e2012-12-21 01:16:25399
Takumi Fujimoto43c8c00f2017-07-26 22:48:56400 UninstallMigratedExtensions();
401
benwells22ab8ee2015-08-21 02:55:08402 // TODO(erikkay): this should probably be deferred to a future point
403 // rather than running immediately at startup.
404 CheckForExternalUpdates();
[email protected]894bb502009-05-21 22:39:57405
benwells22ab8ee2015-08-21 02:55:08406 LoadGreylistFromPrefs();
rkaplowa8fd8d32015-02-25 21:27:56407}
[email protected]3350d712013-11-18 09:32:24408
Tatsuhisa Yamaguchi5ed1aece32017-10-26 10:18:56409void ExtensionService::EnableZipUnpackerExtensionForTest() {
410 EnableZipUnpackerExtension();
411}
412
413void ExtensionService::EnableZipUnpackerExtension() {
414 TRACE_EVENT0("browser,startup",
415 "ExtensionService::EnableZipUnpackerExtension");
416
417#if defined(OS_CHROMEOS)
418 // There were some cases where the Zip Unpacker was disabled in the profile,
419 // by some reason, and cannot re-enable it in any UI. crbug.com/643060
420 const std::string& id = extension_misc::kZIPUnpackerExtensionId;
421 const Extension* extension = registry_->disabled_extensions().GetByID(id);
Tatsuhisa Yamaguchi6f033fa2017-11-21 14:57:25422 if (extension && CanEnableExtension(extension)) {
Ilya Sherman982457e62017-12-13 02:19:36423 base::UmaHistogramSparse(
Tatsuhisa Yamaguchi6f033fa2017-11-21 14:57:25424 "ExtensionService.ZipUnpackerDisabledReason",
425 extension_prefs_->GetDisableReasons(extension->id()));
Tatsuhisa Yamaguchi5ed1aece32017-10-26 10:18:56426 EnableExtension(id);
Tatsuhisa Yamaguchi6f033fa2017-11-21 14:57:25427 }
Tatsuhisa Yamaguchi5ed1aece32017-10-26 10:18:56428#endif
429}
430
rkaplowa8fd8d32015-02-25 21:27:56431void ExtensionService::EnabledReloadableExtensions() {
432 TRACE_EVENT0("browser,startup",
433 "ExtensionService::EnabledReloadableExtensions");
434
435 std::vector<std::string> extensions_to_enable;
achuith2f5578b2016-02-26 21:57:13436 for (const auto& e : registry_->disabled_extensions()) {
rkaplowa8fd8d32015-02-25 21:27:56437 if (extension_prefs_->GetDisableReasons(e->id()) ==
Devlin Cronineea1b7a2018-05-26 02:46:21438 disable_reason::DISABLE_RELOAD)
rkaplowa8fd8d32015-02-25 21:27:56439 extensions_to_enable.push_back(e->id());
rkaplowa8fd8d32015-02-25 21:27:56440 }
441 for (const std::string& extension : extensions_to_enable) {
442 EnableExtension(extension);
443 }
444}
445
446void ExtensionService::MaybeFinishShutdownDelayed() {
447 TRACE_EVENT0("browser,startup",
448 "ExtensionService::MaybeFinishShutdownDelayed");
449
Devlin Cronineea1b7a2018-05-26 02:46:21450 std::unique_ptr<ExtensionPrefs::ExtensionsInfo> delayed_info(
rkaplowa8fd8d32015-02-25 21:27:56451 extension_prefs_->GetAllDelayedInstallInfo());
452 for (size_t i = 0; i < delayed_info->size(); ++i) {
453 ExtensionInfo* info = delayed_info->at(i).get();
achuith2f5578b2016-02-26 21:57:13454 scoped_refptr<const Extension> extension(nullptr);
rkaplowa8fd8d32015-02-25 21:27:56455 if (info->extension_manifest) {
456 std::string error;
457 extension = Extension::Create(
458 info->extension_path, info->extension_location,
459 *info->extension_manifest,
460 extension_prefs_->GetDelayedInstallCreationFlags(info->extension_id),
461 info->extension_id, &error);
462 if (extension.get())
463 delayed_installs_.Insert(extension);
464 }
465 }
466 MaybeFinishDelayedInstallations();
Devlin Cronineea1b7a2018-05-26 02:46:21467 std::unique_ptr<ExtensionPrefs::ExtensionsInfo> delayed_info2(
rkaplowa8fd8d32015-02-25 21:27:56468 extension_prefs_->GetAllDelayedInstallInfo());
469 UMA_HISTOGRAM_COUNTS_100("Extensions.UpdateOnLoad",
470 delayed_info2->size() - delayed_info->size());
[email protected]6014d672008-12-05 00:38:25471}
472
[email protected]2d19eb6e2014-01-27 17:30:00473void ExtensionService::LoadGreylistFromPrefs() {
rkaplowa8fd8d32015-02-25 21:27:56474 TRACE_EVENT0("browser,startup", "ExtensionService::LoadGreylistFromPrefs");
475
dchengc963c7142016-04-08 03:55:22476 std::unique_ptr<ExtensionSet> all_extensions =
[email protected]f47f7172014-03-19 19:27:10477 registry_->GenerateInstalledExtensionsSet();
[email protected]2d19eb6e2014-01-27 17:30:00478
achuith2f5578b2016-02-26 21:57:13479 for (const auto& extension : *all_extensions) {
Devlin Cronineea1b7a2018-05-26 02:46:21480 const BlacklistState state =
achuith2f5578b2016-02-26 21:57:13481 extension_prefs_->GetExtensionBlacklistState(extension->id());
Devlin Cronineea1b7a2018-05-26 02:46:21482 if (state == BLACKLISTED_SECURITY_VULNERABILITY ||
483 state == BLACKLISTED_POTENTIALLY_UNWANTED ||
484 state == BLACKLISTED_CWS_POLICY_VIOLATION)
achuith2f5578b2016-02-26 21:57:13485 greylist_.Insert(extension);
[email protected]2d19eb6e2014-01-27 17:30:00486 }
487}
488
Devlin Cronineea1b7a2018-05-26 02:46:21489bool ExtensionService::UpdateExtension(const CRXFileInfo& file,
[email protected]044e86992014-01-24 22:59:11490 bool file_ownership_passed,
[email protected]31bb5ee62012-09-12 22:58:40491 CrxInstaller** out_crx_installer) {
[email protected]a29a517a2011-01-21 21:11:12492 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]3c4abc82012-10-22 22:25:54493 if (browser_terminating_) {
494 LOG(WARNING) << "Skipping UpdateExtension due to browser shutdown";
495 // Leak the temp file at extension_path. We don't want to add to the disk
496 // I/O burden at shutdown, we can't rely on the I/O completing anyway, and
497 // the file is in the OS temp directory which should be cleaned up for us.
498 return false;
499 }
[email protected]a8af9fdb2010-10-28 21:52:20500
ginkage553af3202015-02-04 12:39:09501 const std::string& id = file.extension_id;
502
Devlin Cronineea1b7a2018-05-26 02:46:21503 const PendingExtensionInfo* pending_extension_info =
[email protected]51a3bf8b2012-06-08 22:53:06504 pending_extension_manager()->GetById(id);
[email protected]8ef78fd2010-08-19 17:14:32505
[email protected]695b5712012-12-06 23:55:28506 const Extension* extension = GetInstalledExtension(id);
[email protected]51a3bf8b2012-06-08 22:53:06507 if (!pending_extension_info && !extension) {
[email protected]aa142702010-03-26 01:26:33508 LOG(WARNING) << "Will not update extension " << id
509 << " because it is not installed or pending";
510 // Delete extension_path since we're not creating a CrxInstaller
511 // that would do it for us.
asargentd50b18c2016-04-21 01:17:16512 if (file_ownership_passed &&
Devlin Cronineea1b7a2018-05-26 02:46:21513 !GetExtensionFileTaskRunner()->PostTask(
514 FROM_HERE,
515 base::BindOnce(&file_util::DeleteFile, file.path, false)))
[email protected]14908b72011-04-20 06:54:36516 NOTREACHED();
[email protected]420a0ec2011-06-01 01:07:03517
518 return false;
[email protected]e957fe52009-06-23 16:51:05519 }
Minh X. Nguyen30975342017-12-04 22:02:41520 // Either |pending_extension_info| or |extension| or both must not be null.
treibe960e282015-09-11 10:38:08521 scoped_refptr<CrxInstaller> installer(CrxInstaller::CreateSilent(this));
[email protected]6dfbbf82010-03-12 23:09:16522 installer->set_expected_id(id);
ginkage47e603e2015-02-27 08:42:41523 installer->set_expected_hash(file.expected_hash);
[email protected]464213a2013-10-15 01:06:48524 int creation_flags = Extension::NO_FLAGS;
[email protected]51a3bf8b2012-06-08 22:53:06525 if (pending_extension_info) {
526 installer->set_install_source(pending_extension_info->install_source());
pkotwicz31eb1e8ec2014-10-08 15:26:46527 installer->set_allow_silent_install(true);
treibe960e282015-09-11 10:38:08528 // If the extension came in disabled due to a permission increase, then
529 // don't grant it all the permissions. crbug.com/484214
530 bool has_permissions_increase =
Devlin Cronineea1b7a2018-05-26 02:46:21531 ExtensionPrefs::Get(profile_)->HasDisableReason(
532 id, disable_reason::DISABLE_PERMISSIONS_INCREASE);
treibe960e282015-09-11 10:38:08533 const base::Version& expected_version = pending_extension_info->version();
534 if (has_permissions_increase ||
535 pending_extension_info->remote_install() ||
536 !expected_version.IsValid()) {
[email protected]21db9ef2014-05-16 02:06:27537 installer->set_grant_permissions(false);
treibe960e282015-09-11 10:38:08538 } else {
539 installer->set_expected_version(expected_version,
540 false /* fail_install_if_unexpected */);
541 }
mamir0128d5a2016-07-15 20:55:48542 creation_flags = pending_extension_info->creation_flags();
[email protected]464213a2013-10-15 01:06:48543 if (pending_extension_info->mark_acknowledged())
[email protected]374ceb6f2014-07-02 19:25:34544 external_install_manager_->AcknowledgeExternalExtension(id);
Minh X. Nguyen30975342017-12-04 22:02:41545 // If the extension was installed from or has migrated to the webstore, or
546 // its auto-update URL is from the webstore, treat it as a webstore install.
547 // Note that we ignore some older extensions with blank auto-update URLs
548 // because we are mostly concerned with restrictions on NaCl extensions,
549 // which are newer.
550 if (!extension && extension_urls::IsWebstoreUpdateUrl(
551 pending_extension_info->update_url()))
552 creation_flags |= Extension::FROM_WEBSTORE;
553 } else {
554 // |extension| must not be null.
[email protected]5eb375e92010-11-26 07:50:41555 installer->set_install_source(extension->location());
[email protected]51a3bf8b2012-06-08 22:53:06556 }
[email protected]a12ce8b22012-01-17 18:40:53557
Minh X. Nguyen30975342017-12-04 22:02:41558 if (extension) {
559 installer->InitializeCreationFlagsForUpdate(extension, creation_flags);
[email protected]c30bda262014-06-19 04:10:13560 installer->set_do_not_sync(extension_prefs_->DoNotSync(id));
Minh X. Nguyen30975342017-12-04 22:02:41561 } else {
562 installer->set_creation_flags(creation_flags);
563 }
[email protected]044e86992014-01-24 22:59:11564 installer->set_delete_source(file_ownership_passed);
[email protected]cb0e50312011-05-09 15:03:07565 installer->set_install_cause(extension_misc::INSTALL_CAUSE_UPDATE);
ginkage553af3202015-02-04 12:39:09566 installer->InstallCrxFile(file);
[email protected]420a0ec2011-06-01 01:07:03567
568 if (out_crx_installer)
[email protected]dc24976f2013-06-02 21:15:09569 *out_crx_installer = installer.get();
[email protected]420a0ec2011-06-01 01:07:03570
571 return true;
[email protected]e957fe52009-06-23 16:51:05572}
573
catmullings98cd1942016-08-30 22:31:59574void ExtensionService::LoadExtensionsFromCommandLineFlag(
575 const char* switch_name) {
576 if (command_line_->HasSwitch(switch_name)) {
577 base::CommandLine::StringType path_list =
578 command_line_->GetSwitchValueNative(switch_name);
579 base::StringTokenizerT<base::CommandLine::StringType,
580 base::CommandLine::StringType::const_iterator>
581 t(path_list, FILE_PATH_LITERAL(","));
582 while (t.GetNext()) {
583 std::string extension_id;
Devlin Cronineea1b7a2018-05-26 02:46:21584 UnpackedInstaller::Create(this)->LoadFromCommandLine(
catmullings98cd1942016-08-30 22:31:59585 base::FilePath(t.token()), &extension_id, false /*only-allow-apps*/);
586 // Extension id is added to whitelist after its extension is loaded
michaelpga8ea0372017-04-06 20:41:35587 // because code is executed asynchronously. TODO(michaelpg): Remove this
588 // assumption so loading extensions does not have to be asynchronous:
589 // crbug.com/708354.
Devlin Cronineea1b7a2018-05-26 02:46:21590 if (switch_name == ::switches::kDisableExtensionsExcept)
catmullings98cd1942016-08-30 22:31:59591 disable_flag_exempted_extensions_.insert(extension_id);
592 }
593 }
594}
595
Michael Giuffrida573992d2018-02-08 00:48:44596// TODO(michaelpg): Group with other ExtensionRegistrar::Delegate overrides
597// according to header file once diffs have settled down.
598void ExtensionService::LoadExtensionForReload(
Devlin Cronineea1b7a2018-05-26 02:46:21599 const ExtensionId& extension_id,
Michael Giuffrida573992d2018-02-08 00:48:44600 const base::FilePath& path,
601 LoadErrorBehavior load_error_behavior) {
Toni Barzic667db0d32018-01-09 18:00:19602 if (delayed_installs_.Contains(extension_id) &&
603 FinishDelayedInstallationIfReady(extension_id,
604 true /*install_immediately*/)) {
[email protected]0db124b02012-11-07 04:55:05605 return;
606 }
607
[email protected]43ceb002012-02-10 23:19:15608 // If we're reloading a component extension, use the component extension
609 // loader's reloader.
610 if (component_loader_->Exists(extension_id)) {
611 component_loader_->Reload(extension_id);
612 return;
613 }
614
[email protected]e6090e42010-03-23 22:44:08615 // Check the installed extensions to see if what we're reloading was already
616 // installed.
dchengc963c7142016-04-08 03:55:22617 std::unique_ptr<ExtensionInfo> installed_extension(
[email protected]e6090e42010-03-23 22:44:08618 extension_prefs_->GetInstalledExtensionInfo(extension_id));
619 if (installed_extension.get() &&
620 installed_extension->extension_manifest.get()) {
Devlin Cronineea1b7a2018-05-26 02:46:21621 InstalledLoader(this).Load(*installed_extension, false);
[email protected]e6090e42010-03-23 22:44:08622 } else {
Michael Giuffrida573992d2018-02-08 00:48:44623 // Otherwise, the extension is unpacked (location LOAD). We must load it
624 // from the path.
625 CHECK(!path.empty()) << "ExtensionRegistrar should never ask to load an "
626 "unknown extension with no path";
Devlin Cronineea1b7a2018-05-26 02:46:21627 scoped_refptr<UnpackedInstaller> unpacked_installer =
628 UnpackedInstaller::Create(this);
Michael Giuffrida573992d2018-02-08 00:48:44629 unpacked_installer->set_be_noisy_on_failure(load_error_behavior ==
630 LoadErrorBehavior::kNoisy);
[email protected]bca4b832014-07-17 20:22:34631 unpacked_installer->Load(path);
[email protected]e6090e42010-03-23 22:44:08632 }
[email protected]9cddd4702009-07-27 22:09:40633}
634
[email protected]bca4b832014-07-17 20:22:34635void ExtensionService::ReloadExtension(const std::string& extension_id) {
Michael Giuffrida573992d2018-02-08 00:48:44636 extension_registrar_.ReloadExtension(extension_id, LoadErrorBehavior::kNoisy);
[email protected]bca4b832014-07-17 20:22:34637}
638
639void ExtensionService::ReloadExtensionWithQuietFailure(
640 const std::string& extension_id) {
Michael Giuffrida573992d2018-02-08 00:48:44641 extension_registrar_.ReloadExtension(extension_id, LoadErrorBehavior::kQuiet);
[email protected]bca4b832014-07-17 20:22:34642}
643
[email protected]757d60a2014-05-23 00:11:44644bool ExtensionService::UninstallExtension(
645 // "transient" because the process of uninstalling may cause the reference
646 // to become invalid. Instead, use |extenson->id()|.
647 const std::string& transient_extension_id,
Devlin Cronineea1b7a2018-05-26 02:46:21648 UninstallReason reason,
[email protected]757d60a2014-05-23 00:11:44649 base::string16* error) {
[email protected]a29a517a2011-01-21 21:11:12650 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]a8af9fdb2010-10-28 21:52:20651
[email protected]757d60a2014-05-23 00:11:44652 scoped_refptr<const Extension> extension =
653 GetInstalledExtension(transient_extension_id);
[email protected]631cf822009-05-15 07:01:25654
[email protected]e7afe2452010-08-22 16:19:13655 // Callers should not send us nonexistent extensions.
[email protected]dc24976f2013-06-02 21:15:09656 CHECK(extension.get());
[email protected]9f1087e2009-06-15 17:29:32657
binjincccacef2014-10-13 19:00:20658 ManagementPolicy* by_policy = system_->management_policy();
[email protected]95da88c42011-03-31 10:07:33659 // Policy change which triggers an uninstall will always set
660 // |external_uninstall| to true so this is the only way to uninstall
661 // managed extensions.
[email protected]90878c52014-04-04 18:21:02662 // Shared modules being uninstalled will also set |external_uninstall| to true
663 // so that we can guarantee users don't uninstall a shared module.
664 // (crbug.com/273300)
665 // TODO(rdevlin.cronin): This is probably not right. We should do something
666 // else, like include an enum IS_INTERNAL_UNINSTALL or IS_USER_UNINSTALL so
667 // we don't do this.
[email protected]cc2f55c2014-07-08 02:19:04668 bool external_uninstall =
Devlin Cronineea1b7a2018-05-26 02:46:21669 (reason == UNINSTALL_REASON_INTERNAL_MANAGEMENT) ||
670 (reason == UNINSTALL_REASON_COMPONENT_REMOVED) ||
671 (reason == UNINSTALL_REASON_REINSTALL) ||
672 (reason == UNINSTALL_REASON_ORPHANED_EXTERNAL_EXTENSION) ||
673 (reason == UNINSTALL_REASON_ORPHANED_SHARED_MODULE) ||
674 (reason == UNINSTALL_REASON_SYNC &&
675 util::WasInstalledByCustodian(extension->id(), profile_));
[email protected]65187152012-06-02 13:14:14676 if (!external_uninstall &&
binjincccacef2014-10-13 19:00:20677 (!by_policy->UserMayModifySettings(extension.get(), error) ||
678 by_policy->MustRemainInstalled(extension.get(), error))) {
[email protected]ad50def52011-10-19 23:17:07679 content::NotificationService::current()->Notify(
Devlin Cronineea1b7a2018-05-26 02:46:21680 NOTIFICATION_EXTENSION_UNINSTALL_NOT_ALLOWED,
[email protected]6c2381d2011-10-19 02:52:53681 content::Source<Profile>(profile_),
[email protected]dc24976f2013-06-02 21:15:09682 content::Details<const Extension>(extension.get()));
[email protected]d6ebc9792011-04-07 18:18:33683 return false;
684 }
[email protected]95da88c42011-03-31 10:07:33685
juncai33e462102015-05-18 20:48:44686 InstallVerifier::Get(GetBrowserContext())->Remove(extension->id());
[email protected]ffd2f79e2013-11-14 00:11:46687
[email protected]9b217652010-10-08 22:04:23688 UMA_HISTOGRAM_ENUMERATION("Extensions.UninstallType",
[email protected]7fa19f82010-12-21 19:40:08689 extension->GetType(), 100);
treib2e0517f92015-05-07 23:15:36690 RecordPermissionMessagesHistogram(extension.get(), "Uninstall");
[email protected]9b217652010-10-08 22:04:23691
[email protected]831aa212010-03-26 13:55:19692 // Unload before doing more cleanup to ensure that nothing is hanging on to
693 // any of these resources.
limasdf0deef2042017-05-03 19:17:17694 UnloadExtension(extension->id(), UnloadedExtensionReason::UNINSTALL);
asargent96c7ec42016-05-27 02:45:47695 if (registry_->blacklisted_extensions().Contains(extension->id()))
696 registry_->RemoveBlacklisted(extension->id());
[email protected]831aa212010-03-26 13:55:19697
[email protected]9f1087e2009-06-15 17:29:32698 // Tell the backend to start deleting installed extensions on the file thread.
[email protected]12075d12013-02-27 05:38:05699 if (!Manifest::IsUnpackedLocation(extension->location())) {
Devlin Cronineea1b7a2018-05-26 02:46:21700 if (!GetExtensionFileTaskRunner()->PostTask(
[email protected]7f8f24f2012-11-15 19:40:14701 FROM_HERE,
tzik8d880ee2017-04-20 19:46:24702 base::BindOnce(&ExtensionService::UninstallExtensionOnFileThread,
703 extension->id(), profile_, install_directory_,
704 extension->path())))
[email protected]14908b72011-04-20 06:54:36705 NOTREACHED();
[email protected]9f1087e2009-06-15 17:29:32706 }
707
Devlin Cronineea1b7a2018-05-26 02:46:21708 DataDeleter::StartDeleting(profile_, extension.get());
[email protected]0d6ec3a72011-09-02 02:09:43709
Michael Giuffridafcb420362017-10-11 21:50:26710 extension_registrar_.UntrackTerminatedExtension(extension->id());
[email protected]211030342010-09-30 18:41:06711
712 // Notify interested parties that we've uninstalled this extension.
[email protected]e43c61f2014-07-20 21:46:34713 ExtensionRegistry::Get(profile_)
714 ->TriggerOnUninstalled(extension.get(), reason);
[email protected]d6ebc9792011-04-07 18:18:33715
[email protected]757d60a2014-05-23 00:11:44716 delayed_installs_.Remove(extension->id());
[email protected]0db124b02012-11-07 04:55:05717
[email protected]757d60a2014-05-23 00:11:44718 extension_prefs_->OnExtensionUninstalled(
719 extension->id(), extension->location(), external_uninstall);
[email protected]d4eda592013-09-18 03:37:57720
[email protected]333b1de2011-09-12 18:28:50721 // Track the uninstallation.
[email protected]49098f702011-10-13 03:47:18722 UMA_HISTOGRAM_ENUMERATION("Extensions.ExtensionUninstalled", 1, 2);
723
[email protected]d6ebc9792011-04-07 18:18:33724 return true;
[email protected]c10da4b02010-03-25 14:38:32725}
726
[email protected]5a145e82014-05-29 22:19:07727// static
728void ExtensionService::UninstallExtensionOnFileThread(
729 const std::string& id,
730 Profile* profile,
731 const base::FilePath& install_dir,
732 const base::FilePath& extension_path) {
Devlin Cronineea1b7a2018-05-26 02:46:21733 ExtensionAssetsManager* assets_manager =
734 ExtensionAssetsManager::GetInstance();
[email protected]5a145e82014-05-29 22:19:07735 assets_manager->UninstallExtension(id, profile, install_dir, extension_path);
736}
737
[email protected]c3cfb012011-04-06 22:07:35738bool ExtensionService::IsExtensionEnabled(
739 const std::string& extension_id) const {
Michael Giuffrida6397c592017-10-09 20:46:53740 return extension_registrar_.IsExtensionEnabled(extension_id);
[email protected]c3cfb012011-04-06 22:07:35741}
742
[email protected]eaa7dd182010-12-14 11:09:00743void ExtensionService::EnableExtension(const std::string& extension_id) {
[email protected]a29a517a2011-01-21 21:11:12744 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
Michael Giuffrida6397c592017-10-09 20:46:53745 extension_registrar_.EnableExtension(extension_id);
[email protected]0c6da502009-08-14 22:32:39746}
747
treibc1192322015-05-20 12:56:07748void ExtensionService::DisableExtension(const std::string& extension_id,
749 int disable_reasons) {
[email protected]a29a517a2011-01-21 21:11:12750 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
Michael Giuffrida6397c592017-10-09 20:46:53751 extension_registrar_.DisableExtension(extension_id, disable_reasons);
[email protected]1784e83a2009-09-08 21:01:52752}
753
Ivan Sandrk4a55dc22018-05-17 18:14:48754void ExtensionService::DisableExtensionWithSource(
755 const Extension* source_extension,
756 const std::string& extension_id,
Devlin Cronineea1b7a2018-05-26 02:46:21757 disable_reason::DisableReason disable_reasons) {
Ivan Sandrk4a55dc22018-05-17 18:14:48758 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
759
Devlin Cronineea1b7a2018-05-26 02:46:21760 DCHECK(disable_reasons == disable_reason::DISABLE_USER_ACTION ||
761 disable_reasons == disable_reason::DISABLE_BLOCKED_BY_POLICY);
762 if (disable_reasons == disable_reason::DISABLE_BLOCKED_BY_POLICY) {
Ivan Sandrk4a55dc22018-05-17 18:14:48763 DCHECK(Manifest::IsPolicyLocation(source_extension->location()) ||
764 Manifest::IsComponentLocation(source_extension->location()));
765 }
766
767 const Extension* extension = GetExtensionById(extension_id, true);
768 CHECK(system_->management_policy()->ExtensionMayModifySettings(
769 source_extension, extension, nullptr));
770 extension_registrar_.DisableExtension(extension_id, disable_reasons);
771}
772
mtomasz294bb3e2017-01-24 02:17:52773void ExtensionService::DisableUserExtensionsExcept(
[email protected]1abf05e2013-07-09 17:04:36774 const std::vector<std::string>& except_ids) {
Devlin Cronineea1b7a2018-05-26 02:46:21775 ManagementPolicy* management_policy = system_->management_policy();
776 ExtensionList to_disable;
[email protected]e516e4c2013-06-12 17:41:14777
achuith2f5578b2016-02-26 21:57:13778 for (const auto& extension : registry_->enabled_extensions()) {
779 if (management_policy->UserMayModifySettings(extension.get(), nullptr))
780 to_disable.push_back(extension);
[email protected]e516e4c2013-06-12 17:41:14781 }
782
achuith2f5578b2016-02-26 21:57:13783 for (const auto& extension : registry_->terminated_extensions()) {
784 if (management_policy->UserMayModifySettings(extension.get(), nullptr))
785 to_disable.push_back(extension);
786 }
787
788 for (const auto& extension : to_disable) {
789 if (extension->was_installed_by_default() &&
[email protected]3082fe32013-08-06 11:12:38790 extension_urls::IsWebstoreUpdateUrl(
Devlin Cronineea1b7a2018-05-26 02:46:21791 ManifestURL::GetUpdateURL(extension.get())))
[email protected]3082fe32013-08-06 11:12:38792 continue;
achuith2f5578b2016-02-26 21:57:13793 const std::string& id = extension->id();
tripta.g0ac673a2017-07-07 05:45:09794 if (!base::ContainsValue(except_ids, id))
Devlin Cronineea1b7a2018-05-26 02:46:21795 DisableExtension(id, disable_reason::DISABLE_USER_ACTION);
[email protected]e516e4c2013-06-12 17:41:14796 }
797}
798
mlerman6a37b6a42014-11-26 22:10:53799// Extensions that are not locked, components or forced by policy should be
800// locked. Extensions are no longer considered enabled or disabled. Blacklisted
801// extensions are now considered both blacklisted and locked.
802void ExtensionService::BlockAllExtensions() {
803 if (block_extensions_)
804 return;
805 block_extensions_ = true;
806
807 // Blacklisted extensions are already unloaded, need not be blocked.
dchengc963c7142016-04-08 03:55:22808 std::unique_ptr<ExtensionSet> extensions =
mlerman6a37b6a42014-11-26 22:10:53809 registry_->GenerateInstalledExtensionsSet(ExtensionRegistry::ENABLED |
810 ExtensionRegistry::DISABLED |
811 ExtensionRegistry::TERMINATED);
812
achuith2f5578b2016-02-26 21:57:13813 for (const auto& extension : *extensions) {
mlerman6a37b6a42014-11-26 22:10:53814 const std::string& id = extension->id();
815
816 if (!CanBlockExtension(extension.get()))
817 continue;
818
819 registry_->RemoveEnabled(id);
820 registry_->RemoveDisabled(id);
821 registry_->RemoveTerminated(id);
822
823 registry_->AddBlocked(extension.get());
Devlin Cronineea1b7a2018-05-26 02:46:21824 UnloadExtension(id, UnloadedExtensionReason::LOCK_ALL);
mlerman6a37b6a42014-11-26 22:10:53825 }
826}
827
828// All locked extensions should revert to being either enabled or disabled
829// as appropriate.
830void ExtensionService::UnblockAllExtensions() {
831 block_extensions_ = false;
dchengc963c7142016-04-08 03:55:22832 std::unique_ptr<ExtensionSet> to_unblock =
mlerman6a37b6a42014-11-26 22:10:53833 registry_->GenerateInstalledExtensionsSet(ExtensionRegistry::BLOCKED);
834
achuith2f5578b2016-02-26 21:57:13835 for (const auto& extension : *to_unblock) {
mlerman6a37b6a42014-11-26 22:10:53836 registry_->RemoveBlocked(extension->id());
837 AddExtension(extension.get());
838 }
Owen Minb71016d2018-01-11 01:51:49839 // While extensions are blocked, we won't display any external install
840 // warnings. Now that they are unblocked, we should update the error.
841 external_install_manager_->UpdateExternalExtensionAlert();
mlerman6a37b6a42014-11-26 22:10:53842}
843
[email protected]eaa7dd182010-12-14 11:09:00844void ExtensionService::GrantPermissionsAndEnableExtension(
[email protected]009633c2013-03-07 22:08:28845 const Extension* extension) {
846 GrantPermissions(extension);
treib2e0517f92015-05-07 23:15:36847 RecordPermissionMessagesHistogram(extension, "ReEnable");
[email protected]8d888c12010-11-30 00:00:25848 EnableExtension(extension->id());
849}
850
[email protected]009633c2013-03-07 22:08:28851void ExtensionService::GrantPermissions(const Extension* extension) {
[email protected]be083862012-09-01 03:53:45852 CHECK(extension);
Devlin Cronineea1b7a2018-05-26 02:46:21853 PermissionsUpdater(profile()).GrantActivePermissions(extension);
[email protected]be083862012-09-01 03:53:45854}
855
[email protected]fe2dd7742011-04-19 22:52:49856// static
857void ExtensionService::RecordPermissionMessagesHistogram(
[email protected]13c68b62013-05-17 11:29:05858 const Extension* extension, const char* histogram) {
[email protected]de415552013-01-23 04:12:17859 // Since this is called from multiple sources, and since the histogram macros
860 // use statics, we need to manually lookup the histogram ourselves.
treib2e0517f92015-05-07 23:15:36861 base::HistogramBase* counter = base::LinearHistogram::FactoryGet(
862 base::StringPrintf("Extensions.Permissions_%s3", histogram),
863 1,
864 APIPermission::kEnumBoundary,
865 APIPermission::kEnumBoundary + 1,
866 base::HistogramBase::kUmaTargetedHistogramFlag);
867
868 base::HistogramBase* counter_has_any = base::BooleanHistogram::FactoryGet(
869 base::StringPrintf("Extensions.HasPermissions_%s3", histogram),
870 base::HistogramBase::kUmaTargetedHistogramFlag);
871
872 PermissionIDSet permissions =
Devlin Cronineea1b7a2018-05-26 02:46:21873 PermissionMessageProvider::Get()->GetAllPermissionIDs(
rdevlin.cronine2d0fd02015-09-24 22:35:49874 extension->permissions_data()->active_permissions(),
treib2e0517f92015-05-07 23:15:36875 extension->GetType());
876 counter_has_any->AddBoolean(!permissions.empty());
877 for (const PermissionID& id : permissions)
878 counter->Add(id.id());
[email protected]fe2dd7742011-04-19 22:52:49879}
880
Michael Giuffrida6397c592017-10-09 20:46:53881// TODO(michaelpg): Group with other ExtensionRegistrar::Delegate overrides
882// according to header file once diffs have settled down.
883void ExtensionService::PostActivateExtension(
Michael Giuffrida19a55982018-02-10 03:03:26884 scoped_refptr<const Extension> extension) {
[email protected]dcc47642014-03-26 22:03:49885 // TODO(kalman): Convert ExtensionSpecialStoragePolicy to a
886 // BrowserContextKeyedService and use ExtensionRegistryObserver.
Michael Giuffrida6397c592017-10-09 20:46:53887 profile_->GetExtensionSpecialStoragePolicy()->GrantRightsForExtension(
888 extension.get(), profile_);
[email protected]c8d407e2011-04-28 21:27:17889
[email protected]dcc47642014-03-26 22:03:49890 // TODO(kalman): This is broken. The crash reporter is process-wide so doesn't
891 // work properly multi-profile. Besides which, it should be using
892 // ExtensionRegistryObserver. See http://crbug.com/355029.
[email protected]c8d407e2011-04-28 21:27:17893 UpdateActiveExtensionsInCrashReporter();
894
Devlin Cronineea1b7a2018-05-26 02:46:21895 const PermissionsData* permissions_data = extension->permissions_data();
[email protected]d695bb12014-06-05 16:16:30896
[email protected]c8d407e2011-04-28 21:27:17897 // If the extension has permission to load chrome://favicon/ resources we need
898 // to make sure that the FaviconSource is registered with the
899 // ChromeURLDataManager.
[email protected]d695bb12014-06-05 16:16:30900 if (permissions_data->HasHostPermission(GURL(chrome::kChromeUIFaviconURL))) {
pkotwiczd95aa6592017-05-11 02:26:21901 FaviconSource* favicon_source = new FaviconSource(profile_);
[email protected]24ea7a12013-01-27 23:54:53902 content::URLDataSource::Add(profile_, favicon_source);
[email protected]c8d407e2011-04-28 21:27:17903 }
[email protected]b07e606e2012-09-15 20:16:15904
[email protected]b07e606e2012-09-15 20:16:15905 // Same for chrome://theme/ resources.
[email protected]d695bb12014-06-05 16:16:30906 if (permissions_data->HasHostPermission(GURL(chrome::kChromeUIThemeURL))) {
[email protected]b07e606e2012-09-15 20:16:15907 ThemeSource* theme_source = new ThemeSource(profile_);
[email protected]24ea7a12013-01-27 23:54:53908 content::URLDataSource::Add(profile_, theme_source);
[email protected]b07e606e2012-09-15 20:16:15909 }
[email protected]b07e606e2012-09-15 20:16:15910
[email protected]5eddc3e2011-10-26 04:33:31911 // Same for chrome://thumb/ resources.
[email protected]d695bb12014-06-05 16:16:30912 if (permissions_data->HasHostPermission(
913 GURL(chrome::kChromeUIThumbnailURL))) {
[email protected]420e6d92013-09-17 01:48:51914 ThumbnailSource* thumbnail_source = new ThumbnailSource(profile_, false);
[email protected]24ea7a12013-01-27 23:54:53915 content::URLDataSource::Add(profile_, thumbnail_source);
[email protected]5eddc3e2011-10-26 04:33:31916 }
[email protected]62d30f42009-10-01 22:36:06917}
918
Michael Giuffrida6397c592017-10-09 20:46:53919// TODO(michaelpg): Group with other ExtensionRegistrar::Delegate overrides
920// according to header file once diffs have settled down.
Michael Giuffrida023e3532017-09-28 23:21:21921void ExtensionService::PostDeactivateExtension(
922 scoped_refptr<const Extension> extension) {
[email protected]dcc47642014-03-26 22:03:49923 // TODO(kalman): Convert ExtensionSpecialStoragePolicy to a
924 // BrowserContextKeyedService and use ExtensionRegistryObserver.
Michael Giuffrida023e3532017-09-28 23:21:21925 profile_->GetExtensionSpecialStoragePolicy()->RevokeRightsForExtension(
926 extension.get());
[email protected]c8d407e2011-04-28 21:27:17927
[email protected]b777b332011-04-16 04:01:08928#if defined(OS_CHROMEOS)
[email protected]ac66e452013-01-11 09:21:23929 // Revoke external file access for the extension from its file system context.
930 // It is safe to access the extension's storage partition at this point. The
931 // storage partition may get destroyed only after the extension gets unloaded.
Devlin Cronineea1b7a2018-05-26 02:46:21932 GURL site = util::GetSiteForExtensionId(extension->id(), profile_);
[email protected]cd501a72014-08-22 19:58:31933 storage::FileSystemContext* filesystem_context =
934 BrowserContext::GetStoragePartitionForSite(profile_, site)
935 ->GetFileSystemContext();
[email protected]f19bbf62013-07-09 01:22:32936 if (filesystem_context && filesystem_context->external_backend()) {
Michael Giuffrida6397c592017-10-09 20:46:53937 filesystem_context->external_backend()->RevokeAccessForExtension(
938 extension->id());
[email protected]62d30f42009-10-01 22:36:06939 }
[email protected]c8d407e2011-04-28 21:27:17940#endif
941
[email protected]dcc47642014-03-26 22:03:49942 // TODO(kalman): This is broken. The crash reporter is process-wide so doesn't
943 // work properly multi-profile. Besides which, it should be using
944 // ExtensionRegistryObserver::OnExtensionLoaded. See http://crbug.com/355029.
[email protected]c8d407e2011-04-28 21:27:17945 UpdateActiveExtensionsInCrashReporter();
[email protected]62d30f42009-10-01 22:36:06946}
947
[email protected]599539802014-01-07 23:06:00948content::BrowserContext* ExtensionService::GetBrowserContext() const {
949 // Implemented in the .cc file to avoid adding a profile.h dependency to
950 // extension_service.h.
951 return profile_;
952}
953
[email protected]25ae0152011-11-18 14:40:02954bool ExtensionService::is_ready() {
[email protected]4a10006a2013-05-17 23:18:35955 return ready_->is_signaled();
[email protected]25ae0152011-11-18 14:40:02956}
957
[email protected]4ee07c62012-08-21 12:40:42958void ExtensionService::CheckManagementPolicy() {
Devlin Cronineea1b7a2018-05-26 02:46:21959 std::map<std::string, disable_reason::DisableReason> to_disable;
binjin8e3d0182014-12-04 16:44:28960 std::vector<std::string> to_enable;
[email protected]695b5712012-12-06 23:55:28961
Karan Bhatia2a117232017-08-23 00:24:56962 // Loop through the extensions list, finding extensions we need to disable.
achuith2f5578b2016-02-26 21:57:13963 for (const auto& extension : registry_->enabled_extensions()) {
Devlin Cronineea1b7a2018-05-26 02:46:21964 disable_reason::DisableReason disable_reason = disable_reason::DISABLE_NONE;
[email protected]0d54b682013-11-05 14:15:36965 if (system_->management_policy()->MustRemainDisabled(
binjin8e3d0182014-12-04 16:44:28966 extension.get(), &disable_reason, nullptr))
[email protected]0d54b682013-11-05 14:15:36967 to_disable[extension->id()] = disable_reason;
[email protected]aa96d3a2010-08-21 08:45:25968 }
969
Devlin Cronineea1b7a2018-05-26 02:46:21970 ExtensionManagement* management =
971 ExtensionManagementFactory::GetForBrowserContext(profile());
972 PermissionsUpdater(profile()).SetDefaultPolicyHostRestrictions(
Devlin Cronin7e0f41ff2018-05-16 17:19:36973 management->GetDefaultPolicyBlockedHosts(),
974 management->GetDefaultPolicyAllowedHosts());
nrpetere33d2a5b2017-04-25 00:12:31975 for (const auto& extension : registry_->enabled_extensions()) {
976 bool uses_default =
Devlin Cronin7e0f41ff2018-05-16 17:19:36977 management->UsesDefaultPolicyHostRestrictions(extension.get());
nrpetere33d2a5b2017-04-25 00:12:31978 if (uses_default) {
Devlin Cronineea1b7a2018-05-26 02:46:21979 PermissionsUpdater(profile()).SetUsesDefaultHostRestrictions(
nrpetere33d2a5b2017-04-25 00:12:31980 extension.get());
981 } else {
Devlin Cronineea1b7a2018-05-26 02:46:21982 PermissionsUpdater(profile()).SetPolicyHostRestrictions(
Devlin Cronin7e0f41ff2018-05-16 17:19:36983 extension.get(), management->GetPolicyBlockedHosts(extension.get()),
984 management->GetPolicyAllowedHosts(extension.get()));
nrpetere33d2a5b2017-04-25 00:12:31985 }
986 }
binjin8e3d0182014-12-04 16:44:28987
988 // Loop through the disabled extension list, find extensions to re-enable
Karan Bhatia2a117232017-08-23 00:24:56989 // automatically. These extensions are exclusive from the |to_disable| list
990 // constructed above, since disabled_extensions() and enabled_extensions() are
991 // supposed to be mutually exclusive.
achuith2f5578b2016-02-26 21:57:13992 for (const auto& extension : registry_->disabled_extensions()) {
Karan Bhatia2a117232017-08-23 00:24:56993 int disable_reasons = extension_prefs_->GetDisableReasons(extension->id());
binjin8e3d0182014-12-04 16:44:28994
Karan Bhatia2a117232017-08-23 00:24:56995 // Find all extensions disabled due to minimum version requirement and
996 // management policy but now satisfying it.
997 if (management->CheckMinimumVersion(extension.get(), nullptr)) {
Devlin Cronineea1b7a2018-05-26 02:46:21998 disable_reasons &= (~disable_reason::DISABLE_UPDATE_REQUIRED_BY_POLICY);
Karan Bhatia2a117232017-08-23 00:24:56999 }
1000
1001 if (!system_->management_policy()->MustRemainDisabled(extension.get(),
1002 nullptr, nullptr)) {
Devlin Cronineea1b7a2018-05-26 02:46:211003 disable_reasons &= (~disable_reason::DISABLE_BLOCKED_BY_POLICY);
Karan Bhatia2a117232017-08-23 00:24:561004 }
1005
1006 extension_prefs_->ReplaceDisableReasons(extension->id(), disable_reasons);
Devlin Cronineea1b7a2018-05-26 02:46:211007 if (disable_reasons == disable_reason::DISABLE_NONE)
Karan Bhatia2a117232017-08-23 00:24:561008 to_enable.push_back(extension->id());
1009 }
[email protected]0d54b682013-11-05 14:15:361010
achuith2f5578b2016-02-26 21:57:131011 for (const auto& i : to_disable)
1012 DisableExtension(i.first, i.second);
binjin8e3d0182014-12-04 16:44:281013
Karan Bhatia2a117232017-08-23 00:24:561014 // No extension is getting re-enabled here after disabling because |to_enable|
1015 // is mutually exclusive to |to_disable|.
binjin8e3d0182014-12-04 16:44:281016 for (const std::string& id : to_enable)
1017 EnableExtension(id);
1018
1019 if (updater_.get()) {
1020 // Find all extensions disabled due to minimum version requirement from
1021 // policy (including the ones that got disabled just now), and check
1022 // for update.
Devlin Cronineea1b7a2018-05-26 02:46:211023 ExtensionUpdater::CheckParams to_recheck;
achuith2f5578b2016-02-26 21:57:131024 for (const auto& extension : registry_->disabled_extensions()) {
binjin8e3d0182014-12-04 16:44:281025 if (extension_prefs_->GetDisableReasons(extension->id()) ==
Devlin Cronineea1b7a2018-05-26 02:46:211026 disable_reason::DISABLE_UPDATE_REQUIRED_BY_POLICY) {
binjin8e3d0182014-12-04 16:44:281027 // The minimum version check is the only thing holding this extension
1028 // back, so check if it can be updated to fix that.
1029 to_recheck.ids.push_back(extension->id());
1030 }
1031 }
1032 if (!to_recheck.ids.empty())
Minh X. Nguyen722b9682018-04-25 21:46:481033 updater_->CheckNow(std::move(to_recheck));
binjin8e3d0182014-12-04 16:44:281034 }
[email protected]aa96d3a2010-08-21 08:45:251035}
1036
[email protected]31206602011-04-13 23:07:321037void ExtensionService::CheckForUpdatesSoon() {
[email protected]90878c52014-04-04 18:21:021038 // This can legitimately happen in unit tests.
1039 if (!updater_.get())
1040 return;
1041
raphael.kubo.da.costa8527f942016-11-15 17:03:511042 updater_->CheckSoon();
[email protected]c3cfb012011-04-06 22:07:351043}
1044
[email protected]8e4560b62011-01-14 10:09:141045// Some extensions will autoupdate themselves externally from Chrome. These
rkaplowa8fd8d32015-02-25 21:27:561046// are typically part of some larger client application package. To support
1047// these, the extension will register its location in the preferences file
[email protected]8e4560b62011-01-14 10:09:141048// (and also, on Windows, in the registry) and this code will periodically
1049// check that location for a .crx file, which it will then install locally if
1050// a new version is available.
Devlin Cronin9722a722017-12-16 03:35:101051// Errors are reported through LoadErrorReporter. Success is not reported.
[email protected]eaa7dd182010-12-14 11:09:001052void ExtensionService::CheckForExternalUpdates() {
lazyboy77214d3c2017-04-04 16:46:121053 if (external_updates_disabled_for_test_)
1054 return;
1055
[email protected]a29a517a2011-01-21 21:11:121056 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
rkaplowa8fd8d32015-02-25 21:27:561057 TRACE_EVENT0("browser,startup", "ExtensionService::CheckForExternalUpdates");
1058 SCOPED_UMA_HISTOGRAM_TIMER("Extensions.CheckForExternalUpdatesTime");
[email protected]8e4560b62011-01-14 10:09:141059
1060 // Note that this installation is intentionally silent (since it didn't
1061 // go through the front-end). Extensions that are registered in this
1062 // way are effectively considered 'pre-bundled', and so implicitly
1063 // trusted. In general, if something has HKLM or filesystem access,
1064 // they could install an extension manually themselves anyway.
[email protected]a29a517a2011-01-21 21:11:121065
[email protected]8e4560b62011-01-14 10:09:141066 // Ask each external extension provider to give us a call back for each
1067 // extension they know about. See OnExternalExtension(File|UpdateUrl)Found.
achuith2f5578b2016-02-26 21:57:131068 for (const auto& provider : external_extension_providers_)
[email protected]8e4560b62011-01-14 10:09:141069 provider->VisitRegisteredExtension();
[email protected]8e4560b62011-01-14 10:09:141070
[email protected]50067e52011-10-20 23:17:071071 // Do any required work that we would have done after completion of all
1072 // providers.
[email protected]373daf972014-04-10 01:50:441073 if (external_extension_providers_.empty())
[email protected]50067e52011-10-20 23:17:071074 OnAllExternalProvidersReady();
[email protected]9f1087e2009-06-15 17:29:321075}
1076
[email protected]50067e52011-10-20 23:17:071077void ExtensionService::OnExternalProviderReady(
lazyboye8634172016-01-28 00:10:481078 const ExternalProviderInterface* provider) {
Istiaque Ahmedf6e72622017-09-08 23:14:171079 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]50067e52011-10-20 23:17:071080 CHECK(provider->IsReady());
[email protected]a29a517a2011-01-21 21:11:121081
1082 // An external provider has finished loading. We only take action
[email protected]8e4560b62011-01-14 10:09:141083 // if all of them are finished. So we check them first.
[email protected]94fde232012-04-27 10:22:301084 if (AreAllExternalProvidersReady())
1085 OnAllExternalProvidersReady();
1086}
1087
1088bool ExtensionService::AreAllExternalProvidersReady() const {
achuith2f5578b2016-02-26 21:57:131089 for (const auto& provider : external_extension_providers_) {
1090 if (!provider->IsReady())
[email protected]94fde232012-04-27 10:22:301091 return false;
[email protected]8e4560b62011-01-14 10:09:141092 }
[email protected]94fde232012-04-27 10:22:301093 return true;
[email protected]50067e52011-10-20 23:17:071094}
1095
1096void ExtensionService::OnAllExternalProvidersReady() {
Istiaque Ahmedf6e72622017-09-08 23:14:171097 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]50067e52011-10-20 23:17:071098 // Install any pending extensions.
[email protected]94fde232012-04-27 10:22:301099 if (update_once_all_providers_are_ready_ && updater()) {
1100 update_once_all_providers_are_ready_ = false;
Devlin Cronineea1b7a2018-05-26 02:46:211101 ExtensionUpdater::CheckParams params;
Minh X. Nguyen722b9682018-04-25 21:46:481102 params.callback =
1103 external_updates_finished_callback_.is_null()
1104 ? base::OnceClosure()
1105 : base::BindOnce(
1106 [](base::RepeatingClosure callback) { callback.Run(); },
1107 external_updates_finished_callback_);
1108 updater()->CheckNow(std::move(params));
[email protected]8e4560b62011-01-14 10:09:141109 }
1110
1111 // Uninstall all the unclaimed extensions.
Devlin Cronineea1b7a2018-05-26 02:46:211112 std::unique_ptr<ExtensionPrefs::ExtensionsInfo> extensions_info(
[email protected]8e4560b62011-01-14 10:09:141113 extension_prefs_->GetInstalledExtensionsInfo());
1114 for (size_t i = 0; i < extensions_info->size(); ++i) {
1115 ExtensionInfo* info = extensions_info->at(i).get();
[email protected]1d5e58b2013-01-31 08:41:401116 if (Manifest::IsExternalLocation(info->extension_location))
[email protected]8e4560b62011-01-14 10:09:141117 CheckExternalUninstall(info->extension_id);
1118 }
[email protected]e5af875f2011-10-10 21:09:141119
[email protected]373daf972014-04-10 01:50:441120 error_controller_->ShowErrorIfNeeded();
[email protected]a9aa5932012-01-25 08:27:401121
[email protected]374ceb6f2014-07-02 19:25:341122 external_install_manager_->UpdateExternalExtensionAlert();
[email protected]e5af875f2011-10-10 21:09:141123}
1124
limasdf0deef2042017-05-03 19:17:171125void ExtensionService::UnloadExtension(const std::string& extension_id,
1126 UnloadedExtensionReason reason) {
Devlin Cronin5b35a082017-10-05 20:44:361127 extension_registrar_.RemoveExtension(extension_id, reason);
[email protected]631cf822009-05-15 07:01:251128}
1129
[email protected]8b1ec202013-09-05 02:09:501130void ExtensionService::RemoveComponentExtension(
1131 const std::string& extension_id) {
1132 scoped_refptr<const Extension> extension(
1133 GetExtensionById(extension_id, false));
limasdf0deef2042017-05-03 19:17:171134 UnloadExtension(extension_id, UnloadedExtensionReason::UNINSTALL);
[email protected]ebe07772014-05-22 04:16:061135 if (extension.get()) {
[email protected]e43c61f2014-07-20 21:46:341136 ExtensionRegistry::Get(profile_)->TriggerOnUninstalled(
Devlin Cronineea1b7a2018-05-26 02:46:211137 extension.get(), UNINSTALL_REASON_COMPONENT_REMOVED);
[email protected]ebe07772014-05-22 04:16:061138 }
[email protected]8b1ec202013-09-05 02:09:501139}
1140
[email protected]bb1bc9b32013-12-21 03:09:141141void ExtensionService::UnloadAllExtensionsForTest() {
1142 UnloadAllExtensionsInternal();
[email protected]9f1087e2009-06-15 17:29:321143}
1144
[email protected]bb1bc9b32013-12-21 03:09:141145void ExtensionService::ReloadExtensionsForTest() {
1146 // Calling UnloadAllExtensionsForTest here triggers a false-positive presubmit
1147 // warning about calling test code in production.
1148 UnloadAllExtensionsInternal();
[email protected]eac88332012-12-26 17:57:451149 component_loader_->LoadAll();
Devlin Cronineea1b7a2018-05-26 02:46:211150 InstalledLoader(this).LoadAllExtensions();
rdevlin.croninf2e1cb012017-05-27 01:27:591151 OnInstalledExtensionsLoaded();
[email protected]4a10006a2013-05-17 23:18:351152 // Don't call SetReadyAndNotifyListeners() since tests call this multiple
1153 // times.
[email protected]9f1087e2009-06-15 17:29:321154}
1155
[email protected]820d9bd2013-04-03 03:46:031156void ExtensionService::SetReadyAndNotifyListeners() {
rkaplowa8fd8d32015-02-25 21:27:561157 TRACE_EVENT0("browser,startup",
1158 "ExtensionService::SetReadyAndNotifyListeners");
1159 SCOPED_UMA_HISTOGRAM_TIMER(
1160 "Extensions.ExtensionServiceNotifyReadyListenersTime");
1161
[email protected]4a10006a2013-05-17 23:18:351162 ready_->Signal();
[email protected]820d9bd2013-04-03 03:46:031163 content::NotificationService::current()->Notify(
Devlin Cronineea1b7a2018-05-26 02:46:211164 NOTIFICATION_EXTENSIONS_READY_DEPRECATED,
[email protected]820d9bd2013-04-03 03:46:031165 content::Source<Profile>(profile_),
1166 content::NotificationService::NoDetails());
1167}
1168
[email protected]fcb58a862012-05-01 01:03:151169void ExtensionService::AddExtension(const Extension* extension) {
rdevlin.cronin08ada0f2017-03-09 23:29:521170 if (!Manifest::IsValidLocation(extension->location())) {
1171 // TODO(devlin): We should *never* add an extension with an invalid
1172 // location, but some bugs (e.g. crbug.com/692069) seem to indicate we do.
1173 // Track down the cases when this can happen, and remove this
1174 // DumpWithoutCrashing() (possibly replacing it with a CHECK).
1175 NOTREACHED();
Lukasz Anforowicz68c21772018-01-13 03:42:441176 DEBUG_ALIAS_FOR_CSTR(extension_id_copy, extension->id().c_str(), 33);
rdevlin.cronin08ada0f2017-03-09 23:29:521177 Manifest::Location location = extension->location();
1178 int creation_flags = extension->creation_flags();
1179 Manifest::Type type = extension->manifest()->type();
rdevlin.cronin08ada0f2017-03-09 23:29:521180 base::debug::Alias(&location);
1181 base::debug::Alias(&creation_flags);
1182 base::debug::Alias(&type);
1183 base::debug::DumpWithoutCrashing();
1184 return;
1185 }
1186
[email protected]c8d407e2011-04-28 21:27:171187 // TODO(jstritar): We may be able to get rid of this branch by overriding the
1188 // default extension state to DISABLED when the --disable-extensions flag
1189 // is set (http://crbug.com/29067).
Devlin Croninefe0c882018-04-20 00:06:481190 if (!extensions_enabled_ &&
1191 !Manifest::ShouldAlwaysLoadExtension(extension->location(),
Devlin Cronin8c23eec2018-05-01 18:42:281192 extension->is_theme()) &&
catmullings98cd1942016-08-30 22:31:591193 disable_flag_exempted_extensions_.count(extension->id()) == 0) {
[email protected]fcb58a862012-05-01 01:03:151194 return;
[email protected]330840c2012-08-29 22:21:011195 }
[email protected]c8d407e2011-04-28 21:27:171196
Michael Giuffrida573992d2018-02-08 00:48:441197 extension_registrar_.AddExtension(extension);
Michael Giuffrida023e3532017-09-28 23:21:211198
Michael Giuffrida573992d2018-02-08 00:48:441199 if (registry_->disabled_extensions().Contains(extension->id())) {
1200 // Show the extension disabled error if a permissions increase or a remote
1201 // installation is the reason it was disabled, and no other reasons exist.
1202 int reasons = extension_prefs_->GetDisableReasons(extension->id());
Devlin Cronineea1b7a2018-05-26 02:46:211203 const int kReasonMask = disable_reason::DISABLE_PERMISSIONS_INCREASE |
1204 disable_reason::DISABLE_REMOTE_INSTALL;
Michael Giuffrida573992d2018-02-08 00:48:441205 if (reasons & kReasonMask && !(reasons & ~kReasonMask)) {
1206 AddExtensionDisabledError(
1207 this, extension,
1208 extension_prefs_->HasDisableReason(
Devlin Cronineea1b7a2018-05-26 02:46:211209 extension->id(), disable_reason::DISABLE_REMOTE_INSTALL));
Michael Giuffrida6397c592017-10-09 20:46:531210 }
[email protected]f574c402012-12-04 23:20:311211 }
[email protected]aab98a52009-12-02 03:22:351212}
1213
[email protected]8c484b742012-11-29 06:05:361214void ExtensionService::AddComponentExtension(const Extension* extension) {
1215 const std::string old_version_string(
1216 extension_prefs_->GetVersionString(extension->id()));
pwnallcbd73192016-08-22 18:59:171217 const base::Version old_version(old_version_string);
[email protected]8c484b742012-11-29 06:05:361218
[email protected]0181a7d2013-11-12 01:08:421219 VLOG(1) << "AddComponentExtension " << extension->name();
Devlin Cronin03bf2d22017-12-20 08:21:051220 if (!old_version.IsValid() || old_version != extension->version()) {
[email protected]8c484b742012-11-29 06:05:361221 VLOG(1) << "Component extension " << extension->name() << " ("
Devlin Cronin03bf2d22017-12-20 08:21:051222 << extension->id() << ") installing/upgrading from '"
1223 << old_version_string << "' to "
1224 << extension->version().GetString();
[email protected]8c484b742012-11-29 06:05:361225
Karandeep Bhatiaa8930652017-10-11 17:41:121226 // TODO(crbug.com/696822): If needed, add support for Declarative Net
1227 // Request to component extensions and pass the ruleset checksum here.
Devlin Cronineea1b7a2018-05-26 02:46:211228 AddNewOrUpdatedExtension(extension, Extension::ENABLED, kInstallFlagNone,
1229 syncer::StringOrdinal(), std::string(),
1230 base::nullopt);
[email protected]8c484b742012-11-29 06:05:361231 return;
1232 }
1233
1234 AddExtension(extension);
1235}
1236
[email protected]b914e2952013-04-26 07:10:031237void ExtensionService::CheckPermissionsIncrease(const Extension* extension,
treib6e51bca2016-06-15 10:26:031238 bool is_extension_loaded) {
Devlin Cronineea1b7a2018-05-26 02:46:211239 PermissionsUpdater(profile_).InitializePermissions(extension);
[email protected]902fd7b2011-07-27 18:42:311240
[email protected]8d888c12010-11-30 00:00:251241 // We keep track of all permissions the user has granted each extension.
1242 // This allows extensions to gracefully support backwards compatibility
1243 // by including unknown permissions in their manifests. When the user
1244 // installs the extension, only the recognized permissions are recorded.
1245 // When the unknown permissions become recognized (e.g., through browser
1246 // upgrade), we can prompt the user to accept these new permissions.
1247 // Extensions can also silently upgrade to less permissions, and then
1248 // silently upgrade to a version that adds these permissions back.
1249 //
1250 // For example, pretend that Chrome 10 includes a permission "omnibox"
1251 // for an API that adds suggestions to the omnibox. An extension can
1252 // maintain backwards compatibility while still having "omnibox" in the
1253 // manifest. If a user installs the extension on Chrome 9, the browser
1254 // will record the permissions it recognized, not including "omnibox."
1255 // When upgrading to Chrome 10, "omnibox" will be recognized and Chrome
1256 // will disable the extension and prompt the user to approve the increase
1257 // in privileges. The extension could then release a new version that
1258 // removes the "omnibox" permission. When the user upgrades, Chrome will
1259 // still remember that "omnibox" had been granted, so that if the
1260 // extension once again includes "omnibox" in an upgrade, the extension
1261 // can upgrade without requiring this user's approval.
[email protected]eb5e4f92012-08-15 23:33:281262 int disable_reasons = extension_prefs_->GetDisableReasons(extension->id());
[email protected]8d888c12010-11-30 00:00:251263
rockot1d4a06262015-02-17 19:39:281264 // Silently grant all active permissions to default apps and apps installed
1265 // in kiosk mode.
[email protected]211a3f32013-05-28 21:48:181266 bool auto_grant_permission =
rockot1d4a06262015-02-17 19:39:281267 extension->was_installed_by_default() ||
Devlin Cronineea1b7a2018-05-26 02:46:211268 ExtensionsBrowserClient::Get()->IsRunningInForcedAppMode();
[email protected]211a3f32013-05-28 21:48:181269 if (auto_grant_permission)
[email protected]b914e2952013-04-26 07:10:031270 GrantPermissions(extension);
1271
1272 bool is_privilege_increase = false;
1273 // We only need to compare the granted permissions to the current permissions
rockot1d4a06262015-02-17 19:39:281274 // if the extension has not been auto-granted its permissions above and is
1275 // installed internally.
1276 if (extension->location() == Manifest::INTERNAL && !auto_grant_permission) {
[email protected]8d888c12010-11-30 00:00:251277 // Add all the recognized permissions if the granted permissions list
1278 // hasn't been initialized yet.
dchengc963c7142016-04-08 03:55:221279 std::unique_ptr<const PermissionSet> granted_permissions =
[email protected]902fd7b2011-07-27 18:42:311280 extension_prefs_->GetGrantedPermissions(extension->id());
[email protected]0d3e4a22011-06-23 19:02:521281 CHECK(granted_permissions.get());
[email protected]8d888c12010-11-30 00:00:251282
1283 // Here, we check if an extension's privileges have increased in a manner
1284 // that requires the user's approval. This could occur because the browser
1285 // upgraded and recognized additional privileges, or an extension upgrades
1286 // to a version that requires additional privileges.
[email protected]c41003472013-10-19 15:37:251287 is_privilege_increase =
Devlin Cronineea1b7a2018-05-26 02:46:211288 PermissionMessageProvider::Get()->IsPrivilegeIncrease(
rdevlin.cronind630c302015-09-30 20:19:331289 *granted_permissions,
rdevlin.cronine2d0fd02015-09-24 22:35:491290 extension->permissions_data()->active_permissions(),
[email protected]076ebeda2014-06-06 21:47:261291 extension->GetType());
treib2c20f9442016-05-18 19:50:281292
1293 // If there was no privilege increase, the extension might still have new
1294 // permissions (which either don't generate a warning message, or whose
1295 // warning messages are suppressed by existing permissions). Grant the new
1296 // permissions.
1297 if (!is_privilege_increase)
1298 GrantPermissions(extension);
[email protected]8d888c12010-11-30 00:00:251299 }
1300
treib6e51bca2016-06-15 10:26:031301 bool previously_disabled =
1302 extension_prefs_->IsExtensionDisabled(extension->id());
1303 // TODO(treib): Is the |is_extension_loaded| check needed here?
1304 if (is_extension_loaded && previously_disabled) {
treib8a6d9892015-08-26 10:23:191305 // Legacy disabled extensions do not have a disable reason. Infer that it
1306 // was likely disabled by the user.
Devlin Cronineea1b7a2018-05-26 02:46:211307 if (disable_reasons == disable_reason::DISABLE_NONE)
1308 disable_reasons |= disable_reason::DISABLE_USER_ACTION;
treib8a6d9892015-08-26 10:23:191309
[email protected]7e9e2422012-12-13 19:54:191310 // Extensions that came to us disabled from sync need a similar inference,
1311 // except based on the new version's permissions.
Minh X. Nguyen45479012017-08-18 21:35:361312 // TODO(treib,devlin): Since M48,
Devlin Cronineea1b7a2018-05-26 02:46:211313 // disable_reason::DISABLE_UNKNOWN_FROM_SYNC isn't used anymore;
Minh X. Nguyen45479012017-08-18 21:35:361314 // this code is still here to migrate any existing old state. Remove it
1315 // after some grace period.
1316 if (disable_reasons &
Devlin Cronineea1b7a2018-05-26 02:46:211317 disable_reason::DEPRECATED_DISABLE_UNKNOWN_FROM_SYNC) {
1318 // Remove the disable_reason::DISABLE_UNKNOWN_FROM_SYNC
Minh X. Nguyen45479012017-08-18 21:35:361319 // reason.
Devlin Cronineea1b7a2018-05-26 02:46:211320 disable_reasons &= ~disable_reason::DEPRECATED_DISABLE_UNKNOWN_FROM_SYNC;
treib8a6d9892015-08-26 10:23:191321 extension_prefs_->RemoveDisableReason(
Minh X. Nguyen45479012017-08-18 21:35:361322 extension->id(),
Devlin Cronineea1b7a2018-05-26 02:46:211323 disable_reason::DEPRECATED_DISABLE_UNKNOWN_FROM_SYNC);
treib8a6d9892015-08-26 10:23:191324 // If there was no privilege increase, it was likely disabled by the user.
[email protected]7e9e2422012-12-13 19:54:191325 if (!is_privilege_increase)
Devlin Cronineea1b7a2018-05-26 02:46:211326 disable_reasons |= disable_reason::DISABLE_USER_ACTION;
[email protected]7e9e2422012-12-13 19:54:191327 }
[email protected]8d888c12010-11-30 00:00:251328 }
1329
treib6e51bca2016-06-15 10:26:031330 // If the extension is disabled due to a permissions increase, but does in
1331 // fact have all permissions, remove that disable reason.
1332 // TODO(devlin): This was added to fix crbug.com/616474, but it's unclear
1333 // if this behavior should stay forever.
Devlin Cronineea1b7a2018-05-26 02:46:211334 if (disable_reasons & disable_reason::DISABLE_PERMISSIONS_INCREASE) {
treib6e51bca2016-06-15 10:26:031335 bool reset_permissions_increase = false;
1336 if (!is_privilege_increase) {
1337 reset_permissions_increase = true;
Devlin Cronineea1b7a2018-05-26 02:46:211338 disable_reasons &= ~disable_reason::DISABLE_PERMISSIONS_INCREASE;
treib6e51bca2016-06-15 10:26:031339 extension_prefs_->RemoveDisableReason(
Devlin Cronineea1b7a2018-05-26 02:46:211340 extension->id(), disable_reason::DISABLE_PERMISSIONS_INCREASE);
treib6e51bca2016-06-15 10:26:031341 }
1342 UMA_HISTOGRAM_BOOLEAN("Extensions.ResetPermissionsIncrease",
1343 reset_permissions_increase);
1344 }
1345
[email protected]8d888c12010-11-30 00:00:251346 // Extension has changed permissions significantly. Disable it. A
[email protected]21db9ef2014-05-16 02:06:271347 // notification should be sent by the caller. If the extension is already
1348 // disabled because it was installed remotely, don't add another disable
treibaac30ec2015-06-10 09:18:091349 // reason.
1350 if (is_privilege_increase &&
Devlin Cronineea1b7a2018-05-26 02:46:211351 !(disable_reasons & disable_reason::DISABLE_REMOTE_INSTALL)) {
1352 disable_reasons |= disable_reason::DISABLE_PERMISSIONS_INCREASE;
treib8a6d9892015-08-26 10:23:191353 if (!extension_prefs_->DidExtensionEscalatePermissions(extension->id()))
treib2e0517f92015-05-07 23:15:361354 RecordPermissionMessagesHistogram(extension, "AutoDisable");
treib8ecc1eb52015-03-04 18:29:061355
brettw9e85ef42016-11-01 21:01:241356#if BUILDFLAG(ENABLE_SUPERVISED_USERS)
treib8ecc1eb52015-03-04 18:29:061357 // If a custodian-installed extension is disabled for a supervised user due
mamir51e05d02016-10-06 10:55:011358 // to a permissions increase, send a request to the custodian.
Devlin Cronineea1b7a2018-05-26 02:46:211359 if (util::IsExtensionSupervised(extension, profile_) &&
treib40d3ad92015-10-20 18:15:421360 !ExtensionSyncService::Get(profile_)->HasPendingReenable(
Devlin Cronin03bf2d22017-12-20 08:21:051361 extension->id(), extension->version())) {
treib8ecc1eb52015-03-04 18:29:061362 SupervisedUserService* supervised_user_service =
1363 SupervisedUserServiceFactory::GetForProfile(profile_);
treib40d3ad92015-10-20 18:15:421364 supervised_user_service->AddExtensionUpdateRequest(extension->id(),
Devlin Cronin03bf2d22017-12-20 08:21:051365 extension->version());
treib8ecc1eb52015-03-04 18:29:061366 }
1367#endif
[email protected]b914e2952013-04-26 07:10:031368 }
treib6e51bca2016-06-15 10:26:031369
Devlin Cronineea1b7a2018-05-26 02:46:211370 if (disable_reasons == disable_reason::DISABLE_NONE)
treib6e51bca2016-06-15 10:26:031371 extension_prefs_->SetExtensionEnabled(extension->id());
1372 else
treib8a6d9892015-08-26 10:23:191373 extension_prefs_->SetExtensionDisabled(extension->id(), disable_reasons);
[email protected]8d888c12010-11-30 00:00:251374}
1375
[email protected]eaa7dd182010-12-14 11:09:001376void ExtensionService::UpdateActiveExtensionsInCrashReporter() {
[email protected]c8865962009-12-16 07:47:391377 std::set<std::string> extension_ids;
achuith2f5578b2016-02-26 21:57:131378 for (const auto& extension : registry_->enabled_extensions()) {
[email protected]1d5e58b2013-01-31 08:41:401379 if (!extension->is_theme() && extension->location() != Manifest::COMPONENT)
[email protected]84df8332011-12-06 18:22:461380 extension_ids.insert(extension->id());
[email protected]aab98a52009-12-02 03:22:351381 }
1382
[email protected]dcc47642014-03-26 22:03:491383 // TODO(kalman): This is broken. ExtensionService is per-profile.
1384 // crash_keys::SetActiveExtensions is per-process. See
1385 // http://crbug.com/355029.
[email protected]f6431be82013-09-07 02:53:451386 crash_keys::SetActiveExtensions(extension_ids);
[email protected]6014d672008-12-05 00:38:251387}
1388
[email protected]8266d662011-07-12 21:53:261389void ExtensionService::OnExtensionInstalled(
[email protected]36a5c4c2011-12-14 16:34:501390 const Extension* extension,
[email protected]98270432012-09-11 20:51:241391 const syncer::StringOrdinal& page_ordinal,
Karandeep Bhatiaa8930652017-10-11 17:41:121392 int install_flags,
1393 const base::Optional<int>& dnr_ruleset_checksum) {
[email protected]a29a517a2011-01-21 21:11:121394 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]a8af9fdb2010-10-28 21:52:201395
[email protected]c3cfb012011-04-06 22:07:351396 const std::string& id = extension->id();
binjin47947f842014-11-18 12:10:241397 int disable_reasons = GetDisableReasonsOnInstalled(extension);
[email protected]d8fd0fd2014-03-24 13:16:061398 std::string install_parameter;
Devlin Cronineea1b7a2018-05-26 02:46:211399 const PendingExtensionInfo* pending_extension_info =
[email protected]96aebe22014-07-16 04:07:511400 pending_extension_manager()->GetById(id);
1401 if (pending_extension_info) {
[email protected]8f3bcbd2013-06-05 08:42:401402 if (!pending_extension_info->ShouldAllowInstall(extension)) {
[email protected]51a3bf8b2012-06-08 22:53:061403 pending_extension_manager()->Remove(id);
[email protected]8ef78fd2010-08-19 17:14:321404
Devlin Cronineea1b7a2018-05-26 02:46:211405 LOG(WARNING) << "ShouldAllowInstall() returned false for " << id
1406 << " of type " << extension->GetType() << " and update URL "
1407 << ManifestURL::GetUpdateURL(extension).spec()
[email protected]31bb5ee62012-09-12 22:58:401408 << "; not installing";
[email protected]ae6cb3022011-04-04 20:11:541409
[email protected]4416c5a2010-06-26 01:28:571410 // Delete the extension directory since we're not going to
1411 // load it.
Devlin Cronineea1b7a2018-05-26 02:46:211412 if (!GetExtensionFileTaskRunner()->PostTask(
1413 FROM_HERE, base::BindOnce(&file_util::DeleteFile,
tzik8d880ee2017-04-20 19:46:241414 extension->path(), true))) {
[email protected]14908b72011-04-20 06:54:361415 NOTREACHED();
[email protected]31bb5ee62012-09-12 22:58:401416 }
[email protected]4416c5a2010-06-26 01:28:571417 return;
1418 }
[email protected]51a3bf8b2012-06-08 22:53:061419
[email protected]d8fd0fd2014-03-24 13:16:061420 install_parameter = pending_extension_info->install_parameter();
[email protected]51a3bf8b2012-06-08 22:53:061421 pending_extension_manager()->Remove(id);
[email protected]4416c5a2010-06-26 01:28:571422 } else {
[email protected]c3cfb012011-04-06 22:07:351423 // We explicitly want to re-enable an uninstalled external
1424 // extension; if we're here, that means the user is manually
1425 // installing the extension.
[email protected]46f3e102014-03-25 01:22:451426 if (extension_prefs_->IsExternalExtensionUninstalled(id)) {
Devlin Cronineea1b7a2018-05-26 02:46:211427 disable_reasons = disable_reason::DISABLE_NONE;
[email protected]6cc7dbae2011-04-29 21:18:331428 }
[email protected]aa142702010-03-26 01:26:331429 }
1430
asargente4de9f92016-09-15 01:40:061431 // If the old version of the extension was disabled due to corruption, this
1432 // new install may correct the problem.
Devlin Cronineea1b7a2018-05-26 02:46:211433 disable_reasons &= ~disable_reason::DISABLE_CORRUPTED;
asargente4de9f92016-09-15 01:40:061434
[email protected]98270432012-09-11 20:51:241435 // Unsupported requirements overrides the management policy.
Devlin Cronineea1b7a2018-05-26 02:46:211436 if (install_flags & kInstallFlagHasRequirementErrors) {
1437 disable_reasons |= disable_reason::DISABLE_UNSUPPORTED_REQUIREMENT;
binjin8e3d0182014-12-04 16:44:281438 } else {
1439 // Requirement is supported now, remove the corresponding disable reason
1440 // instead.
Devlin Cronineea1b7a2018-05-26 02:46:211441 disable_reasons &= ~disable_reason::DISABLE_UNSUPPORTED_REQUIREMENT;
binjin8e3d0182014-12-04 16:44:281442 }
1443
1444 // Check if the extension was disabled because of the minimum version
1445 // requirements from enterprise policy, and satisfies it now.
Devlin Cronineea1b7a2018-05-26 02:46:211446 if (ExtensionManagementFactory::GetForBrowserContext(profile())
binjin8e3d0182014-12-04 16:44:281447 ->CheckMinimumVersion(extension, nullptr)) {
1448 // And remove the corresponding disable reason.
Devlin Cronineea1b7a2018-05-26 02:46:211449 disable_reasons &= ~disable_reason::DISABLE_UPDATE_REQUIRED_BY_POLICY;
[email protected]98270432012-09-11 20:51:241450 }
1451
Devlin Cronineea1b7a2018-05-26 02:46:211452 if (install_flags & kInstallFlagIsBlacklistedForMalware) {
[email protected]9f3c8532013-07-31 19:52:071453 // Installation of a blacklisted extension can happen from sync, policy,
1454 // etc, where to maintain consistency we need to install it, just never
1455 // load it (see AddExtension). Usually it should be the job of callers to
treibaac30ec2015-06-10 09:18:091456 // intercept blacklisted extensions earlier (e.g. CrxInstaller, before even
[email protected]9f3c8532013-07-31 19:52:071457 // showing the install dialogue).
[email protected]7c82539c2014-02-19 06:09:171458 extension_prefs_->AcknowledgeBlacklistedExtension(id);
[email protected]9f3c8532013-07-31 19:52:071459 UMA_HISTOGRAM_ENUMERATION("ExtensionBlacklist.SilentInstall",
1460 extension->location(),
1461 Manifest::NUM_LOCATIONS);
1462 }
1463
[email protected]695b5712012-12-06 23:55:281464 if (!GetInstalledExtension(extension->id())) {
[email protected]07533022011-06-27 20:42:551465 UMA_HISTOGRAM_ENUMERATION("Extensions.InstallType",
1466 extension->GetType(), 100);
[email protected]69084dc2012-11-17 07:39:301467 UMA_HISTOGRAM_ENUMERATION("Extensions.InstallSource",
[email protected]1d5e58b2013-01-31 08:41:401468 extension->location(), Manifest::NUM_LOCATIONS);
treib2e0517f92015-05-07 23:15:361469 RecordPermissionMessagesHistogram(extension, "Install");
[email protected]69084dc2012-11-17 07:39:301470 } else {
1471 UMA_HISTOGRAM_ENUMERATION("Extensions.UpdateType",
1472 extension->GetType(), 100);
1473 UMA_HISTOGRAM_ENUMERATION("Extensions.UpdateSource",
[email protected]1d5e58b2013-01-31 08:41:401474 extension->location(), Manifest::NUM_LOCATIONS);
[email protected]07533022011-06-27 20:42:551475 }
1476
[email protected]399583b2012-12-11 09:33:421477 const Extension::State initial_state =
Devlin Cronineea1b7a2018-05-26 02:46:211478 disable_reasons == disable_reason::DISABLE_NONE ? Extension::ENABLED
1479 : Extension::DISABLED;
treib8a6d9892015-08-26 10:23:191480 if (initial_state == Extension::ENABLED)
1481 extension_prefs_->SetExtensionEnabled(id);
1482 else
1483 extension_prefs_->SetExtensionDisabled(id, disable_reasons);
binjin47947f842014-11-18 12:10:241484
Devlin Cronineea1b7a2018-05-26 02:46:211485 ExtensionPrefs::DelayReason delay_reason;
1486 InstallGate::Action action = ShouldDelayExtensionInstall(
1487 extension, !!(install_flags & kInstallFlagInstallImmediately),
xiyuanf6a4c6a62016-04-19 18:14:541488 &delay_reason);
1489 switch (action) {
Devlin Cronineea1b7a2018-05-26 02:46:211490 case InstallGate::INSTALL:
xiyuanf6a4c6a62016-04-19 18:14:541491 AddNewOrUpdatedExtension(extension, initial_state, install_flags,
Karandeep Bhatiaa8930652017-10-11 17:41:121492 page_ordinal, install_parameter,
1493 dnr_ruleset_checksum);
xiyuanf6a4c6a62016-04-19 18:14:541494 return;
Devlin Cronineea1b7a2018-05-26 02:46:211495 case InstallGate::DELAY:
Karandeep Bhatiaa8930652017-10-11 17:41:121496 extension_prefs_->SetDelayedInstallInfo(
1497 extension, initial_state, install_flags, delay_reason, page_ordinal,
1498 install_parameter, dnr_ruleset_checksum);
[email protected]0db124b02012-11-07 04:55:051499
xiyuanf6a4c6a62016-04-19 18:14:541500 // Transfer ownership of |extension|.
[email protected]9f4e4f082013-06-21 07:11:191501 delayed_installs_.Insert(extension);
xiyuanf6a4c6a62016-04-19 18:14:541502
Devlin Cronineea1b7a2018-05-26 02:46:211503 if (delay_reason == ExtensionPrefs::DELAY_REASON_WAIT_FOR_IDLE) {
xiyuanf6a4c6a62016-04-19 18:14:541504 // Notify observers that app update is available.
ericwilligersb5f79de2016-10-19 04:15:101505 for (auto& observer : update_observers_)
1506 observer.OnAppUpdateAvailable(extension);
xiyuanf6a4c6a62016-04-19 18:14:541507 }
1508 return;
Devlin Cronineea1b7a2018-05-26 02:46:211509 case InstallGate::ABORT:
xiyuanf6a4c6a62016-04-19 18:14:541510 // Do nothing to abort the install. One such case is the shared module
1511 // service gets IMPORT_STATUS_UNRECOVERABLE status for the pending
1512 // install.
1513 return;
[email protected]399583b2012-12-11 09:33:421514 }
xiyuanf6a4c6a62016-04-19 18:14:541515
1516 NOTREACHED() << "Unknown action for delayed install: " << action;
[email protected]8c484b742012-11-29 06:05:361517}
1518
binjin1569c9b2014-09-05 13:33:181519void ExtensionService::OnExtensionManagementSettingsChanged() {
1520 error_controller_->ShowErrorIfNeeded();
binjine6b58b52014-10-31 01:55:571521
1522 // Revokes blocked permissions from active_permissions for all extensions.
Devlin Cronineea1b7a2018-05-26 02:46:211523 ExtensionManagement* settings =
1524 ExtensionManagementFactory::GetForBrowserContext(profile());
binjine6b58b52014-10-31 01:55:571525 CHECK(settings);
dchengc963c7142016-04-08 03:55:221526 std::unique_ptr<ExtensionSet> all_extensions(
binjine6b58b52014-10-31 01:55:571527 registry_->GenerateInstalledExtensionsSet());
achuith2f5578b2016-02-26 21:57:131528 for (const auto& extension : *all_extensions) {
binjine6b58b52014-10-31 01:55:571529 if (!settings->IsPermissionSetAllowed(
binjin685ade82014-11-06 09:53:561530 extension.get(),
Nick Peterson0203be4a2017-07-19 00:25:141531 extension->permissions_data()->active_permissions()) &&
1532 CanBlockExtension(extension.get())) {
Devlin Cronineea1b7a2018-05-26 02:46:211533 PermissionsUpdater(profile()).RemovePermissionsUnsafe(
rdevlin.cronind630c302015-09-30 20:19:331534 extension.get(), *settings->GetBlockedPermissions(extension.get()));
binjine6b58b52014-10-31 01:55:571535 }
1536 }
1537
binjin1569c9b2014-09-05 13:33:181538 CheckManagementPolicy();
1539}
1540
[email protected]8c484b742012-11-29 06:05:361541void ExtensionService::AddNewOrUpdatedExtension(
1542 const Extension* extension,
[email protected]399583b2012-12-11 09:33:421543 Extension::State initial_state,
[email protected]4a1d9c0d2014-06-13 12:50:111544 int install_flags,
[email protected]d8fd0fd2014-03-24 13:16:061545 const syncer::StringOrdinal& page_ordinal,
Karandeep Bhatiaa8930652017-10-11 17:41:121546 const std::string& install_parameter,
1547 const base::Optional<int>& dnr_ruleset_checksum) {
[email protected]8c484b742012-11-29 06:05:361548 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
Karandeep Bhatiaa8930652017-10-11 17:41:121549 extension_prefs_->OnExtensionInstalled(extension, initial_state, page_ordinal,
1550 install_flags, install_parameter,
1551 dnr_ruleset_checksum);
[email protected]9e9c1d12013-07-31 01:58:121552 delayed_installs_.Remove(extension->id());
[email protected]913ffca92014-03-27 15:26:161553 if (InstallVerifier::NeedsVerification(*extension))
juncai33e462102015-05-18 20:48:441554 InstallVerifier::Get(GetBrowserContext())->VerifyExtension(extension->id());
ryanackley48bedbd2015-01-27 23:12:141555
1556 const Extension* old = GetInstalledExtension(extension->id());
Devlin Cronineea1b7a2018-05-26 02:46:211557 if (AppDataMigrator::NeedsMigration(old, extension)) {
ryanackley48bedbd2015-01-27 23:12:141558 app_data_migrator_->DoMigrationAndReply(
vmpstra34d11322016-03-21 20:28:471559 old, extension, base::Bind(&ExtensionService::FinishInstallation,
1560 AsWeakPtr(), base::RetainedRef(extension)));
ryanackley48bedbd2015-01-27 23:12:141561 return;
1562 }
1563
benwells1dd4acd2015-12-09 02:20:241564 FinishInstallation(extension);
[email protected]6f6101832012-11-27 22:10:481565}
1566
Toni Barzic667db0d32018-01-09 18:00:191567bool ExtensionService::FinishDelayedInstallationIfReady(
1568 const std::string& extension_id,
1569 bool install_immediately) {
[email protected]9f4e4f082013-06-21 07:11:191570 // Check if the extension already got installed.
[email protected]9f4e4f082013-06-21 07:11:191571 const Extension* extension = delayed_installs_.GetByID(extension_id);
xiyuanf6a4c6a62016-04-19 18:14:541572 if (!extension)
Toni Barzic667db0d32018-01-09 18:00:191573 return false;
xiyuanf6a4c6a62016-04-19 18:14:541574
Devlin Cronineea1b7a2018-05-26 02:46:211575 ExtensionPrefs::DelayReason reason;
1576 const InstallGate::Action action =
Toni Barzic667db0d32018-01-09 18:00:191577 ShouldDelayExtensionInstall(extension, install_immediately, &reason);
xiyuanf6a4c6a62016-04-19 18:14:541578 switch (action) {
Devlin Cronineea1b7a2018-05-26 02:46:211579 case InstallGate::INSTALL:
xiyuanf6a4c6a62016-04-19 18:14:541580 break;
Devlin Cronineea1b7a2018-05-26 02:46:211581 case InstallGate::DELAY:
xiyuanf6a4c6a62016-04-19 18:14:541582 // Bail out and continue to delay the install.
Toni Barzic667db0d32018-01-09 18:00:191583 return false;
Devlin Cronineea1b7a2018-05-26 02:46:211584 case InstallGate::ABORT:
xiyuanf6a4c6a62016-04-19 18:14:541585 delayed_installs_.Remove(extension_id);
1586 // Make sure no version of the extension is actually installed, (i.e.,
1587 // that this delayed install was not an update).
1588 CHECK(!extension_prefs_->GetInstalledExtensionInfo(extension_id).get());
1589 extension_prefs_->DeleteExtensionPrefs(extension_id);
Toni Barzic667db0d32018-01-09 18:00:191590 return false;
[email protected]9f4e4f082013-06-21 07:11:191591 }
1592
Toni Barzic667db0d32018-01-09 18:00:191593 scoped_refptr<const Extension> delayed_install =
1594 GetPendingExtensionUpdate(extension_id);
1595 CHECK(delayed_install.get());
[email protected]9f4e4f082013-06-21 07:11:191596 delayed_installs_.Remove(extension_id);
[email protected]6f6101832012-11-27 22:10:481597
[email protected]399583b2012-12-11 09:33:421598 if (!extension_prefs_->FinishDelayedInstallInfo(extension_id))
[email protected]6f6101832012-11-27 22:10:481599 NOTREACHED();
1600
Toni Barzic667db0d32018-01-09 18:00:191601 FinishInstallation(delayed_install.get());
1602 return true;
[email protected]6f6101832012-11-27 22:10:481603}
1604
[email protected]760f743b2014-05-28 13:52:021605void ExtensionService::FinishInstallation(
benwells1dd4acd2015-12-09 02:20:241606 const Extension* extension) {
Devlin Cronineea1b7a2018-05-26 02:46:211607 const Extension* existing_extension = GetInstalledExtension(extension->id());
[email protected]e7554c3f2013-05-29 00:36:561608 bool is_update = false;
1609 std::string old_name;
1610 if (existing_extension) {
1611 is_update = true;
1612 old_name = existing_extension->name();
1613 }
[email protected]bc44b5da2014-06-12 14:20:001614 registry_->TriggerOnWillBeInstalled(
benwells1dd4acd2015-12-09 02:20:241615 extension, is_update, old_name);
[email protected]17f07822014-05-22 08:45:151616
[email protected]399583b2012-12-11 09:33:421617 // Unpacked extensions default to allowing file access, but if that has been
1618 // overridden, don't reset the value.
[email protected]1d5e58b2013-01-31 08:41:401619 if (Manifest::ShouldAlwaysAllowFileAccess(extension->location()) &&
[email protected]399583b2012-12-11 09:33:421620 !extension_prefs_->HasAllowFileAccessSetting(extension->id())) {
1621 extension_prefs_->SetAllowFileAccess(extension->id(), true);
1622 }
1623
[email protected]6f6101832012-11-27 22:10:481624 AddExtension(extension);
[email protected]612a1cb12012-10-17 13:18:031625
[email protected]bc44b5da2014-06-12 14:20:001626 // Notify observers that need to know when an installation is complete.
[email protected]38e872532014-07-16 23:27:511627 registry_->TriggerOnInstalled(extension, is_update);
[email protected]bc44b5da2014-06-12 14:20:001628
[email protected]9f4e4f082013-06-21 07:11:191629 // Check extensions that may have been delayed only because this shared module
1630 // was not available.
[email protected]374ceb6f2014-07-02 19:25:341631 if (SharedModuleInfo::IsSharedModule(extension))
[email protected]9f4e4f082013-06-21 07:11:191632 MaybeFinishDelayedInstallations();
[email protected]4a190632009-05-09 01:07:421633}
1634
[email protected]76b65442012-11-17 14:11:481635const Extension* ExtensionService::GetPendingExtensionUpdate(
1636 const std::string& id) const {
[email protected]9f4e4f082013-06-21 07:11:191637 return delayed_installs_.GetByID(id);
[email protected]76b65442012-11-17 14:11:481638}
1639
mukai87a8d402014-09-15 20:15:091640void ExtensionService::RegisterContentSettings(
mmenkead5094ab2017-05-15 19:01:141641 HostContentSettingsMap* host_content_settings_map,
1642 Profile* profile) {
1643 // Most extension services key off of the original profile.
1644 Profile* original_profile = profile->GetOriginalProfile();
1645
rkaplowe65c2ff2015-02-14 16:29:541646 TRACE_EVENT0("browser,startup", "ExtensionService::RegisterContentSettings");
mukaia1aa3512014-10-22 20:14:111647 DCHECK_CURRENTLY_ON(BrowserThread::UI);
mukai87a8d402014-09-15 20:15:091648 host_content_settings_map->RegisterProvider(
mukai87a8d402014-09-15 20:15:091649 HostContentSettingsMap::CUSTOM_EXTENSION_PROVIDER,
dchengc963c7142016-04-08 03:55:221650 std::unique_ptr<content_settings::ObservableProvider>(
mukai87a8d402014-09-15 20:15:091651 new content_settings::CustomExtensionProvider(
Devlin Cronineea1b7a2018-05-26 02:46:211652 ContentSettingsService::Get(original_profile)
dchengc963c7142016-04-08 03:55:221653 ->content_settings_store(),
mmenkead5094ab2017-05-15 19:01:141654 // TODO(mmenke): CustomExtensionProvider expects this to be true
1655 // for incognito profiles.
1656 false)));
mukai87a8d402014-09-15 20:15:091657}
1658
[email protected]e9d7496e2014-04-18 01:25:461659void ExtensionService::TerminateExtension(const std::string& extension_id) {
Michael Giuffridafcb420362017-10-11 21:50:261660 extension_registrar_.TerminateExtension(extension_id);
[email protected]bb7f40952011-01-13 00:21:201661}
1662
[email protected]8001df22011-04-28 19:59:471663const Extension* ExtensionService::GetInstalledExtension(
1664 const std::string& id) const {
[email protected]599539802014-01-07 23:06:001665 return registry_->GetExtensionById(id, ExtensionRegistry::EVERYTHING);
[email protected]0dfe05c2011-02-23 23:03:361666}
1667
[email protected]9060d8b02012-01-13 02:14:301668bool ExtensionService::OnExternalExtensionFileFound(
lazyboye8634172016-01-28 00:10:481669 const ExternalInstallInfoFile& info) {
Istiaque Ahmedf6e72622017-09-08 23:14:171670 DCHECK_CURRENTLY_ON(BrowserThread::UI);
lazyboye8634172016-01-28 00:10:481671 CHECK(crx_file::id_util::IdIsValid(info.extension_id));
1672 if (extension_prefs_->IsExternalExtensionUninstalled(info.extension_id))
[email protected]9060d8b02012-01-13 02:14:301673 return false;
[email protected]a8af9fdb2010-10-28 21:52:201674
[email protected]7577a5c52009-07-30 06:21:581675 // Before even bothering to unpack, check and see if we already have this
[email protected]4c967932009-07-31 01:15:491676 // version. This is important because these extensions are going to get
[email protected]7577a5c52009-07-30 06:21:581677 // installed on every startup.
lazyboye8634172016-01-28 00:10:481678 const Extension* existing = GetExtensionById(info.extension_id, true);
[email protected]910f72ce2012-08-24 01:38:351679
[email protected]7577a5c52009-07-30 06:21:581680 if (existing) {
[email protected]910f72ce2012-08-24 01:38:351681 // The default apps will have the location set as INTERNAL. Since older
1682 // default apps are installed as EXTERNAL, we override them. However, if the
1683 // app is already installed as internal, then do the version check.
[email protected]31bb5ee62012-09-12 22:58:401684 // TODO(grv) : Remove after Q1-2013.
[email protected]910f72ce2012-08-24 01:38:351685 bool is_default_apps_migration =
lazyboye8634172016-01-28 00:10:481686 (info.crx_location == Manifest::INTERNAL &&
[email protected]1d5e58b2013-01-31 08:41:401687 Manifest::IsExternalLocation(existing->location()));
[email protected]910f72ce2012-08-24 01:38:351688
1689 if (!is_default_apps_migration) {
Devlin Cronin03bf2d22017-12-20 08:21:051690 switch (existing->version().CompareTo(info.version)) {
[email protected]910f72ce2012-08-24 01:38:351691 case -1: // existing version is older, we should upgrade
1692 break;
1693 case 0: // existing version is same, do nothing
1694 return false;
1695 case 1: // existing version is newer, uh-oh
lazyboye8634172016-01-28 00:10:481696 LOG(WARNING) << "Found external version of extension "
1697 << info.extension_id
[email protected]910f72ce2012-08-24 01:38:351698 << "that is older than current version. Current version "
1699 << "is: " << existing->VersionString() << ". New "
Devlin Cronind4c2a8f32017-09-29 17:08:301700 << "version is: " << info.version.GetString()
[email protected]910f72ce2012-08-24 01:38:351701 << ". Keeping current version.";
1702 return false;
1703 }
[email protected]7577a5c52009-07-30 06:21:581704 }
1705 }
1706
[email protected]9060d8b02012-01-13 02:14:301707 // If the extension is already pending, don't start an install.
[email protected]e3987852012-05-04 10:06:301708 if (!pending_extension_manager()->AddFromExternalFile(
Devlin Cronind4c2a8f32017-09-29 17:08:301709 info.extension_id, info.crx_location, info.version,
lazyboye8634172016-01-28 00:10:481710 info.creation_flags, info.mark_acknowledged)) {
[email protected]9060d8b02012-01-13 02:14:301711 return false;
[email protected]e3987852012-05-04 10:06:301712 }
[email protected]9c635f22010-12-02 09:36:361713
[email protected]14908b72011-04-20 06:54:361714 // no client (silent install)
[email protected]f8636f92013-08-09 21:02:371715 scoped_refptr<CrxInstaller> installer(CrxInstaller::CreateSilent(this));
lazyboye8634172016-01-28 00:10:481716 installer->set_install_source(info.crx_location);
1717 installer->set_expected_id(info.extension_id);
Devlin Cronind4c2a8f32017-09-29 17:08:301718 installer->set_expected_version(info.version,
treibe960e282015-09-11 10:38:081719 true /* fail_install_if_unexpected */);
[email protected]cb0e50312011-05-09 15:03:071720 installer->set_install_cause(extension_misc::INSTALL_CAUSE_EXTERNAL_FILE);
lazyboye8634172016-01-28 00:10:481721 installer->set_install_immediately(info.install_immediately);
1722 installer->set_creation_flags(info.creation_flags);
[email protected]88e8ec9152013-01-17 04:05:181723#if defined(OS_CHROMEOS)
Devlin Cronineea1b7a2018-05-26 02:46:211724 InstallLimiter::Get(profile_)->Add(installer, info.path);
[email protected]88e8ec9152013-01-17 04:05:181725#else
lazyboye8634172016-01-28 00:10:481726 installer->InstallCrx(info.path);
[email protected]88e8ec9152013-01-17 04:05:181727#endif
[email protected]47fc70c2011-12-06 07:29:511728
1729 // Depending on the source, a new external extension might not need a user
1730 // notification on installation. For such extensions, mark them acknowledged
1731 // now to suppress the notification.
lazyboye8634172016-01-28 00:10:481732 if (info.mark_acknowledged)
1733 external_install_manager_->AcknowledgeExternalExtension(info.extension_id);
[email protected]9060d8b02012-01-13 02:14:301734
1735 return true;
[email protected]7577a5c52009-07-30 06:21:581736}
1737
[email protected]eaa7dd182010-12-14 11:09:001738void ExtensionService::DidCreateRenderViewForBackgroundPage(
Devlin Cronineea1b7a2018-05-26 02:46:211739 ExtensionHost* host) {
Michael Giuffrida573992d2018-02-08 00:48:441740 extension_registrar_.DidCreateRenderViewForBackgroundPage(host);
[email protected]406027c02010-09-27 08:03:181741}
1742
[email protected]432115822011-07-10 15:52:271743void ExtensionService::Observe(int type,
[email protected]6c2381d2011-10-19 02:52:531744 const content::NotificationSource& source,
1745 const content::NotificationDetails& details) {
[email protected]432115822011-07-10 15:52:271746 switch (type) {
[email protected]3c4abc82012-10-22 22:25:541747 case chrome::NOTIFICATION_APP_TERMINATING:
1748 // Shutdown has started. Don't start any more extension installs.
1749 // (We cannot use ExtensionService::Shutdown() for this because it
1750 // happens too late in browser teardown.)
1751 browser_terminating_ = true;
1752 break;
Devlin Cronineea1b7a2018-05-26 02:46:211753 case NOTIFICATION_EXTENSION_PROCESS_TERMINATED: {
[email protected]6c2381d2011-10-19 02:52:531754 if (profile_ !=
1755 content::Source<Profile>(source).ptr()->GetOriginalProfile()) {
[email protected]bc535ee52010-08-31 18:40:321756 break;
[email protected]6c2381d2011-10-19 02:52:531757 }
[email protected]a4ed6282009-12-14 20:51:161758
Michael Giuffridafcb420362017-10-11 21:50:261759 // Mark the extension as terminated and deactivated. We want it to
[email protected]fa2416f2011-05-03 08:41:201760 // be in a consistent state: either fully working or not loaded
1761 // at all, but never half-crashed. We do it in a PostTask so
1762 // that other handlers of this notification will still have
1763 // access to the Extension and ExtensionHost.
Devlin Cronineea1b7a2018-05-26 02:46:211764 ExtensionHost* host = content::Details<ExtensionHost>(details).ptr();
skyostilf221b7de2015-06-11 20:36:321765 base::ThreadTaskRunnerHandle::Get()->PostTask(
Michael Giuffridafcb420362017-10-11 21:50:261766 FROM_HERE, base::BindOnce(&ExtensionService::TerminateExtension,
1767 AsWeakPtr(), host->extension_id()));
[email protected]31f77262009-12-02 20:48:531768 break;
1769 }
[email protected]432115822011-07-10 15:52:271770 case content::NOTIFICATION_RENDERER_PROCESS_TERMINATED: {
[email protected]f3b1a082011-11-18 00:34:301771 content::RenderProcessHost* process =
1772 content::Source<content::RenderProcessHost>(source).ptr();
[email protected]fc30ef082011-08-18 04:07:191773 Profile* host_profile =
[email protected]f3b1a082011-11-18 00:34:301774 Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]fc30ef082011-08-18 04:07:191775 if (!profile_->IsSameProfile(host_profile->GetOriginalProfile()))
1776 break;
1777
Devlin Cronineea1b7a2018-05-26 02:46:211778 ProcessMap* process_map = ProcessMap::Get(profile_);
[email protected]fafdc842014-01-17 18:09:081779 if (process_map->Contains(process->GetID())) {
[email protected]52b76592013-11-02 17:59:031780 // An extension process was terminated, this might have resulted in an
1781 // app or extension becoming idle.
1782 std::set<std::string> extension_ids =
[email protected]fafdc842014-01-17 18:09:081783 process_map->GetExtensionsInProcess(process->GetID());
elijahtaylor0def4432014-10-06 18:15:111784 // In addition to the extensions listed in the process map, one of those
1785 // extensions could be referencing a shared module which is waiting for
1786 // idle to update. Check all imports of these extensions, too.
1787 std::set<std::string> import_ids;
1788 for (std::set<std::string>::const_iterator it = extension_ids.begin();
1789 it != extension_ids.end();
1790 ++it) {
1791 const Extension* extension = GetExtensionById(*it, true);
1792 if (!extension)
1793 continue;
1794 const std::vector<SharedModuleInfo::ImportInfo>& imports =
1795 SharedModuleInfo::GetImports(extension);
1796 std::vector<SharedModuleInfo::ImportInfo>::const_iterator import_it;
1797 for (import_it = imports.begin(); import_it != imports.end();
1798 import_it++) {
1799 import_ids.insert((*import_it).extension_id);
1800 }
1801 }
1802 extension_ids.insert(import_ids.begin(), import_ids.end());
1803
[email protected]52b76592013-11-02 17:59:031804 for (std::set<std::string>::const_iterator it = extension_ids.begin();
1805 it != extension_ids.end(); ++it) {
1806 if (delayed_installs_.Contains(*it)) {
skyostilf221b7de2015-06-11 20:36:321807 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
[email protected]52b76592013-11-02 17:59:031808 FROM_HERE,
tzik8d880ee2017-04-20 19:46:241809 base::BindOnce(
Toni Barzic667db0d32018-01-09 18:00:191810 base::IgnoreResult(
1811 &ExtensionService::FinishDelayedInstallationIfReady),
1812 AsWeakPtr(), *it, false /*install_immediately*/),
[email protected]52b76592013-11-02 17:59:031813 base::TimeDelta::FromSeconds(kUpdateIdleDelay));
1814 }
1815 }
1816 }
1817
[email protected]fafdc842014-01-17 18:09:081818 process_map->RemoveAllFromProcess(process->GetID());
[email protected]6f371442011-11-09 06:45:461819 BrowserThread::PostTask(
tzik8d880ee2017-04-20 19:46:241820 BrowserThread::IO, FROM_HERE,
Devlin Cronineea1b7a2018-05-26 02:46:211821 base::BindOnce(&InfoMap::UnregisterAllExtensionsInProcess,
tzik8d880ee2017-04-20 19:46:241822 system_->info_map(), process->GetID()));
[email protected]da5683db2011-04-23 17:12:211823 break;
1824 }
[email protected]ebe07772014-05-22 04:16:061825 case chrome::NOTIFICATION_PROFILE_DESTRUCTION_STARTED: {
1826 OnProfileDestructionStarted();
1827 break;
1828 }
[email protected]aa96d3a2010-08-21 08:45:251829
[email protected]4814b512009-11-07 00:12:291830 default:
1831 NOTREACHED() << "Unexpected notification type.";
1832 }
1833}
1834
binjin47947f842014-11-18 12:10:241835int ExtensionService::GetDisableReasonsOnInstalled(const Extension* extension) {
rdevlin.cronine1456712016-12-29 22:47:281836 bool is_update_from_same_type = false;
1837 {
1838 const Extension* existing_extension =
1839 GetInstalledExtension(extension->id());
1840 is_update_from_same_type =
1841 existing_extension &&
1842 existing_extension->manifest()->type() == extension->manifest()->type();
1843 }
Devlin Cronineea1b7a2018-05-26 02:46:211844 disable_reason::DisableReason disable_reason = disable_reason::DISABLE_NONE;
binjin47947f842014-11-18 12:10:241845 // Extensions disabled by management policy should always be disabled, even
1846 // if it's force-installed.
1847 if (system_->management_policy()->MustRemainDisabled(
1848 extension, &disable_reason, nullptr)) {
1849 // A specified reason is required to disable the extension.
Devlin Cronineea1b7a2018-05-26 02:46:211850 DCHECK(disable_reason != disable_reason::DISABLE_NONE);
binjin47947f842014-11-18 12:10:241851 return disable_reason;
1852 }
1853
[email protected]612a1cb12012-10-17 13:18:031854 // Extensions installed by policy can't be disabled. So even if a previous
1855 // installation disabled the extension, make sure it is now enabled.
binjin47947f842014-11-18 12:10:241856 if (system_->management_policy()->MustRemainEnabled(extension, nullptr))
Devlin Cronineea1b7a2018-05-26 02:46:211857 return disable_reason::DISABLE_NONE;
[email protected]612a1cb12012-10-17 13:18:031858
binjin47947f842014-11-18 12:10:241859 // An already disabled extension should inherit the disable reasons and
1860 // remain disabled.
1861 if (extension_prefs_->IsExtensionDisabled(extension->id())) {
1862 int disable_reasons = extension_prefs_->GetDisableReasons(extension->id());
1863 // If an extension was disabled without specified reason, presume it's
1864 // disabled by user.
Devlin Cronineea1b7a2018-05-26 02:46:211865 return disable_reasons == disable_reason::DISABLE_NONE
1866 ? disable_reason::DISABLE_USER_ACTION
binjin47947f842014-11-18 12:10:241867 : disable_reasons;
1868 }
[email protected]612a1cb12012-10-17 13:18:031869
Devlin Cronineea1b7a2018-05-26 02:46:211870 if (ExternalInstallManager::IsPromptingEnabled()) {
[email protected]612a1cb12012-10-17 13:18:031871 // External extensions are initially disabled. We prompt the user before
[email protected]2c495c42013-01-04 21:49:541872 // enabling them. Hosted apps are excepted because they are not dangerous
rdevlin.cronine1456712016-12-29 22:47:281873 // (they need to be launched by the user anyway). We also don't prompt for
1874 // extensions updating; this is because the extension will be disabled from
1875 // the initial install if it is supposed to be, and this allows us to turn
1876 // this on for other platforms without disabling already-installed
1877 // extensions.
[email protected]1d5e58b2013-01-31 08:41:401878 if (extension->GetType() != Manifest::TYPE_HOSTED_APP &&
1879 Manifest::IsExternalLocation(extension->location()) &&
rdevlin.cronine1456712016-12-29 22:47:281880 !extension_prefs_->IsExternalExtensionAcknowledged(extension->id()) &&
1881 !is_update_from_same_type) {
Devlin Cronineea1b7a2018-05-26 02:46:211882 return disable_reason::DISABLE_EXTERNAL_EXTENSION;
[email protected]612a1cb12012-10-17 13:18:031883 }
1884 }
[email protected]612a1cb12012-10-17 13:18:031885
Devlin Cronineea1b7a2018-05-26 02:46:211886 return disable_reason::DISABLE_NONE;
[email protected]612a1cb12012-10-17 13:18:031887}
[email protected]0db124b02012-11-07 04:55:051888
mlerman6a37b6a42014-11-26 22:10:531889// Helper method to determine if an extension can be blocked.
1890bool ExtensionService::CanBlockExtension(const Extension* extension) const {
mlerman3690e5be2014-12-01 22:57:441891 DCHECK(extension);
mlerman6a37b6a42014-11-26 22:10:531892 return extension->location() != Manifest::COMPONENT &&
1893 extension->location() != Manifest::EXTERNAL_COMPONENT &&
achuith2f5578b2016-02-26 21:57:131894 !system_->management_policy()->MustRemainEnabled(extension, nullptr);
mlerman6a37b6a42014-11-26 22:10:531895}
1896
Devlin Cronineea1b7a2018-05-26 02:46:211897InstallGate::Action ExtensionService::ShouldDelayExtensionInstall(
1898 const Extension* extension,
xiyuanf6a4c6a62016-04-19 18:14:541899 bool install_immediately,
Devlin Cronineea1b7a2018-05-26 02:46:211900 ExtensionPrefs::DelayReason* reason) const {
xiyuanf6a4c6a62016-04-19 18:14:541901 for (const auto& entry : install_delayer_registry_) {
Devlin Cronineea1b7a2018-05-26 02:46:211902 InstallGate* const delayer = entry.second;
1903 InstallGate::Action action =
xiyuanf6a4c6a62016-04-19 18:14:541904 delayer->ShouldDelay(extension, install_immediately);
Devlin Cronineea1b7a2018-05-26 02:46:211905 if (action != InstallGate::INSTALL) {
xiyuanf6a4c6a62016-04-19 18:14:541906 *reason = entry.first;
1907 return action;
1908 }
[email protected]e7aa7b7e2012-11-27 04:51:221909 }
[email protected]fdd679b2012-11-15 20:49:391910
Devlin Cronineea1b7a2018-05-26 02:46:211911 return InstallGate::INSTALL;
[email protected]9f4e4f082013-06-21 07:11:191912}
1913
1914void ExtensionService::MaybeFinishDelayedInstallations() {
1915 std::vector<std::string> to_be_installed;
achuith2f5578b2016-02-26 21:57:131916 for (const auto& extension : delayed_installs_) {
1917 to_be_installed.push_back(extension->id());
[email protected]399583b2012-12-11 09:33:421918 }
achuith2f5578b2016-02-26 21:57:131919 for (const auto& extension_id : to_be_installed) {
Toni Barzic667db0d32018-01-09 18:00:191920 FinishDelayedInstallationIfReady(extension_id,
1921 false /*install_immediately*/);
[email protected]399583b2012-12-11 09:33:421922 }
[email protected]399583b2012-12-11 09:33:421923}
1924
[email protected]fdd679b2012-11-15 20:49:391925void ExtensionService::OnBlacklistUpdated() {
[email protected]2d19eb6e2014-01-27 17:30:001926 blacklist_->GetBlacklistedIDs(
[email protected]f47f7172014-03-19 19:27:101927 registry_->GenerateInstalledExtensionsSet()->GetIDs(),
[email protected]3f2a2fa2013-09-24 02:55:251928 base::Bind(&ExtensionService::ManageBlacklist, AsWeakPtr()));
[email protected]695b5712012-12-06 23:55:281929}
1930
weidongg04695232017-06-09 00:01:051931void ExtensionService::OnUpgradeRecommended() {
1932 // Notify observers that chrome update is available.
1933 for (auto& observer : update_observers_)
1934 observer.OnChromeUpdateAvailable();
1935}
1936
Devlin Cronineea1b7a2018-05-26 02:46:211937void ExtensionService::PreAddExtension(const Extension* extension,
1938 const Extension* old_extension) {
Michael Giuffrida573992d2018-02-08 00:48:441939 // Check if the extension's privileges have changed and mark the
1940 // extension disabled if necessary.
1941 CheckPermissionsIncrease(extension, !!old_extension);
1942}
1943
Michael Giuffrida6397c592017-10-09 20:46:531944bool ExtensionService::CanEnableExtension(const Extension* extension) {
1945 return !system_->management_policy()->MustRemainDisabled(extension, nullptr,
1946 nullptr);
1947}
1948
1949bool ExtensionService::CanDisableExtension(const Extension* extension) {
1950 // Some extensions cannot be disabled by users:
1951 // - |extension| can be null if sync disables an extension that is not
1952 // installed yet; allow disablement in this case.
1953 if (!extension)
1954 return true;
1955
1956 // - Shared modules are just resources used by other extensions, and are not
1957 // user-controlled.
1958 if (SharedModuleInfo::IsSharedModule(extension))
1959 return false;
1960
1961 // - EXTERNAL_COMPONENT extensions are not generally modifiable by users, but
1962 // can be uninstalled by the browser if the user sets extension-specific
1963 // preferences.
1964 if (extension->location() == Manifest::EXTERNAL_COMPONENT)
1965 return true;
1966
1967 return system_->management_policy()->UserMayModifySettings(extension,
1968 nullptr);
1969}
1970
1971bool ExtensionService::ShouldBlockExtension(const Extension* extension) {
1972 if (!block_extensions_)
1973 return false;
1974
1975 // Blocked extensions aren't marked as such in prefs, thus if
1976 // |block_extensions_| is true then CanBlockExtension() must be called with an
1977 // Extension object. If |extension| is not loaded, assume it should be
1978 // blocked.
1979 return !extension || CanBlockExtension(extension);
1980}
1981
[email protected]2d19eb6e2014-01-27 17:30:001982void ExtensionService::ManageBlacklist(
Devlin Cronineea1b7a2018-05-26 02:46:211983 const Blacklist::BlacklistStateMap& state_map) {
[email protected]54ee8192014-03-29 17:37:241984 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]695b5712012-12-06 23:55:281985
mlerman6a37b6a42014-11-26 22:10:531986 std::set<std::string> blacklisted;
[email protected]2d19eb6e2014-01-27 17:30:001987 ExtensionIdSet greylist;
1988 ExtensionIdSet unchanged;
achuith2f5578b2016-02-26 21:57:131989 for (const auto& it : state_map) {
1990 switch (it.second) {
Devlin Cronineea1b7a2018-05-26 02:46:211991 case NOT_BLACKLISTED:
[email protected]2d19eb6e2014-01-27 17:30:001992 break;
[email protected]695b5712012-12-06 23:55:281993
Devlin Cronineea1b7a2018-05-26 02:46:211994 case BLACKLISTED_MALWARE:
achuith2f5578b2016-02-26 21:57:131995 blacklisted.insert(it.first);
[email protected]2d19eb6e2014-01-27 17:30:001996 break;
1997
Devlin Cronineea1b7a2018-05-26 02:46:211998 case BLACKLISTED_SECURITY_VULNERABILITY:
1999 case BLACKLISTED_CWS_POLICY_VIOLATION:
2000 case BLACKLISTED_POTENTIALLY_UNWANTED:
achuith2f5578b2016-02-26 21:57:132001 greylist.insert(it.first);
[email protected]2d19eb6e2014-01-27 17:30:002002 break;
2003
Devlin Cronineea1b7a2018-05-26 02:46:212004 case BLACKLISTED_UNKNOWN:
achuith2f5578b2016-02-26 21:57:132005 unchanged.insert(it.first);
[email protected]2d19eb6e2014-01-27 17:30:002006 break;
2007 }
2008 }
2009
mlerman6a37b6a42014-11-26 22:10:532010 UpdateBlacklistedExtensions(blacklisted, unchanged);
[email protected]2d19eb6e2014-01-27 17:30:002011 UpdateGreylistedExtensions(greylist, unchanged, state_map);
2012
[email protected]373daf972014-04-10 01:50:442013 error_controller_->ShowErrorIfNeeded();
[email protected]2d19eb6e2014-01-27 17:30:002014}
2015
2016namespace {
2017void Partition(const ExtensionIdSet& before,
2018 const ExtensionIdSet& after,
2019 const ExtensionIdSet& unchanged,
2020 ExtensionIdSet* no_longer,
2021 ExtensionIdSet* not_yet) {
2022 *not_yet = base::STLSetDifference<ExtensionIdSet>(after, before);
2023 *no_longer = base::STLSetDifference<ExtensionIdSet>(before, after);
2024 *no_longer = base::STLSetDifference<ExtensionIdSet>(*no_longer, unchanged);
2025}
2026} // namespace
2027
mlerman6a37b6a42014-11-26 22:10:532028void ExtensionService::UpdateBlacklistedExtensions(
2029 const ExtensionIdSet& blacklisted,
[email protected]2d19eb6e2014-01-27 17:30:002030 const ExtensionIdSet& unchanged) {
2031 ExtensionIdSet not_yet_blocked, no_longer_blocked;
mlerman6a37b6a42014-11-26 22:10:532032 Partition(registry_->blacklisted_extensions().GetIDs(), blacklisted,
2033 unchanged, &no_longer_blocked, &not_yet_blocked);
[email protected]2d19eb6e2014-01-27 17:30:002034
2035 for (ExtensionIdSet::iterator it = no_longer_blocked.begin();
2036 it != no_longer_blocked.end(); ++it) {
[email protected]695b5712012-12-06 23:55:282037 scoped_refptr<const Extension> extension =
[email protected]bb1bc9b32013-12-21 03:09:142038 registry_->blacklisted_extensions().GetByID(*it);
[email protected]3f2a2fa2013-09-24 02:55:252039 if (!extension.get()) {
mlerman6a37b6a42014-11-26 22:10:532040 NOTREACHED() << "Extension " << *it << " no longer blacklisted, "
2041 << "but it was never blacklisted.";
[email protected]695b5712012-12-06 23:55:282042 continue;
[email protected]3f2a2fa2013-09-24 02:55:252043 }
[email protected]bb1bc9b32013-12-21 03:09:142044 registry_->RemoveBlacklisted(*it);
atuchin6dc7c442016-07-20 07:04:342045 extension_prefs_->SetExtensionBlacklistState(extension->id(),
Devlin Cronineea1b7a2018-05-26 02:46:212046 NOT_BLACKLISTED);
[email protected]dc24976f2013-06-02 21:15:092047 AddExtension(extension.get());
[email protected]ac875372013-02-28 04:36:092048 UMA_HISTOGRAM_ENUMERATION("ExtensionBlacklist.UnblacklistInstalled",
[email protected]dc24976f2013-06-02 21:15:092049 extension->location(),
2050 Manifest::NUM_LOCATIONS);
[email protected]695b5712012-12-06 23:55:282051 }
2052
[email protected]2d19eb6e2014-01-27 17:30:002053 for (ExtensionIdSet::iterator it = not_yet_blocked.begin();
2054 it != not_yet_blocked.end(); ++it) {
[email protected]695b5712012-12-06 23:55:282055 scoped_refptr<const Extension> extension = GetInstalledExtension(*it);
[email protected]3f2a2fa2013-09-24 02:55:252056 if (!extension.get()) {
2057 NOTREACHED() << "Extension " << *it << " needs to be "
2058 << "blacklisted, but it's not installed.";
[email protected]695b5712012-12-06 23:55:282059 continue;
[email protected]3f2a2fa2013-09-24 02:55:252060 }
[email protected]bb1bc9b32013-12-21 03:09:142061 registry_->AddBlacklisted(extension);
Devlin Cronineea1b7a2018-05-26 02:46:212062 extension_prefs_->SetExtensionBlacklistState(extension->id(),
2063 BLACKLISTED_MALWARE);
limasdf0deef2042017-05-03 19:17:172064 UnloadExtension(*it, UnloadedExtensionReason::BLACKLIST);
[email protected]ac875372013-02-28 04:36:092065 UMA_HISTOGRAM_ENUMERATION("ExtensionBlacklist.BlacklistInstalled",
2066 extension->location(), Manifest::NUM_LOCATIONS);
[email protected]695b5712012-12-06 23:55:282067 }
[email protected]2d19eb6e2014-01-27 17:30:002068}
[email protected]695b5712012-12-06 23:55:282069
[email protected]2d19eb6e2014-01-27 17:30:002070// TODO(oleg): UMA logging
2071void ExtensionService::UpdateGreylistedExtensions(
2072 const ExtensionIdSet& greylist,
2073 const ExtensionIdSet& unchanged,
Devlin Cronineea1b7a2018-05-26 02:46:212074 const Blacklist::BlacklistStateMap& state_map) {
[email protected]2d19eb6e2014-01-27 17:30:002075 ExtensionIdSet not_yet_greylisted, no_longer_greylisted;
2076 Partition(greylist_.GetIDs(),
2077 greylist, unchanged,
2078 &no_longer_greylisted, &not_yet_greylisted);
2079
2080 for (ExtensionIdSet::iterator it = no_longer_greylisted.begin();
2081 it != no_longer_greylisted.end(); ++it) {
2082 scoped_refptr<const Extension> extension = greylist_.GetByID(*it);
2083 if (!extension.get()) {
2084 NOTREACHED() << "Extension " << *it << " no longer greylisted, "
2085 << "but it was not marked as greylisted.";
2086 continue;
2087 }
2088
2089 greylist_.Remove(*it);
2090 extension_prefs_->SetExtensionBlacklistState(extension->id(),
Devlin Cronineea1b7a2018-05-26 02:46:212091 NOT_BLACKLISTED);
[email protected]2d19eb6e2014-01-27 17:30:002092 if (extension_prefs_->GetDisableReasons(extension->id()) &
Devlin Cronineea1b7a2018-05-26 02:46:212093 disable_reason::DISABLE_GREYLIST)
[email protected]2d19eb6e2014-01-27 17:30:002094 EnableExtension(*it);
2095 }
2096
2097 for (ExtensionIdSet::iterator it = not_yet_greylisted.begin();
2098 it != not_yet_greylisted.end(); ++it) {
2099 scoped_refptr<const Extension> extension = GetInstalledExtension(*it);
2100 if (!extension.get()) {
2101 NOTREACHED() << "Extension " << *it << " needs to be "
2102 << "disabled, but it's not installed.";
2103 continue;
2104 }
2105 greylist_.Insert(extension);
2106 extension_prefs_->SetExtensionBlacklistState(extension->id(),
2107 state_map.find(*it)->second);
2108 if (registry_->enabled_extensions().Contains(extension->id()))
Devlin Cronineea1b7a2018-05-26 02:46:212109 DisableExtension(*it, disable_reason::DISABLE_GREYLIST);
[email protected]2d19eb6e2014-01-27 17:30:002110 }
[email protected]fdd679b2012-11-15 20:49:392111}
[email protected]75bdcb872013-03-13 00:41:452112
Devlin Cronineea1b7a2018-05-26 02:46:212113void ExtensionService::AddUpdateObserver(UpdateObserver* observer) {
[email protected]75bdcb872013-03-13 00:41:452114 update_observers_.AddObserver(observer);
2115}
2116
Devlin Cronineea1b7a2018-05-26 02:46:212117void ExtensionService::RemoveUpdateObserver(UpdateObserver* observer) {
[email protected]75bdcb872013-03-13 00:41:452118 update_observers_.RemoveObserver(observer);
2119}
[email protected]bb1bc9b32013-12-21 03:09:142120
Devlin Cronineea1b7a2018-05-26 02:46:212121void ExtensionService::RegisterInstallGate(ExtensionPrefs::DelayReason reason,
2122 InstallGate* install_delayer) {
xiyuanf6a4c6a62016-04-19 18:14:542123 DCHECK(install_delayer_registry_.end() ==
2124 install_delayer_registry_.find(reason));
2125 install_delayer_registry_[reason] = install_delayer;
2126}
2127
Devlin Cronineea1b7a2018-05-26 02:46:212128void ExtensionService::UnregisterInstallGate(InstallGate* install_delayer) {
xiyuanf6a4c6a62016-04-19 18:14:542129 for (auto it = install_delayer_registry_.begin();
2130 it != install_delayer_registry_.end(); ++it) {
2131 if (it->second == install_delayer) {
2132 install_delayer_registry_.erase(it);
2133 return;
2134 }
2135 }
2136}
2137
[email protected]bb1bc9b32013-12-21 03:09:142138// Used only by test code.
2139void ExtensionService::UnloadAllExtensionsInternal() {
2140 profile_->GetExtensionSpecialStoragePolicy()->RevokeRightsForAllExtensions();
2141
2142 registry_->ClearAll();
[email protected]45f5b7d2014-01-22 23:47:132143 system_->runtime_data()->ClearAll();
[email protected]bb1bc9b32013-12-21 03:09:142144
2145 // TODO(erikkay) should there be a notification for this? We can't use
Devlin Cronineea1b7a2018-05-26 02:46:212146 // EXTENSION_UNLOADED since that implies that the extension has
Minh X. Nguyen45479012017-08-18 21:35:362147 // been disabled or uninstalled.
[email protected]bb1bc9b32013-12-21 03:09:142148}
[email protected]ebe07772014-05-22 04:16:062149
2150void ExtensionService::OnProfileDestructionStarted() {
2151 ExtensionIdSet ids_to_unload = registry_->enabled_extensions().GetIDs();
2152 for (ExtensionIdSet::iterator it = ids_to_unload.begin();
2153 it != ids_to_unload.end();
2154 ++it) {
limasdf0deef2042017-05-03 19:17:172155 UnloadExtension(*it, UnloadedExtensionReason::PROFILE_SHUTDOWN);
[email protected]ebe07772014-05-22 04:16:062156 }
2157}
rdevlin.croninf2e1cb012017-05-27 01:27:592158
2159void ExtensionService::OnInstalledExtensionsLoaded() {
2160 if (updater_)
2161 updater_->Start();
2162
2163 // Enable any Shared Modules that incorrectly got disabled previously.
2164 // This is temporary code to fix incorrect behavior from previous versions of
2165 // Chrome and can be removed after several releases (perhaps M60).
Devlin Cronineea1b7a2018-05-26 02:46:212166 ExtensionList to_enable;
rdevlin.croninf2e1cb012017-05-27 01:27:592167 for (const auto& extension : registry_->disabled_extensions()) {
2168 if (SharedModuleInfo::IsSharedModule(extension.get()))
2169 to_enable.push_back(extension);
2170 }
2171 for (const auto& extension : to_enable) {
2172 EnableExtension(extension->id());
2173 }
2174
2175 OnBlacklistUpdated();
2176}
lazyboy75b9def2017-06-06 18:56:592177
Takumi Fujimoto43c8c00f2017-07-26 22:48:562178void ExtensionService::UninstallMigratedExtensions() {
2179 std::unique_ptr<ExtensionSet> installed_extensions =
2180 registry_->GenerateInstalledExtensionsSet();
2181
2182 for (const std::string& extension_id : kMigratedExtensionIds) {
2183 if (installed_extensions->Contains(extension_id)) {
Devlin Cronineea1b7a2018-05-26 02:46:212184 UninstallExtension(extension_id, UNINSTALL_REASON_MIGRATED, nullptr);
Takumi Fujimoto43c8c00f2017-07-26 22:48:562185 }
2186 }
2187}
Devlin Cronineea1b7a2018-05-26 02:46:212188
2189} // namespace extensions