blob: 865540f35b939a2782ea01d38e5a4c3b51d07697 [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"
[email protected]15730c42009-09-03 00:03:2019#include "chrome/browser/browser_process.h"
[email protected]9ea0cd32013-07-12 01:50:3620#include "chrome/browser/chrome_notification_types.h"
mukai87a8d402014-09-15 20:15:0921#include "chrome/browser/content_settings/content_settings_custom_extension_provider.h"
22#include "chrome/browser/content_settings/content_settings_internal_extension_provider.h"
23#include "chrome/browser/content_settings/host_content_settings_map.h"
24#include "chrome/browser/extensions/api/content_settings/content_settings_service.h"
[email protected]d8c8f25f2011-11-02 18:18:0125#include "chrome/browser/extensions/component_loader.h"
[email protected]13e062e2014-08-09 10:21:5526#include "chrome/browser/extensions/crx_installer.h"
[email protected]d9ede582012-08-14 19:21:3827#include "chrome/browser/extensions/data_deleter.h"
rdevlin.cronin2813c1b2014-08-26 23:51:0828#include "chrome/browser/extensions/extension_action_storage_manager.h"
[email protected]5a145e82014-05-29 22:19:0729#include "chrome/browser/extensions/extension_assets_manager.h"
[email protected]62f051c2012-03-29 17:04:4430#include "chrome/browser/extensions/extension_disabled_ui.h"
[email protected]373daf972014-04-10 01:50:4431#include "chrome/browser/extensions/extension_error_controller.h"
[email protected]00b38242012-07-18 18:43:2232#include "chrome/browser/extensions/extension_install_ui.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"
kustermann98ff22a2014-10-13 13:39:0545#include "chrome/browser/extensions/updater/extension_cache.h"
[email protected]02c967fe2014-08-12 14:48:4346#include "chrome/browser/extensions/updater/extension_downloader.h"
[email protected]13e062e2014-08-09 10:21:5547#include "chrome/browser/extensions/updater/extension_updater.h"
rockotdb5192992014-09-16 21:27:0248#include "chrome/browser/google/google_brand.h"
[email protected]8ecad5e2010-12-02 21:18:3349#include "chrome/browser/profiles/profile.h"
[email protected]b5a507b22013-11-08 20:41:5750#include "chrome/browser/ui/webui/extensions/extension_icon_source.h"
[email protected]c8d407e2011-04-28 21:27:1751#include "chrome/browser/ui/webui/favicon_source.h"
[email protected]5eddc3e2011-10-26 04:33:3152#include "chrome/browser/ui/webui/ntp/thumbnail_source.h"
[email protected]b07e606e2012-09-15 20:16:1553#include "chrome/browser/ui/webui/theme_source.h"
[email protected]e2eb43112009-05-29 21:19:5454#include "chrome/common/chrome_switches.h"
[email protected]f6431be82013-09-07 02:53:4555#include "chrome/common/crash_keys.h"
[email protected]9f4e4f082013-06-21 07:11:1956#include "chrome/common/extensions/extension_constants.h"
[email protected]15d4d2d2013-08-09 06:49:0357#include "chrome/common/extensions/features/feature_channel.h"
[email protected]65348062013-01-15 07:27:2258#include "chrome/common/extensions/manifest_url_handler.h"
[email protected]a57209872009-05-04 22:53:1459#include "chrome/common/url_constants.h"
[email protected]fdd28372014-08-21 02:27:2660#include "components/crx_file/id_util.h"
[email protected]7a83dd072013-09-03 12:09:1761#include "components/startup_metric_utils/startup_metric_utils.h"
[email protected]dccba4f82014-05-29 00:52:5662#include "content/public/browser/devtools_agent_host.h"
[email protected]05aad2da2011-10-28 10:12:3763#include "content/public/browser/notification_service.h"
[email protected]f3b1a082011-11-18 00:34:3064#include "content/public/browser/render_process_host.h"
[email protected]399583b2012-12-11 09:33:4265#include "content/public/browser/storage_partition.h"
[email protected]34423532013-11-21 18:13:1066#include "extensions/browser/event_router.h"
[email protected]22401dc2014-03-21 01:38:5767#include "extensions/browser/extension_host.h"
[email protected]dccba4f82014-05-29 00:52:5668#include "extensions/browser/extension_prefs.h"
[email protected]bb1bc9b32013-12-21 03:09:1469#include "extensions/browser/extension_registry.h"
[email protected]59b0e602014-01-30 00:41:2470#include "extensions/browser/extension_system.h"
[email protected]4a1d9c0d2014-06-13 12:50:1171#include "extensions/browser/install_flag.h"
[email protected]45f5b7d2014-01-22 23:47:1372#include "extensions/browser/runtime_data.h"
[email protected]e43c61f2014-07-20 21:46:3473#include "extensions/browser/uninstall_reason.h"
[email protected]a9aa62b312013-11-29 05:35:0674#include "extensions/browser/update_observer.h"
[email protected]fb820c02014-03-13 15:07:0875#include "extensions/common/extension_messages.h"
rockot90659852014-09-18 19:31:5276#include "extensions/common/extension_urls.h"
[email protected]5ef835a2013-11-08 20:42:5777#include "extensions/common/feature_switch.h"
[email protected]85df9d12014-04-15 17:02:1478#include "extensions/common/file_util.h"
[email protected]0c3c9732013-09-16 08:53:4179#include "extensions/common/manifest_constants.h"
[email protected]558878cc82013-11-09 01:25:5180#include "extensions/common/manifest_handlers/background_info.h"
[email protected]dccba4f82014-05-29 00:52:5681#include "extensions/common/one_shot_event.h"
[email protected]c41003472013-10-19 15:37:2582#include "extensions/common/permissions/permission_message_provider.h"
[email protected]e4452d32013-11-15 23:07:4183#include "extensions/common/permissions/permissions_data.h"
[email protected]79a60642012-10-20 21:03:1884
[email protected]eed367e2011-04-12 03:43:3185#if defined(OS_CHROMEOS)
[email protected]88e8ec9152013-01-17 04:05:1886#include "chrome/browser/chromeos/extensions/install_limiter.h"
pilgrime92c5fcd2014-09-10 23:31:2387#include "storage/browser/fileapi/file_system_backend.h"
88#include "storage/browser/fileapi/file_system_context.h"
[email protected]eed367e2011-04-12 03:43:3189#endif
90
[email protected]55eb70e762012-02-20 17:38:3991using content::BrowserContext;
[email protected]631bb742011-11-02 11:29:3992using content::BrowserThread;
[email protected]98f66112012-12-25 12:59:3693using content::DevToolsAgentHost;
[email protected]bf3d9df2012-07-24 23:20:2794using extensions::CrxInstaller;
[email protected]1c321ee52012-05-21 03:02:3495using extensions::Extension;
96using extensions::ExtensionIdSet;
97using extensions::ExtensionInfo;
[email protected]599539802014-01-07 23:06:0098using extensions::ExtensionRegistry;
[email protected]289c44b2013-12-17 03:26:5799using extensions::ExtensionSet;
[email protected]215a7be2012-10-22 19:53:42100using extensions::FeatureSwitch;
[email protected]ffd2f79e2013-11-14 00:11:46101using extensions::InstallVerifier;
[email protected]0d54b682013-11-05 14:15:36102using extensions::ManagementPolicy;
[email protected]1d5e58b2013-01-31 08:41:40103using extensions::Manifest;
[email protected]c2e66e12012-06-27 06:27:06104using extensions::PermissionMessage;
105using extensions::PermissionMessages;
106using extensions::PermissionSet;
[email protected]9f4e4f082013-06-21 07:11:19107using extensions::SharedModuleInfo;
[email protected]90878c52014-04-04 18:21:02108using extensions::SharedModuleService;
[email protected]e410b5f2012-12-14 14:02:24109using extensions::UnloadedExtensionInfo;
[email protected]5ef47ec2010-01-28 05:58:05110
[email protected]0c3c9732013-09-16 08:53:41111namespace errors = extensions::manifest_errors;
[email protected]c6d474f82009-12-16 21:11:06112
[email protected]b6ab96d2009-08-20 18:58:19113namespace {
114
[email protected]0db124b02012-11-07 04:55:05115// Wait this many seconds after an extensions becomes idle before updating it.
[email protected]ddc6a122014-06-27 04:52:32116const int kUpdateIdleDelay = 5;
[email protected]0db124b02012-11-07 04:55:05117
[email protected]c6d474f82009-12-16 21:11:06118} // namespace
[email protected]b6ab96d2009-08-20 18:58:19119
[email protected]eaa7dd182010-12-14 11:09:00120// ExtensionService.
[email protected]6014d672008-12-05 00:38:25121
[email protected]8e4560b62011-01-14 10:09:14122void ExtensionService::CheckExternalUninstall(const std::string& id) {
[email protected]a29a517a2011-01-21 21:11:12123 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]a8af9fdb2010-10-28 21:52:20124
[email protected]7a4c6852010-09-16 03:44:22125 // Check if the providers know about this extension.
[email protected]5df038b2012-07-16 19:03:27126 extensions::ProviderCollection::const_iterator i;
[email protected]0a60a2e2010-10-25 16:15:21127 for (i = external_extension_providers_.begin();
128 i != external_extension_providers_.end(); ++i) {
[email protected]8e4560b62011-01-14 10:09:14129 DCHECK(i->get()->IsReady());
[email protected]0a60a2e2010-10-25 16:15:21130 if (i->get()->HasExtension(id))
131 return; // Yup, known extension, don't uninstall.
[email protected]7a4c6852010-09-16 03:44:22132 }
133
[email protected]0f48fca2011-05-19 18:46:35134 // We get the list of external extensions to check from preferences.
135 // It is possible that an extension has preferences but is not loaded.
136 // For example, an extension that requires experimental permissions
137 // will not be loaded if the experimental command line flag is not used.
138 // In this case, do not uninstall.
[email protected]31bb5ee62012-09-12 22:58:40139 if (!GetInstalledExtension(id)) {
[email protected]0f48fca2011-05-19 18:46:35140 // We can't call UninstallExtension with an unloaded/invalid
141 // extension ID.
142 LOG(WARNING) << "Attempted uninstallation of unloaded/invalid extension "
143 << "with id: " << id;
144 return;
145 }
[email protected]42d58f62014-07-31 01:32:45146 UninstallExtension(id,
147 extensions::UNINSTALL_REASON_ORPHANED_EXTERNAL_EXTENSION,
148 base::Bind(&base::DoNothing),
149 NULL);
[email protected]7a4c6852010-09-16 03:44:22150}
151
[email protected]7f8f24f2012-11-15 19:40:14152void ExtensionService::SetFileTaskRunnerForTesting(
dcheng605ef8d2014-08-28 18:29:44153 const scoped_refptr<base::SequencedTaskRunner>& task_runner) {
[email protected]7f8f24f2012-11-15 19:40:14154 file_task_runner_ = task_runner;
155}
156
[email protected]8e4560b62011-01-14 10:09:14157void ExtensionService::ClearProvidersForTesting() {
[email protected]7a4c6852010-09-16 03:44:22158 external_extension_providers_.clear();
159}
160
[email protected]8e4560b62011-01-14 10:09:14161void ExtensionService::AddProviderForTesting(
[email protected]5df038b2012-07-16 19:03:27162 extensions::ExternalProviderInterface* test_provider) {
[email protected]a29a517a2011-01-21 21:11:12163 CHECK(test_provider);
[email protected]0a60a2e2010-10-25 16:15:21164 external_extension_providers_.push_back(
[email protected]5df038b2012-07-16 19:03:27165 linked_ptr<extensions::ExternalProviderInterface>(test_provider));
[email protected]7a4c6852010-09-16 03:44:22166}
167
[email protected]8f959f522014-08-06 06:26:28168void ExtensionService::BlacklistExtensionForTest(
169 const std::string& extension_id) {
170 ExtensionIdSet blocked;
171 ExtensionIdSet unchanged;
172 blocked.insert(extension_id);
173 UpdateBlockedExtensions(blocked, unchanged);
174}
175
[email protected]9060d8b02012-01-13 02:14:30176bool ExtensionService::OnExternalExtensionUpdateUrlFound(
[email protected]7a4c6852010-09-16 03:44:22177 const std::string& id,
[email protected]d8fd0fd2014-03-24 13:16:06178 const std::string& install_parameter,
[email protected]21a5a672010-11-04 10:47:42179 const GURL& update_url,
[email protected]464213a2013-10-15 01:06:48180 Manifest::Location location,
181 int creation_flags,
182 bool mark_acknowledged) {
[email protected]ab22ba42011-01-14 16:36:38183 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]fdd28372014-08-21 02:27:26184 CHECK(crx_file::id_util::IdIsValid(id));
[email protected]a8af9fdb2010-10-28 21:52:20185
[email protected]044e86992014-01-24 22:59:11186 if (Manifest::IsExternalLocation(location)) {
187 // All extensions that are not user specific can be cached.
kustermann98ff22a2014-10-13 13:39:05188 extensions::ExtensionCache::GetInstance()->AllowCaching(id);
[email protected]044e86992014-01-24 22:59:11189 }
190
[email protected]8a87a5332011-08-11 17:54:59191 const Extension* extension = GetExtensionById(id, true);
192 if (extension) {
193 // Already installed. Skip this install if the current location has
194 // higher priority than |location|.
[email protected]1d5e58b2013-01-31 08:41:40195 Manifest::Location current = extension->location();
196 if (current == Manifest::GetHigherPriorityLocation(current, location))
[email protected]9060d8b02012-01-13 02:14:30197 return false;
[email protected]8a87a5332011-08-11 17:54:59198 // Otherwise, overwrite the current installation.
[email protected]7a4c6852010-09-16 03:44:22199 }
[email protected]9060d8b02012-01-13 02:14:30200
201 // Add |id| to the set of pending extensions. If it can not be added,
202 // then there is already a pending record from a higher-priority install
203 // source. In this case, signal that this extension will not be
204 // installed by returning false.
205 if (!pending_extension_manager()->AddFromExternalUpdateUrl(
[email protected]d8fd0fd2014-03-24 13:16:06206 id,
207 install_parameter,
208 update_url,
209 location,
210 creation_flags,
211 mark_acknowledged)) {
[email protected]9060d8b02012-01-13 02:14:30212 return false;
[email protected]31bb5ee62012-09-12 22:58:40213 }
[email protected]9060d8b02012-01-13 02:14:30214
[email protected]94fde232012-04-27 10:22:30215 update_once_all_providers_are_ready_ = true;
[email protected]9060d8b02012-01-13 02:14:30216 return true;
[email protected]7a4c6852010-09-16 03:44:22217}
218
[email protected]6aeac8342010-10-01 20:21:18219// static
[email protected]cc2f55c2014-07-08 02:19:04220// This function is used to uninstall an extension via sync. The LOG statements
221// within this function are used to inform the user if the uninstall cannot be
222// done.
[email protected]eaa7dd182010-12-14 11:09:00223bool ExtensionService::UninstallExtensionHelper(
224 ExtensionService* extensions_service,
[email protected]cc2f55c2014-07-08 02:19:04225 const std::string& extension_id,
[email protected]e43c61f2014-07-20 21:46:34226 extensions::UninstallReason reason) {
[email protected]d6ebc9792011-04-07 18:18:33227 // We can't call UninstallExtension with an invalid extension ID.
[email protected]31bb5ee62012-09-12 22:58:40228 if (!extensions_service->GetInstalledExtension(extension_id)) {
[email protected]6aeac8342010-10-01 20:21:18229 LOG(WARNING) << "Attempted uninstallation of non-existent extension with "
[email protected]95da88c42011-03-31 10:07:33230 << "id: " << extension_id;
231 return false;
[email protected]6aeac8342010-10-01 20:21:18232 }
233
[email protected]d6ebc9792011-04-07 18:18:33234 // The following call to UninstallExtension will not allow an uninstall of a
235 // policy-controlled extension.
[email protected]439f1e32013-12-09 20:09:09236 base::string16 error;
[email protected]42d58f62014-07-31 01:32:45237 if (!extensions_service->UninstallExtension(
238 extension_id, reason, base::Bind(&base::DoNothing), &error)) {
[email protected]d6ebc9792011-04-07 18:18:33239 LOG(WARNING) << "Cannot uninstall extension with id " << extension_id
240 << ": " << error;
241 return false;
242 }
[email protected]95da88c42011-03-31 10:07:33243
[email protected]6aeac8342010-10-01 20:21:18244 return true;
245}
246
[email protected]eaa7dd182010-12-14 11:09:00247ExtensionService::ExtensionService(Profile* profile,
[email protected]f0841cd2011-01-19 15:07:24248 const CommandLine* command_line,
[email protected]650b2d52013-02-10 03:41:45249 const base::FilePath& install_directory,
[email protected]45759612012-07-10 17:21:23250 extensions::ExtensionPrefs* extension_prefs,
[email protected]fdd679b2012-11-15 20:49:39251 extensions::Blacklist* blacklist,
[email protected]0436b102011-04-15 18:30:03252 bool autoupdate_enabled,
[email protected]4a10006a2013-05-17 23:18:35253 bool extensions_enabled,
254 extensions::OneShotEvent* ready)
[email protected]fdd679b2012-11-15 20:49:39255 : extensions::Blacklist::Observer(blacklist),
256 profile_(profile),
[email protected]bd306722012-07-11 20:43:59257 system_(extensions::ExtensionSystem::Get(profile)),
[email protected]73c47932010-12-06 18:13:43258 extension_prefs_(extension_prefs),
[email protected]695b5712012-12-06 23:55:28259 blacklist_(blacklist),
[email protected]f8aefb132013-10-30 09:29:52260 extension_sync_service_(NULL),
[email protected]5fdfa562013-12-27 17:43:59261 registry_(extensions::ExtensionRegistry::Get(profile)),
[email protected]6c9bedf2014-05-21 03:55:51262 pending_extension_manager_(profile),
[email protected]a9b00ac2009-06-25 21:03:23263 install_directory_(install_directory),
[email protected]0436b102011-04-15 18:30:03264 extensions_enabled_(extensions_enabled),
[email protected]e81dba32009-06-19 20:19:13265 show_extensions_prompts_(true),
[email protected]fc332ae2012-11-14 20:17:33266 install_updates_when_idle_(true),
[email protected]4a10006a2013-05-17 23:18:35267 ready_(ready),
[email protected]dff1e042012-04-27 10:59:18268 update_once_all_providers_are_ready_(false),
[email protected]3c4abc82012-10-22 22:25:54269 browser_terminating_(false),
[email protected]9f4e4f082013-06-21 07:11:19270 installs_delayed_for_gc_(false),
[email protected]e5f8fffe2014-04-02 00:30:44271 is_first_run_(false),
[email protected]90878c52014-04-04 18:21:02272 shared_module_service_(new extensions::SharedModuleService(profile_)) {
[email protected]a29a517a2011-01-21 21:11:12273 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]a8af9fdb2010-10-28 21:52:20274
[email protected]36a784c2009-06-23 06:21:08275 // Figure out if extension installation should be enabled.
[email protected]367d9b172013-12-03 00:31:02276 if (extensions::ExtensionsBrowserClient::Get()->AreExtensionsDisabled(
277 *command_line, profile))
[email protected]6d60703b2009-08-29 01:29:23278 extensions_enabled_ = false;
[email protected]36a784c2009-06-23 06:21:08279
[email protected]3c4abc82012-10-22 22:25:54280 registrar_.Add(this, chrome::NOTIFICATION_APP_TERMINATING,
281 content::NotificationService::AllBrowserContextsAndSources());
[email protected]adf5a102014-07-31 12:44:06282 registrar_.Add(this,
283 extensions::NOTIFICATION_EXTENSION_PROCESS_TERMINATED,
[email protected]ad50def52011-10-19 23:17:07284 content::NotificationService::AllBrowserContextsAndSources());
[email protected]432115822011-07-10 15:52:27285 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_TERMINATED,
[email protected]ad50def52011-10-19 23:17:07286 content::NotificationService::AllBrowserContextsAndSources());
[email protected]92dd8d92013-02-26 00:41:08287 registrar_.Add(this, chrome::NOTIFICATION_UPGRADE_RECOMMENDED,
288 content::NotificationService::AllBrowserContextsAndSources());
[email protected]ebe07772014-05-22 04:16:06289 registrar_.Add(this,
290 chrome::NOTIFICATION_PROFILE_DESTRUCTION_STARTED,
291 content::Source<Profile>(profile_));
binjin1569c9b2014-09-05 13:33:18292
293 extensions::ExtensionManagementFactory::GetForBrowserContext(profile_)
294 ->AddObserver(this);
[email protected]4814b512009-11-07 00:12:29295
[email protected]93fd78f42009-07-10 16:43:17296 // Set up the ExtensionUpdater
297 if (autoupdate_enabled) {
[email protected]501105b2013-09-26 05:42:02298 int update_frequency = extensions::kDefaultUpdateFrequencySeconds;
[email protected]93fd78f42009-07-10 16:43:17299 if (command_line->HasSwitch(switches::kExtensionsUpdateFrequency)) {
[email protected]e83326f2010-07-31 17:29:25300 base::StringToInt(command_line->GetSwitchValueASCII(
301 switches::kExtensionsUpdateFrequency),
302 &update_frequency);
[email protected]93fd78f42009-07-10 16:43:17303 }
[email protected]044e86992014-01-24 22:59:11304 updater_.reset(new extensions::ExtensionUpdater(
305 this,
306 extension_prefs,
307 profile->GetPrefs(),
308 profile,
309 update_frequency,
kustermann98ff22a2014-10-13 13:39:05310 extensions::ExtensionCache::GetInstance(),
rockotdb5192992014-09-16 21:27:02311 base::Bind(ChromeExtensionDownloaderFactory::CreateForProfile,
312 profile)));
[email protected]93fd78f42009-07-10 16:43:17313 }
314
[email protected]25ae0152011-11-18 14:40:02315 component_loader_.reset(
316 new extensions::ComponentLoader(this,
317 profile->GetPrefs(),
[email protected]55e16cd2013-12-18 04:36:08318 g_browser_process->local_state(),
319 profile));
[email protected]8e4560b62011-01-14 10:09:14320
[email protected]0436b102011-04-15 18:30:03321 if (extensions_enabled_) {
[email protected]ae4c37e2012-12-21 01:16:25322 extensions::ExternalProviderImpl::CreateExternalProviders(
323 this, profile_, &external_extension_providers_);
[email protected]873531342011-03-09 12:16:05324 }
[email protected]b671760b2010-07-15 21:13:47325
[email protected]74474042013-11-21 12:03:54326 // Set this as the ExtensionService for app sorting to ensure it causes syncs
327 // if required.
[email protected]b3aa7182013-04-25 04:45:23328 is_first_run_ = !extension_prefs_->SetAlertSystemFirstRun();
329
[email protected]373daf972014-04-10 01:50:44330 error_controller_.reset(
331 new extensions::ExtensionErrorController(profile_, is_first_run_));
[email protected]374ceb6f2014-07-02 19:25:34332 external_install_manager_.reset(
333 new extensions::ExternalInstallManager(profile_, is_first_run_));
[email protected]373daf972014-04-10 01:50:44334
[email protected]c77f2352012-08-08 22:07:58335 extension_action_storage_manager_.reset(
336 new extensions::ExtensionActionStorageManager(profile_));
337
[email protected]cb0e50312011-05-09 15:03:07338 // How long is the path to the Extensions directory?
339 UMA_HISTOGRAM_CUSTOM_COUNTS("Extensions.ExtensionRootPathLength",
340 install_directory_.value().length(), 0, 500, 100);
[email protected]6014d672008-12-05 00:38:25341}
342
[email protected]84df8332011-12-06 18:22:46343const ExtensionSet* ExtensionService::extensions() const {
[email protected]bb1bc9b32013-12-21 03:09:14344 return &registry_->enabled_extensions();
[email protected]ddb1e5a2010-12-13 20:10:45345}
346
[email protected]3f213ad2012-07-26 23:39:41347extensions::PendingExtensionManager*
348 ExtensionService::pending_extension_manager() {
[email protected]b2907fd2011-03-25 16:43:37349 return &pending_extension_manager_;
[email protected]ddb1e5a2010-12-13 20:10:45350}
351
[email protected]eaa7dd182010-12-14 11:09:00352ExtensionService::~ExtensionService() {
[email protected]c8d407e2011-04-28 21:27:17353 // No need to unload extensions here because they are profile-scoped, and the
354 // profile is in the process of being deleted.
[email protected]94b4ffc2011-02-04 05:55:17355
[email protected]5df038b2012-07-16 19:03:27356 extensions::ProviderCollection::const_iterator i;
[email protected]8e4560b62011-01-14 10:09:14357 for (i = external_extension_providers_.begin();
358 i != external_extension_providers_.end(); ++i) {
[email protected]5df038b2012-07-16 19:03:27359 extensions::ExternalProviderInterface* provider = i->get();
[email protected]8e4560b62011-01-14 10:09:14360 provider->ServiceShutdown();
361 }
[email protected]6014d672008-12-05 00:38:25362}
363
[email protected]037228a2012-10-05 01:36:16364void ExtensionService::Shutdown() {
binjin1569c9b2014-09-05 13:33:18365 extensions::ExtensionManagementFactory::GetInstance()
366 ->GetForBrowserContext(profile())
367 ->RemoveObserver(this);
[email protected]4c9201c42013-08-16 04:56:21368 system_->management_policy()->UnregisterProvider(
369 shared_module_policy_provider_.get());
[email protected]037228a2012-10-05 01:36:16370}
371
[email protected]b2907fd2011-03-25 16:43:37372const Extension* ExtensionService::GetExtensionById(
373 const std::string& id, bool include_disabled) const {
[email protected]599539802014-01-07 23:06:00374 int include_mask = ExtensionRegistry::ENABLED;
[email protected]695b5712012-12-06 23:55:28375 if (include_disabled) {
376 // Include blacklisted extensions here because there are hundreds of
377 // callers of this function, and many might assume that this includes those
378 // that have been disabled due to blacklisting.
[email protected]599539802014-01-07 23:06:00379 include_mask |= ExtensionRegistry::DISABLED |
380 ExtensionRegistry::BLACKLISTED;
[email protected]695b5712012-12-06 23:55:28381 }
[email protected]599539802014-01-07 23:06:00382 return registry_->GetExtensionById(id, include_mask);
[email protected]695b5712012-12-06 23:55:28383}
384
[email protected]eaa7dd182010-12-14 11:09:00385void ExtensionService::Init() {
[email protected]a29a517a2011-01-21 21:11:12386 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]a8af9fdb2010-10-28 21:52:20387
[email protected]3350d712013-11-18 09:32:24388 base::Time begin_time = base::Time::Now();
389
[email protected]4a10006a2013-05-17 23:18:35390 DCHECK(!is_ready()); // Can't redo init.
[email protected]bb1bc9b32013-12-21 03:09:14391 DCHECK_EQ(registry_->enabled_extensions().size(), 0u);
[email protected]9f1087e2009-06-15 17:29:32392
[email protected]820d9bd2013-04-03 03:46:03393 const CommandLine* cmd_line = CommandLine::ForCurrentProcess();
rdevlin.cronin462b2fb2014-10-02 18:32:52394 if (cmd_line->HasSwitch(switches::kInstallEphemeralAppFromWebstore)) {
[email protected]820d9bd2013-04-03 03:46:03395 // The sole purpose of this launch is to install a new extension from CWS
396 // and immediately terminate: loading already installed extensions is
397 // unnecessary and may interfere with the inline install dialog (e.g. if an
398 // extension listens to onStartup and opens a window).
399 SetReadyAndNotifyListeners();
[email protected]ae4c37e2012-12-21 01:16:25400 } else {
[email protected]47b60072013-06-20 10:35:56401 // LoadAllExtensions() calls OnLoadedInstalledExtensions().
402 component_loader_->LoadAll();
403 extensions::InstalledLoader(this).LoadAllExtensions();
[email protected]9f4e4f082013-06-21 07:11:19404
[email protected]2edd57852013-08-14 22:07:40405 // Attempt to re-enable extensions whose only disable reason is reloading.
406 std::vector<std::string> extensions_to_enable;
[email protected]bb1bc9b32013-12-21 03:09:14407 const ExtensionSet& disabled_extensions = registry_->disabled_extensions();
408 for (ExtensionSet::const_iterator iter = disabled_extensions.begin();
409 iter != disabled_extensions.end(); ++iter) {
[email protected]2edd57852013-08-14 22:07:40410 const Extension* e = iter->get();
411 if (extension_prefs_->GetDisableReasons(e->id()) ==
412 Extension::DISABLE_RELOAD) {
413 extensions_to_enable.push_back(e->id());
414 }
415 }
416 for (std::vector<std::string>::iterator it = extensions_to_enable.begin();
417 it != extensions_to_enable.end(); ++it) {
418 EnableExtension(*it);
419 }
420
[email protected]9f4e4f082013-06-21 07:11:19421 // Finish install (if possible) of extensions that were still delayed while
422 // the browser was shut down.
423 scoped_ptr<extensions::ExtensionPrefs::ExtensionsInfo> delayed_info(
424 extension_prefs_->GetAllDelayedInstallInfo());
425 for (size_t i = 0; i < delayed_info->size(); ++i) {
426 ExtensionInfo* info = delayed_info->at(i).get();
427 scoped_refptr<const Extension> extension(NULL);
428 if (info->extension_manifest) {
429 std::string error;
430 extension = Extension::Create(
431 info->extension_path,
432 info->extension_location,
433 *info->extension_manifest,
434 extension_prefs_->GetDelayedInstallCreationFlags(
435 info->extension_id),
436 info->extension_id,
437 &error);
438 if (extension.get())
439 delayed_installs_.Insert(extension);
440 }
441 }
442 MaybeFinishDelayedInstallations();
443
444 scoped_ptr<extensions::ExtensionPrefs::ExtensionsInfo> delayed_info2(
445 extension_prefs_->GetAllDelayedInstallInfo());
446 UMA_HISTOGRAM_COUNTS_100("Extensions.UpdateOnLoad",
447 delayed_info2->size() - delayed_info->size());
448
[email protected]47b60072013-06-20 10:35:56449 SetReadyAndNotifyListeners();
[email protected]ae4c37e2012-12-21 01:16:25450
[email protected]47b60072013-06-20 10:35:56451 // TODO(erikkay) this should probably be deferred to a future point
452 // rather than running immediately at startup.
453 CheckForExternalUpdates();
[email protected]894bb502009-05-21 22:39:57454
[email protected]2d19eb6e2014-01-27 17:30:00455 LoadGreylistFromPrefs();
[email protected]399583b2012-12-11 09:33:42456 }
[email protected]3350d712013-11-18 09:32:24457
458 UMA_HISTOGRAM_TIMES("Extensions.ExtensionServiceInitTime",
459 base::Time::Now() - begin_time);
[email protected]6014d672008-12-05 00:38:25460}
461
[email protected]2d19eb6e2014-01-27 17:30:00462void ExtensionService::LoadGreylistFromPrefs() {
[email protected]f47f7172014-03-19 19:27:10463 scoped_ptr<ExtensionSet> all_extensions =
464 registry_->GenerateInstalledExtensionsSet();
[email protected]2d19eb6e2014-01-27 17:30:00465
466 for (ExtensionSet::const_iterator it = all_extensions->begin();
467 it != all_extensions->end(); ++it) {
468 extensions::BlacklistState state =
469 extension_prefs_->GetExtensionBlacklistState((*it)->id());
470 if (state == extensions::BLACKLISTED_SECURITY_VULNERABILITY ||
471 state == extensions::BLACKLISTED_POTENTIALLY_UNWANTED ||
472 state == extensions::BLACKLISTED_CWS_POLICY_VIOLATION)
473 greylist_.Insert(*it);
474 }
475}
476
[email protected]31bb5ee62012-09-12 22:58:40477bool ExtensionService::UpdateExtension(const std::string& id,
[email protected]650b2d52013-02-10 03:41:45478 const base::FilePath& extension_path,
[email protected]044e86992014-01-24 22:59:11479 bool file_ownership_passed,
[email protected]31bb5ee62012-09-12 22:58:40480 CrxInstaller** out_crx_installer) {
[email protected]a29a517a2011-01-21 21:11:12481 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]3c4abc82012-10-22 22:25:54482 if (browser_terminating_) {
483 LOG(WARNING) << "Skipping UpdateExtension due to browser shutdown";
484 // Leak the temp file at extension_path. We don't want to add to the disk
485 // I/O burden at shutdown, we can't rely on the I/O completing anyway, and
486 // the file is in the OS temp directory which should be cleaned up for us.
487 return false;
488 }
[email protected]a8af9fdb2010-10-28 21:52:20489
[email protected]3f213ad2012-07-26 23:39:41490 const extensions::PendingExtensionInfo* pending_extension_info =
[email protected]51a3bf8b2012-06-08 22:53:06491 pending_extension_manager()->GetById(id);
[email protected]8ef78fd2010-08-19 17:14:32492
[email protected]695b5712012-12-06 23:55:28493 const Extension* extension = GetInstalledExtension(id);
[email protected]51a3bf8b2012-06-08 22:53:06494 if (!pending_extension_info && !extension) {
[email protected]aa142702010-03-26 01:26:33495 LOG(WARNING) << "Will not update extension " << id
496 << " because it is not installed or pending";
497 // Delete extension_path since we're not creating a CrxInstaller
498 // that would do it for us.
[email protected]7f8f24f2012-11-15 19:40:14499 if (!GetFileTaskRunner()->PostTask(
500 FROM_HERE,
[email protected]53612e82011-10-18 18:00:36501 base::Bind(
[email protected]85df9d12014-04-15 17:02:14502 &extensions::file_util::DeleteFile, extension_path, false)))
[email protected]14908b72011-04-20 06:54:36503 NOTREACHED();
[email protected]420a0ec2011-06-01 01:07:03504
505 return false;
[email protected]e957fe52009-06-23 16:51:05506 }
507
[email protected]f8636f92013-08-09 21:02:37508 scoped_refptr<CrxInstaller> installer(
pkotwicz31eb1e8ec2014-10-08 15:26:46509 CrxInstaller::Create(this, scoped_ptr<ExtensionInstallPrompt>()));
[email protected]6dfbbf82010-03-12 23:09:16510 installer->set_expected_id(id);
[email protected]464213a2013-10-15 01:06:48511 int creation_flags = Extension::NO_FLAGS;
[email protected]51a3bf8b2012-06-08 22:53:06512 if (pending_extension_info) {
513 installer->set_install_source(pending_extension_info->install_source());
pkotwicz31eb1e8ec2014-10-08 15:26:46514 installer->set_allow_silent_install(true);
[email protected]21db9ef2014-05-16 02:06:27515 if (pending_extension_info->remote_install())
516 installer->set_grant_permissions(false);
[email protected]464213a2013-10-15 01:06:48517 creation_flags = pending_extension_info->creation_flags();
518 if (pending_extension_info->mark_acknowledged())
[email protected]374ceb6f2014-07-02 19:25:34519 external_install_manager_->AcknowledgeExternalExtension(id);
[email protected]51a3bf8b2012-06-08 22:53:06520 } else if (extension) {
[email protected]5eb375e92010-11-26 07:50:41521 installer->set_install_source(extension->location());
[email protected]51a3bf8b2012-06-08 22:53:06522 }
[email protected]7d8b7072012-04-07 01:07:46523 // If the extension was installed from or has migrated to the webstore, or
[email protected]fcb2c2c2012-10-17 21:08:45524 // its auto-update URL is from the webstore, treat it as a webstore install.
525 // Note that we ignore some older extensions with blank auto-update URLs
526 // because we are mostly concerned with restrictions on NaCl extensions,
527 // which are newer.
[email protected]75764512011-12-19 19:54:28528 if ((extension && extension->from_webstore()) ||
[email protected]4a5fe3e22013-06-04 07:06:38529 (extension && extensions::ManifestURL::UpdatesFromGallery(extension)) ||
[email protected]963d13c2012-09-29 17:13:35530 (!extension && extension_urls::IsWebstoreUpdateUrl(
[email protected]51a3bf8b2012-06-08 22:53:06531 pending_extension_info->update_url()))) {
[email protected]a12ce8b22012-01-17 18:40:53532 creation_flags |= Extension::FROM_WEBSTORE;
533 }
534
535 // Bookmark apps being updated is kind of a contradiction, but that's because
536 // we mark the default apps as bookmark apps, and they're hosted in the web
537 // store, thus they can get updated. See http://crbug.com/101605 for more
538 // details.
539 if (extension && extension->from_bookmark())
540 creation_flags |= Extension::FROM_BOOKMARK;
541
[email protected]e33bbc22012-08-27 22:05:46542 if (extension && extension->was_installed_by_default())
543 creation_flags |= Extension::WAS_INSTALLED_BY_DEFAULT;
544
[email protected]acc3c7c22014-03-19 06:23:39545 if (extension && extension->was_installed_by_oem())
546 creation_flags |= Extension::WAS_INSTALLED_BY_OEM;
547
[email protected]6338fa32014-07-16 21:41:59548 if (extension && extension->was_installed_by_custodian())
549 creation_flags |= Extension::WAS_INSTALLED_BY_CUSTODIAN;
550
[email protected]658eae52014-06-14 20:28:05551 if (extension) {
[email protected]411f8ae2014-05-22 11:12:23552 installer->set_is_ephemeral(extension_prefs_->IsEphemeralApp(id));
[email protected]c30bda262014-06-19 04:10:13553 installer->set_do_not_sync(extension_prefs_->DoNotSync(id));
[email protected]658eae52014-06-14 20:28:05554 }
[email protected]ab6c7be42014-01-16 02:05:54555
[email protected]a12ce8b22012-01-17 18:40:53556 installer->set_creation_flags(creation_flags);
557
[email protected]044e86992014-01-24 22:59:11558 installer->set_delete_source(file_ownership_passed);
[email protected]cb0e50312011-05-09 15:03:07559 installer->set_install_cause(extension_misc::INSTALL_CAUSE_UPDATE);
[email protected]6dfbbf82010-03-12 23:09:16560 installer->InstallCrx(extension_path);
[email protected]420a0ec2011-06-01 01:07:03561
562 if (out_crx_installer)
[email protected]dc24976f2013-06-02 21:15:09563 *out_crx_installer = installer.get();
[email protected]420a0ec2011-06-01 01:07:03564
565 return true;
[email protected]e957fe52009-06-23 16:51:05566}
567
[email protected]bca4b832014-07-17 20:22:34568void ExtensionService::ReloadExtensionImpl(
[email protected]757d60a2014-05-23 00:11:44569 // "transient" because the process of reloading may cause the reference
570 // to become invalid. Instead, use |extension_id|, a copy.
[email protected]bca4b832014-07-17 20:22:34571 const std::string& transient_extension_id,
572 bool be_noisy) {
[email protected]a29a517a2011-01-21 21:11:12573 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]2a947202013-03-06 04:58:05574
575 // If the extension is already reloading, don't reload again.
[email protected]757d60a2014-05-23 00:11:44576 if (extension_prefs_->GetDisableReasons(transient_extension_id) &
[email protected]2a947202013-03-06 04:58:05577 Extension::DISABLE_RELOAD) {
578 return;
579 }
580
[email protected]757d60a2014-05-23 00:11:44581 // Ignore attempts to reload a blacklisted extension. Sometimes this can
582 // happen in a convoluted reload sequence triggered by the termination of a
583 // blacklisted extension and a naive attempt to reload it. For an example see
584 // http://crbug.com/373842.
585 if (registry_->blacklisted_extensions().Contains(transient_extension_id))
586 return;
587
[email protected]650b2d52013-02-10 03:41:45588 base::FilePath path;
[email protected]757d60a2014-05-23 00:11:44589
590 std::string extension_id = transient_extension_id;
591 const Extension* transient_current_extension =
592 GetExtensionById(extension_id, false);
[email protected]9cddd4702009-07-27 22:09:40593
[email protected]f17dbd42010-08-16 23:21:10594 // Disable the extension if it's loaded. It might not be loaded if it crashed.
[email protected]757d60a2014-05-23 00:11:44595 if (transient_current_extension) {
[email protected]4814b512009-11-07 00:12:29596 // If the extension has an inspector open for its background page, detach
597 // the inspector and hang onto a cookie for it, so that we can reattach
598 // later.
[email protected]31d8f5f22012-04-02 15:22:08599 // TODO(yoz): this is not incognito-safe!
[email protected]98b6d942013-11-10 00:34:07600 extensions::ProcessManager* manager = system_->process_manager();
[email protected]3a1dc572012-07-31 22:25:13601 extensions::ExtensionHost* host =
602 manager->GetBackgroundHostForExtension(extension_id);
[email protected]b3f957e62014-08-08 10:09:02603 if (host && DevToolsAgentHost::HasFor(host->host_contents())) {
[email protected]4814b512009-11-07 00:12:29604 // Look for an open inspector for the background page.
[email protected]04ea1bb2013-07-10 09:26:09605 scoped_refptr<DevToolsAgentHost> agent_host =
[email protected]b3f957e62014-08-08 10:09:02606 DevToolsAgentHost::GetOrCreateFor(host->host_contents());
607 agent_host->DisconnectWebContents();
[email protected]04ea1bb2013-07-10 09:26:09608 orphaned_dev_tools_[extension_id] = agent_host;
[email protected]4814b512009-11-07 00:12:29609 }
610
[email protected]757d60a2014-05-23 00:11:44611 path = transient_current_extension->path();
[email protected]58076192013-07-19 19:43:50612 // BeingUpgraded is set back to false when the extension is added.
[email protected]757d60a2014-05-23 00:11:44613 system_->runtime_data()->SetBeingUpgraded(transient_current_extension,
614 true);
[email protected]44d62b62012-04-11 00:06:03615 DisableExtension(extension_id, Extension::DISABLE_RELOAD);
[email protected]b914e2952013-04-26 07:10:03616 reloading_extensions_.insert(extension_id);
[email protected]1eb175082010-02-10 09:26:16617 } else {
[email protected]d32c02a2014-06-16 22:58:36618 std::map<std::string, base::FilePath>::const_iterator iter =
619 unloaded_extension_paths_.find(extension_id);
620 if (iter == unloaded_extension_paths_.end()) {
621 return;
622 }
[email protected]1eb175082010-02-10 09:26:16623 path = unloaded_extension_paths_[extension_id];
[email protected]b65272f2009-08-31 15:47:06624 }
625
[email protected]757d60a2014-05-23 00:11:44626 transient_current_extension = NULL;
627
[email protected]9f4e4f082013-06-21 07:11:19628 if (delayed_installs_.Contains(extension_id)) {
[email protected]6f6101832012-11-27 22:10:48629 FinishDelayedInstallation(extension_id);
[email protected]0db124b02012-11-07 04:55:05630 return;
631 }
632
[email protected]43ceb002012-02-10 23:19:15633 // If we're reloading a component extension, use the component extension
634 // loader's reloader.
635 if (component_loader_->Exists(extension_id)) {
636 component_loader_->Reload(extension_id);
637 return;
638 }
639
[email protected]e6090e42010-03-23 22:44:08640 // Check the installed extensions to see if what we're reloading was already
641 // installed.
642 scoped_ptr<ExtensionInfo> installed_extension(
643 extension_prefs_->GetInstalledExtensionInfo(extension_id));
644 if (installed_extension.get() &&
645 installed_extension->extension_manifest.get()) {
[email protected]d8c8f25f2011-11-02 18:18:01646 extensions::InstalledLoader(this).Load(*installed_extension, false);
[email protected]e6090e42010-03-23 22:44:08647 } else {
[email protected]d8c8f25f2011-11-02 18:18:01648 // Otherwise, the extension is unpacked (location LOAD).
[email protected]e6090e42010-03-23 22:44:08649 // We should always be able to remember the extension's path. If it's not in
650 // the map, someone failed to update |unloaded_extension_paths_|.
651 CHECK(!path.empty());
[email protected]bca4b832014-07-17 20:22:34652 scoped_refptr<extensions::UnpackedInstaller> unpacked_installer =
653 extensions::UnpackedInstaller::Create(this);
654 unpacked_installer->set_be_noisy_on_failure(be_noisy);
655 unpacked_installer->Load(path);
[email protected]e6090e42010-03-23 22:44:08656 }
[email protected]9cddd4702009-07-27 22:09:40657}
658
[email protected]bca4b832014-07-17 20:22:34659void ExtensionService::ReloadExtension(const std::string& extension_id) {
660 ReloadExtensionImpl(extension_id, true); // be_noisy
661}
662
663void ExtensionService::ReloadExtensionWithQuietFailure(
664 const std::string& extension_id) {
665 ReloadExtensionImpl(extension_id, false); // be_noisy
666}
667
[email protected]757d60a2014-05-23 00:11:44668bool ExtensionService::UninstallExtension(
669 // "transient" because the process of uninstalling may cause the reference
670 // to become invalid. Instead, use |extenson->id()|.
671 const std::string& transient_extension_id,
[email protected]e43c61f2014-07-20 21:46:34672 extensions::UninstallReason reason,
[email protected]42d58f62014-07-31 01:32:45673 const base::Closure& deletion_done_callback,
[email protected]757d60a2014-05-23 00:11:44674 base::string16* error) {
[email protected]a29a517a2011-01-21 21:11:12675 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]a8af9fdb2010-10-28 21:52:20676
[email protected]757d60a2014-05-23 00:11:44677 scoped_refptr<const Extension> extension =
678 GetInstalledExtension(transient_extension_id);
[email protected]631cf822009-05-15 07:01:25679
[email protected]e7afe2452010-08-22 16:19:13680 // Callers should not send us nonexistent extensions.
[email protected]dc24976f2013-06-02 21:15:09681 CHECK(extension.get());
[email protected]9f1087e2009-06-15 17:29:32682
binjincccacef2014-10-13 19:00:20683 ManagementPolicy* by_policy = system_->management_policy();
[email protected]95da88c42011-03-31 10:07:33684 // Policy change which triggers an uninstall will always set
685 // |external_uninstall| to true so this is the only way to uninstall
686 // managed extensions.
[email protected]90878c52014-04-04 18:21:02687 // Shared modules being uninstalled will also set |external_uninstall| to true
688 // so that we can guarantee users don't uninstall a shared module.
689 // (crbug.com/273300)
690 // TODO(rdevlin.cronin): This is probably not right. We should do something
691 // else, like include an enum IS_INTERNAL_UNINSTALL or IS_USER_UNINSTALL so
692 // we don't do this.
[email protected]cc2f55c2014-07-08 02:19:04693 bool external_uninstall =
[email protected]e43c61f2014-07-20 21:46:34694 (reason == extensions::UNINSTALL_REASON_INTERNAL_MANAGEMENT) ||
rdevlin.cronin5f6b69d2014-09-20 01:23:35695 (reason == extensions::UNINSTALL_REASON_REINSTALL) ||
[email protected]e43c61f2014-07-20 21:46:34696 (reason == extensions::UNINSTALL_REASON_ORPHANED_EXTERNAL_EXTENSION) ||
[email protected]6ef60012014-07-22 19:08:12697 (reason == extensions::UNINSTALL_REASON_ORPHANED_SHARED_MODULE) ||
698 (reason == extensions::UNINSTALL_REASON_SYNC &&
699 extension->was_installed_by_custodian());
[email protected]65187152012-06-02 13:14:14700 if (!external_uninstall &&
binjincccacef2014-10-13 19:00:20701 (!by_policy->UserMayModifySettings(extension.get(), error) ||
702 by_policy->MustRemainInstalled(extension.get(), error))) {
[email protected]ad50def52011-10-19 23:17:07703 content::NotificationService::current()->Notify(
[email protected]adf5a102014-07-31 12:44:06704 extensions::NOTIFICATION_EXTENSION_UNINSTALL_NOT_ALLOWED,
[email protected]6c2381d2011-10-19 02:52:53705 content::Source<Profile>(profile_),
[email protected]dc24976f2013-06-02 21:15:09706 content::Details<const Extension>(extension.get()));
[email protected]d6ebc9792011-04-07 18:18:33707 return false;
708 }
[email protected]95da88c42011-03-31 10:07:33709
[email protected]65f173552012-06-28 22:43:58710 syncer::SyncChange sync_change;
rdevlin.cronin5f6b69d2014-09-20 01:23:35711 // Don't sync the uninstall if we're going to reinstall the extension
712 // momentarily.
713 if (extension_sync_service_ &&
714 reason != extensions::UNINSTALL_REASON_REINSTALL) {
[email protected]f8aefb132013-10-30 09:29:52715 sync_change = extension_sync_service_->PrepareToSyncUninstallExtension(
716 extension.get(), is_ready());
[email protected]3bdba0d2011-08-23 07:17:30717 }
718
[email protected]d820bc52014-03-13 05:35:23719 system_->install_verifier()->Remove(extension->id());
[email protected]ffd2f79e2013-11-14 00:11:46720
[email protected]9b217652010-10-08 22:04:23721 UMA_HISTOGRAM_ENUMERATION("Extensions.UninstallType",
[email protected]7fa19f82010-12-21 19:40:08722 extension->GetType(), 100);
[email protected]dc24976f2013-06-02 21:15:09723 RecordPermissionMessagesHistogram(extension.get(),
[email protected]4c86be582014-06-04 08:39:11724 "Extensions.Permissions_Uninstall2");
[email protected]9b217652010-10-08 22:04:23725
[email protected]831aa212010-03-26 13:55:19726 // Unload before doing more cleanup to ensure that nothing is hanging on to
727 // any of these resources.
[email protected]757d60a2014-05-23 00:11:44728 UnloadExtension(extension->id(), UnloadedExtensionInfo::REASON_UNINSTALL);
[email protected]831aa212010-03-26 13:55:19729
[email protected]9f1087e2009-06-15 17:29:32730 // Tell the backend to start deleting installed extensions on the file thread.
[email protected]12075d12013-02-27 05:38:05731 if (!Manifest::IsUnpackedLocation(extension->location())) {
[email protected]7f8f24f2012-11-15 19:40:14732 if (!GetFileTaskRunner()->PostTask(
733 FROM_HERE,
[email protected]5a145e82014-05-29 22:19:07734 base::Bind(&ExtensionService::UninstallExtensionOnFileThread,
735 extension->id(),
736 profile_,
[email protected]85df9d12014-04-15 17:02:14737 install_directory_,
[email protected]5a145e82014-05-29 22:19:07738 extension->path())))
[email protected]14908b72011-04-20 06:54:36739 NOTREACHED();
[email protected]9f1087e2009-06-15 17:29:32740 }
741
[email protected]42d58f62014-07-31 01:32:45742 extensions::DataDeleter::StartDeleting(
743 profile_, extension.get(), deletion_done_callback);
[email protected]0d6ec3a72011-09-02 02:09:43744
[email protected]757d60a2014-05-23 00:11:44745 UntrackTerminatedExtension(extension->id());
[email protected]211030342010-09-30 18:41:06746
747 // Notify interested parties that we've uninstalled this extension.
[email protected]ad50def52011-10-19 23:17:07748 content::NotificationService::current()->Notify(
[email protected]adf5a102014-07-31 12:44:06749 extensions::NOTIFICATION_EXTENSION_UNINSTALLED_DEPRECATED,
[email protected]6c2381d2011-10-19 02:52:53750 content::Source<Profile>(profile_),
[email protected]dc24976f2013-06-02 21:15:09751 content::Details<const Extension>(extension.get()));
[email protected]e43c61f2014-07-20 21:46:34752 ExtensionRegistry::Get(profile_)
753 ->TriggerOnUninstalled(extension.get(), reason);
[email protected]d6ebc9792011-04-07 18:18:33754
rdevlin.cronin5f6b69d2014-09-20 01:23:35755 if (sync_change.IsValid()) {
[email protected]757d60a2014-05-23 00:11:44756 extension_sync_service_->ProcessSyncUninstallExtension(extension->id(),
[email protected]f8aefb132013-10-30 09:29:52757 sync_change);
[email protected]3bdba0d2011-08-23 07:17:30758 }
759
[email protected]757d60a2014-05-23 00:11:44760 delayed_installs_.Remove(extension->id());
[email protected]0db124b02012-11-07 04:55:05761
[email protected]757d60a2014-05-23 00:11:44762 extension_prefs_->OnExtensionUninstalled(
763 extension->id(), extension->location(), external_uninstall);
[email protected]d4eda592013-09-18 03:37:57764
[email protected]333b1de2011-09-12 18:28:50765 // Track the uninstallation.
[email protected]49098f702011-10-13 03:47:18766 UMA_HISTOGRAM_ENUMERATION("Extensions.ExtensionUninstalled", 1, 2);
767
[email protected]d6ebc9792011-04-07 18:18:33768 return true;
[email protected]c10da4b02010-03-25 14:38:32769}
770
[email protected]5a145e82014-05-29 22:19:07771// static
772void ExtensionService::UninstallExtensionOnFileThread(
773 const std::string& id,
774 Profile* profile,
775 const base::FilePath& install_dir,
776 const base::FilePath& extension_path) {
777 extensions::ExtensionAssetsManager* assets_manager =
778 extensions::ExtensionAssetsManager::GetInstance();
779 assets_manager->UninstallExtension(id, profile, install_dir, extension_path);
780}
781
[email protected]c3cfb012011-04-06 22:07:35782bool ExtensionService::IsExtensionEnabled(
783 const std::string& extension_id) const {
[email protected]bb1bc9b32013-12-21 03:09:14784 if (registry_->enabled_extensions().Contains(extension_id) ||
785 registry_->terminated_extensions().Contains(extension_id)) {
[email protected]36429da2011-07-11 20:25:18786 return true;
[email protected]dc9a74f72012-08-17 18:07:21787 }
[email protected]36429da2011-07-11 20:25:18788
[email protected]bb1bc9b32013-12-21 03:09:14789 if (registry_->disabled_extensions().Contains(extension_id) ||
790 registry_->blacklisted_extensions().Contains(extension_id)) {
[email protected]ad83ca242011-07-29 01:32:25791 return false;
[email protected]695b5712012-12-06 23:55:28792 }
[email protected]ad83ca242011-07-29 01:32:25793
794 // If the extension hasn't been loaded yet, check the prefs for it. Assume
795 // enabled unless otherwise noted.
796 return !extension_prefs_->IsExtensionDisabled(extension_id) &&
[email protected]27e528322014-05-27 20:54:30797 !extension_prefs_->IsExtensionBlacklisted(extension_id) &&
[email protected]f574c402012-12-04 23:20:31798 !extension_prefs_->IsExternalExtensionUninstalled(extension_id);
[email protected]c3cfb012011-04-06 22:07:35799}
800
[email protected]eaa7dd182010-12-14 11:09:00801void ExtensionService::EnableExtension(const std::string& extension_id) {
[email protected]a29a517a2011-01-21 21:11:12802 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]a8af9fdb2010-10-28 21:52:20803
[email protected]06f92562011-04-29 19:27:31804 if (IsExtensionEnabled(extension_id))
[email protected]0c6da502009-08-14 22:32:39805 return;
[email protected]bb1bc9b32013-12-21 03:09:14806 const Extension* extension =
807 registry_->disabled_extensions().GetByID(extension_id);
[email protected]0d54b682013-11-05 14:15:36808
809 ManagementPolicy* policy = system_->management_policy();
810 if (extension && policy->MustRemainDisabled(extension, NULL, NULL)) {
811 UMA_HISTOGRAM_COUNTS_100("Extensions.EnableDeniedByPolicy", 1);
812 return;
813 }
[email protected]0c6da502009-08-14 22:32:39814
[email protected]b3317ad2011-04-28 23:46:00815 extension_prefs_->SetExtensionState(extension_id, Extension::ENABLED);
[email protected]eb5e4f92012-08-15 23:33:28816 extension_prefs_->ClearDisableReasons(extension_id);
[email protected]1784e83a2009-09-08 21:01:52817
[email protected]06f92562011-04-29 19:27:31818 // This can happen if sync enables an extension that is not
819 // installed yet.
820 if (!extension)
821 return;
822
[email protected]0c6da502009-08-14 22:32:39823 // Move it over to the enabled list.
[email protected]bb1bc9b32013-12-21 03:09:14824 registry_->AddEnabled(make_scoped_refptr(extension));
825 registry_->RemoveDisabled(extension->id());
[email protected]0c6da502009-08-14 22:32:39826
[email protected]62d30f42009-10-01 22:36:06827 NotifyExtensionLoaded(extension);
[email protected]3bdba0d2011-08-23 07:17:30828
[email protected]f74d7f32012-06-19 19:22:51829 // Notify listeners that the extension was enabled.
830 content::NotificationService::current()->Notify(
[email protected]adf5a102014-07-31 12:44:06831 extensions::NOTIFICATION_EXTENSION_ENABLED,
[email protected]f74d7f32012-06-19 19:22:51832 content::Source<Profile>(profile_),
833 content::Details<const Extension>(extension));
834
[email protected]f8aefb132013-10-30 09:29:52835 if (extension_sync_service_)
836 extension_sync_service_->SyncEnableExtension(*extension);
[email protected]0c6da502009-08-14 22:32:39837}
838
[email protected]44d62b62012-04-11 00:06:03839void ExtensionService::DisableExtension(
840 const std::string& extension_id,
841 Extension::DisableReason disable_reason) {
[email protected]a29a517a2011-01-21 21:11:12842 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]a8af9fdb2010-10-28 21:52:20843
[email protected]8f959f522014-08-06 06:26:28844 // The extension may have been disabled already. Just add a disable reason.
845 if (!IsExtensionEnabled(extension_id)) {
846 extension_prefs_->AddDisableReason(extension_id, disable_reason);
[email protected]1784e83a2009-09-08 21:01:52847 return;
[email protected]8f959f522014-08-06 06:26:28848 }
[email protected]1784e83a2009-09-08 21:01:52849
[email protected]06f92562011-04-29 19:27:31850 const Extension* extension = GetInstalledExtension(extension_id);
851 // |extension| can be NULL if sync disables an extension that is not
852 // installed yet.
[email protected]ab894542014-07-03 12:35:39853 // EXTERNAL_COMPONENT extensions are not generally modifiable by users, but
854 // can be uninstalled by the browser if the user sets extension-specific
855 // preferences.
[email protected]65187152012-06-02 13:14:14856 if (extension &&
[email protected]505ccdc2013-06-20 20:15:35857 disable_reason != Extension::DISABLE_RELOAD &&
[email protected]ab894542014-07-03 12:35:39858 !system_->management_policy()->UserMayModifySettings(extension, NULL) &&
859 extension->location() != Manifest::EXTERNAL_COMPONENT) {
[email protected]95da88c42011-03-31 10:07:33860 return;
[email protected]65187152012-06-02 13:14:14861 }
[email protected]95da88c42011-03-31 10:07:33862
[email protected]b3317ad2011-04-28 23:46:00863 extension_prefs_->SetExtensionState(extension_id, Extension::DISABLED);
[email protected]eb5e4f92012-08-15 23:33:28864 extension_prefs_->AddDisableReason(extension_id, disable_reason);
[email protected]1784e83a2009-09-08 21:01:52865
[email protected]599539802014-01-07 23:06:00866 int include_mask =
867 ExtensionRegistry::EVERYTHING & ~ExtensionRegistry::DISABLED;
868 extension = registry_->GetExtensionById(extension_id, include_mask);
[email protected]06f92562011-04-29 19:27:31869 if (!extension)
870 return;
871
[email protected]45f5b7d2014-01-22 23:47:13872 // The extension is either enabled or terminated.
873 DCHECK(registry_->enabled_extensions().Contains(extension->id()) ||
874 registry_->terminated_extensions().Contains(extension->id()));
[email protected]64742de32013-04-22 08:44:34875
[email protected]5c094792012-09-07 19:44:53876 // Move it over to the disabled list. Don't send a second unload notification
877 // for terminated extensions being disabled.
[email protected]bb1bc9b32013-12-21 03:09:14878 registry_->AddDisabled(make_scoped_refptr(extension));
879 if (registry_->enabled_extensions().Contains(extension->id())) {
880 registry_->RemoveEnabled(extension->id());
[email protected]b0af4792013-10-23 09:12:13881 NotifyExtensionUnloaded(extension, UnloadedExtensionInfo::REASON_DISABLE);
[email protected]5c094792012-09-07 19:44:53882 } else {
[email protected]bb1bc9b32013-12-21 03:09:14883 registry_->RemoveTerminated(extension->id());
[email protected]5c094792012-09-07 19:44:53884 }
[email protected]3bdba0d2011-08-23 07:17:30885
[email protected]f8aefb132013-10-30 09:29:52886 if (extension_sync_service_)
887 extension_sync_service_->SyncDisableExtension(*extension);
[email protected]1784e83a2009-09-08 21:01:52888}
889
[email protected]1abf05e2013-07-09 17:04:36890void ExtensionService::DisableUserExtensions(
891 const std::vector<std::string>& except_ids) {
[email protected]e516e4c2013-06-12 17:41:14892 extensions::ManagementPolicy* management_policy =
893 system_->management_policy();
894 extensions::ExtensionList to_disable;
895
[email protected]bb1bc9b32013-12-21 03:09:14896 const ExtensionSet& enabled_set = registry_->enabled_extensions();
897 for (ExtensionSet::const_iterator extension = enabled_set.begin();
898 extension != enabled_set.end(); ++extension) {
[email protected]ab894542014-07-03 12:35:39899 if (management_policy->UserMayModifySettings(extension->get(), NULL))
[email protected]e516e4c2013-06-12 17:41:14900 to_disable.push_back(*extension);
901 }
[email protected]bb1bc9b32013-12-21 03:09:14902 const ExtensionSet& terminated_set = registry_->terminated_extensions();
903 for (ExtensionSet::const_iterator extension = terminated_set.begin();
904 extension != terminated_set.end(); ++extension) {
[email protected]ab894542014-07-03 12:35:39905 if (management_policy->UserMayModifySettings(extension->get(), NULL))
[email protected]e516e4c2013-06-12 17:41:14906 to_disable.push_back(*extension);
907 }
908
909 for (extensions::ExtensionList::const_iterator extension = to_disable.begin();
910 extension != to_disable.end(); ++extension) {
[email protected]3082fe32013-08-06 11:12:38911 if ((*extension)->was_installed_by_default() &&
912 extension_urls::IsWebstoreUpdateUrl(
dchengc7047942014-08-26 05:05:31913 extensions::ManifestURL::GetUpdateURL(extension->get())))
[email protected]3082fe32013-08-06 11:12:38914 continue;
[email protected]1abf05e2013-07-09 17:04:36915 const std::string& id = (*extension)->id();
916 if (except_ids.end() == std::find(except_ids.begin(), except_ids.end(), id))
917 DisableExtension(id, extensions::Extension::DISABLE_USER_ACTION);
[email protected]e516e4c2013-06-12 17:41:14918 }
919}
920
[email protected]eaa7dd182010-12-14 11:09:00921void ExtensionService::GrantPermissionsAndEnableExtension(
[email protected]009633c2013-03-07 22:08:28922 const Extension* extension) {
923 GrantPermissions(extension);
[email protected]4c86be582014-06-04 08:39:11924 RecordPermissionMessagesHistogram(extension,
925 "Extensions.Permissions_ReEnable2");
[email protected]8d888c12010-11-30 00:00:25926 extension_prefs_->SetDidExtensionEscalatePermissions(extension, false);
927 EnableExtension(extension->id());
928}
929
[email protected]009633c2013-03-07 22:08:28930void ExtensionService::GrantPermissions(const Extension* extension) {
[email protected]be083862012-09-01 03:53:45931 CHECK(extension);
[email protected]8d42db52014-06-20 21:50:50932 extensions::PermissionsUpdater(profile()).GrantActivePermissions(extension);
[email protected]be083862012-09-01 03:53:45933}
934
[email protected]fe2dd7742011-04-19 22:52:49935// static
936void ExtensionService::RecordPermissionMessagesHistogram(
[email protected]13c68b62013-05-17 11:29:05937 const Extension* extension, const char* histogram) {
[email protected]de415552013-01-23 04:12:17938 // Since this is called from multiple sources, and since the histogram macros
939 // use statics, we need to manually lookup the histogram ourselves.
940 base::HistogramBase* counter = base::LinearHistogram::FactoryGet(
[email protected]fe2dd7742011-04-19 22:52:49941 histogram,
942 1,
[email protected]c2e66e12012-06-27 06:27:06943 PermissionMessage::kEnumBoundary,
944 PermissionMessage::kEnumBoundary + 1,
[email protected]de415552013-01-23 04:12:17945 base::HistogramBase::kUmaTargetedHistogramFlag);
[email protected]fe2dd7742011-04-19 22:52:49946
[email protected]a6910e72014-06-06 05:04:36947 PermissionMessages permissions =
948 extension->permissions_data()->GetPermissionMessages();
[email protected]fe2dd7742011-04-19 22:52:49949 if (permissions.empty()) {
[email protected]c2e66e12012-06-27 06:27:06950 counter->Add(PermissionMessage::kNone);
[email protected]fe2dd7742011-04-19 22:52:49951 } else {
[email protected]c2e66e12012-06-27 06:27:06952 for (PermissionMessages::iterator it = permissions.begin();
[email protected]0d3e4a22011-06-23 19:02:52953 it != permissions.end(); ++it)
954 counter->Add(it->id());
[email protected]fe2dd7742011-04-19 22:52:49955 }
956}
957
[email protected]eaa7dd182010-12-14 11:09:00958void ExtensionService::NotifyExtensionLoaded(const Extension* extension) {
[email protected]f9c8c7c72014-07-31 16:42:31959 // The URLRequestContexts need to be first to know that the extension
[email protected]62d30f42009-10-01 22:36:06960 // was loaded, otherwise a race can arise where a renderer that is created
961 // for the extension may try to load an extension URL with an extension id
[email protected]57a777f72010-03-31 01:09:42962 // that the request context doesn't yet know about. The profile is responsible
963 // for ensuring its URLRequestContexts appropriately discover the loaded
964 // extension.
[email protected]31d8f5f22012-04-02 15:22:08965 system_->RegisterExtensionWithRequestContexts(extension);
[email protected]62d30f42009-10-01 22:36:06966
[email protected]d5949312012-12-03 22:13:30967 // Tell renderers about the new extension, unless it's a theme (renderers
968 // don't need to know about themes).
[email protected]a58f599c2012-12-01 03:08:19969 if (!extension->is_theme()) {
[email protected]19647262011-12-16 09:57:49970 for (content::RenderProcessHost::iterator i(
971 content::RenderProcessHost::AllHostsIterator());
972 !i.IsAtEnd(); i.Advance()) {
973 content::RenderProcessHost* host = i.GetCurrentValue();
974 Profile* host_profile =
975 Profile::FromBrowserContext(host->GetBrowserContext());
976 if (host_profile->GetOriginalProfile() ==
977 profile_->GetOriginalProfile()) {
978 std::vector<ExtensionMsg_Loaded_Params> loaded_extensions(
979 1, ExtensionMsg_Loaded_Params(extension));
980 host->Send(
981 new ExtensionMsg_Loaded(loaded_extensions));
982 }
[email protected]c8d407e2011-04-28 21:27:17983 }
[email protected]77a6970c2011-04-23 16:58:56984 }
985
[email protected]3442a662012-01-12 08:06:17986 // Tell subsystems that use the EXTENSION_LOADED notification about the new
987 // extension.
988 //
989 // NOTE: It is important that this happen after notifying the renderers about
990 // the new extensions so that if we navigate to an extension URL in
[email protected]fdc76192014-04-20 21:54:41991 // ExtensionRegistryObserver::OnLoaded or
992 // NOTIFICATION_EXTENSION_LOADED_DEPRECATED, the
[email protected]dcc47642014-03-26 22:03:49993 // renderer is guaranteed to know about it.
994 registry_->TriggerOnLoaded(extension);
995
[email protected]3442a662012-01-12 08:06:17996 content::NotificationService::current()->Notify(
[email protected]adf5a102014-07-31 12:44:06997 extensions::NOTIFICATION_EXTENSION_LOADED_DEPRECATED,
[email protected]3442a662012-01-12 08:06:17998 content::Source<Profile>(profile_),
999 content::Details<const Extension>(extension));
1000
[email protected]dcc47642014-03-26 22:03:491001 // TODO(kalman): Convert ExtensionSpecialStoragePolicy to a
1002 // BrowserContextKeyedService and use ExtensionRegistryObserver.
[email protected]c8d407e2011-04-28 21:27:171003 profile_->GetExtensionSpecialStoragePolicy()->
rdevlin.croninbc8979a2014-09-30 01:08:501004 GrantRightsForExtension(extension, profile_);
[email protected]c8d407e2011-04-28 21:27:171005
[email protected]dcc47642014-03-26 22:03:491006 // TODO(kalman): This is broken. The crash reporter is process-wide so doesn't
1007 // work properly multi-profile. Besides which, it should be using
1008 // ExtensionRegistryObserver. See http://crbug.com/355029.
[email protected]c8d407e2011-04-28 21:27:171009 UpdateActiveExtensionsInCrashReporter();
1010
[email protected]d695bb12014-06-05 16:16:301011 const extensions::PermissionsData* permissions_data =
[email protected]a6910e72014-06-06 05:04:361012 extension->permissions_data();
[email protected]d695bb12014-06-05 16:16:301013
[email protected]c8d407e2011-04-28 21:27:171014 // If the extension has permission to load chrome://favicon/ resources we need
1015 // to make sure that the FaviconSource is registered with the
1016 // ChromeURLDataManager.
[email protected]d695bb12014-06-05 16:16:301017 if (permissions_data->HasHostPermission(GURL(chrome::kChromeUIFaviconURL))) {
[email protected]c8d407e2011-04-28 21:27:171018 FaviconSource* favicon_source = new FaviconSource(profile_,
1019 FaviconSource::FAVICON);
[email protected]24ea7a12013-01-27 23:54:531020 content::URLDataSource::Add(profile_, favicon_source);
[email protected]c8d407e2011-04-28 21:27:171021 }
[email protected]b07e606e2012-09-15 20:16:151022
[email protected]b07e606e2012-09-15 20:16:151023 // Same for chrome://theme/ resources.
[email protected]d695bb12014-06-05 16:16:301024 if (permissions_data->HasHostPermission(GURL(chrome::kChromeUIThemeURL))) {
[email protected]b07e606e2012-09-15 20:16:151025 ThemeSource* theme_source = new ThemeSource(profile_);
[email protected]24ea7a12013-01-27 23:54:531026 content::URLDataSource::Add(profile_, theme_source);
[email protected]b07e606e2012-09-15 20:16:151027 }
[email protected]b07e606e2012-09-15 20:16:151028
[email protected]5eddc3e2011-10-26 04:33:311029 // Same for chrome://thumb/ resources.
[email protected]d695bb12014-06-05 16:16:301030 if (permissions_data->HasHostPermission(
1031 GURL(chrome::kChromeUIThumbnailURL))) {
[email protected]420e6d92013-09-17 01:48:511032 ThumbnailSource* thumbnail_source = new ThumbnailSource(profile_, false);
[email protected]24ea7a12013-01-27 23:54:531033 content::URLDataSource::Add(profile_, thumbnail_source);
[email protected]5eddc3e2011-10-26 04:33:311034 }
[email protected]62d30f42009-10-01 22:36:061035}
1036
[email protected]a9f39a312010-12-23 22:14:271037void ExtensionService::NotifyExtensionUnloaded(
[email protected]814a7bf0f2011-08-13 05:30:591038 const Extension* extension,
[email protected]b0af4792013-10-23 09:12:131039 UnloadedExtensionInfo::Reason reason) {
[email protected]a9f39a312010-12-23 22:14:271040 UnloadedExtensionInfo details(extension, reason);
[email protected]e51232f32014-04-18 20:05:361041
1042 registry_->TriggerOnUnloaded(extension, reason);
1043
[email protected]ad50def52011-10-19 23:17:071044 content::NotificationService::current()->Notify(
[email protected]adf5a102014-07-31 12:44:061045 extensions::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED,
[email protected]6c2381d2011-10-19 02:52:531046 content::Source<Profile>(profile_),
1047 content::Details<UnloadedExtensionInfo>(&details));
[email protected]62d30f42009-10-01 22:36:061048
[email protected]f3b1a082011-11-18 00:34:301049 for (content::RenderProcessHost::iterator i(
1050 content::RenderProcessHost::AllHostsIterator());
[email protected]77a6970c2011-04-23 16:58:561051 !i.IsAtEnd(); i.Advance()) {
[email protected]f3b1a082011-11-18 00:34:301052 content::RenderProcessHost* host = i.GetCurrentValue();
[email protected]9b62ecf2011-07-27 20:23:081053 Profile* host_profile =
[email protected]f3b1a082011-11-18 00:34:301054 Profile::FromBrowserContext(host->GetBrowserContext());
[email protected]9b62ecf2011-07-27 20:23:081055 if (host_profile->GetOriginalProfile() == profile_->GetOriginalProfile())
[email protected]c8d407e2011-04-28 21:27:171056 host->Send(new ExtensionMsg_Unloaded(extension->id()));
[email protected]77a6970c2011-04-23 16:58:561057 }
1058
[email protected]31d8f5f22012-04-02 15:22:081059 system_->UnregisterExtensionWithRequestContexts(extension->id(), reason);
[email protected]dcc47642014-03-26 22:03:491060
1061 // TODO(kalman): Convert ExtensionSpecialStoragePolicy to a
1062 // BrowserContextKeyedService and use ExtensionRegistryObserver.
[email protected]c8d407e2011-04-28 21:27:171063 profile_->GetExtensionSpecialStoragePolicy()->
1064 RevokeRightsForExtension(extension);
1065
[email protected]b777b332011-04-16 04:01:081066#if defined(OS_CHROMEOS)
[email protected]ac66e452013-01-11 09:21:231067 // Revoke external file access for the extension from its file system context.
1068 // It is safe to access the extension's storage partition at this point. The
1069 // storage partition may get destroyed only after the extension gets unloaded.
[email protected]3a746ec2014-03-15 05:30:561070 GURL site =
1071 extensions::util::GetSiteForExtensionId(extension->id(), profile_);
[email protected]cd501a72014-08-22 19:58:311072 storage::FileSystemContext* filesystem_context =
1073 BrowserContext::GetStoragePartitionForSite(profile_, site)
1074 ->GetFileSystemContext();
[email protected]f19bbf62013-07-09 01:22:321075 if (filesystem_context && filesystem_context->external_backend()) {
1076 filesystem_context->external_backend()->
[email protected]c8d407e2011-04-28 21:27:171077 RevokeAccessForExtension(extension->id());
[email protected]62d30f42009-10-01 22:36:061078 }
[email protected]c8d407e2011-04-28 21:27:171079#endif
1080
[email protected]dcc47642014-03-26 22:03:491081 // TODO(kalman): This is broken. The crash reporter is process-wide so doesn't
1082 // work properly multi-profile. Besides which, it should be using
1083 // ExtensionRegistryObserver::OnExtensionLoaded. See http://crbug.com/355029.
[email protected]c8d407e2011-04-28 21:27:171084 UpdateActiveExtensionsInCrashReporter();
[email protected]62d30f42009-10-01 22:36:061085}
1086
[email protected]599539802014-01-07 23:06:001087content::BrowserContext* ExtensionService::GetBrowserContext() const {
1088 // Implemented in the .cc file to avoid adding a profile.h dependency to
1089 // extension_service.h.
1090 return profile_;
1091}
1092
[email protected]25ae0152011-11-18 14:40:021093bool ExtensionService::is_ready() {
[email protected]4a10006a2013-05-17 23:18:351094 return ready_->is_signaled();
[email protected]25ae0152011-11-18 14:40:021095}
1096
[email protected]7f8f24f2012-11-15 19:40:141097base::SequencedTaskRunner* ExtensionService::GetFileTaskRunner() {
[email protected]dc24976f2013-06-02 21:15:091098 if (file_task_runner_.get())
1099 return file_task_runner_.get();
[email protected]7f8f24f2012-11-15 19:40:141100
1101 // We should be able to interrupt any part of extension install process during
1102 // shutdown. SKIP_ON_SHUTDOWN ensures that not started extension install tasks
1103 // will be ignored/deleted while we will block on started tasks.
1104 std::string token("ext_install-");
1105 token.append(profile_->GetPath().AsUTF8Unsafe());
1106 file_task_runner_ = BrowserThread::GetBlockingPool()->
1107 GetSequencedTaskRunnerWithShutdownBehavior(
1108 BrowserThread::GetBlockingPool()->GetNamedSequenceToken(token),
1109 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN);
[email protected]dc24976f2013-06-02 21:15:091110 return file_task_runner_.get();
[email protected]7f8f24f2012-11-15 19:40:141111}
1112
[email protected]4ee07c62012-08-21 12:40:421113void ExtensionService::CheckManagementPolicy() {
[email protected]0d54b682013-11-05 14:15:361114 std::vector<std::string> to_unload;
1115 std::map<std::string, Extension::DisableReason> to_disable;
[email protected]695b5712012-12-06 23:55:281116
[email protected]0d54b682013-11-05 14:15:361117 // Loop through the extensions list, finding extensions we need to unload or
1118 // disable.
[email protected]bb1bc9b32013-12-21 03:09:141119 const ExtensionSet& extensions = registry_->enabled_extensions();
1120 for (ExtensionSet::const_iterator iter = extensions.begin();
1121 iter != extensions.end(); ++iter) {
[email protected]cadac622013-06-11 16:46:361122 const Extension* extension = (iter->get());
[email protected]4ee07c62012-08-21 12:40:421123 if (!system_->management_policy()->UserMayLoad(extension, NULL))
[email protected]0d54b682013-11-05 14:15:361124 to_unload.push_back(extension->id());
1125 Extension::DisableReason disable_reason = Extension::DISABLE_NONE;
1126 if (system_->management_policy()->MustRemainDisabled(
1127 extension, &disable_reason, NULL))
1128 to_disable[extension->id()] = disable_reason;
[email protected]aa96d3a2010-08-21 08:45:251129 }
1130
[email protected]0d54b682013-11-05 14:15:361131 for (size_t i = 0; i < to_unload.size(); ++i)
1132 UnloadExtension(to_unload[i], UnloadedExtensionInfo::REASON_DISABLE);
1133
1134 for (std::map<std::string, Extension::DisableReason>::const_iterator i =
1135 to_disable.begin(); i != to_disable.end(); ++i)
1136 DisableExtension(i->first, i->second);
[email protected]aa96d3a2010-08-21 08:45:251137}
1138
[email protected]31206602011-04-13 23:07:321139void ExtensionService::CheckForUpdatesSoon() {
[email protected]90878c52014-04-04 18:21:021140 // This can legitimately happen in unit tests.
1141 if (!updater_.get())
1142 return;
1143
1144 if (AreAllExternalProvidersReady()) {
1145 updater_->CheckSoon();
[email protected]c3cfb012011-04-06 22:07:351146 } else {
[email protected]90878c52014-04-04 18:21:021147 // Sync can start updating before all the external providers are ready
1148 // during startup. Start the update as soon as those providers are ready,
1149 // but not before.
1150 update_once_all_providers_are_ready_ = true;
[email protected]c3cfb012011-04-06 22:07:351151 }
1152}
1153
[email protected]8e4560b62011-01-14 10:09:141154// Some extensions will autoupdate themselves externally from Chrome. These
1155// are typically part of some larger client application package. To support
1156// these, the extension will register its location in the the preferences file
1157// (and also, on Windows, in the registry) and this code will periodically
1158// check that location for a .crx file, which it will then install locally if
1159// a new version is available.
1160// Errors are reported through ExtensionErrorReporter. Succcess is not
1161// reported.
[email protected]eaa7dd182010-12-14 11:09:001162void ExtensionService::CheckForExternalUpdates() {
[email protected]a29a517a2011-01-21 21:11:121163 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]8e4560b62011-01-14 10:09:141164
1165 // Note that this installation is intentionally silent (since it didn't
1166 // go through the front-end). Extensions that are registered in this
1167 // way are effectively considered 'pre-bundled', and so implicitly
1168 // trusted. In general, if something has HKLM or filesystem access,
1169 // they could install an extension manually themselves anyway.
[email protected]a29a517a2011-01-21 21:11:121170
[email protected]8e4560b62011-01-14 10:09:141171 // Ask each external extension provider to give us a call back for each
1172 // extension they know about. See OnExternalExtension(File|UpdateUrl)Found.
[email protected]5df038b2012-07-16 19:03:271173 extensions::ProviderCollection::const_iterator i;
[email protected]8e4560b62011-01-14 10:09:141174 for (i = external_extension_providers_.begin();
1175 i != external_extension_providers_.end(); ++i) {
[email protected]5df038b2012-07-16 19:03:271176 extensions::ExternalProviderInterface* provider = i->get();
[email protected]8e4560b62011-01-14 10:09:141177 provider->VisitRegisteredExtension();
1178 }
1179
[email protected]50067e52011-10-20 23:17:071180 // Do any required work that we would have done after completion of all
1181 // providers.
[email protected]373daf972014-04-10 01:50:441182 if (external_extension_providers_.empty())
[email protected]50067e52011-10-20 23:17:071183 OnAllExternalProvidersReady();
[email protected]9f1087e2009-06-15 17:29:321184}
1185
[email protected]50067e52011-10-20 23:17:071186void ExtensionService::OnExternalProviderReady(
[email protected]5df038b2012-07-16 19:03:271187 const extensions::ExternalProviderInterface* provider) {
[email protected]a29a517a2011-01-21 21:11:121188 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]50067e52011-10-20 23:17:071189 CHECK(provider->IsReady());
[email protected]a29a517a2011-01-21 21:11:121190
1191 // An external provider has finished loading. We only take action
[email protected]8e4560b62011-01-14 10:09:141192 // if all of them are finished. So we check them first.
[email protected]94fde232012-04-27 10:22:301193 if (AreAllExternalProvidersReady())
1194 OnAllExternalProvidersReady();
1195}
1196
1197bool ExtensionService::AreAllExternalProvidersReady() const {
[email protected]5df038b2012-07-16 19:03:271198 extensions::ProviderCollection::const_iterator i;
[email protected]8e4560b62011-01-14 10:09:141199 for (i = external_extension_providers_.begin();
1200 i != external_extension_providers_.end(); ++i) {
[email protected]94fde232012-04-27 10:22:301201 if (!i->get()->IsReady())
1202 return false;
[email protected]8e4560b62011-01-14 10:09:141203 }
[email protected]94fde232012-04-27 10:22:301204 return true;
[email protected]50067e52011-10-20 23:17:071205}
1206
1207void ExtensionService::OnAllExternalProvidersReady() {
1208 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]94fde232012-04-27 10:22:301209 base::TimeDelta elapsed = base::Time::Now() - profile_->GetStartTime();
1210 UMA_HISTOGRAM_TIMES("Extension.ExternalProvidersReadyAfter", elapsed);
[email protected]50067e52011-10-20 23:17:071211
1212 // Install any pending extensions.
[email protected]94fde232012-04-27 10:22:301213 if (update_once_all_providers_are_ready_ && updater()) {
1214 update_once_all_providers_are_ready_ = false;
[email protected]4e9b59d2013-12-18 06:47:141215 extensions::ExtensionUpdater::CheckParams params;
1216 params.callback = external_updates_finished_callback_;
1217 updater()->CheckNow(params);
[email protected]8e4560b62011-01-14 10:09:141218 }
1219
1220 // Uninstall all the unclaimed extensions.
[email protected]45759612012-07-10 17:21:231221 scoped_ptr<extensions::ExtensionPrefs::ExtensionsInfo> extensions_info(
[email protected]8e4560b62011-01-14 10:09:141222 extension_prefs_->GetInstalledExtensionsInfo());
1223 for (size_t i = 0; i < extensions_info->size(); ++i) {
1224 ExtensionInfo* info = extensions_info->at(i).get();
[email protected]1d5e58b2013-01-31 08:41:401225 if (Manifest::IsExternalLocation(info->extension_location))
[email protected]8e4560b62011-01-14 10:09:141226 CheckExternalUninstall(info->extension_id);
1227 }
[email protected]e5af875f2011-10-10 21:09:141228
[email protected]373daf972014-04-10 01:50:441229 error_controller_->ShowErrorIfNeeded();
[email protected]a9aa5932012-01-25 08:27:401230
[email protected]374ceb6f2014-07-02 19:25:341231 external_install_manager_->UpdateExternalExtensionAlert();
[email protected]e5af875f2011-10-10 21:09:141232}
1233
[email protected]a9f39a312010-12-23 22:14:271234void ExtensionService::UnloadExtension(
1235 const std::string& extension_id,
[email protected]b0af4792013-10-23 09:12:131236 UnloadedExtensionInfo::Reason reason) {
[email protected]27e469a2010-01-11 20:35:091237 // Make sure the extension gets deleted after we return from this function.
[email protected]599539802014-01-07 23:06:001238 int include_mask =
1239 ExtensionRegistry::EVERYTHING & ~ExtensionRegistry::TERMINATED;
[email protected]9adb9692010-10-29 23:14:021240 scoped_refptr<const Extension> extension(
[email protected]599539802014-01-07 23:06:001241 registry_->GetExtensionById(extension_id, include_mask));
[email protected]631cf822009-05-15 07:01:251242
[email protected]fa0c96732010-11-17 00:14:231243 // This method can be called via PostTask, so the extension may have been
1244 // unloaded by the time this runs.
[email protected]dc24976f2013-06-02 21:15:091245 if (!extension.get()) {
[email protected]dd163fb02011-05-04 22:22:171246 // In case the extension may have crashed/uninstalled. Allow the profile to
1247 // clean up its RequestContexts.
[email protected]31d8f5f22012-04-02 15:22:081248 system_->UnregisterExtensionWithRequestContexts(extension_id, reason);
[email protected]fa0c96732010-11-17 00:14:231249 return;
[email protected]dd163fb02011-05-04 22:22:171250 }
[email protected]0c6da502009-08-14 22:32:391251
[email protected]1eb175082010-02-10 09:26:161252 // Keep information about the extension so that we can reload it later
1253 // even if it's not permanently installed.
1254 unloaded_extension_paths_[extension->id()] = extension->path();
1255
[email protected]f17dbd42010-08-16 23:21:101256 // Clean up if the extension is meant to be enabled after a reload.
[email protected]b914e2952013-04-26 07:10:031257 reloading_extensions_.erase(extension->id());
[email protected]f17dbd42010-08-16 23:21:101258
[email protected]bb1bc9b32013-12-21 03:09:141259 if (registry_->disabled_extensions().Contains(extension->id())) {
1260 registry_->RemoveDisabled(extension->id());
[email protected]dd163fb02011-05-04 22:22:171261 // Make sure the profile cleans up its RequestContexts when an already
1262 // disabled extension is unloaded (since they are also tracking the disabled
1263 // extensions).
[email protected]31d8f5f22012-04-02 15:22:081264 system_->UnregisterExtensionWithRequestContexts(extension_id, reason);
[email protected]45f5b7d2014-01-22 23:47:131265 // Don't send the unloaded notification. It was sent when the extension
1266 // was disabled.
[email protected]60a174a2013-08-02 20:29:281267 } else {
[email protected]bb1bc9b32013-12-21 03:09:141268 // Remove the extension from the enabled list.
1269 registry_->RemoveEnabled(extension->id());
[email protected]60a174a2013-08-02 20:29:281270 NotifyExtensionUnloaded(extension.get(), reason);
[email protected]0c6da502009-08-14 22:32:391271 }
1272
[email protected]fb789532013-08-27 02:40:211273 content::NotificationService::current()->Notify(
[email protected]adf5a102014-07-31 12:44:061274 extensions::NOTIFICATION_EXTENSION_REMOVED,
[email protected]fb789532013-08-27 02:40:211275 content::Source<Profile>(profile_),
1276 content::Details<const Extension>(extension.get()));
[email protected]631cf822009-05-15 07:01:251277}
1278
[email protected]8b1ec202013-09-05 02:09:501279void ExtensionService::RemoveComponentExtension(
1280 const std::string& extension_id) {
1281 scoped_refptr<const Extension> extension(
1282 GetExtensionById(extension_id, false));
[email protected]b0af4792013-10-23 09:12:131283 UnloadExtension(extension_id, UnloadedExtensionInfo::REASON_UNINSTALL);
[email protected]ebe07772014-05-22 04:16:061284 if (extension.get()) {
1285 content::NotificationService::current()->Notify(
[email protected]adf5a102014-07-31 12:44:061286 extensions::NOTIFICATION_EXTENSION_UNINSTALLED_DEPRECATED,
[email protected]ebe07772014-05-22 04:16:061287 content::Source<Profile>(profile_),
1288 content::Details<const Extension>(extension.get()));
[email protected]e43c61f2014-07-20 21:46:341289 ExtensionRegistry::Get(profile_)->TriggerOnUninstalled(
1290 extension.get(), extensions::UNINSTALL_REASON_INTERNAL_MANAGEMENT);
[email protected]ebe07772014-05-22 04:16:061291 }
[email protected]8b1ec202013-09-05 02:09:501292}
1293
[email protected]bb1bc9b32013-12-21 03:09:141294void ExtensionService::UnloadAllExtensionsForTest() {
1295 UnloadAllExtensionsInternal();
[email protected]9f1087e2009-06-15 17:29:321296}
1297
[email protected]bb1bc9b32013-12-21 03:09:141298void ExtensionService::ReloadExtensionsForTest() {
1299 // Calling UnloadAllExtensionsForTest here triggers a false-positive presubmit
1300 // warning about calling test code in production.
1301 UnloadAllExtensionsInternal();
[email protected]eac88332012-12-26 17:57:451302 component_loader_->LoadAll();
[email protected]d8c8f25f2011-11-02 18:18:011303 extensions::InstalledLoader(this).LoadAllExtensions();
[email protected]4a10006a2013-05-17 23:18:351304 // Don't call SetReadyAndNotifyListeners() since tests call this multiple
1305 // times.
[email protected]9f1087e2009-06-15 17:29:321306}
1307
[email protected]820d9bd2013-04-03 03:46:031308void ExtensionService::SetReadyAndNotifyListeners() {
[email protected]4a10006a2013-05-17 23:18:351309 ready_->Signal();
[email protected]820d9bd2013-04-03 03:46:031310 content::NotificationService::current()->Notify(
[email protected]adf5a102014-07-31 12:44:061311 extensions::NOTIFICATION_EXTENSIONS_READY_DEPRECATED,
[email protected]820d9bd2013-04-03 03:46:031312 content::Source<Profile>(profile_),
1313 content::NotificationService::NoDetails());
1314}
1315
[email protected]eaa7dd182010-12-14 11:09:001316void ExtensionService::OnLoadedInstalledExtensions() {
[email protected]3eeddd892013-04-17 17:00:111317 if (updater_)
[email protected]93fd78f42009-07-10 16:43:171318 updater_->Start();
[email protected]fa6a9102010-11-22 15:38:501319
[email protected]bc151cf92013-02-12 04:57:261320 OnBlacklistUpdated();
[email protected]e72e8eb82009-06-18 17:21:511321}
1322
[email protected]fcb58a862012-05-01 01:03:151323void ExtensionService::AddExtension(const Extension* extension) {
[email protected]c8d407e2011-04-28 21:27:171324 // TODO(jstritar): We may be able to get rid of this branch by overriding the
1325 // default extension state to DISABLED when the --disable-extensions flag
1326 // is set (http://crbug.com/29067).
1327 if (!extensions_enabled() &&
1328 !extension->is_theme() &&
[email protected]1d5e58b2013-01-31 08:41:401329 extension->location() != Manifest::COMPONENT &&
1330 !Manifest::IsExternalLocation(extension->location())) {
[email protected]fcb58a862012-05-01 01:03:151331 return;
[email protected]330840c2012-08-29 22:21:011332 }
[email protected]c8d407e2011-04-28 21:27:171333
[email protected]b914e2952013-04-26 07:10:031334 bool is_extension_upgrade = false;
[email protected]116d40e2013-08-08 17:23:171335 bool is_extension_installed = false;
1336 const Extension* old = GetInstalledExtension(extension->id());
1337 if (old) {
1338 is_extension_installed = true;
1339 int version_compare_result =
1340 extension->version()->CompareTo(*(old->version()));
1341 is_extension_upgrade = version_compare_result > 0;
[email protected]b914e2952013-04-26 07:10:031342 // Other than for unpacked extensions, CrxInstaller should have guaranteed
1343 // that we aren't downgrading.
1344 if (!Manifest::IsUnpackedLocation(extension->location()))
[email protected]116d40e2013-08-08 17:23:171345 CHECK_GE(version_compare_result, 0);
[email protected]b914e2952013-04-26 07:10:031346 }
[email protected]45f5b7d2014-01-22 23:47:131347 system_->runtime_data()->SetBeingUpgraded(extension, is_extension_upgrade);
[email protected]c8d407e2011-04-28 21:27:171348
[email protected]1eb175082010-02-10 09:26:161349 // The extension is now loaded, remove its data from unloaded extension map.
1350 unloaded_extension_paths_.erase(extension->id());
1351
[email protected]bb7f40952011-01-13 00:21:201352 // If a terminated extension is loaded, remove it from the terminated list.
1353 UntrackTerminatedExtension(extension->id());
1354
[email protected]f17dbd42010-08-16 23:21:101355 // If the extension was disabled for a reload, then enable it.
[email protected]ca2e82022013-04-29 16:48:411356 bool reloading = reloading_extensions_.erase(extension->id()) > 0;
[email protected]f17dbd42010-08-16 23:21:101357
[email protected]b914e2952013-04-26 07:10:031358 // Check if the extension's privileges have changed and mark the
1359 // extension disabled if necessary.
[email protected]116d40e2013-08-08 17:23:171360 CheckPermissionsIncrease(extension, is_extension_installed);
[email protected]b914e2952013-04-26 07:10:031361
[email protected]116d40e2013-08-08 17:23:171362 if (is_extension_installed && !reloading) {
[email protected]ca2e82022013-04-29 16:48:411363 // To upgrade an extension in place, unload the old one and then load the
1364 // new one. ReloadExtension disables the extension, which is sufficient.
[email protected]b0af4792013-10-23 09:12:131365 UnloadExtension(extension->id(), UnloadedExtensionInfo::REASON_UPDATE);
[email protected]b914e2952013-04-26 07:10:031366 }
[email protected]0c6da502009-08-14 22:32:391367
[email protected]695b5712012-12-06 23:55:281368 if (extension_prefs_->IsExtensionBlacklisted(extension->id())) {
[email protected]ac875372013-02-28 04:36:091369 // Only prefs is checked for the blacklist. We rely on callers to check the
1370 // blacklist before calling into here, e.g. CrxInstaller checks before
[email protected]9f3c8532013-07-31 19:52:071371 // installation then threads through the install and pending install flow
1372 // of this class, and we check when loading installed extensions.
[email protected]bb1bc9b32013-12-21 03:09:141373 registry_->AddBlacklisted(extension);
[email protected]ca2e82022013-04-29 16:48:411374 } else if (!reloading &&
1375 extension_prefs_->IsExtensionDisabled(extension->id())) {
[email protected]bb1bc9b32013-12-21 03:09:141376 registry_->AddDisabled(extension);
[email protected]f8aefb132013-10-30 09:29:521377 if (extension_sync_service_)
1378 extension_sync_service_->SyncExtensionChangeIfNeeded(*extension);
[email protected]44d62b62012-04-11 00:06:031379 content::NotificationService::current()->Notify(
[email protected]adf5a102014-07-31 12:44:061380 extensions::NOTIFICATION_EXTENSION_UPDATE_DISABLED,
[email protected]44d62b62012-04-11 00:06:031381 content::Source<Profile>(profile_),
1382 content::Details<const Extension>(extension));
[email protected]62f051c2012-03-29 17:04:441383
[email protected]21db9ef2014-05-16 02:06:271384 // Show the extension disabled error if a permissions increase or a remote
1385 // installation is the reason it was disabled, and no other reasons exist.
1386 int reasons = extension_prefs_->GetDisableReasons(extension->id());
1387 const int kReasonMask = Extension::DISABLE_PERMISSIONS_INCREASE |
1388 Extension::DISABLE_REMOTE_INSTALL;
1389 if (reasons & kReasonMask && !(reasons & ~kReasonMask)) {
1390 extensions::AddExtensionDisabledError(
1391 this,
1392 extension,
1393 extension_prefs_->HasDisableReason(
1394 extension->id(), Extension::DISABLE_REMOTE_INSTALL));
[email protected]62f051c2012-03-29 17:04:441395 }
[email protected]ca2e82022013-04-29 16:48:411396 } else if (reloading) {
1397 // Replace the old extension with the new version.
[email protected]bb1bc9b32013-12-21 03:09:141398 CHECK(!registry_->AddDisabled(extension));
[email protected]ca2e82022013-04-29 16:48:411399 EnableExtension(extension->id());
[email protected]695b5712012-12-06 23:55:281400 } else {
1401 // All apps that are displayed in the launcher are ordered by their ordinals
1402 // so we must ensure they have valid ordinals.
1403 if (extension->RequiresSortOrdinal()) {
[email protected]db378322014-07-21 23:19:341404 extension_prefs_->app_sorting()->SetExtensionVisible(
1405 extension->id(),
1406 extension->ShouldDisplayInNewTabPage() &&
1407 !extension_prefs_->IsEphemeralApp(extension->id()));
1408 if (!extension_prefs_->IsEphemeralApp(extension->id())) {
1409 extension_prefs_->app_sorting()->EnsureValidOrdinals(
1410 extension->id(), syncer::StringOrdinal());
[email protected]bd36b652013-02-27 02:13:251411 }
[email protected]695b5712012-12-06 23:55:281412 }
1413
[email protected]bb1bc9b32013-12-21 03:09:141414 registry_->AddEnabled(extension);
[email protected]f8aefb132013-10-30 09:29:521415 if (extension_sync_service_)
1416 extension_sync_service_->SyncExtensionChangeIfNeeded(*extension);
[email protected]695b5712012-12-06 23:55:281417 NotifyExtensionLoaded(extension);
[email protected]f574c402012-12-04 23:20:311418 }
[email protected]45f5b7d2014-01-22 23:47:131419 system_->runtime_data()->SetBeingUpgraded(extension, false);
[email protected]aab98a52009-12-02 03:22:351420}
1421
[email protected]8c484b742012-11-29 06:05:361422void ExtensionService::AddComponentExtension(const Extension* extension) {
1423 const std::string old_version_string(
1424 extension_prefs_->GetVersionString(extension->id()));
[email protected]c5e4a2222014-01-03 16:06:131425 const Version old_version(old_version_string);
[email protected]8c484b742012-11-29 06:05:361426
[email protected]0181a7d2013-11-12 01:08:421427 VLOG(1) << "AddComponentExtension " << extension->name();
[email protected]8c484b742012-11-29 06:05:361428 if (!old_version.IsValid() || !old_version.Equals(*extension->version())) {
1429 VLOG(1) << "Component extension " << extension->name() << " ("
1430 << extension->id() << ") installing/upgrading from '"
1431 << old_version_string << "' to " << extension->version()->GetString();
1432
1433 AddNewOrUpdatedExtension(extension,
[email protected]9ae73962014-08-14 16:53:411434 Extension::ENABLED,
[email protected]4a1d9c0d2014-06-13 12:50:111435 extensions::kInstallFlagNone,
[email protected]d8fd0fd2014-03-24 13:16:061436 syncer::StringOrdinal(),
1437 std::string());
[email protected]8c484b742012-11-29 06:05:361438 return;
1439 }
1440
1441 AddExtension(extension);
1442}
1443
[email protected]b914e2952013-04-26 07:10:031444void ExtensionService::CheckPermissionsIncrease(const Extension* extension,
[email protected]116d40e2013-08-08 17:23:171445 bool is_extension_installed) {
[email protected]23a85362014-07-07 23:26:191446 extensions::PermissionsUpdater(profile_).InitializePermissions(extension);
[email protected]902fd7b2011-07-27 18:42:311447
[email protected]8d888c12010-11-30 00:00:251448 // We keep track of all permissions the user has granted each extension.
1449 // This allows extensions to gracefully support backwards compatibility
1450 // by including unknown permissions in their manifests. When the user
1451 // installs the extension, only the recognized permissions are recorded.
1452 // When the unknown permissions become recognized (e.g., through browser
1453 // upgrade), we can prompt the user to accept these new permissions.
1454 // Extensions can also silently upgrade to less permissions, and then
1455 // silently upgrade to a version that adds these permissions back.
1456 //
1457 // For example, pretend that Chrome 10 includes a permission "omnibox"
1458 // for an API that adds suggestions to the omnibox. An extension can
1459 // maintain backwards compatibility while still having "omnibox" in the
1460 // manifest. If a user installs the extension on Chrome 9, the browser
1461 // will record the permissions it recognized, not including "omnibox."
1462 // When upgrading to Chrome 10, "omnibox" will be recognized and Chrome
1463 // will disable the extension and prompt the user to approve the increase
1464 // in privileges. The extension could then release a new version that
1465 // removes the "omnibox" permission. When the user upgrades, Chrome will
1466 // still remember that "omnibox" had been granted, so that if the
1467 // extension once again includes "omnibox" in an upgrade, the extension
1468 // can upgrade without requiring this user's approval.
[email protected]eb5e4f92012-08-15 23:33:281469 int disable_reasons = extension_prefs_->GetDisableReasons(extension->id());
[email protected]8d888c12010-11-30 00:00:251470
[email protected]211a3f32013-05-28 21:48:181471 bool auto_grant_permission =
[email protected]1b563df2013-10-30 16:49:361472 (!is_extension_installed && extension->was_installed_by_default()) ||
[email protected]45928b682013-11-28 08:20:271473 extensions::ExtensionsBrowserClient::Get()->IsRunningInForcedAppMode();
[email protected]b914e2952013-04-26 07:10:031474 // Silently grant all active permissions to default apps only on install.
1475 // After install they should behave like other apps.
[email protected]211a3f32013-05-28 21:48:181476 // Silently grant all active permissions to apps install in kiosk mode on both
1477 // install and update.
1478 if (auto_grant_permission)
[email protected]b914e2952013-04-26 07:10:031479 GrantPermissions(extension);
1480
1481 bool is_privilege_increase = false;
1482 // We only need to compare the granted permissions to the current permissions
1483 // if the extension is not allowed to silently increase its permissions.
[email protected]13c68b62013-05-17 11:29:051484 if (!extensions::PermissionsData::CanSilentlyIncreasePermissions(extension) &&
[email protected]211a3f32013-05-28 21:48:181485 !auto_grant_permission) {
[email protected]8d888c12010-11-30 00:00:251486 // Add all the recognized permissions if the granted permissions list
1487 // hasn't been initialized yet.
[email protected]c2e66e12012-06-27 06:27:061488 scoped_refptr<PermissionSet> granted_permissions =
[email protected]902fd7b2011-07-27 18:42:311489 extension_prefs_->GetGrantedPermissions(extension->id());
[email protected]0d3e4a22011-06-23 19:02:521490 CHECK(granted_permissions.get());
[email protected]8d888c12010-11-30 00:00:251491
1492 // Here, we check if an extension's privileges have increased in a manner
1493 // that requires the user's approval. This could occur because the browser
1494 // upgraded and recognized additional privileges, or an extension upgrades
1495 // to a version that requires additional privileges.
[email protected]c41003472013-10-19 15:37:251496 is_privilege_increase =
1497 extensions::PermissionMessageProvider::Get()->IsPrivilegeIncrease(
dchengc7047942014-08-26 05:05:311498 granted_permissions.get(),
[email protected]076ebeda2014-06-06 21:47:261499 extension->permissions_data()->active_permissions().get(),
1500 extension->GetType());
[email protected]8d888c12010-11-30 00:00:251501 }
1502
[email protected]116d40e2013-08-08 17:23:171503 if (is_extension_installed) {
[email protected]44d62b62012-04-11 00:06:031504 // If the extension was already disabled, suppress any alerts for becoming
1505 // disabled on permissions increase.
[email protected]b914e2952013-04-26 07:10:031506 bool previously_disabled =
1507 extension_prefs_->IsExtensionDisabled(extension->id());
[email protected]7e9e2422012-12-13 19:54:191508 // Legacy disabled extensions do not have a disable reason. Infer that if
1509 // there was no permission increase, it was likely disabled by the user.
1510 if (previously_disabled && disable_reasons == Extension::DISABLE_NONE &&
[email protected]b914e2952013-04-26 07:10:031511 !extension_prefs_->DidExtensionEscalatePermissions(extension->id())) {
[email protected]7e9e2422012-12-13 19:54:191512 disable_reasons |= Extension::DISABLE_USER_ACTION;
[email protected]44d62b62012-04-11 00:06:031513 }
[email protected]7e9e2422012-12-13 19:54:191514 // Extensions that came to us disabled from sync need a similar inference,
1515 // except based on the new version's permissions.
1516 if (previously_disabled &&
1517 disable_reasons == Extension::DISABLE_UNKNOWN_FROM_SYNC) {
1518 // Remove the DISABLE_UNKNOWN_FROM_SYNC reason.
1519 extension_prefs_->ClearDisableReasons(extension->id());
1520 if (!is_privilege_increase)
1521 disable_reasons |= Extension::DISABLE_USER_ACTION;
1522 }
[email protected]b914e2952013-04-26 07:10:031523 disable_reasons &= ~Extension::DISABLE_UNKNOWN_FROM_SYNC;
[email protected]8d888c12010-11-30 00:00:251524 }
1525
1526 // Extension has changed permissions significantly. Disable it. A
[email protected]21db9ef2014-05-16 02:06:271527 // notification should be sent by the caller. If the extension is already
1528 // disabled because it was installed remotely, don't add another disable
1529 // reason, but instead always set the "did escalate permissions" flag, to
1530 // ensure enabling it will always show a warning.
1531 if (disable_reasons == Extension::DISABLE_REMOTE_INSTALL) {
1532 extension_prefs_->SetDidExtensionEscalatePermissions(extension, true);
1533 } else if (is_privilege_increase) {
[email protected]7e9e2422012-12-13 19:54:191534 disable_reasons |= Extension::DISABLE_PERMISSIONS_INCREASE;
[email protected]fe2dd7742011-04-19 22:52:491535 if (!extension_prefs_->DidExtensionEscalatePermissions(extension->id())) {
[email protected]4c86be582014-06-04 08:39:111536 RecordPermissionMessagesHistogram(extension,
1537 "Extensions.Permissions_AutoDisable2");
[email protected]fe2dd7742011-04-19 22:52:491538 }
[email protected]195c1582013-10-29 18:42:231539 extension_prefs_->SetExtensionState(extension->id(), Extension::DISABLED);
[email protected]8d888c12010-11-30 00:00:251540 extension_prefs_->SetDidExtensionEscalatePermissions(extension, true);
[email protected]b914e2952013-04-26 07:10:031541 }
1542 if (disable_reasons != Extension::DISABLE_NONE) {
[email protected]eb5e4f92012-08-15 23:33:281543 extension_prefs_->AddDisableReason(
1544 extension->id(),
1545 static_cast<Extension::DisableReason>(disable_reasons));
[email protected]8d888c12010-11-30 00:00:251546 }
1547}
1548
[email protected]eaa7dd182010-12-14 11:09:001549void ExtensionService::UpdateActiveExtensionsInCrashReporter() {
[email protected]c8865962009-12-16 07:47:391550 std::set<std::string> extension_ids;
[email protected]bb1bc9b32013-12-21 03:09:141551 const ExtensionSet& extensions = registry_->enabled_extensions();
1552 for (ExtensionSet::const_iterator iter = extensions.begin();
1553 iter != extensions.end(); ++iter) {
[email protected]cadac622013-06-11 16:46:361554 const Extension* extension = iter->get();
[email protected]1d5e58b2013-01-31 08:41:401555 if (!extension->is_theme() && extension->location() != Manifest::COMPONENT)
[email protected]84df8332011-12-06 18:22:461556 extension_ids.insert(extension->id());
[email protected]aab98a52009-12-02 03:22:351557 }
1558
[email protected]dcc47642014-03-26 22:03:491559 // TODO(kalman): This is broken. ExtensionService is per-profile.
1560 // crash_keys::SetActiveExtensions is per-process. See
1561 // http://crbug.com/355029.
[email protected]f6431be82013-09-07 02:53:451562 crash_keys::SetActiveExtensions(extension_ids);
[email protected]6014d672008-12-05 00:38:251563}
1564
[email protected]8266d662011-07-12 21:53:261565void ExtensionService::OnExtensionInstalled(
[email protected]36a5c4c2011-12-14 16:34:501566 const Extension* extension,
[email protected]98270432012-09-11 20:51:241567 const syncer::StringOrdinal& page_ordinal,
[email protected]4a1d9c0d2014-06-13 12:50:111568 int install_flags) {
[email protected]a29a517a2011-01-21 21:11:121569 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]a8af9fdb2010-10-28 21:52:201570
[email protected]c3cfb012011-04-06 22:07:351571 const std::string& id = extension->id();
[email protected]612a1cb12012-10-17 13:18:031572 bool initial_enable = ShouldEnableOnInstall(extension);
[email protected]d8fd0fd2014-03-24 13:16:061573 std::string install_parameter;
[email protected]96aebe22014-07-16 04:07:511574 const extensions::PendingExtensionInfo* pending_extension_info =
1575 pending_extension_manager()->GetById(id);
1576 if (pending_extension_info) {
[email protected]8f3bcbd2013-06-05 08:42:401577 if (!pending_extension_info->ShouldAllowInstall(extension)) {
[email protected]51a3bf8b2012-06-08 22:53:061578 pending_extension_manager()->Remove(id);
[email protected]8ef78fd2010-08-19 17:14:321579
[email protected]31bb5ee62012-09-12 22:58:401580 LOG(WARNING) << "ShouldAllowInstall() returned false for "
1581 << id << " of type " << extension->GetType()
[email protected]65348062013-01-15 07:27:221582 << " and update URL "
1583 << extensions::ManifestURL::GetUpdateURL(extension).spec()
[email protected]31bb5ee62012-09-12 22:58:401584 << "; not installing";
[email protected]ae6cb3022011-04-04 20:11:541585
[email protected]4416c5a2010-06-26 01:28:571586 // Delete the extension directory since we're not going to
1587 // load it.
[email protected]7f8f24f2012-11-15 19:40:141588 if (!GetFileTaskRunner()->PostTask(
1589 FROM_HERE,
[email protected]85df9d12014-04-15 17:02:141590 base::Bind(&extensions::file_util::DeleteFile,
1591 extension->path(),
1592 true))) {
[email protected]14908b72011-04-20 06:54:361593 NOTREACHED();
[email protected]31bb5ee62012-09-12 22:58:401594 }
[email protected]4416c5a2010-06-26 01:28:571595 return;
1596 }
[email protected]51a3bf8b2012-06-08 22:53:061597
[email protected]d8fd0fd2014-03-24 13:16:061598 install_parameter = pending_extension_info->install_parameter();
[email protected]51a3bf8b2012-06-08 22:53:061599 pending_extension_manager()->Remove(id);
[email protected]4416c5a2010-06-26 01:28:571600 } else {
[email protected]c3cfb012011-04-06 22:07:351601 // We explicitly want to re-enable an uninstalled external
1602 // extension; if we're here, that means the user is manually
1603 // installing the extension.
[email protected]46f3e102014-03-25 01:22:451604 if (extension_prefs_->IsExternalExtensionUninstalled(id)) {
[email protected]6cc7dbae2011-04-29 21:18:331605 initial_enable = true;
1606 }
[email protected]aa142702010-03-26 01:26:331607 }
1608
[email protected]98270432012-09-11 20:51:241609 // Unsupported requirements overrides the management policy.
[email protected]4a1d9c0d2014-06-13 12:50:111610 if (install_flags & extensions::kInstallFlagHasRequirementErrors) {
[email protected]98270432012-09-11 20:51:241611 initial_enable = false;
1612 extension_prefs_->AddDisableReason(
1613 id, Extension::DISABLE_UNSUPPORTED_REQUIREMENT);
1614 // If the extension was disabled because of unsupported requirements but
1615 // now supports all requirements after an update and there are not other
1616 // disable reasons, enable it.
1617 } else if (extension_prefs_->GetDisableReasons(id) ==
1618 Extension::DISABLE_UNSUPPORTED_REQUIREMENT) {
1619 initial_enable = true;
1620 extension_prefs_->ClearDisableReasons(id);
1621 }
1622
[email protected]4a1d9c0d2014-06-13 12:50:111623 if (install_flags & extensions::kInstallFlagIsBlacklistedForMalware) {
[email protected]9f3c8532013-07-31 19:52:071624 // Installation of a blacklisted extension can happen from sync, policy,
1625 // etc, where to maintain consistency we need to install it, just never
1626 // load it (see AddExtension). Usually it should be the job of callers to
1627 // incercept blacklisted extension earlier (e.g. CrxInstaller, before even
1628 // showing the install dialogue).
[email protected]7c82539c2014-02-19 06:09:171629 extension_prefs_->AcknowledgeBlacklistedExtension(id);
[email protected]9f3c8532013-07-31 19:52:071630 UMA_HISTOGRAM_ENUMERATION("ExtensionBlacklist.SilentInstall",
1631 extension->location(),
1632 Manifest::NUM_LOCATIONS);
1633 }
1634
[email protected]695b5712012-12-06 23:55:281635 if (!GetInstalledExtension(extension->id())) {
[email protected]07533022011-06-27 20:42:551636 UMA_HISTOGRAM_ENUMERATION("Extensions.InstallType",
1637 extension->GetType(), 100);
[email protected]69084dc2012-11-17 07:39:301638 UMA_HISTOGRAM_ENUMERATION("Extensions.InstallSource",
[email protected]1d5e58b2013-01-31 08:41:401639 extension->location(), Manifest::NUM_LOCATIONS);
[email protected]4c86be582014-06-04 08:39:111640 RecordPermissionMessagesHistogram(extension,
1641 "Extensions.Permissions_Install2");
[email protected]69084dc2012-11-17 07:39:301642 } else {
1643 UMA_HISTOGRAM_ENUMERATION("Extensions.UpdateType",
1644 extension->GetType(), 100);
1645 UMA_HISTOGRAM_ENUMERATION("Extensions.UpdateSource",
[email protected]1d5e58b2013-01-31 08:41:401646 extension->location(), Manifest::NUM_LOCATIONS);
[email protected]8f959f522014-08-06 06:26:281647
1648 // A fully installed app cannot be demoted to an ephemeral app.
1649 if ((install_flags & extensions::kInstallFlagIsEphemeral) &&
1650 !extension_prefs_->IsEphemeralApp(id)) {
1651 install_flags &= ~static_cast<int>(extensions::kInstallFlagIsEphemeral);
1652 }
[email protected]07533022011-06-27 20:42:551653 }
1654
[email protected]399583b2012-12-11 09:33:421655 const Extension::State initial_state =
1656 initial_enable ? Extension::ENABLED : Extension::DISABLED;
[email protected]4a1d9c0d2014-06-13 12:50:111657 if (ShouldDelayExtensionUpdate(
1658 id,
1659 !!(install_flags & extensions::kInstallFlagInstallImmediately))) {
[email protected]9f3c8532013-07-31 19:52:071660 extension_prefs_->SetDelayedInstallInfo(
1661 extension,
1662 initial_state,
[email protected]4a1d9c0d2014-06-13 12:50:111663 install_flags,
[email protected]9f3c8532013-07-31 19:52:071664 extensions::ExtensionPrefs::DELAY_REASON_WAIT_FOR_IDLE,
[email protected]d8fd0fd2014-03-24 13:16:061665 page_ordinal,
1666 install_parameter);
[email protected]0db124b02012-11-07 04:55:051667
1668 // Transfer ownership of |extension|.
[email protected]9f4e4f082013-06-21 07:11:191669 delayed_installs_.Insert(extension);
[email protected]0db124b02012-11-07 04:55:051670
[email protected]75bdcb872013-03-13 00:41:451671 // Notify observers that app update is available.
1672 FOR_EACH_OBSERVER(extensions::UpdateObserver, update_observers_,
[email protected]a9aa62b312013-11-29 05:35:061673 OnAppUpdateAvailable(extension));
[email protected]0db124b02012-11-07 04:55:051674 return;
1675 }
1676
[email protected]90878c52014-04-04 18:21:021677 extensions::SharedModuleService::ImportStatus status =
1678 shared_module_service_->SatisfyImports(extension);
[email protected]e5f8fffe2014-04-02 00:30:441679 if (installs_delayed_for_gc_) {
[email protected]9f3c8532013-07-31 19:52:071680 extension_prefs_->SetDelayedInstallInfo(
1681 extension,
1682 initial_state,
[email protected]4a1d9c0d2014-06-13 12:50:111683 install_flags,
[email protected]9f3c8532013-07-31 19:52:071684 extensions::ExtensionPrefs::DELAY_REASON_GC,
[email protected]d8fd0fd2014-03-24 13:16:061685 page_ordinal,
1686 install_parameter);
[email protected]399583b2012-12-11 09:33:421687 delayed_installs_.Insert(extension);
[email protected]90878c52014-04-04 18:21:021688 } else if (status != SharedModuleService::IMPORT_STATUS_OK) {
1689 if (status == SharedModuleService::IMPORT_STATUS_UNSATISFIED) {
[email protected]9f3c8532013-07-31 19:52:071690 extension_prefs_->SetDelayedInstallInfo(
1691 extension,
1692 initial_state,
[email protected]4a1d9c0d2014-06-13 12:50:111693 install_flags,
[email protected]9f4e4f082013-06-21 07:11:191694 extensions::ExtensionPrefs::DELAY_REASON_WAIT_FOR_IMPORTS,
[email protected]d8fd0fd2014-03-24 13:16:061695 page_ordinal,
1696 install_parameter);
[email protected]9f4e4f082013-06-21 07:11:191697 delayed_installs_.Insert(extension);
1698 }
[email protected]399583b2012-12-11 09:33:421699 } else {
[email protected]9f3c8532013-07-31 19:52:071700 AddNewOrUpdatedExtension(extension,
1701 initial_state,
[email protected]4a1d9c0d2014-06-13 12:50:111702 install_flags,
[email protected]d8fd0fd2014-03-24 13:16:061703 page_ordinal,
1704 install_parameter);
[email protected]399583b2012-12-11 09:33:421705 }
[email protected]8c484b742012-11-29 06:05:361706}
1707
binjin1569c9b2014-09-05 13:33:181708void ExtensionService::OnExtensionManagementSettingsChanged() {
1709 error_controller_->ShowErrorIfNeeded();
1710 CheckManagementPolicy();
1711}
1712
[email protected]8c484b742012-11-29 06:05:361713void ExtensionService::AddNewOrUpdatedExtension(
1714 const Extension* extension,
[email protected]399583b2012-12-11 09:33:421715 Extension::State initial_state,
[email protected]4a1d9c0d2014-06-13 12:50:111716 int install_flags,
[email protected]d8fd0fd2014-03-24 13:16:061717 const syncer::StringOrdinal& page_ordinal,
1718 const std::string& install_parameter) {
[email protected]8c484b742012-11-29 06:05:361719 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]760f743b2014-05-28 13:52:021720 bool was_ephemeral = extension_prefs_->IsEphemeralApp(extension->id());
[email protected]4a1d9c0d2014-06-13 12:50:111721 extension_prefs_->OnExtensionInstalled(
1722 extension, initial_state, page_ordinal, install_flags, install_parameter);
[email protected]9e9c1d12013-07-31 01:58:121723 delayed_installs_.Remove(extension->id());
[email protected]913ffca92014-03-27 15:26:161724 if (InstallVerifier::NeedsVerification(*extension))
1725 system_->install_verifier()->VerifyExtension(extension->id());
[email protected]760f743b2014-05-28 13:52:021726 FinishInstallation(extension, was_ephemeral);
[email protected]6f6101832012-11-27 22:10:481727}
1728
1729void ExtensionService::MaybeFinishDelayedInstallation(
1730 const std::string& extension_id) {
[email protected]9f4e4f082013-06-21 07:11:191731 // Check if the extension already got installed.
1732 if (!delayed_installs_.Contains(extension_id))
[email protected]6f6101832012-11-27 22:10:481733 return;
[email protected]9f4e4f082013-06-21 07:11:191734 extensions::ExtensionPrefs::DelayReason reason =
1735 extension_prefs_->GetDelayedInstallReason(extension_id);
1736
1737 // Check if the extension is idle. DELAY_REASON_NONE is used for older
1738 // preferences files that will not have set this field but it was previously
1739 // only used for idle updates.
1740 if ((reason == extensions::ExtensionPrefs::DELAY_REASON_WAIT_FOR_IDLE ||
1741 reason == extensions::ExtensionPrefs::DELAY_REASON_NONE) &&
[email protected]1d5cf4142014-01-24 18:25:221742 is_ready() && !extensions::util::IsExtensionIdle(extension_id, profile_))
[email protected]6f6101832012-11-27 22:10:481743 return;
1744
[email protected]9f4e4f082013-06-21 07:11:191745 const Extension* extension = delayed_installs_.GetByID(extension_id);
1746 if (reason == extensions::ExtensionPrefs::DELAY_REASON_WAIT_FOR_IMPORTS) {
[email protected]90878c52014-04-04 18:21:021747 extensions::SharedModuleService::ImportStatus status =
1748 shared_module_service_->SatisfyImports(extension);
1749 if (status != SharedModuleService::IMPORT_STATUS_OK) {
1750 if (status == SharedModuleService::IMPORT_STATUS_UNRECOVERABLE) {
[email protected]9f4e4f082013-06-21 07:11:191751 delayed_installs_.Remove(extension_id);
1752 // Make sure no version of the extension is actually installed, (i.e.,
1753 // that this delayed install was not an update).
1754 CHECK(!extension_prefs_->GetInstalledExtensionInfo(extension_id).get());
1755 extension_prefs_->DeleteExtensionPrefs(extension_id);
1756 }
1757 return;
1758 }
1759 }
1760
[email protected]6f6101832012-11-27 22:10:481761 FinishDelayedInstallation(extension_id);
1762}
1763
1764void ExtensionService::FinishDelayedInstallation(
1765 const std::string& extension_id) {
1766 scoped_refptr<const Extension> extension(
1767 GetPendingExtensionUpdate(extension_id));
[email protected]dc24976f2013-06-02 21:15:091768 CHECK(extension.get());
[email protected]9f4e4f082013-06-21 07:11:191769 delayed_installs_.Remove(extension_id);
[email protected]6f6101832012-11-27 22:10:481770
[email protected]760f743b2014-05-28 13:52:021771 bool was_ephemeral = extension_prefs_->IsEphemeralApp(extension->id());
[email protected]399583b2012-12-11 09:33:421772 if (!extension_prefs_->FinishDelayedInstallInfo(extension_id))
[email protected]6f6101832012-11-27 22:10:481773 NOTREACHED();
1774
[email protected]760f743b2014-05-28 13:52:021775 FinishInstallation(extension.get(), was_ephemeral);
[email protected]6f6101832012-11-27 22:10:481776}
1777
[email protected]760f743b2014-05-28 13:52:021778void ExtensionService::FinishInstallation(
1779 const Extension* extension, bool was_ephemeral) {
[email protected]e7554c3f2013-05-29 00:36:561780 const extensions::Extension* existing_extension =
1781 GetInstalledExtension(extension->id());
1782 bool is_update = false;
1783 std::string old_name;
1784 if (existing_extension) {
1785 is_update = true;
1786 old_name = existing_extension->name();
1787 }
[email protected]760f743b2014-05-28 13:52:021788 bool from_ephemeral =
1789 was_ephemeral && !extension_prefs_->IsEphemeralApp(extension->id());
1790 extensions::InstalledExtensionInfo details(
1791 extension, is_update, from_ephemeral, old_name);
[email protected]fcb58a862012-05-01 01:03:151792 content::NotificationService::current()->Notify(
[email protected]adf5a102014-07-31 12:44:061793 extensions::NOTIFICATION_EXTENSION_WILL_BE_INSTALLED_DEPRECATED,
[email protected]fcb58a862012-05-01 01:03:151794 content::Source<Profile>(profile_),
[email protected]41bb80bd2013-05-03 10:56:021795 content::Details<const extensions::InstalledExtensionInfo>(&details));
[email protected]fcb58a862012-05-01 01:03:151796
[email protected]bc44b5da2014-06-12 14:20:001797 registry_->TriggerOnWillBeInstalled(
[email protected]760f743b2014-05-28 13:52:021798 extension, is_update, from_ephemeral, old_name);
[email protected]17f07822014-05-22 08:45:151799
[email protected]399583b2012-12-11 09:33:421800 // Unpacked extensions default to allowing file access, but if that has been
1801 // overridden, don't reset the value.
[email protected]1d5e58b2013-01-31 08:41:401802 if (Manifest::ShouldAlwaysAllowFileAccess(extension->location()) &&
[email protected]399583b2012-12-11 09:33:421803 !extension_prefs_->HasAllowFileAccessSetting(extension->id())) {
1804 extension_prefs_->SetAllowFileAccess(extension->id(), true);
1805 }
1806
[email protected]6f6101832012-11-27 22:10:481807 AddExtension(extension);
[email protected]612a1cb12012-10-17 13:18:031808
[email protected]bc44b5da2014-06-12 14:20:001809 // Notify observers that need to know when an installation is complete.
[email protected]38e872532014-07-16 23:27:511810 registry_->TriggerOnInstalled(extension, is_update);
[email protected]bc44b5da2014-06-12 14:20:001811
[email protected]9f4e4f082013-06-21 07:11:191812 // Check extensions that may have been delayed only because this shared module
1813 // was not available.
[email protected]374ceb6f2014-07-02 19:25:341814 if (SharedModuleInfo::IsSharedModule(extension))
[email protected]9f4e4f082013-06-21 07:11:191815 MaybeFinishDelayedInstallations();
[email protected]4a190632009-05-09 01:07:421816}
1817
[email protected]760f743b2014-05-28 13:52:021818void ExtensionService::PromoteEphemeralApp(
1819 const extensions::Extension* extension, bool is_from_sync) {
1820 DCHECK(GetInstalledExtension(extension->id()) &&
1821 extension_prefs_->IsEphemeralApp(extension->id()));
1822
[email protected]db378322014-07-21 23:19:341823 if (extension->RequiresSortOrdinal()) {
1824 extension_prefs_->app_sorting()->SetExtensionVisible(
1825 extension->id(), extension->ShouldDisplayInNewTabPage());
1826
1827 if (!is_from_sync) {
[email protected]760f743b2014-05-28 13:52:021828 // Reset the sort ordinals of the app to ensure it is added to the default
1829 // position, like newly installed apps would.
1830 extension_prefs_->app_sorting()->ClearOrdinals(extension->id());
[email protected]760f743b2014-05-28 13:52:021831 }
1832
[email protected]db378322014-07-21 23:19:341833 extension_prefs_->app_sorting()->EnsureValidOrdinals(
1834 extension->id(), syncer::StringOrdinal());
1835 }
1836
[email protected]760f743b2014-05-28 13:52:021837 // Remove the ephemeral flags from the preferences.
1838 extension_prefs_->OnEphemeralAppPromoted(extension->id());
1839
1840 // Fire install-related events to allow observers to handle the promotion
1841 // of the ephemeral app.
1842 extensions::InstalledExtensionInfo details(
1843 extension,
1844 true /* is update */,
1845 true /* from ephemeral */,
1846 extension->name() /* old name */);
1847 content::NotificationService::current()->Notify(
[email protected]adf5a102014-07-31 12:44:061848 extensions::NOTIFICATION_EXTENSION_WILL_BE_INSTALLED_DEPRECATED,
[email protected]760f743b2014-05-28 13:52:021849 content::Source<Profile>(profile_),
1850 content::Details<const extensions::InstalledExtensionInfo>(&details));
1851
1852 registry_->TriggerOnWillBeInstalled(
1853 extension,
1854 true /* is update */,
1855 true /* from ephemeral */,
1856 extension->name() /* old name */);
1857
1858 if (registry_->enabled_extensions().Contains(extension->id())) {
[email protected]8f959f522014-08-06 06:26:281859 // If the app is already enabled and loaded, fire the load events to allow
1860 // observers to handle the promotion of the ephemeral app.
[email protected]760f743b2014-05-28 13:52:021861 content::NotificationService::current()->Notify(
[email protected]adf5a102014-07-31 12:44:061862 extensions::NOTIFICATION_EXTENSION_LOADED_DEPRECATED,
[email protected]760f743b2014-05-28 13:52:021863 content::Source<Profile>(profile_),
1864 content::Details<const Extension>(extension));
1865
1866 registry_->TriggerOnLoaded(extension);
[email protected]8f959f522014-08-06 06:26:281867 } else {
1868 // Cached ephemeral apps may be updated and disabled due to permissions
1869 // increase. The app can be enabled (as long as no other disable reasons
1870 // exist) as the install was user-acknowledged.
1871 int disable_mask = Extension::DISABLE_NONE;
1872 if (!is_from_sync)
1873 disable_mask |= Extension::DISABLE_PERMISSIONS_INCREASE;
1874
1875 int other_disable_reasons =
1876 extension_prefs_->GetDisableReasons(extension->id()) & ~disable_mask;
1877 if (!other_disable_reasons) {
1878 if (extension_prefs_->DidExtensionEscalatePermissions(extension->id()))
1879 GrantPermissionsAndEnableExtension(extension);
1880 else
1881 EnableExtension(extension->id());
1882 }
[email protected]760f743b2014-05-28 13:52:021883 }
1884
[email protected]38e872532014-07-16 23:27:511885 registry_->TriggerOnInstalled(extension, true);
[email protected]bc44b5da2014-06-12 14:20:001886
[email protected]760f743b2014-05-28 13:52:021887 if (!is_from_sync && extension_sync_service_)
1888 extension_sync_service_->SyncExtensionChangeIfNeeded(*extension);
1889}
1890
[email protected]76b65442012-11-17 14:11:481891const Extension* ExtensionService::GetPendingExtensionUpdate(
1892 const std::string& id) const {
[email protected]9f4e4f082013-06-21 07:11:191893 return delayed_installs_.GetByID(id);
[email protected]76b65442012-11-17 14:11:481894}
1895
mukai87a8d402014-09-15 20:15:091896void ExtensionService::RegisterContentSettings(
1897 HostContentSettingsMap* host_content_settings_map) {
1898 host_content_settings_map->RegisterProvider(
1899 HostContentSettingsMap::INTERNAL_EXTENSION_PROVIDER,
1900 scoped_ptr<content_settings::ObservableProvider>(
1901 new content_settings::InternalExtensionProvider(this)));
1902
1903 host_content_settings_map->RegisterProvider(
1904 HostContentSettingsMap::CUSTOM_EXTENSION_PROVIDER,
1905 scoped_ptr<content_settings::ObservableProvider>(
1906 new content_settings::CustomExtensionProvider(
1907 extensions::ContentSettingsService::Get(
1908 profile_)->content_settings_store(),
1909 profile_->GetOriginalProfile() != profile_)));
1910}
1911
[email protected]bb7f40952011-01-13 00:21:201912void ExtensionService::TrackTerminatedExtension(const Extension* extension) {
[email protected]bb1bc9b32013-12-21 03:09:141913 // No need to check for duplicates; inserting a duplicate is a no-op.
1914 registry_->AddTerminated(make_scoped_refptr(extension));
[email protected]3964e572014-02-13 21:57:411915 extensions_being_terminated_.erase(extension->id());
[email protected]b0af4792013-10-23 09:12:131916 UnloadExtension(extension->id(), UnloadedExtensionInfo::REASON_TERMINATE);
[email protected]bb7f40952011-01-13 00:21:201917}
1918
[email protected]e9d7496e2014-04-18 01:25:461919void ExtensionService::TerminateExtension(const std::string& extension_id) {
1920 const Extension* extension = GetInstalledExtension(extension_id);
1921 TrackTerminatedExtension(extension);
1922}
1923
[email protected]bb7f40952011-01-13 00:21:201924void ExtensionService::UntrackTerminatedExtension(const std::string& id) {
[email protected]cb1f4ac2014-08-07 16:55:421925 std::string lowercase_id = base::StringToLowerASCII(id);
[email protected]bb1bc9b32013-12-21 03:09:141926 const Extension* extension =
1927 registry_->terminated_extensions().GetByID(lowercase_id);
1928 registry_->RemoveTerminated(lowercase_id);
[email protected]fb789532013-08-27 02:40:211929 if (extension) {
1930 content::NotificationService::current()->Notify(
[email protected]adf5a102014-07-31 12:44:061931 extensions::NOTIFICATION_EXTENSION_REMOVED,
[email protected]fb789532013-08-27 02:40:211932 content::Source<Profile>(profile_),
1933 content::Details<const Extension>(extension));
1934 }
[email protected]bb7f40952011-01-13 00:21:201935}
1936
[email protected]8001df22011-04-28 19:59:471937const Extension* ExtensionService::GetInstalledExtension(
1938 const std::string& id) const {
[email protected]599539802014-01-07 23:06:001939 return registry_->GetExtensionById(id, ExtensionRegistry::EVERYTHING);
[email protected]0dfe05c2011-02-23 23:03:361940}
1941
[email protected]9060d8b02012-01-13 02:14:301942bool ExtensionService::OnExternalExtensionFileFound(
[email protected]8ef78fd2010-08-19 17:14:321943 const std::string& id,
[email protected]c5e4a2222014-01-03 16:06:131944 const Version* version,
[email protected]650b2d52013-02-10 03:41:451945 const base::FilePath& path,
[email protected]1d5e58b2013-01-31 08:41:401946 Manifest::Location location,
[email protected]47fc70c2011-12-06 07:29:511947 int creation_flags,
1948 bool mark_acknowledged) {
[email protected]ab22ba42011-01-14 16:36:381949 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]fdd28372014-08-21 02:27:261950 CHECK(crx_file::id_util::IdIsValid(id));
[email protected]79c833b52011-04-05 18:31:011951 if (extension_prefs_->IsExternalExtensionUninstalled(id))
[email protected]9060d8b02012-01-13 02:14:301952 return false;
[email protected]a8af9fdb2010-10-28 21:52:201953
[email protected]7577a5c52009-07-30 06:21:581954 // Before even bothering to unpack, check and see if we already have this
[email protected]4c967932009-07-31 01:15:491955 // version. This is important because these extensions are going to get
[email protected]7577a5c52009-07-30 06:21:581956 // installed on every startup.
[email protected]9adb9692010-10-29 23:14:021957 const Extension* existing = GetExtensionById(id, true);
[email protected]910f72ce2012-08-24 01:38:351958
[email protected]7577a5c52009-07-30 06:21:581959 if (existing) {
[email protected]910f72ce2012-08-24 01:38:351960 // The default apps will have the location set as INTERNAL. Since older
1961 // default apps are installed as EXTERNAL, we override them. However, if the
1962 // app is already installed as internal, then do the version check.
[email protected]31bb5ee62012-09-12 22:58:401963 // TODO(grv) : Remove after Q1-2013.
[email protected]910f72ce2012-08-24 01:38:351964 bool is_default_apps_migration =
[email protected]1d5e58b2013-01-31 08:41:401965 (location == Manifest::INTERNAL &&
1966 Manifest::IsExternalLocation(existing->location()));
[email protected]910f72ce2012-08-24 01:38:351967
1968 if (!is_default_apps_migration) {
1969 DCHECK(version);
1970
1971 switch (existing->version()->CompareTo(*version)) {
1972 case -1: // existing version is older, we should upgrade
1973 break;
1974 case 0: // existing version is same, do nothing
1975 return false;
1976 case 1: // existing version is newer, uh-oh
1977 LOG(WARNING) << "Found external version of extension " << id
1978 << "that is older than current version. Current version "
1979 << "is: " << existing->VersionString() << ". New "
1980 << "version is: " << version->GetString()
1981 << ". Keeping current version.";
1982 return false;
1983 }
[email protected]7577a5c52009-07-30 06:21:581984 }
1985 }
1986
[email protected]9060d8b02012-01-13 02:14:301987 // If the extension is already pending, don't start an install.
[email protected]e3987852012-05-04 10:06:301988 if (!pending_extension_manager()->AddFromExternalFile(
[email protected]464213a2013-10-15 01:06:481989 id, location, *version, creation_flags, mark_acknowledged)) {
[email protected]9060d8b02012-01-13 02:14:301990 return false;
[email protected]e3987852012-05-04 10:06:301991 }
[email protected]9c635f22010-12-02 09:36:361992
[email protected]14908b72011-04-20 06:54:361993 // no client (silent install)
[email protected]f8636f92013-08-09 21:02:371994 scoped_refptr<CrxInstaller> installer(CrxInstaller::CreateSilent(this));
[email protected]6dfbbf82010-03-12 23:09:161995 installer->set_install_source(location);
1996 installer->set_expected_id(id);
[email protected]cb0e50312011-05-09 15:03:071997 installer->set_expected_version(*version);
1998 installer->set_install_cause(extension_misc::INSTALL_CAUSE_EXTERNAL_FILE);
[email protected]1bf73cc32011-10-26 22:38:311999 installer->set_creation_flags(creation_flags);
[email protected]88e8ec9152013-01-17 04:05:182000#if defined(OS_CHROMEOS)
2001 extensions::InstallLimiter::Get(profile_)->Add(installer, path);
2002#else
[email protected]6dfbbf82010-03-12 23:09:162003 installer->InstallCrx(path);
[email protected]88e8ec9152013-01-17 04:05:182004#endif
[email protected]47fc70c2011-12-06 07:29:512005
2006 // Depending on the source, a new external extension might not need a user
2007 // notification on installation. For such extensions, mark them acknowledged
2008 // now to suppress the notification.
2009 if (mark_acknowledged)
[email protected]374ceb6f2014-07-02 19:25:342010 external_install_manager_->AcknowledgeExternalExtension(id);
[email protected]9060d8b02012-01-13 02:14:302011
2012 return true;
[email protected]7577a5c52009-07-30 06:21:582013}
2014
[email protected]eaa7dd182010-12-14 11:09:002015void ExtensionService::DidCreateRenderViewForBackgroundPage(
[email protected]3a1dc572012-07-31 22:25:132016 extensions::ExtensionHost* host) {
[email protected]406027c02010-09-27 08:03:182017 OrphanedDevTools::iterator iter =
[email protected]2d2f6cfc2011-05-06 21:09:332018 orphaned_dev_tools_.find(host->extension_id());
[email protected]406027c02010-09-27 08:03:182019 if (iter == orphaned_dev_tools_.end())
2020 return;
2021
[email protected]b3f957e62014-08-08 10:09:022022 iter->second->ConnectWebContents(host->host_contents());
[email protected]406027c02010-09-27 08:03:182023 orphaned_dev_tools_.erase(iter);
2024}
2025
[email protected]432115822011-07-10 15:52:272026void ExtensionService::Observe(int type,
[email protected]6c2381d2011-10-19 02:52:532027 const content::NotificationSource& source,
2028 const content::NotificationDetails& details) {
[email protected]432115822011-07-10 15:52:272029 switch (type) {
[email protected]3c4abc82012-10-22 22:25:542030 case chrome::NOTIFICATION_APP_TERMINATING:
2031 // Shutdown has started. Don't start any more extension installs.
2032 // (We cannot use ExtensionService::Shutdown() for this because it
2033 // happens too late in browser teardown.)
2034 browser_terminating_ = true;
2035 break;
[email protected]adf5a102014-07-31 12:44:062036 case extensions::NOTIFICATION_EXTENSION_PROCESS_TERMINATED: {
[email protected]6c2381d2011-10-19 02:52:532037 if (profile_ !=
2038 content::Source<Profile>(source).ptr()->GetOriginalProfile()) {
[email protected]bc535ee52010-08-31 18:40:322039 break;
[email protected]6c2381d2011-10-19 02:52:532040 }
[email protected]a4ed6282009-12-14 20:51:162041
[email protected]3a1dc572012-07-31 22:25:132042 extensions::ExtensionHost* host =
2043 content::Details<extensions::ExtensionHost>(details).ptr();
[email protected]f128af42010-08-05 18:05:262044
[email protected]3964e572014-02-13 21:57:412045 // If the extension is already being terminated, there is nothing left to
2046 // do.
2047 if (!extensions_being_terminated_.insert(host->extension_id()).second)
2048 break;
2049
[email protected]fa2416f2011-05-03 08:41:202050 // Mark the extension as terminated and Unload it. We want it to
2051 // be in a consistent state: either fully working or not loaded
2052 // at all, but never half-crashed. We do it in a PostTask so
2053 // that other handlers of this notification will still have
2054 // access to the Extension and ExtensionHost.
[email protected]b3a25092013-05-28 22:08:162055 base::MessageLoop::current()->PostTask(
[email protected]14908b72011-04-20 06:54:362056 FROM_HERE,
[email protected]53612e82011-10-18 18:00:362057 base::Bind(
[email protected]fa2416f2011-05-03 08:41:202058 &ExtensionService::TrackTerminatedExtension,
[email protected]d8c8f25f2011-11-02 18:18:012059 AsWeakPtr(),
[email protected]fa2416f2011-05-03 08:41:202060 host->extension()));
[email protected]31f77262009-12-02 20:48:532061 break;
2062 }
[email protected]432115822011-07-10 15:52:272063 case content::NOTIFICATION_RENDERER_PROCESS_TERMINATED: {
[email protected]f3b1a082011-11-18 00:34:302064 content::RenderProcessHost* process =
2065 content::Source<content::RenderProcessHost>(source).ptr();
[email protected]fc30ef082011-08-18 04:07:192066 Profile* host_profile =
[email protected]f3b1a082011-11-18 00:34:302067 Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]fc30ef082011-08-18 04:07:192068 if (!profile_->IsSameProfile(host_profile->GetOriginalProfile()))
2069 break;
2070
[email protected]fafdc842014-01-17 18:09:082071 extensions::ProcessMap* process_map =
2072 extensions::ProcessMap::Get(profile_);
2073 if (process_map->Contains(process->GetID())) {
[email protected]52b76592013-11-02 17:59:032074 // An extension process was terminated, this might have resulted in an
2075 // app or extension becoming idle.
2076 std::set<std::string> extension_ids =
[email protected]fafdc842014-01-17 18:09:082077 process_map->GetExtensionsInProcess(process->GetID());
elijahtaylor0def4432014-10-06 18:15:112078 // In addition to the extensions listed in the process map, one of those
2079 // extensions could be referencing a shared module which is waiting for
2080 // idle to update. Check all imports of these extensions, too.
2081 std::set<std::string> import_ids;
2082 for (std::set<std::string>::const_iterator it = extension_ids.begin();
2083 it != extension_ids.end();
2084 ++it) {
2085 const Extension* extension = GetExtensionById(*it, true);
2086 if (!extension)
2087 continue;
2088 const std::vector<SharedModuleInfo::ImportInfo>& imports =
2089 SharedModuleInfo::GetImports(extension);
2090 std::vector<SharedModuleInfo::ImportInfo>::const_iterator import_it;
2091 for (import_it = imports.begin(); import_it != imports.end();
2092 import_it++) {
2093 import_ids.insert((*import_it).extension_id);
2094 }
2095 }
2096 extension_ids.insert(import_ids.begin(), import_ids.end());
2097
[email protected]52b76592013-11-02 17:59:032098 for (std::set<std::string>::const_iterator it = extension_ids.begin();
2099 it != extension_ids.end(); ++it) {
2100 if (delayed_installs_.Contains(*it)) {
2101 base::MessageLoop::current()->PostDelayedTask(
2102 FROM_HERE,
2103 base::Bind(&ExtensionService::MaybeFinishDelayedInstallation,
2104 AsWeakPtr(), *it),
2105 base::TimeDelta::FromSeconds(kUpdateIdleDelay));
2106 }
2107 }
2108 }
2109
[email protected]fafdc842014-01-17 18:09:082110 process_map->RemoveAllFromProcess(process->GetID());
[email protected]6f371442011-11-09 06:45:462111 BrowserThread::PostTask(
[email protected]38427a12013-11-09 17:34:202112 BrowserThread::IO,
2113 FROM_HERE,
2114 base::Bind(&extensions::InfoMap::UnregisterAllExtensionsInProcess,
[email protected]31d8f5f22012-04-02 15:22:082115 system_->info_map(),
[email protected]f3b1a082011-11-18 00:34:302116 process->GetID()));
[email protected]da5683db2011-04-23 17:12:212117 break;
2118 }
[email protected]92dd8d92013-02-26 00:41:082119 case chrome::NOTIFICATION_UPGRADE_RECOMMENDED: {
[email protected]75bdcb872013-03-13 00:41:452120 // Notify observers that chrome update is available.
2121 FOR_EACH_OBSERVER(extensions::UpdateObserver, update_observers_,
2122 OnChromeUpdateAvailable());
[email protected]92dd8d92013-02-26 00:41:082123 break;
2124 }
[email protected]ebe07772014-05-22 04:16:062125 case chrome::NOTIFICATION_PROFILE_DESTRUCTION_STARTED: {
2126 OnProfileDestructionStarted();
2127 break;
2128 }
[email protected]aa96d3a2010-08-21 08:45:252129
[email protected]4814b512009-11-07 00:12:292130 default:
2131 NOTREACHED() << "Unexpected notification type.";
2132 }
2133}
2134
[email protected]612a1cb12012-10-17 13:18:032135bool ExtensionService::ShouldEnableOnInstall(const Extension* extension) {
2136 // Extensions installed by policy can't be disabled. So even if a previous
2137 // installation disabled the extension, make sure it is now enabled.
[email protected]ab894542014-07-03 12:35:392138 if (system_->management_policy()->MustRemainEnabled(extension, NULL))
[email protected]612a1cb12012-10-17 13:18:032139 return true;
2140
2141 if (extension_prefs_->IsExtensionDisabled(extension->id()))
2142 return false;
2143
[email protected]41070e8d2012-10-24 01:34:362144 if (FeatureSwitch::prompt_for_external_extensions()->IsEnabled()) {
[email protected]612a1cb12012-10-17 13:18:032145 // External extensions are initially disabled. We prompt the user before
[email protected]2c495c42013-01-04 21:49:542146 // enabling them. Hosted apps are excepted because they are not dangerous
2147 // (they need to be launched by the user anyway).
[email protected]1d5e58b2013-01-31 08:41:402148 if (extension->GetType() != Manifest::TYPE_HOSTED_APP &&
2149 Manifest::IsExternalLocation(extension->location()) &&
[email protected]612a1cb12012-10-17 13:18:032150 !extension_prefs_->IsExternalExtensionAcknowledged(extension->id())) {
2151 return false;
2152 }
2153 }
[email protected]612a1cb12012-10-17 13:18:032154
2155 return true;
2156}
[email protected]0db124b02012-11-07 04:55:052157
[email protected]e7aa7b7e2012-11-27 04:51:222158bool ExtensionService::ShouldDelayExtensionUpdate(
2159 const std::string& extension_id,
[email protected]4a1d9c0d2014-06-13 12:50:112160 bool install_immediately) const {
[email protected]e7aa7b7e2012-11-27 04:51:222161 const char kOnUpdateAvailableEvent[] = "runtime.onUpdateAvailable";
2162
2163 // If delayed updates are globally disabled, or just for this extension,
2164 // don't delay.
[email protected]4a1d9c0d2014-06-13 12:50:112165 if (!install_updates_when_idle_ || install_immediately)
[email protected]e7aa7b7e2012-11-27 04:51:222166 return false;
2167
[email protected]695b5712012-12-06 23:55:282168 const Extension* old = GetInstalledExtension(extension_id);
[email protected]e7aa7b7e2012-11-27 04:51:222169 // If there is no old extension, this is not an update, so don't delay.
2170 if (!old)
2171 return false;
2172
[email protected]9367eabc2013-03-01 01:29:292173 if (extensions::BackgroundInfo::HasPersistentBackgroundPage(old)) {
[email protected]e7aa7b7e2012-11-27 04:51:222174 // Delay installation if the extension listens for the onUpdateAvailable
2175 // event.
2176 return system_->event_router()->ExtensionHasEventListener(
2177 extension_id, kOnUpdateAvailableEvent);
2178 } else {
2179 // Delay installation if the extension is not idle.
[email protected]1d5cf4142014-01-24 18:25:222180 return !extensions::util::IsExtensionIdle(extension_id, profile_);
[email protected]e7aa7b7e2012-11-27 04:51:222181 }
[email protected]0db124b02012-11-07 04:55:052182}
[email protected]fdd679b2012-11-15 20:49:392183
[email protected]e5f8fffe2014-04-02 00:30:442184void ExtensionService::OnGarbageCollectIsolatedStorageStart() {
2185 DCHECK(!installs_delayed_for_gc_);
2186 installs_delayed_for_gc_ = true;
[email protected]399583b2012-12-11 09:33:422187}
2188
2189void ExtensionService::OnGarbageCollectIsolatedStorageFinished() {
[email protected]e5f8fffe2014-04-02 00:30:442190 DCHECK(installs_delayed_for_gc_);
2191 installs_delayed_for_gc_ = false;
[email protected]9f4e4f082013-06-21 07:11:192192 MaybeFinishDelayedInstallations();
2193}
2194
2195void ExtensionService::MaybeFinishDelayedInstallations() {
2196 std::vector<std::string> to_be_installed;
[email protected]399583b2012-12-11 09:33:422197 for (ExtensionSet::const_iterator it = delayed_installs_.begin();
2198 it != delayed_installs_.end();
2199 ++it) {
[email protected]9f4e4f082013-06-21 07:11:192200 to_be_installed.push_back((*it)->id());
[email protected]399583b2012-12-11 09:33:422201 }
[email protected]9f4e4f082013-06-21 07:11:192202 for (std::vector<std::string>::const_iterator it = to_be_installed.begin();
2203 it != to_be_installed.end();
[email protected]399583b2012-12-11 09:33:422204 ++it) {
[email protected]9f4e4f082013-06-21 07:11:192205 MaybeFinishDelayedInstallation(*it);
[email protected]399583b2012-12-11 09:33:422206 }
[email protected]399583b2012-12-11 09:33:422207}
2208
[email protected]fdd679b2012-11-15 20:49:392209void ExtensionService::OnBlacklistUpdated() {
[email protected]2d19eb6e2014-01-27 17:30:002210 blacklist_->GetBlacklistedIDs(
[email protected]f47f7172014-03-19 19:27:102211 registry_->GenerateInstalledExtensionsSet()->GetIDs(),
[email protected]3f2a2fa2013-09-24 02:55:252212 base::Bind(&ExtensionService::ManageBlacklist, AsWeakPtr()));
[email protected]695b5712012-12-06 23:55:282213}
2214
[email protected]2d19eb6e2014-01-27 17:30:002215void ExtensionService::ManageBlacklist(
2216 const extensions::Blacklist::BlacklistStateMap& state_map) {
[email protected]54ee8192014-03-29 17:37:242217 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]695b5712012-12-06 23:55:282218
[email protected]2d19eb6e2014-01-27 17:30:002219 std::set<std::string> blocked;
2220 ExtensionIdSet greylist;
2221 ExtensionIdSet unchanged;
2222 for (extensions::Blacklist::BlacklistStateMap::const_iterator it =
2223 state_map.begin();
2224 it != state_map.end();
2225 ++it) {
2226 switch (it->second) {
2227 case extensions::NOT_BLACKLISTED:
2228 break;
[email protected]695b5712012-12-06 23:55:282229
[email protected]2d19eb6e2014-01-27 17:30:002230 case extensions::BLACKLISTED_MALWARE:
2231 blocked.insert(it->first);
2232 break;
2233
2234 case extensions::BLACKLISTED_SECURITY_VULNERABILITY:
2235 case extensions::BLACKLISTED_CWS_POLICY_VIOLATION:
2236 case extensions::BLACKLISTED_POTENTIALLY_UNWANTED:
2237 greylist.insert(it->first);
2238 break;
2239
2240 case extensions::BLACKLISTED_UNKNOWN:
2241 unchanged.insert(it->first);
2242 break;
2243 }
2244 }
2245
2246 UpdateBlockedExtensions(blocked, unchanged);
2247 UpdateGreylistedExtensions(greylist, unchanged, state_map);
2248
[email protected]373daf972014-04-10 01:50:442249 error_controller_->ShowErrorIfNeeded();
[email protected]2d19eb6e2014-01-27 17:30:002250}
2251
2252namespace {
2253void Partition(const ExtensionIdSet& before,
2254 const ExtensionIdSet& after,
2255 const ExtensionIdSet& unchanged,
2256 ExtensionIdSet* no_longer,
2257 ExtensionIdSet* not_yet) {
2258 *not_yet = base::STLSetDifference<ExtensionIdSet>(after, before);
2259 *no_longer = base::STLSetDifference<ExtensionIdSet>(before, after);
2260 *no_longer = base::STLSetDifference<ExtensionIdSet>(*no_longer, unchanged);
2261}
2262} // namespace
2263
2264void ExtensionService::UpdateBlockedExtensions(
2265 const ExtensionIdSet& blocked,
2266 const ExtensionIdSet& unchanged) {
2267 ExtensionIdSet not_yet_blocked, no_longer_blocked;
2268 Partition(registry_->blacklisted_extensions().GetIDs(),
2269 blocked, unchanged,
2270 &no_longer_blocked, &not_yet_blocked);
2271
2272 for (ExtensionIdSet::iterator it = no_longer_blocked.begin();
2273 it != no_longer_blocked.end(); ++it) {
[email protected]695b5712012-12-06 23:55:282274 scoped_refptr<const Extension> extension =
[email protected]bb1bc9b32013-12-21 03:09:142275 registry_->blacklisted_extensions().GetByID(*it);
[email protected]3f2a2fa2013-09-24 02:55:252276 if (!extension.get()) {
[email protected]2d19eb6e2014-01-27 17:30:002277 NOTREACHED() << "Extension " << *it << " no longer blocked, "
2278 << "but it was never blocked.";
[email protected]695b5712012-12-06 23:55:282279 continue;
[email protected]3f2a2fa2013-09-24 02:55:252280 }
[email protected]bb1bc9b32013-12-21 03:09:142281 registry_->RemoveBlacklisted(*it);
[email protected]3f2a2fa2013-09-24 02:55:252282 extension_prefs_->SetExtensionBlacklisted(extension->id(), false);
[email protected]dc24976f2013-06-02 21:15:092283 AddExtension(extension.get());
[email protected]ac875372013-02-28 04:36:092284 UMA_HISTOGRAM_ENUMERATION("ExtensionBlacklist.UnblacklistInstalled",
[email protected]dc24976f2013-06-02 21:15:092285 extension->location(),
2286 Manifest::NUM_LOCATIONS);
[email protected]695b5712012-12-06 23:55:282287 }
2288
[email protected]2d19eb6e2014-01-27 17:30:002289 for (ExtensionIdSet::iterator it = not_yet_blocked.begin();
2290 it != not_yet_blocked.end(); ++it) {
[email protected]695b5712012-12-06 23:55:282291 scoped_refptr<const Extension> extension = GetInstalledExtension(*it);
[email protected]3f2a2fa2013-09-24 02:55:252292 if (!extension.get()) {
2293 NOTREACHED() << "Extension " << *it << " needs to be "
2294 << "blacklisted, but it's not installed.";
[email protected]695b5712012-12-06 23:55:282295 continue;
[email protected]3f2a2fa2013-09-24 02:55:252296 }
[email protected]bb1bc9b32013-12-21 03:09:142297 registry_->AddBlacklisted(extension);
[email protected]2d19eb6e2014-01-27 17:30:002298 extension_prefs_->SetExtensionBlacklistState(
2299 extension->id(), extensions::BLACKLISTED_MALWARE);
[email protected]b0af4792013-10-23 09:12:132300 UnloadExtension(*it, UnloadedExtensionInfo::REASON_BLACKLIST);
[email protected]ac875372013-02-28 04:36:092301 UMA_HISTOGRAM_ENUMERATION("ExtensionBlacklist.BlacklistInstalled",
2302 extension->location(), Manifest::NUM_LOCATIONS);
[email protected]695b5712012-12-06 23:55:282303 }
[email protected]2d19eb6e2014-01-27 17:30:002304}
[email protected]695b5712012-12-06 23:55:282305
[email protected]2d19eb6e2014-01-27 17:30:002306// TODO(oleg): UMA logging
2307void ExtensionService::UpdateGreylistedExtensions(
2308 const ExtensionIdSet& greylist,
2309 const ExtensionIdSet& unchanged,
2310 const extensions::Blacklist::BlacklistStateMap& state_map) {
2311 ExtensionIdSet not_yet_greylisted, no_longer_greylisted;
2312 Partition(greylist_.GetIDs(),
2313 greylist, unchanged,
2314 &no_longer_greylisted, &not_yet_greylisted);
2315
2316 for (ExtensionIdSet::iterator it = no_longer_greylisted.begin();
2317 it != no_longer_greylisted.end(); ++it) {
2318 scoped_refptr<const Extension> extension = greylist_.GetByID(*it);
2319 if (!extension.get()) {
2320 NOTREACHED() << "Extension " << *it << " no longer greylisted, "
2321 << "but it was not marked as greylisted.";
2322 continue;
2323 }
2324
2325 greylist_.Remove(*it);
2326 extension_prefs_->SetExtensionBlacklistState(extension->id(),
2327 extensions::NOT_BLACKLISTED);
2328 if (extension_prefs_->GetDisableReasons(extension->id()) &
2329 extensions::Extension::DISABLE_GREYLIST)
2330 EnableExtension(*it);
2331 }
2332
2333 for (ExtensionIdSet::iterator it = not_yet_greylisted.begin();
2334 it != not_yet_greylisted.end(); ++it) {
2335 scoped_refptr<const Extension> extension = GetInstalledExtension(*it);
2336 if (!extension.get()) {
2337 NOTREACHED() << "Extension " << *it << " needs to be "
2338 << "disabled, but it's not installed.";
2339 continue;
2340 }
2341 greylist_.Insert(extension);
2342 extension_prefs_->SetExtensionBlacklistState(extension->id(),
2343 state_map.find(*it)->second);
2344 if (registry_->enabled_extensions().Contains(extension->id()))
2345 DisableExtension(*it, extensions::Extension::DISABLE_GREYLIST);
2346 }
[email protected]fdd679b2012-11-15 20:49:392347}
[email protected]75bdcb872013-03-13 00:41:452348
2349void ExtensionService::AddUpdateObserver(extensions::UpdateObserver* observer) {
2350 update_observers_.AddObserver(observer);
2351}
2352
2353void ExtensionService::RemoveUpdateObserver(
2354 extensions::UpdateObserver* observer) {
2355 update_observers_.RemoveObserver(observer);
2356}
[email protected]bb1bc9b32013-12-21 03:09:142357
2358// Used only by test code.
2359void ExtensionService::UnloadAllExtensionsInternal() {
2360 profile_->GetExtensionSpecialStoragePolicy()->RevokeRightsForAllExtensions();
2361
2362 registry_->ClearAll();
[email protected]45f5b7d2014-01-22 23:47:132363 system_->runtime_data()->ClearAll();
[email protected]bb1bc9b32013-12-21 03:09:142364
2365 // TODO(erikkay) should there be a notification for this? We can't use
2366 // EXTENSION_UNLOADED since that implies that the extension has been disabled
2367 // or uninstalled.
2368}
[email protected]ebe07772014-05-22 04:16:062369
2370void ExtensionService::OnProfileDestructionStarted() {
2371 ExtensionIdSet ids_to_unload = registry_->enabled_extensions().GetIDs();
2372 for (ExtensionIdSet::iterator it = ids_to_unload.begin();
2373 it != ids_to_unload.end();
2374 ++it) {
2375 UnloadExtension(*it, UnloadedExtensionInfo::REASON_PROFILE_SHUTDOWN);
2376 }
2377}