blob: 057485688ee7312b7c525c1fafbe10955a8b734b [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"
skyostilf221b7de2015-06-11 20:36:3216#include "base/location.h"
rkaplowfca0f4dc52015-03-14 21:40:5717#include "base/metrics/histogram_macros.h"
skyostilf221b7de2015-06-11 20:36:3218#include "base/single_thread_task_runner.h"
[email protected]3ea1b182013-02-08 22:38:4119#include "base/strings/string_number_conversions.h"
catmullings98cd1942016-08-30 22:31:5920#include "base/strings/string_tokenizer.h"
[email protected]00e7bef2013-06-10 20:35:1721#include "base/strings/stringprintf.h"
[email protected]112158af2013-06-07 23:46:1822#include "base/strings/utf_string_conversions.h"
[email protected]7f8f24f2012-11-15 19:40:1423#include "base/threading/sequenced_worker_pool.h"
[email protected]34b99632011-01-01 01:01:0624#include "base/threading/thread_restrictions.h"
gabb15e19072016-05-11 20:45:4125#include "base/threading/thread_task_runner_handle.h"
[email protected]41a17c52013-06-28 00:27:5326#include "base/time/time.h"
rkaplowe65c2ff2015-02-14 16:29:5427#include "base/trace_event/trace_event.h"
avia2f4804a2015-12-24 23:11:1328#include "build/build_config.h"
[email protected]15730c42009-09-03 00:03:2029#include "chrome/browser/browser_process.h"
[email protected]9ea0cd32013-07-12 01:50:3630#include "chrome/browser/chrome_notification_types.h"
mukai87a8d402014-09-15 20:15:0931#include "chrome/browser/content_settings/content_settings_internal_extension_provider.h"
sunil.ratnu21b896c2014-11-24 10:09:2432#include "chrome/browser/extensions/api/content_settings/content_settings_custom_extension_provider.h"
mukai87a8d402014-09-15 20:15:0933#include "chrome/browser/extensions/api/content_settings/content_settings_service.h"
ryanackley48bedbd2015-01-27 23:12:1434#include "chrome/browser/extensions/app_data_migrator.h"
[email protected]d8c8f25f2011-11-02 18:18:0135#include "chrome/browser/extensions/component_loader.h"
[email protected]13e062e2014-08-09 10:21:5536#include "chrome/browser/extensions/crx_installer.h"
[email protected]d9ede582012-08-14 19:21:3837#include "chrome/browser/extensions/data_deleter.h"
rdevlin.cronin2813c1b2014-08-26 23:51:0838#include "chrome/browser/extensions/extension_action_storage_manager.h"
[email protected]5a145e82014-05-29 22:19:0739#include "chrome/browser/extensions/extension_assets_manager.h"
[email protected]62f051c2012-03-29 17:04:4440#include "chrome/browser/extensions/extension_disabled_ui.h"
[email protected]373daf972014-04-10 01:50:4441#include "chrome/browser/extensions/extension_error_controller.h"
[email protected]19eb80152011-02-26 00:28:4342#include "chrome/browser/extensions/extension_special_storage_policy.h"
[email protected]f8aefb132013-10-30 09:29:5243#include "chrome/browser/extensions/extension_sync_service.h"
[email protected]617342a42013-12-18 23:34:0344#include "chrome/browser/extensions/extension_util.h"
[email protected]2894a512014-06-26 19:03:5645#include "chrome/browser/extensions/external_install_manager.h"
[email protected]5df038b2012-07-16 19:03:2746#include "chrome/browser/extensions/external_provider_impl.h"
[email protected]ffd2f79e2013-11-14 00:11:4647#include "chrome/browser/extensions/install_verifier.h"
[email protected]d8c8f25f2011-11-02 18:18:0148#include "chrome/browser/extensions/installed_loader.h"
[email protected]f3d3b382014-03-14 21:19:2849#include "chrome/browser/extensions/pending_extension_manager.h"
[email protected]13e062e2014-08-09 10:21:5550#include "chrome/browser/extensions/permissions_updater.h"
[email protected]90878c52014-04-04 18:21:0251#include "chrome/browser/extensions/shared_module_service.h"
[email protected]13e062e2014-08-09 10:21:5552#include "chrome/browser/extensions/unpacked_installer.h"
rockotdb5192992014-09-16 21:27:0253#include "chrome/browser/extensions/updater/chrome_extension_downloader_factory.h"
[email protected]13e062e2014-08-09 10:21:5554#include "chrome/browser/extensions/updater/extension_updater.h"
rockotdb5192992014-09-16 21:27:0255#include "chrome/browser/google/google_brand.h"
[email protected]8ecad5e2010-12-02 21:18:3356#include "chrome/browser/profiles/profile.h"
dbeam8d57a012015-05-21 07:12:2057#include "chrome/browser/search/thumbnail_source.h"
[email protected]b5a507b22013-11-08 20:41:5758#include "chrome/browser/ui/webui/extensions/extension_icon_source.h"
[email protected]c8d407e2011-04-28 21:27:1759#include "chrome/browser/ui/webui/favicon_source.h"
[email protected]b07e606e2012-09-15 20:16:1560#include "chrome/browser/ui/webui/theme_source.h"
[email protected]e2eb43112009-05-29 21:19:5461#include "chrome/common/chrome_switches.h"
[email protected]f6431be82013-09-07 02:53:4562#include "chrome/common/crash_keys.h"
[email protected]9f4e4f082013-06-21 07:11:1963#include "chrome/common/extensions/extension_constants.h"
[email protected]a57209872009-05-04 22:53:1464#include "chrome/common/url_constants.h"
mukai8eaec822014-10-25 17:53:1665#include "components/content_settings/core/browser/host_content_settings_map.h"
[email protected]fdd28372014-08-21 02:27:2666#include "components/crx_file/id_util.h"
[email protected]dccba4f82014-05-29 00:52:5667#include "content/public/browser/devtools_agent_host.h"
[email protected]05aad2da2011-10-28 10:12:3768#include "content/public/browser/notification_service.h"
[email protected]f3b1a082011-11-18 00:34:3069#include "content/public/browser/render_process_host.h"
[email protected]399583b2012-12-11 09:33:4270#include "content/public/browser/storage_partition.h"
treib926ee2d2015-08-06 10:55:4271#include "extensions/browser/app_sorting.h"
[email protected]34423532013-11-21 18:13:1072#include "extensions/browser/event_router.h"
[email protected]22401dc2014-03-21 01:38:5773#include "extensions/browser/extension_host.h"
[email protected]bb1bc9b32013-12-21 03:09:1474#include "extensions/browser/extension_registry.h"
[email protected]59b0e602014-01-30 00:41:2475#include "extensions/browser/extension_system.h"
rockotffa65b12014-10-14 17:19:0676#include "extensions/browser/extensions_browser_client.h"
lazyboye8634172016-01-28 00:10:4877#include "extensions/browser/external_install_info.h"
[email protected]4a1d9c0d2014-06-13 12:50:1178#include "extensions/browser/install_flag.h"
rdevlin.cronin5e510e802016-07-26 15:09:2079#include "extensions/browser/renderer_startup_helper.h"
[email protected]45f5b7d2014-01-22 23:47:1380#include "extensions/browser/runtime_data.h"
[email protected]e43c61f2014-07-20 21:46:3481#include "extensions/browser/uninstall_reason.h"
[email protected]a9aa62b312013-11-29 05:35:0682#include "extensions/browser/update_observer.h"
rockotffa65b12014-10-14 17:19:0683#include "extensions/browser/updater/extension_cache.h"
rockot05f40a922014-10-16 19:40:2584#include "extensions/browser/updater/extension_downloader.h"
[email protected]fb820c02014-03-13 15:07:0885#include "extensions/common/extension_messages.h"
rockot90659852014-09-18 19:31:5286#include "extensions/common/extension_urls.h"
[email protected]5ef835a2013-11-08 20:42:5787#include "extensions/common/feature_switch.h"
rdevlin.cronin41227532016-07-13 21:24:3488#include "extensions/common/features/feature_channel.h"
[email protected]85df9d12014-04-15 17:02:1489#include "extensions/common/file_util.h"
[email protected]0c3c9732013-09-16 08:53:4190#include "extensions/common/manifest_constants.h"
[email protected]558878cc82013-11-09 01:25:5191#include "extensions/common/manifest_handlers/background_info.h"
rockotd5546142014-10-15 00:29:0892#include "extensions/common/manifest_url_handlers.h"
[email protected]dccba4f82014-05-29 00:52:5693#include "extensions/common/one_shot_event.h"
treib2e0517f92015-05-07 23:15:3694#include "extensions/common/permissions/api_permission.h"
[email protected]c41003472013-10-19 15:37:2595#include "extensions/common/permissions/permission_message_provider.h"
[email protected]e4452d32013-11-15 23:07:4196#include "extensions/common/permissions/permissions_data.h"
[email protected]79a60642012-10-20 21:03:1897
treib8ecc1eb52015-03-04 18:29:0698#if defined(ENABLE_SUPERVISED_USERS)
99#include "chrome/browser/supervised_user/supervised_user_service.h"
100#include "chrome/browser/supervised_user/supervised_user_service_factory.h"
101#endif
102
[email protected]eed367e2011-04-12 03:43:31103#if defined(OS_CHROMEOS)
[email protected]88e8ec9152013-01-17 04:05:18104#include "chrome/browser/chromeos/extensions/install_limiter.h"
pilgrime92c5fcd2014-09-10 23:31:23105#include "storage/browser/fileapi/file_system_backend.h"
106#include "storage/browser/fileapi/file_system_context.h"
[email protected]eed367e2011-04-12 03:43:31107#endif
108
[email protected]55eb70e762012-02-20 17:38:39109using content::BrowserContext;
[email protected]631bb742011-11-02 11:29:39110using content::BrowserThread;
[email protected]98f66112012-12-25 12:59:36111using content::DevToolsAgentHost;
treib2e0517f92015-05-07 23:15:36112using extensions::APIPermission;
deepak.m14ba69e62015-11-17 05:42:12113using extensions::AppSorting;
[email protected]bf3d9df2012-07-24 23:20:27114using extensions::CrxInstaller;
[email protected]1c321ee52012-05-21 03:02:34115using extensions::Extension;
116using extensions::ExtensionIdSet;
117using extensions::ExtensionInfo;
[email protected]599539802014-01-07 23:06:00118using extensions::ExtensionRegistry;
[email protected]289c44b2013-12-17 03:26:57119using extensions::ExtensionSet;
lazyboye8634172016-01-28 00:10:48120using extensions::ExternalInstallInfoFile;
121using extensions::ExternalInstallInfoUpdateUrl;
122using extensions::ExternalProviderInterface;
[email protected]215a7be2012-10-22 19:53:42123using extensions::FeatureSwitch;
[email protected]ffd2f79e2013-11-14 00:11:46124using extensions::InstallVerifier;
[email protected]0d54b682013-11-05 14:15:36125using extensions::ManagementPolicy;
[email protected]1d5e58b2013-01-31 08:41:40126using extensions::Manifest;
treib2e0517f92015-05-07 23:15:36127using extensions::PermissionID;
128using extensions::PermissionIDSet;
[email protected]c2e66e12012-06-27 06:27:06129using extensions::PermissionSet;
[email protected]9f4e4f082013-06-21 07:11:19130using extensions::SharedModuleInfo;
[email protected]90878c52014-04-04 18:21:02131using extensions::SharedModuleService;
[email protected]e410b5f2012-12-14 14:02:24132using extensions::UnloadedExtensionInfo;
[email protected]5ef47ec2010-01-28 05:58:05133
[email protected]b6ab96d2009-08-20 18:58:19134namespace {
135
[email protected]0db124b02012-11-07 04:55:05136// Wait this many seconds after an extensions becomes idle before updating it.
[email protected]ddc6a122014-06-27 04:52:32137const int kUpdateIdleDelay = 5;
[email protected]0db124b02012-11-07 04:55:05138
[email protected]c6d474f82009-12-16 21:11:06139} // namespace
[email protected]b6ab96d2009-08-20 18:58:19140
[email protected]eaa7dd182010-12-14 11:09:00141// ExtensionService.
[email protected]6014d672008-12-05 00:38:25142
[email protected]8e4560b62011-01-14 10:09:14143void ExtensionService::CheckExternalUninstall(const std::string& id) {
[email protected]a29a517a2011-01-21 21:11:12144 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]a8af9fdb2010-10-28 21:52:20145
[email protected]7a4c6852010-09-16 03:44:22146 // Check if the providers know about this extension.
achuith2f5578b2016-02-26 21:57:13147 for (const auto& provider : external_extension_providers_) {
148 DCHECK(provider->IsReady());
149 if (provider->HasExtension(id))
[email protected]0a60a2e2010-10-25 16:15:21150 return; // Yup, known extension, don't uninstall.
[email protected]7a4c6852010-09-16 03:44:22151 }
152
[email protected]0f48fca2011-05-19 18:46:35153 // We get the list of external extensions to check from preferences.
154 // It is possible that an extension has preferences but is not loaded.
155 // For example, an extension that requires experimental permissions
156 // will not be loaded if the experimental command line flag is not used.
157 // In this case, do not uninstall.
[email protected]31bb5ee62012-09-12 22:58:40158 if (!GetInstalledExtension(id)) {
[email protected]0f48fca2011-05-19 18:46:35159 // We can't call UninstallExtension with an unloaded/invalid
160 // extension ID.
161 LOG(WARNING) << "Attempted uninstallation of unloaded/invalid extension "
162 << "with id: " << id;
163 return;
164 }
[email protected]42d58f62014-07-31 01:32:45165 UninstallExtension(id,
166 extensions::UNINSTALL_REASON_ORPHANED_EXTERNAL_EXTENSION,
achuith2f5578b2016-02-26 21:57:13167 base::Bind(&base::DoNothing), nullptr);
[email protected]7a4c6852010-09-16 03:44:22168}
169
[email protected]7f8f24f2012-11-15 19:40:14170void ExtensionService::SetFileTaskRunnerForTesting(
dcheng605ef8d2014-08-28 18:29:44171 const scoped_refptr<base::SequencedTaskRunner>& task_runner) {
[email protected]7f8f24f2012-11-15 19:40:14172 file_task_runner_ = task_runner;
173}
174
[email protected]8e4560b62011-01-14 10:09:14175void ExtensionService::ClearProvidersForTesting() {
[email protected]7a4c6852010-09-16 03:44:22176 external_extension_providers_.clear();
177}
178
[email protected]8e4560b62011-01-14 10:09:14179void ExtensionService::AddProviderForTesting(
lazyboyf33109d2016-08-31 00:37:08180 std::unique_ptr<ExternalProviderInterface> test_provider) {
[email protected]a29a517a2011-01-21 21:11:12181 CHECK(test_provider);
lazyboyf33109d2016-08-31 00:37:08182 external_extension_providers_.push_back(std::move(test_provider));
[email protected]7a4c6852010-09-16 03:44:22183}
184
[email protected]8f959f522014-08-06 06:26:28185void ExtensionService::BlacklistExtensionForTest(
186 const std::string& extension_id) {
mlerman6a37b6a42014-11-26 22:10:53187 ExtensionIdSet blacklisted;
[email protected]8f959f522014-08-06 06:26:28188 ExtensionIdSet unchanged;
mlerman6a37b6a42014-11-26 22:10:53189 blacklisted.insert(extension_id);
190 UpdateBlacklistedExtensions(blacklisted, unchanged);
[email protected]8f959f522014-08-06 06:26:28191}
192
[email protected]9060d8b02012-01-13 02:14:30193bool ExtensionService::OnExternalExtensionUpdateUrlFound(
lazyboye8634172016-01-28 00:10:48194 const ExternalInstallInfoUpdateUrl& info,
195 bool is_initial_load) {
[email protected]ab22ba42011-01-14 16:36:38196 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
lazyboye8634172016-01-28 00:10:48197 CHECK(crx_file::id_util::IdIsValid(info.extension_id));
[email protected]a8af9fdb2010-10-28 21:52:20198
lazyboye8634172016-01-28 00:10:48199 if (Manifest::IsExternalLocation(info.download_location)) {
[email protected]044e86992014-01-24 22:59:11200 // All extensions that are not user specific can be cached.
lazyboye8634172016-01-28 00:10:48201 extensions::ExtensionsBrowserClient::Get()
202 ->GetExtensionCache()
203 ->AllowCaching(info.extension_id);
[email protected]044e86992014-01-24 22:59:11204 }
205
lazyboye8634172016-01-28 00:10:48206 const Extension* extension = GetExtensionById(info.extension_id, true);
[email protected]8a87a5332011-08-11 17:54:59207 if (extension) {
asargent56282ab72016-09-09 16:58:03208 // Already installed. Skip this install if the current location has higher
209 // priority than |info.download_location|, and we aren't doing a
210 // reinstall of a corrupt policy force-installed extension.
[email protected]1d5e58b2013-01-31 08:41:40211 Manifest::Location current = extension->location();
asargent56282ab72016-09-09 16:58:03212 if (!pending_extension_manager_.IsPolicyReinstallForCorruptionExpected(
213 info.extension_id) &&
214 current == Manifest::GetHigherPriorityLocation(
215 current, info.download_location)) {
[email protected]9060d8b02012-01-13 02:14:30216 return false;
lazyboye8634172016-01-28 00:10:48217 }
[email protected]8a87a5332011-08-11 17:54:59218 // Otherwise, overwrite the current installation.
[email protected]7a4c6852010-09-16 03:44:22219 }
[email protected]9060d8b02012-01-13 02:14:30220
lazyboye8634172016-01-28 00:10:48221 // Add |info.extension_id| to the set of pending extensions. If it can not
222 // be added, then there is already a pending record from a higher-priority
223 // install source. In this case, signal that this extension will not be
[email protected]9060d8b02012-01-13 02:14:30224 // installed by returning false.
225 if (!pending_extension_manager()->AddFromExternalUpdateUrl(
lazyboye8634172016-01-28 00:10:48226 info.extension_id, info.install_parameter, *info.update_url,
227 info.download_location, info.creation_flags,
228 info.mark_acknowledged)) {
[email protected]9060d8b02012-01-13 02:14:30229 return false;
[email protected]31bb5ee62012-09-12 22:58:40230 }
[email protected]9060d8b02012-01-13 02:14:30231
lazyboye8634172016-01-28 00:10:48232 if (is_initial_load)
233 update_once_all_providers_are_ready_ = true;
[email protected]9060d8b02012-01-13 02:14:30234 return true;
[email protected]7a4c6852010-09-16 03:44:22235}
236
lazyboye8634172016-01-28 00:10:48237void ExtensionService::OnExternalProviderUpdateComplete(
238 const ExternalProviderInterface* provider,
lazyboy4aeef202016-09-07 21:28:59239 const std::vector<std::unique_ptr<ExternalInstallInfoUpdateUrl>>&
240 update_url_extensions,
241 const std::vector<std::unique_ptr<ExternalInstallInfoFile>>&
242 file_extensions,
lazyboye8634172016-01-28 00:10:48243 const std::set<std::string>& removed_extensions) {
244 // Update pending_extension_manager() with the new extensions first.
lazyboy4aeef202016-09-07 21:28:59245 for (const auto& extension : update_url_extensions)
lazyboye8634172016-01-28 00:10:48246 OnExternalExtensionUpdateUrlFound(*extension, false);
lazyboy4aeef202016-09-07 21:28:59247 for (const auto& extension : file_extensions)
lazyboye8634172016-01-28 00:10:48248 OnExternalExtensionFileFound(*extension);
249
250#if DCHECK_IS_ON()
251 for (const std::string& id : removed_extensions) {
lazyboy4aeef202016-09-07 21:28:59252 for (const auto& extension : update_url_extensions)
lazyboye8634172016-01-28 00:10:48253 DCHECK_NE(id, extension->extension_id);
lazyboy4aeef202016-09-07 21:28:59254 for (const auto& extension : file_extensions)
lazyboye8634172016-01-28 00:10:48255 DCHECK_NE(id, extension->extension_id);
256 }
257#endif
258
259 // Then uninstall before running |updater_|.
260 for (const std::string& id : removed_extensions)
261 CheckExternalUninstall(id);
262
263 if (!update_url_extensions.empty() && updater_) {
264 // Empty params will cause pending extensions to be updated.
265 extensions::ExtensionUpdater::CheckParams empty_params;
266 updater_->CheckNow(empty_params);
267 }
268
269 error_controller_->ShowErrorIfNeeded();
270 external_install_manager_->UpdateExternalExtensionAlert();
271}
272
[email protected]6aeac8342010-10-01 20:21:18273// static
[email protected]cc2f55c2014-07-08 02:19:04274// This function is used to uninstall an extension via sync. The LOG statements
275// within this function are used to inform the user if the uninstall cannot be
276// done.
[email protected]eaa7dd182010-12-14 11:09:00277bool ExtensionService::UninstallExtensionHelper(
278 ExtensionService* extensions_service,
[email protected]cc2f55c2014-07-08 02:19:04279 const std::string& extension_id,
[email protected]e43c61f2014-07-20 21:46:34280 extensions::UninstallReason reason) {
[email protected]d6ebc9792011-04-07 18:18:33281 // We can't call UninstallExtension with an invalid extension ID.
[email protected]31bb5ee62012-09-12 22:58:40282 if (!extensions_service->GetInstalledExtension(extension_id)) {
[email protected]6aeac8342010-10-01 20:21:18283 LOG(WARNING) << "Attempted uninstallation of non-existent extension with "
[email protected]95da88c42011-03-31 10:07:33284 << "id: " << extension_id;
285 return false;
[email protected]6aeac8342010-10-01 20:21:18286 }
287
[email protected]d6ebc9792011-04-07 18:18:33288 // The following call to UninstallExtension will not allow an uninstall of a
289 // policy-controlled extension.
[email protected]439f1e32013-12-09 20:09:09290 base::string16 error;
[email protected]42d58f62014-07-31 01:32:45291 if (!extensions_service->UninstallExtension(
292 extension_id, reason, base::Bind(&base::DoNothing), &error)) {
[email protected]d6ebc9792011-04-07 18:18:33293 LOG(WARNING) << "Cannot uninstall extension with id " << extension_id
294 << ": " << error;
295 return false;
296 }
[email protected]95da88c42011-03-31 10:07:33297
[email protected]6aeac8342010-10-01 20:21:18298 return true;
299}
300
[email protected]eaa7dd182010-12-14 11:09:00301ExtensionService::ExtensionService(Profile* profile,
avi3ef9ec9e2014-12-22 22:50:17302 const base::CommandLine* command_line,
[email protected]650b2d52013-02-10 03:41:45303 const base::FilePath& install_directory,
[email protected]45759612012-07-10 17:21:23304 extensions::ExtensionPrefs* extension_prefs,
[email protected]fdd679b2012-11-15 20:49:39305 extensions::Blacklist* blacklist,
[email protected]0436b102011-04-15 18:30:03306 bool autoupdate_enabled,
[email protected]4a10006a2013-05-17 23:18:35307 bool extensions_enabled,
308 extensions::OneShotEvent* ready)
[email protected]fdd679b2012-11-15 20:49:39309 : extensions::Blacklist::Observer(blacklist),
catmullings98cd1942016-08-30 22:31:59310 command_line_(command_line),
[email protected]fdd679b2012-11-15 20:49:39311 profile_(profile),
[email protected]bd306722012-07-11 20:43:59312 system_(extensions::ExtensionSystem::Get(profile)),
[email protected]73c47932010-12-06 18:13:43313 extension_prefs_(extension_prefs),
[email protected]695b5712012-12-06 23:55:28314 blacklist_(blacklist),
[email protected]5fdfa562013-12-27 17:43:59315 registry_(extensions::ExtensionRegistry::Get(profile)),
[email protected]6c9bedf2014-05-21 03:55:51316 pending_extension_manager_(profile),
[email protected]a9b00ac2009-06-25 21:03:23317 install_directory_(install_directory),
[email protected]0436b102011-04-15 18:30:03318 extensions_enabled_(extensions_enabled),
[email protected]4a10006a2013-05-17 23:18:35319 ready_(ready),
ryanackley48bedbd2015-01-27 23:12:14320 shared_module_service_(new extensions::SharedModuleService(profile_)),
rdevlin.cronin5e510e802016-07-26 15:09:20321 renderer_helper_(
322 extensions::RendererStartupHelperFactory::GetForBrowserContext(
323 profile_)),
ryanackley48bedbd2015-01-27 23:12:14324 app_data_migrator_(new extensions::AppDataMigrator(profile_, registry_)) {
[email protected]a29a517a2011-01-21 21:11:12325 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
rkaplowdd66a1342015-03-05 00:31:49326 TRACE_EVENT0("browser,startup", "ExtensionService::ExtensionService::ctor");
[email protected]a8af9fdb2010-10-28 21:52:20327
[email protected]36a784c2009-06-23 06:21:08328 // Figure out if extension installation should be enabled.
[email protected]367d9b172013-12-03 00:31:02329 if (extensions::ExtensionsBrowserClient::Get()->AreExtensionsDisabled(
330 *command_line, profile))
[email protected]6d60703b2009-08-29 01:29:23331 extensions_enabled_ = false;
[email protected]36a784c2009-06-23 06:21:08332
[email protected]3c4abc82012-10-22 22:25:54333 registrar_.Add(this, chrome::NOTIFICATION_APP_TERMINATING,
334 content::NotificationService::AllBrowserContextsAndSources());
[email protected]adf5a102014-07-31 12:44:06335 registrar_.Add(this,
336 extensions::NOTIFICATION_EXTENSION_PROCESS_TERMINATED,
[email protected]ad50def52011-10-19 23:17:07337 content::NotificationService::AllBrowserContextsAndSources());
[email protected]432115822011-07-10 15:52:27338 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_TERMINATED,
[email protected]ad50def52011-10-19 23:17:07339 content::NotificationService::AllBrowserContextsAndSources());
[email protected]92dd8d92013-02-26 00:41:08340 registrar_.Add(this, chrome::NOTIFICATION_UPGRADE_RECOMMENDED,
341 content::NotificationService::AllBrowserContextsAndSources());
[email protected]ebe07772014-05-22 04:16:06342 registrar_.Add(this,
343 chrome::NOTIFICATION_PROFILE_DESTRUCTION_STARTED,
344 content::Source<Profile>(profile_));
binjin1569c9b2014-09-05 13:33:18345
346 extensions::ExtensionManagementFactory::GetForBrowserContext(profile_)
347 ->AddObserver(this);
[email protected]4814b512009-11-07 00:12:29348
rkaplowdd66a1342015-03-05 00:31:49349 // Set up the ExtensionUpdater.
[email protected]93fd78f42009-07-10 16:43:17350 if (autoupdate_enabled) {
[email protected]501105b2013-09-26 05:42:02351 int update_frequency = extensions::kDefaultUpdateFrequencySeconds;
[email protected]93fd78f42009-07-10 16:43:17352 if (command_line->HasSwitch(switches::kExtensionsUpdateFrequency)) {
[email protected]e83326f2010-07-31 17:29:25353 base::StringToInt(command_line->GetSwitchValueASCII(
354 switches::kExtensionsUpdateFrequency),
355 &update_frequency);
[email protected]93fd78f42009-07-10 16:43:17356 }
[email protected]044e86992014-01-24 22:59:11357 updater_.reset(new extensions::ExtensionUpdater(
358 this,
359 extension_prefs,
360 profile->GetPrefs(),
361 profile,
362 update_frequency,
rockotffa65b12014-10-14 17:19:06363 extensions::ExtensionsBrowserClient::Get()->GetExtensionCache(),
rockotdb5192992014-09-16 21:27:02364 base::Bind(ChromeExtensionDownloaderFactory::CreateForProfile,
365 profile)));
[email protected]93fd78f42009-07-10 16:43:17366 }
367
[email protected]25ae0152011-11-18 14:40:02368 component_loader_.reset(
369 new extensions::ComponentLoader(this,
370 profile->GetPrefs(),
[email protected]55e16cd2013-12-18 04:36:08371 g_browser_process->local_state(),
372 profile));
[email protected]8e4560b62011-01-14 10:09:14373
[email protected]0436b102011-04-15 18:30:03374 if (extensions_enabled_) {
[email protected]ae4c37e2012-12-21 01:16:25375 extensions::ExternalProviderImpl::CreateExternalProviders(
376 this, profile_, &external_extension_providers_);
[email protected]873531342011-03-09 12:16:05377 }
[email protected]b671760b2010-07-15 21:13:47378
[email protected]74474042013-11-21 12:03:54379 // Set this as the ExtensionService for app sorting to ensure it causes syncs
380 // if required.
[email protected]b3aa7182013-04-25 04:45:23381 is_first_run_ = !extension_prefs_->SetAlertSystemFirstRun();
382
[email protected]373daf972014-04-10 01:50:44383 error_controller_.reset(
384 new extensions::ExtensionErrorController(profile_, is_first_run_));
[email protected]374ceb6f2014-07-02 19:25:34385 external_install_manager_.reset(
386 new extensions::ExternalInstallManager(profile_, is_first_run_));
[email protected]373daf972014-04-10 01:50:44387
[email protected]c77f2352012-08-08 22:07:58388 extension_action_storage_manager_.reset(
389 new extensions::ExtensionActionStorageManager(profile_));
390
[email protected]cb0e50312011-05-09 15:03:07391 // How long is the path to the Extensions directory?
392 UMA_HISTOGRAM_CUSTOM_COUNTS("Extensions.ExtensionRootPathLength",
drbasicf0d1b262016-08-23 06:10:42393 install_directory_.value().length(), 1, 500, 100);
[email protected]6014d672008-12-05 00:38:25394}
395
[email protected]3f213ad2012-07-26 23:39:41396extensions::PendingExtensionManager*
397 ExtensionService::pending_extension_manager() {
[email protected]b2907fd2011-03-25 16:43:37398 return &pending_extension_manager_;
[email protected]ddb1e5a2010-12-13 20:10:45399}
400
[email protected]eaa7dd182010-12-14 11:09:00401ExtensionService::~ExtensionService() {
[email protected]c8d407e2011-04-28 21:27:17402 // No need to unload extensions here because they are profile-scoped, and the
403 // profile is in the process of being deleted.
achuith2f5578b2016-02-26 21:57:13404 for (const auto& provider : external_extension_providers_)
[email protected]8e4560b62011-01-14 10:09:14405 provider->ServiceShutdown();
[email protected]6014d672008-12-05 00:38:25406}
407
[email protected]037228a2012-10-05 01:36:16408void ExtensionService::Shutdown() {
binjin1569c9b2014-09-05 13:33:18409 extensions::ExtensionManagementFactory::GetInstance()
410 ->GetForBrowserContext(profile())
411 ->RemoveObserver(this);
[email protected]037228a2012-10-05 01:36:16412}
413
[email protected]b2907fd2011-03-25 16:43:37414const Extension* ExtensionService::GetExtensionById(
415 const std::string& id, bool include_disabled) const {
[email protected]599539802014-01-07 23:06:00416 int include_mask = ExtensionRegistry::ENABLED;
[email protected]695b5712012-12-06 23:55:28417 if (include_disabled) {
mlerman6a37b6a42014-11-26 22:10:53418 // Include blacklisted and blocked extensions here because there are
419 // hundreds of callers of this function, and many might assume that this
420 // includes those that have been disabled due to blacklisting or blocking.
[email protected]599539802014-01-07 23:06:00421 include_mask |= ExtensionRegistry::DISABLED |
mlerman6a37b6a42014-11-26 22:10:53422 ExtensionRegistry::BLACKLISTED | ExtensionRegistry::BLOCKED;
[email protected]695b5712012-12-06 23:55:28423 }
[email protected]599539802014-01-07 23:06:00424 return registry_->GetExtensionById(id, include_mask);
[email protected]695b5712012-12-06 23:55:28425}
426
[email protected]eaa7dd182010-12-14 11:09:00427void ExtensionService::Init() {
[email protected]a29a517a2011-01-21 21:11:12428 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
rkaplowe65c2ff2015-02-14 16:29:54429 TRACE_EVENT0("browser,startup", "ExtensionService::Init");
rkaplowa8fd8d32015-02-25 21:27:56430 SCOPED_UMA_HISTOGRAM_TIMER("Extensions.ExtensionServiceInitTime");
[email protected]3350d712013-11-18 09:32:24431
[email protected]4a10006a2013-05-17 23:18:35432 DCHECK(!is_ready()); // Can't redo init.
[email protected]bb1bc9b32013-12-21 03:09:14433 DCHECK_EQ(registry_->enabled_extensions().size(), 0u);
[email protected]9f1087e2009-06-15 17:29:32434
benwells22ab8ee2015-08-21 02:55:08435 // LoadAllExtensions() calls OnLoadedInstalledExtensions().
436 component_loader_->LoadAll();
437 extensions::InstalledLoader(this).LoadAllExtensions();
catmullings98cd1942016-08-30 22:31:59438 LoadExtensionsFromCommandLineFlag(switches::kDisableExtensionsExcept);
439 if (extensions_enabled_)
440 LoadExtensionsFromCommandLineFlag(switches::kLoadExtension);
benwells22ab8ee2015-08-21 02:55:08441 EnabledReloadableExtensions();
442 MaybeFinishShutdownDelayed();
443 SetReadyAndNotifyListeners();
[email protected]ae4c37e2012-12-21 01:16:25444
benwells22ab8ee2015-08-21 02:55:08445 // TODO(erikkay): this should probably be deferred to a future point
446 // rather than running immediately at startup.
447 CheckForExternalUpdates();
[email protected]894bb502009-05-21 22:39:57448
benwells22ab8ee2015-08-21 02:55:08449 LoadGreylistFromPrefs();
rkaplowa8fd8d32015-02-25 21:27:56450}
[email protected]3350d712013-11-18 09:32:24451
rkaplowa8fd8d32015-02-25 21:27:56452void ExtensionService::EnabledReloadableExtensions() {
453 TRACE_EVENT0("browser,startup",
454 "ExtensionService::EnabledReloadableExtensions");
455
456 std::vector<std::string> extensions_to_enable;
achuith2f5578b2016-02-26 21:57:13457 for (const auto& e : registry_->disabled_extensions()) {
rkaplowa8fd8d32015-02-25 21:27:56458 if (extension_prefs_->GetDisableReasons(e->id()) ==
achuith2f5578b2016-02-26 21:57:13459 Extension::DISABLE_RELOAD)
rkaplowa8fd8d32015-02-25 21:27:56460 extensions_to_enable.push_back(e->id());
rkaplowa8fd8d32015-02-25 21:27:56461 }
462 for (const std::string& extension : extensions_to_enable) {
463 EnableExtension(extension);
464 }
465}
466
467void ExtensionService::MaybeFinishShutdownDelayed() {
468 TRACE_EVENT0("browser,startup",
469 "ExtensionService::MaybeFinishShutdownDelayed");
470
dchengc963c7142016-04-08 03:55:22471 std::unique_ptr<extensions::ExtensionPrefs::ExtensionsInfo> delayed_info(
rkaplowa8fd8d32015-02-25 21:27:56472 extension_prefs_->GetAllDelayedInstallInfo());
473 for (size_t i = 0; i < delayed_info->size(); ++i) {
474 ExtensionInfo* info = delayed_info->at(i).get();
achuith2f5578b2016-02-26 21:57:13475 scoped_refptr<const Extension> extension(nullptr);
rkaplowa8fd8d32015-02-25 21:27:56476 if (info->extension_manifest) {
477 std::string error;
478 extension = Extension::Create(
479 info->extension_path, info->extension_location,
480 *info->extension_manifest,
481 extension_prefs_->GetDelayedInstallCreationFlags(info->extension_id),
482 info->extension_id, &error);
483 if (extension.get())
484 delayed_installs_.Insert(extension);
485 }
486 }
487 MaybeFinishDelayedInstallations();
dchengc963c7142016-04-08 03:55:22488 std::unique_ptr<extensions::ExtensionPrefs::ExtensionsInfo> delayed_info2(
rkaplowa8fd8d32015-02-25 21:27:56489 extension_prefs_->GetAllDelayedInstallInfo());
490 UMA_HISTOGRAM_COUNTS_100("Extensions.UpdateOnLoad",
491 delayed_info2->size() - delayed_info->size());
[email protected]6014d672008-12-05 00:38:25492}
493
[email protected]2d19eb6e2014-01-27 17:30:00494void ExtensionService::LoadGreylistFromPrefs() {
rkaplowa8fd8d32015-02-25 21:27:56495 TRACE_EVENT0("browser,startup", "ExtensionService::LoadGreylistFromPrefs");
496
dchengc963c7142016-04-08 03:55:22497 std::unique_ptr<ExtensionSet> all_extensions =
[email protected]f47f7172014-03-19 19:27:10498 registry_->GenerateInstalledExtensionsSet();
[email protected]2d19eb6e2014-01-27 17:30:00499
achuith2f5578b2016-02-26 21:57:13500 for (const auto& extension : *all_extensions) {
501 const extensions::BlacklistState state =
502 extension_prefs_->GetExtensionBlacklistState(extension->id());
[email protected]2d19eb6e2014-01-27 17:30:00503 if (state == extensions::BLACKLISTED_SECURITY_VULNERABILITY ||
504 state == extensions::BLACKLISTED_POTENTIALLY_UNWANTED ||
505 state == extensions::BLACKLISTED_CWS_POLICY_VIOLATION)
achuith2f5578b2016-02-26 21:57:13506 greylist_.Insert(extension);
[email protected]2d19eb6e2014-01-27 17:30:00507 }
508}
509
ginkage553af3202015-02-04 12:39:09510bool ExtensionService::UpdateExtension(const extensions::CRXFileInfo& file,
[email protected]044e86992014-01-24 22:59:11511 bool file_ownership_passed,
[email protected]31bb5ee62012-09-12 22:58:40512 CrxInstaller** out_crx_installer) {
[email protected]a29a517a2011-01-21 21:11:12513 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]3c4abc82012-10-22 22:25:54514 if (browser_terminating_) {
515 LOG(WARNING) << "Skipping UpdateExtension due to browser shutdown";
516 // Leak the temp file at extension_path. We don't want to add to the disk
517 // I/O burden at shutdown, we can't rely on the I/O completing anyway, and
518 // the file is in the OS temp directory which should be cleaned up for us.
519 return false;
520 }
[email protected]a8af9fdb2010-10-28 21:52:20521
ginkage553af3202015-02-04 12:39:09522 const std::string& id = file.extension_id;
523
[email protected]3f213ad2012-07-26 23:39:41524 const extensions::PendingExtensionInfo* pending_extension_info =
[email protected]51a3bf8b2012-06-08 22:53:06525 pending_extension_manager()->GetById(id);
[email protected]8ef78fd2010-08-19 17:14:32526
[email protected]695b5712012-12-06 23:55:28527 const Extension* extension = GetInstalledExtension(id);
[email protected]51a3bf8b2012-06-08 22:53:06528 if (!pending_extension_info && !extension) {
[email protected]aa142702010-03-26 01:26:33529 LOG(WARNING) << "Will not update extension " << id
530 << " because it is not installed or pending";
531 // Delete extension_path since we're not creating a CrxInstaller
532 // that would do it for us.
asargentd50b18c2016-04-21 01:17:16533 if (file_ownership_passed &&
534 !GetFileTaskRunner()->PostTask(
[email protected]7f8f24f2012-11-15 19:40:14535 FROM_HERE,
ginkage553af3202015-02-04 12:39:09536 base::Bind(&extensions::file_util::DeleteFile, file.path, false)))
[email protected]14908b72011-04-20 06:54:36537 NOTREACHED();
[email protected]420a0ec2011-06-01 01:07:03538
539 return false;
[email protected]e957fe52009-06-23 16:51:05540 }
541
treibe960e282015-09-11 10:38:08542 scoped_refptr<CrxInstaller> installer(CrxInstaller::CreateSilent(this));
[email protected]6dfbbf82010-03-12 23:09:16543 installer->set_expected_id(id);
ginkage47e603e2015-02-27 08:42:41544 installer->set_expected_hash(file.expected_hash);
[email protected]464213a2013-10-15 01:06:48545 int creation_flags = Extension::NO_FLAGS;
[email protected]51a3bf8b2012-06-08 22:53:06546 if (pending_extension_info) {
547 installer->set_install_source(pending_extension_info->install_source());
pkotwicz31eb1e8ec2014-10-08 15:26:46548 installer->set_allow_silent_install(true);
treibe960e282015-09-11 10:38:08549 // If the extension came in disabled due to a permission increase, then
550 // don't grant it all the permissions. crbug.com/484214
551 bool has_permissions_increase =
552 extensions::ExtensionPrefs::Get(profile_)->HasDisableReason(
553 id, Extension::DISABLE_PERMISSIONS_INCREASE);
554 const base::Version& expected_version = pending_extension_info->version();
555 if (has_permissions_increase ||
556 pending_extension_info->remote_install() ||
557 !expected_version.IsValid()) {
[email protected]21db9ef2014-05-16 02:06:27558 installer->set_grant_permissions(false);
treibe960e282015-09-11 10:38:08559 } else {
560 installer->set_expected_version(expected_version,
561 false /* fail_install_if_unexpected */);
562 }
mamir0128d5a2016-07-15 20:55:48563 creation_flags = pending_extension_info->creation_flags();
[email protected]464213a2013-10-15 01:06:48564 if (pending_extension_info->mark_acknowledged())
[email protected]374ceb6f2014-07-02 19:25:34565 external_install_manager_->AcknowledgeExternalExtension(id);
[email protected]51a3bf8b2012-06-08 22:53:06566 } else if (extension) {
[email protected]5eb375e92010-11-26 07:50:41567 installer->set_install_source(extension->location());
[email protected]51a3bf8b2012-06-08 22:53:06568 }
[email protected]7d8b7072012-04-07 01:07:46569 // If the extension was installed from or has migrated to the webstore, or
[email protected]fcb2c2c2012-10-17 21:08:45570 // its auto-update URL is from the webstore, treat it as a webstore install.
571 // Note that we ignore some older extensions with blank auto-update URLs
572 // because we are mostly concerned with restrictions on NaCl extensions,
573 // which are newer.
[email protected]75764512011-12-19 19:54:28574 if ((extension && extension->from_webstore()) ||
[email protected]4a5fe3e22013-06-04 07:06:38575 (extension && extensions::ManifestURL::UpdatesFromGallery(extension)) ||
[email protected]963d13c2012-09-29 17:13:35576 (!extension && extension_urls::IsWebstoreUpdateUrl(
[email protected]51a3bf8b2012-06-08 22:53:06577 pending_extension_info->update_url()))) {
[email protected]a12ce8b22012-01-17 18:40:53578 creation_flags |= Extension::FROM_WEBSTORE;
579 }
580
581 // Bookmark apps being updated is kind of a contradiction, but that's because
582 // we mark the default apps as bookmark apps, and they're hosted in the web
583 // store, thus they can get updated. See http://crbug.com/101605 for more
584 // details.
585 if (extension && extension->from_bookmark())
586 creation_flags |= Extension::FROM_BOOKMARK;
587
[email protected]e33bbc22012-08-27 22:05:46588 if (extension && extension->was_installed_by_default())
589 creation_flags |= Extension::WAS_INSTALLED_BY_DEFAULT;
590
[email protected]acc3c7c22014-03-19 06:23:39591 if (extension && extension->was_installed_by_oem())
592 creation_flags |= Extension::WAS_INSTALLED_BY_OEM;
593
benwells1dd4acd2015-12-09 02:20:24594 if (extension)
[email protected]c30bda262014-06-19 04:10:13595 installer->set_do_not_sync(extension_prefs_->DoNotSync(id));
[email protected]ab6c7be42014-01-16 02:05:54596
[email protected]a12ce8b22012-01-17 18:40:53597 installer->set_creation_flags(creation_flags);
598
[email protected]044e86992014-01-24 22:59:11599 installer->set_delete_source(file_ownership_passed);
[email protected]cb0e50312011-05-09 15:03:07600 installer->set_install_cause(extension_misc::INSTALL_CAUSE_UPDATE);
ginkage553af3202015-02-04 12:39:09601 installer->InstallCrxFile(file);
[email protected]420a0ec2011-06-01 01:07:03602
603 if (out_crx_installer)
[email protected]dc24976f2013-06-02 21:15:09604 *out_crx_installer = installer.get();
[email protected]420a0ec2011-06-01 01:07:03605
606 return true;
[email protected]e957fe52009-06-23 16:51:05607}
608
catmullings98cd1942016-08-30 22:31:59609void ExtensionService::LoadExtensionsFromCommandLineFlag(
610 const char* switch_name) {
611 if (command_line_->HasSwitch(switch_name)) {
612 base::CommandLine::StringType path_list =
613 command_line_->GetSwitchValueNative(switch_name);
614 base::StringTokenizerT<base::CommandLine::StringType,
615 base::CommandLine::StringType::const_iterator>
616 t(path_list, FILE_PATH_LITERAL(","));
617 while (t.GetNext()) {
618 std::string extension_id;
619 extensions::UnpackedInstaller::Create(this)->LoadFromCommandLine(
620 base::FilePath(t.token()), &extension_id, false /*only-allow-apps*/);
621 // Extension id is added to whitelist after its extension is loaded
622 // because code is executed asynchronously.
623 if (switch_name == switches::kDisableExtensionsExcept)
624 disable_flag_exempted_extensions_.insert(extension_id);
625 }
626 }
627}
628
[email protected]bca4b832014-07-17 20:22:34629void ExtensionService::ReloadExtensionImpl(
[email protected]757d60a2014-05-23 00:11:44630 // "transient" because the process of reloading may cause the reference
631 // to become invalid. Instead, use |extension_id|, a copy.
[email protected]bca4b832014-07-17 20:22:34632 const std::string& transient_extension_id,
633 bool be_noisy) {
[email protected]a29a517a2011-01-21 21:11:12634 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]2a947202013-03-06 04:58:05635
636 // If the extension is already reloading, don't reload again.
[email protected]757d60a2014-05-23 00:11:44637 if (extension_prefs_->GetDisableReasons(transient_extension_id) &
[email protected]2a947202013-03-06 04:58:05638 Extension::DISABLE_RELOAD) {
639 return;
640 }
641
mlerman6a37b6a42014-11-26 22:10:53642 // Ignore attempts to reload a blacklisted or blocked extension. Sometimes
643 // this can happen in a convoluted reload sequence triggered by the
644 // termination of a blacklisted or blocked extension and a naive attempt to
645 // reload it. For an example see http://crbug.com/373842.
646 if (registry_->blacklisted_extensions().Contains(transient_extension_id) ||
647 registry_->blocked_extensions().Contains(transient_extension_id)) {
[email protected]757d60a2014-05-23 00:11:44648 return;
mlerman6a37b6a42014-11-26 22:10:53649 }
[email protected]757d60a2014-05-23 00:11:44650
[email protected]650b2d52013-02-10 03:41:45651 base::FilePath path;
[email protected]757d60a2014-05-23 00:11:44652
653 std::string extension_id = transient_extension_id;
654 const Extension* transient_current_extension =
655 GetExtensionById(extension_id, false);
[email protected]9cddd4702009-07-27 22:09:40656
[email protected]f17dbd42010-08-16 23:21:10657 // Disable the extension if it's loaded. It might not be loaded if it crashed.
[email protected]757d60a2014-05-23 00:11:44658 if (transient_current_extension) {
[email protected]4814b512009-11-07 00:12:29659 // If the extension has an inspector open for its background page, detach
660 // the inspector and hang onto a cookie for it, so that we can reattach
661 // later.
[email protected]31d8f5f22012-04-02 15:22:08662 // TODO(yoz): this is not incognito-safe!
reillyg0ea3fa902014-10-28 15:30:23663 extensions::ProcessManager* manager =
664 extensions::ProcessManager::Get(profile_);
[email protected]3a1dc572012-07-31 22:25:13665 extensions::ExtensionHost* host =
666 manager->GetBackgroundHostForExtension(extension_id);
[email protected]b3f957e62014-08-08 10:09:02667 if (host && DevToolsAgentHost::HasFor(host->host_contents())) {
[email protected]4814b512009-11-07 00:12:29668 // Look for an open inspector for the background page.
[email protected]04ea1bb2013-07-10 09:26:09669 scoped_refptr<DevToolsAgentHost> agent_host =
[email protected]b3f957e62014-08-08 10:09:02670 DevToolsAgentHost::GetOrCreateFor(host->host_contents());
671 agent_host->DisconnectWebContents();
[email protected]04ea1bb2013-07-10 09:26:09672 orphaned_dev_tools_[extension_id] = agent_host;
[email protected]4814b512009-11-07 00:12:29673 }
674
[email protected]757d60a2014-05-23 00:11:44675 path = transient_current_extension->path();
[email protected]58076192013-07-19 19:43:50676 // BeingUpgraded is set back to false when the extension is added.
rdevlin.cronin2c16c602014-11-21 01:35:49677 system_->runtime_data()->SetBeingUpgraded(transient_current_extension->id(),
[email protected]757d60a2014-05-23 00:11:44678 true);
[email protected]44d62b62012-04-11 00:06:03679 DisableExtension(extension_id, Extension::DISABLE_RELOAD);
[email protected]b914e2952013-04-26 07:10:03680 reloading_extensions_.insert(extension_id);
[email protected]1eb175082010-02-10 09:26:16681 } else {
[email protected]d32c02a2014-06-16 22:58:36682 std::map<std::string, base::FilePath>::const_iterator iter =
683 unloaded_extension_paths_.find(extension_id);
684 if (iter == unloaded_extension_paths_.end()) {
685 return;
686 }
[email protected]1eb175082010-02-10 09:26:16687 path = unloaded_extension_paths_[extension_id];
[email protected]b65272f2009-08-31 15:47:06688 }
689
achuith2f5578b2016-02-26 21:57:13690 transient_current_extension = nullptr;
[email protected]757d60a2014-05-23 00:11:44691
[email protected]9f4e4f082013-06-21 07:11:19692 if (delayed_installs_.Contains(extension_id)) {
[email protected]6f6101832012-11-27 22:10:48693 FinishDelayedInstallation(extension_id);
[email protected]0db124b02012-11-07 04:55:05694 return;
695 }
696
[email protected]43ceb002012-02-10 23:19:15697 // If we're reloading a component extension, use the component extension
698 // loader's reloader.
699 if (component_loader_->Exists(extension_id)) {
700 component_loader_->Reload(extension_id);
701 return;
702 }
703
[email protected]e6090e42010-03-23 22:44:08704 // Check the installed extensions to see if what we're reloading was already
705 // installed.
dchengc963c7142016-04-08 03:55:22706 std::unique_ptr<ExtensionInfo> installed_extension(
[email protected]e6090e42010-03-23 22:44:08707 extension_prefs_->GetInstalledExtensionInfo(extension_id));
708 if (installed_extension.get() &&
709 installed_extension->extension_manifest.get()) {
[email protected]d8c8f25f2011-11-02 18:18:01710 extensions::InstalledLoader(this).Load(*installed_extension, false);
[email protected]e6090e42010-03-23 22:44:08711 } else {
[email protected]d8c8f25f2011-11-02 18:18:01712 // Otherwise, the extension is unpacked (location LOAD).
[email protected]e6090e42010-03-23 22:44:08713 // We should always be able to remember the extension's path. If it's not in
714 // the map, someone failed to update |unloaded_extension_paths_|.
715 CHECK(!path.empty());
[email protected]bca4b832014-07-17 20:22:34716 scoped_refptr<extensions::UnpackedInstaller> unpacked_installer =
717 extensions::UnpackedInstaller::Create(this);
718 unpacked_installer->set_be_noisy_on_failure(be_noisy);
719 unpacked_installer->Load(path);
[email protected]e6090e42010-03-23 22:44:08720 }
[email protected]9cddd4702009-07-27 22:09:40721}
722
[email protected]bca4b832014-07-17 20:22:34723void ExtensionService::ReloadExtension(const std::string& extension_id) {
asargentd50b18c2016-04-21 01:17:16724 ReloadExtensionImpl(extension_id, true); // be_noisy
[email protected]bca4b832014-07-17 20:22:34725}
726
727void ExtensionService::ReloadExtensionWithQuietFailure(
728 const std::string& extension_id) {
asargentd50b18c2016-04-21 01:17:16729 ReloadExtensionImpl(extension_id, false); // be_noisy
[email protected]bca4b832014-07-17 20:22:34730}
731
[email protected]757d60a2014-05-23 00:11:44732bool ExtensionService::UninstallExtension(
733 // "transient" because the process of uninstalling may cause the reference
734 // to become invalid. Instead, use |extenson->id()|.
735 const std::string& transient_extension_id,
[email protected]e43c61f2014-07-20 21:46:34736 extensions::UninstallReason reason,
[email protected]42d58f62014-07-31 01:32:45737 const base::Closure& deletion_done_callback,
[email protected]757d60a2014-05-23 00:11:44738 base::string16* error) {
[email protected]a29a517a2011-01-21 21:11:12739 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]a8af9fdb2010-10-28 21:52:20740
[email protected]757d60a2014-05-23 00:11:44741 scoped_refptr<const Extension> extension =
742 GetInstalledExtension(transient_extension_id);
[email protected]631cf822009-05-15 07:01:25743
[email protected]e7afe2452010-08-22 16:19:13744 // Callers should not send us nonexistent extensions.
[email protected]dc24976f2013-06-02 21:15:09745 CHECK(extension.get());
[email protected]9f1087e2009-06-15 17:29:32746
binjincccacef2014-10-13 19:00:20747 ManagementPolicy* by_policy = system_->management_policy();
[email protected]95da88c42011-03-31 10:07:33748 // Policy change which triggers an uninstall will always set
749 // |external_uninstall| to true so this is the only way to uninstall
750 // managed extensions.
[email protected]90878c52014-04-04 18:21:02751 // Shared modules being uninstalled will also set |external_uninstall| to true
752 // so that we can guarantee users don't uninstall a shared module.
753 // (crbug.com/273300)
754 // TODO(rdevlin.cronin): This is probably not right. We should do something
755 // else, like include an enum IS_INTERNAL_UNINSTALL or IS_USER_UNINSTALL so
756 // we don't do this.
[email protected]cc2f55c2014-07-08 02:19:04757 bool external_uninstall =
[email protected]e43c61f2014-07-20 21:46:34758 (reason == extensions::UNINSTALL_REASON_INTERNAL_MANAGEMENT) ||
dtseng9fb3d5b2015-02-23 17:24:17759 (reason == extensions::UNINSTALL_REASON_COMPONENT_REMOVED) ||
rdevlin.cronin5f6b69d2014-09-20 01:23:35760 (reason == extensions::UNINSTALL_REASON_REINSTALL) ||
[email protected]e43c61f2014-07-20 21:46:34761 (reason == extensions::UNINSTALL_REASON_ORPHANED_EXTERNAL_EXTENSION) ||
[email protected]6ef60012014-07-22 19:08:12762 (reason == extensions::UNINSTALL_REASON_ORPHANED_SHARED_MODULE) ||
763 (reason == extensions::UNINSTALL_REASON_SYNC &&
mamir192d7882016-06-22 17:10:16764 extensions::util::WasInstalledByCustodian(extension->id(), profile_));
[email protected]65187152012-06-02 13:14:14765 if (!external_uninstall &&
binjincccacef2014-10-13 19:00:20766 (!by_policy->UserMayModifySettings(extension.get(), error) ||
767 by_policy->MustRemainInstalled(extension.get(), error))) {
[email protected]ad50def52011-10-19 23:17:07768 content::NotificationService::current()->Notify(
[email protected]adf5a102014-07-31 12:44:06769 extensions::NOTIFICATION_EXTENSION_UNINSTALL_NOT_ALLOWED,
[email protected]6c2381d2011-10-19 02:52:53770 content::Source<Profile>(profile_),
[email protected]dc24976f2013-06-02 21:15:09771 content::Details<const Extension>(extension.get()));
[email protected]d6ebc9792011-04-07 18:18:33772 return false;
773 }
[email protected]95da88c42011-03-31 10:07:33774
juncai33e462102015-05-18 20:48:44775 InstallVerifier::Get(GetBrowserContext())->Remove(extension->id());
[email protected]ffd2f79e2013-11-14 00:11:46776
[email protected]9b217652010-10-08 22:04:23777 UMA_HISTOGRAM_ENUMERATION("Extensions.UninstallType",
[email protected]7fa19f82010-12-21 19:40:08778 extension->GetType(), 100);
treib2e0517f92015-05-07 23:15:36779 RecordPermissionMessagesHistogram(extension.get(), "Uninstall");
[email protected]9b217652010-10-08 22:04:23780
[email protected]831aa212010-03-26 13:55:19781 // Unload before doing more cleanup to ensure that nothing is hanging on to
782 // any of these resources.
[email protected]757d60a2014-05-23 00:11:44783 UnloadExtension(extension->id(), UnloadedExtensionInfo::REASON_UNINSTALL);
asargent96c7ec42016-05-27 02:45:47784 if (registry_->blacklisted_extensions().Contains(extension->id()))
785 registry_->RemoveBlacklisted(extension->id());
[email protected]831aa212010-03-26 13:55:19786
[email protected]9f1087e2009-06-15 17:29:32787 // Tell the backend to start deleting installed extensions on the file thread.
[email protected]12075d12013-02-27 05:38:05788 if (!Manifest::IsUnpackedLocation(extension->location())) {
[email protected]7f8f24f2012-11-15 19:40:14789 if (!GetFileTaskRunner()->PostTask(
790 FROM_HERE,
[email protected]5a145e82014-05-29 22:19:07791 base::Bind(&ExtensionService::UninstallExtensionOnFileThread,
792 extension->id(),
793 profile_,
[email protected]85df9d12014-04-15 17:02:14794 install_directory_,
[email protected]5a145e82014-05-29 22:19:07795 extension->path())))
[email protected]14908b72011-04-20 06:54:36796 NOTREACHED();
[email protected]9f1087e2009-06-15 17:29:32797 }
798
[email protected]42d58f62014-07-31 01:32:45799 extensions::DataDeleter::StartDeleting(
800 profile_, extension.get(), deletion_done_callback);
[email protected]0d6ec3a72011-09-02 02:09:43801
[email protected]757d60a2014-05-23 00:11:44802 UntrackTerminatedExtension(extension->id());
[email protected]211030342010-09-30 18:41:06803
804 // Notify interested parties that we've uninstalled this extension.
[email protected]e43c61f2014-07-20 21:46:34805 ExtensionRegistry::Get(profile_)
806 ->TriggerOnUninstalled(extension.get(), reason);
[email protected]d6ebc9792011-04-07 18:18:33807
[email protected]757d60a2014-05-23 00:11:44808 delayed_installs_.Remove(extension->id());
[email protected]0db124b02012-11-07 04:55:05809
[email protected]757d60a2014-05-23 00:11:44810 extension_prefs_->OnExtensionUninstalled(
811 extension->id(), extension->location(), external_uninstall);
[email protected]d4eda592013-09-18 03:37:57812
[email protected]333b1de2011-09-12 18:28:50813 // Track the uninstallation.
[email protected]49098f702011-10-13 03:47:18814 UMA_HISTOGRAM_ENUMERATION("Extensions.ExtensionUninstalled", 1, 2);
815
[email protected]d6ebc9792011-04-07 18:18:33816 return true;
[email protected]c10da4b02010-03-25 14:38:32817}
818
[email protected]5a145e82014-05-29 22:19:07819// static
820void ExtensionService::UninstallExtensionOnFileThread(
821 const std::string& id,
822 Profile* profile,
823 const base::FilePath& install_dir,
824 const base::FilePath& extension_path) {
825 extensions::ExtensionAssetsManager* assets_manager =
826 extensions::ExtensionAssetsManager::GetInstance();
827 assets_manager->UninstallExtension(id, profile, install_dir, extension_path);
828}
829
[email protected]c3cfb012011-04-06 22:07:35830bool ExtensionService::IsExtensionEnabled(
831 const std::string& extension_id) const {
[email protected]bb1bc9b32013-12-21 03:09:14832 if (registry_->enabled_extensions().Contains(extension_id) ||
833 registry_->terminated_extensions().Contains(extension_id)) {
[email protected]36429da2011-07-11 20:25:18834 return true;
[email protected]dc9a74f72012-08-17 18:07:21835 }
[email protected]36429da2011-07-11 20:25:18836
[email protected]bb1bc9b32013-12-21 03:09:14837 if (registry_->disabled_extensions().Contains(extension_id) ||
mlerman6a37b6a42014-11-26 22:10:53838 registry_->blacklisted_extensions().Contains(extension_id) ||
839 registry_->blocked_extensions().Contains(extension_id)) {
[email protected]ad83ca242011-07-29 01:32:25840 return false;
[email protected]695b5712012-12-06 23:55:28841 }
[email protected]ad83ca242011-07-29 01:32:25842
mlerman3690e5be2014-12-01 22:57:44843 // Blocked extensions aren't marked as such in prefs, thus if
844 // |block_extensions_| is true then CanBlockExtension() must be called with an
845 // Extension object. If the |extension_id| is not loaded, assume not enabled.
846 if (block_extensions_) {
847 const Extension* extension = GetInstalledExtension(extension_id);
848 if (!extension || CanBlockExtension(extension))
849 return false;
850 }
mlerman6a37b6a42014-11-26 22:10:53851
[email protected]ad83ca242011-07-29 01:32:25852 // If the extension hasn't been loaded yet, check the prefs for it. Assume
853 // enabled unless otherwise noted.
854 return !extension_prefs_->IsExtensionDisabled(extension_id) &&
[email protected]27e528322014-05-27 20:54:30855 !extension_prefs_->IsExtensionBlacklisted(extension_id) &&
[email protected]f574c402012-12-04 23:20:31856 !extension_prefs_->IsExternalExtensionUninstalled(extension_id);
[email protected]c3cfb012011-04-06 22:07:35857}
858
[email protected]eaa7dd182010-12-14 11:09:00859void ExtensionService::EnableExtension(const std::string& extension_id) {
[email protected]a29a517a2011-01-21 21:11:12860 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]a8af9fdb2010-10-28 21:52:20861
asargent96c7ec42016-05-27 02:45:47862 if (IsExtensionEnabled(extension_id) ||
863 extension_prefs_->IsExtensionBlacklisted(extension_id))
[email protected]0c6da502009-08-14 22:32:39864 return;
[email protected]bb1bc9b32013-12-21 03:09:14865 const Extension* extension =
866 registry_->disabled_extensions().GetByID(extension_id);
[email protected]0d54b682013-11-05 14:15:36867
868 ManagementPolicy* policy = system_->management_policy();
achuith2f5578b2016-02-26 21:57:13869 if (extension && policy->MustRemainDisabled(extension, nullptr, nullptr)) {
[email protected]0d54b682013-11-05 14:15:36870 UMA_HISTOGRAM_COUNTS_100("Extensions.EnableDeniedByPolicy", 1);
871 return;
872 }
[email protected]0c6da502009-08-14 22:32:39873
treib8a6d9892015-08-26 10:23:19874 extension_prefs_->SetExtensionEnabled(extension_id);
[email protected]1784e83a2009-09-08 21:01:52875
treib8a6d9892015-08-26 10:23:19876 // This can happen if sync enables an extension that is not installed yet.
[email protected]06f92562011-04-29 19:27:31877 if (!extension)
878 return;
879
[email protected]0c6da502009-08-14 22:32:39880 // Move it over to the enabled list.
[email protected]bb1bc9b32013-12-21 03:09:14881 registry_->AddEnabled(make_scoped_refptr(extension));
882 registry_->RemoveDisabled(extension->id());
[email protected]0c6da502009-08-14 22:32:39883
[email protected]62d30f42009-10-01 22:36:06884 NotifyExtensionLoaded(extension);
[email protected]3bdba0d2011-08-23 07:17:30885
[email protected]f74d7f32012-06-19 19:22:51886 // Notify listeners that the extension was enabled.
887 content::NotificationService::current()->Notify(
[email protected]adf5a102014-07-31 12:44:06888 extensions::NOTIFICATION_EXTENSION_ENABLED,
[email protected]f74d7f32012-06-19 19:22:51889 content::Source<Profile>(profile_),
890 content::Details<const Extension>(extension));
[email protected]0c6da502009-08-14 22:32:39891}
892
treibc1192322015-05-20 12:56:07893void ExtensionService::DisableExtension(const std::string& extension_id,
894 int disable_reasons) {
[email protected]a29a517a2011-01-21 21:11:12895 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]a8af9fdb2010-10-28 21:52:20896
asargent96c7ec42016-05-27 02:45:47897 if (extension_prefs_->IsExtensionBlacklisted(extension_id))
898 return;
899
treib8a6d9892015-08-26 10:23:19900 // The extension may have been disabled already. Just add the disable reasons.
[email protected]8f959f522014-08-06 06:26:28901 if (!IsExtensionEnabled(extension_id)) {
treibc1192322015-05-20 12:56:07902 extension_prefs_->AddDisableReasons(extension_id, disable_reasons);
[email protected]1784e83a2009-09-08 21:01:52903 return;
[email protected]8f959f522014-08-06 06:26:28904 }
[email protected]1784e83a2009-09-08 21:01:52905
[email protected]06f92562011-04-29 19:27:31906 const Extension* extension = GetInstalledExtension(extension_id);
elijahtaylor49c09c5c2016-07-09 01:06:22907
908 // Shared modules cannot be disabled, they are just resources used by other
909 // extensions, and are not user controlled.
910 if (extension && SharedModuleInfo::IsSharedModule(extension))
911 return;
912
achuith2f5578b2016-02-26 21:57:13913 // |extension| can be nullptr if sync disables an extension that is not
[email protected]06f92562011-04-29 19:27:31914 // installed yet.
[email protected]ab894542014-07-03 12:35:39915 // EXTERNAL_COMPONENT extensions are not generally modifiable by users, but
916 // can be uninstalled by the browser if the user sets extension-specific
917 // preferences.
achuith2f5578b2016-02-26 21:57:13918 if (extension && !(disable_reasons & Extension::DISABLE_RELOAD) &&
asargent56282ab72016-09-09 16:58:03919 !(disable_reasons & Extension::DISABLE_CORRUPTED) &&
treibc1192322015-05-20 12:56:07920 !(disable_reasons & Extension::DISABLE_UPDATE_REQUIRED_BY_POLICY) &&
achuith2f5578b2016-02-26 21:57:13921 !system_->management_policy()->UserMayModifySettings(extension,
922 nullptr) &&
[email protected]ab894542014-07-03 12:35:39923 extension->location() != Manifest::EXTERNAL_COMPONENT) {
[email protected]95da88c42011-03-31 10:07:33924 return;
[email protected]65187152012-06-02 13:14:14925 }
[email protected]95da88c42011-03-31 10:07:33926
treib8a6d9892015-08-26 10:23:19927 extension_prefs_->SetExtensionDisabled(extension_id, disable_reasons);
[email protected]1784e83a2009-09-08 21:01:52928
[email protected]599539802014-01-07 23:06:00929 int include_mask =
930 ExtensionRegistry::EVERYTHING & ~ExtensionRegistry::DISABLED;
931 extension = registry_->GetExtensionById(extension_id, include_mask);
[email protected]06f92562011-04-29 19:27:31932 if (!extension)
933 return;
934
[email protected]45f5b7d2014-01-22 23:47:13935 // The extension is either enabled or terminated.
936 DCHECK(registry_->enabled_extensions().Contains(extension->id()) ||
937 registry_->terminated_extensions().Contains(extension->id()));
[email protected]64742de32013-04-22 08:44:34938
[email protected]5c094792012-09-07 19:44:53939 // Move it over to the disabled list. Don't send a second unload notification
940 // for terminated extensions being disabled.
[email protected]bb1bc9b32013-12-21 03:09:14941 registry_->AddDisabled(make_scoped_refptr(extension));
942 if (registry_->enabled_extensions().Contains(extension->id())) {
943 registry_->RemoveEnabled(extension->id());
[email protected]b0af4792013-10-23 09:12:13944 NotifyExtensionUnloaded(extension, UnloadedExtensionInfo::REASON_DISABLE);
[email protected]5c094792012-09-07 19:44:53945 } else {
[email protected]bb1bc9b32013-12-21 03:09:14946 registry_->RemoveTerminated(extension->id());
[email protected]5c094792012-09-07 19:44:53947 }
[email protected]1784e83a2009-09-08 21:01:52948}
949
[email protected]1abf05e2013-07-09 17:04:36950void ExtensionService::DisableUserExtensions(
951 const std::vector<std::string>& except_ids) {
[email protected]e516e4c2013-06-12 17:41:14952 extensions::ManagementPolicy* management_policy =
953 system_->management_policy();
954 extensions::ExtensionList to_disable;
955
achuith2f5578b2016-02-26 21:57:13956 for (const auto& extension : registry_->enabled_extensions()) {
957 if (management_policy->UserMayModifySettings(extension.get(), nullptr))
958 to_disable.push_back(extension);
[email protected]e516e4c2013-06-12 17:41:14959 }
960
achuith2f5578b2016-02-26 21:57:13961 for (const auto& extension : registry_->terminated_extensions()) {
962 if (management_policy->UserMayModifySettings(extension.get(), nullptr))
963 to_disable.push_back(extension);
964 }
965
966 for (const auto& extension : to_disable) {
967 if (extension->was_installed_by_default() &&
[email protected]3082fe32013-08-06 11:12:38968 extension_urls::IsWebstoreUpdateUrl(
achuith2f5578b2016-02-26 21:57:13969 extensions::ManifestURL::GetUpdateURL(extension.get())))
[email protected]3082fe32013-08-06 11:12:38970 continue;
achuith2f5578b2016-02-26 21:57:13971 const std::string& id = extension->id();
[email protected]1abf05e2013-07-09 17:04:36972 if (except_ids.end() == std::find(except_ids.begin(), except_ids.end(), id))
973 DisableExtension(id, extensions::Extension::DISABLE_USER_ACTION);
[email protected]e516e4c2013-06-12 17:41:14974 }
975}
976
mlerman6a37b6a42014-11-26 22:10:53977// Extensions that are not locked, components or forced by policy should be
978// locked. Extensions are no longer considered enabled or disabled. Blacklisted
979// extensions are now considered both blacklisted and locked.
980void ExtensionService::BlockAllExtensions() {
981 if (block_extensions_)
982 return;
983 block_extensions_ = true;
984
985 // Blacklisted extensions are already unloaded, need not be blocked.
dchengc963c7142016-04-08 03:55:22986 std::unique_ptr<ExtensionSet> extensions =
mlerman6a37b6a42014-11-26 22:10:53987 registry_->GenerateInstalledExtensionsSet(ExtensionRegistry::ENABLED |
988 ExtensionRegistry::DISABLED |
989 ExtensionRegistry::TERMINATED);
990
achuith2f5578b2016-02-26 21:57:13991 for (const auto& extension : *extensions) {
mlerman6a37b6a42014-11-26 22:10:53992 const std::string& id = extension->id();
993
994 if (!CanBlockExtension(extension.get()))
995 continue;
996
997 registry_->RemoveEnabled(id);
998 registry_->RemoveDisabled(id);
999 registry_->RemoveTerminated(id);
1000
1001 registry_->AddBlocked(extension.get());
1002 UnloadExtension(id, extensions::UnloadedExtensionInfo::REASON_LOCK_ALL);
1003 }
1004}
1005
1006// All locked extensions should revert to being either enabled or disabled
1007// as appropriate.
1008void ExtensionService::UnblockAllExtensions() {
1009 block_extensions_ = false;
dchengc963c7142016-04-08 03:55:221010 std::unique_ptr<ExtensionSet> to_unblock =
mlerman6a37b6a42014-11-26 22:10:531011 registry_->GenerateInstalledExtensionsSet(ExtensionRegistry::BLOCKED);
1012
achuith2f5578b2016-02-26 21:57:131013 for (const auto& extension : *to_unblock) {
mlerman6a37b6a42014-11-26 22:10:531014 registry_->RemoveBlocked(extension->id());
1015 AddExtension(extension.get());
1016 }
1017}
1018
[email protected]eaa7dd182010-12-14 11:09:001019void ExtensionService::GrantPermissionsAndEnableExtension(
[email protected]009633c2013-03-07 22:08:281020 const Extension* extension) {
1021 GrantPermissions(extension);
treib2e0517f92015-05-07 23:15:361022 RecordPermissionMessagesHistogram(extension, "ReEnable");
[email protected]8d888c12010-11-30 00:00:251023 EnableExtension(extension->id());
1024}
1025
[email protected]009633c2013-03-07 22:08:281026void ExtensionService::GrantPermissions(const Extension* extension) {
[email protected]be083862012-09-01 03:53:451027 CHECK(extension);
[email protected]8d42db52014-06-20 21:50:501028 extensions::PermissionsUpdater(profile()).GrantActivePermissions(extension);
[email protected]be083862012-09-01 03:53:451029}
1030
[email protected]fe2dd7742011-04-19 22:52:491031// static
1032void ExtensionService::RecordPermissionMessagesHistogram(
[email protected]13c68b62013-05-17 11:29:051033 const Extension* extension, const char* histogram) {
[email protected]de415552013-01-23 04:12:171034 // Since this is called from multiple sources, and since the histogram macros
1035 // use statics, we need to manually lookup the histogram ourselves.
treib2e0517f92015-05-07 23:15:361036 base::HistogramBase* counter = base::LinearHistogram::FactoryGet(
1037 base::StringPrintf("Extensions.Permissions_%s3", histogram),
1038 1,
1039 APIPermission::kEnumBoundary,
1040 APIPermission::kEnumBoundary + 1,
1041 base::HistogramBase::kUmaTargetedHistogramFlag);
1042
1043 base::HistogramBase* counter_has_any = base::BooleanHistogram::FactoryGet(
1044 base::StringPrintf("Extensions.HasPermissions_%s3", histogram),
1045 base::HistogramBase::kUmaTargetedHistogramFlag);
1046
1047 PermissionIDSet permissions =
1048 extensions::PermissionMessageProvider::Get()->GetAllPermissionIDs(
rdevlin.cronine2d0fd02015-09-24 22:35:491049 extension->permissions_data()->active_permissions(),
treib2e0517f92015-05-07 23:15:361050 extension->GetType());
1051 counter_has_any->AddBoolean(!permissions.empty());
1052 for (const PermissionID& id : permissions)
1053 counter->Add(id.id());
[email protected]fe2dd7742011-04-19 22:52:491054}
1055
[email protected]eaa7dd182010-12-14 11:09:001056void ExtensionService::NotifyExtensionLoaded(const Extension* extension) {
[email protected]f9c8c7c72014-07-31 16:42:311057 // The URLRequestContexts need to be first to know that the extension
[email protected]62d30f42009-10-01 22:36:061058 // was loaded, otherwise a race can arise where a renderer that is created
1059 // for the extension may try to load an extension URL with an extension id
[email protected]57a777f72010-03-31 01:09:421060 // that the request context doesn't yet know about. The profile is responsible
1061 // for ensuring its URLRequestContexts appropriately discover the loaded
1062 // extension.
rockot494f0072015-07-29 17:58:071063 system_->RegisterExtensionWithRequestContexts(
1064 extension,
1065 base::Bind(&ExtensionService::OnExtensionRegisteredWithRequestContexts,
1066 AsWeakPtr(), make_scoped_refptr(extension)));
[email protected]62d30f42009-10-01 22:36:061067
rdevlin.cronin5e510e802016-07-26 15:09:201068 renderer_helper_->OnExtensionLoaded(*extension);
[email protected]77a6970c2011-04-23 16:58:561069
[email protected]3442a662012-01-12 08:06:171070 // Tell subsystems that use the EXTENSION_LOADED notification about the new
1071 // extension.
1072 //
1073 // NOTE: It is important that this happen after notifying the renderers about
1074 // the new extensions so that if we navigate to an extension URL in
[email protected]fdc76192014-04-20 21:54:411075 // ExtensionRegistryObserver::OnLoaded or
1076 // NOTIFICATION_EXTENSION_LOADED_DEPRECATED, the
[email protected]dcc47642014-03-26 22:03:491077 // renderer is guaranteed to know about it.
1078 registry_->TriggerOnLoaded(extension);
1079
[email protected]3442a662012-01-12 08:06:171080 content::NotificationService::current()->Notify(
[email protected]adf5a102014-07-31 12:44:061081 extensions::NOTIFICATION_EXTENSION_LOADED_DEPRECATED,
[email protected]3442a662012-01-12 08:06:171082 content::Source<Profile>(profile_),
1083 content::Details<const Extension>(extension));
1084
[email protected]dcc47642014-03-26 22:03:491085 // TODO(kalman): Convert ExtensionSpecialStoragePolicy to a
1086 // BrowserContextKeyedService and use ExtensionRegistryObserver.
[email protected]c8d407e2011-04-28 21:27:171087 profile_->GetExtensionSpecialStoragePolicy()->
rdevlin.croninbc8979a2014-09-30 01:08:501088 GrantRightsForExtension(extension, profile_);
[email protected]c8d407e2011-04-28 21:27:171089
[email protected]dcc47642014-03-26 22:03:491090 // TODO(kalman): This is broken. The crash reporter is process-wide so doesn't
1091 // work properly multi-profile. Besides which, it should be using
1092 // ExtensionRegistryObserver. See http://crbug.com/355029.
[email protected]c8d407e2011-04-28 21:27:171093 UpdateActiveExtensionsInCrashReporter();
1094
[email protected]d695bb12014-06-05 16:16:301095 const extensions::PermissionsData* permissions_data =
[email protected]a6910e72014-06-06 05:04:361096 extension->permissions_data();
[email protected]d695bb12014-06-05 16:16:301097
[email protected]c8d407e2011-04-28 21:27:171098 // If the extension has permission to load chrome://favicon/ resources we need
1099 // to make sure that the FaviconSource is registered with the
1100 // ChromeURLDataManager.
[email protected]d695bb12014-06-05 16:16:301101 if (permissions_data->HasHostPermission(GURL(chrome::kChromeUIFaviconURL))) {
[email protected]c8d407e2011-04-28 21:27:171102 FaviconSource* favicon_source = new FaviconSource(profile_,
1103 FaviconSource::FAVICON);
[email protected]24ea7a12013-01-27 23:54:531104 content::URLDataSource::Add(profile_, favicon_source);
[email protected]c8d407e2011-04-28 21:27:171105 }
[email protected]b07e606e2012-09-15 20:16:151106
[email protected]b07e606e2012-09-15 20:16:151107 // Same for chrome://theme/ resources.
[email protected]d695bb12014-06-05 16:16:301108 if (permissions_data->HasHostPermission(GURL(chrome::kChromeUIThemeURL))) {
[email protected]b07e606e2012-09-15 20:16:151109 ThemeSource* theme_source = new ThemeSource(profile_);
[email protected]24ea7a12013-01-27 23:54:531110 content::URLDataSource::Add(profile_, theme_source);
[email protected]b07e606e2012-09-15 20:16:151111 }
[email protected]b07e606e2012-09-15 20:16:151112
[email protected]5eddc3e2011-10-26 04:33:311113 // Same for chrome://thumb/ resources.
[email protected]d695bb12014-06-05 16:16:301114 if (permissions_data->HasHostPermission(
1115 GURL(chrome::kChromeUIThumbnailURL))) {
[email protected]420e6d92013-09-17 01:48:511116 ThumbnailSource* thumbnail_source = new ThumbnailSource(profile_, false);
[email protected]24ea7a12013-01-27 23:54:531117 content::URLDataSource::Add(profile_, thumbnail_source);
[email protected]5eddc3e2011-10-26 04:33:311118 }
[email protected]62d30f42009-10-01 22:36:061119}
1120
rockot494f0072015-07-29 17:58:071121void ExtensionService::OnExtensionRegisteredWithRequestContexts(
1122 scoped_refptr<const extensions::Extension> extension) {
1123 registry_->AddReady(extension);
1124 if (registry_->enabled_extensions().Contains(extension->id()))
1125 registry_->TriggerOnReady(extension.get());
1126}
1127
[email protected]a9f39a312010-12-23 22:14:271128void ExtensionService::NotifyExtensionUnloaded(
[email protected]814a7bf0f2011-08-13 05:30:591129 const Extension* extension,
[email protected]b0af4792013-10-23 09:12:131130 UnloadedExtensionInfo::Reason reason) {
[email protected]a9f39a312010-12-23 22:14:271131 UnloadedExtensionInfo details(extension, reason);
[email protected]e51232f32014-04-18 20:05:361132
1133 registry_->TriggerOnUnloaded(extension, reason);
1134
[email protected]ad50def52011-10-19 23:17:071135 content::NotificationService::current()->Notify(
[email protected]adf5a102014-07-31 12:44:061136 extensions::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED,
[email protected]6c2381d2011-10-19 02:52:531137 content::Source<Profile>(profile_),
1138 content::Details<UnloadedExtensionInfo>(&details));
[email protected]62d30f42009-10-01 22:36:061139
rdevlin.croninc40d39f2016-08-04 23:42:131140 renderer_helper_->OnExtensionUnloaded(*extension);
[email protected]77a6970c2011-04-23 16:58:561141
[email protected]31d8f5f22012-04-02 15:22:081142 system_->UnregisterExtensionWithRequestContexts(extension->id(), reason);
[email protected]dcc47642014-03-26 22:03:491143
1144 // TODO(kalman): Convert ExtensionSpecialStoragePolicy to a
1145 // BrowserContextKeyedService and use ExtensionRegistryObserver.
[email protected]c8d407e2011-04-28 21:27:171146 profile_->GetExtensionSpecialStoragePolicy()->
1147 RevokeRightsForExtension(extension);
1148
[email protected]b777b332011-04-16 04:01:081149#if defined(OS_CHROMEOS)
[email protected]ac66e452013-01-11 09:21:231150 // Revoke external file access for the extension from its file system context.
1151 // It is safe to access the extension's storage partition at this point. The
1152 // storage partition may get destroyed only after the extension gets unloaded.
[email protected]3a746ec2014-03-15 05:30:561153 GURL site =
1154 extensions::util::GetSiteForExtensionId(extension->id(), profile_);
[email protected]cd501a72014-08-22 19:58:311155 storage::FileSystemContext* filesystem_context =
1156 BrowserContext::GetStoragePartitionForSite(profile_, site)
1157 ->GetFileSystemContext();
[email protected]f19bbf62013-07-09 01:22:321158 if (filesystem_context && filesystem_context->external_backend()) {
1159 filesystem_context->external_backend()->
[email protected]c8d407e2011-04-28 21:27:171160 RevokeAccessForExtension(extension->id());
[email protected]62d30f42009-10-01 22:36:061161 }
[email protected]c8d407e2011-04-28 21:27:171162#endif
1163
[email protected]dcc47642014-03-26 22:03:491164 // TODO(kalman): This is broken. The crash reporter is process-wide so doesn't
1165 // work properly multi-profile. Besides which, it should be using
1166 // ExtensionRegistryObserver::OnExtensionLoaded. See http://crbug.com/355029.
[email protected]c8d407e2011-04-28 21:27:171167 UpdateActiveExtensionsInCrashReporter();
[email protected]62d30f42009-10-01 22:36:061168}
1169
[email protected]599539802014-01-07 23:06:001170content::BrowserContext* ExtensionService::GetBrowserContext() const {
1171 // Implemented in the .cc file to avoid adding a profile.h dependency to
1172 // extension_service.h.
1173 return profile_;
1174}
1175
[email protected]25ae0152011-11-18 14:40:021176bool ExtensionService::is_ready() {
[email protected]4a10006a2013-05-17 23:18:351177 return ready_->is_signaled();
[email protected]25ae0152011-11-18 14:40:021178}
1179
[email protected]7f8f24f2012-11-15 19:40:141180base::SequencedTaskRunner* ExtensionService::GetFileTaskRunner() {
[email protected]dc24976f2013-06-02 21:15:091181 if (file_task_runner_.get())
1182 return file_task_runner_.get();
[email protected]7f8f24f2012-11-15 19:40:141183
1184 // We should be able to interrupt any part of extension install process during
1185 // shutdown. SKIP_ON_SHUTDOWN ensures that not started extension install tasks
1186 // will be ignored/deleted while we will block on started tasks.
1187 std::string token("ext_install-");
1188 token.append(profile_->GetPath().AsUTF8Unsafe());
1189 file_task_runner_ = BrowserThread::GetBlockingPool()->
1190 GetSequencedTaskRunnerWithShutdownBehavior(
1191 BrowserThread::GetBlockingPool()->GetNamedSequenceToken(token),
1192 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN);
[email protected]dc24976f2013-06-02 21:15:091193 return file_task_runner_.get();
[email protected]7f8f24f2012-11-15 19:40:141194}
1195
[email protected]4ee07c62012-08-21 12:40:421196void ExtensionService::CheckManagementPolicy() {
[email protected]0d54b682013-11-05 14:15:361197 std::vector<std::string> to_unload;
1198 std::map<std::string, Extension::DisableReason> to_disable;
binjin8e3d0182014-12-04 16:44:281199 std::vector<std::string> to_enable;
[email protected]695b5712012-12-06 23:55:281200
[email protected]0d54b682013-11-05 14:15:361201 // Loop through the extensions list, finding extensions we need to unload or
1202 // disable.
achuith2f5578b2016-02-26 21:57:131203 for (const auto& extension : registry_->enabled_extensions()) {
binjin8e3d0182014-12-04 16:44:281204 if (!system_->management_policy()->UserMayLoad(extension.get(), nullptr))
[email protected]0d54b682013-11-05 14:15:361205 to_unload.push_back(extension->id());
1206 Extension::DisableReason disable_reason = Extension::DISABLE_NONE;
1207 if (system_->management_policy()->MustRemainDisabled(
binjin8e3d0182014-12-04 16:44:281208 extension.get(), &disable_reason, nullptr))
[email protected]0d54b682013-11-05 14:15:361209 to_disable[extension->id()] = disable_reason;
[email protected]aa96d3a2010-08-21 08:45:251210 }
1211
binjin8e3d0182014-12-04 16:44:281212 extensions::ExtensionManagement* management =
1213 extensions::ExtensionManagementFactory::GetForBrowserContext(profile());
1214
1215 // Loop through the disabled extension list, find extensions to re-enable
1216 // automatically. These extensions are exclusive from the |to_disable| and
1217 // |to_unload| lists constructed above, since disabled_extensions() and
1218 // enabled_extensions() are supposed to be mutually exclusive.
achuith2f5578b2016-02-26 21:57:131219 for (const auto& extension : registry_->disabled_extensions()) {
binjin8e3d0182014-12-04 16:44:281220 // Find all disabled extensions disabled due to minimum version requirement,
1221 // but now satisfying it.
1222 if (management->CheckMinimumVersion(extension.get(), nullptr) &&
1223 extension_prefs_->HasDisableReason(
1224 extension->id(), Extension::DISABLE_UPDATE_REQUIRED_BY_POLICY)) {
1225 // Is DISABLE_UPDATE_REQUIRED_BY_POLICY the *only* reason?
1226 if (extension_prefs_->GetDisableReasons(extension->id()) ==
1227 Extension::DISABLE_UPDATE_REQUIRED_BY_POLICY) {
1228 // We need to enable those disabled *only* due to minimum version
1229 // requirement.
1230 to_enable.push_back(extension->id());
1231 }
1232 extension_prefs_->RemoveDisableReason(
1233 extension->id(), Extension::DISABLE_UPDATE_REQUIRED_BY_POLICY);
1234 }
1235 }
1236
1237 for (const std::string& id : to_unload)
1238 UnloadExtension(id, UnloadedExtensionInfo::REASON_DISABLE);
[email protected]0d54b682013-11-05 14:15:361239
achuith2f5578b2016-02-26 21:57:131240 for (const auto& i : to_disable)
1241 DisableExtension(i.first, i.second);
binjin8e3d0182014-12-04 16:44:281242
1243 // No extension is getting re-enabled here after disabling/unloading
1244 // because to_enable is mutually exclusive to to_disable + to_unload.
1245 for (const std::string& id : to_enable)
1246 EnableExtension(id);
1247
1248 if (updater_.get()) {
1249 // Find all extensions disabled due to minimum version requirement from
1250 // policy (including the ones that got disabled just now), and check
1251 // for update.
1252 extensions::ExtensionUpdater::CheckParams to_recheck;
achuith2f5578b2016-02-26 21:57:131253 for (const auto& extension : registry_->disabled_extensions()) {
binjin8e3d0182014-12-04 16:44:281254 if (extension_prefs_->GetDisableReasons(extension->id()) ==
1255 Extension::DISABLE_UPDATE_REQUIRED_BY_POLICY) {
1256 // The minimum version check is the only thing holding this extension
1257 // back, so check if it can be updated to fix that.
1258 to_recheck.ids.push_back(extension->id());
1259 }
1260 }
1261 if (!to_recheck.ids.empty())
1262 updater_->CheckNow(to_recheck);
1263 }
[email protected]aa96d3a2010-08-21 08:45:251264}
1265
[email protected]31206602011-04-13 23:07:321266void ExtensionService::CheckForUpdatesSoon() {
[email protected]90878c52014-04-04 18:21:021267 // This can legitimately happen in unit tests.
1268 if (!updater_.get())
1269 return;
1270
[email protected]90878c52014-04-04 18:21:021271 updater_->CheckSoon();
[email protected]c3cfb012011-04-06 22:07:351272}
1273
[email protected]8e4560b62011-01-14 10:09:141274// Some extensions will autoupdate themselves externally from Chrome. These
rkaplowa8fd8d32015-02-25 21:27:561275// are typically part of some larger client application package. To support
1276// these, the extension will register its location in the preferences file
[email protected]8e4560b62011-01-14 10:09:141277// (and also, on Windows, in the registry) and this code will periodically
1278// check that location for a .crx file, which it will then install locally if
1279// a new version is available.
rkaplowa8fd8d32015-02-25 21:27:561280// Errors are reported through ExtensionErrorReporter. Success is not
[email protected]8e4560b62011-01-14 10:09:141281// reported.
[email protected]eaa7dd182010-12-14 11:09:001282void ExtensionService::CheckForExternalUpdates() {
[email protected]a29a517a2011-01-21 21:11:121283 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
rkaplowa8fd8d32015-02-25 21:27:561284 TRACE_EVENT0("browser,startup", "ExtensionService::CheckForExternalUpdates");
1285 SCOPED_UMA_HISTOGRAM_TIMER("Extensions.CheckForExternalUpdatesTime");
[email protected]8e4560b62011-01-14 10:09:141286
1287 // Note that this installation is intentionally silent (since it didn't
1288 // go through the front-end). Extensions that are registered in this
1289 // way are effectively considered 'pre-bundled', and so implicitly
1290 // trusted. In general, if something has HKLM or filesystem access,
1291 // they could install an extension manually themselves anyway.
[email protected]a29a517a2011-01-21 21:11:121292
[email protected]8e4560b62011-01-14 10:09:141293 // Ask each external extension provider to give us a call back for each
1294 // extension they know about. See OnExternalExtension(File|UpdateUrl)Found.
achuith2f5578b2016-02-26 21:57:131295 for (const auto& provider : external_extension_providers_)
[email protected]8e4560b62011-01-14 10:09:141296 provider->VisitRegisteredExtension();
[email protected]8e4560b62011-01-14 10:09:141297
[email protected]50067e52011-10-20 23:17:071298 // Do any required work that we would have done after completion of all
1299 // providers.
[email protected]373daf972014-04-10 01:50:441300 if (external_extension_providers_.empty())
[email protected]50067e52011-10-20 23:17:071301 OnAllExternalProvidersReady();
[email protected]9f1087e2009-06-15 17:29:321302}
1303
[email protected]50067e52011-10-20 23:17:071304void ExtensionService::OnExternalProviderReady(
lazyboye8634172016-01-28 00:10:481305 const ExternalProviderInterface* provider) {
[email protected]a29a517a2011-01-21 21:11:121306 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]50067e52011-10-20 23:17:071307 CHECK(provider->IsReady());
[email protected]a29a517a2011-01-21 21:11:121308
1309 // An external provider has finished loading. We only take action
[email protected]8e4560b62011-01-14 10:09:141310 // if all of them are finished. So we check them first.
[email protected]94fde232012-04-27 10:22:301311 if (AreAllExternalProvidersReady())
1312 OnAllExternalProvidersReady();
1313}
1314
1315bool ExtensionService::AreAllExternalProvidersReady() const {
achuith2f5578b2016-02-26 21:57:131316 for (const auto& provider : external_extension_providers_) {
1317 if (!provider->IsReady())
[email protected]94fde232012-04-27 10:22:301318 return false;
[email protected]8e4560b62011-01-14 10:09:141319 }
[email protected]94fde232012-04-27 10:22:301320 return true;
[email protected]50067e52011-10-20 23:17:071321}
1322
1323void ExtensionService::OnAllExternalProvidersReady() {
1324 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]94fde232012-04-27 10:22:301325 base::TimeDelta elapsed = base::Time::Now() - profile_->GetStartTime();
1326 UMA_HISTOGRAM_TIMES("Extension.ExternalProvidersReadyAfter", elapsed);
[email protected]50067e52011-10-20 23:17:071327
1328 // Install any pending extensions.
[email protected]94fde232012-04-27 10:22:301329 if (update_once_all_providers_are_ready_ && updater()) {
1330 update_once_all_providers_are_ready_ = false;
[email protected]4e9b59d2013-12-18 06:47:141331 extensions::ExtensionUpdater::CheckParams params;
1332 params.callback = external_updates_finished_callback_;
1333 updater()->CheckNow(params);
[email protected]8e4560b62011-01-14 10:09:141334 }
1335
1336 // Uninstall all the unclaimed extensions.
dchengc963c7142016-04-08 03:55:221337 std::unique_ptr<extensions::ExtensionPrefs::ExtensionsInfo> extensions_info(
[email protected]8e4560b62011-01-14 10:09:141338 extension_prefs_->GetInstalledExtensionsInfo());
1339 for (size_t i = 0; i < extensions_info->size(); ++i) {
1340 ExtensionInfo* info = extensions_info->at(i).get();
[email protected]1d5e58b2013-01-31 08:41:401341 if (Manifest::IsExternalLocation(info->extension_location))
[email protected]8e4560b62011-01-14 10:09:141342 CheckExternalUninstall(info->extension_id);
1343 }
[email protected]e5af875f2011-10-10 21:09:141344
[email protected]373daf972014-04-10 01:50:441345 error_controller_->ShowErrorIfNeeded();
[email protected]a9aa5932012-01-25 08:27:401346
[email protected]374ceb6f2014-07-02 19:25:341347 external_install_manager_->UpdateExternalExtensionAlert();
[email protected]e5af875f2011-10-10 21:09:141348}
1349
[email protected]a9f39a312010-12-23 22:14:271350void ExtensionService::UnloadExtension(
1351 const std::string& extension_id,
[email protected]b0af4792013-10-23 09:12:131352 UnloadedExtensionInfo::Reason reason) {
[email protected]27e469a2010-01-11 20:35:091353 // Make sure the extension gets deleted after we return from this function.
[email protected]599539802014-01-07 23:06:001354 int include_mask =
1355 ExtensionRegistry::EVERYTHING & ~ExtensionRegistry::TERMINATED;
[email protected]9adb9692010-10-29 23:14:021356 scoped_refptr<const Extension> extension(
[email protected]599539802014-01-07 23:06:001357 registry_->GetExtensionById(extension_id, include_mask));
[email protected]631cf822009-05-15 07:01:251358
[email protected]fa0c96732010-11-17 00:14:231359 // This method can be called via PostTask, so the extension may have been
1360 // unloaded by the time this runs.
[email protected]dc24976f2013-06-02 21:15:091361 if (!extension.get()) {
[email protected]dd163fb02011-05-04 22:22:171362 // In case the extension may have crashed/uninstalled. Allow the profile to
1363 // clean up its RequestContexts.
[email protected]31d8f5f22012-04-02 15:22:081364 system_->UnregisterExtensionWithRequestContexts(extension_id, reason);
[email protected]fa0c96732010-11-17 00:14:231365 return;
[email protected]dd163fb02011-05-04 22:22:171366 }
[email protected]0c6da502009-08-14 22:32:391367
[email protected]1eb175082010-02-10 09:26:161368 // Keep information about the extension so that we can reload it later
1369 // even if it's not permanently installed.
1370 unloaded_extension_paths_[extension->id()] = extension->path();
1371
[email protected]f17dbd42010-08-16 23:21:101372 // Clean up if the extension is meant to be enabled after a reload.
[email protected]b914e2952013-04-26 07:10:031373 reloading_extensions_.erase(extension->id());
[email protected]f17dbd42010-08-16 23:21:101374
[email protected]bb1bc9b32013-12-21 03:09:141375 if (registry_->disabled_extensions().Contains(extension->id())) {
1376 registry_->RemoveDisabled(extension->id());
[email protected]dd163fb02011-05-04 22:22:171377 // Make sure the profile cleans up its RequestContexts when an already
1378 // disabled extension is unloaded (since they are also tracking the disabled
1379 // extensions).
[email protected]31d8f5f22012-04-02 15:22:081380 system_->UnregisterExtensionWithRequestContexts(extension_id, reason);
[email protected]45f5b7d2014-01-22 23:47:131381 // Don't send the unloaded notification. It was sent when the extension
1382 // was disabled.
[email protected]60a174a2013-08-02 20:29:281383 } else {
[email protected]bb1bc9b32013-12-21 03:09:141384 // Remove the extension from the enabled list.
1385 registry_->RemoveEnabled(extension->id());
[email protected]60a174a2013-08-02 20:29:281386 NotifyExtensionUnloaded(extension.get(), reason);
[email protected]0c6da502009-08-14 22:32:391387 }
1388
[email protected]fb789532013-08-27 02:40:211389 content::NotificationService::current()->Notify(
[email protected]adf5a102014-07-31 12:44:061390 extensions::NOTIFICATION_EXTENSION_REMOVED,
[email protected]fb789532013-08-27 02:40:211391 content::Source<Profile>(profile_),
1392 content::Details<const Extension>(extension.get()));
[email protected]631cf822009-05-15 07:01:251393}
1394
[email protected]8b1ec202013-09-05 02:09:501395void ExtensionService::RemoveComponentExtension(
1396 const std::string& extension_id) {
1397 scoped_refptr<const Extension> extension(
1398 GetExtensionById(extension_id, false));
[email protected]b0af4792013-10-23 09:12:131399 UnloadExtension(extension_id, UnloadedExtensionInfo::REASON_UNINSTALL);
[email protected]ebe07772014-05-22 04:16:061400 if (extension.get()) {
[email protected]e43c61f2014-07-20 21:46:341401 ExtensionRegistry::Get(profile_)->TriggerOnUninstalled(
dtseng9fb3d5b2015-02-23 17:24:171402 extension.get(), extensions::UNINSTALL_REASON_COMPONENT_REMOVED);
[email protected]ebe07772014-05-22 04:16:061403 }
[email protected]8b1ec202013-09-05 02:09:501404}
1405
[email protected]bb1bc9b32013-12-21 03:09:141406void ExtensionService::UnloadAllExtensionsForTest() {
1407 UnloadAllExtensionsInternal();
[email protected]9f1087e2009-06-15 17:29:321408}
1409
[email protected]bb1bc9b32013-12-21 03:09:141410void ExtensionService::ReloadExtensionsForTest() {
1411 // Calling UnloadAllExtensionsForTest here triggers a false-positive presubmit
1412 // warning about calling test code in production.
1413 UnloadAllExtensionsInternal();
[email protected]eac88332012-12-26 17:57:451414 component_loader_->LoadAll();
[email protected]d8c8f25f2011-11-02 18:18:011415 extensions::InstalledLoader(this).LoadAllExtensions();
[email protected]4a10006a2013-05-17 23:18:351416 // Don't call SetReadyAndNotifyListeners() since tests call this multiple
1417 // times.
[email protected]9f1087e2009-06-15 17:29:321418}
1419
[email protected]820d9bd2013-04-03 03:46:031420void ExtensionService::SetReadyAndNotifyListeners() {
rkaplowa8fd8d32015-02-25 21:27:561421 TRACE_EVENT0("browser,startup",
1422 "ExtensionService::SetReadyAndNotifyListeners");
1423 SCOPED_UMA_HISTOGRAM_TIMER(
1424 "Extensions.ExtensionServiceNotifyReadyListenersTime");
1425
[email protected]4a10006a2013-05-17 23:18:351426 ready_->Signal();
[email protected]820d9bd2013-04-03 03:46:031427 content::NotificationService::current()->Notify(
[email protected]adf5a102014-07-31 12:44:061428 extensions::NOTIFICATION_EXTENSIONS_READY_DEPRECATED,
[email protected]820d9bd2013-04-03 03:46:031429 content::Source<Profile>(profile_),
1430 content::NotificationService::NoDetails());
1431}
1432
[email protected]eaa7dd182010-12-14 11:09:001433void ExtensionService::OnLoadedInstalledExtensions() {
[email protected]3eeddd892013-04-17 17:00:111434 if (updater_)
[email protected]93fd78f42009-07-10 16:43:171435 updater_->Start();
[email protected]fa6a9102010-11-22 15:38:501436
elijahtaylor49c09c5c2016-07-09 01:06:221437 // Enable any Shared Modules that incorrectly got disabled previously.
1438 // This is temporary code to fix incorrect behavior from previous versions of
1439 // Chrome and can be removed after several releases (perhaps M60).
1440 extensions::ExtensionList to_enable;
1441 for (const auto& extension : registry_->disabled_extensions()) {
1442 if (SharedModuleInfo::IsSharedModule(extension.get()))
1443 to_enable.push_back(extension);
1444 }
1445 for (const auto& extension : to_enable) {
1446 EnableExtension(extension->id());
1447 }
1448
[email protected]bc151cf92013-02-12 04:57:261449 OnBlacklistUpdated();
[email protected]e72e8eb82009-06-18 17:21:511450}
1451
[email protected]fcb58a862012-05-01 01:03:151452void ExtensionService::AddExtension(const Extension* extension) {
[email protected]c8d407e2011-04-28 21:27:171453 // TODO(jstritar): We may be able to get rid of this branch by overriding the
1454 // default extension state to DISABLED when the --disable-extensions flag
1455 // is set (http://crbug.com/29067).
catmullings98cd1942016-08-30 22:31:591456 if (!extensions_enabled() && !extension->is_theme() &&
[email protected]1d5e58b2013-01-31 08:41:401457 extension->location() != Manifest::COMPONENT &&
catmullings98cd1942016-08-30 22:31:591458 !Manifest::IsExternalLocation(extension->location()) &&
1459 disable_flag_exempted_extensions_.count(extension->id()) == 0) {
[email protected]fcb58a862012-05-01 01:03:151460 return;
[email protected]330840c2012-08-29 22:21:011461 }
[email protected]c8d407e2011-04-28 21:27:171462
[email protected]b914e2952013-04-26 07:10:031463 bool is_extension_upgrade = false;
treib6e51bca2016-06-15 10:26:031464 bool is_extension_loaded = false;
[email protected]116d40e2013-08-08 17:23:171465 const Extension* old = GetInstalledExtension(extension->id());
1466 if (old) {
treib6e51bca2016-06-15 10:26:031467 is_extension_loaded = true;
[email protected]116d40e2013-08-08 17:23:171468 int version_compare_result =
1469 extension->version()->CompareTo(*(old->version()));
1470 is_extension_upgrade = version_compare_result > 0;
[email protected]b914e2952013-04-26 07:10:031471 // Other than for unpacked extensions, CrxInstaller should have guaranteed
1472 // that we aren't downgrading.
1473 if (!Manifest::IsUnpackedLocation(extension->location()))
[email protected]116d40e2013-08-08 17:23:171474 CHECK_GE(version_compare_result, 0);
[email protected]b914e2952013-04-26 07:10:031475 }
rdevlin.cronin2c16c602014-11-21 01:35:491476 // If the extension was disabled for a reload, then enable it.
1477 bool reloading = reloading_extensions_.erase(extension->id()) > 0;
1478
1479 // Set the upgraded bit; we consider reloads upgrades.
1480 system_->runtime_data()->SetBeingUpgraded(extension->id(),
1481 is_extension_upgrade || reloading);
[email protected]c8d407e2011-04-28 21:27:171482
[email protected]1eb175082010-02-10 09:26:161483 // The extension is now loaded, remove its data from unloaded extension map.
1484 unloaded_extension_paths_.erase(extension->id());
1485
[email protected]bb7f40952011-01-13 00:21:201486 // If a terminated extension is loaded, remove it from the terminated list.
1487 UntrackTerminatedExtension(extension->id());
1488
[email protected]b914e2952013-04-26 07:10:031489 // Check if the extension's privileges have changed and mark the
1490 // extension disabled if necessary.
treib6e51bca2016-06-15 10:26:031491 CheckPermissionsIncrease(extension, is_extension_loaded);
[email protected]b914e2952013-04-26 07:10:031492
treib6e51bca2016-06-15 10:26:031493 if (is_extension_loaded && !reloading) {
[email protected]ca2e82022013-04-29 16:48:411494 // To upgrade an extension in place, unload the old one and then load the
1495 // new one. ReloadExtension disables the extension, which is sufficient.
[email protected]b0af4792013-10-23 09:12:131496 UnloadExtension(extension->id(), UnloadedExtensionInfo::REASON_UPDATE);
[email protected]b914e2952013-04-26 07:10:031497 }
[email protected]0c6da502009-08-14 22:32:391498
[email protected]695b5712012-12-06 23:55:281499 if (extension_prefs_->IsExtensionBlacklisted(extension->id())) {
[email protected]ac875372013-02-28 04:36:091500 // Only prefs is checked for the blacklist. We rely on callers to check the
1501 // blacklist before calling into here, e.g. CrxInstaller checks before
[email protected]9f3c8532013-07-31 19:52:071502 // installation then threads through the install and pending install flow
1503 // of this class, and we check when loading installed extensions.
[email protected]bb1bc9b32013-12-21 03:09:141504 registry_->AddBlacklisted(extension);
mlerman6a37b6a42014-11-26 22:10:531505 } else if (block_extensions_ && CanBlockExtension(extension)) {
1506 registry_->AddBlocked(extension);
[email protected]ca2e82022013-04-29 16:48:411507 } else if (!reloading &&
1508 extension_prefs_->IsExtensionDisabled(extension->id())) {
[email protected]bb1bc9b32013-12-21 03:09:141509 registry_->AddDisabled(extension);
[email protected]44d62b62012-04-11 00:06:031510 content::NotificationService::current()->Notify(
[email protected]adf5a102014-07-31 12:44:061511 extensions::NOTIFICATION_EXTENSION_UPDATE_DISABLED,
[email protected]44d62b62012-04-11 00:06:031512 content::Source<Profile>(profile_),
1513 content::Details<const Extension>(extension));
[email protected]62f051c2012-03-29 17:04:441514
[email protected]21db9ef2014-05-16 02:06:271515 // Show the extension disabled error if a permissions increase or a remote
1516 // installation is the reason it was disabled, and no other reasons exist.
1517 int reasons = extension_prefs_->GetDisableReasons(extension->id());
1518 const int kReasonMask = Extension::DISABLE_PERMISSIONS_INCREASE |
1519 Extension::DISABLE_REMOTE_INSTALL;
1520 if (reasons & kReasonMask && !(reasons & ~kReasonMask)) {
1521 extensions::AddExtensionDisabledError(
1522 this,
1523 extension,
1524 extension_prefs_->HasDisableReason(
1525 extension->id(), Extension::DISABLE_REMOTE_INSTALL));
[email protected]62f051c2012-03-29 17:04:441526 }
[email protected]ca2e82022013-04-29 16:48:411527 } else if (reloading) {
1528 // Replace the old extension with the new version.
[email protected]bb1bc9b32013-12-21 03:09:141529 CHECK(!registry_->AddDisabled(extension));
[email protected]ca2e82022013-04-29 16:48:411530 EnableExtension(extension->id());
[email protected]695b5712012-12-06 23:55:281531 } else {
1532 // All apps that are displayed in the launcher are ordered by their ordinals
1533 // so we must ensure they have valid ordinals.
1534 if (extension->RequiresSortOrdinal()) {
deepak.m14ba69e62015-11-17 05:42:121535 AppSorting* app_sorting =
1536 extensions::ExtensionSystem::Get(GetBrowserContext())->app_sorting();
1537 app_sorting->SetExtensionVisible(
[email protected]db378322014-07-21 23:19:341538 extension->id(),
benwells1dd4acd2015-12-09 02:20:241539 extension->ShouldDisplayInNewTabPage());
1540 app_sorting->EnsureValidOrdinals(extension->id(),
1541 syncer::StringOrdinal());
[email protected]695b5712012-12-06 23:55:281542 }
1543
[email protected]bb1bc9b32013-12-21 03:09:141544 registry_->AddEnabled(extension);
[email protected]695b5712012-12-06 23:55:281545 NotifyExtensionLoaded(extension);
[email protected]f574c402012-12-04 23:20:311546 }
rdevlin.cronin2c16c602014-11-21 01:35:491547 system_->runtime_data()->SetBeingUpgraded(extension->id(), false);
[email protected]aab98a52009-12-02 03:22:351548}
1549
[email protected]8c484b742012-11-29 06:05:361550void ExtensionService::AddComponentExtension(const Extension* extension) {
1551 const std::string old_version_string(
1552 extension_prefs_->GetVersionString(extension->id()));
pwnallcbd73192016-08-22 18:59:171553 const base::Version old_version(old_version_string);
[email protected]8c484b742012-11-29 06:05:361554
[email protected]0181a7d2013-11-12 01:08:421555 VLOG(1) << "AddComponentExtension " << extension->name();
robpercivaldcd8b102016-01-25 19:39:001556 if (!old_version.IsValid() || old_version != *extension->version()) {
[email protected]8c484b742012-11-29 06:05:361557 VLOG(1) << "Component extension " << extension->name() << " ("
1558 << extension->id() << ") installing/upgrading from '"
1559 << old_version_string << "' to " << extension->version()->GetString();
1560
1561 AddNewOrUpdatedExtension(extension,
[email protected]9ae73962014-08-14 16:53:411562 Extension::ENABLED,
[email protected]4a1d9c0d2014-06-13 12:50:111563 extensions::kInstallFlagNone,
[email protected]d8fd0fd2014-03-24 13:16:061564 syncer::StringOrdinal(),
1565 std::string());
[email protected]8c484b742012-11-29 06:05:361566 return;
1567 }
1568
1569 AddExtension(extension);
1570}
1571
[email protected]b914e2952013-04-26 07:10:031572void ExtensionService::CheckPermissionsIncrease(const Extension* extension,
treib6e51bca2016-06-15 10:26:031573 bool is_extension_loaded) {
[email protected]23a85362014-07-07 23:26:191574 extensions::PermissionsUpdater(profile_).InitializePermissions(extension);
[email protected]902fd7b2011-07-27 18:42:311575
[email protected]8d888c12010-11-30 00:00:251576 // We keep track of all permissions the user has granted each extension.
1577 // This allows extensions to gracefully support backwards compatibility
1578 // by including unknown permissions in their manifests. When the user
1579 // installs the extension, only the recognized permissions are recorded.
1580 // When the unknown permissions become recognized (e.g., through browser
1581 // upgrade), we can prompt the user to accept these new permissions.
1582 // Extensions can also silently upgrade to less permissions, and then
1583 // silently upgrade to a version that adds these permissions back.
1584 //
1585 // For example, pretend that Chrome 10 includes a permission "omnibox"
1586 // for an API that adds suggestions to the omnibox. An extension can
1587 // maintain backwards compatibility while still having "omnibox" in the
1588 // manifest. If a user installs the extension on Chrome 9, the browser
1589 // will record the permissions it recognized, not including "omnibox."
1590 // When upgrading to Chrome 10, "omnibox" will be recognized and Chrome
1591 // will disable the extension and prompt the user to approve the increase
1592 // in privileges. The extension could then release a new version that
1593 // removes the "omnibox" permission. When the user upgrades, Chrome will
1594 // still remember that "omnibox" had been granted, so that if the
1595 // extension once again includes "omnibox" in an upgrade, the extension
1596 // can upgrade without requiring this user's approval.
[email protected]eb5e4f92012-08-15 23:33:281597 int disable_reasons = extension_prefs_->GetDisableReasons(extension->id());
[email protected]8d888c12010-11-30 00:00:251598
rockot1d4a06262015-02-17 19:39:281599 // Silently grant all active permissions to default apps and apps installed
1600 // in kiosk mode.
[email protected]211a3f32013-05-28 21:48:181601 bool auto_grant_permission =
rockot1d4a06262015-02-17 19:39:281602 extension->was_installed_by_default() ||
[email protected]45928b682013-11-28 08:20:271603 extensions::ExtensionsBrowserClient::Get()->IsRunningInForcedAppMode();
[email protected]211a3f32013-05-28 21:48:181604 if (auto_grant_permission)
[email protected]b914e2952013-04-26 07:10:031605 GrantPermissions(extension);
1606
1607 bool is_privilege_increase = false;
1608 // We only need to compare the granted permissions to the current permissions
rockot1d4a06262015-02-17 19:39:281609 // if the extension has not been auto-granted its permissions above and is
1610 // installed internally.
1611 if (extension->location() == Manifest::INTERNAL && !auto_grant_permission) {
[email protected]8d888c12010-11-30 00:00:251612 // Add all the recognized permissions if the granted permissions list
1613 // hasn't been initialized yet.
dchengc963c7142016-04-08 03:55:221614 std::unique_ptr<const PermissionSet> granted_permissions =
[email protected]902fd7b2011-07-27 18:42:311615 extension_prefs_->GetGrantedPermissions(extension->id());
[email protected]0d3e4a22011-06-23 19:02:521616 CHECK(granted_permissions.get());
[email protected]8d888c12010-11-30 00:00:251617
1618 // Here, we check if an extension's privileges have increased in a manner
1619 // that requires the user's approval. This could occur because the browser
1620 // upgraded and recognized additional privileges, or an extension upgrades
1621 // to a version that requires additional privileges.
[email protected]c41003472013-10-19 15:37:251622 is_privilege_increase =
1623 extensions::PermissionMessageProvider::Get()->IsPrivilegeIncrease(
rdevlin.cronind630c302015-09-30 20:19:331624 *granted_permissions,
rdevlin.cronine2d0fd02015-09-24 22:35:491625 extension->permissions_data()->active_permissions(),
[email protected]076ebeda2014-06-06 21:47:261626 extension->GetType());
treib2c20f9442016-05-18 19:50:281627
1628 // If there was no privilege increase, the extension might still have new
1629 // permissions (which either don't generate a warning message, or whose
1630 // warning messages are suppressed by existing permissions). Grant the new
1631 // permissions.
1632 if (!is_privilege_increase)
1633 GrantPermissions(extension);
[email protected]8d888c12010-11-30 00:00:251634 }
1635
treib6e51bca2016-06-15 10:26:031636 bool previously_disabled =
1637 extension_prefs_->IsExtensionDisabled(extension->id());
1638 // TODO(treib): Is the |is_extension_loaded| check needed here?
1639 if (is_extension_loaded && previously_disabled) {
treib8a6d9892015-08-26 10:23:191640 // Legacy disabled extensions do not have a disable reason. Infer that it
1641 // was likely disabled by the user.
treib6e51bca2016-06-15 10:26:031642 if (disable_reasons == Extension::DISABLE_NONE)
[email protected]7e9e2422012-12-13 19:54:191643 disable_reasons |= Extension::DISABLE_USER_ACTION;
treib8a6d9892015-08-26 10:23:191644
[email protected]7e9e2422012-12-13 19:54:191645 // Extensions that came to us disabled from sync need a similar inference,
1646 // except based on the new version's permissions.
treib3b91e9f2015-11-04 11:29:411647 // TODO(treib,devlin): Since M48, DISABLE_UNKNOWN_FROM_SYNC isn't used
1648 // anymore; this code is still here to migrate any existing old state.
1649 // Remove it after some grace period.
treib6e51bca2016-06-15 10:26:031650 if (disable_reasons & Extension::DEPRECATED_DISABLE_UNKNOWN_FROM_SYNC) {
[email protected]7e9e2422012-12-13 19:54:191651 // Remove the DISABLE_UNKNOWN_FROM_SYNC reason.
treib3b91e9f2015-11-04 11:29:411652 disable_reasons &= ~Extension::DEPRECATED_DISABLE_UNKNOWN_FROM_SYNC;
treib8a6d9892015-08-26 10:23:191653 extension_prefs_->RemoveDisableReason(
treib3b91e9f2015-11-04 11:29:411654 extension->id(), Extension::DEPRECATED_DISABLE_UNKNOWN_FROM_SYNC);
treib8a6d9892015-08-26 10:23:191655 // If there was no privilege increase, it was likely disabled by the user.
[email protected]7e9e2422012-12-13 19:54:191656 if (!is_privilege_increase)
1657 disable_reasons |= Extension::DISABLE_USER_ACTION;
1658 }
[email protected]8d888c12010-11-30 00:00:251659 }
1660
treib6e51bca2016-06-15 10:26:031661 // If the extension is disabled due to a permissions increase, but does in
1662 // fact have all permissions, remove that disable reason.
1663 // TODO(devlin): This was added to fix crbug.com/616474, but it's unclear
1664 // if this behavior should stay forever.
1665 if (disable_reasons & Extension::DISABLE_PERMISSIONS_INCREASE) {
1666 bool reset_permissions_increase = false;
1667 if (!is_privilege_increase) {
1668 reset_permissions_increase = true;
1669 disable_reasons &= ~Extension::DISABLE_PERMISSIONS_INCREASE;
1670 extension_prefs_->RemoveDisableReason(
1671 extension->id(), Extension::DISABLE_PERMISSIONS_INCREASE);
1672 }
1673 UMA_HISTOGRAM_BOOLEAN("Extensions.ResetPermissionsIncrease",
1674 reset_permissions_increase);
1675 }
1676
[email protected]8d888c12010-11-30 00:00:251677 // Extension has changed permissions significantly. Disable it. A
[email protected]21db9ef2014-05-16 02:06:271678 // notification should be sent by the caller. If the extension is already
1679 // disabled because it was installed remotely, don't add another disable
treibaac30ec2015-06-10 09:18:091680 // reason.
1681 if (is_privilege_increase &&
treib8a6d9892015-08-26 10:23:191682 !(disable_reasons & Extension::DISABLE_REMOTE_INSTALL)) {
[email protected]7e9e2422012-12-13 19:54:191683 disable_reasons |= Extension::DISABLE_PERMISSIONS_INCREASE;
treib8a6d9892015-08-26 10:23:191684 if (!extension_prefs_->DidExtensionEscalatePermissions(extension->id()))
treib2e0517f92015-05-07 23:15:361685 RecordPermissionMessagesHistogram(extension, "AutoDisable");
treib8ecc1eb52015-03-04 18:29:061686
1687#if defined(ENABLE_SUPERVISED_USERS)
1688 // If a custodian-installed extension is disabled for a supervised user due
mamir51e05d02016-10-06 10:55:011689 // to a permissions increase, send a request to the custodian.
treib3202d592015-07-31 08:33:161690 if (extensions::util::IsExtensionSupervised(extension, profile_) &&
treib40d3ad92015-10-20 18:15:421691 !ExtensionSyncService::Get(profile_)->HasPendingReenable(
1692 extension->id(), *extension->version())) {
treib8ecc1eb52015-03-04 18:29:061693 SupervisedUserService* supervised_user_service =
1694 SupervisedUserServiceFactory::GetForProfile(profile_);
treib40d3ad92015-10-20 18:15:421695 supervised_user_service->AddExtensionUpdateRequest(extension->id(),
1696 *extension->version());
treib8ecc1eb52015-03-04 18:29:061697 }
1698#endif
[email protected]b914e2952013-04-26 07:10:031699 }
treib6e51bca2016-06-15 10:26:031700
1701 if (disable_reasons == Extension::DISABLE_NONE)
1702 extension_prefs_->SetExtensionEnabled(extension->id());
1703 else
treib8a6d9892015-08-26 10:23:191704 extension_prefs_->SetExtensionDisabled(extension->id(), disable_reasons);
[email protected]8d888c12010-11-30 00:00:251705}
1706
[email protected]eaa7dd182010-12-14 11:09:001707void ExtensionService::UpdateActiveExtensionsInCrashReporter() {
[email protected]c8865962009-12-16 07:47:391708 std::set<std::string> extension_ids;
achuith2f5578b2016-02-26 21:57:131709 for (const auto& extension : registry_->enabled_extensions()) {
[email protected]1d5e58b2013-01-31 08:41:401710 if (!extension->is_theme() && extension->location() != Manifest::COMPONENT)
[email protected]84df8332011-12-06 18:22:461711 extension_ids.insert(extension->id());
[email protected]aab98a52009-12-02 03:22:351712 }
1713
[email protected]dcc47642014-03-26 22:03:491714 // TODO(kalman): This is broken. ExtensionService is per-profile.
1715 // crash_keys::SetActiveExtensions is per-process. See
1716 // http://crbug.com/355029.
[email protected]f6431be82013-09-07 02:53:451717 crash_keys::SetActiveExtensions(extension_ids);
[email protected]6014d672008-12-05 00:38:251718}
1719
[email protected]8266d662011-07-12 21:53:261720void ExtensionService::OnExtensionInstalled(
[email protected]36a5c4c2011-12-14 16:34:501721 const Extension* extension,
[email protected]98270432012-09-11 20:51:241722 const syncer::StringOrdinal& page_ordinal,
[email protected]4a1d9c0d2014-06-13 12:50:111723 int install_flags) {
[email protected]a29a517a2011-01-21 21:11:121724 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]a8af9fdb2010-10-28 21:52:201725
[email protected]c3cfb012011-04-06 22:07:351726 const std::string& id = extension->id();
binjin47947f842014-11-18 12:10:241727 int disable_reasons = GetDisableReasonsOnInstalled(extension);
[email protected]d8fd0fd2014-03-24 13:16:061728 std::string install_parameter;
[email protected]96aebe22014-07-16 04:07:511729 const extensions::PendingExtensionInfo* pending_extension_info =
1730 pending_extension_manager()->GetById(id);
1731 if (pending_extension_info) {
[email protected]8f3bcbd2013-06-05 08:42:401732 if (!pending_extension_info->ShouldAllowInstall(extension)) {
treib227b2582015-12-09 09:28:261733 // Hack for crbug.com/558299, see comment on DeleteThemeDoNotUse.
1734 if (extension->is_theme() && pending_extension_info->is_from_sync())
1735 ExtensionSyncService::Get(profile_)->DeleteThemeDoNotUse(*extension);
1736
[email protected]51a3bf8b2012-06-08 22:53:061737 pending_extension_manager()->Remove(id);
[email protected]8ef78fd2010-08-19 17:14:321738
[email protected]31bb5ee62012-09-12 22:58:401739 LOG(WARNING) << "ShouldAllowInstall() returned false for "
1740 << id << " of type " << extension->GetType()
[email protected]65348062013-01-15 07:27:221741 << " and update URL "
1742 << extensions::ManifestURL::GetUpdateURL(extension).spec()
[email protected]31bb5ee62012-09-12 22:58:401743 << "; not installing";
[email protected]ae6cb3022011-04-04 20:11:541744
[email protected]4416c5a2010-06-26 01:28:571745 // Delete the extension directory since we're not going to
1746 // load it.
[email protected]7f8f24f2012-11-15 19:40:141747 if (!GetFileTaskRunner()->PostTask(
1748 FROM_HERE,
[email protected]85df9d12014-04-15 17:02:141749 base::Bind(&extensions::file_util::DeleteFile,
1750 extension->path(),
1751 true))) {
[email protected]14908b72011-04-20 06:54:361752 NOTREACHED();
[email protected]31bb5ee62012-09-12 22:58:401753 }
[email protected]4416c5a2010-06-26 01:28:571754 return;
1755 }
[email protected]51a3bf8b2012-06-08 22:53:061756
[email protected]d8fd0fd2014-03-24 13:16:061757 install_parameter = pending_extension_info->install_parameter();
[email protected]51a3bf8b2012-06-08 22:53:061758 pending_extension_manager()->Remove(id);
[email protected]4416c5a2010-06-26 01:28:571759 } else {
[email protected]c3cfb012011-04-06 22:07:351760 // We explicitly want to re-enable an uninstalled external
1761 // extension; if we're here, that means the user is manually
1762 // installing the extension.
[email protected]46f3e102014-03-25 01:22:451763 if (extension_prefs_->IsExternalExtensionUninstalled(id)) {
binjin47947f842014-11-18 12:10:241764 disable_reasons = Extension::DISABLE_NONE;
[email protected]6cc7dbae2011-04-29 21:18:331765 }
[email protected]aa142702010-03-26 01:26:331766 }
1767
asargente4de9f92016-09-15 01:40:061768 // If the old version of the extension was disabled due to corruption, this
1769 // new install may correct the problem.
1770 disable_reasons &= ~Extension::DISABLE_CORRUPTED;
1771
[email protected]98270432012-09-11 20:51:241772 // Unsupported requirements overrides the management policy.
[email protected]4a1d9c0d2014-06-13 12:50:111773 if (install_flags & extensions::kInstallFlagHasRequirementErrors) {
binjin47947f842014-11-18 12:10:241774 disable_reasons |= Extension::DISABLE_UNSUPPORTED_REQUIREMENT;
binjin8e3d0182014-12-04 16:44:281775 } else {
1776 // Requirement is supported now, remove the corresponding disable reason
1777 // instead.
binjin8e3d0182014-12-04 16:44:281778 disable_reasons &= ~Extension::DISABLE_UNSUPPORTED_REQUIREMENT;
1779 }
1780
1781 // Check if the extension was disabled because of the minimum version
1782 // requirements from enterprise policy, and satisfies it now.
1783 if (extensions::ExtensionManagementFactory::GetForBrowserContext(profile())
1784 ->CheckMinimumVersion(extension, nullptr)) {
1785 // And remove the corresponding disable reason.
binjin8e3d0182014-12-04 16:44:281786 disable_reasons &= ~Extension::DISABLE_UPDATE_REQUIRED_BY_POLICY;
[email protected]98270432012-09-11 20:51:241787 }
1788
[email protected]4a1d9c0d2014-06-13 12:50:111789 if (install_flags & extensions::kInstallFlagIsBlacklistedForMalware) {
[email protected]9f3c8532013-07-31 19:52:071790 // Installation of a blacklisted extension can happen from sync, policy,
1791 // etc, where to maintain consistency we need to install it, just never
1792 // load it (see AddExtension). Usually it should be the job of callers to
treibaac30ec2015-06-10 09:18:091793 // intercept blacklisted extensions earlier (e.g. CrxInstaller, before even
[email protected]9f3c8532013-07-31 19:52:071794 // showing the install dialogue).
[email protected]7c82539c2014-02-19 06:09:171795 extension_prefs_->AcknowledgeBlacklistedExtension(id);
[email protected]9f3c8532013-07-31 19:52:071796 UMA_HISTOGRAM_ENUMERATION("ExtensionBlacklist.SilentInstall",
1797 extension->location(),
1798 Manifest::NUM_LOCATIONS);
1799 }
1800
[email protected]695b5712012-12-06 23:55:281801 if (!GetInstalledExtension(extension->id())) {
[email protected]07533022011-06-27 20:42:551802 UMA_HISTOGRAM_ENUMERATION("Extensions.InstallType",
1803 extension->GetType(), 100);
[email protected]69084dc2012-11-17 07:39:301804 UMA_HISTOGRAM_ENUMERATION("Extensions.InstallSource",
[email protected]1d5e58b2013-01-31 08:41:401805 extension->location(), Manifest::NUM_LOCATIONS);
treib2e0517f92015-05-07 23:15:361806 RecordPermissionMessagesHistogram(extension, "Install");
[email protected]69084dc2012-11-17 07:39:301807 } else {
1808 UMA_HISTOGRAM_ENUMERATION("Extensions.UpdateType",
1809 extension->GetType(), 100);
1810 UMA_HISTOGRAM_ENUMERATION("Extensions.UpdateSource",
[email protected]1d5e58b2013-01-31 08:41:401811 extension->location(), Manifest::NUM_LOCATIONS);
[email protected]07533022011-06-27 20:42:551812 }
1813
[email protected]399583b2012-12-11 09:33:421814 const Extension::State initial_state =
binjin47947f842014-11-18 12:10:241815 disable_reasons == Extension::DISABLE_NONE ? Extension::ENABLED
1816 : Extension::DISABLED;
treib8a6d9892015-08-26 10:23:191817 if (initial_state == Extension::ENABLED)
1818 extension_prefs_->SetExtensionEnabled(id);
1819 else
1820 extension_prefs_->SetExtensionDisabled(id, disable_reasons);
binjin47947f842014-11-18 12:10:241821
xiyuanf6a4c6a62016-04-19 18:14:541822 extensions::ExtensionPrefs::DelayReason delay_reason;
1823 extensions::InstallGate::Action action = ShouldDelayExtensionInstall(
1824 extension, !!(install_flags & extensions::kInstallFlagInstallImmediately),
1825 &delay_reason);
1826 switch (action) {
1827 case extensions::InstallGate::INSTALL:
1828 AddNewOrUpdatedExtension(extension, initial_state, install_flags,
1829 page_ordinal, install_parameter);
1830 return;
1831 case extensions::InstallGate::DELAY:
1832 extension_prefs_->SetDelayedInstallInfo(extension, initial_state,
1833 install_flags, delay_reason,
1834 page_ordinal, install_parameter);
[email protected]0db124b02012-11-07 04:55:051835
xiyuanf6a4c6a62016-04-19 18:14:541836 // Transfer ownership of |extension|.
[email protected]9f4e4f082013-06-21 07:11:191837 delayed_installs_.Insert(extension);
xiyuanf6a4c6a62016-04-19 18:14:541838
1839 if (delay_reason ==
1840 extensions::ExtensionPrefs::DELAY_REASON_WAIT_FOR_IDLE) {
1841 // Notify observers that app update is available.
ericwilligersb5f79de2016-10-19 04:15:101842 for (auto& observer : update_observers_)
1843 observer.OnAppUpdateAvailable(extension);
xiyuanf6a4c6a62016-04-19 18:14:541844 }
1845 return;
1846 case extensions::InstallGate::ABORT:
1847 // Do nothing to abort the install. One such case is the shared module
1848 // service gets IMPORT_STATUS_UNRECOVERABLE status for the pending
1849 // install.
1850 return;
[email protected]399583b2012-12-11 09:33:421851 }
xiyuanf6a4c6a62016-04-19 18:14:541852
1853 NOTREACHED() << "Unknown action for delayed install: " << action;
[email protected]8c484b742012-11-29 06:05:361854}
1855
binjin1569c9b2014-09-05 13:33:181856void ExtensionService::OnExtensionManagementSettingsChanged() {
1857 error_controller_->ShowErrorIfNeeded();
binjine6b58b52014-10-31 01:55:571858
1859 // Revokes blocked permissions from active_permissions for all extensions.
1860 extensions::ExtensionManagement* settings =
1861 extensions::ExtensionManagementFactory::GetForBrowserContext(profile());
1862 CHECK(settings);
dchengc963c7142016-04-08 03:55:221863 std::unique_ptr<ExtensionSet> all_extensions(
binjine6b58b52014-10-31 01:55:571864 registry_->GenerateInstalledExtensionsSet());
achuith2f5578b2016-02-26 21:57:131865 for (const auto& extension : *all_extensions) {
binjine6b58b52014-10-31 01:55:571866 if (!settings->IsPermissionSetAllowed(
binjin685ade82014-11-06 09:53:561867 extension.get(),
rdevlin.cronind630c302015-09-30 20:19:331868 extension->permissions_data()->active_permissions())) {
rdevlin.cronin77cb0ef2015-09-16 17:03:481869 extensions::PermissionsUpdater(profile()).RemovePermissionsUnsafe(
rdevlin.cronind630c302015-09-30 20:19:331870 extension.get(), *settings->GetBlockedPermissions(extension.get()));
binjine6b58b52014-10-31 01:55:571871 }
1872 }
1873
binjin1569c9b2014-09-05 13:33:181874 CheckManagementPolicy();
1875}
1876
[email protected]8c484b742012-11-29 06:05:361877void ExtensionService::AddNewOrUpdatedExtension(
1878 const Extension* extension,
[email protected]399583b2012-12-11 09:33:421879 Extension::State initial_state,
[email protected]4a1d9c0d2014-06-13 12:50:111880 int install_flags,
[email protected]d8fd0fd2014-03-24 13:16:061881 const syncer::StringOrdinal& page_ordinal,
1882 const std::string& install_parameter) {
[email protected]8c484b742012-11-29 06:05:361883 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]4a1d9c0d2014-06-13 12:50:111884 extension_prefs_->OnExtensionInstalled(
1885 extension, initial_state, page_ordinal, install_flags, install_parameter);
[email protected]9e9c1d12013-07-31 01:58:121886 delayed_installs_.Remove(extension->id());
[email protected]913ffca92014-03-27 15:26:161887 if (InstallVerifier::NeedsVerification(*extension))
juncai33e462102015-05-18 20:48:441888 InstallVerifier::Get(GetBrowserContext())->VerifyExtension(extension->id());
ryanackley48bedbd2015-01-27 23:12:141889
1890 const Extension* old = GetInstalledExtension(extension->id());
1891 if (extensions::AppDataMigrator::NeedsMigration(old, extension)) {
1892 app_data_migrator_->DoMigrationAndReply(
vmpstra34d11322016-03-21 20:28:471893 old, extension, base::Bind(&ExtensionService::FinishInstallation,
1894 AsWeakPtr(), base::RetainedRef(extension)));
ryanackley48bedbd2015-01-27 23:12:141895 return;
1896 }
1897
benwells1dd4acd2015-12-09 02:20:241898 FinishInstallation(extension);
[email protected]6f6101832012-11-27 22:10:481899}
1900
1901void ExtensionService::MaybeFinishDelayedInstallation(
1902 const std::string& extension_id) {
[email protected]9f4e4f082013-06-21 07:11:191903 // Check if the extension already got installed.
[email protected]9f4e4f082013-06-21 07:11:191904 const Extension* extension = delayed_installs_.GetByID(extension_id);
xiyuanf6a4c6a62016-04-19 18:14:541905 if (!extension)
1906 return;
1907
1908 extensions::ExtensionPrefs::DelayReason reason;
1909 const extensions::InstallGate::Action action = ShouldDelayExtensionInstall(
1910 extension, false /* install_immediately*/, &reason);
1911 switch (action) {
1912 case extensions::InstallGate::INSTALL:
1913 break;
1914 case extensions::InstallGate::DELAY:
1915 // Bail out and continue to delay the install.
[email protected]9f4e4f082013-06-21 07:11:191916 return;
xiyuanf6a4c6a62016-04-19 18:14:541917 case extensions::InstallGate::ABORT:
1918 delayed_installs_.Remove(extension_id);
1919 // Make sure no version of the extension is actually installed, (i.e.,
1920 // that this delayed install was not an update).
1921 CHECK(!extension_prefs_->GetInstalledExtensionInfo(extension_id).get());
1922 extension_prefs_->DeleteExtensionPrefs(extension_id);
1923 return;
[email protected]9f4e4f082013-06-21 07:11:191924 }
1925
[email protected]6f6101832012-11-27 22:10:481926 FinishDelayedInstallation(extension_id);
1927}
1928
1929void ExtensionService::FinishDelayedInstallation(
1930 const std::string& extension_id) {
1931 scoped_refptr<const Extension> extension(
1932 GetPendingExtensionUpdate(extension_id));
[email protected]dc24976f2013-06-02 21:15:091933 CHECK(extension.get());
[email protected]9f4e4f082013-06-21 07:11:191934 delayed_installs_.Remove(extension_id);
[email protected]6f6101832012-11-27 22:10:481935
[email protected]399583b2012-12-11 09:33:421936 if (!extension_prefs_->FinishDelayedInstallInfo(extension_id))
[email protected]6f6101832012-11-27 22:10:481937 NOTREACHED();
1938
benwells1dd4acd2015-12-09 02:20:241939 FinishInstallation(extension.get());
[email protected]6f6101832012-11-27 22:10:481940}
1941
[email protected]760f743b2014-05-28 13:52:021942void ExtensionService::FinishInstallation(
benwells1dd4acd2015-12-09 02:20:241943 const Extension* extension) {
[email protected]e7554c3f2013-05-29 00:36:561944 const extensions::Extension* existing_extension =
1945 GetInstalledExtension(extension->id());
1946 bool is_update = false;
1947 std::string old_name;
1948 if (existing_extension) {
1949 is_update = true;
1950 old_name = existing_extension->name();
1951 }
[email protected]bc44b5da2014-06-12 14:20:001952 registry_->TriggerOnWillBeInstalled(
benwells1dd4acd2015-12-09 02:20:241953 extension, is_update, old_name);
[email protected]17f07822014-05-22 08:45:151954
[email protected]399583b2012-12-11 09:33:421955 // Unpacked extensions default to allowing file access, but if that has been
1956 // overridden, don't reset the value.
[email protected]1d5e58b2013-01-31 08:41:401957 if (Manifest::ShouldAlwaysAllowFileAccess(extension->location()) &&
[email protected]399583b2012-12-11 09:33:421958 !extension_prefs_->HasAllowFileAccessSetting(extension->id())) {
1959 extension_prefs_->SetAllowFileAccess(extension->id(), true);
1960 }
1961
[email protected]6f6101832012-11-27 22:10:481962 AddExtension(extension);
[email protected]612a1cb12012-10-17 13:18:031963
[email protected]bc44b5da2014-06-12 14:20:001964 // Notify observers that need to know when an installation is complete.
[email protected]38e872532014-07-16 23:27:511965 registry_->TriggerOnInstalled(extension, is_update);
[email protected]bc44b5da2014-06-12 14:20:001966
[email protected]9f4e4f082013-06-21 07:11:191967 // Check extensions that may have been delayed only because this shared module
1968 // was not available.
[email protected]374ceb6f2014-07-02 19:25:341969 if (SharedModuleInfo::IsSharedModule(extension))
[email protected]9f4e4f082013-06-21 07:11:191970 MaybeFinishDelayedInstallations();
[email protected]4a190632009-05-09 01:07:421971}
1972
[email protected]76b65442012-11-17 14:11:481973const Extension* ExtensionService::GetPendingExtensionUpdate(
1974 const std::string& id) const {
[email protected]9f4e4f082013-06-21 07:11:191975 return delayed_installs_.GetByID(id);
[email protected]76b65442012-11-17 14:11:481976}
1977
mukai87a8d402014-09-15 20:15:091978void ExtensionService::RegisterContentSettings(
1979 HostContentSettingsMap* host_content_settings_map) {
rkaplowe65c2ff2015-02-14 16:29:541980 TRACE_EVENT0("browser,startup", "ExtensionService::RegisterContentSettings");
mukaia1aa3512014-10-22 20:14:111981 DCHECK_CURRENTLY_ON(BrowserThread::UI);
mukai87a8d402014-09-15 20:15:091982 host_content_settings_map->RegisterProvider(
1983 HostContentSettingsMap::INTERNAL_EXTENSION_PROVIDER,
dchengc963c7142016-04-08 03:55:221984 std::unique_ptr<content_settings::ObservableProvider>(
reillyga3acbc12014-11-11 23:17:121985 new content_settings::InternalExtensionProvider(profile_)));
mukai87a8d402014-09-15 20:15:091986
1987 host_content_settings_map->RegisterProvider(
1988 HostContentSettingsMap::CUSTOM_EXTENSION_PROVIDER,
dchengc963c7142016-04-08 03:55:221989 std::unique_ptr<content_settings::ObservableProvider>(
mukai87a8d402014-09-15 20:15:091990 new content_settings::CustomExtensionProvider(
dchengc963c7142016-04-08 03:55:221991 extensions::ContentSettingsService::Get(profile_)
1992 ->content_settings_store(),
mukai87a8d402014-09-15 20:15:091993 profile_->GetOriginalProfile() != profile_)));
1994}
1995
xiyuane87def2e2015-06-04 22:50:221996void ExtensionService::TrackTerminatedExtension(
1997 const std::string& extension_id) {
1998 extensions_being_terminated_.erase(extension_id);
1999
2000 const Extension* extension = GetInstalledExtension(extension_id);
2001 if (!extension) {
xiyuane87def2e2015-06-04 22:50:222002 return;
2003 }
2004
[email protected]bb1bc9b32013-12-21 03:09:142005 // No need to check for duplicates; inserting a duplicate is a no-op.
2006 registry_->AddTerminated(make_scoped_refptr(extension));
[email protected]b0af4792013-10-23 09:12:132007 UnloadExtension(extension->id(), UnloadedExtensionInfo::REASON_TERMINATE);
[email protected]bb7f40952011-01-13 00:21:202008}
2009
[email protected]e9d7496e2014-04-18 01:25:462010void ExtensionService::TerminateExtension(const std::string& extension_id) {
xiyuana30a2092015-06-09 23:14:442011 TrackTerminatedExtension(extension_id);
[email protected]e9d7496e2014-04-18 01:25:462012}
2013
[email protected]bb7f40952011-01-13 00:21:202014void ExtensionService::UntrackTerminatedExtension(const std::string& id) {
brettwfce8d192015-08-10 19:07:512015 std::string lowercase_id = base::ToLowerASCII(id);
[email protected]bb1bc9b32013-12-21 03:09:142016 const Extension* extension =
2017 registry_->terminated_extensions().GetByID(lowercase_id);
2018 registry_->RemoveTerminated(lowercase_id);
[email protected]fb789532013-08-27 02:40:212019 if (extension) {
2020 content::NotificationService::current()->Notify(
[email protected]adf5a102014-07-31 12:44:062021 extensions::NOTIFICATION_EXTENSION_REMOVED,
[email protected]fb789532013-08-27 02:40:212022 content::Source<Profile>(profile_),
2023 content::Details<const Extension>(extension));
2024 }
[email protected]bb7f40952011-01-13 00:21:202025}
2026
[email protected]8001df22011-04-28 19:59:472027const Extension* ExtensionService::GetInstalledExtension(
2028 const std::string& id) const {
[email protected]599539802014-01-07 23:06:002029 return registry_->GetExtensionById(id, ExtensionRegistry::EVERYTHING);
[email protected]0dfe05c2011-02-23 23:03:362030}
2031
[email protected]9060d8b02012-01-13 02:14:302032bool ExtensionService::OnExternalExtensionFileFound(
lazyboye8634172016-01-28 00:10:482033 const ExternalInstallInfoFile& info) {
[email protected]ab22ba42011-01-14 16:36:382034 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
lazyboye8634172016-01-28 00:10:482035 CHECK(crx_file::id_util::IdIsValid(info.extension_id));
2036 if (extension_prefs_->IsExternalExtensionUninstalled(info.extension_id))
[email protected]9060d8b02012-01-13 02:14:302037 return false;
[email protected]a8af9fdb2010-10-28 21:52:202038
[email protected]7577a5c52009-07-30 06:21:582039 // Before even bothering to unpack, check and see if we already have this
[email protected]4c967932009-07-31 01:15:492040 // version. This is important because these extensions are going to get
[email protected]7577a5c52009-07-30 06:21:582041 // installed on every startup.
lazyboye8634172016-01-28 00:10:482042 const Extension* existing = GetExtensionById(info.extension_id, true);
[email protected]910f72ce2012-08-24 01:38:352043
[email protected]7577a5c52009-07-30 06:21:582044 if (existing) {
[email protected]910f72ce2012-08-24 01:38:352045 // The default apps will have the location set as INTERNAL. Since older
2046 // default apps are installed as EXTERNAL, we override them. However, if the
2047 // app is already installed as internal, then do the version check.
[email protected]31bb5ee62012-09-12 22:58:402048 // TODO(grv) : Remove after Q1-2013.
[email protected]910f72ce2012-08-24 01:38:352049 bool is_default_apps_migration =
lazyboye8634172016-01-28 00:10:482050 (info.crx_location == Manifest::INTERNAL &&
[email protected]1d5e58b2013-01-31 08:41:402051 Manifest::IsExternalLocation(existing->location()));
[email protected]910f72ce2012-08-24 01:38:352052
2053 if (!is_default_apps_migration) {
lazyboye8634172016-01-28 00:10:482054 DCHECK(info.version.get());
[email protected]910f72ce2012-08-24 01:38:352055
lazyboye8634172016-01-28 00:10:482056 switch (existing->version()->CompareTo(*info.version)) {
[email protected]910f72ce2012-08-24 01:38:352057 case -1: // existing version is older, we should upgrade
2058 break;
2059 case 0: // existing version is same, do nothing
2060 return false;
2061 case 1: // existing version is newer, uh-oh
lazyboye8634172016-01-28 00:10:482062 LOG(WARNING) << "Found external version of extension "
2063 << info.extension_id
[email protected]910f72ce2012-08-24 01:38:352064 << "that is older than current version. Current version "
2065 << "is: " << existing->VersionString() << ". New "
lazyboye8634172016-01-28 00:10:482066 << "version is: " << info.version->GetString()
[email protected]910f72ce2012-08-24 01:38:352067 << ". Keeping current version.";
2068 return false;
2069 }
[email protected]7577a5c52009-07-30 06:21:582070 }
2071 }
2072
[email protected]9060d8b02012-01-13 02:14:302073 // If the extension is already pending, don't start an install.
[email protected]e3987852012-05-04 10:06:302074 if (!pending_extension_manager()->AddFromExternalFile(
lazyboye8634172016-01-28 00:10:482075 info.extension_id, info.crx_location, *info.version,
2076 info.creation_flags, info.mark_acknowledged)) {
[email protected]9060d8b02012-01-13 02:14:302077 return false;
[email protected]e3987852012-05-04 10:06:302078 }
[email protected]9c635f22010-12-02 09:36:362079
[email protected]14908b72011-04-20 06:54:362080 // no client (silent install)
[email protected]f8636f92013-08-09 21:02:372081 scoped_refptr<CrxInstaller> installer(CrxInstaller::CreateSilent(this));
lazyboye8634172016-01-28 00:10:482082 installer->set_install_source(info.crx_location);
2083 installer->set_expected_id(info.extension_id);
2084 installer->set_expected_version(*info.version,
treibe960e282015-09-11 10:38:082085 true /* fail_install_if_unexpected */);
[email protected]cb0e50312011-05-09 15:03:072086 installer->set_install_cause(extension_misc::INSTALL_CAUSE_EXTERNAL_FILE);
lazyboye8634172016-01-28 00:10:482087 installer->set_install_immediately(info.install_immediately);
2088 installer->set_creation_flags(info.creation_flags);
[email protected]88e8ec9152013-01-17 04:05:182089#if defined(OS_CHROMEOS)
lazyboye8634172016-01-28 00:10:482090 extensions::InstallLimiter::Get(profile_)->Add(installer, info.path);
[email protected]88e8ec9152013-01-17 04:05:182091#else
lazyboye8634172016-01-28 00:10:482092 installer->InstallCrx(info.path);
[email protected]88e8ec9152013-01-17 04:05:182093#endif
[email protected]47fc70c2011-12-06 07:29:512094
2095 // Depending on the source, a new external extension might not need a user
2096 // notification on installation. For such extensions, mark them acknowledged
2097 // now to suppress the notification.
lazyboye8634172016-01-28 00:10:482098 if (info.mark_acknowledged)
2099 external_install_manager_->AcknowledgeExternalExtension(info.extension_id);
[email protected]9060d8b02012-01-13 02:14:302100
2101 return true;
[email protected]7577a5c52009-07-30 06:21:582102}
2103
[email protected]eaa7dd182010-12-14 11:09:002104void ExtensionService::DidCreateRenderViewForBackgroundPage(
[email protected]3a1dc572012-07-31 22:25:132105 extensions::ExtensionHost* host) {
[email protected]406027c02010-09-27 08:03:182106 OrphanedDevTools::iterator iter =
[email protected]2d2f6cfc2011-05-06 21:09:332107 orphaned_dev_tools_.find(host->extension_id());
[email protected]406027c02010-09-27 08:03:182108 if (iter == orphaned_dev_tools_.end())
2109 return;
2110
rockota34fed222015-09-25 21:56:312111 // Keepalive count is reset on extension reload. This re-establishes the
2112 // keepalive that was added when the DevTools agent was initially attached.
2113 extensions::ProcessManager::Get(profile_)->IncrementLazyKeepaliveCount(
2114 host->extension());
[email protected]b3f957e62014-08-08 10:09:022115 iter->second->ConnectWebContents(host->host_contents());
[email protected]406027c02010-09-27 08:03:182116 orphaned_dev_tools_.erase(iter);
2117}
2118
[email protected]432115822011-07-10 15:52:272119void ExtensionService::Observe(int type,
[email protected]6c2381d2011-10-19 02:52:532120 const content::NotificationSource& source,
2121 const content::NotificationDetails& details) {
[email protected]432115822011-07-10 15:52:272122 switch (type) {
[email protected]3c4abc82012-10-22 22:25:542123 case chrome::NOTIFICATION_APP_TERMINATING:
2124 // Shutdown has started. Don't start any more extension installs.
2125 // (We cannot use ExtensionService::Shutdown() for this because it
2126 // happens too late in browser teardown.)
2127 browser_terminating_ = true;
2128 break;
[email protected]adf5a102014-07-31 12:44:062129 case extensions::NOTIFICATION_EXTENSION_PROCESS_TERMINATED: {
[email protected]6c2381d2011-10-19 02:52:532130 if (profile_ !=
2131 content::Source<Profile>(source).ptr()->GetOriginalProfile()) {
[email protected]bc535ee52010-08-31 18:40:322132 break;
[email protected]6c2381d2011-10-19 02:52:532133 }
[email protected]a4ed6282009-12-14 20:51:162134
[email protected]3a1dc572012-07-31 22:25:132135 extensions::ExtensionHost* host =
2136 content::Details<extensions::ExtensionHost>(details).ptr();
[email protected]f128af42010-08-05 18:05:262137
[email protected]3964e572014-02-13 21:57:412138 // If the extension is already being terminated, there is nothing left to
2139 // do.
2140 if (!extensions_being_terminated_.insert(host->extension_id()).second)
2141 break;
2142
[email protected]fa2416f2011-05-03 08:41:202143 // Mark the extension as terminated and Unload it. We want it to
2144 // be in a consistent state: either fully working or not loaded
2145 // at all, but never half-crashed. We do it in a PostTask so
2146 // that other handlers of this notification will still have
2147 // access to the Extension and ExtensionHost.
skyostilf221b7de2015-06-11 20:36:322148 base::ThreadTaskRunnerHandle::Get()->PostTask(
2149 FROM_HERE, base::Bind(&ExtensionService::TrackTerminatedExtension,
2150 AsWeakPtr(), host->extension()->id()));
[email protected]31f77262009-12-02 20:48:532151 break;
2152 }
[email protected]432115822011-07-10 15:52:272153 case content::NOTIFICATION_RENDERER_PROCESS_TERMINATED: {
[email protected]f3b1a082011-11-18 00:34:302154 content::RenderProcessHost* process =
2155 content::Source<content::RenderProcessHost>(source).ptr();
[email protected]fc30ef082011-08-18 04:07:192156 Profile* host_profile =
[email protected]f3b1a082011-11-18 00:34:302157 Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]fc30ef082011-08-18 04:07:192158 if (!profile_->IsSameProfile(host_profile->GetOriginalProfile()))
2159 break;
2160
[email protected]fafdc842014-01-17 18:09:082161 extensions::ProcessMap* process_map =
2162 extensions::ProcessMap::Get(profile_);
2163 if (process_map->Contains(process->GetID())) {
[email protected]52b76592013-11-02 17:59:032164 // An extension process was terminated, this might have resulted in an
2165 // app or extension becoming idle.
2166 std::set<std::string> extension_ids =
[email protected]fafdc842014-01-17 18:09:082167 process_map->GetExtensionsInProcess(process->GetID());
elijahtaylor0def4432014-10-06 18:15:112168 // In addition to the extensions listed in the process map, one of those
2169 // extensions could be referencing a shared module which is waiting for
2170 // idle to update. Check all imports of these extensions, too.
2171 std::set<std::string> import_ids;
2172 for (std::set<std::string>::const_iterator it = extension_ids.begin();
2173 it != extension_ids.end();
2174 ++it) {
2175 const Extension* extension = GetExtensionById(*it, true);
2176 if (!extension)
2177 continue;
2178 const std::vector<SharedModuleInfo::ImportInfo>& imports =
2179 SharedModuleInfo::GetImports(extension);
2180 std::vector<SharedModuleInfo::ImportInfo>::const_iterator import_it;
2181 for (import_it = imports.begin(); import_it != imports.end();
2182 import_it++) {
2183 import_ids.insert((*import_it).extension_id);
2184 }
2185 }
2186 extension_ids.insert(import_ids.begin(), import_ids.end());
2187
[email protected]52b76592013-11-02 17:59:032188 for (std::set<std::string>::const_iterator it = extension_ids.begin();
2189 it != extension_ids.end(); ++it) {
2190 if (delayed_installs_.Contains(*it)) {
skyostilf221b7de2015-06-11 20:36:322191 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
[email protected]52b76592013-11-02 17:59:032192 FROM_HERE,
2193 base::Bind(&ExtensionService::MaybeFinishDelayedInstallation,
2194 AsWeakPtr(), *it),
2195 base::TimeDelta::FromSeconds(kUpdateIdleDelay));
2196 }
2197 }
2198 }
2199
[email protected]fafdc842014-01-17 18:09:082200 process_map->RemoveAllFromProcess(process->GetID());
[email protected]6f371442011-11-09 06:45:462201 BrowserThread::PostTask(
[email protected]38427a12013-11-09 17:34:202202 BrowserThread::IO,
2203 FROM_HERE,
2204 base::Bind(&extensions::InfoMap::UnregisterAllExtensionsInProcess,
[email protected]31d8f5f22012-04-02 15:22:082205 system_->info_map(),
[email protected]f3b1a082011-11-18 00:34:302206 process->GetID()));
[email protected]da5683db2011-04-23 17:12:212207 break;
2208 }
[email protected]92dd8d92013-02-26 00:41:082209 case chrome::NOTIFICATION_UPGRADE_RECOMMENDED: {
[email protected]75bdcb872013-03-13 00:41:452210 // Notify observers that chrome update is available.
ericwilligersb5f79de2016-10-19 04:15:102211 for (auto& observer : update_observers_)
2212 observer.OnChromeUpdateAvailable();
[email protected]92dd8d92013-02-26 00:41:082213 break;
2214 }
[email protected]ebe07772014-05-22 04:16:062215 case chrome::NOTIFICATION_PROFILE_DESTRUCTION_STARTED: {
2216 OnProfileDestructionStarted();
2217 break;
2218 }
[email protected]aa96d3a2010-08-21 08:45:252219
[email protected]4814b512009-11-07 00:12:292220 default:
2221 NOTREACHED() << "Unexpected notification type.";
2222 }
2223}
2224
binjin47947f842014-11-18 12:10:242225int ExtensionService::GetDisableReasonsOnInstalled(const Extension* extension) {
2226 Extension::DisableReason disable_reason;
2227 // Extensions disabled by management policy should always be disabled, even
2228 // if it's force-installed.
2229 if (system_->management_policy()->MustRemainDisabled(
2230 extension, &disable_reason, nullptr)) {
2231 // A specified reason is required to disable the extension.
2232 DCHECK(disable_reason != Extension::DISABLE_NONE);
2233 return disable_reason;
2234 }
2235
[email protected]612a1cb12012-10-17 13:18:032236 // Extensions installed by policy can't be disabled. So even if a previous
2237 // installation disabled the extension, make sure it is now enabled.
binjin47947f842014-11-18 12:10:242238 if (system_->management_policy()->MustRemainEnabled(extension, nullptr))
2239 return Extension::DISABLE_NONE;
[email protected]612a1cb12012-10-17 13:18:032240
binjin47947f842014-11-18 12:10:242241 // An already disabled extension should inherit the disable reasons and
2242 // remain disabled.
2243 if (extension_prefs_->IsExtensionDisabled(extension->id())) {
2244 int disable_reasons = extension_prefs_->GetDisableReasons(extension->id());
2245 // If an extension was disabled without specified reason, presume it's
2246 // disabled by user.
2247 return disable_reasons == Extension::DISABLE_NONE
2248 ? Extension::DISABLE_USER_ACTION
2249 : disable_reasons;
2250 }
[email protected]612a1cb12012-10-17 13:18:032251
[email protected]41070e8d2012-10-24 01:34:362252 if (FeatureSwitch::prompt_for_external_extensions()->IsEnabled()) {
[email protected]612a1cb12012-10-17 13:18:032253 // External extensions are initially disabled. We prompt the user before
[email protected]2c495c42013-01-04 21:49:542254 // enabling them. Hosted apps are excepted because they are not dangerous
2255 // (they need to be launched by the user anyway).
[email protected]1d5e58b2013-01-31 08:41:402256 if (extension->GetType() != Manifest::TYPE_HOSTED_APP &&
2257 Manifest::IsExternalLocation(extension->location()) &&
[email protected]612a1cb12012-10-17 13:18:032258 !extension_prefs_->IsExternalExtensionAcknowledged(extension->id())) {
binjin47947f842014-11-18 12:10:242259 return Extension::DISABLE_EXTERNAL_EXTENSION;
[email protected]612a1cb12012-10-17 13:18:032260 }
2261 }
[email protected]612a1cb12012-10-17 13:18:032262
binjin47947f842014-11-18 12:10:242263 return Extension::DISABLE_NONE;
[email protected]612a1cb12012-10-17 13:18:032264}
[email protected]0db124b02012-11-07 04:55:052265
mlerman6a37b6a42014-11-26 22:10:532266// Helper method to determine if an extension can be blocked.
2267bool ExtensionService::CanBlockExtension(const Extension* extension) const {
mlerman3690e5be2014-12-01 22:57:442268 DCHECK(extension);
mlerman6a37b6a42014-11-26 22:10:532269 return extension->location() != Manifest::COMPONENT &&
2270 extension->location() != Manifest::EXTERNAL_COMPONENT &&
achuith2f5578b2016-02-26 21:57:132271 !system_->management_policy()->MustRemainEnabled(extension, nullptr);
mlerman6a37b6a42014-11-26 22:10:532272}
2273
xiyuanf6a4c6a62016-04-19 18:14:542274extensions::InstallGate::Action ExtensionService::ShouldDelayExtensionInstall(
2275 const extensions::Extension* extension,
2276 bool install_immediately,
2277 extensions::ExtensionPrefs::DelayReason* reason) const {
2278 for (const auto& entry : install_delayer_registry_) {
2279 extensions::InstallGate* const delayer = entry.second;
2280 extensions::InstallGate::Action action =
2281 delayer->ShouldDelay(extension, install_immediately);
2282 if (action != extensions::InstallGate::INSTALL) {
2283 *reason = entry.first;
2284 return action;
2285 }
[email protected]e7aa7b7e2012-11-27 04:51:222286 }
[email protected]fdd679b2012-11-15 20:49:392287
xiyuanf6a4c6a62016-04-19 18:14:542288 return extensions::InstallGate::INSTALL;
[email protected]9f4e4f082013-06-21 07:11:192289}
2290
2291void ExtensionService::MaybeFinishDelayedInstallations() {
2292 std::vector<std::string> to_be_installed;
achuith2f5578b2016-02-26 21:57:132293 for (const auto& extension : delayed_installs_) {
2294 to_be_installed.push_back(extension->id());
[email protected]399583b2012-12-11 09:33:422295 }
achuith2f5578b2016-02-26 21:57:132296 for (const auto& extension_id : to_be_installed) {
2297 MaybeFinishDelayedInstallation(extension_id);
[email protected]399583b2012-12-11 09:33:422298 }
[email protected]399583b2012-12-11 09:33:422299}
2300
[email protected]fdd679b2012-11-15 20:49:392301void ExtensionService::OnBlacklistUpdated() {
[email protected]2d19eb6e2014-01-27 17:30:002302 blacklist_->GetBlacklistedIDs(
[email protected]f47f7172014-03-19 19:27:102303 registry_->GenerateInstalledExtensionsSet()->GetIDs(),
[email protected]3f2a2fa2013-09-24 02:55:252304 base::Bind(&ExtensionService::ManageBlacklist, AsWeakPtr()));
[email protected]695b5712012-12-06 23:55:282305}
2306
[email protected]2d19eb6e2014-01-27 17:30:002307void ExtensionService::ManageBlacklist(
2308 const extensions::Blacklist::BlacklistStateMap& state_map) {
[email protected]54ee8192014-03-29 17:37:242309 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]695b5712012-12-06 23:55:282310
mlerman6a37b6a42014-11-26 22:10:532311 std::set<std::string> blacklisted;
[email protected]2d19eb6e2014-01-27 17:30:002312 ExtensionIdSet greylist;
2313 ExtensionIdSet unchanged;
achuith2f5578b2016-02-26 21:57:132314 for (const auto& it : state_map) {
2315 switch (it.second) {
[email protected]2d19eb6e2014-01-27 17:30:002316 case extensions::NOT_BLACKLISTED:
2317 break;
[email protected]695b5712012-12-06 23:55:282318
[email protected]2d19eb6e2014-01-27 17:30:002319 case extensions::BLACKLISTED_MALWARE:
achuith2f5578b2016-02-26 21:57:132320 blacklisted.insert(it.first);
[email protected]2d19eb6e2014-01-27 17:30:002321 break;
2322
2323 case extensions::BLACKLISTED_SECURITY_VULNERABILITY:
2324 case extensions::BLACKLISTED_CWS_POLICY_VIOLATION:
2325 case extensions::BLACKLISTED_POTENTIALLY_UNWANTED:
achuith2f5578b2016-02-26 21:57:132326 greylist.insert(it.first);
[email protected]2d19eb6e2014-01-27 17:30:002327 break;
2328
2329 case extensions::BLACKLISTED_UNKNOWN:
achuith2f5578b2016-02-26 21:57:132330 unchanged.insert(it.first);
[email protected]2d19eb6e2014-01-27 17:30:002331 break;
2332 }
2333 }
2334
mlerman6a37b6a42014-11-26 22:10:532335 UpdateBlacklistedExtensions(blacklisted, unchanged);
[email protected]2d19eb6e2014-01-27 17:30:002336 UpdateGreylistedExtensions(greylist, unchanged, state_map);
2337
[email protected]373daf972014-04-10 01:50:442338 error_controller_->ShowErrorIfNeeded();
[email protected]2d19eb6e2014-01-27 17:30:002339}
2340
2341namespace {
2342void Partition(const ExtensionIdSet& before,
2343 const ExtensionIdSet& after,
2344 const ExtensionIdSet& unchanged,
2345 ExtensionIdSet* no_longer,
2346 ExtensionIdSet* not_yet) {
2347 *not_yet = base::STLSetDifference<ExtensionIdSet>(after, before);
2348 *no_longer = base::STLSetDifference<ExtensionIdSet>(before, after);
2349 *no_longer = base::STLSetDifference<ExtensionIdSet>(*no_longer, unchanged);
2350}
2351} // namespace
2352
mlerman6a37b6a42014-11-26 22:10:532353void ExtensionService::UpdateBlacklistedExtensions(
2354 const ExtensionIdSet& blacklisted,
[email protected]2d19eb6e2014-01-27 17:30:002355 const ExtensionIdSet& unchanged) {
2356 ExtensionIdSet not_yet_blocked, no_longer_blocked;
mlerman6a37b6a42014-11-26 22:10:532357 Partition(registry_->blacklisted_extensions().GetIDs(), blacklisted,
2358 unchanged, &no_longer_blocked, &not_yet_blocked);
[email protected]2d19eb6e2014-01-27 17:30:002359
2360 for (ExtensionIdSet::iterator it = no_longer_blocked.begin();
2361 it != no_longer_blocked.end(); ++it) {
[email protected]695b5712012-12-06 23:55:282362 scoped_refptr<const Extension> extension =
[email protected]bb1bc9b32013-12-21 03:09:142363 registry_->blacklisted_extensions().GetByID(*it);
[email protected]3f2a2fa2013-09-24 02:55:252364 if (!extension.get()) {
mlerman6a37b6a42014-11-26 22:10:532365 NOTREACHED() << "Extension " << *it << " no longer blacklisted, "
2366 << "but it was never blacklisted.";
[email protected]695b5712012-12-06 23:55:282367 continue;
[email protected]3f2a2fa2013-09-24 02:55:252368 }
[email protected]bb1bc9b32013-12-21 03:09:142369 registry_->RemoveBlacklisted(*it);
atuchin6dc7c442016-07-20 07:04:342370 extension_prefs_->SetExtensionBlacklistState(extension->id(),
2371 extensions::NOT_BLACKLISTED);
[email protected]dc24976f2013-06-02 21:15:092372 AddExtension(extension.get());
[email protected]ac875372013-02-28 04:36:092373 UMA_HISTOGRAM_ENUMERATION("ExtensionBlacklist.UnblacklistInstalled",
[email protected]dc24976f2013-06-02 21:15:092374 extension->location(),
2375 Manifest::NUM_LOCATIONS);
[email protected]695b5712012-12-06 23:55:282376 }
2377
[email protected]2d19eb6e2014-01-27 17:30:002378 for (ExtensionIdSet::iterator it = not_yet_blocked.begin();
2379 it != not_yet_blocked.end(); ++it) {
[email protected]695b5712012-12-06 23:55:282380 scoped_refptr<const Extension> extension = GetInstalledExtension(*it);
[email protected]3f2a2fa2013-09-24 02:55:252381 if (!extension.get()) {
2382 NOTREACHED() << "Extension " << *it << " needs to be "
2383 << "blacklisted, but it's not installed.";
[email protected]695b5712012-12-06 23:55:282384 continue;
[email protected]3f2a2fa2013-09-24 02:55:252385 }
[email protected]bb1bc9b32013-12-21 03:09:142386 registry_->AddBlacklisted(extension);
[email protected]2d19eb6e2014-01-27 17:30:002387 extension_prefs_->SetExtensionBlacklistState(
2388 extension->id(), extensions::BLACKLISTED_MALWARE);
[email protected]b0af4792013-10-23 09:12:132389 UnloadExtension(*it, UnloadedExtensionInfo::REASON_BLACKLIST);
[email protected]ac875372013-02-28 04:36:092390 UMA_HISTOGRAM_ENUMERATION("ExtensionBlacklist.BlacklistInstalled",
2391 extension->location(), Manifest::NUM_LOCATIONS);
[email protected]695b5712012-12-06 23:55:282392 }
[email protected]2d19eb6e2014-01-27 17:30:002393}
[email protected]695b5712012-12-06 23:55:282394
[email protected]2d19eb6e2014-01-27 17:30:002395// TODO(oleg): UMA logging
2396void ExtensionService::UpdateGreylistedExtensions(
2397 const ExtensionIdSet& greylist,
2398 const ExtensionIdSet& unchanged,
2399 const extensions::Blacklist::BlacklistStateMap& state_map) {
2400 ExtensionIdSet not_yet_greylisted, no_longer_greylisted;
2401 Partition(greylist_.GetIDs(),
2402 greylist, unchanged,
2403 &no_longer_greylisted, &not_yet_greylisted);
2404
2405 for (ExtensionIdSet::iterator it = no_longer_greylisted.begin();
2406 it != no_longer_greylisted.end(); ++it) {
2407 scoped_refptr<const Extension> extension = greylist_.GetByID(*it);
2408 if (!extension.get()) {
2409 NOTREACHED() << "Extension " << *it << " no longer greylisted, "
2410 << "but it was not marked as greylisted.";
2411 continue;
2412 }
2413
2414 greylist_.Remove(*it);
2415 extension_prefs_->SetExtensionBlacklistState(extension->id(),
2416 extensions::NOT_BLACKLISTED);
2417 if (extension_prefs_->GetDisableReasons(extension->id()) &
2418 extensions::Extension::DISABLE_GREYLIST)
2419 EnableExtension(*it);
2420 }
2421
2422 for (ExtensionIdSet::iterator it = not_yet_greylisted.begin();
2423 it != not_yet_greylisted.end(); ++it) {
2424 scoped_refptr<const Extension> extension = GetInstalledExtension(*it);
2425 if (!extension.get()) {
2426 NOTREACHED() << "Extension " << *it << " needs to be "
2427 << "disabled, but it's not installed.";
2428 continue;
2429 }
2430 greylist_.Insert(extension);
2431 extension_prefs_->SetExtensionBlacklistState(extension->id(),
2432 state_map.find(*it)->second);
2433 if (registry_->enabled_extensions().Contains(extension->id()))
2434 DisableExtension(*it, extensions::Extension::DISABLE_GREYLIST);
2435 }
[email protected]fdd679b2012-11-15 20:49:392436}
[email protected]75bdcb872013-03-13 00:41:452437
2438void ExtensionService::AddUpdateObserver(extensions::UpdateObserver* observer) {
2439 update_observers_.AddObserver(observer);
2440}
2441
2442void ExtensionService::RemoveUpdateObserver(
2443 extensions::UpdateObserver* observer) {
2444 update_observers_.RemoveObserver(observer);
2445}
[email protected]bb1bc9b32013-12-21 03:09:142446
xiyuanf6a4c6a62016-04-19 18:14:542447void ExtensionService::RegisterInstallGate(
2448 extensions::ExtensionPrefs::DelayReason reason,
2449 extensions::InstallGate* install_delayer) {
2450 DCHECK(install_delayer_registry_.end() ==
2451 install_delayer_registry_.find(reason));
2452 install_delayer_registry_[reason] = install_delayer;
2453}
2454
2455void ExtensionService::UnregisterInstallGate(
2456 extensions::InstallGate* install_delayer) {
2457 for (auto it = install_delayer_registry_.begin();
2458 it != install_delayer_registry_.end(); ++it) {
2459 if (it->second == install_delayer) {
2460 install_delayer_registry_.erase(it);
2461 return;
2462 }
2463 }
2464}
2465
[email protected]bb1bc9b32013-12-21 03:09:142466// Used only by test code.
2467void ExtensionService::UnloadAllExtensionsInternal() {
2468 profile_->GetExtensionSpecialStoragePolicy()->RevokeRightsForAllExtensions();
2469
2470 registry_->ClearAll();
[email protected]45f5b7d2014-01-22 23:47:132471 system_->runtime_data()->ClearAll();
[email protected]bb1bc9b32013-12-21 03:09:142472
2473 // TODO(erikkay) should there be a notification for this? We can't use
2474 // EXTENSION_UNLOADED since that implies that the extension has been disabled
2475 // or uninstalled.
2476}
[email protected]ebe07772014-05-22 04:16:062477
2478void ExtensionService::OnProfileDestructionStarted() {
2479 ExtensionIdSet ids_to_unload = registry_->enabled_extensions().GetIDs();
2480 for (ExtensionIdSet::iterator it = ids_to_unload.begin();
2481 it != ids_to_unload.end();
2482 ++it) {
2483 UnloadExtension(*it, UnloadedExtensionInfo::REASON_PROFILE_SHUTDOWN);
2484 }
2485}