blob: 46ddb77bd244b70ec9440edda53a4dffc945c18c [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]654512b2010-09-01 02:09:429#include <algorithm>
[email protected]695b5712012-12-06 23:55:2810#include <iterator>
asargente4de9f92016-09-15 01:40:0611#include <memory>
[email protected]97d2f1d2011-01-15 00:41:0812#include <set>
asargente4de9f92016-09-15 01:40:0613#include <utility>
[email protected]654512b2010-09-01 02:09:4214
[email protected]62433d32011-10-12 22:33:1215#include "base/command_line.h"
rdevlin.cronin08ada0f2017-03-09 23:29:5216#include "base/debug/alias.h"
17#include "base/debug/dump_without_crashing.h"
skyostilf221b7de2015-06-11 20:36:3218#include "base/location.h"
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"
[email protected]3ea1b182013-02-08 22:38:4121#include "base/strings/string_number_conversions.h"
catmullings98cd1942016-08-30 22:31:5922#include "base/strings/string_tokenizer.h"
[email protected]00e7bef2013-06-10 20:35:1723#include "base/strings/stringprintf.h"
[email protected]112158af2013-06-07 23:46:1824#include "base/strings/utf_string_conversions.h"
[email protected]7f8f24f2012-11-15 19:40:1425#include "base/threading/sequenced_worker_pool.h"
[email protected]34b99632011-01-01 01:01:0626#include "base/threading/thread_restrictions.h"
gabb15e19072016-05-11 20:45:4127#include "base/threading/thread_task_runner_handle.h"
[email protected]41a17c52013-06-28 00:27:5328#include "base/time/time.h"
rkaplowe65c2ff2015-02-14 16:29:5429#include "base/trace_event/trace_event.h"
avia2f4804a2015-12-24 23:11:1330#include "build/build_config.h"
[email protected]15730c42009-09-03 00:03:2031#include "chrome/browser/browser_process.h"
[email protected]9ea0cd32013-07-12 01:50:3632#include "chrome/browser/chrome_notification_types.h"
mukai87a8d402014-09-15 20:15:0933#include "chrome/browser/content_settings/content_settings_internal_extension_provider.h"
sunil.ratnu21b896c2014-11-24 10:09:2434#include "chrome/browser/extensions/api/content_settings/content_settings_custom_extension_provider.h"
mukai87a8d402014-09-15 20:15:0935#include "chrome/browser/extensions/api/content_settings/content_settings_service.h"
ryanackley48bedbd2015-01-27 23:12:1436#include "chrome/browser/extensions/app_data_migrator.h"
[email protected]d8c8f25f2011-11-02 18:18:0137#include "chrome/browser/extensions/component_loader.h"
[email protected]13e062e2014-08-09 10:21:5538#include "chrome/browser/extensions/crx_installer.h"
[email protected]d9ede582012-08-14 19:21:3839#include "chrome/browser/extensions/data_deleter.h"
rdevlin.cronin2813c1b2014-08-26 23:51:0840#include "chrome/browser/extensions/extension_action_storage_manager.h"
[email protected]5a145e82014-05-29 22:19:0741#include "chrome/browser/extensions/extension_assets_manager.h"
[email protected]62f051c2012-03-29 17:04:4442#include "chrome/browser/extensions/extension_disabled_ui.h"
[email protected]373daf972014-04-10 01:50:4443#include "chrome/browser/extensions/extension_error_controller.h"
[email protected]19eb80152011-02-26 00:28:4344#include "chrome/browser/extensions/extension_special_storage_policy.h"
[email protected]f8aefb132013-10-30 09:29:5245#include "chrome/browser/extensions/extension_sync_service.h"
[email protected]617342a42013-12-18 23:34:0346#include "chrome/browser/extensions/extension_util.h"
[email protected]2894a512014-06-26 19:03:5647#include "chrome/browser/extensions/external_install_manager.h"
[email protected]5df038b2012-07-16 19:03:2748#include "chrome/browser/extensions/external_provider_impl.h"
[email protected]ffd2f79e2013-11-14 00:11:4649#include "chrome/browser/extensions/install_verifier.h"
[email protected]d8c8f25f2011-11-02 18:18:0150#include "chrome/browser/extensions/installed_loader.h"
[email protected]f3d3b382014-03-14 21:19:2851#include "chrome/browser/extensions/pending_extension_manager.h"
[email protected]13e062e2014-08-09 10:21:5552#include "chrome/browser/extensions/permissions_updater.h"
[email protected]90878c52014-04-04 18:21:0253#include "chrome/browser/extensions/shared_module_service.h"
[email protected]13e062e2014-08-09 10:21:5554#include "chrome/browser/extensions/unpacked_installer.h"
rockotdb5192992014-09-16 21:27:0255#include "chrome/browser/extensions/updater/chrome_extension_downloader_factory.h"
[email protected]13e062e2014-08-09 10:21:5556#include "chrome/browser/extensions/updater/extension_updater.h"
rockotdb5192992014-09-16 21:27:0257#include "chrome/browser/google/google_brand.h"
[email protected]8ecad5e2010-12-02 21:18:3358#include "chrome/browser/profiles/profile.h"
dbeam8d57a012015-05-21 07:12:2059#include "chrome/browser/search/thumbnail_source.h"
[email protected]b5a507b22013-11-08 20:41:5760#include "chrome/browser/ui/webui/extensions/extension_icon_source.h"
[email protected]c8d407e2011-04-28 21:27:1761#include "chrome/browser/ui/webui/favicon_source.h"
[email protected]b07e606e2012-09-15 20:16:1562#include "chrome/browser/ui/webui/theme_source.h"
[email protected]e2eb43112009-05-29 21:19:5463#include "chrome/common/chrome_switches.h"
[email protected]f6431be82013-09-07 02:53:4564#include "chrome/common/crash_keys.h"
[email protected]9f4e4f082013-06-21 07:11:1965#include "chrome/common/extensions/extension_constants.h"
brettw9e85ef42016-11-01 21:01:2466#include "chrome/common/features.h"
[email protected]a57209872009-05-04 22:53:1467#include "chrome/common/url_constants.h"
mukai8eaec822014-10-25 17:53:1668#include "components/content_settings/core/browser/host_content_settings_map.h"
[email protected]fdd28372014-08-21 02:27:2669#include "components/crx_file/id_util.h"
[email protected]dccba4f82014-05-29 00:52:5670#include "content/public/browser/devtools_agent_host.h"
[email protected]05aad2da2011-10-28 10:12:3771#include "content/public/browser/notification_service.h"
[email protected]f3b1a082011-11-18 00:34:3072#include "content/public/browser/render_process_host.h"
[email protected]399583b2012-12-11 09:33:4273#include "content/public/browser/storage_partition.h"
treib926ee2d2015-08-06 10:55:4274#include "extensions/browser/app_sorting.h"
[email protected]34423532013-11-21 18:13:1075#include "extensions/browser/event_router.h"
[email protected]22401dc2014-03-21 01:38:5776#include "extensions/browser/extension_host.h"
[email protected]bb1bc9b32013-12-21 03:09:1477#include "extensions/browser/extension_registry.h"
[email protected]59b0e602014-01-30 00:41:2478#include "extensions/browser/extension_system.h"
rockotffa65b12014-10-14 17:19:0679#include "extensions/browser/extensions_browser_client.h"
lazyboye8634172016-01-28 00:10:4880#include "extensions/browser/external_install_info.h"
[email protected]4a1d9c0d2014-06-13 12:50:1181#include "extensions/browser/install_flag.h"
rdevlin.cronin5e510e802016-07-26 15:09:2082#include "extensions/browser/renderer_startup_helper.h"
[email protected]45f5b7d2014-01-22 23:47:1383#include "extensions/browser/runtime_data.h"
[email protected]e43c61f2014-07-20 21:46:3484#include "extensions/browser/uninstall_reason.h"
[email protected]a9aa62b312013-11-29 05:35:0685#include "extensions/browser/update_observer.h"
rockotffa65b12014-10-14 17:19:0686#include "extensions/browser/updater/extension_cache.h"
rockot05f40a922014-10-16 19:40:2587#include "extensions/browser/updater/extension_downloader.h"
[email protected]fb820c02014-03-13 15:07:0888#include "extensions/common/extension_messages.h"
rockot90659852014-09-18 19:31:5289#include "extensions/common/extension_urls.h"
[email protected]5ef835a2013-11-08 20:42:5790#include "extensions/common/feature_switch.h"
rdevlin.cronin41227532016-07-13 21:24:3491#include "extensions/common/features/feature_channel.h"
[email protected]85df9d12014-04-15 17:02:1492#include "extensions/common/file_util.h"
[email protected]0c3c9732013-09-16 08:53:4193#include "extensions/common/manifest_constants.h"
[email protected]558878cc82013-11-09 01:25:5194#include "extensions/common/manifest_handlers/background_info.h"
rockotd5546142014-10-15 00:29:0895#include "extensions/common/manifest_url_handlers.h"
[email protected]dccba4f82014-05-29 00:52:5696#include "extensions/common/one_shot_event.h"
treib2e0517f92015-05-07 23:15:3697#include "extensions/common/permissions/api_permission.h"
[email protected]c41003472013-10-19 15:37:2598#include "extensions/common/permissions/permission_message_provider.h"
[email protected]e4452d32013-11-15 23:07:4199#include "extensions/common/permissions/permissions_data.h"
[email protected]79a60642012-10-20 21:03:18100
brettw9e85ef42016-11-01 21:01:24101#if BUILDFLAG(ENABLE_SUPERVISED_USERS)
treib8ecc1eb52015-03-04 18:29:06102#include "chrome/browser/supervised_user/supervised_user_service.h"
103#include "chrome/browser/supervised_user/supervised_user_service_factory.h"
104#endif
105
[email protected]eed367e2011-04-12 03:43:31106#if defined(OS_CHROMEOS)
[email protected]88e8ec9152013-01-17 04:05:18107#include "chrome/browser/chromeos/extensions/install_limiter.h"
pilgrime92c5fcd2014-09-10 23:31:23108#include "storage/browser/fileapi/file_system_backend.h"
109#include "storage/browser/fileapi/file_system_context.h"
[email protected]eed367e2011-04-12 03:43:31110#endif
111
[email protected]55eb70e762012-02-20 17:38:39112using content::BrowserContext;
[email protected]631bb742011-11-02 11:29:39113using content::BrowserThread;
[email protected]98f66112012-12-25 12:59:36114using content::DevToolsAgentHost;
treib2e0517f92015-05-07 23:15:36115using extensions::APIPermission;
deepak.m14ba69e62015-11-17 05:42:12116using extensions::AppSorting;
[email protected]bf3d9df2012-07-24 23:20:27117using extensions::CrxInstaller;
[email protected]1c321ee52012-05-21 03:02:34118using extensions::Extension;
119using extensions::ExtensionIdSet;
120using extensions::ExtensionInfo;
[email protected]599539802014-01-07 23:06:00121using extensions::ExtensionRegistry;
[email protected]289c44b2013-12-17 03:26:57122using extensions::ExtensionSet;
lazyboye8634172016-01-28 00:10:48123using extensions::ExternalInstallInfoFile;
124using extensions::ExternalInstallInfoUpdateUrl;
125using extensions::ExternalProviderInterface;
[email protected]215a7be2012-10-22 19:53:42126using extensions::FeatureSwitch;
[email protected]ffd2f79e2013-11-14 00:11:46127using extensions::InstallVerifier;
[email protected]0d54b682013-11-05 14:15:36128using extensions::ManagementPolicy;
[email protected]1d5e58b2013-01-31 08:41:40129using extensions::Manifest;
treib2e0517f92015-05-07 23:15:36130using extensions::PermissionID;
131using extensions::PermissionIDSet;
[email protected]c2e66e12012-06-27 06:27:06132using extensions::PermissionSet;
[email protected]9f4e4f082013-06-21 07:11:19133using extensions::SharedModuleInfo;
[email protected]90878c52014-04-04 18:21:02134using extensions::SharedModuleService;
[email protected]e410b5f2012-12-14 14:02:24135using extensions::UnloadedExtensionInfo;
[email protected]5ef47ec2010-01-28 05:58:05136
[email protected]b6ab96d2009-08-20 18:58:19137namespace {
138
[email protected]0db124b02012-11-07 04:55:05139// Wait this many seconds after an extensions becomes idle before updating it.
[email protected]ddc6a122014-06-27 04:52:32140const int kUpdateIdleDelay = 5;
[email protected]0db124b02012-11-07 04:55:05141
samuong5da9a9a2017-02-15 06:08:20142// Comma-separated list of directories with extensions to load.
143// TODO(samuong): Remove this in M58 (see comment in ExtensionService::Init).
144const char kDeprecatedLoadComponentExtension[] = "load-component-extension";
145
[email protected]c6d474f82009-12-16 21:11:06146} // namespace
[email protected]b6ab96d2009-08-20 18:58:19147
[email protected]eaa7dd182010-12-14 11:09:00148// ExtensionService.
[email protected]6014d672008-12-05 00:38:25149
[email protected]8e4560b62011-01-14 10:09:14150void ExtensionService::CheckExternalUninstall(const std::string& id) {
[email protected]a29a517a2011-01-21 21:11:12151 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]a8af9fdb2010-10-28 21:52:20152
[email protected]7a4c6852010-09-16 03:44:22153 // Check if the providers know about this extension.
achuith2f5578b2016-02-26 21:57:13154 for (const auto& provider : external_extension_providers_) {
155 DCHECK(provider->IsReady());
156 if (provider->HasExtension(id))
[email protected]0a60a2e2010-10-25 16:15:21157 return; // Yup, known extension, don't uninstall.
[email protected]7a4c6852010-09-16 03:44:22158 }
159
[email protected]0f48fca2011-05-19 18:46:35160 // We get the list of external extensions to check from preferences.
161 // It is possible that an extension has preferences but is not loaded.
162 // For example, an extension that requires experimental permissions
163 // will not be loaded if the experimental command line flag is not used.
164 // In this case, do not uninstall.
[email protected]31bb5ee62012-09-12 22:58:40165 if (!GetInstalledExtension(id)) {
[email protected]0f48fca2011-05-19 18:46:35166 // We can't call UninstallExtension with an unloaded/invalid
167 // extension ID.
168 LOG(WARNING) << "Attempted uninstallation of unloaded/invalid extension "
169 << "with id: " << id;
170 return;
171 }
[email protected]42d58f62014-07-31 01:32:45172 UninstallExtension(id,
173 extensions::UNINSTALL_REASON_ORPHANED_EXTERNAL_EXTENSION,
achuith2f5578b2016-02-26 21:57:13174 base::Bind(&base::DoNothing), nullptr);
[email protected]7a4c6852010-09-16 03:44:22175}
176
[email protected]7f8f24f2012-11-15 19:40:14177void ExtensionService::SetFileTaskRunnerForTesting(
dcheng605ef8d2014-08-28 18:29:44178 const scoped_refptr<base::SequencedTaskRunner>& task_runner) {
[email protected]7f8f24f2012-11-15 19:40:14179 file_task_runner_ = task_runner;
180}
181
[email protected]8e4560b62011-01-14 10:09:14182void ExtensionService::ClearProvidersForTesting() {
[email protected]7a4c6852010-09-16 03:44:22183 external_extension_providers_.clear();
184}
185
[email protected]8e4560b62011-01-14 10:09:14186void ExtensionService::AddProviderForTesting(
lazyboyf33109d2016-08-31 00:37:08187 std::unique_ptr<ExternalProviderInterface> test_provider) {
[email protected]a29a517a2011-01-21 21:11:12188 CHECK(test_provider);
lazyboyf33109d2016-08-31 00:37:08189 external_extension_providers_.push_back(std::move(test_provider));
[email protected]7a4c6852010-09-16 03:44:22190}
191
[email protected]8f959f522014-08-06 06:26:28192void ExtensionService::BlacklistExtensionForTest(
193 const std::string& extension_id) {
mlerman6a37b6a42014-11-26 22:10:53194 ExtensionIdSet blacklisted;
[email protected]8f959f522014-08-06 06:26:28195 ExtensionIdSet unchanged;
mlerman6a37b6a42014-11-26 22:10:53196 blacklisted.insert(extension_id);
197 UpdateBlacklistedExtensions(blacklisted, unchanged);
[email protected]8f959f522014-08-06 06:26:28198}
199
[email protected]9060d8b02012-01-13 02:14:30200bool ExtensionService::OnExternalExtensionUpdateUrlFound(
lazyboye8634172016-01-28 00:10:48201 const ExternalInstallInfoUpdateUrl& info,
202 bool is_initial_load) {
[email protected]ab22ba42011-01-14 16:36:38203 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
lazyboye8634172016-01-28 00:10:48204 CHECK(crx_file::id_util::IdIsValid(info.extension_id));
[email protected]a8af9fdb2010-10-28 21:52:20205
lazyboye8634172016-01-28 00:10:48206 if (Manifest::IsExternalLocation(info.download_location)) {
[email protected]044e86992014-01-24 22:59:11207 // All extensions that are not user specific can be cached.
lazyboye8634172016-01-28 00:10:48208 extensions::ExtensionsBrowserClient::Get()
209 ->GetExtensionCache()
210 ->AllowCaching(info.extension_id);
[email protected]044e86992014-01-24 22:59:11211 }
212
lazyboye8634172016-01-28 00:10:48213 const Extension* extension = GetExtensionById(info.extension_id, true);
[email protected]8a87a5332011-08-11 17:54:59214 if (extension) {
asargent56282ab72016-09-09 16:58:03215 // Already installed. Skip this install if the current location has higher
216 // priority than |info.download_location|, and we aren't doing a
217 // reinstall of a corrupt policy force-installed extension.
[email protected]1d5e58b2013-01-31 08:41:40218 Manifest::Location current = extension->location();
asargent56282ab72016-09-09 16:58:03219 if (!pending_extension_manager_.IsPolicyReinstallForCorruptionExpected(
220 info.extension_id) &&
221 current == Manifest::GetHigherPriorityLocation(
222 current, info.download_location)) {
[email protected]9060d8b02012-01-13 02:14:30223 return false;
lazyboye8634172016-01-28 00:10:48224 }
[email protected]8a87a5332011-08-11 17:54:59225 // Otherwise, overwrite the current installation.
[email protected]7a4c6852010-09-16 03:44:22226 }
[email protected]9060d8b02012-01-13 02:14:30227
lazyboye8634172016-01-28 00:10:48228 // Add |info.extension_id| to the set of pending extensions. If it can not
229 // be added, then there is already a pending record from a higher-priority
230 // install source. In this case, signal that this extension will not be
[email protected]9060d8b02012-01-13 02:14:30231 // installed by returning false.
232 if (!pending_extension_manager()->AddFromExternalUpdateUrl(
lazyboye8634172016-01-28 00:10:48233 info.extension_id, info.install_parameter, *info.update_url,
234 info.download_location, info.creation_flags,
235 info.mark_acknowledged)) {
[email protected]9060d8b02012-01-13 02:14:30236 return false;
[email protected]31bb5ee62012-09-12 22:58:40237 }
[email protected]9060d8b02012-01-13 02:14:30238
lazyboye8634172016-01-28 00:10:48239 if (is_initial_load)
240 update_once_all_providers_are_ready_ = true;
[email protected]9060d8b02012-01-13 02:14:30241 return true;
[email protected]7a4c6852010-09-16 03:44:22242}
243
lazyboye8634172016-01-28 00:10:48244void ExtensionService::OnExternalProviderUpdateComplete(
245 const ExternalProviderInterface* provider,
lazyboy4aeef202016-09-07 21:28:59246 const std::vector<std::unique_ptr<ExternalInstallInfoUpdateUrl>>&
247 update_url_extensions,
248 const std::vector<std::unique_ptr<ExternalInstallInfoFile>>&
249 file_extensions,
lazyboye8634172016-01-28 00:10:48250 const std::set<std::string>& removed_extensions) {
251 // Update pending_extension_manager() with the new extensions first.
lazyboy4aeef202016-09-07 21:28:59252 for (const auto& extension : update_url_extensions)
lazyboye8634172016-01-28 00:10:48253 OnExternalExtensionUpdateUrlFound(*extension, false);
lazyboy4aeef202016-09-07 21:28:59254 for (const auto& extension : file_extensions)
lazyboye8634172016-01-28 00:10:48255 OnExternalExtensionFileFound(*extension);
256
257#if DCHECK_IS_ON()
258 for (const std::string& id : removed_extensions) {
lazyboy4aeef202016-09-07 21:28:59259 for (const auto& extension : update_url_extensions)
lazyboye8634172016-01-28 00:10:48260 DCHECK_NE(id, extension->extension_id);
lazyboy4aeef202016-09-07 21:28:59261 for (const auto& extension : file_extensions)
lazyboye8634172016-01-28 00:10:48262 DCHECK_NE(id, extension->extension_id);
263 }
264#endif
265
266 // Then uninstall before running |updater_|.
267 for (const std::string& id : removed_extensions)
268 CheckExternalUninstall(id);
269
270 if (!update_url_extensions.empty() && updater_) {
271 // Empty params will cause pending extensions to be updated.
272 extensions::ExtensionUpdater::CheckParams empty_params;
273 updater_->CheckNow(empty_params);
274 }
275
276 error_controller_->ShowErrorIfNeeded();
277 external_install_manager_->UpdateExternalExtensionAlert();
278}
279
[email protected]6aeac8342010-10-01 20:21:18280// static
[email protected]cc2f55c2014-07-08 02:19:04281// This function is used to uninstall an extension via sync. The LOG statements
282// within this function are used to inform the user if the uninstall cannot be
283// done.
[email protected]eaa7dd182010-12-14 11:09:00284bool ExtensionService::UninstallExtensionHelper(
285 ExtensionService* extensions_service,
[email protected]cc2f55c2014-07-08 02:19:04286 const std::string& extension_id,
[email protected]e43c61f2014-07-20 21:46:34287 extensions::UninstallReason reason) {
[email protected]d6ebc9792011-04-07 18:18:33288 // We can't call UninstallExtension with an invalid extension ID.
[email protected]31bb5ee62012-09-12 22:58:40289 if (!extensions_service->GetInstalledExtension(extension_id)) {
[email protected]6aeac8342010-10-01 20:21:18290 LOG(WARNING) << "Attempted uninstallation of non-existent extension with "
[email protected]95da88c42011-03-31 10:07:33291 << "id: " << extension_id;
292 return false;
[email protected]6aeac8342010-10-01 20:21:18293 }
294
[email protected]d6ebc9792011-04-07 18:18:33295 // The following call to UninstallExtension will not allow an uninstall of a
296 // policy-controlled extension.
[email protected]439f1e32013-12-09 20:09:09297 base::string16 error;
[email protected]42d58f62014-07-31 01:32:45298 if (!extensions_service->UninstallExtension(
299 extension_id, reason, base::Bind(&base::DoNothing), &error)) {
[email protected]d6ebc9792011-04-07 18:18:33300 LOG(WARNING) << "Cannot uninstall extension with id " << extension_id
301 << ": " << error;
302 return false;
303 }
[email protected]95da88c42011-03-31 10:07:33304
[email protected]6aeac8342010-10-01 20:21:18305 return true;
306}
307
[email protected]eaa7dd182010-12-14 11:09:00308ExtensionService::ExtensionService(Profile* profile,
avi3ef9ec9e2014-12-22 22:50:17309 const base::CommandLine* command_line,
[email protected]650b2d52013-02-10 03:41:45310 const base::FilePath& install_directory,
[email protected]45759612012-07-10 17:21:23311 extensions::ExtensionPrefs* extension_prefs,
[email protected]fdd679b2012-11-15 20:49:39312 extensions::Blacklist* blacklist,
[email protected]0436b102011-04-15 18:30:03313 bool autoupdate_enabled,
[email protected]4a10006a2013-05-17 23:18:35314 bool extensions_enabled,
315 extensions::OneShotEvent* ready)
[email protected]fdd679b2012-11-15 20:49:39316 : extensions::Blacklist::Observer(blacklist),
catmullings98cd1942016-08-30 22:31:59317 command_line_(command_line),
[email protected]fdd679b2012-11-15 20:49:39318 profile_(profile),
[email protected]bd306722012-07-11 20:43:59319 system_(extensions::ExtensionSystem::Get(profile)),
[email protected]73c47932010-12-06 18:13:43320 extension_prefs_(extension_prefs),
[email protected]695b5712012-12-06 23:55:28321 blacklist_(blacklist),
[email protected]5fdfa562013-12-27 17:43:59322 registry_(extensions::ExtensionRegistry::Get(profile)),
[email protected]6c9bedf2014-05-21 03:55:51323 pending_extension_manager_(profile),
[email protected]a9b00ac2009-06-25 21:03:23324 install_directory_(install_directory),
[email protected]0436b102011-04-15 18:30:03325 extensions_enabled_(extensions_enabled),
[email protected]4a10006a2013-05-17 23:18:35326 ready_(ready),
ryanackley48bedbd2015-01-27 23:12:14327 shared_module_service_(new extensions::SharedModuleService(profile_)),
rdevlin.cronin5e510e802016-07-26 15:09:20328 renderer_helper_(
329 extensions::RendererStartupHelperFactory::GetForBrowserContext(
330 profile_)),
ryanackley48bedbd2015-01-27 23:12:14331 app_data_migrator_(new extensions::AppDataMigrator(profile_, registry_)) {
[email protected]a29a517a2011-01-21 21:11:12332 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
rkaplowdd66a1342015-03-05 00:31:49333 TRACE_EVENT0("browser,startup", "ExtensionService::ExtensionService::ctor");
[email protected]a8af9fdb2010-10-28 21:52:20334
[email protected]36a784c2009-06-23 06:21:08335 // Figure out if extension installation should be enabled.
[email protected]367d9b172013-12-03 00:31:02336 if (extensions::ExtensionsBrowserClient::Get()->AreExtensionsDisabled(
337 *command_line, profile))
[email protected]6d60703b2009-08-29 01:29:23338 extensions_enabled_ = false;
[email protected]36a784c2009-06-23 06:21:08339
[email protected]3c4abc82012-10-22 22:25:54340 registrar_.Add(this, chrome::NOTIFICATION_APP_TERMINATING,
341 content::NotificationService::AllBrowserContextsAndSources());
[email protected]adf5a102014-07-31 12:44:06342 registrar_.Add(this,
343 extensions::NOTIFICATION_EXTENSION_PROCESS_TERMINATED,
[email protected]ad50def52011-10-19 23:17:07344 content::NotificationService::AllBrowserContextsAndSources());
[email protected]432115822011-07-10 15:52:27345 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_TERMINATED,
[email protected]ad50def52011-10-19 23:17:07346 content::NotificationService::AllBrowserContextsAndSources());
[email protected]92dd8d92013-02-26 00:41:08347 registrar_.Add(this, chrome::NOTIFICATION_UPGRADE_RECOMMENDED,
348 content::NotificationService::AllBrowserContextsAndSources());
[email protected]ebe07772014-05-22 04:16:06349 registrar_.Add(this,
350 chrome::NOTIFICATION_PROFILE_DESTRUCTION_STARTED,
351 content::Source<Profile>(profile_));
binjin1569c9b2014-09-05 13:33:18352
353 extensions::ExtensionManagementFactory::GetForBrowserContext(profile_)
354 ->AddObserver(this);
[email protected]4814b512009-11-07 00:12:29355
rkaplowdd66a1342015-03-05 00:31:49356 // Set up the ExtensionUpdater.
[email protected]93fd78f42009-07-10 16:43:17357 if (autoupdate_enabled) {
[email protected]501105b2013-09-26 05:42:02358 int update_frequency = extensions::kDefaultUpdateFrequencySeconds;
[email protected]93fd78f42009-07-10 16:43:17359 if (command_line->HasSwitch(switches::kExtensionsUpdateFrequency)) {
[email protected]e83326f2010-07-31 17:29:25360 base::StringToInt(command_line->GetSwitchValueASCII(
361 switches::kExtensionsUpdateFrequency),
362 &update_frequency);
[email protected]93fd78f42009-07-10 16:43:17363 }
[email protected]044e86992014-01-24 22:59:11364 updater_.reset(new extensions::ExtensionUpdater(
365 this,
366 extension_prefs,
367 profile->GetPrefs(),
368 profile,
369 update_frequency,
rockotffa65b12014-10-14 17:19:06370 extensions::ExtensionsBrowserClient::Get()->GetExtensionCache(),
rockotdb5192992014-09-16 21:27:02371 base::Bind(ChromeExtensionDownloaderFactory::CreateForProfile,
372 profile)));
[email protected]93fd78f42009-07-10 16:43:17373 }
374
[email protected]25ae0152011-11-18 14:40:02375 component_loader_.reset(
376 new extensions::ComponentLoader(this,
377 profile->GetPrefs(),
[email protected]55e16cd2013-12-18 04:36:08378 g_browser_process->local_state(),
379 profile));
[email protected]8e4560b62011-01-14 10:09:14380
[email protected]0436b102011-04-15 18:30:03381 if (extensions_enabled_) {
[email protected]ae4c37e2012-12-21 01:16:25382 extensions::ExternalProviderImpl::CreateExternalProviders(
383 this, profile_, &external_extension_providers_);
[email protected]873531342011-03-09 12:16:05384 }
[email protected]b671760b2010-07-15 21:13:47385
[email protected]74474042013-11-21 12:03:54386 // Set this as the ExtensionService for app sorting to ensure it causes syncs
387 // if required.
[email protected]b3aa7182013-04-25 04:45:23388 is_first_run_ = !extension_prefs_->SetAlertSystemFirstRun();
389
[email protected]373daf972014-04-10 01:50:44390 error_controller_.reset(
391 new extensions::ExtensionErrorController(profile_, is_first_run_));
[email protected]374ceb6f2014-07-02 19:25:34392 external_install_manager_.reset(
393 new extensions::ExternalInstallManager(profile_, is_first_run_));
[email protected]373daf972014-04-10 01:50:44394
[email protected]c77f2352012-08-08 22:07:58395 extension_action_storage_manager_.reset(
396 new extensions::ExtensionActionStorageManager(profile_));
397
[email protected]cb0e50312011-05-09 15:03:07398 // How long is the path to the Extensions directory?
399 UMA_HISTOGRAM_CUSTOM_COUNTS("Extensions.ExtensionRootPathLength",
drbasicf0d1b262016-08-23 06:10:42400 install_directory_.value().length(), 1, 500, 100);
[email protected]6014d672008-12-05 00:38:25401}
402
[email protected]3f213ad2012-07-26 23:39:41403extensions::PendingExtensionManager*
404 ExtensionService::pending_extension_manager() {
[email protected]b2907fd2011-03-25 16:43:37405 return &pending_extension_manager_;
[email protected]ddb1e5a2010-12-13 20:10:45406}
407
[email protected]eaa7dd182010-12-14 11:09:00408ExtensionService::~ExtensionService() {
[email protected]c8d407e2011-04-28 21:27:17409 // No need to unload extensions here because they are profile-scoped, and the
410 // profile is in the process of being deleted.
achuith2f5578b2016-02-26 21:57:13411 for (const auto& provider : external_extension_providers_)
[email protected]8e4560b62011-01-14 10:09:14412 provider->ServiceShutdown();
[email protected]6014d672008-12-05 00:38:25413}
414
[email protected]037228a2012-10-05 01:36:16415void ExtensionService::Shutdown() {
binjin1569c9b2014-09-05 13:33:18416 extensions::ExtensionManagementFactory::GetInstance()
417 ->GetForBrowserContext(profile())
418 ->RemoveObserver(this);
[email protected]037228a2012-10-05 01:36:16419}
420
[email protected]b2907fd2011-03-25 16:43:37421const Extension* ExtensionService::GetExtensionById(
422 const std::string& id, bool include_disabled) const {
[email protected]599539802014-01-07 23:06:00423 int include_mask = ExtensionRegistry::ENABLED;
[email protected]695b5712012-12-06 23:55:28424 if (include_disabled) {
mlerman6a37b6a42014-11-26 22:10:53425 // Include blacklisted and blocked extensions here because there are
426 // hundreds of callers of this function, and many might assume that this
427 // includes those that have been disabled due to blacklisting or blocking.
[email protected]599539802014-01-07 23:06:00428 include_mask |= ExtensionRegistry::DISABLED |
mlerman6a37b6a42014-11-26 22:10:53429 ExtensionRegistry::BLACKLISTED | ExtensionRegistry::BLOCKED;
[email protected]695b5712012-12-06 23:55:28430 }
[email protected]599539802014-01-07 23:06:00431 return registry_->GetExtensionById(id, include_mask);
[email protected]695b5712012-12-06 23:55:28432}
433
[email protected]eaa7dd182010-12-14 11:09:00434void ExtensionService::Init() {
[email protected]a29a517a2011-01-21 21:11:12435 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
rkaplowe65c2ff2015-02-14 16:29:54436 TRACE_EVENT0("browser,startup", "ExtensionService::Init");
rkaplowa8fd8d32015-02-25 21:27:56437 SCOPED_UMA_HISTOGRAM_TIMER("Extensions.ExtensionServiceInitTime");
[email protected]3350d712013-11-18 09:32:24438
[email protected]4a10006a2013-05-17 23:18:35439 DCHECK(!is_ready()); // Can't redo init.
[email protected]bb1bc9b32013-12-21 03:09:14440 DCHECK_EQ(registry_->enabled_extensions().size(), 0u);
[email protected]9f1087e2009-06-15 17:29:32441
benwells22ab8ee2015-08-21 02:55:08442 // LoadAllExtensions() calls OnLoadedInstalledExtensions().
443 component_loader_->LoadAll();
444 extensions::InstalledLoader(this).LoadAllExtensions();
catmullings98cd1942016-08-30 22:31:59445 LoadExtensionsFromCommandLineFlag(switches::kDisableExtensionsExcept);
446 if (extensions_enabled_)
447 LoadExtensionsFromCommandLineFlag(switches::kLoadExtension);
samuong5da9a9a2017-02-15 06:08:20448 // ChromeDriver has no way of determining the Chrome version until after
449 // launch, so it needs to continue passing load-component-extension until it
450 // stops supporting Chrome 56 (when M58 is released). These extensions are
451 // loaded as regular extensions, not component extensions, and are thus safe.
452 // TODO(samuong): Remove this when we release Chrome 58 to stable channel.
453 if (command_line_->HasSwitch(switches::kEnableAutomation) &&
454 command_line_->HasSwitch(kDeprecatedLoadComponentExtension)) {
455 LOG(WARNING) << "Loading extension specified by "
456 "--load-component-extension as a regular extension. "
457 "Extensions specified by --load-component-extension will "
458 "not be loaded starting in M58. Use --load-extension or "
459 "--disable-extensions-except.";
460 LoadExtensionsFromCommandLineFlag(kDeprecatedLoadComponentExtension);
461 }
benwells22ab8ee2015-08-21 02:55:08462 EnabledReloadableExtensions();
463 MaybeFinishShutdownDelayed();
464 SetReadyAndNotifyListeners();
[email protected]ae4c37e2012-12-21 01:16:25465
benwells22ab8ee2015-08-21 02:55:08466 // TODO(erikkay): this should probably be deferred to a future point
467 // rather than running immediately at startup.
468 CheckForExternalUpdates();
[email protected]894bb502009-05-21 22:39:57469
benwells22ab8ee2015-08-21 02:55:08470 LoadGreylistFromPrefs();
rkaplowa8fd8d32015-02-25 21:27:56471}
[email protected]3350d712013-11-18 09:32:24472
rkaplowa8fd8d32015-02-25 21:27:56473void ExtensionService::EnabledReloadableExtensions() {
474 TRACE_EVENT0("browser,startup",
475 "ExtensionService::EnabledReloadableExtensions");
476
477 std::vector<std::string> extensions_to_enable;
achuith2f5578b2016-02-26 21:57:13478 for (const auto& e : registry_->disabled_extensions()) {
rkaplowa8fd8d32015-02-25 21:27:56479 if (extension_prefs_->GetDisableReasons(e->id()) ==
achuith2f5578b2016-02-26 21:57:13480 Extension::DISABLE_RELOAD)
rkaplowa8fd8d32015-02-25 21:27:56481 extensions_to_enable.push_back(e->id());
rkaplowa8fd8d32015-02-25 21:27:56482 }
483 for (const std::string& extension : extensions_to_enable) {
484 EnableExtension(extension);
485 }
486}
487
488void ExtensionService::MaybeFinishShutdownDelayed() {
489 TRACE_EVENT0("browser,startup",
490 "ExtensionService::MaybeFinishShutdownDelayed");
491
dchengc963c7142016-04-08 03:55:22492 std::unique_ptr<extensions::ExtensionPrefs::ExtensionsInfo> delayed_info(
rkaplowa8fd8d32015-02-25 21:27:56493 extension_prefs_->GetAllDelayedInstallInfo());
494 for (size_t i = 0; i < delayed_info->size(); ++i) {
495 ExtensionInfo* info = delayed_info->at(i).get();
achuith2f5578b2016-02-26 21:57:13496 scoped_refptr<const Extension> extension(nullptr);
rkaplowa8fd8d32015-02-25 21:27:56497 if (info->extension_manifest) {
498 std::string error;
499 extension = Extension::Create(
500 info->extension_path, info->extension_location,
501 *info->extension_manifest,
502 extension_prefs_->GetDelayedInstallCreationFlags(info->extension_id),
503 info->extension_id, &error);
504 if (extension.get())
505 delayed_installs_.Insert(extension);
506 }
507 }
508 MaybeFinishDelayedInstallations();
dchengc963c7142016-04-08 03:55:22509 std::unique_ptr<extensions::ExtensionPrefs::ExtensionsInfo> delayed_info2(
rkaplowa8fd8d32015-02-25 21:27:56510 extension_prefs_->GetAllDelayedInstallInfo());
511 UMA_HISTOGRAM_COUNTS_100("Extensions.UpdateOnLoad",
512 delayed_info2->size() - delayed_info->size());
[email protected]6014d672008-12-05 00:38:25513}
514
[email protected]2d19eb6e2014-01-27 17:30:00515void ExtensionService::LoadGreylistFromPrefs() {
rkaplowa8fd8d32015-02-25 21:27:56516 TRACE_EVENT0("browser,startup", "ExtensionService::LoadGreylistFromPrefs");
517
dchengc963c7142016-04-08 03:55:22518 std::unique_ptr<ExtensionSet> all_extensions =
[email protected]f47f7172014-03-19 19:27:10519 registry_->GenerateInstalledExtensionsSet();
[email protected]2d19eb6e2014-01-27 17:30:00520
achuith2f5578b2016-02-26 21:57:13521 for (const auto& extension : *all_extensions) {
522 const extensions::BlacklistState state =
523 extension_prefs_->GetExtensionBlacklistState(extension->id());
[email protected]2d19eb6e2014-01-27 17:30:00524 if (state == extensions::BLACKLISTED_SECURITY_VULNERABILITY ||
525 state == extensions::BLACKLISTED_POTENTIALLY_UNWANTED ||
526 state == extensions::BLACKLISTED_CWS_POLICY_VIOLATION)
achuith2f5578b2016-02-26 21:57:13527 greylist_.Insert(extension);
[email protected]2d19eb6e2014-01-27 17:30:00528 }
529}
530
ginkage553af3202015-02-04 12:39:09531bool ExtensionService::UpdateExtension(const extensions::CRXFileInfo& file,
[email protected]044e86992014-01-24 22:59:11532 bool file_ownership_passed,
[email protected]31bb5ee62012-09-12 22:58:40533 CrxInstaller** out_crx_installer) {
[email protected]a29a517a2011-01-21 21:11:12534 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]3c4abc82012-10-22 22:25:54535 if (browser_terminating_) {
536 LOG(WARNING) << "Skipping UpdateExtension due to browser shutdown";
537 // Leak the temp file at extension_path. We don't want to add to the disk
538 // I/O burden at shutdown, we can't rely on the I/O completing anyway, and
539 // the file is in the OS temp directory which should be cleaned up for us.
540 return false;
541 }
[email protected]a8af9fdb2010-10-28 21:52:20542
ginkage553af3202015-02-04 12:39:09543 const std::string& id = file.extension_id;
544
[email protected]3f213ad2012-07-26 23:39:41545 const extensions::PendingExtensionInfo* pending_extension_info =
[email protected]51a3bf8b2012-06-08 22:53:06546 pending_extension_manager()->GetById(id);
[email protected]8ef78fd2010-08-19 17:14:32547
[email protected]695b5712012-12-06 23:55:28548 const Extension* extension = GetInstalledExtension(id);
[email protected]51a3bf8b2012-06-08 22:53:06549 if (!pending_extension_info && !extension) {
[email protected]aa142702010-03-26 01:26:33550 LOG(WARNING) << "Will not update extension " << id
551 << " because it is not installed or pending";
552 // Delete extension_path since we're not creating a CrxInstaller
553 // that would do it for us.
asargentd50b18c2016-04-21 01:17:16554 if (file_ownership_passed &&
555 !GetFileTaskRunner()->PostTask(
[email protected]7f8f24f2012-11-15 19:40:14556 FROM_HERE,
ginkage553af3202015-02-04 12:39:09557 base::Bind(&extensions::file_util::DeleteFile, file.path, false)))
[email protected]14908b72011-04-20 06:54:36558 NOTREACHED();
[email protected]420a0ec2011-06-01 01:07:03559
560 return false;
[email protected]e957fe52009-06-23 16:51:05561 }
562
treibe960e282015-09-11 10:38:08563 scoped_refptr<CrxInstaller> installer(CrxInstaller::CreateSilent(this));
[email protected]6dfbbf82010-03-12 23:09:16564 installer->set_expected_id(id);
ginkage47e603e2015-02-27 08:42:41565 installer->set_expected_hash(file.expected_hash);
[email protected]464213a2013-10-15 01:06:48566 int creation_flags = Extension::NO_FLAGS;
[email protected]51a3bf8b2012-06-08 22:53:06567 if (pending_extension_info) {
568 installer->set_install_source(pending_extension_info->install_source());
pkotwicz31eb1e8ec2014-10-08 15:26:46569 installer->set_allow_silent_install(true);
treibe960e282015-09-11 10:38:08570 // If the extension came in disabled due to a permission increase, then
571 // don't grant it all the permissions. crbug.com/484214
572 bool has_permissions_increase =
573 extensions::ExtensionPrefs::Get(profile_)->HasDisableReason(
574 id, Extension::DISABLE_PERMISSIONS_INCREASE);
575 const base::Version& expected_version = pending_extension_info->version();
576 if (has_permissions_increase ||
577 pending_extension_info->remote_install() ||
578 !expected_version.IsValid()) {
[email protected]21db9ef2014-05-16 02:06:27579 installer->set_grant_permissions(false);
treibe960e282015-09-11 10:38:08580 } else {
581 installer->set_expected_version(expected_version,
582 false /* fail_install_if_unexpected */);
583 }
mamir0128d5a2016-07-15 20:55:48584 creation_flags = pending_extension_info->creation_flags();
[email protected]464213a2013-10-15 01:06:48585 if (pending_extension_info->mark_acknowledged())
[email protected]374ceb6f2014-07-02 19:25:34586 external_install_manager_->AcknowledgeExternalExtension(id);
[email protected]51a3bf8b2012-06-08 22:53:06587 } else if (extension) {
[email protected]5eb375e92010-11-26 07:50:41588 installer->set_install_source(extension->location());
[email protected]51a3bf8b2012-06-08 22:53:06589 }
[email protected]7d8b7072012-04-07 01:07:46590 // If the extension was installed from or has migrated to the webstore, or
[email protected]fcb2c2c2012-10-17 21:08:45591 // its auto-update URL is from the webstore, treat it as a webstore install.
592 // Note that we ignore some older extensions with blank auto-update URLs
593 // because we are mostly concerned with restrictions on NaCl extensions,
594 // which are newer.
[email protected]75764512011-12-19 19:54:28595 if ((extension && extension->from_webstore()) ||
[email protected]4a5fe3e22013-06-04 07:06:38596 (extension && extensions::ManifestURL::UpdatesFromGallery(extension)) ||
[email protected]963d13c2012-09-29 17:13:35597 (!extension && extension_urls::IsWebstoreUpdateUrl(
[email protected]51a3bf8b2012-06-08 22:53:06598 pending_extension_info->update_url()))) {
[email protected]a12ce8b22012-01-17 18:40:53599 creation_flags |= Extension::FROM_WEBSTORE;
600 }
601
602 // Bookmark apps being updated is kind of a contradiction, but that's because
603 // we mark the default apps as bookmark apps, and they're hosted in the web
604 // store, thus they can get updated. See http://crbug.com/101605 for more
605 // details.
606 if (extension && extension->from_bookmark())
607 creation_flags |= Extension::FROM_BOOKMARK;
608
[email protected]e33bbc22012-08-27 22:05:46609 if (extension && extension->was_installed_by_default())
610 creation_flags |= Extension::WAS_INSTALLED_BY_DEFAULT;
611
[email protected]acc3c7c22014-03-19 06:23:39612 if (extension && extension->was_installed_by_oem())
613 creation_flags |= Extension::WAS_INSTALLED_BY_OEM;
614
benwells1dd4acd2015-12-09 02:20:24615 if (extension)
[email protected]c30bda262014-06-19 04:10:13616 installer->set_do_not_sync(extension_prefs_->DoNotSync(id));
[email protected]ab6c7be42014-01-16 02:05:54617
[email protected]a12ce8b22012-01-17 18:40:53618 installer->set_creation_flags(creation_flags);
619
[email protected]044e86992014-01-24 22:59:11620 installer->set_delete_source(file_ownership_passed);
[email protected]cb0e50312011-05-09 15:03:07621 installer->set_install_cause(extension_misc::INSTALL_CAUSE_UPDATE);
ginkage553af3202015-02-04 12:39:09622 installer->InstallCrxFile(file);
[email protected]420a0ec2011-06-01 01:07:03623
624 if (out_crx_installer)
[email protected]dc24976f2013-06-02 21:15:09625 *out_crx_installer = installer.get();
[email protected]420a0ec2011-06-01 01:07:03626
627 return true;
[email protected]e957fe52009-06-23 16:51:05628}
629
catmullings98cd1942016-08-30 22:31:59630void ExtensionService::LoadExtensionsFromCommandLineFlag(
631 const char* switch_name) {
632 if (command_line_->HasSwitch(switch_name)) {
633 base::CommandLine::StringType path_list =
634 command_line_->GetSwitchValueNative(switch_name);
635 base::StringTokenizerT<base::CommandLine::StringType,
636 base::CommandLine::StringType::const_iterator>
637 t(path_list, FILE_PATH_LITERAL(","));
638 while (t.GetNext()) {
639 std::string extension_id;
640 extensions::UnpackedInstaller::Create(this)->LoadFromCommandLine(
641 base::FilePath(t.token()), &extension_id, false /*only-allow-apps*/);
642 // Extension id is added to whitelist after its extension is loaded
643 // because code is executed asynchronously.
644 if (switch_name == switches::kDisableExtensionsExcept)
645 disable_flag_exempted_extensions_.insert(extension_id);
646 }
647 }
648}
649
[email protected]bca4b832014-07-17 20:22:34650void ExtensionService::ReloadExtensionImpl(
[email protected]757d60a2014-05-23 00:11:44651 // "transient" because the process of reloading may cause the reference
652 // to become invalid. Instead, use |extension_id|, a copy.
[email protected]bca4b832014-07-17 20:22:34653 const std::string& transient_extension_id,
654 bool be_noisy) {
[email protected]a29a517a2011-01-21 21:11:12655 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]2a947202013-03-06 04:58:05656
657 // If the extension is already reloading, don't reload again.
[email protected]757d60a2014-05-23 00:11:44658 if (extension_prefs_->GetDisableReasons(transient_extension_id) &
[email protected]2a947202013-03-06 04:58:05659 Extension::DISABLE_RELOAD) {
660 return;
661 }
662
mlerman6a37b6a42014-11-26 22:10:53663 // Ignore attempts to reload a blacklisted or blocked extension. Sometimes
664 // this can happen in a convoluted reload sequence triggered by the
665 // termination of a blacklisted or blocked extension and a naive attempt to
666 // reload it. For an example see http://crbug.com/373842.
667 if (registry_->blacklisted_extensions().Contains(transient_extension_id) ||
668 registry_->blocked_extensions().Contains(transient_extension_id)) {
[email protected]757d60a2014-05-23 00:11:44669 return;
mlerman6a37b6a42014-11-26 22:10:53670 }
[email protected]757d60a2014-05-23 00:11:44671
[email protected]650b2d52013-02-10 03:41:45672 base::FilePath path;
[email protected]757d60a2014-05-23 00:11:44673
674 std::string extension_id = transient_extension_id;
675 const Extension* transient_current_extension =
676 GetExtensionById(extension_id, false);
[email protected]9cddd4702009-07-27 22:09:40677
[email protected]f17dbd42010-08-16 23:21:10678 // Disable the extension if it's loaded. It might not be loaded if it crashed.
[email protected]757d60a2014-05-23 00:11:44679 if (transient_current_extension) {
[email protected]4814b512009-11-07 00:12:29680 // If the extension has an inspector open for its background page, detach
681 // the inspector and hang onto a cookie for it, so that we can reattach
682 // later.
[email protected]31d8f5f22012-04-02 15:22:08683 // TODO(yoz): this is not incognito-safe!
reillyg0ea3fa902014-10-28 15:30:23684 extensions::ProcessManager* manager =
685 extensions::ProcessManager::Get(profile_);
[email protected]3a1dc572012-07-31 22:25:13686 extensions::ExtensionHost* host =
687 manager->GetBackgroundHostForExtension(extension_id);
[email protected]b3f957e62014-08-08 10:09:02688 if (host && DevToolsAgentHost::HasFor(host->host_contents())) {
[email protected]4814b512009-11-07 00:12:29689 // Look for an open inspector for the background page.
[email protected]04ea1bb2013-07-10 09:26:09690 scoped_refptr<DevToolsAgentHost> agent_host =
[email protected]b3f957e62014-08-08 10:09:02691 DevToolsAgentHost::GetOrCreateFor(host->host_contents());
692 agent_host->DisconnectWebContents();
[email protected]04ea1bb2013-07-10 09:26:09693 orphaned_dev_tools_[extension_id] = agent_host;
[email protected]4814b512009-11-07 00:12:29694 }
695
[email protected]757d60a2014-05-23 00:11:44696 path = transient_current_extension->path();
[email protected]58076192013-07-19 19:43:50697 // BeingUpgraded is set back to false when the extension is added.
rdevlin.cronin2c16c602014-11-21 01:35:49698 system_->runtime_data()->SetBeingUpgraded(transient_current_extension->id(),
[email protected]757d60a2014-05-23 00:11:44699 true);
[email protected]44d62b62012-04-11 00:06:03700 DisableExtension(extension_id, Extension::DISABLE_RELOAD);
rdevlin.cronin07f10c12017-02-08 19:37:58701 DCHECK(registry_->disabled_extensions().Contains(extension_id));
[email protected]b914e2952013-04-26 07:10:03702 reloading_extensions_.insert(extension_id);
[email protected]1eb175082010-02-10 09:26:16703 } else {
[email protected]d32c02a2014-06-16 22:58:36704 std::map<std::string, base::FilePath>::const_iterator iter =
705 unloaded_extension_paths_.find(extension_id);
706 if (iter == unloaded_extension_paths_.end()) {
707 return;
708 }
[email protected]1eb175082010-02-10 09:26:16709 path = unloaded_extension_paths_[extension_id];
[email protected]b65272f2009-08-31 15:47:06710 }
711
achuith2f5578b2016-02-26 21:57:13712 transient_current_extension = nullptr;
[email protected]757d60a2014-05-23 00:11:44713
[email protected]9f4e4f082013-06-21 07:11:19714 if (delayed_installs_.Contains(extension_id)) {
[email protected]6f6101832012-11-27 22:10:48715 FinishDelayedInstallation(extension_id);
[email protected]0db124b02012-11-07 04:55:05716 return;
717 }
718
[email protected]43ceb002012-02-10 23:19:15719 // If we're reloading a component extension, use the component extension
720 // loader's reloader.
721 if (component_loader_->Exists(extension_id)) {
722 component_loader_->Reload(extension_id);
723 return;
724 }
725
[email protected]e6090e42010-03-23 22:44:08726 // Check the installed extensions to see if what we're reloading was already
727 // installed.
dchengc963c7142016-04-08 03:55:22728 std::unique_ptr<ExtensionInfo> installed_extension(
[email protected]e6090e42010-03-23 22:44:08729 extension_prefs_->GetInstalledExtensionInfo(extension_id));
730 if (installed_extension.get() &&
731 installed_extension->extension_manifest.get()) {
[email protected]d8c8f25f2011-11-02 18:18:01732 extensions::InstalledLoader(this).Load(*installed_extension, false);
[email protected]e6090e42010-03-23 22:44:08733 } else {
[email protected]d8c8f25f2011-11-02 18:18:01734 // Otherwise, the extension is unpacked (location LOAD).
[email protected]e6090e42010-03-23 22:44:08735 // We should always be able to remember the extension's path. If it's not in
736 // the map, someone failed to update |unloaded_extension_paths_|.
737 CHECK(!path.empty());
[email protected]bca4b832014-07-17 20:22:34738 scoped_refptr<extensions::UnpackedInstaller> unpacked_installer =
739 extensions::UnpackedInstaller::Create(this);
740 unpacked_installer->set_be_noisy_on_failure(be_noisy);
741 unpacked_installer->Load(path);
[email protected]e6090e42010-03-23 22:44:08742 }
[email protected]9cddd4702009-07-27 22:09:40743}
744
[email protected]bca4b832014-07-17 20:22:34745void ExtensionService::ReloadExtension(const std::string& extension_id) {
asargentd50b18c2016-04-21 01:17:16746 ReloadExtensionImpl(extension_id, true); // be_noisy
[email protected]bca4b832014-07-17 20:22:34747}
748
749void ExtensionService::ReloadExtensionWithQuietFailure(
750 const std::string& extension_id) {
asargentd50b18c2016-04-21 01:17:16751 ReloadExtensionImpl(extension_id, false); // be_noisy
[email protected]bca4b832014-07-17 20:22:34752}
753
[email protected]757d60a2014-05-23 00:11:44754bool ExtensionService::UninstallExtension(
755 // "transient" because the process of uninstalling may cause the reference
756 // to become invalid. Instead, use |extenson->id()|.
757 const std::string& transient_extension_id,
[email protected]e43c61f2014-07-20 21:46:34758 extensions::UninstallReason reason,
[email protected]42d58f62014-07-31 01:32:45759 const base::Closure& deletion_done_callback,
[email protected]757d60a2014-05-23 00:11:44760 base::string16* error) {
[email protected]a29a517a2011-01-21 21:11:12761 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]a8af9fdb2010-10-28 21:52:20762
[email protected]757d60a2014-05-23 00:11:44763 scoped_refptr<const Extension> extension =
764 GetInstalledExtension(transient_extension_id);
[email protected]631cf822009-05-15 07:01:25765
[email protected]e7afe2452010-08-22 16:19:13766 // Callers should not send us nonexistent extensions.
[email protected]dc24976f2013-06-02 21:15:09767 CHECK(extension.get());
[email protected]9f1087e2009-06-15 17:29:32768
binjincccacef2014-10-13 19:00:20769 ManagementPolicy* by_policy = system_->management_policy();
[email protected]95da88c42011-03-31 10:07:33770 // Policy change which triggers an uninstall will always set
771 // |external_uninstall| to true so this is the only way to uninstall
772 // managed extensions.
[email protected]90878c52014-04-04 18:21:02773 // Shared modules being uninstalled will also set |external_uninstall| to true
774 // so that we can guarantee users don't uninstall a shared module.
775 // (crbug.com/273300)
776 // TODO(rdevlin.cronin): This is probably not right. We should do something
777 // else, like include an enum IS_INTERNAL_UNINSTALL or IS_USER_UNINSTALL so
778 // we don't do this.
[email protected]cc2f55c2014-07-08 02:19:04779 bool external_uninstall =
[email protected]e43c61f2014-07-20 21:46:34780 (reason == extensions::UNINSTALL_REASON_INTERNAL_MANAGEMENT) ||
dtseng9fb3d5b2015-02-23 17:24:17781 (reason == extensions::UNINSTALL_REASON_COMPONENT_REMOVED) ||
rdevlin.cronin5f6b69d2014-09-20 01:23:35782 (reason == extensions::UNINSTALL_REASON_REINSTALL) ||
[email protected]e43c61f2014-07-20 21:46:34783 (reason == extensions::UNINSTALL_REASON_ORPHANED_EXTERNAL_EXTENSION) ||
[email protected]6ef60012014-07-22 19:08:12784 (reason == extensions::UNINSTALL_REASON_ORPHANED_SHARED_MODULE) ||
785 (reason == extensions::UNINSTALL_REASON_SYNC &&
mamir192d7882016-06-22 17:10:16786 extensions::util::WasInstalledByCustodian(extension->id(), profile_));
[email protected]65187152012-06-02 13:14:14787 if (!external_uninstall &&
binjincccacef2014-10-13 19:00:20788 (!by_policy->UserMayModifySettings(extension.get(), error) ||
789 by_policy->MustRemainInstalled(extension.get(), error))) {
[email protected]ad50def52011-10-19 23:17:07790 content::NotificationService::current()->Notify(
[email protected]adf5a102014-07-31 12:44:06791 extensions::NOTIFICATION_EXTENSION_UNINSTALL_NOT_ALLOWED,
[email protected]6c2381d2011-10-19 02:52:53792 content::Source<Profile>(profile_),
[email protected]dc24976f2013-06-02 21:15:09793 content::Details<const Extension>(extension.get()));
[email protected]d6ebc9792011-04-07 18:18:33794 return false;
795 }
[email protected]95da88c42011-03-31 10:07:33796
juncai33e462102015-05-18 20:48:44797 InstallVerifier::Get(GetBrowserContext())->Remove(extension->id());
[email protected]ffd2f79e2013-11-14 00:11:46798
[email protected]9b217652010-10-08 22:04:23799 UMA_HISTOGRAM_ENUMERATION("Extensions.UninstallType",
[email protected]7fa19f82010-12-21 19:40:08800 extension->GetType(), 100);
treib2e0517f92015-05-07 23:15:36801 RecordPermissionMessagesHistogram(extension.get(), "Uninstall");
[email protected]9b217652010-10-08 22:04:23802
[email protected]831aa212010-03-26 13:55:19803 // Unload before doing more cleanup to ensure that nothing is hanging on to
804 // any of these resources.
[email protected]757d60a2014-05-23 00:11:44805 UnloadExtension(extension->id(), UnloadedExtensionInfo::REASON_UNINSTALL);
asargent96c7ec42016-05-27 02:45:47806 if (registry_->blacklisted_extensions().Contains(extension->id()))
807 registry_->RemoveBlacklisted(extension->id());
[email protected]831aa212010-03-26 13:55:19808
[email protected]9f1087e2009-06-15 17:29:32809 // Tell the backend to start deleting installed extensions on the file thread.
[email protected]12075d12013-02-27 05:38:05810 if (!Manifest::IsUnpackedLocation(extension->location())) {
[email protected]7f8f24f2012-11-15 19:40:14811 if (!GetFileTaskRunner()->PostTask(
812 FROM_HERE,
[email protected]5a145e82014-05-29 22:19:07813 base::Bind(&ExtensionService::UninstallExtensionOnFileThread,
814 extension->id(),
815 profile_,
[email protected]85df9d12014-04-15 17:02:14816 install_directory_,
[email protected]5a145e82014-05-29 22:19:07817 extension->path())))
[email protected]14908b72011-04-20 06:54:36818 NOTREACHED();
[email protected]9f1087e2009-06-15 17:29:32819 }
820
[email protected]42d58f62014-07-31 01:32:45821 extensions::DataDeleter::StartDeleting(
822 profile_, extension.get(), deletion_done_callback);
[email protected]0d6ec3a72011-09-02 02:09:43823
[email protected]757d60a2014-05-23 00:11:44824 UntrackTerminatedExtension(extension->id());
[email protected]211030342010-09-30 18:41:06825
826 // Notify interested parties that we've uninstalled this extension.
[email protected]e43c61f2014-07-20 21:46:34827 ExtensionRegistry::Get(profile_)
828 ->TriggerOnUninstalled(extension.get(), reason);
[email protected]d6ebc9792011-04-07 18:18:33829
[email protected]757d60a2014-05-23 00:11:44830 delayed_installs_.Remove(extension->id());
[email protected]0db124b02012-11-07 04:55:05831
[email protected]757d60a2014-05-23 00:11:44832 extension_prefs_->OnExtensionUninstalled(
833 extension->id(), extension->location(), external_uninstall);
[email protected]d4eda592013-09-18 03:37:57834
[email protected]333b1de2011-09-12 18:28:50835 // Track the uninstallation.
[email protected]49098f702011-10-13 03:47:18836 UMA_HISTOGRAM_ENUMERATION("Extensions.ExtensionUninstalled", 1, 2);
837
[email protected]d6ebc9792011-04-07 18:18:33838 return true;
[email protected]c10da4b02010-03-25 14:38:32839}
840
[email protected]5a145e82014-05-29 22:19:07841// static
842void ExtensionService::UninstallExtensionOnFileThread(
843 const std::string& id,
844 Profile* profile,
845 const base::FilePath& install_dir,
846 const base::FilePath& extension_path) {
847 extensions::ExtensionAssetsManager* assets_manager =
848 extensions::ExtensionAssetsManager::GetInstance();
849 assets_manager->UninstallExtension(id, profile, install_dir, extension_path);
850}
851
[email protected]c3cfb012011-04-06 22:07:35852bool ExtensionService::IsExtensionEnabled(
853 const std::string& extension_id) const {
[email protected]bb1bc9b32013-12-21 03:09:14854 if (registry_->enabled_extensions().Contains(extension_id) ||
855 registry_->terminated_extensions().Contains(extension_id)) {
[email protected]36429da2011-07-11 20:25:18856 return true;
[email protected]dc9a74f72012-08-17 18:07:21857 }
[email protected]36429da2011-07-11 20:25:18858
[email protected]bb1bc9b32013-12-21 03:09:14859 if (registry_->disabled_extensions().Contains(extension_id) ||
mlerman6a37b6a42014-11-26 22:10:53860 registry_->blacklisted_extensions().Contains(extension_id) ||
861 registry_->blocked_extensions().Contains(extension_id)) {
[email protected]ad83ca242011-07-29 01:32:25862 return false;
[email protected]695b5712012-12-06 23:55:28863 }
[email protected]ad83ca242011-07-29 01:32:25864
mlerman3690e5be2014-12-01 22:57:44865 // Blocked extensions aren't marked as such in prefs, thus if
866 // |block_extensions_| is true then CanBlockExtension() must be called with an
867 // Extension object. If the |extension_id| is not loaded, assume not enabled.
868 if (block_extensions_) {
869 const Extension* extension = GetInstalledExtension(extension_id);
870 if (!extension || CanBlockExtension(extension))
871 return false;
872 }
mlerman6a37b6a42014-11-26 22:10:53873
[email protected]ad83ca242011-07-29 01:32:25874 // If the extension hasn't been loaded yet, check the prefs for it. Assume
875 // enabled unless otherwise noted.
876 return !extension_prefs_->IsExtensionDisabled(extension_id) &&
[email protected]27e528322014-05-27 20:54:30877 !extension_prefs_->IsExtensionBlacklisted(extension_id) &&
[email protected]f574c402012-12-04 23:20:31878 !extension_prefs_->IsExternalExtensionUninstalled(extension_id);
[email protected]c3cfb012011-04-06 22:07:35879}
880
[email protected]eaa7dd182010-12-14 11:09:00881void ExtensionService::EnableExtension(const std::string& extension_id) {
[email protected]a29a517a2011-01-21 21:11:12882 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]a8af9fdb2010-10-28 21:52:20883
rdevlin.croninf87d15f2017-01-26 22:57:19884 // If the extension is currently reloading, it will be enabled once the reload
885 // is complete.
886 if (reloading_extensions_.count(extension_id) > 0)
887 return;
888
asargent96c7ec42016-05-27 02:45:47889 if (IsExtensionEnabled(extension_id) ||
890 extension_prefs_->IsExtensionBlacklisted(extension_id))
[email protected]0c6da502009-08-14 22:32:39891 return;
[email protected]bb1bc9b32013-12-21 03:09:14892 const Extension* extension =
893 registry_->disabled_extensions().GetByID(extension_id);
[email protected]0d54b682013-11-05 14:15:36894
895 ManagementPolicy* policy = system_->management_policy();
achuith2f5578b2016-02-26 21:57:13896 if (extension && policy->MustRemainDisabled(extension, nullptr, nullptr)) {
[email protected]0d54b682013-11-05 14:15:36897 UMA_HISTOGRAM_COUNTS_100("Extensions.EnableDeniedByPolicy", 1);
898 return;
899 }
[email protected]0c6da502009-08-14 22:32:39900
treib8a6d9892015-08-26 10:23:19901 extension_prefs_->SetExtensionEnabled(extension_id);
[email protected]1784e83a2009-09-08 21:01:52902
treib8a6d9892015-08-26 10:23:19903 // This can happen if sync enables an extension that is not installed yet.
[email protected]06f92562011-04-29 19:27:31904 if (!extension)
905 return;
906
[email protected]0c6da502009-08-14 22:32:39907 // Move it over to the enabled list.
[email protected]bb1bc9b32013-12-21 03:09:14908 registry_->AddEnabled(make_scoped_refptr(extension));
909 registry_->RemoveDisabled(extension->id());
[email protected]0c6da502009-08-14 22:32:39910
[email protected]62d30f42009-10-01 22:36:06911 NotifyExtensionLoaded(extension);
[email protected]3bdba0d2011-08-23 07:17:30912
[email protected]f74d7f32012-06-19 19:22:51913 // Notify listeners that the extension was enabled.
914 content::NotificationService::current()->Notify(
[email protected]adf5a102014-07-31 12:44:06915 extensions::NOTIFICATION_EXTENSION_ENABLED,
[email protected]f74d7f32012-06-19 19:22:51916 content::Source<Profile>(profile_),
917 content::Details<const Extension>(extension));
[email protected]0c6da502009-08-14 22:32:39918}
919
treibc1192322015-05-20 12:56:07920void ExtensionService::DisableExtension(const std::string& extension_id,
921 int disable_reasons) {
[email protected]a29a517a2011-01-21 21:11:12922 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]a8af9fdb2010-10-28 21:52:20923
asargent96c7ec42016-05-27 02:45:47924 if (extension_prefs_->IsExtensionBlacklisted(extension_id))
925 return;
926
treib8a6d9892015-08-26 10:23:19927 // The extension may have been disabled already. Just add the disable reasons.
[email protected]8f959f522014-08-06 06:26:28928 if (!IsExtensionEnabled(extension_id)) {
treibc1192322015-05-20 12:56:07929 extension_prefs_->AddDisableReasons(extension_id, disable_reasons);
[email protected]1784e83a2009-09-08 21:01:52930 return;
[email protected]8f959f522014-08-06 06:26:28931 }
[email protected]1784e83a2009-09-08 21:01:52932
[email protected]06f92562011-04-29 19:27:31933 const Extension* extension = GetInstalledExtension(extension_id);
elijahtaylor49c09c5c2016-07-09 01:06:22934
rdevlin.cronin07f10c12017-02-08 19:37:58935 // Some extensions cannot be disabled by users:
936 // - |extension| can be null if sync disables an extension that is not
937 // installed yet; allow disablement in this case.
938 // - Shared modules are just resources used by other extensions, and are not
939 // user-controlled.
940 // - EXTERNAL_COMPONENT extensions are not generally modifiable by users, but
941 // can be uninstalled by the browser if the user sets extension-specific
942 // preferences.
943 bool is_controlled_extension =
944 extension && (SharedModuleInfo::IsSharedModule(extension) ||
945 (!system_->management_policy()->UserMayModifySettings(
946 extension, nullptr) &&
947 extension->location() != Manifest::EXTERNAL_COMPONENT));
elijahtaylor49c09c5c2016-07-09 01:06:22948
rdevlin.cronin07f10c12017-02-08 19:37:58949 // Certain disable reasons are always allowed, since they are more internal to
950 // chrome (rather than the user choosing to disable the extension).
951 int internal_disable_reason_mask =
952 Extension::DISABLE_RELOAD | Extension::DISABLE_CORRUPTED |
953 Extension::DISABLE_UPDATE_REQUIRED_BY_POLICY;
954 bool is_internal_disable =
955 (disable_reasons & internal_disable_reason_mask) > 0;
956
957 if (!is_internal_disable && is_controlled_extension)
[email protected]95da88c42011-03-31 10:07:33958 return;
959
treib8a6d9892015-08-26 10:23:19960 extension_prefs_->SetExtensionDisabled(extension_id, disable_reasons);
[email protected]1784e83a2009-09-08 21:01:52961
[email protected]599539802014-01-07 23:06:00962 int include_mask =
963 ExtensionRegistry::EVERYTHING & ~ExtensionRegistry::DISABLED;
964 extension = registry_->GetExtensionById(extension_id, include_mask);
[email protected]06f92562011-04-29 19:27:31965 if (!extension)
966 return;
967
[email protected]45f5b7d2014-01-22 23:47:13968 // The extension is either enabled or terminated.
969 DCHECK(registry_->enabled_extensions().Contains(extension->id()) ||
970 registry_->terminated_extensions().Contains(extension->id()));
[email protected]64742de32013-04-22 08:44:34971
[email protected]5c094792012-09-07 19:44:53972 // Move it over to the disabled list. Don't send a second unload notification
973 // for terminated extensions being disabled.
[email protected]bb1bc9b32013-12-21 03:09:14974 registry_->AddDisabled(make_scoped_refptr(extension));
975 if (registry_->enabled_extensions().Contains(extension->id())) {
976 registry_->RemoveEnabled(extension->id());
[email protected]b0af4792013-10-23 09:12:13977 NotifyExtensionUnloaded(extension, UnloadedExtensionInfo::REASON_DISABLE);
[email protected]5c094792012-09-07 19:44:53978 } else {
[email protected]bb1bc9b32013-12-21 03:09:14979 registry_->RemoveTerminated(extension->id());
[email protected]5c094792012-09-07 19:44:53980 }
[email protected]1784e83a2009-09-08 21:01:52981}
982
mtomasz294bb3e2017-01-24 02:17:52983void ExtensionService::DisableUserExtensionsExcept(
[email protected]1abf05e2013-07-09 17:04:36984 const std::vector<std::string>& except_ids) {
[email protected]e516e4c2013-06-12 17:41:14985 extensions::ManagementPolicy* management_policy =
986 system_->management_policy();
987 extensions::ExtensionList to_disable;
988
achuith2f5578b2016-02-26 21:57:13989 for (const auto& extension : registry_->enabled_extensions()) {
990 if (management_policy->UserMayModifySettings(extension.get(), nullptr))
991 to_disable.push_back(extension);
[email protected]e516e4c2013-06-12 17:41:14992 }
993
achuith2f5578b2016-02-26 21:57:13994 for (const auto& extension : registry_->terminated_extensions()) {
995 if (management_policy->UserMayModifySettings(extension.get(), nullptr))
996 to_disable.push_back(extension);
997 }
998
999 for (const auto& extension : to_disable) {
1000 if (extension->was_installed_by_default() &&
[email protected]3082fe32013-08-06 11:12:381001 extension_urls::IsWebstoreUpdateUrl(
achuith2f5578b2016-02-26 21:57:131002 extensions::ManifestURL::GetUpdateURL(extension.get())))
[email protected]3082fe32013-08-06 11:12:381003 continue;
achuith2f5578b2016-02-26 21:57:131004 const std::string& id = extension->id();
[email protected]1abf05e2013-07-09 17:04:361005 if (except_ids.end() == std::find(except_ids.begin(), except_ids.end(), id))
1006 DisableExtension(id, extensions::Extension::DISABLE_USER_ACTION);
[email protected]e516e4c2013-06-12 17:41:141007 }
1008}
1009
mlerman6a37b6a42014-11-26 22:10:531010// Extensions that are not locked, components or forced by policy should be
1011// locked. Extensions are no longer considered enabled or disabled. Blacklisted
1012// extensions are now considered both blacklisted and locked.
1013void ExtensionService::BlockAllExtensions() {
1014 if (block_extensions_)
1015 return;
1016 block_extensions_ = true;
1017
1018 // Blacklisted extensions are already unloaded, need not be blocked.
dchengc963c7142016-04-08 03:55:221019 std::unique_ptr<ExtensionSet> extensions =
mlerman6a37b6a42014-11-26 22:10:531020 registry_->GenerateInstalledExtensionsSet(ExtensionRegistry::ENABLED |
1021 ExtensionRegistry::DISABLED |
1022 ExtensionRegistry::TERMINATED);
1023
achuith2f5578b2016-02-26 21:57:131024 for (const auto& extension : *extensions) {
mlerman6a37b6a42014-11-26 22:10:531025 const std::string& id = extension->id();
1026
1027 if (!CanBlockExtension(extension.get()))
1028 continue;
1029
1030 registry_->RemoveEnabled(id);
1031 registry_->RemoveDisabled(id);
1032 registry_->RemoveTerminated(id);
1033
1034 registry_->AddBlocked(extension.get());
1035 UnloadExtension(id, extensions::UnloadedExtensionInfo::REASON_LOCK_ALL);
1036 }
1037}
1038
1039// All locked extensions should revert to being either enabled or disabled
1040// as appropriate.
1041void ExtensionService::UnblockAllExtensions() {
1042 block_extensions_ = false;
dchengc963c7142016-04-08 03:55:221043 std::unique_ptr<ExtensionSet> to_unblock =
mlerman6a37b6a42014-11-26 22:10:531044 registry_->GenerateInstalledExtensionsSet(ExtensionRegistry::BLOCKED);
1045
achuith2f5578b2016-02-26 21:57:131046 for (const auto& extension : *to_unblock) {
mlerman6a37b6a42014-11-26 22:10:531047 registry_->RemoveBlocked(extension->id());
1048 AddExtension(extension.get());
1049 }
1050}
1051
[email protected]eaa7dd182010-12-14 11:09:001052void ExtensionService::GrantPermissionsAndEnableExtension(
[email protected]009633c2013-03-07 22:08:281053 const Extension* extension) {
1054 GrantPermissions(extension);
treib2e0517f92015-05-07 23:15:361055 RecordPermissionMessagesHistogram(extension, "ReEnable");
[email protected]8d888c12010-11-30 00:00:251056 EnableExtension(extension->id());
1057}
1058
[email protected]009633c2013-03-07 22:08:281059void ExtensionService::GrantPermissions(const Extension* extension) {
[email protected]be083862012-09-01 03:53:451060 CHECK(extension);
[email protected]8d42db52014-06-20 21:50:501061 extensions::PermissionsUpdater(profile()).GrantActivePermissions(extension);
[email protected]be083862012-09-01 03:53:451062}
1063
[email protected]fe2dd7742011-04-19 22:52:491064// static
1065void ExtensionService::RecordPermissionMessagesHistogram(
[email protected]13c68b62013-05-17 11:29:051066 const Extension* extension, const char* histogram) {
[email protected]de415552013-01-23 04:12:171067 // Since this is called from multiple sources, and since the histogram macros
1068 // use statics, we need to manually lookup the histogram ourselves.
treib2e0517f92015-05-07 23:15:361069 base::HistogramBase* counter = base::LinearHistogram::FactoryGet(
1070 base::StringPrintf("Extensions.Permissions_%s3", histogram),
1071 1,
1072 APIPermission::kEnumBoundary,
1073 APIPermission::kEnumBoundary + 1,
1074 base::HistogramBase::kUmaTargetedHistogramFlag);
1075
1076 base::HistogramBase* counter_has_any = base::BooleanHistogram::FactoryGet(
1077 base::StringPrintf("Extensions.HasPermissions_%s3", histogram),
1078 base::HistogramBase::kUmaTargetedHistogramFlag);
1079
1080 PermissionIDSet permissions =
1081 extensions::PermissionMessageProvider::Get()->GetAllPermissionIDs(
rdevlin.cronine2d0fd02015-09-24 22:35:491082 extension->permissions_data()->active_permissions(),
treib2e0517f92015-05-07 23:15:361083 extension->GetType());
1084 counter_has_any->AddBoolean(!permissions.empty());
1085 for (const PermissionID& id : permissions)
1086 counter->Add(id.id());
[email protected]fe2dd7742011-04-19 22:52:491087}
1088
[email protected]eaa7dd182010-12-14 11:09:001089void ExtensionService::NotifyExtensionLoaded(const Extension* extension) {
[email protected]f9c8c7c72014-07-31 16:42:311090 // The URLRequestContexts need to be first to know that the extension
[email protected]62d30f42009-10-01 22:36:061091 // was loaded, otherwise a race can arise where a renderer that is created
1092 // for the extension may try to load an extension URL with an extension id
[email protected]57a777f72010-03-31 01:09:421093 // that the request context doesn't yet know about. The profile is responsible
1094 // for ensuring its URLRequestContexts appropriately discover the loaded
1095 // extension.
rockot494f0072015-07-29 17:58:071096 system_->RegisterExtensionWithRequestContexts(
1097 extension,
1098 base::Bind(&ExtensionService::OnExtensionRegisteredWithRequestContexts,
1099 AsWeakPtr(), make_scoped_refptr(extension)));
[email protected]62d30f42009-10-01 22:36:061100
rdevlin.cronin5e510e802016-07-26 15:09:201101 renderer_helper_->OnExtensionLoaded(*extension);
[email protected]77a6970c2011-04-23 16:58:561102
[email protected]3442a662012-01-12 08:06:171103 // Tell subsystems that use the EXTENSION_LOADED notification about the new
1104 // extension.
1105 //
1106 // NOTE: It is important that this happen after notifying the renderers about
1107 // the new extensions so that if we navigate to an extension URL in
[email protected]fdc76192014-04-20 21:54:411108 // ExtensionRegistryObserver::OnLoaded or
1109 // NOTIFICATION_EXTENSION_LOADED_DEPRECATED, the
[email protected]dcc47642014-03-26 22:03:491110 // renderer is guaranteed to know about it.
1111 registry_->TriggerOnLoaded(extension);
1112
[email protected]3442a662012-01-12 08:06:171113 content::NotificationService::current()->Notify(
[email protected]adf5a102014-07-31 12:44:061114 extensions::NOTIFICATION_EXTENSION_LOADED_DEPRECATED,
[email protected]3442a662012-01-12 08:06:171115 content::Source<Profile>(profile_),
1116 content::Details<const Extension>(extension));
1117
[email protected]dcc47642014-03-26 22:03:491118 // TODO(kalman): Convert ExtensionSpecialStoragePolicy to a
1119 // BrowserContextKeyedService and use ExtensionRegistryObserver.
[email protected]c8d407e2011-04-28 21:27:171120 profile_->GetExtensionSpecialStoragePolicy()->
rdevlin.croninbc8979a2014-09-30 01:08:501121 GrantRightsForExtension(extension, profile_);
[email protected]c8d407e2011-04-28 21:27:171122
[email protected]dcc47642014-03-26 22:03:491123 // TODO(kalman): This is broken. The crash reporter is process-wide so doesn't
1124 // work properly multi-profile. Besides which, it should be using
1125 // ExtensionRegistryObserver. See http://crbug.com/355029.
[email protected]c8d407e2011-04-28 21:27:171126 UpdateActiveExtensionsInCrashReporter();
1127
[email protected]d695bb12014-06-05 16:16:301128 const extensions::PermissionsData* permissions_data =
[email protected]a6910e72014-06-06 05:04:361129 extension->permissions_data();
[email protected]d695bb12014-06-05 16:16:301130
[email protected]c8d407e2011-04-28 21:27:171131 // If the extension has permission to load chrome://favicon/ resources we need
1132 // to make sure that the FaviconSource is registered with the
1133 // ChromeURLDataManager.
[email protected]d695bb12014-06-05 16:16:301134 if (permissions_data->HasHostPermission(GURL(chrome::kChromeUIFaviconURL))) {
[email protected]c8d407e2011-04-28 21:27:171135 FaviconSource* favicon_source = new FaviconSource(profile_,
1136 FaviconSource::FAVICON);
[email protected]24ea7a12013-01-27 23:54:531137 content::URLDataSource::Add(profile_, favicon_source);
[email protected]c8d407e2011-04-28 21:27:171138 }
[email protected]b07e606e2012-09-15 20:16:151139
[email protected]b07e606e2012-09-15 20:16:151140 // Same for chrome://theme/ resources.
[email protected]d695bb12014-06-05 16:16:301141 if (permissions_data->HasHostPermission(GURL(chrome::kChromeUIThemeURL))) {
[email protected]b07e606e2012-09-15 20:16:151142 ThemeSource* theme_source = new ThemeSource(profile_);
[email protected]24ea7a12013-01-27 23:54:531143 content::URLDataSource::Add(profile_, theme_source);
[email protected]b07e606e2012-09-15 20:16:151144 }
[email protected]b07e606e2012-09-15 20:16:151145
[email protected]5eddc3e2011-10-26 04:33:311146 // Same for chrome://thumb/ resources.
[email protected]d695bb12014-06-05 16:16:301147 if (permissions_data->HasHostPermission(
1148 GURL(chrome::kChromeUIThumbnailURL))) {
[email protected]420e6d92013-09-17 01:48:511149 ThumbnailSource* thumbnail_source = new ThumbnailSource(profile_, false);
[email protected]24ea7a12013-01-27 23:54:531150 content::URLDataSource::Add(profile_, thumbnail_source);
[email protected]5eddc3e2011-10-26 04:33:311151 }
[email protected]62d30f42009-10-01 22:36:061152}
1153
rockot494f0072015-07-29 17:58:071154void ExtensionService::OnExtensionRegisteredWithRequestContexts(
1155 scoped_refptr<const extensions::Extension> extension) {
1156 registry_->AddReady(extension);
1157 if (registry_->enabled_extensions().Contains(extension->id()))
1158 registry_->TriggerOnReady(extension.get());
1159}
1160
[email protected]a9f39a312010-12-23 22:14:271161void ExtensionService::NotifyExtensionUnloaded(
[email protected]814a7bf0f2011-08-13 05:30:591162 const Extension* extension,
[email protected]b0af4792013-10-23 09:12:131163 UnloadedExtensionInfo::Reason reason) {
[email protected]a9f39a312010-12-23 22:14:271164 UnloadedExtensionInfo details(extension, reason);
[email protected]e51232f32014-04-18 20:05:361165
1166 registry_->TriggerOnUnloaded(extension, reason);
1167
[email protected]ad50def52011-10-19 23:17:071168 content::NotificationService::current()->Notify(
[email protected]adf5a102014-07-31 12:44:061169 extensions::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED,
[email protected]6c2381d2011-10-19 02:52:531170 content::Source<Profile>(profile_),
1171 content::Details<UnloadedExtensionInfo>(&details));
[email protected]62d30f42009-10-01 22:36:061172
rdevlin.croninc40d39f2016-08-04 23:42:131173 renderer_helper_->OnExtensionUnloaded(*extension);
[email protected]77a6970c2011-04-23 16:58:561174
[email protected]31d8f5f22012-04-02 15:22:081175 system_->UnregisterExtensionWithRequestContexts(extension->id(), reason);
[email protected]dcc47642014-03-26 22:03:491176
1177 // TODO(kalman): Convert ExtensionSpecialStoragePolicy to a
1178 // BrowserContextKeyedService and use ExtensionRegistryObserver.
[email protected]c8d407e2011-04-28 21:27:171179 profile_->GetExtensionSpecialStoragePolicy()->
1180 RevokeRightsForExtension(extension);
1181
[email protected]b777b332011-04-16 04:01:081182#if defined(OS_CHROMEOS)
[email protected]ac66e452013-01-11 09:21:231183 // Revoke external file access for the extension from its file system context.
1184 // It is safe to access the extension's storage partition at this point. The
1185 // storage partition may get destroyed only after the extension gets unloaded.
[email protected]3a746ec2014-03-15 05:30:561186 GURL site =
1187 extensions::util::GetSiteForExtensionId(extension->id(), profile_);
[email protected]cd501a72014-08-22 19:58:311188 storage::FileSystemContext* filesystem_context =
1189 BrowserContext::GetStoragePartitionForSite(profile_, site)
1190 ->GetFileSystemContext();
[email protected]f19bbf62013-07-09 01:22:321191 if (filesystem_context && filesystem_context->external_backend()) {
1192 filesystem_context->external_backend()->
[email protected]c8d407e2011-04-28 21:27:171193 RevokeAccessForExtension(extension->id());
[email protected]62d30f42009-10-01 22:36:061194 }
[email protected]c8d407e2011-04-28 21:27:171195#endif
1196
[email protected]dcc47642014-03-26 22:03:491197 // TODO(kalman): This is broken. The crash reporter is process-wide so doesn't
1198 // work properly multi-profile. Besides which, it should be using
1199 // ExtensionRegistryObserver::OnExtensionLoaded. See http://crbug.com/355029.
[email protected]c8d407e2011-04-28 21:27:171200 UpdateActiveExtensionsInCrashReporter();
[email protected]62d30f42009-10-01 22:36:061201}
1202
[email protected]599539802014-01-07 23:06:001203content::BrowserContext* ExtensionService::GetBrowserContext() const {
1204 // Implemented in the .cc file to avoid adding a profile.h dependency to
1205 // extension_service.h.
1206 return profile_;
1207}
1208
[email protected]25ae0152011-11-18 14:40:021209bool ExtensionService::is_ready() {
[email protected]4a10006a2013-05-17 23:18:351210 return ready_->is_signaled();
[email protected]25ae0152011-11-18 14:40:021211}
1212
[email protected]7f8f24f2012-11-15 19:40:141213base::SequencedTaskRunner* ExtensionService::GetFileTaskRunner() {
[email protected]dc24976f2013-06-02 21:15:091214 if (file_task_runner_.get())
1215 return file_task_runner_.get();
[email protected]7f8f24f2012-11-15 19:40:141216
1217 // We should be able to interrupt any part of extension install process during
1218 // shutdown. SKIP_ON_SHUTDOWN ensures that not started extension install tasks
1219 // will be ignored/deleted while we will block on started tasks.
1220 std::string token("ext_install-");
1221 token.append(profile_->GetPath().AsUTF8Unsafe());
1222 file_task_runner_ = BrowserThread::GetBlockingPool()->
1223 GetSequencedTaskRunnerWithShutdownBehavior(
1224 BrowserThread::GetBlockingPool()->GetNamedSequenceToken(token),
1225 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN);
[email protected]dc24976f2013-06-02 21:15:091226 return file_task_runner_.get();
[email protected]7f8f24f2012-11-15 19:40:141227}
1228
[email protected]4ee07c62012-08-21 12:40:421229void ExtensionService::CheckManagementPolicy() {
[email protected]0d54b682013-11-05 14:15:361230 std::vector<std::string> to_unload;
1231 std::map<std::string, Extension::DisableReason> to_disable;
binjin8e3d0182014-12-04 16:44:281232 std::vector<std::string> to_enable;
[email protected]695b5712012-12-06 23:55:281233
[email protected]0d54b682013-11-05 14:15:361234 // Loop through the extensions list, finding extensions we need to unload or
1235 // disable.
achuith2f5578b2016-02-26 21:57:131236 for (const auto& extension : registry_->enabled_extensions()) {
binjin8e3d0182014-12-04 16:44:281237 if (!system_->management_policy()->UserMayLoad(extension.get(), nullptr))
[email protected]0d54b682013-11-05 14:15:361238 to_unload.push_back(extension->id());
1239 Extension::DisableReason disable_reason = Extension::DISABLE_NONE;
1240 if (system_->management_policy()->MustRemainDisabled(
binjin8e3d0182014-12-04 16:44:281241 extension.get(), &disable_reason, nullptr))
[email protected]0d54b682013-11-05 14:15:361242 to_disable[extension->id()] = disable_reason;
[email protected]aa96d3a2010-08-21 08:45:251243 }
1244
binjin8e3d0182014-12-04 16:44:281245 extensions::ExtensionManagement* management =
1246 extensions::ExtensionManagementFactory::GetForBrowserContext(profile());
1247
1248 // Loop through the disabled extension list, find extensions to re-enable
1249 // automatically. These extensions are exclusive from the |to_disable| and
1250 // |to_unload| lists constructed above, since disabled_extensions() and
1251 // enabled_extensions() are supposed to be mutually exclusive.
achuith2f5578b2016-02-26 21:57:131252 for (const auto& extension : registry_->disabled_extensions()) {
binjin8e3d0182014-12-04 16:44:281253 // Find all disabled extensions disabled due to minimum version requirement,
1254 // but now satisfying it.
1255 if (management->CheckMinimumVersion(extension.get(), nullptr) &&
1256 extension_prefs_->HasDisableReason(
1257 extension->id(), Extension::DISABLE_UPDATE_REQUIRED_BY_POLICY)) {
1258 // Is DISABLE_UPDATE_REQUIRED_BY_POLICY the *only* reason?
1259 if (extension_prefs_->GetDisableReasons(extension->id()) ==
1260 Extension::DISABLE_UPDATE_REQUIRED_BY_POLICY) {
1261 // We need to enable those disabled *only* due to minimum version
1262 // requirement.
1263 to_enable.push_back(extension->id());
1264 }
1265 extension_prefs_->RemoveDisableReason(
1266 extension->id(), Extension::DISABLE_UPDATE_REQUIRED_BY_POLICY);
1267 }
1268 }
1269
1270 for (const std::string& id : to_unload)
1271 UnloadExtension(id, UnloadedExtensionInfo::REASON_DISABLE);
[email protected]0d54b682013-11-05 14:15:361272
achuith2f5578b2016-02-26 21:57:131273 for (const auto& i : to_disable)
1274 DisableExtension(i.first, i.second);
binjin8e3d0182014-12-04 16:44:281275
1276 // No extension is getting re-enabled here after disabling/unloading
1277 // because to_enable is mutually exclusive to to_disable + to_unload.
1278 for (const std::string& id : to_enable)
1279 EnableExtension(id);
1280
1281 if (updater_.get()) {
1282 // Find all extensions disabled due to minimum version requirement from
1283 // policy (including the ones that got disabled just now), and check
1284 // for update.
1285 extensions::ExtensionUpdater::CheckParams to_recheck;
achuith2f5578b2016-02-26 21:57:131286 for (const auto& extension : registry_->disabled_extensions()) {
binjin8e3d0182014-12-04 16:44:281287 if (extension_prefs_->GetDisableReasons(extension->id()) ==
1288 Extension::DISABLE_UPDATE_REQUIRED_BY_POLICY) {
1289 // The minimum version check is the only thing holding this extension
1290 // back, so check if it can be updated to fix that.
1291 to_recheck.ids.push_back(extension->id());
1292 }
1293 }
1294 if (!to_recheck.ids.empty())
1295 updater_->CheckNow(to_recheck);
1296 }
[email protected]aa96d3a2010-08-21 08:45:251297}
1298
[email protected]31206602011-04-13 23:07:321299void ExtensionService::CheckForUpdatesSoon() {
[email protected]90878c52014-04-04 18:21:021300 // This can legitimately happen in unit tests.
1301 if (!updater_.get())
1302 return;
1303
raphael.kubo.da.costa8527f942016-11-15 17:03:511304 updater_->CheckSoon();
[email protected]c3cfb012011-04-06 22:07:351305}
1306
[email protected]8e4560b62011-01-14 10:09:141307// Some extensions will autoupdate themselves externally from Chrome. These
rkaplowa8fd8d32015-02-25 21:27:561308// are typically part of some larger client application package. To support
1309// these, the extension will register its location in the preferences file
[email protected]8e4560b62011-01-14 10:09:141310// (and also, on Windows, in the registry) and this code will periodically
1311// check that location for a .crx file, which it will then install locally if
1312// a new version is available.
rkaplowa8fd8d32015-02-25 21:27:561313// Errors are reported through ExtensionErrorReporter. Success is not
[email protected]8e4560b62011-01-14 10:09:141314// reported.
[email protected]eaa7dd182010-12-14 11:09:001315void ExtensionService::CheckForExternalUpdates() {
[email protected]a29a517a2011-01-21 21:11:121316 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
rkaplowa8fd8d32015-02-25 21:27:561317 TRACE_EVENT0("browser,startup", "ExtensionService::CheckForExternalUpdates");
1318 SCOPED_UMA_HISTOGRAM_TIMER("Extensions.CheckForExternalUpdatesTime");
[email protected]8e4560b62011-01-14 10:09:141319
1320 // Note that this installation is intentionally silent (since it didn't
1321 // go through the front-end). Extensions that are registered in this
1322 // way are effectively considered 'pre-bundled', and so implicitly
1323 // trusted. In general, if something has HKLM or filesystem access,
1324 // they could install an extension manually themselves anyway.
[email protected]a29a517a2011-01-21 21:11:121325
[email protected]8e4560b62011-01-14 10:09:141326 // Ask each external extension provider to give us a call back for each
1327 // extension they know about. See OnExternalExtension(File|UpdateUrl)Found.
achuith2f5578b2016-02-26 21:57:131328 for (const auto& provider : external_extension_providers_)
[email protected]8e4560b62011-01-14 10:09:141329 provider->VisitRegisteredExtension();
[email protected]8e4560b62011-01-14 10:09:141330
[email protected]50067e52011-10-20 23:17:071331 // Do any required work that we would have done after completion of all
1332 // providers.
[email protected]373daf972014-04-10 01:50:441333 if (external_extension_providers_.empty())
[email protected]50067e52011-10-20 23:17:071334 OnAllExternalProvidersReady();
[email protected]9f1087e2009-06-15 17:29:321335}
1336
[email protected]50067e52011-10-20 23:17:071337void ExtensionService::OnExternalProviderReady(
lazyboye8634172016-01-28 00:10:481338 const ExternalProviderInterface* provider) {
[email protected]a29a517a2011-01-21 21:11:121339 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]50067e52011-10-20 23:17:071340 CHECK(provider->IsReady());
[email protected]a29a517a2011-01-21 21:11:121341
1342 // An external provider has finished loading. We only take action
[email protected]8e4560b62011-01-14 10:09:141343 // if all of them are finished. So we check them first.
[email protected]94fde232012-04-27 10:22:301344 if (AreAllExternalProvidersReady())
1345 OnAllExternalProvidersReady();
1346}
1347
1348bool ExtensionService::AreAllExternalProvidersReady() const {
achuith2f5578b2016-02-26 21:57:131349 for (const auto& provider : external_extension_providers_) {
1350 if (!provider->IsReady())
[email protected]94fde232012-04-27 10:22:301351 return false;
[email protected]8e4560b62011-01-14 10:09:141352 }
[email protected]94fde232012-04-27 10:22:301353 return true;
[email protected]50067e52011-10-20 23:17:071354}
1355
1356void ExtensionService::OnAllExternalProvidersReady() {
1357 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]94fde232012-04-27 10:22:301358 base::TimeDelta elapsed = base::Time::Now() - profile_->GetStartTime();
1359 UMA_HISTOGRAM_TIMES("Extension.ExternalProvidersReadyAfter", elapsed);
[email protected]50067e52011-10-20 23:17:071360
1361 // Install any pending extensions.
[email protected]94fde232012-04-27 10:22:301362 if (update_once_all_providers_are_ready_ && updater()) {
1363 update_once_all_providers_are_ready_ = false;
[email protected]4e9b59d2013-12-18 06:47:141364 extensions::ExtensionUpdater::CheckParams params;
1365 params.callback = external_updates_finished_callback_;
1366 updater()->CheckNow(params);
[email protected]8e4560b62011-01-14 10:09:141367 }
1368
1369 // Uninstall all the unclaimed extensions.
dchengc963c7142016-04-08 03:55:221370 std::unique_ptr<extensions::ExtensionPrefs::ExtensionsInfo> extensions_info(
[email protected]8e4560b62011-01-14 10:09:141371 extension_prefs_->GetInstalledExtensionsInfo());
1372 for (size_t i = 0; i < extensions_info->size(); ++i) {
1373 ExtensionInfo* info = extensions_info->at(i).get();
[email protected]1d5e58b2013-01-31 08:41:401374 if (Manifest::IsExternalLocation(info->extension_location))
[email protected]8e4560b62011-01-14 10:09:141375 CheckExternalUninstall(info->extension_id);
1376 }
[email protected]e5af875f2011-10-10 21:09:141377
[email protected]373daf972014-04-10 01:50:441378 error_controller_->ShowErrorIfNeeded();
[email protected]a9aa5932012-01-25 08:27:401379
[email protected]374ceb6f2014-07-02 19:25:341380 external_install_manager_->UpdateExternalExtensionAlert();
[email protected]e5af875f2011-10-10 21:09:141381}
1382
[email protected]a9f39a312010-12-23 22:14:271383void ExtensionService::UnloadExtension(
1384 const std::string& extension_id,
[email protected]b0af4792013-10-23 09:12:131385 UnloadedExtensionInfo::Reason reason) {
[email protected]27e469a2010-01-11 20:35:091386 // Make sure the extension gets deleted after we return from this function.
[email protected]599539802014-01-07 23:06:001387 int include_mask =
1388 ExtensionRegistry::EVERYTHING & ~ExtensionRegistry::TERMINATED;
[email protected]9adb9692010-10-29 23:14:021389 scoped_refptr<const Extension> extension(
[email protected]599539802014-01-07 23:06:001390 registry_->GetExtensionById(extension_id, include_mask));
[email protected]631cf822009-05-15 07:01:251391
[email protected]fa0c96732010-11-17 00:14:231392 // This method can be called via PostTask, so the extension may have been
1393 // unloaded by the time this runs.
[email protected]dc24976f2013-06-02 21:15:091394 if (!extension.get()) {
[email protected]dd163fb02011-05-04 22:22:171395 // In case the extension may have crashed/uninstalled. Allow the profile to
1396 // clean up its RequestContexts.
[email protected]31d8f5f22012-04-02 15:22:081397 system_->UnregisterExtensionWithRequestContexts(extension_id, reason);
[email protected]fa0c96732010-11-17 00:14:231398 return;
[email protected]dd163fb02011-05-04 22:22:171399 }
[email protected]0c6da502009-08-14 22:32:391400
[email protected]1eb175082010-02-10 09:26:161401 // Keep information about the extension so that we can reload it later
1402 // even if it's not permanently installed.
1403 unloaded_extension_paths_[extension->id()] = extension->path();
1404
[email protected]f17dbd42010-08-16 23:21:101405 // Clean up if the extension is meant to be enabled after a reload.
[email protected]b914e2952013-04-26 07:10:031406 reloading_extensions_.erase(extension->id());
[email protected]f17dbd42010-08-16 23:21:101407
[email protected]bb1bc9b32013-12-21 03:09:141408 if (registry_->disabled_extensions().Contains(extension->id())) {
1409 registry_->RemoveDisabled(extension->id());
[email protected]dd163fb02011-05-04 22:22:171410 // Make sure the profile cleans up its RequestContexts when an already
1411 // disabled extension is unloaded (since they are also tracking the disabled
1412 // extensions).
[email protected]31d8f5f22012-04-02 15:22:081413 system_->UnregisterExtensionWithRequestContexts(extension_id, reason);
[email protected]45f5b7d2014-01-22 23:47:131414 // Don't send the unloaded notification. It was sent when the extension
1415 // was disabled.
[email protected]60a174a2013-08-02 20:29:281416 } else {
[email protected]bb1bc9b32013-12-21 03:09:141417 // Remove the extension from the enabled list.
1418 registry_->RemoveEnabled(extension->id());
[email protected]60a174a2013-08-02 20:29:281419 NotifyExtensionUnloaded(extension.get(), reason);
[email protected]0c6da502009-08-14 22:32:391420 }
1421
[email protected]fb789532013-08-27 02:40:211422 content::NotificationService::current()->Notify(
[email protected]adf5a102014-07-31 12:44:061423 extensions::NOTIFICATION_EXTENSION_REMOVED,
[email protected]fb789532013-08-27 02:40:211424 content::Source<Profile>(profile_),
1425 content::Details<const Extension>(extension.get()));
[email protected]631cf822009-05-15 07:01:251426}
1427
[email protected]8b1ec202013-09-05 02:09:501428void ExtensionService::RemoveComponentExtension(
1429 const std::string& extension_id) {
1430 scoped_refptr<const Extension> extension(
1431 GetExtensionById(extension_id, false));
[email protected]b0af4792013-10-23 09:12:131432 UnloadExtension(extension_id, UnloadedExtensionInfo::REASON_UNINSTALL);
[email protected]ebe07772014-05-22 04:16:061433 if (extension.get()) {
[email protected]e43c61f2014-07-20 21:46:341434 ExtensionRegistry::Get(profile_)->TriggerOnUninstalled(
dtseng9fb3d5b2015-02-23 17:24:171435 extension.get(), extensions::UNINSTALL_REASON_COMPONENT_REMOVED);
[email protected]ebe07772014-05-22 04:16:061436 }
[email protected]8b1ec202013-09-05 02:09:501437}
1438
[email protected]bb1bc9b32013-12-21 03:09:141439void ExtensionService::UnloadAllExtensionsForTest() {
1440 UnloadAllExtensionsInternal();
[email protected]9f1087e2009-06-15 17:29:321441}
1442
[email protected]bb1bc9b32013-12-21 03:09:141443void ExtensionService::ReloadExtensionsForTest() {
1444 // Calling UnloadAllExtensionsForTest here triggers a false-positive presubmit
1445 // warning about calling test code in production.
1446 UnloadAllExtensionsInternal();
[email protected]eac88332012-12-26 17:57:451447 component_loader_->LoadAll();
[email protected]d8c8f25f2011-11-02 18:18:011448 extensions::InstalledLoader(this).LoadAllExtensions();
[email protected]4a10006a2013-05-17 23:18:351449 // Don't call SetReadyAndNotifyListeners() since tests call this multiple
1450 // times.
[email protected]9f1087e2009-06-15 17:29:321451}
1452
[email protected]820d9bd2013-04-03 03:46:031453void ExtensionService::SetReadyAndNotifyListeners() {
rkaplowa8fd8d32015-02-25 21:27:561454 TRACE_EVENT0("browser,startup",
1455 "ExtensionService::SetReadyAndNotifyListeners");
1456 SCOPED_UMA_HISTOGRAM_TIMER(
1457 "Extensions.ExtensionServiceNotifyReadyListenersTime");
1458
[email protected]4a10006a2013-05-17 23:18:351459 ready_->Signal();
[email protected]820d9bd2013-04-03 03:46:031460 content::NotificationService::current()->Notify(
[email protected]adf5a102014-07-31 12:44:061461 extensions::NOTIFICATION_EXTENSIONS_READY_DEPRECATED,
[email protected]820d9bd2013-04-03 03:46:031462 content::Source<Profile>(profile_),
1463 content::NotificationService::NoDetails());
1464}
1465
[email protected]eaa7dd182010-12-14 11:09:001466void ExtensionService::OnLoadedInstalledExtensions() {
[email protected]3eeddd892013-04-17 17:00:111467 if (updater_)
[email protected]93fd78f42009-07-10 16:43:171468 updater_->Start();
[email protected]fa6a9102010-11-22 15:38:501469
elijahtaylor49c09c5c2016-07-09 01:06:221470 // Enable any Shared Modules that incorrectly got disabled previously.
1471 // This is temporary code to fix incorrect behavior from previous versions of
1472 // Chrome and can be removed after several releases (perhaps M60).
1473 extensions::ExtensionList to_enable;
1474 for (const auto& extension : registry_->disabled_extensions()) {
1475 if (SharedModuleInfo::IsSharedModule(extension.get()))
1476 to_enable.push_back(extension);
1477 }
1478 for (const auto& extension : to_enable) {
1479 EnableExtension(extension->id());
1480 }
1481
[email protected]bc151cf92013-02-12 04:57:261482 OnBlacklistUpdated();
[email protected]e72e8eb82009-06-18 17:21:511483}
1484
[email protected]fcb58a862012-05-01 01:03:151485void ExtensionService::AddExtension(const Extension* extension) {
rdevlin.cronin08ada0f2017-03-09 23:29:521486 if (!Manifest::IsValidLocation(extension->location())) {
1487 // TODO(devlin): We should *never* add an extension with an invalid
1488 // location, but some bugs (e.g. crbug.com/692069) seem to indicate we do.
1489 // Track down the cases when this can happen, and remove this
1490 // DumpWithoutCrashing() (possibly replacing it with a CHECK).
1491 NOTREACHED();
1492 char extension_id_copy[33];
1493 base::strlcpy(extension_id_copy, extension->id().c_str(),
1494 arraysize(extension_id_copy));
1495 Manifest::Location location = extension->location();
1496 int creation_flags = extension->creation_flags();
1497 Manifest::Type type = extension->manifest()->type();
1498 base::debug::Alias(extension_id_copy);
1499 base::debug::Alias(&location);
1500 base::debug::Alias(&creation_flags);
1501 base::debug::Alias(&type);
1502 base::debug::DumpWithoutCrashing();
1503 return;
1504 }
1505
[email protected]c8d407e2011-04-28 21:27:171506 // TODO(jstritar): We may be able to get rid of this branch by overriding the
1507 // default extension state to DISABLED when the --disable-extensions flag
1508 // is set (http://crbug.com/29067).
catmullings98cd1942016-08-30 22:31:591509 if (!extensions_enabled() && !extension->is_theme() &&
[email protected]1d5e58b2013-01-31 08:41:401510 extension->location() != Manifest::COMPONENT &&
catmullings98cd1942016-08-30 22:31:591511 !Manifest::IsExternalLocation(extension->location()) &&
1512 disable_flag_exempted_extensions_.count(extension->id()) == 0) {
[email protected]fcb58a862012-05-01 01:03:151513 return;
[email protected]330840c2012-08-29 22:21:011514 }
[email protected]c8d407e2011-04-28 21:27:171515
[email protected]b914e2952013-04-26 07:10:031516 bool is_extension_upgrade = false;
treib6e51bca2016-06-15 10:26:031517 bool is_extension_loaded = false;
[email protected]116d40e2013-08-08 17:23:171518 const Extension* old = GetInstalledExtension(extension->id());
1519 if (old) {
treib6e51bca2016-06-15 10:26:031520 is_extension_loaded = true;
[email protected]116d40e2013-08-08 17:23:171521 int version_compare_result =
1522 extension->version()->CompareTo(*(old->version()));
1523 is_extension_upgrade = version_compare_result > 0;
[email protected]b914e2952013-04-26 07:10:031524 // Other than for unpacked extensions, CrxInstaller should have guaranteed
1525 // that we aren't downgrading.
1526 if (!Manifest::IsUnpackedLocation(extension->location()))
[email protected]116d40e2013-08-08 17:23:171527 CHECK_GE(version_compare_result, 0);
[email protected]b914e2952013-04-26 07:10:031528 }
rdevlin.cronin2c16c602014-11-21 01:35:491529 // If the extension was disabled for a reload, then enable it.
1530 bool reloading = reloading_extensions_.erase(extension->id()) > 0;
1531
1532 // Set the upgraded bit; we consider reloads upgrades.
1533 system_->runtime_data()->SetBeingUpgraded(extension->id(),
1534 is_extension_upgrade || reloading);
[email protected]c8d407e2011-04-28 21:27:171535
[email protected]1eb175082010-02-10 09:26:161536 // The extension is now loaded, remove its data from unloaded extension map.
1537 unloaded_extension_paths_.erase(extension->id());
1538
[email protected]bb7f40952011-01-13 00:21:201539 // If a terminated extension is loaded, remove it from the terminated list.
1540 UntrackTerminatedExtension(extension->id());
1541
[email protected]b914e2952013-04-26 07:10:031542 // Check if the extension's privileges have changed and mark the
1543 // extension disabled if necessary.
treib6e51bca2016-06-15 10:26:031544 CheckPermissionsIncrease(extension, is_extension_loaded);
[email protected]b914e2952013-04-26 07:10:031545
treib6e51bca2016-06-15 10:26:031546 if (is_extension_loaded && !reloading) {
[email protected]ca2e82022013-04-29 16:48:411547 // To upgrade an extension in place, unload the old one and then load the
1548 // new one. ReloadExtension disables the extension, which is sufficient.
[email protected]b0af4792013-10-23 09:12:131549 UnloadExtension(extension->id(), UnloadedExtensionInfo::REASON_UPDATE);
[email protected]b914e2952013-04-26 07:10:031550 }
[email protected]0c6da502009-08-14 22:32:391551
[email protected]695b5712012-12-06 23:55:281552 if (extension_prefs_->IsExtensionBlacklisted(extension->id())) {
[email protected]ac875372013-02-28 04:36:091553 // Only prefs is checked for the blacklist. We rely on callers to check the
1554 // blacklist before calling into here, e.g. CrxInstaller checks before
[email protected]9f3c8532013-07-31 19:52:071555 // installation then threads through the install and pending install flow
1556 // of this class, and we check when loading installed extensions.
[email protected]bb1bc9b32013-12-21 03:09:141557 registry_->AddBlacklisted(extension);
mlerman6a37b6a42014-11-26 22:10:531558 } else if (block_extensions_ && CanBlockExtension(extension)) {
1559 registry_->AddBlocked(extension);
[email protected]ca2e82022013-04-29 16:48:411560 } else if (!reloading &&
1561 extension_prefs_->IsExtensionDisabled(extension->id())) {
[email protected]bb1bc9b32013-12-21 03:09:141562 registry_->AddDisabled(extension);
[email protected]44d62b62012-04-11 00:06:031563 content::NotificationService::current()->Notify(
[email protected]adf5a102014-07-31 12:44:061564 extensions::NOTIFICATION_EXTENSION_UPDATE_DISABLED,
[email protected]44d62b62012-04-11 00:06:031565 content::Source<Profile>(profile_),
1566 content::Details<const Extension>(extension));
[email protected]62f051c2012-03-29 17:04:441567
[email protected]21db9ef2014-05-16 02:06:271568 // Show the extension disabled error if a permissions increase or a remote
1569 // installation is the reason it was disabled, and no other reasons exist.
1570 int reasons = extension_prefs_->GetDisableReasons(extension->id());
1571 const int kReasonMask = Extension::DISABLE_PERMISSIONS_INCREASE |
1572 Extension::DISABLE_REMOTE_INSTALL;
1573 if (reasons & kReasonMask && !(reasons & ~kReasonMask)) {
1574 extensions::AddExtensionDisabledError(
1575 this,
1576 extension,
1577 extension_prefs_->HasDisableReason(
1578 extension->id(), Extension::DISABLE_REMOTE_INSTALL));
[email protected]62f051c2012-03-29 17:04:441579 }
[email protected]ca2e82022013-04-29 16:48:411580 } else if (reloading) {
1581 // Replace the old extension with the new version.
[email protected]bb1bc9b32013-12-21 03:09:141582 CHECK(!registry_->AddDisabled(extension));
[email protected]ca2e82022013-04-29 16:48:411583 EnableExtension(extension->id());
[email protected]695b5712012-12-06 23:55:281584 } else {
1585 // All apps that are displayed in the launcher are ordered by their ordinals
1586 // so we must ensure they have valid ordinals.
1587 if (extension->RequiresSortOrdinal()) {
deepak.m14ba69e62015-11-17 05:42:121588 AppSorting* app_sorting =
1589 extensions::ExtensionSystem::Get(GetBrowserContext())->app_sorting();
1590 app_sorting->SetExtensionVisible(
[email protected]db378322014-07-21 23:19:341591 extension->id(),
benwells1dd4acd2015-12-09 02:20:241592 extension->ShouldDisplayInNewTabPage());
1593 app_sorting->EnsureValidOrdinals(extension->id(),
1594 syncer::StringOrdinal());
[email protected]695b5712012-12-06 23:55:281595 }
1596
[email protected]bb1bc9b32013-12-21 03:09:141597 registry_->AddEnabled(extension);
[email protected]695b5712012-12-06 23:55:281598 NotifyExtensionLoaded(extension);
[email protected]f574c402012-12-04 23:20:311599 }
rdevlin.cronin2c16c602014-11-21 01:35:491600 system_->runtime_data()->SetBeingUpgraded(extension->id(), false);
[email protected]aab98a52009-12-02 03:22:351601}
1602
[email protected]8c484b742012-11-29 06:05:361603void ExtensionService::AddComponentExtension(const Extension* extension) {
1604 const std::string old_version_string(
1605 extension_prefs_->GetVersionString(extension->id()));
pwnallcbd73192016-08-22 18:59:171606 const base::Version old_version(old_version_string);
[email protected]8c484b742012-11-29 06:05:361607
[email protected]0181a7d2013-11-12 01:08:421608 VLOG(1) << "AddComponentExtension " << extension->name();
robpercivaldcd8b102016-01-25 19:39:001609 if (!old_version.IsValid() || old_version != *extension->version()) {
[email protected]8c484b742012-11-29 06:05:361610 VLOG(1) << "Component extension " << extension->name() << " ("
1611 << extension->id() << ") installing/upgrading from '"
1612 << old_version_string << "' to " << extension->version()->GetString();
1613
1614 AddNewOrUpdatedExtension(extension,
[email protected]9ae73962014-08-14 16:53:411615 Extension::ENABLED,
[email protected]4a1d9c0d2014-06-13 12:50:111616 extensions::kInstallFlagNone,
[email protected]d8fd0fd2014-03-24 13:16:061617 syncer::StringOrdinal(),
1618 std::string());
[email protected]8c484b742012-11-29 06:05:361619 return;
1620 }
1621
1622 AddExtension(extension);
1623}
1624
[email protected]b914e2952013-04-26 07:10:031625void ExtensionService::CheckPermissionsIncrease(const Extension* extension,
treib6e51bca2016-06-15 10:26:031626 bool is_extension_loaded) {
[email protected]23a85362014-07-07 23:26:191627 extensions::PermissionsUpdater(profile_).InitializePermissions(extension);
[email protected]902fd7b2011-07-27 18:42:311628
[email protected]8d888c12010-11-30 00:00:251629 // We keep track of all permissions the user has granted each extension.
1630 // This allows extensions to gracefully support backwards compatibility
1631 // by including unknown permissions in their manifests. When the user
1632 // installs the extension, only the recognized permissions are recorded.
1633 // When the unknown permissions become recognized (e.g., through browser
1634 // upgrade), we can prompt the user to accept these new permissions.
1635 // Extensions can also silently upgrade to less permissions, and then
1636 // silently upgrade to a version that adds these permissions back.
1637 //
1638 // For example, pretend that Chrome 10 includes a permission "omnibox"
1639 // for an API that adds suggestions to the omnibox. An extension can
1640 // maintain backwards compatibility while still having "omnibox" in the
1641 // manifest. If a user installs the extension on Chrome 9, the browser
1642 // will record the permissions it recognized, not including "omnibox."
1643 // When upgrading to Chrome 10, "omnibox" will be recognized and Chrome
1644 // will disable the extension and prompt the user to approve the increase
1645 // in privileges. The extension could then release a new version that
1646 // removes the "omnibox" permission. When the user upgrades, Chrome will
1647 // still remember that "omnibox" had been granted, so that if the
1648 // extension once again includes "omnibox" in an upgrade, the extension
1649 // can upgrade without requiring this user's approval.
[email protected]eb5e4f92012-08-15 23:33:281650 int disable_reasons = extension_prefs_->GetDisableReasons(extension->id());
[email protected]8d888c12010-11-30 00:00:251651
rockot1d4a06262015-02-17 19:39:281652 // Silently grant all active permissions to default apps and apps installed
1653 // in kiosk mode.
[email protected]211a3f32013-05-28 21:48:181654 bool auto_grant_permission =
rockot1d4a06262015-02-17 19:39:281655 extension->was_installed_by_default() ||
[email protected]45928b682013-11-28 08:20:271656 extensions::ExtensionsBrowserClient::Get()->IsRunningInForcedAppMode();
[email protected]211a3f32013-05-28 21:48:181657 if (auto_grant_permission)
[email protected]b914e2952013-04-26 07:10:031658 GrantPermissions(extension);
1659
1660 bool is_privilege_increase = false;
1661 // We only need to compare the granted permissions to the current permissions
rockot1d4a06262015-02-17 19:39:281662 // if the extension has not been auto-granted its permissions above and is
1663 // installed internally.
1664 if (extension->location() == Manifest::INTERNAL && !auto_grant_permission) {
[email protected]8d888c12010-11-30 00:00:251665 // Add all the recognized permissions if the granted permissions list
1666 // hasn't been initialized yet.
dchengc963c7142016-04-08 03:55:221667 std::unique_ptr<const PermissionSet> granted_permissions =
[email protected]902fd7b2011-07-27 18:42:311668 extension_prefs_->GetGrantedPermissions(extension->id());
[email protected]0d3e4a22011-06-23 19:02:521669 CHECK(granted_permissions.get());
[email protected]8d888c12010-11-30 00:00:251670
1671 // Here, we check if an extension's privileges have increased in a manner
1672 // that requires the user's approval. This could occur because the browser
1673 // upgraded and recognized additional privileges, or an extension upgrades
1674 // to a version that requires additional privileges.
[email protected]c41003472013-10-19 15:37:251675 is_privilege_increase =
1676 extensions::PermissionMessageProvider::Get()->IsPrivilegeIncrease(
rdevlin.cronind630c302015-09-30 20:19:331677 *granted_permissions,
rdevlin.cronine2d0fd02015-09-24 22:35:491678 extension->permissions_data()->active_permissions(),
[email protected]076ebeda2014-06-06 21:47:261679 extension->GetType());
treib2c20f9442016-05-18 19:50:281680
1681 // If there was no privilege increase, the extension might still have new
1682 // permissions (which either don't generate a warning message, or whose
1683 // warning messages are suppressed by existing permissions). Grant the new
1684 // permissions.
1685 if (!is_privilege_increase)
1686 GrantPermissions(extension);
[email protected]8d888c12010-11-30 00:00:251687 }
1688
treib6e51bca2016-06-15 10:26:031689 bool previously_disabled =
1690 extension_prefs_->IsExtensionDisabled(extension->id());
1691 // TODO(treib): Is the |is_extension_loaded| check needed here?
1692 if (is_extension_loaded && previously_disabled) {
treib8a6d9892015-08-26 10:23:191693 // Legacy disabled extensions do not have a disable reason. Infer that it
1694 // was likely disabled by the user.
treib6e51bca2016-06-15 10:26:031695 if (disable_reasons == Extension::DISABLE_NONE)
[email protected]7e9e2422012-12-13 19:54:191696 disable_reasons |= Extension::DISABLE_USER_ACTION;
treib8a6d9892015-08-26 10:23:191697
[email protected]7e9e2422012-12-13 19:54:191698 // Extensions that came to us disabled from sync need a similar inference,
1699 // except based on the new version's permissions.
treib3b91e9f2015-11-04 11:29:411700 // TODO(treib,devlin): Since M48, DISABLE_UNKNOWN_FROM_SYNC isn't used
1701 // anymore; this code is still here to migrate any existing old state.
1702 // Remove it after some grace period.
treib6e51bca2016-06-15 10:26:031703 if (disable_reasons & Extension::DEPRECATED_DISABLE_UNKNOWN_FROM_SYNC) {
[email protected]7e9e2422012-12-13 19:54:191704 // Remove the DISABLE_UNKNOWN_FROM_SYNC reason.
treib3b91e9f2015-11-04 11:29:411705 disable_reasons &= ~Extension::DEPRECATED_DISABLE_UNKNOWN_FROM_SYNC;
treib8a6d9892015-08-26 10:23:191706 extension_prefs_->RemoveDisableReason(
treib3b91e9f2015-11-04 11:29:411707 extension->id(), Extension::DEPRECATED_DISABLE_UNKNOWN_FROM_SYNC);
treib8a6d9892015-08-26 10:23:191708 // If there was no privilege increase, it was likely disabled by the user.
[email protected]7e9e2422012-12-13 19:54:191709 if (!is_privilege_increase)
1710 disable_reasons |= Extension::DISABLE_USER_ACTION;
1711 }
[email protected]8d888c12010-11-30 00:00:251712 }
1713
treib6e51bca2016-06-15 10:26:031714 // If the extension is disabled due to a permissions increase, but does in
1715 // fact have all permissions, remove that disable reason.
1716 // TODO(devlin): This was added to fix crbug.com/616474, but it's unclear
1717 // if this behavior should stay forever.
1718 if (disable_reasons & Extension::DISABLE_PERMISSIONS_INCREASE) {
1719 bool reset_permissions_increase = false;
1720 if (!is_privilege_increase) {
1721 reset_permissions_increase = true;
1722 disable_reasons &= ~Extension::DISABLE_PERMISSIONS_INCREASE;
1723 extension_prefs_->RemoveDisableReason(
1724 extension->id(), Extension::DISABLE_PERMISSIONS_INCREASE);
1725 }
1726 UMA_HISTOGRAM_BOOLEAN("Extensions.ResetPermissionsIncrease",
1727 reset_permissions_increase);
1728 }
1729
[email protected]8d888c12010-11-30 00:00:251730 // Extension has changed permissions significantly. Disable it. A
[email protected]21db9ef2014-05-16 02:06:271731 // notification should be sent by the caller. If the extension is already
1732 // disabled because it was installed remotely, don't add another disable
treibaac30ec2015-06-10 09:18:091733 // reason.
1734 if (is_privilege_increase &&
treib8a6d9892015-08-26 10:23:191735 !(disable_reasons & Extension::DISABLE_REMOTE_INSTALL)) {
[email protected]7e9e2422012-12-13 19:54:191736 disable_reasons |= Extension::DISABLE_PERMISSIONS_INCREASE;
treib8a6d9892015-08-26 10:23:191737 if (!extension_prefs_->DidExtensionEscalatePermissions(extension->id()))
treib2e0517f92015-05-07 23:15:361738 RecordPermissionMessagesHistogram(extension, "AutoDisable");
treib8ecc1eb52015-03-04 18:29:061739
brettw9e85ef42016-11-01 21:01:241740#if BUILDFLAG(ENABLE_SUPERVISED_USERS)
treib8ecc1eb52015-03-04 18:29:061741 // If a custodian-installed extension is disabled for a supervised user due
mamir51e05d02016-10-06 10:55:011742 // to a permissions increase, send a request to the custodian.
treib3202d592015-07-31 08:33:161743 if (extensions::util::IsExtensionSupervised(extension, profile_) &&
treib40d3ad92015-10-20 18:15:421744 !ExtensionSyncService::Get(profile_)->HasPendingReenable(
1745 extension->id(), *extension->version())) {
treib8ecc1eb52015-03-04 18:29:061746 SupervisedUserService* supervised_user_service =
1747 SupervisedUserServiceFactory::GetForProfile(profile_);
treib40d3ad92015-10-20 18:15:421748 supervised_user_service->AddExtensionUpdateRequest(extension->id(),
1749 *extension->version());
treib8ecc1eb52015-03-04 18:29:061750 }
1751#endif
[email protected]b914e2952013-04-26 07:10:031752 }
treib6e51bca2016-06-15 10:26:031753
1754 if (disable_reasons == Extension::DISABLE_NONE)
1755 extension_prefs_->SetExtensionEnabled(extension->id());
1756 else
treib8a6d9892015-08-26 10:23:191757 extension_prefs_->SetExtensionDisabled(extension->id(), disable_reasons);
[email protected]8d888c12010-11-30 00:00:251758}
1759
[email protected]eaa7dd182010-12-14 11:09:001760void ExtensionService::UpdateActiveExtensionsInCrashReporter() {
[email protected]c8865962009-12-16 07:47:391761 std::set<std::string> extension_ids;
achuith2f5578b2016-02-26 21:57:131762 for (const auto& extension : registry_->enabled_extensions()) {
[email protected]1d5e58b2013-01-31 08:41:401763 if (!extension->is_theme() && extension->location() != Manifest::COMPONENT)
[email protected]84df8332011-12-06 18:22:461764 extension_ids.insert(extension->id());
[email protected]aab98a52009-12-02 03:22:351765 }
1766
[email protected]dcc47642014-03-26 22:03:491767 // TODO(kalman): This is broken. ExtensionService is per-profile.
1768 // crash_keys::SetActiveExtensions is per-process. See
1769 // http://crbug.com/355029.
[email protected]f6431be82013-09-07 02:53:451770 crash_keys::SetActiveExtensions(extension_ids);
[email protected]6014d672008-12-05 00:38:251771}
1772
[email protected]8266d662011-07-12 21:53:261773void ExtensionService::OnExtensionInstalled(
[email protected]36a5c4c2011-12-14 16:34:501774 const Extension* extension,
[email protected]98270432012-09-11 20:51:241775 const syncer::StringOrdinal& page_ordinal,
[email protected]4a1d9c0d2014-06-13 12:50:111776 int install_flags) {
[email protected]a29a517a2011-01-21 21:11:121777 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]a8af9fdb2010-10-28 21:52:201778
[email protected]c3cfb012011-04-06 22:07:351779 const std::string& id = extension->id();
binjin47947f842014-11-18 12:10:241780 int disable_reasons = GetDisableReasonsOnInstalled(extension);
[email protected]d8fd0fd2014-03-24 13:16:061781 std::string install_parameter;
[email protected]96aebe22014-07-16 04:07:511782 const extensions::PendingExtensionInfo* pending_extension_info =
1783 pending_extension_manager()->GetById(id);
1784 if (pending_extension_info) {
[email protected]8f3bcbd2013-06-05 08:42:401785 if (!pending_extension_info->ShouldAllowInstall(extension)) {
treib227b2582015-12-09 09:28:261786 // Hack for crbug.com/558299, see comment on DeleteThemeDoNotUse.
1787 if (extension->is_theme() && pending_extension_info->is_from_sync())
1788 ExtensionSyncService::Get(profile_)->DeleteThemeDoNotUse(*extension);
1789
[email protected]51a3bf8b2012-06-08 22:53:061790 pending_extension_manager()->Remove(id);
[email protected]8ef78fd2010-08-19 17:14:321791
[email protected]31bb5ee62012-09-12 22:58:401792 LOG(WARNING) << "ShouldAllowInstall() returned false for "
1793 << id << " of type " << extension->GetType()
[email protected]65348062013-01-15 07:27:221794 << " and update URL "
1795 << extensions::ManifestURL::GetUpdateURL(extension).spec()
[email protected]31bb5ee62012-09-12 22:58:401796 << "; not installing";
[email protected]ae6cb3022011-04-04 20:11:541797
[email protected]4416c5a2010-06-26 01:28:571798 // Delete the extension directory since we're not going to
1799 // load it.
[email protected]7f8f24f2012-11-15 19:40:141800 if (!GetFileTaskRunner()->PostTask(
1801 FROM_HERE,
[email protected]85df9d12014-04-15 17:02:141802 base::Bind(&extensions::file_util::DeleteFile,
1803 extension->path(),
1804 true))) {
[email protected]14908b72011-04-20 06:54:361805 NOTREACHED();
[email protected]31bb5ee62012-09-12 22:58:401806 }
[email protected]4416c5a2010-06-26 01:28:571807 return;
1808 }
[email protected]51a3bf8b2012-06-08 22:53:061809
[email protected]d8fd0fd2014-03-24 13:16:061810 install_parameter = pending_extension_info->install_parameter();
[email protected]51a3bf8b2012-06-08 22:53:061811 pending_extension_manager()->Remove(id);
[email protected]4416c5a2010-06-26 01:28:571812 } else {
[email protected]c3cfb012011-04-06 22:07:351813 // We explicitly want to re-enable an uninstalled external
1814 // extension; if we're here, that means the user is manually
1815 // installing the extension.
[email protected]46f3e102014-03-25 01:22:451816 if (extension_prefs_->IsExternalExtensionUninstalled(id)) {
binjin47947f842014-11-18 12:10:241817 disable_reasons = Extension::DISABLE_NONE;
[email protected]6cc7dbae2011-04-29 21:18:331818 }
[email protected]aa142702010-03-26 01:26:331819 }
1820
asargente4de9f92016-09-15 01:40:061821 // If the old version of the extension was disabled due to corruption, this
1822 // new install may correct the problem.
1823 disable_reasons &= ~Extension::DISABLE_CORRUPTED;
1824
[email protected]98270432012-09-11 20:51:241825 // Unsupported requirements overrides the management policy.
[email protected]4a1d9c0d2014-06-13 12:50:111826 if (install_flags & extensions::kInstallFlagHasRequirementErrors) {
binjin47947f842014-11-18 12:10:241827 disable_reasons |= Extension::DISABLE_UNSUPPORTED_REQUIREMENT;
binjin8e3d0182014-12-04 16:44:281828 } else {
1829 // Requirement is supported now, remove the corresponding disable reason
1830 // instead.
binjin8e3d0182014-12-04 16:44:281831 disable_reasons &= ~Extension::DISABLE_UNSUPPORTED_REQUIREMENT;
1832 }
1833
1834 // Check if the extension was disabled because of the minimum version
1835 // requirements from enterprise policy, and satisfies it now.
1836 if (extensions::ExtensionManagementFactory::GetForBrowserContext(profile())
1837 ->CheckMinimumVersion(extension, nullptr)) {
1838 // And remove the corresponding disable reason.
binjin8e3d0182014-12-04 16:44:281839 disable_reasons &= ~Extension::DISABLE_UPDATE_REQUIRED_BY_POLICY;
[email protected]98270432012-09-11 20:51:241840 }
1841
[email protected]4a1d9c0d2014-06-13 12:50:111842 if (install_flags & extensions::kInstallFlagIsBlacklistedForMalware) {
[email protected]9f3c8532013-07-31 19:52:071843 // Installation of a blacklisted extension can happen from sync, policy,
1844 // etc, where to maintain consistency we need to install it, just never
1845 // load it (see AddExtension). Usually it should be the job of callers to
treibaac30ec2015-06-10 09:18:091846 // intercept blacklisted extensions earlier (e.g. CrxInstaller, before even
[email protected]9f3c8532013-07-31 19:52:071847 // showing the install dialogue).
[email protected]7c82539c2014-02-19 06:09:171848 extension_prefs_->AcknowledgeBlacklistedExtension(id);
[email protected]9f3c8532013-07-31 19:52:071849 UMA_HISTOGRAM_ENUMERATION("ExtensionBlacklist.SilentInstall",
1850 extension->location(),
1851 Manifest::NUM_LOCATIONS);
1852 }
1853
[email protected]695b5712012-12-06 23:55:281854 if (!GetInstalledExtension(extension->id())) {
[email protected]07533022011-06-27 20:42:551855 UMA_HISTOGRAM_ENUMERATION("Extensions.InstallType",
1856 extension->GetType(), 100);
[email protected]69084dc2012-11-17 07:39:301857 UMA_HISTOGRAM_ENUMERATION("Extensions.InstallSource",
[email protected]1d5e58b2013-01-31 08:41:401858 extension->location(), Manifest::NUM_LOCATIONS);
treib2e0517f92015-05-07 23:15:361859 RecordPermissionMessagesHistogram(extension, "Install");
[email protected]69084dc2012-11-17 07:39:301860 } else {
1861 UMA_HISTOGRAM_ENUMERATION("Extensions.UpdateType",
1862 extension->GetType(), 100);
1863 UMA_HISTOGRAM_ENUMERATION("Extensions.UpdateSource",
[email protected]1d5e58b2013-01-31 08:41:401864 extension->location(), Manifest::NUM_LOCATIONS);
[email protected]07533022011-06-27 20:42:551865 }
1866
[email protected]399583b2012-12-11 09:33:421867 const Extension::State initial_state =
binjin47947f842014-11-18 12:10:241868 disable_reasons == Extension::DISABLE_NONE ? Extension::ENABLED
1869 : Extension::DISABLED;
treib8a6d9892015-08-26 10:23:191870 if (initial_state == Extension::ENABLED)
1871 extension_prefs_->SetExtensionEnabled(id);
1872 else
1873 extension_prefs_->SetExtensionDisabled(id, disable_reasons);
binjin47947f842014-11-18 12:10:241874
xiyuanf6a4c6a62016-04-19 18:14:541875 extensions::ExtensionPrefs::DelayReason delay_reason;
1876 extensions::InstallGate::Action action = ShouldDelayExtensionInstall(
1877 extension, !!(install_flags & extensions::kInstallFlagInstallImmediately),
1878 &delay_reason);
1879 switch (action) {
1880 case extensions::InstallGate::INSTALL:
1881 AddNewOrUpdatedExtension(extension, initial_state, install_flags,
1882 page_ordinal, install_parameter);
1883 return;
1884 case extensions::InstallGate::DELAY:
1885 extension_prefs_->SetDelayedInstallInfo(extension, initial_state,
1886 install_flags, delay_reason,
1887 page_ordinal, install_parameter);
[email protected]0db124b02012-11-07 04:55:051888
xiyuanf6a4c6a62016-04-19 18:14:541889 // Transfer ownership of |extension|.
[email protected]9f4e4f082013-06-21 07:11:191890 delayed_installs_.Insert(extension);
xiyuanf6a4c6a62016-04-19 18:14:541891
1892 if (delay_reason ==
1893 extensions::ExtensionPrefs::DELAY_REASON_WAIT_FOR_IDLE) {
1894 // Notify observers that app update is available.
ericwilligersb5f79de2016-10-19 04:15:101895 for (auto& observer : update_observers_)
1896 observer.OnAppUpdateAvailable(extension);
xiyuanf6a4c6a62016-04-19 18:14:541897 }
1898 return;
1899 case extensions::InstallGate::ABORT:
1900 // Do nothing to abort the install. One such case is the shared module
1901 // service gets IMPORT_STATUS_UNRECOVERABLE status for the pending
1902 // install.
1903 return;
[email protected]399583b2012-12-11 09:33:421904 }
xiyuanf6a4c6a62016-04-19 18:14:541905
1906 NOTREACHED() << "Unknown action for delayed install: " << action;
[email protected]8c484b742012-11-29 06:05:361907}
1908
binjin1569c9b2014-09-05 13:33:181909void ExtensionService::OnExtensionManagementSettingsChanged() {
1910 error_controller_->ShowErrorIfNeeded();
binjine6b58b52014-10-31 01:55:571911
1912 // Revokes blocked permissions from active_permissions for all extensions.
1913 extensions::ExtensionManagement* settings =
1914 extensions::ExtensionManagementFactory::GetForBrowserContext(profile());
1915 CHECK(settings);
dchengc963c7142016-04-08 03:55:221916 std::unique_ptr<ExtensionSet> all_extensions(
binjine6b58b52014-10-31 01:55:571917 registry_->GenerateInstalledExtensionsSet());
achuith2f5578b2016-02-26 21:57:131918 for (const auto& extension : *all_extensions) {
binjine6b58b52014-10-31 01:55:571919 if (!settings->IsPermissionSetAllowed(
binjin685ade82014-11-06 09:53:561920 extension.get(),
rdevlin.cronind630c302015-09-30 20:19:331921 extension->permissions_data()->active_permissions())) {
rdevlin.cronin77cb0ef2015-09-16 17:03:481922 extensions::PermissionsUpdater(profile()).RemovePermissionsUnsafe(
rdevlin.cronind630c302015-09-30 20:19:331923 extension.get(), *settings->GetBlockedPermissions(extension.get()));
binjine6b58b52014-10-31 01:55:571924 }
1925 }
1926
binjin1569c9b2014-09-05 13:33:181927 CheckManagementPolicy();
1928}
1929
[email protected]8c484b742012-11-29 06:05:361930void ExtensionService::AddNewOrUpdatedExtension(
1931 const Extension* extension,
[email protected]399583b2012-12-11 09:33:421932 Extension::State initial_state,
[email protected]4a1d9c0d2014-06-13 12:50:111933 int install_flags,
[email protected]d8fd0fd2014-03-24 13:16:061934 const syncer::StringOrdinal& page_ordinal,
1935 const std::string& install_parameter) {
[email protected]8c484b742012-11-29 06:05:361936 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]4a1d9c0d2014-06-13 12:50:111937 extension_prefs_->OnExtensionInstalled(
1938 extension, initial_state, page_ordinal, install_flags, install_parameter);
[email protected]9e9c1d12013-07-31 01:58:121939 delayed_installs_.Remove(extension->id());
[email protected]913ffca92014-03-27 15:26:161940 if (InstallVerifier::NeedsVerification(*extension))
juncai33e462102015-05-18 20:48:441941 InstallVerifier::Get(GetBrowserContext())->VerifyExtension(extension->id());
ryanackley48bedbd2015-01-27 23:12:141942
1943 const Extension* old = GetInstalledExtension(extension->id());
1944 if (extensions::AppDataMigrator::NeedsMigration(old, extension)) {
1945 app_data_migrator_->DoMigrationAndReply(
vmpstra34d11322016-03-21 20:28:471946 old, extension, base::Bind(&ExtensionService::FinishInstallation,
1947 AsWeakPtr(), base::RetainedRef(extension)));
ryanackley48bedbd2015-01-27 23:12:141948 return;
1949 }
1950
benwells1dd4acd2015-12-09 02:20:241951 FinishInstallation(extension);
[email protected]6f6101832012-11-27 22:10:481952}
1953
1954void ExtensionService::MaybeFinishDelayedInstallation(
1955 const std::string& extension_id) {
[email protected]9f4e4f082013-06-21 07:11:191956 // Check if the extension already got installed.
[email protected]9f4e4f082013-06-21 07:11:191957 const Extension* extension = delayed_installs_.GetByID(extension_id);
xiyuanf6a4c6a62016-04-19 18:14:541958 if (!extension)
1959 return;
1960
1961 extensions::ExtensionPrefs::DelayReason reason;
1962 const extensions::InstallGate::Action action = ShouldDelayExtensionInstall(
1963 extension, false /* install_immediately*/, &reason);
1964 switch (action) {
1965 case extensions::InstallGate::INSTALL:
1966 break;
1967 case extensions::InstallGate::DELAY:
1968 // Bail out and continue to delay the install.
[email protected]9f4e4f082013-06-21 07:11:191969 return;
xiyuanf6a4c6a62016-04-19 18:14:541970 case extensions::InstallGate::ABORT:
1971 delayed_installs_.Remove(extension_id);
1972 // Make sure no version of the extension is actually installed, (i.e.,
1973 // that this delayed install was not an update).
1974 CHECK(!extension_prefs_->GetInstalledExtensionInfo(extension_id).get());
1975 extension_prefs_->DeleteExtensionPrefs(extension_id);
1976 return;
[email protected]9f4e4f082013-06-21 07:11:191977 }
1978
[email protected]6f6101832012-11-27 22:10:481979 FinishDelayedInstallation(extension_id);
1980}
1981
1982void ExtensionService::FinishDelayedInstallation(
1983 const std::string& extension_id) {
1984 scoped_refptr<const Extension> extension(
1985 GetPendingExtensionUpdate(extension_id));
[email protected]dc24976f2013-06-02 21:15:091986 CHECK(extension.get());
[email protected]9f4e4f082013-06-21 07:11:191987 delayed_installs_.Remove(extension_id);
[email protected]6f6101832012-11-27 22:10:481988
[email protected]399583b2012-12-11 09:33:421989 if (!extension_prefs_->FinishDelayedInstallInfo(extension_id))
[email protected]6f6101832012-11-27 22:10:481990 NOTREACHED();
1991
benwells1dd4acd2015-12-09 02:20:241992 FinishInstallation(extension.get());
[email protected]6f6101832012-11-27 22:10:481993}
1994
[email protected]760f743b2014-05-28 13:52:021995void ExtensionService::FinishInstallation(
benwells1dd4acd2015-12-09 02:20:241996 const Extension* extension) {
[email protected]e7554c3f2013-05-29 00:36:561997 const extensions::Extension* existing_extension =
1998 GetInstalledExtension(extension->id());
1999 bool is_update = false;
2000 std::string old_name;
2001 if (existing_extension) {
2002 is_update = true;
2003 old_name = existing_extension->name();
2004 }
[email protected]bc44b5da2014-06-12 14:20:002005 registry_->TriggerOnWillBeInstalled(
benwells1dd4acd2015-12-09 02:20:242006 extension, is_update, old_name);
[email protected]17f07822014-05-22 08:45:152007
[email protected]399583b2012-12-11 09:33:422008 // Unpacked extensions default to allowing file access, but if that has been
2009 // overridden, don't reset the value.
[email protected]1d5e58b2013-01-31 08:41:402010 if (Manifest::ShouldAlwaysAllowFileAccess(extension->location()) &&
[email protected]399583b2012-12-11 09:33:422011 !extension_prefs_->HasAllowFileAccessSetting(extension->id())) {
2012 extension_prefs_->SetAllowFileAccess(extension->id(), true);
2013 }
2014
[email protected]6f6101832012-11-27 22:10:482015 AddExtension(extension);
[email protected]612a1cb12012-10-17 13:18:032016
[email protected]bc44b5da2014-06-12 14:20:002017 // Notify observers that need to know when an installation is complete.
[email protected]38e872532014-07-16 23:27:512018 registry_->TriggerOnInstalled(extension, is_update);
[email protected]bc44b5da2014-06-12 14:20:002019
[email protected]9f4e4f082013-06-21 07:11:192020 // Check extensions that may have been delayed only because this shared module
2021 // was not available.
[email protected]374ceb6f2014-07-02 19:25:342022 if (SharedModuleInfo::IsSharedModule(extension))
[email protected]9f4e4f082013-06-21 07:11:192023 MaybeFinishDelayedInstallations();
[email protected]4a190632009-05-09 01:07:422024}
2025
[email protected]76b65442012-11-17 14:11:482026const Extension* ExtensionService::GetPendingExtensionUpdate(
2027 const std::string& id) const {
[email protected]9f4e4f082013-06-21 07:11:192028 return delayed_installs_.GetByID(id);
[email protected]76b65442012-11-17 14:11:482029}
2030
mukai87a8d402014-09-15 20:15:092031void ExtensionService::RegisterContentSettings(
2032 HostContentSettingsMap* host_content_settings_map) {
rkaplowe65c2ff2015-02-14 16:29:542033 TRACE_EVENT0("browser,startup", "ExtensionService::RegisterContentSettings");
mukaia1aa3512014-10-22 20:14:112034 DCHECK_CURRENTLY_ON(BrowserThread::UI);
mukai87a8d402014-09-15 20:15:092035 host_content_settings_map->RegisterProvider(
2036 HostContentSettingsMap::INTERNAL_EXTENSION_PROVIDER,
dchengc963c7142016-04-08 03:55:222037 std::unique_ptr<content_settings::ObservableProvider>(
reillyga3acbc12014-11-11 23:17:122038 new content_settings::InternalExtensionProvider(profile_)));
mukai87a8d402014-09-15 20:15:092039
2040 host_content_settings_map->RegisterProvider(
2041 HostContentSettingsMap::CUSTOM_EXTENSION_PROVIDER,
dchengc963c7142016-04-08 03:55:222042 std::unique_ptr<content_settings::ObservableProvider>(
mukai87a8d402014-09-15 20:15:092043 new content_settings::CustomExtensionProvider(
dchengc963c7142016-04-08 03:55:222044 extensions::ContentSettingsService::Get(profile_)
2045 ->content_settings_store(),
mukai87a8d402014-09-15 20:15:092046 profile_->GetOriginalProfile() != profile_)));
2047}
2048
xiyuane87def2e2015-06-04 22:50:222049void ExtensionService::TrackTerminatedExtension(
2050 const std::string& extension_id) {
2051 extensions_being_terminated_.erase(extension_id);
2052
2053 const Extension* extension = GetInstalledExtension(extension_id);
2054 if (!extension) {
xiyuane87def2e2015-06-04 22:50:222055 return;
2056 }
2057
[email protected]bb1bc9b32013-12-21 03:09:142058 // No need to check for duplicates; inserting a duplicate is a no-op.
2059 registry_->AddTerminated(make_scoped_refptr(extension));
[email protected]b0af4792013-10-23 09:12:132060 UnloadExtension(extension->id(), UnloadedExtensionInfo::REASON_TERMINATE);
[email protected]bb7f40952011-01-13 00:21:202061}
2062
[email protected]e9d7496e2014-04-18 01:25:462063void ExtensionService::TerminateExtension(const std::string& extension_id) {
xiyuana30a2092015-06-09 23:14:442064 TrackTerminatedExtension(extension_id);
[email protected]e9d7496e2014-04-18 01:25:462065}
2066
[email protected]bb7f40952011-01-13 00:21:202067void ExtensionService::UntrackTerminatedExtension(const std::string& id) {
brettwfce8d192015-08-10 19:07:512068 std::string lowercase_id = base::ToLowerASCII(id);
[email protected]bb1bc9b32013-12-21 03:09:142069 const Extension* extension =
2070 registry_->terminated_extensions().GetByID(lowercase_id);
2071 registry_->RemoveTerminated(lowercase_id);
[email protected]fb789532013-08-27 02:40:212072 if (extension) {
2073 content::NotificationService::current()->Notify(
[email protected]adf5a102014-07-31 12:44:062074 extensions::NOTIFICATION_EXTENSION_REMOVED,
[email protected]fb789532013-08-27 02:40:212075 content::Source<Profile>(profile_),
2076 content::Details<const Extension>(extension));
2077 }
[email protected]bb7f40952011-01-13 00:21:202078}
2079
[email protected]8001df22011-04-28 19:59:472080const Extension* ExtensionService::GetInstalledExtension(
2081 const std::string& id) const {
[email protected]599539802014-01-07 23:06:002082 return registry_->GetExtensionById(id, ExtensionRegistry::EVERYTHING);
[email protected]0dfe05c2011-02-23 23:03:362083}
2084
[email protected]9060d8b02012-01-13 02:14:302085bool ExtensionService::OnExternalExtensionFileFound(
lazyboye8634172016-01-28 00:10:482086 const ExternalInstallInfoFile& info) {
[email protected]ab22ba42011-01-14 16:36:382087 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
lazyboye8634172016-01-28 00:10:482088 CHECK(crx_file::id_util::IdIsValid(info.extension_id));
2089 if (extension_prefs_->IsExternalExtensionUninstalled(info.extension_id))
[email protected]9060d8b02012-01-13 02:14:302090 return false;
[email protected]a8af9fdb2010-10-28 21:52:202091
[email protected]7577a5c52009-07-30 06:21:582092 // Before even bothering to unpack, check and see if we already have this
[email protected]4c967932009-07-31 01:15:492093 // version. This is important because these extensions are going to get
[email protected]7577a5c52009-07-30 06:21:582094 // installed on every startup.
lazyboye8634172016-01-28 00:10:482095 const Extension* existing = GetExtensionById(info.extension_id, true);
[email protected]910f72ce2012-08-24 01:38:352096
[email protected]7577a5c52009-07-30 06:21:582097 if (existing) {
[email protected]910f72ce2012-08-24 01:38:352098 // The default apps will have the location set as INTERNAL. Since older
2099 // default apps are installed as EXTERNAL, we override them. However, if the
2100 // app is already installed as internal, then do the version check.
[email protected]31bb5ee62012-09-12 22:58:402101 // TODO(grv) : Remove after Q1-2013.
[email protected]910f72ce2012-08-24 01:38:352102 bool is_default_apps_migration =
lazyboye8634172016-01-28 00:10:482103 (info.crx_location == Manifest::INTERNAL &&
[email protected]1d5e58b2013-01-31 08:41:402104 Manifest::IsExternalLocation(existing->location()));
[email protected]910f72ce2012-08-24 01:38:352105
2106 if (!is_default_apps_migration) {
lazyboye8634172016-01-28 00:10:482107 DCHECK(info.version.get());
[email protected]910f72ce2012-08-24 01:38:352108
lazyboye8634172016-01-28 00:10:482109 switch (existing->version()->CompareTo(*info.version)) {
[email protected]910f72ce2012-08-24 01:38:352110 case -1: // existing version is older, we should upgrade
2111 break;
2112 case 0: // existing version is same, do nothing
2113 return false;
2114 case 1: // existing version is newer, uh-oh
lazyboye8634172016-01-28 00:10:482115 LOG(WARNING) << "Found external version of extension "
2116 << info.extension_id
[email protected]910f72ce2012-08-24 01:38:352117 << "that is older than current version. Current version "
2118 << "is: " << existing->VersionString() << ". New "
lazyboye8634172016-01-28 00:10:482119 << "version is: " << info.version->GetString()
[email protected]910f72ce2012-08-24 01:38:352120 << ". Keeping current version.";
2121 return false;
2122 }
[email protected]7577a5c52009-07-30 06:21:582123 }
2124 }
2125
[email protected]9060d8b02012-01-13 02:14:302126 // If the extension is already pending, don't start an install.
[email protected]e3987852012-05-04 10:06:302127 if (!pending_extension_manager()->AddFromExternalFile(
lazyboye8634172016-01-28 00:10:482128 info.extension_id, info.crx_location, *info.version,
2129 info.creation_flags, info.mark_acknowledged)) {
[email protected]9060d8b02012-01-13 02:14:302130 return false;
[email protected]e3987852012-05-04 10:06:302131 }
[email protected]9c635f22010-12-02 09:36:362132
[email protected]14908b72011-04-20 06:54:362133 // no client (silent install)
[email protected]f8636f92013-08-09 21:02:372134 scoped_refptr<CrxInstaller> installer(CrxInstaller::CreateSilent(this));
lazyboye8634172016-01-28 00:10:482135 installer->set_install_source(info.crx_location);
2136 installer->set_expected_id(info.extension_id);
2137 installer->set_expected_version(*info.version,
treibe960e282015-09-11 10:38:082138 true /* fail_install_if_unexpected */);
[email protected]cb0e50312011-05-09 15:03:072139 installer->set_install_cause(extension_misc::INSTALL_CAUSE_EXTERNAL_FILE);
lazyboye8634172016-01-28 00:10:482140 installer->set_install_immediately(info.install_immediately);
2141 installer->set_creation_flags(info.creation_flags);
[email protected]88e8ec9152013-01-17 04:05:182142#if defined(OS_CHROMEOS)
lazyboye8634172016-01-28 00:10:482143 extensions::InstallLimiter::Get(profile_)->Add(installer, info.path);
[email protected]88e8ec9152013-01-17 04:05:182144#else
lazyboye8634172016-01-28 00:10:482145 installer->InstallCrx(info.path);
[email protected]88e8ec9152013-01-17 04:05:182146#endif
[email protected]47fc70c2011-12-06 07:29:512147
2148 // Depending on the source, a new external extension might not need a user
2149 // notification on installation. For such extensions, mark them acknowledged
2150 // now to suppress the notification.
lazyboye8634172016-01-28 00:10:482151 if (info.mark_acknowledged)
2152 external_install_manager_->AcknowledgeExternalExtension(info.extension_id);
[email protected]9060d8b02012-01-13 02:14:302153
2154 return true;
[email protected]7577a5c52009-07-30 06:21:582155}
2156
[email protected]eaa7dd182010-12-14 11:09:002157void ExtensionService::DidCreateRenderViewForBackgroundPage(
[email protected]3a1dc572012-07-31 22:25:132158 extensions::ExtensionHost* host) {
[email protected]406027c02010-09-27 08:03:182159 OrphanedDevTools::iterator iter =
[email protected]2d2f6cfc2011-05-06 21:09:332160 orphaned_dev_tools_.find(host->extension_id());
[email protected]406027c02010-09-27 08:03:182161 if (iter == orphaned_dev_tools_.end())
2162 return;
2163
rockota34fed222015-09-25 21:56:312164 // Keepalive count is reset on extension reload. This re-establishes the
2165 // keepalive that was added when the DevTools agent was initially attached.
2166 extensions::ProcessManager::Get(profile_)->IncrementLazyKeepaliveCount(
2167 host->extension());
[email protected]b3f957e62014-08-08 10:09:022168 iter->second->ConnectWebContents(host->host_contents());
[email protected]406027c02010-09-27 08:03:182169 orphaned_dev_tools_.erase(iter);
2170}
2171
[email protected]432115822011-07-10 15:52:272172void ExtensionService::Observe(int type,
[email protected]6c2381d2011-10-19 02:52:532173 const content::NotificationSource& source,
2174 const content::NotificationDetails& details) {
[email protected]432115822011-07-10 15:52:272175 switch (type) {
[email protected]3c4abc82012-10-22 22:25:542176 case chrome::NOTIFICATION_APP_TERMINATING:
2177 // Shutdown has started. Don't start any more extension installs.
2178 // (We cannot use ExtensionService::Shutdown() for this because it
2179 // happens too late in browser teardown.)
2180 browser_terminating_ = true;
2181 break;
[email protected]adf5a102014-07-31 12:44:062182 case extensions::NOTIFICATION_EXTENSION_PROCESS_TERMINATED: {
[email protected]6c2381d2011-10-19 02:52:532183 if (profile_ !=
2184 content::Source<Profile>(source).ptr()->GetOriginalProfile()) {
[email protected]bc535ee52010-08-31 18:40:322185 break;
[email protected]6c2381d2011-10-19 02:52:532186 }
[email protected]a4ed6282009-12-14 20:51:162187
[email protected]3a1dc572012-07-31 22:25:132188 extensions::ExtensionHost* host =
2189 content::Details<extensions::ExtensionHost>(details).ptr();
[email protected]f128af42010-08-05 18:05:262190
[email protected]3964e572014-02-13 21:57:412191 // If the extension is already being terminated, there is nothing left to
2192 // do.
2193 if (!extensions_being_terminated_.insert(host->extension_id()).second)
2194 break;
2195
[email protected]fa2416f2011-05-03 08:41:202196 // Mark the extension as terminated and Unload it. We want it to
2197 // be in a consistent state: either fully working or not loaded
2198 // at all, but never half-crashed. We do it in a PostTask so
2199 // that other handlers of this notification will still have
2200 // access to the Extension and ExtensionHost.
skyostilf221b7de2015-06-11 20:36:322201 base::ThreadTaskRunnerHandle::Get()->PostTask(
2202 FROM_HERE, base::Bind(&ExtensionService::TrackTerminatedExtension,
2203 AsWeakPtr(), host->extension()->id()));
[email protected]31f77262009-12-02 20:48:532204 break;
2205 }
[email protected]432115822011-07-10 15:52:272206 case content::NOTIFICATION_RENDERER_PROCESS_TERMINATED: {
[email protected]f3b1a082011-11-18 00:34:302207 content::RenderProcessHost* process =
2208 content::Source<content::RenderProcessHost>(source).ptr();
[email protected]fc30ef082011-08-18 04:07:192209 Profile* host_profile =
[email protected]f3b1a082011-11-18 00:34:302210 Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]fc30ef082011-08-18 04:07:192211 if (!profile_->IsSameProfile(host_profile->GetOriginalProfile()))
2212 break;
2213
[email protected]fafdc842014-01-17 18:09:082214 extensions::ProcessMap* process_map =
2215 extensions::ProcessMap::Get(profile_);
2216 if (process_map->Contains(process->GetID())) {
[email protected]52b76592013-11-02 17:59:032217 // An extension process was terminated, this might have resulted in an
2218 // app or extension becoming idle.
2219 std::set<std::string> extension_ids =
[email protected]fafdc842014-01-17 18:09:082220 process_map->GetExtensionsInProcess(process->GetID());
elijahtaylor0def4432014-10-06 18:15:112221 // In addition to the extensions listed in the process map, one of those
2222 // extensions could be referencing a shared module which is waiting for
2223 // idle to update. Check all imports of these extensions, too.
2224 std::set<std::string> import_ids;
2225 for (std::set<std::string>::const_iterator it = extension_ids.begin();
2226 it != extension_ids.end();
2227 ++it) {
2228 const Extension* extension = GetExtensionById(*it, true);
2229 if (!extension)
2230 continue;
2231 const std::vector<SharedModuleInfo::ImportInfo>& imports =
2232 SharedModuleInfo::GetImports(extension);
2233 std::vector<SharedModuleInfo::ImportInfo>::const_iterator import_it;
2234 for (import_it = imports.begin(); import_it != imports.end();
2235 import_it++) {
2236 import_ids.insert((*import_it).extension_id);
2237 }
2238 }
2239 extension_ids.insert(import_ids.begin(), import_ids.end());
2240
[email protected]52b76592013-11-02 17:59:032241 for (std::set<std::string>::const_iterator it = extension_ids.begin();
2242 it != extension_ids.end(); ++it) {
2243 if (delayed_installs_.Contains(*it)) {
skyostilf221b7de2015-06-11 20:36:322244 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
[email protected]52b76592013-11-02 17:59:032245 FROM_HERE,
2246 base::Bind(&ExtensionService::MaybeFinishDelayedInstallation,
2247 AsWeakPtr(), *it),
2248 base::TimeDelta::FromSeconds(kUpdateIdleDelay));
2249 }
2250 }
2251 }
2252
[email protected]fafdc842014-01-17 18:09:082253 process_map->RemoveAllFromProcess(process->GetID());
[email protected]6f371442011-11-09 06:45:462254 BrowserThread::PostTask(
[email protected]38427a12013-11-09 17:34:202255 BrowserThread::IO,
2256 FROM_HERE,
2257 base::Bind(&extensions::InfoMap::UnregisterAllExtensionsInProcess,
[email protected]31d8f5f22012-04-02 15:22:082258 system_->info_map(),
[email protected]f3b1a082011-11-18 00:34:302259 process->GetID()));
[email protected]da5683db2011-04-23 17:12:212260 break;
2261 }
[email protected]92dd8d92013-02-26 00:41:082262 case chrome::NOTIFICATION_UPGRADE_RECOMMENDED: {
[email protected]75bdcb872013-03-13 00:41:452263 // Notify observers that chrome update is available.
ericwilligersb5f79de2016-10-19 04:15:102264 for (auto& observer : update_observers_)
2265 observer.OnChromeUpdateAvailable();
[email protected]92dd8d92013-02-26 00:41:082266 break;
2267 }
[email protected]ebe07772014-05-22 04:16:062268 case chrome::NOTIFICATION_PROFILE_DESTRUCTION_STARTED: {
2269 OnProfileDestructionStarted();
2270 break;
2271 }
[email protected]aa96d3a2010-08-21 08:45:252272
[email protected]4814b512009-11-07 00:12:292273 default:
2274 NOTREACHED() << "Unexpected notification type.";
2275 }
2276}
2277
binjin47947f842014-11-18 12:10:242278int ExtensionService::GetDisableReasonsOnInstalled(const Extension* extension) {
rdevlin.cronine1456712016-12-29 22:47:282279 bool is_update_from_same_type = false;
2280 {
2281 const Extension* existing_extension =
2282 GetInstalledExtension(extension->id());
2283 is_update_from_same_type =
2284 existing_extension &&
2285 existing_extension->manifest()->type() == extension->manifest()->type();
2286 }
2287 Extension::DisableReason disable_reason = Extension::DISABLE_NONE;
binjin47947f842014-11-18 12:10:242288 // Extensions disabled by management policy should always be disabled, even
2289 // if it's force-installed.
2290 if (system_->management_policy()->MustRemainDisabled(
2291 extension, &disable_reason, nullptr)) {
2292 // A specified reason is required to disable the extension.
2293 DCHECK(disable_reason != Extension::DISABLE_NONE);
2294 return disable_reason;
2295 }
2296
[email protected]612a1cb12012-10-17 13:18:032297 // Extensions installed by policy can't be disabled. So even if a previous
2298 // installation disabled the extension, make sure it is now enabled.
binjin47947f842014-11-18 12:10:242299 if (system_->management_policy()->MustRemainEnabled(extension, nullptr))
2300 return Extension::DISABLE_NONE;
[email protected]612a1cb12012-10-17 13:18:032301
binjin47947f842014-11-18 12:10:242302 // An already disabled extension should inherit the disable reasons and
2303 // remain disabled.
2304 if (extension_prefs_->IsExtensionDisabled(extension->id())) {
2305 int disable_reasons = extension_prefs_->GetDisableReasons(extension->id());
2306 // If an extension was disabled without specified reason, presume it's
2307 // disabled by user.
2308 return disable_reasons == Extension::DISABLE_NONE
2309 ? Extension::DISABLE_USER_ACTION
2310 : disable_reasons;
2311 }
[email protected]612a1cb12012-10-17 13:18:032312
rdevlin.cronin9d7ae4d2017-01-13 16:38:232313 if (extensions::ExternalInstallManager::IsPromptingEnabled()) {
[email protected]612a1cb12012-10-17 13:18:032314 // External extensions are initially disabled. We prompt the user before
[email protected]2c495c42013-01-04 21:49:542315 // enabling them. Hosted apps are excepted because they are not dangerous
rdevlin.cronine1456712016-12-29 22:47:282316 // (they need to be launched by the user anyway). We also don't prompt for
2317 // extensions updating; this is because the extension will be disabled from
2318 // the initial install if it is supposed to be, and this allows us to turn
2319 // this on for other platforms without disabling already-installed
2320 // extensions.
[email protected]1d5e58b2013-01-31 08:41:402321 if (extension->GetType() != Manifest::TYPE_HOSTED_APP &&
2322 Manifest::IsExternalLocation(extension->location()) &&
rdevlin.cronine1456712016-12-29 22:47:282323 !extension_prefs_->IsExternalExtensionAcknowledged(extension->id()) &&
2324 !is_update_from_same_type) {
binjin47947f842014-11-18 12:10:242325 return Extension::DISABLE_EXTERNAL_EXTENSION;
[email protected]612a1cb12012-10-17 13:18:032326 }
2327 }
[email protected]612a1cb12012-10-17 13:18:032328
binjin47947f842014-11-18 12:10:242329 return Extension::DISABLE_NONE;
[email protected]612a1cb12012-10-17 13:18:032330}
[email protected]0db124b02012-11-07 04:55:052331
mlerman6a37b6a42014-11-26 22:10:532332// Helper method to determine if an extension can be blocked.
2333bool ExtensionService::CanBlockExtension(const Extension* extension) const {
mlerman3690e5be2014-12-01 22:57:442334 DCHECK(extension);
mlerman6a37b6a42014-11-26 22:10:532335 return extension->location() != Manifest::COMPONENT &&
2336 extension->location() != Manifest::EXTERNAL_COMPONENT &&
achuith2f5578b2016-02-26 21:57:132337 !system_->management_policy()->MustRemainEnabled(extension, nullptr);
mlerman6a37b6a42014-11-26 22:10:532338}
2339
xiyuanf6a4c6a62016-04-19 18:14:542340extensions::InstallGate::Action ExtensionService::ShouldDelayExtensionInstall(
2341 const extensions::Extension* extension,
2342 bool install_immediately,
2343 extensions::ExtensionPrefs::DelayReason* reason) const {
2344 for (const auto& entry : install_delayer_registry_) {
2345 extensions::InstallGate* const delayer = entry.second;
2346 extensions::InstallGate::Action action =
2347 delayer->ShouldDelay(extension, install_immediately);
2348 if (action != extensions::InstallGate::INSTALL) {
2349 *reason = entry.first;
2350 return action;
2351 }
[email protected]e7aa7b7e2012-11-27 04:51:222352 }
[email protected]fdd679b2012-11-15 20:49:392353
xiyuanf6a4c6a62016-04-19 18:14:542354 return extensions::InstallGate::INSTALL;
[email protected]9f4e4f082013-06-21 07:11:192355}
2356
2357void ExtensionService::MaybeFinishDelayedInstallations() {
2358 std::vector<std::string> to_be_installed;
achuith2f5578b2016-02-26 21:57:132359 for (const auto& extension : delayed_installs_) {
2360 to_be_installed.push_back(extension->id());
[email protected]399583b2012-12-11 09:33:422361 }
achuith2f5578b2016-02-26 21:57:132362 for (const auto& extension_id : to_be_installed) {
2363 MaybeFinishDelayedInstallation(extension_id);
[email protected]399583b2012-12-11 09:33:422364 }
[email protected]399583b2012-12-11 09:33:422365}
2366
[email protected]fdd679b2012-11-15 20:49:392367void ExtensionService::OnBlacklistUpdated() {
[email protected]2d19eb6e2014-01-27 17:30:002368 blacklist_->GetBlacklistedIDs(
[email protected]f47f7172014-03-19 19:27:102369 registry_->GenerateInstalledExtensionsSet()->GetIDs(),
[email protected]3f2a2fa2013-09-24 02:55:252370 base::Bind(&ExtensionService::ManageBlacklist, AsWeakPtr()));
[email protected]695b5712012-12-06 23:55:282371}
2372
[email protected]2d19eb6e2014-01-27 17:30:002373void ExtensionService::ManageBlacklist(
2374 const extensions::Blacklist::BlacklistStateMap& state_map) {
[email protected]54ee8192014-03-29 17:37:242375 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]695b5712012-12-06 23:55:282376
mlerman6a37b6a42014-11-26 22:10:532377 std::set<std::string> blacklisted;
[email protected]2d19eb6e2014-01-27 17:30:002378 ExtensionIdSet greylist;
2379 ExtensionIdSet unchanged;
achuith2f5578b2016-02-26 21:57:132380 for (const auto& it : state_map) {
2381 switch (it.second) {
[email protected]2d19eb6e2014-01-27 17:30:002382 case extensions::NOT_BLACKLISTED:
2383 break;
[email protected]695b5712012-12-06 23:55:282384
[email protected]2d19eb6e2014-01-27 17:30:002385 case extensions::BLACKLISTED_MALWARE:
achuith2f5578b2016-02-26 21:57:132386 blacklisted.insert(it.first);
[email protected]2d19eb6e2014-01-27 17:30:002387 break;
2388
2389 case extensions::BLACKLISTED_SECURITY_VULNERABILITY:
2390 case extensions::BLACKLISTED_CWS_POLICY_VIOLATION:
2391 case extensions::BLACKLISTED_POTENTIALLY_UNWANTED:
achuith2f5578b2016-02-26 21:57:132392 greylist.insert(it.first);
[email protected]2d19eb6e2014-01-27 17:30:002393 break;
2394
2395 case extensions::BLACKLISTED_UNKNOWN:
achuith2f5578b2016-02-26 21:57:132396 unchanged.insert(it.first);
[email protected]2d19eb6e2014-01-27 17:30:002397 break;
2398 }
2399 }
2400
mlerman6a37b6a42014-11-26 22:10:532401 UpdateBlacklistedExtensions(blacklisted, unchanged);
[email protected]2d19eb6e2014-01-27 17:30:002402 UpdateGreylistedExtensions(greylist, unchanged, state_map);
2403
[email protected]373daf972014-04-10 01:50:442404 error_controller_->ShowErrorIfNeeded();
[email protected]2d19eb6e2014-01-27 17:30:002405}
2406
2407namespace {
2408void Partition(const ExtensionIdSet& before,
2409 const ExtensionIdSet& after,
2410 const ExtensionIdSet& unchanged,
2411 ExtensionIdSet* no_longer,
2412 ExtensionIdSet* not_yet) {
2413 *not_yet = base::STLSetDifference<ExtensionIdSet>(after, before);
2414 *no_longer = base::STLSetDifference<ExtensionIdSet>(before, after);
2415 *no_longer = base::STLSetDifference<ExtensionIdSet>(*no_longer, unchanged);
2416}
2417} // namespace
2418
mlerman6a37b6a42014-11-26 22:10:532419void ExtensionService::UpdateBlacklistedExtensions(
2420 const ExtensionIdSet& blacklisted,
[email protected]2d19eb6e2014-01-27 17:30:002421 const ExtensionIdSet& unchanged) {
2422 ExtensionIdSet not_yet_blocked, no_longer_blocked;
mlerman6a37b6a42014-11-26 22:10:532423 Partition(registry_->blacklisted_extensions().GetIDs(), blacklisted,
2424 unchanged, &no_longer_blocked, &not_yet_blocked);
[email protected]2d19eb6e2014-01-27 17:30:002425
2426 for (ExtensionIdSet::iterator it = no_longer_blocked.begin();
2427 it != no_longer_blocked.end(); ++it) {
[email protected]695b5712012-12-06 23:55:282428 scoped_refptr<const Extension> extension =
[email protected]bb1bc9b32013-12-21 03:09:142429 registry_->blacklisted_extensions().GetByID(*it);
[email protected]3f2a2fa2013-09-24 02:55:252430 if (!extension.get()) {
mlerman6a37b6a42014-11-26 22:10:532431 NOTREACHED() << "Extension " << *it << " no longer blacklisted, "
2432 << "but it was never blacklisted.";
[email protected]695b5712012-12-06 23:55:282433 continue;
[email protected]3f2a2fa2013-09-24 02:55:252434 }
[email protected]bb1bc9b32013-12-21 03:09:142435 registry_->RemoveBlacklisted(*it);
atuchin6dc7c442016-07-20 07:04:342436 extension_prefs_->SetExtensionBlacklistState(extension->id(),
2437 extensions::NOT_BLACKLISTED);
[email protected]dc24976f2013-06-02 21:15:092438 AddExtension(extension.get());
[email protected]ac875372013-02-28 04:36:092439 UMA_HISTOGRAM_ENUMERATION("ExtensionBlacklist.UnblacklistInstalled",
[email protected]dc24976f2013-06-02 21:15:092440 extension->location(),
2441 Manifest::NUM_LOCATIONS);
[email protected]695b5712012-12-06 23:55:282442 }
2443
[email protected]2d19eb6e2014-01-27 17:30:002444 for (ExtensionIdSet::iterator it = not_yet_blocked.begin();
2445 it != not_yet_blocked.end(); ++it) {
[email protected]695b5712012-12-06 23:55:282446 scoped_refptr<const Extension> extension = GetInstalledExtension(*it);
[email protected]3f2a2fa2013-09-24 02:55:252447 if (!extension.get()) {
2448 NOTREACHED() << "Extension " << *it << " needs to be "
2449 << "blacklisted, but it's not installed.";
[email protected]695b5712012-12-06 23:55:282450 continue;
[email protected]3f2a2fa2013-09-24 02:55:252451 }
[email protected]bb1bc9b32013-12-21 03:09:142452 registry_->AddBlacklisted(extension);
[email protected]2d19eb6e2014-01-27 17:30:002453 extension_prefs_->SetExtensionBlacklistState(
2454 extension->id(), extensions::BLACKLISTED_MALWARE);
[email protected]b0af4792013-10-23 09:12:132455 UnloadExtension(*it, UnloadedExtensionInfo::REASON_BLACKLIST);
[email protected]ac875372013-02-28 04:36:092456 UMA_HISTOGRAM_ENUMERATION("ExtensionBlacklist.BlacklistInstalled",
2457 extension->location(), Manifest::NUM_LOCATIONS);
[email protected]695b5712012-12-06 23:55:282458 }
[email protected]2d19eb6e2014-01-27 17:30:002459}
[email protected]695b5712012-12-06 23:55:282460
[email protected]2d19eb6e2014-01-27 17:30:002461// TODO(oleg): UMA logging
2462void ExtensionService::UpdateGreylistedExtensions(
2463 const ExtensionIdSet& greylist,
2464 const ExtensionIdSet& unchanged,
2465 const extensions::Blacklist::BlacklistStateMap& state_map) {
2466 ExtensionIdSet not_yet_greylisted, no_longer_greylisted;
2467 Partition(greylist_.GetIDs(),
2468 greylist, unchanged,
2469 &no_longer_greylisted, &not_yet_greylisted);
2470
2471 for (ExtensionIdSet::iterator it = no_longer_greylisted.begin();
2472 it != no_longer_greylisted.end(); ++it) {
2473 scoped_refptr<const Extension> extension = greylist_.GetByID(*it);
2474 if (!extension.get()) {
2475 NOTREACHED() << "Extension " << *it << " no longer greylisted, "
2476 << "but it was not marked as greylisted.";
2477 continue;
2478 }
2479
2480 greylist_.Remove(*it);
2481 extension_prefs_->SetExtensionBlacklistState(extension->id(),
2482 extensions::NOT_BLACKLISTED);
2483 if (extension_prefs_->GetDisableReasons(extension->id()) &
2484 extensions::Extension::DISABLE_GREYLIST)
2485 EnableExtension(*it);
2486 }
2487
2488 for (ExtensionIdSet::iterator it = not_yet_greylisted.begin();
2489 it != not_yet_greylisted.end(); ++it) {
2490 scoped_refptr<const Extension> extension = GetInstalledExtension(*it);
2491 if (!extension.get()) {
2492 NOTREACHED() << "Extension " << *it << " needs to be "
2493 << "disabled, but it's not installed.";
2494 continue;
2495 }
2496 greylist_.Insert(extension);
2497 extension_prefs_->SetExtensionBlacklistState(extension->id(),
2498 state_map.find(*it)->second);
2499 if (registry_->enabled_extensions().Contains(extension->id()))
2500 DisableExtension(*it, extensions::Extension::DISABLE_GREYLIST);
2501 }
[email protected]fdd679b2012-11-15 20:49:392502}
[email protected]75bdcb872013-03-13 00:41:452503
2504void ExtensionService::AddUpdateObserver(extensions::UpdateObserver* observer) {
2505 update_observers_.AddObserver(observer);
2506}
2507
2508void ExtensionService::RemoveUpdateObserver(
2509 extensions::UpdateObserver* observer) {
2510 update_observers_.RemoveObserver(observer);
2511}
[email protected]bb1bc9b32013-12-21 03:09:142512
xiyuanf6a4c6a62016-04-19 18:14:542513void ExtensionService::RegisterInstallGate(
2514 extensions::ExtensionPrefs::DelayReason reason,
2515 extensions::InstallGate* install_delayer) {
2516 DCHECK(install_delayer_registry_.end() ==
2517 install_delayer_registry_.find(reason));
2518 install_delayer_registry_[reason] = install_delayer;
2519}
2520
2521void ExtensionService::UnregisterInstallGate(
2522 extensions::InstallGate* install_delayer) {
2523 for (auto it = install_delayer_registry_.begin();
2524 it != install_delayer_registry_.end(); ++it) {
2525 if (it->second == install_delayer) {
2526 install_delayer_registry_.erase(it);
2527 return;
2528 }
2529 }
2530}
2531
[email protected]bb1bc9b32013-12-21 03:09:142532// Used only by test code.
2533void ExtensionService::UnloadAllExtensionsInternal() {
2534 profile_->GetExtensionSpecialStoragePolicy()->RevokeRightsForAllExtensions();
2535
2536 registry_->ClearAll();
[email protected]45f5b7d2014-01-22 23:47:132537 system_->runtime_data()->ClearAll();
[email protected]bb1bc9b32013-12-21 03:09:142538
2539 // TODO(erikkay) should there be a notification for this? We can't use
2540 // EXTENSION_UNLOADED since that implies that the extension has been disabled
2541 // or uninstalled.
2542}
[email protected]ebe07772014-05-22 04:16:062543
2544void ExtensionService::OnProfileDestructionStarted() {
2545 ExtensionIdSet ids_to_unload = registry_->enabled_extensions().GetIDs();
2546 for (ExtensionIdSet::iterator it = ids_to_unload.begin();
2547 it != ids_to_unload.end();
2548 ++it) {
2549 UnloadExtension(*it, UnloadedExtensionInfo::REASON_PROFILE_SHUTDOWN);
2550 }
2551}