blob: 109d09b7f2f8f52c44fd7926f0910b380d4a7a29 [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"
Gabriel Charette44db1422018-08-06 11:19:3326#include "base/task/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"
Greg Thompson8bcd799b2018-08-10 09:49:3363#include "chrome/browser/upgrade_detector/upgrade_detector.h"
Giovanni Ortuño Urquidi218522862018-08-28 12:48:0464#include "chrome/browser/web_applications/extensions/web_app_extension_ids_map.h"
Scott Violet6200d332018-02-23 21:29:2365#include "chrome/common/buildflags.h"
[email protected]e2eb43112009-05-29 21:19:5466#include "chrome/common/chrome_switches.h"
[email protected]f6431be82013-09-07 02:53:4567#include "chrome/common/crash_keys.h"
[email protected]9f4e4f082013-06-21 07:11:1968#include "chrome/common/extensions/extension_constants.h"
[email protected]a57209872009-05-04 22:53:1469#include "chrome/common/url_constants.h"
mukai8eaec822014-10-25 17:53:1670#include "components/content_settings/core/browser/host_content_settings_map.h"
[email protected]fdd28372014-08-21 02:27:2671#include "components/crx_file/id_util.h"
Gabriel Charette790754c2018-03-16 21:32:5972#include "content/public/browser/browser_thread.h"
[email protected]05aad2da2011-10-28 10:12:3773#include "content/public/browser/notification_service.h"
[email protected]f3b1a082011-11-18 00:34:3074#include "content/public/browser/render_process_host.h"
[email protected]399583b2012-12-11 09:33:4275#include "content/public/browser/storage_partition.h"
[email protected]34423532013-11-21 18:13:1076#include "extensions/browser/event_router.h"
Devlin Cronin40b4cbc2017-08-02 01:57:5977#include "extensions/browser/extension_file_task_runner.h"
[email protected]22401dc2014-03-21 01:38:5778#include "extensions/browser/extension_host.h"
[email protected]bb1bc9b32013-12-21 03:09:1479#include "extensions/browser/extension_registry.h"
[email protected]59b0e602014-01-30 00:41:2480#include "extensions/browser/extension_system.h"
Michael Giuffrida7efeed142017-06-07 06:29:2181#include "extensions/browser/extension_util.h"
rockotffa65b12014-10-14 17:19:0682#include "extensions/browser/extensions_browser_client.h"
lazyboye8634172016-01-28 00:10:4883#include "extensions/browser/external_install_info.h"
[email protected]4a1d9c0d2014-06-13 12:50:1184#include "extensions/browser/install_flag.h"
Michael Giuffrida6397c592017-10-09 20:46:5385#include "extensions/browser/management_policy.h"
[email protected]45f5b7d2014-01-22 23:47:1386#include "extensions/browser/runtime_data.h"
[email protected]e43c61f2014-07-20 21:46:3487#include "extensions/browser/uninstall_reason.h"
[email protected]a9aa62b312013-11-29 05:35:0688#include "extensions/browser/update_observer.h"
rockotffa65b12014-10-14 17:19:0689#include "extensions/browser/updater/extension_cache.h"
rockot05f40a922014-10-16 19:40:2590#include "extensions/browser/updater/extension_downloader.h"
[email protected]fb820c02014-03-13 15:07:0891#include "extensions/common/extension_messages.h"
rockot90659852014-09-18 19:31:5292#include "extensions/common/extension_urls.h"
[email protected]5ef835a2013-11-08 20:42:5793#include "extensions/common/feature_switch.h"
rdevlin.cronin41227532016-07-13 21:24:3494#include "extensions/common/features/feature_channel.h"
[email protected]85df9d12014-04-15 17:02:1495#include "extensions/common/file_util.h"
[email protected]0c3c9732013-09-16 08:53:4196#include "extensions/common/manifest_constants.h"
Michael Giuffrida6397c592017-10-09 20:46:5397#include "extensions/common/manifest_handlers/shared_module_info.h"
rockotd5546142014-10-15 00:29:0898#include "extensions/common/manifest_url_handlers.h"
[email protected]dccba4f82014-05-29 00:52:5699#include "extensions/common/one_shot_event.h"
treib2e0517f92015-05-07 23:15:36100#include "extensions/common/permissions/api_permission.h"
[email protected]c41003472013-10-19 15:37:25101#include "extensions/common/permissions/permission_message_provider.h"
[email protected]e4452d32013-11-15 23:07:41102#include "extensions/common/permissions/permissions_data.h"
Michael Giuffridab158f3f2017-07-17 19:53:44103#include "extensions/common/switches.h"
[email protected]79a60642012-10-20 21:03:18104
brettw9e85ef42016-11-01 21:01:24105#if BUILDFLAG(ENABLE_SUPERVISED_USERS)
treib8ecc1eb52015-03-04 18:29:06106#include "chrome/browser/supervised_user/supervised_user_service.h"
107#include "chrome/browser/supervised_user/supervised_user_service_factory.h"
108#endif
109
[email protected]eed367e2011-04-12 03:43:31110#if defined(OS_CHROMEOS)
[email protected]88e8ec9152013-01-17 04:05:18111#include "chrome/browser/chromeos/extensions/install_limiter.h"
achuithd3da4f02017-03-23 20:05:29112#include "chrome/browser/chromeos/profiles/profile_helper.h"
pilgrime92c5fcd2014-09-10 23:31:23113#include "storage/browser/fileapi/file_system_backend.h"
114#include "storage/browser/fileapi/file_system_context.h"
[email protected]eed367e2011-04-12 03:43:31115#endif
116
[email protected]55eb70e762012-02-20 17:38:39117using content::BrowserContext;
[email protected]631bb742011-11-02 11:29:39118using content::BrowserThread;
Devlin Cronineea1b7a2018-05-26 02:46:21119
120namespace extensions {
[email protected]5ef47ec2010-01-28 05:58:05121
Michael Giuffrida573992d2018-02-08 00:48:44122using LoadErrorBehavior = ExtensionRegistrar::LoadErrorBehavior;
123
[email protected]b6ab96d2009-08-20 18:58:19124namespace {
125
Lei Zhang15339152018-08-09 22:20:44126// Wait this long after an extensions becomes idle before updating it.
127constexpr base::TimeDelta kUpdateIdleDelay = base::TimeDelta::FromSeconds(5);
[email protected]0db124b02012-11-07 04:55:05128
Takumi Fujimoto43c8c00f2017-07-26 22:48:56129// IDs of extensions that have been replaced by component extensions and need to
130// be uninstalled.
Lei Zhang15339152018-08-09 22:20:44131const char* const kMigratedExtensionIds[] = {
Takumi Fujimoto43c8c00f2017-07-26 22:48:56132 "boadgeojelhgndaghljhdicfkmllpafd", // Google Cast
133 "dliochdbjfkdbacpmhlcpmleaejidimm" // Google Cast (Beta)
134};
135
[email protected]c6d474f82009-12-16 21:11:06136} // namespace
[email protected]b6ab96d2009-08-20 18:58:19137
[email protected]eaa7dd182010-12-14 11:09:00138// ExtensionService.
[email protected]6014d672008-12-05 00:38:25139
[email protected]8e4560b62011-01-14 10:09:14140void ExtensionService::CheckExternalUninstall(const std::string& id) {
[email protected]a29a517a2011-01-21 21:11:12141 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]a8af9fdb2010-10-28 21:52:20142
[email protected]7a4c6852010-09-16 03:44:22143 // Check if the providers know about this extension.
achuith2f5578b2016-02-26 21:57:13144 for (const auto& provider : external_extension_providers_) {
145 DCHECK(provider->IsReady());
146 if (provider->HasExtension(id))
[email protected]0a60a2e2010-10-25 16:15:21147 return; // Yup, known extension, don't uninstall.
[email protected]7a4c6852010-09-16 03:44:22148 }
149
Giovanni Ortuño Urquidi218522862018-08-28 12:48:04150 // Historically, the code under //chrome/browser/extensions has
151 // unsurprisingly managed all extensions. Later, Progressive Web Apps (PWAs)
152 // were implemented on top of extensions, more out of convenience than out of
153 // principle. As of mid 2018, there is work underway to separate PWAs's
154 // implementation details from the //c/b/e code. During the transition
155 // period, PWA-extensions are no longer managed solely by //c/b/e code. We
156 // add a special case here so that //c/b/e code doesn't uninstall
157 // PWA-extensions that it doesn't otherwise know about.
158 //
159 // Long term, PWAs will be completely separate from extensions, and we can
160 // remove this cross-link.
161 if (web_app::ExtensionIdsMap::HasExtensionId(profile_->GetPrefs(), id)) {
162 return;
163 }
164
[email protected]0f48fca2011-05-19 18:46:35165 // We get the list of external extensions to check from preferences.
166 // It is possible that an extension has preferences but is not loaded.
167 // For example, an extension that requires experimental permissions
168 // will not be loaded if the experimental command line flag is not used.
169 // In this case, do not uninstall.
[email protected]31bb5ee62012-09-12 22:58:40170 if (!GetInstalledExtension(id)) {
[email protected]0f48fca2011-05-19 18:46:35171 // We can't call UninstallExtension with an unloaded/invalid
172 // extension ID.
173 LOG(WARNING) << "Attempted uninstallation of unloaded/invalid extension "
174 << "with id: " << id;
175 return;
176 }
Devlin Cronineea1b7a2018-05-26 02:46:21177 UninstallExtension(id, UNINSTALL_REASON_ORPHANED_EXTERNAL_EXTENSION, nullptr);
[email protected]7a4c6852010-09-16 03:44:22178}
179
[email protected]8e4560b62011-01-14 10:09:14180void ExtensionService::ClearProvidersForTesting() {
[email protected]7a4c6852010-09-16 03:44:22181 external_extension_providers_.clear();
182}
183
[email protected]8e4560b62011-01-14 10:09:14184void ExtensionService::AddProviderForTesting(
lazyboyf33109d2016-08-31 00:37:08185 std::unique_ptr<ExternalProviderInterface> test_provider) {
[email protected]a29a517a2011-01-21 21:11:12186 CHECK(test_provider);
lazyboyf33109d2016-08-31 00:37:08187 external_extension_providers_.push_back(std::move(test_provider));
[email protected]7a4c6852010-09-16 03:44:22188}
189
[email protected]8f959f522014-08-06 06:26:28190void ExtensionService::BlacklistExtensionForTest(
191 const std::string& extension_id) {
mlerman6a37b6a42014-11-26 22:10:53192 ExtensionIdSet blacklisted;
[email protected]8f959f522014-08-06 06:26:28193 ExtensionIdSet unchanged;
mlerman6a37b6a42014-11-26 22:10:53194 blacklisted.insert(extension_id);
195 UpdateBlacklistedExtensions(blacklisted, unchanged);
[email protected]8f959f522014-08-06 06:26:28196}
197
[email protected]9060d8b02012-01-13 02:14:30198bool ExtensionService::OnExternalExtensionUpdateUrlFound(
lazyboye8634172016-01-28 00:10:48199 const ExternalInstallInfoUpdateUrl& info,
200 bool is_initial_load) {
Istiaque Ahmedf6e72622017-09-08 23:14:17201 DCHECK_CURRENTLY_ON(BrowserThread::UI);
lazyboye8634172016-01-28 00:10:48202 CHECK(crx_file::id_util::IdIsValid(info.extension_id));
[email protected]a8af9fdb2010-10-28 21:52:20203
lazyboye8634172016-01-28 00:10:48204 if (Manifest::IsExternalLocation(info.download_location)) {
[email protected]044e86992014-01-24 22:59:11205 // All extensions that are not user specific can be cached.
Devlin Cronineea1b7a2018-05-26 02:46:21206 ExtensionsBrowserClient::Get()->GetExtensionCache()->AllowCaching(
207 info.extension_id);
[email protected]044e86992014-01-24 22:59:11208 }
209
lazyboye8634172016-01-28 00:10:48210 const Extension* extension = GetExtensionById(info.extension_id, true);
[email protected]8a87a5332011-08-11 17:54:59211 if (extension) {
asargent56282ab72016-09-09 16:58:03212 // Already installed. Skip this install if the current location has higher
213 // priority than |info.download_location|, and we aren't doing a
214 // reinstall of a corrupt policy force-installed extension.
[email protected]1d5e58b2013-01-31 08:41:40215 Manifest::Location current = extension->location();
asargent56282ab72016-09-09 16:58:03216 if (!pending_extension_manager_.IsPolicyReinstallForCorruptionExpected(
217 info.extension_id) &&
218 current == Manifest::GetHigherPriorityLocation(
219 current, info.download_location)) {
[email protected]9060d8b02012-01-13 02:14:30220 return false;
lazyboye8634172016-01-28 00:10:48221 }
[email protected]8a87a5332011-08-11 17:54:59222 // Otherwise, overwrite the current installation.
[email protected]7a4c6852010-09-16 03:44:22223 }
[email protected]9060d8b02012-01-13 02:14:30224
lazyboye8634172016-01-28 00:10:48225 // Add |info.extension_id| to the set of pending extensions. If it can not
226 // be added, then there is already a pending record from a higher-priority
227 // install source. In this case, signal that this extension will not be
[email protected]9060d8b02012-01-13 02:14:30228 // installed by returning false.
229 if (!pending_extension_manager()->AddFromExternalUpdateUrl(
Devlin Cronind4c2a8f32017-09-29 17:08:30230 info.extension_id, info.install_parameter, info.update_url,
lazyboye8634172016-01-28 00:10:48231 info.download_location, info.creation_flags,
232 info.mark_acknowledged)) {
[email protected]9060d8b02012-01-13 02:14:30233 return false;
[email protected]31bb5ee62012-09-12 22:58:40234 }
[email protected]9060d8b02012-01-13 02:14:30235
lazyboye8634172016-01-28 00:10:48236 if (is_initial_load)
237 update_once_all_providers_are_ready_ = true;
[email protected]9060d8b02012-01-13 02:14:30238 return true;
[email protected]7a4c6852010-09-16 03:44:22239}
240
lazyboye8634172016-01-28 00:10:48241void ExtensionService::OnExternalProviderUpdateComplete(
242 const ExternalProviderInterface* provider,
Devlin Cronin19f70b6a2017-10-01 04:14:05243 const std::vector<ExternalInstallInfoUpdateUrl>& update_url_extensions,
244 const std::vector<ExternalInstallInfoFile>& file_extensions,
lazyboye8634172016-01-28 00:10:48245 const std::set<std::string>& removed_extensions) {
246 // Update pending_extension_manager() with the new extensions first.
lazyboy4aeef202016-09-07 21:28:59247 for (const auto& extension : update_url_extensions)
Devlin Cronin19f70b6a2017-10-01 04:14:05248 OnExternalExtensionUpdateUrlFound(extension, false);
lazyboy4aeef202016-09-07 21:28:59249 for (const auto& extension : file_extensions)
Devlin Cronin19f70b6a2017-10-01 04:14:05250 OnExternalExtensionFileFound(extension);
lazyboye8634172016-01-28 00:10:48251
252#if DCHECK_IS_ON()
253 for (const std::string& id : removed_extensions) {
lazyboy4aeef202016-09-07 21:28:59254 for (const auto& extension : update_url_extensions)
Devlin Cronin19f70b6a2017-10-01 04:14:05255 DCHECK_NE(id, extension.extension_id);
lazyboy4aeef202016-09-07 21:28:59256 for (const auto& extension : file_extensions)
Devlin Cronin19f70b6a2017-10-01 04:14:05257 DCHECK_NE(id, extension.extension_id);
lazyboye8634172016-01-28 00:10:48258 }
259#endif
260
261 // Then uninstall before running |updater_|.
262 for (const std::string& id : removed_extensions)
263 CheckExternalUninstall(id);
264
265 if (!update_url_extensions.empty() && updater_) {
266 // Empty params will cause pending extensions to be updated.
Devlin Cronineea1b7a2018-05-26 02:46:21267 updater_->CheckNow(ExtensionUpdater::CheckParams());
lazyboye8634172016-01-28 00:10:48268 }
269
270 error_controller_->ShowErrorIfNeeded();
271 external_install_manager_->UpdateExternalExtensionAlert();
272}
273
[email protected]eaa7dd182010-12-14 11:09:00274ExtensionService::ExtensionService(Profile* profile,
avi3ef9ec9e2014-12-22 22:50:17275 const base::CommandLine* command_line,
[email protected]650b2d52013-02-10 03:41:45276 const base::FilePath& install_directory,
Devlin Cronineea1b7a2018-05-26 02:46:21277 ExtensionPrefs* extension_prefs,
278 Blacklist* blacklist,
[email protected]0436b102011-04-15 18:30:03279 bool autoupdate_enabled,
[email protected]4a10006a2013-05-17 23:18:35280 bool extensions_enabled,
Devlin Cronineea1b7a2018-05-26 02:46:21281 OneShotEvent* ready)
282 : Blacklist::Observer(blacklist),
catmullings98cd1942016-08-30 22:31:59283 command_line_(command_line),
[email protected]fdd679b2012-11-15 20:49:39284 profile_(profile),
Devlin Cronineea1b7a2018-05-26 02:46:21285 system_(ExtensionSystem::Get(profile)),
[email protected]73c47932010-12-06 18:13:43286 extension_prefs_(extension_prefs),
[email protected]695b5712012-12-06 23:55:28287 blacklist_(blacklist),
Devlin Cronineea1b7a2018-05-26 02:46:21288 registry_(ExtensionRegistry::Get(profile)),
[email protected]6c9bedf2014-05-21 03:55:51289 pending_extension_manager_(profile),
[email protected]a9b00ac2009-06-25 21:03:23290 install_directory_(install_directory),
[email protected]0436b102011-04-15 18:30:03291 extensions_enabled_(extensions_enabled),
[email protected]4a10006a2013-05-17 23:18:35292 ready_(ready),
Devlin Cronineea1b7a2018-05-26 02:46:21293 shared_module_service_(new SharedModuleService(profile_)),
294 app_data_migrator_(new AppDataMigrator(profile_, registry_)),
Sergey Poromov0360b9e72018-04-19 17:37:29295 extension_registrar_(profile_, this),
296 forced_extensions_tracker_(registry_, profile_->GetPrefs()) {
[email protected]a29a517a2011-01-21 21:11:12297 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
rkaplowdd66a1342015-03-05 00:31:49298 TRACE_EVENT0("browser,startup", "ExtensionService::ExtensionService::ctor");
[email protected]a8af9fdb2010-10-28 21:52:20299
[email protected]36a784c2009-06-23 06:21:08300 // Figure out if extension installation should be enabled.
Devlin Cronineea1b7a2018-05-26 02:46:21301 if (ExtensionsBrowserClient::Get()->AreExtensionsDisabled(*command_line,
302 profile))
[email protected]6d60703b2009-08-29 01:29:23303 extensions_enabled_ = false;
[email protected]36a784c2009-06-23 06:21:08304
[email protected]3c4abc82012-10-22 22:25:54305 registrar_.Add(this, chrome::NOTIFICATION_APP_TERMINATING,
306 content::NotificationService::AllBrowserContextsAndSources());
Devlin Cronineea1b7a2018-05-26 02:46:21307 registrar_.Add(this, NOTIFICATION_EXTENSION_PROCESS_TERMINATED,
[email protected]ad50def52011-10-19 23:17:07308 content::NotificationService::AllBrowserContextsAndSources());
[email protected]432115822011-07-10 15:52:27309 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_TERMINATED,
[email protected]ad50def52011-10-19 23:17:07310 content::NotificationService::AllBrowserContextsAndSources());
[email protected]ebe07772014-05-22 04:16:06311 registrar_.Add(this,
312 chrome::NOTIFICATION_PROFILE_DESTRUCTION_STARTED,
313 content::Source<Profile>(profile_));
binjin1569c9b2014-09-05 13:33:18314
weidongg04695232017-06-09 00:01:05315 UpgradeDetector::GetInstance()->AddObserver(this);
316
Devlin Cronineea1b7a2018-05-26 02:46:21317 ExtensionManagementFactory::GetForBrowserContext(profile_)->AddObserver(this);
[email protected]4814b512009-11-07 00:12:29318
rkaplowdd66a1342015-03-05 00:31:49319 // Set up the ExtensionUpdater.
[email protected]93fd78f42009-07-10 16:43:17320 if (autoupdate_enabled) {
Devlin Cronineea1b7a2018-05-26 02:46:21321 updater_.reset(new ExtensionUpdater(
David Bertonidccbd352018-03-20 00:31:04322 this, extension_prefs, profile->GetPrefs(), profile,
Devlin Cronineea1b7a2018-05-26 02:46:21323 kDefaultUpdateFrequencySeconds,
324 ExtensionsBrowserClient::Get()->GetExtensionCache(),
rockotdb5192992014-09-16 21:27:02325 base::Bind(ChromeExtensionDownloaderFactory::CreateForProfile,
326 profile)));
[email protected]93fd78f42009-07-10 16:43:17327 }
328
Devlin Cronineea1b7a2018-05-26 02:46:21329 component_loader_.reset(new ComponentLoader(
330 this, profile->GetPrefs(), g_browser_process->local_state(), profile));
[email protected]8e4560b62011-01-14 10:09:14331
[email protected]0436b102011-04-15 18:30:03332 if (extensions_enabled_) {
Devlin Cronineea1b7a2018-05-26 02:46:21333 ExternalProviderImpl::CreateExternalProviders(
[email protected]ae4c37e2012-12-21 01:16:25334 this, profile_, &external_extension_providers_);
[email protected]873531342011-03-09 12:16:05335 }
[email protected]b671760b2010-07-15 21:13:47336
[email protected]74474042013-11-21 12:03:54337 // Set this as the ExtensionService for app sorting to ensure it causes syncs
338 // if required.
[email protected]b3aa7182013-04-25 04:45:23339 is_first_run_ = !extension_prefs_->SetAlertSystemFirstRun();
340
[email protected]373daf972014-04-10 01:50:44341 error_controller_.reset(
Devlin Cronineea1b7a2018-05-26 02:46:21342 new ExtensionErrorController(profile_, is_first_run_));
[email protected]374ceb6f2014-07-02 19:25:34343 external_install_manager_.reset(
Devlin Cronineea1b7a2018-05-26 02:46:21344 new ExternalInstallManager(profile_, is_first_run_));
[email protected]373daf972014-04-10 01:50:44345
[email protected]c77f2352012-08-08 22:07:58346 extension_action_storage_manager_.reset(
Devlin Cronineea1b7a2018-05-26 02:46:21347 new ExtensionActionStorageManager(profile_));
[email protected]c77f2352012-08-08 22:07:58348
[email protected]cb0e50312011-05-09 15:03:07349 // How long is the path to the Extensions directory?
350 UMA_HISTOGRAM_CUSTOM_COUNTS("Extensions.ExtensionRootPathLength",
drbasicf0d1b262016-08-23 06:10:42351 install_directory_.value().length(), 1, 500, 100);
[email protected]6014d672008-12-05 00:38:25352}
353
Devlin Cronineea1b7a2018-05-26 02:46:21354PendingExtensionManager* ExtensionService::pending_extension_manager() {
[email protected]b2907fd2011-03-25 16:43:37355 return &pending_extension_manager_;
[email protected]ddb1e5a2010-12-13 20:10:45356}
357
[email protected]eaa7dd182010-12-14 11:09:00358ExtensionService::~ExtensionService() {
weidongg04695232017-06-09 00:01:05359 UpgradeDetector::GetInstance()->RemoveObserver(this);
[email protected]c8d407e2011-04-28 21:27:17360 // No need to unload extensions here because they are profile-scoped, and the
361 // profile is in the process of being deleted.
achuith2f5578b2016-02-26 21:57:13362 for (const auto& provider : external_extension_providers_)
[email protected]8e4560b62011-01-14 10:09:14363 provider->ServiceShutdown();
[email protected]6014d672008-12-05 00:38:25364}
365
[email protected]037228a2012-10-05 01:36:16366void ExtensionService::Shutdown() {
Devlin Cronineea1b7a2018-05-26 02:46:21367 ExtensionManagementFactory::GetInstance()
binjin1569c9b2014-09-05 13:33:18368 ->GetForBrowserContext(profile())
369 ->RemoveObserver(this);
[email protected]037228a2012-10-05 01:36:16370}
371
[email protected]b2907fd2011-03-25 16:43:37372const Extension* ExtensionService::GetExtensionById(
373 const std::string& id, bool include_disabled) const {
[email protected]599539802014-01-07 23:06:00374 int include_mask = ExtensionRegistry::ENABLED;
[email protected]695b5712012-12-06 23:55:28375 if (include_disabled) {
mlerman6a37b6a42014-11-26 22:10:53376 // Include blacklisted and blocked extensions here because there are
377 // hundreds of callers of this function, and many might assume that this
378 // includes those that have been disabled due to blacklisting or blocking.
[email protected]599539802014-01-07 23:06:00379 include_mask |= ExtensionRegistry::DISABLED |
mlerman6a37b6a42014-11-26 22:10:53380 ExtensionRegistry::BLACKLISTED | ExtensionRegistry::BLOCKED;
[email protected]695b5712012-12-06 23:55:28381 }
[email protected]599539802014-01-07 23:06:00382 return registry_->GetExtensionById(id, include_mask);
[email protected]695b5712012-12-06 23:55:28383}
384
[email protected]eaa7dd182010-12-14 11:09:00385void ExtensionService::Init() {
[email protected]a29a517a2011-01-21 21:11:12386 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
rkaplowe65c2ff2015-02-14 16:29:54387 TRACE_EVENT0("browser,startup", "ExtensionService::Init");
rkaplowa8fd8d32015-02-25 21:27:56388 SCOPED_UMA_HISTOGRAM_TIMER("Extensions.ExtensionServiceInitTime");
[email protected]3350d712013-11-18 09:32:24389
[email protected]4a10006a2013-05-17 23:18:35390 DCHECK(!is_ready()); // Can't redo init.
[email protected]bb1bc9b32013-12-21 03:09:14391 DCHECK_EQ(registry_->enabled_extensions().size(), 0u);
[email protected]9f1087e2009-06-15 17:29:32392
benwells22ab8ee2015-08-21 02:55:08393 component_loader_->LoadAll();
achuithd3da4f02017-03-23 20:05:29394 bool load_saved_extensions = true;
emaxx35e8b822017-04-11 02:04:29395 bool load_command_line_extensions = extensions_enabled_;
achuithd3da4f02017-03-23 20:05:29396#if defined(OS_CHROMEOS)
tbarzicd2a741e2017-06-28 20:37:54397 if (chromeos::ProfileHelper::IsSigninProfile(profile_) ||
398 chromeos::ProfileHelper::IsLockScreenAppProfile(profile_)) {
achuithd3da4f02017-03-23 20:05:29399 load_saved_extensions = false;
emaxx35e8b822017-04-11 02:04:29400 load_command_line_extensions = false;
401 }
achuithd3da4f02017-03-23 20:05:29402#endif
rdevlin.croninf2e1cb012017-05-27 01:27:59403 if (load_saved_extensions)
Devlin Cronineea1b7a2018-05-26 02:46:21404 InstalledLoader(this).LoadAllExtensions();
rdevlin.croninf2e1cb012017-05-27 01:27:59405
406 OnInstalledExtensionsLoaded();
407
Devlin Cronineea1b7a2018-05-26 02:46:21408 LoadExtensionsFromCommandLineFlag(::switches::kDisableExtensionsExcept);
emaxx35e8b822017-04-11 02:04:29409 if (load_command_line_extensions)
Devlin Cronineea1b7a2018-05-26 02:46:21410 LoadExtensionsFromCommandLineFlag(switches::kLoadExtension);
Tatsuhisa Yamaguchi5ed1aece32017-10-26 10:18:56411 EnableZipUnpackerExtension();
benwells22ab8ee2015-08-21 02:55:08412 EnabledReloadableExtensions();
413 MaybeFinishShutdownDelayed();
414 SetReadyAndNotifyListeners();
[email protected]ae4c37e2012-12-21 01:16:25415
Takumi Fujimoto43c8c00f2017-07-26 22:48:56416 UninstallMigratedExtensions();
417
benwells22ab8ee2015-08-21 02:55:08418 // TODO(erikkay): this should probably be deferred to a future point
419 // rather than running immediately at startup.
420 CheckForExternalUpdates();
[email protected]894bb502009-05-21 22:39:57421
benwells22ab8ee2015-08-21 02:55:08422 LoadGreylistFromPrefs();
rkaplowa8fd8d32015-02-25 21:27:56423}
[email protected]3350d712013-11-18 09:32:24424
Tatsuhisa Yamaguchi5ed1aece32017-10-26 10:18:56425void ExtensionService::EnableZipUnpackerExtensionForTest() {
426 EnableZipUnpackerExtension();
427}
428
429void ExtensionService::EnableZipUnpackerExtension() {
430 TRACE_EVENT0("browser,startup",
431 "ExtensionService::EnableZipUnpackerExtension");
432
433#if defined(OS_CHROMEOS)
434 // There were some cases where the Zip Unpacker was disabled in the profile,
435 // by some reason, and cannot re-enable it in any UI. crbug.com/643060
436 const std::string& id = extension_misc::kZIPUnpackerExtensionId;
437 const Extension* extension = registry_->disabled_extensions().GetByID(id);
Tatsuhisa Yamaguchi6f033fa2017-11-21 14:57:25438 if (extension && CanEnableExtension(extension)) {
Ilya Sherman982457e62017-12-13 02:19:36439 base::UmaHistogramSparse(
Tatsuhisa Yamaguchi6f033fa2017-11-21 14:57:25440 "ExtensionService.ZipUnpackerDisabledReason",
441 extension_prefs_->GetDisableReasons(extension->id()));
Tatsuhisa Yamaguchi5ed1aece32017-10-26 10:18:56442 EnableExtension(id);
Tatsuhisa Yamaguchi6f033fa2017-11-21 14:57:25443 }
Tatsuhisa Yamaguchi5ed1aece32017-10-26 10:18:56444#endif
445}
446
rkaplowa8fd8d32015-02-25 21:27:56447void ExtensionService::EnabledReloadableExtensions() {
448 TRACE_EVENT0("browser,startup",
449 "ExtensionService::EnabledReloadableExtensions");
450
451 std::vector<std::string> extensions_to_enable;
achuith2f5578b2016-02-26 21:57:13452 for (const auto& e : registry_->disabled_extensions()) {
rkaplowa8fd8d32015-02-25 21:27:56453 if (extension_prefs_->GetDisableReasons(e->id()) ==
Devlin Cronineea1b7a2018-05-26 02:46:21454 disable_reason::DISABLE_RELOAD)
rkaplowa8fd8d32015-02-25 21:27:56455 extensions_to_enable.push_back(e->id());
rkaplowa8fd8d32015-02-25 21:27:56456 }
457 for (const std::string& extension : extensions_to_enable) {
458 EnableExtension(extension);
459 }
460}
461
462void ExtensionService::MaybeFinishShutdownDelayed() {
463 TRACE_EVENT0("browser,startup",
464 "ExtensionService::MaybeFinishShutdownDelayed");
465
Devlin Cronineea1b7a2018-05-26 02:46:21466 std::unique_ptr<ExtensionPrefs::ExtensionsInfo> delayed_info(
rkaplowa8fd8d32015-02-25 21:27:56467 extension_prefs_->GetAllDelayedInstallInfo());
468 for (size_t i = 0; i < delayed_info->size(); ++i) {
469 ExtensionInfo* info = delayed_info->at(i).get();
achuith2f5578b2016-02-26 21:57:13470 scoped_refptr<const Extension> extension(nullptr);
rkaplowa8fd8d32015-02-25 21:27:56471 if (info->extension_manifest) {
472 std::string error;
473 extension = Extension::Create(
474 info->extension_path, info->extension_location,
475 *info->extension_manifest,
476 extension_prefs_->GetDelayedInstallCreationFlags(info->extension_id),
477 info->extension_id, &error);
478 if (extension.get())
479 delayed_installs_.Insert(extension);
480 }
481 }
482 MaybeFinishDelayedInstallations();
Devlin Cronineea1b7a2018-05-26 02:46:21483 std::unique_ptr<ExtensionPrefs::ExtensionsInfo> delayed_info2(
rkaplowa8fd8d32015-02-25 21:27:56484 extension_prefs_->GetAllDelayedInstallInfo());
485 UMA_HISTOGRAM_COUNTS_100("Extensions.UpdateOnLoad",
486 delayed_info2->size() - delayed_info->size());
[email protected]6014d672008-12-05 00:38:25487}
488
[email protected]2d19eb6e2014-01-27 17:30:00489void ExtensionService::LoadGreylistFromPrefs() {
rkaplowa8fd8d32015-02-25 21:27:56490 TRACE_EVENT0("browser,startup", "ExtensionService::LoadGreylistFromPrefs");
491
dchengc963c7142016-04-08 03:55:22492 std::unique_ptr<ExtensionSet> all_extensions =
[email protected]f47f7172014-03-19 19:27:10493 registry_->GenerateInstalledExtensionsSet();
[email protected]2d19eb6e2014-01-27 17:30:00494
achuith2f5578b2016-02-26 21:57:13495 for (const auto& extension : *all_extensions) {
Devlin Cronineea1b7a2018-05-26 02:46:21496 const BlacklistState state =
achuith2f5578b2016-02-26 21:57:13497 extension_prefs_->GetExtensionBlacklistState(extension->id());
Devlin Cronineea1b7a2018-05-26 02:46:21498 if (state == BLACKLISTED_SECURITY_VULNERABILITY ||
499 state == BLACKLISTED_POTENTIALLY_UNWANTED ||
500 state == BLACKLISTED_CWS_POLICY_VIOLATION)
achuith2f5578b2016-02-26 21:57:13501 greylist_.Insert(extension);
[email protected]2d19eb6e2014-01-27 17:30:00502 }
503}
504
Devlin Cronineea1b7a2018-05-26 02:46:21505bool ExtensionService::UpdateExtension(const CRXFileInfo& file,
[email protected]044e86992014-01-24 22:59:11506 bool file_ownership_passed,
[email protected]31bb5ee62012-09-12 22:58:40507 CrxInstaller** out_crx_installer) {
[email protected]a29a517a2011-01-21 21:11:12508 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]3c4abc82012-10-22 22:25:54509 if (browser_terminating_) {
510 LOG(WARNING) << "Skipping UpdateExtension due to browser shutdown";
511 // Leak the temp file at extension_path. We don't want to add to the disk
512 // I/O burden at shutdown, we can't rely on the I/O completing anyway, and
513 // the file is in the OS temp directory which should be cleaned up for us.
514 return false;
515 }
[email protected]a8af9fdb2010-10-28 21:52:20516
ginkage553af3202015-02-04 12:39:09517 const std::string& id = file.extension_id;
518
Devlin Cronineea1b7a2018-05-26 02:46:21519 const PendingExtensionInfo* pending_extension_info =
[email protected]51a3bf8b2012-06-08 22:53:06520 pending_extension_manager()->GetById(id);
[email protected]8ef78fd2010-08-19 17:14:32521
[email protected]695b5712012-12-06 23:55:28522 const Extension* extension = GetInstalledExtension(id);
[email protected]51a3bf8b2012-06-08 22:53:06523 if (!pending_extension_info && !extension) {
[email protected]aa142702010-03-26 01:26:33524 LOG(WARNING) << "Will not update extension " << id
525 << " because it is not installed or pending";
526 // Delete extension_path since we're not creating a CrxInstaller
527 // that would do it for us.
asargentd50b18c2016-04-21 01:17:16528 if (file_ownership_passed &&
Devlin Cronineea1b7a2018-05-26 02:46:21529 !GetExtensionFileTaskRunner()->PostTask(
530 FROM_HERE,
531 base::BindOnce(&file_util::DeleteFile, file.path, false)))
[email protected]14908b72011-04-20 06:54:36532 NOTREACHED();
[email protected]420a0ec2011-06-01 01:07:03533
534 return false;
[email protected]e957fe52009-06-23 16:51:05535 }
Minh X. Nguyen30975342017-12-04 22:02:41536 // Either |pending_extension_info| or |extension| or both must not be null.
treibe960e282015-09-11 10:38:08537 scoped_refptr<CrxInstaller> installer(CrxInstaller::CreateSilent(this));
[email protected]6dfbbf82010-03-12 23:09:16538 installer->set_expected_id(id);
ginkage47e603e2015-02-27 08:42:41539 installer->set_expected_hash(file.expected_hash);
[email protected]464213a2013-10-15 01:06:48540 int creation_flags = Extension::NO_FLAGS;
[email protected]51a3bf8b2012-06-08 22:53:06541 if (pending_extension_info) {
542 installer->set_install_source(pending_extension_info->install_source());
pkotwicz31eb1e8ec2014-10-08 15:26:46543 installer->set_allow_silent_install(true);
treibe960e282015-09-11 10:38:08544 // If the extension came in disabled due to a permission increase, then
545 // don't grant it all the permissions. crbug.com/484214
546 bool has_permissions_increase =
Devlin Cronineea1b7a2018-05-26 02:46:21547 ExtensionPrefs::Get(profile_)->HasDisableReason(
548 id, disable_reason::DISABLE_PERMISSIONS_INCREASE);
treibe960e282015-09-11 10:38:08549 const base::Version& expected_version = pending_extension_info->version();
550 if (has_permissions_increase ||
551 pending_extension_info->remote_install() ||
552 !expected_version.IsValid()) {
[email protected]21db9ef2014-05-16 02:06:27553 installer->set_grant_permissions(false);
treibe960e282015-09-11 10:38:08554 } else {
555 installer->set_expected_version(expected_version,
556 false /* fail_install_if_unexpected */);
557 }
mamir0128d5a2016-07-15 20:55:48558 creation_flags = pending_extension_info->creation_flags();
[email protected]464213a2013-10-15 01:06:48559 if (pending_extension_info->mark_acknowledged())
[email protected]374ceb6f2014-07-02 19:25:34560 external_install_manager_->AcknowledgeExternalExtension(id);
Minh X. Nguyen30975342017-12-04 22:02:41561 // If the extension was installed from or has migrated to the webstore, or
562 // its auto-update URL is from the webstore, treat it as a webstore install.
563 // Note that we ignore some older extensions with blank auto-update URLs
564 // because we are mostly concerned with restrictions on NaCl extensions,
565 // which are newer.
566 if (!extension && extension_urls::IsWebstoreUpdateUrl(
567 pending_extension_info->update_url()))
568 creation_flags |= Extension::FROM_WEBSTORE;
569 } else {
570 // |extension| must not be null.
[email protected]5eb375e92010-11-26 07:50:41571 installer->set_install_source(extension->location());
[email protected]51a3bf8b2012-06-08 22:53:06572 }
[email protected]a12ce8b22012-01-17 18:40:53573
Minh X. Nguyen30975342017-12-04 22:02:41574 if (extension) {
575 installer->InitializeCreationFlagsForUpdate(extension, creation_flags);
[email protected]c30bda262014-06-19 04:10:13576 installer->set_do_not_sync(extension_prefs_->DoNotSync(id));
Minh X. Nguyen30975342017-12-04 22:02:41577 } else {
578 installer->set_creation_flags(creation_flags);
579 }
[email protected]044e86992014-01-24 22:59:11580 installer->set_delete_source(file_ownership_passed);
[email protected]cb0e50312011-05-09 15:03:07581 installer->set_install_cause(extension_misc::INSTALL_CAUSE_UPDATE);
ginkage553af3202015-02-04 12:39:09582 installer->InstallCrxFile(file);
[email protected]420a0ec2011-06-01 01:07:03583
584 if (out_crx_installer)
[email protected]dc24976f2013-06-02 21:15:09585 *out_crx_installer = installer.get();
[email protected]420a0ec2011-06-01 01:07:03586
587 return true;
[email protected]e957fe52009-06-23 16:51:05588}
589
catmullings98cd1942016-08-30 22:31:59590void ExtensionService::LoadExtensionsFromCommandLineFlag(
591 const char* switch_name) {
592 if (command_line_->HasSwitch(switch_name)) {
593 base::CommandLine::StringType path_list =
594 command_line_->GetSwitchValueNative(switch_name);
595 base::StringTokenizerT<base::CommandLine::StringType,
596 base::CommandLine::StringType::const_iterator>
597 t(path_list, FILE_PATH_LITERAL(","));
598 while (t.GetNext()) {
599 std::string extension_id;
Devlin Cronineea1b7a2018-05-26 02:46:21600 UnpackedInstaller::Create(this)->LoadFromCommandLine(
catmullings98cd1942016-08-30 22:31:59601 base::FilePath(t.token()), &extension_id, false /*only-allow-apps*/);
602 // Extension id is added to whitelist after its extension is loaded
michaelpga8ea0372017-04-06 20:41:35603 // because code is executed asynchronously. TODO(michaelpg): Remove this
604 // assumption so loading extensions does not have to be asynchronous:
605 // crbug.com/708354.
Devlin Cronineea1b7a2018-05-26 02:46:21606 if (switch_name == ::switches::kDisableExtensionsExcept)
catmullings98cd1942016-08-30 22:31:59607 disable_flag_exempted_extensions_.insert(extension_id);
608 }
609 }
610}
611
Michael Giuffrida573992d2018-02-08 00:48:44612// TODO(michaelpg): Group with other ExtensionRegistrar::Delegate overrides
613// according to header file once diffs have settled down.
614void ExtensionService::LoadExtensionForReload(
Devlin Cronineea1b7a2018-05-26 02:46:21615 const ExtensionId& extension_id,
Michael Giuffrida573992d2018-02-08 00:48:44616 const base::FilePath& path,
617 LoadErrorBehavior load_error_behavior) {
Toni Barzic667db0d32018-01-09 18:00:19618 if (delayed_installs_.Contains(extension_id) &&
619 FinishDelayedInstallationIfReady(extension_id,
620 true /*install_immediately*/)) {
[email protected]0db124b02012-11-07 04:55:05621 return;
622 }
623
[email protected]43ceb002012-02-10 23:19:15624 // If we're reloading a component extension, use the component extension
625 // loader's reloader.
626 if (component_loader_->Exists(extension_id)) {
627 component_loader_->Reload(extension_id);
628 return;
629 }
630
[email protected]e6090e42010-03-23 22:44:08631 // Check the installed extensions to see if what we're reloading was already
632 // installed.
dchengc963c7142016-04-08 03:55:22633 std::unique_ptr<ExtensionInfo> installed_extension(
[email protected]e6090e42010-03-23 22:44:08634 extension_prefs_->GetInstalledExtensionInfo(extension_id));
635 if (installed_extension.get() &&
636 installed_extension->extension_manifest.get()) {
Devlin Cronineea1b7a2018-05-26 02:46:21637 InstalledLoader(this).Load(*installed_extension, false);
[email protected]e6090e42010-03-23 22:44:08638 } else {
Michael Giuffrida573992d2018-02-08 00:48:44639 // Otherwise, the extension is unpacked (location LOAD). We must load it
640 // from the path.
641 CHECK(!path.empty()) << "ExtensionRegistrar should never ask to load an "
642 "unknown extension with no path";
Devlin Cronineea1b7a2018-05-26 02:46:21643 scoped_refptr<UnpackedInstaller> unpacked_installer =
644 UnpackedInstaller::Create(this);
Michael Giuffrida573992d2018-02-08 00:48:44645 unpacked_installer->set_be_noisy_on_failure(load_error_behavior ==
646 LoadErrorBehavior::kNoisy);
[email protected]bca4b832014-07-17 20:22:34647 unpacked_installer->Load(path);
[email protected]e6090e42010-03-23 22:44:08648 }
[email protected]9cddd4702009-07-27 22:09:40649}
650
[email protected]bca4b832014-07-17 20:22:34651void ExtensionService::ReloadExtension(const std::string& extension_id) {
Michael Giuffrida573992d2018-02-08 00:48:44652 extension_registrar_.ReloadExtension(extension_id, LoadErrorBehavior::kNoisy);
[email protected]bca4b832014-07-17 20:22:34653}
654
655void ExtensionService::ReloadExtensionWithQuietFailure(
656 const std::string& extension_id) {
Michael Giuffrida573992d2018-02-08 00:48:44657 extension_registrar_.ReloadExtension(extension_id, LoadErrorBehavior::kQuiet);
[email protected]bca4b832014-07-17 20:22:34658}
659
[email protected]757d60a2014-05-23 00:11:44660bool ExtensionService::UninstallExtension(
661 // "transient" because the process of uninstalling may cause the reference
662 // to become invalid. Instead, use |extenson->id()|.
663 const std::string& transient_extension_id,
Devlin Cronineea1b7a2018-05-26 02:46:21664 UninstallReason reason,
[email protected]757d60a2014-05-23 00:11:44665 base::string16* error) {
[email protected]a29a517a2011-01-21 21:11:12666 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]a8af9fdb2010-10-28 21:52:20667
[email protected]757d60a2014-05-23 00:11:44668 scoped_refptr<const Extension> extension =
669 GetInstalledExtension(transient_extension_id);
[email protected]631cf822009-05-15 07:01:25670
[email protected]e7afe2452010-08-22 16:19:13671 // Callers should not send us nonexistent extensions.
[email protected]dc24976f2013-06-02 21:15:09672 CHECK(extension.get());
[email protected]9f1087e2009-06-15 17:29:32673
binjincccacef2014-10-13 19:00:20674 ManagementPolicy* by_policy = system_->management_policy();
[email protected]95da88c42011-03-31 10:07:33675 // Policy change which triggers an uninstall will always set
676 // |external_uninstall| to true so this is the only way to uninstall
677 // managed extensions.
[email protected]90878c52014-04-04 18:21:02678 // Shared modules being uninstalled will also set |external_uninstall| to true
679 // so that we can guarantee users don't uninstall a shared module.
680 // (crbug.com/273300)
681 // TODO(rdevlin.cronin): This is probably not right. We should do something
682 // else, like include an enum IS_INTERNAL_UNINSTALL or IS_USER_UNINSTALL so
683 // we don't do this.
[email protected]cc2f55c2014-07-08 02:19:04684 bool external_uninstall =
Devlin Cronineea1b7a2018-05-26 02:46:21685 (reason == UNINSTALL_REASON_INTERNAL_MANAGEMENT) ||
686 (reason == UNINSTALL_REASON_COMPONENT_REMOVED) ||
687 (reason == UNINSTALL_REASON_REINSTALL) ||
688 (reason == UNINSTALL_REASON_ORPHANED_EXTERNAL_EXTENSION) ||
689 (reason == UNINSTALL_REASON_ORPHANED_SHARED_MODULE) ||
690 (reason == UNINSTALL_REASON_SYNC &&
691 util::WasInstalledByCustodian(extension->id(), profile_));
[email protected]65187152012-06-02 13:14:14692 if (!external_uninstall &&
binjincccacef2014-10-13 19:00:20693 (!by_policy->UserMayModifySettings(extension.get(), error) ||
694 by_policy->MustRemainInstalled(extension.get(), error))) {
[email protected]ad50def52011-10-19 23:17:07695 content::NotificationService::current()->Notify(
Devlin Cronineea1b7a2018-05-26 02:46:21696 NOTIFICATION_EXTENSION_UNINSTALL_NOT_ALLOWED,
[email protected]6c2381d2011-10-19 02:52:53697 content::Source<Profile>(profile_),
[email protected]dc24976f2013-06-02 21:15:09698 content::Details<const Extension>(extension.get()));
[email protected]d6ebc9792011-04-07 18:18:33699 return false;
700 }
[email protected]95da88c42011-03-31 10:07:33701
juncai33e462102015-05-18 20:48:44702 InstallVerifier::Get(GetBrowserContext())->Remove(extension->id());
[email protected]ffd2f79e2013-11-14 00:11:46703
[email protected]9b217652010-10-08 22:04:23704 UMA_HISTOGRAM_ENUMERATION("Extensions.UninstallType",
[email protected]7fa19f82010-12-21 19:40:08705 extension->GetType(), 100);
treib2e0517f92015-05-07 23:15:36706 RecordPermissionMessagesHistogram(extension.get(), "Uninstall");
[email protected]9b217652010-10-08 22:04:23707
[email protected]831aa212010-03-26 13:55:19708 // Unload before doing more cleanup to ensure that nothing is hanging on to
709 // any of these resources.
limasdf0deef2042017-05-03 19:17:17710 UnloadExtension(extension->id(), UnloadedExtensionReason::UNINSTALL);
asargent96c7ec42016-05-27 02:45:47711 if (registry_->blacklisted_extensions().Contains(extension->id()))
712 registry_->RemoveBlacklisted(extension->id());
[email protected]831aa212010-03-26 13:55:19713
[email protected]9f1087e2009-06-15 17:29:32714 // Tell the backend to start deleting installed extensions on the file thread.
[email protected]12075d12013-02-27 05:38:05715 if (!Manifest::IsUnpackedLocation(extension->location())) {
Devlin Cronineea1b7a2018-05-26 02:46:21716 if (!GetExtensionFileTaskRunner()->PostTask(
[email protected]7f8f24f2012-11-15 19:40:14717 FROM_HERE,
tzik8d880ee2017-04-20 19:46:24718 base::BindOnce(&ExtensionService::UninstallExtensionOnFileThread,
719 extension->id(), profile_, install_directory_,
720 extension->path())))
[email protected]14908b72011-04-20 06:54:36721 NOTREACHED();
[email protected]9f1087e2009-06-15 17:29:32722 }
723
Devlin Cronineea1b7a2018-05-26 02:46:21724 DataDeleter::StartDeleting(profile_, extension.get());
[email protected]0d6ec3a72011-09-02 02:09:43725
Michael Giuffridafcb420362017-10-11 21:50:26726 extension_registrar_.UntrackTerminatedExtension(extension->id());
[email protected]211030342010-09-30 18:41:06727
728 // Notify interested parties that we've uninstalled this extension.
[email protected]e43c61f2014-07-20 21:46:34729 ExtensionRegistry::Get(profile_)
730 ->TriggerOnUninstalled(extension.get(), reason);
[email protected]d6ebc9792011-04-07 18:18:33731
[email protected]757d60a2014-05-23 00:11:44732 delayed_installs_.Remove(extension->id());
[email protected]0db124b02012-11-07 04:55:05733
[email protected]757d60a2014-05-23 00:11:44734 extension_prefs_->OnExtensionUninstalled(
735 extension->id(), extension->location(), external_uninstall);
[email protected]d4eda592013-09-18 03:37:57736
[email protected]333b1de2011-09-12 18:28:50737 // Track the uninstallation.
[email protected]49098f702011-10-13 03:47:18738 UMA_HISTOGRAM_ENUMERATION("Extensions.ExtensionUninstalled", 1, 2);
739
[email protected]d6ebc9792011-04-07 18:18:33740 return true;
[email protected]c10da4b02010-03-25 14:38:32741}
742
[email protected]5a145e82014-05-29 22:19:07743// static
744void ExtensionService::UninstallExtensionOnFileThread(
745 const std::string& id,
746 Profile* profile,
747 const base::FilePath& install_dir,
748 const base::FilePath& extension_path) {
Devlin Cronineea1b7a2018-05-26 02:46:21749 ExtensionAssetsManager* assets_manager =
750 ExtensionAssetsManager::GetInstance();
[email protected]5a145e82014-05-29 22:19:07751 assets_manager->UninstallExtension(id, profile, install_dir, extension_path);
752}
753
[email protected]c3cfb012011-04-06 22:07:35754bool ExtensionService::IsExtensionEnabled(
755 const std::string& extension_id) const {
Michael Giuffrida6397c592017-10-09 20:46:53756 return extension_registrar_.IsExtensionEnabled(extension_id);
[email protected]c3cfb012011-04-06 22:07:35757}
758
[email protected]eaa7dd182010-12-14 11:09:00759void ExtensionService::EnableExtension(const std::string& extension_id) {
[email protected]a29a517a2011-01-21 21:11:12760 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
Michael Giuffrida6397c592017-10-09 20:46:53761 extension_registrar_.EnableExtension(extension_id);
[email protected]0c6da502009-08-14 22:32:39762}
763
treibc1192322015-05-20 12:56:07764void ExtensionService::DisableExtension(const std::string& extension_id,
765 int disable_reasons) {
[email protected]a29a517a2011-01-21 21:11:12766 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
Michael Giuffrida6397c592017-10-09 20:46:53767 extension_registrar_.DisableExtension(extension_id, disable_reasons);
[email protected]1784e83a2009-09-08 21:01:52768}
769
Ivan Sandrk4a55dc22018-05-17 18:14:48770void ExtensionService::DisableExtensionWithSource(
771 const Extension* source_extension,
772 const std::string& extension_id,
Devlin Cronineea1b7a2018-05-26 02:46:21773 disable_reason::DisableReason disable_reasons) {
Ivan Sandrk4a55dc22018-05-17 18:14:48774 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
775
Devlin Cronineea1b7a2018-05-26 02:46:21776 DCHECK(disable_reasons == disable_reason::DISABLE_USER_ACTION ||
777 disable_reasons == disable_reason::DISABLE_BLOCKED_BY_POLICY);
778 if (disable_reasons == disable_reason::DISABLE_BLOCKED_BY_POLICY) {
Ivan Sandrk4a55dc22018-05-17 18:14:48779 DCHECK(Manifest::IsPolicyLocation(source_extension->location()) ||
780 Manifest::IsComponentLocation(source_extension->location()));
781 }
782
783 const Extension* extension = GetExtensionById(extension_id, true);
784 CHECK(system_->management_policy()->ExtensionMayModifySettings(
785 source_extension, extension, nullptr));
786 extension_registrar_.DisableExtension(extension_id, disable_reasons);
787}
788
mtomasz294bb3e2017-01-24 02:17:52789void ExtensionService::DisableUserExtensionsExcept(
[email protected]1abf05e2013-07-09 17:04:36790 const std::vector<std::string>& except_ids) {
Devlin Cronineea1b7a2018-05-26 02:46:21791 ManagementPolicy* management_policy = system_->management_policy();
792 ExtensionList to_disable;
[email protected]e516e4c2013-06-12 17:41:14793
achuith2f5578b2016-02-26 21:57:13794 for (const auto& extension : registry_->enabled_extensions()) {
795 if (management_policy->UserMayModifySettings(extension.get(), nullptr))
796 to_disable.push_back(extension);
[email protected]e516e4c2013-06-12 17:41:14797 }
798
achuith2f5578b2016-02-26 21:57:13799 for (const auto& extension : registry_->terminated_extensions()) {
800 if (management_policy->UserMayModifySettings(extension.get(), nullptr))
801 to_disable.push_back(extension);
802 }
803
804 for (const auto& extension : to_disable) {
805 if (extension->was_installed_by_default() &&
[email protected]3082fe32013-08-06 11:12:38806 extension_urls::IsWebstoreUpdateUrl(
Devlin Cronineea1b7a2018-05-26 02:46:21807 ManifestURL::GetUpdateURL(extension.get())))
[email protected]3082fe32013-08-06 11:12:38808 continue;
achuith2f5578b2016-02-26 21:57:13809 const std::string& id = extension->id();
tripta.g0ac673a2017-07-07 05:45:09810 if (!base::ContainsValue(except_ids, id))
Devlin Cronineea1b7a2018-05-26 02:46:21811 DisableExtension(id, disable_reason::DISABLE_USER_ACTION);
[email protected]e516e4c2013-06-12 17:41:14812 }
813}
814
mlerman6a37b6a42014-11-26 22:10:53815// Extensions that are not locked, components or forced by policy should be
816// locked. Extensions are no longer considered enabled or disabled. Blacklisted
817// extensions are now considered both blacklisted and locked.
818void ExtensionService::BlockAllExtensions() {
819 if (block_extensions_)
820 return;
821 block_extensions_ = true;
822
823 // Blacklisted extensions are already unloaded, need not be blocked.
dchengc963c7142016-04-08 03:55:22824 std::unique_ptr<ExtensionSet> extensions =
mlerman6a37b6a42014-11-26 22:10:53825 registry_->GenerateInstalledExtensionsSet(ExtensionRegistry::ENABLED |
826 ExtensionRegistry::DISABLED |
827 ExtensionRegistry::TERMINATED);
828
achuith2f5578b2016-02-26 21:57:13829 for (const auto& extension : *extensions) {
mlerman6a37b6a42014-11-26 22:10:53830 const std::string& id = extension->id();
831
832 if (!CanBlockExtension(extension.get()))
833 continue;
834
835 registry_->RemoveEnabled(id);
836 registry_->RemoveDisabled(id);
837 registry_->RemoveTerminated(id);
838
839 registry_->AddBlocked(extension.get());
Devlin Cronineea1b7a2018-05-26 02:46:21840 UnloadExtension(id, UnloadedExtensionReason::LOCK_ALL);
mlerman6a37b6a42014-11-26 22:10:53841 }
842}
843
844// All locked extensions should revert to being either enabled or disabled
845// as appropriate.
846void ExtensionService::UnblockAllExtensions() {
847 block_extensions_ = false;
dchengc963c7142016-04-08 03:55:22848 std::unique_ptr<ExtensionSet> to_unblock =
mlerman6a37b6a42014-11-26 22:10:53849 registry_->GenerateInstalledExtensionsSet(ExtensionRegistry::BLOCKED);
850
achuith2f5578b2016-02-26 21:57:13851 for (const auto& extension : *to_unblock) {
mlerman6a37b6a42014-11-26 22:10:53852 registry_->RemoveBlocked(extension->id());
853 AddExtension(extension.get());
854 }
Owen Minb71016d2018-01-11 01:51:49855 // While extensions are blocked, we won't display any external install
856 // warnings. Now that they are unblocked, we should update the error.
857 external_install_manager_->UpdateExternalExtensionAlert();
mlerman6a37b6a42014-11-26 22:10:53858}
859
[email protected]eaa7dd182010-12-14 11:09:00860void ExtensionService::GrantPermissionsAndEnableExtension(
[email protected]009633c2013-03-07 22:08:28861 const Extension* extension) {
862 GrantPermissions(extension);
treib2e0517f92015-05-07 23:15:36863 RecordPermissionMessagesHistogram(extension, "ReEnable");
[email protected]8d888c12010-11-30 00:00:25864 EnableExtension(extension->id());
865}
866
[email protected]009633c2013-03-07 22:08:28867void ExtensionService::GrantPermissions(const Extension* extension) {
[email protected]be083862012-09-01 03:53:45868 CHECK(extension);
Devlin Cronineea1b7a2018-05-26 02:46:21869 PermissionsUpdater(profile()).GrantActivePermissions(extension);
[email protected]be083862012-09-01 03:53:45870}
871
[email protected]fe2dd7742011-04-19 22:52:49872// static
873void ExtensionService::RecordPermissionMessagesHistogram(
[email protected]13c68b62013-05-17 11:29:05874 const Extension* extension, const char* histogram) {
[email protected]de415552013-01-23 04:12:17875 // Since this is called from multiple sources, and since the histogram macros
876 // use statics, we need to manually lookup the histogram ourselves.
treib2e0517f92015-05-07 23:15:36877 base::HistogramBase* counter = base::LinearHistogram::FactoryGet(
878 base::StringPrintf("Extensions.Permissions_%s3", histogram),
879 1,
880 APIPermission::kEnumBoundary,
881 APIPermission::kEnumBoundary + 1,
882 base::HistogramBase::kUmaTargetedHistogramFlag);
883
884 base::HistogramBase* counter_has_any = base::BooleanHistogram::FactoryGet(
885 base::StringPrintf("Extensions.HasPermissions_%s3", histogram),
886 base::HistogramBase::kUmaTargetedHistogramFlag);
887
888 PermissionIDSet permissions =
Devlin Cronineea1b7a2018-05-26 02:46:21889 PermissionMessageProvider::Get()->GetAllPermissionIDs(
rdevlin.cronine2d0fd02015-09-24 22:35:49890 extension->permissions_data()->active_permissions(),
treib2e0517f92015-05-07 23:15:36891 extension->GetType());
892 counter_has_any->AddBoolean(!permissions.empty());
893 for (const PermissionID& id : permissions)
894 counter->Add(id.id());
[email protected]fe2dd7742011-04-19 22:52:49895}
896
Michael Giuffrida6397c592017-10-09 20:46:53897// TODO(michaelpg): Group with other ExtensionRegistrar::Delegate overrides
898// according to header file once diffs have settled down.
899void ExtensionService::PostActivateExtension(
Michael Giuffrida19a55982018-02-10 03:03:26900 scoped_refptr<const Extension> extension) {
[email protected]dcc47642014-03-26 22:03:49901 // TODO(kalman): Convert ExtensionSpecialStoragePolicy to a
902 // BrowserContextKeyedService and use ExtensionRegistryObserver.
Michael Giuffrida6397c592017-10-09 20:46:53903 profile_->GetExtensionSpecialStoragePolicy()->GrantRightsForExtension(
904 extension.get(), profile_);
[email protected]c8d407e2011-04-28 21:27:17905
[email protected]dcc47642014-03-26 22:03:49906 // TODO(kalman): This is broken. The crash reporter is process-wide so doesn't
907 // work properly multi-profile. Besides which, it should be using
908 // ExtensionRegistryObserver. See http://crbug.com/355029.
[email protected]c8d407e2011-04-28 21:27:17909 UpdateActiveExtensionsInCrashReporter();
910
Devlin Cronineea1b7a2018-05-26 02:46:21911 const PermissionsData* permissions_data = extension->permissions_data();
[email protected]d695bb12014-06-05 16:16:30912
[email protected]c8d407e2011-04-28 21:27:17913 // If the extension has permission to load chrome://favicon/ resources we need
914 // to make sure that the FaviconSource is registered with the
915 // ChromeURLDataManager.
[email protected]d695bb12014-06-05 16:16:30916 if (permissions_data->HasHostPermission(GURL(chrome::kChromeUIFaviconURL))) {
pkotwiczd95aa6592017-05-11 02:26:21917 FaviconSource* favicon_source = new FaviconSource(profile_);
[email protected]24ea7a12013-01-27 23:54:53918 content::URLDataSource::Add(profile_, favicon_source);
[email protected]c8d407e2011-04-28 21:27:17919 }
[email protected]b07e606e2012-09-15 20:16:15920
[email protected]b07e606e2012-09-15 20:16:15921 // Same for chrome://theme/ resources.
[email protected]d695bb12014-06-05 16:16:30922 if (permissions_data->HasHostPermission(GURL(chrome::kChromeUIThemeURL))) {
[email protected]b07e606e2012-09-15 20:16:15923 ThemeSource* theme_source = new ThemeSource(profile_);
[email protected]24ea7a12013-01-27 23:54:53924 content::URLDataSource::Add(profile_, theme_source);
[email protected]b07e606e2012-09-15 20:16:15925 }
[email protected]b07e606e2012-09-15 20:16:15926
[email protected]5eddc3e2011-10-26 04:33:31927 // Same for chrome://thumb/ resources.
[email protected]d695bb12014-06-05 16:16:30928 if (permissions_data->HasHostPermission(
929 GURL(chrome::kChromeUIThumbnailURL))) {
[email protected]420e6d92013-09-17 01:48:51930 ThumbnailSource* thumbnail_source = new ThumbnailSource(profile_, false);
[email protected]24ea7a12013-01-27 23:54:53931 content::URLDataSource::Add(profile_, thumbnail_source);
[email protected]5eddc3e2011-10-26 04:33:31932 }
[email protected]62d30f42009-10-01 22:36:06933}
934
Michael Giuffrida6397c592017-10-09 20:46:53935// TODO(michaelpg): Group with other ExtensionRegistrar::Delegate overrides
936// according to header file once diffs have settled down.
Michael Giuffrida023e3532017-09-28 23:21:21937void ExtensionService::PostDeactivateExtension(
938 scoped_refptr<const Extension> extension) {
[email protected]dcc47642014-03-26 22:03:49939 // TODO(kalman): Convert ExtensionSpecialStoragePolicy to a
940 // BrowserContextKeyedService and use ExtensionRegistryObserver.
Michael Giuffrida023e3532017-09-28 23:21:21941 profile_->GetExtensionSpecialStoragePolicy()->RevokeRightsForExtension(
942 extension.get());
[email protected]c8d407e2011-04-28 21:27:17943
[email protected]b777b332011-04-16 04:01:08944#if defined(OS_CHROMEOS)
[email protected]ac66e452013-01-11 09:21:23945 // Revoke external file access for the extension from its file system context.
946 // It is safe to access the extension's storage partition at this point. The
947 // storage partition may get destroyed only after the extension gets unloaded.
Devlin Cronineea1b7a2018-05-26 02:46:21948 GURL site = util::GetSiteForExtensionId(extension->id(), profile_);
[email protected]cd501a72014-08-22 19:58:31949 storage::FileSystemContext* filesystem_context =
950 BrowserContext::GetStoragePartitionForSite(profile_, site)
951 ->GetFileSystemContext();
[email protected]f19bbf62013-07-09 01:22:32952 if (filesystem_context && filesystem_context->external_backend()) {
Michael Giuffrida6397c592017-10-09 20:46:53953 filesystem_context->external_backend()->RevokeAccessForExtension(
954 extension->id());
[email protected]62d30f42009-10-01 22:36:06955 }
[email protected]c8d407e2011-04-28 21:27:17956#endif
957
[email protected]dcc47642014-03-26 22:03:49958 // TODO(kalman): This is broken. The crash reporter is process-wide so doesn't
959 // work properly multi-profile. Besides which, it should be using
960 // ExtensionRegistryObserver::OnExtensionLoaded. See http://crbug.com/355029.
[email protected]c8d407e2011-04-28 21:27:17961 UpdateActiveExtensionsInCrashReporter();
[email protected]62d30f42009-10-01 22:36:06962}
963
[email protected]599539802014-01-07 23:06:00964content::BrowserContext* ExtensionService::GetBrowserContext() const {
965 // Implemented in the .cc file to avoid adding a profile.h dependency to
966 // extension_service.h.
967 return profile_;
968}
969
[email protected]25ae0152011-11-18 14:40:02970bool ExtensionService::is_ready() {
[email protected]4a10006a2013-05-17 23:18:35971 return ready_->is_signaled();
[email protected]25ae0152011-11-18 14:40:02972}
973
[email protected]4ee07c62012-08-21 12:40:42974void ExtensionService::CheckManagementPolicy() {
Devlin Cronineea1b7a2018-05-26 02:46:21975 std::map<std::string, disable_reason::DisableReason> to_disable;
binjin8e3d0182014-12-04 16:44:28976 std::vector<std::string> to_enable;
[email protected]695b5712012-12-06 23:55:28977
Karan Bhatia2a117232017-08-23 00:24:56978 // Loop through the extensions list, finding extensions we need to disable.
achuith2f5578b2016-02-26 21:57:13979 for (const auto& extension : registry_->enabled_extensions()) {
Devlin Cronineea1b7a2018-05-26 02:46:21980 disable_reason::DisableReason disable_reason = disable_reason::DISABLE_NONE;
[email protected]0d54b682013-11-05 14:15:36981 if (system_->management_policy()->MustRemainDisabled(
binjin8e3d0182014-12-04 16:44:28982 extension.get(), &disable_reason, nullptr))
[email protected]0d54b682013-11-05 14:15:36983 to_disable[extension->id()] = disable_reason;
[email protected]aa96d3a2010-08-21 08:45:25984 }
985
Devlin Cronineea1b7a2018-05-26 02:46:21986 ExtensionManagement* management =
987 ExtensionManagementFactory::GetForBrowserContext(profile());
988 PermissionsUpdater(profile()).SetDefaultPolicyHostRestrictions(
Devlin Cronin7e0f41ff2018-05-16 17:19:36989 management->GetDefaultPolicyBlockedHosts(),
990 management->GetDefaultPolicyAllowedHosts());
nrpetere33d2a5b2017-04-25 00:12:31991 for (const auto& extension : registry_->enabled_extensions()) {
992 bool uses_default =
Devlin Cronin7e0f41ff2018-05-16 17:19:36993 management->UsesDefaultPolicyHostRestrictions(extension.get());
nrpetere33d2a5b2017-04-25 00:12:31994 if (uses_default) {
Devlin Cronineea1b7a2018-05-26 02:46:21995 PermissionsUpdater(profile()).SetUsesDefaultHostRestrictions(
nrpetere33d2a5b2017-04-25 00:12:31996 extension.get());
997 } else {
Devlin Cronineea1b7a2018-05-26 02:46:21998 PermissionsUpdater(profile()).SetPolicyHostRestrictions(
Devlin Cronin7e0f41ff2018-05-16 17:19:36999 extension.get(), management->GetPolicyBlockedHosts(extension.get()),
1000 management->GetPolicyAllowedHosts(extension.get()));
nrpetere33d2a5b2017-04-25 00:12:311001 }
1002 }
binjin8e3d0182014-12-04 16:44:281003
1004 // Loop through the disabled extension list, find extensions to re-enable
Karan Bhatia2a117232017-08-23 00:24:561005 // automatically. These extensions are exclusive from the |to_disable| list
1006 // constructed above, since disabled_extensions() and enabled_extensions() are
1007 // supposed to be mutually exclusive.
achuith2f5578b2016-02-26 21:57:131008 for (const auto& extension : registry_->disabled_extensions()) {
Karan Bhatia2a117232017-08-23 00:24:561009 int disable_reasons = extension_prefs_->GetDisableReasons(extension->id());
binjin8e3d0182014-12-04 16:44:281010
Karan Bhatia2a117232017-08-23 00:24:561011 // Find all extensions disabled due to minimum version requirement and
1012 // management policy but now satisfying it.
1013 if (management->CheckMinimumVersion(extension.get(), nullptr)) {
Devlin Cronineea1b7a2018-05-26 02:46:211014 disable_reasons &= (~disable_reason::DISABLE_UPDATE_REQUIRED_BY_POLICY);
Karan Bhatia2a117232017-08-23 00:24:561015 }
1016
1017 if (!system_->management_policy()->MustRemainDisabled(extension.get(),
1018 nullptr, nullptr)) {
Devlin Cronineea1b7a2018-05-26 02:46:211019 disable_reasons &= (~disable_reason::DISABLE_BLOCKED_BY_POLICY);
Karan Bhatia2a117232017-08-23 00:24:561020 }
1021
1022 extension_prefs_->ReplaceDisableReasons(extension->id(), disable_reasons);
Devlin Cronineea1b7a2018-05-26 02:46:211023 if (disable_reasons == disable_reason::DISABLE_NONE)
Karan Bhatia2a117232017-08-23 00:24:561024 to_enable.push_back(extension->id());
1025 }
[email protected]0d54b682013-11-05 14:15:361026
achuith2f5578b2016-02-26 21:57:131027 for (const auto& i : to_disable)
1028 DisableExtension(i.first, i.second);
binjin8e3d0182014-12-04 16:44:281029
Karan Bhatia2a117232017-08-23 00:24:561030 // No extension is getting re-enabled here after disabling because |to_enable|
1031 // is mutually exclusive to |to_disable|.
binjin8e3d0182014-12-04 16:44:281032 for (const std::string& id : to_enable)
1033 EnableExtension(id);
1034
1035 if (updater_.get()) {
1036 // Find all extensions disabled due to minimum version requirement from
1037 // policy (including the ones that got disabled just now), and check
1038 // for update.
Devlin Cronineea1b7a2018-05-26 02:46:211039 ExtensionUpdater::CheckParams to_recheck;
achuith2f5578b2016-02-26 21:57:131040 for (const auto& extension : registry_->disabled_extensions()) {
binjin8e3d0182014-12-04 16:44:281041 if (extension_prefs_->GetDisableReasons(extension->id()) ==
Devlin Cronineea1b7a2018-05-26 02:46:211042 disable_reason::DISABLE_UPDATE_REQUIRED_BY_POLICY) {
binjin8e3d0182014-12-04 16:44:281043 // The minimum version check is the only thing holding this extension
1044 // back, so check if it can be updated to fix that.
1045 to_recheck.ids.push_back(extension->id());
1046 }
1047 }
1048 if (!to_recheck.ids.empty())
Minh X. Nguyen722b9682018-04-25 21:46:481049 updater_->CheckNow(std::move(to_recheck));
binjin8e3d0182014-12-04 16:44:281050 }
[email protected]aa96d3a2010-08-21 08:45:251051}
1052
[email protected]31206602011-04-13 23:07:321053void ExtensionService::CheckForUpdatesSoon() {
[email protected]90878c52014-04-04 18:21:021054 // This can legitimately happen in unit tests.
1055 if (!updater_.get())
1056 return;
1057
raphael.kubo.da.costa8527f942016-11-15 17:03:511058 updater_->CheckSoon();
[email protected]c3cfb012011-04-06 22:07:351059}
1060
[email protected]8e4560b62011-01-14 10:09:141061// Some extensions will autoupdate themselves externally from Chrome. These
rkaplowa8fd8d32015-02-25 21:27:561062// are typically part of some larger client application package. To support
1063// these, the extension will register its location in the preferences file
[email protected]8e4560b62011-01-14 10:09:141064// (and also, on Windows, in the registry) and this code will periodically
1065// check that location for a .crx file, which it will then install locally if
1066// a new version is available.
Devlin Cronin9722a722017-12-16 03:35:101067// Errors are reported through LoadErrorReporter. Success is not reported.
[email protected]eaa7dd182010-12-14 11:09:001068void ExtensionService::CheckForExternalUpdates() {
lazyboy77214d3c2017-04-04 16:46:121069 if (external_updates_disabled_for_test_)
1070 return;
1071
[email protected]a29a517a2011-01-21 21:11:121072 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
rkaplowa8fd8d32015-02-25 21:27:561073 TRACE_EVENT0("browser,startup", "ExtensionService::CheckForExternalUpdates");
1074 SCOPED_UMA_HISTOGRAM_TIMER("Extensions.CheckForExternalUpdatesTime");
[email protected]8e4560b62011-01-14 10:09:141075
1076 // Note that this installation is intentionally silent (since it didn't
1077 // go through the front-end). Extensions that are registered in this
1078 // way are effectively considered 'pre-bundled', and so implicitly
1079 // trusted. In general, if something has HKLM or filesystem access,
1080 // they could install an extension manually themselves anyway.
[email protected]a29a517a2011-01-21 21:11:121081
[email protected]8e4560b62011-01-14 10:09:141082 // Ask each external extension provider to give us a call back for each
1083 // extension they know about. See OnExternalExtension(File|UpdateUrl)Found.
achuith2f5578b2016-02-26 21:57:131084 for (const auto& provider : external_extension_providers_)
[email protected]8e4560b62011-01-14 10:09:141085 provider->VisitRegisteredExtension();
[email protected]8e4560b62011-01-14 10:09:141086
[email protected]50067e52011-10-20 23:17:071087 // Do any required work that we would have done after completion of all
1088 // providers.
[email protected]373daf972014-04-10 01:50:441089 if (external_extension_providers_.empty())
[email protected]50067e52011-10-20 23:17:071090 OnAllExternalProvidersReady();
[email protected]9f1087e2009-06-15 17:29:321091}
1092
[email protected]50067e52011-10-20 23:17:071093void ExtensionService::OnExternalProviderReady(
lazyboye8634172016-01-28 00:10:481094 const ExternalProviderInterface* provider) {
Istiaque Ahmedf6e72622017-09-08 23:14:171095 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]50067e52011-10-20 23:17:071096 CHECK(provider->IsReady());
[email protected]a29a517a2011-01-21 21:11:121097
1098 // An external provider has finished loading. We only take action
[email protected]8e4560b62011-01-14 10:09:141099 // if all of them are finished. So we check them first.
[email protected]94fde232012-04-27 10:22:301100 if (AreAllExternalProvidersReady())
1101 OnAllExternalProvidersReady();
1102}
1103
1104bool ExtensionService::AreAllExternalProvidersReady() const {
achuith2f5578b2016-02-26 21:57:131105 for (const auto& provider : external_extension_providers_) {
1106 if (!provider->IsReady())
[email protected]94fde232012-04-27 10:22:301107 return false;
[email protected]8e4560b62011-01-14 10:09:141108 }
[email protected]94fde232012-04-27 10:22:301109 return true;
[email protected]50067e52011-10-20 23:17:071110}
1111
1112void ExtensionService::OnAllExternalProvidersReady() {
Istiaque Ahmedf6e72622017-09-08 23:14:171113 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]50067e52011-10-20 23:17:071114 // Install any pending extensions.
[email protected]94fde232012-04-27 10:22:301115 if (update_once_all_providers_are_ready_ && updater()) {
1116 update_once_all_providers_are_ready_ = false;
Devlin Cronineea1b7a2018-05-26 02:46:211117 ExtensionUpdater::CheckParams params;
Minh X. Nguyen722b9682018-04-25 21:46:481118 params.callback =
1119 external_updates_finished_callback_.is_null()
1120 ? base::OnceClosure()
1121 : base::BindOnce(
1122 [](base::RepeatingClosure callback) { callback.Run(); },
1123 external_updates_finished_callback_);
1124 updater()->CheckNow(std::move(params));
[email protected]8e4560b62011-01-14 10:09:141125 }
1126
1127 // Uninstall all the unclaimed extensions.
Devlin Cronineea1b7a2018-05-26 02:46:211128 std::unique_ptr<ExtensionPrefs::ExtensionsInfo> extensions_info(
[email protected]8e4560b62011-01-14 10:09:141129 extension_prefs_->GetInstalledExtensionsInfo());
1130 for (size_t i = 0; i < extensions_info->size(); ++i) {
1131 ExtensionInfo* info = extensions_info->at(i).get();
[email protected]1d5e58b2013-01-31 08:41:401132 if (Manifest::IsExternalLocation(info->extension_location))
[email protected]8e4560b62011-01-14 10:09:141133 CheckExternalUninstall(info->extension_id);
1134 }
[email protected]e5af875f2011-10-10 21:09:141135
[email protected]373daf972014-04-10 01:50:441136 error_controller_->ShowErrorIfNeeded();
[email protected]a9aa5932012-01-25 08:27:401137
[email protected]374ceb6f2014-07-02 19:25:341138 external_install_manager_->UpdateExternalExtensionAlert();
[email protected]e5af875f2011-10-10 21:09:141139}
1140
limasdf0deef2042017-05-03 19:17:171141void ExtensionService::UnloadExtension(const std::string& extension_id,
1142 UnloadedExtensionReason reason) {
Devlin Cronin5b35a082017-10-05 20:44:361143 extension_registrar_.RemoveExtension(extension_id, reason);
[email protected]631cf822009-05-15 07:01:251144}
1145
[email protected]8b1ec202013-09-05 02:09:501146void ExtensionService::RemoveComponentExtension(
1147 const std::string& extension_id) {
1148 scoped_refptr<const Extension> extension(
1149 GetExtensionById(extension_id, false));
limasdf0deef2042017-05-03 19:17:171150 UnloadExtension(extension_id, UnloadedExtensionReason::UNINSTALL);
[email protected]ebe07772014-05-22 04:16:061151 if (extension.get()) {
[email protected]e43c61f2014-07-20 21:46:341152 ExtensionRegistry::Get(profile_)->TriggerOnUninstalled(
Devlin Cronineea1b7a2018-05-26 02:46:211153 extension.get(), UNINSTALL_REASON_COMPONENT_REMOVED);
[email protected]ebe07772014-05-22 04:16:061154 }
[email protected]8b1ec202013-09-05 02:09:501155}
1156
[email protected]bb1bc9b32013-12-21 03:09:141157void ExtensionService::UnloadAllExtensionsForTest() {
1158 UnloadAllExtensionsInternal();
[email protected]9f1087e2009-06-15 17:29:321159}
1160
[email protected]bb1bc9b32013-12-21 03:09:141161void ExtensionService::ReloadExtensionsForTest() {
1162 // Calling UnloadAllExtensionsForTest here triggers a false-positive presubmit
1163 // warning about calling test code in production.
1164 UnloadAllExtensionsInternal();
[email protected]eac88332012-12-26 17:57:451165 component_loader_->LoadAll();
Devlin Cronineea1b7a2018-05-26 02:46:211166 InstalledLoader(this).LoadAllExtensions();
rdevlin.croninf2e1cb012017-05-27 01:27:591167 OnInstalledExtensionsLoaded();
[email protected]4a10006a2013-05-17 23:18:351168 // Don't call SetReadyAndNotifyListeners() since tests call this multiple
1169 // times.
[email protected]9f1087e2009-06-15 17:29:321170}
1171
[email protected]820d9bd2013-04-03 03:46:031172void ExtensionService::SetReadyAndNotifyListeners() {
rkaplowa8fd8d32015-02-25 21:27:561173 TRACE_EVENT0("browser,startup",
1174 "ExtensionService::SetReadyAndNotifyListeners");
1175 SCOPED_UMA_HISTOGRAM_TIMER(
1176 "Extensions.ExtensionServiceNotifyReadyListenersTime");
1177
[email protected]4a10006a2013-05-17 23:18:351178 ready_->Signal();
[email protected]820d9bd2013-04-03 03:46:031179 content::NotificationService::current()->Notify(
Devlin Cronineea1b7a2018-05-26 02:46:211180 NOTIFICATION_EXTENSIONS_READY_DEPRECATED,
[email protected]820d9bd2013-04-03 03:46:031181 content::Source<Profile>(profile_),
1182 content::NotificationService::NoDetails());
1183}
1184
[email protected]fcb58a862012-05-01 01:03:151185void ExtensionService::AddExtension(const Extension* extension) {
rdevlin.cronin08ada0f2017-03-09 23:29:521186 if (!Manifest::IsValidLocation(extension->location())) {
1187 // TODO(devlin): We should *never* add an extension with an invalid
1188 // location, but some bugs (e.g. crbug.com/692069) seem to indicate we do.
1189 // Track down the cases when this can happen, and remove this
1190 // DumpWithoutCrashing() (possibly replacing it with a CHECK).
1191 NOTREACHED();
Lukasz Anforowicz68c21772018-01-13 03:42:441192 DEBUG_ALIAS_FOR_CSTR(extension_id_copy, extension->id().c_str(), 33);
rdevlin.cronin08ada0f2017-03-09 23:29:521193 Manifest::Location location = extension->location();
1194 int creation_flags = extension->creation_flags();
1195 Manifest::Type type = extension->manifest()->type();
rdevlin.cronin08ada0f2017-03-09 23:29:521196 base::debug::Alias(&location);
1197 base::debug::Alias(&creation_flags);
1198 base::debug::Alias(&type);
1199 base::debug::DumpWithoutCrashing();
1200 return;
1201 }
1202
[email protected]c8d407e2011-04-28 21:27:171203 // TODO(jstritar): We may be able to get rid of this branch by overriding the
1204 // default extension state to DISABLED when the --disable-extensions flag
1205 // is set (http://crbug.com/29067).
Devlin Croninefe0c882018-04-20 00:06:481206 if (!extensions_enabled_ &&
1207 !Manifest::ShouldAlwaysLoadExtension(extension->location(),
Devlin Cronin8c23eec2018-05-01 18:42:281208 extension->is_theme()) &&
catmullings98cd1942016-08-30 22:31:591209 disable_flag_exempted_extensions_.count(extension->id()) == 0) {
[email protected]fcb58a862012-05-01 01:03:151210 return;
[email protected]330840c2012-08-29 22:21:011211 }
[email protected]c8d407e2011-04-28 21:27:171212
Michael Giuffrida573992d2018-02-08 00:48:441213 extension_registrar_.AddExtension(extension);
Michael Giuffrida023e3532017-09-28 23:21:211214
Michael Giuffrida573992d2018-02-08 00:48:441215 if (registry_->disabled_extensions().Contains(extension->id())) {
1216 // Show the extension disabled error if a permissions increase or a remote
1217 // installation is the reason it was disabled, and no other reasons exist.
1218 int reasons = extension_prefs_->GetDisableReasons(extension->id());
Devlin Cronineea1b7a2018-05-26 02:46:211219 const int kReasonMask = disable_reason::DISABLE_PERMISSIONS_INCREASE |
1220 disable_reason::DISABLE_REMOTE_INSTALL;
Michael Giuffrida573992d2018-02-08 00:48:441221 if (reasons & kReasonMask && !(reasons & ~kReasonMask)) {
1222 AddExtensionDisabledError(
1223 this, extension,
1224 extension_prefs_->HasDisableReason(
Devlin Cronineea1b7a2018-05-26 02:46:211225 extension->id(), disable_reason::DISABLE_REMOTE_INSTALL));
Michael Giuffrida6397c592017-10-09 20:46:531226 }
[email protected]f574c402012-12-04 23:20:311227 }
[email protected]aab98a52009-12-02 03:22:351228}
1229
[email protected]8c484b742012-11-29 06:05:361230void ExtensionService::AddComponentExtension(const Extension* extension) {
1231 const std::string old_version_string(
1232 extension_prefs_->GetVersionString(extension->id()));
pwnallcbd73192016-08-22 18:59:171233 const base::Version old_version(old_version_string);
[email protected]8c484b742012-11-29 06:05:361234
[email protected]0181a7d2013-11-12 01:08:421235 VLOG(1) << "AddComponentExtension " << extension->name();
Devlin Cronin03bf2d22017-12-20 08:21:051236 if (!old_version.IsValid() || old_version != extension->version()) {
[email protected]8c484b742012-11-29 06:05:361237 VLOG(1) << "Component extension " << extension->name() << " ("
Devlin Cronin03bf2d22017-12-20 08:21:051238 << extension->id() << ") installing/upgrading from '"
1239 << old_version_string << "' to "
1240 << extension->version().GetString();
[email protected]8c484b742012-11-29 06:05:361241
Karandeep Bhatiaa8930652017-10-11 17:41:121242 // TODO(crbug.com/696822): If needed, add support for Declarative Net
1243 // Request to component extensions and pass the ruleset checksum here.
Devlin Cronineea1b7a2018-05-26 02:46:211244 AddNewOrUpdatedExtension(extension, Extension::ENABLED, kInstallFlagNone,
1245 syncer::StringOrdinal(), std::string(),
1246 base::nullopt);
[email protected]8c484b742012-11-29 06:05:361247 return;
1248 }
1249
1250 AddExtension(extension);
1251}
1252
[email protected]b914e292013-04-26 07:10:031253void ExtensionService::CheckPermissionsIncrease(const Extension* extension,
treib6e51bca2016-06-15 10:26:031254 bool is_extension_loaded) {
Devlin Cronineea1b7a2018-05-26 02:46:211255 PermissionsUpdater(profile_).InitializePermissions(extension);
[email protected]902fd7b2011-07-27 18:42:311256
[email protected]8d888c12010-11-30 00:00:251257 // We keep track of all permissions the user has granted each extension.
1258 // This allows extensions to gracefully support backwards compatibility
1259 // by including unknown permissions in their manifests. When the user
1260 // installs the extension, only the recognized permissions are recorded.
1261 // When the unknown permissions become recognized (e.g., through browser
1262 // upgrade), we can prompt the user to accept these new permissions.
1263 // Extensions can also silently upgrade to less permissions, and then
1264 // silently upgrade to a version that adds these permissions back.
1265 //
1266 // For example, pretend that Chrome 10 includes a permission "omnibox"
1267 // for an API that adds suggestions to the omnibox. An extension can
1268 // maintain backwards compatibility while still having "omnibox" in the
1269 // manifest. If a user installs the extension on Chrome 9, the browser
1270 // will record the permissions it recognized, not including "omnibox."
1271 // When upgrading to Chrome 10, "omnibox" will be recognized and Chrome
1272 // will disable the extension and prompt the user to approve the increase
1273 // in privileges. The extension could then release a new version that
1274 // removes the "omnibox" permission. When the user upgrades, Chrome will
1275 // still remember that "omnibox" had been granted, so that if the
1276 // extension once again includes "omnibox" in an upgrade, the extension
1277 // can upgrade without requiring this user's approval.
[email protected]eb5e4f92012-08-15 23:33:281278 int disable_reasons = extension_prefs_->GetDisableReasons(extension->id());
[email protected]8d888c12010-11-30 00:00:251279
rockot1d4a06262015-02-17 19:39:281280 // Silently grant all active permissions to default apps and apps installed
1281 // in kiosk mode.
[email protected]211a3f32013-05-28 21:48:181282 bool auto_grant_permission =
rockot1d4a06262015-02-17 19:39:281283 extension->was_installed_by_default() ||
Devlin Cronineea1b7a2018-05-26 02:46:211284 ExtensionsBrowserClient::Get()->IsRunningInForcedAppMode();
[email protected]211a3f32013-05-28 21:48:181285 if (auto_grant_permission)
[email protected]b914e292013-04-26 07:10:031286 GrantPermissions(extension);
1287
1288 bool is_privilege_increase = false;
1289 // We only need to compare the granted permissions to the current permissions
rockot1d4a06262015-02-17 19:39:281290 // if the extension has not been auto-granted its permissions above and is
1291 // installed internally.
1292 if (extension->location() == Manifest::INTERNAL && !auto_grant_permission) {
[email protected]8d888c12010-11-30 00:00:251293 // Add all the recognized permissions if the granted permissions list
1294 // hasn't been initialized yet.
dchengc963c7142016-04-08 03:55:221295 std::unique_ptr<const PermissionSet> granted_permissions =
[email protected]902fd7b2011-07-27 18:42:311296 extension_prefs_->GetGrantedPermissions(extension->id());
[email protected]0d3e4a22011-06-23 19:02:521297 CHECK(granted_permissions.get());
[email protected]8d888c12010-11-30 00:00:251298
1299 // Here, we check if an extension's privileges have increased in a manner
1300 // that requires the user's approval. This could occur because the browser
1301 // upgraded and recognized additional privileges, or an extension upgrades
1302 // to a version that requires additional privileges.
[email protected]c41003472013-10-19 15:37:251303 is_privilege_increase =
Devlin Cronineea1b7a2018-05-26 02:46:211304 PermissionMessageProvider::Get()->IsPrivilegeIncrease(
rdevlin.cronind630c302015-09-30 20:19:331305 *granted_permissions,
rdevlin.cronine2d0fd02015-09-24 22:35:491306 extension->permissions_data()->active_permissions(),
[email protected]076ebeda2014-06-06 21:47:261307 extension->GetType());
treib2c20f9442016-05-18 19:50:281308
1309 // If there was no privilege increase, the extension might still have new
1310 // permissions (which either don't generate a warning message, or whose
1311 // warning messages are suppressed by existing permissions). Grant the new
1312 // permissions.
1313 if (!is_privilege_increase)
1314 GrantPermissions(extension);
[email protected]8d888c12010-11-30 00:00:251315 }
1316
Marc Treib4bdb790b2018-07-07 15:02:481317 // TODO(crbug.com/860198): Before M48, extensions that came to us from sync in
1318 // a disabled state got assigned disable_reason::DISABLE_UNKNOWN_FROM_SYNC.
1319 // That reason isn't used anymore since the actual disable reason(s) are now
1320 // synced. This code is here to migrate any existing old state.
1321 if (disable_reasons & disable_reason::DEPRECATED_DISABLE_UNKNOWN_FROM_SYNC) {
1322 // Remove the disable_reason::DEPRECATED_DISABLE_UNKNOWN_FROM_SYNC
1323 // reason.
1324 disable_reasons &= ~disable_reason::DEPRECATED_DISABLE_UNKNOWN_FROM_SYNC;
1325 extension_prefs_->RemoveDisableReason(
1326 extension->id(), disable_reason::DEPRECATED_DISABLE_UNKNOWN_FROM_SYNC);
1327 // If there was no privilege increase, it was likely disabled by the user.
1328 // (If there *was* a privilege increase, we'll add an appropriate reason
1329 // later on, so nothing needs to be done here.)
1330 if (!is_privilege_increase)
1331 disable_reasons |= disable_reason::DISABLE_USER_ACTION;
1332 }
1333
treib6e51bca2016-06-15 10:26:031334 bool previously_disabled =
1335 extension_prefs_->IsExtensionDisabled(extension->id());
Marc Treib4bdb790b2018-07-07 15:02:481336 // TODO(devlin): Is the |is_extension_loaded| check needed here?
treib6e51bca2016-06-15 10:26:031337 if (is_extension_loaded && previously_disabled) {
treib8a6d9892015-08-26 10:23:191338 // Legacy disabled extensions do not have a disable reason. Infer that it
1339 // was likely disabled by the user.
Devlin Cronineea1b7a2018-05-26 02:46:211340 if (disable_reasons == disable_reason::DISABLE_NONE)
1341 disable_reasons |= disable_reason::DISABLE_USER_ACTION;
[email protected]8d888c12010-11-30 00:00:251342 }
1343
treib6e51bca2016-06-15 10:26:031344 // If the extension is disabled due to a permissions increase, but does in
1345 // fact have all permissions, remove that disable reason.
1346 // TODO(devlin): This was added to fix crbug.com/616474, but it's unclear
1347 // if this behavior should stay forever.
Devlin Cronineea1b7a2018-05-26 02:46:211348 if (disable_reasons & disable_reason::DISABLE_PERMISSIONS_INCREASE) {
treib6e51bca2016-06-15 10:26:031349 bool reset_permissions_increase = false;
1350 if (!is_privilege_increase) {
1351 reset_permissions_increase = true;
Devlin Cronineea1b7a2018-05-26 02:46:211352 disable_reasons &= ~disable_reason::DISABLE_PERMISSIONS_INCREASE;
treib6e51bca2016-06-15 10:26:031353 extension_prefs_->RemoveDisableReason(
Devlin Cronineea1b7a2018-05-26 02:46:211354 extension->id(), disable_reason::DISABLE_PERMISSIONS_INCREASE);
treib6e51bca2016-06-15 10:26:031355 }
1356 UMA_HISTOGRAM_BOOLEAN("Extensions.ResetPermissionsIncrease",
1357 reset_permissions_increase);
1358 }
1359
[email protected]8d888c12010-11-30 00:00:251360 // Extension has changed permissions significantly. Disable it. A
[email protected]21db9ef2014-05-16 02:06:271361 // notification should be sent by the caller. If the extension is already
1362 // disabled because it was installed remotely, don't add another disable
treibaac30ec2015-06-10 09:18:091363 // reason.
1364 if (is_privilege_increase &&
Devlin Cronineea1b7a2018-05-26 02:46:211365 !(disable_reasons & disable_reason::DISABLE_REMOTE_INSTALL)) {
1366 disable_reasons |= disable_reason::DISABLE_PERMISSIONS_INCREASE;
treib8a6d9892015-08-26 10:23:191367 if (!extension_prefs_->DidExtensionEscalatePermissions(extension->id()))
treib2e0517f92015-05-07 23:15:361368 RecordPermissionMessagesHistogram(extension, "AutoDisable");
treib8ecc1eb52015-03-04 18:29:061369
brettw9e85ef42016-11-01 21:01:241370#if BUILDFLAG(ENABLE_SUPERVISED_USERS)
treib8ecc1eb52015-03-04 18:29:061371 // If a custodian-installed extension is disabled for a supervised user due
mamir51e05d02016-10-06 10:55:011372 // to a permissions increase, send a request to the custodian.
Devlin Cronineea1b7a2018-05-26 02:46:211373 if (util::IsExtensionSupervised(extension, profile_) &&
treib40d3ad92015-10-20 18:15:421374 !ExtensionSyncService::Get(profile_)->HasPendingReenable(
Devlin Cronin03bf2d22017-12-20 08:21:051375 extension->id(), extension->version())) {
treib8ecc1eb52015-03-04 18:29:061376 SupervisedUserService* supervised_user_service =
1377 SupervisedUserServiceFactory::GetForProfile(profile_);
treib40d3ad92015-10-20 18:15:421378 supervised_user_service->AddExtensionUpdateRequest(extension->id(),
Devlin Cronin03bf2d22017-12-20 08:21:051379 extension->version());
treib8ecc1eb52015-03-04 18:29:061380 }
1381#endif
[email protected]b914e292013-04-26 07:10:031382 }
treib6e51bca2016-06-15 10:26:031383
Devlin Cronineea1b7a2018-05-26 02:46:211384 if (disable_reasons == disable_reason::DISABLE_NONE)
treib6e51bca2016-06-15 10:26:031385 extension_prefs_->SetExtensionEnabled(extension->id());
1386 else
treib8a6d9892015-08-26 10:23:191387 extension_prefs_->SetExtensionDisabled(extension->id(), disable_reasons);
[email protected]8d888c12010-11-30 00:00:251388}
1389
[email protected]eaa7dd182010-12-14 11:09:001390void ExtensionService::UpdateActiveExtensionsInCrashReporter() {
[email protected]c8865962009-12-16 07:47:391391 std::set<std::string> extension_ids;
achuith2f5578b2016-02-26 21:57:131392 for (const auto& extension : registry_->enabled_extensions()) {
[email protected]1d5e58b2013-01-31 08:41:401393 if (!extension->is_theme() && extension->location() != Manifest::COMPONENT)
[email protected]84df8332011-12-06 18:22:461394 extension_ids.insert(extension->id());
[email protected]aab98a52009-12-02 03:22:351395 }
1396
[email protected]dcc47642014-03-26 22:03:491397 // TODO(kalman): This is broken. ExtensionService is per-profile.
1398 // crash_keys::SetActiveExtensions is per-process. See
1399 // http://crbug.com/355029.
[email protected]f6431be82013-09-07 02:53:451400 crash_keys::SetActiveExtensions(extension_ids);
[email protected]6014d672008-12-05 00:38:251401}
1402
[email protected]8266d662011-07-12 21:53:261403void ExtensionService::OnExtensionInstalled(
[email protected]36a5c4c2011-12-14 16:34:501404 const Extension* extension,
[email protected]98270432012-09-11 20:51:241405 const syncer::StringOrdinal& page_ordinal,
Karandeep Bhatiaa8930652017-10-11 17:41:121406 int install_flags,
1407 const base::Optional<int>& dnr_ruleset_checksum) {
[email protected]a29a517a2011-01-21 21:11:121408 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]a8af9fdb2010-10-28 21:52:201409
[email protected]c3cfb012011-04-06 22:07:351410 const std::string& id = extension->id();
binjin47947f842014-11-18 12:10:241411 int disable_reasons = GetDisableReasonsOnInstalled(extension);
[email protected]d8fd0fd2014-03-24 13:16:061412 std::string install_parameter;
Devlin Cronineea1b7a2018-05-26 02:46:211413 const PendingExtensionInfo* pending_extension_info =
[email protected]96aebe22014-07-16 04:07:511414 pending_extension_manager()->GetById(id);
1415 if (pending_extension_info) {
[email protected]8f3bcbd2013-06-05 08:42:401416 if (!pending_extension_info->ShouldAllowInstall(extension)) {
Devlinec30d362018-07-13 18:13:391417 // Hack for crbug.com/558299, see comment on DeleteThemeDoNotUse.
1418 if (extension->is_theme() && pending_extension_info->is_from_sync())
1419 ExtensionSyncService::Get(profile_)->DeleteThemeDoNotUse(*extension);
1420
[email protected]51a3bf8b2012-06-08 22:53:061421 pending_extension_manager()->Remove(id);
[email protected]8ef78fd2010-08-19 17:14:321422
Devlin Cronineea1b7a2018-05-26 02:46:211423 LOG(WARNING) << "ShouldAllowInstall() returned false for " << id
1424 << " of type " << extension->GetType() << " and update URL "
1425 << ManifestURL::GetUpdateURL(extension).spec()
[email protected]31bb5ee62012-09-12 22:58:401426 << "; not installing";
[email protected]ae6cb3022011-04-04 20:11:541427
[email protected]4416c5a2010-06-26 01:28:571428 // Delete the extension directory since we're not going to
1429 // load it.
Devlin Cronineea1b7a2018-05-26 02:46:211430 if (!GetExtensionFileTaskRunner()->PostTask(
1431 FROM_HERE, base::BindOnce(&file_util::DeleteFile,
tzik8d880ee2017-04-20 19:46:241432 extension->path(), true))) {
[email protected]14908b72011-04-20 06:54:361433 NOTREACHED();
[email protected]31bb5ee62012-09-12 22:58:401434 }
[email protected]4416c5a2010-06-26 01:28:571435 return;
1436 }
[email protected]51a3bf8b2012-06-08 22:53:061437
[email protected]d8fd0fd2014-03-24 13:16:061438 install_parameter = pending_extension_info->install_parameter();
[email protected]51a3bf8b2012-06-08 22:53:061439 pending_extension_manager()->Remove(id);
[email protected]4416c5a2010-06-26 01:28:571440 } else {
[email protected]c3cfb012011-04-06 22:07:351441 // We explicitly want to re-enable an uninstalled external
1442 // extension; if we're here, that means the user is manually
1443 // installing the extension.
[email protected]46f3e102014-03-25 01:22:451444 if (extension_prefs_->IsExternalExtensionUninstalled(id)) {
Devlin Cronineea1b7a2018-05-26 02:46:211445 disable_reasons = disable_reason::DISABLE_NONE;
[email protected]6cc7dbae2011-04-29 21:18:331446 }
[email protected]aa142702010-03-26 01:26:331447 }
1448
asargente4de9f92016-09-15 01:40:061449 // If the old version of the extension was disabled due to corruption, this
1450 // new install may correct the problem.
Devlin Cronineea1b7a2018-05-26 02:46:211451 disable_reasons &= ~disable_reason::DISABLE_CORRUPTED;
asargente4de9f92016-09-15 01:40:061452
[email protected]98270432012-09-11 20:51:241453 // Unsupported requirements overrides the management policy.
Devlin Cronineea1b7a2018-05-26 02:46:211454 if (install_flags & kInstallFlagHasRequirementErrors) {
1455 disable_reasons |= disable_reason::DISABLE_UNSUPPORTED_REQUIREMENT;
binjin8e3d0182014-12-04 16:44:281456 } else {
1457 // Requirement is supported now, remove the corresponding disable reason
1458 // instead.
Devlin Cronineea1b7a2018-05-26 02:46:211459 disable_reasons &= ~disable_reason::DISABLE_UNSUPPORTED_REQUIREMENT;
binjin8e3d0182014-12-04 16:44:281460 }
1461
1462 // Check if the extension was disabled because of the minimum version
1463 // requirements from enterprise policy, and satisfies it now.
Devlin Cronineea1b7a2018-05-26 02:46:211464 if (ExtensionManagementFactory::GetForBrowserContext(profile())
binjin8e3d0182014-12-04 16:44:281465 ->CheckMinimumVersion(extension, nullptr)) {
1466 // And remove the corresponding disable reason.
Devlin Cronineea1b7a2018-05-26 02:46:211467 disable_reasons &= ~disable_reason::DISABLE_UPDATE_REQUIRED_BY_POLICY;
[email protected]98270432012-09-11 20:51:241468 }
1469
Devlin Cronineea1b7a2018-05-26 02:46:211470 if (install_flags & kInstallFlagIsBlacklistedForMalware) {
[email protected]9f3c8532013-07-31 19:52:071471 // Installation of a blacklisted extension can happen from sync, policy,
1472 // etc, where to maintain consistency we need to install it, just never
1473 // load it (see AddExtension). Usually it should be the job of callers to
treibaac30ec2015-06-10 09:18:091474 // intercept blacklisted extensions earlier (e.g. CrxInstaller, before even
[email protected]9f3c8532013-07-31 19:52:071475 // showing the install dialogue).
[email protected]7c82539c2014-02-19 06:09:171476 extension_prefs_->AcknowledgeBlacklistedExtension(id);
[email protected]9f3c8532013-07-31 19:52:071477 UMA_HISTOGRAM_ENUMERATION("ExtensionBlacklist.SilentInstall",
1478 extension->location(),
1479 Manifest::NUM_LOCATIONS);
1480 }
1481
[email protected]695b5712012-12-06 23:55:281482 if (!GetInstalledExtension(extension->id())) {
[email protected]07533022011-06-27 20:42:551483 UMA_HISTOGRAM_ENUMERATION("Extensions.InstallType",
1484 extension->GetType(), 100);
[email protected]69084dc2012-11-17 07:39:301485 UMA_HISTOGRAM_ENUMERATION("Extensions.InstallSource",
[email protected]1d5e58b2013-01-31 08:41:401486 extension->location(), Manifest::NUM_LOCATIONS);
treib2e0517f92015-05-07 23:15:361487 RecordPermissionMessagesHistogram(extension, "Install");
[email protected]69084dc2012-11-17 07:39:301488 } else {
1489 UMA_HISTOGRAM_ENUMERATION("Extensions.UpdateType",
1490 extension->GetType(), 100);
1491 UMA_HISTOGRAM_ENUMERATION("Extensions.UpdateSource",
[email protected]1d5e58b2013-01-31 08:41:401492 extension->location(), Manifest::NUM_LOCATIONS);
[email protected]07533022011-06-27 20:42:551493 }
1494
[email protected]399583b2012-12-11 09:33:421495 const Extension::State initial_state =
Devlin Cronineea1b7a2018-05-26 02:46:211496 disable_reasons == disable_reason::DISABLE_NONE ? Extension::ENABLED
1497 : Extension::DISABLED;
treib8a6d9892015-08-26 10:23:191498 if (initial_state == Extension::ENABLED)
1499 extension_prefs_->SetExtensionEnabled(id);
1500 else
1501 extension_prefs_->SetExtensionDisabled(id, disable_reasons);
binjin47947f842014-11-18 12:10:241502
Devlin Cronineea1b7a2018-05-26 02:46:211503 ExtensionPrefs::DelayReason delay_reason;
1504 InstallGate::Action action = ShouldDelayExtensionInstall(
1505 extension, !!(install_flags & kInstallFlagInstallImmediately),
xiyuanf6a4c6a62016-04-19 18:14:541506 &delay_reason);
1507 switch (action) {
Devlin Cronineea1b7a2018-05-26 02:46:211508 case InstallGate::INSTALL:
xiyuanf6a4c6a62016-04-19 18:14:541509 AddNewOrUpdatedExtension(extension, initial_state, install_flags,
Karandeep Bhatiaa8930652017-10-11 17:41:121510 page_ordinal, install_parameter,
1511 dnr_ruleset_checksum);
xiyuanf6a4c6a62016-04-19 18:14:541512 return;
Devlin Cronineea1b7a2018-05-26 02:46:211513 case InstallGate::DELAY:
Karandeep Bhatiaa8930652017-10-11 17:41:121514 extension_prefs_->SetDelayedInstallInfo(
1515 extension, initial_state, install_flags, delay_reason, page_ordinal,
1516 install_parameter, dnr_ruleset_checksum);
[email protected]0db124b02012-11-07 04:55:051517
xiyuanf6a4c6a62016-04-19 18:14:541518 // Transfer ownership of |extension|.
[email protected]9f4e4f082013-06-21 07:11:191519 delayed_installs_.Insert(extension);
xiyuanf6a4c6a62016-04-19 18:14:541520
Devlin Cronineea1b7a2018-05-26 02:46:211521 if (delay_reason == ExtensionPrefs::DELAY_REASON_WAIT_FOR_IDLE) {
xiyuanf6a4c6a62016-04-19 18:14:541522 // Notify observers that app update is available.
ericwilligersb5f79de2016-10-19 04:15:101523 for (auto& observer : update_observers_)
1524 observer.OnAppUpdateAvailable(extension);
xiyuanf6a4c6a62016-04-19 18:14:541525 }
1526 return;
Devlin Cronineea1b7a2018-05-26 02:46:211527 case InstallGate::ABORT:
xiyuanf6a4c6a62016-04-19 18:14:541528 // Do nothing to abort the install. One such case is the shared module
1529 // service gets IMPORT_STATUS_UNRECOVERABLE status for the pending
1530 // install.
1531 return;
[email protected]399583b2012-12-11 09:33:421532 }
xiyuanf6a4c6a62016-04-19 18:14:541533
1534 NOTREACHED() << "Unknown action for delayed install: " << action;
[email protected]8c484b742012-11-29 06:05:361535}
1536
binjin1569c9b2014-09-05 13:33:181537void ExtensionService::OnExtensionManagementSettingsChanged() {
1538 error_controller_->ShowErrorIfNeeded();
binjine6b58b52014-10-31 01:55:571539
1540 // Revokes blocked permissions from active_permissions for all extensions.
Devlin Cronineea1b7a2018-05-26 02:46:211541 ExtensionManagement* settings =
1542 ExtensionManagementFactory::GetForBrowserContext(profile());
binjine6b58b52014-10-31 01:55:571543 CHECK(settings);
dchengc963c7142016-04-08 03:55:221544 std::unique_ptr<ExtensionSet> all_extensions(
binjine6b58b52014-10-31 01:55:571545 registry_->GenerateInstalledExtensionsSet());
achuith2f5578b2016-02-26 21:57:131546 for (const auto& extension : *all_extensions) {
binjine6b58b52014-10-31 01:55:571547 if (!settings->IsPermissionSetAllowed(
binjin685ade82014-11-06 09:53:561548 extension.get(),
Nick Peterson0203be4a2017-07-19 00:25:141549 extension->permissions_data()->active_permissions()) &&
1550 CanBlockExtension(extension.get())) {
Devlin Cronineea1b7a2018-05-26 02:46:211551 PermissionsUpdater(profile()).RemovePermissionsUnsafe(
rdevlin.cronind630c302015-09-30 20:19:331552 extension.get(), *settings->GetBlockedPermissions(extension.get()));
binjine6b58b52014-10-31 01:55:571553 }
1554 }
1555
binjin1569c9b2014-09-05 13:33:181556 CheckManagementPolicy();
1557}
1558
[email protected]8c484b742012-11-29 06:05:361559void ExtensionService::AddNewOrUpdatedExtension(
1560 const Extension* extension,
[email protected]399583b2012-12-11 09:33:421561 Extension::State initial_state,
[email protected]4a1d9c0d2014-06-13 12:50:111562 int install_flags,
[email protected]d8fd0fd2014-03-24 13:16:061563 const syncer::StringOrdinal& page_ordinal,
Karandeep Bhatiaa8930652017-10-11 17:41:121564 const std::string& install_parameter,
1565 const base::Optional<int>& dnr_ruleset_checksum) {
[email protected]8c484b742012-11-29 06:05:361566 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
Karandeep Bhatiaa8930652017-10-11 17:41:121567 extension_prefs_->OnExtensionInstalled(extension, initial_state, page_ordinal,
1568 install_flags, install_parameter,
1569 dnr_ruleset_checksum);
[email protected]9e9c1d12013-07-31 01:58:121570 delayed_installs_.Remove(extension->id());
[email protected]913ffca92014-03-27 15:26:161571 if (InstallVerifier::NeedsVerification(*extension))
juncai33e462102015-05-18 20:48:441572 InstallVerifier::Get(GetBrowserContext())->VerifyExtension(extension->id());
ryanackley48bedbd2015-01-27 23:12:141573
1574 const Extension* old = GetInstalledExtension(extension->id());
Devlin Cronineea1b7a2018-05-26 02:46:211575 if (AppDataMigrator::NeedsMigration(old, extension)) {
ryanackley48bedbd2015-01-27 23:12:141576 app_data_migrator_->DoMigrationAndReply(
vmpstra34d11322016-03-21 20:28:471577 old, extension, base::Bind(&ExtensionService::FinishInstallation,
1578 AsWeakPtr(), base::RetainedRef(extension)));
ryanackley48bedbd2015-01-27 23:12:141579 return;
1580 }
1581
benwells1dd4acd2015-12-09 02:20:241582 FinishInstallation(extension);
[email protected]6f6101832012-11-27 22:10:481583}
1584
Toni Barzic667db0d32018-01-09 18:00:191585bool ExtensionService::FinishDelayedInstallationIfReady(
1586 const std::string& extension_id,
1587 bool install_immediately) {
[email protected]9f4e4f082013-06-21 07:11:191588 // Check if the extension already got installed.
[email protected]9f4e4f082013-06-21 07:11:191589 const Extension* extension = delayed_installs_.GetByID(extension_id);
xiyuanf6a4c6a62016-04-19 18:14:541590 if (!extension)
Toni Barzic667db0d32018-01-09 18:00:191591 return false;
xiyuanf6a4c6a62016-04-19 18:14:541592
Devlin Cronineea1b7a2018-05-26 02:46:211593 ExtensionPrefs::DelayReason reason;
1594 const InstallGate::Action action =
Toni Barzic667db0d32018-01-09 18:00:191595 ShouldDelayExtensionInstall(extension, install_immediately, &reason);
xiyuanf6a4c6a62016-04-19 18:14:541596 switch (action) {
Devlin Cronineea1b7a2018-05-26 02:46:211597 case InstallGate::INSTALL:
xiyuanf6a4c6a62016-04-19 18:14:541598 break;
Devlin Cronineea1b7a2018-05-26 02:46:211599 case InstallGate::DELAY:
xiyuanf6a4c6a62016-04-19 18:14:541600 // Bail out and continue to delay the install.
Toni Barzic667db0d32018-01-09 18:00:191601 return false;
Devlin Cronineea1b7a2018-05-26 02:46:211602 case InstallGate::ABORT:
xiyuanf6a4c6a62016-04-19 18:14:541603 delayed_installs_.Remove(extension_id);
1604 // Make sure no version of the extension is actually installed, (i.e.,
1605 // that this delayed install was not an update).
1606 CHECK(!extension_prefs_->GetInstalledExtensionInfo(extension_id).get());
1607 extension_prefs_->DeleteExtensionPrefs(extension_id);
Toni Barzic667db0d32018-01-09 18:00:191608 return false;
[email protected]9f4e4f082013-06-21 07:11:191609 }
1610
Toni Barzic667db0d32018-01-09 18:00:191611 scoped_refptr<const Extension> delayed_install =
1612 GetPendingExtensionUpdate(extension_id);
1613 CHECK(delayed_install.get());
[email protected]9f4e4f082013-06-21 07:11:191614 delayed_installs_.Remove(extension_id);
[email protected]6f6101832012-11-27 22:10:481615
[email protected]399583b2012-12-11 09:33:421616 if (!extension_prefs_->FinishDelayedInstallInfo(extension_id))
[email protected]6f6101832012-11-27 22:10:481617 NOTREACHED();
1618
Toni Barzic667db0d32018-01-09 18:00:191619 FinishInstallation(delayed_install.get());
1620 return true;
[email protected]6f6101832012-11-27 22:10:481621}
1622
[email protected]760f743b2014-05-28 13:52:021623void ExtensionService::FinishInstallation(
benwells1dd4acd2015-12-09 02:20:241624 const Extension* extension) {
Devlin Cronineea1b7a2018-05-26 02:46:211625 const Extension* existing_extension = GetInstalledExtension(extension->id());
[email protected]e7554c3f2013-05-29 00:36:561626 bool is_update = false;
1627 std::string old_name;
1628 if (existing_extension) {
1629 is_update = true;
1630 old_name = existing_extension->name();
1631 }
[email protected]bc44b5da2014-06-12 14:20:001632 registry_->TriggerOnWillBeInstalled(
benwells1dd4acd2015-12-09 02:20:241633 extension, is_update, old_name);
[email protected]17f07822014-05-22 08:45:151634
[email protected]399583b2012-12-11 09:33:421635 // Unpacked extensions default to allowing file access, but if that has been
1636 // overridden, don't reset the value.
[email protected]1d5e58b2013-01-31 08:41:401637 if (Manifest::ShouldAlwaysAllowFileAccess(extension->location()) &&
[email protected]399583b2012-12-11 09:33:421638 !extension_prefs_->HasAllowFileAccessSetting(extension->id())) {
1639 extension_prefs_->SetAllowFileAccess(extension->id(), true);
1640 }
1641
[email protected]6f6101832012-11-27 22:10:481642 AddExtension(extension);
[email protected]612a1cb12012-10-17 13:18:031643
[email protected]bc44b5da2014-06-12 14:20:001644 // Notify observers that need to know when an installation is complete.
[email protected]38e872532014-07-16 23:27:511645 registry_->TriggerOnInstalled(extension, is_update);
[email protected]bc44b5da2014-06-12 14:20:001646
[email protected]9f4e4f082013-06-21 07:11:191647 // Check extensions that may have been delayed only because this shared module
1648 // was not available.
[email protected]374ceb6f2014-07-02 19:25:341649 if (SharedModuleInfo::IsSharedModule(extension))
[email protected]9f4e4f082013-06-21 07:11:191650 MaybeFinishDelayedInstallations();
[email protected]4a190632009-05-09 01:07:421651}
1652
[email protected]76b65442012-11-17 14:11:481653const Extension* ExtensionService::GetPendingExtensionUpdate(
1654 const std::string& id) const {
[email protected]9f4e4f082013-06-21 07:11:191655 return delayed_installs_.GetByID(id);
[email protected]76b65442012-11-17 14:11:481656}
1657
mukai87a8d402014-09-15 20:15:091658void ExtensionService::RegisterContentSettings(
mmenkead5094ab2017-05-15 19:01:141659 HostContentSettingsMap* host_content_settings_map,
1660 Profile* profile) {
1661 // Most extension services key off of the original profile.
1662 Profile* original_profile = profile->GetOriginalProfile();
1663
rkaplowe65c2ff2015-02-14 16:29:541664 TRACE_EVENT0("browser,startup", "ExtensionService::RegisterContentSettings");
mukaia1aa3512014-10-22 20:14:111665 DCHECK_CURRENTLY_ON(BrowserThread::UI);
mukai87a8d402014-09-15 20:15:091666 host_content_settings_map->RegisterProvider(
mukai87a8d402014-09-15 20:15:091667 HostContentSettingsMap::CUSTOM_EXTENSION_PROVIDER,
dchengc963c7142016-04-08 03:55:221668 std::unique_ptr<content_settings::ObservableProvider>(
mukai87a8d402014-09-15 20:15:091669 new content_settings::CustomExtensionProvider(
Devlin Cronineea1b7a2018-05-26 02:46:211670 ContentSettingsService::Get(original_profile)
dchengc963c7142016-04-08 03:55:221671 ->content_settings_store(),
mmenkead5094ab2017-05-15 19:01:141672 // TODO(mmenke): CustomExtensionProvider expects this to be true
1673 // for incognito profiles.
1674 false)));
mukai87a8d402014-09-15 20:15:091675}
1676
[email protected]e9d7496e2014-04-18 01:25:461677void ExtensionService::TerminateExtension(const std::string& extension_id) {
Michael Giuffridafcb420362017-10-11 21:50:261678 extension_registrar_.TerminateExtension(extension_id);
[email protected]bb7f40952011-01-13 00:21:201679}
1680
[email protected]8001df22011-04-28 19:59:471681const Extension* ExtensionService::GetInstalledExtension(
1682 const std::string& id) const {
[email protected]599539802014-01-07 23:06:001683 return registry_->GetExtensionById(id, ExtensionRegistry::EVERYTHING);
[email protected]0dfe05c2011-02-23 23:03:361684}
1685
[email protected]9060d8b02012-01-13 02:14:301686bool ExtensionService::OnExternalExtensionFileFound(
lazyboye8634172016-01-28 00:10:481687 const ExternalInstallInfoFile& info) {
Istiaque Ahmedf6e72622017-09-08 23:14:171688 DCHECK_CURRENTLY_ON(BrowserThread::UI);
lazyboye8634172016-01-28 00:10:481689 CHECK(crx_file::id_util::IdIsValid(info.extension_id));
1690 if (extension_prefs_->IsExternalExtensionUninstalled(info.extension_id))
[email protected]9060d8b02012-01-13 02:14:301691 return false;
[email protected]a8af9fdb2010-10-28 21:52:201692
[email protected]7577a5c52009-07-30 06:21:581693 // Before even bothering to unpack, check and see if we already have this
[email protected]4c967932009-07-31 01:15:491694 // version. This is important because these extensions are going to get
[email protected]7577a5c52009-07-30 06:21:581695 // installed on every startup.
lazyboye8634172016-01-28 00:10:481696 const Extension* existing = GetExtensionById(info.extension_id, true);
[email protected]910f72ce2012-08-24 01:38:351697
[email protected]7577a5c52009-07-30 06:21:581698 if (existing) {
[email protected]910f72ce2012-08-24 01:38:351699 // The default apps will have the location set as INTERNAL. Since older
1700 // default apps are installed as EXTERNAL, we override them. However, if the
1701 // app is already installed as internal, then do the version check.
[email protected]31bb5ee62012-09-12 22:58:401702 // TODO(grv) : Remove after Q1-2013.
[email protected]910f72ce2012-08-24 01:38:351703 bool is_default_apps_migration =
lazyboye8634172016-01-28 00:10:481704 (info.crx_location == Manifest::INTERNAL &&
[email protected]1d5e58b2013-01-31 08:41:401705 Manifest::IsExternalLocation(existing->location()));
[email protected]910f72ce2012-08-24 01:38:351706
1707 if (!is_default_apps_migration) {
Devlin Cronin03bf2d22017-12-20 08:21:051708 switch (existing->version().CompareTo(info.version)) {
[email protected]910f72ce2012-08-24 01:38:351709 case -1: // existing version is older, we should upgrade
1710 break;
1711 case 0: // existing version is same, do nothing
1712 return false;
1713 case 1: // existing version is newer, uh-oh
lazyboye8634172016-01-28 00:10:481714 LOG(WARNING) << "Found external version of extension "
1715 << info.extension_id
[email protected]910f72ce2012-08-24 01:38:351716 << "that is older than current version. Current version "
1717 << "is: " << existing->VersionString() << ". New "
Devlin Cronind4c2a8f32017-09-29 17:08:301718 << "version is: " << info.version.GetString()
[email protected]910f72ce2012-08-24 01:38:351719 << ". Keeping current version.";
1720 return false;
1721 }
[email protected]7577a5c52009-07-30 06:21:581722 }
1723 }
1724
[email protected]9060d8b02012-01-13 02:14:301725 // If the extension is already pending, don't start an install.
[email protected]e3987852012-05-04 10:06:301726 if (!pending_extension_manager()->AddFromExternalFile(
Devlin Cronind4c2a8f32017-09-29 17:08:301727 info.extension_id, info.crx_location, info.version,
lazyboye8634172016-01-28 00:10:481728 info.creation_flags, info.mark_acknowledged)) {
[email protected]9060d8b02012-01-13 02:14:301729 return false;
[email protected]e3987852012-05-04 10:06:301730 }
[email protected]9c635f22010-12-02 09:36:361731
[email protected]14908b72011-04-20 06:54:361732 // no client (silent install)
[email protected]f8636f92013-08-09 21:02:371733 scoped_refptr<CrxInstaller> installer(CrxInstaller::CreateSilent(this));
lazyboye8634172016-01-28 00:10:481734 installer->set_install_source(info.crx_location);
1735 installer->set_expected_id(info.extension_id);
Devlin Cronind4c2a8f32017-09-29 17:08:301736 installer->set_expected_version(info.version,
treibe960e282015-09-11 10:38:081737 true /* fail_install_if_unexpected */);
[email protected]cb0e50312011-05-09 15:03:071738 installer->set_install_cause(extension_misc::INSTALL_CAUSE_EXTERNAL_FILE);
lazyboye8634172016-01-28 00:10:481739 installer->set_install_immediately(info.install_immediately);
1740 installer->set_creation_flags(info.creation_flags);
[email protected]88e8ec9152013-01-17 04:05:181741#if defined(OS_CHROMEOS)
Devlin Cronineea1b7a2018-05-26 02:46:211742 InstallLimiter::Get(profile_)->Add(installer, info.path);
[email protected]88e8ec9152013-01-17 04:05:181743#else
lazyboye8634172016-01-28 00:10:481744 installer->InstallCrx(info.path);
[email protected]88e8ec9152013-01-17 04:05:181745#endif
[email protected]47fc70c2011-12-06 07:29:511746
1747 // Depending on the source, a new external extension might not need a user
1748 // notification on installation. For such extensions, mark them acknowledged
1749 // now to suppress the notification.
lazyboye8634172016-01-28 00:10:481750 if (info.mark_acknowledged)
1751 external_install_manager_->AcknowledgeExternalExtension(info.extension_id);
[email protected]9060d8b02012-01-13 02:14:301752
1753 return true;
[email protected]7577a5c52009-07-30 06:21:581754}
1755
[email protected]eaa7dd182010-12-14 11:09:001756void ExtensionService::DidCreateRenderViewForBackgroundPage(
Devlin Cronineea1b7a2018-05-26 02:46:211757 ExtensionHost* host) {
Michael Giuffrida573992d2018-02-08 00:48:441758 extension_registrar_.DidCreateRenderViewForBackgroundPage(host);
[email protected]406027c02010-09-27 08:03:181759}
1760
[email protected]432115822011-07-10 15:52:271761void ExtensionService::Observe(int type,
[email protected]6c2381d2011-10-19 02:52:531762 const content::NotificationSource& source,
1763 const content::NotificationDetails& details) {
[email protected]432115822011-07-10 15:52:271764 switch (type) {
[email protected]3c4abc82012-10-22 22:25:541765 case chrome::NOTIFICATION_APP_TERMINATING:
1766 // Shutdown has started. Don't start any more extension installs.
1767 // (We cannot use ExtensionService::Shutdown() for this because it
1768 // happens too late in browser teardown.)
1769 browser_terminating_ = true;
1770 break;
Devlin Cronineea1b7a2018-05-26 02:46:211771 case NOTIFICATION_EXTENSION_PROCESS_TERMINATED: {
[email protected]6c2381d2011-10-19 02:52:531772 if (profile_ !=
1773 content::Source<Profile>(source).ptr()->GetOriginalProfile()) {
[email protected]bc535ee52010-08-31 18:40:321774 break;
[email protected]6c2381d2011-10-19 02:52:531775 }
[email protected]a4ed6282009-12-14 20:51:161776
Michael Giuffridafcb420362017-10-11 21:50:261777 // Mark the extension as terminated and deactivated. We want it to
[email protected]fa2416f2011-05-03 08:41:201778 // be in a consistent state: either fully working or not loaded
1779 // at all, but never half-crashed. We do it in a PostTask so
1780 // that other handlers of this notification will still have
1781 // access to the Extension and ExtensionHost.
Devlin Cronineea1b7a2018-05-26 02:46:211782 ExtensionHost* host = content::Details<ExtensionHost>(details).ptr();
skyostilf221b7de2015-06-11 20:36:321783 base::ThreadTaskRunnerHandle::Get()->PostTask(
Michael Giuffridafcb420362017-10-11 21:50:261784 FROM_HERE, base::BindOnce(&ExtensionService::TerminateExtension,
1785 AsWeakPtr(), host->extension_id()));
[email protected]31f77262009-12-02 20:48:531786 break;
1787 }
[email protected]432115822011-07-10 15:52:271788 case content::NOTIFICATION_RENDERER_PROCESS_TERMINATED: {
[email protected]f3b1a082011-11-18 00:34:301789 content::RenderProcessHost* process =
1790 content::Source<content::RenderProcessHost>(source).ptr();
[email protected]fc30ef082011-08-18 04:07:191791 Profile* host_profile =
[email protected]f3b1a082011-11-18 00:34:301792 Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]fc30ef082011-08-18 04:07:191793 if (!profile_->IsSameProfile(host_profile->GetOriginalProfile()))
1794 break;
1795
Devlin Cronineea1b7a2018-05-26 02:46:211796 ProcessMap* process_map = ProcessMap::Get(profile_);
[email protected]fafdc842014-01-17 18:09:081797 if (process_map->Contains(process->GetID())) {
[email protected]52b76592013-11-02 17:59:031798 // An extension process was terminated, this might have resulted in an
1799 // app or extension becoming idle.
1800 std::set<std::string> extension_ids =
[email protected]fafdc842014-01-17 18:09:081801 process_map->GetExtensionsInProcess(process->GetID());
elijahtaylor0def4432014-10-06 18:15:111802 // In addition to the extensions listed in the process map, one of those
1803 // extensions could be referencing a shared module which is waiting for
1804 // idle to update. Check all imports of these extensions, too.
1805 std::set<std::string> import_ids;
1806 for (std::set<std::string>::const_iterator it = extension_ids.begin();
1807 it != extension_ids.end();
1808 ++it) {
1809 const Extension* extension = GetExtensionById(*it, true);
1810 if (!extension)
1811 continue;
1812 const std::vector<SharedModuleInfo::ImportInfo>& imports =
1813 SharedModuleInfo::GetImports(extension);
1814 std::vector<SharedModuleInfo::ImportInfo>::const_iterator import_it;
1815 for (import_it = imports.begin(); import_it != imports.end();
1816 import_it++) {
1817 import_ids.insert((*import_it).extension_id);
1818 }
1819 }
1820 extension_ids.insert(import_ids.begin(), import_ids.end());
1821
[email protected]52b76592013-11-02 17:59:031822 for (std::set<std::string>::const_iterator it = extension_ids.begin();
1823 it != extension_ids.end(); ++it) {
1824 if (delayed_installs_.Contains(*it)) {
skyostilf221b7de2015-06-11 20:36:321825 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
[email protected]52b76592013-11-02 17:59:031826 FROM_HERE,
tzik8d880ee2017-04-20 19:46:241827 base::BindOnce(
Toni Barzic667db0d32018-01-09 18:00:191828 base::IgnoreResult(
1829 &ExtensionService::FinishDelayedInstallationIfReady),
1830 AsWeakPtr(), *it, false /*install_immediately*/),
Lei Zhang15339152018-08-09 22:20:441831 kUpdateIdleDelay);
[email protected]52b76592013-11-02 17:59:031832 }
1833 }
1834 }
1835
[email protected]fafdc842014-01-17 18:09:081836 process_map->RemoveAllFromProcess(process->GetID());
[email protected]6f371442011-11-09 06:45:461837 BrowserThread::PostTask(
tzik8d880ee2017-04-20 19:46:241838 BrowserThread::IO, FROM_HERE,
Devlin Cronineea1b7a2018-05-26 02:46:211839 base::BindOnce(&InfoMap::UnregisterAllExtensionsInProcess,
tzik8d880ee2017-04-20 19:46:241840 system_->info_map(), process->GetID()));
[email protected]da5683db2011-04-23 17:12:211841 break;
1842 }
[email protected]ebe07772014-05-22 04:16:061843 case chrome::NOTIFICATION_PROFILE_DESTRUCTION_STARTED: {
1844 OnProfileDestructionStarted();
1845 break;
1846 }
[email protected]aa96d3a2010-08-21 08:45:251847
[email protected]4814b512009-11-07 00:12:291848 default:
1849 NOTREACHED() << "Unexpected notification type.";
1850 }
1851}
1852
binjin47947f842014-11-18 12:10:241853int ExtensionService::GetDisableReasonsOnInstalled(const Extension* extension) {
rdevlin.cronine1456712016-12-29 22:47:281854 bool is_update_from_same_type = false;
1855 {
1856 const Extension* existing_extension =
1857 GetInstalledExtension(extension->id());
1858 is_update_from_same_type =
1859 existing_extension &&
1860 existing_extension->manifest()->type() == extension->manifest()->type();
1861 }
Devlin Cronineea1b7a2018-05-26 02:46:211862 disable_reason::DisableReason disable_reason = disable_reason::DISABLE_NONE;
binjin47947f842014-11-18 12:10:241863 // Extensions disabled by management policy should always be disabled, even
1864 // if it's force-installed.
1865 if (system_->management_policy()->MustRemainDisabled(
1866 extension, &disable_reason, nullptr)) {
1867 // A specified reason is required to disable the extension.
Devlin Cronineea1b7a2018-05-26 02:46:211868 DCHECK(disable_reason != disable_reason::DISABLE_NONE);
binjin47947f842014-11-18 12:10:241869 return disable_reason;
1870 }
1871
[email protected]612a1cb12012-10-17 13:18:031872 // Extensions installed by policy can't be disabled. So even if a previous
1873 // installation disabled the extension, make sure it is now enabled.
binjin47947f842014-11-18 12:10:241874 if (system_->management_policy()->MustRemainEnabled(extension, nullptr))
Devlin Cronineea1b7a2018-05-26 02:46:211875 return disable_reason::DISABLE_NONE;
[email protected]612a1cb12012-10-17 13:18:031876
binjin47947f842014-11-18 12:10:241877 // An already disabled extension should inherit the disable reasons and
1878 // remain disabled.
1879 if (extension_prefs_->IsExtensionDisabled(extension->id())) {
1880 int disable_reasons = extension_prefs_->GetDisableReasons(extension->id());
1881 // If an extension was disabled without specified reason, presume it's
1882 // disabled by user.
Devlin Cronineea1b7a2018-05-26 02:46:211883 return disable_reasons == disable_reason::DISABLE_NONE
1884 ? disable_reason::DISABLE_USER_ACTION
binjin47947f842014-11-18 12:10:241885 : disable_reasons;
1886 }
[email protected]612a1cb12012-10-17 13:18:031887
Devlin Cronineea1b7a2018-05-26 02:46:211888 if (ExternalInstallManager::IsPromptingEnabled()) {
[email protected]612a1cb12012-10-17 13:18:031889 // External extensions are initially disabled. We prompt the user before
[email protected]2c495c42013-01-04 21:49:541890 // enabling them. Hosted apps are excepted because they are not dangerous
rdevlin.cronine1456712016-12-29 22:47:281891 // (they need to be launched by the user anyway). We also don't prompt for
1892 // extensions updating; this is because the extension will be disabled from
1893 // the initial install if it is supposed to be, and this allows us to turn
1894 // this on for other platforms without disabling already-installed
1895 // extensions.
[email protected]1d5e58b2013-01-31 08:41:401896 if (extension->GetType() != Manifest::TYPE_HOSTED_APP &&
1897 Manifest::IsExternalLocation(extension->location()) &&
rdevlin.cronine1456712016-12-29 22:47:281898 !extension_prefs_->IsExternalExtensionAcknowledged(extension->id()) &&
1899 !is_update_from_same_type) {
Devlin Cronineea1b7a2018-05-26 02:46:211900 return disable_reason::DISABLE_EXTERNAL_EXTENSION;
[email protected]612a1cb12012-10-17 13:18:031901 }
1902 }
[email protected]612a1cb12012-10-17 13:18:031903
Devlin Cronineea1b7a2018-05-26 02:46:211904 return disable_reason::DISABLE_NONE;
[email protected]612a1cb12012-10-17 13:18:031905}
[email protected]0db124b02012-11-07 04:55:051906
mlerman6a37b6a42014-11-26 22:10:531907// Helper method to determine if an extension can be blocked.
1908bool ExtensionService::CanBlockExtension(const Extension* extension) const {
mlerman3690e5be2014-12-01 22:57:441909 DCHECK(extension);
mlerman6a37b6a42014-11-26 22:10:531910 return extension->location() != Manifest::COMPONENT &&
1911 extension->location() != Manifest::EXTERNAL_COMPONENT &&
achuith2f5578b2016-02-26 21:57:131912 !system_->management_policy()->MustRemainEnabled(extension, nullptr);
mlerman6a37b6a42014-11-26 22:10:531913}
1914
Devlin Cronineea1b7a2018-05-26 02:46:211915InstallGate::Action ExtensionService::ShouldDelayExtensionInstall(
1916 const Extension* extension,
xiyuanf6a4c6a62016-04-19 18:14:541917 bool install_immediately,
Devlin Cronineea1b7a2018-05-26 02:46:211918 ExtensionPrefs::DelayReason* reason) const {
xiyuanf6a4c6a62016-04-19 18:14:541919 for (const auto& entry : install_delayer_registry_) {
Devlin Cronineea1b7a2018-05-26 02:46:211920 InstallGate* const delayer = entry.second;
1921 InstallGate::Action action =
xiyuanf6a4c6a62016-04-19 18:14:541922 delayer->ShouldDelay(extension, install_immediately);
Devlin Cronineea1b7a2018-05-26 02:46:211923 if (action != InstallGate::INSTALL) {
xiyuanf6a4c6a62016-04-19 18:14:541924 *reason = entry.first;
1925 return action;
1926 }
[email protected]e7aa7b7e2012-11-27 04:51:221927 }
[email protected]fdd679b2012-11-15 20:49:391928
Devlin Cronineea1b7a2018-05-26 02:46:211929 return InstallGate::INSTALL;
[email protected]9f4e4f082013-06-21 07:11:191930}
1931
1932void ExtensionService::MaybeFinishDelayedInstallations() {
1933 std::vector<std::string> to_be_installed;
achuith2f5578b2016-02-26 21:57:131934 for (const auto& extension : delayed_installs_) {
1935 to_be_installed.push_back(extension->id());
[email protected]399583b2012-12-11 09:33:421936 }
achuith2f5578b2016-02-26 21:57:131937 for (const auto& extension_id : to_be_installed) {
Toni Barzic667db0d32018-01-09 18:00:191938 FinishDelayedInstallationIfReady(extension_id,
1939 false /*install_immediately*/);
[email protected]399583b2012-12-11 09:33:421940 }
[email protected]399583b2012-12-11 09:33:421941}
1942
[email protected]fdd679b2012-11-15 20:49:391943void ExtensionService::OnBlacklistUpdated() {
[email protected]2d19eb6e2014-01-27 17:30:001944 blacklist_->GetBlacklistedIDs(
[email protected]f47f7172014-03-19 19:27:101945 registry_->GenerateInstalledExtensionsSet()->GetIDs(),
[email protected]3f2a2fa2013-09-24 02:55:251946 base::Bind(&ExtensionService::ManageBlacklist, AsWeakPtr()));
[email protected]695b5712012-12-06 23:55:281947}
1948
weidongg04695232017-06-09 00:01:051949void ExtensionService::OnUpgradeRecommended() {
1950 // Notify observers that chrome update is available.
1951 for (auto& observer : update_observers_)
1952 observer.OnChromeUpdateAvailable();
1953}
1954
Devlin Cronineea1b7a2018-05-26 02:46:211955void ExtensionService::PreAddExtension(const Extension* extension,
1956 const Extension* old_extension) {
Michael Giuffrida573992d2018-02-08 00:48:441957 // Check if the extension's privileges have changed and mark the
1958 // extension disabled if necessary.
1959 CheckPermissionsIncrease(extension, !!old_extension);
1960}
1961
Michael Giuffrida6397c592017-10-09 20:46:531962bool ExtensionService::CanEnableExtension(const Extension* extension) {
1963 return !system_->management_policy()->MustRemainDisabled(extension, nullptr,
1964 nullptr);
1965}
1966
1967bool ExtensionService::CanDisableExtension(const Extension* extension) {
1968 // Some extensions cannot be disabled by users:
1969 // - |extension| can be null if sync disables an extension that is not
1970 // installed yet; allow disablement in this case.
1971 if (!extension)
1972 return true;
1973
1974 // - Shared modules are just resources used by other extensions, and are not
1975 // user-controlled.
1976 if (SharedModuleInfo::IsSharedModule(extension))
1977 return false;
1978
1979 // - EXTERNAL_COMPONENT extensions are not generally modifiable by users, but
1980 // can be uninstalled by the browser if the user sets extension-specific
1981 // preferences.
1982 if (extension->location() == Manifest::EXTERNAL_COMPONENT)
1983 return true;
1984
1985 return system_->management_policy()->UserMayModifySettings(extension,
1986 nullptr);
1987}
1988
1989bool ExtensionService::ShouldBlockExtension(const Extension* extension) {
1990 if (!block_extensions_)
1991 return false;
1992
1993 // Blocked extensions aren't marked as such in prefs, thus if
1994 // |block_extensions_| is true then CanBlockExtension() must be called with an
1995 // Extension object. If |extension| is not loaded, assume it should be
1996 // blocked.
1997 return !extension || CanBlockExtension(extension);
1998}
1999
[email protected]2d19eb6e2014-01-27 17:30:002000void ExtensionService::ManageBlacklist(
Devlin Cronineea1b7a2018-05-26 02:46:212001 const Blacklist::BlacklistStateMap& state_map) {
[email protected]54ee8192014-03-29 17:37:242002 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]695b5712012-12-06 23:55:282003
mlerman6a37b6a42014-11-26 22:10:532004 std::set<std::string> blacklisted;
[email protected]2d19eb6e2014-01-27 17:30:002005 ExtensionIdSet greylist;
2006 ExtensionIdSet unchanged;
achuith2f5578b2016-02-26 21:57:132007 for (const auto& it : state_map) {
2008 switch (it.second) {
Devlin Cronineea1b7a2018-05-26 02:46:212009 case NOT_BLACKLISTED:
[email protected]2d19eb6e2014-01-27 17:30:002010 break;
[email protected]695b5712012-12-06 23:55:282011
Devlin Cronineea1b7a2018-05-26 02:46:212012 case BLACKLISTED_MALWARE:
achuith2f5578b2016-02-26 21:57:132013 blacklisted.insert(it.first);
[email protected]2d19eb6e2014-01-27 17:30:002014 break;
2015
Devlin Cronineea1b7a2018-05-26 02:46:212016 case BLACKLISTED_SECURITY_VULNERABILITY:
2017 case BLACKLISTED_CWS_POLICY_VIOLATION:
2018 case BLACKLISTED_POTENTIALLY_UNWANTED:
achuith2f5578b2016-02-26 21:57:132019 greylist.insert(it.first);
[email protected]2d19eb6e2014-01-27 17:30:002020 break;
2021
Devlin Cronineea1b7a2018-05-26 02:46:212022 case BLACKLISTED_UNKNOWN:
achuith2f5578b2016-02-26 21:57:132023 unchanged.insert(it.first);
[email protected]2d19eb6e2014-01-27 17:30:002024 break;
2025 }
2026 }
2027
mlerman6a37b6a42014-11-26 22:10:532028 UpdateBlacklistedExtensions(blacklisted, unchanged);
[email protected]2d19eb6e2014-01-27 17:30:002029 UpdateGreylistedExtensions(greylist, unchanged, state_map);
2030
[email protected]373daf972014-04-10 01:50:442031 error_controller_->ShowErrorIfNeeded();
[email protected]2d19eb6e2014-01-27 17:30:002032}
2033
2034namespace {
2035void Partition(const ExtensionIdSet& before,
2036 const ExtensionIdSet& after,
2037 const ExtensionIdSet& unchanged,
2038 ExtensionIdSet* no_longer,
2039 ExtensionIdSet* not_yet) {
2040 *not_yet = base::STLSetDifference<ExtensionIdSet>(after, before);
2041 *no_longer = base::STLSetDifference<ExtensionIdSet>(before, after);
2042 *no_longer = base::STLSetDifference<ExtensionIdSet>(*no_longer, unchanged);
2043}
2044} // namespace
2045
mlerman6a37b6a42014-11-26 22:10:532046void ExtensionService::UpdateBlacklistedExtensions(
2047 const ExtensionIdSet& blacklisted,
[email protected]2d19eb6e2014-01-27 17:30:002048 const ExtensionIdSet& unchanged) {
2049 ExtensionIdSet not_yet_blocked, no_longer_blocked;
mlerman6a37b6a42014-11-26 22:10:532050 Partition(registry_->blacklisted_extensions().GetIDs(), blacklisted,
2051 unchanged, &no_longer_blocked, &not_yet_blocked);
[email protected]2d19eb6e2014-01-27 17:30:002052
2053 for (ExtensionIdSet::iterator it = no_longer_blocked.begin();
2054 it != no_longer_blocked.end(); ++it) {
[email protected]695b5712012-12-06 23:55:282055 scoped_refptr<const Extension> extension =
[email protected]bb1bc9b32013-12-21 03:09:142056 registry_->blacklisted_extensions().GetByID(*it);
[email protected]3f2a2fa2013-09-24 02:55:252057 if (!extension.get()) {
mlerman6a37b6a42014-11-26 22:10:532058 NOTREACHED() << "Extension " << *it << " no longer blacklisted, "
2059 << "but it was never blacklisted.";
[email protected]695b5712012-12-06 23:55:282060 continue;
[email protected]3f2a2fa2013-09-24 02:55:252061 }
[email protected]bb1bc9b32013-12-21 03:09:142062 registry_->RemoveBlacklisted(*it);
atuchin6dc7c442016-07-20 07:04:342063 extension_prefs_->SetExtensionBlacklistState(extension->id(),
Devlin Cronineea1b7a2018-05-26 02:46:212064 NOT_BLACKLISTED);
[email protected]dc24976f2013-06-02 21:15:092065 AddExtension(extension.get());
[email protected]ac875372013-02-28 04:36:092066 UMA_HISTOGRAM_ENUMERATION("ExtensionBlacklist.UnblacklistInstalled",
[email protected]dc24976f2013-06-02 21:15:092067 extension->location(),
2068 Manifest::NUM_LOCATIONS);
[email protected]695b5712012-12-06 23:55:282069 }
2070
[email protected]2d19eb6e2014-01-27 17:30:002071 for (ExtensionIdSet::iterator it = not_yet_blocked.begin();
2072 it != not_yet_blocked.end(); ++it) {
[email protected]695b5712012-12-06 23:55:282073 scoped_refptr<const Extension> extension = GetInstalledExtension(*it);
[email protected]3f2a2fa2013-09-24 02:55:252074 if (!extension.get()) {
2075 NOTREACHED() << "Extension " << *it << " needs to be "
2076 << "blacklisted, but it's not installed.";
[email protected]695b5712012-12-06 23:55:282077 continue;
[email protected]3f2a2fa2013-09-24 02:55:252078 }
[email protected]bb1bc9b32013-12-21 03:09:142079 registry_->AddBlacklisted(extension);
Devlin Cronineea1b7a2018-05-26 02:46:212080 extension_prefs_->SetExtensionBlacklistState(extension->id(),
2081 BLACKLISTED_MALWARE);
limasdf0deef2042017-05-03 19:17:172082 UnloadExtension(*it, UnloadedExtensionReason::BLACKLIST);
[email protected]ac875372013-02-28 04:36:092083 UMA_HISTOGRAM_ENUMERATION("ExtensionBlacklist.BlacklistInstalled",
2084 extension->location(), Manifest::NUM_LOCATIONS);
[email protected]695b5712012-12-06 23:55:282085 }
[email protected]2d19eb6e2014-01-27 17:30:002086}
[email protected]695b5712012-12-06 23:55:282087
[email protected]2d19eb6e2014-01-27 17:30:002088// TODO(oleg): UMA logging
2089void ExtensionService::UpdateGreylistedExtensions(
2090 const ExtensionIdSet& greylist,
2091 const ExtensionIdSet& unchanged,
Devlin Cronineea1b7a2018-05-26 02:46:212092 const Blacklist::BlacklistStateMap& state_map) {
[email protected]2d19eb6e2014-01-27 17:30:002093 ExtensionIdSet not_yet_greylisted, no_longer_greylisted;
2094 Partition(greylist_.GetIDs(),
2095 greylist, unchanged,
2096 &no_longer_greylisted, &not_yet_greylisted);
2097
2098 for (ExtensionIdSet::iterator it = no_longer_greylisted.begin();
2099 it != no_longer_greylisted.end(); ++it) {
2100 scoped_refptr<const Extension> extension = greylist_.GetByID(*it);
2101 if (!extension.get()) {
2102 NOTREACHED() << "Extension " << *it << " no longer greylisted, "
2103 << "but it was not marked as greylisted.";
2104 continue;
2105 }
2106
2107 greylist_.Remove(*it);
2108 extension_prefs_->SetExtensionBlacklistState(extension->id(),
Devlin Cronineea1b7a2018-05-26 02:46:212109 NOT_BLACKLISTED);
[email protected]2d19eb6e2014-01-27 17:30:002110 if (extension_prefs_->GetDisableReasons(extension->id()) &
Devlin Cronineea1b7a2018-05-26 02:46:212111 disable_reason::DISABLE_GREYLIST)
[email protected]2d19eb6e2014-01-27 17:30:002112 EnableExtension(*it);
2113 }
2114
2115 for (ExtensionIdSet::iterator it = not_yet_greylisted.begin();
2116 it != not_yet_greylisted.end(); ++it) {
2117 scoped_refptr<const Extension> extension = GetInstalledExtension(*it);
2118 if (!extension.get()) {
2119 NOTREACHED() << "Extension " << *it << " needs to be "
2120 << "disabled, but it's not installed.";
2121 continue;
2122 }
2123 greylist_.Insert(extension);
2124 extension_prefs_->SetExtensionBlacklistState(extension->id(),
2125 state_map.find(*it)->second);
2126 if (registry_->enabled_extensions().Contains(extension->id()))
Devlin Cronineea1b7a2018-05-26 02:46:212127 DisableExtension(*it, disable_reason::DISABLE_GREYLIST);
[email protected]2d19eb6e2014-01-27 17:30:002128 }
[email protected]fdd679b2012-11-15 20:49:392129}
[email protected]75bdcb872013-03-13 00:41:452130
Devlin Cronineea1b7a2018-05-26 02:46:212131void ExtensionService::AddUpdateObserver(UpdateObserver* observer) {
[email protected]75bdcb872013-03-13 00:41:452132 update_observers_.AddObserver(observer);
2133}
2134
Devlin Cronineea1b7a2018-05-26 02:46:212135void ExtensionService::RemoveUpdateObserver(UpdateObserver* observer) {
[email protected]75bdcb872013-03-13 00:41:452136 update_observers_.RemoveObserver(observer);
2137}
[email protected]bb1bc9b32013-12-21 03:09:142138
Devlin Cronineea1b7a2018-05-26 02:46:212139void ExtensionService::RegisterInstallGate(ExtensionPrefs::DelayReason reason,
2140 InstallGate* install_delayer) {
xiyuanf6a4c6a62016-04-19 18:14:542141 DCHECK(install_delayer_registry_.end() ==
2142 install_delayer_registry_.find(reason));
2143 install_delayer_registry_[reason] = install_delayer;
2144}
2145
Devlin Cronineea1b7a2018-05-26 02:46:212146void ExtensionService::UnregisterInstallGate(InstallGate* install_delayer) {
xiyuanf6a4c6a62016-04-19 18:14:542147 for (auto it = install_delayer_registry_.begin();
2148 it != install_delayer_registry_.end(); ++it) {
2149 if (it->second == install_delayer) {
2150 install_delayer_registry_.erase(it);
2151 return;
2152 }
2153 }
2154}
2155
[email protected]bb1bc9b32013-12-21 03:09:142156// Used only by test code.
2157void ExtensionService::UnloadAllExtensionsInternal() {
2158 profile_->GetExtensionSpecialStoragePolicy()->RevokeRightsForAllExtensions();
2159
2160 registry_->ClearAll();
[email protected]45f5b7d2014-01-22 23:47:132161 system_->runtime_data()->ClearAll();
[email protected]bb1bc9b32013-12-21 03:09:142162
2163 // TODO(erikkay) should there be a notification for this? We can't use
Devlin Cronineea1b7a2018-05-26 02:46:212164 // EXTENSION_UNLOADED since that implies that the extension has
Minh X. Nguyen45479012017-08-18 21:35:362165 // been disabled or uninstalled.
[email protected]bb1bc9b32013-12-21 03:09:142166}
[email protected]ebe07772014-05-22 04:16:062167
2168void ExtensionService::OnProfileDestructionStarted() {
2169 ExtensionIdSet ids_to_unload = registry_->enabled_extensions().GetIDs();
2170 for (ExtensionIdSet::iterator it = ids_to_unload.begin();
2171 it != ids_to_unload.end();
2172 ++it) {
limasdf0deef2042017-05-03 19:17:172173 UnloadExtension(*it, UnloadedExtensionReason::PROFILE_SHUTDOWN);
[email protected]ebe07772014-05-22 04:16:062174 }
2175}
rdevlin.croninf2e1cb012017-05-27 01:27:592176
2177void ExtensionService::OnInstalledExtensionsLoaded() {
2178 if (updater_)
2179 updater_->Start();
2180
2181 // Enable any Shared Modules that incorrectly got disabled previously.
2182 // This is temporary code to fix incorrect behavior from previous versions of
2183 // Chrome and can be removed after several releases (perhaps M60).
Devlin Cronineea1b7a2018-05-26 02:46:212184 ExtensionList to_enable;
rdevlin.croninf2e1cb012017-05-27 01:27:592185 for (const auto& extension : registry_->disabled_extensions()) {
2186 if (SharedModuleInfo::IsSharedModule(extension.get()))
2187 to_enable.push_back(extension);
2188 }
2189 for (const auto& extension : to_enable) {
2190 EnableExtension(extension->id());
2191 }
2192
2193 OnBlacklistUpdated();
2194}
lazyboy75b9def2017-06-06 18:56:592195
Takumi Fujimoto43c8c00f2017-07-26 22:48:562196void ExtensionService::UninstallMigratedExtensions() {
2197 std::unique_ptr<ExtensionSet> installed_extensions =
2198 registry_->GenerateInstalledExtensionsSet();
2199
2200 for (const std::string& extension_id : kMigratedExtensionIds) {
2201 if (installed_extensions->Contains(extension_id)) {
Devlin Cronineea1b7a2018-05-26 02:46:212202 UninstallExtension(extension_id, UNINSTALL_REASON_MIGRATED, nullptr);
Takumi Fujimoto43c8c00f2017-07-26 22:48:562203 }
2204 }
2205}
Devlin Cronineea1b7a2018-05-26 02:46:212206
2207} // namespace extensions