blob: 0fa7c9e76b1e729cedd759261c011eee8b57bd14 [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"
skyostilf221b7de2015-06-11 20:36:3212#include "base/location.h"
rkaplowfca0f4dc52015-03-14 21:40:5713#include "base/metrics/histogram_macros.h"
yiyaoliu252f915e2015-04-23 21:56:3614#include "base/profiler/scoped_profile.h"
skyostilf221b7de2015-06-11 20:36:3215#include "base/single_thread_task_runner.h"
[email protected]3ea1b182013-02-08 22:38:4116#include "base/strings/string_number_conversions.h"
[email protected]00e7bef2013-06-10 20:35:1717#include "base/strings/stringprintf.h"
[email protected]112158af2013-06-07 23:46:1818#include "base/strings/utf_string_conversions.h"
skyostilf221b7de2015-06-11 20:36:3219#include "base/thread_task_runner_handle.h"
[email protected]7f8f24f2012-11-15 19:40:1420#include "base/threading/sequenced_worker_pool.h"
[email protected]34b99632011-01-01 01:01:0621#include "base/threading/thread_restrictions.h"
[email protected]41a17c52013-06-28 00:27:5322#include "base/time/time.h"
rkaplowe65c2ff2015-02-14 16:29:5423#include "base/trace_event/trace_event.h"
[email protected]15730c42009-09-03 00:03:2024#include "chrome/browser/browser_process.h"
[email protected]9ea0cd32013-07-12 01:50:3625#include "chrome/browser/chrome_notification_types.h"
mukai87a8d402014-09-15 20:15:0926#include "chrome/browser/content_settings/content_settings_internal_extension_provider.h"
sunil.ratnu21b896c2014-11-24 10:09:2427#include "chrome/browser/extensions/api/content_settings/content_settings_custom_extension_provider.h"
mukai87a8d402014-09-15 20:15:0928#include "chrome/browser/extensions/api/content_settings/content_settings_service.h"
ryanackley48bedbd2015-01-27 23:12:1429#include "chrome/browser/extensions/app_data_migrator.h"
[email protected]d8c8f25f2011-11-02 18:18:0130#include "chrome/browser/extensions/component_loader.h"
[email protected]13e062e2014-08-09 10:21:5531#include "chrome/browser/extensions/crx_installer.h"
[email protected]d9ede582012-08-14 19:21:3832#include "chrome/browser/extensions/data_deleter.h"
rdevlin.cronin2813c1b2014-08-26 23:51:0833#include "chrome/browser/extensions/extension_action_storage_manager.h"
[email protected]5a145e82014-05-29 22:19:0734#include "chrome/browser/extensions/extension_assets_manager.h"
[email protected]62f051c2012-03-29 17:04:4435#include "chrome/browser/extensions/extension_disabled_ui.h"
[email protected]373daf972014-04-10 01:50:4436#include "chrome/browser/extensions/extension_error_controller.h"
[email protected]19eb80152011-02-26 00:28:4337#include "chrome/browser/extensions/extension_special_storage_policy.h"
[email protected]f8aefb132013-10-30 09:29:5238#include "chrome/browser/extensions/extension_sync_service.h"
[email protected]617342a42013-12-18 23:34:0339#include "chrome/browser/extensions/extension_util.h"
[email protected]2894a512014-06-26 19:03:5640#include "chrome/browser/extensions/external_install_manager.h"
[email protected]5df038b2012-07-16 19:03:2741#include "chrome/browser/extensions/external_provider_impl.h"
[email protected]ffd2f79e2013-11-14 00:11:4642#include "chrome/browser/extensions/install_verifier.h"
[email protected]d8c8f25f2011-11-02 18:18:0143#include "chrome/browser/extensions/installed_loader.h"
[email protected]f3d3b382014-03-14 21:19:2844#include "chrome/browser/extensions/pending_extension_manager.h"
[email protected]13e062e2014-08-09 10:21:5545#include "chrome/browser/extensions/permissions_updater.h"
[email protected]90878c52014-04-04 18:21:0246#include "chrome/browser/extensions/shared_module_service.h"
[email protected]13e062e2014-08-09 10:21:5547#include "chrome/browser/extensions/unpacked_installer.h"
rockotdb5192992014-09-16 21:27:0248#include "chrome/browser/extensions/updater/chrome_extension_downloader_factory.h"
[email protected]13e062e2014-08-09 10:21:5549#include "chrome/browser/extensions/updater/extension_updater.h"
rockotdb5192992014-09-16 21:27:0250#include "chrome/browser/google/google_brand.h"
[email protected]8ecad5e2010-12-02 21:18:3351#include "chrome/browser/profiles/profile.h"
dbeam8d57a012015-05-21 07:12:2052#include "chrome/browser/search/thumbnail_source.h"
[email protected]b5a507b22013-11-08 20:41:5753#include "chrome/browser/ui/webui/extensions/extension_icon_source.h"
[email protected]c8d407e2011-04-28 21:27:1754#include "chrome/browser/ui/webui/favicon_source.h"
[email protected]b07e606e2012-09-15 20:16:1555#include "chrome/browser/ui/webui/theme_source.h"
[email protected]e2eb43112009-05-29 21:19:5456#include "chrome/common/chrome_switches.h"
[email protected]f6431be82013-09-07 02:53:4557#include "chrome/common/crash_keys.h"
[email protected]9f4e4f082013-06-21 07:11:1958#include "chrome/common/extensions/extension_constants.h"
[email protected]15d4d2d2013-08-09 06:49:0359#include "chrome/common/extensions/features/feature_channel.h"
[email protected]a57209872009-05-04 22:53:1460#include "chrome/common/url_constants.h"
mukai8eaec822014-10-25 17:53:1661#include "components/content_settings/core/browser/host_content_settings_map.h"
[email protected]fdd28372014-08-21 02:27:2662#include "components/crx_file/id_util.h"
[email protected]7a83dd072013-09-03 12:09:1763#include "components/startup_metric_utils/startup_metric_utils.h"
[email protected]dccba4f82014-05-29 00:52:5664#include "content/public/browser/devtools_agent_host.h"
[email protected]05aad2da2011-10-28 10:12:3765#include "content/public/browser/notification_service.h"
[email protected]f3b1a082011-11-18 00:34:3066#include "content/public/browser/render_process_host.h"
[email protected]399583b2012-12-11 09:33:4267#include "content/public/browser/storage_partition.h"
treib926ee2d2015-08-06 10:55:4268#include "extensions/browser/app_sorting.h"
[email protected]34423532013-11-21 18:13:1069#include "extensions/browser/event_router.h"
[email protected]22401dc2014-03-21 01:38:5770#include "extensions/browser/extension_host.h"
[email protected]dccba4f82014-05-29 00:52:5671#include "extensions/browser/extension_prefs.h"
[email protected]bb1bc9b32013-12-21 03:09:1472#include "extensions/browser/extension_registry.h"
[email protected]59b0e602014-01-30 00:41:2473#include "extensions/browser/extension_system.h"
rockotffa65b12014-10-14 17:19:0674#include "extensions/browser/extensions_browser_client.h"
[email protected]4a1d9c0d2014-06-13 12:50:1175#include "extensions/browser/install_flag.h"
[email protected]45f5b7d2014-01-22 23:47:1376#include "extensions/browser/runtime_data.h"
[email protected]e43c61f2014-07-20 21:46:3477#include "extensions/browser/uninstall_reason.h"
[email protected]a9aa62b312013-11-29 05:35:0678#include "extensions/browser/update_observer.h"
rockotffa65b12014-10-14 17:19:0679#include "extensions/browser/updater/extension_cache.h"
rockot05f40a922014-10-16 19:40:2580#include "extensions/browser/updater/extension_downloader.h"
[email protected]fb820c02014-03-13 15:07:0881#include "extensions/common/extension_messages.h"
rockot90659852014-09-18 19:31:5282#include "extensions/common/extension_urls.h"
[email protected]5ef835a2013-11-08 20:42:5783#include "extensions/common/feature_switch.h"
[email protected]85df9d12014-04-15 17:02:1484#include "extensions/common/file_util.h"
[email protected]0c3c9732013-09-16 08:53:4185#include "extensions/common/manifest_constants.h"
[email protected]558878cc82013-11-09 01:25:5186#include "extensions/common/manifest_handlers/background_info.h"
rockotd5546142014-10-15 00:29:0887#include "extensions/common/manifest_url_handlers.h"
[email protected]dccba4f82014-05-29 00:52:5688#include "extensions/common/one_shot_event.h"
treib2e0517f92015-05-07 23:15:3689#include "extensions/common/permissions/api_permission.h"
[email protected]c41003472013-10-19 15:37:2590#include "extensions/common/permissions/permission_message_provider.h"
[email protected]e4452d32013-11-15 23:07:4191#include "extensions/common/permissions/permissions_data.h"
[email protected]79a60642012-10-20 21:03:1892
treib8ecc1eb52015-03-04 18:29:0693#if defined(ENABLE_SUPERVISED_USERS)
94#include "chrome/browser/supervised_user/supervised_user_service.h"
95#include "chrome/browser/supervised_user/supervised_user_service_factory.h"
96#endif
97
[email protected]eed367e2011-04-12 03:43:3198#if defined(OS_CHROMEOS)
[email protected]88e8ec9152013-01-17 04:05:1899#include "chrome/browser/chromeos/extensions/install_limiter.h"
pilgrime92c5fcd2014-09-10 23:31:23100#include "storage/browser/fileapi/file_system_backend.h"
101#include "storage/browser/fileapi/file_system_context.h"
[email protected]eed367e2011-04-12 03:43:31102#endif
103
[email protected]55eb70e762012-02-20 17:38:39104using content::BrowserContext;
[email protected]631bb742011-11-02 11:29:39105using content::BrowserThread;
[email protected]98f66112012-12-25 12:59:36106using content::DevToolsAgentHost;
treib2e0517f92015-05-07 23:15:36107using extensions::APIPermission;
[email protected]bf3d9df2012-07-24 23:20:27108using extensions::CrxInstaller;
[email protected]1c321ee52012-05-21 03:02:34109using extensions::Extension;
110using extensions::ExtensionIdSet;
111using extensions::ExtensionInfo;
[email protected]599539802014-01-07 23:06:00112using extensions::ExtensionRegistry;
[email protected]289c44b2013-12-17 03:26:57113using extensions::ExtensionSet;
[email protected]215a7be2012-10-22 19:53:42114using extensions::FeatureSwitch;
[email protected]ffd2f79e2013-11-14 00:11:46115using extensions::InstallVerifier;
[email protected]0d54b682013-11-05 14:15:36116using extensions::ManagementPolicy;
[email protected]1d5e58b2013-01-31 08:41:40117using extensions::Manifest;
treib2e0517f92015-05-07 23:15:36118using extensions::PermissionID;
119using extensions::PermissionIDSet;
[email protected]c2e66e12012-06-27 06:27:06120using extensions::PermissionSet;
[email protected]9f4e4f082013-06-21 07:11:19121using extensions::SharedModuleInfo;
[email protected]90878c52014-04-04 18:21:02122using extensions::SharedModuleService;
[email protected]e410b5f2012-12-14 14:02:24123using extensions::UnloadedExtensionInfo;
[email protected]5ef47ec2010-01-28 05:58:05124
[email protected]b6ab96d2009-08-20 18:58:19125namespace {
126
[email protected]0db124b02012-11-07 04:55:05127// Wait this many seconds after an extensions becomes idle before updating it.
[email protected]ddc6a122014-06-27 04:52:32128const int kUpdateIdleDelay = 5;
[email protected]0db124b02012-11-07 04:55:05129
[email protected]c6d474f82009-12-16 21:11:06130} // namespace
[email protected]b6ab96d2009-08-20 18:58:19131
[email protected]eaa7dd182010-12-14 11:09:00132// ExtensionService.
[email protected]6014d672008-12-05 00:38:25133
[email protected]8e4560b62011-01-14 10:09:14134void ExtensionService::CheckExternalUninstall(const std::string& id) {
[email protected]a29a517a2011-01-21 21:11:12135 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]a8af9fdb2010-10-28 21:52:20136
[email protected]7a4c6852010-09-16 03:44:22137 // Check if the providers know about this extension.
[email protected]5df038b2012-07-16 19:03:27138 extensions::ProviderCollection::const_iterator i;
[email protected]0a60a2e2010-10-25 16:15:21139 for (i = external_extension_providers_.begin();
140 i != external_extension_providers_.end(); ++i) {
[email protected]8e4560b62011-01-14 10:09:14141 DCHECK(i->get()->IsReady());
[email protected]0a60a2e2010-10-25 16:15:21142 if (i->get()->HasExtension(id))
143 return; // Yup, known extension, don't uninstall.
[email protected]7a4c6852010-09-16 03:44:22144 }
145
[email protected]0f48fca2011-05-19 18:46:35146 // We get the list of external extensions to check from preferences.
147 // It is possible that an extension has preferences but is not loaded.
148 // For example, an extension that requires experimental permissions
149 // will not be loaded if the experimental command line flag is not used.
150 // In this case, do not uninstall.
[email protected]31bb5ee62012-09-12 22:58:40151 if (!GetInstalledExtension(id)) {
[email protected]0f48fca2011-05-19 18:46:35152 // We can't call UninstallExtension with an unloaded/invalid
153 // extension ID.
154 LOG(WARNING) << "Attempted uninstallation of unloaded/invalid extension "
155 << "with id: " << id;
156 return;
157 }
[email protected]42d58f62014-07-31 01:32:45158 UninstallExtension(id,
159 extensions::UNINSTALL_REASON_ORPHANED_EXTERNAL_EXTENSION,
160 base::Bind(&base::DoNothing),
161 NULL);
[email protected]7a4c6852010-09-16 03:44:22162}
163
[email protected]7f8f24f2012-11-15 19:40:14164void ExtensionService::SetFileTaskRunnerForTesting(
dcheng605ef8d2014-08-28 18:29:44165 const scoped_refptr<base::SequencedTaskRunner>& task_runner) {
[email protected]7f8f24f2012-11-15 19:40:14166 file_task_runner_ = task_runner;
167}
168
[email protected]8e4560b62011-01-14 10:09:14169void ExtensionService::ClearProvidersForTesting() {
[email protected]7a4c6852010-09-16 03:44:22170 external_extension_providers_.clear();
171}
172
[email protected]8e4560b62011-01-14 10:09:14173void ExtensionService::AddProviderForTesting(
[email protected]5df038b2012-07-16 19:03:27174 extensions::ExternalProviderInterface* test_provider) {
[email protected]a29a517a2011-01-21 21:11:12175 CHECK(test_provider);
[email protected]0a60a2e2010-10-25 16:15:21176 external_extension_providers_.push_back(
[email protected]5df038b2012-07-16 19:03:27177 linked_ptr<extensions::ExternalProviderInterface>(test_provider));
[email protected]7a4c6852010-09-16 03:44:22178}
179
[email protected]8f959f522014-08-06 06:26:28180void ExtensionService::BlacklistExtensionForTest(
181 const std::string& extension_id) {
mlerman6a37b6a42014-11-26 22:10:53182 ExtensionIdSet blacklisted;
[email protected]8f959f522014-08-06 06:26:28183 ExtensionIdSet unchanged;
mlerman6a37b6a42014-11-26 22:10:53184 blacklisted.insert(extension_id);
185 UpdateBlacklistedExtensions(blacklisted, unchanged);
[email protected]8f959f522014-08-06 06:26:28186}
187
[email protected]9060d8b02012-01-13 02:14:30188bool ExtensionService::OnExternalExtensionUpdateUrlFound(
[email protected]7a4c6852010-09-16 03:44:22189 const std::string& id,
[email protected]d8fd0fd2014-03-24 13:16:06190 const std::string& install_parameter,
[email protected]21a5a672010-11-04 10:47:42191 const GURL& update_url,
[email protected]464213a2013-10-15 01:06:48192 Manifest::Location location,
193 int creation_flags,
194 bool mark_acknowledged) {
[email protected]ab22ba42011-01-14 16:36:38195 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]fdd28372014-08-21 02:27:26196 CHECK(crx_file::id_util::IdIsValid(id));
[email protected]a8af9fdb2010-10-28 21:52:20197
[email protected]044e86992014-01-24 22:59:11198 if (Manifest::IsExternalLocation(location)) {
199 // All extensions that are not user specific can be cached.
rockotffa65b12014-10-14 17:19:06200 extensions::ExtensionsBrowserClient::Get()->GetExtensionCache()
201 ->AllowCaching(id);
[email protected]044e86992014-01-24 22:59:11202 }
203
[email protected]8a87a5332011-08-11 17:54:59204 const Extension* extension = GetExtensionById(id, true);
205 if (extension) {
206 // Already installed. Skip this install if the current location has
207 // higher priority than |location|.
[email protected]1d5e58b2013-01-31 08:41:40208 Manifest::Location current = extension->location();
209 if (current == Manifest::GetHigherPriorityLocation(current, location))
[email protected]9060d8b02012-01-13 02:14:30210 return false;
[email protected]8a87a5332011-08-11 17:54:59211 // Otherwise, overwrite the current installation.
[email protected]7a4c6852010-09-16 03:44:22212 }
[email protected]9060d8b02012-01-13 02:14:30213
214 // Add |id| to the set of pending extensions. If it can not be added,
215 // then there is already a pending record from a higher-priority install
216 // source. In this case, signal that this extension will not be
217 // installed by returning false.
218 if (!pending_extension_manager()->AddFromExternalUpdateUrl(
[email protected]d8fd0fd2014-03-24 13:16:06219 id,
220 install_parameter,
221 update_url,
222 location,
223 creation_flags,
224 mark_acknowledged)) {
[email protected]9060d8b02012-01-13 02:14:30225 return false;
[email protected]31bb5ee62012-09-12 22:58:40226 }
[email protected]9060d8b02012-01-13 02:14:30227
[email protected]94fde232012-04-27 10:22:30228 update_once_all_providers_are_ready_ = true;
[email protected]9060d8b02012-01-13 02:14:30229 return true;
[email protected]7a4c6852010-09-16 03:44:22230}
231
[email protected]6aeac8342010-10-01 20:21:18232// static
[email protected]cc2f55c2014-07-08 02:19:04233// This function is used to uninstall an extension via sync. The LOG statements
234// within this function are used to inform the user if the uninstall cannot be
235// done.
[email protected]eaa7dd182010-12-14 11:09:00236bool ExtensionService::UninstallExtensionHelper(
237 ExtensionService* extensions_service,
[email protected]cc2f55c2014-07-08 02:19:04238 const std::string& extension_id,
[email protected]e43c61f2014-07-20 21:46:34239 extensions::UninstallReason reason) {
[email protected]d6ebc9792011-04-07 18:18:33240 // We can't call UninstallExtension with an invalid extension ID.
[email protected]31bb5ee62012-09-12 22:58:40241 if (!extensions_service->GetInstalledExtension(extension_id)) {
[email protected]6aeac8342010-10-01 20:21:18242 LOG(WARNING) << "Attempted uninstallation of non-existent extension with "
[email protected]95da88c42011-03-31 10:07:33243 << "id: " << extension_id;
244 return false;
[email protected]6aeac8342010-10-01 20:21:18245 }
246
[email protected]d6ebc9792011-04-07 18:18:33247 // The following call to UninstallExtension will not allow an uninstall of a
248 // policy-controlled extension.
[email protected]439f1e32013-12-09 20:09:09249 base::string16 error;
[email protected]42d58f62014-07-31 01:32:45250 if (!extensions_service->UninstallExtension(
251 extension_id, reason, base::Bind(&base::DoNothing), &error)) {
[email protected]d6ebc9792011-04-07 18:18:33252 LOG(WARNING) << "Cannot uninstall extension with id " << extension_id
253 << ": " << error;
254 return false;
255 }
[email protected]95da88c42011-03-31 10:07:33256
[email protected]6aeac8342010-10-01 20:21:18257 return true;
258}
259
[email protected]eaa7dd182010-12-14 11:09:00260ExtensionService::ExtensionService(Profile* profile,
avi3ef9ec9e2014-12-22 22:50:17261 const base::CommandLine* command_line,
[email protected]650b2d52013-02-10 03:41:45262 const base::FilePath& install_directory,
[email protected]45759612012-07-10 17:21:23263 extensions::ExtensionPrefs* extension_prefs,
[email protected]fdd679b2012-11-15 20:49:39264 extensions::Blacklist* blacklist,
[email protected]0436b102011-04-15 18:30:03265 bool autoupdate_enabled,
[email protected]4a10006a2013-05-17 23:18:35266 bool extensions_enabled,
267 extensions::OneShotEvent* ready)
[email protected]fdd679b2012-11-15 20:49:39268 : extensions::Blacklist::Observer(blacklist),
269 profile_(profile),
[email protected]bd306722012-07-11 20:43:59270 system_(extensions::ExtensionSystem::Get(profile)),
[email protected]73c47932010-12-06 18:13:43271 extension_prefs_(extension_prefs),
[email protected]695b5712012-12-06 23:55:28272 blacklist_(blacklist),
[email protected]5fdfa562013-12-27 17:43:59273 registry_(extensions::ExtensionRegistry::Get(profile)),
[email protected]6c9bedf2014-05-21 03:55:51274 pending_extension_manager_(profile),
[email protected]a9b00ac2009-06-25 21:03:23275 install_directory_(install_directory),
[email protected]0436b102011-04-15 18:30:03276 extensions_enabled_(extensions_enabled),
[email protected]e81dba32009-06-19 20:19:13277 show_extensions_prompts_(true),
[email protected]fc332ae2012-11-14 20:17:33278 install_updates_when_idle_(true),
[email protected]4a10006a2013-05-17 23:18:35279 ready_(ready),
[email protected]dff1e042012-04-27 10:59:18280 update_once_all_providers_are_ready_(false),
[email protected]3c4abc82012-10-22 22:25:54281 browser_terminating_(false),
[email protected]9f4e4f082013-06-21 07:11:19282 installs_delayed_for_gc_(false),
[email protected]e5f8fffe2014-04-02 00:30:44283 is_first_run_(false),
mlerman6a37b6a42014-11-26 22:10:53284 block_extensions_(false),
ryanackley48bedbd2015-01-27 23:12:14285 shared_module_service_(new extensions::SharedModuleService(profile_)),
286 app_data_migrator_(new extensions::AppDataMigrator(profile_, registry_)) {
[email protected]a29a517a2011-01-21 21:11:12287 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
rkaplowdd66a1342015-03-05 00:31:49288 TRACE_EVENT0("browser,startup", "ExtensionService::ExtensionService::ctor");
[email protected]a8af9fdb2010-10-28 21:52:20289
[email protected]36a784c2009-06-23 06:21:08290 // Figure out if extension installation should be enabled.
[email protected]367d9b172013-12-03 00:31:02291 if (extensions::ExtensionsBrowserClient::Get()->AreExtensionsDisabled(
292 *command_line, profile))
[email protected]6d60703b2009-08-29 01:29:23293 extensions_enabled_ = false;
[email protected]36a784c2009-06-23 06:21:08294
[email protected]3c4abc82012-10-22 22:25:54295 registrar_.Add(this, chrome::NOTIFICATION_APP_TERMINATING,
296 content::NotificationService::AllBrowserContextsAndSources());
[email protected]adf5a102014-07-31 12:44:06297 registrar_.Add(this,
298 extensions::NOTIFICATION_EXTENSION_PROCESS_TERMINATED,
[email protected]ad50def52011-10-19 23:17:07299 content::NotificationService::AllBrowserContextsAndSources());
[email protected]432115822011-07-10 15:52:27300 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_TERMINATED,
[email protected]ad50def52011-10-19 23:17:07301 content::NotificationService::AllBrowserContextsAndSources());
[email protected]92dd8d92013-02-26 00:41:08302 registrar_.Add(this, chrome::NOTIFICATION_UPGRADE_RECOMMENDED,
303 content::NotificationService::AllBrowserContextsAndSources());
[email protected]ebe07772014-05-22 04:16:06304 registrar_.Add(this,
305 chrome::NOTIFICATION_PROFILE_DESTRUCTION_STARTED,
306 content::Source<Profile>(profile_));
binjin1569c9b2014-09-05 13:33:18307
308 extensions::ExtensionManagementFactory::GetForBrowserContext(profile_)
309 ->AddObserver(this);
[email protected]4814b512009-11-07 00:12:29310
rkaplowdd66a1342015-03-05 00:31:49311 // Set up the ExtensionUpdater.
[email protected]93fd78f42009-07-10 16:43:17312 if (autoupdate_enabled) {
[email protected]501105b2013-09-26 05:42:02313 int update_frequency = extensions::kDefaultUpdateFrequencySeconds;
[email protected]93fd78f42009-07-10 16:43:17314 if (command_line->HasSwitch(switches::kExtensionsUpdateFrequency)) {
[email protected]e83326f2010-07-31 17:29:25315 base::StringToInt(command_line->GetSwitchValueASCII(
316 switches::kExtensionsUpdateFrequency),
317 &update_frequency);
[email protected]93fd78f42009-07-10 16:43:17318 }
[email protected]044e86992014-01-24 22:59:11319 updater_.reset(new extensions::ExtensionUpdater(
320 this,
321 extension_prefs,
322 profile->GetPrefs(),
323 profile,
324 update_frequency,
rockotffa65b12014-10-14 17:19:06325 extensions::ExtensionsBrowserClient::Get()->GetExtensionCache(),
rockotdb5192992014-09-16 21:27:02326 base::Bind(ChromeExtensionDownloaderFactory::CreateForProfile,
327 profile)));
[email protected]93fd78f42009-07-10 16:43:17328 }
329
[email protected]25ae0152011-11-18 14:40:02330 component_loader_.reset(
331 new extensions::ComponentLoader(this,
332 profile->GetPrefs(),
[email protected]55e16cd2013-12-18 04:36:08333 g_browser_process->local_state(),
334 profile));
[email protected]8e4560b62011-01-14 10:09:14335
[email protected]0436b102011-04-15 18:30:03336 if (extensions_enabled_) {
[email protected]ae4c37e2012-12-21 01:16:25337 extensions::ExternalProviderImpl::CreateExternalProviders(
338 this, profile_, &external_extension_providers_);
[email protected]873531342011-03-09 12:16:05339 }
[email protected]b671760b2010-07-15 21:13:47340
[email protected]74474042013-11-21 12:03:54341 // Set this as the ExtensionService for app sorting to ensure it causes syncs
342 // if required.
[email protected]b3aa7182013-04-25 04:45:23343 is_first_run_ = !extension_prefs_->SetAlertSystemFirstRun();
344
[email protected]373daf972014-04-10 01:50:44345 error_controller_.reset(
346 new extensions::ExtensionErrorController(profile_, is_first_run_));
[email protected]374ceb6f2014-07-02 19:25:34347 external_install_manager_.reset(
348 new extensions::ExternalInstallManager(profile_, is_first_run_));
[email protected]373daf972014-04-10 01:50:44349
[email protected]c77f2352012-08-08 22:07:58350 extension_action_storage_manager_.reset(
351 new extensions::ExtensionActionStorageManager(profile_));
352
[email protected]cb0e50312011-05-09 15:03:07353 // How long is the path to the Extensions directory?
354 UMA_HISTOGRAM_CUSTOM_COUNTS("Extensions.ExtensionRootPathLength",
355 install_directory_.value().length(), 0, 500, 100);
[email protected]6014d672008-12-05 00:38:25356}
357
[email protected]3f213ad2012-07-26 23:39:41358extensions::PendingExtensionManager*
359 ExtensionService::pending_extension_manager() {
[email protected]b2907fd2011-03-25 16:43:37360 return &pending_extension_manager_;
[email protected]ddb1e5a2010-12-13 20:10:45361}
362
[email protected]eaa7dd182010-12-14 11:09:00363ExtensionService::~ExtensionService() {
[email protected]c8d407e2011-04-28 21:27:17364 // No need to unload extensions here because they are profile-scoped, and the
365 // profile is in the process of being deleted.
[email protected]94b4ffc2011-02-04 05:55:17366
[email protected]5df038b2012-07-16 19:03:27367 extensions::ProviderCollection::const_iterator i;
[email protected]8e4560b62011-01-14 10:09:14368 for (i = external_extension_providers_.begin();
369 i != external_extension_providers_.end(); ++i) {
[email protected]5df038b2012-07-16 19:03:27370 extensions::ExternalProviderInterface* provider = i->get();
[email protected]8e4560b62011-01-14 10:09:14371 provider->ServiceShutdown();
372 }
[email protected]6014d672008-12-05 00:38:25373}
374
[email protected]037228a2012-10-05 01:36:16375void ExtensionService::Shutdown() {
binjin1569c9b2014-09-05 13:33:18376 extensions::ExtensionManagementFactory::GetInstance()
377 ->GetForBrowserContext(profile())
378 ->RemoveObserver(this);
[email protected]4c9201c42013-08-16 04:56:21379 system_->management_policy()->UnregisterProvider(
380 shared_module_policy_provider_.get());
[email protected]037228a2012-10-05 01:36:16381}
382
[email protected]b2907fd2011-03-25 16:43:37383const Extension* ExtensionService::GetExtensionById(
384 const std::string& id, bool include_disabled) const {
[email protected]599539802014-01-07 23:06:00385 int include_mask = ExtensionRegistry::ENABLED;
[email protected]695b5712012-12-06 23:55:28386 if (include_disabled) {
mlerman6a37b6a42014-11-26 22:10:53387 // Include blacklisted and blocked extensions here because there are
388 // hundreds of callers of this function, and many might assume that this
389 // includes those that have been disabled due to blacklisting or blocking.
[email protected]599539802014-01-07 23:06:00390 include_mask |= ExtensionRegistry::DISABLED |
mlerman6a37b6a42014-11-26 22:10:53391 ExtensionRegistry::BLACKLISTED | ExtensionRegistry::BLOCKED;
[email protected]695b5712012-12-06 23:55:28392 }
[email protected]599539802014-01-07 23:06:00393 return registry_->GetExtensionById(id, include_mask);
[email protected]695b5712012-12-06 23:55:28394}
395
[email protected]eaa7dd182010-12-14 11:09:00396void ExtensionService::Init() {
[email protected]a29a517a2011-01-21 21:11:12397 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
rkaplowe65c2ff2015-02-14 16:29:54398 TRACE_EVENT0("browser,startup", "ExtensionService::Init");
yiyaoliu252f915e2015-04-23 21:56:36399 TRACK_SCOPED_REGION("Startup", "ExtensionService::Init");
rkaplowa8fd8d32015-02-25 21:27:56400 SCOPED_UMA_HISTOGRAM_TIMER("Extensions.ExtensionServiceInitTime");
[email protected]3350d712013-11-18 09:32:24401
[email protected]4a10006a2013-05-17 23:18:35402 DCHECK(!is_ready()); // Can't redo init.
[email protected]bb1bc9b32013-12-21 03:09:14403 DCHECK_EQ(registry_->enabled_extensions().size(), 0u);
[email protected]9f1087e2009-06-15 17:29:32404
benwells22ab8ee2015-08-21 02:55:08405 // LoadAllExtensions() calls OnLoadedInstalledExtensions().
406 component_loader_->LoadAll();
407 extensions::InstalledLoader(this).LoadAllExtensions();
[email protected]9f4e4f082013-06-21 07:11:19408
benwells22ab8ee2015-08-21 02:55:08409 EnabledReloadableExtensions();
410 MaybeFinishShutdownDelayed();
411 SetReadyAndNotifyListeners();
[email protected]ae4c37e2012-12-21 01:16:25412
benwells22ab8ee2015-08-21 02:55:08413 // TODO(erikkay): this should probably be deferred to a future point
414 // rather than running immediately at startup.
415 CheckForExternalUpdates();
[email protected]894bb502009-05-21 22:39:57416
benwells22ab8ee2015-08-21 02:55:08417 LoadGreylistFromPrefs();
rkaplowa8fd8d32015-02-25 21:27:56418}
[email protected]3350d712013-11-18 09:32:24419
rkaplowa8fd8d32015-02-25 21:27:56420void ExtensionService::EnabledReloadableExtensions() {
421 TRACE_EVENT0("browser,startup",
422 "ExtensionService::EnabledReloadableExtensions");
423
424 std::vector<std::string> extensions_to_enable;
425 const ExtensionSet& disabled_extensions = registry_->disabled_extensions();
426 for (ExtensionSet::const_iterator iter = disabled_extensions.begin();
427 iter != disabled_extensions.end(); ++iter) {
428 const Extension* e = iter->get();
429 if (extension_prefs_->GetDisableReasons(e->id()) ==
430 Extension::DISABLE_RELOAD) {
431 extensions_to_enable.push_back(e->id());
432 }
433 }
434 for (const std::string& extension : extensions_to_enable) {
435 EnableExtension(extension);
436 }
437}
438
439void ExtensionService::MaybeFinishShutdownDelayed() {
440 TRACE_EVENT0("browser,startup",
441 "ExtensionService::MaybeFinishShutdownDelayed");
442
443 scoped_ptr<extensions::ExtensionPrefs::ExtensionsInfo> delayed_info(
444 extension_prefs_->GetAllDelayedInstallInfo());
445 for (size_t i = 0; i < delayed_info->size(); ++i) {
446 ExtensionInfo* info = delayed_info->at(i).get();
447 scoped_refptr<const Extension> extension(NULL);
448 if (info->extension_manifest) {
449 std::string error;
450 extension = Extension::Create(
451 info->extension_path, info->extension_location,
452 *info->extension_manifest,
453 extension_prefs_->GetDelayedInstallCreationFlags(info->extension_id),
454 info->extension_id, &error);
455 if (extension.get())
456 delayed_installs_.Insert(extension);
457 }
458 }
459 MaybeFinishDelayedInstallations();
460 scoped_ptr<extensions::ExtensionPrefs::ExtensionsInfo> delayed_info2(
461 extension_prefs_->GetAllDelayedInstallInfo());
462 UMA_HISTOGRAM_COUNTS_100("Extensions.UpdateOnLoad",
463 delayed_info2->size() - delayed_info->size());
[email protected]6014d672008-12-05 00:38:25464}
465
[email protected]2d19eb6e2014-01-27 17:30:00466void ExtensionService::LoadGreylistFromPrefs() {
rkaplowa8fd8d32015-02-25 21:27:56467 TRACE_EVENT0("browser,startup", "ExtensionService::LoadGreylistFromPrefs");
468
[email protected]f47f7172014-03-19 19:27:10469 scoped_ptr<ExtensionSet> all_extensions =
470 registry_->GenerateInstalledExtensionsSet();
[email protected]2d19eb6e2014-01-27 17:30:00471
472 for (ExtensionSet::const_iterator it = all_extensions->begin();
473 it != all_extensions->end(); ++it) {
474 extensions::BlacklistState state =
475 extension_prefs_->GetExtensionBlacklistState((*it)->id());
476 if (state == extensions::BLACKLISTED_SECURITY_VULNERABILITY ||
477 state == extensions::BLACKLISTED_POTENTIALLY_UNWANTED ||
478 state == extensions::BLACKLISTED_CWS_POLICY_VIOLATION)
479 greylist_.Insert(*it);
480 }
481}
482
ginkage553af3202015-02-04 12:39:09483bool ExtensionService::UpdateExtension(const extensions::CRXFileInfo& file,
[email protected]044e86992014-01-24 22:59:11484 bool file_ownership_passed,
[email protected]31bb5ee62012-09-12 22:58:40485 CrxInstaller** out_crx_installer) {
[email protected]a29a517a2011-01-21 21:11:12486 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]3c4abc82012-10-22 22:25:54487 if (browser_terminating_) {
488 LOG(WARNING) << "Skipping UpdateExtension due to browser shutdown";
489 // Leak the temp file at extension_path. We don't want to add to the disk
490 // I/O burden at shutdown, we can't rely on the I/O completing anyway, and
491 // the file is in the OS temp directory which should be cleaned up for us.
492 return false;
493 }
[email protected]a8af9fdb2010-10-28 21:52:20494
ginkage553af3202015-02-04 12:39:09495 const std::string& id = file.extension_id;
496
[email protected]3f213ad2012-07-26 23:39:41497 const extensions::PendingExtensionInfo* pending_extension_info =
[email protected]51a3bf8b2012-06-08 22:53:06498 pending_extension_manager()->GetById(id);
[email protected]8ef78fd2010-08-19 17:14:32499
[email protected]695b5712012-12-06 23:55:28500 const Extension* extension = GetInstalledExtension(id);
[email protected]51a3bf8b2012-06-08 22:53:06501 if (!pending_extension_info && !extension) {
[email protected]aa142702010-03-26 01:26:33502 LOG(WARNING) << "Will not update extension " << id
503 << " because it is not installed or pending";
504 // Delete extension_path since we're not creating a CrxInstaller
505 // that would do it for us.
[email protected]7f8f24f2012-11-15 19:40:14506 if (!GetFileTaskRunner()->PostTask(
507 FROM_HERE,
ginkage553af3202015-02-04 12:39:09508 base::Bind(&extensions::file_util::DeleteFile, file.path, false)))
[email protected]14908b72011-04-20 06:54:36509 NOTREACHED();
[email protected]420a0ec2011-06-01 01:07:03510
511 return false;
[email protected]e957fe52009-06-23 16:51:05512 }
513
treibe960e282015-09-11 10:38:08514 scoped_refptr<CrxInstaller> installer(CrxInstaller::CreateSilent(this));
[email protected]6dfbbf82010-03-12 23:09:16515 installer->set_expected_id(id);
ginkage47e603e2015-02-27 08:42:41516 installer->set_expected_hash(file.expected_hash);
[email protected]464213a2013-10-15 01:06:48517 int creation_flags = Extension::NO_FLAGS;
[email protected]51a3bf8b2012-06-08 22:53:06518 if (pending_extension_info) {
519 installer->set_install_source(pending_extension_info->install_source());
pkotwicz31eb1e8ec2014-10-08 15:26:46520 installer->set_allow_silent_install(true);
treibe960e282015-09-11 10:38:08521 // If the extension came in disabled due to a permission increase, then
522 // don't grant it all the permissions. crbug.com/484214
523 bool has_permissions_increase =
524 extensions::ExtensionPrefs::Get(profile_)->HasDisableReason(
525 id, Extension::DISABLE_PERMISSIONS_INCREASE);
526 const base::Version& expected_version = pending_extension_info->version();
527 if (has_permissions_increase ||
528 pending_extension_info->remote_install() ||
529 !expected_version.IsValid()) {
[email protected]21db9ef2014-05-16 02:06:27530 installer->set_grant_permissions(false);
treibe960e282015-09-11 10:38:08531 } else {
532 installer->set_expected_version(expected_version,
533 false /* fail_install_if_unexpected */);
534 }
[email protected]464213a2013-10-15 01:06:48535 creation_flags = pending_extension_info->creation_flags();
536 if (pending_extension_info->mark_acknowledged())
[email protected]374ceb6f2014-07-02 19:25:34537 external_install_manager_->AcknowledgeExternalExtension(id);
[email protected]51a3bf8b2012-06-08 22:53:06538 } else if (extension) {
[email protected]5eb375e92010-11-26 07:50:41539 installer->set_install_source(extension->location());
[email protected]51a3bf8b2012-06-08 22:53:06540 }
[email protected]7d8b7072012-04-07 01:07:46541 // If the extension was installed from or has migrated to the webstore, or
[email protected]fcb2c2c2012-10-17 21:08:45542 // its auto-update URL is from the webstore, treat it as a webstore install.
543 // Note that we ignore some older extensions with blank auto-update URLs
544 // because we are mostly concerned with restrictions on NaCl extensions,
545 // which are newer.
[email protected]75764512011-12-19 19:54:28546 if ((extension && extension->from_webstore()) ||
[email protected]4a5fe3e22013-06-04 07:06:38547 (extension && extensions::ManifestURL::UpdatesFromGallery(extension)) ||
[email protected]963d13c2012-09-29 17:13:35548 (!extension && extension_urls::IsWebstoreUpdateUrl(
[email protected]51a3bf8b2012-06-08 22:53:06549 pending_extension_info->update_url()))) {
[email protected]a12ce8b22012-01-17 18:40:53550 creation_flags |= Extension::FROM_WEBSTORE;
551 }
552
553 // Bookmark apps being updated is kind of a contradiction, but that's because
554 // we mark the default apps as bookmark apps, and they're hosted in the web
555 // store, thus they can get updated. See http://crbug.com/101605 for more
556 // details.
557 if (extension && extension->from_bookmark())
558 creation_flags |= Extension::FROM_BOOKMARK;
559
[email protected]e33bbc22012-08-27 22:05:46560 if (extension && extension->was_installed_by_default())
561 creation_flags |= Extension::WAS_INSTALLED_BY_DEFAULT;
562
[email protected]acc3c7c22014-03-19 06:23:39563 if (extension && extension->was_installed_by_oem())
564 creation_flags |= Extension::WAS_INSTALLED_BY_OEM;
565
[email protected]6338fa32014-07-16 21:41:59566 if (extension && extension->was_installed_by_custodian())
567 creation_flags |= Extension::WAS_INSTALLED_BY_CUSTODIAN;
568
[email protected]658eae52014-06-14 20:28:05569 if (extension) {
[email protected]411f8ae2014-05-22 11:12:23570 installer->set_is_ephemeral(extension_prefs_->IsEphemeralApp(id));
[email protected]c30bda262014-06-19 04:10:13571 installer->set_do_not_sync(extension_prefs_->DoNotSync(id));
[email protected]658eae52014-06-14 20:28:05572 }
[email protected]ab6c7be42014-01-16 02:05:54573
[email protected]a12ce8b22012-01-17 18:40:53574 installer->set_creation_flags(creation_flags);
575
[email protected]044e86992014-01-24 22:59:11576 installer->set_delete_source(file_ownership_passed);
[email protected]cb0e50312011-05-09 15:03:07577 installer->set_install_cause(extension_misc::INSTALL_CAUSE_UPDATE);
ginkage553af3202015-02-04 12:39:09578 installer->InstallCrxFile(file);
[email protected]420a0ec2011-06-01 01:07:03579
580 if (out_crx_installer)
[email protected]dc24976f2013-06-02 21:15:09581 *out_crx_installer = installer.get();
[email protected]420a0ec2011-06-01 01:07:03582
583 return true;
[email protected]e957fe52009-06-23 16:51:05584}
585
[email protected]bca4b832014-07-17 20:22:34586void ExtensionService::ReloadExtensionImpl(
[email protected]757d60a2014-05-23 00:11:44587 // "transient" because the process of reloading may cause the reference
588 // to become invalid. Instead, use |extension_id|, a copy.
[email protected]bca4b832014-07-17 20:22:34589 const std::string& transient_extension_id,
590 bool be_noisy) {
[email protected]a29a517a2011-01-21 21:11:12591 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]2a947202013-03-06 04:58:05592
593 // If the extension is already reloading, don't reload again.
[email protected]757d60a2014-05-23 00:11:44594 if (extension_prefs_->GetDisableReasons(transient_extension_id) &
[email protected]2a947202013-03-06 04:58:05595 Extension::DISABLE_RELOAD) {
596 return;
597 }
598
mlerman6a37b6a42014-11-26 22:10:53599 // Ignore attempts to reload a blacklisted or blocked extension. Sometimes
600 // this can happen in a convoluted reload sequence triggered by the
601 // termination of a blacklisted or blocked extension and a naive attempt to
602 // reload it. For an example see http://crbug.com/373842.
603 if (registry_->blacklisted_extensions().Contains(transient_extension_id) ||
604 registry_->blocked_extensions().Contains(transient_extension_id)) {
[email protected]757d60a2014-05-23 00:11:44605 return;
mlerman6a37b6a42014-11-26 22:10:53606 }
[email protected]757d60a2014-05-23 00:11:44607
[email protected]650b2d52013-02-10 03:41:45608 base::FilePath path;
[email protected]757d60a2014-05-23 00:11:44609
610 std::string extension_id = transient_extension_id;
611 const Extension* transient_current_extension =
612 GetExtensionById(extension_id, false);
[email protected]9cddd4702009-07-27 22:09:40613
[email protected]f17dbd42010-08-16 23:21:10614 // Disable the extension if it's loaded. It might not be loaded if it crashed.
[email protected]757d60a2014-05-23 00:11:44615 if (transient_current_extension) {
[email protected]4814b512009-11-07 00:12:29616 // If the extension has an inspector open for its background page, detach
617 // the inspector and hang onto a cookie for it, so that we can reattach
618 // later.
[email protected]31d8f5f22012-04-02 15:22:08619 // TODO(yoz): this is not incognito-safe!
reillyg0ea3fa902014-10-28 15:30:23620 extensions::ProcessManager* manager =
621 extensions::ProcessManager::Get(profile_);
[email protected]3a1dc572012-07-31 22:25:13622 extensions::ExtensionHost* host =
623 manager->GetBackgroundHostForExtension(extension_id);
[email protected]b3f957e62014-08-08 10:09:02624 if (host && DevToolsAgentHost::HasFor(host->host_contents())) {
[email protected]4814b512009-11-07 00:12:29625 // Look for an open inspector for the background page.
[email protected]04ea1bb2013-07-10 09:26:09626 scoped_refptr<DevToolsAgentHost> agent_host =
[email protected]b3f957e62014-08-08 10:09:02627 DevToolsAgentHost::GetOrCreateFor(host->host_contents());
628 agent_host->DisconnectWebContents();
[email protected]04ea1bb2013-07-10 09:26:09629 orphaned_dev_tools_[extension_id] = agent_host;
[email protected]4814b512009-11-07 00:12:29630 }
631
[email protected]757d60a2014-05-23 00:11:44632 path = transient_current_extension->path();
[email protected]58076192013-07-19 19:43:50633 // BeingUpgraded is set back to false when the extension is added.
rdevlin.cronin2c16c602014-11-21 01:35:49634 system_->runtime_data()->SetBeingUpgraded(transient_current_extension->id(),
[email protected]757d60a2014-05-23 00:11:44635 true);
[email protected]44d62b62012-04-11 00:06:03636 DisableExtension(extension_id, Extension::DISABLE_RELOAD);
[email protected]b914e2952013-04-26 07:10:03637 reloading_extensions_.insert(extension_id);
[email protected]1eb175082010-02-10 09:26:16638 } else {
[email protected]d32c02a2014-06-16 22:58:36639 std::map<std::string, base::FilePath>::const_iterator iter =
640 unloaded_extension_paths_.find(extension_id);
641 if (iter == unloaded_extension_paths_.end()) {
642 return;
643 }
[email protected]1eb175082010-02-10 09:26:16644 path = unloaded_extension_paths_[extension_id];
[email protected]b65272f2009-08-31 15:47:06645 }
646
[email protected]757d60a2014-05-23 00:11:44647 transient_current_extension = NULL;
648
[email protected]9f4e4f082013-06-21 07:11:19649 if (delayed_installs_.Contains(extension_id)) {
[email protected]6f6101832012-11-27 22:10:48650 FinishDelayedInstallation(extension_id);
[email protected]0db124b02012-11-07 04:55:05651 return;
652 }
653
[email protected]43ceb002012-02-10 23:19:15654 // If we're reloading a component extension, use the component extension
655 // loader's reloader.
656 if (component_loader_->Exists(extension_id)) {
657 component_loader_->Reload(extension_id);
658 return;
659 }
660
[email protected]e6090e42010-03-23 22:44:08661 // Check the installed extensions to see if what we're reloading was already
662 // installed.
663 scoped_ptr<ExtensionInfo> installed_extension(
664 extension_prefs_->GetInstalledExtensionInfo(extension_id));
665 if (installed_extension.get() &&
666 installed_extension->extension_manifest.get()) {
[email protected]d8c8f25f2011-11-02 18:18:01667 extensions::InstalledLoader(this).Load(*installed_extension, false);
[email protected]e6090e42010-03-23 22:44:08668 } else {
[email protected]d8c8f25f2011-11-02 18:18:01669 // Otherwise, the extension is unpacked (location LOAD).
[email protected]e6090e42010-03-23 22:44:08670 // We should always be able to remember the extension's path. If it's not in
671 // the map, someone failed to update |unloaded_extension_paths_|.
672 CHECK(!path.empty());
[email protected]bca4b832014-07-17 20:22:34673 scoped_refptr<extensions::UnpackedInstaller> unpacked_installer =
674 extensions::UnpackedInstaller::Create(this);
675 unpacked_installer->set_be_noisy_on_failure(be_noisy);
676 unpacked_installer->Load(path);
[email protected]e6090e42010-03-23 22:44:08677 }
[email protected]9cddd4702009-07-27 22:09:40678}
679
[email protected]bca4b832014-07-17 20:22:34680void ExtensionService::ReloadExtension(const std::string& extension_id) {
681 ReloadExtensionImpl(extension_id, true); // be_noisy
682}
683
684void ExtensionService::ReloadExtensionWithQuietFailure(
685 const std::string& extension_id) {
686 ReloadExtensionImpl(extension_id, false); // be_noisy
687}
688
[email protected]757d60a2014-05-23 00:11:44689bool ExtensionService::UninstallExtension(
690 // "transient" because the process of uninstalling may cause the reference
691 // to become invalid. Instead, use |extenson->id()|.
692 const std::string& transient_extension_id,
[email protected]e43c61f2014-07-20 21:46:34693 extensions::UninstallReason reason,
[email protected]42d58f62014-07-31 01:32:45694 const base::Closure& deletion_done_callback,
[email protected]757d60a2014-05-23 00:11:44695 base::string16* error) {
[email protected]a29a517a2011-01-21 21:11:12696 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]a8af9fdb2010-10-28 21:52:20697
[email protected]757d60a2014-05-23 00:11:44698 scoped_refptr<const Extension> extension =
699 GetInstalledExtension(transient_extension_id);
[email protected]631cf822009-05-15 07:01:25700
[email protected]e7afe2452010-08-22 16:19:13701 // Callers should not send us nonexistent extensions.
[email protected]dc24976f2013-06-02 21:15:09702 CHECK(extension.get());
[email protected]9f1087e2009-06-15 17:29:32703
binjincccacef2014-10-13 19:00:20704 ManagementPolicy* by_policy = system_->management_policy();
[email protected]95da88c42011-03-31 10:07:33705 // Policy change which triggers an uninstall will always set
706 // |external_uninstall| to true so this is the only way to uninstall
707 // managed extensions.
[email protected]90878c52014-04-04 18:21:02708 // Shared modules being uninstalled will also set |external_uninstall| to true
709 // so that we can guarantee users don't uninstall a shared module.
710 // (crbug.com/273300)
711 // TODO(rdevlin.cronin): This is probably not right. We should do something
712 // else, like include an enum IS_INTERNAL_UNINSTALL or IS_USER_UNINSTALL so
713 // we don't do this.
[email protected]cc2f55c2014-07-08 02:19:04714 bool external_uninstall =
[email protected]e43c61f2014-07-20 21:46:34715 (reason == extensions::UNINSTALL_REASON_INTERNAL_MANAGEMENT) ||
dtseng9fb3d5b2015-02-23 17:24:17716 (reason == extensions::UNINSTALL_REASON_COMPONENT_REMOVED) ||
rdevlin.cronin5f6b69d2014-09-20 01:23:35717 (reason == extensions::UNINSTALL_REASON_REINSTALL) ||
[email protected]e43c61f2014-07-20 21:46:34718 (reason == extensions::UNINSTALL_REASON_ORPHANED_EXTERNAL_EXTENSION) ||
[email protected]6ef60012014-07-22 19:08:12719 (reason == extensions::UNINSTALL_REASON_ORPHANED_SHARED_MODULE) ||
720 (reason == extensions::UNINSTALL_REASON_SYNC &&
dtseng9fb3d5b2015-02-23 17:24:17721 extension->was_installed_by_custodian());
[email protected]65187152012-06-02 13:14:14722 if (!external_uninstall &&
binjincccacef2014-10-13 19:00:20723 (!by_policy->UserMayModifySettings(extension.get(), error) ||
724 by_policy->MustRemainInstalled(extension.get(), error))) {
[email protected]ad50def52011-10-19 23:17:07725 content::NotificationService::current()->Notify(
[email protected]adf5a102014-07-31 12:44:06726 extensions::NOTIFICATION_EXTENSION_UNINSTALL_NOT_ALLOWED,
[email protected]6c2381d2011-10-19 02:52:53727 content::Source<Profile>(profile_),
[email protected]dc24976f2013-06-02 21:15:09728 content::Details<const Extension>(extension.get()));
[email protected]d6ebc9792011-04-07 18:18:33729 return false;
730 }
[email protected]95da88c42011-03-31 10:07:33731
juncai33e462102015-05-18 20:48:44732 InstallVerifier::Get(GetBrowserContext())->Remove(extension->id());
[email protected]ffd2f79e2013-11-14 00:11:46733
[email protected]9b217652010-10-08 22:04:23734 UMA_HISTOGRAM_ENUMERATION("Extensions.UninstallType",
[email protected]7fa19f82010-12-21 19:40:08735 extension->GetType(), 100);
treib2e0517f92015-05-07 23:15:36736 RecordPermissionMessagesHistogram(extension.get(), "Uninstall");
[email protected]9b217652010-10-08 22:04:23737
[email protected]831aa212010-03-26 13:55:19738 // Unload before doing more cleanup to ensure that nothing is hanging on to
739 // any of these resources.
[email protected]757d60a2014-05-23 00:11:44740 UnloadExtension(extension->id(), UnloadedExtensionInfo::REASON_UNINSTALL);
[email protected]831aa212010-03-26 13:55:19741
[email protected]9f1087e2009-06-15 17:29:32742 // Tell the backend to start deleting installed extensions on the file thread.
[email protected]12075d12013-02-27 05:38:05743 if (!Manifest::IsUnpackedLocation(extension->location())) {
[email protected]7f8f24f2012-11-15 19:40:14744 if (!GetFileTaskRunner()->PostTask(
745 FROM_HERE,
[email protected]5a145e82014-05-29 22:19:07746 base::Bind(&ExtensionService::UninstallExtensionOnFileThread,
747 extension->id(),
748 profile_,
[email protected]85df9d12014-04-15 17:02:14749 install_directory_,
[email protected]5a145e82014-05-29 22:19:07750 extension->path())))
[email protected]14908b72011-04-20 06:54:36751 NOTREACHED();
[email protected]9f1087e2009-06-15 17:29:32752 }
753
[email protected]42d58f62014-07-31 01:32:45754 extensions::DataDeleter::StartDeleting(
755 profile_, extension.get(), deletion_done_callback);
[email protected]0d6ec3a72011-09-02 02:09:43756
[email protected]757d60a2014-05-23 00:11:44757 UntrackTerminatedExtension(extension->id());
[email protected]211030342010-09-30 18:41:06758
759 // Notify interested parties that we've uninstalled this extension.
[email protected]e43c61f2014-07-20 21:46:34760 ExtensionRegistry::Get(profile_)
761 ->TriggerOnUninstalled(extension.get(), reason);
[email protected]d6ebc9792011-04-07 18:18:33762
[email protected]757d60a2014-05-23 00:11:44763 delayed_installs_.Remove(extension->id());
[email protected]0db124b02012-11-07 04:55:05764
[email protected]757d60a2014-05-23 00:11:44765 extension_prefs_->OnExtensionUninstalled(
766 extension->id(), extension->location(), external_uninstall);
[email protected]d4eda592013-09-18 03:37:57767
[email protected]333b1de2011-09-12 18:28:50768 // Track the uninstallation.
[email protected]49098f702011-10-13 03:47:18769 UMA_HISTOGRAM_ENUMERATION("Extensions.ExtensionUninstalled", 1, 2);
770
[email protected]d6ebc9792011-04-07 18:18:33771 return true;
[email protected]c10da4b02010-03-25 14:38:32772}
773
[email protected]5a145e82014-05-29 22:19:07774// static
775void ExtensionService::UninstallExtensionOnFileThread(
776 const std::string& id,
777 Profile* profile,
778 const base::FilePath& install_dir,
779 const base::FilePath& extension_path) {
780 extensions::ExtensionAssetsManager* assets_manager =
781 extensions::ExtensionAssetsManager::GetInstance();
782 assets_manager->UninstallExtension(id, profile, install_dir, extension_path);
783}
784
[email protected]c3cfb012011-04-06 22:07:35785bool ExtensionService::IsExtensionEnabled(
786 const std::string& extension_id) const {
[email protected]bb1bc9b32013-12-21 03:09:14787 if (registry_->enabled_extensions().Contains(extension_id) ||
788 registry_->terminated_extensions().Contains(extension_id)) {
[email protected]36429da2011-07-11 20:25:18789 return true;
[email protected]dc9a74f72012-08-17 18:07:21790 }
[email protected]36429da2011-07-11 20:25:18791
[email protected]bb1bc9b32013-12-21 03:09:14792 if (registry_->disabled_extensions().Contains(extension_id) ||
mlerman6a37b6a42014-11-26 22:10:53793 registry_->blacklisted_extensions().Contains(extension_id) ||
794 registry_->blocked_extensions().Contains(extension_id)) {
[email protected]ad83ca242011-07-29 01:32:25795 return false;
[email protected]695b5712012-12-06 23:55:28796 }
[email protected]ad83ca242011-07-29 01:32:25797
mlerman3690e5be2014-12-01 22:57:44798 // Blocked extensions aren't marked as such in prefs, thus if
799 // |block_extensions_| is true then CanBlockExtension() must be called with an
800 // Extension object. If the |extension_id| is not loaded, assume not enabled.
801 if (block_extensions_) {
802 const Extension* extension = GetInstalledExtension(extension_id);
803 if (!extension || CanBlockExtension(extension))
804 return false;
805 }
mlerman6a37b6a42014-11-26 22:10:53806
[email protected]ad83ca242011-07-29 01:32:25807 // If the extension hasn't been loaded yet, check the prefs for it. Assume
808 // enabled unless otherwise noted.
809 return !extension_prefs_->IsExtensionDisabled(extension_id) &&
[email protected]27e528322014-05-27 20:54:30810 !extension_prefs_->IsExtensionBlacklisted(extension_id) &&
[email protected]f574c402012-12-04 23:20:31811 !extension_prefs_->IsExternalExtensionUninstalled(extension_id);
[email protected]c3cfb012011-04-06 22:07:35812}
813
[email protected]eaa7dd182010-12-14 11:09:00814void ExtensionService::EnableExtension(const std::string& extension_id) {
[email protected]a29a517a2011-01-21 21:11:12815 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]a8af9fdb2010-10-28 21:52:20816
[email protected]06f92562011-04-29 19:27:31817 if (IsExtensionEnabled(extension_id))
[email protected]0c6da502009-08-14 22:32:39818 return;
[email protected]bb1bc9b32013-12-21 03:09:14819 const Extension* extension =
820 registry_->disabled_extensions().GetByID(extension_id);
[email protected]0d54b682013-11-05 14:15:36821
822 ManagementPolicy* policy = system_->management_policy();
823 if (extension && policy->MustRemainDisabled(extension, NULL, NULL)) {
824 UMA_HISTOGRAM_COUNTS_100("Extensions.EnableDeniedByPolicy", 1);
825 return;
826 }
[email protected]0c6da502009-08-14 22:32:39827
treib8a6d9892015-08-26 10:23:19828 extension_prefs_->SetExtensionEnabled(extension_id);
[email protected]1784e83a2009-09-08 21:01:52829
treib8a6d9892015-08-26 10:23:19830 // This can happen if sync enables an extension that is not installed yet.
[email protected]06f92562011-04-29 19:27:31831 if (!extension)
832 return;
833
[email protected]0c6da502009-08-14 22:32:39834 // Move it over to the enabled list.
[email protected]bb1bc9b32013-12-21 03:09:14835 registry_->AddEnabled(make_scoped_refptr(extension));
836 registry_->RemoveDisabled(extension->id());
[email protected]0c6da502009-08-14 22:32:39837
[email protected]62d30f42009-10-01 22:36:06838 NotifyExtensionLoaded(extension);
[email protected]3bdba0d2011-08-23 07:17:30839
[email protected]f74d7f32012-06-19 19:22:51840 // Notify listeners that the extension was enabled.
841 content::NotificationService::current()->Notify(
[email protected]adf5a102014-07-31 12:44:06842 extensions::NOTIFICATION_EXTENSION_ENABLED,
[email protected]f74d7f32012-06-19 19:22:51843 content::Source<Profile>(profile_),
844 content::Details<const Extension>(extension));
[email protected]0c6da502009-08-14 22:32:39845}
846
treibc1192322015-05-20 12:56:07847void ExtensionService::DisableExtension(const std::string& extension_id,
848 int disable_reasons) {
[email protected]a29a517a2011-01-21 21:11:12849 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]a8af9fdb2010-10-28 21:52:20850
treib8a6d9892015-08-26 10:23:19851 // The extension may have been disabled already. Just add the disable reasons.
[email protected]8f959f522014-08-06 06:26:28852 if (!IsExtensionEnabled(extension_id)) {
treibc1192322015-05-20 12:56:07853 extension_prefs_->AddDisableReasons(extension_id, disable_reasons);
[email protected]1784e83a2009-09-08 21:01:52854 return;
[email protected]8f959f522014-08-06 06:26:28855 }
[email protected]1784e83a2009-09-08 21:01:52856
[email protected]06f92562011-04-29 19:27:31857 const Extension* extension = GetInstalledExtension(extension_id);
858 // |extension| can be NULL if sync disables an extension that is not
859 // installed yet.
[email protected]ab894542014-07-03 12:35:39860 // EXTERNAL_COMPONENT extensions are not generally modifiable by users, but
861 // can be uninstalled by the browser if the user sets extension-specific
862 // preferences.
[email protected]65187152012-06-02 13:14:14863 if (extension &&
treibc1192322015-05-20 12:56:07864 !(disable_reasons & Extension::DISABLE_RELOAD) &&
865 !(disable_reasons & Extension::DISABLE_UPDATE_REQUIRED_BY_POLICY) &&
[email protected]ab894542014-07-03 12:35:39866 !system_->management_policy()->UserMayModifySettings(extension, NULL) &&
867 extension->location() != Manifest::EXTERNAL_COMPONENT) {
[email protected]95da88c42011-03-31 10:07:33868 return;
[email protected]65187152012-06-02 13:14:14869 }
[email protected]95da88c42011-03-31 10:07:33870
treib8a6d9892015-08-26 10:23:19871 extension_prefs_->SetExtensionDisabled(extension_id, disable_reasons);
[email protected]1784e83a2009-09-08 21:01:52872
[email protected]599539802014-01-07 23:06:00873 int include_mask =
874 ExtensionRegistry::EVERYTHING & ~ExtensionRegistry::DISABLED;
875 extension = registry_->GetExtensionById(extension_id, include_mask);
[email protected]06f92562011-04-29 19:27:31876 if (!extension)
877 return;
878
[email protected]45f5b7d2014-01-22 23:47:13879 // The extension is either enabled or terminated.
880 DCHECK(registry_->enabled_extensions().Contains(extension->id()) ||
881 registry_->terminated_extensions().Contains(extension->id()));
[email protected]64742de32013-04-22 08:44:34882
[email protected]5c094792012-09-07 19:44:53883 // Move it over to the disabled list. Don't send a second unload notification
884 // for terminated extensions being disabled.
[email protected]bb1bc9b32013-12-21 03:09:14885 registry_->AddDisabled(make_scoped_refptr(extension));
886 if (registry_->enabled_extensions().Contains(extension->id())) {
887 registry_->RemoveEnabled(extension->id());
[email protected]b0af4792013-10-23 09:12:13888 NotifyExtensionUnloaded(extension, UnloadedExtensionInfo::REASON_DISABLE);
[email protected]5c094792012-09-07 19:44:53889 } else {
[email protected]bb1bc9b32013-12-21 03:09:14890 registry_->RemoveTerminated(extension->id());
[email protected]5c094792012-09-07 19:44:53891 }
[email protected]1784e83a2009-09-08 21:01:52892}
893
[email protected]1abf05e2013-07-09 17:04:36894void ExtensionService::DisableUserExtensions(
895 const std::vector<std::string>& except_ids) {
[email protected]e516e4c2013-06-12 17:41:14896 extensions::ManagementPolicy* management_policy =
897 system_->management_policy();
898 extensions::ExtensionList to_disable;
899
[email protected]bb1bc9b32013-12-21 03:09:14900 const ExtensionSet& enabled_set = registry_->enabled_extensions();
901 for (ExtensionSet::const_iterator extension = enabled_set.begin();
902 extension != enabled_set.end(); ++extension) {
[email protected]ab894542014-07-03 12:35:39903 if (management_policy->UserMayModifySettings(extension->get(), NULL))
[email protected]e516e4c2013-06-12 17:41:14904 to_disable.push_back(*extension);
905 }
[email protected]bb1bc9b32013-12-21 03:09:14906 const ExtensionSet& terminated_set = registry_->terminated_extensions();
907 for (ExtensionSet::const_iterator extension = terminated_set.begin();
908 extension != terminated_set.end(); ++extension) {
[email protected]ab894542014-07-03 12:35:39909 if (management_policy->UserMayModifySettings(extension->get(), NULL))
[email protected]e516e4c2013-06-12 17:41:14910 to_disable.push_back(*extension);
911 }
912
913 for (extensions::ExtensionList::const_iterator extension = to_disable.begin();
914 extension != to_disable.end(); ++extension) {
[email protected]3082fe32013-08-06 11:12:38915 if ((*extension)->was_installed_by_default() &&
916 extension_urls::IsWebstoreUpdateUrl(
dchengc7047942014-08-26 05:05:31917 extensions::ManifestURL::GetUpdateURL(extension->get())))
[email protected]3082fe32013-08-06 11:12:38918 continue;
[email protected]1abf05e2013-07-09 17:04:36919 const std::string& id = (*extension)->id();
920 if (except_ids.end() == std::find(except_ids.begin(), except_ids.end(), id))
921 DisableExtension(id, extensions::Extension::DISABLE_USER_ACTION);
[email protected]e516e4c2013-06-12 17:41:14922 }
923}
924
mlerman6a37b6a42014-11-26 22:10:53925// Extensions that are not locked, components or forced by policy should be
926// locked. Extensions are no longer considered enabled or disabled. Blacklisted
927// extensions are now considered both blacklisted and locked.
928void ExtensionService::BlockAllExtensions() {
929 if (block_extensions_)
930 return;
931 block_extensions_ = true;
932
933 // Blacklisted extensions are already unloaded, need not be blocked.
934 scoped_ptr<ExtensionSet> extensions =
935 registry_->GenerateInstalledExtensionsSet(ExtensionRegistry::ENABLED |
936 ExtensionRegistry::DISABLED |
937 ExtensionRegistry::TERMINATED);
938
939 for (const scoped_refptr<const Extension>& extension : *extensions) {
940 const std::string& id = extension->id();
941
942 if (!CanBlockExtension(extension.get()))
943 continue;
944
945 registry_->RemoveEnabled(id);
946 registry_->RemoveDisabled(id);
947 registry_->RemoveTerminated(id);
948
949 registry_->AddBlocked(extension.get());
950 UnloadExtension(id, extensions::UnloadedExtensionInfo::REASON_LOCK_ALL);
951 }
952}
953
954// All locked extensions should revert to being either enabled or disabled
955// as appropriate.
956void ExtensionService::UnblockAllExtensions() {
957 block_extensions_ = false;
958 scoped_ptr<ExtensionSet> to_unblock =
959 registry_->GenerateInstalledExtensionsSet(ExtensionRegistry::BLOCKED);
960
961 for (const scoped_refptr<const Extension>& extension : *to_unblock) {
962 registry_->RemoveBlocked(extension->id());
963 AddExtension(extension.get());
964 }
965}
966
[email protected]eaa7dd182010-12-14 11:09:00967void ExtensionService::GrantPermissionsAndEnableExtension(
[email protected]009633c2013-03-07 22:08:28968 const Extension* extension) {
969 GrantPermissions(extension);
treib2e0517f92015-05-07 23:15:36970 RecordPermissionMessagesHistogram(extension, "ReEnable");
[email protected]8d888c12010-11-30 00:00:25971 EnableExtension(extension->id());
972}
973
[email protected]009633c2013-03-07 22:08:28974void ExtensionService::GrantPermissions(const Extension* extension) {
[email protected]be083862012-09-01 03:53:45975 CHECK(extension);
[email protected]8d42db52014-06-20 21:50:50976 extensions::PermissionsUpdater(profile()).GrantActivePermissions(extension);
[email protected]be083862012-09-01 03:53:45977}
978
[email protected]fe2dd7742011-04-19 22:52:49979// static
980void ExtensionService::RecordPermissionMessagesHistogram(
[email protected]13c68b62013-05-17 11:29:05981 const Extension* extension, const char* histogram) {
[email protected]de415552013-01-23 04:12:17982 // Since this is called from multiple sources, and since the histogram macros
983 // use statics, we need to manually lookup the histogram ourselves.
treib2e0517f92015-05-07 23:15:36984 base::HistogramBase* counter = base::LinearHistogram::FactoryGet(
985 base::StringPrintf("Extensions.Permissions_%s3", histogram),
986 1,
987 APIPermission::kEnumBoundary,
988 APIPermission::kEnumBoundary + 1,
989 base::HistogramBase::kUmaTargetedHistogramFlag);
990
991 base::HistogramBase* counter_has_any = base::BooleanHistogram::FactoryGet(
992 base::StringPrintf("Extensions.HasPermissions_%s3", histogram),
993 base::HistogramBase::kUmaTargetedHistogramFlag);
994
995 PermissionIDSet permissions =
996 extensions::PermissionMessageProvider::Get()->GetAllPermissionIDs(
rdevlin.cronine2d0fd02015-09-24 22:35:49997 extension->permissions_data()->active_permissions(),
treib2e0517f92015-05-07 23:15:36998 extension->GetType());
999 counter_has_any->AddBoolean(!permissions.empty());
1000 for (const PermissionID& id : permissions)
1001 counter->Add(id.id());
[email protected]fe2dd7742011-04-19 22:52:491002}
1003
[email protected]eaa7dd182010-12-14 11:09:001004void ExtensionService::NotifyExtensionLoaded(const Extension* extension) {
[email protected]f9c8c7c72014-07-31 16:42:311005 // The URLRequestContexts need to be first to know that the extension
[email protected]62d30f42009-10-01 22:36:061006 // was loaded, otherwise a race can arise where a renderer that is created
1007 // for the extension may try to load an extension URL with an extension id
[email protected]57a777f72010-03-31 01:09:421008 // that the request context doesn't yet know about. The profile is responsible
1009 // for ensuring its URLRequestContexts appropriately discover the loaded
1010 // extension.
rockot494f0072015-07-29 17:58:071011 system_->RegisterExtensionWithRequestContexts(
1012 extension,
1013 base::Bind(&ExtensionService::OnExtensionRegisteredWithRequestContexts,
1014 AsWeakPtr(), make_scoped_refptr(extension)));
[email protected]62d30f42009-10-01 22:36:061015
[email protected]d5949312012-12-03 22:13:301016 // Tell renderers about the new extension, unless it's a theme (renderers
1017 // don't need to know about themes).
[email protected]a58f599c2012-12-01 03:08:191018 if (!extension->is_theme()) {
[email protected]19647262011-12-16 09:57:491019 for (content::RenderProcessHost::iterator i(
1020 content::RenderProcessHost::AllHostsIterator());
1021 !i.IsAtEnd(); i.Advance()) {
1022 content::RenderProcessHost* host = i.GetCurrentValue();
1023 Profile* host_profile =
1024 Profile::FromBrowserContext(host->GetBrowserContext());
1025 if (host_profile->GetOriginalProfile() ==
1026 profile_->GetOriginalProfile()) {
rdevlin.croninc491dbf2015-02-07 00:31:551027 // We don't need to include tab permisisons here, since the extension
1028 // was just loaded.
[email protected]19647262011-12-16 09:57:491029 std::vector<ExtensionMsg_Loaded_Params> loaded_extensions(
rdevlin.croninc491dbf2015-02-07 00:31:551030 1, ExtensionMsg_Loaded_Params(extension,
1031 false /* no tab permissions */));
[email protected]19647262011-12-16 09:57:491032 host->Send(
1033 new ExtensionMsg_Loaded(loaded_extensions));
1034 }
[email protected]c8d407e2011-04-28 21:27:171035 }
[email protected]77a6970c2011-04-23 16:58:561036 }
1037
[email protected]3442a662012-01-12 08:06:171038 // Tell subsystems that use the EXTENSION_LOADED notification about the new
1039 // extension.
1040 //
1041 // NOTE: It is important that this happen after notifying the renderers about
1042 // the new extensions so that if we navigate to an extension URL in
[email protected]fdc76192014-04-20 21:54:411043 // ExtensionRegistryObserver::OnLoaded or
1044 // NOTIFICATION_EXTENSION_LOADED_DEPRECATED, the
[email protected]dcc47642014-03-26 22:03:491045 // renderer is guaranteed to know about it.
1046 registry_->TriggerOnLoaded(extension);
1047
[email protected]3442a662012-01-12 08:06:171048 content::NotificationService::current()->Notify(
[email protected]adf5a102014-07-31 12:44:061049 extensions::NOTIFICATION_EXTENSION_LOADED_DEPRECATED,
[email protected]3442a662012-01-12 08:06:171050 content::Source<Profile>(profile_),
1051 content::Details<const Extension>(extension));
1052
[email protected]dcc47642014-03-26 22:03:491053 // TODO(kalman): Convert ExtensionSpecialStoragePolicy to a
1054 // BrowserContextKeyedService and use ExtensionRegistryObserver.
[email protected]c8d407e2011-04-28 21:27:171055 profile_->GetExtensionSpecialStoragePolicy()->
rdevlin.croninbc8979a2014-09-30 01:08:501056 GrantRightsForExtension(extension, profile_);
[email protected]c8d407e2011-04-28 21:27:171057
[email protected]dcc47642014-03-26 22:03:491058 // TODO(kalman): This is broken. The crash reporter is process-wide so doesn't
1059 // work properly multi-profile. Besides which, it should be using
1060 // ExtensionRegistryObserver. See http://crbug.com/355029.
[email protected]c8d407e2011-04-28 21:27:171061 UpdateActiveExtensionsInCrashReporter();
1062
[email protected]d695bb12014-06-05 16:16:301063 const extensions::PermissionsData* permissions_data =
[email protected]a6910e72014-06-06 05:04:361064 extension->permissions_data();
[email protected]d695bb12014-06-05 16:16:301065
[email protected]c8d407e2011-04-28 21:27:171066 // If the extension has permission to load chrome://favicon/ resources we need
1067 // to make sure that the FaviconSource is registered with the
1068 // ChromeURLDataManager.
[email protected]d695bb12014-06-05 16:16:301069 if (permissions_data->HasHostPermission(GURL(chrome::kChromeUIFaviconURL))) {
[email protected]c8d407e2011-04-28 21:27:171070 FaviconSource* favicon_source = new FaviconSource(profile_,
1071 FaviconSource::FAVICON);
[email protected]24ea7a12013-01-27 23:54:531072 content::URLDataSource::Add(profile_, favicon_source);
[email protected]c8d407e2011-04-28 21:27:171073 }
[email protected]b07e606e2012-09-15 20:16:151074
[email protected]b07e606e2012-09-15 20:16:151075 // Same for chrome://theme/ resources.
[email protected]d695bb12014-06-05 16:16:301076 if (permissions_data->HasHostPermission(GURL(chrome::kChromeUIThemeURL))) {
[email protected]b07e606e2012-09-15 20:16:151077 ThemeSource* theme_source = new ThemeSource(profile_);
[email protected]24ea7a12013-01-27 23:54:531078 content::URLDataSource::Add(profile_, theme_source);
[email protected]b07e606e2012-09-15 20:16:151079 }
[email protected]b07e606e2012-09-15 20:16:151080
[email protected]5eddc3e2011-10-26 04:33:311081 // Same for chrome://thumb/ resources.
[email protected]d695bb12014-06-05 16:16:301082 if (permissions_data->HasHostPermission(
1083 GURL(chrome::kChromeUIThumbnailURL))) {
[email protected]420e6d92013-09-17 01:48:511084 ThumbnailSource* thumbnail_source = new ThumbnailSource(profile_, false);
[email protected]24ea7a12013-01-27 23:54:531085 content::URLDataSource::Add(profile_, thumbnail_source);
[email protected]5eddc3e2011-10-26 04:33:311086 }
[email protected]62d30f42009-10-01 22:36:061087}
1088
rockot494f0072015-07-29 17:58:071089void ExtensionService::OnExtensionRegisteredWithRequestContexts(
1090 scoped_refptr<const extensions::Extension> extension) {
1091 registry_->AddReady(extension);
1092 if (registry_->enabled_extensions().Contains(extension->id()))
1093 registry_->TriggerOnReady(extension.get());
1094}
1095
[email protected]a9f39a312010-12-23 22:14:271096void ExtensionService::NotifyExtensionUnloaded(
[email protected]814a7bf0f2011-08-13 05:30:591097 const Extension* extension,
[email protected]b0af4792013-10-23 09:12:131098 UnloadedExtensionInfo::Reason reason) {
[email protected]a9f39a312010-12-23 22:14:271099 UnloadedExtensionInfo details(extension, reason);
[email protected]e51232f32014-04-18 20:05:361100
1101 registry_->TriggerOnUnloaded(extension, reason);
1102
[email protected]ad50def52011-10-19 23:17:071103 content::NotificationService::current()->Notify(
[email protected]adf5a102014-07-31 12:44:061104 extensions::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED,
[email protected]6c2381d2011-10-19 02:52:531105 content::Source<Profile>(profile_),
1106 content::Details<UnloadedExtensionInfo>(&details));
[email protected]62d30f42009-10-01 22:36:061107
[email protected]f3b1a082011-11-18 00:34:301108 for (content::RenderProcessHost::iterator i(
1109 content::RenderProcessHost::AllHostsIterator());
[email protected]77a6970c2011-04-23 16:58:561110 !i.IsAtEnd(); i.Advance()) {
[email protected]f3b1a082011-11-18 00:34:301111 content::RenderProcessHost* host = i.GetCurrentValue();
[email protected]9b62ecf2011-07-27 20:23:081112 Profile* host_profile =
[email protected]f3b1a082011-11-18 00:34:301113 Profile::FromBrowserContext(host->GetBrowserContext());
[email protected]9b62ecf2011-07-27 20:23:081114 if (host_profile->GetOriginalProfile() == profile_->GetOriginalProfile())
[email protected]c8d407e2011-04-28 21:27:171115 host->Send(new ExtensionMsg_Unloaded(extension->id()));
[email protected]77a6970c2011-04-23 16:58:561116 }
1117
[email protected]31d8f5f22012-04-02 15:22:081118 system_->UnregisterExtensionWithRequestContexts(extension->id(), reason);
[email protected]dcc47642014-03-26 22:03:491119
1120 // TODO(kalman): Convert ExtensionSpecialStoragePolicy to a
1121 // BrowserContextKeyedService and use ExtensionRegistryObserver.
[email protected]c8d407e2011-04-28 21:27:171122 profile_->GetExtensionSpecialStoragePolicy()->
1123 RevokeRightsForExtension(extension);
1124
[email protected]b777b332011-04-16 04:01:081125#if defined(OS_CHROMEOS)
[email protected]ac66e452013-01-11 09:21:231126 // Revoke external file access for the extension from its file system context.
1127 // It is safe to access the extension's storage partition at this point. The
1128 // storage partition may get destroyed only after the extension gets unloaded.
[email protected]3a746ec2014-03-15 05:30:561129 GURL site =
1130 extensions::util::GetSiteForExtensionId(extension->id(), profile_);
[email protected]cd501a72014-08-22 19:58:311131 storage::FileSystemContext* filesystem_context =
1132 BrowserContext::GetStoragePartitionForSite(profile_, site)
1133 ->GetFileSystemContext();
[email protected]f19bbf62013-07-09 01:22:321134 if (filesystem_context && filesystem_context->external_backend()) {
1135 filesystem_context->external_backend()->
[email protected]c8d407e2011-04-28 21:27:171136 RevokeAccessForExtension(extension->id());
[email protected]62d30f42009-10-01 22:36:061137 }
[email protected]c8d407e2011-04-28 21:27:171138#endif
1139
[email protected]dcc47642014-03-26 22:03:491140 // TODO(kalman): This is broken. The crash reporter is process-wide so doesn't
1141 // work properly multi-profile. Besides which, it should be using
1142 // ExtensionRegistryObserver::OnExtensionLoaded. See http://crbug.com/355029.
[email protected]c8d407e2011-04-28 21:27:171143 UpdateActiveExtensionsInCrashReporter();
[email protected]62d30f42009-10-01 22:36:061144}
1145
[email protected]599539802014-01-07 23:06:001146content::BrowserContext* ExtensionService::GetBrowserContext() const {
1147 // Implemented in the .cc file to avoid adding a profile.h dependency to
1148 // extension_service.h.
1149 return profile_;
1150}
1151
[email protected]25ae0152011-11-18 14:40:021152bool ExtensionService::is_ready() {
[email protected]4a10006a2013-05-17 23:18:351153 return ready_->is_signaled();
[email protected]25ae0152011-11-18 14:40:021154}
1155
[email protected]7f8f24f2012-11-15 19:40:141156base::SequencedTaskRunner* ExtensionService::GetFileTaskRunner() {
[email protected]dc24976f2013-06-02 21:15:091157 if (file_task_runner_.get())
1158 return file_task_runner_.get();
[email protected]7f8f24f2012-11-15 19:40:141159
1160 // We should be able to interrupt any part of extension install process during
1161 // shutdown. SKIP_ON_SHUTDOWN ensures that not started extension install tasks
1162 // will be ignored/deleted while we will block on started tasks.
1163 std::string token("ext_install-");
1164 token.append(profile_->GetPath().AsUTF8Unsafe());
1165 file_task_runner_ = BrowserThread::GetBlockingPool()->
1166 GetSequencedTaskRunnerWithShutdownBehavior(
1167 BrowserThread::GetBlockingPool()->GetNamedSequenceToken(token),
1168 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN);
[email protected]dc24976f2013-06-02 21:15:091169 return file_task_runner_.get();
[email protected]7f8f24f2012-11-15 19:40:141170}
1171
[email protected]4ee07c62012-08-21 12:40:421172void ExtensionService::CheckManagementPolicy() {
[email protected]0d54b682013-11-05 14:15:361173 std::vector<std::string> to_unload;
1174 std::map<std::string, Extension::DisableReason> to_disable;
binjin8e3d0182014-12-04 16:44:281175 std::vector<std::string> to_enable;
[email protected]695b5712012-12-06 23:55:281176
[email protected]0d54b682013-11-05 14:15:361177 // Loop through the extensions list, finding extensions we need to unload or
1178 // disable.
binjin8e3d0182014-12-04 16:44:281179 for (scoped_refptr<const Extension> extension :
1180 registry_->enabled_extensions()) {
1181 if (!system_->management_policy()->UserMayLoad(extension.get(), nullptr))
[email protected]0d54b682013-11-05 14:15:361182 to_unload.push_back(extension->id());
1183 Extension::DisableReason disable_reason = Extension::DISABLE_NONE;
1184 if (system_->management_policy()->MustRemainDisabled(
binjin8e3d0182014-12-04 16:44:281185 extension.get(), &disable_reason, nullptr))
[email protected]0d54b682013-11-05 14:15:361186 to_disable[extension->id()] = disable_reason;
[email protected]aa96d3a2010-08-21 08:45:251187 }
1188
binjin8e3d0182014-12-04 16:44:281189 extensions::ExtensionManagement* management =
1190 extensions::ExtensionManagementFactory::GetForBrowserContext(profile());
1191
1192 // Loop through the disabled extension list, find extensions to re-enable
1193 // automatically. These extensions are exclusive from the |to_disable| and
1194 // |to_unload| lists constructed above, since disabled_extensions() and
1195 // enabled_extensions() are supposed to be mutually exclusive.
1196 for (scoped_refptr<const Extension> extension :
1197 registry_->disabled_extensions()) {
1198 // Find all disabled extensions disabled due to minimum version requirement,
1199 // but now satisfying it.
1200 if (management->CheckMinimumVersion(extension.get(), nullptr) &&
1201 extension_prefs_->HasDisableReason(
1202 extension->id(), Extension::DISABLE_UPDATE_REQUIRED_BY_POLICY)) {
1203 // Is DISABLE_UPDATE_REQUIRED_BY_POLICY the *only* reason?
1204 if (extension_prefs_->GetDisableReasons(extension->id()) ==
1205 Extension::DISABLE_UPDATE_REQUIRED_BY_POLICY) {
1206 // We need to enable those disabled *only* due to minimum version
1207 // requirement.
1208 to_enable.push_back(extension->id());
1209 }
1210 extension_prefs_->RemoveDisableReason(
1211 extension->id(), Extension::DISABLE_UPDATE_REQUIRED_BY_POLICY);
1212 }
1213 }
1214
1215 for (const std::string& id : to_unload)
1216 UnloadExtension(id, UnloadedExtensionInfo::REASON_DISABLE);
[email protected]0d54b682013-11-05 14:15:361217
1218 for (std::map<std::string, Extension::DisableReason>::const_iterator i =
1219 to_disable.begin(); i != to_disable.end(); ++i)
1220 DisableExtension(i->first, i->second);
binjin8e3d0182014-12-04 16:44:281221
1222 // No extension is getting re-enabled here after disabling/unloading
1223 // because to_enable is mutually exclusive to to_disable + to_unload.
1224 for (const std::string& id : to_enable)
1225 EnableExtension(id);
1226
1227 if (updater_.get()) {
1228 // Find all extensions disabled due to minimum version requirement from
1229 // policy (including the ones that got disabled just now), and check
1230 // for update.
1231 extensions::ExtensionUpdater::CheckParams to_recheck;
1232 for (scoped_refptr<const Extension> extension :
1233 registry_->disabled_extensions()) {
1234 if (extension_prefs_->GetDisableReasons(extension->id()) ==
1235 Extension::DISABLE_UPDATE_REQUIRED_BY_POLICY) {
1236 // The minimum version check is the only thing holding this extension
1237 // back, so check if it can be updated to fix that.
1238 to_recheck.ids.push_back(extension->id());
1239 }
1240 }
1241 if (!to_recheck.ids.empty())
1242 updater_->CheckNow(to_recheck);
1243 }
[email protected]aa96d3a2010-08-21 08:45:251244}
1245
[email protected]31206602011-04-13 23:07:321246void ExtensionService::CheckForUpdatesSoon() {
[email protected]90878c52014-04-04 18:21:021247 // This can legitimately happen in unit tests.
1248 if (!updater_.get())
1249 return;
1250
[email protected]90878c52014-04-04 18:21:021251 updater_->CheckSoon();
[email protected]c3cfb012011-04-06 22:07:351252}
1253
[email protected]8e4560b62011-01-14 10:09:141254// Some extensions will autoupdate themselves externally from Chrome. These
rkaplowa8fd8d32015-02-25 21:27:561255// are typically part of some larger client application package. To support
1256// these, the extension will register its location in the preferences file
[email protected]8e4560b62011-01-14 10:09:141257// (and also, on Windows, in the registry) and this code will periodically
1258// check that location for a .crx file, which it will then install locally if
1259// a new version is available.
rkaplowa8fd8d32015-02-25 21:27:561260// Errors are reported through ExtensionErrorReporter. Success is not
[email protected]8e4560b62011-01-14 10:09:141261// reported.
[email protected]eaa7dd182010-12-14 11:09:001262void ExtensionService::CheckForExternalUpdates() {
[email protected]a29a517a2011-01-21 21:11:121263 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
rkaplowa8fd8d32015-02-25 21:27:561264 TRACE_EVENT0("browser,startup", "ExtensionService::CheckForExternalUpdates");
1265 SCOPED_UMA_HISTOGRAM_TIMER("Extensions.CheckForExternalUpdatesTime");
[email protected]8e4560b62011-01-14 10:09:141266
1267 // Note that this installation is intentionally silent (since it didn't
1268 // go through the front-end). Extensions that are registered in this
1269 // way are effectively considered 'pre-bundled', and so implicitly
1270 // trusted. In general, if something has HKLM or filesystem access,
1271 // they could install an extension manually themselves anyway.
[email protected]a29a517a2011-01-21 21:11:121272
[email protected]8e4560b62011-01-14 10:09:141273 // Ask each external extension provider to give us a call back for each
1274 // extension they know about. See OnExternalExtension(File|UpdateUrl)Found.
[email protected]5df038b2012-07-16 19:03:271275 extensions::ProviderCollection::const_iterator i;
[email protected]8e4560b62011-01-14 10:09:141276 for (i = external_extension_providers_.begin();
1277 i != external_extension_providers_.end(); ++i) {
[email protected]5df038b2012-07-16 19:03:271278 extensions::ExternalProviderInterface* provider = i->get();
[email protected]8e4560b62011-01-14 10:09:141279 provider->VisitRegisteredExtension();
1280 }
1281
[email protected]50067e52011-10-20 23:17:071282 // Do any required work that we would have done after completion of all
1283 // providers.
[email protected]373daf972014-04-10 01:50:441284 if (external_extension_providers_.empty())
[email protected]50067e52011-10-20 23:17:071285 OnAllExternalProvidersReady();
[email protected]9f1087e2009-06-15 17:29:321286}
1287
[email protected]50067e52011-10-20 23:17:071288void ExtensionService::OnExternalProviderReady(
[email protected]5df038b2012-07-16 19:03:271289 const extensions::ExternalProviderInterface* provider) {
[email protected]a29a517a2011-01-21 21:11:121290 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]50067e52011-10-20 23:17:071291 CHECK(provider->IsReady());
[email protected]a29a517a2011-01-21 21:11:121292
1293 // An external provider has finished loading. We only take action
[email protected]8e4560b62011-01-14 10:09:141294 // if all of them are finished. So we check them first.
[email protected]94fde232012-04-27 10:22:301295 if (AreAllExternalProvidersReady())
1296 OnAllExternalProvidersReady();
1297}
1298
1299bool ExtensionService::AreAllExternalProvidersReady() const {
[email protected]5df038b2012-07-16 19:03:271300 extensions::ProviderCollection::const_iterator i;
[email protected]8e4560b62011-01-14 10:09:141301 for (i = external_extension_providers_.begin();
1302 i != external_extension_providers_.end(); ++i) {
[email protected]94fde232012-04-27 10:22:301303 if (!i->get()->IsReady())
1304 return false;
[email protected]8e4560b62011-01-14 10:09:141305 }
[email protected]94fde232012-04-27 10:22:301306 return true;
[email protected]50067e52011-10-20 23:17:071307}
1308
1309void ExtensionService::OnAllExternalProvidersReady() {
1310 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]94fde232012-04-27 10:22:301311 base::TimeDelta elapsed = base::Time::Now() - profile_->GetStartTime();
1312 UMA_HISTOGRAM_TIMES("Extension.ExternalProvidersReadyAfter", elapsed);
[email protected]50067e52011-10-20 23:17:071313
1314 // Install any pending extensions.
[email protected]94fde232012-04-27 10:22:301315 if (update_once_all_providers_are_ready_ && updater()) {
1316 update_once_all_providers_are_ready_ = false;
[email protected]4e9b59d2013-12-18 06:47:141317 extensions::ExtensionUpdater::CheckParams params;
1318 params.callback = external_updates_finished_callback_;
1319 updater()->CheckNow(params);
[email protected]8e4560b62011-01-14 10:09:141320 }
1321
1322 // Uninstall all the unclaimed extensions.
[email protected]45759612012-07-10 17:21:231323 scoped_ptr<extensions::ExtensionPrefs::ExtensionsInfo> extensions_info(
[email protected]8e4560b62011-01-14 10:09:141324 extension_prefs_->GetInstalledExtensionsInfo());
1325 for (size_t i = 0; i < extensions_info->size(); ++i) {
1326 ExtensionInfo* info = extensions_info->at(i).get();
[email protected]1d5e58b2013-01-31 08:41:401327 if (Manifest::IsExternalLocation(info->extension_location))
[email protected]8e4560b62011-01-14 10:09:141328 CheckExternalUninstall(info->extension_id);
1329 }
[email protected]e5af875f2011-10-10 21:09:141330
[email protected]373daf972014-04-10 01:50:441331 error_controller_->ShowErrorIfNeeded();
[email protected]a9aa5932012-01-25 08:27:401332
[email protected]374ceb6f2014-07-02 19:25:341333 external_install_manager_->UpdateExternalExtensionAlert();
[email protected]e5af875f2011-10-10 21:09:141334}
1335
[email protected]a9f39a312010-12-23 22:14:271336void ExtensionService::UnloadExtension(
1337 const std::string& extension_id,
[email protected]b0af4792013-10-23 09:12:131338 UnloadedExtensionInfo::Reason reason) {
[email protected]27e469a2010-01-11 20:35:091339 // Make sure the extension gets deleted after we return from this function.
[email protected]599539802014-01-07 23:06:001340 int include_mask =
1341 ExtensionRegistry::EVERYTHING & ~ExtensionRegistry::TERMINATED;
[email protected]9adb9692010-10-29 23:14:021342 scoped_refptr<const Extension> extension(
[email protected]599539802014-01-07 23:06:001343 registry_->GetExtensionById(extension_id, include_mask));
[email protected]631cf822009-05-15 07:01:251344
[email protected]fa0c96732010-11-17 00:14:231345 // This method can be called via PostTask, so the extension may have been
1346 // unloaded by the time this runs.
[email protected]dc24976f2013-06-02 21:15:091347 if (!extension.get()) {
[email protected]dd163fb02011-05-04 22:22:171348 // In case the extension may have crashed/uninstalled. Allow the profile to
1349 // clean up its RequestContexts.
[email protected]31d8f5f22012-04-02 15:22:081350 system_->UnregisterExtensionWithRequestContexts(extension_id, reason);
[email protected]fa0c96732010-11-17 00:14:231351 return;
[email protected]dd163fb02011-05-04 22:22:171352 }
[email protected]0c6da502009-08-14 22:32:391353
[email protected]1eb175082010-02-10 09:26:161354 // Keep information about the extension so that we can reload it later
1355 // even if it's not permanently installed.
1356 unloaded_extension_paths_[extension->id()] = extension->path();
1357
[email protected]f17dbd42010-08-16 23:21:101358 // Clean up if the extension is meant to be enabled after a reload.
[email protected]b914e2952013-04-26 07:10:031359 reloading_extensions_.erase(extension->id());
[email protected]f17dbd42010-08-16 23:21:101360
[email protected]bb1bc9b32013-12-21 03:09:141361 if (registry_->disabled_extensions().Contains(extension->id())) {
1362 registry_->RemoveDisabled(extension->id());
[email protected]dd163fb02011-05-04 22:22:171363 // Make sure the profile cleans up its RequestContexts when an already
1364 // disabled extension is unloaded (since they are also tracking the disabled
1365 // extensions).
[email protected]31d8f5f22012-04-02 15:22:081366 system_->UnregisterExtensionWithRequestContexts(extension_id, reason);
[email protected]45f5b7d2014-01-22 23:47:131367 // Don't send the unloaded notification. It was sent when the extension
1368 // was disabled.
[email protected]60a174a2013-08-02 20:29:281369 } else {
[email protected]bb1bc9b32013-12-21 03:09:141370 // Remove the extension from the enabled list.
1371 registry_->RemoveEnabled(extension->id());
[email protected]60a174a2013-08-02 20:29:281372 NotifyExtensionUnloaded(extension.get(), reason);
[email protected]0c6da502009-08-14 22:32:391373 }
1374
[email protected]fb789532013-08-27 02:40:211375 content::NotificationService::current()->Notify(
[email protected]adf5a102014-07-31 12:44:061376 extensions::NOTIFICATION_EXTENSION_REMOVED,
[email protected]fb789532013-08-27 02:40:211377 content::Source<Profile>(profile_),
1378 content::Details<const Extension>(extension.get()));
[email protected]631cf822009-05-15 07:01:251379}
1380
[email protected]8b1ec202013-09-05 02:09:501381void ExtensionService::RemoveComponentExtension(
1382 const std::string& extension_id) {
1383 scoped_refptr<const Extension> extension(
1384 GetExtensionById(extension_id, false));
[email protected]b0af4792013-10-23 09:12:131385 UnloadExtension(extension_id, UnloadedExtensionInfo::REASON_UNINSTALL);
[email protected]ebe07772014-05-22 04:16:061386 if (extension.get()) {
[email protected]e43c61f2014-07-20 21:46:341387 ExtensionRegistry::Get(profile_)->TriggerOnUninstalled(
dtseng9fb3d5b2015-02-23 17:24:171388 extension.get(), extensions::UNINSTALL_REASON_COMPONENT_REMOVED);
[email protected]ebe07772014-05-22 04:16:061389 }
[email protected]8b1ec202013-09-05 02:09:501390}
1391
[email protected]bb1bc9b32013-12-21 03:09:141392void ExtensionService::UnloadAllExtensionsForTest() {
1393 UnloadAllExtensionsInternal();
[email protected]9f1087e2009-06-15 17:29:321394}
1395
[email protected]bb1bc9b32013-12-21 03:09:141396void ExtensionService::ReloadExtensionsForTest() {
1397 // Calling UnloadAllExtensionsForTest here triggers a false-positive presubmit
1398 // warning about calling test code in production.
1399 UnloadAllExtensionsInternal();
[email protected]eac88332012-12-26 17:57:451400 component_loader_->LoadAll();
[email protected]d8c8f25f2011-11-02 18:18:011401 extensions::InstalledLoader(this).LoadAllExtensions();
[email protected]4a10006a2013-05-17 23:18:351402 // Don't call SetReadyAndNotifyListeners() since tests call this multiple
1403 // times.
[email protected]9f1087e2009-06-15 17:29:321404}
1405
[email protected]820d9bd2013-04-03 03:46:031406void ExtensionService::SetReadyAndNotifyListeners() {
rkaplowa8fd8d32015-02-25 21:27:561407 TRACE_EVENT0("browser,startup",
1408 "ExtensionService::SetReadyAndNotifyListeners");
yiyaoliu252f915e2015-04-23 21:56:361409 TRACK_SCOPED_REGION(
1410 "Startup", "ExtensionService::SetReadyAndNotifyListeners");
rkaplowa8fd8d32015-02-25 21:27:561411 SCOPED_UMA_HISTOGRAM_TIMER(
1412 "Extensions.ExtensionServiceNotifyReadyListenersTime");
1413
[email protected]4a10006a2013-05-17 23:18:351414 ready_->Signal();
[email protected]820d9bd2013-04-03 03:46:031415 content::NotificationService::current()->Notify(
[email protected]adf5a102014-07-31 12:44:061416 extensions::NOTIFICATION_EXTENSIONS_READY_DEPRECATED,
[email protected]820d9bd2013-04-03 03:46:031417 content::Source<Profile>(profile_),
1418 content::NotificationService::NoDetails());
[email protected]820d9bd2013-04-03 03:46:031419}
1420
[email protected]eaa7dd182010-12-14 11:09:001421void ExtensionService::OnLoadedInstalledExtensions() {
[email protected]3eeddd892013-04-17 17:00:111422 if (updater_)
[email protected]93fd78f42009-07-10 16:43:171423 updater_->Start();
[email protected]fa6a9102010-11-22 15:38:501424
[email protected]bc151cf92013-02-12 04:57:261425 OnBlacklistUpdated();
[email protected]e72e8eb82009-06-18 17:21:511426}
1427
[email protected]fcb58a862012-05-01 01:03:151428void ExtensionService::AddExtension(const Extension* extension) {
[email protected]c8d407e2011-04-28 21:27:171429 // TODO(jstritar): We may be able to get rid of this branch by overriding the
1430 // default extension state to DISABLED when the --disable-extensions flag
1431 // is set (http://crbug.com/29067).
1432 if (!extensions_enabled() &&
1433 !extension->is_theme() &&
[email protected]1d5e58b2013-01-31 08:41:401434 extension->location() != Manifest::COMPONENT &&
1435 !Manifest::IsExternalLocation(extension->location())) {
[email protected]fcb58a862012-05-01 01:03:151436 return;
[email protected]330840c2012-08-29 22:21:011437 }
[email protected]c8d407e2011-04-28 21:27:171438
[email protected]b914e2952013-04-26 07:10:031439 bool is_extension_upgrade = false;
[email protected]116d40e2013-08-08 17:23:171440 bool is_extension_installed = false;
1441 const Extension* old = GetInstalledExtension(extension->id());
1442 if (old) {
1443 is_extension_installed = true;
1444 int version_compare_result =
1445 extension->version()->CompareTo(*(old->version()));
1446 is_extension_upgrade = version_compare_result > 0;
[email protected]b914e2952013-04-26 07:10:031447 // Other than for unpacked extensions, CrxInstaller should have guaranteed
1448 // that we aren't downgrading.
1449 if (!Manifest::IsUnpackedLocation(extension->location()))
[email protected]116d40e2013-08-08 17:23:171450 CHECK_GE(version_compare_result, 0);
[email protected]b914e2952013-04-26 07:10:031451 }
rdevlin.cronin2c16c602014-11-21 01:35:491452 // If the extension was disabled for a reload, then enable it.
1453 bool reloading = reloading_extensions_.erase(extension->id()) > 0;
1454
1455 // Set the upgraded bit; we consider reloads upgrades.
1456 system_->runtime_data()->SetBeingUpgraded(extension->id(),
1457 is_extension_upgrade || reloading);
[email protected]c8d407e2011-04-28 21:27:171458
[email protected]1eb175082010-02-10 09:26:161459 // The extension is now loaded, remove its data from unloaded extension map.
1460 unloaded_extension_paths_.erase(extension->id());
1461
[email protected]bb7f40952011-01-13 00:21:201462 // If a terminated extension is loaded, remove it from the terminated list.
1463 UntrackTerminatedExtension(extension->id());
1464
[email protected]b914e2952013-04-26 07:10:031465 // Check if the extension's privileges have changed and mark the
1466 // extension disabled if necessary.
[email protected]116d40e2013-08-08 17:23:171467 CheckPermissionsIncrease(extension, is_extension_installed);
[email protected]b914e2952013-04-26 07:10:031468
[email protected]116d40e2013-08-08 17:23:171469 if (is_extension_installed && !reloading) {
[email protected]ca2e82022013-04-29 16:48:411470 // To upgrade an extension in place, unload the old one and then load the
1471 // new one. ReloadExtension disables the extension, which is sufficient.
[email protected]b0af4792013-10-23 09:12:131472 UnloadExtension(extension->id(), UnloadedExtensionInfo::REASON_UPDATE);
[email protected]b914e2952013-04-26 07:10:031473 }
[email protected]0c6da502009-08-14 22:32:391474
[email protected]695b5712012-12-06 23:55:281475 if (extension_prefs_->IsExtensionBlacklisted(extension->id())) {
[email protected]ac875372013-02-28 04:36:091476 // Only prefs is checked for the blacklist. We rely on callers to check the
1477 // blacklist before calling into here, e.g. CrxInstaller checks before
[email protected]9f3c8532013-07-31 19:52:071478 // installation then threads through the install and pending install flow
1479 // of this class, and we check when loading installed extensions.
[email protected]bb1bc9b32013-12-21 03:09:141480 registry_->AddBlacklisted(extension);
mlerman6a37b6a42014-11-26 22:10:531481 } else if (block_extensions_ && CanBlockExtension(extension)) {
1482 registry_->AddBlocked(extension);
[email protected]ca2e82022013-04-29 16:48:411483 } else if (!reloading &&
1484 extension_prefs_->IsExtensionDisabled(extension->id())) {
[email protected]bb1bc9b32013-12-21 03:09:141485 registry_->AddDisabled(extension);
[email protected]44d62b62012-04-11 00:06:031486 content::NotificationService::current()->Notify(
[email protected]adf5a102014-07-31 12:44:061487 extensions::NOTIFICATION_EXTENSION_UPDATE_DISABLED,
[email protected]44d62b62012-04-11 00:06:031488 content::Source<Profile>(profile_),
1489 content::Details<const Extension>(extension));
[email protected]62f051c2012-03-29 17:04:441490
[email protected]21db9ef2014-05-16 02:06:271491 // Show the extension disabled error if a permissions increase or a remote
1492 // installation is the reason it was disabled, and no other reasons exist.
1493 int reasons = extension_prefs_->GetDisableReasons(extension->id());
1494 const int kReasonMask = Extension::DISABLE_PERMISSIONS_INCREASE |
1495 Extension::DISABLE_REMOTE_INSTALL;
1496 if (reasons & kReasonMask && !(reasons & ~kReasonMask)) {
1497 extensions::AddExtensionDisabledError(
1498 this,
1499 extension,
1500 extension_prefs_->HasDisableReason(
1501 extension->id(), Extension::DISABLE_REMOTE_INSTALL));
[email protected]62f051c2012-03-29 17:04:441502 }
[email protected]ca2e82022013-04-29 16:48:411503 } else if (reloading) {
1504 // Replace the old extension with the new version.
[email protected]bb1bc9b32013-12-21 03:09:141505 CHECK(!registry_->AddDisabled(extension));
[email protected]ca2e82022013-04-29 16:48:411506 EnableExtension(extension->id());
[email protected]695b5712012-12-06 23:55:281507 } else {
1508 // All apps that are displayed in the launcher are ordered by their ordinals
1509 // so we must ensure they have valid ordinals.
1510 if (extension->RequiresSortOrdinal()) {
[email protected]db378322014-07-21 23:19:341511 extension_prefs_->app_sorting()->SetExtensionVisible(
1512 extension->id(),
1513 extension->ShouldDisplayInNewTabPage() &&
1514 !extension_prefs_->IsEphemeralApp(extension->id()));
1515 if (!extension_prefs_->IsEphemeralApp(extension->id())) {
1516 extension_prefs_->app_sorting()->EnsureValidOrdinals(
1517 extension->id(), syncer::StringOrdinal());
[email protected]bd36b652013-02-27 02:13:251518 }
[email protected]695b5712012-12-06 23:55:281519 }
1520
[email protected]bb1bc9b32013-12-21 03:09:141521 registry_->AddEnabled(extension);
[email protected]695b5712012-12-06 23:55:281522 NotifyExtensionLoaded(extension);
[email protected]f574c402012-12-04 23:20:311523 }
rdevlin.cronin2c16c602014-11-21 01:35:491524 system_->runtime_data()->SetBeingUpgraded(extension->id(), false);
[email protected]aab98a52009-12-02 03:22:351525}
1526
[email protected]8c484b742012-11-29 06:05:361527void ExtensionService::AddComponentExtension(const Extension* extension) {
1528 const std::string old_version_string(
1529 extension_prefs_->GetVersionString(extension->id()));
thakis37be69c2015-08-19 03:26:571530 const Version old_version(old_version_string);
[email protected]8c484b742012-11-29 06:05:361531
[email protected]0181a7d2013-11-12 01:08:421532 VLOG(1) << "AddComponentExtension " << extension->name();
[email protected]8c484b742012-11-29 06:05:361533 if (!old_version.IsValid() || !old_version.Equals(*extension->version())) {
1534 VLOG(1) << "Component extension " << extension->name() << " ("
1535 << extension->id() << ") installing/upgrading from '"
1536 << old_version_string << "' to " << extension->version()->GetString();
1537
1538 AddNewOrUpdatedExtension(extension,
[email protected]9ae73962014-08-14 16:53:411539 Extension::ENABLED,
[email protected]4a1d9c0d2014-06-13 12:50:111540 extensions::kInstallFlagNone,
[email protected]d8fd0fd2014-03-24 13:16:061541 syncer::StringOrdinal(),
1542 std::string());
[email protected]8c484b742012-11-29 06:05:361543 return;
1544 }
1545
1546 AddExtension(extension);
1547}
1548
[email protected]b914e2952013-04-26 07:10:031549void ExtensionService::CheckPermissionsIncrease(const Extension* extension,
[email protected]116d40e2013-08-08 17:23:171550 bool is_extension_installed) {
[email protected]23a85362014-07-07 23:26:191551 extensions::PermissionsUpdater(profile_).InitializePermissions(extension);
[email protected]902fd7b2011-07-27 18:42:311552
[email protected]8d888c12010-11-30 00:00:251553 // We keep track of all permissions the user has granted each extension.
1554 // This allows extensions to gracefully support backwards compatibility
1555 // by including unknown permissions in their manifests. When the user
1556 // installs the extension, only the recognized permissions are recorded.
1557 // When the unknown permissions become recognized (e.g., through browser
1558 // upgrade), we can prompt the user to accept these new permissions.
1559 // Extensions can also silently upgrade to less permissions, and then
1560 // silently upgrade to a version that adds these permissions back.
1561 //
1562 // For example, pretend that Chrome 10 includes a permission "omnibox"
1563 // for an API that adds suggestions to the omnibox. An extension can
1564 // maintain backwards compatibility while still having "omnibox" in the
1565 // manifest. If a user installs the extension on Chrome 9, the browser
1566 // will record the permissions it recognized, not including "omnibox."
1567 // When upgrading to Chrome 10, "omnibox" will be recognized and Chrome
1568 // will disable the extension and prompt the user to approve the increase
1569 // in privileges. The extension could then release a new version that
1570 // removes the "omnibox" permission. When the user upgrades, Chrome will
1571 // still remember that "omnibox" had been granted, so that if the
1572 // extension once again includes "omnibox" in an upgrade, the extension
1573 // can upgrade without requiring this user's approval.
[email protected]eb5e4f92012-08-15 23:33:281574 int disable_reasons = extension_prefs_->GetDisableReasons(extension->id());
[email protected]8d888c12010-11-30 00:00:251575
rockot1d4a06262015-02-17 19:39:281576 // Silently grant all active permissions to default apps and apps installed
1577 // in kiosk mode.
[email protected]211a3f32013-05-28 21:48:181578 bool auto_grant_permission =
rockot1d4a06262015-02-17 19:39:281579 extension->was_installed_by_default() ||
[email protected]45928b682013-11-28 08:20:271580 extensions::ExtensionsBrowserClient::Get()->IsRunningInForcedAppMode();
[email protected]211a3f32013-05-28 21:48:181581 if (auto_grant_permission)
[email protected]b914e2952013-04-26 07:10:031582 GrantPermissions(extension);
1583
1584 bool is_privilege_increase = false;
1585 // We only need to compare the granted permissions to the current permissions
rockot1d4a06262015-02-17 19:39:281586 // if the extension has not been auto-granted its permissions above and is
1587 // installed internally.
1588 if (extension->location() == Manifest::INTERNAL && !auto_grant_permission) {
[email protected]8d888c12010-11-30 00:00:251589 // Add all the recognized permissions if the granted permissions list
1590 // hasn't been initialized yet.
rdevlin.cronine2d0fd02015-09-24 22:35:491591 scoped_ptr<const PermissionSet> granted_permissions =
[email protected]902fd7b2011-07-27 18:42:311592 extension_prefs_->GetGrantedPermissions(extension->id());
[email protected]0d3e4a22011-06-23 19:02:521593 CHECK(granted_permissions.get());
[email protected]8d888c12010-11-30 00:00:251594
1595 // Here, we check if an extension's privileges have increased in a manner
1596 // that requires the user's approval. This could occur because the browser
1597 // upgraded and recognized additional privileges, or an extension upgrades
1598 // to a version that requires additional privileges.
[email protected]c41003472013-10-19 15:37:251599 is_privilege_increase =
1600 extensions::PermissionMessageProvider::Get()->IsPrivilegeIncrease(
rdevlin.cronind630c302015-09-30 20:19:331601 *granted_permissions,
rdevlin.cronine2d0fd02015-09-24 22:35:491602 extension->permissions_data()->active_permissions(),
[email protected]076ebeda2014-06-06 21:47:261603 extension->GetType());
[email protected]8d888c12010-11-30 00:00:251604 }
1605
[email protected]116d40e2013-08-08 17:23:171606 if (is_extension_installed) {
[email protected]44d62b62012-04-11 00:06:031607 // If the extension was already disabled, suppress any alerts for becoming
1608 // disabled on permissions increase.
[email protected]b914e2952013-04-26 07:10:031609 bool previously_disabled =
1610 extension_prefs_->IsExtensionDisabled(extension->id());
treib8a6d9892015-08-26 10:23:191611 // Legacy disabled extensions do not have a disable reason. Infer that it
1612 // was likely disabled by the user.
1613 if (previously_disabled && disable_reasons == Extension::DISABLE_NONE)
[email protected]7e9e2422012-12-13 19:54:191614 disable_reasons |= Extension::DISABLE_USER_ACTION;
treib8a6d9892015-08-26 10:23:191615
[email protected]7e9e2422012-12-13 19:54:191616 // Extensions that came to us disabled from sync need a similar inference,
1617 // except based on the new version's permissions.
1618 if (previously_disabled &&
treib8a6d9892015-08-26 10:23:191619 (disable_reasons & Extension::DISABLE_UNKNOWN_FROM_SYNC)) {
[email protected]7e9e2422012-12-13 19:54:191620 // Remove the DISABLE_UNKNOWN_FROM_SYNC reason.
treib8a6d9892015-08-26 10:23:191621 disable_reasons &= ~Extension::DISABLE_UNKNOWN_FROM_SYNC;
1622 extension_prefs_->RemoveDisableReason(
1623 extension->id(), Extension::DISABLE_UNKNOWN_FROM_SYNC);
1624 // If there was no privilege increase, it was likely disabled by the user.
[email protected]7e9e2422012-12-13 19:54:191625 if (!is_privilege_increase)
1626 disable_reasons |= Extension::DISABLE_USER_ACTION;
1627 }
[email protected]8d888c12010-11-30 00:00:251628 }
1629
1630 // Extension has changed permissions significantly. Disable it. A
[email protected]21db9ef2014-05-16 02:06:271631 // notification should be sent by the caller. If the extension is already
1632 // disabled because it was installed remotely, don't add another disable
treibaac30ec2015-06-10 09:18:091633 // reason.
1634 if (is_privilege_increase &&
treib8a6d9892015-08-26 10:23:191635 !(disable_reasons & Extension::DISABLE_REMOTE_INSTALL)) {
[email protected]7e9e2422012-12-13 19:54:191636 disable_reasons |= Extension::DISABLE_PERMISSIONS_INCREASE;
treib8a6d9892015-08-26 10:23:191637 if (!extension_prefs_->DidExtensionEscalatePermissions(extension->id()))
treib2e0517f92015-05-07 23:15:361638 RecordPermissionMessagesHistogram(extension, "AutoDisable");
treib8ecc1eb52015-03-04 18:29:061639
1640#if defined(ENABLE_SUPERVISED_USERS)
1641 // If a custodian-installed extension is disabled for a supervised user due
treib3202d592015-07-31 08:33:161642 // to a permissions increase, send a request to the custodian if the
treibf832a992015-03-24 18:09:241643 // supervised user themselves can't re-enable the extension.
treib3202d592015-07-31 08:33:161644 if (extensions::util::IsExtensionSupervised(extension, profile_) &&
treib40d3ad92015-10-20 18:15:421645 extensions::util::NeedCustodianApprovalForPermissionIncrease() &&
1646 !ExtensionSyncService::Get(profile_)->HasPendingReenable(
1647 extension->id(), *extension->version())) {
treib8ecc1eb52015-03-04 18:29:061648 SupervisedUserService* supervised_user_service =
1649 SupervisedUserServiceFactory::GetForProfile(profile_);
treib40d3ad92015-10-20 18:15:421650 supervised_user_service->AddExtensionUpdateRequest(extension->id(),
1651 *extension->version());
treib8ecc1eb52015-03-04 18:29:061652 }
1653#endif
[email protected]b914e2952013-04-26 07:10:031654 }
treib0c714f7c2015-07-08 10:04:581655 if (disable_reasons != Extension::DISABLE_NONE)
treib8a6d9892015-08-26 10:23:191656 extension_prefs_->SetExtensionDisabled(extension->id(), disable_reasons);
[email protected]8d888c12010-11-30 00:00:251657}
1658
[email protected]eaa7dd182010-12-14 11:09:001659void ExtensionService::UpdateActiveExtensionsInCrashReporter() {
[email protected]c8865962009-12-16 07:47:391660 std::set<std::string> extension_ids;
[email protected]bb1bc9b32013-12-21 03:09:141661 const ExtensionSet& extensions = registry_->enabled_extensions();
1662 for (ExtensionSet::const_iterator iter = extensions.begin();
1663 iter != extensions.end(); ++iter) {
[email protected]cadac622013-06-11 16:46:361664 const Extension* extension = iter->get();
[email protected]1d5e58b2013-01-31 08:41:401665 if (!extension->is_theme() && extension->location() != Manifest::COMPONENT)
[email protected]84df8332011-12-06 18:22:461666 extension_ids.insert(extension->id());
[email protected]aab98a52009-12-02 03:22:351667 }
1668
[email protected]dcc47642014-03-26 22:03:491669 // TODO(kalman): This is broken. ExtensionService is per-profile.
1670 // crash_keys::SetActiveExtensions is per-process. See
1671 // http://crbug.com/355029.
[email protected]f6431be82013-09-07 02:53:451672 crash_keys::SetActiveExtensions(extension_ids);
[email protected]6014d672008-12-05 00:38:251673}
1674
[email protected]8266d662011-07-12 21:53:261675void ExtensionService::OnExtensionInstalled(
[email protected]36a5c4c2011-12-14 16:34:501676 const Extension* extension,
[email protected]98270432012-09-11 20:51:241677 const syncer::StringOrdinal& page_ordinal,
[email protected]4a1d9c0d2014-06-13 12:50:111678 int install_flags) {
[email protected]a29a517a2011-01-21 21:11:121679 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]a8af9fdb2010-10-28 21:52:201680
[email protected]c3cfb012011-04-06 22:07:351681 const std::string& id = extension->id();
binjin47947f842014-11-18 12:10:241682 int disable_reasons = GetDisableReasonsOnInstalled(extension);
[email protected]d8fd0fd2014-03-24 13:16:061683 std::string install_parameter;
[email protected]96aebe22014-07-16 04:07:511684 const extensions::PendingExtensionInfo* pending_extension_info =
1685 pending_extension_manager()->GetById(id);
1686 if (pending_extension_info) {
[email protected]8f3bcbd2013-06-05 08:42:401687 if (!pending_extension_info->ShouldAllowInstall(extension)) {
[email protected]51a3bf8b2012-06-08 22:53:061688 pending_extension_manager()->Remove(id);
[email protected]8ef78fd2010-08-19 17:14:321689
[email protected]31bb5ee62012-09-12 22:58:401690 LOG(WARNING) << "ShouldAllowInstall() returned false for "
1691 << id << " of type " << extension->GetType()
[email protected]65348062013-01-15 07:27:221692 << " and update URL "
1693 << extensions::ManifestURL::GetUpdateURL(extension).spec()
[email protected]31bb5ee62012-09-12 22:58:401694 << "; not installing";
[email protected]ae6cb3022011-04-04 20:11:541695
[email protected]4416c5a2010-06-26 01:28:571696 // Delete the extension directory since we're not going to
1697 // load it.
[email protected]7f8f24f2012-11-15 19:40:141698 if (!GetFileTaskRunner()->PostTask(
1699 FROM_HERE,
[email protected]85df9d12014-04-15 17:02:141700 base::Bind(&extensions::file_util::DeleteFile,
1701 extension->path(),
1702 true))) {
[email protected]14908b72011-04-20 06:54:361703 NOTREACHED();
[email protected]31bb5ee62012-09-12 22:58:401704 }
[email protected]4416c5a2010-06-26 01:28:571705 return;
1706 }
[email protected]51a3bf8b2012-06-08 22:53:061707
[email protected]d8fd0fd2014-03-24 13:16:061708 install_parameter = pending_extension_info->install_parameter();
[email protected]51a3bf8b2012-06-08 22:53:061709 pending_extension_manager()->Remove(id);
[email protected]4416c5a2010-06-26 01:28:571710 } else {
[email protected]c3cfb012011-04-06 22:07:351711 // We explicitly want to re-enable an uninstalled external
1712 // extension; if we're here, that means the user is manually
1713 // installing the extension.
[email protected]46f3e102014-03-25 01:22:451714 if (extension_prefs_->IsExternalExtensionUninstalled(id)) {
binjin47947f842014-11-18 12:10:241715 disable_reasons = Extension::DISABLE_NONE;
[email protected]6cc7dbae2011-04-29 21:18:331716 }
[email protected]aa142702010-03-26 01:26:331717 }
1718
[email protected]98270432012-09-11 20:51:241719 // Unsupported requirements overrides the management policy.
[email protected]4a1d9c0d2014-06-13 12:50:111720 if (install_flags & extensions::kInstallFlagHasRequirementErrors) {
binjin47947f842014-11-18 12:10:241721 disable_reasons |= Extension::DISABLE_UNSUPPORTED_REQUIREMENT;
binjin8e3d0182014-12-04 16:44:281722 } else {
1723 // Requirement is supported now, remove the corresponding disable reason
1724 // instead.
binjin8e3d0182014-12-04 16:44:281725 disable_reasons &= ~Extension::DISABLE_UNSUPPORTED_REQUIREMENT;
1726 }
1727
1728 // Check if the extension was disabled because of the minimum version
1729 // requirements from enterprise policy, and satisfies it now.
1730 if (extensions::ExtensionManagementFactory::GetForBrowserContext(profile())
1731 ->CheckMinimumVersion(extension, nullptr)) {
1732 // And remove the corresponding disable reason.
binjin8e3d0182014-12-04 16:44:281733 disable_reasons &= ~Extension::DISABLE_UPDATE_REQUIRED_BY_POLICY;
[email protected]98270432012-09-11 20:51:241734 }
1735
[email protected]4a1d9c0d2014-06-13 12:50:111736 if (install_flags & extensions::kInstallFlagIsBlacklistedForMalware) {
[email protected]9f3c8532013-07-31 19:52:071737 // Installation of a blacklisted extension can happen from sync, policy,
1738 // etc, where to maintain consistency we need to install it, just never
1739 // load it (see AddExtension). Usually it should be the job of callers to
treibaac30ec2015-06-10 09:18:091740 // intercept blacklisted extensions earlier (e.g. CrxInstaller, before even
[email protected]9f3c8532013-07-31 19:52:071741 // showing the install dialogue).
[email protected]7c82539c2014-02-19 06:09:171742 extension_prefs_->AcknowledgeBlacklistedExtension(id);
[email protected]9f3c8532013-07-31 19:52:071743 UMA_HISTOGRAM_ENUMERATION("ExtensionBlacklist.SilentInstall",
1744 extension->location(),
1745 Manifest::NUM_LOCATIONS);
1746 }
1747
[email protected]695b5712012-12-06 23:55:281748 if (!GetInstalledExtension(extension->id())) {
[email protected]07533022011-06-27 20:42:551749 UMA_HISTOGRAM_ENUMERATION("Extensions.InstallType",
1750 extension->GetType(), 100);
[email protected]69084dc2012-11-17 07:39:301751 UMA_HISTOGRAM_ENUMERATION("Extensions.InstallSource",
[email protected]1d5e58b2013-01-31 08:41:401752 extension->location(), Manifest::NUM_LOCATIONS);
treib2e0517f92015-05-07 23:15:361753 RecordPermissionMessagesHistogram(extension, "Install");
[email protected]69084dc2012-11-17 07:39:301754 } else {
1755 UMA_HISTOGRAM_ENUMERATION("Extensions.UpdateType",
1756 extension->GetType(), 100);
1757 UMA_HISTOGRAM_ENUMERATION("Extensions.UpdateSource",
[email protected]1d5e58b2013-01-31 08:41:401758 extension->location(), Manifest::NUM_LOCATIONS);
[email protected]8f959f522014-08-06 06:26:281759
1760 // A fully installed app cannot be demoted to an ephemeral app.
1761 if ((install_flags & extensions::kInstallFlagIsEphemeral) &&
1762 !extension_prefs_->IsEphemeralApp(id)) {
1763 install_flags &= ~static_cast<int>(extensions::kInstallFlagIsEphemeral);
1764 }
[email protected]07533022011-06-27 20:42:551765 }
1766
[email protected]399583b2012-12-11 09:33:421767 const Extension::State initial_state =
binjin47947f842014-11-18 12:10:241768 disable_reasons == Extension::DISABLE_NONE ? Extension::ENABLED
1769 : Extension::DISABLED;
treib8a6d9892015-08-26 10:23:191770 if (initial_state == Extension::ENABLED)
1771 extension_prefs_->SetExtensionEnabled(id);
1772 else
1773 extension_prefs_->SetExtensionDisabled(id, disable_reasons);
binjin47947f842014-11-18 12:10:241774
[email protected]4a1d9c0d2014-06-13 12:50:111775 if (ShouldDelayExtensionUpdate(
1776 id,
1777 !!(install_flags & extensions::kInstallFlagInstallImmediately))) {
[email protected]9f3c8532013-07-31 19:52:071778 extension_prefs_->SetDelayedInstallInfo(
1779 extension,
1780 initial_state,
[email protected]4a1d9c0d2014-06-13 12:50:111781 install_flags,
[email protected]9f3c8532013-07-31 19:52:071782 extensions::ExtensionPrefs::DELAY_REASON_WAIT_FOR_IDLE,
[email protected]d8fd0fd2014-03-24 13:16:061783 page_ordinal,
1784 install_parameter);
[email protected]0db124b02012-11-07 04:55:051785
1786 // Transfer ownership of |extension|.
[email protected]9f4e4f082013-06-21 07:11:191787 delayed_installs_.Insert(extension);
[email protected]0db124b02012-11-07 04:55:051788
[email protected]75bdcb872013-03-13 00:41:451789 // Notify observers that app update is available.
1790 FOR_EACH_OBSERVER(extensions::UpdateObserver, update_observers_,
[email protected]a9aa62b312013-11-29 05:35:061791 OnAppUpdateAvailable(extension));
[email protected]0db124b02012-11-07 04:55:051792 return;
1793 }
1794
[email protected]90878c52014-04-04 18:21:021795 extensions::SharedModuleService::ImportStatus status =
1796 shared_module_service_->SatisfyImports(extension);
[email protected]e5f8fffe2014-04-02 00:30:441797 if (installs_delayed_for_gc_) {
[email protected]9f3c8532013-07-31 19:52:071798 extension_prefs_->SetDelayedInstallInfo(
1799 extension,
1800 initial_state,
[email protected]4a1d9c0d2014-06-13 12:50:111801 install_flags,
[email protected]9f3c8532013-07-31 19:52:071802 extensions::ExtensionPrefs::DELAY_REASON_GC,
[email protected]d8fd0fd2014-03-24 13:16:061803 page_ordinal,
1804 install_parameter);
[email protected]399583b2012-12-11 09:33:421805 delayed_installs_.Insert(extension);
[email protected]90878c52014-04-04 18:21:021806 } else if (status != SharedModuleService::IMPORT_STATUS_OK) {
1807 if (status == SharedModuleService::IMPORT_STATUS_UNSATISFIED) {
[email protected]9f3c8532013-07-31 19:52:071808 extension_prefs_->SetDelayedInstallInfo(
1809 extension,
1810 initial_state,
[email protected]4a1d9c0d2014-06-13 12:50:111811 install_flags,
[email protected]9f4e4f082013-06-21 07:11:191812 extensions::ExtensionPrefs::DELAY_REASON_WAIT_FOR_IMPORTS,
[email protected]d8fd0fd2014-03-24 13:16:061813 page_ordinal,
1814 install_parameter);
[email protected]9f4e4f082013-06-21 07:11:191815 delayed_installs_.Insert(extension);
1816 }
[email protected]399583b2012-12-11 09:33:421817 } else {
[email protected]9f3c8532013-07-31 19:52:071818 AddNewOrUpdatedExtension(extension,
1819 initial_state,
[email protected]4a1d9c0d2014-06-13 12:50:111820 install_flags,
[email protected]d8fd0fd2014-03-24 13:16:061821 page_ordinal,
1822 install_parameter);
[email protected]399583b2012-12-11 09:33:421823 }
[email protected]8c484b742012-11-29 06:05:361824}
1825
binjin1569c9b2014-09-05 13:33:181826void ExtensionService::OnExtensionManagementSettingsChanged() {
1827 error_controller_->ShowErrorIfNeeded();
binjine6b58b52014-10-31 01:55:571828
1829 // Revokes blocked permissions from active_permissions for all extensions.
1830 extensions::ExtensionManagement* settings =
1831 extensions::ExtensionManagementFactory::GetForBrowserContext(profile());
1832 CHECK(settings);
1833 scoped_ptr<ExtensionSet> all_extensions(
1834 registry_->GenerateInstalledExtensionsSet());
1835 for (const auto& extension : *all_extensions.get()) {
1836 if (!settings->IsPermissionSetAllowed(
binjin685ade82014-11-06 09:53:561837 extension.get(),
rdevlin.cronind630c302015-09-30 20:19:331838 extension->permissions_data()->active_permissions())) {
rdevlin.cronin77cb0ef2015-09-16 17:03:481839 extensions::PermissionsUpdater(profile()).RemovePermissionsUnsafe(
rdevlin.cronind630c302015-09-30 20:19:331840 extension.get(), *settings->GetBlockedPermissions(extension.get()));
binjine6b58b52014-10-31 01:55:571841 }
1842 }
1843
binjin1569c9b2014-09-05 13:33:181844 CheckManagementPolicy();
1845}
1846
[email protected]8c484b742012-11-29 06:05:361847void ExtensionService::AddNewOrUpdatedExtension(
1848 const Extension* extension,
[email protected]399583b2012-12-11 09:33:421849 Extension::State initial_state,
[email protected]4a1d9c0d2014-06-13 12:50:111850 int install_flags,
[email protected]d8fd0fd2014-03-24 13:16:061851 const syncer::StringOrdinal& page_ordinal,
1852 const std::string& install_parameter) {
[email protected]8c484b742012-11-29 06:05:361853 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]760f743b2014-05-28 13:52:021854 bool was_ephemeral = extension_prefs_->IsEphemeralApp(extension->id());
[email protected]4a1d9c0d2014-06-13 12:50:111855 extension_prefs_->OnExtensionInstalled(
1856 extension, initial_state, page_ordinal, install_flags, install_parameter);
[email protected]9e9c1d12013-07-31 01:58:121857 delayed_installs_.Remove(extension->id());
[email protected]913ffca92014-03-27 15:26:161858 if (InstallVerifier::NeedsVerification(*extension))
juncai33e462102015-05-18 20:48:441859 InstallVerifier::Get(GetBrowserContext())->VerifyExtension(extension->id());
ryanackley48bedbd2015-01-27 23:12:141860
1861 const Extension* old = GetInstalledExtension(extension->id());
1862 if (extensions::AppDataMigrator::NeedsMigration(old, extension)) {
1863 app_data_migrator_->DoMigrationAndReply(
1864 old, extension,
1865 base::Bind(&ExtensionService::FinishInstallation, AsWeakPtr(),
1866 make_scoped_refptr(extension), was_ephemeral));
1867 return;
1868 }
1869
[email protected]760f743b2014-05-28 13:52:021870 FinishInstallation(extension, was_ephemeral);
[email protected]6f6101832012-11-27 22:10:481871}
1872
1873void ExtensionService::MaybeFinishDelayedInstallation(
1874 const std::string& extension_id) {
[email protected]9f4e4f082013-06-21 07:11:191875 // Check if the extension already got installed.
1876 if (!delayed_installs_.Contains(extension_id))
[email protected]6f6101832012-11-27 22:10:481877 return;
[email protected]9f4e4f082013-06-21 07:11:191878 extensions::ExtensionPrefs::DelayReason reason =
1879 extension_prefs_->GetDelayedInstallReason(extension_id);
1880
1881 // Check if the extension is idle. DELAY_REASON_NONE is used for older
1882 // preferences files that will not have set this field but it was previously
1883 // only used for idle updates.
1884 if ((reason == extensions::ExtensionPrefs::DELAY_REASON_WAIT_FOR_IDLE ||
1885 reason == extensions::ExtensionPrefs::DELAY_REASON_NONE) &&
[email protected]1d5cf4142014-01-24 18:25:221886 is_ready() && !extensions::util::IsExtensionIdle(extension_id, profile_))
[email protected]6f6101832012-11-27 22:10:481887 return;
1888
[email protected]9f4e4f082013-06-21 07:11:191889 const Extension* extension = delayed_installs_.GetByID(extension_id);
1890 if (reason == extensions::ExtensionPrefs::DELAY_REASON_WAIT_FOR_IMPORTS) {
[email protected]90878c52014-04-04 18:21:021891 extensions::SharedModuleService::ImportStatus status =
1892 shared_module_service_->SatisfyImports(extension);
1893 if (status != SharedModuleService::IMPORT_STATUS_OK) {
1894 if (status == SharedModuleService::IMPORT_STATUS_UNRECOVERABLE) {
[email protected]9f4e4f082013-06-21 07:11:191895 delayed_installs_.Remove(extension_id);
1896 // Make sure no version of the extension is actually installed, (i.e.,
1897 // that this delayed install was not an update).
1898 CHECK(!extension_prefs_->GetInstalledExtensionInfo(extension_id).get());
1899 extension_prefs_->DeleteExtensionPrefs(extension_id);
1900 }
1901 return;
1902 }
1903 }
1904
[email protected]6f6101832012-11-27 22:10:481905 FinishDelayedInstallation(extension_id);
1906}
1907
1908void ExtensionService::FinishDelayedInstallation(
1909 const std::string& extension_id) {
1910 scoped_refptr<const Extension> extension(
1911 GetPendingExtensionUpdate(extension_id));
[email protected]dc24976f2013-06-02 21:15:091912 CHECK(extension.get());
[email protected]9f4e4f082013-06-21 07:11:191913 delayed_installs_.Remove(extension_id);
[email protected]6f6101832012-11-27 22:10:481914
[email protected]760f743b2014-05-28 13:52:021915 bool was_ephemeral = extension_prefs_->IsEphemeralApp(extension->id());
[email protected]399583b2012-12-11 09:33:421916 if (!extension_prefs_->FinishDelayedInstallInfo(extension_id))
[email protected]6f6101832012-11-27 22:10:481917 NOTREACHED();
1918
[email protected]760f743b2014-05-28 13:52:021919 FinishInstallation(extension.get(), was_ephemeral);
[email protected]6f6101832012-11-27 22:10:481920}
1921
[email protected]760f743b2014-05-28 13:52:021922void ExtensionService::FinishInstallation(
1923 const Extension* extension, bool was_ephemeral) {
[email protected]e7554c3f2013-05-29 00:36:561924 const extensions::Extension* existing_extension =
1925 GetInstalledExtension(extension->id());
1926 bool is_update = false;
1927 std::string old_name;
1928 if (existing_extension) {
1929 is_update = true;
1930 old_name = existing_extension->name();
1931 }
[email protected]760f743b2014-05-28 13:52:021932 bool from_ephemeral =
1933 was_ephemeral && !extension_prefs_->IsEphemeralApp(extension->id());
1934 extensions::InstalledExtensionInfo details(
1935 extension, is_update, from_ephemeral, old_name);
[email protected]fcb58a862012-05-01 01:03:151936 content::NotificationService::current()->Notify(
[email protected]adf5a102014-07-31 12:44:061937 extensions::NOTIFICATION_EXTENSION_WILL_BE_INSTALLED_DEPRECATED,
[email protected]fcb58a862012-05-01 01:03:151938 content::Source<Profile>(profile_),
[email protected]41bb80bd2013-05-03 10:56:021939 content::Details<const extensions::InstalledExtensionInfo>(&details));
[email protected]fcb58a862012-05-01 01:03:151940
[email protected]bc44b5da2014-06-12 14:20:001941 registry_->TriggerOnWillBeInstalled(
[email protected]760f743b2014-05-28 13:52:021942 extension, is_update, from_ephemeral, old_name);
[email protected]17f07822014-05-22 08:45:151943
[email protected]399583b2012-12-11 09:33:421944 // Unpacked extensions default to allowing file access, but if that has been
1945 // overridden, don't reset the value.
[email protected]1d5e58b2013-01-31 08:41:401946 if (Manifest::ShouldAlwaysAllowFileAccess(extension->location()) &&
[email protected]399583b2012-12-11 09:33:421947 !extension_prefs_->HasAllowFileAccessSetting(extension->id())) {
1948 extension_prefs_->SetAllowFileAccess(extension->id(), true);
1949 }
1950
[email protected]6f6101832012-11-27 22:10:481951 AddExtension(extension);
[email protected]612a1cb12012-10-17 13:18:031952
[email protected]bc44b5da2014-06-12 14:20:001953 // Notify observers that need to know when an installation is complete.
[email protected]38e872532014-07-16 23:27:511954 registry_->TriggerOnInstalled(extension, is_update);
[email protected]bc44b5da2014-06-12 14:20:001955
[email protected]9f4e4f082013-06-21 07:11:191956 // Check extensions that may have been delayed only because this shared module
1957 // was not available.
[email protected]374ceb6f2014-07-02 19:25:341958 if (SharedModuleInfo::IsSharedModule(extension))
[email protected]9f4e4f082013-06-21 07:11:191959 MaybeFinishDelayedInstallations();
[email protected]4a190632009-05-09 01:07:421960}
1961
[email protected]760f743b2014-05-28 13:52:021962void ExtensionService::PromoteEphemeralApp(
1963 const extensions::Extension* extension, bool is_from_sync) {
1964 DCHECK(GetInstalledExtension(extension->id()) &&
1965 extension_prefs_->IsEphemeralApp(extension->id()));
1966
[email protected]db378322014-07-21 23:19:341967 if (extension->RequiresSortOrdinal()) {
1968 extension_prefs_->app_sorting()->SetExtensionVisible(
1969 extension->id(), extension->ShouldDisplayInNewTabPage());
1970
1971 if (!is_from_sync) {
[email protected]760f743b2014-05-28 13:52:021972 // Reset the sort ordinals of the app to ensure it is added to the default
1973 // position, like newly installed apps would.
1974 extension_prefs_->app_sorting()->ClearOrdinals(extension->id());
[email protected]760f743b2014-05-28 13:52:021975 }
1976
[email protected]db378322014-07-21 23:19:341977 extension_prefs_->app_sorting()->EnsureValidOrdinals(
1978 extension->id(), syncer::StringOrdinal());
1979 }
1980
[email protected]760f743b2014-05-28 13:52:021981 // Remove the ephemeral flags from the preferences.
1982 extension_prefs_->OnEphemeralAppPromoted(extension->id());
1983
1984 // Fire install-related events to allow observers to handle the promotion
1985 // of the ephemeral app.
1986 extensions::InstalledExtensionInfo details(
1987 extension,
1988 true /* is update */,
1989 true /* from ephemeral */,
1990 extension->name() /* old name */);
1991 content::NotificationService::current()->Notify(
[email protected]adf5a102014-07-31 12:44:061992 extensions::NOTIFICATION_EXTENSION_WILL_BE_INSTALLED_DEPRECATED,
[email protected]760f743b2014-05-28 13:52:021993 content::Source<Profile>(profile_),
1994 content::Details<const extensions::InstalledExtensionInfo>(&details));
1995
1996 registry_->TriggerOnWillBeInstalled(
1997 extension,
1998 true /* is update */,
1999 true /* from ephemeral */,
2000 extension->name() /* old name */);
2001
2002 if (registry_->enabled_extensions().Contains(extension->id())) {
[email protected]8f959f522014-08-06 06:26:282003 // If the app is already enabled and loaded, fire the load events to allow
2004 // observers to handle the promotion of the ephemeral app.
[email protected]760f743b2014-05-28 13:52:022005 content::NotificationService::current()->Notify(
[email protected]adf5a102014-07-31 12:44:062006 extensions::NOTIFICATION_EXTENSION_LOADED_DEPRECATED,
[email protected]760f743b2014-05-28 13:52:022007 content::Source<Profile>(profile_),
2008 content::Details<const Extension>(extension));
2009
2010 registry_->TriggerOnLoaded(extension);
[email protected]8f959f522014-08-06 06:26:282011 } else {
2012 // Cached ephemeral apps may be updated and disabled due to permissions
2013 // increase. The app can be enabled (as long as no other disable reasons
2014 // exist) as the install was user-acknowledged.
2015 int disable_mask = Extension::DISABLE_NONE;
2016 if (!is_from_sync)
2017 disable_mask |= Extension::DISABLE_PERMISSIONS_INCREASE;
2018
2019 int other_disable_reasons =
2020 extension_prefs_->GetDisableReasons(extension->id()) & ~disable_mask;
2021 if (!other_disable_reasons) {
2022 if (extension_prefs_->DidExtensionEscalatePermissions(extension->id()))
2023 GrantPermissionsAndEnableExtension(extension);
2024 else
2025 EnableExtension(extension->id());
2026 }
[email protected]760f743b2014-05-28 13:52:022027 }
2028
[email protected]38e872532014-07-16 23:27:512029 registry_->TriggerOnInstalled(extension, true);
[email protected]bc44b5da2014-06-12 14:20:002030
treibc3494532015-07-21 14:51:452031 if (!is_from_sync) {
2032 ExtensionSyncService::Get(profile_)->SyncExtensionChangeIfNeeded(
2033 *extension);
2034 }
[email protected]760f743b2014-05-28 13:52:022035}
2036
[email protected]76b65442012-11-17 14:11:482037const Extension* ExtensionService::GetPendingExtensionUpdate(
2038 const std::string& id) const {
[email protected]9f4e4f082013-06-21 07:11:192039 return delayed_installs_.GetByID(id);
[email protected]76b65442012-11-17 14:11:482040}
2041
mukai87a8d402014-09-15 20:15:092042void ExtensionService::RegisterContentSettings(
2043 HostContentSettingsMap* host_content_settings_map) {
rkaplowe65c2ff2015-02-14 16:29:542044 TRACE_EVENT0("browser,startup", "ExtensionService::RegisterContentSettings");
mukaia1aa3512014-10-22 20:14:112045 DCHECK_CURRENTLY_ON(BrowserThread::UI);
mukai87a8d402014-09-15 20:15:092046 host_content_settings_map->RegisterProvider(
2047 HostContentSettingsMap::INTERNAL_EXTENSION_PROVIDER,
2048 scoped_ptr<content_settings::ObservableProvider>(
reillyga3acbc12014-11-11 23:17:122049 new content_settings::InternalExtensionProvider(profile_)));
mukai87a8d402014-09-15 20:15:092050
2051 host_content_settings_map->RegisterProvider(
2052 HostContentSettingsMap::CUSTOM_EXTENSION_PROVIDER,
2053 scoped_ptr<content_settings::ObservableProvider>(
2054 new content_settings::CustomExtensionProvider(
2055 extensions::ContentSettingsService::Get(
2056 profile_)->content_settings_store(),
2057 profile_->GetOriginalProfile() != profile_)));
2058}
2059
xiyuane87def2e2015-06-04 22:50:222060void ExtensionService::TrackTerminatedExtension(
2061 const std::string& extension_id) {
2062 extensions_being_terminated_.erase(extension_id);
2063
2064 const Extension* extension = GetInstalledExtension(extension_id);
2065 if (!extension) {
xiyuane87def2e2015-06-04 22:50:222066 return;
2067 }
2068
[email protected]bb1bc9b32013-12-21 03:09:142069 // No need to check for duplicates; inserting a duplicate is a no-op.
2070 registry_->AddTerminated(make_scoped_refptr(extension));
[email protected]b0af4792013-10-23 09:12:132071 UnloadExtension(extension->id(), UnloadedExtensionInfo::REASON_TERMINATE);
[email protected]bb7f40952011-01-13 00:21:202072}
2073
[email protected]e9d7496e2014-04-18 01:25:462074void ExtensionService::TerminateExtension(const std::string& extension_id) {
xiyuana30a2092015-06-09 23:14:442075 TrackTerminatedExtension(extension_id);
[email protected]e9d7496e2014-04-18 01:25:462076}
2077
[email protected]bb7f40952011-01-13 00:21:202078void ExtensionService::UntrackTerminatedExtension(const std::string& id) {
brettwfce8d192015-08-10 19:07:512079 std::string lowercase_id = base::ToLowerASCII(id);
[email protected]bb1bc9b32013-12-21 03:09:142080 const Extension* extension =
2081 registry_->terminated_extensions().GetByID(lowercase_id);
2082 registry_->RemoveTerminated(lowercase_id);
[email protected]fb789532013-08-27 02:40:212083 if (extension) {
2084 content::NotificationService::current()->Notify(
[email protected]adf5a102014-07-31 12:44:062085 extensions::NOTIFICATION_EXTENSION_REMOVED,
[email protected]fb789532013-08-27 02:40:212086 content::Source<Profile>(profile_),
2087 content::Details<const Extension>(extension));
2088 }
[email protected]bb7f40952011-01-13 00:21:202089}
2090
[email protected]8001df22011-04-28 19:59:472091const Extension* ExtensionService::GetInstalledExtension(
2092 const std::string& id) const {
[email protected]599539802014-01-07 23:06:002093 return registry_->GetExtensionById(id, ExtensionRegistry::EVERYTHING);
[email protected]0dfe05c2011-02-23 23:03:362094}
2095
[email protected]9060d8b02012-01-13 02:14:302096bool ExtensionService::OnExternalExtensionFileFound(
thakis37be69c2015-08-19 03:26:572097 const std::string& id,
2098 const Version* version,
2099 const base::FilePath& path,
2100 Manifest::Location location,
2101 int creation_flags,
2102 bool mark_acknowledged,
2103 bool install_immediately) {
[email protected]ab22ba42011-01-14 16:36:382104 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]fdd28372014-08-21 02:27:262105 CHECK(crx_file::id_util::IdIsValid(id));
[email protected]79c833b52011-04-05 18:31:012106 if (extension_prefs_->IsExternalExtensionUninstalled(id))
[email protected]9060d8b02012-01-13 02:14:302107 return false;
[email protected]a8af9fdb2010-10-28 21:52:202108
[email protected]7577a5c52009-07-30 06:21:582109 // Before even bothering to unpack, check and see if we already have this
[email protected]4c967932009-07-31 01:15:492110 // version. This is important because these extensions are going to get
[email protected]7577a5c52009-07-30 06:21:582111 // installed on every startup.
[email protected]9adb9692010-10-29 23:14:022112 const Extension* existing = GetExtensionById(id, true);
[email protected]910f72ce2012-08-24 01:38:352113
[email protected]7577a5c52009-07-30 06:21:582114 if (existing) {
[email protected]910f72ce2012-08-24 01:38:352115 // The default apps will have the location set as INTERNAL. Since older
2116 // default apps are installed as EXTERNAL, we override them. However, if the
2117 // app is already installed as internal, then do the version check.
[email protected]31bb5ee62012-09-12 22:58:402118 // TODO(grv) : Remove after Q1-2013.
[email protected]910f72ce2012-08-24 01:38:352119 bool is_default_apps_migration =
[email protected]1d5e58b2013-01-31 08:41:402120 (location == Manifest::INTERNAL &&
2121 Manifest::IsExternalLocation(existing->location()));
[email protected]910f72ce2012-08-24 01:38:352122
2123 if (!is_default_apps_migration) {
2124 DCHECK(version);
2125
2126 switch (existing->version()->CompareTo(*version)) {
2127 case -1: // existing version is older, we should upgrade
2128 break;
2129 case 0: // existing version is same, do nothing
2130 return false;
2131 case 1: // existing version is newer, uh-oh
2132 LOG(WARNING) << "Found external version of extension " << id
2133 << "that is older than current version. Current version "
2134 << "is: " << existing->VersionString() << ". New "
2135 << "version is: " << version->GetString()
2136 << ". Keeping current version.";
2137 return false;
2138 }
[email protected]7577a5c52009-07-30 06:21:582139 }
2140 }
2141
[email protected]9060d8b02012-01-13 02:14:302142 // If the extension is already pending, don't start an install.
[email protected]e3987852012-05-04 10:06:302143 if (!pending_extension_manager()->AddFromExternalFile(
[email protected]464213a2013-10-15 01:06:482144 id, location, *version, creation_flags, mark_acknowledged)) {
[email protected]9060d8b02012-01-13 02:14:302145 return false;
[email protected]e3987852012-05-04 10:06:302146 }
[email protected]9c635f22010-12-02 09:36:362147
[email protected]14908b72011-04-20 06:54:362148 // no client (silent install)
[email protected]f8636f92013-08-09 21:02:372149 scoped_refptr<CrxInstaller> installer(CrxInstaller::CreateSilent(this));
[email protected]6dfbbf82010-03-12 23:09:162150 installer->set_install_source(location);
2151 installer->set_expected_id(id);
treibe960e282015-09-11 10:38:082152 installer->set_expected_version(*version,
2153 true /* fail_install_if_unexpected */);
[email protected]cb0e50312011-05-09 15:03:072154 installer->set_install_cause(extension_misc::INSTALL_CAUSE_EXTERNAL_FILE);
xiyuan4d82f7b62015-03-04 02:29:222155 installer->set_install_immediately(install_immediately);
[email protected]1bf73cc32011-10-26 22:38:312156 installer->set_creation_flags(creation_flags);
[email protected]88e8ec9152013-01-17 04:05:182157#if defined(OS_CHROMEOS)
2158 extensions::InstallLimiter::Get(profile_)->Add(installer, path);
2159#else
[email protected]6dfbbf82010-03-12 23:09:162160 installer->InstallCrx(path);
[email protected]88e8ec9152013-01-17 04:05:182161#endif
[email protected]47fc70c2011-12-06 07:29:512162
2163 // Depending on the source, a new external extension might not need a user
2164 // notification on installation. For such extensions, mark them acknowledged
2165 // now to suppress the notification.
2166 if (mark_acknowledged)
[email protected]374ceb6f2014-07-02 19:25:342167 external_install_manager_->AcknowledgeExternalExtension(id);
[email protected]9060d8b02012-01-13 02:14:302168
2169 return true;
[email protected]7577a5c52009-07-30 06:21:582170}
2171
[email protected]eaa7dd182010-12-14 11:09:002172void ExtensionService::DidCreateRenderViewForBackgroundPage(
[email protected]3a1dc572012-07-31 22:25:132173 extensions::ExtensionHost* host) {
[email protected]406027c02010-09-27 08:03:182174 OrphanedDevTools::iterator iter =
[email protected]2d2f6cfc2011-05-06 21:09:332175 orphaned_dev_tools_.find(host->extension_id());
[email protected]406027c02010-09-27 08:03:182176 if (iter == orphaned_dev_tools_.end())
2177 return;
2178
rockota34fed222015-09-25 21:56:312179 // Keepalive count is reset on extension reload. This re-establishes the
2180 // keepalive that was added when the DevTools agent was initially attached.
2181 extensions::ProcessManager::Get(profile_)->IncrementLazyKeepaliveCount(
2182 host->extension());
[email protected]b3f957e62014-08-08 10:09:022183 iter->second->ConnectWebContents(host->host_contents());
[email protected]406027c02010-09-27 08:03:182184 orphaned_dev_tools_.erase(iter);
2185}
2186
[email protected]432115822011-07-10 15:52:272187void ExtensionService::Observe(int type,
[email protected]6c2381d2011-10-19 02:52:532188 const content::NotificationSource& source,
2189 const content::NotificationDetails& details) {
[email protected]432115822011-07-10 15:52:272190 switch (type) {
[email protected]3c4abc82012-10-22 22:25:542191 case chrome::NOTIFICATION_APP_TERMINATING:
2192 // Shutdown has started. Don't start any more extension installs.
2193 // (We cannot use ExtensionService::Shutdown() for this because it
2194 // happens too late in browser teardown.)
2195 browser_terminating_ = true;
2196 break;
[email protected]adf5a102014-07-31 12:44:062197 case extensions::NOTIFICATION_EXTENSION_PROCESS_TERMINATED: {
[email protected]6c2381d2011-10-19 02:52:532198 if (profile_ !=
2199 content::Source<Profile>(source).ptr()->GetOriginalProfile()) {
[email protected]bc535ee52010-08-31 18:40:322200 break;
[email protected]6c2381d2011-10-19 02:52:532201 }
[email protected]a4ed6282009-12-14 20:51:162202
[email protected]3a1dc572012-07-31 22:25:132203 extensions::ExtensionHost* host =
2204 content::Details<extensions::ExtensionHost>(details).ptr();
[email protected]f128af42010-08-05 18:05:262205
[email protected]3964e572014-02-13 21:57:412206 // If the extension is already being terminated, there is nothing left to
2207 // do.
2208 if (!extensions_being_terminated_.insert(host->extension_id()).second)
2209 break;
2210
[email protected]fa2416f2011-05-03 08:41:202211 // Mark the extension as terminated and Unload it. We want it to
2212 // be in a consistent state: either fully working or not loaded
2213 // at all, but never half-crashed. We do it in a PostTask so
2214 // that other handlers of this notification will still have
2215 // access to the Extension and ExtensionHost.
skyostilf221b7de2015-06-11 20:36:322216 base::ThreadTaskRunnerHandle::Get()->PostTask(
2217 FROM_HERE, base::Bind(&ExtensionService::TrackTerminatedExtension,
2218 AsWeakPtr(), host->extension()->id()));
[email protected]31f77262009-12-02 20:48:532219 break;
2220 }
[email protected]432115822011-07-10 15:52:272221 case content::NOTIFICATION_RENDERER_PROCESS_TERMINATED: {
[email protected]f3b1a082011-11-18 00:34:302222 content::RenderProcessHost* process =
2223 content::Source<content::RenderProcessHost>(source).ptr();
[email protected]fc30ef082011-08-18 04:07:192224 Profile* host_profile =
[email protected]f3b1a082011-11-18 00:34:302225 Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]fc30ef082011-08-18 04:07:192226 if (!profile_->IsSameProfile(host_profile->GetOriginalProfile()))
2227 break;
2228
[email protected]fafdc842014-01-17 18:09:082229 extensions::ProcessMap* process_map =
2230 extensions::ProcessMap::Get(profile_);
2231 if (process_map->Contains(process->GetID())) {
[email protected]52b76592013-11-02 17:59:032232 // An extension process was terminated, this might have resulted in an
2233 // app or extension becoming idle.
2234 std::set<std::string> extension_ids =
[email protected]fafdc842014-01-17 18:09:082235 process_map->GetExtensionsInProcess(process->GetID());
elijahtaylor0def4432014-10-06 18:15:112236 // In addition to the extensions listed in the process map, one of those
2237 // extensions could be referencing a shared module which is waiting for
2238 // idle to update. Check all imports of these extensions, too.
2239 std::set<std::string> import_ids;
2240 for (std::set<std::string>::const_iterator it = extension_ids.begin();
2241 it != extension_ids.end();
2242 ++it) {
2243 const Extension* extension = GetExtensionById(*it, true);
2244 if (!extension)
2245 continue;
2246 const std::vector<SharedModuleInfo::ImportInfo>& imports =
2247 SharedModuleInfo::GetImports(extension);
2248 std::vector<SharedModuleInfo::ImportInfo>::const_iterator import_it;
2249 for (import_it = imports.begin(); import_it != imports.end();
2250 import_it++) {
2251 import_ids.insert((*import_it).extension_id);
2252 }
2253 }
2254 extension_ids.insert(import_ids.begin(), import_ids.end());
2255
[email protected]52b76592013-11-02 17:59:032256 for (std::set<std::string>::const_iterator it = extension_ids.begin();
2257 it != extension_ids.end(); ++it) {
2258 if (delayed_installs_.Contains(*it)) {
skyostilf221b7de2015-06-11 20:36:322259 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
[email protected]52b76592013-11-02 17:59:032260 FROM_HERE,
2261 base::Bind(&ExtensionService::MaybeFinishDelayedInstallation,
2262 AsWeakPtr(), *it),
2263 base::TimeDelta::FromSeconds(kUpdateIdleDelay));
2264 }
2265 }
2266 }
2267
[email protected]fafdc842014-01-17 18:09:082268 process_map->RemoveAllFromProcess(process->GetID());
[email protected]6f371442011-11-09 06:45:462269 BrowserThread::PostTask(
[email protected]38427a12013-11-09 17:34:202270 BrowserThread::IO,
2271 FROM_HERE,
2272 base::Bind(&extensions::InfoMap::UnregisterAllExtensionsInProcess,
[email protected]31d8f5f22012-04-02 15:22:082273 system_->info_map(),
[email protected]f3b1a082011-11-18 00:34:302274 process->GetID()));
[email protected]da5683db2011-04-23 17:12:212275 break;
2276 }
[email protected]92dd8d92013-02-26 00:41:082277 case chrome::NOTIFICATION_UPGRADE_RECOMMENDED: {
[email protected]75bdcb872013-03-13 00:41:452278 // Notify observers that chrome update is available.
2279 FOR_EACH_OBSERVER(extensions::UpdateObserver, update_observers_,
2280 OnChromeUpdateAvailable());
[email protected]92dd8d92013-02-26 00:41:082281 break;
2282 }
[email protected]ebe07772014-05-22 04:16:062283 case chrome::NOTIFICATION_PROFILE_DESTRUCTION_STARTED: {
2284 OnProfileDestructionStarted();
2285 break;
2286 }
[email protected]aa96d3a2010-08-21 08:45:252287
[email protected]4814b512009-11-07 00:12:292288 default:
2289 NOTREACHED() << "Unexpected notification type.";
2290 }
2291}
2292
binjin47947f842014-11-18 12:10:242293int ExtensionService::GetDisableReasonsOnInstalled(const Extension* extension) {
2294 Extension::DisableReason disable_reason;
2295 // Extensions disabled by management policy should always be disabled, even
2296 // if it's force-installed.
2297 if (system_->management_policy()->MustRemainDisabled(
2298 extension, &disable_reason, nullptr)) {
2299 // A specified reason is required to disable the extension.
2300 DCHECK(disable_reason != Extension::DISABLE_NONE);
2301 return disable_reason;
2302 }
2303
[email protected]612a1cb12012-10-17 13:18:032304 // Extensions installed by policy can't be disabled. So even if a previous
2305 // installation disabled the extension, make sure it is now enabled.
binjin47947f842014-11-18 12:10:242306 if (system_->management_policy()->MustRemainEnabled(extension, nullptr))
2307 return Extension::DISABLE_NONE;
[email protected]612a1cb12012-10-17 13:18:032308
binjin47947f842014-11-18 12:10:242309 // An already disabled extension should inherit the disable reasons and
2310 // remain disabled.
2311 if (extension_prefs_->IsExtensionDisabled(extension->id())) {
2312 int disable_reasons = extension_prefs_->GetDisableReasons(extension->id());
2313 // If an extension was disabled without specified reason, presume it's
2314 // disabled by user.
2315 return disable_reasons == Extension::DISABLE_NONE
2316 ? Extension::DISABLE_USER_ACTION
2317 : disable_reasons;
2318 }
[email protected]612a1cb12012-10-17 13:18:032319
[email protected]41070e8d2012-10-24 01:34:362320 if (FeatureSwitch::prompt_for_external_extensions()->IsEnabled()) {
[email protected]612a1cb12012-10-17 13:18:032321 // External extensions are initially disabled. We prompt the user before
[email protected]2c495c42013-01-04 21:49:542322 // enabling them. Hosted apps are excepted because they are not dangerous
2323 // (they need to be launched by the user anyway).
[email protected]1d5e58b2013-01-31 08:41:402324 if (extension->GetType() != Manifest::TYPE_HOSTED_APP &&
2325 Manifest::IsExternalLocation(extension->location()) &&
[email protected]612a1cb12012-10-17 13:18:032326 !extension_prefs_->IsExternalExtensionAcknowledged(extension->id())) {
binjin47947f842014-11-18 12:10:242327 return Extension::DISABLE_EXTERNAL_EXTENSION;
[email protected]612a1cb12012-10-17 13:18:032328 }
2329 }
[email protected]612a1cb12012-10-17 13:18:032330
binjin47947f842014-11-18 12:10:242331 return Extension::DISABLE_NONE;
[email protected]612a1cb12012-10-17 13:18:032332}
[email protected]0db124b02012-11-07 04:55:052333
mlerman6a37b6a42014-11-26 22:10:532334// Helper method to determine if an extension can be blocked.
2335bool ExtensionService::CanBlockExtension(const Extension* extension) const {
mlerman3690e5be2014-12-01 22:57:442336 DCHECK(extension);
mlerman6a37b6a42014-11-26 22:10:532337 return extension->location() != Manifest::COMPONENT &&
2338 extension->location() != Manifest::EXTERNAL_COMPONENT &&
2339 !system_->management_policy()->MustRemainEnabled(extension, NULL);
2340}
2341
[email protected]e7aa7b7e2012-11-27 04:51:222342bool ExtensionService::ShouldDelayExtensionUpdate(
2343 const std::string& extension_id,
[email protected]4a1d9c0d2014-06-13 12:50:112344 bool install_immediately) const {
[email protected]e7aa7b7e2012-11-27 04:51:222345 const char kOnUpdateAvailableEvent[] = "runtime.onUpdateAvailable";
2346
2347 // If delayed updates are globally disabled, or just for this extension,
2348 // don't delay.
[email protected]4a1d9c0d2014-06-13 12:50:112349 if (!install_updates_when_idle_ || install_immediately)
[email protected]e7aa7b7e2012-11-27 04:51:222350 return false;
2351
[email protected]695b5712012-12-06 23:55:282352 const Extension* old = GetInstalledExtension(extension_id);
[email protected]e7aa7b7e2012-11-27 04:51:222353 // If there is no old extension, this is not an update, so don't delay.
2354 if (!old)
2355 return false;
2356
[email protected]9367eabc2013-03-01 01:29:292357 if (extensions::BackgroundInfo::HasPersistentBackgroundPage(old)) {
[email protected]e7aa7b7e2012-11-27 04:51:222358 // Delay installation if the extension listens for the onUpdateAvailable
2359 // event.
juncaicf523332015-06-04 00:14:042360 return extensions::EventRouter::Get(profile_)
2361 ->ExtensionHasEventListener(extension_id, kOnUpdateAvailableEvent);
[email protected]e7aa7b7e2012-11-27 04:51:222362 } else {
2363 // Delay installation if the extension is not idle.
[email protected]1d5cf4142014-01-24 18:25:222364 return !extensions::util::IsExtensionIdle(extension_id, profile_);
[email protected]e7aa7b7e2012-11-27 04:51:222365 }
[email protected]0db124b02012-11-07 04:55:052366}
[email protected]fdd679b2012-11-15 20:49:392367
[email protected]e5f8fffe2014-04-02 00:30:442368void ExtensionService::OnGarbageCollectIsolatedStorageStart() {
2369 DCHECK(!installs_delayed_for_gc_);
2370 installs_delayed_for_gc_ = true;
[email protected]399583b2012-12-11 09:33:422371}
2372
2373void ExtensionService::OnGarbageCollectIsolatedStorageFinished() {
[email protected]e5f8fffe2014-04-02 00:30:442374 DCHECK(installs_delayed_for_gc_);
2375 installs_delayed_for_gc_ = false;
[email protected]9f4e4f082013-06-21 07:11:192376 MaybeFinishDelayedInstallations();
2377}
2378
2379void ExtensionService::MaybeFinishDelayedInstallations() {
2380 std::vector<std::string> to_be_installed;
[email protected]399583b2012-12-11 09:33:422381 for (ExtensionSet::const_iterator it = delayed_installs_.begin();
2382 it != delayed_installs_.end();
2383 ++it) {
[email protected]9f4e4f082013-06-21 07:11:192384 to_be_installed.push_back((*it)->id());
[email protected]399583b2012-12-11 09:33:422385 }
[email protected]9f4e4f082013-06-21 07:11:192386 for (std::vector<std::string>::const_iterator it = to_be_installed.begin();
2387 it != to_be_installed.end();
[email protected]399583b2012-12-11 09:33:422388 ++it) {
[email protected]9f4e4f082013-06-21 07:11:192389 MaybeFinishDelayedInstallation(*it);
[email protected]399583b2012-12-11 09:33:422390 }
[email protected]399583b2012-12-11 09:33:422391}
2392
[email protected]fdd679b2012-11-15 20:49:392393void ExtensionService::OnBlacklistUpdated() {
[email protected]2d19eb6e2014-01-27 17:30:002394 blacklist_->GetBlacklistedIDs(
[email protected]f47f7172014-03-19 19:27:102395 registry_->GenerateInstalledExtensionsSet()->GetIDs(),
[email protected]3f2a2fa2013-09-24 02:55:252396 base::Bind(&ExtensionService::ManageBlacklist, AsWeakPtr()));
[email protected]695b5712012-12-06 23:55:282397}
2398
[email protected]2d19eb6e2014-01-27 17:30:002399void ExtensionService::ManageBlacklist(
2400 const extensions::Blacklist::BlacklistStateMap& state_map) {
[email protected]54ee8192014-03-29 17:37:242401 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]695b5712012-12-06 23:55:282402
mlerman6a37b6a42014-11-26 22:10:532403 std::set<std::string> blacklisted;
[email protected]2d19eb6e2014-01-27 17:30:002404 ExtensionIdSet greylist;
2405 ExtensionIdSet unchanged;
2406 for (extensions::Blacklist::BlacklistStateMap::const_iterator it =
2407 state_map.begin();
2408 it != state_map.end();
2409 ++it) {
2410 switch (it->second) {
2411 case extensions::NOT_BLACKLISTED:
2412 break;
[email protected]695b5712012-12-06 23:55:282413
[email protected]2d19eb6e2014-01-27 17:30:002414 case extensions::BLACKLISTED_MALWARE:
mlerman6a37b6a42014-11-26 22:10:532415 blacklisted.insert(it->first);
[email protected]2d19eb6e2014-01-27 17:30:002416 break;
2417
2418 case extensions::BLACKLISTED_SECURITY_VULNERABILITY:
2419 case extensions::BLACKLISTED_CWS_POLICY_VIOLATION:
2420 case extensions::BLACKLISTED_POTENTIALLY_UNWANTED:
2421 greylist.insert(it->first);
2422 break;
2423
2424 case extensions::BLACKLISTED_UNKNOWN:
2425 unchanged.insert(it->first);
2426 break;
2427 }
2428 }
2429
mlerman6a37b6a42014-11-26 22:10:532430 UpdateBlacklistedExtensions(blacklisted, unchanged);
[email protected]2d19eb6e2014-01-27 17:30:002431 UpdateGreylistedExtensions(greylist, unchanged, state_map);
2432
[email protected]373daf972014-04-10 01:50:442433 error_controller_->ShowErrorIfNeeded();
[email protected]2d19eb6e2014-01-27 17:30:002434}
2435
2436namespace {
2437void Partition(const ExtensionIdSet& before,
2438 const ExtensionIdSet& after,
2439 const ExtensionIdSet& unchanged,
2440 ExtensionIdSet* no_longer,
2441 ExtensionIdSet* not_yet) {
2442 *not_yet = base::STLSetDifference<ExtensionIdSet>(after, before);
2443 *no_longer = base::STLSetDifference<ExtensionIdSet>(before, after);
2444 *no_longer = base::STLSetDifference<ExtensionIdSet>(*no_longer, unchanged);
2445}
2446} // namespace
2447
mlerman6a37b6a42014-11-26 22:10:532448void ExtensionService::UpdateBlacklistedExtensions(
2449 const ExtensionIdSet& blacklisted,
[email protected]2d19eb6e2014-01-27 17:30:002450 const ExtensionIdSet& unchanged) {
2451 ExtensionIdSet not_yet_blocked, no_longer_blocked;
mlerman6a37b6a42014-11-26 22:10:532452 Partition(registry_->blacklisted_extensions().GetIDs(), blacklisted,
2453 unchanged, &no_longer_blocked, &not_yet_blocked);
[email protected]2d19eb6e2014-01-27 17:30:002454
2455 for (ExtensionIdSet::iterator it = no_longer_blocked.begin();
2456 it != no_longer_blocked.end(); ++it) {
[email protected]695b5712012-12-06 23:55:282457 scoped_refptr<const Extension> extension =
[email protected]bb1bc9b32013-12-21 03:09:142458 registry_->blacklisted_extensions().GetByID(*it);
[email protected]3f2a2fa2013-09-24 02:55:252459 if (!extension.get()) {
mlerman6a37b6a42014-11-26 22:10:532460 NOTREACHED() << "Extension " << *it << " no longer blacklisted, "
2461 << "but it was never blacklisted.";
[email protected]695b5712012-12-06 23:55:282462 continue;
[email protected]3f2a2fa2013-09-24 02:55:252463 }
[email protected]bb1bc9b32013-12-21 03:09:142464 registry_->RemoveBlacklisted(*it);
[email protected]3f2a2fa2013-09-24 02:55:252465 extension_prefs_->SetExtensionBlacklisted(extension->id(), false);
[email protected]dc24976f2013-06-02 21:15:092466 AddExtension(extension.get());
[email protected]ac875372013-02-28 04:36:092467 UMA_HISTOGRAM_ENUMERATION("ExtensionBlacklist.UnblacklistInstalled",
[email protected]dc24976f2013-06-02 21:15:092468 extension->location(),
2469 Manifest::NUM_LOCATIONS);
[email protected]695b5712012-12-06 23:55:282470 }
2471
[email protected]2d19eb6e2014-01-27 17:30:002472 for (ExtensionIdSet::iterator it = not_yet_blocked.begin();
2473 it != not_yet_blocked.end(); ++it) {
[email protected]695b5712012-12-06 23:55:282474 scoped_refptr<const Extension> extension = GetInstalledExtension(*it);
[email protected]3f2a2fa2013-09-24 02:55:252475 if (!extension.get()) {
2476 NOTREACHED() << "Extension " << *it << " needs to be "
2477 << "blacklisted, but it's not installed.";
[email protected]695b5712012-12-06 23:55:282478 continue;
[email protected]3f2a2fa2013-09-24 02:55:252479 }
[email protected]bb1bc9b32013-12-21 03:09:142480 registry_->AddBlacklisted(extension);
[email protected]2d19eb6e2014-01-27 17:30:002481 extension_prefs_->SetExtensionBlacklistState(
2482 extension->id(), extensions::BLACKLISTED_MALWARE);
[email protected]b0af4792013-10-23 09:12:132483 UnloadExtension(*it, UnloadedExtensionInfo::REASON_BLACKLIST);
[email protected]ac875372013-02-28 04:36:092484 UMA_HISTOGRAM_ENUMERATION("ExtensionBlacklist.BlacklistInstalled",
2485 extension->location(), Manifest::NUM_LOCATIONS);
[email protected]695b5712012-12-06 23:55:282486 }
[email protected]2d19eb6e2014-01-27 17:30:002487}
[email protected]695b5712012-12-06 23:55:282488
[email protected]2d19eb6e2014-01-27 17:30:002489// TODO(oleg): UMA logging
2490void ExtensionService::UpdateGreylistedExtensions(
2491 const ExtensionIdSet& greylist,
2492 const ExtensionIdSet& unchanged,
2493 const extensions::Blacklist::BlacklistStateMap& state_map) {
2494 ExtensionIdSet not_yet_greylisted, no_longer_greylisted;
2495 Partition(greylist_.GetIDs(),
2496 greylist, unchanged,
2497 &no_longer_greylisted, &not_yet_greylisted);
2498
2499 for (ExtensionIdSet::iterator it = no_longer_greylisted.begin();
2500 it != no_longer_greylisted.end(); ++it) {
2501 scoped_refptr<const Extension> extension = greylist_.GetByID(*it);
2502 if (!extension.get()) {
2503 NOTREACHED() << "Extension " << *it << " no longer greylisted, "
2504 << "but it was not marked as greylisted.";
2505 continue;
2506 }
2507
2508 greylist_.Remove(*it);
2509 extension_prefs_->SetExtensionBlacklistState(extension->id(),
2510 extensions::NOT_BLACKLISTED);
2511 if (extension_prefs_->GetDisableReasons(extension->id()) &
2512 extensions::Extension::DISABLE_GREYLIST)
2513 EnableExtension(*it);
2514 }
2515
2516 for (ExtensionIdSet::iterator it = not_yet_greylisted.begin();
2517 it != not_yet_greylisted.end(); ++it) {
2518 scoped_refptr<const Extension> extension = GetInstalledExtension(*it);
2519 if (!extension.get()) {
2520 NOTREACHED() << "Extension " << *it << " needs to be "
2521 << "disabled, but it's not installed.";
2522 continue;
2523 }
2524 greylist_.Insert(extension);
2525 extension_prefs_->SetExtensionBlacklistState(extension->id(),
2526 state_map.find(*it)->second);
2527 if (registry_->enabled_extensions().Contains(extension->id()))
2528 DisableExtension(*it, extensions::Extension::DISABLE_GREYLIST);
2529 }
[email protected]fdd679b2012-11-15 20:49:392530}
[email protected]75bdcb872013-03-13 00:41:452531
2532void ExtensionService::AddUpdateObserver(extensions::UpdateObserver* observer) {
2533 update_observers_.AddObserver(observer);
2534}
2535
2536void ExtensionService::RemoveUpdateObserver(
2537 extensions::UpdateObserver* observer) {
2538 update_observers_.RemoveObserver(observer);
2539}
[email protected]bb1bc9b32013-12-21 03:09:142540
2541// Used only by test code.
2542void ExtensionService::UnloadAllExtensionsInternal() {
2543 profile_->GetExtensionSpecialStoragePolicy()->RevokeRightsForAllExtensions();
2544
2545 registry_->ClearAll();
[email protected]45f5b7d2014-01-22 23:47:132546 system_->runtime_data()->ClearAll();
[email protected]bb1bc9b32013-12-21 03:09:142547
2548 // TODO(erikkay) should there be a notification for this? We can't use
2549 // EXTENSION_UNLOADED since that implies that the extension has been disabled
2550 // or uninstalled.
2551}
[email protected]ebe07772014-05-22 04:16:062552
2553void ExtensionService::OnProfileDestructionStarted() {
2554 ExtensionIdSet ids_to_unload = registry_->enabled_extensions().GetIDs();
2555 for (ExtensionIdSet::iterator it = ids_to_unload.begin();
2556 it != ids_to_unload.end();
2557 ++it) {
2558 UnloadExtension(*it, UnloadedExtensionInfo::REASON_PROFILE_SHUTDOWN);
2559 }
2560}