blob: df8a778493631bf4c29cdf86ea936649e80aef18 [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");
rkaplowa8fd8d32015-02-25 21:27:56389 SCOPED_UMA_HISTOGRAM_TIMER("Extensions.ExtensionServiceInitTime");
[email protected]3350d712013-11-18 09:32:24390
[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
rkaplowa8fd8d32015-02-25 21:27:56406 EnabledReloadableExtensions();
407 MaybeFinishShutdownDelayed();
[email protected]47b60072013-06-20 10:35:56408 SetReadyAndNotifyListeners();
[email protected]ae4c37e2012-12-21 01:16:25409
rkaplowa8fd8d32015-02-25 21:27:56410 // TODO(erikkay): this should probably be deferred to a future point
[email protected]47b60072013-06-20 10:35:56411 // rather than running immediately at startup.
412 CheckForExternalUpdates();
[email protected]894bb502009-05-21 22:39:57413
[email protected]2d19eb6e2014-01-27 17:30:00414 LoadGreylistFromPrefs();
[email protected]399583b2012-12-11 09:33:42415 }
rkaplowa8fd8d32015-02-25 21:27:56416}
[email protected]3350d712013-11-18 09:32:24417
rkaplowa8fd8d32015-02-25 21:27:56418void ExtensionService::EnabledReloadableExtensions() {
419 TRACE_EVENT0("browser,startup",
420 "ExtensionService::EnabledReloadableExtensions");
421
422 std::vector<std::string> extensions_to_enable;
423 const ExtensionSet& disabled_extensions = registry_->disabled_extensions();
424 for (ExtensionSet::const_iterator iter = disabled_extensions.begin();
425 iter != disabled_extensions.end(); ++iter) {
426 const Extension* e = iter->get();
427 if (extension_prefs_->GetDisableReasons(e->id()) ==
428 Extension::DISABLE_RELOAD) {
429 extensions_to_enable.push_back(e->id());
430 }
431 }
432 for (const std::string& extension : extensions_to_enable) {
433 EnableExtension(extension);
434 }
435}
436
437void ExtensionService::MaybeFinishShutdownDelayed() {
438 TRACE_EVENT0("browser,startup",
439 "ExtensionService::MaybeFinishShutdownDelayed");
440
441 scoped_ptr<extensions::ExtensionPrefs::ExtensionsInfo> delayed_info(
442 extension_prefs_->GetAllDelayedInstallInfo());
443 for (size_t i = 0; i < delayed_info->size(); ++i) {
444 ExtensionInfo* info = delayed_info->at(i).get();
445 scoped_refptr<const Extension> extension(NULL);
446 if (info->extension_manifest) {
447 std::string error;
448 extension = Extension::Create(
449 info->extension_path, info->extension_location,
450 *info->extension_manifest,
451 extension_prefs_->GetDelayedInstallCreationFlags(info->extension_id),
452 info->extension_id, &error);
453 if (extension.get())
454 delayed_installs_.Insert(extension);
455 }
456 }
457 MaybeFinishDelayedInstallations();
458 scoped_ptr<extensions::ExtensionPrefs::ExtensionsInfo> delayed_info2(
459 extension_prefs_->GetAllDelayedInstallInfo());
460 UMA_HISTOGRAM_COUNTS_100("Extensions.UpdateOnLoad",
461 delayed_info2->size() - delayed_info->size());
[email protected]6014d672008-12-05 00:38:25462}
463
[email protected]2d19eb6e2014-01-27 17:30:00464void ExtensionService::LoadGreylistFromPrefs() {
rkaplowa8fd8d32015-02-25 21:27:56465 TRACE_EVENT0("browser,startup", "ExtensionService::LoadGreylistFromPrefs");
466
[email protected]f47f7172014-03-19 19:27:10467 scoped_ptr<ExtensionSet> all_extensions =
468 registry_->GenerateInstalledExtensionsSet();
[email protected]2d19eb6e2014-01-27 17:30:00469
470 for (ExtensionSet::const_iterator it = all_extensions->begin();
471 it != all_extensions->end(); ++it) {
472 extensions::BlacklistState state =
473 extension_prefs_->GetExtensionBlacklistState((*it)->id());
474 if (state == extensions::BLACKLISTED_SECURITY_VULNERABILITY ||
475 state == extensions::BLACKLISTED_POTENTIALLY_UNWANTED ||
476 state == extensions::BLACKLISTED_CWS_POLICY_VIOLATION)
477 greylist_.Insert(*it);
478 }
479}
480
ginkage553af3202015-02-04 12:39:09481bool ExtensionService::UpdateExtension(const extensions::CRXFileInfo& file,
[email protected]044e86992014-01-24 22:59:11482 bool file_ownership_passed,
[email protected]31bb5ee62012-09-12 22:58:40483 CrxInstaller** out_crx_installer) {
[email protected]a29a517a2011-01-21 21:11:12484 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]3c4abc82012-10-22 22:25:54485 if (browser_terminating_) {
486 LOG(WARNING) << "Skipping UpdateExtension due to browser shutdown";
487 // Leak the temp file at extension_path. We don't want to add to the disk
488 // I/O burden at shutdown, we can't rely on the I/O completing anyway, and
489 // the file is in the OS temp directory which should be cleaned up for us.
490 return false;
491 }
[email protected]a8af9fdb2010-10-28 21:52:20492
ginkage553af3202015-02-04 12:39:09493 const std::string& id = file.extension_id;
494
[email protected]3f213ad2012-07-26 23:39:41495 const extensions::PendingExtensionInfo* pending_extension_info =
[email protected]51a3bf8b2012-06-08 22:53:06496 pending_extension_manager()->GetById(id);
[email protected]8ef78fd2010-08-19 17:14:32497
[email protected]695b5712012-12-06 23:55:28498 const Extension* extension = GetInstalledExtension(id);
[email protected]51a3bf8b2012-06-08 22:53:06499 if (!pending_extension_info && !extension) {
[email protected]aa142702010-03-26 01:26:33500 LOG(WARNING) << "Will not update extension " << id
501 << " because it is not installed or pending";
502 // Delete extension_path since we're not creating a CrxInstaller
503 // that would do it for us.
[email protected]7f8f24f2012-11-15 19:40:14504 if (!GetFileTaskRunner()->PostTask(
505 FROM_HERE,
ginkage553af3202015-02-04 12:39:09506 base::Bind(&extensions::file_util::DeleteFile, file.path, false)))
[email protected]14908b72011-04-20 06:54:36507 NOTREACHED();
[email protected]420a0ec2011-06-01 01:07:03508
509 return false;
[email protected]e957fe52009-06-23 16:51:05510 }
511
[email protected]f8636f92013-08-09 21:02:37512 scoped_refptr<CrxInstaller> installer(
pkotwicz31eb1e8ec2014-10-08 15:26:46513 CrxInstaller::Create(this, scoped_ptr<ExtensionInstallPrompt>()));
[email protected]6dfbbf82010-03-12 23:09:16514 installer->set_expected_id(id);
[email protected]464213a2013-10-15 01:06:48515 int creation_flags = Extension::NO_FLAGS;
[email protected]51a3bf8b2012-06-08 22:53:06516 if (pending_extension_info) {
517 installer->set_install_source(pending_extension_info->install_source());
pkotwicz31eb1e8ec2014-10-08 15:26:46518 installer->set_allow_silent_install(true);
[email protected]21db9ef2014-05-16 02:06:27519 if (pending_extension_info->remote_install())
520 installer->set_grant_permissions(false);
[email protected]464213a2013-10-15 01:06:48521 creation_flags = pending_extension_info->creation_flags();
522 if (pending_extension_info->mark_acknowledged())
[email protected]374ceb6f2014-07-02 19:25:34523 external_install_manager_->AcknowledgeExternalExtension(id);
[email protected]51a3bf8b2012-06-08 22:53:06524 } else if (extension) {
[email protected]5eb375e92010-11-26 07:50:41525 installer->set_install_source(extension->location());
[email protected]51a3bf8b2012-06-08 22:53:06526 }
[email protected]7d8b7072012-04-07 01:07:46527 // If the extension was installed from or has migrated to the webstore, or
[email protected]fcb2c2c2012-10-17 21:08:45528 // its auto-update URL is from the webstore, treat it as a webstore install.
529 // Note that we ignore some older extensions with blank auto-update URLs
530 // because we are mostly concerned with restrictions on NaCl extensions,
531 // which are newer.
[email protected]75764512011-12-19 19:54:28532 if ((extension && extension->from_webstore()) ||
[email protected]4a5fe3e22013-06-04 07:06:38533 (extension && extensions::ManifestURL::UpdatesFromGallery(extension)) ||
[email protected]963d13c2012-09-29 17:13:35534 (!extension && extension_urls::IsWebstoreUpdateUrl(
[email protected]51a3bf8b2012-06-08 22:53:06535 pending_extension_info->update_url()))) {
[email protected]a12ce8b22012-01-17 18:40:53536 creation_flags |= Extension::FROM_WEBSTORE;
537 }
538
539 // Bookmark apps being updated is kind of a contradiction, but that's because
540 // we mark the default apps as bookmark apps, and they're hosted in the web
541 // store, thus they can get updated. See http://crbug.com/101605 for more
542 // details.
543 if (extension && extension->from_bookmark())
544 creation_flags |= Extension::FROM_BOOKMARK;
545
[email protected]e33bbc22012-08-27 22:05:46546 if (extension && extension->was_installed_by_default())
547 creation_flags |= Extension::WAS_INSTALLED_BY_DEFAULT;
548
[email protected]acc3c7c22014-03-19 06:23:39549 if (extension && extension->was_installed_by_oem())
550 creation_flags |= Extension::WAS_INSTALLED_BY_OEM;
551
[email protected]6338fa32014-07-16 21:41:59552 if (extension && extension->was_installed_by_custodian())
553 creation_flags |= Extension::WAS_INSTALLED_BY_CUSTODIAN;
554
[email protected]658eae52014-06-14 20:28:05555 if (extension) {
[email protected]411f8ae2014-05-22 11:12:23556 installer->set_is_ephemeral(extension_prefs_->IsEphemeralApp(id));
[email protected]c30bda262014-06-19 04:10:13557 installer->set_do_not_sync(extension_prefs_->DoNotSync(id));
[email protected]658eae52014-06-14 20:28:05558 }
[email protected]ab6c7be42014-01-16 02:05:54559
[email protected]a12ce8b22012-01-17 18:40:53560 installer->set_creation_flags(creation_flags);
561
[email protected]044e86992014-01-24 22:59:11562 installer->set_delete_source(file_ownership_passed);
[email protected]cb0e50312011-05-09 15:03:07563 installer->set_install_cause(extension_misc::INSTALL_CAUSE_UPDATE);
ginkage553af3202015-02-04 12:39:09564 installer->InstallCrxFile(file);
[email protected]420a0ec2011-06-01 01:07:03565
566 if (out_crx_installer)
[email protected]dc24976f2013-06-02 21:15:09567 *out_crx_installer = installer.get();
[email protected]420a0ec2011-06-01 01:07:03568
569 return true;
[email protected]e957fe52009-06-23 16:51:05570}
571
[email protected]bca4b832014-07-17 20:22:34572void ExtensionService::ReloadExtensionImpl(
[email protected]757d60a2014-05-23 00:11:44573 // "transient" because the process of reloading may cause the reference
574 // to become invalid. Instead, use |extension_id|, a copy.
[email protected]bca4b832014-07-17 20:22:34575 const std::string& transient_extension_id,
576 bool be_noisy) {
[email protected]a29a517a2011-01-21 21:11:12577 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]2a947202013-03-06 04:58:05578
579 // If the extension is already reloading, don't reload again.
[email protected]757d60a2014-05-23 00:11:44580 if (extension_prefs_->GetDisableReasons(transient_extension_id) &
[email protected]2a947202013-03-06 04:58:05581 Extension::DISABLE_RELOAD) {
582 return;
583 }
584
mlerman6a37b6a42014-11-26 22:10:53585 // Ignore attempts to reload a blacklisted or blocked extension. Sometimes
586 // this can happen in a convoluted reload sequence triggered by the
587 // termination of a blacklisted or blocked extension and a naive attempt to
588 // reload it. For an example see http://crbug.com/373842.
589 if (registry_->blacklisted_extensions().Contains(transient_extension_id) ||
590 registry_->blocked_extensions().Contains(transient_extension_id)) {
[email protected]757d60a2014-05-23 00:11:44591 return;
mlerman6a37b6a42014-11-26 22:10:53592 }
[email protected]757d60a2014-05-23 00:11:44593
[email protected]650b2d52013-02-10 03:41:45594 base::FilePath path;
[email protected]757d60a2014-05-23 00:11:44595
596 std::string extension_id = transient_extension_id;
597 const Extension* transient_current_extension =
598 GetExtensionById(extension_id, false);
[email protected]9cddd4702009-07-27 22:09:40599
[email protected]f17dbd42010-08-16 23:21:10600 // Disable the extension if it's loaded. It might not be loaded if it crashed.
[email protected]757d60a2014-05-23 00:11:44601 if (transient_current_extension) {
[email protected]4814b512009-11-07 00:12:29602 // If the extension has an inspector open for its background page, detach
603 // the inspector and hang onto a cookie for it, so that we can reattach
604 // later.
[email protected]31d8f5f22012-04-02 15:22:08605 // TODO(yoz): this is not incognito-safe!
reillyg0ea3fa902014-10-28 15:30:23606 extensions::ProcessManager* manager =
607 extensions::ProcessManager::Get(profile_);
[email protected]3a1dc572012-07-31 22:25:13608 extensions::ExtensionHost* host =
609 manager->GetBackgroundHostForExtension(extension_id);
[email protected]b3f957e62014-08-08 10:09:02610 if (host && DevToolsAgentHost::HasFor(host->host_contents())) {
[email protected]4814b512009-11-07 00:12:29611 // Look for an open inspector for the background page.
[email protected]04ea1bb2013-07-10 09:26:09612 scoped_refptr<DevToolsAgentHost> agent_host =
[email protected]b3f957e62014-08-08 10:09:02613 DevToolsAgentHost::GetOrCreateFor(host->host_contents());
614 agent_host->DisconnectWebContents();
[email protected]04ea1bb2013-07-10 09:26:09615 orphaned_dev_tools_[extension_id] = agent_host;
[email protected]4814b512009-11-07 00:12:29616 }
617
[email protected]757d60a2014-05-23 00:11:44618 path = transient_current_extension->path();
[email protected]58076192013-07-19 19:43:50619 // BeingUpgraded is set back to false when the extension is added.
rdevlin.cronin2c16c602014-11-21 01:35:49620 system_->runtime_data()->SetBeingUpgraded(transient_current_extension->id(),
[email protected]757d60a2014-05-23 00:11:44621 true);
[email protected]44d62b62012-04-11 00:06:03622 DisableExtension(extension_id, Extension::DISABLE_RELOAD);
[email protected]b914e2952013-04-26 07:10:03623 reloading_extensions_.insert(extension_id);
[email protected]1eb175082010-02-10 09:26:16624 } else {
[email protected]d32c02a2014-06-16 22:58:36625 std::map<std::string, base::FilePath>::const_iterator iter =
626 unloaded_extension_paths_.find(extension_id);
627 if (iter == unloaded_extension_paths_.end()) {
628 return;
629 }
[email protected]1eb175082010-02-10 09:26:16630 path = unloaded_extension_paths_[extension_id];
[email protected]b65272f2009-08-31 15:47:06631 }
632
[email protected]757d60a2014-05-23 00:11:44633 transient_current_extension = NULL;
634
[email protected]9f4e4f082013-06-21 07:11:19635 if (delayed_installs_.Contains(extension_id)) {
[email protected]6f6101832012-11-27 22:10:48636 FinishDelayedInstallation(extension_id);
[email protected]0db124b02012-11-07 04:55:05637 return;
638 }
639
[email protected]43ceb002012-02-10 23:19:15640 // If we're reloading a component extension, use the component extension
641 // loader's reloader.
642 if (component_loader_->Exists(extension_id)) {
643 component_loader_->Reload(extension_id);
644 return;
645 }
646
[email protected]e6090e42010-03-23 22:44:08647 // Check the installed extensions to see if what we're reloading was already
648 // installed.
649 scoped_ptr<ExtensionInfo> installed_extension(
650 extension_prefs_->GetInstalledExtensionInfo(extension_id));
651 if (installed_extension.get() &&
652 installed_extension->extension_manifest.get()) {
[email protected]d8c8f25f2011-11-02 18:18:01653 extensions::InstalledLoader(this).Load(*installed_extension, false);
[email protected]e6090e42010-03-23 22:44:08654 } else {
[email protected]d8c8f25f2011-11-02 18:18:01655 // Otherwise, the extension is unpacked (location LOAD).
[email protected]e6090e42010-03-23 22:44:08656 // We should always be able to remember the extension's path. If it's not in
657 // the map, someone failed to update |unloaded_extension_paths_|.
658 CHECK(!path.empty());
[email protected]bca4b832014-07-17 20:22:34659 scoped_refptr<extensions::UnpackedInstaller> unpacked_installer =
660 extensions::UnpackedInstaller::Create(this);
661 unpacked_installer->set_be_noisy_on_failure(be_noisy);
662 unpacked_installer->Load(path);
[email protected]e6090e42010-03-23 22:44:08663 }
[email protected]9cddd4702009-07-27 22:09:40664}
665
[email protected]bca4b832014-07-17 20:22:34666void ExtensionService::ReloadExtension(const std::string& extension_id) {
667 ReloadExtensionImpl(extension_id, true); // be_noisy
668}
669
670void ExtensionService::ReloadExtensionWithQuietFailure(
671 const std::string& extension_id) {
672 ReloadExtensionImpl(extension_id, false); // be_noisy
673}
674
[email protected]757d60a2014-05-23 00:11:44675bool ExtensionService::UninstallExtension(
676 // "transient" because the process of uninstalling may cause the reference
677 // to become invalid. Instead, use |extenson->id()|.
678 const std::string& transient_extension_id,
[email protected]e43c61f2014-07-20 21:46:34679 extensions::UninstallReason reason,
[email protected]42d58f62014-07-31 01:32:45680 const base::Closure& deletion_done_callback,
[email protected]757d60a2014-05-23 00:11:44681 base::string16* error) {
[email protected]a29a517a2011-01-21 21:11:12682 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]a8af9fdb2010-10-28 21:52:20683
[email protected]757d60a2014-05-23 00:11:44684 scoped_refptr<const Extension> extension =
685 GetInstalledExtension(transient_extension_id);
[email protected]631cf822009-05-15 07:01:25686
[email protected]e7afe2452010-08-22 16:19:13687 // Callers should not send us nonexistent extensions.
[email protected]dc24976f2013-06-02 21:15:09688 CHECK(extension.get());
[email protected]9f1087e2009-06-15 17:29:32689
binjincccacef2014-10-13 19:00:20690 ManagementPolicy* by_policy = system_->management_policy();
[email protected]95da88c42011-03-31 10:07:33691 // Policy change which triggers an uninstall will always set
692 // |external_uninstall| to true so this is the only way to uninstall
693 // managed extensions.
[email protected]90878c52014-04-04 18:21:02694 // Shared modules being uninstalled will also set |external_uninstall| to true
695 // so that we can guarantee users don't uninstall a shared module.
696 // (crbug.com/273300)
697 // TODO(rdevlin.cronin): This is probably not right. We should do something
698 // else, like include an enum IS_INTERNAL_UNINSTALL or IS_USER_UNINSTALL so
699 // we don't do this.
[email protected]cc2f55c2014-07-08 02:19:04700 bool external_uninstall =
[email protected]e43c61f2014-07-20 21:46:34701 (reason == extensions::UNINSTALL_REASON_INTERNAL_MANAGEMENT) ||
dtseng9fb3d5b2015-02-23 17:24:17702 (reason == extensions::UNINSTALL_REASON_COMPONENT_REMOVED) ||
rdevlin.cronin5f6b69d2014-09-20 01:23:35703 (reason == extensions::UNINSTALL_REASON_REINSTALL) ||
[email protected]e43c61f2014-07-20 21:46:34704 (reason == extensions::UNINSTALL_REASON_ORPHANED_EXTERNAL_EXTENSION) ||
[email protected]6ef60012014-07-22 19:08:12705 (reason == extensions::UNINSTALL_REASON_ORPHANED_SHARED_MODULE) ||
706 (reason == extensions::UNINSTALL_REASON_SYNC &&
dtseng9fb3d5b2015-02-23 17:24:17707 extension->was_installed_by_custodian());
[email protected]65187152012-06-02 13:14:14708 if (!external_uninstall &&
binjincccacef2014-10-13 19:00:20709 (!by_policy->UserMayModifySettings(extension.get(), error) ||
710 by_policy->MustRemainInstalled(extension.get(), error))) {
[email protected]ad50def52011-10-19 23:17:07711 content::NotificationService::current()->Notify(
[email protected]adf5a102014-07-31 12:44:06712 extensions::NOTIFICATION_EXTENSION_UNINSTALL_NOT_ALLOWED,
[email protected]6c2381d2011-10-19 02:52:53713 content::Source<Profile>(profile_),
[email protected]dc24976f2013-06-02 21:15:09714 content::Details<const Extension>(extension.get()));
[email protected]d6ebc9792011-04-07 18:18:33715 return false;
716 }
[email protected]95da88c42011-03-31 10:07:33717
[email protected]65f173552012-06-28 22:43:58718 syncer::SyncChange sync_change;
rdevlin.cronin5f6b69d2014-09-20 01:23:35719 // Don't sync the uninstall if we're going to reinstall the extension
720 // momentarily.
721 if (extension_sync_service_ &&
722 reason != extensions::UNINSTALL_REASON_REINSTALL) {
[email protected]f8aefb132013-10-30 09:29:52723 sync_change = extension_sync_service_->PrepareToSyncUninstallExtension(
724 extension.get(), is_ready());
[email protected]3bdba0d2011-08-23 07:17:30725 }
726
[email protected]d820bc52014-03-13 05:35:23727 system_->install_verifier()->Remove(extension->id());
[email protected]ffd2f79e2013-11-14 00:11:46728
[email protected]9b217652010-10-08 22:04:23729 UMA_HISTOGRAM_ENUMERATION("Extensions.UninstallType",
[email protected]7fa19f82010-12-21 19:40:08730 extension->GetType(), 100);
[email protected]dc24976f2013-06-02 21:15:09731 RecordPermissionMessagesHistogram(extension.get(),
[email protected]4c86be582014-06-04 08:39:11732 "Extensions.Permissions_Uninstall2");
[email protected]9b217652010-10-08 22:04:23733
[email protected]831aa212010-03-26 13:55:19734 // Unload before doing more cleanup to ensure that nothing is hanging on to
735 // any of these resources.
[email protected]757d60a2014-05-23 00:11:44736 UnloadExtension(extension->id(), UnloadedExtensionInfo::REASON_UNINSTALL);
[email protected]831aa212010-03-26 13:55:19737
[email protected]9f1087e2009-06-15 17:29:32738 // Tell the backend to start deleting installed extensions on the file thread.
[email protected]12075d12013-02-27 05:38:05739 if (!Manifest::IsUnpackedLocation(extension->location())) {
[email protected]7f8f24f2012-11-15 19:40:14740 if (!GetFileTaskRunner()->PostTask(
741 FROM_HERE,
[email protected]5a145e82014-05-29 22:19:07742 base::Bind(&ExtensionService::UninstallExtensionOnFileThread,
743 extension->id(),
744 profile_,
[email protected]85df9d12014-04-15 17:02:14745 install_directory_,
[email protected]5a145e82014-05-29 22:19:07746 extension->path())))
[email protected]14908b72011-04-20 06:54:36747 NOTREACHED();
[email protected]9f1087e2009-06-15 17:29:32748 }
749
[email protected]42d58f62014-07-31 01:32:45750 extensions::DataDeleter::StartDeleting(
751 profile_, extension.get(), deletion_done_callback);
[email protected]0d6ec3a72011-09-02 02:09:43752
[email protected]757d60a2014-05-23 00:11:44753 UntrackTerminatedExtension(extension->id());
[email protected]211030342010-09-30 18:41:06754
755 // Notify interested parties that we've uninstalled this extension.
[email protected]ad50def52011-10-19 23:17:07756 content::NotificationService::current()->Notify(
[email protected]adf5a102014-07-31 12:44:06757 extensions::NOTIFICATION_EXTENSION_UNINSTALLED_DEPRECATED,
[email protected]6c2381d2011-10-19 02:52:53758 content::Source<Profile>(profile_),
[email protected]dc24976f2013-06-02 21:15:09759 content::Details<const Extension>(extension.get()));
[email protected]e43c61f2014-07-20 21:46:34760 ExtensionRegistry::Get(profile_)
761 ->TriggerOnUninstalled(extension.get(), reason);
[email protected]d6ebc9792011-04-07 18:18:33762
rdevlin.cronin5f6b69d2014-09-20 01:23:35763 if (sync_change.IsValid()) {
[email protected]757d60a2014-05-23 00:11:44764 extension_sync_service_->ProcessSyncUninstallExtension(extension->id(),
[email protected]f8aefb132013-10-30 09:29:52765 sync_change);
[email protected]3bdba0d2011-08-23 07:17:30766 }
767
[email protected]757d60a2014-05-23 00:11:44768 delayed_installs_.Remove(extension->id());
[email protected]0db124b02012-11-07 04:55:05769
[email protected]757d60a2014-05-23 00:11:44770 extension_prefs_->OnExtensionUninstalled(
771 extension->id(), extension->location(), external_uninstall);
[email protected]d4eda592013-09-18 03:37:57772
[email protected]333b1de2011-09-12 18:28:50773 // Track the uninstallation.
[email protected]49098f702011-10-13 03:47:18774 UMA_HISTOGRAM_ENUMERATION("Extensions.ExtensionUninstalled", 1, 2);
775
[email protected]d6ebc9792011-04-07 18:18:33776 return true;
[email protected]c10da4b02010-03-25 14:38:32777}
778
[email protected]5a145e82014-05-29 22:19:07779// static
780void ExtensionService::UninstallExtensionOnFileThread(
781 const std::string& id,
782 Profile* profile,
783 const base::FilePath& install_dir,
784 const base::FilePath& extension_path) {
785 extensions::ExtensionAssetsManager* assets_manager =
786 extensions::ExtensionAssetsManager::GetInstance();
787 assets_manager->UninstallExtension(id, profile, install_dir, extension_path);
788}
789
[email protected]c3cfb012011-04-06 22:07:35790bool ExtensionService::IsExtensionEnabled(
791 const std::string& extension_id) const {
[email protected]bb1bc9b32013-12-21 03:09:14792 if (registry_->enabled_extensions().Contains(extension_id) ||
793 registry_->terminated_extensions().Contains(extension_id)) {
[email protected]36429da2011-07-11 20:25:18794 return true;
[email protected]dc9a74f72012-08-17 18:07:21795 }
[email protected]36429da2011-07-11 20:25:18796
[email protected]bb1bc9b32013-12-21 03:09:14797 if (registry_->disabled_extensions().Contains(extension_id) ||
mlerman6a37b6a42014-11-26 22:10:53798 registry_->blacklisted_extensions().Contains(extension_id) ||
799 registry_->blocked_extensions().Contains(extension_id)) {
[email protected]ad83ca242011-07-29 01:32:25800 return false;
[email protected]695b5712012-12-06 23:55:28801 }
[email protected]ad83ca242011-07-29 01:32:25802
mlerman3690e5be2014-12-01 22:57:44803 // Blocked extensions aren't marked as such in prefs, thus if
804 // |block_extensions_| is true then CanBlockExtension() must be called with an
805 // Extension object. If the |extension_id| is not loaded, assume not enabled.
806 if (block_extensions_) {
807 const Extension* extension = GetInstalledExtension(extension_id);
808 if (!extension || CanBlockExtension(extension))
809 return false;
810 }
mlerman6a37b6a42014-11-26 22:10:53811
[email protected]ad83ca242011-07-29 01:32:25812 // If the extension hasn't been loaded yet, check the prefs for it. Assume
813 // enabled unless otherwise noted.
814 return !extension_prefs_->IsExtensionDisabled(extension_id) &&
[email protected]27e528322014-05-27 20:54:30815 !extension_prefs_->IsExtensionBlacklisted(extension_id) &&
[email protected]f574c402012-12-04 23:20:31816 !extension_prefs_->IsExternalExtensionUninstalled(extension_id);
[email protected]c3cfb012011-04-06 22:07:35817}
818
[email protected]eaa7dd182010-12-14 11:09:00819void ExtensionService::EnableExtension(const std::string& extension_id) {
[email protected]a29a517a2011-01-21 21:11:12820 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]a8af9fdb2010-10-28 21:52:20821
[email protected]06f92562011-04-29 19:27:31822 if (IsExtensionEnabled(extension_id))
[email protected]0c6da502009-08-14 22:32:39823 return;
[email protected]bb1bc9b32013-12-21 03:09:14824 const Extension* extension =
825 registry_->disabled_extensions().GetByID(extension_id);
[email protected]0d54b682013-11-05 14:15:36826
827 ManagementPolicy* policy = system_->management_policy();
828 if (extension && policy->MustRemainDisabled(extension, NULL, NULL)) {
829 UMA_HISTOGRAM_COUNTS_100("Extensions.EnableDeniedByPolicy", 1);
830 return;
831 }
[email protected]0c6da502009-08-14 22:32:39832
[email protected]b3317ad2011-04-28 23:46:00833 extension_prefs_->SetExtensionState(extension_id, Extension::ENABLED);
[email protected]eb5e4f92012-08-15 23:33:28834 extension_prefs_->ClearDisableReasons(extension_id);
[email protected]1784e83a2009-09-08 21:01:52835
[email protected]06f92562011-04-29 19:27:31836 // This can happen if sync enables an extension that is not
837 // installed yet.
838 if (!extension)
839 return;
840
[email protected]0c6da502009-08-14 22:32:39841 // Move it over to the enabled list.
[email protected]bb1bc9b32013-12-21 03:09:14842 registry_->AddEnabled(make_scoped_refptr(extension));
843 registry_->RemoveDisabled(extension->id());
[email protected]0c6da502009-08-14 22:32:39844
[email protected]62d30f42009-10-01 22:36:06845 NotifyExtensionLoaded(extension);
[email protected]3bdba0d2011-08-23 07:17:30846
[email protected]f74d7f32012-06-19 19:22:51847 // Notify listeners that the extension was enabled.
848 content::NotificationService::current()->Notify(
[email protected]adf5a102014-07-31 12:44:06849 extensions::NOTIFICATION_EXTENSION_ENABLED,
[email protected]f74d7f32012-06-19 19:22:51850 content::Source<Profile>(profile_),
851 content::Details<const Extension>(extension));
852
[email protected]f8aefb132013-10-30 09:29:52853 if (extension_sync_service_)
854 extension_sync_service_->SyncEnableExtension(*extension);
[email protected]0c6da502009-08-14 22:32:39855}
856
[email protected]44d62b62012-04-11 00:06:03857void ExtensionService::DisableExtension(
858 const std::string& extension_id,
859 Extension::DisableReason disable_reason) {
[email protected]a29a517a2011-01-21 21:11:12860 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]a8af9fdb2010-10-28 21:52:20861
[email protected]8f959f522014-08-06 06:26:28862 // The extension may have been disabled already. Just add a disable reason.
863 if (!IsExtensionEnabled(extension_id)) {
864 extension_prefs_->AddDisableReason(extension_id, disable_reason);
[email protected]1784e83a2009-09-08 21:01:52865 return;
[email protected]8f959f522014-08-06 06:26:28866 }
[email protected]1784e83a2009-09-08 21:01:52867
[email protected]06f92562011-04-29 19:27:31868 const Extension* extension = GetInstalledExtension(extension_id);
869 // |extension| can be NULL if sync disables an extension that is not
870 // installed yet.
[email protected]ab894542014-07-03 12:35:39871 // EXTERNAL_COMPONENT extensions are not generally modifiable by users, but
872 // can be uninstalled by the browser if the user sets extension-specific
873 // preferences.
[email protected]65187152012-06-02 13:14:14874 if (extension &&
[email protected]505ccdc2013-06-20 20:15:35875 disable_reason != Extension::DISABLE_RELOAD &&
binjin8e3d0182014-12-04 16:44:28876 disable_reason != Extension::DISABLE_UPDATE_REQUIRED_BY_POLICY &&
[email protected]ab894542014-07-03 12:35:39877 !system_->management_policy()->UserMayModifySettings(extension, NULL) &&
878 extension->location() != Manifest::EXTERNAL_COMPONENT) {
[email protected]95da88c42011-03-31 10:07:33879 return;
[email protected]65187152012-06-02 13:14:14880 }
[email protected]95da88c42011-03-31 10:07:33881
[email protected]b3317ad2011-04-28 23:46:00882 extension_prefs_->SetExtensionState(extension_id, Extension::DISABLED);
[email protected]eb5e4f92012-08-15 23:33:28883 extension_prefs_->AddDisableReason(extension_id, disable_reason);
[email protected]1784e83a2009-09-08 21:01:52884
[email protected]599539802014-01-07 23:06:00885 int include_mask =
886 ExtensionRegistry::EVERYTHING & ~ExtensionRegistry::DISABLED;
887 extension = registry_->GetExtensionById(extension_id, include_mask);
[email protected]06f92562011-04-29 19:27:31888 if (!extension)
889 return;
890
[email protected]45f5b7d2014-01-22 23:47:13891 // The extension is either enabled or terminated.
892 DCHECK(registry_->enabled_extensions().Contains(extension->id()) ||
893 registry_->terminated_extensions().Contains(extension->id()));
[email protected]64742de32013-04-22 08:44:34894
[email protected]5c094792012-09-07 19:44:53895 // Move it over to the disabled list. Don't send a second unload notification
896 // for terminated extensions being disabled.
[email protected]bb1bc9b32013-12-21 03:09:14897 registry_->AddDisabled(make_scoped_refptr(extension));
898 if (registry_->enabled_extensions().Contains(extension->id())) {
899 registry_->RemoveEnabled(extension->id());
[email protected]b0af4792013-10-23 09:12:13900 NotifyExtensionUnloaded(extension, UnloadedExtensionInfo::REASON_DISABLE);
[email protected]5c094792012-09-07 19:44:53901 } else {
[email protected]bb1bc9b32013-12-21 03:09:14902 registry_->RemoveTerminated(extension->id());
[email protected]5c094792012-09-07 19:44:53903 }
[email protected]3bdba0d2011-08-23 07:17:30904
[email protected]f8aefb132013-10-30 09:29:52905 if (extension_sync_service_)
906 extension_sync_service_->SyncDisableExtension(*extension);
[email protected]1784e83a2009-09-08 21:01:52907}
908
[email protected]1abf05e2013-07-09 17:04:36909void ExtensionService::DisableUserExtensions(
910 const std::vector<std::string>& except_ids) {
[email protected]e516e4c2013-06-12 17:41:14911 extensions::ManagementPolicy* management_policy =
912 system_->management_policy();
913 extensions::ExtensionList to_disable;
914
[email protected]bb1bc9b32013-12-21 03:09:14915 const ExtensionSet& enabled_set = registry_->enabled_extensions();
916 for (ExtensionSet::const_iterator extension = enabled_set.begin();
917 extension != enabled_set.end(); ++extension) {
[email protected]ab894542014-07-03 12:35:39918 if (management_policy->UserMayModifySettings(extension->get(), NULL))
[email protected]e516e4c2013-06-12 17:41:14919 to_disable.push_back(*extension);
920 }
[email protected]bb1bc9b32013-12-21 03:09:14921 const ExtensionSet& terminated_set = registry_->terminated_extensions();
922 for (ExtensionSet::const_iterator extension = terminated_set.begin();
923 extension != terminated_set.end(); ++extension) {
[email protected]ab894542014-07-03 12:35:39924 if (management_policy->UserMayModifySettings(extension->get(), NULL))
[email protected]e516e4c2013-06-12 17:41:14925 to_disable.push_back(*extension);
926 }
927
928 for (extensions::ExtensionList::const_iterator extension = to_disable.begin();
929 extension != to_disable.end(); ++extension) {
[email protected]3082fe32013-08-06 11:12:38930 if ((*extension)->was_installed_by_default() &&
931 extension_urls::IsWebstoreUpdateUrl(
dchengc7047942014-08-26 05:05:31932 extensions::ManifestURL::GetUpdateURL(extension->get())))
[email protected]3082fe32013-08-06 11:12:38933 continue;
[email protected]1abf05e2013-07-09 17:04:36934 const std::string& id = (*extension)->id();
935 if (except_ids.end() == std::find(except_ids.begin(), except_ids.end(), id))
936 DisableExtension(id, extensions::Extension::DISABLE_USER_ACTION);
[email protected]e516e4c2013-06-12 17:41:14937 }
938}
939
mlerman6a37b6a42014-11-26 22:10:53940// Extensions that are not locked, components or forced by policy should be
941// locked. Extensions are no longer considered enabled or disabled. Blacklisted
942// extensions are now considered both blacklisted and locked.
943void ExtensionService::BlockAllExtensions() {
944 if (block_extensions_)
945 return;
946 block_extensions_ = true;
947
948 // Blacklisted extensions are already unloaded, need not be blocked.
949 scoped_ptr<ExtensionSet> extensions =
950 registry_->GenerateInstalledExtensionsSet(ExtensionRegistry::ENABLED |
951 ExtensionRegistry::DISABLED |
952 ExtensionRegistry::TERMINATED);
953
954 for (const scoped_refptr<const Extension>& extension : *extensions) {
955 const std::string& id = extension->id();
956
957 if (!CanBlockExtension(extension.get()))
958 continue;
959
960 registry_->RemoveEnabled(id);
961 registry_->RemoveDisabled(id);
962 registry_->RemoveTerminated(id);
963
964 registry_->AddBlocked(extension.get());
965 UnloadExtension(id, extensions::UnloadedExtensionInfo::REASON_LOCK_ALL);
966 }
967}
968
969// All locked extensions should revert to being either enabled or disabled
970// as appropriate.
971void ExtensionService::UnblockAllExtensions() {
972 block_extensions_ = false;
973 scoped_ptr<ExtensionSet> to_unblock =
974 registry_->GenerateInstalledExtensionsSet(ExtensionRegistry::BLOCKED);
975
976 for (const scoped_refptr<const Extension>& extension : *to_unblock) {
977 registry_->RemoveBlocked(extension->id());
978 AddExtension(extension.get());
979 }
980}
981
[email protected]eaa7dd182010-12-14 11:09:00982void ExtensionService::GrantPermissionsAndEnableExtension(
[email protected]009633c2013-03-07 22:08:28983 const Extension* extension) {
984 GrantPermissions(extension);
[email protected]4c86be582014-06-04 08:39:11985 RecordPermissionMessagesHistogram(extension,
986 "Extensions.Permissions_ReEnable2");
[email protected]8d888c12010-11-30 00:00:25987 extension_prefs_->SetDidExtensionEscalatePermissions(extension, false);
988 EnableExtension(extension->id());
989}
990
[email protected]009633c2013-03-07 22:08:28991void ExtensionService::GrantPermissions(const Extension* extension) {
[email protected]be083862012-09-01 03:53:45992 CHECK(extension);
[email protected]8d42db52014-06-20 21:50:50993 extensions::PermissionsUpdater(profile()).GrantActivePermissions(extension);
[email protected]be083862012-09-01 03:53:45994}
995
[email protected]fe2dd7742011-04-19 22:52:49996// static
997void ExtensionService::RecordPermissionMessagesHistogram(
[email protected]13c68b62013-05-17 11:29:05998 const Extension* extension, const char* histogram) {
[email protected]de415552013-01-23 04:12:17999 // Since this is called from multiple sources, and since the histogram macros
1000 // use statics, we need to manually lookup the histogram ourselves.
1001 base::HistogramBase* counter = base::LinearHistogram::FactoryGet(
[email protected]fe2dd7742011-04-19 22:52:491002 histogram,
1003 1,
[email protected]c2e66e12012-06-27 06:27:061004 PermissionMessage::kEnumBoundary,
1005 PermissionMessage::kEnumBoundary + 1,
[email protected]de415552013-01-23 04:12:171006 base::HistogramBase::kUmaTargetedHistogramFlag);
[email protected]fe2dd7742011-04-19 22:52:491007
[email protected]a6910e72014-06-06 05:04:361008 PermissionMessages permissions =
1009 extension->permissions_data()->GetPermissionMessages();
[email protected]fe2dd7742011-04-19 22:52:491010 if (permissions.empty()) {
[email protected]c2e66e12012-06-27 06:27:061011 counter->Add(PermissionMessage::kNone);
[email protected]fe2dd7742011-04-19 22:52:491012 } else {
[email protected]c2e66e12012-06-27 06:27:061013 for (PermissionMessages::iterator it = permissions.begin();
[email protected]0d3e4a22011-06-23 19:02:521014 it != permissions.end(); ++it)
1015 counter->Add(it->id());
[email protected]fe2dd7742011-04-19 22:52:491016 }
1017}
1018
[email protected]eaa7dd182010-12-14 11:09:001019void ExtensionService::NotifyExtensionLoaded(const Extension* extension) {
[email protected]f9c8c7c72014-07-31 16:42:311020 // The URLRequestContexts need to be first to know that the extension
[email protected]62d30f42009-10-01 22:36:061021 // was loaded, otherwise a race can arise where a renderer that is created
1022 // for the extension may try to load an extension URL with an extension id
[email protected]57a777f72010-03-31 01:09:421023 // that the request context doesn't yet know about. The profile is responsible
1024 // for ensuring its URLRequestContexts appropriately discover the loaded
1025 // extension.
[email protected]31d8f5f22012-04-02 15:22:081026 system_->RegisterExtensionWithRequestContexts(extension);
[email protected]62d30f42009-10-01 22:36:061027
[email protected]d5949312012-12-03 22:13:301028 // Tell renderers about the new extension, unless it's a theme (renderers
1029 // don't need to know about themes).
[email protected]a58f599c2012-12-01 03:08:191030 if (!extension->is_theme()) {
[email protected]19647262011-12-16 09:57:491031 for (content::RenderProcessHost::iterator i(
1032 content::RenderProcessHost::AllHostsIterator());
1033 !i.IsAtEnd(); i.Advance()) {
1034 content::RenderProcessHost* host = i.GetCurrentValue();
1035 Profile* host_profile =
1036 Profile::FromBrowserContext(host->GetBrowserContext());
1037 if (host_profile->GetOriginalProfile() ==
1038 profile_->GetOriginalProfile()) {
rdevlin.croninc491dbf2015-02-07 00:31:551039 // We don't need to include tab permisisons here, since the extension
1040 // was just loaded.
[email protected]19647262011-12-16 09:57:491041 std::vector<ExtensionMsg_Loaded_Params> loaded_extensions(
rdevlin.croninc491dbf2015-02-07 00:31:551042 1, ExtensionMsg_Loaded_Params(extension,
1043 false /* no tab permissions */));
[email protected]19647262011-12-16 09:57:491044 host->Send(
1045 new ExtensionMsg_Loaded(loaded_extensions));
1046 }
[email protected]c8d407e2011-04-28 21:27:171047 }
[email protected]77a6970c2011-04-23 16:58:561048 }
1049
[email protected]3442a662012-01-12 08:06:171050 // Tell subsystems that use the EXTENSION_LOADED notification about the new
1051 // extension.
1052 //
1053 // NOTE: It is important that this happen after notifying the renderers about
1054 // the new extensions so that if we navigate to an extension URL in
[email protected]fdc76192014-04-20 21:54:411055 // ExtensionRegistryObserver::OnLoaded or
1056 // NOTIFICATION_EXTENSION_LOADED_DEPRECATED, the
[email protected]dcc47642014-03-26 22:03:491057 // renderer is guaranteed to know about it.
1058 registry_->TriggerOnLoaded(extension);
1059
[email protected]3442a662012-01-12 08:06:171060 content::NotificationService::current()->Notify(
[email protected]adf5a102014-07-31 12:44:061061 extensions::NOTIFICATION_EXTENSION_LOADED_DEPRECATED,
[email protected]3442a662012-01-12 08:06:171062 content::Source<Profile>(profile_),
1063 content::Details<const Extension>(extension));
1064
[email protected]dcc47642014-03-26 22:03:491065 // TODO(kalman): Convert ExtensionSpecialStoragePolicy to a
1066 // BrowserContextKeyedService and use ExtensionRegistryObserver.
[email protected]c8d407e2011-04-28 21:27:171067 profile_->GetExtensionSpecialStoragePolicy()->
rdevlin.croninbc8979a2014-09-30 01:08:501068 GrantRightsForExtension(extension, profile_);
[email protected]c8d407e2011-04-28 21:27:171069
[email protected]dcc47642014-03-26 22:03:491070 // TODO(kalman): This is broken. The crash reporter is process-wide so doesn't
1071 // work properly multi-profile. Besides which, it should be using
1072 // ExtensionRegistryObserver. See http://crbug.com/355029.
[email protected]c8d407e2011-04-28 21:27:171073 UpdateActiveExtensionsInCrashReporter();
1074
[email protected]d695bb12014-06-05 16:16:301075 const extensions::PermissionsData* permissions_data =
[email protected]a6910e72014-06-06 05:04:361076 extension->permissions_data();
[email protected]d695bb12014-06-05 16:16:301077
[email protected]c8d407e2011-04-28 21:27:171078 // If the extension has permission to load chrome://favicon/ resources we need
1079 // to make sure that the FaviconSource is registered with the
1080 // ChromeURLDataManager.
[email protected]d695bb12014-06-05 16:16:301081 if (permissions_data->HasHostPermission(GURL(chrome::kChromeUIFaviconURL))) {
[email protected]c8d407e2011-04-28 21:27:171082 FaviconSource* favicon_source = new FaviconSource(profile_,
1083 FaviconSource::FAVICON);
[email protected]24ea7a12013-01-27 23:54:531084 content::URLDataSource::Add(profile_, favicon_source);
[email protected]c8d407e2011-04-28 21:27:171085 }
[email protected]b07e606e2012-09-15 20:16:151086
[email protected]b07e606e2012-09-15 20:16:151087 // Same for chrome://theme/ resources.
[email protected]d695bb12014-06-05 16:16:301088 if (permissions_data->HasHostPermission(GURL(chrome::kChromeUIThemeURL))) {
[email protected]b07e606e2012-09-15 20:16:151089 ThemeSource* theme_source = new ThemeSource(profile_);
[email protected]24ea7a12013-01-27 23:54:531090 content::URLDataSource::Add(profile_, theme_source);
[email protected]b07e606e2012-09-15 20:16:151091 }
[email protected]b07e606e2012-09-15 20:16:151092
[email protected]5eddc3e2011-10-26 04:33:311093 // Same for chrome://thumb/ resources.
[email protected]d695bb12014-06-05 16:16:301094 if (permissions_data->HasHostPermission(
1095 GURL(chrome::kChromeUIThumbnailURL))) {
[email protected]420e6d92013-09-17 01:48:511096 ThumbnailSource* thumbnail_source = new ThumbnailSource(profile_, false);
[email protected]24ea7a12013-01-27 23:54:531097 content::URLDataSource::Add(profile_, thumbnail_source);
[email protected]5eddc3e2011-10-26 04:33:311098 }
[email protected]62d30f42009-10-01 22:36:061099}
1100
[email protected]a9f39a312010-12-23 22:14:271101void ExtensionService::NotifyExtensionUnloaded(
[email protected]814a7bf0f2011-08-13 05:30:591102 const Extension* extension,
[email protected]b0af4792013-10-23 09:12:131103 UnloadedExtensionInfo::Reason reason) {
[email protected]a9f39a312010-12-23 22:14:271104 UnloadedExtensionInfo details(extension, reason);
[email protected]e51232f32014-04-18 20:05:361105
1106 registry_->TriggerOnUnloaded(extension, reason);
1107
[email protected]ad50def52011-10-19 23:17:071108 content::NotificationService::current()->Notify(
[email protected]adf5a102014-07-31 12:44:061109 extensions::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED,
[email protected]6c2381d2011-10-19 02:52:531110 content::Source<Profile>(profile_),
1111 content::Details<UnloadedExtensionInfo>(&details));
[email protected]62d30f42009-10-01 22:36:061112
[email protected]f3b1a082011-11-18 00:34:301113 for (content::RenderProcessHost::iterator i(
1114 content::RenderProcessHost::AllHostsIterator());
[email protected]77a6970c2011-04-23 16:58:561115 !i.IsAtEnd(); i.Advance()) {
[email protected]f3b1a082011-11-18 00:34:301116 content::RenderProcessHost* host = i.GetCurrentValue();
[email protected]9b62ecf2011-07-27 20:23:081117 Profile* host_profile =
[email protected]f3b1a082011-11-18 00:34:301118 Profile::FromBrowserContext(host->GetBrowserContext());
[email protected]9b62ecf2011-07-27 20:23:081119 if (host_profile->GetOriginalProfile() == profile_->GetOriginalProfile())
[email protected]c8d407e2011-04-28 21:27:171120 host->Send(new ExtensionMsg_Unloaded(extension->id()));
[email protected]77a6970c2011-04-23 16:58:561121 }
1122
[email protected]31d8f5f22012-04-02 15:22:081123 system_->UnregisterExtensionWithRequestContexts(extension->id(), reason);
[email protected]dcc47642014-03-26 22:03:491124
1125 // TODO(kalman): Convert ExtensionSpecialStoragePolicy to a
1126 // BrowserContextKeyedService and use ExtensionRegistryObserver.
[email protected]c8d407e2011-04-28 21:27:171127 profile_->GetExtensionSpecialStoragePolicy()->
1128 RevokeRightsForExtension(extension);
1129
[email protected]b777b332011-04-16 04:01:081130#if defined(OS_CHROMEOS)
[email protected]ac66e452013-01-11 09:21:231131 // Revoke external file access for the extension from its file system context.
1132 // It is safe to access the extension's storage partition at this point. The
1133 // storage partition may get destroyed only after the extension gets unloaded.
[email protected]3a746ec2014-03-15 05:30:561134 GURL site =
1135 extensions::util::GetSiteForExtensionId(extension->id(), profile_);
[email protected]cd501a72014-08-22 19:58:311136 storage::FileSystemContext* filesystem_context =
1137 BrowserContext::GetStoragePartitionForSite(profile_, site)
1138 ->GetFileSystemContext();
[email protected]f19bbf62013-07-09 01:22:321139 if (filesystem_context && filesystem_context->external_backend()) {
1140 filesystem_context->external_backend()->
[email protected]c8d407e2011-04-28 21:27:171141 RevokeAccessForExtension(extension->id());
[email protected]62d30f42009-10-01 22:36:061142 }
[email protected]c8d407e2011-04-28 21:27:171143#endif
1144
[email protected]dcc47642014-03-26 22:03:491145 // TODO(kalman): This is broken. The crash reporter is process-wide so doesn't
1146 // work properly multi-profile. Besides which, it should be using
1147 // ExtensionRegistryObserver::OnExtensionLoaded. See http://crbug.com/355029.
[email protected]c8d407e2011-04-28 21:27:171148 UpdateActiveExtensionsInCrashReporter();
[email protected]62d30f42009-10-01 22:36:061149}
1150
[email protected]599539802014-01-07 23:06:001151content::BrowserContext* ExtensionService::GetBrowserContext() const {
1152 // Implemented in the .cc file to avoid adding a profile.h dependency to
1153 // extension_service.h.
1154 return profile_;
1155}
1156
[email protected]25ae0152011-11-18 14:40:021157bool ExtensionService::is_ready() {
[email protected]4a10006a2013-05-17 23:18:351158 return ready_->is_signaled();
[email protected]25ae0152011-11-18 14:40:021159}
1160
[email protected]7f8f24f2012-11-15 19:40:141161base::SequencedTaskRunner* ExtensionService::GetFileTaskRunner() {
[email protected]dc24976f2013-06-02 21:15:091162 if (file_task_runner_.get())
1163 return file_task_runner_.get();
[email protected]7f8f24f2012-11-15 19:40:141164
1165 // We should be able to interrupt any part of extension install process during
1166 // shutdown. SKIP_ON_SHUTDOWN ensures that not started extension install tasks
1167 // will be ignored/deleted while we will block on started tasks.
1168 std::string token("ext_install-");
1169 token.append(profile_->GetPath().AsUTF8Unsafe());
1170 file_task_runner_ = BrowserThread::GetBlockingPool()->
1171 GetSequencedTaskRunnerWithShutdownBehavior(
1172 BrowserThread::GetBlockingPool()->GetNamedSequenceToken(token),
1173 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN);
[email protected]dc24976f2013-06-02 21:15:091174 return file_task_runner_.get();
[email protected]7f8f24f2012-11-15 19:40:141175}
1176
[email protected]4ee07c62012-08-21 12:40:421177void ExtensionService::CheckManagementPolicy() {
[email protected]0d54b682013-11-05 14:15:361178 std::vector<std::string> to_unload;
1179 std::map<std::string, Extension::DisableReason> to_disable;
binjin8e3d0182014-12-04 16:44:281180 std::vector<std::string> to_enable;
[email protected]695b5712012-12-06 23:55:281181
[email protected]0d54b682013-11-05 14:15:361182 // Loop through the extensions list, finding extensions we need to unload or
1183 // disable.
binjin8e3d0182014-12-04 16:44:281184 for (scoped_refptr<const Extension> extension :
1185 registry_->enabled_extensions()) {
1186 if (!system_->management_policy()->UserMayLoad(extension.get(), nullptr))
[email protected]0d54b682013-11-05 14:15:361187 to_unload.push_back(extension->id());
1188 Extension::DisableReason disable_reason = Extension::DISABLE_NONE;
1189 if (system_->management_policy()->MustRemainDisabled(
binjin8e3d0182014-12-04 16:44:281190 extension.get(), &disable_reason, nullptr))
[email protected]0d54b682013-11-05 14:15:361191 to_disable[extension->id()] = disable_reason;
[email protected]aa96d3a2010-08-21 08:45:251192 }
1193
binjin8e3d0182014-12-04 16:44:281194 extensions::ExtensionManagement* management =
1195 extensions::ExtensionManagementFactory::GetForBrowserContext(profile());
1196
1197 // Loop through the disabled extension list, find extensions to re-enable
1198 // automatically. These extensions are exclusive from the |to_disable| and
1199 // |to_unload| lists constructed above, since disabled_extensions() and
1200 // enabled_extensions() are supposed to be mutually exclusive.
1201 for (scoped_refptr<const Extension> extension :
1202 registry_->disabled_extensions()) {
1203 // Find all disabled extensions disabled due to minimum version requirement,
1204 // but now satisfying it.
1205 if (management->CheckMinimumVersion(extension.get(), nullptr) &&
1206 extension_prefs_->HasDisableReason(
1207 extension->id(), Extension::DISABLE_UPDATE_REQUIRED_BY_POLICY)) {
1208 // Is DISABLE_UPDATE_REQUIRED_BY_POLICY the *only* reason?
1209 if (extension_prefs_->GetDisableReasons(extension->id()) ==
1210 Extension::DISABLE_UPDATE_REQUIRED_BY_POLICY) {
1211 // We need to enable those disabled *only* due to minimum version
1212 // requirement.
1213 to_enable.push_back(extension->id());
1214 }
1215 extension_prefs_->RemoveDisableReason(
1216 extension->id(), Extension::DISABLE_UPDATE_REQUIRED_BY_POLICY);
1217 }
1218 }
1219
1220 for (const std::string& id : to_unload)
1221 UnloadExtension(id, UnloadedExtensionInfo::REASON_DISABLE);
[email protected]0d54b682013-11-05 14:15:361222
1223 for (std::map<std::string, Extension::DisableReason>::const_iterator i =
1224 to_disable.begin(); i != to_disable.end(); ++i)
1225 DisableExtension(i->first, i->second);
binjin8e3d0182014-12-04 16:44:281226
1227 // No extension is getting re-enabled here after disabling/unloading
1228 // because to_enable is mutually exclusive to to_disable + to_unload.
1229 for (const std::string& id : to_enable)
1230 EnableExtension(id);
1231
1232 if (updater_.get()) {
1233 // Find all extensions disabled due to minimum version requirement from
1234 // policy (including the ones that got disabled just now), and check
1235 // for update.
1236 extensions::ExtensionUpdater::CheckParams to_recheck;
1237 for (scoped_refptr<const Extension> extension :
1238 registry_->disabled_extensions()) {
1239 if (extension_prefs_->GetDisableReasons(extension->id()) ==
1240 Extension::DISABLE_UPDATE_REQUIRED_BY_POLICY) {
1241 // The minimum version check is the only thing holding this extension
1242 // back, so check if it can be updated to fix that.
1243 to_recheck.ids.push_back(extension->id());
1244 }
1245 }
1246 if (!to_recheck.ids.empty())
1247 updater_->CheckNow(to_recheck);
1248 }
[email protected]aa96d3a2010-08-21 08:45:251249}
1250
[email protected]31206602011-04-13 23:07:321251void ExtensionService::CheckForUpdatesSoon() {
[email protected]90878c52014-04-04 18:21:021252 // This can legitimately happen in unit tests.
1253 if (!updater_.get())
1254 return;
1255
1256 if (AreAllExternalProvidersReady()) {
1257 updater_->CheckSoon();
[email protected]c3cfb012011-04-06 22:07:351258 } else {
[email protected]90878c52014-04-04 18:21:021259 // Sync can start updating before all the external providers are ready
1260 // during startup. Start the update as soon as those providers are ready,
1261 // but not before.
1262 update_once_all_providers_are_ready_ = true;
[email protected]c3cfb012011-04-06 22:07:351263 }
1264}
1265
[email protected]8e4560b62011-01-14 10:09:141266// Some extensions will autoupdate themselves externally from Chrome. These
rkaplowa8fd8d32015-02-25 21:27:561267// are typically part of some larger client application package. To support
1268// these, the extension will register its location in the preferences file
[email protected]8e4560b62011-01-14 10:09:141269// (and also, on Windows, in the registry) and this code will periodically
1270// check that location for a .crx file, which it will then install locally if
1271// a new version is available.
rkaplowa8fd8d32015-02-25 21:27:561272// Errors are reported through ExtensionErrorReporter. Success is not
[email protected]8e4560b62011-01-14 10:09:141273// reported.
[email protected]eaa7dd182010-12-14 11:09:001274void ExtensionService::CheckForExternalUpdates() {
[email protected]a29a517a2011-01-21 21:11:121275 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
rkaplowa8fd8d32015-02-25 21:27:561276 TRACE_EVENT0("browser,startup", "ExtensionService::CheckForExternalUpdates");
1277 SCOPED_UMA_HISTOGRAM_TIMER("Extensions.CheckForExternalUpdatesTime");
[email protected]8e4560b62011-01-14 10:09:141278
1279 // Note that this installation is intentionally silent (since it didn't
1280 // go through the front-end). Extensions that are registered in this
1281 // way are effectively considered 'pre-bundled', and so implicitly
1282 // trusted. In general, if something has HKLM or filesystem access,
1283 // they could install an extension manually themselves anyway.
[email protected]a29a517a2011-01-21 21:11:121284
[email protected]8e4560b62011-01-14 10:09:141285 // Ask each external extension provider to give us a call back for each
1286 // extension they know about. See OnExternalExtension(File|UpdateUrl)Found.
[email protected]5df038b2012-07-16 19:03:271287 extensions::ProviderCollection::const_iterator i;
[email protected]8e4560b62011-01-14 10:09:141288 for (i = external_extension_providers_.begin();
1289 i != external_extension_providers_.end(); ++i) {
[email protected]5df038b2012-07-16 19:03:271290 extensions::ExternalProviderInterface* provider = i->get();
[email protected]8e4560b62011-01-14 10:09:141291 provider->VisitRegisteredExtension();
1292 }
1293
[email protected]50067e52011-10-20 23:17:071294 // Do any required work that we would have done after completion of all
1295 // providers.
[email protected]373daf972014-04-10 01:50:441296 if (external_extension_providers_.empty())
[email protected]50067e52011-10-20 23:17:071297 OnAllExternalProvidersReady();
[email protected]9f1087e2009-06-15 17:29:321298}
1299
[email protected]50067e52011-10-20 23:17:071300void ExtensionService::OnExternalProviderReady(
[email protected]5df038b2012-07-16 19:03:271301 const extensions::ExternalProviderInterface* provider) {
[email protected]a29a517a2011-01-21 21:11:121302 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]50067e52011-10-20 23:17:071303 CHECK(provider->IsReady());
[email protected]a29a517a2011-01-21 21:11:121304
1305 // An external provider has finished loading. We only take action
[email protected]8e4560b62011-01-14 10:09:141306 // if all of them are finished. So we check them first.
[email protected]94fde232012-04-27 10:22:301307 if (AreAllExternalProvidersReady())
1308 OnAllExternalProvidersReady();
1309}
1310
1311bool ExtensionService::AreAllExternalProvidersReady() const {
[email protected]5df038b2012-07-16 19:03:271312 extensions::ProviderCollection::const_iterator i;
[email protected]8e4560b62011-01-14 10:09:141313 for (i = external_extension_providers_.begin();
1314 i != external_extension_providers_.end(); ++i) {
[email protected]94fde232012-04-27 10:22:301315 if (!i->get()->IsReady())
1316 return false;
[email protected]8e4560b62011-01-14 10:09:141317 }
[email protected]94fde232012-04-27 10:22:301318 return true;
[email protected]50067e52011-10-20 23:17:071319}
1320
1321void ExtensionService::OnAllExternalProvidersReady() {
1322 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]94fde232012-04-27 10:22:301323 base::TimeDelta elapsed = base::Time::Now() - profile_->GetStartTime();
1324 UMA_HISTOGRAM_TIMES("Extension.ExternalProvidersReadyAfter", elapsed);
[email protected]50067e52011-10-20 23:17:071325
1326 // Install any pending extensions.
[email protected]94fde232012-04-27 10:22:301327 if (update_once_all_providers_are_ready_ && updater()) {
1328 update_once_all_providers_are_ready_ = false;
[email protected]4e9b59d2013-12-18 06:47:141329 extensions::ExtensionUpdater::CheckParams params;
1330 params.callback = external_updates_finished_callback_;
1331 updater()->CheckNow(params);
[email protected]8e4560b62011-01-14 10:09:141332 }
1333
1334 // Uninstall all the unclaimed extensions.
[email protected]45759612012-07-10 17:21:231335 scoped_ptr<extensions::ExtensionPrefs::ExtensionsInfo> extensions_info(
[email protected]8e4560b62011-01-14 10:09:141336 extension_prefs_->GetInstalledExtensionsInfo());
1337 for (size_t i = 0; i < extensions_info->size(); ++i) {
1338 ExtensionInfo* info = extensions_info->at(i).get();
[email protected]1d5e58b2013-01-31 08:41:401339 if (Manifest::IsExternalLocation(info->extension_location))
[email protected]8e4560b62011-01-14 10:09:141340 CheckExternalUninstall(info->extension_id);
1341 }
[email protected]e5af875f2011-10-10 21:09:141342
[email protected]373daf972014-04-10 01:50:441343 error_controller_->ShowErrorIfNeeded();
[email protected]a9aa5932012-01-25 08:27:401344
[email protected]374ceb6f2014-07-02 19:25:341345 external_install_manager_->UpdateExternalExtensionAlert();
[email protected]e5af875f2011-10-10 21:09:141346}
1347
[email protected]a9f39a312010-12-23 22:14:271348void ExtensionService::UnloadExtension(
1349 const std::string& extension_id,
[email protected]b0af4792013-10-23 09:12:131350 UnloadedExtensionInfo::Reason reason) {
[email protected]27e469a2010-01-11 20:35:091351 // Make sure the extension gets deleted after we return from this function.
[email protected]599539802014-01-07 23:06:001352 int include_mask =
1353 ExtensionRegistry::EVERYTHING & ~ExtensionRegistry::TERMINATED;
[email protected]9adb9692010-10-29 23:14:021354 scoped_refptr<const Extension> extension(
[email protected]599539802014-01-07 23:06:001355 registry_->GetExtensionById(extension_id, include_mask));
[email protected]631cf822009-05-15 07:01:251356
[email protected]fa0c96732010-11-17 00:14:231357 // This method can be called via PostTask, so the extension may have been
1358 // unloaded by the time this runs.
[email protected]dc24976f2013-06-02 21:15:091359 if (!extension.get()) {
[email protected]dd163fb02011-05-04 22:22:171360 // In case the extension may have crashed/uninstalled. Allow the profile to
1361 // clean up its RequestContexts.
[email protected]31d8f5f22012-04-02 15:22:081362 system_->UnregisterExtensionWithRequestContexts(extension_id, reason);
[email protected]fa0c96732010-11-17 00:14:231363 return;
[email protected]dd163fb02011-05-04 22:22:171364 }
[email protected]0c6da502009-08-14 22:32:391365
[email protected]1eb175082010-02-10 09:26:161366 // Keep information about the extension so that we can reload it later
1367 // even if it's not permanently installed.
1368 unloaded_extension_paths_[extension->id()] = extension->path();
1369
[email protected]f17dbd42010-08-16 23:21:101370 // Clean up if the extension is meant to be enabled after a reload.
[email protected]b914e2952013-04-26 07:10:031371 reloading_extensions_.erase(extension->id());
[email protected]f17dbd42010-08-16 23:21:101372
[email protected]bb1bc9b32013-12-21 03:09:141373 if (registry_->disabled_extensions().Contains(extension->id())) {
1374 registry_->RemoveDisabled(extension->id());
[email protected]dd163fb02011-05-04 22:22:171375 // Make sure the profile cleans up its RequestContexts when an already
1376 // disabled extension is unloaded (since they are also tracking the disabled
1377 // extensions).
[email protected]31d8f5f22012-04-02 15:22:081378 system_->UnregisterExtensionWithRequestContexts(extension_id, reason);
[email protected]45f5b7d2014-01-22 23:47:131379 // Don't send the unloaded notification. It was sent when the extension
1380 // was disabled.
[email protected]60a174a2013-08-02 20:29:281381 } else {
[email protected]bb1bc9b32013-12-21 03:09:141382 // Remove the extension from the enabled list.
1383 registry_->RemoveEnabled(extension->id());
[email protected]60a174a2013-08-02 20:29:281384 NotifyExtensionUnloaded(extension.get(), reason);
[email protected]0c6da502009-08-14 22:32:391385 }
1386
[email protected]fb789532013-08-27 02:40:211387 content::NotificationService::current()->Notify(
[email protected]adf5a102014-07-31 12:44:061388 extensions::NOTIFICATION_EXTENSION_REMOVED,
[email protected]fb789532013-08-27 02:40:211389 content::Source<Profile>(profile_),
1390 content::Details<const Extension>(extension.get()));
[email protected]631cf822009-05-15 07:01:251391}
1392
[email protected]8b1ec202013-09-05 02:09:501393void ExtensionService::RemoveComponentExtension(
1394 const std::string& extension_id) {
1395 scoped_refptr<const Extension> extension(
1396 GetExtensionById(extension_id, false));
[email protected]b0af4792013-10-23 09:12:131397 UnloadExtension(extension_id, UnloadedExtensionInfo::REASON_UNINSTALL);
[email protected]ebe07772014-05-22 04:16:061398 if (extension.get()) {
1399 content::NotificationService::current()->Notify(
[email protected]adf5a102014-07-31 12:44:061400 extensions::NOTIFICATION_EXTENSION_UNINSTALLED_DEPRECATED,
[email protected]ebe07772014-05-22 04:16:061401 content::Source<Profile>(profile_),
1402 content::Details<const Extension>(extension.get()));
[email protected]e43c61f2014-07-20 21:46:341403 ExtensionRegistry::Get(profile_)->TriggerOnUninstalled(
dtseng9fb3d5b2015-02-23 17:24:171404 extension.get(), extensions::UNINSTALL_REASON_COMPONENT_REMOVED);
[email protected]ebe07772014-05-22 04:16:061405 }
[email protected]8b1ec202013-09-05 02:09:501406}
1407
[email protected]bb1bc9b32013-12-21 03:09:141408void ExtensionService::UnloadAllExtensionsForTest() {
1409 UnloadAllExtensionsInternal();
[email protected]9f1087e2009-06-15 17:29:321410}
1411
[email protected]bb1bc9b32013-12-21 03:09:141412void ExtensionService::ReloadExtensionsForTest() {
1413 // Calling UnloadAllExtensionsForTest here triggers a false-positive presubmit
1414 // warning about calling test code in production.
1415 UnloadAllExtensionsInternal();
[email protected]eac88332012-12-26 17:57:451416 component_loader_->LoadAll();
[email protected]d8c8f25f2011-11-02 18:18:011417 extensions::InstalledLoader(this).LoadAllExtensions();
[email protected]4a10006a2013-05-17 23:18:351418 // Don't call SetReadyAndNotifyListeners() since tests call this multiple
1419 // times.
[email protected]9f1087e2009-06-15 17:29:321420}
1421
[email protected]820d9bd2013-04-03 03:46:031422void ExtensionService::SetReadyAndNotifyListeners() {
rkaplowa8fd8d32015-02-25 21:27:561423 TRACE_EVENT0("browser,startup",
1424 "ExtensionService::SetReadyAndNotifyListeners");
1425 SCOPED_UMA_HISTOGRAM_TIMER(
1426 "Extensions.ExtensionServiceNotifyReadyListenersTime");
1427
[email protected]4a10006a2013-05-17 23:18:351428 ready_->Signal();
[email protected]820d9bd2013-04-03 03:46:031429 content::NotificationService::current()->Notify(
[email protected]adf5a102014-07-31 12:44:061430 extensions::NOTIFICATION_EXTENSIONS_READY_DEPRECATED,
[email protected]820d9bd2013-04-03 03:46:031431 content::Source<Profile>(profile_),
1432 content::NotificationService::NoDetails());
[email protected]820d9bd2013-04-03 03:46:031433}
1434
[email protected]eaa7dd182010-12-14 11:09:001435void ExtensionService::OnLoadedInstalledExtensions() {
[email protected]3eeddd892013-04-17 17:00:111436 if (updater_)
[email protected]93fd78f42009-07-10 16:43:171437 updater_->Start();
[email protected]fa6a9102010-11-22 15:38:501438
[email protected]bc151cf92013-02-12 04:57:261439 OnBlacklistUpdated();
[email protected]e72e8eb82009-06-18 17:21:511440}
1441
[email protected]fcb58a862012-05-01 01:03:151442void ExtensionService::AddExtension(const Extension* extension) {
[email protected]c8d407e2011-04-28 21:27:171443 // TODO(jstritar): We may be able to get rid of this branch by overriding the
1444 // default extension state to DISABLED when the --disable-extensions flag
1445 // is set (http://crbug.com/29067).
1446 if (!extensions_enabled() &&
1447 !extension->is_theme() &&
[email protected]1d5e58b2013-01-31 08:41:401448 extension->location() != Manifest::COMPONENT &&
1449 !Manifest::IsExternalLocation(extension->location())) {
[email protected]fcb58a862012-05-01 01:03:151450 return;
[email protected]330840c2012-08-29 22:21:011451 }
[email protected]c8d407e2011-04-28 21:27:171452
[email protected]b914e2952013-04-26 07:10:031453 bool is_extension_upgrade = false;
[email protected]116d40e2013-08-08 17:23:171454 bool is_extension_installed = false;
1455 const Extension* old = GetInstalledExtension(extension->id());
1456 if (old) {
1457 is_extension_installed = true;
1458 int version_compare_result =
1459 extension->version()->CompareTo(*(old->version()));
1460 is_extension_upgrade = version_compare_result > 0;
[email protected]b914e2952013-04-26 07:10:031461 // Other than for unpacked extensions, CrxInstaller should have guaranteed
1462 // that we aren't downgrading.
1463 if (!Manifest::IsUnpackedLocation(extension->location()))
[email protected]116d40e2013-08-08 17:23:171464 CHECK_GE(version_compare_result, 0);
[email protected]b914e2952013-04-26 07:10:031465 }
rdevlin.cronin2c16c602014-11-21 01:35:491466 // If the extension was disabled for a reload, then enable it.
1467 bool reloading = reloading_extensions_.erase(extension->id()) > 0;
1468
1469 // Set the upgraded bit; we consider reloads upgrades.
1470 system_->runtime_data()->SetBeingUpgraded(extension->id(),
1471 is_extension_upgrade || reloading);
[email protected]c8d407e2011-04-28 21:27:171472
[email protected]1eb175082010-02-10 09:26:161473 // The extension is now loaded, remove its data from unloaded extension map.
1474 unloaded_extension_paths_.erase(extension->id());
1475
[email protected]bb7f40952011-01-13 00:21:201476 // If a terminated extension is loaded, remove it from the terminated list.
1477 UntrackTerminatedExtension(extension->id());
1478
[email protected]b914e2952013-04-26 07:10:031479 // Check if the extension's privileges have changed and mark the
1480 // extension disabled if necessary.
[email protected]116d40e2013-08-08 17:23:171481 CheckPermissionsIncrease(extension, is_extension_installed);
[email protected]b914e2952013-04-26 07:10:031482
[email protected]116d40e2013-08-08 17:23:171483 if (is_extension_installed && !reloading) {
[email protected]ca2e82022013-04-29 16:48:411484 // To upgrade an extension in place, unload the old one and then load the
1485 // new one. ReloadExtension disables the extension, which is sufficient.
[email protected]b0af4792013-10-23 09:12:131486 UnloadExtension(extension->id(), UnloadedExtensionInfo::REASON_UPDATE);
[email protected]b914e2952013-04-26 07:10:031487 }
[email protected]0c6da502009-08-14 22:32:391488
[email protected]695b5712012-12-06 23:55:281489 if (extension_prefs_->IsExtensionBlacklisted(extension->id())) {
[email protected]ac875372013-02-28 04:36:091490 // Only prefs is checked for the blacklist. We rely on callers to check the
1491 // blacklist before calling into here, e.g. CrxInstaller checks before
[email protected]9f3c8532013-07-31 19:52:071492 // installation then threads through the install and pending install flow
1493 // of this class, and we check when loading installed extensions.
[email protected]bb1bc9b32013-12-21 03:09:141494 registry_->AddBlacklisted(extension);
mlerman6a37b6a42014-11-26 22:10:531495 } else if (block_extensions_ && CanBlockExtension(extension)) {
1496 registry_->AddBlocked(extension);
[email protected]ca2e82022013-04-29 16:48:411497 } else if (!reloading &&
1498 extension_prefs_->IsExtensionDisabled(extension->id())) {
[email protected]bb1bc9b32013-12-21 03:09:141499 registry_->AddDisabled(extension);
[email protected]f8aefb132013-10-30 09:29:521500 if (extension_sync_service_)
1501 extension_sync_service_->SyncExtensionChangeIfNeeded(*extension);
[email protected]44d62b62012-04-11 00:06:031502 content::NotificationService::current()->Notify(
[email protected]adf5a102014-07-31 12:44:061503 extensions::NOTIFICATION_EXTENSION_UPDATE_DISABLED,
[email protected]44d62b62012-04-11 00:06:031504 content::Source<Profile>(profile_),
1505 content::Details<const Extension>(extension));
[email protected]62f051c2012-03-29 17:04:441506
[email protected]21db9ef2014-05-16 02:06:271507 // Show the extension disabled error if a permissions increase or a remote
1508 // installation is the reason it was disabled, and no other reasons exist.
1509 int reasons = extension_prefs_->GetDisableReasons(extension->id());
1510 const int kReasonMask = Extension::DISABLE_PERMISSIONS_INCREASE |
1511 Extension::DISABLE_REMOTE_INSTALL;
1512 if (reasons & kReasonMask && !(reasons & ~kReasonMask)) {
1513 extensions::AddExtensionDisabledError(
1514 this,
1515 extension,
1516 extension_prefs_->HasDisableReason(
1517 extension->id(), Extension::DISABLE_REMOTE_INSTALL));
[email protected]62f051c2012-03-29 17:04:441518 }
[email protected]ca2e82022013-04-29 16:48:411519 } else if (reloading) {
1520 // Replace the old extension with the new version.
[email protected]bb1bc9b32013-12-21 03:09:141521 CHECK(!registry_->AddDisabled(extension));
[email protected]ca2e82022013-04-29 16:48:411522 EnableExtension(extension->id());
[email protected]695b5712012-12-06 23:55:281523 } else {
1524 // All apps that are displayed in the launcher are ordered by their ordinals
1525 // so we must ensure they have valid ordinals.
1526 if (extension->RequiresSortOrdinal()) {
[email protected]db378322014-07-21 23:19:341527 extension_prefs_->app_sorting()->SetExtensionVisible(
1528 extension->id(),
1529 extension->ShouldDisplayInNewTabPage() &&
1530 !extension_prefs_->IsEphemeralApp(extension->id()));
1531 if (!extension_prefs_->IsEphemeralApp(extension->id())) {
1532 extension_prefs_->app_sorting()->EnsureValidOrdinals(
1533 extension->id(), syncer::StringOrdinal());
[email protected]bd36b652013-02-27 02:13:251534 }
[email protected]695b5712012-12-06 23:55:281535 }
1536
[email protected]bb1bc9b32013-12-21 03:09:141537 registry_->AddEnabled(extension);
[email protected]f8aefb132013-10-30 09:29:521538 if (extension_sync_service_)
1539 extension_sync_service_->SyncExtensionChangeIfNeeded(*extension);
[email protected]695b5712012-12-06 23:55:281540 NotifyExtensionLoaded(extension);
[email protected]f574c402012-12-04 23:20:311541 }
rdevlin.cronin2c16c602014-11-21 01:35:491542 system_->runtime_data()->SetBeingUpgraded(extension->id(), false);
[email protected]aab98a52009-12-02 03:22:351543}
1544
[email protected]8c484b742012-11-29 06:05:361545void ExtensionService::AddComponentExtension(const Extension* extension) {
1546 const std::string old_version_string(
1547 extension_prefs_->GetVersionString(extension->id()));
[email protected]c5e4a2222014-01-03 16:06:131548 const Version old_version(old_version_string);
[email protected]8c484b742012-11-29 06:05:361549
[email protected]0181a7d2013-11-12 01:08:421550 VLOG(1) << "AddComponentExtension " << extension->name();
[email protected]8c484b742012-11-29 06:05:361551 if (!old_version.IsValid() || !old_version.Equals(*extension->version())) {
1552 VLOG(1) << "Component extension " << extension->name() << " ("
1553 << extension->id() << ") installing/upgrading from '"
1554 << old_version_string << "' to " << extension->version()->GetString();
1555
1556 AddNewOrUpdatedExtension(extension,
[email protected]9ae73962014-08-14 16:53:411557 Extension::ENABLED,
[email protected]4a1d9c0d2014-06-13 12:50:111558 extensions::kInstallFlagNone,
[email protected]d8fd0fd2014-03-24 13:16:061559 syncer::StringOrdinal(),
1560 std::string());
[email protected]8c484b742012-11-29 06:05:361561 return;
1562 }
1563
1564 AddExtension(extension);
1565}
1566
[email protected]b914e2952013-04-26 07:10:031567void ExtensionService::CheckPermissionsIncrease(const Extension* extension,
[email protected]116d40e2013-08-08 17:23:171568 bool is_extension_installed) {
[email protected]23a85362014-07-07 23:26:191569 extensions::PermissionsUpdater(profile_).InitializePermissions(extension);
[email protected]902fd7b2011-07-27 18:42:311570
[email protected]8d888c12010-11-30 00:00:251571 // We keep track of all permissions the user has granted each extension.
1572 // This allows extensions to gracefully support backwards compatibility
1573 // by including unknown permissions in their manifests. When the user
1574 // installs the extension, only the recognized permissions are recorded.
1575 // When the unknown permissions become recognized (e.g., through browser
1576 // upgrade), we can prompt the user to accept these new permissions.
1577 // Extensions can also silently upgrade to less permissions, and then
1578 // silently upgrade to a version that adds these permissions back.
1579 //
1580 // For example, pretend that Chrome 10 includes a permission "omnibox"
1581 // for an API that adds suggestions to the omnibox. An extension can
1582 // maintain backwards compatibility while still having "omnibox" in the
1583 // manifest. If a user installs the extension on Chrome 9, the browser
1584 // will record the permissions it recognized, not including "omnibox."
1585 // When upgrading to Chrome 10, "omnibox" will be recognized and Chrome
1586 // will disable the extension and prompt the user to approve the increase
1587 // in privileges. The extension could then release a new version that
1588 // removes the "omnibox" permission. When the user upgrades, Chrome will
1589 // still remember that "omnibox" had been granted, so that if the
1590 // extension once again includes "omnibox" in an upgrade, the extension
1591 // can upgrade without requiring this user's approval.
[email protected]eb5e4f92012-08-15 23:33:281592 int disable_reasons = extension_prefs_->GetDisableReasons(extension->id());
[email protected]8d888c12010-11-30 00:00:251593
rockot1d4a06262015-02-17 19:39:281594 // Silently grant all active permissions to default apps and apps installed
1595 // in kiosk mode.
[email protected]211a3f32013-05-28 21:48:181596 bool auto_grant_permission =
rockot1d4a06262015-02-17 19:39:281597 extension->was_installed_by_default() ||
[email protected]45928b682013-11-28 08:20:271598 extensions::ExtensionsBrowserClient::Get()->IsRunningInForcedAppMode();
[email protected]211a3f32013-05-28 21:48:181599 if (auto_grant_permission)
[email protected]b914e2952013-04-26 07:10:031600 GrantPermissions(extension);
1601
1602 bool is_privilege_increase = false;
1603 // We only need to compare the granted permissions to the current permissions
rockot1d4a06262015-02-17 19:39:281604 // if the extension has not been auto-granted its permissions above and is
1605 // installed internally.
1606 if (extension->location() == Manifest::INTERNAL && !auto_grant_permission) {
[email protected]8d888c12010-11-30 00:00:251607 // Add all the recognized permissions if the granted permissions list
1608 // hasn't been initialized yet.
[email protected]c2e66e12012-06-27 06:27:061609 scoped_refptr<PermissionSet> granted_permissions =
[email protected]902fd7b2011-07-27 18:42:311610 extension_prefs_->GetGrantedPermissions(extension->id());
[email protected]0d3e4a22011-06-23 19:02:521611 CHECK(granted_permissions.get());
[email protected]8d888c12010-11-30 00:00:251612
1613 // Here, we check if an extension's privileges have increased in a manner
1614 // that requires the user's approval. This could occur because the browser
1615 // upgraded and recognized additional privileges, or an extension upgrades
1616 // to a version that requires additional privileges.
[email protected]c41003472013-10-19 15:37:251617 is_privilege_increase =
1618 extensions::PermissionMessageProvider::Get()->IsPrivilegeIncrease(
dchengc7047942014-08-26 05:05:311619 granted_permissions.get(),
[email protected]076ebeda2014-06-06 21:47:261620 extension->permissions_data()->active_permissions().get(),
1621 extension->GetType());
[email protected]8d888c12010-11-30 00:00:251622 }
1623
[email protected]116d40e2013-08-08 17:23:171624 if (is_extension_installed) {
[email protected]44d62b62012-04-11 00:06:031625 // If the extension was already disabled, suppress any alerts for becoming
1626 // disabled on permissions increase.
[email protected]b914e2952013-04-26 07:10:031627 bool previously_disabled =
1628 extension_prefs_->IsExtensionDisabled(extension->id());
[email protected]7e9e2422012-12-13 19:54:191629 // Legacy disabled extensions do not have a disable reason. Infer that if
1630 // there was no permission increase, it was likely disabled by the user.
1631 if (previously_disabled && disable_reasons == Extension::DISABLE_NONE &&
[email protected]b914e2952013-04-26 07:10:031632 !extension_prefs_->DidExtensionEscalatePermissions(extension->id())) {
[email protected]7e9e2422012-12-13 19:54:191633 disable_reasons |= Extension::DISABLE_USER_ACTION;
[email protected]44d62b62012-04-11 00:06:031634 }
[email protected]7e9e2422012-12-13 19:54:191635 // Extensions that came to us disabled from sync need a similar inference,
1636 // except based on the new version's permissions.
1637 if (previously_disabled &&
1638 disable_reasons == Extension::DISABLE_UNKNOWN_FROM_SYNC) {
1639 // Remove the DISABLE_UNKNOWN_FROM_SYNC reason.
1640 extension_prefs_->ClearDisableReasons(extension->id());
1641 if (!is_privilege_increase)
1642 disable_reasons |= Extension::DISABLE_USER_ACTION;
1643 }
[email protected]b914e2952013-04-26 07:10:031644 disable_reasons &= ~Extension::DISABLE_UNKNOWN_FROM_SYNC;
[email protected]8d888c12010-11-30 00:00:251645 }
1646
1647 // Extension has changed permissions significantly. Disable it. A
[email protected]21db9ef2014-05-16 02:06:271648 // notification should be sent by the caller. If the extension is already
1649 // disabled because it was installed remotely, don't add another disable
1650 // reason, but instead always set the "did escalate permissions" flag, to
1651 // ensure enabling it will always show a warning.
1652 if (disable_reasons == Extension::DISABLE_REMOTE_INSTALL) {
1653 extension_prefs_->SetDidExtensionEscalatePermissions(extension, true);
1654 } else if (is_privilege_increase) {
[email protected]7e9e2422012-12-13 19:54:191655 disable_reasons |= Extension::DISABLE_PERMISSIONS_INCREASE;
[email protected]fe2dd7742011-04-19 22:52:491656 if (!extension_prefs_->DidExtensionEscalatePermissions(extension->id())) {
[email protected]4c86be582014-06-04 08:39:111657 RecordPermissionMessagesHistogram(extension,
1658 "Extensions.Permissions_AutoDisable2");
[email protected]fe2dd7742011-04-19 22:52:491659 }
[email protected]195c1582013-10-29 18:42:231660 extension_prefs_->SetExtensionState(extension->id(), Extension::DISABLED);
[email protected]8d888c12010-11-30 00:00:251661 extension_prefs_->SetDidExtensionEscalatePermissions(extension, true);
[email protected]b914e2952013-04-26 07:10:031662 }
1663 if (disable_reasons != Extension::DISABLE_NONE) {
[email protected]eb5e4f92012-08-15 23:33:281664 extension_prefs_->AddDisableReason(
1665 extension->id(),
1666 static_cast<Extension::DisableReason>(disable_reasons));
[email protected]8d888c12010-11-30 00:00:251667 }
1668}
1669
[email protected]eaa7dd182010-12-14 11:09:001670void ExtensionService::UpdateActiveExtensionsInCrashReporter() {
[email protected]c8865962009-12-16 07:47:391671 std::set<std::string> extension_ids;
[email protected]bb1bc9b32013-12-21 03:09:141672 const ExtensionSet& extensions = registry_->enabled_extensions();
1673 for (ExtensionSet::const_iterator iter = extensions.begin();
1674 iter != extensions.end(); ++iter) {
[email protected]cadac622013-06-11 16:46:361675 const Extension* extension = iter->get();
[email protected]1d5e58b2013-01-31 08:41:401676 if (!extension->is_theme() && extension->location() != Manifest::COMPONENT)
[email protected]84df8332011-12-06 18:22:461677 extension_ids.insert(extension->id());
[email protected]aab98a52009-12-02 03:22:351678 }
1679
[email protected]dcc47642014-03-26 22:03:491680 // TODO(kalman): This is broken. ExtensionService is per-profile.
1681 // crash_keys::SetActiveExtensions is per-process. See
1682 // http://crbug.com/355029.
[email protected]f6431be82013-09-07 02:53:451683 crash_keys::SetActiveExtensions(extension_ids);
[email protected]6014d672008-12-05 00:38:251684}
1685
[email protected]8266d662011-07-12 21:53:261686void ExtensionService::OnExtensionInstalled(
[email protected]36a5c4c2011-12-14 16:34:501687 const Extension* extension,
[email protected]98270432012-09-11 20:51:241688 const syncer::StringOrdinal& page_ordinal,
[email protected]4a1d9c0d2014-06-13 12:50:111689 int install_flags) {
[email protected]a29a517a2011-01-21 21:11:121690 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]a8af9fdb2010-10-28 21:52:201691
[email protected]c3cfb012011-04-06 22:07:351692 const std::string& id = extension->id();
binjin47947f842014-11-18 12:10:241693 int disable_reasons = GetDisableReasonsOnInstalled(extension);
[email protected]d8fd0fd2014-03-24 13:16:061694 std::string install_parameter;
[email protected]96aebe22014-07-16 04:07:511695 const extensions::PendingExtensionInfo* pending_extension_info =
1696 pending_extension_manager()->GetById(id);
1697 if (pending_extension_info) {
[email protected]8f3bcbd2013-06-05 08:42:401698 if (!pending_extension_info->ShouldAllowInstall(extension)) {
[email protected]51a3bf8b2012-06-08 22:53:061699 pending_extension_manager()->Remove(id);
[email protected]8ef78fd2010-08-19 17:14:321700
[email protected]31bb5ee62012-09-12 22:58:401701 LOG(WARNING) << "ShouldAllowInstall() returned false for "
1702 << id << " of type " << extension->GetType()
[email protected]65348062013-01-15 07:27:221703 << " and update URL "
1704 << extensions::ManifestURL::GetUpdateURL(extension).spec()
[email protected]31bb5ee62012-09-12 22:58:401705 << "; not installing";
[email protected]ae6cb3022011-04-04 20:11:541706
[email protected]4416c5a2010-06-26 01:28:571707 // Delete the extension directory since we're not going to
1708 // load it.
[email protected]7f8f24f2012-11-15 19:40:141709 if (!GetFileTaskRunner()->PostTask(
1710 FROM_HERE,
[email protected]85df9d12014-04-15 17:02:141711 base::Bind(&extensions::file_util::DeleteFile,
1712 extension->path(),
1713 true))) {
[email protected]14908b72011-04-20 06:54:361714 NOTREACHED();
[email protected]31bb5ee62012-09-12 22:58:401715 }
[email protected]4416c5a2010-06-26 01:28:571716 return;
1717 }
[email protected]51a3bf8b2012-06-08 22:53:061718
[email protected]d8fd0fd2014-03-24 13:16:061719 install_parameter = pending_extension_info->install_parameter();
[email protected]51a3bf8b2012-06-08 22:53:061720 pending_extension_manager()->Remove(id);
[email protected]4416c5a2010-06-26 01:28:571721 } else {
[email protected]c3cfb012011-04-06 22:07:351722 // We explicitly want to re-enable an uninstalled external
1723 // extension; if we're here, that means the user is manually
1724 // installing the extension.
[email protected]46f3e102014-03-25 01:22:451725 if (extension_prefs_->IsExternalExtensionUninstalled(id)) {
binjin47947f842014-11-18 12:10:241726 disable_reasons = Extension::DISABLE_NONE;
[email protected]6cc7dbae2011-04-29 21:18:331727 }
[email protected]aa142702010-03-26 01:26:331728 }
1729
[email protected]98270432012-09-11 20:51:241730 // Unsupported requirements overrides the management policy.
[email protected]4a1d9c0d2014-06-13 12:50:111731 if (install_flags & extensions::kInstallFlagHasRequirementErrors) {
binjin47947f842014-11-18 12:10:241732 disable_reasons |= Extension::DISABLE_UNSUPPORTED_REQUIREMENT;
binjin8e3d0182014-12-04 16:44:281733 } else {
1734 // Requirement is supported now, remove the corresponding disable reason
1735 // instead.
1736 extension_prefs_->RemoveDisableReason(
1737 id, Extension::DISABLE_UNSUPPORTED_REQUIREMENT);
1738 disable_reasons &= ~Extension::DISABLE_UNSUPPORTED_REQUIREMENT;
1739 }
1740
1741 // Check if the extension was disabled because of the minimum version
1742 // requirements from enterprise policy, and satisfies it now.
1743 if (extensions::ExtensionManagementFactory::GetForBrowserContext(profile())
1744 ->CheckMinimumVersion(extension, nullptr)) {
1745 // And remove the corresponding disable reason.
1746 extension_prefs_->RemoveDisableReason(
1747 id, Extension::DISABLE_UPDATE_REQUIRED_BY_POLICY);
1748 disable_reasons &= ~Extension::DISABLE_UPDATE_REQUIRED_BY_POLICY;
[email protected]98270432012-09-11 20:51:241749 }
1750
[email protected]4a1d9c0d2014-06-13 12:50:111751 if (install_flags & extensions::kInstallFlagIsBlacklistedForMalware) {
[email protected]9f3c8532013-07-31 19:52:071752 // Installation of a blacklisted extension can happen from sync, policy,
1753 // etc, where to maintain consistency we need to install it, just never
1754 // load it (see AddExtension). Usually it should be the job of callers to
1755 // incercept blacklisted extension earlier (e.g. CrxInstaller, before even
1756 // showing the install dialogue).
[email protected]7c82539c2014-02-19 06:09:171757 extension_prefs_->AcknowledgeBlacklistedExtension(id);
[email protected]9f3c8532013-07-31 19:52:071758 UMA_HISTOGRAM_ENUMERATION("ExtensionBlacklist.SilentInstall",
1759 extension->location(),
1760 Manifest::NUM_LOCATIONS);
1761 }
1762
[email protected]695b5712012-12-06 23:55:281763 if (!GetInstalledExtension(extension->id())) {
[email protected]07533022011-06-27 20:42:551764 UMA_HISTOGRAM_ENUMERATION("Extensions.InstallType",
1765 extension->GetType(), 100);
[email protected]69084dc2012-11-17 07:39:301766 UMA_HISTOGRAM_ENUMERATION("Extensions.InstallSource",
[email protected]1d5e58b2013-01-31 08:41:401767 extension->location(), Manifest::NUM_LOCATIONS);
[email protected]4c86be582014-06-04 08:39:111768 RecordPermissionMessagesHistogram(extension,
1769 "Extensions.Permissions_Install2");
[email protected]69084dc2012-11-17 07:39:301770 } else {
1771 UMA_HISTOGRAM_ENUMERATION("Extensions.UpdateType",
1772 extension->GetType(), 100);
1773 UMA_HISTOGRAM_ENUMERATION("Extensions.UpdateSource",
[email protected]1d5e58b2013-01-31 08:41:401774 extension->location(), Manifest::NUM_LOCATIONS);
[email protected]8f959f522014-08-06 06:26:281775
1776 // A fully installed app cannot be demoted to an ephemeral app.
1777 if ((install_flags & extensions::kInstallFlagIsEphemeral) &&
1778 !extension_prefs_->IsEphemeralApp(id)) {
1779 install_flags &= ~static_cast<int>(extensions::kInstallFlagIsEphemeral);
1780 }
[email protected]07533022011-06-27 20:42:551781 }
1782
binjin47947f842014-11-18 12:10:241783 if (disable_reasons)
1784 extension_prefs_->AddDisableReasons(id, disable_reasons);
1785
[email protected]399583b2012-12-11 09:33:421786 const Extension::State initial_state =
binjin47947f842014-11-18 12:10:241787 disable_reasons == Extension::DISABLE_NONE ? Extension::ENABLED
1788 : Extension::DISABLED;
1789
[email protected]4a1d9c0d2014-06-13 12:50:111790 if (ShouldDelayExtensionUpdate(
1791 id,
1792 !!(install_flags & extensions::kInstallFlagInstallImmediately))) {
[email protected]9f3c8532013-07-31 19:52:071793 extension_prefs_->SetDelayedInstallInfo(
1794 extension,
1795 initial_state,
[email protected]4a1d9c0d2014-06-13 12:50:111796 install_flags,
[email protected]9f3c8532013-07-31 19:52:071797 extensions::ExtensionPrefs::DELAY_REASON_WAIT_FOR_IDLE,
[email protected]d8fd0fd2014-03-24 13:16:061798 page_ordinal,
1799 install_parameter);
[email protected]0db124b02012-11-07 04:55:051800
1801 // Transfer ownership of |extension|.
[email protected]9f4e4f082013-06-21 07:11:191802 delayed_installs_.Insert(extension);
[email protected]0db124b02012-11-07 04:55:051803
[email protected]75bdcb872013-03-13 00:41:451804 // Notify observers that app update is available.
1805 FOR_EACH_OBSERVER(extensions::UpdateObserver, update_observers_,
[email protected]a9aa62b312013-11-29 05:35:061806 OnAppUpdateAvailable(extension));
[email protected]0db124b02012-11-07 04:55:051807 return;
1808 }
1809
[email protected]90878c52014-04-04 18:21:021810 extensions::SharedModuleService::ImportStatus status =
1811 shared_module_service_->SatisfyImports(extension);
[email protected]e5f8fffe2014-04-02 00:30:441812 if (installs_delayed_for_gc_) {
[email protected]9f3c8532013-07-31 19:52:071813 extension_prefs_->SetDelayedInstallInfo(
1814 extension,
1815 initial_state,
[email protected]4a1d9c0d2014-06-13 12:50:111816 install_flags,
[email protected]9f3c8532013-07-31 19:52:071817 extensions::ExtensionPrefs::DELAY_REASON_GC,
[email protected]d8fd0fd2014-03-24 13:16:061818 page_ordinal,
1819 install_parameter);
[email protected]399583b2012-12-11 09:33:421820 delayed_installs_.Insert(extension);
[email protected]90878c52014-04-04 18:21:021821 } else if (status != SharedModuleService::IMPORT_STATUS_OK) {
1822 if (status == SharedModuleService::IMPORT_STATUS_UNSATISFIED) {
[email protected]9f3c8532013-07-31 19:52:071823 extension_prefs_->SetDelayedInstallInfo(
1824 extension,
1825 initial_state,
[email protected]4a1d9c0d2014-06-13 12:50:111826 install_flags,
[email protected]9f4e4f082013-06-21 07:11:191827 extensions::ExtensionPrefs::DELAY_REASON_WAIT_FOR_IMPORTS,
[email protected]d8fd0fd2014-03-24 13:16:061828 page_ordinal,
1829 install_parameter);
[email protected]9f4e4f082013-06-21 07:11:191830 delayed_installs_.Insert(extension);
1831 }
[email protected]399583b2012-12-11 09:33:421832 } else {
[email protected]9f3c8532013-07-31 19:52:071833 AddNewOrUpdatedExtension(extension,
1834 initial_state,
[email protected]4a1d9c0d2014-06-13 12:50:111835 install_flags,
[email protected]d8fd0fd2014-03-24 13:16:061836 page_ordinal,
1837 install_parameter);
[email protected]399583b2012-12-11 09:33:421838 }
[email protected]8c484b742012-11-29 06:05:361839}
1840
binjin1569c9b2014-09-05 13:33:181841void ExtensionService::OnExtensionManagementSettingsChanged() {
1842 error_controller_->ShowErrorIfNeeded();
binjine6b58b52014-10-31 01:55:571843
1844 // Revokes blocked permissions from active_permissions for all extensions.
1845 extensions::ExtensionManagement* settings =
1846 extensions::ExtensionManagementFactory::GetForBrowserContext(profile());
1847 CHECK(settings);
1848 scoped_ptr<ExtensionSet> all_extensions(
1849 registry_->GenerateInstalledExtensionsSet());
1850 for (const auto& extension : *all_extensions.get()) {
1851 if (!settings->IsPermissionSetAllowed(
binjin685ade82014-11-06 09:53:561852 extension.get(),
binjine6b58b52014-10-31 01:55:571853 extension->permissions_data()->active_permissions())) {
1854 extensions::PermissionsUpdater(profile()).RemovePermissions(
1855 extension.get(),
binjin685ade82014-11-06 09:53:561856 settings->GetBlockedPermissions(extension.get()).get());
binjine6b58b52014-10-31 01:55:571857 }
1858 }
1859
binjin1569c9b2014-09-05 13:33:181860 CheckManagementPolicy();
1861}
1862
[email protected]8c484b742012-11-29 06:05:361863void ExtensionService::AddNewOrUpdatedExtension(
1864 const Extension* extension,
[email protected]399583b2012-12-11 09:33:421865 Extension::State initial_state,
[email protected]4a1d9c0d2014-06-13 12:50:111866 int install_flags,
[email protected]d8fd0fd2014-03-24 13:16:061867 const syncer::StringOrdinal& page_ordinal,
1868 const std::string& install_parameter) {
[email protected]8c484b742012-11-29 06:05:361869 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]760f743b2014-05-28 13:52:021870 bool was_ephemeral = extension_prefs_->IsEphemeralApp(extension->id());
[email protected]4a1d9c0d2014-06-13 12:50:111871 extension_prefs_->OnExtensionInstalled(
1872 extension, initial_state, page_ordinal, install_flags, install_parameter);
[email protected]9e9c1d12013-07-31 01:58:121873 delayed_installs_.Remove(extension->id());
[email protected]913ffca92014-03-27 15:26:161874 if (InstallVerifier::NeedsVerification(*extension))
1875 system_->install_verifier()->VerifyExtension(extension->id());
ryanackley48bedbd2015-01-27 23:12:141876
1877 const Extension* old = GetInstalledExtension(extension->id());
1878 if (extensions::AppDataMigrator::NeedsMigration(old, extension)) {
1879 app_data_migrator_->DoMigrationAndReply(
1880 old, extension,
1881 base::Bind(&ExtensionService::FinishInstallation, AsWeakPtr(),
1882 make_scoped_refptr(extension), was_ephemeral));
1883 return;
1884 }
1885
[email protected]760f743b2014-05-28 13:52:021886 FinishInstallation(extension, was_ephemeral);
[email protected]6f6101832012-11-27 22:10:481887}
1888
1889void ExtensionService::MaybeFinishDelayedInstallation(
1890 const std::string& extension_id) {
[email protected]9f4e4f082013-06-21 07:11:191891 // Check if the extension already got installed.
1892 if (!delayed_installs_.Contains(extension_id))
[email protected]6f6101832012-11-27 22:10:481893 return;
[email protected]9f4e4f082013-06-21 07:11:191894 extensions::ExtensionPrefs::DelayReason reason =
1895 extension_prefs_->GetDelayedInstallReason(extension_id);
1896
1897 // Check if the extension is idle. DELAY_REASON_NONE is used for older
1898 // preferences files that will not have set this field but it was previously
1899 // only used for idle updates.
1900 if ((reason == extensions::ExtensionPrefs::DELAY_REASON_WAIT_FOR_IDLE ||
1901 reason == extensions::ExtensionPrefs::DELAY_REASON_NONE) &&
[email protected]1d5cf4142014-01-24 18:25:221902 is_ready() && !extensions::util::IsExtensionIdle(extension_id, profile_))
[email protected]6f6101832012-11-27 22:10:481903 return;
1904
[email protected]9f4e4f082013-06-21 07:11:191905 const Extension* extension = delayed_installs_.GetByID(extension_id);
1906 if (reason == extensions::ExtensionPrefs::DELAY_REASON_WAIT_FOR_IMPORTS) {
[email protected]90878c52014-04-04 18:21:021907 extensions::SharedModuleService::ImportStatus status =
1908 shared_module_service_->SatisfyImports(extension);
1909 if (status != SharedModuleService::IMPORT_STATUS_OK) {
1910 if (status == SharedModuleService::IMPORT_STATUS_UNRECOVERABLE) {
[email protected]9f4e4f082013-06-21 07:11:191911 delayed_installs_.Remove(extension_id);
1912 // Make sure no version of the extension is actually installed, (i.e.,
1913 // that this delayed install was not an update).
1914 CHECK(!extension_prefs_->GetInstalledExtensionInfo(extension_id).get());
1915 extension_prefs_->DeleteExtensionPrefs(extension_id);
1916 }
1917 return;
1918 }
1919 }
1920
[email protected]6f6101832012-11-27 22:10:481921 FinishDelayedInstallation(extension_id);
1922}
1923
1924void ExtensionService::FinishDelayedInstallation(
1925 const std::string& extension_id) {
1926 scoped_refptr<const Extension> extension(
1927 GetPendingExtensionUpdate(extension_id));
[email protected]dc24976f2013-06-02 21:15:091928 CHECK(extension.get());
[email protected]9f4e4f082013-06-21 07:11:191929 delayed_installs_.Remove(extension_id);
[email protected]6f6101832012-11-27 22:10:481930
[email protected]760f743b2014-05-28 13:52:021931 bool was_ephemeral = extension_prefs_->IsEphemeralApp(extension->id());
[email protected]399583b2012-12-11 09:33:421932 if (!extension_prefs_->FinishDelayedInstallInfo(extension_id))
[email protected]6f6101832012-11-27 22:10:481933 NOTREACHED();
1934
[email protected]760f743b2014-05-28 13:52:021935 FinishInstallation(extension.get(), was_ephemeral);
[email protected]6f6101832012-11-27 22:10:481936}
1937
[email protected]760f743b2014-05-28 13:52:021938void ExtensionService::FinishInstallation(
1939 const Extension* extension, bool was_ephemeral) {
[email protected]e7554c3f2013-05-29 00:36:561940 const extensions::Extension* existing_extension =
1941 GetInstalledExtension(extension->id());
1942 bool is_update = false;
1943 std::string old_name;
1944 if (existing_extension) {
1945 is_update = true;
1946 old_name = existing_extension->name();
1947 }
[email protected]760f743b2014-05-28 13:52:021948 bool from_ephemeral =
1949 was_ephemeral && !extension_prefs_->IsEphemeralApp(extension->id());
1950 extensions::InstalledExtensionInfo details(
1951 extension, is_update, from_ephemeral, old_name);
[email protected]fcb58a862012-05-01 01:03:151952 content::NotificationService::current()->Notify(
[email protected]adf5a102014-07-31 12:44:061953 extensions::NOTIFICATION_EXTENSION_WILL_BE_INSTALLED_DEPRECATED,
[email protected]fcb58a862012-05-01 01:03:151954 content::Source<Profile>(profile_),
[email protected]41bb80bd2013-05-03 10:56:021955 content::Details<const extensions::InstalledExtensionInfo>(&details));
[email protected]fcb58a862012-05-01 01:03:151956
[email protected]bc44b5da2014-06-12 14:20:001957 registry_->TriggerOnWillBeInstalled(
[email protected]760f743b2014-05-28 13:52:021958 extension, is_update, from_ephemeral, old_name);
[email protected]17f07822014-05-22 08:45:151959
[email protected]399583b2012-12-11 09:33:421960 // Unpacked extensions default to allowing file access, but if that has been
1961 // overridden, don't reset the value.
[email protected]1d5e58b2013-01-31 08:41:401962 if (Manifest::ShouldAlwaysAllowFileAccess(extension->location()) &&
[email protected]399583b2012-12-11 09:33:421963 !extension_prefs_->HasAllowFileAccessSetting(extension->id())) {
1964 extension_prefs_->SetAllowFileAccess(extension->id(), true);
1965 }
1966
[email protected]6f6101832012-11-27 22:10:481967 AddExtension(extension);
[email protected]612a1cb12012-10-17 13:18:031968
[email protected]bc44b5da2014-06-12 14:20:001969 // Notify observers that need to know when an installation is complete.
[email protected]38e872532014-07-16 23:27:511970 registry_->TriggerOnInstalled(extension, is_update);
[email protected]bc44b5da2014-06-12 14:20:001971
[email protected]9f4e4f082013-06-21 07:11:191972 // Check extensions that may have been delayed only because this shared module
1973 // was not available.
[email protected]374ceb6f2014-07-02 19:25:341974 if (SharedModuleInfo::IsSharedModule(extension))
[email protected]9f4e4f082013-06-21 07:11:191975 MaybeFinishDelayedInstallations();
[email protected]4a190632009-05-09 01:07:421976}
1977
[email protected]760f743b2014-05-28 13:52:021978void ExtensionService::PromoteEphemeralApp(
1979 const extensions::Extension* extension, bool is_from_sync) {
1980 DCHECK(GetInstalledExtension(extension->id()) &&
1981 extension_prefs_->IsEphemeralApp(extension->id()));
1982
[email protected]db378322014-07-21 23:19:341983 if (extension->RequiresSortOrdinal()) {
1984 extension_prefs_->app_sorting()->SetExtensionVisible(
1985 extension->id(), extension->ShouldDisplayInNewTabPage());
1986
1987 if (!is_from_sync) {
[email protected]760f743b2014-05-28 13:52:021988 // Reset the sort ordinals of the app to ensure it is added to the default
1989 // position, like newly installed apps would.
1990 extension_prefs_->app_sorting()->ClearOrdinals(extension->id());
[email protected]760f743b2014-05-28 13:52:021991 }
1992
[email protected]db378322014-07-21 23:19:341993 extension_prefs_->app_sorting()->EnsureValidOrdinals(
1994 extension->id(), syncer::StringOrdinal());
1995 }
1996
[email protected]760f743b2014-05-28 13:52:021997 // Remove the ephemeral flags from the preferences.
1998 extension_prefs_->OnEphemeralAppPromoted(extension->id());
1999
2000 // Fire install-related events to allow observers to handle the promotion
2001 // of the ephemeral app.
2002 extensions::InstalledExtensionInfo details(
2003 extension,
2004 true /* is update */,
2005 true /* from ephemeral */,
2006 extension->name() /* old name */);
2007 content::NotificationService::current()->Notify(
[email protected]adf5a102014-07-31 12:44:062008 extensions::NOTIFICATION_EXTENSION_WILL_BE_INSTALLED_DEPRECATED,
[email protected]760f743b2014-05-28 13:52:022009 content::Source<Profile>(profile_),
2010 content::Details<const extensions::InstalledExtensionInfo>(&details));
2011
2012 registry_->TriggerOnWillBeInstalled(
2013 extension,
2014 true /* is update */,
2015 true /* from ephemeral */,
2016 extension->name() /* old name */);
2017
2018 if (registry_->enabled_extensions().Contains(extension->id())) {
[email protected]8f959f522014-08-06 06:26:282019 // If the app is already enabled and loaded, fire the load events to allow
2020 // observers to handle the promotion of the ephemeral app.
[email protected]760f743b2014-05-28 13:52:022021 content::NotificationService::current()->Notify(
[email protected]adf5a102014-07-31 12:44:062022 extensions::NOTIFICATION_EXTENSION_LOADED_DEPRECATED,
[email protected]760f743b2014-05-28 13:52:022023 content::Source<Profile>(profile_),
2024 content::Details<const Extension>(extension));
2025
2026 registry_->TriggerOnLoaded(extension);
[email protected]8f959f522014-08-06 06:26:282027 } else {
2028 // Cached ephemeral apps may be updated and disabled due to permissions
2029 // increase. The app can be enabled (as long as no other disable reasons
2030 // exist) as the install was user-acknowledged.
2031 int disable_mask = Extension::DISABLE_NONE;
2032 if (!is_from_sync)
2033 disable_mask |= Extension::DISABLE_PERMISSIONS_INCREASE;
2034
2035 int other_disable_reasons =
2036 extension_prefs_->GetDisableReasons(extension->id()) & ~disable_mask;
2037 if (!other_disable_reasons) {
2038 if (extension_prefs_->DidExtensionEscalatePermissions(extension->id()))
2039 GrantPermissionsAndEnableExtension(extension);
2040 else
2041 EnableExtension(extension->id());
2042 }
[email protected]760f743b2014-05-28 13:52:022043 }
2044
[email protected]38e872532014-07-16 23:27:512045 registry_->TriggerOnInstalled(extension, true);
[email protected]bc44b5da2014-06-12 14:20:002046
[email protected]760f743b2014-05-28 13:52:022047 if (!is_from_sync && extension_sync_service_)
2048 extension_sync_service_->SyncExtensionChangeIfNeeded(*extension);
2049}
2050
[email protected]76b65442012-11-17 14:11:482051const Extension* ExtensionService::GetPendingExtensionUpdate(
2052 const std::string& id) const {
[email protected]9f4e4f082013-06-21 07:11:192053 return delayed_installs_.GetByID(id);
[email protected]76b65442012-11-17 14:11:482054}
2055
mukai87a8d402014-09-15 20:15:092056void ExtensionService::RegisterContentSettings(
2057 HostContentSettingsMap* host_content_settings_map) {
rkaplowe65c2ff2015-02-14 16:29:542058 TRACE_EVENT0("browser,startup", "ExtensionService::RegisterContentSettings");
mukaia1aa3512014-10-22 20:14:112059 DCHECK_CURRENTLY_ON(BrowserThread::UI);
mukai87a8d402014-09-15 20:15:092060 host_content_settings_map->RegisterProvider(
2061 HostContentSettingsMap::INTERNAL_EXTENSION_PROVIDER,
2062 scoped_ptr<content_settings::ObservableProvider>(
reillyga3acbc12014-11-11 23:17:122063 new content_settings::InternalExtensionProvider(profile_)));
mukai87a8d402014-09-15 20:15:092064
2065 host_content_settings_map->RegisterProvider(
2066 HostContentSettingsMap::CUSTOM_EXTENSION_PROVIDER,
2067 scoped_ptr<content_settings::ObservableProvider>(
2068 new content_settings::CustomExtensionProvider(
2069 extensions::ContentSettingsService::Get(
2070 profile_)->content_settings_store(),
2071 profile_->GetOriginalProfile() != profile_)));
2072}
2073
[email protected]bb7f40952011-01-13 00:21:202074void ExtensionService::TrackTerminatedExtension(const Extension* extension) {
[email protected]bb1bc9b32013-12-21 03:09:142075 // No need to check for duplicates; inserting a duplicate is a no-op.
2076 registry_->AddTerminated(make_scoped_refptr(extension));
[email protected]3964e572014-02-13 21:57:412077 extensions_being_terminated_.erase(extension->id());
[email protected]b0af4792013-10-23 09:12:132078 UnloadExtension(extension->id(), UnloadedExtensionInfo::REASON_TERMINATE);
[email protected]bb7f40952011-01-13 00:21:202079}
2080
[email protected]e9d7496e2014-04-18 01:25:462081void ExtensionService::TerminateExtension(const std::string& extension_id) {
2082 const Extension* extension = GetInstalledExtension(extension_id);
2083 TrackTerminatedExtension(extension);
2084}
2085
[email protected]bb7f40952011-01-13 00:21:202086void ExtensionService::UntrackTerminatedExtension(const std::string& id) {
[email protected]cb1f4ac2014-08-07 16:55:422087 std::string lowercase_id = base::StringToLowerASCII(id);
[email protected]bb1bc9b32013-12-21 03:09:142088 const Extension* extension =
2089 registry_->terminated_extensions().GetByID(lowercase_id);
2090 registry_->RemoveTerminated(lowercase_id);
[email protected]fb789532013-08-27 02:40:212091 if (extension) {
2092 content::NotificationService::current()->Notify(
[email protected]adf5a102014-07-31 12:44:062093 extensions::NOTIFICATION_EXTENSION_REMOVED,
[email protected]fb789532013-08-27 02:40:212094 content::Source<Profile>(profile_),
2095 content::Details<const Extension>(extension));
2096 }
[email protected]bb7f40952011-01-13 00:21:202097}
2098
[email protected]8001df22011-04-28 19:59:472099const Extension* ExtensionService::GetInstalledExtension(
2100 const std::string& id) const {
[email protected]599539802014-01-07 23:06:002101 return registry_->GetExtensionById(id, ExtensionRegistry::EVERYTHING);
[email protected]0dfe05c2011-02-23 23:03:362102}
2103
[email protected]9060d8b02012-01-13 02:14:302104bool ExtensionService::OnExternalExtensionFileFound(
[email protected]8ef78fd2010-08-19 17:14:322105 const std::string& id,
[email protected]c5e4a2222014-01-03 16:06:132106 const Version* version,
[email protected]650b2d52013-02-10 03:41:452107 const base::FilePath& path,
[email protected]1d5e58b2013-01-31 08:41:402108 Manifest::Location location,
[email protected]47fc70c2011-12-06 07:29:512109 int creation_flags,
2110 bool mark_acknowledged) {
[email protected]ab22ba42011-01-14 16:36:382111 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]fdd28372014-08-21 02:27:262112 CHECK(crx_file::id_util::IdIsValid(id));
[email protected]79c833b52011-04-05 18:31:012113 if (extension_prefs_->IsExternalExtensionUninstalled(id))
[email protected]9060d8b02012-01-13 02:14:302114 return false;
[email protected]a8af9fdb2010-10-28 21:52:202115
[email protected]7577a5c52009-07-30 06:21:582116 // Before even bothering to unpack, check and see if we already have this
[email protected]4c967932009-07-31 01:15:492117 // version. This is important because these extensions are going to get
[email protected]7577a5c52009-07-30 06:21:582118 // installed on every startup.
[email protected]9adb9692010-10-29 23:14:022119 const Extension* existing = GetExtensionById(id, true);
[email protected]910f72ce2012-08-24 01:38:352120
[email protected]7577a5c52009-07-30 06:21:582121 if (existing) {
[email protected]910f72ce2012-08-24 01:38:352122 // The default apps will have the location set as INTERNAL. Since older
2123 // default apps are installed as EXTERNAL, we override them. However, if the
2124 // app is already installed as internal, then do the version check.
[email protected]31bb5ee62012-09-12 22:58:402125 // TODO(grv) : Remove after Q1-2013.
[email protected]910f72ce2012-08-24 01:38:352126 bool is_default_apps_migration =
[email protected]1d5e58b2013-01-31 08:41:402127 (location == Manifest::INTERNAL &&
2128 Manifest::IsExternalLocation(existing->location()));
[email protected]910f72ce2012-08-24 01:38:352129
2130 if (!is_default_apps_migration) {
2131 DCHECK(version);
2132
2133 switch (existing->version()->CompareTo(*version)) {
2134 case -1: // existing version is older, we should upgrade
2135 break;
2136 case 0: // existing version is same, do nothing
2137 return false;
2138 case 1: // existing version is newer, uh-oh
2139 LOG(WARNING) << "Found external version of extension " << id
2140 << "that is older than current version. Current version "
2141 << "is: " << existing->VersionString() << ". New "
2142 << "version is: " << version->GetString()
2143 << ". Keeping current version.";
2144 return false;
2145 }
[email protected]7577a5c52009-07-30 06:21:582146 }
2147 }
2148
[email protected]9060d8b02012-01-13 02:14:302149 // If the extension is already pending, don't start an install.
[email protected]e3987852012-05-04 10:06:302150 if (!pending_extension_manager()->AddFromExternalFile(
[email protected]464213a2013-10-15 01:06:482151 id, location, *version, creation_flags, mark_acknowledged)) {
[email protected]9060d8b02012-01-13 02:14:302152 return false;
[email protected]e3987852012-05-04 10:06:302153 }
[email protected]9c635f22010-12-02 09:36:362154
[email protected]14908b72011-04-20 06:54:362155 // no client (silent install)
[email protected]f8636f92013-08-09 21:02:372156 scoped_refptr<CrxInstaller> installer(CrxInstaller::CreateSilent(this));
[email protected]6dfbbf82010-03-12 23:09:162157 installer->set_install_source(location);
2158 installer->set_expected_id(id);
[email protected]cb0e50312011-05-09 15:03:072159 installer->set_expected_version(*version);
2160 installer->set_install_cause(extension_misc::INSTALL_CAUSE_EXTERNAL_FILE);
[email protected]1bf73cc32011-10-26 22:38:312161 installer->set_creation_flags(creation_flags);
[email protected]88e8ec9152013-01-17 04:05:182162#if defined(OS_CHROMEOS)
2163 extensions::InstallLimiter::Get(profile_)->Add(installer, path);
2164#else
[email protected]6dfbbf82010-03-12 23:09:162165 installer->InstallCrx(path);
[email protected]88e8ec9152013-01-17 04:05:182166#endif
[email protected]47fc70c2011-12-06 07:29:512167
2168 // Depending on the source, a new external extension might not need a user
2169 // notification on installation. For such extensions, mark them acknowledged
2170 // now to suppress the notification.
2171 if (mark_acknowledged)
[email protected]374ceb6f2014-07-02 19:25:342172 external_install_manager_->AcknowledgeExternalExtension(id);
[email protected]9060d8b02012-01-13 02:14:302173
2174 return true;
[email protected]7577a5c52009-07-30 06:21:582175}
2176
[email protected]eaa7dd182010-12-14 11:09:002177void ExtensionService::DidCreateRenderViewForBackgroundPage(
[email protected]3a1dc572012-07-31 22:25:132178 extensions::ExtensionHost* host) {
[email protected]406027c02010-09-27 08:03:182179 OrphanedDevTools::iterator iter =
[email protected]2d2f6cfc2011-05-06 21:09:332180 orphaned_dev_tools_.find(host->extension_id());
[email protected]406027c02010-09-27 08:03:182181 if (iter == orphaned_dev_tools_.end())
2182 return;
2183
[email protected]b3f957e62014-08-08 10:09:022184 iter->second->ConnectWebContents(host->host_contents());
[email protected]406027c02010-09-27 08:03:182185 orphaned_dev_tools_.erase(iter);
2186}
2187
[email protected]432115822011-07-10 15:52:272188void ExtensionService::Observe(int type,
[email protected]6c2381d2011-10-19 02:52:532189 const content::NotificationSource& source,
2190 const content::NotificationDetails& details) {
[email protected]432115822011-07-10 15:52:272191 switch (type) {
[email protected]3c4abc82012-10-22 22:25:542192 case chrome::NOTIFICATION_APP_TERMINATING:
2193 // Shutdown has started. Don't start any more extension installs.
2194 // (We cannot use ExtensionService::Shutdown() for this because it
2195 // happens too late in browser teardown.)
2196 browser_terminating_ = true;
2197 break;
[email protected]adf5a102014-07-31 12:44:062198 case extensions::NOTIFICATION_EXTENSION_PROCESS_TERMINATED: {
[email protected]6c2381d2011-10-19 02:52:532199 if (profile_ !=
2200 content::Source<Profile>(source).ptr()->GetOriginalProfile()) {
[email protected]bc535ee52010-08-31 18:40:322201 break;
[email protected]6c2381d2011-10-19 02:52:532202 }
[email protected]a4ed6282009-12-14 20:51:162203
[email protected]3a1dc572012-07-31 22:25:132204 extensions::ExtensionHost* host =
2205 content::Details<extensions::ExtensionHost>(details).ptr();
[email protected]f128af42010-08-05 18:05:262206
[email protected]3964e572014-02-13 21:57:412207 // If the extension is already being terminated, there is nothing left to
2208 // do.
2209 if (!extensions_being_terminated_.insert(host->extension_id()).second)
2210 break;
2211
[email protected]fa2416f2011-05-03 08:41:202212 // Mark the extension as terminated and Unload it. We want it to
2213 // be in a consistent state: either fully working or not loaded
2214 // at all, but never half-crashed. We do it in a PostTask so
2215 // that other handlers of this notification will still have
2216 // access to the Extension and ExtensionHost.
[email protected]b3a25092013-05-28 22:08:162217 base::MessageLoop::current()->PostTask(
[email protected]14908b72011-04-20 06:54:362218 FROM_HERE,
[email protected]53612e82011-10-18 18:00:362219 base::Bind(
[email protected]fa2416f2011-05-03 08:41:202220 &ExtensionService::TrackTerminatedExtension,
[email protected]d8c8f25f2011-11-02 18:18:012221 AsWeakPtr(),
[email protected]fa2416f2011-05-03 08:41:202222 host->extension()));
[email protected]31f77262009-12-02 20:48:532223 break;
2224 }
[email protected]432115822011-07-10 15:52:272225 case content::NOTIFICATION_RENDERER_PROCESS_TERMINATED: {
[email protected]f3b1a082011-11-18 00:34:302226 content::RenderProcessHost* process =
2227 content::Source<content::RenderProcessHost>(source).ptr();
[email protected]fc30ef082011-08-18 04:07:192228 Profile* host_profile =
[email protected]f3b1a082011-11-18 00:34:302229 Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]fc30ef082011-08-18 04:07:192230 if (!profile_->IsSameProfile(host_profile->GetOriginalProfile()))
2231 break;
2232
[email protected]fafdc842014-01-17 18:09:082233 extensions::ProcessMap* process_map =
2234 extensions::ProcessMap::Get(profile_);
2235 if (process_map->Contains(process->GetID())) {
[email protected]52b76592013-11-02 17:59:032236 // An extension process was terminated, this might have resulted in an
2237 // app or extension becoming idle.
2238 std::set<std::string> extension_ids =
[email protected]fafdc842014-01-17 18:09:082239 process_map->GetExtensionsInProcess(process->GetID());
elijahtaylor0def4432014-10-06 18:15:112240 // In addition to the extensions listed in the process map, one of those
2241 // extensions could be referencing a shared module which is waiting for
2242 // idle to update. Check all imports of these extensions, too.
2243 std::set<std::string> import_ids;
2244 for (std::set<std::string>::const_iterator it = extension_ids.begin();
2245 it != extension_ids.end();
2246 ++it) {
2247 const Extension* extension = GetExtensionById(*it, true);
2248 if (!extension)
2249 continue;
2250 const std::vector<SharedModuleInfo::ImportInfo>& imports =
2251 SharedModuleInfo::GetImports(extension);
2252 std::vector<SharedModuleInfo::ImportInfo>::const_iterator import_it;
2253 for (import_it = imports.begin(); import_it != imports.end();
2254 import_it++) {
2255 import_ids.insert((*import_it).extension_id);
2256 }
2257 }
2258 extension_ids.insert(import_ids.begin(), import_ids.end());
2259
[email protected]52b76592013-11-02 17:59:032260 for (std::set<std::string>::const_iterator it = extension_ids.begin();
2261 it != extension_ids.end(); ++it) {
2262 if (delayed_installs_.Contains(*it)) {
2263 base::MessageLoop::current()->PostDelayedTask(
2264 FROM_HERE,
2265 base::Bind(&ExtensionService::MaybeFinishDelayedInstallation,
2266 AsWeakPtr(), *it),
2267 base::TimeDelta::FromSeconds(kUpdateIdleDelay));
2268 }
2269 }
2270 }
2271
[email protected]fafdc842014-01-17 18:09:082272 process_map->RemoveAllFromProcess(process->GetID());
[email protected]6f371442011-11-09 06:45:462273 BrowserThread::PostTask(
[email protected]38427a12013-11-09 17:34:202274 BrowserThread::IO,
2275 FROM_HERE,
2276 base::Bind(&extensions::InfoMap::UnregisterAllExtensionsInProcess,
[email protected]31d8f5f22012-04-02 15:22:082277 system_->info_map(),
[email protected]f3b1a082011-11-18 00:34:302278 process->GetID()));
[email protected]da5683db2011-04-23 17:12:212279 break;
2280 }
[email protected]92dd8d92013-02-26 00:41:082281 case chrome::NOTIFICATION_UPGRADE_RECOMMENDED: {
[email protected]75bdcb872013-03-13 00:41:452282 // Notify observers that chrome update is available.
2283 FOR_EACH_OBSERVER(extensions::UpdateObserver, update_observers_,
2284 OnChromeUpdateAvailable());
[email protected]92dd8d92013-02-26 00:41:082285 break;
2286 }
[email protected]ebe07772014-05-22 04:16:062287 case chrome::NOTIFICATION_PROFILE_DESTRUCTION_STARTED: {
2288 OnProfileDestructionStarted();
2289 break;
2290 }
[email protected]aa96d3a2010-08-21 08:45:252291
[email protected]4814b512009-11-07 00:12:292292 default:
2293 NOTREACHED() << "Unexpected notification type.";
2294 }
2295}
2296
binjin47947f842014-11-18 12:10:242297int ExtensionService::GetDisableReasonsOnInstalled(const Extension* extension) {
2298 Extension::DisableReason disable_reason;
2299 // Extensions disabled by management policy should always be disabled, even
2300 // if it's force-installed.
2301 if (system_->management_policy()->MustRemainDisabled(
2302 extension, &disable_reason, nullptr)) {
2303 // A specified reason is required to disable the extension.
2304 DCHECK(disable_reason != Extension::DISABLE_NONE);
2305 return disable_reason;
2306 }
2307
[email protected]612a1cb12012-10-17 13:18:032308 // Extensions installed by policy can't be disabled. So even if a previous
2309 // installation disabled the extension, make sure it is now enabled.
binjin47947f842014-11-18 12:10:242310 if (system_->management_policy()->MustRemainEnabled(extension, nullptr))
2311 return Extension::DISABLE_NONE;
[email protected]612a1cb12012-10-17 13:18:032312
binjin47947f842014-11-18 12:10:242313 // An already disabled extension should inherit the disable reasons and
2314 // remain disabled.
2315 if (extension_prefs_->IsExtensionDisabled(extension->id())) {
2316 int disable_reasons = extension_prefs_->GetDisableReasons(extension->id());
2317 // If an extension was disabled without specified reason, presume it's
2318 // disabled by user.
2319 return disable_reasons == Extension::DISABLE_NONE
2320 ? Extension::DISABLE_USER_ACTION
2321 : disable_reasons;
2322 }
[email protected]612a1cb12012-10-17 13:18:032323
[email protected]41070e8d2012-10-24 01:34:362324 if (FeatureSwitch::prompt_for_external_extensions()->IsEnabled()) {
[email protected]612a1cb12012-10-17 13:18:032325 // External extensions are initially disabled. We prompt the user before
[email protected]2c495c42013-01-04 21:49:542326 // enabling them. Hosted apps are excepted because they are not dangerous
2327 // (they need to be launched by the user anyway).
[email protected]1d5e58b2013-01-31 08:41:402328 if (extension->GetType() != Manifest::TYPE_HOSTED_APP &&
2329 Manifest::IsExternalLocation(extension->location()) &&
[email protected]612a1cb12012-10-17 13:18:032330 !extension_prefs_->IsExternalExtensionAcknowledged(extension->id())) {
binjin47947f842014-11-18 12:10:242331 return Extension::DISABLE_EXTERNAL_EXTENSION;
[email protected]612a1cb12012-10-17 13:18:032332 }
2333 }
[email protected]612a1cb12012-10-17 13:18:032334
binjin47947f842014-11-18 12:10:242335 return Extension::DISABLE_NONE;
[email protected]612a1cb12012-10-17 13:18:032336}
[email protected]0db124b02012-11-07 04:55:052337
mlerman6a37b6a42014-11-26 22:10:532338// Helper method to determine if an extension can be blocked.
2339bool ExtensionService::CanBlockExtension(const Extension* extension) const {
mlerman3690e5be2014-12-01 22:57:442340 DCHECK(extension);
mlerman6a37b6a42014-11-26 22:10:532341 return extension->location() != Manifest::COMPONENT &&
2342 extension->location() != Manifest::EXTERNAL_COMPONENT &&
2343 !system_->management_policy()->MustRemainEnabled(extension, NULL);
2344}
2345
[email protected]e7aa7b7e2012-11-27 04:51:222346bool ExtensionService::ShouldDelayExtensionUpdate(
2347 const std::string& extension_id,
[email protected]4a1d9c0d2014-06-13 12:50:112348 bool install_immediately) const {
[email protected]e7aa7b7e2012-11-27 04:51:222349 const char kOnUpdateAvailableEvent[] = "runtime.onUpdateAvailable";
2350
2351 // If delayed updates are globally disabled, or just for this extension,
2352 // don't delay.
[email protected]4a1d9c0d2014-06-13 12:50:112353 if (!install_updates_when_idle_ || install_immediately)
[email protected]e7aa7b7e2012-11-27 04:51:222354 return false;
2355
[email protected]695b5712012-12-06 23:55:282356 const Extension* old = GetInstalledExtension(extension_id);
[email protected]e7aa7b7e2012-11-27 04:51:222357 // If there is no old extension, this is not an update, so don't delay.
2358 if (!old)
2359 return false;
2360
[email protected]9367eabc2013-03-01 01:29:292361 if (extensions::BackgroundInfo::HasPersistentBackgroundPage(old)) {
[email protected]e7aa7b7e2012-11-27 04:51:222362 // Delay installation if the extension listens for the onUpdateAvailable
2363 // event.
2364 return system_->event_router()->ExtensionHasEventListener(
2365 extension_id, kOnUpdateAvailableEvent);
2366 } else {
2367 // Delay installation if the extension is not idle.
[email protected]1d5cf4142014-01-24 18:25:222368 return !extensions::util::IsExtensionIdle(extension_id, profile_);
[email protected]e7aa7b7e2012-11-27 04:51:222369 }
[email protected]0db124b02012-11-07 04:55:052370}
[email protected]fdd679b2012-11-15 20:49:392371
[email protected]e5f8fffe2014-04-02 00:30:442372void ExtensionService::OnGarbageCollectIsolatedStorageStart() {
2373 DCHECK(!installs_delayed_for_gc_);
2374 installs_delayed_for_gc_ = true;
[email protected]399583b2012-12-11 09:33:422375}
2376
2377void ExtensionService::OnGarbageCollectIsolatedStorageFinished() {
[email protected]e5f8fffe2014-04-02 00:30:442378 DCHECK(installs_delayed_for_gc_);
2379 installs_delayed_for_gc_ = false;
[email protected]9f4e4f082013-06-21 07:11:192380 MaybeFinishDelayedInstallations();
2381}
2382
2383void ExtensionService::MaybeFinishDelayedInstallations() {
2384 std::vector<std::string> to_be_installed;
[email protected]399583b2012-12-11 09:33:422385 for (ExtensionSet::const_iterator it = delayed_installs_.begin();
2386 it != delayed_installs_.end();
2387 ++it) {
[email protected]9f4e4f082013-06-21 07:11:192388 to_be_installed.push_back((*it)->id());
[email protected]399583b2012-12-11 09:33:422389 }
[email protected]9f4e4f082013-06-21 07:11:192390 for (std::vector<std::string>::const_iterator it = to_be_installed.begin();
2391 it != to_be_installed.end();
[email protected]399583b2012-12-11 09:33:422392 ++it) {
[email protected]9f4e4f082013-06-21 07:11:192393 MaybeFinishDelayedInstallation(*it);
[email protected]399583b2012-12-11 09:33:422394 }
[email protected]399583b2012-12-11 09:33:422395}
2396
[email protected]fdd679b2012-11-15 20:49:392397void ExtensionService::OnBlacklistUpdated() {
[email protected]2d19eb6e2014-01-27 17:30:002398 blacklist_->GetBlacklistedIDs(
[email protected]f47f7172014-03-19 19:27:102399 registry_->GenerateInstalledExtensionsSet()->GetIDs(),
[email protected]3f2a2fa2013-09-24 02:55:252400 base::Bind(&ExtensionService::ManageBlacklist, AsWeakPtr()));
[email protected]695b5712012-12-06 23:55:282401}
2402
[email protected]2d19eb6e2014-01-27 17:30:002403void ExtensionService::ManageBlacklist(
2404 const extensions::Blacklist::BlacklistStateMap& state_map) {
[email protected]54ee8192014-03-29 17:37:242405 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]695b5712012-12-06 23:55:282406
mlerman6a37b6a42014-11-26 22:10:532407 std::set<std::string> blacklisted;
[email protected]2d19eb6e2014-01-27 17:30:002408 ExtensionIdSet greylist;
2409 ExtensionIdSet unchanged;
2410 for (extensions::Blacklist::BlacklistStateMap::const_iterator it =
2411 state_map.begin();
2412 it != state_map.end();
2413 ++it) {
2414 switch (it->second) {
2415 case extensions::NOT_BLACKLISTED:
2416 break;
[email protected]695b5712012-12-06 23:55:282417
[email protected]2d19eb6e2014-01-27 17:30:002418 case extensions::BLACKLISTED_MALWARE:
mlerman6a37b6a42014-11-26 22:10:532419 blacklisted.insert(it->first);
[email protected]2d19eb6e2014-01-27 17:30:002420 break;
2421
2422 case extensions::BLACKLISTED_SECURITY_VULNERABILITY:
2423 case extensions::BLACKLISTED_CWS_POLICY_VIOLATION:
2424 case extensions::BLACKLISTED_POTENTIALLY_UNWANTED:
2425 greylist.insert(it->first);
2426 break;
2427
2428 case extensions::BLACKLISTED_UNKNOWN:
2429 unchanged.insert(it->first);
2430 break;
2431 }
2432 }
2433
mlerman6a37b6a42014-11-26 22:10:532434 UpdateBlacklistedExtensions(blacklisted, unchanged);
[email protected]2d19eb6e2014-01-27 17:30:002435 UpdateGreylistedExtensions(greylist, unchanged, state_map);
2436
[email protected]373daf972014-04-10 01:50:442437 error_controller_->ShowErrorIfNeeded();
[email protected]2d19eb6e2014-01-27 17:30:002438}
2439
2440namespace {
2441void Partition(const ExtensionIdSet& before,
2442 const ExtensionIdSet& after,
2443 const ExtensionIdSet& unchanged,
2444 ExtensionIdSet* no_longer,
2445 ExtensionIdSet* not_yet) {
2446 *not_yet = base::STLSetDifference<ExtensionIdSet>(after, before);
2447 *no_longer = base::STLSetDifference<ExtensionIdSet>(before, after);
2448 *no_longer = base::STLSetDifference<ExtensionIdSet>(*no_longer, unchanged);
2449}
2450} // namespace
2451
mlerman6a37b6a42014-11-26 22:10:532452void ExtensionService::UpdateBlacklistedExtensions(
2453 const ExtensionIdSet& blacklisted,
[email protected]2d19eb6e2014-01-27 17:30:002454 const ExtensionIdSet& unchanged) {
2455 ExtensionIdSet not_yet_blocked, no_longer_blocked;
mlerman6a37b6a42014-11-26 22:10:532456 Partition(registry_->blacklisted_extensions().GetIDs(), blacklisted,
2457 unchanged, &no_longer_blocked, &not_yet_blocked);
[email protected]2d19eb6e2014-01-27 17:30:002458
2459 for (ExtensionIdSet::iterator it = no_longer_blocked.begin();
2460 it != no_longer_blocked.end(); ++it) {
[email protected]695b5712012-12-06 23:55:282461 scoped_refptr<const Extension> extension =
[email protected]bb1bc9b32013-12-21 03:09:142462 registry_->blacklisted_extensions().GetByID(*it);
[email protected]3f2a2fa2013-09-24 02:55:252463 if (!extension.get()) {
mlerman6a37b6a42014-11-26 22:10:532464 NOTREACHED() << "Extension " << *it << " no longer blacklisted, "
2465 << "but it was never blacklisted.";
[email protected]695b5712012-12-06 23:55:282466 continue;
[email protected]3f2a2fa2013-09-24 02:55:252467 }
[email protected]bb1bc9b32013-12-21 03:09:142468 registry_->RemoveBlacklisted(*it);
[email protected]3f2a2fa2013-09-24 02:55:252469 extension_prefs_->SetExtensionBlacklisted(extension->id(), false);
[email protected]dc24976f2013-06-02 21:15:092470 AddExtension(extension.get());
[email protected]ac875372013-02-28 04:36:092471 UMA_HISTOGRAM_ENUMERATION("ExtensionBlacklist.UnblacklistInstalled",
[email protected]dc24976f2013-06-02 21:15:092472 extension->location(),
2473 Manifest::NUM_LOCATIONS);
[email protected]695b5712012-12-06 23:55:282474 }
2475
[email protected]2d19eb6e2014-01-27 17:30:002476 for (ExtensionIdSet::iterator it = not_yet_blocked.begin();
2477 it != not_yet_blocked.end(); ++it) {
[email protected]695b5712012-12-06 23:55:282478 scoped_refptr<const Extension> extension = GetInstalledExtension(*it);
[email protected]3f2a2fa2013-09-24 02:55:252479 if (!extension.get()) {
2480 NOTREACHED() << "Extension " << *it << " needs to be "
2481 << "blacklisted, but it's not installed.";
[email protected]695b5712012-12-06 23:55:282482 continue;
[email protected]3f2a2fa2013-09-24 02:55:252483 }
[email protected]bb1bc9b32013-12-21 03:09:142484 registry_->AddBlacklisted(extension);
[email protected]2d19eb6e2014-01-27 17:30:002485 extension_prefs_->SetExtensionBlacklistState(
2486 extension->id(), extensions::BLACKLISTED_MALWARE);
[email protected]b0af4792013-10-23 09:12:132487 UnloadExtension(*it, UnloadedExtensionInfo::REASON_BLACKLIST);
[email protected]ac875372013-02-28 04:36:092488 UMA_HISTOGRAM_ENUMERATION("ExtensionBlacklist.BlacklistInstalled",
2489 extension->location(), Manifest::NUM_LOCATIONS);
[email protected]695b5712012-12-06 23:55:282490 }
[email protected]2d19eb6e2014-01-27 17:30:002491}
[email protected]695b5712012-12-06 23:55:282492
[email protected]2d19eb6e2014-01-27 17:30:002493// TODO(oleg): UMA logging
2494void ExtensionService::UpdateGreylistedExtensions(
2495 const ExtensionIdSet& greylist,
2496 const ExtensionIdSet& unchanged,
2497 const extensions::Blacklist::BlacklistStateMap& state_map) {
2498 ExtensionIdSet not_yet_greylisted, no_longer_greylisted;
2499 Partition(greylist_.GetIDs(),
2500 greylist, unchanged,
2501 &no_longer_greylisted, &not_yet_greylisted);
2502
2503 for (ExtensionIdSet::iterator it = no_longer_greylisted.begin();
2504 it != no_longer_greylisted.end(); ++it) {
2505 scoped_refptr<const Extension> extension = greylist_.GetByID(*it);
2506 if (!extension.get()) {
2507 NOTREACHED() << "Extension " << *it << " no longer greylisted, "
2508 << "but it was not marked as greylisted.";
2509 continue;
2510 }
2511
2512 greylist_.Remove(*it);
2513 extension_prefs_->SetExtensionBlacklistState(extension->id(),
2514 extensions::NOT_BLACKLISTED);
2515 if (extension_prefs_->GetDisableReasons(extension->id()) &
2516 extensions::Extension::DISABLE_GREYLIST)
2517 EnableExtension(*it);
2518 }
2519
2520 for (ExtensionIdSet::iterator it = not_yet_greylisted.begin();
2521 it != not_yet_greylisted.end(); ++it) {
2522 scoped_refptr<const Extension> extension = GetInstalledExtension(*it);
2523 if (!extension.get()) {
2524 NOTREACHED() << "Extension " << *it << " needs to be "
2525 << "disabled, but it's not installed.";
2526 continue;
2527 }
2528 greylist_.Insert(extension);
2529 extension_prefs_->SetExtensionBlacklistState(extension->id(),
2530 state_map.find(*it)->second);
2531 if (registry_->enabled_extensions().Contains(extension->id()))
2532 DisableExtension(*it, extensions::Extension::DISABLE_GREYLIST);
2533 }
[email protected]fdd679b2012-11-15 20:49:392534}
[email protected]75bdcb872013-03-13 00:41:452535
2536void ExtensionService::AddUpdateObserver(extensions::UpdateObserver* observer) {
2537 update_observers_.AddObserver(observer);
2538}
2539
2540void ExtensionService::RemoveUpdateObserver(
2541 extensions::UpdateObserver* observer) {
2542 update_observers_.RemoveObserver(observer);
2543}
[email protected]bb1bc9b32013-12-21 03:09:142544
2545// Used only by test code.
2546void ExtensionService::UnloadAllExtensionsInternal() {
2547 profile_->GetExtensionSpecialStoragePolicy()->RevokeRightsForAllExtensions();
2548
2549 registry_->ClearAll();
[email protected]45f5b7d2014-01-22 23:47:132550 system_->runtime_data()->ClearAll();
[email protected]bb1bc9b32013-12-21 03:09:142551
2552 // TODO(erikkay) should there be a notification for this? We can't use
2553 // EXTENSION_UNLOADED since that implies that the extension has been disabled
2554 // or uninstalled.
2555}
[email protected]ebe07772014-05-22 04:16:062556
2557void ExtensionService::OnProfileDestructionStarted() {
2558 ExtensionIdSet ids_to_unload = registry_->enabled_extensions().GetIDs();
2559 for (ExtensionIdSet::iterator it = ids_to_unload.begin();
2560 it != ids_to_unload.end();
2561 ++it) {
2562 UnloadExtension(*it, UnloadedExtensionInfo::REASON_PROFILE_SHUTDOWN);
2563 }
2564}