blob: 49e0117f8cd42cfeabb41a4168b417186474a3ab [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;
treib2e0517f92015-05-07 23:15:36118using extensions::APIPermission;
[email protected]bf3d9df2012-07-24 23:20:27119using extensions::CrxInstaller;
[email protected]1c321ee52012-05-21 03:02:34120using extensions::Extension;
121using extensions::ExtensionIdSet;
122using extensions::ExtensionInfo;
Michael Giuffrida6397c592017-10-09 20:46:53123using extensions::ExtensionRegistrar;
[email protected]599539802014-01-07 23:06:00124using extensions::ExtensionRegistry;
[email protected]289c44b2013-12-17 03:26:57125using extensions::ExtensionSet;
lazyboye8634172016-01-28 00:10:48126using extensions::ExternalInstallInfoFile;
127using extensions::ExternalInstallInfoUpdateUrl;
128using extensions::ExternalProviderInterface;
[email protected]215a7be2012-10-22 19:53:42129using extensions::FeatureSwitch;
[email protected]ffd2f79e2013-11-14 00:11:46130using extensions::InstallVerifier;
[email protected]0d54b682013-11-05 14:15:36131using extensions::ManagementPolicy;
[email protected]1d5e58b2013-01-31 08:41:40132using extensions::Manifest;
treib2e0517f92015-05-07 23:15:36133using extensions::PermissionID;
134using extensions::PermissionIDSet;
[email protected]c2e66e12012-06-27 06:27:06135using extensions::PermissionSet;
[email protected]9f4e4f082013-06-21 07:11:19136using extensions::SharedModuleInfo;
[email protected]90878c52014-04-04 18:21:02137using extensions::SharedModuleService;
limasdf0deef2042017-05-03 19:17:17138using extensions::UnloadedExtensionReason;
[email protected]5ef47ec2010-01-28 05:58:05139
Michael Giuffrida573992d2018-02-08 00:48:44140using LoadErrorBehavior = ExtensionRegistrar::LoadErrorBehavior;
141
[email protected]b6ab96d2009-08-20 18:58:19142namespace {
143
[email protected]0db124b02012-11-07 04:55:05144// Wait this many seconds after an extensions becomes idle before updating it.
[email protected]ddc6a122014-06-27 04:52:32145const int kUpdateIdleDelay = 5;
[email protected]0db124b02012-11-07 04:55:05146
Takumi Fujimoto43c8c00f2017-07-26 22:48:56147// IDs of extensions that have been replaced by component extensions and need to
148// be uninstalled.
149const char* kMigratedExtensionIds[] = {
150 "boadgeojelhgndaghljhdicfkmllpafd", // Google Cast
151 "dliochdbjfkdbacpmhlcpmleaejidimm" // Google Cast (Beta)
152};
153
[email protected]c6d474f82009-12-16 21:11:06154} // namespace
[email protected]b6ab96d2009-08-20 18:58:19155
[email protected]eaa7dd182010-12-14 11:09:00156// ExtensionService.
[email protected]6014d672008-12-05 00:38:25157
[email protected]8e4560b62011-01-14 10:09:14158void ExtensionService::CheckExternalUninstall(const std::string& id) {
[email protected]a29a517a2011-01-21 21:11:12159 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]a8af9fdb2010-10-28 21:52:20160
[email protected]7a4c6852010-09-16 03:44:22161 // Check if the providers know about this extension.
achuith2f5578b2016-02-26 21:57:13162 for (const auto& provider : external_extension_providers_) {
163 DCHECK(provider->IsReady());
164 if (provider->HasExtension(id))
[email protected]0a60a2e2010-10-25 16:15:21165 return; // Yup, known extension, don't uninstall.
[email protected]7a4c6852010-09-16 03:44:22166 }
167
[email protected]0f48fca2011-05-19 18:46:35168 // We get the list of external extensions to check from preferences.
169 // It is possible that an extension has preferences but is not loaded.
170 // For example, an extension that requires experimental permissions
171 // will not be loaded if the experimental command line flag is not used.
172 // In this case, do not uninstall.
[email protected]31bb5ee62012-09-12 22:58:40173 if (!GetInstalledExtension(id)) {
[email protected]0f48fca2011-05-19 18:46:35174 // We can't call UninstallExtension with an unloaded/invalid
175 // extension ID.
176 LOG(WARNING) << "Attempted uninstallation of unloaded/invalid extension "
177 << "with id: " << id;
178 return;
179 }
Devlin Cronin218df7f2017-11-21 21:41:31180 UninstallExtension(
181 id, extensions::UNINSTALL_REASON_ORPHANED_EXTERNAL_EXTENSION, nullptr);
[email protected]7a4c6852010-09-16 03:44:22182}
183
[email protected]8e4560b62011-01-14 10:09:14184void ExtensionService::ClearProvidersForTesting() {
[email protected]7a4c6852010-09-16 03:44:22185 external_extension_providers_.clear();
186}
187
[email protected]8e4560b62011-01-14 10:09:14188void ExtensionService::AddProviderForTesting(
lazyboyf33109d2016-08-31 00:37:08189 std::unique_ptr<ExternalProviderInterface> test_provider) {
[email protected]a29a517a2011-01-21 21:11:12190 CHECK(test_provider);
lazyboyf33109d2016-08-31 00:37:08191 external_extension_providers_.push_back(std::move(test_provider));
[email protected]7a4c6852010-09-16 03:44:22192}
193
[email protected]8f959f522014-08-06 06:26:28194void ExtensionService::BlacklistExtensionForTest(
195 const std::string& extension_id) {
mlerman6a37b6a42014-11-26 22:10:53196 ExtensionIdSet blacklisted;
[email protected]8f959f522014-08-06 06:26:28197 ExtensionIdSet unchanged;
mlerman6a37b6a42014-11-26 22:10:53198 blacklisted.insert(extension_id);
199 UpdateBlacklistedExtensions(blacklisted, unchanged);
[email protected]8f959f522014-08-06 06:26:28200}
201
[email protected]9060d8b02012-01-13 02:14:30202bool ExtensionService::OnExternalExtensionUpdateUrlFound(
lazyboye8634172016-01-28 00:10:48203 const ExternalInstallInfoUpdateUrl& info,
204 bool is_initial_load) {
Istiaque Ahmedf6e72622017-09-08 23:14:17205 DCHECK_CURRENTLY_ON(BrowserThread::UI);
lazyboye8634172016-01-28 00:10:48206 CHECK(crx_file::id_util::IdIsValid(info.extension_id));
[email protected]a8af9fdb2010-10-28 21:52:20207
lazyboye8634172016-01-28 00:10:48208 if (Manifest::IsExternalLocation(info.download_location)) {
[email protected]044e86992014-01-24 22:59:11209 // All extensions that are not user specific can be cached.
lazyboye8634172016-01-28 00:10:48210 extensions::ExtensionsBrowserClient::Get()
211 ->GetExtensionCache()
212 ->AllowCaching(info.extension_id);
[email protected]044e86992014-01-24 22:59:11213 }
214
lazyboye8634172016-01-28 00:10:48215 const Extension* extension = GetExtensionById(info.extension_id, true);
[email protected]8a87a5332011-08-11 17:54:59216 if (extension) {
asargent56282ab72016-09-09 16:58:03217 // Already installed. Skip this install if the current location has higher
218 // priority than |info.download_location|, and we aren't doing a
219 // reinstall of a corrupt policy force-installed extension.
[email protected]1d5e58b2013-01-31 08:41:40220 Manifest::Location current = extension->location();
asargent56282ab72016-09-09 16:58:03221 if (!pending_extension_manager_.IsPolicyReinstallForCorruptionExpected(
222 info.extension_id) &&
223 current == Manifest::GetHigherPriorityLocation(
224 current, info.download_location)) {
[email protected]9060d8b02012-01-13 02:14:30225 return false;
lazyboye8634172016-01-28 00:10:48226 }
[email protected]8a87a5332011-08-11 17:54:59227 // Otherwise, overwrite the current installation.
[email protected]7a4c6852010-09-16 03:44:22228 }
[email protected]9060d8b02012-01-13 02:14:30229
lazyboye8634172016-01-28 00:10:48230 // Add |info.extension_id| to the set of pending extensions. If it can not
231 // be added, then there is already a pending record from a higher-priority
232 // install source. In this case, signal that this extension will not be
[email protected]9060d8b02012-01-13 02:14:30233 // installed by returning false.
234 if (!pending_extension_manager()->AddFromExternalUpdateUrl(
Devlin Cronind4c2a8f32017-09-29 17:08:30235 info.extension_id, info.install_parameter, info.update_url,
lazyboye8634172016-01-28 00:10:48236 info.download_location, info.creation_flags,
237 info.mark_acknowledged)) {
[email protected]9060d8b02012-01-13 02:14:30238 return false;
[email protected]31bb5ee62012-09-12 22:58:40239 }
[email protected]9060d8b02012-01-13 02:14:30240
lazyboye8634172016-01-28 00:10:48241 if (is_initial_load)
242 update_once_all_providers_are_ready_ = true;
[email protected]9060d8b02012-01-13 02:14:30243 return true;
[email protected]7a4c6852010-09-16 03:44:22244}
245
lazyboye8634172016-01-28 00:10:48246void ExtensionService::OnExternalProviderUpdateComplete(
247 const ExternalProviderInterface* provider,
Devlin Cronin19f70b6a2017-10-01 04:14:05248 const std::vector<ExternalInstallInfoUpdateUrl>& update_url_extensions,
249 const std::vector<ExternalInstallInfoFile>& file_extensions,
lazyboye8634172016-01-28 00:10:48250 const std::set<std::string>& removed_extensions) {
251 // Update pending_extension_manager() with the new extensions first.
lazyboy4aeef202016-09-07 21:28:59252 for (const auto& extension : update_url_extensions)
Devlin Cronin19f70b6a2017-10-01 04:14:05253 OnExternalExtensionUpdateUrlFound(extension, false);
lazyboy4aeef202016-09-07 21:28:59254 for (const auto& extension : file_extensions)
Devlin Cronin19f70b6a2017-10-01 04:14:05255 OnExternalExtensionFileFound(extension);
lazyboye8634172016-01-28 00:10:48256
257#if DCHECK_IS_ON()
258 for (const std::string& id : removed_extensions) {
lazyboy4aeef202016-09-07 21:28:59259 for (const auto& extension : update_url_extensions)
Devlin Cronin19f70b6a2017-10-01 04:14:05260 DCHECK_NE(id, extension.extension_id);
lazyboy4aeef202016-09-07 21:28:59261 for (const auto& extension : file_extensions)
Devlin Cronin19f70b6a2017-10-01 04:14:05262 DCHECK_NE(id, extension.extension_id);
lazyboye8634172016-01-28 00:10:48263 }
264#endif
265
266 // Then uninstall before running |updater_|.
267 for (const std::string& id : removed_extensions)
268 CheckExternalUninstall(id);
269
270 if (!update_url_extensions.empty() && updater_) {
271 // Empty params will cause pending extensions to be updated.
272 extensions::ExtensionUpdater::CheckParams empty_params;
273 updater_->CheckNow(empty_params);
274 }
275
276 error_controller_->ShowErrorIfNeeded();
277 external_install_manager_->UpdateExternalExtensionAlert();
278}
279
[email protected]eaa7dd182010-12-14 11:09:00280ExtensionService::ExtensionService(Profile* profile,
avi3ef9ec9e2014-12-22 22:50:17281 const base::CommandLine* command_line,
[email protected]650b2d52013-02-10 03:41:45282 const base::FilePath& install_directory,
[email protected]45759612012-07-10 17:21:23283 extensions::ExtensionPrefs* extension_prefs,
[email protected]fdd679b2012-11-15 20:49:39284 extensions::Blacklist* blacklist,
[email protected]0436b102011-04-15 18:30:03285 bool autoupdate_enabled,
[email protected]4a10006a2013-05-17 23:18:35286 bool extensions_enabled,
287 extensions::OneShotEvent* ready)
[email protected]fdd679b2012-11-15 20:49:39288 : extensions::Blacklist::Observer(blacklist),
catmullings98cd1942016-08-30 22:31:59289 command_line_(command_line),
[email protected]fdd679b2012-11-15 20:49:39290 profile_(profile),
[email protected]bd306722012-07-11 20:43:59291 system_(extensions::ExtensionSystem::Get(profile)),
[email protected]73c47932010-12-06 18:13:43292 extension_prefs_(extension_prefs),
[email protected]695b5712012-12-06 23:55:28293 blacklist_(blacklist),
[email protected]5fdfa562013-12-27 17:43:59294 registry_(extensions::ExtensionRegistry::Get(profile)),
[email protected]6c9bedf2014-05-21 03:55:51295 pending_extension_manager_(profile),
[email protected]a9b00ac2009-06-25 21:03:23296 install_directory_(install_directory),
[email protected]0436b102011-04-15 18:30:03297 extensions_enabled_(extensions_enabled),
[email protected]4a10006a2013-05-17 23:18:35298 ready_(ready),
ryanackley48bedbd2015-01-27 23:12:14299 shared_module_service_(new extensions::SharedModuleService(profile_)),
Michael Giuffrida023e3532017-09-28 23:21:21300 app_data_migrator_(new extensions::AppDataMigrator(profile_, registry_)),
Sergey Poromov0360b9e72018-04-19 17:37:29301 extension_registrar_(profile_, this),
302 forced_extensions_tracker_(registry_, profile_->GetPrefs()) {
[email protected]a29a517a2011-01-21 21:11:12303 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
rkaplowdd66a1342015-03-05 00:31:49304 TRACE_EVENT0("browser,startup", "ExtensionService::ExtensionService::ctor");
[email protected]a8af9fdb2010-10-28 21:52:20305
[email protected]36a784c2009-06-23 06:21:08306 // Figure out if extension installation should be enabled.
[email protected]367d9b172013-12-03 00:31:02307 if (extensions::ExtensionsBrowserClient::Get()->AreExtensionsDisabled(
308 *command_line, profile))
[email protected]6d60703b2009-08-29 01:29:23309 extensions_enabled_ = false;
[email protected]36a784c2009-06-23 06:21:08310
[email protected]3c4abc82012-10-22 22:25:54311 registrar_.Add(this, chrome::NOTIFICATION_APP_TERMINATING,
312 content::NotificationService::AllBrowserContextsAndSources());
[email protected]adf5a102014-07-31 12:44:06313 registrar_.Add(this,
314 extensions::NOTIFICATION_EXTENSION_PROCESS_TERMINATED,
[email protected]ad50def52011-10-19 23:17:07315 content::NotificationService::AllBrowserContextsAndSources());
[email protected]432115822011-07-10 15:52:27316 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_TERMINATED,
[email protected]ad50def52011-10-19 23:17:07317 content::NotificationService::AllBrowserContextsAndSources());
[email protected]ebe07772014-05-22 04:16:06318 registrar_.Add(this,
319 chrome::NOTIFICATION_PROFILE_DESTRUCTION_STARTED,
320 content::Source<Profile>(profile_));
binjin1569c9b2014-09-05 13:33:18321
weidongg04695232017-06-09 00:01:05322 UpgradeDetector::GetInstance()->AddObserver(this);
323
binjin1569c9b2014-09-05 13:33:18324 extensions::ExtensionManagementFactory::GetForBrowserContext(profile_)
325 ->AddObserver(this);
[email protected]4814b512009-11-07 00:12:29326
rkaplowdd66a1342015-03-05 00:31:49327 // Set up the ExtensionUpdater.
[email protected]93fd78f42009-07-10 16:43:17328 if (autoupdate_enabled) {
[email protected]044e86992014-01-24 22:59:11329 updater_.reset(new extensions::ExtensionUpdater(
David Bertonidccbd352018-03-20 00:31:04330 this, extension_prefs, profile->GetPrefs(), profile,
331 extensions::kDefaultUpdateFrequencySeconds,
rockotffa65b12014-10-14 17:19:06332 extensions::ExtensionsBrowserClient::Get()->GetExtensionCache(),
rockotdb5192992014-09-16 21:27:02333 base::Bind(ChromeExtensionDownloaderFactory::CreateForProfile,
334 profile)));
[email protected]93fd78f42009-07-10 16:43:17335 }
336
[email protected]25ae0152011-11-18 14:40:02337 component_loader_.reset(
338 new extensions::ComponentLoader(this,
339 profile->GetPrefs(),
[email protected]55e16cd2013-12-18 04:36:08340 g_browser_process->local_state(),
341 profile));
[email protected]8e4560b62011-01-14 10:09:14342
[email protected]0436b102011-04-15 18:30:03343 if (extensions_enabled_) {
[email protected]ae4c37e2012-12-21 01:16:25344 extensions::ExternalProviderImpl::CreateExternalProviders(
345 this, profile_, &external_extension_providers_);
[email protected]873531342011-03-09 12:16:05346 }
[email protected]b671760b2010-07-15 21:13:47347
[email protected]74474042013-11-21 12:03:54348 // Set this as the ExtensionService for app sorting to ensure it causes syncs
349 // if required.
[email protected]b3aa7182013-04-25 04:45:23350 is_first_run_ = !extension_prefs_->SetAlertSystemFirstRun();
351
[email protected]373daf972014-04-10 01:50:44352 error_controller_.reset(
353 new extensions::ExtensionErrorController(profile_, is_first_run_));
[email protected]374ceb6f2014-07-02 19:25:34354 external_install_manager_.reset(
355 new extensions::ExternalInstallManager(profile_, is_first_run_));
[email protected]373daf972014-04-10 01:50:44356
[email protected]c77f2352012-08-08 22:07:58357 extension_action_storage_manager_.reset(
358 new extensions::ExtensionActionStorageManager(profile_));
359
[email protected]cb0e50312011-05-09 15:03:07360 // How long is the path to the Extensions directory?
361 UMA_HISTOGRAM_CUSTOM_COUNTS("Extensions.ExtensionRootPathLength",
drbasicf0d1b262016-08-23 06:10:42362 install_directory_.value().length(), 1, 500, 100);
[email protected]6014d672008-12-05 00:38:25363}
364
[email protected]3f213ad2012-07-26 23:39:41365extensions::PendingExtensionManager*
366 ExtensionService::pending_extension_manager() {
[email protected]b2907fd2011-03-25 16:43:37367 return &pending_extension_manager_;
[email protected]ddb1e5a2010-12-13 20:10:45368}
369
[email protected]eaa7dd182010-12-14 11:09:00370ExtensionService::~ExtensionService() {
weidongg04695232017-06-09 00:01:05371 UpgradeDetector::GetInstance()->RemoveObserver(this);
[email protected]c8d407e2011-04-28 21:27:17372 // No need to unload extensions here because they are profile-scoped, and the
373 // profile is in the process of being deleted.
achuith2f5578b2016-02-26 21:57:13374 for (const auto& provider : external_extension_providers_)
[email protected]8e4560b62011-01-14 10:09:14375 provider->ServiceShutdown();
[email protected]6014d672008-12-05 00:38:25376}
377
[email protected]037228a2012-10-05 01:36:16378void ExtensionService::Shutdown() {
binjin1569c9b2014-09-05 13:33:18379 extensions::ExtensionManagementFactory::GetInstance()
380 ->GetForBrowserContext(profile())
381 ->RemoveObserver(this);
[email protected]037228a2012-10-05 01:36:16382}
383
[email protected]b2907fd2011-03-25 16:43:37384const Extension* ExtensionService::GetExtensionById(
385 const std::string& id, bool include_disabled) const {
[email protected]599539802014-01-07 23:06:00386 int include_mask = ExtensionRegistry::ENABLED;
[email protected]695b5712012-12-06 23:55:28387 if (include_disabled) {
mlerman6a37b6a42014-11-26 22:10:53388 // Include blacklisted and blocked extensions here because there are
389 // hundreds of callers of this function, and many might assume that this
390 // includes those that have been disabled due to blacklisting or blocking.
[email protected]599539802014-01-07 23:06:00391 include_mask |= ExtensionRegistry::DISABLED |
mlerman6a37b6a42014-11-26 22:10:53392 ExtensionRegistry::BLACKLISTED | ExtensionRegistry::BLOCKED;
[email protected]695b5712012-12-06 23:55:28393 }
[email protected]599539802014-01-07 23:06:00394 return registry_->GetExtensionById(id, include_mask);
[email protected]695b5712012-12-06 23:55:28395}
396
[email protected]eaa7dd182010-12-14 11:09:00397void ExtensionService::Init() {
[email protected]a29a517a2011-01-21 21:11:12398 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
rkaplowe65c2ff2015-02-14 16:29:54399 TRACE_EVENT0("browser,startup", "ExtensionService::Init");
rkaplowa8fd8d32015-02-25 21:27:56400 SCOPED_UMA_HISTOGRAM_TIMER("Extensions.ExtensionServiceInitTime");
[email protected]3350d712013-11-18 09:32:24401
[email protected]4a10006a2013-05-17 23:18:35402 DCHECK(!is_ready()); // Can't redo init.
[email protected]bb1bc9b32013-12-21 03:09:14403 DCHECK_EQ(registry_->enabled_extensions().size(), 0u);
[email protected]9f1087e2009-06-15 17:29:32404
benwells22ab8ee2015-08-21 02:55:08405 component_loader_->LoadAll();
achuithd3da4f02017-03-23 20:05:29406 bool load_saved_extensions = true;
emaxx35e8b822017-04-11 02:04:29407 bool load_command_line_extensions = extensions_enabled_;
achuithd3da4f02017-03-23 20:05:29408#if defined(OS_CHROMEOS)
tbarzicd2a741e2017-06-28 20:37:54409 if (chromeos::ProfileHelper::IsSigninProfile(profile_) ||
410 chromeos::ProfileHelper::IsLockScreenAppProfile(profile_)) {
achuithd3da4f02017-03-23 20:05:29411 load_saved_extensions = false;
emaxx35e8b822017-04-11 02:04:29412 load_command_line_extensions = false;
413 }
achuithd3da4f02017-03-23 20:05:29414#endif
rdevlin.croninf2e1cb012017-05-27 01:27:59415 if (load_saved_extensions)
achuithd3da4f02017-03-23 20:05:29416 extensions::InstalledLoader(this).LoadAllExtensions();
rdevlin.croninf2e1cb012017-05-27 01:27:59417
418 OnInstalledExtensionsLoaded();
419
catmullings98cd1942016-08-30 22:31:59420 LoadExtensionsFromCommandLineFlag(switches::kDisableExtensionsExcept);
emaxx35e8b822017-04-11 02:04:29421 if (load_command_line_extensions)
Michael Giuffridab158f3f2017-07-17 19:53:44422 LoadExtensionsFromCommandLineFlag(extensions::switches::kLoadExtension);
Tatsuhisa Yamaguchi5ed1aece32017-10-26 10:18:56423 EnableZipUnpackerExtension();
benwells22ab8ee2015-08-21 02:55:08424 EnabledReloadableExtensions();
425 MaybeFinishShutdownDelayed();
426 SetReadyAndNotifyListeners();
[email protected]ae4c37e2012-12-21 01:16:25427
Takumi Fujimoto43c8c00f2017-07-26 22:48:56428 UninstallMigratedExtensions();
429
benwells22ab8ee2015-08-21 02:55:08430 // TODO(erikkay): this should probably be deferred to a future point
431 // rather than running immediately at startup.
432 CheckForExternalUpdates();
[email protected]894bb502009-05-21 22:39:57433
benwells22ab8ee2015-08-21 02:55:08434 LoadGreylistFromPrefs();
rkaplowa8fd8d32015-02-25 21:27:56435}
[email protected]3350d712013-11-18 09:32:24436
Tatsuhisa Yamaguchi5ed1aece32017-10-26 10:18:56437void ExtensionService::EnableZipUnpackerExtensionForTest() {
438 EnableZipUnpackerExtension();
439}
440
441void ExtensionService::EnableZipUnpackerExtension() {
442 TRACE_EVENT0("browser,startup",
443 "ExtensionService::EnableZipUnpackerExtension");
444
445#if defined(OS_CHROMEOS)
446 // There were some cases where the Zip Unpacker was disabled in the profile,
447 // by some reason, and cannot re-enable it in any UI. crbug.com/643060
448 const std::string& id = extension_misc::kZIPUnpackerExtensionId;
449 const Extension* extension = registry_->disabled_extensions().GetByID(id);
Tatsuhisa Yamaguchi6f033fa2017-11-21 14:57:25450 if (extension && CanEnableExtension(extension)) {
Ilya Sherman982457e62017-12-13 02:19:36451 base::UmaHistogramSparse(
Tatsuhisa Yamaguchi6f033fa2017-11-21 14:57:25452 "ExtensionService.ZipUnpackerDisabledReason",
453 extension_prefs_->GetDisableReasons(extension->id()));
Tatsuhisa Yamaguchi5ed1aece32017-10-26 10:18:56454 EnableExtension(id);
Tatsuhisa Yamaguchi6f033fa2017-11-21 14:57:25455 }
Tatsuhisa Yamaguchi5ed1aece32017-10-26 10:18:56456#endif
457}
458
rkaplowa8fd8d32015-02-25 21:27:56459void ExtensionService::EnabledReloadableExtensions() {
460 TRACE_EVENT0("browser,startup",
461 "ExtensionService::EnabledReloadableExtensions");
462
463 std::vector<std::string> extensions_to_enable;
achuith2f5578b2016-02-26 21:57:13464 for (const auto& e : registry_->disabled_extensions()) {
rkaplowa8fd8d32015-02-25 21:27:56465 if (extension_prefs_->GetDisableReasons(e->id()) ==
Minh X. Nguyen45479012017-08-18 21:35:36466 extensions::disable_reason::DISABLE_RELOAD)
rkaplowa8fd8d32015-02-25 21:27:56467 extensions_to_enable.push_back(e->id());
rkaplowa8fd8d32015-02-25 21:27:56468 }
469 for (const std::string& extension : extensions_to_enable) {
470 EnableExtension(extension);
471 }
472}
473
474void ExtensionService::MaybeFinishShutdownDelayed() {
475 TRACE_EVENT0("browser,startup",
476 "ExtensionService::MaybeFinishShutdownDelayed");
477
dchengc963c7142016-04-08 03:55:22478 std::unique_ptr<extensions::ExtensionPrefs::ExtensionsInfo> delayed_info(
rkaplowa8fd8d32015-02-25 21:27:56479 extension_prefs_->GetAllDelayedInstallInfo());
480 for (size_t i = 0; i < delayed_info->size(); ++i) {
481 ExtensionInfo* info = delayed_info->at(i).get();
achuith2f5578b2016-02-26 21:57:13482 scoped_refptr<const Extension> extension(nullptr);
rkaplowa8fd8d32015-02-25 21:27:56483 if (info->extension_manifest) {
484 std::string error;
485 extension = Extension::Create(
486 info->extension_path, info->extension_location,
487 *info->extension_manifest,
488 extension_prefs_->GetDelayedInstallCreationFlags(info->extension_id),
489 info->extension_id, &error);
490 if (extension.get())
491 delayed_installs_.Insert(extension);
492 }
493 }
494 MaybeFinishDelayedInstallations();
dchengc963c7142016-04-08 03:55:22495 std::unique_ptr<extensions::ExtensionPrefs::ExtensionsInfo> delayed_info2(
rkaplowa8fd8d32015-02-25 21:27:56496 extension_prefs_->GetAllDelayedInstallInfo());
497 UMA_HISTOGRAM_COUNTS_100("Extensions.UpdateOnLoad",
498 delayed_info2->size() - delayed_info->size());
[email protected]6014d672008-12-05 00:38:25499}
500
[email protected]2d19eb6e2014-01-27 17:30:00501void ExtensionService::LoadGreylistFromPrefs() {
rkaplowa8fd8d32015-02-25 21:27:56502 TRACE_EVENT0("browser,startup", "ExtensionService::LoadGreylistFromPrefs");
503
dchengc963c7142016-04-08 03:55:22504 std::unique_ptr<ExtensionSet> all_extensions =
[email protected]f47f7172014-03-19 19:27:10505 registry_->GenerateInstalledExtensionsSet();
[email protected]2d19eb6e2014-01-27 17:30:00506
achuith2f5578b2016-02-26 21:57:13507 for (const auto& extension : *all_extensions) {
508 const extensions::BlacklistState state =
509 extension_prefs_->GetExtensionBlacklistState(extension->id());
[email protected]2d19eb6e2014-01-27 17:30:00510 if (state == extensions::BLACKLISTED_SECURITY_VULNERABILITY ||
511 state == extensions::BLACKLISTED_POTENTIALLY_UNWANTED ||
512 state == extensions::BLACKLISTED_CWS_POLICY_VIOLATION)
achuith2f5578b2016-02-26 21:57:13513 greylist_.Insert(extension);
[email protected]2d19eb6e2014-01-27 17:30:00514 }
515}
516
ginkage553af3202015-02-04 12:39:09517bool ExtensionService::UpdateExtension(const extensions::CRXFileInfo& file,
[email protected]044e86992014-01-24 22:59:11518 bool file_ownership_passed,
[email protected]31bb5ee62012-09-12 22:58:40519 CrxInstaller** out_crx_installer) {
[email protected]a29a517a2011-01-21 21:11:12520 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]3c4abc82012-10-22 22:25:54521 if (browser_terminating_) {
522 LOG(WARNING) << "Skipping UpdateExtension due to browser shutdown";
523 // Leak the temp file at extension_path. We don't want to add to the disk
524 // I/O burden at shutdown, we can't rely on the I/O completing anyway, and
525 // the file is in the OS temp directory which should be cleaned up for us.
526 return false;
527 }
[email protected]a8af9fdb2010-10-28 21:52:20528
ginkage553af3202015-02-04 12:39:09529 const std::string& id = file.extension_id;
530
[email protected]3f213ad2012-07-26 23:39:41531 const extensions::PendingExtensionInfo* pending_extension_info =
[email protected]51a3bf8b2012-06-08 22:53:06532 pending_extension_manager()->GetById(id);
[email protected]8ef78fd2010-08-19 17:14:32533
[email protected]695b5712012-12-06 23:55:28534 const Extension* extension = GetInstalledExtension(id);
[email protected]51a3bf8b2012-06-08 22:53:06535 if (!pending_extension_info && !extension) {
[email protected]aa142702010-03-26 01:26:33536 LOG(WARNING) << "Will not update extension " << id
537 << " because it is not installed or pending";
538 // Delete extension_path since we're not creating a CrxInstaller
539 // that would do it for us.
asargentd50b18c2016-04-21 01:17:16540 if (file_ownership_passed &&
Devlin Croninad3c52b2017-08-10 01:49:37541 !extensions::GetExtensionFileTaskRunner()->PostTask(
tzik8d880ee2017-04-20 19:46:24542 FROM_HERE, base::BindOnce(&extensions::file_util::DeleteFile,
543 file.path, false)))
[email protected]14908b72011-04-20 06:54:36544 NOTREACHED();
[email protected]420a0ec2011-06-01 01:07:03545
546 return false;
[email protected]e957fe52009-06-23 16:51:05547 }
Minh X. Nguyen30975342017-12-04 22:02:41548 // Either |pending_extension_info| or |extension| or both must not be null.
treibe960e282015-09-11 10:38:08549 scoped_refptr<CrxInstaller> installer(CrxInstaller::CreateSilent(this));
[email protected]6dfbbf82010-03-12 23:09:16550 installer->set_expected_id(id);
ginkage47e603e2015-02-27 08:42:41551 installer->set_expected_hash(file.expected_hash);
[email protected]464213a2013-10-15 01:06:48552 int creation_flags = Extension::NO_FLAGS;
[email protected]51a3bf8b2012-06-08 22:53:06553 if (pending_extension_info) {
554 installer->set_install_source(pending_extension_info->install_source());
pkotwicz31eb1e8ec2014-10-08 15:26:46555 installer->set_allow_silent_install(true);
treibe960e282015-09-11 10:38:08556 // If the extension came in disabled due to a permission increase, then
557 // don't grant it all the permissions. crbug.com/484214
558 bool has_permissions_increase =
559 extensions::ExtensionPrefs::Get(profile_)->HasDisableReason(
Minh X. Nguyen45479012017-08-18 21:35:36560 id, extensions::disable_reason::DISABLE_PERMISSIONS_INCREASE);
treibe960e282015-09-11 10:38:08561 const base::Version& expected_version = pending_extension_info->version();
562 if (has_permissions_increase ||
563 pending_extension_info->remote_install() ||
564 !expected_version.IsValid()) {
[email protected]21db9ef2014-05-16 02:06:27565 installer->set_grant_permissions(false);
treibe960e282015-09-11 10:38:08566 } else {
567 installer->set_expected_version(expected_version,
568 false /* fail_install_if_unexpected */);
569 }
mamir0128d5a2016-07-15 20:55:48570 creation_flags = pending_extension_info->creation_flags();
[email protected]464213a2013-10-15 01:06:48571 if (pending_extension_info->mark_acknowledged())
[email protected]374ceb6f2014-07-02 19:25:34572 external_install_manager_->AcknowledgeExternalExtension(id);
Minh X. Nguyen30975342017-12-04 22:02:41573 // If the extension was installed from or has migrated to the webstore, or
574 // its auto-update URL is from the webstore, treat it as a webstore install.
575 // Note that we ignore some older extensions with blank auto-update URLs
576 // because we are mostly concerned with restrictions on NaCl extensions,
577 // which are newer.
578 if (!extension && extension_urls::IsWebstoreUpdateUrl(
579 pending_extension_info->update_url()))
580 creation_flags |= Extension::FROM_WEBSTORE;
581 } else {
582 // |extension| must not be null.
[email protected]5eb375e92010-11-26 07:50:41583 installer->set_install_source(extension->location());
[email protected]51a3bf8b2012-06-08 22:53:06584 }
[email protected]a12ce8b22012-01-17 18:40:53585
Minh X. Nguyen30975342017-12-04 22:02:41586 if (extension) {
587 installer->InitializeCreationFlagsForUpdate(extension, creation_flags);
[email protected]c30bda262014-06-19 04:10:13588 installer->set_do_not_sync(extension_prefs_->DoNotSync(id));
Minh X. Nguyen30975342017-12-04 22:02:41589 } else {
590 installer->set_creation_flags(creation_flags);
591 }
[email protected]044e86992014-01-24 22:59:11592 installer->set_delete_source(file_ownership_passed);
[email protected]cb0e50312011-05-09 15:03:07593 installer->set_install_cause(extension_misc::INSTALL_CAUSE_UPDATE);
ginkage553af3202015-02-04 12:39:09594 installer->InstallCrxFile(file);
[email protected]420a0ec2011-06-01 01:07:03595
596 if (out_crx_installer)
[email protected]dc24976f2013-06-02 21:15:09597 *out_crx_installer = installer.get();
[email protected]420a0ec2011-06-01 01:07:03598
599 return true;
[email protected]e957fe52009-06-23 16:51:05600}
601
catmullings98cd1942016-08-30 22:31:59602void ExtensionService::LoadExtensionsFromCommandLineFlag(
603 const char* switch_name) {
604 if (command_line_->HasSwitch(switch_name)) {
605 base::CommandLine::StringType path_list =
606 command_line_->GetSwitchValueNative(switch_name);
607 base::StringTokenizerT<base::CommandLine::StringType,
608 base::CommandLine::StringType::const_iterator>
609 t(path_list, FILE_PATH_LITERAL(","));
610 while (t.GetNext()) {
611 std::string extension_id;
612 extensions::UnpackedInstaller::Create(this)->LoadFromCommandLine(
613 base::FilePath(t.token()), &extension_id, false /*only-allow-apps*/);
614 // Extension id is added to whitelist after its extension is loaded
michaelpga8ea0372017-04-06 20:41:35615 // because code is executed asynchronously. TODO(michaelpg): Remove this
616 // assumption so loading extensions does not have to be asynchronous:
617 // crbug.com/708354.
catmullings98cd1942016-08-30 22:31:59618 if (switch_name == switches::kDisableExtensionsExcept)
619 disable_flag_exempted_extensions_.insert(extension_id);
620 }
621 }
622}
623
Michael Giuffrida573992d2018-02-08 00:48:44624// TODO(michaelpg): Group with other ExtensionRegistrar::Delegate overrides
625// according to header file once diffs have settled down.
626void ExtensionService::LoadExtensionForReload(
627 const extensions::ExtensionId& extension_id,
628 const base::FilePath& path,
629 LoadErrorBehavior load_error_behavior) {
Toni Barzic667db0d32018-01-09 18:00:19630 if (delayed_installs_.Contains(extension_id) &&
631 FinishDelayedInstallationIfReady(extension_id,
632 true /*install_immediately*/)) {
[email protected]0db124b02012-11-07 04:55:05633 return;
634 }
635
[email protected]43ceb002012-02-10 23:19:15636 // If we're reloading a component extension, use the component extension
637 // loader's reloader.
638 if (component_loader_->Exists(extension_id)) {
639 component_loader_->Reload(extension_id);
640 return;
641 }
642
[email protected]e6090e42010-03-23 22:44:08643 // Check the installed extensions to see if what we're reloading was already
644 // installed.
dchengc963c7142016-04-08 03:55:22645 std::unique_ptr<ExtensionInfo> installed_extension(
[email protected]e6090e42010-03-23 22:44:08646 extension_prefs_->GetInstalledExtensionInfo(extension_id));
647 if (installed_extension.get() &&
648 installed_extension->extension_manifest.get()) {
[email protected]d8c8f25f2011-11-02 18:18:01649 extensions::InstalledLoader(this).Load(*installed_extension, false);
[email protected]e6090e42010-03-23 22:44:08650 } else {
Michael Giuffrida573992d2018-02-08 00:48:44651 // Otherwise, the extension is unpacked (location LOAD). We must load it
652 // from the path.
653 CHECK(!path.empty()) << "ExtensionRegistrar should never ask to load an "
654 "unknown extension with no path";
[email protected]bca4b832014-07-17 20:22:34655 scoped_refptr<extensions::UnpackedInstaller> unpacked_installer =
656 extensions::UnpackedInstaller::Create(this);
Michael Giuffrida573992d2018-02-08 00:48:44657 unpacked_installer->set_be_noisy_on_failure(load_error_behavior ==
658 LoadErrorBehavior::kNoisy);
[email protected]bca4b832014-07-17 20:22:34659 unpacked_installer->Load(path);
[email protected]e6090e42010-03-23 22:44:08660 }
[email protected]9cddd4702009-07-27 22:09:40661}
662
[email protected]bca4b832014-07-17 20:22:34663void ExtensionService::ReloadExtension(const std::string& extension_id) {
Michael Giuffrida573992d2018-02-08 00:48:44664 extension_registrar_.ReloadExtension(extension_id, LoadErrorBehavior::kNoisy);
[email protected]bca4b832014-07-17 20:22:34665}
666
667void ExtensionService::ReloadExtensionWithQuietFailure(
668 const std::string& extension_id) {
Michael Giuffrida573992d2018-02-08 00:48:44669 extension_registrar_.ReloadExtension(extension_id, LoadErrorBehavior::kQuiet);
[email protected]bca4b832014-07-17 20:22:34670}
671
[email protected]757d60a2014-05-23 00:11:44672bool ExtensionService::UninstallExtension(
673 // "transient" because the process of uninstalling may cause the reference
674 // to become invalid. Instead, use |extenson->id()|.
675 const std::string& transient_extension_id,
[email protected]e43c61f2014-07-20 21:46:34676 extensions::UninstallReason reason,
[email protected]757d60a2014-05-23 00:11:44677 base::string16* error) {
[email protected]a29a517a2011-01-21 21:11:12678 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]a8af9fdb2010-10-28 21:52:20679
[email protected]757d60a2014-05-23 00:11:44680 scoped_refptr<const Extension> extension =
681 GetInstalledExtension(transient_extension_id);
[email protected]631cf822009-05-15 07:01:25682
[email protected]e7afe2452010-08-22 16:19:13683 // Callers should not send us nonexistent extensions.
[email protected]dc24976f2013-06-02 21:15:09684 CHECK(extension.get());
[email protected]9f1087e2009-06-15 17:29:32685
binjincccacef2014-10-13 19:00:20686 ManagementPolicy* by_policy = system_->management_policy();
[email protected]95da88c42011-03-31 10:07:33687 // Policy change which triggers an uninstall will always set
688 // |external_uninstall| to true so this is the only way to uninstall
689 // managed extensions.
[email protected]90878c52014-04-04 18:21:02690 // Shared modules being uninstalled will also set |external_uninstall| to true
691 // so that we can guarantee users don't uninstall a shared module.
692 // (crbug.com/273300)
693 // TODO(rdevlin.cronin): This is probably not right. We should do something
694 // else, like include an enum IS_INTERNAL_UNINSTALL or IS_USER_UNINSTALL so
695 // we don't do this.
[email protected]cc2f55c2014-07-08 02:19:04696 bool external_uninstall =
[email protected]e43c61f2014-07-20 21:46:34697 (reason == extensions::UNINSTALL_REASON_INTERNAL_MANAGEMENT) ||
dtseng9fb3d5b2015-02-23 17:24:17698 (reason == extensions::UNINSTALL_REASON_COMPONENT_REMOVED) ||
rdevlin.cronin5f6b69d2014-09-20 01:23:35699 (reason == extensions::UNINSTALL_REASON_REINSTALL) ||
[email protected]e43c61f2014-07-20 21:46:34700 (reason == extensions::UNINSTALL_REASON_ORPHANED_EXTERNAL_EXTENSION) ||
[email protected]6ef60012014-07-22 19:08:12701 (reason == extensions::UNINSTALL_REASON_ORPHANED_SHARED_MODULE) ||
702 (reason == extensions::UNINSTALL_REASON_SYNC &&
mamir192d7882016-06-22 17:10:16703 extensions::util::WasInstalledByCustodian(extension->id(), profile_));
[email protected]65187152012-06-02 13:14:14704 if (!external_uninstall &&
binjincccacef2014-10-13 19:00:20705 (!by_policy->UserMayModifySettings(extension.get(), error) ||
706 by_policy->MustRemainInstalled(extension.get(), error))) {
[email protected]ad50def52011-10-19 23:17:07707 content::NotificationService::current()->Notify(
[email protected]adf5a102014-07-31 12:44:06708 extensions::NOTIFICATION_EXTENSION_UNINSTALL_NOT_ALLOWED,
[email protected]6c2381d2011-10-19 02:52:53709 content::Source<Profile>(profile_),
[email protected]dc24976f2013-06-02 21:15:09710 content::Details<const Extension>(extension.get()));
[email protected]d6ebc9792011-04-07 18:18:33711 return false;
712 }
[email protected]95da88c42011-03-31 10:07:33713
juncai33e462102015-05-18 20:48:44714 InstallVerifier::Get(GetBrowserContext())->Remove(extension->id());
[email protected]ffd2f79e2013-11-14 00:11:46715
[email protected]9b217652010-10-08 22:04:23716 UMA_HISTOGRAM_ENUMERATION("Extensions.UninstallType",
[email protected]7fa19f82010-12-21 19:40:08717 extension->GetType(), 100);
treib2e0517f92015-05-07 23:15:36718 RecordPermissionMessagesHistogram(extension.get(), "Uninstall");
[email protected]9b217652010-10-08 22:04:23719
[email protected]831aa212010-03-26 13:55:19720 // Unload before doing more cleanup to ensure that nothing is hanging on to
721 // any of these resources.
limasdf0deef2042017-05-03 19:17:17722 UnloadExtension(extension->id(), UnloadedExtensionReason::UNINSTALL);
asargent96c7ec42016-05-27 02:45:47723 if (registry_->blacklisted_extensions().Contains(extension->id()))
724 registry_->RemoveBlacklisted(extension->id());
[email protected]831aa212010-03-26 13:55:19725
[email protected]9f1087e2009-06-15 17:29:32726 // Tell the backend to start deleting installed extensions on the file thread.
[email protected]12075d12013-02-27 05:38:05727 if (!Manifest::IsUnpackedLocation(extension->location())) {
Devlin Croninad3c52b2017-08-10 01:49:37728 if (!extensions::GetExtensionFileTaskRunner()->PostTask(
[email protected]7f8f24f2012-11-15 19:40:14729 FROM_HERE,
tzik8d880ee2017-04-20 19:46:24730 base::BindOnce(&ExtensionService::UninstallExtensionOnFileThread,
731 extension->id(), profile_, install_directory_,
732 extension->path())))
[email protected]14908b72011-04-20 06:54:36733 NOTREACHED();
[email protected]9f1087e2009-06-15 17:29:32734 }
735
Devlin Cronina68c2a852017-11-29 19:11:26736 extensions::DataDeleter::StartDeleting(profile_, extension.get());
[email protected]0d6ec3a72011-09-02 02:09:43737
Michael Giuffridafcb420362017-10-11 21:50:26738 extension_registrar_.UntrackTerminatedExtension(extension->id());
[email protected]211030342010-09-30 18:41:06739
740 // Notify interested parties that we've uninstalled this extension.
[email protected]e43c61f2014-07-20 21:46:34741 ExtensionRegistry::Get(profile_)
742 ->TriggerOnUninstalled(extension.get(), reason);
[email protected]d6ebc9792011-04-07 18:18:33743
[email protected]757d60a2014-05-23 00:11:44744 delayed_installs_.Remove(extension->id());
[email protected]0db124b02012-11-07 04:55:05745
[email protected]757d60a2014-05-23 00:11:44746 extension_prefs_->OnExtensionUninstalled(
747 extension->id(), extension->location(), external_uninstall);
[email protected]d4eda592013-09-18 03:37:57748
[email protected]333b1de2011-09-12 18:28:50749 // Track the uninstallation.
[email protected]49098f702011-10-13 03:47:18750 UMA_HISTOGRAM_ENUMERATION("Extensions.ExtensionUninstalled", 1, 2);
751
[email protected]d6ebc9792011-04-07 18:18:33752 return true;
[email protected]c10da4b02010-03-25 14:38:32753}
754
[email protected]5a145e82014-05-29 22:19:07755// static
756void ExtensionService::UninstallExtensionOnFileThread(
757 const std::string& id,
758 Profile* profile,
759 const base::FilePath& install_dir,
760 const base::FilePath& extension_path) {
761 extensions::ExtensionAssetsManager* assets_manager =
762 extensions::ExtensionAssetsManager::GetInstance();
763 assets_manager->UninstallExtension(id, profile, install_dir, extension_path);
764}
765
[email protected]c3cfb012011-04-06 22:07:35766bool ExtensionService::IsExtensionEnabled(
767 const std::string& extension_id) const {
Michael Giuffrida6397c592017-10-09 20:46:53768 return extension_registrar_.IsExtensionEnabled(extension_id);
[email protected]c3cfb012011-04-06 22:07:35769}
770
[email protected]eaa7dd182010-12-14 11:09:00771void ExtensionService::EnableExtension(const std::string& extension_id) {
[email protected]a29a517a2011-01-21 21:11:12772 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
Michael Giuffrida6397c592017-10-09 20:46:53773 extension_registrar_.EnableExtension(extension_id);
[email protected]0c6da502009-08-14 22:32:39774}
775
treibc1192322015-05-20 12:56:07776void ExtensionService::DisableExtension(const std::string& extension_id,
777 int disable_reasons) {
[email protected]a29a517a2011-01-21 21:11:12778 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
Michael Giuffrida6397c592017-10-09 20:46:53779 extension_registrar_.DisableExtension(extension_id, disable_reasons);
[email protected]1784e83a2009-09-08 21:01:52780}
781
mtomasz294bb3e2017-01-24 02:17:52782void ExtensionService::DisableUserExtensionsExcept(
[email protected]1abf05e2013-07-09 17:04:36783 const std::vector<std::string>& except_ids) {
[email protected]e516e4c2013-06-12 17:41:14784 extensions::ManagementPolicy* management_policy =
785 system_->management_policy();
786 extensions::ExtensionList to_disable;
787
achuith2f5578b2016-02-26 21:57:13788 for (const auto& extension : registry_->enabled_extensions()) {
789 if (management_policy->UserMayModifySettings(extension.get(), nullptr))
790 to_disable.push_back(extension);
[email protected]e516e4c2013-06-12 17:41:14791 }
792
achuith2f5578b2016-02-26 21:57:13793 for (const auto& extension : registry_->terminated_extensions()) {
794 if (management_policy->UserMayModifySettings(extension.get(), nullptr))
795 to_disable.push_back(extension);
796 }
797
798 for (const auto& extension : to_disable) {
799 if (extension->was_installed_by_default() &&
[email protected]3082fe32013-08-06 11:12:38800 extension_urls::IsWebstoreUpdateUrl(
achuith2f5578b2016-02-26 21:57:13801 extensions::ManifestURL::GetUpdateURL(extension.get())))
[email protected]3082fe32013-08-06 11:12:38802 continue;
achuith2f5578b2016-02-26 21:57:13803 const std::string& id = extension->id();
tripta.g0ac673a2017-07-07 05:45:09804 if (!base::ContainsValue(except_ids, id))
Minh X. Nguyen45479012017-08-18 21:35:36805 DisableExtension(id, extensions::disable_reason::DISABLE_USER_ACTION);
[email protected]e516e4c2013-06-12 17:41:14806 }
807}
808
mlerman6a37b6a42014-11-26 22:10:53809// Extensions that are not locked, components or forced by policy should be
810// locked. Extensions are no longer considered enabled or disabled. Blacklisted
811// extensions are now considered both blacklisted and locked.
812void ExtensionService::BlockAllExtensions() {
813 if (block_extensions_)
814 return;
815 block_extensions_ = true;
816
817 // Blacklisted extensions are already unloaded, need not be blocked.
dchengc963c7142016-04-08 03:55:22818 std::unique_ptr<ExtensionSet> extensions =
mlerman6a37b6a42014-11-26 22:10:53819 registry_->GenerateInstalledExtensionsSet(ExtensionRegistry::ENABLED |
820 ExtensionRegistry::DISABLED |
821 ExtensionRegistry::TERMINATED);
822
achuith2f5578b2016-02-26 21:57:13823 for (const auto& extension : *extensions) {
mlerman6a37b6a42014-11-26 22:10:53824 const std::string& id = extension->id();
825
826 if (!CanBlockExtension(extension.get()))
827 continue;
828
829 registry_->RemoveEnabled(id);
830 registry_->RemoveDisabled(id);
831 registry_->RemoveTerminated(id);
832
833 registry_->AddBlocked(extension.get());
limasdf0deef2042017-05-03 19:17:17834 UnloadExtension(id, extensions::UnloadedExtensionReason::LOCK_ALL);
mlerman6a37b6a42014-11-26 22:10:53835 }
836}
837
838// All locked extensions should revert to being either enabled or disabled
839// as appropriate.
840void ExtensionService::UnblockAllExtensions() {
841 block_extensions_ = false;
dchengc963c7142016-04-08 03:55:22842 std::unique_ptr<ExtensionSet> to_unblock =
mlerman6a37b6a42014-11-26 22:10:53843 registry_->GenerateInstalledExtensionsSet(ExtensionRegistry::BLOCKED);
844
achuith2f5578b2016-02-26 21:57:13845 for (const auto& extension : *to_unblock) {
mlerman6a37b6a42014-11-26 22:10:53846 registry_->RemoveBlocked(extension->id());
847 AddExtension(extension.get());
848 }
Owen Minb71016d2018-01-11 01:51:49849 // While extensions are blocked, we won't display any external install
850 // warnings. Now that they are unblocked, we should update the error.
851 external_install_manager_->UpdateExternalExtensionAlert();
mlerman6a37b6a42014-11-26 22:10:53852}
853
[email protected]eaa7dd182010-12-14 11:09:00854void ExtensionService::GrantPermissionsAndEnableExtension(
[email protected]009633c2013-03-07 22:08:28855 const Extension* extension) {
856 GrantPermissions(extension);
treib2e0517f92015-05-07 23:15:36857 RecordPermissionMessagesHistogram(extension, "ReEnable");
[email protected]8d888c12010-11-30 00:00:25858 EnableExtension(extension->id());
859}
860
[email protected]009633c2013-03-07 22:08:28861void ExtensionService::GrantPermissions(const Extension* extension) {
[email protected]be083862012-09-01 03:53:45862 CHECK(extension);
[email protected]8d42db52014-06-20 21:50:50863 extensions::PermissionsUpdater(profile()).GrantActivePermissions(extension);
[email protected]be083862012-09-01 03:53:45864}
865
[email protected]fe2dd7742011-04-19 22:52:49866// static
867void ExtensionService::RecordPermissionMessagesHistogram(
[email protected]13c68b62013-05-17 11:29:05868 const Extension* extension, const char* histogram) {
[email protected]de415552013-01-23 04:12:17869 // Since this is called from multiple sources, and since the histogram macros
870 // use statics, we need to manually lookup the histogram ourselves.
treib2e0517f92015-05-07 23:15:36871 base::HistogramBase* counter = base::LinearHistogram::FactoryGet(
872 base::StringPrintf("Extensions.Permissions_%s3", histogram),
873 1,
874 APIPermission::kEnumBoundary,
875 APIPermission::kEnumBoundary + 1,
876 base::HistogramBase::kUmaTargetedHistogramFlag);
877
878 base::HistogramBase* counter_has_any = base::BooleanHistogram::FactoryGet(
879 base::StringPrintf("Extensions.HasPermissions_%s3", histogram),
880 base::HistogramBase::kUmaTargetedHistogramFlag);
881
882 PermissionIDSet permissions =
883 extensions::PermissionMessageProvider::Get()->GetAllPermissionIDs(
rdevlin.cronine2d0fd02015-09-24 22:35:49884 extension->permissions_data()->active_permissions(),
treib2e0517f92015-05-07 23:15:36885 extension->GetType());
886 counter_has_any->AddBoolean(!permissions.empty());
887 for (const PermissionID& id : permissions)
888 counter->Add(id.id());
[email protected]fe2dd7742011-04-19 22:52:49889}
890
Michael Giuffrida6397c592017-10-09 20:46:53891// TODO(michaelpg): Group with other ExtensionRegistrar::Delegate overrides
892// according to header file once diffs have settled down.
893void ExtensionService::PostActivateExtension(
Michael Giuffrida19a55982018-02-10 03:03:26894 scoped_refptr<const Extension> extension) {
[email protected]dcc47642014-03-26 22:03:49895 // TODO(kalman): Convert ExtensionSpecialStoragePolicy to a
896 // BrowserContextKeyedService and use ExtensionRegistryObserver.
Michael Giuffrida6397c592017-10-09 20:46:53897 profile_->GetExtensionSpecialStoragePolicy()->GrantRightsForExtension(
898 extension.get(), profile_);
[email protected]c8d407e2011-04-28 21:27:17899
[email protected]dcc47642014-03-26 22:03:49900 // TODO(kalman): This is broken. The crash reporter is process-wide so doesn't
901 // work properly multi-profile. Besides which, it should be using
902 // ExtensionRegistryObserver. See http://crbug.com/355029.
[email protected]c8d407e2011-04-28 21:27:17903 UpdateActiveExtensionsInCrashReporter();
904
[email protected]d695bb12014-06-05 16:16:30905 const extensions::PermissionsData* permissions_data =
[email protected]a6910e72014-06-06 05:04:36906 extension->permissions_data();
[email protected]d695bb12014-06-05 16:16:30907
[email protected]c8d407e2011-04-28 21:27:17908 // If the extension has permission to load chrome://favicon/ resources we need
909 // to make sure that the FaviconSource is registered with the
910 // ChromeURLDataManager.
[email protected]d695bb12014-06-05 16:16:30911 if (permissions_data->HasHostPermission(GURL(chrome::kChromeUIFaviconURL))) {
pkotwiczd95aa6592017-05-11 02:26:21912 FaviconSource* favicon_source = new FaviconSource(profile_);
[email protected]24ea7a12013-01-27 23:54:53913 content::URLDataSource::Add(profile_, favicon_source);
[email protected]c8d407e2011-04-28 21:27:17914 }
[email protected]b07e606e2012-09-15 20:16:15915
[email protected]b07e606e2012-09-15 20:16:15916 // Same for chrome://theme/ resources.
[email protected]d695bb12014-06-05 16:16:30917 if (permissions_data->HasHostPermission(GURL(chrome::kChromeUIThemeURL))) {
[email protected]b07e606e2012-09-15 20:16:15918 ThemeSource* theme_source = new ThemeSource(profile_);
[email protected]24ea7a12013-01-27 23:54:53919 content::URLDataSource::Add(profile_, theme_source);
[email protected]b07e606e2012-09-15 20:16:15920 }
[email protected]b07e606e2012-09-15 20:16:15921
[email protected]5eddc3e2011-10-26 04:33:31922 // Same for chrome://thumb/ resources.
[email protected]d695bb12014-06-05 16:16:30923 if (permissions_data->HasHostPermission(
924 GURL(chrome::kChromeUIThumbnailURL))) {
[email protected]420e6d92013-09-17 01:48:51925 ThumbnailSource* thumbnail_source = new ThumbnailSource(profile_, false);
[email protected]24ea7a12013-01-27 23:54:53926 content::URLDataSource::Add(profile_, thumbnail_source);
[email protected]5eddc3e2011-10-26 04:33:31927 }
[email protected]62d30f42009-10-01 22:36:06928}
929
Michael Giuffrida6397c592017-10-09 20:46:53930// TODO(michaelpg): Group with other ExtensionRegistrar::Delegate overrides
931// according to header file once diffs have settled down.
Michael Giuffrida023e3532017-09-28 23:21:21932void ExtensionService::PostDeactivateExtension(
933 scoped_refptr<const Extension> extension) {
[email protected]dcc47642014-03-26 22:03:49934 // TODO(kalman): Convert ExtensionSpecialStoragePolicy to a
935 // BrowserContextKeyedService and use ExtensionRegistryObserver.
Michael Giuffrida023e3532017-09-28 23:21:21936 profile_->GetExtensionSpecialStoragePolicy()->RevokeRightsForExtension(
937 extension.get());
[email protected]c8d407e2011-04-28 21:27:17938
[email protected]b777b332011-04-16 04:01:08939#if defined(OS_CHROMEOS)
[email protected]ac66e452013-01-11 09:21:23940 // Revoke external file access for the extension from its file system context.
941 // It is safe to access the extension's storage partition at this point. The
942 // storage partition may get destroyed only after the extension gets unloaded.
[email protected]3a746ec2014-03-15 05:30:56943 GURL site =
944 extensions::util::GetSiteForExtensionId(extension->id(), profile_);
[email protected]cd501a72014-08-22 19:58:31945 storage::FileSystemContext* filesystem_context =
946 BrowserContext::GetStoragePartitionForSite(profile_, site)
947 ->GetFileSystemContext();
[email protected]f19bbf62013-07-09 01:22:32948 if (filesystem_context && filesystem_context->external_backend()) {
Michael Giuffrida6397c592017-10-09 20:46:53949 filesystem_context->external_backend()->RevokeAccessForExtension(
950 extension->id());
[email protected]62d30f42009-10-01 22:36:06951 }
[email protected]c8d407e2011-04-28 21:27:17952#endif
953
[email protected]dcc47642014-03-26 22:03:49954 // TODO(kalman): This is broken. The crash reporter is process-wide so doesn't
955 // work properly multi-profile. Besides which, it should be using
956 // ExtensionRegistryObserver::OnExtensionLoaded. See http://crbug.com/355029.
[email protected]c8d407e2011-04-28 21:27:17957 UpdateActiveExtensionsInCrashReporter();
[email protected]62d30f42009-10-01 22:36:06958}
959
[email protected]599539802014-01-07 23:06:00960content::BrowserContext* ExtensionService::GetBrowserContext() const {
961 // Implemented in the .cc file to avoid adding a profile.h dependency to
962 // extension_service.h.
963 return profile_;
964}
965
[email protected]25ae0152011-11-18 14:40:02966bool ExtensionService::is_ready() {
[email protected]4a10006a2013-05-17 23:18:35967 return ready_->is_signaled();
[email protected]25ae0152011-11-18 14:40:02968}
969
[email protected]4ee07c62012-08-21 12:40:42970void ExtensionService::CheckManagementPolicy() {
Minh X. Nguyen45479012017-08-18 21:35:36971 std::map<std::string, extensions::disable_reason::DisableReason> to_disable;
binjin8e3d0182014-12-04 16:44:28972 std::vector<std::string> to_enable;
[email protected]695b5712012-12-06 23:55:28973
Karan Bhatia2a117232017-08-23 00:24:56974 // Loop through the extensions list, finding extensions we need to disable.
achuith2f5578b2016-02-26 21:57:13975 for (const auto& extension : registry_->enabled_extensions()) {
Minh X. Nguyen45479012017-08-18 21:35:36976 extensions::disable_reason::DisableReason disable_reason =
977 extensions::disable_reason::DISABLE_NONE;
[email protected]0d54b682013-11-05 14:15:36978 if (system_->management_policy()->MustRemainDisabled(
binjin8e3d0182014-12-04 16:44:28979 extension.get(), &disable_reason, nullptr))
[email protected]0d54b682013-11-05 14:15:36980 to_disable[extension->id()] = disable_reason;
[email protected]aa96d3a2010-08-21 08:45:25981 }
982
binjin8e3d0182014-12-04 16:44:28983 extensions::ExtensionManagement* management =
984 extensions::ExtensionManagementFactory::GetForBrowserContext(profile());
nrpetere33d2a5b2017-04-25 00:12:31985 extensions::PermissionsUpdater(profile()).SetDefaultPolicyHostRestrictions(
986 management->GetDefaultRuntimeBlockedHosts(),
987 management->GetDefaultRuntimeAllowedHosts());
988 for (const auto& extension : registry_->enabled_extensions()) {
989 bool uses_default =
990 management->UsesDefaultRuntimeHostRestrictions(extension.get());
991 if (uses_default) {
992 extensions::PermissionsUpdater(profile()).SetUsesDefaultHostRestrictions(
993 extension.get());
994 } else {
995 extensions::PermissionsUpdater(profile()).SetPolicyHostRestrictions(
996 extension.get(), management->GetRuntimeBlockedHosts(extension.get()),
997 management->GetRuntimeAllowedHosts(extension.get()));
998 }
999 }
binjin8e3d0182014-12-04 16:44:281000
1001 // Loop through the disabled extension list, find extensions to re-enable
Karan Bhatia2a117232017-08-23 00:24:561002 // automatically. These extensions are exclusive from the |to_disable| list
1003 // constructed above, since disabled_extensions() and enabled_extensions() are
1004 // supposed to be mutually exclusive.
achuith2f5578b2016-02-26 21:57:131005 for (const auto& extension : registry_->disabled_extensions()) {
Karan Bhatia2a117232017-08-23 00:24:561006 int disable_reasons = extension_prefs_->GetDisableReasons(extension->id());
binjin8e3d0182014-12-04 16:44:281007
Karan Bhatia2a117232017-08-23 00:24:561008 // Find all extensions disabled due to minimum version requirement and
1009 // management policy but now satisfying it.
1010 if (management->CheckMinimumVersion(extension.get(), nullptr)) {
1011 disable_reasons &=
1012 (~extensions::disable_reason::DISABLE_UPDATE_REQUIRED_BY_POLICY);
1013 }
1014
1015 if (!system_->management_policy()->MustRemainDisabled(extension.get(),
1016 nullptr, nullptr)) {
1017 disable_reasons &=
1018 (~extensions::disable_reason::DISABLE_BLOCKED_BY_POLICY);
1019 }
1020
1021 extension_prefs_->ReplaceDisableReasons(extension->id(), disable_reasons);
1022 if (disable_reasons == extensions::disable_reason::DISABLE_NONE)
1023 to_enable.push_back(extension->id());
1024 }
[email protected]0d54b682013-11-05 14:15:361025
achuith2f5578b2016-02-26 21:57:131026 for (const auto& i : to_disable)
1027 DisableExtension(i.first, i.second);
binjin8e3d0182014-12-04 16:44:281028
Karan Bhatia2a117232017-08-23 00:24:561029 // No extension is getting re-enabled here after disabling because |to_enable|
1030 // is mutually exclusive to |to_disable|.
binjin8e3d0182014-12-04 16:44:281031 for (const std::string& id : to_enable)
1032 EnableExtension(id);
1033
1034 if (updater_.get()) {
1035 // Find all extensions disabled due to minimum version requirement from
1036 // policy (including the ones that got disabled just now), and check
1037 // for update.
1038 extensions::ExtensionUpdater::CheckParams to_recheck;
achuith2f5578b2016-02-26 21:57:131039 for (const auto& extension : registry_->disabled_extensions()) {
binjin8e3d0182014-12-04 16:44:281040 if (extension_prefs_->GetDisableReasons(extension->id()) ==
Minh X. Nguyen45479012017-08-18 21:35:361041 extensions::disable_reason::DISABLE_UPDATE_REQUIRED_BY_POLICY) {
binjin8e3d0182014-12-04 16:44:281042 // The minimum version check is the only thing holding this extension
1043 // back, so check if it can be updated to fix that.
1044 to_recheck.ids.push_back(extension->id());
1045 }
1046 }
1047 if (!to_recheck.ids.empty())
1048 updater_->CheckNow(to_recheck);
1049 }
[email protected]aa96d3a2010-08-21 08:45:251050}
1051
[email protected]31206602011-04-13 23:07:321052void ExtensionService::CheckForUpdatesSoon() {
[email protected]90878c52014-04-04 18:21:021053 // This can legitimately happen in unit tests.
1054 if (!updater_.get())
1055 return;
1056
raphael.kubo.da.costa8527f942016-11-15 17:03:511057 updater_->CheckSoon();
[email protected]c3cfb012011-04-06 22:07:351058}
1059
[email protected]8e4560b62011-01-14 10:09:141060// Some extensions will autoupdate themselves externally from Chrome. These
rkaplowa8fd8d32015-02-25 21:27:561061// are typically part of some larger client application package. To support
1062// these, the extension will register its location in the preferences file
[email protected]8e4560b62011-01-14 10:09:141063// (and also, on Windows, in the registry) and this code will periodically
1064// check that location for a .crx file, which it will then install locally if
1065// a new version is available.
Devlin Cronin9722a722017-12-16 03:35:101066// Errors are reported through LoadErrorReporter. Success is not reported.
[email protected]eaa7dd182010-12-14 11:09:001067void ExtensionService::CheckForExternalUpdates() {
lazyboy77214d3c2017-04-04 16:46:121068 if (external_updates_disabled_for_test_)
1069 return;
1070
[email protected]a29a517a2011-01-21 21:11:121071 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
rkaplowa8fd8d32015-02-25 21:27:561072 TRACE_EVENT0("browser,startup", "ExtensionService::CheckForExternalUpdates");
1073 SCOPED_UMA_HISTOGRAM_TIMER("Extensions.CheckForExternalUpdatesTime");
[email protected]8e4560b62011-01-14 10:09:141074
1075 // Note that this installation is intentionally silent (since it didn't
1076 // go through the front-end). Extensions that are registered in this
1077 // way are effectively considered 'pre-bundled', and so implicitly
1078 // trusted. In general, if something has HKLM or filesystem access,
1079 // they could install an extension manually themselves anyway.
[email protected]a29a517a2011-01-21 21:11:121080
[email protected]8e4560b62011-01-14 10:09:141081 // Ask each external extension provider to give us a call back for each
1082 // extension they know about. See OnExternalExtension(File|UpdateUrl)Found.
achuith2f5578b2016-02-26 21:57:131083 for (const auto& provider : external_extension_providers_)
[email protected]8e4560b62011-01-14 10:09:141084 provider->VisitRegisteredExtension();
[email protected]8e4560b62011-01-14 10:09:141085
[email protected]50067e52011-10-20 23:17:071086 // Do any required work that we would have done after completion of all
1087 // providers.
[email protected]373daf972014-04-10 01:50:441088 if (external_extension_providers_.empty())
[email protected]50067e52011-10-20 23:17:071089 OnAllExternalProvidersReady();
[email protected]9f1087e2009-06-15 17:29:321090}
1091
[email protected]50067e52011-10-20 23:17:071092void ExtensionService::OnExternalProviderReady(
lazyboye8634172016-01-28 00:10:481093 const ExternalProviderInterface* provider) {
Istiaque Ahmedf6e72622017-09-08 23:14:171094 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]50067e52011-10-20 23:17:071095 CHECK(provider->IsReady());
[email protected]a29a517a2011-01-21 21:11:121096
1097 // An external provider has finished loading. We only take action
[email protected]8e4560b62011-01-14 10:09:141098 // if all of them are finished. So we check them first.
[email protected]94fde232012-04-27 10:22:301099 if (AreAllExternalProvidersReady())
1100 OnAllExternalProvidersReady();
1101}
1102
1103bool ExtensionService::AreAllExternalProvidersReady() const {
achuith2f5578b2016-02-26 21:57:131104 for (const auto& provider : external_extension_providers_) {
1105 if (!provider->IsReady())
[email protected]94fde232012-04-27 10:22:301106 return false;
[email protected]8e4560b62011-01-14 10:09:141107 }
[email protected]94fde232012-04-27 10:22:301108 return true;
[email protected]50067e52011-10-20 23:17:071109}
1110
1111void ExtensionService::OnAllExternalProvidersReady() {
Istiaque Ahmedf6e72622017-09-08 23:14:171112 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]94fde232012-04-27 10:22:301113 base::TimeDelta elapsed = base::Time::Now() - profile_->GetStartTime();
1114 UMA_HISTOGRAM_TIMES("Extension.ExternalProvidersReadyAfter", elapsed);
[email protected]50067e52011-10-20 23:17:071115
1116 // Install any pending extensions.
[email protected]94fde232012-04-27 10:22:301117 if (update_once_all_providers_are_ready_ && updater()) {
1118 update_once_all_providers_are_ready_ = false;
[email protected]4e9b59d2013-12-18 06:47:141119 extensions::ExtensionUpdater::CheckParams params;
1120 params.callback = external_updates_finished_callback_;
1121 updater()->CheckNow(params);
[email protected]8e4560b62011-01-14 10:09:141122 }
1123
1124 // Uninstall all the unclaimed extensions.
dchengc963c7142016-04-08 03:55:221125 std::unique_ptr<extensions::ExtensionPrefs::ExtensionsInfo> extensions_info(
[email protected]8e4560b62011-01-14 10:09:141126 extension_prefs_->GetInstalledExtensionsInfo());
1127 for (size_t i = 0; i < extensions_info->size(); ++i) {
1128 ExtensionInfo* info = extensions_info->at(i).get();
[email protected]1d5e58b2013-01-31 08:41:401129 if (Manifest::IsExternalLocation(info->extension_location))
[email protected]8e4560b62011-01-14 10:09:141130 CheckExternalUninstall(info->extension_id);
1131 }
[email protected]e5af875f2011-10-10 21:09:141132
[email protected]373daf972014-04-10 01:50:441133 error_controller_->ShowErrorIfNeeded();
[email protected]a9aa5932012-01-25 08:27:401134
[email protected]374ceb6f2014-07-02 19:25:341135 external_install_manager_->UpdateExternalExtensionAlert();
[email protected]e5af875f2011-10-10 21:09:141136}
1137
limasdf0deef2042017-05-03 19:17:171138void ExtensionService::UnloadExtension(const std::string& extension_id,
1139 UnloadedExtensionReason reason) {
Devlin Cronin5b35a082017-10-05 20:44:361140 extension_registrar_.RemoveExtension(extension_id, reason);
[email protected]631cf822009-05-15 07:01:251141}
1142
[email protected]8b1ec202013-09-05 02:09:501143void ExtensionService::RemoveComponentExtension(
1144 const std::string& extension_id) {
1145 scoped_refptr<const Extension> extension(
1146 GetExtensionById(extension_id, false));
limasdf0deef2042017-05-03 19:17:171147 UnloadExtension(extension_id, UnloadedExtensionReason::UNINSTALL);
[email protected]ebe07772014-05-22 04:16:061148 if (extension.get()) {
[email protected]e43c61f2014-07-20 21:46:341149 ExtensionRegistry::Get(profile_)->TriggerOnUninstalled(
dtseng9fb3d5b2015-02-23 17:24:171150 extension.get(), extensions::UNINSTALL_REASON_COMPONENT_REMOVED);
[email protected]ebe07772014-05-22 04:16:061151 }
[email protected]8b1ec202013-09-05 02:09:501152}
1153
[email protected]bb1bc9b32013-12-21 03:09:141154void ExtensionService::UnloadAllExtensionsForTest() {
1155 UnloadAllExtensionsInternal();
[email protected]9f1087e2009-06-15 17:29:321156}
1157
[email protected]bb1bc9b32013-12-21 03:09:141158void ExtensionService::ReloadExtensionsForTest() {
1159 // Calling UnloadAllExtensionsForTest here triggers a false-positive presubmit
1160 // warning about calling test code in production.
1161 UnloadAllExtensionsInternal();
[email protected]eac88332012-12-26 17:57:451162 component_loader_->LoadAll();
[email protected]d8c8f25f2011-11-02 18:18:011163 extensions::InstalledLoader(this).LoadAllExtensions();
rdevlin.croninf2e1cb012017-05-27 01:27:591164 OnInstalledExtensionsLoaded();
[email protected]4a10006a2013-05-17 23:18:351165 // Don't call SetReadyAndNotifyListeners() since tests call this multiple
1166 // times.
[email protected]9f1087e2009-06-15 17:29:321167}
1168
[email protected]820d9bd2013-04-03 03:46:031169void ExtensionService::SetReadyAndNotifyListeners() {
rkaplowa8fd8d32015-02-25 21:27:561170 TRACE_EVENT0("browser,startup",
1171 "ExtensionService::SetReadyAndNotifyListeners");
1172 SCOPED_UMA_HISTOGRAM_TIMER(
1173 "Extensions.ExtensionServiceNotifyReadyListenersTime");
1174
[email protected]4a10006a2013-05-17 23:18:351175 ready_->Signal();
[email protected]820d9bd2013-04-03 03:46:031176 content::NotificationService::current()->Notify(
[email protected]adf5a102014-07-31 12:44:061177 extensions::NOTIFICATION_EXTENSIONS_READY_DEPRECATED,
[email protected]820d9bd2013-04-03 03:46:031178 content::Source<Profile>(profile_),
1179 content::NotificationService::NoDetails());
1180}
1181
[email protected]fcb58a862012-05-01 01:03:151182void ExtensionService::AddExtension(const Extension* extension) {
rdevlin.cronin08ada0f2017-03-09 23:29:521183 if (!Manifest::IsValidLocation(extension->location())) {
1184 // TODO(devlin): We should *never* add an extension with an invalid
1185 // location, but some bugs (e.g. crbug.com/692069) seem to indicate we do.
1186 // Track down the cases when this can happen, and remove this
1187 // DumpWithoutCrashing() (possibly replacing it with a CHECK).
1188 NOTREACHED();
Lukasz Anforowicz68c21772018-01-13 03:42:441189 DEBUG_ALIAS_FOR_CSTR(extension_id_copy, extension->id().c_str(), 33);
rdevlin.cronin08ada0f2017-03-09 23:29:521190 Manifest::Location location = extension->location();
1191 int creation_flags = extension->creation_flags();
1192 Manifest::Type type = extension->manifest()->type();
rdevlin.cronin08ada0f2017-03-09 23:29:521193 base::debug::Alias(&location);
1194 base::debug::Alias(&creation_flags);
1195 base::debug::Alias(&type);
1196 base::debug::DumpWithoutCrashing();
1197 return;
1198 }
1199
[email protected]c8d407e2011-04-28 21:27:171200 // TODO(jstritar): We may be able to get rid of this branch by overriding the
1201 // default extension state to DISABLED when the --disable-extensions flag
1202 // is set (http://crbug.com/29067).
Devlin Croninefe0c882018-04-20 00:06:481203 if (!extensions_enabled_ &&
1204 !Manifest::ShouldAlwaysLoadExtension(extension->location(),
1205 extension->GetType()) &&
catmullings98cd1942016-08-30 22:31:591206 disable_flag_exempted_extensions_.count(extension->id()) == 0) {
[email protected]fcb58a862012-05-01 01:03:151207 return;
[email protected]330840c2012-08-29 22:21:011208 }
[email protected]c8d407e2011-04-28 21:27:171209
Michael Giuffrida573992d2018-02-08 00:48:441210 extension_registrar_.AddExtension(extension);
Michael Giuffrida023e3532017-09-28 23:21:211211
Michael Giuffrida573992d2018-02-08 00:48:441212 if (registry_->disabled_extensions().Contains(extension->id())) {
1213 // Show the extension disabled error if a permissions increase or a remote
1214 // installation is the reason it was disabled, and no other reasons exist.
1215 int reasons = extension_prefs_->GetDisableReasons(extension->id());
1216 const int kReasonMask =
1217 extensions::disable_reason::DISABLE_PERMISSIONS_INCREASE |
1218 extensions::disable_reason::DISABLE_REMOTE_INSTALL;
1219 if (reasons & kReasonMask && !(reasons & ~kReasonMask)) {
1220 AddExtensionDisabledError(
1221 this, extension,
1222 extension_prefs_->HasDisableReason(
1223 extension->id(),
1224 extensions::disable_reason::DISABLE_REMOTE_INSTALL));
Michael Giuffrida6397c592017-10-09 20:46:531225 }
[email protected]f574c402012-12-04 23:20:311226 }
[email protected]aab98a52009-12-02 03:22:351227}
1228
[email protected]8c484b742012-11-29 06:05:361229void ExtensionService::AddComponentExtension(const Extension* extension) {
1230 const std::string old_version_string(
1231 extension_prefs_->GetVersionString(extension->id()));
pwnallcbd73192016-08-22 18:59:171232 const base::Version old_version(old_version_string);
[email protected]8c484b742012-11-29 06:05:361233
[email protected]0181a7d2013-11-12 01:08:421234 VLOG(1) << "AddComponentExtension " << extension->name();
Devlin Cronin03bf2d22017-12-20 08:21:051235 if (!old_version.IsValid() || old_version != extension->version()) {
[email protected]8c484b742012-11-29 06:05:361236 VLOG(1) << "Component extension " << extension->name() << " ("
Devlin Cronin03bf2d22017-12-20 08:21:051237 << extension->id() << ") installing/upgrading from '"
1238 << old_version_string << "' to "
1239 << extension->version().GetString();
[email protected]8c484b742012-11-29 06:05:361240
Karandeep Bhatiaa8930652017-10-11 17:41:121241 // TODO(crbug.com/696822): If needed, add support for Declarative Net
1242 // Request to component extensions and pass the ruleset checksum here.
1243 AddNewOrUpdatedExtension(
1244 extension, Extension::ENABLED, extensions::kInstallFlagNone,
1245 syncer::StringOrdinal(), std::string(), base::nullopt);
[email protected]8c484b742012-11-29 06:05:361246 return;
1247 }
1248
1249 AddExtension(extension);
1250}
1251
[email protected]b914e2952013-04-26 07:10:031252void ExtensionService::CheckPermissionsIncrease(const Extension* extension,
treib6e51bca2016-06-15 10:26:031253 bool is_extension_loaded) {
[email protected]23a85362014-07-07 23:26:191254 extensions::PermissionsUpdater(profile_).InitializePermissions(extension);
[email protected]902fd7b2011-07-27 18:42:311255
[email protected]8d888c12010-11-30 00:00:251256 // We keep track of all permissions the user has granted each extension.
1257 // This allows extensions to gracefully support backwards compatibility
1258 // by including unknown permissions in their manifests. When the user
1259 // installs the extension, only the recognized permissions are recorded.
1260 // When the unknown permissions become recognized (e.g., through browser
1261 // upgrade), we can prompt the user to accept these new permissions.
1262 // Extensions can also silently upgrade to less permissions, and then
1263 // silently upgrade to a version that adds these permissions back.
1264 //
1265 // For example, pretend that Chrome 10 includes a permission "omnibox"
1266 // for an API that adds suggestions to the omnibox. An extension can
1267 // maintain backwards compatibility while still having "omnibox" in the
1268 // manifest. If a user installs the extension on Chrome 9, the browser
1269 // will record the permissions it recognized, not including "omnibox."
1270 // When upgrading to Chrome 10, "omnibox" will be recognized and Chrome
1271 // will disable the extension and prompt the user to approve the increase
1272 // in privileges. The extension could then release a new version that
1273 // removes the "omnibox" permission. When the user upgrades, Chrome will
1274 // still remember that "omnibox" had been granted, so that if the
1275 // extension once again includes "omnibox" in an upgrade, the extension
1276 // can upgrade without requiring this user's approval.
[email protected]eb5e4f92012-08-15 23:33:281277 int disable_reasons = extension_prefs_->GetDisableReasons(extension->id());
[email protected]8d888c12010-11-30 00:00:251278
rockot1d4a06262015-02-17 19:39:281279 // Silently grant all active permissions to default apps and apps installed
1280 // in kiosk mode.
[email protected]211a3f32013-05-28 21:48:181281 bool auto_grant_permission =
rockot1d4a06262015-02-17 19:39:281282 extension->was_installed_by_default() ||
[email protected]45928b682013-11-28 08:20:271283 extensions::ExtensionsBrowserClient::Get()->IsRunningInForcedAppMode();
[email protected]211a3f32013-05-28 21:48:181284 if (auto_grant_permission)
[email protected]b914e2952013-04-26 07:10:031285 GrantPermissions(extension);
1286
1287 bool is_privilege_increase = false;
1288 // We only need to compare the granted permissions to the current permissions
rockot1d4a06262015-02-17 19:39:281289 // if the extension has not been auto-granted its permissions above and is
1290 // installed internally.
1291 if (extension->location() == Manifest::INTERNAL && !auto_grant_permission) {
[email protected]8d888c12010-11-30 00:00:251292 // Add all the recognized permissions if the granted permissions list
1293 // hasn't been initialized yet.
dchengc963c7142016-04-08 03:55:221294 std::unique_ptr<const PermissionSet> granted_permissions =
[email protected]902fd7b2011-07-27 18:42:311295 extension_prefs_->GetGrantedPermissions(extension->id());
[email protected]0d3e4a22011-06-23 19:02:521296 CHECK(granted_permissions.get());
[email protected]8d888c12010-11-30 00:00:251297
1298 // Here, we check if an extension's privileges have increased in a manner
1299 // that requires the user's approval. This could occur because the browser
1300 // upgraded and recognized additional privileges, or an extension upgrades
1301 // to a version that requires additional privileges.
[email protected]c41003472013-10-19 15:37:251302 is_privilege_increase =
1303 extensions::PermissionMessageProvider::Get()->IsPrivilegeIncrease(
rdevlin.cronind630c302015-09-30 20:19:331304 *granted_permissions,
rdevlin.cronine2d0fd02015-09-24 22:35:491305 extension->permissions_data()->active_permissions(),
[email protected]076ebeda2014-06-06 21:47:261306 extension->GetType());
treib2c20f9442016-05-18 19:50:281307
1308 // If there was no privilege increase, the extension might still have new
1309 // permissions (which either don't generate a warning message, or whose
1310 // warning messages are suppressed by existing permissions). Grant the new
1311 // permissions.
1312 if (!is_privilege_increase)
1313 GrantPermissions(extension);
[email protected]8d888c12010-11-30 00:00:251314 }
1315
treib6e51bca2016-06-15 10:26:031316 bool previously_disabled =
1317 extension_prefs_->IsExtensionDisabled(extension->id());
1318 // TODO(treib): Is the |is_extension_loaded| check needed here?
1319 if (is_extension_loaded && previously_disabled) {
treib8a6d9892015-08-26 10:23:191320 // Legacy disabled extensions do not have a disable reason. Infer that it
1321 // was likely disabled by the user.
Minh X. Nguyen45479012017-08-18 21:35:361322 if (disable_reasons == extensions::disable_reason::DISABLE_NONE)
1323 disable_reasons |= extensions::disable_reason::DISABLE_USER_ACTION;
treib8a6d9892015-08-26 10:23:191324
[email protected]7e9e2422012-12-13 19:54:191325 // Extensions that came to us disabled from sync need a similar inference,
1326 // except based on the new version's permissions.
Minh X. Nguyen45479012017-08-18 21:35:361327 // TODO(treib,devlin): Since M48,
1328 // extensions::disable_reason::DISABLE_UNKNOWN_FROM_SYNC isn't used anymore;
1329 // this code is still here to migrate any existing old state. Remove it
1330 // after some grace period.
1331 if (disable_reasons &
1332 extensions::disable_reason::DEPRECATED_DISABLE_UNKNOWN_FROM_SYNC) {
1333 // Remove the extensions::disable_reason::DISABLE_UNKNOWN_FROM_SYNC
1334 // reason.
1335 disable_reasons &=
1336 ~extensions::disable_reason::DEPRECATED_DISABLE_UNKNOWN_FROM_SYNC;
treib8a6d9892015-08-26 10:23:191337 extension_prefs_->RemoveDisableReason(
Minh X. Nguyen45479012017-08-18 21:35:361338 extension->id(),
1339 extensions::disable_reason::DEPRECATED_DISABLE_UNKNOWN_FROM_SYNC);
treib8a6d9892015-08-26 10:23:191340 // If there was no privilege increase, it was likely disabled by the user.
[email protected]7e9e2422012-12-13 19:54:191341 if (!is_privilege_increase)
Minh X. Nguyen45479012017-08-18 21:35:361342 disable_reasons |= extensions::disable_reason::DISABLE_USER_ACTION;
[email protected]7e9e2422012-12-13 19:54:191343 }
[email protected]8d888c12010-11-30 00:00:251344 }
1345
treib6e51bca2016-06-15 10:26:031346 // If the extension is disabled due to a permissions increase, but does in
1347 // fact have all permissions, remove that disable reason.
1348 // TODO(devlin): This was added to fix crbug.com/616474, but it's unclear
1349 // if this behavior should stay forever.
Minh X. Nguyen45479012017-08-18 21:35:361350 if (disable_reasons &
1351 extensions::disable_reason::DISABLE_PERMISSIONS_INCREASE) {
treib6e51bca2016-06-15 10:26:031352 bool reset_permissions_increase = false;
1353 if (!is_privilege_increase) {
1354 reset_permissions_increase = true;
Minh X. Nguyen45479012017-08-18 21:35:361355 disable_reasons &=
1356 ~extensions::disable_reason::DISABLE_PERMISSIONS_INCREASE;
treib6e51bca2016-06-15 10:26:031357 extension_prefs_->RemoveDisableReason(
Minh X. Nguyen45479012017-08-18 21:35:361358 extension->id(),
1359 extensions::disable_reason::DISABLE_PERMISSIONS_INCREASE);
treib6e51bca2016-06-15 10:26:031360 }
1361 UMA_HISTOGRAM_BOOLEAN("Extensions.ResetPermissionsIncrease",
1362 reset_permissions_increase);
1363 }
1364
[email protected]8d888c12010-11-30 00:00:251365 // Extension has changed permissions significantly. Disable it. A
[email protected]21db9ef2014-05-16 02:06:271366 // notification should be sent by the caller. If the extension is already
1367 // disabled because it was installed remotely, don't add another disable
treibaac30ec2015-06-10 09:18:091368 // reason.
1369 if (is_privilege_increase &&
Minh X. Nguyen45479012017-08-18 21:35:361370 !(disable_reasons & extensions::disable_reason::DISABLE_REMOTE_INSTALL)) {
1371 disable_reasons |= extensions::disable_reason::DISABLE_PERMISSIONS_INCREASE;
treib8a6d9892015-08-26 10:23:191372 if (!extension_prefs_->DidExtensionEscalatePermissions(extension->id()))
treib2e0517f92015-05-07 23:15:361373 RecordPermissionMessagesHistogram(extension, "AutoDisable");
treib8ecc1eb52015-03-04 18:29:061374
brettw9e85ef42016-11-01 21:01:241375#if BUILDFLAG(ENABLE_SUPERVISED_USERS)
treib8ecc1eb52015-03-04 18:29:061376 // If a custodian-installed extension is disabled for a supervised user due
mamir51e05d02016-10-06 10:55:011377 // to a permissions increase, send a request to the custodian.
treib3202d592015-07-31 08:33:161378 if (extensions::util::IsExtensionSupervised(extension, profile_) &&
treib40d3ad92015-10-20 18:15:421379 !ExtensionSyncService::Get(profile_)->HasPendingReenable(
Devlin Cronin03bf2d22017-12-20 08:21:051380 extension->id(), extension->version())) {
treib8ecc1eb52015-03-04 18:29:061381 SupervisedUserService* supervised_user_service =
1382 SupervisedUserServiceFactory::GetForProfile(profile_);
treib40d3ad92015-10-20 18:15:421383 supervised_user_service->AddExtensionUpdateRequest(extension->id(),
Devlin Cronin03bf2d22017-12-20 08:21:051384 extension->version());
treib8ecc1eb52015-03-04 18:29:061385 }
1386#endif
[email protected]b914e2952013-04-26 07:10:031387 }
treib6e51bca2016-06-15 10:26:031388
Minh X. Nguyen45479012017-08-18 21:35:361389 if (disable_reasons == extensions::disable_reason::DISABLE_NONE)
treib6e51bca2016-06-15 10:26:031390 extension_prefs_->SetExtensionEnabled(extension->id());
1391 else
treib8a6d9892015-08-26 10:23:191392 extension_prefs_->SetExtensionDisabled(extension->id(), disable_reasons);
[email protected]8d888c12010-11-30 00:00:251393}
1394
[email protected]eaa7dd182010-12-14 11:09:001395void ExtensionService::UpdateActiveExtensionsInCrashReporter() {
[email protected]c8865962009-12-16 07:47:391396 std::set<std::string> extension_ids;
achuith2f5578b2016-02-26 21:57:131397 for (const auto& extension : registry_->enabled_extensions()) {
[email protected]1d5e58b2013-01-31 08:41:401398 if (!extension->is_theme() && extension->location() != Manifest::COMPONENT)
[email protected]84df8332011-12-06 18:22:461399 extension_ids.insert(extension->id());
[email protected]aab98a52009-12-02 03:22:351400 }
1401
[email protected]dcc47642014-03-26 22:03:491402 // TODO(kalman): This is broken. ExtensionService is per-profile.
1403 // crash_keys::SetActiveExtensions is per-process. See
1404 // http://crbug.com/355029.
[email protected]f6431be82013-09-07 02:53:451405 crash_keys::SetActiveExtensions(extension_ids);
[email protected]6014d672008-12-05 00:38:251406}
1407
[email protected]8266d662011-07-12 21:53:261408void ExtensionService::OnExtensionInstalled(
[email protected]36a5c4c2011-12-14 16:34:501409 const Extension* extension,
[email protected]98270432012-09-11 20:51:241410 const syncer::StringOrdinal& page_ordinal,
Karandeep Bhatiaa8930652017-10-11 17:41:121411 int install_flags,
1412 const base::Optional<int>& dnr_ruleset_checksum) {
[email protected]a29a517a2011-01-21 21:11:121413 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]a8af9fdb2010-10-28 21:52:201414
[email protected]c3cfb012011-04-06 22:07:351415 const std::string& id = extension->id();
binjin47947f842014-11-18 12:10:241416 int disable_reasons = GetDisableReasonsOnInstalled(extension);
[email protected]d8fd0fd2014-03-24 13:16:061417 std::string install_parameter;
[email protected]96aebe22014-07-16 04:07:511418 const extensions::PendingExtensionInfo* pending_extension_info =
1419 pending_extension_manager()->GetById(id);
1420 if (pending_extension_info) {
[email protected]8f3bcbd2013-06-05 08:42:401421 if (!pending_extension_info->ShouldAllowInstall(extension)) {
treib227b2582015-12-09 09:28:261422 // Hack for crbug.com/558299, see comment on DeleteThemeDoNotUse.
1423 if (extension->is_theme() && pending_extension_info->is_from_sync())
1424 ExtensionSyncService::Get(profile_)->DeleteThemeDoNotUse(*extension);
1425
[email protected]51a3bf8b2012-06-08 22:53:061426 pending_extension_manager()->Remove(id);
[email protected]8ef78fd2010-08-19 17:14:321427
[email protected]31bb5ee62012-09-12 22:58:401428 LOG(WARNING) << "ShouldAllowInstall() returned false for "
1429 << id << " of type " << extension->GetType()
[email protected]65348062013-01-15 07:27:221430 << " and update URL "
1431 << extensions::ManifestURL::GetUpdateURL(extension).spec()
[email protected]31bb5ee62012-09-12 22:58:401432 << "; not installing";
[email protected]ae6cb3022011-04-04 20:11:541433
[email protected]4416c5a2010-06-26 01:28:571434 // Delete the extension directory since we're not going to
1435 // load it.
Devlin Croninad3c52b2017-08-10 01:49:371436 if (!extensions::GetExtensionFileTaskRunner()->PostTask(
tzik8d880ee2017-04-20 19:46:241437 FROM_HERE, base::BindOnce(&extensions::file_util::DeleteFile,
1438 extension->path(), true))) {
[email protected]14908b72011-04-20 06:54:361439 NOTREACHED();
[email protected]31bb5ee62012-09-12 22:58:401440 }
[email protected]4416c5a2010-06-26 01:28:571441 return;
1442 }
[email protected]51a3bf8b2012-06-08 22:53:061443
[email protected]d8fd0fd2014-03-24 13:16:061444 install_parameter = pending_extension_info->install_parameter();
[email protected]51a3bf8b2012-06-08 22:53:061445 pending_extension_manager()->Remove(id);
[email protected]4416c5a2010-06-26 01:28:571446 } else {
[email protected]c3cfb012011-04-06 22:07:351447 // We explicitly want to re-enable an uninstalled external
1448 // extension; if we're here, that means the user is manually
1449 // installing the extension.
[email protected]46f3e102014-03-25 01:22:451450 if (extension_prefs_->IsExternalExtensionUninstalled(id)) {
Minh X. Nguyen45479012017-08-18 21:35:361451 disable_reasons = extensions::disable_reason::DISABLE_NONE;
[email protected]6cc7dbae2011-04-29 21:18:331452 }
[email protected]aa142702010-03-26 01:26:331453 }
1454
asargente4de9f92016-09-15 01:40:061455 // If the old version of the extension was disabled due to corruption, this
1456 // new install may correct the problem.
Minh X. Nguyen45479012017-08-18 21:35:361457 disable_reasons &= ~extensions::disable_reason::DISABLE_CORRUPTED;
asargente4de9f92016-09-15 01:40:061458
[email protected]98270432012-09-11 20:51:241459 // Unsupported requirements overrides the management policy.
[email protected]4a1d9c0d2014-06-13 12:50:111460 if (install_flags & extensions::kInstallFlagHasRequirementErrors) {
Minh X. Nguyen45479012017-08-18 21:35:361461 disable_reasons |=
1462 extensions::disable_reason::DISABLE_UNSUPPORTED_REQUIREMENT;
binjin8e3d0182014-12-04 16:44:281463 } else {
1464 // Requirement is supported now, remove the corresponding disable reason
1465 // instead.
Minh X. Nguyen45479012017-08-18 21:35:361466 disable_reasons &=
1467 ~extensions::disable_reason::DISABLE_UNSUPPORTED_REQUIREMENT;
binjin8e3d0182014-12-04 16:44:281468 }
1469
1470 // Check if the extension was disabled because of the minimum version
1471 // requirements from enterprise policy, and satisfies it now.
1472 if (extensions::ExtensionManagementFactory::GetForBrowserContext(profile())
1473 ->CheckMinimumVersion(extension, nullptr)) {
1474 // And remove the corresponding disable reason.
Minh X. Nguyen45479012017-08-18 21:35:361475 disable_reasons &=
1476 ~extensions::disable_reason::DISABLE_UPDATE_REQUIRED_BY_POLICY;
[email protected]98270432012-09-11 20:51:241477 }
1478
[email protected]4a1d9c0d2014-06-13 12:50:111479 if (install_flags & extensions::kInstallFlagIsBlacklistedForMalware) {
[email protected]9f3c8532013-07-31 19:52:071480 // Installation of a blacklisted extension can happen from sync, policy,
1481 // etc, where to maintain consistency we need to install it, just never
1482 // load it (see AddExtension). Usually it should be the job of callers to
treibaac30ec2015-06-10 09:18:091483 // intercept blacklisted extensions earlier (e.g. CrxInstaller, before even
[email protected]9f3c8532013-07-31 19:52:071484 // showing the install dialogue).
[email protected]7c82539c2014-02-19 06:09:171485 extension_prefs_->AcknowledgeBlacklistedExtension(id);
[email protected]9f3c8532013-07-31 19:52:071486 UMA_HISTOGRAM_ENUMERATION("ExtensionBlacklist.SilentInstall",
1487 extension->location(),
1488 Manifest::NUM_LOCATIONS);
1489 }
1490
[email protected]695b5712012-12-06 23:55:281491 if (!GetInstalledExtension(extension->id())) {
[email protected]07533022011-06-27 20:42:551492 UMA_HISTOGRAM_ENUMERATION("Extensions.InstallType",
1493 extension->GetType(), 100);
[email protected]69084dc2012-11-17 07:39:301494 UMA_HISTOGRAM_ENUMERATION("Extensions.InstallSource",
[email protected]1d5e58b2013-01-31 08:41:401495 extension->location(), Manifest::NUM_LOCATIONS);
treib2e0517f92015-05-07 23:15:361496 RecordPermissionMessagesHistogram(extension, "Install");
[email protected]69084dc2012-11-17 07:39:301497 } else {
1498 UMA_HISTOGRAM_ENUMERATION("Extensions.UpdateType",
1499 extension->GetType(), 100);
1500 UMA_HISTOGRAM_ENUMERATION("Extensions.UpdateSource",
[email protected]1d5e58b2013-01-31 08:41:401501 extension->location(), Manifest::NUM_LOCATIONS);
[email protected]07533022011-06-27 20:42:551502 }
1503
[email protected]399583b2012-12-11 09:33:421504 const Extension::State initial_state =
Minh X. Nguyen45479012017-08-18 21:35:361505 disable_reasons == extensions::disable_reason::DISABLE_NONE
1506 ? Extension::ENABLED
1507 : Extension::DISABLED;
treib8a6d9892015-08-26 10:23:191508 if (initial_state == Extension::ENABLED)
1509 extension_prefs_->SetExtensionEnabled(id);
1510 else
1511 extension_prefs_->SetExtensionDisabled(id, disable_reasons);
binjin47947f842014-11-18 12:10:241512
xiyuanf6a4c6a62016-04-19 18:14:541513 extensions::ExtensionPrefs::DelayReason delay_reason;
1514 extensions::InstallGate::Action action = ShouldDelayExtensionInstall(
1515 extension, !!(install_flags & extensions::kInstallFlagInstallImmediately),
1516 &delay_reason);
1517 switch (action) {
1518 case extensions::InstallGate::INSTALL:
1519 AddNewOrUpdatedExtension(extension, initial_state, install_flags,
Karandeep Bhatiaa8930652017-10-11 17:41:121520 page_ordinal, install_parameter,
1521 dnr_ruleset_checksum);
xiyuanf6a4c6a62016-04-19 18:14:541522 return;
1523 case extensions::InstallGate::DELAY:
Karandeep Bhatiaa8930652017-10-11 17:41:121524 extension_prefs_->SetDelayedInstallInfo(
1525 extension, initial_state, install_flags, delay_reason, page_ordinal,
1526 install_parameter, dnr_ruleset_checksum);
[email protected]0db124b02012-11-07 04:55:051527
xiyuanf6a4c6a62016-04-19 18:14:541528 // Transfer ownership of |extension|.
[email protected]9f4e4f082013-06-21 07:11:191529 delayed_installs_.Insert(extension);
xiyuanf6a4c6a62016-04-19 18:14:541530
1531 if (delay_reason ==
1532 extensions::ExtensionPrefs::DELAY_REASON_WAIT_FOR_IDLE) {
1533 // Notify observers that app update is available.
ericwilligersb5f79de2016-10-19 04:15:101534 for (auto& observer : update_observers_)
1535 observer.OnAppUpdateAvailable(extension);
xiyuanf6a4c6a62016-04-19 18:14:541536 }
1537 return;
1538 case extensions::InstallGate::ABORT:
1539 // Do nothing to abort the install. One such case is the shared module
1540 // service gets IMPORT_STATUS_UNRECOVERABLE status for the pending
1541 // install.
1542 return;
[email protected]399583b2012-12-11 09:33:421543 }
xiyuanf6a4c6a62016-04-19 18:14:541544
1545 NOTREACHED() << "Unknown action for delayed install: " << action;
[email protected]8c484b742012-11-29 06:05:361546}
1547
binjin1569c9b2014-09-05 13:33:181548void ExtensionService::OnExtensionManagementSettingsChanged() {
1549 error_controller_->ShowErrorIfNeeded();
binjine6b58b52014-10-31 01:55:571550
1551 // Revokes blocked permissions from active_permissions for all extensions.
1552 extensions::ExtensionManagement* settings =
1553 extensions::ExtensionManagementFactory::GetForBrowserContext(profile());
1554 CHECK(settings);
dchengc963c7142016-04-08 03:55:221555 std::unique_ptr<ExtensionSet> all_extensions(
binjine6b58b52014-10-31 01:55:571556 registry_->GenerateInstalledExtensionsSet());
achuith2f5578b2016-02-26 21:57:131557 for (const auto& extension : *all_extensions) {
binjine6b58b52014-10-31 01:55:571558 if (!settings->IsPermissionSetAllowed(
binjin685ade82014-11-06 09:53:561559 extension.get(),
Nick Peterson0203be4a2017-07-19 00:25:141560 extension->permissions_data()->active_permissions()) &&
1561 CanBlockExtension(extension.get())) {
rdevlin.cronin77cb0ef2015-09-16 17:03:481562 extensions::PermissionsUpdater(profile()).RemovePermissionsUnsafe(
rdevlin.cronind630c302015-09-30 20:19:331563 extension.get(), *settings->GetBlockedPermissions(extension.get()));
binjine6b58b52014-10-31 01:55:571564 }
1565 }
1566
binjin1569c9b2014-09-05 13:33:181567 CheckManagementPolicy();
1568}
1569
[email protected]8c484b742012-11-29 06:05:361570void ExtensionService::AddNewOrUpdatedExtension(
1571 const Extension* extension,
[email protected]399583b2012-12-11 09:33:421572 Extension::State initial_state,
[email protected]4a1d9c0d2014-06-13 12:50:111573 int install_flags,
[email protected]d8fd0fd2014-03-24 13:16:061574 const syncer::StringOrdinal& page_ordinal,
Karandeep Bhatiaa8930652017-10-11 17:41:121575 const std::string& install_parameter,
1576 const base::Optional<int>& dnr_ruleset_checksum) {
[email protected]8c484b742012-11-29 06:05:361577 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
Karandeep Bhatiaa8930652017-10-11 17:41:121578 extension_prefs_->OnExtensionInstalled(extension, initial_state, page_ordinal,
1579 install_flags, install_parameter,
1580 dnr_ruleset_checksum);
[email protected]9e9c1d12013-07-31 01:58:121581 delayed_installs_.Remove(extension->id());
[email protected]913ffca92014-03-27 15:26:161582 if (InstallVerifier::NeedsVerification(*extension))
juncai33e462102015-05-18 20:48:441583 InstallVerifier::Get(GetBrowserContext())->VerifyExtension(extension->id());
ryanackley48bedbd2015-01-27 23:12:141584
1585 const Extension* old = GetInstalledExtension(extension->id());
1586 if (extensions::AppDataMigrator::NeedsMigration(old, extension)) {
1587 app_data_migrator_->DoMigrationAndReply(
vmpstra34d11322016-03-21 20:28:471588 old, extension, base::Bind(&ExtensionService::FinishInstallation,
1589 AsWeakPtr(), base::RetainedRef(extension)));
ryanackley48bedbd2015-01-27 23:12:141590 return;
1591 }
1592
benwells1dd4acd2015-12-09 02:20:241593 FinishInstallation(extension);
[email protected]6f6101832012-11-27 22:10:481594}
1595
Toni Barzic667db0d32018-01-09 18:00:191596bool ExtensionService::FinishDelayedInstallationIfReady(
1597 const std::string& extension_id,
1598 bool install_immediately) {
[email protected]9f4e4f082013-06-21 07:11:191599 // Check if the extension already got installed.
[email protected]9f4e4f082013-06-21 07:11:191600 const Extension* extension = delayed_installs_.GetByID(extension_id);
xiyuanf6a4c6a62016-04-19 18:14:541601 if (!extension)
Toni Barzic667db0d32018-01-09 18:00:191602 return false;
xiyuanf6a4c6a62016-04-19 18:14:541603
1604 extensions::ExtensionPrefs::DelayReason reason;
Toni Barzic667db0d32018-01-09 18:00:191605 const extensions::InstallGate::Action action =
1606 ShouldDelayExtensionInstall(extension, install_immediately, &reason);
xiyuanf6a4c6a62016-04-19 18:14:541607 switch (action) {
1608 case extensions::InstallGate::INSTALL:
1609 break;
1610 case extensions::InstallGate::DELAY:
1611 // Bail out and continue to delay the install.
Toni Barzic667db0d32018-01-09 18:00:191612 return false;
xiyuanf6a4c6a62016-04-19 18:14:541613 case extensions::InstallGate::ABORT:
1614 delayed_installs_.Remove(extension_id);
1615 // Make sure no version of the extension is actually installed, (i.e.,
1616 // that this delayed install was not an update).
1617 CHECK(!extension_prefs_->GetInstalledExtensionInfo(extension_id).get());
1618 extension_prefs_->DeleteExtensionPrefs(extension_id);
Toni Barzic667db0d32018-01-09 18:00:191619 return false;
[email protected]9f4e4f082013-06-21 07:11:191620 }
1621
Toni Barzic667db0d32018-01-09 18:00:191622 scoped_refptr<const Extension> delayed_install =
1623 GetPendingExtensionUpdate(extension_id);
1624 CHECK(delayed_install.get());
[email protected]9f4e4f082013-06-21 07:11:191625 delayed_installs_.Remove(extension_id);
[email protected]6f6101832012-11-27 22:10:481626
[email protected]399583b2012-12-11 09:33:421627 if (!extension_prefs_->FinishDelayedInstallInfo(extension_id))
[email protected]6f6101832012-11-27 22:10:481628 NOTREACHED();
1629
Toni Barzic667db0d32018-01-09 18:00:191630 FinishInstallation(delayed_install.get());
1631 return true;
[email protected]6f6101832012-11-27 22:10:481632}
1633
[email protected]760f743b2014-05-28 13:52:021634void ExtensionService::FinishInstallation(
benwells1dd4acd2015-12-09 02:20:241635 const Extension* extension) {
[email protected]e7554c3f2013-05-29 00:36:561636 const extensions::Extension* existing_extension =
1637 GetInstalledExtension(extension->id());
1638 bool is_update = false;
1639 std::string old_name;
1640 if (existing_extension) {
1641 is_update = true;
1642 old_name = existing_extension->name();
1643 }
[email protected]bc44b5da2014-06-12 14:20:001644 registry_->TriggerOnWillBeInstalled(
benwells1dd4acd2015-12-09 02:20:241645 extension, is_update, old_name);
[email protected]17f07822014-05-22 08:45:151646
[email protected]399583b2012-12-11 09:33:421647 // Unpacked extensions default to allowing file access, but if that has been
1648 // overridden, don't reset the value.
[email protected]1d5e58b2013-01-31 08:41:401649 if (Manifest::ShouldAlwaysAllowFileAccess(extension->location()) &&
[email protected]399583b2012-12-11 09:33:421650 !extension_prefs_->HasAllowFileAccessSetting(extension->id())) {
1651 extension_prefs_->SetAllowFileAccess(extension->id(), true);
1652 }
1653
[email protected]6f6101832012-11-27 22:10:481654 AddExtension(extension);
[email protected]612a1cb12012-10-17 13:18:031655
[email protected]bc44b5da2014-06-12 14:20:001656 // Notify observers that need to know when an installation is complete.
[email protected]38e872532014-07-16 23:27:511657 registry_->TriggerOnInstalled(extension, is_update);
[email protected]bc44b5da2014-06-12 14:20:001658
[email protected]9f4e4f082013-06-21 07:11:191659 // Check extensions that may have been delayed only because this shared module
1660 // was not available.
[email protected]374ceb6f2014-07-02 19:25:341661 if (SharedModuleInfo::IsSharedModule(extension))
[email protected]9f4e4f082013-06-21 07:11:191662 MaybeFinishDelayedInstallations();
[email protected]4a190632009-05-09 01:07:421663}
1664
[email protected]76b65442012-11-17 14:11:481665const Extension* ExtensionService::GetPendingExtensionUpdate(
1666 const std::string& id) const {
[email protected]9f4e4f082013-06-21 07:11:191667 return delayed_installs_.GetByID(id);
[email protected]76b65442012-11-17 14:11:481668}
1669
mukai87a8d402014-09-15 20:15:091670void ExtensionService::RegisterContentSettings(
mmenkead5094ab2017-05-15 19:01:141671 HostContentSettingsMap* host_content_settings_map,
1672 Profile* profile) {
1673 // Most extension services key off of the original profile.
1674 Profile* original_profile = profile->GetOriginalProfile();
1675
rkaplowe65c2ff2015-02-14 16:29:541676 TRACE_EVENT0("browser,startup", "ExtensionService::RegisterContentSettings");
mukaia1aa3512014-10-22 20:14:111677 DCHECK_CURRENTLY_ON(BrowserThread::UI);
mukai87a8d402014-09-15 20:15:091678 host_content_settings_map->RegisterProvider(
mukai87a8d402014-09-15 20:15:091679 HostContentSettingsMap::CUSTOM_EXTENSION_PROVIDER,
dchengc963c7142016-04-08 03:55:221680 std::unique_ptr<content_settings::ObservableProvider>(
mukai87a8d402014-09-15 20:15:091681 new content_settings::CustomExtensionProvider(
mmenkead5094ab2017-05-15 19:01:141682 extensions::ContentSettingsService::Get(original_profile)
dchengc963c7142016-04-08 03:55:221683 ->content_settings_store(),
mmenkead5094ab2017-05-15 19:01:141684 // TODO(mmenke): CustomExtensionProvider expects this to be true
1685 // for incognito profiles.
1686 false)));
mukai87a8d402014-09-15 20:15:091687}
1688
[email protected]e9d7496e2014-04-18 01:25:461689void ExtensionService::TerminateExtension(const std::string& extension_id) {
Michael Giuffridafcb420362017-10-11 21:50:261690 extension_registrar_.TerminateExtension(extension_id);
[email protected]bb7f40952011-01-13 00:21:201691}
1692
[email protected]8001df22011-04-28 19:59:471693const Extension* ExtensionService::GetInstalledExtension(
1694 const std::string& id) const {
[email protected]599539802014-01-07 23:06:001695 return registry_->GetExtensionById(id, ExtensionRegistry::EVERYTHING);
[email protected]0dfe05c2011-02-23 23:03:361696}
1697
[email protected]9060d8b02012-01-13 02:14:301698bool ExtensionService::OnExternalExtensionFileFound(
lazyboye8634172016-01-28 00:10:481699 const ExternalInstallInfoFile& info) {
Istiaque Ahmedf6e72622017-09-08 23:14:171700 DCHECK_CURRENTLY_ON(BrowserThread::UI);
lazyboye8634172016-01-28 00:10:481701 CHECK(crx_file::id_util::IdIsValid(info.extension_id));
1702 if (extension_prefs_->IsExternalExtensionUninstalled(info.extension_id))
[email protected]9060d8b02012-01-13 02:14:301703 return false;
[email protected]a8af9fdb2010-10-28 21:52:201704
[email protected]7577a5c52009-07-30 06:21:581705 // Before even bothering to unpack, check and see if we already have this
[email protected]4c967932009-07-31 01:15:491706 // version. This is important because these extensions are going to get
[email protected]7577a5c52009-07-30 06:21:581707 // installed on every startup.
lazyboye8634172016-01-28 00:10:481708 const Extension* existing = GetExtensionById(info.extension_id, true);
[email protected]910f72ce2012-08-24 01:38:351709
[email protected]7577a5c52009-07-30 06:21:581710 if (existing) {
[email protected]910f72ce2012-08-24 01:38:351711 // The default apps will have the location set as INTERNAL. Since older
1712 // default apps are installed as EXTERNAL, we override them. However, if the
1713 // app is already installed as internal, then do the version check.
[email protected]31bb5ee62012-09-12 22:58:401714 // TODO(grv) : Remove after Q1-2013.
[email protected]910f72ce2012-08-24 01:38:351715 bool is_default_apps_migration =
lazyboye8634172016-01-28 00:10:481716 (info.crx_location == Manifest::INTERNAL &&
[email protected]1d5e58b2013-01-31 08:41:401717 Manifest::IsExternalLocation(existing->location()));
[email protected]910f72ce2012-08-24 01:38:351718
1719 if (!is_default_apps_migration) {
Devlin Cronin03bf2d22017-12-20 08:21:051720 switch (existing->version().CompareTo(info.version)) {
[email protected]910f72ce2012-08-24 01:38:351721 case -1: // existing version is older, we should upgrade
1722 break;
1723 case 0: // existing version is same, do nothing
1724 return false;
1725 case 1: // existing version is newer, uh-oh
lazyboye8634172016-01-28 00:10:481726 LOG(WARNING) << "Found external version of extension "
1727 << info.extension_id
[email protected]910f72ce2012-08-24 01:38:351728 << "that is older than current version. Current version "
1729 << "is: " << existing->VersionString() << ". New "
Devlin Cronind4c2a8f32017-09-29 17:08:301730 << "version is: " << info.version.GetString()
[email protected]910f72ce2012-08-24 01:38:351731 << ". Keeping current version.";
1732 return false;
1733 }
[email protected]7577a5c52009-07-30 06:21:581734 }
1735 }
1736
[email protected]9060d8b02012-01-13 02:14:301737 // If the extension is already pending, don't start an install.
[email protected]e3987852012-05-04 10:06:301738 if (!pending_extension_manager()->AddFromExternalFile(
Devlin Cronind4c2a8f32017-09-29 17:08:301739 info.extension_id, info.crx_location, info.version,
lazyboye8634172016-01-28 00:10:481740 info.creation_flags, info.mark_acknowledged)) {
[email protected]9060d8b02012-01-13 02:14:301741 return false;
[email protected]e3987852012-05-04 10:06:301742 }
[email protected]9c635f22010-12-02 09:36:361743
[email protected]14908b72011-04-20 06:54:361744 // no client (silent install)
[email protected]f8636f92013-08-09 21:02:371745 scoped_refptr<CrxInstaller> installer(CrxInstaller::CreateSilent(this));
lazyboye8634172016-01-28 00:10:481746 installer->set_install_source(info.crx_location);
1747 installer->set_expected_id(info.extension_id);
Devlin Cronind4c2a8f32017-09-29 17:08:301748 installer->set_expected_version(info.version,
treibe960e282015-09-11 10:38:081749 true /* fail_install_if_unexpected */);
[email protected]cb0e50312011-05-09 15:03:071750 installer->set_install_cause(extension_misc::INSTALL_CAUSE_EXTERNAL_FILE);
lazyboye8634172016-01-28 00:10:481751 installer->set_install_immediately(info.install_immediately);
1752 installer->set_creation_flags(info.creation_flags);
[email protected]88e8ec9152013-01-17 04:05:181753#if defined(OS_CHROMEOS)
lazyboye8634172016-01-28 00:10:481754 extensions::InstallLimiter::Get(profile_)->Add(installer, info.path);
[email protected]88e8ec9152013-01-17 04:05:181755#else
lazyboye8634172016-01-28 00:10:481756 installer->InstallCrx(info.path);
[email protected]88e8ec9152013-01-17 04:05:181757#endif
[email protected]47fc70c2011-12-06 07:29:511758
1759 // Depending on the source, a new external extension might not need a user
1760 // notification on installation. For such extensions, mark them acknowledged
1761 // now to suppress the notification.
lazyboye8634172016-01-28 00:10:481762 if (info.mark_acknowledged)
1763 external_install_manager_->AcknowledgeExternalExtension(info.extension_id);
[email protected]9060d8b02012-01-13 02:14:301764
1765 return true;
[email protected]7577a5c52009-07-30 06:21:581766}
1767
[email protected]eaa7dd182010-12-14 11:09:001768void ExtensionService::DidCreateRenderViewForBackgroundPage(
[email protected]3a1dc572012-07-31 22:25:131769 extensions::ExtensionHost* host) {
Michael Giuffrida573992d2018-02-08 00:48:441770 extension_registrar_.DidCreateRenderViewForBackgroundPage(host);
[email protected]406027c02010-09-27 08:03:181771}
1772
[email protected]432115822011-07-10 15:52:271773void ExtensionService::Observe(int type,
[email protected]6c2381d2011-10-19 02:52:531774 const content::NotificationSource& source,
1775 const content::NotificationDetails& details) {
[email protected]432115822011-07-10 15:52:271776 switch (type) {
[email protected]3c4abc82012-10-22 22:25:541777 case chrome::NOTIFICATION_APP_TERMINATING:
1778 // Shutdown has started. Don't start any more extension installs.
1779 // (We cannot use ExtensionService::Shutdown() for this because it
1780 // happens too late in browser teardown.)
1781 browser_terminating_ = true;
1782 break;
[email protected]adf5a102014-07-31 12:44:061783 case extensions::NOTIFICATION_EXTENSION_PROCESS_TERMINATED: {
[email protected]6c2381d2011-10-19 02:52:531784 if (profile_ !=
1785 content::Source<Profile>(source).ptr()->GetOriginalProfile()) {
[email protected]bc535ee52010-08-31 18:40:321786 break;
[email protected]6c2381d2011-10-19 02:52:531787 }
[email protected]a4ed6282009-12-14 20:51:161788
Michael Giuffridafcb420362017-10-11 21:50:261789 // Mark the extension as terminated and deactivated. We want it to
[email protected]fa2416f2011-05-03 08:41:201790 // be in a consistent state: either fully working or not loaded
1791 // at all, but never half-crashed. We do it in a PostTask so
1792 // that other handlers of this notification will still have
1793 // access to the Extension and ExtensionHost.
Michael Giuffridafcb420362017-10-11 21:50:261794 extensions::ExtensionHost* host =
1795 content::Details<extensions::ExtensionHost>(details).ptr();
skyostilf221b7de2015-06-11 20:36:321796 base::ThreadTaskRunnerHandle::Get()->PostTask(
Michael Giuffridafcb420362017-10-11 21:50:261797 FROM_HERE, base::BindOnce(&ExtensionService::TerminateExtension,
1798 AsWeakPtr(), host->extension_id()));
[email protected]31f77262009-12-02 20:48:531799 break;
1800 }
[email protected]432115822011-07-10 15:52:271801 case content::NOTIFICATION_RENDERER_PROCESS_TERMINATED: {
[email protected]f3b1a082011-11-18 00:34:301802 content::RenderProcessHost* process =
1803 content::Source<content::RenderProcessHost>(source).ptr();
[email protected]fc30ef082011-08-18 04:07:191804 Profile* host_profile =
[email protected]f3b1a082011-11-18 00:34:301805 Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]fc30ef082011-08-18 04:07:191806 if (!profile_->IsSameProfile(host_profile->GetOriginalProfile()))
1807 break;
1808
[email protected]fafdc842014-01-17 18:09:081809 extensions::ProcessMap* process_map =
1810 extensions::ProcessMap::Get(profile_);
1811 if (process_map->Contains(process->GetID())) {
[email protected]52b76592013-11-02 17:59:031812 // An extension process was terminated, this might have resulted in an
1813 // app or extension becoming idle.
1814 std::set<std::string> extension_ids =
[email protected]fafdc842014-01-17 18:09:081815 process_map->GetExtensionsInProcess(process->GetID());
elijahtaylor0def4432014-10-06 18:15:111816 // In addition to the extensions listed in the process map, one of those
1817 // extensions could be referencing a shared module which is waiting for
1818 // idle to update. Check all imports of these extensions, too.
1819 std::set<std::string> import_ids;
1820 for (std::set<std::string>::const_iterator it = extension_ids.begin();
1821 it != extension_ids.end();
1822 ++it) {
1823 const Extension* extension = GetExtensionById(*it, true);
1824 if (!extension)
1825 continue;
1826 const std::vector<SharedModuleInfo::ImportInfo>& imports =
1827 SharedModuleInfo::GetImports(extension);
1828 std::vector<SharedModuleInfo::ImportInfo>::const_iterator import_it;
1829 for (import_it = imports.begin(); import_it != imports.end();
1830 import_it++) {
1831 import_ids.insert((*import_it).extension_id);
1832 }
1833 }
1834 extension_ids.insert(import_ids.begin(), import_ids.end());
1835
[email protected]52b76592013-11-02 17:59:031836 for (std::set<std::string>::const_iterator it = extension_ids.begin();
1837 it != extension_ids.end(); ++it) {
1838 if (delayed_installs_.Contains(*it)) {
skyostilf221b7de2015-06-11 20:36:321839 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
[email protected]52b76592013-11-02 17:59:031840 FROM_HERE,
tzik8d880ee2017-04-20 19:46:241841 base::BindOnce(
Toni Barzic667db0d32018-01-09 18:00:191842 base::IgnoreResult(
1843 &ExtensionService::FinishDelayedInstallationIfReady),
1844 AsWeakPtr(), *it, false /*install_immediately*/),
[email protected]52b76592013-11-02 17:59:031845 base::TimeDelta::FromSeconds(kUpdateIdleDelay));
1846 }
1847 }
1848 }
1849
[email protected]fafdc842014-01-17 18:09:081850 process_map->RemoveAllFromProcess(process->GetID());
[email protected]6f371442011-11-09 06:45:461851 BrowserThread::PostTask(
tzik8d880ee2017-04-20 19:46:241852 BrowserThread::IO, FROM_HERE,
1853 base::BindOnce(&extensions::InfoMap::UnregisterAllExtensionsInProcess,
1854 system_->info_map(), process->GetID()));
[email protected]da5683db2011-04-23 17:12:211855 break;
1856 }
[email protected]ebe07772014-05-22 04:16:061857 case chrome::NOTIFICATION_PROFILE_DESTRUCTION_STARTED: {
1858 OnProfileDestructionStarted();
1859 break;
1860 }
[email protected]aa96d3a2010-08-21 08:45:251861
[email protected]4814b512009-11-07 00:12:291862 default:
1863 NOTREACHED() << "Unexpected notification type.";
1864 }
1865}
1866
binjin47947f842014-11-18 12:10:241867int ExtensionService::GetDisableReasonsOnInstalled(const Extension* extension) {
rdevlin.cronine1456712016-12-29 22:47:281868 bool is_update_from_same_type = false;
1869 {
1870 const Extension* existing_extension =
1871 GetInstalledExtension(extension->id());
1872 is_update_from_same_type =
1873 existing_extension &&
1874 existing_extension->manifest()->type() == extension->manifest()->type();
1875 }
Minh X. Nguyen45479012017-08-18 21:35:361876 extensions::disable_reason::DisableReason disable_reason =
1877 extensions::disable_reason::DISABLE_NONE;
binjin47947f842014-11-18 12:10:241878 // Extensions disabled by management policy should always be disabled, even
1879 // if it's force-installed.
1880 if (system_->management_policy()->MustRemainDisabled(
1881 extension, &disable_reason, nullptr)) {
1882 // A specified reason is required to disable the extension.
Minh X. Nguyen45479012017-08-18 21:35:361883 DCHECK(disable_reason != extensions::disable_reason::DISABLE_NONE);
binjin47947f842014-11-18 12:10:241884 return disable_reason;
1885 }
1886
[email protected]612a1cb12012-10-17 13:18:031887 // Extensions installed by policy can't be disabled. So even if a previous
1888 // installation disabled the extension, make sure it is now enabled.
binjin47947f842014-11-18 12:10:241889 if (system_->management_policy()->MustRemainEnabled(extension, nullptr))
Minh X. Nguyen45479012017-08-18 21:35:361890 return extensions::disable_reason::DISABLE_NONE;
[email protected]612a1cb12012-10-17 13:18:031891
binjin47947f842014-11-18 12:10:241892 // An already disabled extension should inherit the disable reasons and
1893 // remain disabled.
1894 if (extension_prefs_->IsExtensionDisabled(extension->id())) {
1895 int disable_reasons = extension_prefs_->GetDisableReasons(extension->id());
1896 // If an extension was disabled without specified reason, presume it's
1897 // disabled by user.
Minh X. Nguyen45479012017-08-18 21:35:361898 return disable_reasons == extensions::disable_reason::DISABLE_NONE
1899 ? extensions::disable_reason::DISABLE_USER_ACTION
binjin47947f842014-11-18 12:10:241900 : disable_reasons;
1901 }
[email protected]612a1cb12012-10-17 13:18:031902
rdevlin.cronin9d7ae4d2017-01-13 16:38:231903 if (extensions::ExternalInstallManager::IsPromptingEnabled()) {
[email protected]612a1cb12012-10-17 13:18:031904 // External extensions are initially disabled. We prompt the user before
[email protected]2c495c42013-01-04 21:49:541905 // enabling them. Hosted apps are excepted because they are not dangerous
rdevlin.cronine1456712016-12-29 22:47:281906 // (they need to be launched by the user anyway). We also don't prompt for
1907 // extensions updating; this is because the extension will be disabled from
1908 // the initial install if it is supposed to be, and this allows us to turn
1909 // this on for other platforms without disabling already-installed
1910 // extensions.
[email protected]1d5e58b2013-01-31 08:41:401911 if (extension->GetType() != Manifest::TYPE_HOSTED_APP &&
1912 Manifest::IsExternalLocation(extension->location()) &&
rdevlin.cronine1456712016-12-29 22:47:281913 !extension_prefs_->IsExternalExtensionAcknowledged(extension->id()) &&
1914 !is_update_from_same_type) {
Minh X. Nguyen45479012017-08-18 21:35:361915 return extensions::disable_reason::DISABLE_EXTERNAL_EXTENSION;
[email protected]612a1cb12012-10-17 13:18:031916 }
1917 }
[email protected]612a1cb12012-10-17 13:18:031918
Minh X. Nguyen45479012017-08-18 21:35:361919 return extensions::disable_reason::DISABLE_NONE;
[email protected]612a1cb12012-10-17 13:18:031920}
[email protected]0db124b02012-11-07 04:55:051921
mlerman6a37b6a42014-11-26 22:10:531922// Helper method to determine if an extension can be blocked.
1923bool ExtensionService::CanBlockExtension(const Extension* extension) const {
mlerman3690e5be2014-12-01 22:57:441924 DCHECK(extension);
mlerman6a37b6a42014-11-26 22:10:531925 return extension->location() != Manifest::COMPONENT &&
1926 extension->location() != Manifest::EXTERNAL_COMPONENT &&
achuith2f5578b2016-02-26 21:57:131927 !system_->management_policy()->MustRemainEnabled(extension, nullptr);
mlerman6a37b6a42014-11-26 22:10:531928}
1929
xiyuanf6a4c6a62016-04-19 18:14:541930extensions::InstallGate::Action ExtensionService::ShouldDelayExtensionInstall(
1931 const extensions::Extension* extension,
1932 bool install_immediately,
1933 extensions::ExtensionPrefs::DelayReason* reason) const {
1934 for (const auto& entry : install_delayer_registry_) {
1935 extensions::InstallGate* const delayer = entry.second;
1936 extensions::InstallGate::Action action =
1937 delayer->ShouldDelay(extension, install_immediately);
1938 if (action != extensions::InstallGate::INSTALL) {
1939 *reason = entry.first;
1940 return action;
1941 }
[email protected]e7aa7b7e2012-11-27 04:51:221942 }
[email protected]fdd679b2012-11-15 20:49:391943
xiyuanf6a4c6a62016-04-19 18:14:541944 return extensions::InstallGate::INSTALL;
[email protected]9f4e4f082013-06-21 07:11:191945}
1946
1947void ExtensionService::MaybeFinishDelayedInstallations() {
1948 std::vector<std::string> to_be_installed;
achuith2f5578b2016-02-26 21:57:131949 for (const auto& extension : delayed_installs_) {
1950 to_be_installed.push_back(extension->id());
[email protected]399583b2012-12-11 09:33:421951 }
achuith2f5578b2016-02-26 21:57:131952 for (const auto& extension_id : to_be_installed) {
Toni Barzic667db0d32018-01-09 18:00:191953 FinishDelayedInstallationIfReady(extension_id,
1954 false /*install_immediately*/);
[email protected]399583b2012-12-11 09:33:421955 }
[email protected]399583b2012-12-11 09:33:421956}
1957
[email protected]fdd679b2012-11-15 20:49:391958void ExtensionService::OnBlacklistUpdated() {
[email protected]2d19eb6e2014-01-27 17:30:001959 blacklist_->GetBlacklistedIDs(
[email protected]f47f7172014-03-19 19:27:101960 registry_->GenerateInstalledExtensionsSet()->GetIDs(),
[email protected]3f2a2fa2013-09-24 02:55:251961 base::Bind(&ExtensionService::ManageBlacklist, AsWeakPtr()));
[email protected]695b5712012-12-06 23:55:281962}
1963
weidongg04695232017-06-09 00:01:051964void ExtensionService::OnUpgradeRecommended() {
1965 // Notify observers that chrome update is available.
1966 for (auto& observer : update_observers_)
1967 observer.OnChromeUpdateAvailable();
1968}
1969
Michael Giuffrida573992d2018-02-08 00:48:441970void ExtensionService::PreAddExtension(
1971 const extensions::Extension* extension,
1972 const extensions::Extension* old_extension) {
1973 // Check if the extension's privileges have changed and mark the
1974 // extension disabled if necessary.
1975 CheckPermissionsIncrease(extension, !!old_extension);
1976}
1977
Michael Giuffrida6397c592017-10-09 20:46:531978bool ExtensionService::CanEnableExtension(const Extension* extension) {
1979 return !system_->management_policy()->MustRemainDisabled(extension, nullptr,
1980 nullptr);
1981}
1982
1983bool ExtensionService::CanDisableExtension(const Extension* extension) {
1984 // Some extensions cannot be disabled by users:
1985 // - |extension| can be null if sync disables an extension that is not
1986 // installed yet; allow disablement in this case.
1987 if (!extension)
1988 return true;
1989
1990 // - Shared modules are just resources used by other extensions, and are not
1991 // user-controlled.
1992 if (SharedModuleInfo::IsSharedModule(extension))
1993 return false;
1994
1995 // - EXTERNAL_COMPONENT extensions are not generally modifiable by users, but
1996 // can be uninstalled by the browser if the user sets extension-specific
1997 // preferences.
1998 if (extension->location() == Manifest::EXTERNAL_COMPONENT)
1999 return true;
2000
2001 return system_->management_policy()->UserMayModifySettings(extension,
2002 nullptr);
2003}
2004
2005bool ExtensionService::ShouldBlockExtension(const Extension* extension) {
2006 if (!block_extensions_)
2007 return false;
2008
2009 // Blocked extensions aren't marked as such in prefs, thus if
2010 // |block_extensions_| is true then CanBlockExtension() must be called with an
2011 // Extension object. If |extension| is not loaded, assume it should be
2012 // blocked.
2013 return !extension || CanBlockExtension(extension);
2014}
2015
[email protected]2d19eb6e2014-01-27 17:30:002016void ExtensionService::ManageBlacklist(
2017 const extensions::Blacklist::BlacklistStateMap& state_map) {
[email protected]54ee8192014-03-29 17:37:242018 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]695b5712012-12-06 23:55:282019
mlerman6a37b6a42014-11-26 22:10:532020 std::set<std::string> blacklisted;
[email protected]2d19eb6e2014-01-27 17:30:002021 ExtensionIdSet greylist;
2022 ExtensionIdSet unchanged;
achuith2f5578b2016-02-26 21:57:132023 for (const auto& it : state_map) {
2024 switch (it.second) {
[email protected]2d19eb6e2014-01-27 17:30:002025 case extensions::NOT_BLACKLISTED:
2026 break;
[email protected]695b5712012-12-06 23:55:282027
[email protected]2d19eb6e2014-01-27 17:30:002028 case extensions::BLACKLISTED_MALWARE:
achuith2f5578b2016-02-26 21:57:132029 blacklisted.insert(it.first);
[email protected]2d19eb6e2014-01-27 17:30:002030 break;
2031
2032 case extensions::BLACKLISTED_SECURITY_VULNERABILITY:
2033 case extensions::BLACKLISTED_CWS_POLICY_VIOLATION:
2034 case extensions::BLACKLISTED_POTENTIALLY_UNWANTED:
achuith2f5578b2016-02-26 21:57:132035 greylist.insert(it.first);
[email protected]2d19eb6e2014-01-27 17:30:002036 break;
2037
2038 case extensions::BLACKLISTED_UNKNOWN:
achuith2f5578b2016-02-26 21:57:132039 unchanged.insert(it.first);
[email protected]2d19eb6e2014-01-27 17:30:002040 break;
2041 }
2042 }
2043
mlerman6a37b6a42014-11-26 22:10:532044 UpdateBlacklistedExtensions(blacklisted, unchanged);
[email protected]2d19eb6e2014-01-27 17:30:002045 UpdateGreylistedExtensions(greylist, unchanged, state_map);
2046
[email protected]373daf972014-04-10 01:50:442047 error_controller_->ShowErrorIfNeeded();
[email protected]2d19eb6e2014-01-27 17:30:002048}
2049
2050namespace {
2051void Partition(const ExtensionIdSet& before,
2052 const ExtensionIdSet& after,
2053 const ExtensionIdSet& unchanged,
2054 ExtensionIdSet* no_longer,
2055 ExtensionIdSet* not_yet) {
2056 *not_yet = base::STLSetDifference<ExtensionIdSet>(after, before);
2057 *no_longer = base::STLSetDifference<ExtensionIdSet>(before, after);
2058 *no_longer = base::STLSetDifference<ExtensionIdSet>(*no_longer, unchanged);
2059}
2060} // namespace
2061
mlerman6a37b6a42014-11-26 22:10:532062void ExtensionService::UpdateBlacklistedExtensions(
2063 const ExtensionIdSet& blacklisted,
[email protected]2d19eb6e2014-01-27 17:30:002064 const ExtensionIdSet& unchanged) {
2065 ExtensionIdSet not_yet_blocked, no_longer_blocked;
mlerman6a37b6a42014-11-26 22:10:532066 Partition(registry_->blacklisted_extensions().GetIDs(), blacklisted,
2067 unchanged, &no_longer_blocked, &not_yet_blocked);
[email protected]2d19eb6e2014-01-27 17:30:002068
2069 for (ExtensionIdSet::iterator it = no_longer_blocked.begin();
2070 it != no_longer_blocked.end(); ++it) {
[email protected]695b5712012-12-06 23:55:282071 scoped_refptr<const Extension> extension =
[email protected]bb1bc9b32013-12-21 03:09:142072 registry_->blacklisted_extensions().GetByID(*it);
[email protected]3f2a2fa2013-09-24 02:55:252073 if (!extension.get()) {
mlerman6a37b6a42014-11-26 22:10:532074 NOTREACHED() << "Extension " << *it << " no longer blacklisted, "
2075 << "but it was never blacklisted.";
[email protected]695b5712012-12-06 23:55:282076 continue;
[email protected]3f2a2fa2013-09-24 02:55:252077 }
[email protected]bb1bc9b32013-12-21 03:09:142078 registry_->RemoveBlacklisted(*it);
atuchin6dc7c442016-07-20 07:04:342079 extension_prefs_->SetExtensionBlacklistState(extension->id(),
2080 extensions::NOT_BLACKLISTED);
[email protected]dc24976f2013-06-02 21:15:092081 AddExtension(extension.get());
[email protected]ac875372013-02-28 04:36:092082 UMA_HISTOGRAM_ENUMERATION("ExtensionBlacklist.UnblacklistInstalled",
[email protected]dc24976f2013-06-02 21:15:092083 extension->location(),
2084 Manifest::NUM_LOCATIONS);
[email protected]695b5712012-12-06 23:55:282085 }
2086
[email protected]2d19eb6e2014-01-27 17:30:002087 for (ExtensionIdSet::iterator it = not_yet_blocked.begin();
2088 it != not_yet_blocked.end(); ++it) {
[email protected]695b5712012-12-06 23:55:282089 scoped_refptr<const Extension> extension = GetInstalledExtension(*it);
[email protected]3f2a2fa2013-09-24 02:55:252090 if (!extension.get()) {
2091 NOTREACHED() << "Extension " << *it << " needs to be "
2092 << "blacklisted, but it's not installed.";
[email protected]695b5712012-12-06 23:55:282093 continue;
[email protected]3f2a2fa2013-09-24 02:55:252094 }
[email protected]bb1bc9b32013-12-21 03:09:142095 registry_->AddBlacklisted(extension);
[email protected]2d19eb6e2014-01-27 17:30:002096 extension_prefs_->SetExtensionBlacklistState(
2097 extension->id(), extensions::BLACKLISTED_MALWARE);
limasdf0deef2042017-05-03 19:17:172098 UnloadExtension(*it, UnloadedExtensionReason::BLACKLIST);
[email protected]ac875372013-02-28 04:36:092099 UMA_HISTOGRAM_ENUMERATION("ExtensionBlacklist.BlacklistInstalled",
2100 extension->location(), Manifest::NUM_LOCATIONS);
[email protected]695b5712012-12-06 23:55:282101 }
[email protected]2d19eb6e2014-01-27 17:30:002102}
[email protected]695b5712012-12-06 23:55:282103
[email protected]2d19eb6e2014-01-27 17:30:002104// TODO(oleg): UMA logging
2105void ExtensionService::UpdateGreylistedExtensions(
2106 const ExtensionIdSet& greylist,
2107 const ExtensionIdSet& unchanged,
2108 const extensions::Blacklist::BlacklistStateMap& state_map) {
2109 ExtensionIdSet not_yet_greylisted, no_longer_greylisted;
2110 Partition(greylist_.GetIDs(),
2111 greylist, unchanged,
2112 &no_longer_greylisted, &not_yet_greylisted);
2113
2114 for (ExtensionIdSet::iterator it = no_longer_greylisted.begin();
2115 it != no_longer_greylisted.end(); ++it) {
2116 scoped_refptr<const Extension> extension = greylist_.GetByID(*it);
2117 if (!extension.get()) {
2118 NOTREACHED() << "Extension " << *it << " no longer greylisted, "
2119 << "but it was not marked as greylisted.";
2120 continue;
2121 }
2122
2123 greylist_.Remove(*it);
2124 extension_prefs_->SetExtensionBlacklistState(extension->id(),
2125 extensions::NOT_BLACKLISTED);
2126 if (extension_prefs_->GetDisableReasons(extension->id()) &
Minh X. Nguyen45479012017-08-18 21:35:362127 extensions::disable_reason::DISABLE_GREYLIST)
[email protected]2d19eb6e2014-01-27 17:30:002128 EnableExtension(*it);
2129 }
2130
2131 for (ExtensionIdSet::iterator it = not_yet_greylisted.begin();
2132 it != not_yet_greylisted.end(); ++it) {
2133 scoped_refptr<const Extension> extension = GetInstalledExtension(*it);
2134 if (!extension.get()) {
2135 NOTREACHED() << "Extension " << *it << " needs to be "
2136 << "disabled, but it's not installed.";
2137 continue;
2138 }
2139 greylist_.Insert(extension);
2140 extension_prefs_->SetExtensionBlacklistState(extension->id(),
2141 state_map.find(*it)->second);
2142 if (registry_->enabled_extensions().Contains(extension->id()))
Minh X. Nguyen45479012017-08-18 21:35:362143 DisableExtension(*it, extensions::disable_reason::DISABLE_GREYLIST);
[email protected]2d19eb6e2014-01-27 17:30:002144 }
[email protected]fdd679b2012-11-15 20:49:392145}
[email protected]75bdcb872013-03-13 00:41:452146
2147void ExtensionService::AddUpdateObserver(extensions::UpdateObserver* observer) {
2148 update_observers_.AddObserver(observer);
2149}
2150
2151void ExtensionService::RemoveUpdateObserver(
2152 extensions::UpdateObserver* observer) {
2153 update_observers_.RemoveObserver(observer);
2154}
[email protected]bb1bc9b32013-12-21 03:09:142155
xiyuanf6a4c6a62016-04-19 18:14:542156void ExtensionService::RegisterInstallGate(
2157 extensions::ExtensionPrefs::DelayReason reason,
2158 extensions::InstallGate* install_delayer) {
2159 DCHECK(install_delayer_registry_.end() ==
2160 install_delayer_registry_.find(reason));
2161 install_delayer_registry_[reason] = install_delayer;
2162}
2163
2164void ExtensionService::UnregisterInstallGate(
2165 extensions::InstallGate* install_delayer) {
2166 for (auto it = install_delayer_registry_.begin();
2167 it != install_delayer_registry_.end(); ++it) {
2168 if (it->second == install_delayer) {
2169 install_delayer_registry_.erase(it);
2170 return;
2171 }
2172 }
2173}
2174
[email protected]bb1bc9b32013-12-21 03:09:142175// Used only by test code.
2176void ExtensionService::UnloadAllExtensionsInternal() {
2177 profile_->GetExtensionSpecialStoragePolicy()->RevokeRightsForAllExtensions();
2178
2179 registry_->ClearAll();
[email protected]45f5b7d2014-01-22 23:47:132180 system_->runtime_data()->ClearAll();
[email protected]bb1bc9b32013-12-21 03:09:142181
2182 // TODO(erikkay) should there be a notification for this? We can't use
Minh X. Nguyen45479012017-08-18 21:35:362183 // extensions::EXTENSION_UNLOADED since that implies that the extension has
2184 // been disabled or uninstalled.
[email protected]bb1bc9b32013-12-21 03:09:142185}
[email protected]ebe07772014-05-22 04:16:062186
2187void ExtensionService::OnProfileDestructionStarted() {
2188 ExtensionIdSet ids_to_unload = registry_->enabled_extensions().GetIDs();
2189 for (ExtensionIdSet::iterator it = ids_to_unload.begin();
2190 it != ids_to_unload.end();
2191 ++it) {
limasdf0deef2042017-05-03 19:17:172192 UnloadExtension(*it, UnloadedExtensionReason::PROFILE_SHUTDOWN);
[email protected]ebe07772014-05-22 04:16:062193 }
2194}
rdevlin.croninf2e1cb012017-05-27 01:27:592195
2196void ExtensionService::OnInstalledExtensionsLoaded() {
2197 if (updater_)
2198 updater_->Start();
2199
2200 // Enable any Shared Modules that incorrectly got disabled previously.
2201 // This is temporary code to fix incorrect behavior from previous versions of
2202 // Chrome and can be removed after several releases (perhaps M60).
2203 extensions::ExtensionList to_enable;
2204 for (const auto& extension : registry_->disabled_extensions()) {
2205 if (SharedModuleInfo::IsSharedModule(extension.get()))
2206 to_enable.push_back(extension);
2207 }
2208 for (const auto& extension : to_enable) {
2209 EnableExtension(extension->id());
2210 }
2211
2212 OnBlacklistUpdated();
2213}
lazyboy75b9def2017-06-06 18:56:592214
Takumi Fujimoto43c8c00f2017-07-26 22:48:562215void ExtensionService::UninstallMigratedExtensions() {
2216 std::unique_ptr<ExtensionSet> installed_extensions =
2217 registry_->GenerateInstalledExtensionsSet();
2218
2219 for (const std::string& extension_id : kMigratedExtensionIds) {
2220 if (installed_extensions->Contains(extension_id)) {
2221 UninstallExtension(extension_id, extensions::UNINSTALL_REASON_MIGRATED,
Devlin Cronin218df7f2017-11-21 21:41:312222 nullptr);
Takumi Fujimoto43c8c00f2017-07-26 22:48:562223 }
2224 }
2225}