blob: 3e3d06a3ec20ebea1b378b45d8d89fe50d2a76ad [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
[email protected]654512b2010-09-01 02:09:427#include <algorithm>
[email protected]695b5712012-12-06 23:55:288#include <iterator>
[email protected]97d2f1d2011-01-15 00:41:089#include <set>
[email protected]654512b2010-09-01 02:09:4210
[email protected]62433d32011-10-12 22:33:1211#include "base/command_line.h"
[email protected]835d7c82010-10-14 04:38:3812#include "base/metrics/histogram.h"
[email protected]3ea1b182013-02-08 22:38:4113#include "base/strings/string_number_conversions.h"
[email protected]00e7bef2013-06-10 20:35:1714#include "base/strings/stringprintf.h"
[email protected]112158af2013-06-07 23:46:1815#include "base/strings/utf_string_conversions.h"
[email protected]7f8f24f2012-11-15 19:40:1416#include "base/threading/sequenced_worker_pool.h"
[email protected]34b99632011-01-01 01:01:0617#include "base/threading/thread_restrictions.h"
[email protected]41a17c52013-06-28 00:27:5318#include "base/time/time.h"
rkaplowe65c2ff2015-02-14 16:29:5419#include "base/trace_event/trace_event.h"
[email protected]15730c42009-09-03 00:03:2020#include "chrome/browser/browser_process.h"
[email protected]9ea0cd32013-07-12 01:50:3621#include "chrome/browser/chrome_notification_types.h"
mukai87a8d402014-09-15 20:15:0922#include "chrome/browser/content_settings/content_settings_internal_extension_provider.h"
sunil.ratnu21b896c2014-11-24 10:09:2423#include "chrome/browser/extensions/api/content_settings/content_settings_custom_extension_provider.h"
mukai87a8d402014-09-15 20:15:0924#include "chrome/browser/extensions/api/content_settings/content_settings_service.h"
ryanackley48bedbd2015-01-27 23:12:1425#include "chrome/browser/extensions/app_data_migrator.h"
[email protected]d8c8f25f2011-11-02 18:18:0126#include "chrome/browser/extensions/component_loader.h"
[email protected]13e062e2014-08-09 10:21:5527#include "chrome/browser/extensions/crx_installer.h"
[email protected]d9ede582012-08-14 19:21:3828#include "chrome/browser/extensions/data_deleter.h"
rdevlin.cronin2813c1b2014-08-26 23:51:0829#include "chrome/browser/extensions/extension_action_storage_manager.h"
[email protected]5a145e82014-05-29 22:19:0730#include "chrome/browser/extensions/extension_assets_manager.h"
[email protected]62f051c2012-03-29 17:04:4431#include "chrome/browser/extensions/extension_disabled_ui.h"
[email protected]373daf972014-04-10 01:50:4432#include "chrome/browser/extensions/extension_error_controller.h"
[email protected]19eb80152011-02-26 00:28:4333#include "chrome/browser/extensions/extension_special_storage_policy.h"
[email protected]f8aefb132013-10-30 09:29:5234#include "chrome/browser/extensions/extension_sync_service.h"
[email protected]617342a42013-12-18 23:34:0335#include "chrome/browser/extensions/extension_util.h"
[email protected]2894a512014-06-26 19:03:5636#include "chrome/browser/extensions/external_install_manager.h"
[email protected]5df038b2012-07-16 19:03:2737#include "chrome/browser/extensions/external_provider_impl.h"
[email protected]ffd2f79e2013-11-14 00:11:4638#include "chrome/browser/extensions/install_verifier.h"
[email protected]d8c8f25f2011-11-02 18:18:0139#include "chrome/browser/extensions/installed_loader.h"
[email protected]f3d3b382014-03-14 21:19:2840#include "chrome/browser/extensions/pending_extension_manager.h"
[email protected]13e062e2014-08-09 10:21:5541#include "chrome/browser/extensions/permissions_updater.h"
[email protected]90878c52014-04-04 18:21:0242#include "chrome/browser/extensions/shared_module_service.h"
[email protected]13e062e2014-08-09 10:21:5543#include "chrome/browser/extensions/unpacked_installer.h"
rockotdb5192992014-09-16 21:27:0244#include "chrome/browser/extensions/updater/chrome_extension_downloader_factory.h"
[email protected]13e062e2014-08-09 10:21:5545#include "chrome/browser/extensions/updater/extension_updater.h"
rockotdb5192992014-09-16 21:27:0246#include "chrome/browser/google/google_brand.h"
[email protected]8ecad5e2010-12-02 21:18:3347#include "chrome/browser/profiles/profile.h"
[email protected]b5a507b22013-11-08 20:41:5748#include "chrome/browser/ui/webui/extensions/extension_icon_source.h"
[email protected]c8d407e2011-04-28 21:27:1749#include "chrome/browser/ui/webui/favicon_source.h"
[email protected]5eddc3e2011-10-26 04:33:3150#include "chrome/browser/ui/webui/ntp/thumbnail_source.h"
[email protected]b07e606e2012-09-15 20:16:1551#include "chrome/browser/ui/webui/theme_source.h"
[email protected]e2eb43112009-05-29 21:19:5452#include "chrome/common/chrome_switches.h"
[email protected]f6431be82013-09-07 02:53:4553#include "chrome/common/crash_keys.h"
[email protected]9f4e4f082013-06-21 07:11:1954#include "chrome/common/extensions/extension_constants.h"
[email protected]15d4d2d2013-08-09 06:49:0355#include "chrome/common/extensions/features/feature_channel.h"
[email protected]a57209872009-05-04 22:53:1456#include "chrome/common/url_constants.h"
mukai8eaec822014-10-25 17:53:1657#include "components/content_settings/core/browser/host_content_settings_map.h"
[email protected]fdd28372014-08-21 02:27:2658#include "components/crx_file/id_util.h"
[email protected]7a83dd072013-09-03 12:09:1759#include "components/startup_metric_utils/startup_metric_utils.h"
[email protected]dccba4f82014-05-29 00:52:5660#include "content/public/browser/devtools_agent_host.h"
[email protected]05aad2da2011-10-28 10:12:3761#include "content/public/browser/notification_service.h"
[email protected]f3b1a082011-11-18 00:34:3062#include "content/public/browser/render_process_host.h"
[email protected]399583b2012-12-11 09:33:4263#include "content/public/browser/storage_partition.h"
[email protected]34423532013-11-21 18:13:1064#include "extensions/browser/event_router.h"
[email protected]22401dc2014-03-21 01:38:5765#include "extensions/browser/extension_host.h"
[email protected]dccba4f82014-05-29 00:52:5666#include "extensions/browser/extension_prefs.h"
[email protected]bb1bc9b32013-12-21 03:09:1467#include "extensions/browser/extension_registry.h"
[email protected]59b0e602014-01-30 00:41:2468#include "extensions/browser/extension_system.h"
rockotffa65b12014-10-14 17:19:0669#include "extensions/browser/extensions_browser_client.h"
[email protected]4a1d9c0d2014-06-13 12:50:1170#include "extensions/browser/install_flag.h"
[email protected]45f5b7d2014-01-22 23:47:1371#include "extensions/browser/runtime_data.h"
[email protected]e43c61f2014-07-20 21:46:3472#include "extensions/browser/uninstall_reason.h"
[email protected]a9aa62b312013-11-29 05:35:0673#include "extensions/browser/update_observer.h"
rockotffa65b12014-10-14 17:19:0674#include "extensions/browser/updater/extension_cache.h"
rockot05f40a922014-10-16 19:40:2575#include "extensions/browser/updater/extension_downloader.h"
[email protected]fb820c02014-03-13 15:07:0876#include "extensions/common/extension_messages.h"
rockot90659852014-09-18 19:31:5277#include "extensions/common/extension_urls.h"
[email protected]5ef835a2013-11-08 20:42:5778#include "extensions/common/feature_switch.h"
[email protected]85df9d12014-04-15 17:02:1479#include "extensions/common/file_util.h"
[email protected]0c3c9732013-09-16 08:53:4180#include "extensions/common/manifest_constants.h"
[email protected]558878cc82013-11-09 01:25:5181#include "extensions/common/manifest_handlers/background_info.h"
rockotd5546142014-10-15 00:29:0882#include "extensions/common/manifest_url_handlers.h"
[email protected]dccba4f82014-05-29 00:52:5683#include "extensions/common/one_shot_event.h"
[email protected]c41003472013-10-19 15:37:2584#include "extensions/common/permissions/permission_message_provider.h"
[email protected]e4452d32013-11-15 23:07:4185#include "extensions/common/permissions/permissions_data.h"
[email protected]79a60642012-10-20 21:03:1886
[email protected]eed367e2011-04-12 03:43:3187#if defined(OS_CHROMEOS)
[email protected]88e8ec9152013-01-17 04:05:1888#include "chrome/browser/chromeos/extensions/install_limiter.h"
pilgrime92c5fcd2014-09-10 23:31:2389#include "storage/browser/fileapi/file_system_backend.h"
90#include "storage/browser/fileapi/file_system_context.h"
[email protected]eed367e2011-04-12 03:43:3191#endif
92
[email protected]55eb70e762012-02-20 17:38:3993using content::BrowserContext;
[email protected]631bb742011-11-02 11:29:3994using content::BrowserThread;
[email protected]98f66112012-12-25 12:59:3695using content::DevToolsAgentHost;
[email protected]bf3d9df2012-07-24 23:20:2796using extensions::CrxInstaller;
[email protected]1c321ee52012-05-21 03:02:3497using extensions::Extension;
98using extensions::ExtensionIdSet;
99using extensions::ExtensionInfo;
[email protected]599539802014-01-07 23:06:00100using extensions::ExtensionRegistry;
[email protected]289c44b2013-12-17 03:26:57101using extensions::ExtensionSet;
[email protected]215a7be2012-10-22 19:53:42102using extensions::FeatureSwitch;
[email protected]ffd2f79e2013-11-14 00:11:46103using extensions::InstallVerifier;
[email protected]0d54b682013-11-05 14:15:36104using extensions::ManagementPolicy;
[email protected]1d5e58b2013-01-31 08:41:40105using extensions::Manifest;
[email protected]c2e66e12012-06-27 06:27:06106using extensions::PermissionMessage;
107using extensions::PermissionMessages;
108using extensions::PermissionSet;
[email protected]9f4e4f082013-06-21 07:11:19109using extensions::SharedModuleInfo;
[email protected]90878c52014-04-04 18:21:02110using extensions::SharedModuleService;
[email protected]e410b5f2012-12-14 14:02:24111using extensions::UnloadedExtensionInfo;
[email protected]5ef47ec2010-01-28 05:58:05112
[email protected]0c3c9732013-09-16 08:53:41113namespace errors = extensions::manifest_errors;
[email protected]c6d474f82009-12-16 21:11:06114
[email protected]b6ab96d2009-08-20 18:58:19115namespace {
116
[email protected]0db124b02012-11-07 04:55:05117// Wait this many seconds after an extensions becomes idle before updating it.
[email protected]ddc6a122014-06-27 04:52:32118const int kUpdateIdleDelay = 5;
[email protected]0db124b02012-11-07 04:55:05119
[email protected]c6d474f82009-12-16 21:11:06120} // namespace
[email protected]b6ab96d2009-08-20 18:58:19121
[email protected]eaa7dd182010-12-14 11:09:00122// ExtensionService.
[email protected]6014d672008-12-05 00:38:25123
[email protected]8e4560b62011-01-14 10:09:14124void ExtensionService::CheckExternalUninstall(const std::string& id) {
[email protected]a29a517a2011-01-21 21:11:12125 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]a8af9fdb2010-10-28 21:52:20126
[email protected]7a4c6852010-09-16 03:44:22127 // Check if the providers know about this extension.
[email protected]5df038b2012-07-16 19:03:27128 extensions::ProviderCollection::const_iterator i;
[email protected]0a60a2e2010-10-25 16:15:21129 for (i = external_extension_providers_.begin();
130 i != external_extension_providers_.end(); ++i) {
[email protected]8e4560b62011-01-14 10:09:14131 DCHECK(i->get()->IsReady());
[email protected]0a60a2e2010-10-25 16:15:21132 if (i->get()->HasExtension(id))
133 return; // Yup, known extension, don't uninstall.
[email protected]7a4c6852010-09-16 03:44:22134 }
135
[email protected]0f48fca2011-05-19 18:46:35136 // We get the list of external extensions to check from preferences.
137 // It is possible that an extension has preferences but is not loaded.
138 // For example, an extension that requires experimental permissions
139 // will not be loaded if the experimental command line flag is not used.
140 // In this case, do not uninstall.
[email protected]31bb5ee62012-09-12 22:58:40141 if (!GetInstalledExtension(id)) {
[email protected]0f48fca2011-05-19 18:46:35142 // We can't call UninstallExtension with an unloaded/invalid
143 // extension ID.
144 LOG(WARNING) << "Attempted uninstallation of unloaded/invalid extension "
145 << "with id: " << id;
146 return;
147 }
[email protected]42d58f62014-07-31 01:32:45148 UninstallExtension(id,
149 extensions::UNINSTALL_REASON_ORPHANED_EXTERNAL_EXTENSION,
150 base::Bind(&base::DoNothing),
151 NULL);
[email protected]7a4c6852010-09-16 03:44:22152}
153
[email protected]7f8f24f2012-11-15 19:40:14154void ExtensionService::SetFileTaskRunnerForTesting(
dcheng605ef8d2014-08-28 18:29:44155 const scoped_refptr<base::SequencedTaskRunner>& task_runner) {
[email protected]7f8f24f2012-11-15 19:40:14156 file_task_runner_ = task_runner;
157}
158
[email protected]8e4560b62011-01-14 10:09:14159void ExtensionService::ClearProvidersForTesting() {
[email protected]7a4c6852010-09-16 03:44:22160 external_extension_providers_.clear();
161}
162
[email protected]8e4560b62011-01-14 10:09:14163void ExtensionService::AddProviderForTesting(
[email protected]5df038b2012-07-16 19:03:27164 extensions::ExternalProviderInterface* test_provider) {
[email protected]a29a517a2011-01-21 21:11:12165 CHECK(test_provider);
[email protected]0a60a2e2010-10-25 16:15:21166 external_extension_providers_.push_back(
[email protected]5df038b2012-07-16 19:03:27167 linked_ptr<extensions::ExternalProviderInterface>(test_provider));
[email protected]7a4c6852010-09-16 03:44:22168}
169
[email protected]8f959f522014-08-06 06:26:28170void ExtensionService::BlacklistExtensionForTest(
171 const std::string& extension_id) {
mlerman6a37b6a42014-11-26 22:10:53172 ExtensionIdSet blacklisted;
[email protected]8f959f522014-08-06 06:26:28173 ExtensionIdSet unchanged;
mlerman6a37b6a42014-11-26 22:10:53174 blacklisted.insert(extension_id);
175 UpdateBlacklistedExtensions(blacklisted, unchanged);
[email protected]8f959f522014-08-06 06:26:28176}
177
[email protected]9060d8b02012-01-13 02:14:30178bool ExtensionService::OnExternalExtensionUpdateUrlFound(
[email protected]7a4c6852010-09-16 03:44:22179 const std::string& id,
[email protected]d8fd0fd2014-03-24 13:16:06180 const std::string& install_parameter,
[email protected]21a5a672010-11-04 10:47:42181 const GURL& update_url,
[email protected]464213a2013-10-15 01:06:48182 Manifest::Location location,
183 int creation_flags,
184 bool mark_acknowledged) {
[email protected]ab22ba42011-01-14 16:36:38185 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]fdd28372014-08-21 02:27:26186 CHECK(crx_file::id_util::IdIsValid(id));
[email protected]a8af9fdb2010-10-28 21:52:20187
[email protected]044e86992014-01-24 22:59:11188 if (Manifest::IsExternalLocation(location)) {
189 // All extensions that are not user specific can be cached.
rockotffa65b12014-10-14 17:19:06190 extensions::ExtensionsBrowserClient::Get()->GetExtensionCache()
191 ->AllowCaching(id);
[email protected]044e86992014-01-24 22:59:11192 }
193
[email protected]8a87a5332011-08-11 17:54:59194 const Extension* extension = GetExtensionById(id, true);
195 if (extension) {
196 // Already installed. Skip this install if the current location has
197 // higher priority than |location|.
[email protected]1d5e58b2013-01-31 08:41:40198 Manifest::Location current = extension->location();
199 if (current == Manifest::GetHigherPriorityLocation(current, location))
[email protected]9060d8b02012-01-13 02:14:30200 return false;
[email protected]8a87a5332011-08-11 17:54:59201 // Otherwise, overwrite the current installation.
[email protected]7a4c6852010-09-16 03:44:22202 }
[email protected]9060d8b02012-01-13 02:14:30203
204 // Add |id| to the set of pending extensions. If it can not be added,
205 // then there is already a pending record from a higher-priority install
206 // source. In this case, signal that this extension will not be
207 // installed by returning false.
208 if (!pending_extension_manager()->AddFromExternalUpdateUrl(
[email protected]d8fd0fd2014-03-24 13:16:06209 id,
210 install_parameter,
211 update_url,
212 location,
213 creation_flags,
214 mark_acknowledged)) {
[email protected]9060d8b02012-01-13 02:14:30215 return false;
[email protected]31bb5ee62012-09-12 22:58:40216 }
[email protected]9060d8b02012-01-13 02:14:30217
[email protected]94fde232012-04-27 10:22:30218 update_once_all_providers_are_ready_ = true;
[email protected]9060d8b02012-01-13 02:14:30219 return true;
[email protected]7a4c6852010-09-16 03:44:22220}
221
[email protected]6aeac8342010-10-01 20:21:18222// static
[email protected]cc2f55c2014-07-08 02:19:04223// This function is used to uninstall an extension via sync. The LOG statements
224// within this function are used to inform the user if the uninstall cannot be
225// done.
[email protected]eaa7dd182010-12-14 11:09:00226bool ExtensionService::UninstallExtensionHelper(
227 ExtensionService* extensions_service,
[email protected]cc2f55c2014-07-08 02:19:04228 const std::string& extension_id,
[email protected]e43c61f2014-07-20 21:46:34229 extensions::UninstallReason reason) {
[email protected]d6ebc9792011-04-07 18:18:33230 // We can't call UninstallExtension with an invalid extension ID.
[email protected]31bb5ee62012-09-12 22:58:40231 if (!extensions_service->GetInstalledExtension(extension_id)) {
[email protected]6aeac8342010-10-01 20:21:18232 LOG(WARNING) << "Attempted uninstallation of non-existent extension with "
[email protected]95da88c42011-03-31 10:07:33233 << "id: " << extension_id;
234 return false;
[email protected]6aeac8342010-10-01 20:21:18235 }
236
[email protected]d6ebc9792011-04-07 18:18:33237 // The following call to UninstallExtension will not allow an uninstall of a
238 // policy-controlled extension.
[email protected]439f1e32013-12-09 20:09:09239 base::string16 error;
[email protected]42d58f62014-07-31 01:32:45240 if (!extensions_service->UninstallExtension(
241 extension_id, reason, base::Bind(&base::DoNothing), &error)) {
[email protected]d6ebc9792011-04-07 18:18:33242 LOG(WARNING) << "Cannot uninstall extension with id " << extension_id
243 << ": " << error;
244 return false;
245 }
[email protected]95da88c42011-03-31 10:07:33246
[email protected]6aeac8342010-10-01 20:21:18247 return true;
248}
249
[email protected]eaa7dd182010-12-14 11:09:00250ExtensionService::ExtensionService(Profile* profile,
avi3ef9ec9e2014-12-22 22:50:17251 const base::CommandLine* command_line,
[email protected]650b2d52013-02-10 03:41:45252 const base::FilePath& install_directory,
[email protected]45759612012-07-10 17:21:23253 extensions::ExtensionPrefs* extension_prefs,
[email protected]fdd679b2012-11-15 20:49:39254 extensions::Blacklist* blacklist,
[email protected]0436b102011-04-15 18:30:03255 bool autoupdate_enabled,
[email protected]4a10006a2013-05-17 23:18:35256 bool extensions_enabled,
257 extensions::OneShotEvent* ready)
[email protected]fdd679b2012-11-15 20:49:39258 : extensions::Blacklist::Observer(blacklist),
259 profile_(profile),
[email protected]bd306722012-07-11 20:43:59260 system_(extensions::ExtensionSystem::Get(profile)),
[email protected]73c47932010-12-06 18:13:43261 extension_prefs_(extension_prefs),
[email protected]695b5712012-12-06 23:55:28262 blacklist_(blacklist),
[email protected]f8aefb132013-10-30 09:29:52263 extension_sync_service_(NULL),
[email protected]5fdfa562013-12-27 17:43:59264 registry_(extensions::ExtensionRegistry::Get(profile)),
[email protected]6c9bedf2014-05-21 03:55:51265 pending_extension_manager_(profile),
[email protected]a9b00ac2009-06-25 21:03:23266 install_directory_(install_directory),
[email protected]0436b102011-04-15 18:30:03267 extensions_enabled_(extensions_enabled),
[email protected]e81dba32009-06-19 20:19:13268 show_extensions_prompts_(true),
[email protected]fc332ae2012-11-14 20:17:33269 install_updates_when_idle_(true),
[email protected]4a10006a2013-05-17 23:18:35270 ready_(ready),
[email protected]dff1e042012-04-27 10:59:18271 update_once_all_providers_are_ready_(false),
[email protected]3c4abc82012-10-22 22:25:54272 browser_terminating_(false),
[email protected]9f4e4f082013-06-21 07:11:19273 installs_delayed_for_gc_(false),
[email protected]e5f8fffe2014-04-02 00:30:44274 is_first_run_(false),
mlerman6a37b6a42014-11-26 22:10:53275 block_extensions_(false),
ryanackley48bedbd2015-01-27 23:12:14276 shared_module_service_(new extensions::SharedModuleService(profile_)),
277 app_data_migrator_(new extensions::AppDataMigrator(profile_, registry_)) {
[email protected]a29a517a2011-01-21 21:11:12278 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]a8af9fdb2010-10-28 21:52:20279
[email protected]36a784c2009-06-23 06:21:08280 // Figure out if extension installation should be enabled.
[email protected]367d9b172013-12-03 00:31:02281 if (extensions::ExtensionsBrowserClient::Get()->AreExtensionsDisabled(
282 *command_line, profile))
[email protected]6d60703b2009-08-29 01:29:23283 extensions_enabled_ = false;
[email protected]36a784c2009-06-23 06:21:08284
[email protected]3c4abc82012-10-22 22:25:54285 registrar_.Add(this, chrome::NOTIFICATION_APP_TERMINATING,
286 content::NotificationService::AllBrowserContextsAndSources());
[email protected]adf5a102014-07-31 12:44:06287 registrar_.Add(this,
288 extensions::NOTIFICATION_EXTENSION_PROCESS_TERMINATED,
[email protected]ad50def52011-10-19 23:17:07289 content::NotificationService::AllBrowserContextsAndSources());
[email protected]432115822011-07-10 15:52:27290 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_TERMINATED,
[email protected]ad50def52011-10-19 23:17:07291 content::NotificationService::AllBrowserContextsAndSources());
[email protected]92dd8d92013-02-26 00:41:08292 registrar_.Add(this, chrome::NOTIFICATION_UPGRADE_RECOMMENDED,
293 content::NotificationService::AllBrowserContextsAndSources());
[email protected]ebe07772014-05-22 04:16:06294 registrar_.Add(this,
295 chrome::NOTIFICATION_PROFILE_DESTRUCTION_STARTED,
296 content::Source<Profile>(profile_));
binjin1569c9b2014-09-05 13:33:18297
298 extensions::ExtensionManagementFactory::GetForBrowserContext(profile_)
299 ->AddObserver(this);
[email protected]4814b512009-11-07 00:12:29300
[email protected]93fd78f42009-07-10 16:43:17301 // Set up the ExtensionUpdater
302 if (autoupdate_enabled) {
[email protected]501105b2013-09-26 05:42:02303 int update_frequency = extensions::kDefaultUpdateFrequencySeconds;
[email protected]93fd78f42009-07-10 16:43:17304 if (command_line->HasSwitch(switches::kExtensionsUpdateFrequency)) {
[email protected]e83326f2010-07-31 17:29:25305 base::StringToInt(command_line->GetSwitchValueASCII(
306 switches::kExtensionsUpdateFrequency),
307 &update_frequency);
[email protected]93fd78f42009-07-10 16:43:17308 }
[email protected]044e86992014-01-24 22:59:11309 updater_.reset(new extensions::ExtensionUpdater(
310 this,
311 extension_prefs,
312 profile->GetPrefs(),
313 profile,
314 update_frequency,
rockotffa65b12014-10-14 17:19:06315 extensions::ExtensionsBrowserClient::Get()->GetExtensionCache(),
rockotdb5192992014-09-16 21:27:02316 base::Bind(ChromeExtensionDownloaderFactory::CreateForProfile,
317 profile)));
[email protected]93fd78f42009-07-10 16:43:17318 }
319
[email protected]25ae0152011-11-18 14:40:02320 component_loader_.reset(
321 new extensions::ComponentLoader(this,
322 profile->GetPrefs(),
[email protected]55e16cd2013-12-18 04:36:08323 g_browser_process->local_state(),
324 profile));
[email protected]8e4560b62011-01-14 10:09:14325
[email protected]0436b102011-04-15 18:30:03326 if (extensions_enabled_) {
[email protected]ae4c37e2012-12-21 01:16:25327 extensions::ExternalProviderImpl::CreateExternalProviders(
328 this, profile_, &external_extension_providers_);
[email protected]873531342011-03-09 12:16:05329 }
[email protected]b671760b2010-07-15 21:13:47330
[email protected]74474042013-11-21 12:03:54331 // Set this as the ExtensionService for app sorting to ensure it causes syncs
332 // if required.
[email protected]b3aa7182013-04-25 04:45:23333 is_first_run_ = !extension_prefs_->SetAlertSystemFirstRun();
334
[email protected]373daf972014-04-10 01:50:44335 error_controller_.reset(
336 new extensions::ExtensionErrorController(profile_, is_first_run_));
[email protected]374ceb6f2014-07-02 19:25:34337 external_install_manager_.reset(
338 new extensions::ExternalInstallManager(profile_, is_first_run_));
[email protected]373daf972014-04-10 01:50:44339
[email protected]c77f2352012-08-08 22:07:58340 extension_action_storage_manager_.reset(
341 new extensions::ExtensionActionStorageManager(profile_));
342
[email protected]cb0e50312011-05-09 15:03:07343 // How long is the path to the Extensions directory?
344 UMA_HISTOGRAM_CUSTOM_COUNTS("Extensions.ExtensionRootPathLength",
345 install_directory_.value().length(), 0, 500, 100);
[email protected]6014d672008-12-05 00:38:25346}
347
[email protected]3f213ad2012-07-26 23:39:41348extensions::PendingExtensionManager*
349 ExtensionService::pending_extension_manager() {
[email protected]b2907fd2011-03-25 16:43:37350 return &pending_extension_manager_;
[email protected]ddb1e5a2010-12-13 20:10:45351}
352
[email protected]eaa7dd182010-12-14 11:09:00353ExtensionService::~ExtensionService() {
[email protected]c8d407e2011-04-28 21:27:17354 // No need to unload extensions here because they are profile-scoped, and the
355 // profile is in the process of being deleted.
[email protected]94b4ffc2011-02-04 05:55:17356
[email protected]5df038b2012-07-16 19:03:27357 extensions::ProviderCollection::const_iterator i;
[email protected]8e4560b62011-01-14 10:09:14358 for (i = external_extension_providers_.begin();
359 i != external_extension_providers_.end(); ++i) {
[email protected]5df038b2012-07-16 19:03:27360 extensions::ExternalProviderInterface* provider = i->get();
[email protected]8e4560b62011-01-14 10:09:14361 provider->ServiceShutdown();
362 }
[email protected]6014d672008-12-05 00:38:25363}
364
[email protected]037228a2012-10-05 01:36:16365void ExtensionService::Shutdown() {
binjin1569c9b2014-09-05 13:33:18366 extensions::ExtensionManagementFactory::GetInstance()
367 ->GetForBrowserContext(profile())
368 ->RemoveObserver(this);
[email protected]4c9201c42013-08-16 04:56:21369 system_->management_policy()->UnregisterProvider(
370 shared_module_policy_provider_.get());
[email protected]037228a2012-10-05 01:36:16371}
372
[email protected]b2907fd2011-03-25 16:43:37373const Extension* ExtensionService::GetExtensionById(
374 const std::string& id, bool include_disabled) const {
[email protected]599539802014-01-07 23:06:00375 int include_mask = ExtensionRegistry::ENABLED;
[email protected]695b5712012-12-06 23:55:28376 if (include_disabled) {
mlerman6a37b6a42014-11-26 22:10:53377 // Include blacklisted and blocked extensions here because there are
378 // hundreds of callers of this function, and many might assume that this
379 // includes those that have been disabled due to blacklisting or blocking.
[email protected]599539802014-01-07 23:06:00380 include_mask |= ExtensionRegistry::DISABLED |
mlerman6a37b6a42014-11-26 22:10:53381 ExtensionRegistry::BLACKLISTED | ExtensionRegistry::BLOCKED;
[email protected]695b5712012-12-06 23:55:28382 }
[email protected]599539802014-01-07 23:06:00383 return registry_->GetExtensionById(id, include_mask);
[email protected]695b5712012-12-06 23:55:28384}
385
[email protected]eaa7dd182010-12-14 11:09:00386void ExtensionService::Init() {
[email protected]a29a517a2011-01-21 21:11:12387 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
rkaplowe65c2ff2015-02-14 16:29:54388 TRACE_EVENT0("browser,startup", "ExtensionService::Init");
[email protected]3350d712013-11-18 09:32:24389 base::Time begin_time = base::Time::Now();
390
[email protected]4a10006a2013-05-17 23:18:35391 DCHECK(!is_ready()); // Can't redo init.
[email protected]bb1bc9b32013-12-21 03:09:14392 DCHECK_EQ(registry_->enabled_extensions().size(), 0u);
[email protected]9f1087e2009-06-15 17:29:32393
avi3ef9ec9e2014-12-22 22:50:17394 const base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess();
rdevlin.cronin462b2fb2014-10-02 18:32:52395 if (cmd_line->HasSwitch(switches::kInstallEphemeralAppFromWebstore)) {
[email protected]820d9bd2013-04-03 03:46:03396 // The sole purpose of this launch is to install a new extension from CWS
397 // and immediately terminate: loading already installed extensions is
398 // unnecessary and may interfere with the inline install dialog (e.g. if an
399 // extension listens to onStartup and opens a window).
400 SetReadyAndNotifyListeners();
[email protected]ae4c37e2012-12-21 01:16:25401 } else {
[email protected]47b60072013-06-20 10:35:56402 // LoadAllExtensions() calls OnLoadedInstalledExtensions().
403 component_loader_->LoadAll();
404 extensions::InstalledLoader(this).LoadAllExtensions();
[email protected]9f4e4f082013-06-21 07:11:19405
[email protected]2edd57852013-08-14 22:07:40406 // Attempt to re-enable extensions whose only disable reason is reloading.
407 std::vector<std::string> extensions_to_enable;
[email protected]bb1bc9b32013-12-21 03:09:14408 const ExtensionSet& disabled_extensions = registry_->disabled_extensions();
409 for (ExtensionSet::const_iterator iter = disabled_extensions.begin();
410 iter != disabled_extensions.end(); ++iter) {
[email protected]2edd57852013-08-14 22:07:40411 const Extension* e = iter->get();
412 if (extension_prefs_->GetDisableReasons(e->id()) ==
413 Extension::DISABLE_RELOAD) {
414 extensions_to_enable.push_back(e->id());
415 }
416 }
417 for (std::vector<std::string>::iterator it = extensions_to_enable.begin();
418 it != extensions_to_enable.end(); ++it) {
419 EnableExtension(*it);
420 }
421
[email protected]9f4e4f082013-06-21 07:11:19422 // Finish install (if possible) of extensions that were still delayed while
423 // the browser was shut down.
424 scoped_ptr<extensions::ExtensionPrefs::ExtensionsInfo> delayed_info(
425 extension_prefs_->GetAllDelayedInstallInfo());
426 for (size_t i = 0; i < delayed_info->size(); ++i) {
427 ExtensionInfo* info = delayed_info->at(i).get();
428 scoped_refptr<const Extension> extension(NULL);
429 if (info->extension_manifest) {
430 std::string error;
431 extension = Extension::Create(
432 info->extension_path,
433 info->extension_location,
434 *info->extension_manifest,
435 extension_prefs_->GetDelayedInstallCreationFlags(
436 info->extension_id),
437 info->extension_id,
438 &error);
439 if (extension.get())
440 delayed_installs_.Insert(extension);
441 }
442 }
443 MaybeFinishDelayedInstallations();
444
445 scoped_ptr<extensions::ExtensionPrefs::ExtensionsInfo> delayed_info2(
446 extension_prefs_->GetAllDelayedInstallInfo());
447 UMA_HISTOGRAM_COUNTS_100("Extensions.UpdateOnLoad",
448 delayed_info2->size() - delayed_info->size());
449
[email protected]47b60072013-06-20 10:35:56450 SetReadyAndNotifyListeners();
[email protected]ae4c37e2012-12-21 01:16:25451
[email protected]47b60072013-06-20 10:35:56452 // TODO(erikkay) this should probably be deferred to a future point
453 // rather than running immediately at startup.
454 CheckForExternalUpdates();
[email protected]894bb502009-05-21 22:39:57455
[email protected]2d19eb6e2014-01-27 17:30:00456 LoadGreylistFromPrefs();
[email protected]399583b2012-12-11 09:33:42457 }
[email protected]3350d712013-11-18 09:32:24458
459 UMA_HISTOGRAM_TIMES("Extensions.ExtensionServiceInitTime",
460 base::Time::Now() - begin_time);
[email protected]6014d672008-12-05 00:38:25461}
462
[email protected]2d19eb6e2014-01-27 17:30:00463void ExtensionService::LoadGreylistFromPrefs() {
[email protected]f47f7172014-03-19 19:27:10464 scoped_ptr<ExtensionSet> all_extensions =
465 registry_->GenerateInstalledExtensionsSet();
[email protected]2d19eb6e2014-01-27 17:30:00466
467 for (ExtensionSet::const_iterator it = all_extensions->begin();
468 it != all_extensions->end(); ++it) {
469 extensions::BlacklistState state =
470 extension_prefs_->GetExtensionBlacklistState((*it)->id());
471 if (state == extensions::BLACKLISTED_SECURITY_VULNERABILITY ||
472 state == extensions::BLACKLISTED_POTENTIALLY_UNWANTED ||
473 state == extensions::BLACKLISTED_CWS_POLICY_VIOLATION)
474 greylist_.Insert(*it);
475 }
476}
477
ginkage553af3202015-02-04 12:39:09478bool ExtensionService::UpdateExtension(const extensions::CRXFileInfo& file,
[email protected]044e86992014-01-24 22:59:11479 bool file_ownership_passed,
[email protected]31bb5ee62012-09-12 22:58:40480 CrxInstaller** out_crx_installer) {
[email protected]a29a517a2011-01-21 21:11:12481 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]3c4abc82012-10-22 22:25:54482 if (browser_terminating_) {
483 LOG(WARNING) << "Skipping UpdateExtension due to browser shutdown";
484 // Leak the temp file at extension_path. We don't want to add to the disk
485 // I/O burden at shutdown, we can't rely on the I/O completing anyway, and
486 // the file is in the OS temp directory which should be cleaned up for us.
487 return false;
488 }
[email protected]a8af9fdb2010-10-28 21:52:20489
ginkage553af3202015-02-04 12:39:09490 const std::string& id = file.extension_id;
491
[email protected]3f213ad2012-07-26 23:39:41492 const extensions::PendingExtensionInfo* pending_extension_info =
[email protected]51a3bf8b2012-06-08 22:53:06493 pending_extension_manager()->GetById(id);
[email protected]8ef78fd2010-08-19 17:14:32494
[email protected]695b5712012-12-06 23:55:28495 const Extension* extension = GetInstalledExtension(id);
[email protected]51a3bf8b2012-06-08 22:53:06496 if (!pending_extension_info && !extension) {
[email protected]aa142702010-03-26 01:26:33497 LOG(WARNING) << "Will not update extension " << id
498 << " because it is not installed or pending";
499 // Delete extension_path since we're not creating a CrxInstaller
500 // that would do it for us.
[email protected]7f8f24f2012-11-15 19:40:14501 if (!GetFileTaskRunner()->PostTask(
502 FROM_HERE,
ginkage553af3202015-02-04 12:39:09503 base::Bind(&extensions::file_util::DeleteFile, file.path, false)))
[email protected]14908b72011-04-20 06:54:36504 NOTREACHED();
[email protected]420a0ec2011-06-01 01:07:03505
506 return false;
[email protected]e957fe52009-06-23 16:51:05507 }
508
[email protected]f8636f92013-08-09 21:02:37509 scoped_refptr<CrxInstaller> installer(
pkotwicz31eb1e8ec2014-10-08 15:26:46510 CrxInstaller::Create(this, scoped_ptr<ExtensionInstallPrompt>()));
[email protected]6dfbbf82010-03-12 23:09:16511 installer->set_expected_id(id);
[email protected]464213a2013-10-15 01:06:48512 int creation_flags = Extension::NO_FLAGS;
[email protected]51a3bf8b2012-06-08 22:53:06513 if (pending_extension_info) {
514 installer->set_install_source(pending_extension_info->install_source());
pkotwicz31eb1e8ec2014-10-08 15:26:46515 installer->set_allow_silent_install(true);
[email protected]21db9ef2014-05-16 02:06:27516 if (pending_extension_info->remote_install())
517 installer->set_grant_permissions(false);
[email protected]464213a2013-10-15 01:06:48518 creation_flags = pending_extension_info->creation_flags();
519 if (pending_extension_info->mark_acknowledged())
[email protected]374ceb6f2014-07-02 19:25:34520 external_install_manager_->AcknowledgeExternalExtension(id);
[email protected]51a3bf8b2012-06-08 22:53:06521 } else if (extension) {
[email protected]5eb375e92010-11-26 07:50:41522 installer->set_install_source(extension->location());
[email protected]51a3bf8b2012-06-08 22:53:06523 }
[email protected]7d8b7072012-04-07 01:07:46524 // If the extension was installed from or has migrated to the webstore, or
[email protected]fcb2c2c2012-10-17 21:08:45525 // its auto-update URL is from the webstore, treat it as a webstore install.
526 // Note that we ignore some older extensions with blank auto-update URLs
527 // because we are mostly concerned with restrictions on NaCl extensions,
528 // which are newer.
[email protected]75764512011-12-19 19:54:28529 if ((extension && extension->from_webstore()) ||
[email protected]4a5fe3e22013-06-04 07:06:38530 (extension && extensions::ManifestURL::UpdatesFromGallery(extension)) ||
[email protected]963d13c2012-09-29 17:13:35531 (!extension && extension_urls::IsWebstoreUpdateUrl(
[email protected]51a3bf8b2012-06-08 22:53:06532 pending_extension_info->update_url()))) {
[email protected]a12ce8b22012-01-17 18:40:53533 creation_flags |= Extension::FROM_WEBSTORE;
534 }
535
536 // Bookmark apps being updated is kind of a contradiction, but that's because
537 // we mark the default apps as bookmark apps, and they're hosted in the web
538 // store, thus they can get updated. See http://crbug.com/101605 for more
539 // details.
540 if (extension && extension->from_bookmark())
541 creation_flags |= Extension::FROM_BOOKMARK;
542
[email protected]e33bbc22012-08-27 22:05:46543 if (extension && extension->was_installed_by_default())
544 creation_flags |= Extension::WAS_INSTALLED_BY_DEFAULT;
545
[email protected]acc3c7c22014-03-19 06:23:39546 if (extension && extension->was_installed_by_oem())
547 creation_flags |= Extension::WAS_INSTALLED_BY_OEM;
548
[email protected]6338fa32014-07-16 21:41:59549 if (extension && extension->was_installed_by_custodian())
550 creation_flags |= Extension::WAS_INSTALLED_BY_CUSTODIAN;
551
[email protected]658eae52014-06-14 20:28:05552 if (extension) {
[email protected]411f8ae2014-05-22 11:12:23553 installer->set_is_ephemeral(extension_prefs_->IsEphemeralApp(id));
[email protected]c30bda262014-06-19 04:10:13554 installer->set_do_not_sync(extension_prefs_->DoNotSync(id));
[email protected]658eae52014-06-14 20:28:05555 }
[email protected]ab6c7be42014-01-16 02:05:54556
[email protected]a12ce8b22012-01-17 18:40:53557 installer->set_creation_flags(creation_flags);
558
[email protected]044e86992014-01-24 22:59:11559 installer->set_delete_source(file_ownership_passed);
[email protected]cb0e50312011-05-09 15:03:07560 installer->set_install_cause(extension_misc::INSTALL_CAUSE_UPDATE);
ginkage553af3202015-02-04 12:39:09561 installer->InstallCrxFile(file);
[email protected]420a0ec2011-06-01 01:07:03562
563 if (out_crx_installer)
[email protected]dc24976f2013-06-02 21:15:09564 *out_crx_installer = installer.get();
[email protected]420a0ec2011-06-01 01:07:03565
566 return true;
[email protected]e957fe52009-06-23 16:51:05567}
568
[email protected]bca4b832014-07-17 20:22:34569void ExtensionService::ReloadExtensionImpl(
[email protected]757d60a2014-05-23 00:11:44570 // "transient" because the process of reloading may cause the reference
571 // to become invalid. Instead, use |extension_id|, a copy.
[email protected]bca4b832014-07-17 20:22:34572 const std::string& transient_extension_id,
573 bool be_noisy) {
[email protected]a29a517a2011-01-21 21:11:12574 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]2a947202013-03-06 04:58:05575
576 // If the extension is already reloading, don't reload again.
[email protected]757d60a2014-05-23 00:11:44577 if (extension_prefs_->GetDisableReasons(transient_extension_id) &
[email protected]2a947202013-03-06 04:58:05578 Extension::DISABLE_RELOAD) {
579 return;
580 }
581
mlerman6a37b6a42014-11-26 22:10:53582 // Ignore attempts to reload a blacklisted or blocked extension. Sometimes
583 // this can happen in a convoluted reload sequence triggered by the
584 // termination of a blacklisted or blocked extension and a naive attempt to
585 // reload it. For an example see http://crbug.com/373842.
586 if (registry_->blacklisted_extensions().Contains(transient_extension_id) ||
587 registry_->blocked_extensions().Contains(transient_extension_id)) {
[email protected]757d60a2014-05-23 00:11:44588 return;
mlerman6a37b6a42014-11-26 22:10:53589 }
[email protected]757d60a2014-05-23 00:11:44590
[email protected]650b2d52013-02-10 03:41:45591 base::FilePath path;
[email protected]757d60a2014-05-23 00:11:44592
593 std::string extension_id = transient_extension_id;
594 const Extension* transient_current_extension =
595 GetExtensionById(extension_id, false);
[email protected]9cddd4702009-07-27 22:09:40596
[email protected]f17dbd42010-08-16 23:21:10597 // Disable the extension if it's loaded. It might not be loaded if it crashed.
[email protected]757d60a2014-05-23 00:11:44598 if (transient_current_extension) {
[email protected]4814b512009-11-07 00:12:29599 // If the extension has an inspector open for its background page, detach
600 // the inspector and hang onto a cookie for it, so that we can reattach
601 // later.
[email protected]31d8f5f22012-04-02 15:22:08602 // TODO(yoz): this is not incognito-safe!
reillyg0ea3fa902014-10-28 15:30:23603 extensions::ProcessManager* manager =
604 extensions::ProcessManager::Get(profile_);
[email protected]3a1dc572012-07-31 22:25:13605 extensions::ExtensionHost* host =
606 manager->GetBackgroundHostForExtension(extension_id);
[email protected]b3f957e62014-08-08 10:09:02607 if (host && DevToolsAgentHost::HasFor(host->host_contents())) {
[email protected]4814b512009-11-07 00:12:29608 // Look for an open inspector for the background page.
[email protected]04ea1bb2013-07-10 09:26:09609 scoped_refptr<DevToolsAgentHost> agent_host =
[email protected]b3f957e62014-08-08 10:09:02610 DevToolsAgentHost::GetOrCreateFor(host->host_contents());
611 agent_host->DisconnectWebContents();
[email protected]04ea1bb2013-07-10 09:26:09612 orphaned_dev_tools_[extension_id] = agent_host;
[email protected]4814b512009-11-07 00:12:29613 }
614
[email protected]757d60a2014-05-23 00:11:44615 path = transient_current_extension->path();
[email protected]58076192013-07-19 19:43:50616 // BeingUpgraded is set back to false when the extension is added.
rdevlin.cronin2c16c602014-11-21 01:35:49617 system_->runtime_data()->SetBeingUpgraded(transient_current_extension->id(),
[email protected]757d60a2014-05-23 00:11:44618 true);
[email protected]44d62b62012-04-11 00:06:03619 DisableExtension(extension_id, Extension::DISABLE_RELOAD);
[email protected]b914e2952013-04-26 07:10:03620 reloading_extensions_.insert(extension_id);
[email protected]1eb175082010-02-10 09:26:16621 } else {
[email protected]d32c02a2014-06-16 22:58:36622 std::map<std::string, base::FilePath>::const_iterator iter =
623 unloaded_extension_paths_.find(extension_id);
624 if (iter == unloaded_extension_paths_.end()) {
625 return;
626 }
[email protected]1eb175082010-02-10 09:26:16627 path = unloaded_extension_paths_[extension_id];
[email protected]b65272f2009-08-31 15:47:06628 }
629
[email protected]757d60a2014-05-23 00:11:44630 transient_current_extension = NULL;
631
[email protected]9f4e4f082013-06-21 07:11:19632 if (delayed_installs_.Contains(extension_id)) {
[email protected]6f6101832012-11-27 22:10:48633 FinishDelayedInstallation(extension_id);
[email protected]0db124b02012-11-07 04:55:05634 return;
635 }
636
[email protected]43ceb002012-02-10 23:19:15637 // If we're reloading a component extension, use the component extension
638 // loader's reloader.
639 if (component_loader_->Exists(extension_id)) {
640 component_loader_->Reload(extension_id);
641 return;
642 }
643
[email protected]e6090e42010-03-23 22:44:08644 // Check the installed extensions to see if what we're reloading was already
645 // installed.
646 scoped_ptr<ExtensionInfo> installed_extension(
647 extension_prefs_->GetInstalledExtensionInfo(extension_id));
648 if (installed_extension.get() &&
649 installed_extension->extension_manifest.get()) {
[email protected]d8c8f25f2011-11-02 18:18:01650 extensions::InstalledLoader(this).Load(*installed_extension, false);
[email protected]e6090e42010-03-23 22:44:08651 } else {
[email protected]d8c8f25f2011-11-02 18:18:01652 // Otherwise, the extension is unpacked (location LOAD).
[email protected]e6090e42010-03-23 22:44:08653 // We should always be able to remember the extension's path. If it's not in
654 // the map, someone failed to update |unloaded_extension_paths_|.
655 CHECK(!path.empty());
[email protected]bca4b832014-07-17 20:22:34656 scoped_refptr<extensions::UnpackedInstaller> unpacked_installer =
657 extensions::UnpackedInstaller::Create(this);
658 unpacked_installer->set_be_noisy_on_failure(be_noisy);
659 unpacked_installer->Load(path);
[email protected]e6090e42010-03-23 22:44:08660 }
[email protected]9cddd4702009-07-27 22:09:40661}
662
[email protected]bca4b832014-07-17 20:22:34663void ExtensionService::ReloadExtension(const std::string& extension_id) {
664 ReloadExtensionImpl(extension_id, true); // be_noisy
665}
666
667void ExtensionService::ReloadExtensionWithQuietFailure(
668 const std::string& extension_id) {
669 ReloadExtensionImpl(extension_id, false); // be_noisy
670}
671
[email protected]757d60a2014-05-23 00:11:44672bool ExtensionService::UninstallExtension(
673 // "transient" because the process of uninstalling may cause the reference
674 // to become invalid. Instead, use |extenson->id()|.
675 const std::string& transient_extension_id,
[email protected]e43c61f2014-07-20 21:46:34676 extensions::UninstallReason reason,
[email protected]42d58f62014-07-31 01:32:45677 const base::Closure& deletion_done_callback,
[email protected]757d60a2014-05-23 00:11:44678 base::string16* error) {
[email protected]a29a517a2011-01-21 21:11:12679 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]a8af9fdb2010-10-28 21:52:20680
[email protected]757d60a2014-05-23 00:11:44681 scoped_refptr<const Extension> extension =
682 GetInstalledExtension(transient_extension_id);
[email protected]631cf822009-05-15 07:01:25683
[email protected]e7afe2452010-08-22 16:19:13684 // Callers should not send us nonexistent extensions.
[email protected]dc24976f2013-06-02 21:15:09685 CHECK(extension.get());
[email protected]9f1087e2009-06-15 17:29:32686
binjincccacef2014-10-13 19:00:20687 ManagementPolicy* by_policy = system_->management_policy();
[email protected]95da88c42011-03-31 10:07:33688 // Policy change which triggers an uninstall will always set
689 // |external_uninstall| to true so this is the only way to uninstall
690 // managed extensions.
[email protected]90878c52014-04-04 18:21:02691 // Shared modules being uninstalled will also set |external_uninstall| to true
692 // so that we can guarantee users don't uninstall a shared module.
693 // (crbug.com/273300)
694 // TODO(rdevlin.cronin): This is probably not right. We should do something
695 // else, like include an enum IS_INTERNAL_UNINSTALL or IS_USER_UNINSTALL so
696 // we don't do this.
[email protected]cc2f55c2014-07-08 02:19:04697 bool external_uninstall =
[email protected]e43c61f2014-07-20 21:46:34698 (reason == extensions::UNINSTALL_REASON_INTERNAL_MANAGEMENT) ||
dtseng9fb3d5b2015-02-23 17:24:17699 (reason == extensions::UNINSTALL_REASON_COMPONENT_REMOVED) ||
rdevlin.cronin5f6b69d2014-09-20 01:23:35700 (reason == extensions::UNINSTALL_REASON_REINSTALL) ||
[email protected]e43c61f2014-07-20 21:46:34701 (reason == extensions::UNINSTALL_REASON_ORPHANED_EXTERNAL_EXTENSION) ||
[email protected]6ef60012014-07-22 19:08:12702 (reason == extensions::UNINSTALL_REASON_ORPHANED_SHARED_MODULE) ||
703 (reason == extensions::UNINSTALL_REASON_SYNC &&
dtseng9fb3d5b2015-02-23 17:24:17704 extension->was_installed_by_custodian());
[email protected]65187152012-06-02 13:14:14705 if (!external_uninstall &&
binjincccacef2014-10-13 19:00:20706 (!by_policy->UserMayModifySettings(extension.get(), error) ||
707 by_policy->MustRemainInstalled(extension.get(), error))) {
[email protected]ad50def52011-10-19 23:17:07708 content::NotificationService::current()->Notify(
[email protected]adf5a102014-07-31 12:44:06709 extensions::NOTIFICATION_EXTENSION_UNINSTALL_NOT_ALLOWED,
[email protected]6c2381d2011-10-19 02:52:53710 content::Source<Profile>(profile_),
[email protected]dc24976f2013-06-02 21:15:09711 content::Details<const Extension>(extension.get()));
[email protected]d6ebc9792011-04-07 18:18:33712 return false;
713 }
[email protected]95da88c42011-03-31 10:07:33714
[email protected]65f173552012-06-28 22:43:58715 syncer::SyncChange sync_change;
rdevlin.cronin5f6b69d2014-09-20 01:23:35716 // Don't sync the uninstall if we're going to reinstall the extension
717 // momentarily.
718 if (extension_sync_service_ &&
719 reason != extensions::UNINSTALL_REASON_REINSTALL) {
[email protected]f8aefb132013-10-30 09:29:52720 sync_change = extension_sync_service_->PrepareToSyncUninstallExtension(
721 extension.get(), is_ready());
[email protected]3bdba0d2011-08-23 07:17:30722 }
723
[email protected]d820bc52014-03-13 05:35:23724 system_->install_verifier()->Remove(extension->id());
[email protected]ffd2f79e2013-11-14 00:11:46725
[email protected]9b217652010-10-08 22:04:23726 UMA_HISTOGRAM_ENUMERATION("Extensions.UninstallType",
[email protected]7fa19f82010-12-21 19:40:08727 extension->GetType(), 100);
[email protected]dc24976f2013-06-02 21:15:09728 RecordPermissionMessagesHistogram(extension.get(),
[email protected]4c86be582014-06-04 08:39:11729 "Extensions.Permissions_Uninstall2");
[email protected]9b217652010-10-08 22:04:23730
[email protected]831aa212010-03-26 13:55:19731 // Unload before doing more cleanup to ensure that nothing is hanging on to
732 // any of these resources.
[email protected]757d60a2014-05-23 00:11:44733 UnloadExtension(extension->id(), UnloadedExtensionInfo::REASON_UNINSTALL);
[email protected]831aa212010-03-26 13:55:19734
[email protected]9f1087e2009-06-15 17:29:32735 // Tell the backend to start deleting installed extensions on the file thread.
[email protected]12075d12013-02-27 05:38:05736 if (!Manifest::IsUnpackedLocation(extension->location())) {
[email protected]7f8f24f2012-11-15 19:40:14737 if (!GetFileTaskRunner()->PostTask(
738 FROM_HERE,
[email protected]5a145e82014-05-29 22:19:07739 base::Bind(&ExtensionService::UninstallExtensionOnFileThread,
740 extension->id(),
741 profile_,
[email protected]85df9d12014-04-15 17:02:14742 install_directory_,
[email protected]5a145e82014-05-29 22:19:07743 extension->path())))
[email protected]14908b72011-04-20 06:54:36744 NOTREACHED();
[email protected]9f1087e2009-06-15 17:29:32745 }
746
[email protected]42d58f62014-07-31 01:32:45747 extensions::DataDeleter::StartDeleting(
748 profile_, extension.get(), deletion_done_callback);
[email protected]0d6ec3a72011-09-02 02:09:43749
[email protected]757d60a2014-05-23 00:11:44750 UntrackTerminatedExtension(extension->id());
[email protected]211030342010-09-30 18:41:06751
752 // Notify interested parties that we've uninstalled this extension.
[email protected]ad50def52011-10-19 23:17:07753 content::NotificationService::current()->Notify(
[email protected]adf5a102014-07-31 12:44:06754 extensions::NOTIFICATION_EXTENSION_UNINSTALLED_DEPRECATED,
[email protected]6c2381d2011-10-19 02:52:53755 content::Source<Profile>(profile_),
[email protected]dc24976f2013-06-02 21:15:09756 content::Details<const Extension>(extension.get()));
[email protected]e43c61f2014-07-20 21:46:34757 ExtensionRegistry::Get(profile_)
758 ->TriggerOnUninstalled(extension.get(), reason);
[email protected]d6ebc9792011-04-07 18:18:33759
rdevlin.cronin5f6b69d2014-09-20 01:23:35760 if (sync_change.IsValid()) {
[email protected]757d60a2014-05-23 00:11:44761 extension_sync_service_->ProcessSyncUninstallExtension(extension->id(),
[email protected]f8aefb132013-10-30 09:29:52762 sync_change);
[email protected]3bdba0d2011-08-23 07:17:30763 }
764
[email protected]757d60a2014-05-23 00:11:44765 delayed_installs_.Remove(extension->id());
[email protected]0db124b02012-11-07 04:55:05766
[email protected]757d60a2014-05-23 00:11:44767 extension_prefs_->OnExtensionUninstalled(
768 extension->id(), extension->location(), external_uninstall);
[email protected]d4eda592013-09-18 03:37:57769
[email protected]333b1de2011-09-12 18:28:50770 // Track the uninstallation.
[email protected]49098f702011-10-13 03:47:18771 UMA_HISTOGRAM_ENUMERATION("Extensions.ExtensionUninstalled", 1, 2);
772
[email protected]d6ebc9792011-04-07 18:18:33773 return true;
[email protected]c10da4b02010-03-25 14:38:32774}
775
[email protected]5a145e82014-05-29 22:19:07776// static
777void ExtensionService::UninstallExtensionOnFileThread(
778 const std::string& id,
779 Profile* profile,
780 const base::FilePath& install_dir,
781 const base::FilePath& extension_path) {
782 extensions::ExtensionAssetsManager* assets_manager =
783 extensions::ExtensionAssetsManager::GetInstance();
784 assets_manager->UninstallExtension(id, profile, install_dir, extension_path);
785}
786
[email protected]c3cfb012011-04-06 22:07:35787bool ExtensionService::IsExtensionEnabled(
788 const std::string& extension_id) const {
[email protected]bb1bc9b32013-12-21 03:09:14789 if (registry_->enabled_extensions().Contains(extension_id) ||
790 registry_->terminated_extensions().Contains(extension_id)) {
[email protected]36429da2011-07-11 20:25:18791 return true;
[email protected]dc9a74f72012-08-17 18:07:21792 }
[email protected]36429da2011-07-11 20:25:18793
[email protected]bb1bc9b32013-12-21 03:09:14794 if (registry_->disabled_extensions().Contains(extension_id) ||
mlerman6a37b6a42014-11-26 22:10:53795 registry_->blacklisted_extensions().Contains(extension_id) ||
796 registry_->blocked_extensions().Contains(extension_id)) {
[email protected]ad83ca242011-07-29 01:32:25797 return false;
[email protected]695b5712012-12-06 23:55:28798 }
[email protected]ad83ca242011-07-29 01:32:25799
mlerman3690e5be2014-12-01 22:57:44800 // Blocked extensions aren't marked as such in prefs, thus if
801 // |block_extensions_| is true then CanBlockExtension() must be called with an
802 // Extension object. If the |extension_id| is not loaded, assume not enabled.
803 if (block_extensions_) {
804 const Extension* extension = GetInstalledExtension(extension_id);
805 if (!extension || CanBlockExtension(extension))
806 return false;
807 }
mlerman6a37b6a42014-11-26 22:10:53808
[email protected]ad83ca242011-07-29 01:32:25809 // If the extension hasn't been loaded yet, check the prefs for it. Assume
810 // enabled unless otherwise noted.
811 return !extension_prefs_->IsExtensionDisabled(extension_id) &&
[email protected]27e528322014-05-27 20:54:30812 !extension_prefs_->IsExtensionBlacklisted(extension_id) &&
[email protected]f574c402012-12-04 23:20:31813 !extension_prefs_->IsExternalExtensionUninstalled(extension_id);
[email protected]c3cfb012011-04-06 22:07:35814}
815
[email protected]eaa7dd182010-12-14 11:09:00816void ExtensionService::EnableExtension(const std::string& extension_id) {
[email protected]a29a517a2011-01-21 21:11:12817 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]a8af9fdb2010-10-28 21:52:20818
[email protected]06f92562011-04-29 19:27:31819 if (IsExtensionEnabled(extension_id))
[email protected]0c6da502009-08-14 22:32:39820 return;
[email protected]bb1bc9b32013-12-21 03:09:14821 const Extension* extension =
822 registry_->disabled_extensions().GetByID(extension_id);
[email protected]0d54b682013-11-05 14:15:36823
824 ManagementPolicy* policy = system_->management_policy();
825 if (extension && policy->MustRemainDisabled(extension, NULL, NULL)) {
826 UMA_HISTOGRAM_COUNTS_100("Extensions.EnableDeniedByPolicy", 1);
827 return;
828 }
[email protected]0c6da502009-08-14 22:32:39829
[email protected]b3317ad2011-04-28 23:46:00830 extension_prefs_->SetExtensionState(extension_id, Extension::ENABLED);
[email protected]eb5e4f92012-08-15 23:33:28831 extension_prefs_->ClearDisableReasons(extension_id);
[email protected]1784e83a2009-09-08 21:01:52832
[email protected]06f92562011-04-29 19:27:31833 // This can happen if sync enables an extension that is not
834 // installed yet.
835 if (!extension)
836 return;
837
[email protected]0c6da502009-08-14 22:32:39838 // Move it over to the enabled list.
[email protected]bb1bc9b32013-12-21 03:09:14839 registry_->AddEnabled(make_scoped_refptr(extension));
840 registry_->RemoveDisabled(extension->id());
[email protected]0c6da502009-08-14 22:32:39841
[email protected]62d30f42009-10-01 22:36:06842 NotifyExtensionLoaded(extension);
[email protected]3bdba0d2011-08-23 07:17:30843
[email protected]f74d7f32012-06-19 19:22:51844 // Notify listeners that the extension was enabled.
845 content::NotificationService::current()->Notify(
[email protected]adf5a102014-07-31 12:44:06846 extensions::NOTIFICATION_EXTENSION_ENABLED,
[email protected]f74d7f32012-06-19 19:22:51847 content::Source<Profile>(profile_),
848 content::Details<const Extension>(extension));
849
[email protected]f8aefb132013-10-30 09:29:52850 if (extension_sync_service_)
851 extension_sync_service_->SyncEnableExtension(*extension);
[email protected]0c6da502009-08-14 22:32:39852}
853
[email protected]44d62b62012-04-11 00:06:03854void ExtensionService::DisableExtension(
855 const std::string& extension_id,
856 Extension::DisableReason disable_reason) {
[email protected]a29a517a2011-01-21 21:11:12857 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]a8af9fdb2010-10-28 21:52:20858
[email protected]8f959f522014-08-06 06:26:28859 // The extension may have been disabled already. Just add a disable reason.
860 if (!IsExtensionEnabled(extension_id)) {
861 extension_prefs_->AddDisableReason(extension_id, disable_reason);
[email protected]1784e83a2009-09-08 21:01:52862 return;
[email protected]8f959f522014-08-06 06:26:28863 }
[email protected]1784e83a2009-09-08 21:01:52864
[email protected]06f92562011-04-29 19:27:31865 const Extension* extension = GetInstalledExtension(extension_id);
866 // |extension| can be NULL if sync disables an extension that is not
867 // installed yet.
[email protected]ab894542014-07-03 12:35:39868 // EXTERNAL_COMPONENT extensions are not generally modifiable by users, but
869 // can be uninstalled by the browser if the user sets extension-specific
870 // preferences.
[email protected]65187152012-06-02 13:14:14871 if (extension &&
[email protected]505ccdc2013-06-20 20:15:35872 disable_reason != Extension::DISABLE_RELOAD &&
binjin8e3d0182014-12-04 16:44:28873 disable_reason != Extension::DISABLE_UPDATE_REQUIRED_BY_POLICY &&
[email protected]ab894542014-07-03 12:35:39874 !system_->management_policy()->UserMayModifySettings(extension, NULL) &&
875 extension->location() != Manifest::EXTERNAL_COMPONENT) {
[email protected]95da88c42011-03-31 10:07:33876 return;
[email protected]65187152012-06-02 13:14:14877 }
[email protected]95da88c42011-03-31 10:07:33878
[email protected]b3317ad2011-04-28 23:46:00879 extension_prefs_->SetExtensionState(extension_id, Extension::DISABLED);
[email protected]eb5e4f92012-08-15 23:33:28880 extension_prefs_->AddDisableReason(extension_id, disable_reason);
[email protected]1784e83a2009-09-08 21:01:52881
[email protected]599539802014-01-07 23:06:00882 int include_mask =
883 ExtensionRegistry::EVERYTHING & ~ExtensionRegistry::DISABLED;
884 extension = registry_->GetExtensionById(extension_id, include_mask);
[email protected]06f92562011-04-29 19:27:31885 if (!extension)
886 return;
887
[email protected]45f5b7d2014-01-22 23:47:13888 // The extension is either enabled or terminated.
889 DCHECK(registry_->enabled_extensions().Contains(extension->id()) ||
890 registry_->terminated_extensions().Contains(extension->id()));
[email protected]64742de32013-04-22 08:44:34891
[email protected]5c094792012-09-07 19:44:53892 // Move it over to the disabled list. Don't send a second unload notification
893 // for terminated extensions being disabled.
[email protected]bb1bc9b32013-12-21 03:09:14894 registry_->AddDisabled(make_scoped_refptr(extension));
895 if (registry_->enabled_extensions().Contains(extension->id())) {
896 registry_->RemoveEnabled(extension->id());
[email protected]b0af4792013-10-23 09:12:13897 NotifyExtensionUnloaded(extension, UnloadedExtensionInfo::REASON_DISABLE);
[email protected]5c094792012-09-07 19:44:53898 } else {
[email protected]bb1bc9b32013-12-21 03:09:14899 registry_->RemoveTerminated(extension->id());
[email protected]5c094792012-09-07 19:44:53900 }
[email protected]3bdba0d2011-08-23 07:17:30901
[email protected]f8aefb132013-10-30 09:29:52902 if (extension_sync_service_)
903 extension_sync_service_->SyncDisableExtension(*extension);
[email protected]1784e83a2009-09-08 21:01:52904}
905
[email protected]1abf05e2013-07-09 17:04:36906void ExtensionService::DisableUserExtensions(
907 const std::vector<std::string>& except_ids) {
[email protected]e516e4c2013-06-12 17:41:14908 extensions::ManagementPolicy* management_policy =
909 system_->management_policy();
910 extensions::ExtensionList to_disable;
911
[email protected]bb1bc9b32013-12-21 03:09:14912 const ExtensionSet& enabled_set = registry_->enabled_extensions();
913 for (ExtensionSet::const_iterator extension = enabled_set.begin();
914 extension != enabled_set.end(); ++extension) {
[email protected]ab894542014-07-03 12:35:39915 if (management_policy->UserMayModifySettings(extension->get(), NULL))
[email protected]e516e4c2013-06-12 17:41:14916 to_disable.push_back(*extension);
917 }
[email protected]bb1bc9b32013-12-21 03:09:14918 const ExtensionSet& terminated_set = registry_->terminated_extensions();
919 for (ExtensionSet::const_iterator extension = terminated_set.begin();
920 extension != terminated_set.end(); ++extension) {
[email protected]ab894542014-07-03 12:35:39921 if (management_policy->UserMayModifySettings(extension->get(), NULL))
[email protected]e516e4c2013-06-12 17:41:14922 to_disable.push_back(*extension);
923 }
924
925 for (extensions::ExtensionList::const_iterator extension = to_disable.begin();
926 extension != to_disable.end(); ++extension) {
[email protected]3082fe32013-08-06 11:12:38927 if ((*extension)->was_installed_by_default() &&
928 extension_urls::IsWebstoreUpdateUrl(
dchengc7047942014-08-26 05:05:31929 extensions::ManifestURL::GetUpdateURL(extension->get())))
[email protected]3082fe32013-08-06 11:12:38930 continue;
[email protected]1abf05e2013-07-09 17:04:36931 const std::string& id = (*extension)->id();
932 if (except_ids.end() == std::find(except_ids.begin(), except_ids.end(), id))
933 DisableExtension(id, extensions::Extension::DISABLE_USER_ACTION);
[email protected]e516e4c2013-06-12 17:41:14934 }
935}
936
mlerman6a37b6a42014-11-26 22:10:53937// Extensions that are not locked, components or forced by policy should be
938// locked. Extensions are no longer considered enabled or disabled. Blacklisted
939// extensions are now considered both blacklisted and locked.
940void ExtensionService::BlockAllExtensions() {
941 if (block_extensions_)
942 return;
943 block_extensions_ = true;
944
945 // Blacklisted extensions are already unloaded, need not be blocked.
946 scoped_ptr<ExtensionSet> extensions =
947 registry_->GenerateInstalledExtensionsSet(ExtensionRegistry::ENABLED |
948 ExtensionRegistry::DISABLED |
949 ExtensionRegistry::TERMINATED);
950
951 for (const scoped_refptr<const Extension>& extension : *extensions) {
952 const std::string& id = extension->id();
953
954 if (!CanBlockExtension(extension.get()))
955 continue;
956
957 registry_->RemoveEnabled(id);
958 registry_->RemoveDisabled(id);
959 registry_->RemoveTerminated(id);
960
961 registry_->AddBlocked(extension.get());
962 UnloadExtension(id, extensions::UnloadedExtensionInfo::REASON_LOCK_ALL);
963 }
964}
965
966// All locked extensions should revert to being either enabled or disabled
967// as appropriate.
968void ExtensionService::UnblockAllExtensions() {
969 block_extensions_ = false;
970 scoped_ptr<ExtensionSet> to_unblock =
971 registry_->GenerateInstalledExtensionsSet(ExtensionRegistry::BLOCKED);
972
973 for (const scoped_refptr<const Extension>& extension : *to_unblock) {
974 registry_->RemoveBlocked(extension->id());
975 AddExtension(extension.get());
976 }
977}
978
[email protected]eaa7dd182010-12-14 11:09:00979void ExtensionService::GrantPermissionsAndEnableExtension(
[email protected]009633c2013-03-07 22:08:28980 const Extension* extension) {
981 GrantPermissions(extension);
[email protected]4c86be582014-06-04 08:39:11982 RecordPermissionMessagesHistogram(extension,
983 "Extensions.Permissions_ReEnable2");
[email protected]8d888c12010-11-30 00:00:25984 extension_prefs_->SetDidExtensionEscalatePermissions(extension, false);
985 EnableExtension(extension->id());
986}
987
[email protected]009633c2013-03-07 22:08:28988void ExtensionService::GrantPermissions(const Extension* extension) {
[email protected]be083862012-09-01 03:53:45989 CHECK(extension);
[email protected]8d42db52014-06-20 21:50:50990 extensions::PermissionsUpdater(profile()).GrantActivePermissions(extension);
[email protected]be083862012-09-01 03:53:45991}
992
[email protected]fe2dd7742011-04-19 22:52:49993// static
994void ExtensionService::RecordPermissionMessagesHistogram(
[email protected]13c68b62013-05-17 11:29:05995 const Extension* extension, const char* histogram) {
[email protected]de415552013-01-23 04:12:17996 // Since this is called from multiple sources, and since the histogram macros
997 // use statics, we need to manually lookup the histogram ourselves.
998 base::HistogramBase* counter = base::LinearHistogram::FactoryGet(
[email protected]fe2dd7742011-04-19 22:52:49999 histogram,
1000 1,
[email protected]c2e66e12012-06-27 06:27:061001 PermissionMessage::kEnumBoundary,
1002 PermissionMessage::kEnumBoundary + 1,
[email protected]de415552013-01-23 04:12:171003 base::HistogramBase::kUmaTargetedHistogramFlag);
[email protected]fe2dd7742011-04-19 22:52:491004
[email protected]a6910e72014-06-06 05:04:361005 PermissionMessages permissions =
1006 extension->permissions_data()->GetPermissionMessages();
[email protected]fe2dd7742011-04-19 22:52:491007 if (permissions.empty()) {
[email protected]c2e66e12012-06-27 06:27:061008 counter->Add(PermissionMessage::kNone);
[email protected]fe2dd7742011-04-19 22:52:491009 } else {
[email protected]c2e66e12012-06-27 06:27:061010 for (PermissionMessages::iterator it = permissions.begin();
[email protected]0d3e4a22011-06-23 19:02:521011 it != permissions.end(); ++it)
1012 counter->Add(it->id());
[email protected]fe2dd7742011-04-19 22:52:491013 }
1014}
1015
[email protected]eaa7dd182010-12-14 11:09:001016void ExtensionService::NotifyExtensionLoaded(const Extension* extension) {
[email protected]f9c8c7c72014-07-31 16:42:311017 // The URLRequestContexts need to be first to know that the extension
[email protected]62d30f42009-10-01 22:36:061018 // was loaded, otherwise a race can arise where a renderer that is created
1019 // for the extension may try to load an extension URL with an extension id
[email protected]57a777f72010-03-31 01:09:421020 // that the request context doesn't yet know about. The profile is responsible
1021 // for ensuring its URLRequestContexts appropriately discover the loaded
1022 // extension.
[email protected]31d8f5f22012-04-02 15:22:081023 system_->RegisterExtensionWithRequestContexts(extension);
[email protected]62d30f42009-10-01 22:36:061024
[email protected]d5949312012-12-03 22:13:301025 // Tell renderers about the new extension, unless it's a theme (renderers
1026 // don't need to know about themes).
[email protected]a58f599c2012-12-01 03:08:191027 if (!extension->is_theme()) {
[email protected]19647262011-12-16 09:57:491028 for (content::RenderProcessHost::iterator i(
1029 content::RenderProcessHost::AllHostsIterator());
1030 !i.IsAtEnd(); i.Advance()) {
1031 content::RenderProcessHost* host = i.GetCurrentValue();
1032 Profile* host_profile =
1033 Profile::FromBrowserContext(host->GetBrowserContext());
1034 if (host_profile->GetOriginalProfile() ==
1035 profile_->GetOriginalProfile()) {
rdevlin.croninc491dbf2015-02-07 00:31:551036 // We don't need to include tab permisisons here, since the extension
1037 // was just loaded.
[email protected]19647262011-12-16 09:57:491038 std::vector<ExtensionMsg_Loaded_Params> loaded_extensions(
rdevlin.croninc491dbf2015-02-07 00:31:551039 1, ExtensionMsg_Loaded_Params(extension,
1040 false /* no tab permissions */));
[email protected]19647262011-12-16 09:57:491041 host->Send(
1042 new ExtensionMsg_Loaded(loaded_extensions));
1043 }
[email protected]c8d407e2011-04-28 21:27:171044 }
[email protected]77a6970c2011-04-23 16:58:561045 }
1046
[email protected]3442a662012-01-12 08:06:171047 // Tell subsystems that use the EXTENSION_LOADED notification about the new
1048 // extension.
1049 //
1050 // NOTE: It is important that this happen after notifying the renderers about
1051 // the new extensions so that if we navigate to an extension URL in
[email protected]fdc76192014-04-20 21:54:411052 // ExtensionRegistryObserver::OnLoaded or
1053 // NOTIFICATION_EXTENSION_LOADED_DEPRECATED, the
[email protected]dcc47642014-03-26 22:03:491054 // renderer is guaranteed to know about it.
1055 registry_->TriggerOnLoaded(extension);
1056
[email protected]3442a662012-01-12 08:06:171057 content::NotificationService::current()->Notify(
[email protected]adf5a102014-07-31 12:44:061058 extensions::NOTIFICATION_EXTENSION_LOADED_DEPRECATED,
[email protected]3442a662012-01-12 08:06:171059 content::Source<Profile>(profile_),
1060 content::Details<const Extension>(extension));
1061
[email protected]dcc47642014-03-26 22:03:491062 // TODO(kalman): Convert ExtensionSpecialStoragePolicy to a
1063 // BrowserContextKeyedService and use ExtensionRegistryObserver.
[email protected]c8d407e2011-04-28 21:27:171064 profile_->GetExtensionSpecialStoragePolicy()->
rdevlin.croninbc8979a2014-09-30 01:08:501065 GrantRightsForExtension(extension, profile_);
[email protected]c8d407e2011-04-28 21:27:171066
[email protected]dcc47642014-03-26 22:03:491067 // TODO(kalman): This is broken. The crash reporter is process-wide so doesn't
1068 // work properly multi-profile. Besides which, it should be using
1069 // ExtensionRegistryObserver. See http://crbug.com/355029.
[email protected]c8d407e2011-04-28 21:27:171070 UpdateActiveExtensionsInCrashReporter();
1071
[email protected]d695bb12014-06-05 16:16:301072 const extensions::PermissionsData* permissions_data =
[email protected]a6910e72014-06-06 05:04:361073 extension->permissions_data();
[email protected]d695bb12014-06-05 16:16:301074
[email protected]c8d407e2011-04-28 21:27:171075 // If the extension has permission to load chrome://favicon/ resources we need
1076 // to make sure that the FaviconSource is registered with the
1077 // ChromeURLDataManager.
[email protected]d695bb12014-06-05 16:16:301078 if (permissions_data->HasHostPermission(GURL(chrome::kChromeUIFaviconURL))) {
[email protected]c8d407e2011-04-28 21:27:171079 FaviconSource* favicon_source = new FaviconSource(profile_,
1080 FaviconSource::FAVICON);
[email protected]24ea7a12013-01-27 23:54:531081 content::URLDataSource::Add(profile_, favicon_source);
[email protected]c8d407e2011-04-28 21:27:171082 }
[email protected]b07e606e2012-09-15 20:16:151083
[email protected]b07e606e2012-09-15 20:16:151084 // Same for chrome://theme/ resources.
[email protected]d695bb12014-06-05 16:16:301085 if (permissions_data->HasHostPermission(GURL(chrome::kChromeUIThemeURL))) {
[email protected]b07e606e2012-09-15 20:16:151086 ThemeSource* theme_source = new ThemeSource(profile_);
[email protected]24ea7a12013-01-27 23:54:531087 content::URLDataSource::Add(profile_, theme_source);
[email protected]b07e606e2012-09-15 20:16:151088 }
[email protected]b07e606e2012-09-15 20:16:151089
[email protected]5eddc3e2011-10-26 04:33:311090 // Same for chrome://thumb/ resources.
[email protected]d695bb12014-06-05 16:16:301091 if (permissions_data->HasHostPermission(
1092 GURL(chrome::kChromeUIThumbnailURL))) {
[email protected]420e6d92013-09-17 01:48:511093 ThumbnailSource* thumbnail_source = new ThumbnailSource(profile_, false);
[email protected]24ea7a12013-01-27 23:54:531094 content::URLDataSource::Add(profile_, thumbnail_source);
[email protected]5eddc3e2011-10-26 04:33:311095 }
[email protected]62d30f42009-10-01 22:36:061096}
1097
[email protected]a9f39a312010-12-23 22:14:271098void ExtensionService::NotifyExtensionUnloaded(
[email protected]814a7bf0f2011-08-13 05:30:591099 const Extension* extension,
[email protected]b0af4792013-10-23 09:12:131100 UnloadedExtensionInfo::Reason reason) {
[email protected]a9f39a312010-12-23 22:14:271101 UnloadedExtensionInfo details(extension, reason);
[email protected]e51232f32014-04-18 20:05:361102
1103 registry_->TriggerOnUnloaded(extension, reason);
1104
[email protected]ad50def52011-10-19 23:17:071105 content::NotificationService::current()->Notify(
[email protected]adf5a102014-07-31 12:44:061106 extensions::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED,
[email protected]6c2381d2011-10-19 02:52:531107 content::Source<Profile>(profile_),
1108 content::Details<UnloadedExtensionInfo>(&details));
[email protected]62d30f42009-10-01 22:36:061109
[email protected]f3b1a082011-11-18 00:34:301110 for (content::RenderProcessHost::iterator i(
1111 content::RenderProcessHost::AllHostsIterator());
[email protected]77a6970c2011-04-23 16:58:561112 !i.IsAtEnd(); i.Advance()) {
[email protected]f3b1a082011-11-18 00:34:301113 content::RenderProcessHost* host = i.GetCurrentValue();
[email protected]9b62ecf2011-07-27 20:23:081114 Profile* host_profile =
[email protected]f3b1a082011-11-18 00:34:301115 Profile::FromBrowserContext(host->GetBrowserContext());
[email protected]9b62ecf2011-07-27 20:23:081116 if (host_profile->GetOriginalProfile() == profile_->GetOriginalProfile())
[email protected]c8d407e2011-04-28 21:27:171117 host->Send(new ExtensionMsg_Unloaded(extension->id()));
[email protected]77a6970c2011-04-23 16:58:561118 }
1119
[email protected]31d8f5f22012-04-02 15:22:081120 system_->UnregisterExtensionWithRequestContexts(extension->id(), reason);
[email protected]dcc47642014-03-26 22:03:491121
1122 // TODO(kalman): Convert ExtensionSpecialStoragePolicy to a
1123 // BrowserContextKeyedService and use ExtensionRegistryObserver.
[email protected]c8d407e2011-04-28 21:27:171124 profile_->GetExtensionSpecialStoragePolicy()->
1125 RevokeRightsForExtension(extension);
1126
[email protected]b777b332011-04-16 04:01:081127#if defined(OS_CHROMEOS)
[email protected]ac66e452013-01-11 09:21:231128 // Revoke external file access for the extension from its file system context.
1129 // It is safe to access the extension's storage partition at this point. The
1130 // storage partition may get destroyed only after the extension gets unloaded.
[email protected]3a746ec2014-03-15 05:30:561131 GURL site =
1132 extensions::util::GetSiteForExtensionId(extension->id(), profile_);
[email protected]cd501a72014-08-22 19:58:311133 storage::FileSystemContext* filesystem_context =
1134 BrowserContext::GetStoragePartitionForSite(profile_, site)
1135 ->GetFileSystemContext();
[email protected]f19bbf62013-07-09 01:22:321136 if (filesystem_context && filesystem_context->external_backend()) {
1137 filesystem_context->external_backend()->
[email protected]c8d407e2011-04-28 21:27:171138 RevokeAccessForExtension(extension->id());
[email protected]62d30f42009-10-01 22:36:061139 }
[email protected]c8d407e2011-04-28 21:27:171140#endif
1141
[email protected]dcc47642014-03-26 22:03:491142 // TODO(kalman): This is broken. The crash reporter is process-wide so doesn't
1143 // work properly multi-profile. Besides which, it should be using
1144 // ExtensionRegistryObserver::OnExtensionLoaded. See http://crbug.com/355029.
[email protected]c8d407e2011-04-28 21:27:171145 UpdateActiveExtensionsInCrashReporter();
[email protected]62d30f42009-10-01 22:36:061146}
1147
[email protected]599539802014-01-07 23:06:001148content::BrowserContext* ExtensionService::GetBrowserContext() const {
1149 // Implemented in the .cc file to avoid adding a profile.h dependency to
1150 // extension_service.h.
1151 return profile_;
1152}
1153
[email protected]25ae0152011-11-18 14:40:021154bool ExtensionService::is_ready() {
[email protected]4a10006a2013-05-17 23:18:351155 return ready_->is_signaled();
[email protected]25ae0152011-11-18 14:40:021156}
1157
[email protected]7f8f24f2012-11-15 19:40:141158base::SequencedTaskRunner* ExtensionService::GetFileTaskRunner() {
[email protected]dc24976f2013-06-02 21:15:091159 if (file_task_runner_.get())
1160 return file_task_runner_.get();
[email protected]7f8f24f2012-11-15 19:40:141161
1162 // We should be able to interrupt any part of extension install process during
1163 // shutdown. SKIP_ON_SHUTDOWN ensures that not started extension install tasks
1164 // will be ignored/deleted while we will block on started tasks.
1165 std::string token("ext_install-");
1166 token.append(profile_->GetPath().AsUTF8Unsafe());
1167 file_task_runner_ = BrowserThread::GetBlockingPool()->
1168 GetSequencedTaskRunnerWithShutdownBehavior(
1169 BrowserThread::GetBlockingPool()->GetNamedSequenceToken(token),
1170 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN);
[email protected]dc24976f2013-06-02 21:15:091171 return file_task_runner_.get();
[email protected]7f8f24f2012-11-15 19:40:141172}
1173
[email protected]4ee07c62012-08-21 12:40:421174void ExtensionService::CheckManagementPolicy() {
[email protected]0d54b682013-11-05 14:15:361175 std::vector<std::string> to_unload;
1176 std::map<std::string, Extension::DisableReason> to_disable;
binjin8e3d0182014-12-04 16:44:281177 std::vector<std::string> to_enable;
[email protected]695b5712012-12-06 23:55:281178
[email protected]0d54b682013-11-05 14:15:361179 // Loop through the extensions list, finding extensions we need to unload or
1180 // disable.
binjin8e3d0182014-12-04 16:44:281181 for (scoped_refptr<const Extension> extension :
1182 registry_->enabled_extensions()) {
1183 if (!system_->management_policy()->UserMayLoad(extension.get(), nullptr))
[email protected]0d54b682013-11-05 14:15:361184 to_unload.push_back(extension->id());
1185 Extension::DisableReason disable_reason = Extension::DISABLE_NONE;
1186 if (system_->management_policy()->MustRemainDisabled(
binjin8e3d0182014-12-04 16:44:281187 extension.get(), &disable_reason, nullptr))
[email protected]0d54b682013-11-05 14:15:361188 to_disable[extension->id()] = disable_reason;
[email protected]aa96d3a2010-08-21 08:45:251189 }
1190
binjin8e3d0182014-12-04 16:44:281191 extensions::ExtensionManagement* management =
1192 extensions::ExtensionManagementFactory::GetForBrowserContext(profile());
1193
1194 // Loop through the disabled extension list, find extensions to re-enable
1195 // automatically. These extensions are exclusive from the |to_disable| and
1196 // |to_unload| lists constructed above, since disabled_extensions() and
1197 // enabled_extensions() are supposed to be mutually exclusive.
1198 for (scoped_refptr<const Extension> extension :
1199 registry_->disabled_extensions()) {
1200 // Find all disabled extensions disabled due to minimum version requirement,
1201 // but now satisfying it.
1202 if (management->CheckMinimumVersion(extension.get(), nullptr) &&
1203 extension_prefs_->HasDisableReason(
1204 extension->id(), Extension::DISABLE_UPDATE_REQUIRED_BY_POLICY)) {
1205 // Is DISABLE_UPDATE_REQUIRED_BY_POLICY the *only* reason?
1206 if (extension_prefs_->GetDisableReasons(extension->id()) ==
1207 Extension::DISABLE_UPDATE_REQUIRED_BY_POLICY) {
1208 // We need to enable those disabled *only* due to minimum version
1209 // requirement.
1210 to_enable.push_back(extension->id());
1211 }
1212 extension_prefs_->RemoveDisableReason(
1213 extension->id(), Extension::DISABLE_UPDATE_REQUIRED_BY_POLICY);
1214 }
1215 }
1216
1217 for (const std::string& id : to_unload)
1218 UnloadExtension(id, UnloadedExtensionInfo::REASON_DISABLE);
[email protected]0d54b682013-11-05 14:15:361219
1220 for (std::map<std::string, Extension::DisableReason>::const_iterator i =
1221 to_disable.begin(); i != to_disable.end(); ++i)
1222 DisableExtension(i->first, i->second);
binjin8e3d0182014-12-04 16:44:281223
1224 // No extension is getting re-enabled here after disabling/unloading
1225 // because to_enable is mutually exclusive to to_disable + to_unload.
1226 for (const std::string& id : to_enable)
1227 EnableExtension(id);
1228
1229 if (updater_.get()) {
1230 // Find all extensions disabled due to minimum version requirement from
1231 // policy (including the ones that got disabled just now), and check
1232 // for update.
1233 extensions::ExtensionUpdater::CheckParams to_recheck;
1234 for (scoped_refptr<const Extension> extension :
1235 registry_->disabled_extensions()) {
1236 if (extension_prefs_->GetDisableReasons(extension->id()) ==
1237 Extension::DISABLE_UPDATE_REQUIRED_BY_POLICY) {
1238 // The minimum version check is the only thing holding this extension
1239 // back, so check if it can be updated to fix that.
1240 to_recheck.ids.push_back(extension->id());
1241 }
1242 }
1243 if (!to_recheck.ids.empty())
1244 updater_->CheckNow(to_recheck);
1245 }
[email protected]aa96d3a2010-08-21 08:45:251246}
1247
[email protected]31206602011-04-13 23:07:321248void ExtensionService::CheckForUpdatesSoon() {
[email protected]90878c52014-04-04 18:21:021249 // This can legitimately happen in unit tests.
1250 if (!updater_.get())
1251 return;
1252
1253 if (AreAllExternalProvidersReady()) {
1254 updater_->CheckSoon();
[email protected]c3cfb012011-04-06 22:07:351255 } else {
[email protected]90878c52014-04-04 18:21:021256 // Sync can start updating before all the external providers are ready
1257 // during startup. Start the update as soon as those providers are ready,
1258 // but not before.
1259 update_once_all_providers_are_ready_ = true;
[email protected]c3cfb012011-04-06 22:07:351260 }
1261}
1262
[email protected]8e4560b62011-01-14 10:09:141263// Some extensions will autoupdate themselves externally from Chrome. These
1264// are typically part of some larger client application package. To support
1265// these, the extension will register its location in the the preferences file
1266// (and also, on Windows, in the registry) and this code will periodically
1267// check that location for a .crx file, which it will then install locally if
1268// a new version is available.
1269// Errors are reported through ExtensionErrorReporter. Succcess is not
1270// reported.
[email protected]eaa7dd182010-12-14 11:09:001271void ExtensionService::CheckForExternalUpdates() {
[email protected]a29a517a2011-01-21 21:11:121272 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]8e4560b62011-01-14 10:09:141273
1274 // Note that this installation is intentionally silent (since it didn't
1275 // go through the front-end). Extensions that are registered in this
1276 // way are effectively considered 'pre-bundled', and so implicitly
1277 // trusted. In general, if something has HKLM or filesystem access,
1278 // they could install an extension manually themselves anyway.
[email protected]a29a517a2011-01-21 21:11:121279
[email protected]8e4560b62011-01-14 10:09:141280 // Ask each external extension provider to give us a call back for each
1281 // extension they know about. See OnExternalExtension(File|UpdateUrl)Found.
[email protected]5df038b2012-07-16 19:03:271282 extensions::ProviderCollection::const_iterator i;
[email protected]8e4560b62011-01-14 10:09:141283 for (i = external_extension_providers_.begin();
1284 i != external_extension_providers_.end(); ++i) {
[email protected]5df038b2012-07-16 19:03:271285 extensions::ExternalProviderInterface* provider = i->get();
[email protected]8e4560b62011-01-14 10:09:141286 provider->VisitRegisteredExtension();
1287 }
1288
[email protected]50067e52011-10-20 23:17:071289 // Do any required work that we would have done after completion of all
1290 // providers.
[email protected]373daf972014-04-10 01:50:441291 if (external_extension_providers_.empty())
[email protected]50067e52011-10-20 23:17:071292 OnAllExternalProvidersReady();
[email protected]9f1087e2009-06-15 17:29:321293}
1294
[email protected]50067e52011-10-20 23:17:071295void ExtensionService::OnExternalProviderReady(
[email protected]5df038b2012-07-16 19:03:271296 const extensions::ExternalProviderInterface* provider) {
[email protected]a29a517a2011-01-21 21:11:121297 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]50067e52011-10-20 23:17:071298 CHECK(provider->IsReady());
[email protected]a29a517a2011-01-21 21:11:121299
1300 // An external provider has finished loading. We only take action
[email protected]8e4560b62011-01-14 10:09:141301 // if all of them are finished. So we check them first.
[email protected]94fde232012-04-27 10:22:301302 if (AreAllExternalProvidersReady())
1303 OnAllExternalProvidersReady();
1304}
1305
1306bool ExtensionService::AreAllExternalProvidersReady() const {
[email protected]5df038b2012-07-16 19:03:271307 extensions::ProviderCollection::const_iterator i;
[email protected]8e4560b62011-01-14 10:09:141308 for (i = external_extension_providers_.begin();
1309 i != external_extension_providers_.end(); ++i) {
[email protected]94fde232012-04-27 10:22:301310 if (!i->get()->IsReady())
1311 return false;
[email protected]8e4560b62011-01-14 10:09:141312 }
[email protected]94fde232012-04-27 10:22:301313 return true;
[email protected]50067e52011-10-20 23:17:071314}
1315
1316void ExtensionService::OnAllExternalProvidersReady() {
1317 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]94fde232012-04-27 10:22:301318 base::TimeDelta elapsed = base::Time::Now() - profile_->GetStartTime();
1319 UMA_HISTOGRAM_TIMES("Extension.ExternalProvidersReadyAfter", elapsed);
[email protected]50067e52011-10-20 23:17:071320
1321 // Install any pending extensions.
[email protected]94fde232012-04-27 10:22:301322 if (update_once_all_providers_are_ready_ && updater()) {
1323 update_once_all_providers_are_ready_ = false;
[email protected]4e9b59d2013-12-18 06:47:141324 extensions::ExtensionUpdater::CheckParams params;
1325 params.callback = external_updates_finished_callback_;
1326 updater()->CheckNow(params);
[email protected]8e4560b62011-01-14 10:09:141327 }
1328
1329 // Uninstall all the unclaimed extensions.
[email protected]45759612012-07-10 17:21:231330 scoped_ptr<extensions::ExtensionPrefs::ExtensionsInfo> extensions_info(
[email protected]8e4560b62011-01-14 10:09:141331 extension_prefs_->GetInstalledExtensionsInfo());
1332 for (size_t i = 0; i < extensions_info->size(); ++i) {
1333 ExtensionInfo* info = extensions_info->at(i).get();
[email protected]1d5e58b2013-01-31 08:41:401334 if (Manifest::IsExternalLocation(info->extension_location))
[email protected]8e4560b62011-01-14 10:09:141335 CheckExternalUninstall(info->extension_id);
1336 }
[email protected]e5af875f2011-10-10 21:09:141337
[email protected]373daf972014-04-10 01:50:441338 error_controller_->ShowErrorIfNeeded();
[email protected]a9aa5932012-01-25 08:27:401339
[email protected]374ceb6f2014-07-02 19:25:341340 external_install_manager_->UpdateExternalExtensionAlert();
[email protected]e5af875f2011-10-10 21:09:141341}
1342
[email protected]a9f39a312010-12-23 22:14:271343void ExtensionService::UnloadExtension(
1344 const std::string& extension_id,
[email protected]b0af4792013-10-23 09:12:131345 UnloadedExtensionInfo::Reason reason) {
[email protected]27e469a2010-01-11 20:35:091346 // Make sure the extension gets deleted after we return from this function.
[email protected]599539802014-01-07 23:06:001347 int include_mask =
1348 ExtensionRegistry::EVERYTHING & ~ExtensionRegistry::TERMINATED;
[email protected]9adb9692010-10-29 23:14:021349 scoped_refptr<const Extension> extension(
[email protected]599539802014-01-07 23:06:001350 registry_->GetExtensionById(extension_id, include_mask));
[email protected]631cf822009-05-15 07:01:251351
[email protected]fa0c96732010-11-17 00:14:231352 // This method can be called via PostTask, so the extension may have been
1353 // unloaded by the time this runs.
[email protected]dc24976f2013-06-02 21:15:091354 if (!extension.get()) {
[email protected]dd163fb02011-05-04 22:22:171355 // In case the extension may have crashed/uninstalled. Allow the profile to
1356 // clean up its RequestContexts.
[email protected]31d8f5f22012-04-02 15:22:081357 system_->UnregisterExtensionWithRequestContexts(extension_id, reason);
[email protected]fa0c96732010-11-17 00:14:231358 return;
[email protected]dd163fb02011-05-04 22:22:171359 }
[email protected]0c6da502009-08-14 22:32:391360
[email protected]1eb175082010-02-10 09:26:161361 // Keep information about the extension so that we can reload it later
1362 // even if it's not permanently installed.
1363 unloaded_extension_paths_[extension->id()] = extension->path();
1364
[email protected]f17dbd42010-08-16 23:21:101365 // Clean up if the extension is meant to be enabled after a reload.
[email protected]b914e2952013-04-26 07:10:031366 reloading_extensions_.erase(extension->id());
[email protected]f17dbd42010-08-16 23:21:101367
[email protected]bb1bc9b32013-12-21 03:09:141368 if (registry_->disabled_extensions().Contains(extension->id())) {
1369 registry_->RemoveDisabled(extension->id());
[email protected]dd163fb02011-05-04 22:22:171370 // Make sure the profile cleans up its RequestContexts when an already
1371 // disabled extension is unloaded (since they are also tracking the disabled
1372 // extensions).
[email protected]31d8f5f22012-04-02 15:22:081373 system_->UnregisterExtensionWithRequestContexts(extension_id, reason);
[email protected]45f5b7d2014-01-22 23:47:131374 // Don't send the unloaded notification. It was sent when the extension
1375 // was disabled.
[email protected]60a174a2013-08-02 20:29:281376 } else {
[email protected]bb1bc9b32013-12-21 03:09:141377 // Remove the extension from the enabled list.
1378 registry_->RemoveEnabled(extension->id());
[email protected]60a174a2013-08-02 20:29:281379 NotifyExtensionUnloaded(extension.get(), reason);
[email protected]0c6da502009-08-14 22:32:391380 }
1381
[email protected]fb789532013-08-27 02:40:211382 content::NotificationService::current()->Notify(
[email protected]adf5a102014-07-31 12:44:061383 extensions::NOTIFICATION_EXTENSION_REMOVED,
[email protected]fb789532013-08-27 02:40:211384 content::Source<Profile>(profile_),
1385 content::Details<const Extension>(extension.get()));
[email protected]631cf822009-05-15 07:01:251386}
1387
[email protected]8b1ec202013-09-05 02:09:501388void ExtensionService::RemoveComponentExtension(
1389 const std::string& extension_id) {
1390 scoped_refptr<const Extension> extension(
1391 GetExtensionById(extension_id, false));
[email protected]b0af4792013-10-23 09:12:131392 UnloadExtension(extension_id, UnloadedExtensionInfo::REASON_UNINSTALL);
[email protected]ebe07772014-05-22 04:16:061393 if (extension.get()) {
1394 content::NotificationService::current()->Notify(
[email protected]adf5a102014-07-31 12:44:061395 extensions::NOTIFICATION_EXTENSION_UNINSTALLED_DEPRECATED,
[email protected]ebe07772014-05-22 04:16:061396 content::Source<Profile>(profile_),
1397 content::Details<const Extension>(extension.get()));
[email protected]e43c61f2014-07-20 21:46:341398 ExtensionRegistry::Get(profile_)->TriggerOnUninstalled(
dtseng9fb3d5b2015-02-23 17:24:171399 extension.get(), extensions::UNINSTALL_REASON_COMPONENT_REMOVED);
[email protected]ebe07772014-05-22 04:16:061400 }
[email protected]8b1ec202013-09-05 02:09:501401}
1402
[email protected]bb1bc9b32013-12-21 03:09:141403void ExtensionService::UnloadAllExtensionsForTest() {
1404 UnloadAllExtensionsInternal();
[email protected]9f1087e2009-06-15 17:29:321405}
1406
[email protected]bb1bc9b32013-12-21 03:09:141407void ExtensionService::ReloadExtensionsForTest() {
1408 // Calling UnloadAllExtensionsForTest here triggers a false-positive presubmit
1409 // warning about calling test code in production.
1410 UnloadAllExtensionsInternal();
[email protected]eac88332012-12-26 17:57:451411 component_loader_->LoadAll();
[email protected]d8c8f25f2011-11-02 18:18:011412 extensions::InstalledLoader(this).LoadAllExtensions();
[email protected]4a10006a2013-05-17 23:18:351413 // Don't call SetReadyAndNotifyListeners() since tests call this multiple
1414 // times.
[email protected]9f1087e2009-06-15 17:29:321415}
1416
[email protected]820d9bd2013-04-03 03:46:031417void ExtensionService::SetReadyAndNotifyListeners() {
kalmanfc4a9aae2015-01-28 23:30:191418 const base::TimeTicks start_time = base::TimeTicks::Now();
[email protected]4a10006a2013-05-17 23:18:351419 ready_->Signal();
[email protected]820d9bd2013-04-03 03:46:031420 content::NotificationService::current()->Notify(
[email protected]adf5a102014-07-31 12:44:061421 extensions::NOTIFICATION_EXTENSIONS_READY_DEPRECATED,
[email protected]820d9bd2013-04-03 03:46:031422 content::Source<Profile>(profile_),
1423 content::NotificationService::NoDetails());
kalmanfc4a9aae2015-01-28 23:30:191424 UMA_HISTOGRAM_TIMES("Extensions.ExtensionServiceNotifyReadyListenersTime",
1425 base::TimeTicks::Now() - start_time);
[email protected]820d9bd2013-04-03 03:46:031426}
1427
[email protected]eaa7dd182010-12-14 11:09:001428void ExtensionService::OnLoadedInstalledExtensions() {
[email protected]3eeddd892013-04-17 17:00:111429 if (updater_)
[email protected]93fd78f42009-07-10 16:43:171430 updater_->Start();
[email protected]fa6a9102010-11-22 15:38:501431
[email protected]bc151cf92013-02-12 04:57:261432 OnBlacklistUpdated();
[email protected]e72e8eb82009-06-18 17:21:511433}
1434
[email protected]fcb58a862012-05-01 01:03:151435void ExtensionService::AddExtension(const Extension* extension) {
[email protected]c8d407e2011-04-28 21:27:171436 // TODO(jstritar): We may be able to get rid of this branch by overriding the
1437 // default extension state to DISABLED when the --disable-extensions flag
1438 // is set (http://crbug.com/29067).
1439 if (!extensions_enabled() &&
1440 !extension->is_theme() &&
[email protected]1d5e58b2013-01-31 08:41:401441 extension->location() != Manifest::COMPONENT &&
1442 !Manifest::IsExternalLocation(extension->location())) {
[email protected]fcb58a862012-05-01 01:03:151443 return;
[email protected]330840c2012-08-29 22:21:011444 }
[email protected]c8d407e2011-04-28 21:27:171445
[email protected]b914e2952013-04-26 07:10:031446 bool is_extension_upgrade = false;
[email protected]116d40e2013-08-08 17:23:171447 bool is_extension_installed = false;
1448 const Extension* old = GetInstalledExtension(extension->id());
1449 if (old) {
1450 is_extension_installed = true;
1451 int version_compare_result =
1452 extension->version()->CompareTo(*(old->version()));
1453 is_extension_upgrade = version_compare_result > 0;
[email protected]b914e2952013-04-26 07:10:031454 // Other than for unpacked extensions, CrxInstaller should have guaranteed
1455 // that we aren't downgrading.
1456 if (!Manifest::IsUnpackedLocation(extension->location()))
[email protected]116d40e2013-08-08 17:23:171457 CHECK_GE(version_compare_result, 0);
[email protected]b914e2952013-04-26 07:10:031458 }
rdevlin.cronin2c16c602014-11-21 01:35:491459 // If the extension was disabled for a reload, then enable it.
1460 bool reloading = reloading_extensions_.erase(extension->id()) > 0;
1461
1462 // Set the upgraded bit; we consider reloads upgrades.
1463 system_->runtime_data()->SetBeingUpgraded(extension->id(),
1464 is_extension_upgrade || reloading);
[email protected]c8d407e2011-04-28 21:27:171465
[email protected]1eb175082010-02-10 09:26:161466 // The extension is now loaded, remove its data from unloaded extension map.
1467 unloaded_extension_paths_.erase(extension->id());
1468
[email protected]bb7f40952011-01-13 00:21:201469 // If a terminated extension is loaded, remove it from the terminated list.
1470 UntrackTerminatedExtension(extension->id());
1471
[email protected]b914e2952013-04-26 07:10:031472 // Check if the extension's privileges have changed and mark the
1473 // extension disabled if necessary.
[email protected]116d40e2013-08-08 17:23:171474 CheckPermissionsIncrease(extension, is_extension_installed);
[email protected]b914e2952013-04-26 07:10:031475
[email protected]116d40e2013-08-08 17:23:171476 if (is_extension_installed && !reloading) {
[email protected]ca2e82022013-04-29 16:48:411477 // To upgrade an extension in place, unload the old one and then load the
1478 // new one. ReloadExtension disables the extension, which is sufficient.
[email protected]b0af4792013-10-23 09:12:131479 UnloadExtension(extension->id(), UnloadedExtensionInfo::REASON_UPDATE);
[email protected]b914e2952013-04-26 07:10:031480 }
[email protected]0c6da502009-08-14 22:32:391481
[email protected]695b5712012-12-06 23:55:281482 if (extension_prefs_->IsExtensionBlacklisted(extension->id())) {
[email protected]ac875372013-02-28 04:36:091483 // Only prefs is checked for the blacklist. We rely on callers to check the
1484 // blacklist before calling into here, e.g. CrxInstaller checks before
[email protected]9f3c8532013-07-31 19:52:071485 // installation then threads through the install and pending install flow
1486 // of this class, and we check when loading installed extensions.
[email protected]bb1bc9b32013-12-21 03:09:141487 registry_->AddBlacklisted(extension);
mlerman6a37b6a42014-11-26 22:10:531488 } else if (block_extensions_ && CanBlockExtension(extension)) {
1489 registry_->AddBlocked(extension);
[email protected]ca2e82022013-04-29 16:48:411490 } else if (!reloading &&
1491 extension_prefs_->IsExtensionDisabled(extension->id())) {
[email protected]bb1bc9b32013-12-21 03:09:141492 registry_->AddDisabled(extension);
[email protected]f8aefb132013-10-30 09:29:521493 if (extension_sync_service_)
1494 extension_sync_service_->SyncExtensionChangeIfNeeded(*extension);
[email protected]44d62b62012-04-11 00:06:031495 content::NotificationService::current()->Notify(
[email protected]adf5a102014-07-31 12:44:061496 extensions::NOTIFICATION_EXTENSION_UPDATE_DISABLED,
[email protected]44d62b62012-04-11 00:06:031497 content::Source<Profile>(profile_),
1498 content::Details<const Extension>(extension));
[email protected]62f051c2012-03-29 17:04:441499
[email protected]21db9ef2014-05-16 02:06:271500 // Show the extension disabled error if a permissions increase or a remote
1501 // installation is the reason it was disabled, and no other reasons exist.
1502 int reasons = extension_prefs_->GetDisableReasons(extension->id());
1503 const int kReasonMask = Extension::DISABLE_PERMISSIONS_INCREASE |
1504 Extension::DISABLE_REMOTE_INSTALL;
1505 if (reasons & kReasonMask && !(reasons & ~kReasonMask)) {
1506 extensions::AddExtensionDisabledError(
1507 this,
1508 extension,
1509 extension_prefs_->HasDisableReason(
1510 extension->id(), Extension::DISABLE_REMOTE_INSTALL));
[email protected]62f051c2012-03-29 17:04:441511 }
[email protected]ca2e82022013-04-29 16:48:411512 } else if (reloading) {
1513 // Replace the old extension with the new version.
[email protected]bb1bc9b32013-12-21 03:09:141514 CHECK(!registry_->AddDisabled(extension));
[email protected]ca2e82022013-04-29 16:48:411515 EnableExtension(extension->id());
[email protected]695b5712012-12-06 23:55:281516 } else {
1517 // All apps that are displayed in the launcher are ordered by their ordinals
1518 // so we must ensure they have valid ordinals.
1519 if (extension->RequiresSortOrdinal()) {
[email protected]db378322014-07-21 23:19:341520 extension_prefs_->app_sorting()->SetExtensionVisible(
1521 extension->id(),
1522 extension->ShouldDisplayInNewTabPage() &&
1523 !extension_prefs_->IsEphemeralApp(extension->id()));
1524 if (!extension_prefs_->IsEphemeralApp(extension->id())) {
1525 extension_prefs_->app_sorting()->EnsureValidOrdinals(
1526 extension->id(), syncer::StringOrdinal());
[email protected]bd36b652013-02-27 02:13:251527 }
[email protected]695b5712012-12-06 23:55:281528 }
1529
[email protected]bb1bc9b32013-12-21 03:09:141530 registry_->AddEnabled(extension);
[email protected]f8aefb132013-10-30 09:29:521531 if (extension_sync_service_)
1532 extension_sync_service_->SyncExtensionChangeIfNeeded(*extension);
[email protected]695b5712012-12-06 23:55:281533 NotifyExtensionLoaded(extension);
[email protected]f574c402012-12-04 23:20:311534 }
rdevlin.cronin2c16c602014-11-21 01:35:491535 system_->runtime_data()->SetBeingUpgraded(extension->id(), false);
[email protected]aab98a52009-12-02 03:22:351536}
1537
[email protected]8c484b742012-11-29 06:05:361538void ExtensionService::AddComponentExtension(const Extension* extension) {
1539 const std::string old_version_string(
1540 extension_prefs_->GetVersionString(extension->id()));
[email protected]c5e4a2222014-01-03 16:06:131541 const Version old_version(old_version_string);
[email protected]8c484b742012-11-29 06:05:361542
[email protected]0181a7d2013-11-12 01:08:421543 VLOG(1) << "AddComponentExtension " << extension->name();
[email protected]8c484b742012-11-29 06:05:361544 if (!old_version.IsValid() || !old_version.Equals(*extension->version())) {
1545 VLOG(1) << "Component extension " << extension->name() << " ("
1546 << extension->id() << ") installing/upgrading from '"
1547 << old_version_string << "' to " << extension->version()->GetString();
1548
1549 AddNewOrUpdatedExtension(extension,
[email protected]9ae73962014-08-14 16:53:411550 Extension::ENABLED,
[email protected]4a1d9c0d2014-06-13 12:50:111551 extensions::kInstallFlagNone,
[email protected]d8fd0fd2014-03-24 13:16:061552 syncer::StringOrdinal(),
1553 std::string());
[email protected]8c484b742012-11-29 06:05:361554 return;
1555 }
1556
1557 AddExtension(extension);
1558}
1559
[email protected]b914e2952013-04-26 07:10:031560void ExtensionService::CheckPermissionsIncrease(const Extension* extension,
[email protected]116d40e2013-08-08 17:23:171561 bool is_extension_installed) {
[email protected]23a85362014-07-07 23:26:191562 extensions::PermissionsUpdater(profile_).InitializePermissions(extension);
[email protected]902fd7b2011-07-27 18:42:311563
[email protected]8d888c12010-11-30 00:00:251564 // We keep track of all permissions the user has granted each extension.
1565 // This allows extensions to gracefully support backwards compatibility
1566 // by including unknown permissions in their manifests. When the user
1567 // installs the extension, only the recognized permissions are recorded.
1568 // When the unknown permissions become recognized (e.g., through browser
1569 // upgrade), we can prompt the user to accept these new permissions.
1570 // Extensions can also silently upgrade to less permissions, and then
1571 // silently upgrade to a version that adds these permissions back.
1572 //
1573 // For example, pretend that Chrome 10 includes a permission "omnibox"
1574 // for an API that adds suggestions to the omnibox. An extension can
1575 // maintain backwards compatibility while still having "omnibox" in the
1576 // manifest. If a user installs the extension on Chrome 9, the browser
1577 // will record the permissions it recognized, not including "omnibox."
1578 // When upgrading to Chrome 10, "omnibox" will be recognized and Chrome
1579 // will disable the extension and prompt the user to approve the increase
1580 // in privileges. The extension could then release a new version that
1581 // removes the "omnibox" permission. When the user upgrades, Chrome will
1582 // still remember that "omnibox" had been granted, so that if the
1583 // extension once again includes "omnibox" in an upgrade, the extension
1584 // can upgrade without requiring this user's approval.
[email protected]eb5e4f92012-08-15 23:33:281585 int disable_reasons = extension_prefs_->GetDisableReasons(extension->id());
[email protected]8d888c12010-11-30 00:00:251586
rockot1d4a06262015-02-17 19:39:281587 // Silently grant all active permissions to default apps and apps installed
1588 // in kiosk mode.
[email protected]211a3f32013-05-28 21:48:181589 bool auto_grant_permission =
rockot1d4a06262015-02-17 19:39:281590 extension->was_installed_by_default() ||
[email protected]45928b682013-11-28 08:20:271591 extensions::ExtensionsBrowserClient::Get()->IsRunningInForcedAppMode();
[email protected]211a3f32013-05-28 21:48:181592 if (auto_grant_permission)
[email protected]b914e2952013-04-26 07:10:031593 GrantPermissions(extension);
1594
1595 bool is_privilege_increase = false;
1596 // We only need to compare the granted permissions to the current permissions
rockot1d4a06262015-02-17 19:39:281597 // if the extension has not been auto-granted its permissions above and is
1598 // installed internally.
1599 if (extension->location() == Manifest::INTERNAL && !auto_grant_permission) {
[email protected]8d888c12010-11-30 00:00:251600 // Add all the recognized permissions if the granted permissions list
1601 // hasn't been initialized yet.
[email protected]c2e66e12012-06-27 06:27:061602 scoped_refptr<PermissionSet> granted_permissions =
[email protected]902fd7b2011-07-27 18:42:311603 extension_prefs_->GetGrantedPermissions(extension->id());
[email protected]0d3e4a22011-06-23 19:02:521604 CHECK(granted_permissions.get());
[email protected]8d888c12010-11-30 00:00:251605
1606 // Here, we check if an extension's privileges have increased in a manner
1607 // that requires the user's approval. This could occur because the browser
1608 // upgraded and recognized additional privileges, or an extension upgrades
1609 // to a version that requires additional privileges.
[email protected]c41003472013-10-19 15:37:251610 is_privilege_increase =
1611 extensions::PermissionMessageProvider::Get()->IsPrivilegeIncrease(
dchengc7047942014-08-26 05:05:311612 granted_permissions.get(),
[email protected]076ebeda2014-06-06 21:47:261613 extension->permissions_data()->active_permissions().get(),
1614 extension->GetType());
[email protected]8d888c12010-11-30 00:00:251615 }
1616
[email protected]116d40e2013-08-08 17:23:171617 if (is_extension_installed) {
[email protected]44d62b62012-04-11 00:06:031618 // If the extension was already disabled, suppress any alerts for becoming
1619 // disabled on permissions increase.
[email protected]b914e2952013-04-26 07:10:031620 bool previously_disabled =
1621 extension_prefs_->IsExtensionDisabled(extension->id());
[email protected]7e9e2422012-12-13 19:54:191622 // Legacy disabled extensions do not have a disable reason. Infer that if
1623 // there was no permission increase, it was likely disabled by the user.
1624 if (previously_disabled && disable_reasons == Extension::DISABLE_NONE &&
[email protected]b914e2952013-04-26 07:10:031625 !extension_prefs_->DidExtensionEscalatePermissions(extension->id())) {
[email protected]7e9e2422012-12-13 19:54:191626 disable_reasons |= Extension::DISABLE_USER_ACTION;
[email protected]44d62b62012-04-11 00:06:031627 }
[email protected]7e9e2422012-12-13 19:54:191628 // Extensions that came to us disabled from sync need a similar inference,
1629 // except based on the new version's permissions.
1630 if (previously_disabled &&
1631 disable_reasons == Extension::DISABLE_UNKNOWN_FROM_SYNC) {
1632 // Remove the DISABLE_UNKNOWN_FROM_SYNC reason.
1633 extension_prefs_->ClearDisableReasons(extension->id());
1634 if (!is_privilege_increase)
1635 disable_reasons |= Extension::DISABLE_USER_ACTION;
1636 }
[email protected]b914e2952013-04-26 07:10:031637 disable_reasons &= ~Extension::DISABLE_UNKNOWN_FROM_SYNC;
[email protected]8d888c12010-11-30 00:00:251638 }
1639
1640 // Extension has changed permissions significantly. Disable it. A
[email protected]21db9ef2014-05-16 02:06:271641 // notification should be sent by the caller. If the extension is already
1642 // disabled because it was installed remotely, don't add another disable
1643 // reason, but instead always set the "did escalate permissions" flag, to
1644 // ensure enabling it will always show a warning.
1645 if (disable_reasons == Extension::DISABLE_REMOTE_INSTALL) {
1646 extension_prefs_->SetDidExtensionEscalatePermissions(extension, true);
1647 } else if (is_privilege_increase) {
[email protected]7e9e2422012-12-13 19:54:191648 disable_reasons |= Extension::DISABLE_PERMISSIONS_INCREASE;
[email protected]fe2dd7742011-04-19 22:52:491649 if (!extension_prefs_->DidExtensionEscalatePermissions(extension->id())) {
[email protected]4c86be582014-06-04 08:39:111650 RecordPermissionMessagesHistogram(extension,
1651 "Extensions.Permissions_AutoDisable2");
[email protected]fe2dd7742011-04-19 22:52:491652 }
[email protected]195c1582013-10-29 18:42:231653 extension_prefs_->SetExtensionState(extension->id(), Extension::DISABLED);
[email protected]8d888c12010-11-30 00:00:251654 extension_prefs_->SetDidExtensionEscalatePermissions(extension, true);
[email protected]b914e2952013-04-26 07:10:031655 }
1656 if (disable_reasons != Extension::DISABLE_NONE) {
[email protected]eb5e4f92012-08-15 23:33:281657 extension_prefs_->AddDisableReason(
1658 extension->id(),
1659 static_cast<Extension::DisableReason>(disable_reasons));
[email protected]8d888c12010-11-30 00:00:251660 }
1661}
1662
[email protected]eaa7dd182010-12-14 11:09:001663void ExtensionService::UpdateActiveExtensionsInCrashReporter() {
[email protected]c8865962009-12-16 07:47:391664 std::set<std::string> extension_ids;
[email protected]bb1bc9b32013-12-21 03:09:141665 const ExtensionSet& extensions = registry_->enabled_extensions();
1666 for (ExtensionSet::const_iterator iter = extensions.begin();
1667 iter != extensions.end(); ++iter) {
[email protected]cadac622013-06-11 16:46:361668 const Extension* extension = iter->get();
[email protected]1d5e58b2013-01-31 08:41:401669 if (!extension->is_theme() && extension->location() != Manifest::COMPONENT)
[email protected]84df8332011-12-06 18:22:461670 extension_ids.insert(extension->id());
[email protected]aab98a52009-12-02 03:22:351671 }
1672
[email protected]dcc47642014-03-26 22:03:491673 // TODO(kalman): This is broken. ExtensionService is per-profile.
1674 // crash_keys::SetActiveExtensions is per-process. See
1675 // http://crbug.com/355029.
[email protected]f6431be82013-09-07 02:53:451676 crash_keys::SetActiveExtensions(extension_ids);
[email protected]6014d672008-12-05 00:38:251677}
1678
[email protected]8266d662011-07-12 21:53:261679void ExtensionService::OnExtensionInstalled(
[email protected]36a5c4c2011-12-14 16:34:501680 const Extension* extension,
[email protected]98270432012-09-11 20:51:241681 const syncer::StringOrdinal& page_ordinal,
[email protected]4a1d9c0d2014-06-13 12:50:111682 int install_flags) {
[email protected]a29a517a2011-01-21 21:11:121683 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]a8af9fdb2010-10-28 21:52:201684
[email protected]c3cfb012011-04-06 22:07:351685 const std::string& id = extension->id();
binjin47947f842014-11-18 12:10:241686 int disable_reasons = GetDisableReasonsOnInstalled(extension);
[email protected]d8fd0fd2014-03-24 13:16:061687 std::string install_parameter;
[email protected]96aebe22014-07-16 04:07:511688 const extensions::PendingExtensionInfo* pending_extension_info =
1689 pending_extension_manager()->GetById(id);
1690 if (pending_extension_info) {
[email protected]8f3bcbd2013-06-05 08:42:401691 if (!pending_extension_info->ShouldAllowInstall(extension)) {
[email protected]51a3bf8b2012-06-08 22:53:061692 pending_extension_manager()->Remove(id);
[email protected]8ef78fd2010-08-19 17:14:321693
[email protected]31bb5ee62012-09-12 22:58:401694 LOG(WARNING) << "ShouldAllowInstall() returned false for "
1695 << id << " of type " << extension->GetType()
[email protected]65348062013-01-15 07:27:221696 << " and update URL "
1697 << extensions::ManifestURL::GetUpdateURL(extension).spec()
[email protected]31bb5ee62012-09-12 22:58:401698 << "; not installing";
[email protected]ae6cb3022011-04-04 20:11:541699
[email protected]4416c5a2010-06-26 01:28:571700 // Delete the extension directory since we're not going to
1701 // load it.
[email protected]7f8f24f2012-11-15 19:40:141702 if (!GetFileTaskRunner()->PostTask(
1703 FROM_HERE,
[email protected]85df9d12014-04-15 17:02:141704 base::Bind(&extensions::file_util::DeleteFile,
1705 extension->path(),
1706 true))) {
[email protected]14908b72011-04-20 06:54:361707 NOTREACHED();
[email protected]31bb5ee62012-09-12 22:58:401708 }
[email protected]4416c5a2010-06-26 01:28:571709 return;
1710 }
[email protected]51a3bf8b2012-06-08 22:53:061711
[email protected]d8fd0fd2014-03-24 13:16:061712 install_parameter = pending_extension_info->install_parameter();
[email protected]51a3bf8b2012-06-08 22:53:061713 pending_extension_manager()->Remove(id);
[email protected]4416c5a2010-06-26 01:28:571714 } else {
[email protected]c3cfb012011-04-06 22:07:351715 // We explicitly want to re-enable an uninstalled external
1716 // extension; if we're here, that means the user is manually
1717 // installing the extension.
[email protected]46f3e102014-03-25 01:22:451718 if (extension_prefs_->IsExternalExtensionUninstalled(id)) {
binjin47947f842014-11-18 12:10:241719 disable_reasons = Extension::DISABLE_NONE;
[email protected]6cc7dbae2011-04-29 21:18:331720 }
[email protected]aa142702010-03-26 01:26:331721 }
1722
[email protected]98270432012-09-11 20:51:241723 // Unsupported requirements overrides the management policy.
[email protected]4a1d9c0d2014-06-13 12:50:111724 if (install_flags & extensions::kInstallFlagHasRequirementErrors) {
binjin47947f842014-11-18 12:10:241725 disable_reasons |= Extension::DISABLE_UNSUPPORTED_REQUIREMENT;
binjin8e3d0182014-12-04 16:44:281726 } else {
1727 // Requirement is supported now, remove the corresponding disable reason
1728 // instead.
1729 extension_prefs_->RemoveDisableReason(
1730 id, Extension::DISABLE_UNSUPPORTED_REQUIREMENT);
1731 disable_reasons &= ~Extension::DISABLE_UNSUPPORTED_REQUIREMENT;
1732 }
1733
1734 // Check if the extension was disabled because of the minimum version
1735 // requirements from enterprise policy, and satisfies it now.
1736 if (extensions::ExtensionManagementFactory::GetForBrowserContext(profile())
1737 ->CheckMinimumVersion(extension, nullptr)) {
1738 // And remove the corresponding disable reason.
1739 extension_prefs_->RemoveDisableReason(
1740 id, Extension::DISABLE_UPDATE_REQUIRED_BY_POLICY);
1741 disable_reasons &= ~Extension::DISABLE_UPDATE_REQUIRED_BY_POLICY;
[email protected]98270432012-09-11 20:51:241742 }
1743
[email protected]4a1d9c0d2014-06-13 12:50:111744 if (install_flags & extensions::kInstallFlagIsBlacklistedForMalware) {
[email protected]9f3c8532013-07-31 19:52:071745 // Installation of a blacklisted extension can happen from sync, policy,
1746 // etc, where to maintain consistency we need to install it, just never
1747 // load it (see AddExtension). Usually it should be the job of callers to
1748 // incercept blacklisted extension earlier (e.g. CrxInstaller, before even
1749 // showing the install dialogue).
[email protected]7c82539c2014-02-19 06:09:171750 extension_prefs_->AcknowledgeBlacklistedExtension(id);
[email protected]9f3c8532013-07-31 19:52:071751 UMA_HISTOGRAM_ENUMERATION("ExtensionBlacklist.SilentInstall",
1752 extension->location(),
1753 Manifest::NUM_LOCATIONS);
1754 }
1755
[email protected]695b5712012-12-06 23:55:281756 if (!GetInstalledExtension(extension->id())) {
[email protected]07533022011-06-27 20:42:551757 UMA_HISTOGRAM_ENUMERATION("Extensions.InstallType",
1758 extension->GetType(), 100);
[email protected]69084dc2012-11-17 07:39:301759 UMA_HISTOGRAM_ENUMERATION("Extensions.InstallSource",
[email protected]1d5e58b2013-01-31 08:41:401760 extension->location(), Manifest::NUM_LOCATIONS);
[email protected]4c86be582014-06-04 08:39:111761 RecordPermissionMessagesHistogram(extension,
1762 "Extensions.Permissions_Install2");
[email protected]69084dc2012-11-17 07:39:301763 } else {
1764 UMA_HISTOGRAM_ENUMERATION("Extensions.UpdateType",
1765 extension->GetType(), 100);
1766 UMA_HISTOGRAM_ENUMERATION("Extensions.UpdateSource",
[email protected]1d5e58b2013-01-31 08:41:401767 extension->location(), Manifest::NUM_LOCATIONS);
[email protected]8f959f522014-08-06 06:26:281768
1769 // A fully installed app cannot be demoted to an ephemeral app.
1770 if ((install_flags & extensions::kInstallFlagIsEphemeral) &&
1771 !extension_prefs_->IsEphemeralApp(id)) {
1772 install_flags &= ~static_cast<int>(extensions::kInstallFlagIsEphemeral);
1773 }
[email protected]07533022011-06-27 20:42:551774 }
1775
binjin47947f842014-11-18 12:10:241776 if (disable_reasons)
1777 extension_prefs_->AddDisableReasons(id, disable_reasons);
1778
[email protected]399583b2012-12-11 09:33:421779 const Extension::State initial_state =
binjin47947f842014-11-18 12:10:241780 disable_reasons == Extension::DISABLE_NONE ? Extension::ENABLED
1781 : Extension::DISABLED;
1782
[email protected]4a1d9c0d2014-06-13 12:50:111783 if (ShouldDelayExtensionUpdate(
1784 id,
1785 !!(install_flags & extensions::kInstallFlagInstallImmediately))) {
[email protected]9f3c8532013-07-31 19:52:071786 extension_prefs_->SetDelayedInstallInfo(
1787 extension,
1788 initial_state,
[email protected]4a1d9c0d2014-06-13 12:50:111789 install_flags,
[email protected]9f3c8532013-07-31 19:52:071790 extensions::ExtensionPrefs::DELAY_REASON_WAIT_FOR_IDLE,
[email protected]d8fd0fd2014-03-24 13:16:061791 page_ordinal,
1792 install_parameter);
[email protected]0db124b02012-11-07 04:55:051793
1794 // Transfer ownership of |extension|.
[email protected]9f4e4f082013-06-21 07:11:191795 delayed_installs_.Insert(extension);
[email protected]0db124b02012-11-07 04:55:051796
[email protected]75bdcb872013-03-13 00:41:451797 // Notify observers that app update is available.
1798 FOR_EACH_OBSERVER(extensions::UpdateObserver, update_observers_,
[email protected]a9aa62b312013-11-29 05:35:061799 OnAppUpdateAvailable(extension));
[email protected]0db124b02012-11-07 04:55:051800 return;
1801 }
1802
[email protected]90878c52014-04-04 18:21:021803 extensions::SharedModuleService::ImportStatus status =
1804 shared_module_service_->SatisfyImports(extension);
[email protected]e5f8fffe2014-04-02 00:30:441805 if (installs_delayed_for_gc_) {
[email protected]9f3c8532013-07-31 19:52:071806 extension_prefs_->SetDelayedInstallInfo(
1807 extension,
1808 initial_state,
[email protected]4a1d9c0d2014-06-13 12:50:111809 install_flags,
[email protected]9f3c8532013-07-31 19:52:071810 extensions::ExtensionPrefs::DELAY_REASON_GC,
[email protected]d8fd0fd2014-03-24 13:16:061811 page_ordinal,
1812 install_parameter);
[email protected]399583b2012-12-11 09:33:421813 delayed_installs_.Insert(extension);
[email protected]90878c52014-04-04 18:21:021814 } else if (status != SharedModuleService::IMPORT_STATUS_OK) {
1815 if (status == SharedModuleService::IMPORT_STATUS_UNSATISFIED) {
[email protected]9f3c8532013-07-31 19:52:071816 extension_prefs_->SetDelayedInstallInfo(
1817 extension,
1818 initial_state,
[email protected]4a1d9c0d2014-06-13 12:50:111819 install_flags,
[email protected]9f4e4f082013-06-21 07:11:191820 extensions::ExtensionPrefs::DELAY_REASON_WAIT_FOR_IMPORTS,
[email protected]d8fd0fd2014-03-24 13:16:061821 page_ordinal,
1822 install_parameter);
[email protected]9f4e4f082013-06-21 07:11:191823 delayed_installs_.Insert(extension);
1824 }
[email protected]399583b2012-12-11 09:33:421825 } else {
[email protected]9f3c8532013-07-31 19:52:071826 AddNewOrUpdatedExtension(extension,
1827 initial_state,
[email protected]4a1d9c0d2014-06-13 12:50:111828 install_flags,
[email protected]d8fd0fd2014-03-24 13:16:061829 page_ordinal,
1830 install_parameter);
[email protected]399583b2012-12-11 09:33:421831 }
[email protected]8c484b742012-11-29 06:05:361832}
1833
binjin1569c9b2014-09-05 13:33:181834void ExtensionService::OnExtensionManagementSettingsChanged() {
1835 error_controller_->ShowErrorIfNeeded();
binjine6b58b52014-10-31 01:55:571836
1837 // Revokes blocked permissions from active_permissions for all extensions.
1838 extensions::ExtensionManagement* settings =
1839 extensions::ExtensionManagementFactory::GetForBrowserContext(profile());
1840 CHECK(settings);
1841 scoped_ptr<ExtensionSet> all_extensions(
1842 registry_->GenerateInstalledExtensionsSet());
1843 for (const auto& extension : *all_extensions.get()) {
1844 if (!settings->IsPermissionSetAllowed(
binjin685ade82014-11-06 09:53:561845 extension.get(),
binjine6b58b52014-10-31 01:55:571846 extension->permissions_data()->active_permissions())) {
1847 extensions::PermissionsUpdater(profile()).RemovePermissions(
1848 extension.get(),
binjin685ade82014-11-06 09:53:561849 settings->GetBlockedPermissions(extension.get()).get());
binjine6b58b52014-10-31 01:55:571850 }
1851 }
1852
binjin1569c9b2014-09-05 13:33:181853 CheckManagementPolicy();
1854}
1855
[email protected]8c484b742012-11-29 06:05:361856void ExtensionService::AddNewOrUpdatedExtension(
1857 const Extension* extension,
[email protected]399583b2012-12-11 09:33:421858 Extension::State initial_state,
[email protected]4a1d9c0d2014-06-13 12:50:111859 int install_flags,
[email protected]d8fd0fd2014-03-24 13:16:061860 const syncer::StringOrdinal& page_ordinal,
1861 const std::string& install_parameter) {
[email protected]8c484b742012-11-29 06:05:361862 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]760f743b2014-05-28 13:52:021863 bool was_ephemeral = extension_prefs_->IsEphemeralApp(extension->id());
[email protected]4a1d9c0d2014-06-13 12:50:111864 extension_prefs_->OnExtensionInstalled(
1865 extension, initial_state, page_ordinal, install_flags, install_parameter);
[email protected]9e9c1d12013-07-31 01:58:121866 delayed_installs_.Remove(extension->id());
[email protected]913ffca92014-03-27 15:26:161867 if (InstallVerifier::NeedsVerification(*extension))
1868 system_->install_verifier()->VerifyExtension(extension->id());
ryanackley48bedbd2015-01-27 23:12:141869
1870 const Extension* old = GetInstalledExtension(extension->id());
1871 if (extensions::AppDataMigrator::NeedsMigration(old, extension)) {
1872 app_data_migrator_->DoMigrationAndReply(
1873 old, extension,
1874 base::Bind(&ExtensionService::FinishInstallation, AsWeakPtr(),
1875 make_scoped_refptr(extension), was_ephemeral));
1876 return;
1877 }
1878
[email protected]760f743b2014-05-28 13:52:021879 FinishInstallation(extension, was_ephemeral);
[email protected]6f6101832012-11-27 22:10:481880}
1881
1882void ExtensionService::MaybeFinishDelayedInstallation(
1883 const std::string& extension_id) {
[email protected]9f4e4f082013-06-21 07:11:191884 // Check if the extension already got installed.
1885 if (!delayed_installs_.Contains(extension_id))
[email protected]6f6101832012-11-27 22:10:481886 return;
[email protected]9f4e4f082013-06-21 07:11:191887 extensions::ExtensionPrefs::DelayReason reason =
1888 extension_prefs_->GetDelayedInstallReason(extension_id);
1889
1890 // Check if the extension is idle. DELAY_REASON_NONE is used for older
1891 // preferences files that will not have set this field but it was previously
1892 // only used for idle updates.
1893 if ((reason == extensions::ExtensionPrefs::DELAY_REASON_WAIT_FOR_IDLE ||
1894 reason == extensions::ExtensionPrefs::DELAY_REASON_NONE) &&
[email protected]1d5cf4142014-01-24 18:25:221895 is_ready() && !extensions::util::IsExtensionIdle(extension_id, profile_))
[email protected]6f6101832012-11-27 22:10:481896 return;
1897
[email protected]9f4e4f082013-06-21 07:11:191898 const Extension* extension = delayed_installs_.GetByID(extension_id);
1899 if (reason == extensions::ExtensionPrefs::DELAY_REASON_WAIT_FOR_IMPORTS) {
[email protected]90878c52014-04-04 18:21:021900 extensions::SharedModuleService::ImportStatus status =
1901 shared_module_service_->SatisfyImports(extension);
1902 if (status != SharedModuleService::IMPORT_STATUS_OK) {
1903 if (status == SharedModuleService::IMPORT_STATUS_UNRECOVERABLE) {
[email protected]9f4e4f082013-06-21 07:11:191904 delayed_installs_.Remove(extension_id);
1905 // Make sure no version of the extension is actually installed, (i.e.,
1906 // that this delayed install was not an update).
1907 CHECK(!extension_prefs_->GetInstalledExtensionInfo(extension_id).get());
1908 extension_prefs_->DeleteExtensionPrefs(extension_id);
1909 }
1910 return;
1911 }
1912 }
1913
[email protected]6f6101832012-11-27 22:10:481914 FinishDelayedInstallation(extension_id);
1915}
1916
1917void ExtensionService::FinishDelayedInstallation(
1918 const std::string& extension_id) {
1919 scoped_refptr<const Extension> extension(
1920 GetPendingExtensionUpdate(extension_id));
[email protected]dc24976f2013-06-02 21:15:091921 CHECK(extension.get());
[email protected]9f4e4f082013-06-21 07:11:191922 delayed_installs_.Remove(extension_id);
[email protected]6f6101832012-11-27 22:10:481923
[email protected]760f743b2014-05-28 13:52:021924 bool was_ephemeral = extension_prefs_->IsEphemeralApp(extension->id());
[email protected]399583b2012-12-11 09:33:421925 if (!extension_prefs_->FinishDelayedInstallInfo(extension_id))
[email protected]6f6101832012-11-27 22:10:481926 NOTREACHED();
1927
[email protected]760f743b2014-05-28 13:52:021928 FinishInstallation(extension.get(), was_ephemeral);
[email protected]6f6101832012-11-27 22:10:481929}
1930
[email protected]760f743b2014-05-28 13:52:021931void ExtensionService::FinishInstallation(
1932 const Extension* extension, bool was_ephemeral) {
[email protected]e7554c3f2013-05-29 00:36:561933 const extensions::Extension* existing_extension =
1934 GetInstalledExtension(extension->id());
1935 bool is_update = false;
1936 std::string old_name;
1937 if (existing_extension) {
1938 is_update = true;
1939 old_name = existing_extension->name();
1940 }
[email protected]760f743b2014-05-28 13:52:021941 bool from_ephemeral =
1942 was_ephemeral && !extension_prefs_->IsEphemeralApp(extension->id());
1943 extensions::InstalledExtensionInfo details(
1944 extension, is_update, from_ephemeral, old_name);
[email protected]fcb58a862012-05-01 01:03:151945 content::NotificationService::current()->Notify(
[email protected]adf5a102014-07-31 12:44:061946 extensions::NOTIFICATION_EXTENSION_WILL_BE_INSTALLED_DEPRECATED,
[email protected]fcb58a862012-05-01 01:03:151947 content::Source<Profile>(profile_),
[email protected]41bb80bd2013-05-03 10:56:021948 content::Details<const extensions::InstalledExtensionInfo>(&details));
[email protected]fcb58a862012-05-01 01:03:151949
[email protected]bc44b5da2014-06-12 14:20:001950 registry_->TriggerOnWillBeInstalled(
[email protected]760f743b2014-05-28 13:52:021951 extension, is_update, from_ephemeral, old_name);
[email protected]17f07822014-05-22 08:45:151952
[email protected]399583b2012-12-11 09:33:421953 // Unpacked extensions default to allowing file access, but if that has been
1954 // overridden, don't reset the value.
[email protected]1d5e58b2013-01-31 08:41:401955 if (Manifest::ShouldAlwaysAllowFileAccess(extension->location()) &&
[email protected]399583b2012-12-11 09:33:421956 !extension_prefs_->HasAllowFileAccessSetting(extension->id())) {
1957 extension_prefs_->SetAllowFileAccess(extension->id(), true);
1958 }
1959
[email protected]6f6101832012-11-27 22:10:481960 AddExtension(extension);
[email protected]612a1cb12012-10-17 13:18:031961
[email protected]bc44b5da2014-06-12 14:20:001962 // Notify observers that need to know when an installation is complete.
[email protected]38e872532014-07-16 23:27:511963 registry_->TriggerOnInstalled(extension, is_update);
[email protected]bc44b5da2014-06-12 14:20:001964
[email protected]9f4e4f082013-06-21 07:11:191965 // Check extensions that may have been delayed only because this shared module
1966 // was not available.
[email protected]374ceb6f2014-07-02 19:25:341967 if (SharedModuleInfo::IsSharedModule(extension))
[email protected]9f4e4f082013-06-21 07:11:191968 MaybeFinishDelayedInstallations();
[email protected]4a190632009-05-09 01:07:421969}
1970
[email protected]760f743b2014-05-28 13:52:021971void ExtensionService::PromoteEphemeralApp(
1972 const extensions::Extension* extension, bool is_from_sync) {
1973 DCHECK(GetInstalledExtension(extension->id()) &&
1974 extension_prefs_->IsEphemeralApp(extension->id()));
1975
[email protected]db378322014-07-21 23:19:341976 if (extension->RequiresSortOrdinal()) {
1977 extension_prefs_->app_sorting()->SetExtensionVisible(
1978 extension->id(), extension->ShouldDisplayInNewTabPage());
1979
1980 if (!is_from_sync) {
[email protected]760f743b2014-05-28 13:52:021981 // Reset the sort ordinals of the app to ensure it is added to the default
1982 // position, like newly installed apps would.
1983 extension_prefs_->app_sorting()->ClearOrdinals(extension->id());
[email protected]760f743b2014-05-28 13:52:021984 }
1985
[email protected]db378322014-07-21 23:19:341986 extension_prefs_->app_sorting()->EnsureValidOrdinals(
1987 extension->id(), syncer::StringOrdinal());
1988 }
1989
[email protected]760f743b2014-05-28 13:52:021990 // Remove the ephemeral flags from the preferences.
1991 extension_prefs_->OnEphemeralAppPromoted(extension->id());
1992
1993 // Fire install-related events to allow observers to handle the promotion
1994 // of the ephemeral app.
1995 extensions::InstalledExtensionInfo details(
1996 extension,
1997 true /* is update */,
1998 true /* from ephemeral */,
1999 extension->name() /* old name */);
2000 content::NotificationService::current()->Notify(
[email protected]adf5a102014-07-31 12:44:062001 extensions::NOTIFICATION_EXTENSION_WILL_BE_INSTALLED_DEPRECATED,
[email protected]760f743b2014-05-28 13:52:022002 content::Source<Profile>(profile_),
2003 content::Details<const extensions::InstalledExtensionInfo>(&details));
2004
2005 registry_->TriggerOnWillBeInstalled(
2006 extension,
2007 true /* is update */,
2008 true /* from ephemeral */,
2009 extension->name() /* old name */);
2010
2011 if (registry_->enabled_extensions().Contains(extension->id())) {
[email protected]8f959f522014-08-06 06:26:282012 // If the app is already enabled and loaded, fire the load events to allow
2013 // observers to handle the promotion of the ephemeral app.
[email protected]760f743b2014-05-28 13:52:022014 content::NotificationService::current()->Notify(
[email protected]adf5a102014-07-31 12:44:062015 extensions::NOTIFICATION_EXTENSION_LOADED_DEPRECATED,
[email protected]760f743b2014-05-28 13:52:022016 content::Source<Profile>(profile_),
2017 content::Details<const Extension>(extension));
2018
2019 registry_->TriggerOnLoaded(extension);
[email protected]8f959f522014-08-06 06:26:282020 } else {
2021 // Cached ephemeral apps may be updated and disabled due to permissions
2022 // increase. The app can be enabled (as long as no other disable reasons
2023 // exist) as the install was user-acknowledged.
2024 int disable_mask = Extension::DISABLE_NONE;
2025 if (!is_from_sync)
2026 disable_mask |= Extension::DISABLE_PERMISSIONS_INCREASE;
2027
2028 int other_disable_reasons =
2029 extension_prefs_->GetDisableReasons(extension->id()) & ~disable_mask;
2030 if (!other_disable_reasons) {
2031 if (extension_prefs_->DidExtensionEscalatePermissions(extension->id()))
2032 GrantPermissionsAndEnableExtension(extension);
2033 else
2034 EnableExtension(extension->id());
2035 }
[email protected]760f743b2014-05-28 13:52:022036 }
2037
[email protected]38e872532014-07-16 23:27:512038 registry_->TriggerOnInstalled(extension, true);
[email protected]bc44b5da2014-06-12 14:20:002039
[email protected]760f743b2014-05-28 13:52:022040 if (!is_from_sync && extension_sync_service_)
2041 extension_sync_service_->SyncExtensionChangeIfNeeded(*extension);
2042}
2043
[email protected]76b65442012-11-17 14:11:482044const Extension* ExtensionService::GetPendingExtensionUpdate(
2045 const std::string& id) const {
[email protected]9f4e4f082013-06-21 07:11:192046 return delayed_installs_.GetByID(id);
[email protected]76b65442012-11-17 14:11:482047}
2048
mukai87a8d402014-09-15 20:15:092049void ExtensionService::RegisterContentSettings(
2050 HostContentSettingsMap* host_content_settings_map) {
rkaplowe65c2ff2015-02-14 16:29:542051 TRACE_EVENT0("browser,startup", "ExtensionService::RegisterContentSettings");
mukaia1aa3512014-10-22 20:14:112052 DCHECK_CURRENTLY_ON(BrowserThread::UI);
mukai87a8d402014-09-15 20:15:092053 host_content_settings_map->RegisterProvider(
2054 HostContentSettingsMap::INTERNAL_EXTENSION_PROVIDER,
2055 scoped_ptr<content_settings::ObservableProvider>(
reillyga3acbc12014-11-11 23:17:122056 new content_settings::InternalExtensionProvider(profile_)));
mukai87a8d402014-09-15 20:15:092057
2058 host_content_settings_map->RegisterProvider(
2059 HostContentSettingsMap::CUSTOM_EXTENSION_PROVIDER,
2060 scoped_ptr<content_settings::ObservableProvider>(
2061 new content_settings::CustomExtensionProvider(
2062 extensions::ContentSettingsService::Get(
2063 profile_)->content_settings_store(),
2064 profile_->GetOriginalProfile() != profile_)));
2065}
2066
[email protected]bb7f40952011-01-13 00:21:202067void ExtensionService::TrackTerminatedExtension(const Extension* extension) {
[email protected]bb1bc9b32013-12-21 03:09:142068 // No need to check for duplicates; inserting a duplicate is a no-op.
2069 registry_->AddTerminated(make_scoped_refptr(extension));
[email protected]3964e572014-02-13 21:57:412070 extensions_being_terminated_.erase(extension->id());
[email protected]b0af4792013-10-23 09:12:132071 UnloadExtension(extension->id(), UnloadedExtensionInfo::REASON_TERMINATE);
[email protected]bb7f40952011-01-13 00:21:202072}
2073
[email protected]e9d7496e2014-04-18 01:25:462074void ExtensionService::TerminateExtension(const std::string& extension_id) {
2075 const Extension* extension = GetInstalledExtension(extension_id);
2076 TrackTerminatedExtension(extension);
2077}
2078
[email protected]bb7f40952011-01-13 00:21:202079void ExtensionService::UntrackTerminatedExtension(const std::string& id) {
[email protected]cb1f4ac2014-08-07 16:55:422080 std::string lowercase_id = base::StringToLowerASCII(id);
[email protected]bb1bc9b32013-12-21 03:09:142081 const Extension* extension =
2082 registry_->terminated_extensions().GetByID(lowercase_id);
2083 registry_->RemoveTerminated(lowercase_id);
[email protected]fb789532013-08-27 02:40:212084 if (extension) {
2085 content::NotificationService::current()->Notify(
[email protected]adf5a102014-07-31 12:44:062086 extensions::NOTIFICATION_EXTENSION_REMOVED,
[email protected]fb789532013-08-27 02:40:212087 content::Source<Profile>(profile_),
2088 content::Details<const Extension>(extension));
2089 }
[email protected]bb7f40952011-01-13 00:21:202090}
2091
[email protected]8001df22011-04-28 19:59:472092const Extension* ExtensionService::GetInstalledExtension(
2093 const std::string& id) const {
[email protected]599539802014-01-07 23:06:002094 return registry_->GetExtensionById(id, ExtensionRegistry::EVERYTHING);
[email protected]0dfe05c2011-02-23 23:03:362095}
2096
[email protected]9060d8b02012-01-13 02:14:302097bool ExtensionService::OnExternalExtensionFileFound(
[email protected]8ef78fd2010-08-19 17:14:322098 const std::string& id,
[email protected]c5e4a2222014-01-03 16:06:132099 const Version* version,
[email protected]650b2d52013-02-10 03:41:452100 const base::FilePath& path,
[email protected]1d5e58b2013-01-31 08:41:402101 Manifest::Location location,
[email protected]47fc70c2011-12-06 07:29:512102 int creation_flags,
2103 bool mark_acknowledged) {
[email protected]ab22ba42011-01-14 16:36:382104 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]fdd28372014-08-21 02:27:262105 CHECK(crx_file::id_util::IdIsValid(id));
[email protected]79c833b52011-04-05 18:31:012106 if (extension_prefs_->IsExternalExtensionUninstalled(id))
[email protected]9060d8b02012-01-13 02:14:302107 return false;
[email protected]a8af9fdb2010-10-28 21:52:202108
[email protected]7577a5c52009-07-30 06:21:582109 // Before even bothering to unpack, check and see if we already have this
[email protected]4c967932009-07-31 01:15:492110 // version. This is important because these extensions are going to get
[email protected]7577a5c52009-07-30 06:21:582111 // installed on every startup.
[email protected]9adb9692010-10-29 23:14:022112 const Extension* existing = GetExtensionById(id, true);
[email protected]910f72ce2012-08-24 01:38:352113
[email protected]7577a5c52009-07-30 06:21:582114 if (existing) {
[email protected]910f72ce2012-08-24 01:38:352115 // The default apps will have the location set as INTERNAL. Since older
2116 // default apps are installed as EXTERNAL, we override them. However, if the
2117 // app is already installed as internal, then do the version check.
[email protected]31bb5ee62012-09-12 22:58:402118 // TODO(grv) : Remove after Q1-2013.
[email protected]910f72ce2012-08-24 01:38:352119 bool is_default_apps_migration =
[email protected]1d5e58b2013-01-31 08:41:402120 (location == Manifest::INTERNAL &&
2121 Manifest::IsExternalLocation(existing->location()));
[email protected]910f72ce2012-08-24 01:38:352122
2123 if (!is_default_apps_migration) {
2124 DCHECK(version);
2125
2126 switch (existing->version()->CompareTo(*version)) {
2127 case -1: // existing version is older, we should upgrade
2128 break;
2129 case 0: // existing version is same, do nothing
2130 return false;
2131 case 1: // existing version is newer, uh-oh
2132 LOG(WARNING) << "Found external version of extension " << id
2133 << "that is older than current version. Current version "
2134 << "is: " << existing->VersionString() << ". New "
2135 << "version is: " << version->GetString()
2136 << ". Keeping current version.";
2137 return false;
2138 }
[email protected]7577a5c52009-07-30 06:21:582139 }
2140 }
2141
[email protected]9060d8b02012-01-13 02:14:302142 // If the extension is already pending, don't start an install.
[email protected]e3987852012-05-04 10:06:302143 if (!pending_extension_manager()->AddFromExternalFile(
[email protected]464213a2013-10-15 01:06:482144 id, location, *version, creation_flags, mark_acknowledged)) {
[email protected]9060d8b02012-01-13 02:14:302145 return false;
[email protected]e3987852012-05-04 10:06:302146 }
[email protected]9c635f22010-12-02 09:36:362147
[email protected]14908b72011-04-20 06:54:362148 // no client (silent install)
[email protected]f8636f92013-08-09 21:02:372149 scoped_refptr<CrxInstaller> installer(CrxInstaller::CreateSilent(this));
[email protected]6dfbbf82010-03-12 23:09:162150 installer->set_install_source(location);
2151 installer->set_expected_id(id);
[email protected]cb0e50312011-05-09 15:03:072152 installer->set_expected_version(*version);
2153 installer->set_install_cause(extension_misc::INSTALL_CAUSE_EXTERNAL_FILE);
[email protected]1bf73cc32011-10-26 22:38:312154 installer->set_creation_flags(creation_flags);
[email protected]88e8ec9152013-01-17 04:05:182155#if defined(OS_CHROMEOS)
2156 extensions::InstallLimiter::Get(profile_)->Add(installer, path);
2157#else
[email protected]6dfbbf82010-03-12 23:09:162158 installer->InstallCrx(path);
[email protected]88e8ec9152013-01-17 04:05:182159#endif
[email protected]47fc70c2011-12-06 07:29:512160
2161 // Depending on the source, a new external extension might not need a user
2162 // notification on installation. For such extensions, mark them acknowledged
2163 // now to suppress the notification.
2164 if (mark_acknowledged)
[email protected]374ceb6f2014-07-02 19:25:342165 external_install_manager_->AcknowledgeExternalExtension(id);
[email protected]9060d8b02012-01-13 02:14:302166
2167 return true;
[email protected]7577a5c52009-07-30 06:21:582168}
2169
[email protected]eaa7dd182010-12-14 11:09:002170void ExtensionService::DidCreateRenderViewForBackgroundPage(
[email protected]3a1dc572012-07-31 22:25:132171 extensions::ExtensionHost* host) {
[email protected]406027c02010-09-27 08:03:182172 OrphanedDevTools::iterator iter =
[email protected]2d2f6cfc2011-05-06 21:09:332173 orphaned_dev_tools_.find(host->extension_id());
[email protected]406027c02010-09-27 08:03:182174 if (iter == orphaned_dev_tools_.end())
2175 return;
2176
[email protected]b3f957e62014-08-08 10:09:022177 iter->second->ConnectWebContents(host->host_contents());
[email protected]406027c02010-09-27 08:03:182178 orphaned_dev_tools_.erase(iter);
2179}
2180
[email protected]432115822011-07-10 15:52:272181void ExtensionService::Observe(int type,
[email protected]6c2381d2011-10-19 02:52:532182 const content::NotificationSource& source,
2183 const content::NotificationDetails& details) {
[email protected]432115822011-07-10 15:52:272184 switch (type) {
[email protected]3c4abc82012-10-22 22:25:542185 case chrome::NOTIFICATION_APP_TERMINATING:
2186 // Shutdown has started. Don't start any more extension installs.
2187 // (We cannot use ExtensionService::Shutdown() for this because it
2188 // happens too late in browser teardown.)
2189 browser_terminating_ = true;
2190 break;
[email protected]adf5a102014-07-31 12:44:062191 case extensions::NOTIFICATION_EXTENSION_PROCESS_TERMINATED: {
[email protected]6c2381d2011-10-19 02:52:532192 if (profile_ !=
2193 content::Source<Profile>(source).ptr()->GetOriginalProfile()) {
[email protected]bc535ee52010-08-31 18:40:322194 break;
[email protected]6c2381d2011-10-19 02:52:532195 }
[email protected]a4ed6282009-12-14 20:51:162196
[email protected]3a1dc572012-07-31 22:25:132197 extensions::ExtensionHost* host =
2198 content::Details<extensions::ExtensionHost>(details).ptr();
[email protected]f128af42010-08-05 18:05:262199
[email protected]3964e572014-02-13 21:57:412200 // If the extension is already being terminated, there is nothing left to
2201 // do.
2202 if (!extensions_being_terminated_.insert(host->extension_id()).second)
2203 break;
2204
[email protected]fa2416f2011-05-03 08:41:202205 // Mark the extension as terminated and Unload it. We want it to
2206 // be in a consistent state: either fully working or not loaded
2207 // at all, but never half-crashed. We do it in a PostTask so
2208 // that other handlers of this notification will still have
2209 // access to the Extension and ExtensionHost.
[email protected]b3a25092013-05-28 22:08:162210 base::MessageLoop::current()->PostTask(
[email protected]14908b72011-04-20 06:54:362211 FROM_HERE,
[email protected]53612e82011-10-18 18:00:362212 base::Bind(
[email protected]fa2416f2011-05-03 08:41:202213 &ExtensionService::TrackTerminatedExtension,
[email protected]d8c8f25f2011-11-02 18:18:012214 AsWeakPtr(),
[email protected]fa2416f2011-05-03 08:41:202215 host->extension()));
[email protected]31f77262009-12-02 20:48:532216 break;
2217 }
[email protected]432115822011-07-10 15:52:272218 case content::NOTIFICATION_RENDERER_PROCESS_TERMINATED: {
[email protected]f3b1a082011-11-18 00:34:302219 content::RenderProcessHost* process =
2220 content::Source<content::RenderProcessHost>(source).ptr();
[email protected]fc30ef082011-08-18 04:07:192221 Profile* host_profile =
[email protected]f3b1a082011-11-18 00:34:302222 Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]fc30ef082011-08-18 04:07:192223 if (!profile_->IsSameProfile(host_profile->GetOriginalProfile()))
2224 break;
2225
[email protected]fafdc842014-01-17 18:09:082226 extensions::ProcessMap* process_map =
2227 extensions::ProcessMap::Get(profile_);
2228 if (process_map->Contains(process->GetID())) {
[email protected]52b76592013-11-02 17:59:032229 // An extension process was terminated, this might have resulted in an
2230 // app or extension becoming idle.
2231 std::set<std::string> extension_ids =
[email protected]fafdc842014-01-17 18:09:082232 process_map->GetExtensionsInProcess(process->GetID());
elijahtaylor0def4432014-10-06 18:15:112233 // In addition to the extensions listed in the process map, one of those
2234 // extensions could be referencing a shared module which is waiting for
2235 // idle to update. Check all imports of these extensions, too.
2236 std::set<std::string> import_ids;
2237 for (std::set<std::string>::const_iterator it = extension_ids.begin();
2238 it != extension_ids.end();
2239 ++it) {
2240 const Extension* extension = GetExtensionById(*it, true);
2241 if (!extension)
2242 continue;
2243 const std::vector<SharedModuleInfo::ImportInfo>& imports =
2244 SharedModuleInfo::GetImports(extension);
2245 std::vector<SharedModuleInfo::ImportInfo>::const_iterator import_it;
2246 for (import_it = imports.begin(); import_it != imports.end();
2247 import_it++) {
2248 import_ids.insert((*import_it).extension_id);
2249 }
2250 }
2251 extension_ids.insert(import_ids.begin(), import_ids.end());
2252
[email protected]52b76592013-11-02 17:59:032253 for (std::set<std::string>::const_iterator it = extension_ids.begin();
2254 it != extension_ids.end(); ++it) {
2255 if (delayed_installs_.Contains(*it)) {
2256 base::MessageLoop::current()->PostDelayedTask(
2257 FROM_HERE,
2258 base::Bind(&ExtensionService::MaybeFinishDelayedInstallation,
2259 AsWeakPtr(), *it),
2260 base::TimeDelta::FromSeconds(kUpdateIdleDelay));
2261 }
2262 }
2263 }
2264
[email protected]fafdc842014-01-17 18:09:082265 process_map->RemoveAllFromProcess(process->GetID());
[email protected]6f371442011-11-09 06:45:462266 BrowserThread::PostTask(
[email protected]38427a12013-11-09 17:34:202267 BrowserThread::IO,
2268 FROM_HERE,
2269 base::Bind(&extensions::InfoMap::UnregisterAllExtensionsInProcess,
[email protected]31d8f5f22012-04-02 15:22:082270 system_->info_map(),
[email protected]f3b1a082011-11-18 00:34:302271 process->GetID()));
[email protected]da5683db2011-04-23 17:12:212272 break;
2273 }
[email protected]92dd8d92013-02-26 00:41:082274 case chrome::NOTIFICATION_UPGRADE_RECOMMENDED: {
[email protected]75bdcb872013-03-13 00:41:452275 // Notify observers that chrome update is available.
2276 FOR_EACH_OBSERVER(extensions::UpdateObserver, update_observers_,
2277 OnChromeUpdateAvailable());
[email protected]92dd8d92013-02-26 00:41:082278 break;
2279 }
[email protected]ebe07772014-05-22 04:16:062280 case chrome::NOTIFICATION_PROFILE_DESTRUCTION_STARTED: {
2281 OnProfileDestructionStarted();
2282 break;
2283 }
[email protected]aa96d3a2010-08-21 08:45:252284
[email protected]4814b512009-11-07 00:12:292285 default:
2286 NOTREACHED() << "Unexpected notification type.";
2287 }
2288}
2289
binjin47947f842014-11-18 12:10:242290int ExtensionService::GetDisableReasonsOnInstalled(const Extension* extension) {
2291 Extension::DisableReason disable_reason;
2292 // Extensions disabled by management policy should always be disabled, even
2293 // if it's force-installed.
2294 if (system_->management_policy()->MustRemainDisabled(
2295 extension, &disable_reason, nullptr)) {
2296 // A specified reason is required to disable the extension.
2297 DCHECK(disable_reason != Extension::DISABLE_NONE);
2298 return disable_reason;
2299 }
2300
[email protected]612a1cb12012-10-17 13:18:032301 // Extensions installed by policy can't be disabled. So even if a previous
2302 // installation disabled the extension, make sure it is now enabled.
binjin47947f842014-11-18 12:10:242303 if (system_->management_policy()->MustRemainEnabled(extension, nullptr))
2304 return Extension::DISABLE_NONE;
[email protected]612a1cb12012-10-17 13:18:032305
binjin47947f842014-11-18 12:10:242306 // An already disabled extension should inherit the disable reasons and
2307 // remain disabled.
2308 if (extension_prefs_->IsExtensionDisabled(extension->id())) {
2309 int disable_reasons = extension_prefs_->GetDisableReasons(extension->id());
2310 // If an extension was disabled without specified reason, presume it's
2311 // disabled by user.
2312 return disable_reasons == Extension::DISABLE_NONE
2313 ? Extension::DISABLE_USER_ACTION
2314 : disable_reasons;
2315 }
[email protected]612a1cb12012-10-17 13:18:032316
[email protected]41070e8d2012-10-24 01:34:362317 if (FeatureSwitch::prompt_for_external_extensions()->IsEnabled()) {
[email protected]612a1cb12012-10-17 13:18:032318 // External extensions are initially disabled. We prompt the user before
[email protected]2c495c42013-01-04 21:49:542319 // enabling them. Hosted apps are excepted because they are not dangerous
2320 // (they need to be launched by the user anyway).
[email protected]1d5e58b2013-01-31 08:41:402321 if (extension->GetType() != Manifest::TYPE_HOSTED_APP &&
2322 Manifest::IsExternalLocation(extension->location()) &&
[email protected]612a1cb12012-10-17 13:18:032323 !extension_prefs_->IsExternalExtensionAcknowledged(extension->id())) {
binjin47947f842014-11-18 12:10:242324 return Extension::DISABLE_EXTERNAL_EXTENSION;
[email protected]612a1cb12012-10-17 13:18:032325 }
2326 }
[email protected]612a1cb12012-10-17 13:18:032327
binjin47947f842014-11-18 12:10:242328 return Extension::DISABLE_NONE;
[email protected]612a1cb12012-10-17 13:18:032329}
[email protected]0db124b02012-11-07 04:55:052330
mlerman6a37b6a42014-11-26 22:10:532331// Helper method to determine if an extension can be blocked.
2332bool ExtensionService::CanBlockExtension(const Extension* extension) const {
mlerman3690e5be2014-12-01 22:57:442333 DCHECK(extension);
mlerman6a37b6a42014-11-26 22:10:532334 return extension->location() != Manifest::COMPONENT &&
2335 extension->location() != Manifest::EXTERNAL_COMPONENT &&
2336 !system_->management_policy()->MustRemainEnabled(extension, NULL);
2337}
2338
[email protected]e7aa7b7e2012-11-27 04:51:222339bool ExtensionService::ShouldDelayExtensionUpdate(
2340 const std::string& extension_id,
[email protected]4a1d9c0d2014-06-13 12:50:112341 bool install_immediately) const {
[email protected]e7aa7b7e2012-11-27 04:51:222342 const char kOnUpdateAvailableEvent[] = "runtime.onUpdateAvailable";
2343
2344 // If delayed updates are globally disabled, or just for this extension,
2345 // don't delay.
[email protected]4a1d9c0d2014-06-13 12:50:112346 if (!install_updates_when_idle_ || install_immediately)
[email protected]e7aa7b7e2012-11-27 04:51:222347 return false;
2348
[email protected]695b5712012-12-06 23:55:282349 const Extension* old = GetInstalledExtension(extension_id);
[email protected]e7aa7b7e2012-11-27 04:51:222350 // If there is no old extension, this is not an update, so don't delay.
2351 if (!old)
2352 return false;
2353
[email protected]9367eabc2013-03-01 01:29:292354 if (extensions::BackgroundInfo::HasPersistentBackgroundPage(old)) {
[email protected]e7aa7b7e2012-11-27 04:51:222355 // Delay installation if the extension listens for the onUpdateAvailable
2356 // event.
2357 return system_->event_router()->ExtensionHasEventListener(
2358 extension_id, kOnUpdateAvailableEvent);
2359 } else {
2360 // Delay installation if the extension is not idle.
[email protected]1d5cf4142014-01-24 18:25:222361 return !extensions::util::IsExtensionIdle(extension_id, profile_);
[email protected]e7aa7b7e2012-11-27 04:51:222362 }
[email protected]0db124b02012-11-07 04:55:052363}
[email protected]fdd679b2012-11-15 20:49:392364
[email protected]e5f8fffe2014-04-02 00:30:442365void ExtensionService::OnGarbageCollectIsolatedStorageStart() {
2366 DCHECK(!installs_delayed_for_gc_);
2367 installs_delayed_for_gc_ = true;
[email protected]399583b2012-12-11 09:33:422368}
2369
2370void ExtensionService::OnGarbageCollectIsolatedStorageFinished() {
[email protected]e5f8fffe2014-04-02 00:30:442371 DCHECK(installs_delayed_for_gc_);
2372 installs_delayed_for_gc_ = false;
[email protected]9f4e4f082013-06-21 07:11:192373 MaybeFinishDelayedInstallations();
2374}
2375
2376void ExtensionService::MaybeFinishDelayedInstallations() {
2377 std::vector<std::string> to_be_installed;
[email protected]399583b2012-12-11 09:33:422378 for (ExtensionSet::const_iterator it = delayed_installs_.begin();
2379 it != delayed_installs_.end();
2380 ++it) {
[email protected]9f4e4f082013-06-21 07:11:192381 to_be_installed.push_back((*it)->id());
[email protected]399583b2012-12-11 09:33:422382 }
[email protected]9f4e4f082013-06-21 07:11:192383 for (std::vector<std::string>::const_iterator it = to_be_installed.begin();
2384 it != to_be_installed.end();
[email protected]399583b2012-12-11 09:33:422385 ++it) {
[email protected]9f4e4f082013-06-21 07:11:192386 MaybeFinishDelayedInstallation(*it);
[email protected]399583b2012-12-11 09:33:422387 }
[email protected]399583b2012-12-11 09:33:422388}
2389
[email protected]fdd679b2012-11-15 20:49:392390void ExtensionService::OnBlacklistUpdated() {
[email protected]2d19eb6e2014-01-27 17:30:002391 blacklist_->GetBlacklistedIDs(
[email protected]f47f7172014-03-19 19:27:102392 registry_->GenerateInstalledExtensionsSet()->GetIDs(),
[email protected]3f2a2fa2013-09-24 02:55:252393 base::Bind(&ExtensionService::ManageBlacklist, AsWeakPtr()));
[email protected]695b5712012-12-06 23:55:282394}
2395
[email protected]2d19eb6e2014-01-27 17:30:002396void ExtensionService::ManageBlacklist(
2397 const extensions::Blacklist::BlacklistStateMap& state_map) {
[email protected]54ee8192014-03-29 17:37:242398 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]695b5712012-12-06 23:55:282399
mlerman6a37b6a42014-11-26 22:10:532400 std::set<std::string> blacklisted;
[email protected]2d19eb6e2014-01-27 17:30:002401 ExtensionIdSet greylist;
2402 ExtensionIdSet unchanged;
2403 for (extensions::Blacklist::BlacklistStateMap::const_iterator it =
2404 state_map.begin();
2405 it != state_map.end();
2406 ++it) {
2407 switch (it->second) {
2408 case extensions::NOT_BLACKLISTED:
2409 break;
[email protected]695b5712012-12-06 23:55:282410
[email protected]2d19eb6e2014-01-27 17:30:002411 case extensions::BLACKLISTED_MALWARE:
mlerman6a37b6a42014-11-26 22:10:532412 blacklisted.insert(it->first);
[email protected]2d19eb6e2014-01-27 17:30:002413 break;
2414
2415 case extensions::BLACKLISTED_SECURITY_VULNERABILITY:
2416 case extensions::BLACKLISTED_CWS_POLICY_VIOLATION:
2417 case extensions::BLACKLISTED_POTENTIALLY_UNWANTED:
2418 greylist.insert(it->first);
2419 break;
2420
2421 case extensions::BLACKLISTED_UNKNOWN:
2422 unchanged.insert(it->first);
2423 break;
2424 }
2425 }
2426
mlerman6a37b6a42014-11-26 22:10:532427 UpdateBlacklistedExtensions(blacklisted, unchanged);
[email protected]2d19eb6e2014-01-27 17:30:002428 UpdateGreylistedExtensions(greylist, unchanged, state_map);
2429
[email protected]373daf972014-04-10 01:50:442430 error_controller_->ShowErrorIfNeeded();
[email protected]2d19eb6e2014-01-27 17:30:002431}
2432
2433namespace {
2434void Partition(const ExtensionIdSet& before,
2435 const ExtensionIdSet& after,
2436 const ExtensionIdSet& unchanged,
2437 ExtensionIdSet* no_longer,
2438 ExtensionIdSet* not_yet) {
2439 *not_yet = base::STLSetDifference<ExtensionIdSet>(after, before);
2440 *no_longer = base::STLSetDifference<ExtensionIdSet>(before, after);
2441 *no_longer = base::STLSetDifference<ExtensionIdSet>(*no_longer, unchanged);
2442}
2443} // namespace
2444
mlerman6a37b6a42014-11-26 22:10:532445void ExtensionService::UpdateBlacklistedExtensions(
2446 const ExtensionIdSet& blacklisted,
[email protected]2d19eb6e2014-01-27 17:30:002447 const ExtensionIdSet& unchanged) {
2448 ExtensionIdSet not_yet_blocked, no_longer_blocked;
mlerman6a37b6a42014-11-26 22:10:532449 Partition(registry_->blacklisted_extensions().GetIDs(), blacklisted,
2450 unchanged, &no_longer_blocked, &not_yet_blocked);
[email protected]2d19eb6e2014-01-27 17:30:002451
2452 for (ExtensionIdSet::iterator it = no_longer_blocked.begin();
2453 it != no_longer_blocked.end(); ++it) {
[email protected]695b5712012-12-06 23:55:282454 scoped_refptr<const Extension> extension =
[email protected]bb1bc9b32013-12-21 03:09:142455 registry_->blacklisted_extensions().GetByID(*it);
[email protected]3f2a2fa2013-09-24 02:55:252456 if (!extension.get()) {
mlerman6a37b6a42014-11-26 22:10:532457 NOTREACHED() << "Extension " << *it << " no longer blacklisted, "
2458 << "but it was never blacklisted.";
[email protected]695b5712012-12-06 23:55:282459 continue;
[email protected]3f2a2fa2013-09-24 02:55:252460 }
[email protected]bb1bc9b32013-12-21 03:09:142461 registry_->RemoveBlacklisted(*it);
[email protected]3f2a2fa2013-09-24 02:55:252462 extension_prefs_->SetExtensionBlacklisted(extension->id(), false);
[email protected]dc24976f2013-06-02 21:15:092463 AddExtension(extension.get());
[email protected]ac875372013-02-28 04:36:092464 UMA_HISTOGRAM_ENUMERATION("ExtensionBlacklist.UnblacklistInstalled",
[email protected]dc24976f2013-06-02 21:15:092465 extension->location(),
2466 Manifest::NUM_LOCATIONS);
[email protected]695b5712012-12-06 23:55:282467 }
2468
[email protected]2d19eb6e2014-01-27 17:30:002469 for (ExtensionIdSet::iterator it = not_yet_blocked.begin();
2470 it != not_yet_blocked.end(); ++it) {
[email protected]695b5712012-12-06 23:55:282471 scoped_refptr<const Extension> extension = GetInstalledExtension(*it);
[email protected]3f2a2fa2013-09-24 02:55:252472 if (!extension.get()) {
2473 NOTREACHED() << "Extension " << *it << " needs to be "
2474 << "blacklisted, but it's not installed.";
[email protected]695b5712012-12-06 23:55:282475 continue;
[email protected]3f2a2fa2013-09-24 02:55:252476 }
[email protected]bb1bc9b32013-12-21 03:09:142477 registry_->AddBlacklisted(extension);
[email protected]2d19eb6e2014-01-27 17:30:002478 extension_prefs_->SetExtensionBlacklistState(
2479 extension->id(), extensions::BLACKLISTED_MALWARE);
[email protected]b0af4792013-10-23 09:12:132480 UnloadExtension(*it, UnloadedExtensionInfo::REASON_BLACKLIST);
[email protected]ac875372013-02-28 04:36:092481 UMA_HISTOGRAM_ENUMERATION("ExtensionBlacklist.BlacklistInstalled",
2482 extension->location(), Manifest::NUM_LOCATIONS);
[email protected]695b5712012-12-06 23:55:282483 }
[email protected]2d19eb6e2014-01-27 17:30:002484}
[email protected]695b5712012-12-06 23:55:282485
[email protected]2d19eb6e2014-01-27 17:30:002486// TODO(oleg): UMA logging
2487void ExtensionService::UpdateGreylistedExtensions(
2488 const ExtensionIdSet& greylist,
2489 const ExtensionIdSet& unchanged,
2490 const extensions::Blacklist::BlacklistStateMap& state_map) {
2491 ExtensionIdSet not_yet_greylisted, no_longer_greylisted;
2492 Partition(greylist_.GetIDs(),
2493 greylist, unchanged,
2494 &no_longer_greylisted, &not_yet_greylisted);
2495
2496 for (ExtensionIdSet::iterator it = no_longer_greylisted.begin();
2497 it != no_longer_greylisted.end(); ++it) {
2498 scoped_refptr<const Extension> extension = greylist_.GetByID(*it);
2499 if (!extension.get()) {
2500 NOTREACHED() << "Extension " << *it << " no longer greylisted, "
2501 << "but it was not marked as greylisted.";
2502 continue;
2503 }
2504
2505 greylist_.Remove(*it);
2506 extension_prefs_->SetExtensionBlacklistState(extension->id(),
2507 extensions::NOT_BLACKLISTED);
2508 if (extension_prefs_->GetDisableReasons(extension->id()) &
2509 extensions::Extension::DISABLE_GREYLIST)
2510 EnableExtension(*it);
2511 }
2512
2513 for (ExtensionIdSet::iterator it = not_yet_greylisted.begin();
2514 it != not_yet_greylisted.end(); ++it) {
2515 scoped_refptr<const Extension> extension = GetInstalledExtension(*it);
2516 if (!extension.get()) {
2517 NOTREACHED() << "Extension " << *it << " needs to be "
2518 << "disabled, but it's not installed.";
2519 continue;
2520 }
2521 greylist_.Insert(extension);
2522 extension_prefs_->SetExtensionBlacklistState(extension->id(),
2523 state_map.find(*it)->second);
2524 if (registry_->enabled_extensions().Contains(extension->id()))
2525 DisableExtension(*it, extensions::Extension::DISABLE_GREYLIST);
2526 }
[email protected]fdd679b2012-11-15 20:49:392527}
[email protected]75bdcb872013-03-13 00:41:452528
2529void ExtensionService::AddUpdateObserver(extensions::UpdateObserver* observer) {
2530 update_observers_.AddObserver(observer);
2531}
2532
2533void ExtensionService::RemoveUpdateObserver(
2534 extensions::UpdateObserver* observer) {
2535 update_observers_.RemoveObserver(observer);
2536}
[email protected]bb1bc9b32013-12-21 03:09:142537
2538// Used only by test code.
2539void ExtensionService::UnloadAllExtensionsInternal() {
2540 profile_->GetExtensionSpecialStoragePolicy()->RevokeRightsForAllExtensions();
2541
2542 registry_->ClearAll();
[email protected]45f5b7d2014-01-22 23:47:132543 system_->runtime_data()->ClearAll();
[email protected]bb1bc9b32013-12-21 03:09:142544
2545 // TODO(erikkay) should there be a notification for this? We can't use
2546 // EXTENSION_UNLOADED since that implies that the extension has been disabled
2547 // or uninstalled.
2548}
[email protected]ebe07772014-05-22 04:16:062549
2550void ExtensionService::OnProfileDestructionStarted() {
2551 ExtensionIdSet ids_to_unload = registry_->enabled_extensions().GetIDs();
2552 for (ExtensionIdSet::iterator it = ids_to_unload.begin();
2553 it != ids_to_unload.end();
2554 ++it) {
2555 UnloadExtension(*it, UnloadedExtensionInfo::REASON_PROFILE_SHUTDOWN);
2556 }
2557}