blob: fb0830d4339293eca0a6a0907b6d08ca499f644d [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]24b538a2010-02-27 01:22:4411#include "base/basictypes.h"
[email protected]05aad2da2011-10-28 10:12:3712#include "base/bind.h"
[email protected]e5af875f2011-10-10 21:09:1413#include "base/callback.h"
[email protected]62433d32011-10-12 22:33:1214#include "base/command_line.h"
[email protected]6014d672008-12-05 00:38:2515#include "base/file_util.h"
[email protected]14908b72011-04-20 06:54:3616#include "base/logging.h"
[email protected]835d7c82010-10-14 04:38:3817#include "base/metrics/histogram.h"
[email protected]3853a4c2013-02-11 17:15:5718#include "base/prefs/pref_service.h"
[email protected]7286e3fc2011-07-19 22:13:2419#include "base/stl_util.h"
[email protected]3ea1b182013-02-08 22:38:4120#include "base/strings/string_number_conversions.h"
[email protected]00e7bef2013-06-10 20:35:1721#include "base/strings/string_util.h"
22#include "base/strings/stringprintf.h"
[email protected]112158af2013-06-07 23:46:1823#include "base/strings/utf_string_conversions.h"
[email protected]7f8f24f2012-11-15 19:40:1424#include "base/threading/sequenced_worker_pool.h"
[email protected]34b99632011-01-01 01:01:0625#include "base/threading/thread_restrictions.h"
[email protected]41a17c52013-06-28 00:27:5326#include "base/time/time.h"
[email protected]cc655912009-01-29 23:19:1927#include "base/values.h"
[email protected]aa142702010-03-26 01:26:3328#include "base/version.h"
[email protected]15730c42009-09-03 00:03:2029#include "chrome/browser/browser_process.h"
[email protected]9ea0cd32013-07-12 01:50:3630#include "chrome/browser/chrome_notification_types.h"
[email protected]ad445762013-01-23 00:47:4431#include "chrome/browser/extensions/api/extension_action/extension_action_api.h"
[email protected]4636c832013-01-11 02:10:1132#include "chrome/browser/extensions/api/storage/settings_frontend.h"
[email protected]d8c8f25f2011-11-02 18:18:0133#include "chrome/browser/extensions/component_loader.h"
[email protected]e0785902011-05-19 23:34:1734#include "chrome/browser/extensions/crx_installer.h"
[email protected]d9ede582012-08-14 19:21:3835#include "chrome/browser/extensions/data_deleter.h"
[email protected]62f051c2012-03-29 17:04:4436#include "chrome/browser/extensions/extension_disabled_ui.h"
[email protected]14a000d2010-04-29 21:44:2437#include "chrome/browser/extensions/extension_error_reporter.h"
[email protected]89226982012-07-16 20:09:1838#include "chrome/browser/extensions/extension_error_ui.h"
[email protected]b1748b1d82009-11-30 20:32:5639#include "chrome/browser/extensions/extension_host.h"
[email protected]00b38242012-07-18 18:43:2240#include "chrome/browser/extensions/extension_install_ui.h"
[email protected]19eb80152011-02-26 00:28:4341#include "chrome/browser/extensions/extension_special_storage_policy.h"
[email protected]f8aefb132013-10-30 09:29:5242#include "chrome/browser/extensions/extension_sync_service.h"
[email protected]31d8f5f22012-04-02 15:22:0843#include "chrome/browser/extensions/extension_system.h"
[email protected]612a1cb12012-10-17 13:18:0344#include "chrome/browser/extensions/external_install_ui.h"
[email protected]5df038b2012-07-16 19:03:2745#include "chrome/browser/extensions/external_provider_impl.h"
[email protected]ffd2f79e2013-11-14 00:11:4646#include "chrome/browser/extensions/install_verifier.h"
[email protected]d8c8f25f2011-11-02 18:18:0147#include "chrome/browser/extensions/installed_loader.h"
[email protected]c333e792012-01-06 16:57:3948#include "chrome/browser/extensions/permissions_updater.h"
[email protected]d8c8f25f2011-11-02 18:18:0149#include "chrome/browser/extensions/unpacked_installer.h"
[email protected]42a08162012-03-16 18:09:1150#include "chrome/browser/extensions/updater/extension_updater.h"
[email protected]8ecad5e2010-12-02 21:18:3351#include "chrome/browser/profiles/profile.h"
[email protected]b5a507b22013-11-08 20:41:5752#include "chrome/browser/ui/webui/extensions/extension_icon_source.h"
[email protected]c8d407e2011-04-28 21:27:1753#include "chrome/browser/ui/webui/favicon_source.h"
[email protected]5eddc3e2011-10-26 04:33:3154#include "chrome/browser/ui/webui/ntp/thumbnail_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]7c927b62010-02-24 09:54:1359#include "chrome/common/extensions/extension_file_util.h"
[email protected]77a6970c2011-04-23 16:58:5660#include "chrome/common/extensions/extension_messages.h"
[email protected]15d4d2d2013-08-09 06:49:0361#include "chrome/common/extensions/features/feature_channel.h"
[email protected]561e33d52013-04-03 06:58:4362#include "chrome/common/extensions/manifest_handlers/app_isolation_info.h"
[email protected]6b414c232013-06-05 07:53:3463#include "chrome/common/extensions/manifest_handlers/app_launch_info.h"
[email protected]65348062013-01-15 07:27:2264#include "chrome/common/extensions/manifest_url_handler.h"
[email protected]25b34332009-06-05 21:53:1965#include "chrome/common/pref_names.h"
[email protected]a57209872009-05-04 22:53:1466#include "chrome/common/url_constants.h"
[email protected]7a83dd072013-09-03 12:09:1767#include "components/startup_metric_utils/startup_metric_utils.h"
[email protected]c38831a12011-10-28 12:44:4968#include "content/public/browser/browser_thread.h"
[email protected]98f66112012-12-25 12:59:3669#include "content/public/browser/devtools_agent_host.h"
[email protected]05aad2da2011-10-28 10:12:3770#include "content/public/browser/notification_service.h"
[email protected]0d6e9bd2011-10-18 04:29:1671#include "content/public/browser/notification_types.h"
[email protected]f3b1a082011-11-18 00:34:3072#include "content/public/browser/render_process_host.h"
[email protected]399583b2012-12-11 09:33:4273#include "content/public/browser/site_instance.h"
74#include "content/public/browser/storage_partition.h"
[email protected]24ea7a12013-01-27 23:54:5375#include "content/public/browser/url_data_source.h"
[email protected]74474042013-11-21 12:03:5476#include "extensions/browser/app_sorting.h"
[email protected]34423532013-11-21 18:13:1077#include "extensions/browser/event_router.h"
[email protected]45928b682013-11-28 08:20:2778#include "extensions/browser/extensions_browser_client.h"
[email protected]301116c62013-11-26 10:37:4579#include "extensions/browser/external_provider_interface.h"
80#include "extensions/browser/management_policy.h"
[email protected]b52f8ca2013-11-28 08:25:2281#include "extensions/browser/pending_extension_manager.h"
[email protected]98b6d942013-11-10 00:34:0782#include "extensions/browser/process_manager.h"
[email protected]a9aa62b312013-11-29 05:35:0683#include "extensions/browser/update_observer.h"
[email protected]836e2982013-05-16 08:07:4284#include "extensions/common/constants.h"
[email protected]e9f541a2012-11-19 21:52:3185#include "extensions/common/error_utils.h"
[email protected]e4452d32013-11-15 23:07:4186#include "extensions/common/extension.h"
[email protected]c81f5d32013-10-26 10:38:4287#include "extensions/common/extensions_client.h"
[email protected]5ef835a2013-11-08 20:42:5788#include "extensions/common/feature_switch.h"
[email protected]d42c11152013-08-22 19:36:3289#include "extensions/common/manifest.h"
[email protected]0c3c9732013-09-16 08:53:4190#include "extensions/common/manifest_constants.h"
[email protected]558878cc82013-11-09 01:25:5191#include "extensions/common/manifest_handlers/background_info.h"
[email protected]1f7de252013-11-06 22:02:0092#include "extensions/common/manifest_handlers/incognito_info.h"
[email protected]301116c62013-11-26 10:37:4593#include "extensions/common/manifest_handlers/shared_module_info.h"
[email protected]c41003472013-10-19 15:37:2594#include "extensions/common/permissions/permission_message_provider.h"
[email protected]e4452d32013-11-15 23:07:4195#include "extensions/common/permissions/permissions_data.h"
[email protected]65187152012-06-02 13:14:1496#include "grit/generated_resources.h"
[email protected]be28b5f42012-07-20 11:31:2597#include "net/base/registry_controlled_domains/registry_controlled_domain.h"
[email protected]cd67ed52013-10-15 01:22:1398#include "ui/base/webui/web_ui_util.h"
[email protected]a6483d22013-07-03 22:11:0099#include "url/gurl.h"
[email protected]08b1f75f2013-05-22 22:02:38100#include "webkit/browser/database/database_tracker.h"
101#include "webkit/browser/database/database_util.h"
[email protected]79a60642012-10-20 21:03:18102
[email protected]eed367e2011-04-12 03:43:31103#if defined(OS_CHROMEOS)
[email protected]88e8ec9152013-01-17 04:05:18104#include "chrome/browser/chromeos/extensions/install_limiter.h"
[email protected]f19bbf62013-07-09 01:22:32105#include "webkit/browser/fileapi/file_system_backend.h"
[email protected]c6f9203a2013-05-28 02:08:07106#include "webkit/browser/fileapi/file_system_context.h"
[email protected]eed367e2011-04-12 03:43:31107#endif
108
[email protected]55eb70e762012-02-20 17:38:39109using content::BrowserContext;
[email protected]631bb742011-11-02 11:29:39110using content::BrowserThread;
[email protected]98f66112012-12-25 12:59:36111using content::DevToolsAgentHost;
[email protected]bf3d9df2012-07-24 23:20:27112using extensions::CrxInstaller;
[email protected]1c321ee52012-05-21 03:02:34113using extensions::Extension;
114using extensions::ExtensionIdSet;
115using extensions::ExtensionInfo;
[email protected]289c44b2013-12-17 03:26:57116using extensions::ExtensionSet;
[email protected]215a7be2012-10-22 19:53:42117using extensions::FeatureSwitch;
[email protected]ffd2f79e2013-11-14 00:11:46118using extensions::InstallVerifier;
[email protected]0d54b682013-11-05 14:15:36119using extensions::ManagementPolicy;
[email protected]1d5e58b2013-01-31 08:41:40120using extensions::Manifest;
[email protected]c2e66e12012-06-27 06:27:06121using extensions::PermissionMessage;
122using extensions::PermissionMessages;
123using extensions::PermissionSet;
[email protected]9f4e4f082013-06-21 07:11:19124using extensions::SharedModuleInfo;
[email protected]e410b5f2012-12-14 14:02:24125using extensions::UnloadedExtensionInfo;
[email protected]5ef47ec2010-01-28 05:58:05126
[email protected]0c3c9732013-09-16 08:53:41127namespace errors = extensions::manifest_errors;
[email protected]c6d474f82009-12-16 21:11:06128
[email protected]b6ab96d2009-08-20 18:58:19129namespace {
130
[email protected]d96eb512012-11-01 23:44:08131// Histogram values for logging events related to externally installed
132// extensions.
133enum ExternalExtensionEvent {
134 EXTERNAL_EXTENSION_INSTALLED = 0,
135 EXTERNAL_EXTENSION_IGNORED,
136 EXTERNAL_EXTENSION_REENABLED,
137 EXTERNAL_EXTENSION_UNINSTALLED,
138 EXTERNAL_EXTENSION_BUCKET_BOUNDARY,
139};
140
[email protected]612a1cb12012-10-17 13:18:03141// Prompt the user this many times before considering an extension acknowledged.
142static const int kMaxExtensionAcknowledgePromptCount = 3;
143
[email protected]0db124b02012-11-07 04:55:05144// Wait this many seconds after an extensions becomes idle before updating it.
145static const int kUpdateIdleDelay = 5;
146
[email protected]9bd9a6862012-11-29 09:24:22147// Wait this many seconds before trying to garbage collect extensions again.
148static const int kGarbageCollectRetryDelay = 30;
149
[email protected]36fc54f2013-06-14 02:49:34150// Wait this many seconds after startup to see if there are any extensions
151// which can be garbage collected.
152static const int kGarbageCollectStartupDelay = 30;
153
[email protected]9f4e4f082013-06-21 07:11:19154static bool IsSharedModule(const Extension* extension) {
155 return SharedModuleInfo::IsSharedModule(extension);
156}
157
[email protected]4c9201c42013-08-16 04:56:21158static bool IsCWSSharedModule(const Extension* extension) {
159 return extension->from_webstore() && IsSharedModule(extension);
160}
161
162class SharedModuleProvider : public extensions::ManagementPolicy::Provider {
163 public:
164 SharedModuleProvider() {}
165 virtual ~SharedModuleProvider() {}
166
167 virtual std::string GetDebugPolicyProviderName() const OVERRIDE {
168 return "SharedModuleProvider";
169 }
170
171 virtual bool UserMayModifySettings(const Extension* extension,
[email protected]439f1e32013-12-09 20:09:09172 base::string16* error) const OVERRIDE {
[email protected]4c9201c42013-08-16 04:56:21173 return !IsCWSSharedModule(extension);
174 }
175
176 virtual bool MustRemainEnabled(const Extension* extension,
[email protected]439f1e32013-12-09 20:09:09177 base::string16* error) const OVERRIDE {
[email protected]4c9201c42013-08-16 04:56:21178 return IsCWSSharedModule(extension);
179 }
180
181 private:
182 DISALLOW_COPY_AND_ASSIGN(SharedModuleProvider);
183};
184
185
[email protected]c6d474f82009-12-16 21:11:06186} // namespace
[email protected]b6ab96d2009-08-20 18:58:19187
[email protected]eaa7dd182010-12-14 11:09:00188ExtensionService::ExtensionRuntimeData::ExtensionRuntimeData()
[email protected]d7e9a862010-11-03 21:57:49189 : background_page_ready(false),
[email protected]f8bf5992011-10-24 22:38:57190 being_upgraded(false),
191 has_used_webrequest(false) {
[email protected]d7e9a862010-11-03 21:57:49192}
193
[email protected]eaa7dd182010-12-14 11:09:00194ExtensionService::ExtensionRuntimeData::~ExtensionRuntimeData() {
[email protected]d7e9a862010-11-03 21:57:49195}
196
[email protected]eaa7dd182010-12-14 11:09:00197// ExtensionService.
[email protected]6014d672008-12-05 00:38:25198
[email protected]8e4560b62011-01-14 10:09:14199void ExtensionService::CheckExternalUninstall(const std::string& id) {
[email protected]a29a517a2011-01-21 21:11:12200 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]a8af9fdb2010-10-28 21:52:20201
[email protected]7a4c6852010-09-16 03:44:22202 // Check if the providers know about this extension.
[email protected]5df038b2012-07-16 19:03:27203 extensions::ProviderCollection::const_iterator i;
[email protected]0a60a2e2010-10-25 16:15:21204 for (i = external_extension_providers_.begin();
205 i != external_extension_providers_.end(); ++i) {
[email protected]8e4560b62011-01-14 10:09:14206 DCHECK(i->get()->IsReady());
[email protected]0a60a2e2010-10-25 16:15:21207 if (i->get()->HasExtension(id))
208 return; // Yup, known extension, don't uninstall.
[email protected]7a4c6852010-09-16 03:44:22209 }
210
[email protected]0f48fca2011-05-19 18:46:35211 // We get the list of external extensions to check from preferences.
212 // It is possible that an extension has preferences but is not loaded.
213 // For example, an extension that requires experimental permissions
214 // will not be loaded if the experimental command line flag is not used.
215 // In this case, do not uninstall.
[email protected]31bb5ee62012-09-12 22:58:40216 if (!GetInstalledExtension(id)) {
[email protected]0f48fca2011-05-19 18:46:35217 // We can't call UninstallExtension with an unloaded/invalid
218 // extension ID.
219 LOG(WARNING) << "Attempted uninstallation of unloaded/invalid extension "
220 << "with id: " << id;
221 return;
222 }
[email protected]d6ebc9792011-04-07 18:18:33223 UninstallExtension(id, true, NULL);
[email protected]7a4c6852010-09-16 03:44:22224}
225
[email protected]7f8f24f2012-11-15 19:40:14226void ExtensionService::SetFileTaskRunnerForTesting(
227 base::SequencedTaskRunner* task_runner) {
228 file_task_runner_ = task_runner;
229}
230
[email protected]8e4560b62011-01-14 10:09:14231void ExtensionService::ClearProvidersForTesting() {
[email protected]7a4c6852010-09-16 03:44:22232 external_extension_providers_.clear();
233}
234
[email protected]8e4560b62011-01-14 10:09:14235void ExtensionService::AddProviderForTesting(
[email protected]5df038b2012-07-16 19:03:27236 extensions::ExternalProviderInterface* test_provider) {
[email protected]a29a517a2011-01-21 21:11:12237 CHECK(test_provider);
[email protected]0a60a2e2010-10-25 16:15:21238 external_extension_providers_.push_back(
[email protected]5df038b2012-07-16 19:03:27239 linked_ptr<extensions::ExternalProviderInterface>(test_provider));
[email protected]7a4c6852010-09-16 03:44:22240}
241
[email protected]9060d8b02012-01-13 02:14:30242bool ExtensionService::OnExternalExtensionUpdateUrlFound(
[email protected]7a4c6852010-09-16 03:44:22243 const std::string& id,
[email protected]21a5a672010-11-04 10:47:42244 const GURL& update_url,
[email protected]464213a2013-10-15 01:06:48245 Manifest::Location location,
246 int creation_flags,
247 bool mark_acknowledged) {
[email protected]ab22ba42011-01-14 16:36:38248 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
249 CHECK(Extension::IdIsValid(id));
[email protected]a8af9fdb2010-10-28 21:52:20250
[email protected]8a87a5332011-08-11 17:54:59251 const Extension* extension = GetExtensionById(id, true);
252 if (extension) {
253 // Already installed. Skip this install if the current location has
254 // higher priority than |location|.
[email protected]1d5e58b2013-01-31 08:41:40255 Manifest::Location current = extension->location();
256 if (current == Manifest::GetHigherPriorityLocation(current, location))
[email protected]9060d8b02012-01-13 02:14:30257 return false;
[email protected]8a87a5332011-08-11 17:54:59258 // Otherwise, overwrite the current installation.
[email protected]7a4c6852010-09-16 03:44:22259 }
[email protected]9060d8b02012-01-13 02:14:30260
261 // Add |id| to the set of pending extensions. If it can not be added,
262 // then there is already a pending record from a higher-priority install
263 // source. In this case, signal that this extension will not be
264 // installed by returning false.
265 if (!pending_extension_manager()->AddFromExternalUpdateUrl(
[email protected]464213a2013-10-15 01:06:48266 id, update_url, location, creation_flags, mark_acknowledged)) {
[email protected]9060d8b02012-01-13 02:14:30267 return false;
[email protected]31bb5ee62012-09-12 22:58:40268 }
[email protected]9060d8b02012-01-13 02:14:30269
[email protected]94fde232012-04-27 10:22:30270 update_once_all_providers_are_ready_ = true;
[email protected]9060d8b02012-01-13 02:14:30271 return true;
[email protected]7a4c6852010-09-16 03:44:22272}
273
[email protected]400c4392013-12-13 14:41:58274const Extension* ExtensionService::GetInstalledExtensionByUrl(
275 const GURL& url) const {
276 return extensions_.GetExtensionOrAppByURL(url);
277}
278
[email protected]dc9a74f72012-08-17 18:07:21279const Extension* ExtensionService::GetInstalledApp(const GURL& url) const {
[email protected]400c4392013-12-13 14:41:58280 const Extension* extension = GetInstalledExtensionByUrl(url);
[email protected]dc9a74f72012-08-17 18:07:21281 return (extension && extension->is_app()) ? extension : NULL;
[email protected]d9696672011-03-15 22:45:09282}
283
[email protected]dc9a74f72012-08-17 18:07:21284bool ExtensionService::IsInstalledApp(const GURL& url) const {
[email protected]d9696672011-03-15 22:45:09285 return !!GetInstalledApp(url);
[email protected]ffb204f22010-12-05 23:20:27286}
287
[email protected]6aeac8342010-10-01 20:21:18288// static
[email protected]d6ebc9792011-04-07 18:18:33289// This function is used to implement the command-line switch
[email protected]3bdba0d2011-08-23 07:17:30290// --uninstall-extension, and to uninstall an extension via sync. The LOG
291// statements within this function are used to inform the user if the uninstall
292// cannot be done.
[email protected]eaa7dd182010-12-14 11:09:00293bool ExtensionService::UninstallExtensionHelper(
294 ExtensionService* extensions_service,
[email protected]6aeac8342010-10-01 20:21:18295 const std::string& extension_id) {
[email protected]d6ebc9792011-04-07 18:18:33296 // We can't call UninstallExtension with an invalid extension ID.
[email protected]31bb5ee62012-09-12 22:58:40297 if (!extensions_service->GetInstalledExtension(extension_id)) {
[email protected]6aeac8342010-10-01 20:21:18298 LOG(WARNING) << "Attempted uninstallation of non-existent extension with "
[email protected]95da88c42011-03-31 10:07:33299 << "id: " << extension_id;
300 return false;
[email protected]6aeac8342010-10-01 20:21:18301 }
302
[email protected]d6ebc9792011-04-07 18:18:33303 // The following call to UninstallExtension will not allow an uninstall of a
304 // policy-controlled extension.
[email protected]439f1e32013-12-09 20:09:09305 base::string16 error;
[email protected]d6ebc9792011-04-07 18:18:33306 if (!extensions_service->UninstallExtension(extension_id, false, &error)) {
307 LOG(WARNING) << "Cannot uninstall extension with id " << extension_id
308 << ": " << error;
309 return false;
310 }
[email protected]95da88c42011-03-31 10:07:33311
[email protected]6aeac8342010-10-01 20:21:18312 return true;
313}
314
[email protected]eaa7dd182010-12-14 11:09:00315ExtensionService::ExtensionService(Profile* profile,
[email protected]f0841cd2011-01-19 15:07:24316 const CommandLine* command_line,
[email protected]650b2d52013-02-10 03:41:45317 const base::FilePath& install_directory,
[email protected]45759612012-07-10 17:21:23318 extensions::ExtensionPrefs* extension_prefs,
[email protected]fdd679b2012-11-15 20:49:39319 extensions::Blacklist* blacklist,
[email protected]0436b102011-04-15 18:30:03320 bool autoupdate_enabled,
[email protected]4a10006a2013-05-17 23:18:35321 bool extensions_enabled,
322 extensions::OneShotEvent* ready)
[email protected]fdd679b2012-11-15 20:49:39323 : extensions::Blacklist::Observer(blacklist),
324 profile_(profile),
[email protected]bd306722012-07-11 20:43:59325 system_(extensions::ExtensionSystem::Get(profile)),
[email protected]73c47932010-12-06 18:13:43326 extension_prefs_(extension_prefs),
[email protected]695b5712012-12-06 23:55:28327 blacklist_(blacklist),
[email protected]cccdf0aa2011-11-11 03:43:38328 settings_frontend_(extensions::SettingsFrontend::Create(profile)),
[email protected]f8aefb132013-10-30 09:29:52329 extension_sync_service_(NULL),
[email protected]9c009092013-05-01 03:14:09330 pending_extension_manager_(*this),
[email protected]a9b00ac2009-06-25 21:03:23331 install_directory_(install_directory),
[email protected]0436b102011-04-15 18:30:03332 extensions_enabled_(extensions_enabled),
[email protected]e81dba32009-06-19 20:19:13333 show_extensions_prompts_(true),
[email protected]fc332ae2012-11-14 20:17:33334 install_updates_when_idle_(true),
[email protected]4a10006a2013-05-17 23:18:35335 ready_(ready),
[email protected]dff1e042012-04-27 10:59:18336 update_once_all_providers_are_ready_(false),
[email protected]3c4abc82012-10-22 22:25:54337 browser_terminating_(false),
[email protected]9f4e4f082013-06-21 07:11:19338 installs_delayed_for_gc_(false),
[email protected]f8aefb132013-10-30 09:29:52339 is_first_run_(false) {
[email protected]c04fd3dd2013-09-05 08:20:10340#if defined(OS_CHROMEOS)
341 disable_garbage_collection_ = false;
342#endif
[email protected]a29a517a2011-01-21 21:11:12343 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]a8af9fdb2010-10-28 21:52:20344
[email protected]36a784c2009-06-23 06:21:08345 // Figure out if extension installation should be enabled.
[email protected]367d9b172013-12-03 00:31:02346 if (extensions::ExtensionsBrowserClient::Get()->AreExtensionsDisabled(
347 *command_line, profile))
[email protected]6d60703b2009-08-29 01:29:23348 extensions_enabled_ = false;
[email protected]36a784c2009-06-23 06:21:08349
[email protected]3c4abc82012-10-22 22:25:54350 registrar_.Add(this, chrome::NOTIFICATION_APP_TERMINATING,
351 content::NotificationService::AllBrowserContextsAndSources());
[email protected]432115822011-07-10 15:52:27352 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_PROCESS_TERMINATED,
[email protected]ad50def52011-10-19 23:17:07353 content::NotificationService::AllBrowserContextsAndSources());
[email protected]432115822011-07-10 15:52:27354 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_CREATED,
[email protected]ad50def52011-10-19 23:17:07355 content::NotificationService::AllBrowserContextsAndSources());
[email protected]432115822011-07-10 15:52:27356 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_TERMINATED,
[email protected]ad50def52011-10-19 23:17:07357 content::NotificationService::AllBrowserContextsAndSources());
[email protected]92dd8d92013-02-26 00:41:08358 registrar_.Add(this, chrome::NOTIFICATION_UPGRADE_RECOMMENDED,
359 content::NotificationService::AllBrowserContextsAndSources());
[email protected]2fb7dc982010-09-29 12:24:28360 pref_change_registrar_.Init(profile->GetPrefs());
[email protected]90bb38d2012-11-14 18:36:03361 base::Closure callback =
362 base::Bind(&ExtensionService::OnExtensionInstallPrefChanged,
363 base::Unretained(this));
364 pref_change_registrar_.Add(prefs::kExtensionInstallAllowList, callback);
365 pref_change_registrar_.Add(prefs::kExtensionInstallDenyList, callback);
[email protected]e410b5f2012-12-14 14:02:24366 pref_change_registrar_.Add(prefs::kExtensionAllowedTypes, callback);
[email protected]4814b512009-11-07 00:12:29367
[email protected]93fd78f42009-07-10 16:43:17368 // Set up the ExtensionUpdater
369 if (autoupdate_enabled) {
[email protected]501105b2013-09-26 05:42:02370 int update_frequency = extensions::kDefaultUpdateFrequencySeconds;
[email protected]93fd78f42009-07-10 16:43:17371 if (command_line->HasSwitch(switches::kExtensionsUpdateFrequency)) {
[email protected]e83326f2010-07-31 17:29:25372 base::StringToInt(command_line->GetSwitchValueASCII(
373 switches::kExtensionsUpdateFrequency),
374 &update_frequency);
[email protected]93fd78f42009-07-10 16:43:17375 }
[email protected]42a08162012-03-16 18:09:11376 updater_.reset(new extensions::ExtensionUpdater(this,
377 extension_prefs,
378 profile->GetPrefs(),
379 profile,
380 update_frequency));
[email protected]93fd78f42009-07-10 16:43:17381 }
382
[email protected]25ae0152011-11-18 14:40:02383 component_loader_.reset(
384 new extensions::ComponentLoader(this,
385 profile->GetPrefs(),
[email protected]55e16cd2013-12-18 04:36:08386 g_browser_process->local_state(),
387 profile));
[email protected]8e4560b62011-01-14 10:09:14388
[email protected]0436b102011-04-15 18:30:03389 if (extensions_enabled_) {
[email protected]ae4c37e2012-12-21 01:16:25390 extensions::ExternalProviderImpl::CreateExternalProviders(
391 this, profile_, &external_extension_providers_);
[email protected]873531342011-03-09 12:16:05392 }
[email protected]b671760b2010-07-15 21:13:47393
[email protected]74474042013-11-21 12:03:54394 // Set this as the ExtensionService for app sorting to ensure it causes syncs
395 // if required.
[email protected]b3aa7182013-04-25 04:45:23396 is_first_run_ = !extension_prefs_->SetAlertSystemFirstRun();
397
[email protected]9ce11d22012-08-08 23:20:13398#if defined(ENABLE_EXTENSIONS)
[email protected]c77f2352012-08-08 22:07:58399 extension_action_storage_manager_.reset(
400 new extensions::ExtensionActionStorageManager(profile_));
[email protected]9ce11d22012-08-08 23:20:13401#endif
[email protected]c77f2352012-08-08 22:07:58402
[email protected]4c9201c42013-08-16 04:56:21403 shared_module_policy_provider_.reset(new SharedModuleProvider);
404
[email protected]cb0e50312011-05-09 15:03:07405 // How long is the path to the Extensions directory?
406 UMA_HISTOGRAM_CUSTOM_COUNTS("Extensions.ExtensionRootPathLength",
407 install_directory_.value().length(), 0, 500, 100);
[email protected]6014d672008-12-05 00:38:25408}
409
[email protected]84df8332011-12-06 18:22:46410const ExtensionSet* ExtensionService::extensions() const {
[email protected]ddb1e5a2010-12-13 20:10:45411 return &extensions_;
412}
413
[email protected]84df8332011-12-06 18:22:46414const ExtensionSet* ExtensionService::disabled_extensions() const {
[email protected]ddb1e5a2010-12-13 20:10:45415 return &disabled_extensions_;
416}
417
[email protected]84df8332011-12-06 18:22:46418const ExtensionSet* ExtensionService::terminated_extensions() const {
[email protected]bb7f40952011-01-13 00:21:20419 return &terminated_extensions_;
420}
421
[email protected]695b5712012-12-06 23:55:28422const ExtensionSet* ExtensionService::blacklisted_extensions() const {
423 return &blacklisted_extensions_;
424}
425
[email protected]9e9c1d12013-07-31 01:58:12426const ExtensionSet* ExtensionService::delayed_installs() const {
427 return &delayed_installs_;
428}
429
[email protected]620b5a62013-11-18 04:21:08430scoped_ptr<ExtensionSet>
[email protected]695b5712012-12-06 23:55:28431 ExtensionService::GenerateInstalledExtensionsSet() const {
432 scoped_ptr<ExtensionSet> installed_extensions(new ExtensionSet());
[email protected]7f4308d2012-01-18 07:43:01433 installed_extensions->InsertAll(extensions_);
434 installed_extensions->InsertAll(disabled_extensions_);
435 installed_extensions->InsertAll(terminated_extensions_);
[email protected]695b5712012-12-06 23:55:28436 installed_extensions->InsertAll(blacklisted_extensions_);
[email protected]620b5a62013-11-18 04:21:08437 return installed_extensions.PassAs<ExtensionSet>();
[email protected]7f4308d2012-01-18 07:43:01438}
439
[email protected]3f213ad2012-07-26 23:39:41440extensions::PendingExtensionManager*
441 ExtensionService::pending_extension_manager() {
[email protected]b2907fd2011-03-25 16:43:37442 return &pending_extension_manager_;
[email protected]ddb1e5a2010-12-13 20:10:45443}
444
[email protected]eaa7dd182010-12-14 11:09:00445ExtensionService::~ExtensionService() {
[email protected]c8d407e2011-04-28 21:27:17446 // No need to unload extensions here because they are profile-scoped, and the
447 // profile is in the process of being deleted.
[email protected]94b4ffc2011-02-04 05:55:17448
[email protected]5df038b2012-07-16 19:03:27449 extensions::ProviderCollection::const_iterator i;
[email protected]8e4560b62011-01-14 10:09:14450 for (i = external_extension_providers_.begin();
451 i != external_extension_providers_.end(); ++i) {
[email protected]5df038b2012-07-16 19:03:27452 extensions::ExternalProviderInterface* provider = i->get();
[email protected]8e4560b62011-01-14 10:09:14453 provider->ServiceShutdown();
454 }
[email protected]6014d672008-12-05 00:38:25455}
456
[email protected]037228a2012-10-05 01:36:16457void ExtensionService::Shutdown() {
[email protected]4c9201c42013-08-16 04:56:21458 system_->management_policy()->UnregisterProvider(
459 shared_module_policy_provider_.get());
[email protected]037228a2012-10-05 01:36:16460}
461
[email protected]b2907fd2011-03-25 16:43:37462const Extension* ExtensionService::GetExtensionById(
463 const std::string& id, bool include_disabled) const {
[email protected]81f0d162012-08-15 04:21:47464 int include_mask = INCLUDE_ENABLED;
[email protected]695b5712012-12-06 23:55:28465 if (include_disabled) {
466 // Include blacklisted extensions here because there are hundreds of
467 // callers of this function, and many might assume that this includes those
468 // that have been disabled due to blacklisting.
[email protected]d2fff5d2013-12-11 02:49:19469 include_mask |= INCLUDE_DISABLED | INCLUDE_BLACKLISTED;
[email protected]695b5712012-12-06 23:55:28470 }
471 return GetExtensionById(id, include_mask);
472}
473
[email protected]399583b2012-12-11 09:33:42474GURL ExtensionService::GetSiteForExtensionId(const std::string& extension_id) {
475 return content::SiteInstance::GetSiteForURL(
476 profile_,
477 Extension::GetBaseURLFromExtensionId(extension_id));
478}
479
[email protected]695b5712012-12-06 23:55:28480const Extension* ExtensionService::GetExtensionById(
481 const std::string& id, int include_mask) const {
482 std::string lowercase_id = StringToLowerASCII(id);
483 if (include_mask & INCLUDE_ENABLED) {
484 const Extension* extension = extensions_.GetByID(lowercase_id);
485 if (extension)
486 return extension;
487 }
488 if (include_mask & INCLUDE_DISABLED) {
489 const Extension* extension = disabled_extensions_.GetByID(lowercase_id);
490 if (extension)
491 return extension;
492 }
493 if (include_mask & INCLUDE_TERMINATED) {
494 const Extension* extension = terminated_extensions_.GetByID(lowercase_id);
495 if (extension)
496 return extension;
497 }
498 if (include_mask & INCLUDE_BLACKLISTED) {
499 const Extension* extension = blacklisted_extensions_.GetByID(lowercase_id);
500 if (extension)
501 return extension;
502 }
503 return NULL;
[email protected]78994ab02010-12-08 18:06:44504}
505
[email protected]eaa7dd182010-12-14 11:09:00506void ExtensionService::Init() {
[email protected]a29a517a2011-01-21 21:11:12507 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]a8af9fdb2010-10-28 21:52:20508
[email protected]3350d712013-11-18 09:32:24509 base::Time begin_time = base::Time::Now();
510
[email protected]4a10006a2013-05-17 23:18:35511 DCHECK(!is_ready()); // Can't redo init.
[email protected]93fd78f42009-07-10 16:43:17512 DCHECK_EQ(extensions_.size(), 0u);
[email protected]9f1087e2009-06-15 17:29:32513
[email protected]820d9bd2013-04-03 03:46:03514 const CommandLine* cmd_line = CommandLine::ForCurrentProcess();
[email protected]820d9bd2013-04-03 03:46:03515 if (cmd_line->HasSwitch(switches::kInstallFromWebstore) ||
516 cmd_line->HasSwitch(switches::kLimitedInstallFromWebstore)) {
517 // The sole purpose of this launch is to install a new extension from CWS
518 // and immediately terminate: loading already installed extensions is
519 // unnecessary and may interfere with the inline install dialog (e.g. if an
520 // extension listens to onStartup and opens a window).
521 SetReadyAndNotifyListeners();
[email protected]ae4c37e2012-12-21 01:16:25522 } else {
[email protected]47b60072013-06-20 10:35:56523 // LoadAllExtensions() calls OnLoadedInstalledExtensions().
524 component_loader_->LoadAll();
525 extensions::InstalledLoader(this).LoadAllExtensions();
[email protected]9f4e4f082013-06-21 07:11:19526
[email protected]59ee99d2013-10-11 15:46:16527 ReconcileKnownDisabled();
528
[email protected]2edd57852013-08-14 22:07:40529 // Attempt to re-enable extensions whose only disable reason is reloading.
530 std::vector<std::string> extensions_to_enable;
531 for (ExtensionSet::const_iterator iter = disabled_extensions_.begin();
532 iter != disabled_extensions_.end(); ++iter) {
533 const Extension* e = iter->get();
534 if (extension_prefs_->GetDisableReasons(e->id()) ==
535 Extension::DISABLE_RELOAD) {
536 extensions_to_enable.push_back(e->id());
537 }
538 }
539 for (std::vector<std::string>::iterator it = extensions_to_enable.begin();
540 it != extensions_to_enable.end(); ++it) {
541 EnableExtension(*it);
542 }
543
[email protected]9f4e4f082013-06-21 07:11:19544 // Finish install (if possible) of extensions that were still delayed while
545 // the browser was shut down.
546 scoped_ptr<extensions::ExtensionPrefs::ExtensionsInfo> delayed_info(
547 extension_prefs_->GetAllDelayedInstallInfo());
548 for (size_t i = 0; i < delayed_info->size(); ++i) {
549 ExtensionInfo* info = delayed_info->at(i).get();
550 scoped_refptr<const Extension> extension(NULL);
551 if (info->extension_manifest) {
552 std::string error;
553 extension = Extension::Create(
554 info->extension_path,
555 info->extension_location,
556 *info->extension_manifest,
557 extension_prefs_->GetDelayedInstallCreationFlags(
558 info->extension_id),
559 info->extension_id,
560 &error);
561 if (extension.get())
562 delayed_installs_.Insert(extension);
563 }
564 }
565 MaybeFinishDelayedInstallations();
566
567 scoped_ptr<extensions::ExtensionPrefs::ExtensionsInfo> delayed_info2(
568 extension_prefs_->GetAllDelayedInstallInfo());
569 UMA_HISTOGRAM_COUNTS_100("Extensions.UpdateOnLoad",
570 delayed_info2->size() - delayed_info->size());
571
[email protected]47b60072013-06-20 10:35:56572 SetReadyAndNotifyListeners();
[email protected]ae4c37e2012-12-21 01:16:25573
[email protected]47b60072013-06-20 10:35:56574 // TODO(erikkay) this should probably be deferred to a future point
575 // rather than running immediately at startup.
576 CheckForExternalUpdates();
[email protected]894bb502009-05-21 22:39:57577
[email protected]68e5cc72013-12-17 02:41:53578 InstallVerifier* verifier =
579 extensions::ExtensionSystem::Get(profile_)->install_verifier();
580 if (verifier->NeedsBootstrap())
581 VerifyAllExtensions();
582
[email protected]47b60072013-06-20 10:35:56583 base::MessageLoop::current()->PostDelayedTask(
584 FROM_HERE,
585 base::Bind(&ExtensionService::GarbageCollectExtensions, AsWeakPtr()),
586 base::TimeDelta::FromSeconds(kGarbageCollectStartupDelay));
[email protected]215a7be2012-10-22 19:53:42587
[email protected]820d9bd2013-04-03 03:46:03588 if (extension_prefs_->NeedsStorageGarbageCollection()) {
589 GarbageCollectIsolatedStorage();
590 extension_prefs_->SetNeedsStorageGarbageCollection(false);
591 }
[email protected]4c9201c42013-08-16 04:56:21592 system_->management_policy()->RegisterProvider(
593 shared_module_policy_provider_.get());
[email protected]399583b2012-12-11 09:33:42594 }
[email protected]3350d712013-11-18 09:32:24595
596 UMA_HISTOGRAM_TIMES("Extensions.ExtensionServiceInitTime",
597 base::Time::Now() - begin_time);
[email protected]6014d672008-12-05 00:38:25598}
599
[email protected]68e5cc72013-12-17 02:41:53600void ExtensionService::VerifyAllExtensions() {
601 ExtensionIdSet to_add;
602 scoped_ptr<ExtensionSet> all_extensions = GenerateInstalledExtensionsSet();
603
604 for (ExtensionSet::const_iterator i = all_extensions->begin();
605 i != all_extensions->end(); ++i) {
606 const Extension& extension = **i;
607
608 if (extensions::ManifestURL::UpdatesFromGallery(&extension) &&
609 extension.is_extension())
610 to_add.insert(extension.id());
611 }
612 extensions::ExtensionSystem::Get(profile_)->install_verifier()->AddMany(
613 to_add, base::Bind(&ExtensionService::FinishVerifyAllExtensions,
614 AsWeakPtr()));
615}
616
617void ExtensionService::FinishVerifyAllExtensions(bool success) {
618 if (success) {
619 // Check to see if any currently unverified extensions became verified.
620 InstallVerifier* verifier =
621 extensions::ExtensionSystem::Get(profile_)->install_verifier();
622 for (ExtensionSet::const_iterator i = disabled_extensions_.begin();
623 i != disabled_extensions_.end(); ++i) {
624 const Extension& extension = **i;
625 int disable_reasons = extension_prefs_->GetDisableReasons(extension.id());
626 if (disable_reasons & Extension::DISABLE_NOT_VERIFIED &&
627 !verifier->MustRemainDisabled(&extension, NULL, NULL)) {
628 extension_prefs_->RemoveDisableReason(extension.id(),
629 Extension::DISABLE_NOT_VERIFIED);
630 // Notify interested observers (eg the extensions settings page) by
631 // sending an UNLOADED notification.
632 //
633 // TODO(asargent) - this is a slight hack because it's already
634 // disabled; the right solution might be to add a separate listener
635 // interface for DisableReason's changing. http://crbug.com/328916
636 UnloadedExtensionInfo details(&extension,
637 UnloadedExtensionInfo::REASON_DISABLE);
638 content::NotificationService::current()->Notify(
639 chrome::NOTIFICATION_EXTENSION_UNLOADED,
640 content::Source<Profile>(profile_),
641 content::Details<UnloadedExtensionInfo>(&details));
642 }
643 }
644 // Might disable some extensions.
645 CheckManagementPolicy();
646 }
647}
648
[email protected]31bb5ee62012-09-12 22:58:40649bool ExtensionService::UpdateExtension(const std::string& id,
[email protected]650b2d52013-02-10 03:41:45650 const base::FilePath& extension_path,
[email protected]31bb5ee62012-09-12 22:58:40651 const GURL& download_url,
652 CrxInstaller** out_crx_installer) {
[email protected]a29a517a2011-01-21 21:11:12653 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]3c4abc82012-10-22 22:25:54654 if (browser_terminating_) {
655 LOG(WARNING) << "Skipping UpdateExtension due to browser shutdown";
656 // Leak the temp file at extension_path. We don't want to add to the disk
657 // I/O burden at shutdown, we can't rely on the I/O completing anyway, and
658 // the file is in the OS temp directory which should be cleaned up for us.
659 return false;
660 }
[email protected]a8af9fdb2010-10-28 21:52:20661
[email protected]3f213ad2012-07-26 23:39:41662 const extensions::PendingExtensionInfo* pending_extension_info =
[email protected]51a3bf8b2012-06-08 22:53:06663 pending_extension_manager()->GetById(id);
[email protected]8ef78fd2010-08-19 17:14:32664
[email protected]695b5712012-12-06 23:55:28665 const Extension* extension = GetInstalledExtension(id);
[email protected]51a3bf8b2012-06-08 22:53:06666 if (!pending_extension_info && !extension) {
[email protected]aa142702010-03-26 01:26:33667 LOG(WARNING) << "Will not update extension " << id
668 << " because it is not installed or pending";
669 // Delete extension_path since we're not creating a CrxInstaller
670 // that would do it for us.
[email protected]7f8f24f2012-11-15 19:40:14671 if (!GetFileTaskRunner()->PostTask(
672 FROM_HERE,
[email protected]53612e82011-10-18 18:00:36673 base::Bind(
[email protected]7296f2762011-11-21 19:23:44674 &extension_file_util::DeleteFile, extension_path, false)))
[email protected]14908b72011-04-20 06:54:36675 NOTREACHED();
[email protected]420a0ec2011-06-01 01:07:03676
677 return false;
[email protected]e957fe52009-06-23 16:51:05678 }
679
[email protected]aa142702010-03-26 01:26:33680 // We want a silent install only for non-pending extensions and
681 // pending extensions that have install_silently set.
[email protected]f8636f92013-08-09 21:02:37682 scoped_ptr<ExtensionInstallPrompt> client;
[email protected]91e51d612012-10-21 23:03:05683 if (pending_extension_info && !pending_extension_info->install_silently())
[email protected]f8636f92013-08-09 21:02:37684 client.reset(ExtensionInstallUI::CreateInstallPromptWithProfile(profile_));
[email protected]aa142702010-03-26 01:26:33685
[email protected]f8636f92013-08-09 21:02:37686 scoped_refptr<CrxInstaller> installer(
687 CrxInstaller::Create(this, client.Pass()));
[email protected]6dfbbf82010-03-12 23:09:16688 installer->set_expected_id(id);
[email protected]464213a2013-10-15 01:06:48689 int creation_flags = Extension::NO_FLAGS;
[email protected]51a3bf8b2012-06-08 22:53:06690 if (pending_extension_info) {
691 installer->set_install_source(pending_extension_info->install_source());
692 if (pending_extension_info->install_silently())
693 installer->set_allow_silent_install(true);
[email protected]464213a2013-10-15 01:06:48694 creation_flags = pending_extension_info->creation_flags();
695 if (pending_extension_info->mark_acknowledged())
696 AcknowledgeExternalExtension(id);
[email protected]51a3bf8b2012-06-08 22:53:06697 } else if (extension) {
[email protected]5eb375e92010-11-26 07:50:41698 installer->set_install_source(extension->location());
[email protected]51a3bf8b2012-06-08 22:53:06699 }
[email protected]7d8b7072012-04-07 01:07:46700 // If the extension was installed from or has migrated to the webstore, or
[email protected]fcb2c2c2012-10-17 21:08:45701 // its auto-update URL is from the webstore, treat it as a webstore install.
702 // Note that we ignore some older extensions with blank auto-update URLs
703 // because we are mostly concerned with restrictions on NaCl extensions,
704 // which are newer.
[email protected]75764512011-12-19 19:54:28705 if ((extension && extension->from_webstore()) ||
[email protected]4a5fe3e22013-06-04 07:06:38706 (extension && extensions::ManifestURL::UpdatesFromGallery(extension)) ||
[email protected]963d13c2012-09-29 17:13:35707 (!extension && extension_urls::IsWebstoreUpdateUrl(
[email protected]51a3bf8b2012-06-08 22:53:06708 pending_extension_info->update_url()))) {
[email protected]a12ce8b22012-01-17 18:40:53709 creation_flags |= Extension::FROM_WEBSTORE;
710 }
711
712 // Bookmark apps being updated is kind of a contradiction, but that's because
713 // we mark the default apps as bookmark apps, and they're hosted in the web
714 // store, thus they can get updated. See http://crbug.com/101605 for more
715 // details.
716 if (extension && extension->from_bookmark())
717 creation_flags |= Extension::FROM_BOOKMARK;
718
[email protected]e33bbc22012-08-27 22:05:46719 if (extension && extension->was_installed_by_default())
720 creation_flags |= Extension::WAS_INSTALLED_BY_DEFAULT;
721
[email protected]a12ce8b22012-01-17 18:40:53722 installer->set_creation_flags(creation_flags);
723
[email protected]6dfbbf82010-03-12 23:09:16724 installer->set_delete_source(true);
[email protected]655b2b1a2011-10-13 17:13:06725 installer->set_download_url(download_url);
[email protected]cb0e50312011-05-09 15:03:07726 installer->set_install_cause(extension_misc::INSTALL_CAUSE_UPDATE);
[email protected]6dfbbf82010-03-12 23:09:16727 installer->InstallCrx(extension_path);
[email protected]420a0ec2011-06-01 01:07:03728
729 if (out_crx_installer)
[email protected]dc24976f2013-06-02 21:15:09730 *out_crx_installer = installer.get();
[email protected]420a0ec2011-06-01 01:07:03731
732 return true;
[email protected]e957fe52009-06-23 16:51:05733}
734
[email protected]e178ad92013-06-28 02:29:25735void ExtensionService::ReloadExtension(const std::string extension_id) {
[email protected]a29a517a2011-01-21 21:11:12736 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]2a947202013-03-06 04:58:05737
738 // If the extension is already reloading, don't reload again.
739 if (extension_prefs_->GetDisableReasons(extension_id) &
740 Extension::DISABLE_RELOAD) {
741 return;
742 }
743
[email protected]650b2d52013-02-10 03:41:45744 base::FilePath path;
[email protected]9adb9692010-10-29 23:14:02745 const Extension* current_extension = GetExtensionById(extension_id, false);
[email protected]9cddd4702009-07-27 22:09:40746
[email protected]f17dbd42010-08-16 23:21:10747 // Disable the extension if it's loaded. It might not be loaded if it crashed.
[email protected]b65272f2009-08-31 15:47:06748 if (current_extension) {
[email protected]4814b512009-11-07 00:12:29749 // If the extension has an inspector open for its background page, detach
750 // the inspector and hang onto a cookie for it, so that we can reattach
751 // later.
[email protected]31d8f5f22012-04-02 15:22:08752 // TODO(yoz): this is not incognito-safe!
[email protected]98b6d942013-11-10 00:34:07753 extensions::ProcessManager* manager = system_->process_manager();
[email protected]3a1dc572012-07-31 22:25:13754 extensions::ExtensionHost* host =
755 manager->GetBackgroundHostForExtension(extension_id);
[email protected]98f66112012-12-25 12:59:36756 if (host && DevToolsAgentHost::HasFor(host->render_view_host())) {
[email protected]4814b512009-11-07 00:12:29757 // Look for an open inspector for the background page.
[email protected]04ea1bb2013-07-10 09:26:09758 scoped_refptr<DevToolsAgentHost> agent_host =
759 DevToolsAgentHost::GetOrCreateFor(host->render_view_host());
760 agent_host->DisconnectRenderViewHost();
761 orphaned_dev_tools_[extension_id] = agent_host;
[email protected]4814b512009-11-07 00:12:29762 }
763
[email protected]b65272f2009-08-31 15:47:06764 path = current_extension->path();
[email protected]58076192013-07-19 19:43:50765 // BeingUpgraded is set back to false when the extension is added.
766 SetBeingUpgraded(current_extension, true);
[email protected]44d62b62012-04-11 00:06:03767 DisableExtension(extension_id, Extension::DISABLE_RELOAD);
[email protected]b914e2952013-04-26 07:10:03768 reloading_extensions_.insert(extension_id);
[email protected]1eb175082010-02-10 09:26:16769 } else {
770 path = unloaded_extension_paths_[extension_id];
[email protected]b65272f2009-08-31 15:47:06771 }
772
[email protected]9f4e4f082013-06-21 07:11:19773 if (delayed_installs_.Contains(extension_id)) {
[email protected]6f6101832012-11-27 22:10:48774 FinishDelayedInstallation(extension_id);
[email protected]0db124b02012-11-07 04:55:05775 return;
776 }
777
[email protected]43ceb002012-02-10 23:19:15778 // If we're reloading a component extension, use the component extension
779 // loader's reloader.
780 if (component_loader_->Exists(extension_id)) {
[email protected]e178ad92013-06-28 02:29:25781 SetBeingReloaded(extension_id, true);
[email protected]43ceb002012-02-10 23:19:15782 component_loader_->Reload(extension_id);
[email protected]e178ad92013-06-28 02:29:25783 SetBeingReloaded(extension_id, false);
[email protected]43ceb002012-02-10 23:19:15784 return;
785 }
786
[email protected]e6090e42010-03-23 22:44:08787 // Check the installed extensions to see if what we're reloading was already
788 // installed.
[email protected]e178ad92013-06-28 02:29:25789 SetBeingReloaded(extension_id, true);
[email protected]e6090e42010-03-23 22:44:08790 scoped_ptr<ExtensionInfo> installed_extension(
791 extension_prefs_->GetInstalledExtensionInfo(extension_id));
792 if (installed_extension.get() &&
793 installed_extension->extension_manifest.get()) {
[email protected]d8c8f25f2011-11-02 18:18:01794 extensions::InstalledLoader(this).Load(*installed_extension, false);
[email protected]e6090e42010-03-23 22:44:08795 } else {
[email protected]d8c8f25f2011-11-02 18:18:01796 // Otherwise, the extension is unpacked (location LOAD).
[email protected]e6090e42010-03-23 22:44:08797 // We should always be able to remember the extension's path. If it's not in
798 // the map, someone failed to update |unloaded_extension_paths_|.
799 CHECK(!path.empty());
[email protected]d8c8f25f2011-11-02 18:18:01800 extensions::UnpackedInstaller::Create(this)->Load(path);
[email protected]e6090e42010-03-23 22:44:08801 }
[email protected]e178ad92013-06-28 02:29:25802 // When reloading is done, mark this extension as done reloading.
803 SetBeingReloaded(extension_id, false);
[email protected]9cddd4702009-07-27 22:09:40804}
805
[email protected]fa2416f2011-05-03 08:41:20806bool ExtensionService::UninstallExtension(
[email protected]a12c706e2011-12-01 00:58:08807 std::string extension_id,
[email protected]fa2416f2011-05-03 08:41:20808 bool external_uninstall,
[email protected]439f1e32013-12-09 20:09:09809 base::string16* error) {
[email protected]a29a517a2011-01-21 21:11:12810 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]a8af9fdb2010-10-28 21:52:20811
[email protected]0d6ec3a72011-09-02 02:09:43812 scoped_refptr<const Extension> extension(GetInstalledExtension(extension_id));
[email protected]631cf822009-05-15 07:01:25813
[email protected]e7afe2452010-08-22 16:19:13814 // Callers should not send us nonexistent extensions.
[email protected]dc24976f2013-06-02 21:15:09815 CHECK(extension.get());
[email protected]9f1087e2009-06-15 17:29:32816
[email protected]95da88c42011-03-31 10:07:33817 // Policy change which triggers an uninstall will always set
818 // |external_uninstall| to true so this is the only way to uninstall
819 // managed extensions.
[email protected]65187152012-06-02 13:14:14820 if (!external_uninstall &&
821 !system_->management_policy()->UserMayModifySettings(
822 extension.get(), error)) {
[email protected]ad50def52011-10-19 23:17:07823 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:27824 chrome::NOTIFICATION_EXTENSION_UNINSTALL_NOT_ALLOWED,
[email protected]6c2381d2011-10-19 02:52:53825 content::Source<Profile>(profile_),
[email protected]dc24976f2013-06-02 21:15:09826 content::Details<const Extension>(extension.get()));
[email protected]d6ebc9792011-04-07 18:18:33827 return false;
828 }
[email protected]95da88c42011-03-31 10:07:33829
[email protected]65f173552012-06-28 22:43:58830 syncer::SyncChange sync_change;
[email protected]f8aefb132013-10-30 09:29:52831 if (extension_sync_service_) {
832 sync_change = extension_sync_service_->PrepareToSyncUninstallExtension(
833 extension.get(), is_ready());
[email protected]3bdba0d2011-08-23 07:17:30834 }
835
[email protected]ffd2f79e2013-11-14 00:11:46836 extensions::ExtensionSystem::Get(profile_)->install_verifier()->Remove(
837 extension->id());
838
[email protected]dc24976f2013-06-02 21:15:09839 if (IsUnacknowledgedExternalExtension(extension.get())) {
[email protected]d96eb512012-11-01 23:44:08840 UMA_HISTOGRAM_ENUMERATION("Extensions.ExternalExtensionEvent",
841 EXTERNAL_EXTENSION_UNINSTALLED,
842 EXTERNAL_EXTENSION_BUCKET_BOUNDARY);
[email protected]446e37e2013-08-07 00:30:02843 if (extensions::ManifestURL::UpdatesFromGallery(extension.get())) {
844 UMA_HISTOGRAM_ENUMERATION("Extensions.ExternalExtensionEventWebstore",
845 EXTERNAL_EXTENSION_UNINSTALLED,
846 EXTERNAL_EXTENSION_BUCKET_BOUNDARY);
847 } else {
848 UMA_HISTOGRAM_ENUMERATION("Extensions.ExternalExtensionEventNonWebstore",
849 EXTERNAL_EXTENSION_UNINSTALLED,
850 EXTERNAL_EXTENSION_BUCKET_BOUNDARY);
851 }
[email protected]d96eb512012-11-01 23:44:08852 }
[email protected]9b217652010-10-08 22:04:23853 UMA_HISTOGRAM_ENUMERATION("Extensions.UninstallType",
[email protected]7fa19f82010-12-21 19:40:08854 extension->GetType(), 100);
[email protected]dc24976f2013-06-02 21:15:09855 RecordPermissionMessagesHistogram(extension.get(),
856 "Extensions.Permissions_Uninstall");
[email protected]9b217652010-10-08 22:04:23857
[email protected]831aa212010-03-26 13:55:19858 // Unload before doing more cleanup to ensure that nothing is hanging on to
859 // any of these resources.
[email protected]b0af4792013-10-23 09:12:13860 UnloadExtension(extension_id, UnloadedExtensionInfo::REASON_UNINSTALL);
[email protected]831aa212010-03-26 13:55:19861
[email protected]9f1087e2009-06-15 17:29:32862 // Tell the backend to start deleting installed extensions on the file thread.
[email protected]12075d12013-02-27 05:38:05863 if (!Manifest::IsUnpackedLocation(extension->location())) {
[email protected]7f8f24f2012-11-15 19:40:14864 if (!GetFileTaskRunner()->PostTask(
865 FROM_HERE,
[email protected]53612e82011-10-18 18:00:36866 base::Bind(
[email protected]14908b72011-04-20 06:54:36867 &extension_file_util::UninstallExtension,
868 install_directory_,
[email protected]fa2416f2011-05-03 08:41:20869 extension_id)))
[email protected]14908b72011-04-20 06:54:36870 NOTREACHED();
[email protected]9f1087e2009-06-15 17:29:32871 }
872
[email protected]6b414c232013-06-05 07:53:34873 GURL launch_web_url_origin(
[email protected]cadac622013-06-11 16:46:36874 extensions::AppLaunchInfo::GetLaunchWebURL(extension.get()).GetOrigin());
[email protected]561e33d52013-04-03 06:58:43875 bool is_storage_isolated =
[email protected]dc24976f2013-06-02 21:15:09876 extensions::AppIsolationInfo::HasIsolatedStorage(extension.get());
[email protected]0d6ec3a72011-09-02 02:09:43877
[email protected]399583b2012-12-11 09:33:42878 if (is_storage_isolated) {
879 BrowserContext::AsyncObliterateStoragePartition(
880 profile_,
881 GetSiteForExtensionId(extension_id),
882 base::Bind(&ExtensionService::OnNeedsToGarbageCollectIsolatedStorage,
883 AsWeakPtr()));
884 } else {
885 if (extension->is_hosted_app() &&
886 !profile_->GetExtensionSpecialStoragePolicy()->
887 IsStorageProtected(launch_web_url_origin)) {
888 extensions::DataDeleter::StartDeleting(
889 profile_, extension_id, launch_web_url_origin);
890 }
891 extensions::DataDeleter::StartDeleting(profile_, extension_id,
892 extension->url());
[email protected]0d6ec3a72011-09-02 02:09:43893 }
[email protected]0d6ec3a72011-09-02 02:09:43894
[email protected]0dfe05c2011-02-23 23:03:36895 UntrackTerminatedExtension(extension_id);
[email protected]211030342010-09-30 18:41:06896
897 // Notify interested parties that we've uninstalled this extension.
[email protected]ad50def52011-10-19 23:17:07898 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:27899 chrome::NOTIFICATION_EXTENSION_UNINSTALLED,
[email protected]6c2381d2011-10-19 02:52:53900 content::Source<Profile>(profile_),
[email protected]dc24976f2013-06-02 21:15:09901 content::Details<const Extension>(extension.get()));
[email protected]d6ebc9792011-04-07 18:18:33902
[email protected]f8aefb132013-10-30 09:29:52903 if (extension_sync_service_) {
904 extension_sync_service_->ProcessSyncUninstallExtension(extension_id,
905 sync_change);
[email protected]3bdba0d2011-08-23 07:17:30906 }
907
[email protected]399583b2012-12-11 09:33:42908 delayed_installs_.Remove(extension_id);
[email protected]0db124b02012-11-07 04:55:05909
[email protected]198b5902013-06-27 10:36:11910 PruneSharedModulesOnUninstall(extension.get());
[email protected]9f4e4f082013-06-21 07:11:19911
[email protected]d4eda592013-09-18 03:37:57912 extension_prefs_->OnExtensionUninstalled(extension_id, extension->location(),
913 external_uninstall);
914
[email protected]333b1de2011-09-12 18:28:50915 // Track the uninstallation.
[email protected]49098f702011-10-13 03:47:18916 UMA_HISTOGRAM_ENUMERATION("Extensions.ExtensionUninstalled", 1, 2);
917
[email protected]d6ebc9792011-04-07 18:18:33918 return true;
[email protected]c10da4b02010-03-25 14:38:32919}
920
[email protected]c3cfb012011-04-06 22:07:35921bool ExtensionService::IsExtensionEnabled(
922 const std::string& extension_id) const {
[email protected]84df8332011-12-06 18:22:46923 if (extensions_.Contains(extension_id) ||
[email protected]dc9a74f72012-08-17 18:07:21924 terminated_extensions_.Contains(extension_id)) {
[email protected]36429da2011-07-11 20:25:18925 return true;
[email protected]dc9a74f72012-08-17 18:07:21926 }
[email protected]36429da2011-07-11 20:25:18927
[email protected]695b5712012-12-06 23:55:28928 if (disabled_extensions_.Contains(extension_id) ||
929 blacklisted_extensions_.Contains(extension_id)) {
[email protected]ad83ca242011-07-29 01:32:25930 return false;
[email protected]695b5712012-12-06 23:55:28931 }
[email protected]ad83ca242011-07-29 01:32:25932
933 // If the extension hasn't been loaded yet, check the prefs for it. Assume
934 // enabled unless otherwise noted.
935 return !extension_prefs_->IsExtensionDisabled(extension_id) &&
[email protected]f574c402012-12-04 23:20:31936 !extension_prefs_->IsExternalExtensionUninstalled(extension_id);
[email protected]c3cfb012011-04-06 22:07:35937}
938
939bool ExtensionService::IsExternalExtensionUninstalled(
940 const std::string& extension_id) const {
941 return extension_prefs_->IsExternalExtensionUninstalled(extension_id);
942}
943
[email protected]eaa7dd182010-12-14 11:09:00944void ExtensionService::EnableExtension(const std::string& extension_id) {
[email protected]a29a517a2011-01-21 21:11:12945 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]a8af9fdb2010-10-28 21:52:20946
[email protected]06f92562011-04-29 19:27:31947 if (IsExtensionEnabled(extension_id))
[email protected]0c6da502009-08-14 22:32:39948 return;
[email protected]0d54b682013-11-05 14:15:36949 const Extension* extension = disabled_extensions_.GetByID(extension_id);
950
951 ManagementPolicy* policy = system_->management_policy();
952 if (extension && policy->MustRemainDisabled(extension, NULL, NULL)) {
953 UMA_HISTOGRAM_COUNTS_100("Extensions.EnableDeniedByPolicy", 1);
954 return;
955 }
[email protected]0c6da502009-08-14 22:32:39956
[email protected]b3317ad2011-04-28 23:46:00957 extension_prefs_->SetExtensionState(extension_id, Extension::ENABLED);
[email protected]eb5e4f92012-08-15 23:33:28958 extension_prefs_->ClearDisableReasons(extension_id);
[email protected]1784e83a2009-09-08 21:01:52959
[email protected]06f92562011-04-29 19:27:31960 // This can happen if sync enables an extension that is not
961 // installed yet.
962 if (!extension)
963 return;
964
[email protected]d96eb512012-11-01 23:44:08965 if (IsUnacknowledgedExternalExtension(extension)) {
966 UMA_HISTOGRAM_ENUMERATION("Extensions.ExternalExtensionEvent",
967 EXTERNAL_EXTENSION_REENABLED,
968 EXTERNAL_EXTENSION_BUCKET_BOUNDARY);
[email protected]446e37e2013-08-07 00:30:02969 if (extensions::ManifestURL::UpdatesFromGallery(extension)) {
970 UMA_HISTOGRAM_ENUMERATION("Extensions.ExternalExtensionEventWebstore",
971 EXTERNAL_EXTENSION_REENABLED,
972 EXTERNAL_EXTENSION_BUCKET_BOUNDARY);
973 } else {
974 UMA_HISTOGRAM_ENUMERATION("Extensions.ExternalExtensionEventNonWebstore",
975 EXTERNAL_EXTENSION_REENABLED,
976 EXTERNAL_EXTENSION_BUCKET_BOUNDARY);
977 }
[email protected]612a1cb12012-10-17 13:18:03978 AcknowledgeExternalExtension(extension->id());
[email protected]d96eb512012-11-01 23:44:08979 }
[email protected]612a1cb12012-10-17 13:18:03980
[email protected]0c6da502009-08-14 22:32:39981 // Move it over to the enabled list.
[email protected]84df8332011-12-06 18:22:46982 extensions_.Insert(make_scoped_refptr(extension));
[email protected]195c1582013-10-29 18:42:23983 disabled_extensions_.Remove(extension->id());
[email protected]0c6da502009-08-14 22:32:39984
[email protected]62d30f42009-10-01 22:36:06985 NotifyExtensionLoaded(extension);
[email protected]3bdba0d2011-08-23 07:17:30986
[email protected]f74d7f32012-06-19 19:22:51987 // Notify listeners that the extension was enabled.
988 content::NotificationService::current()->Notify(
989 chrome::NOTIFICATION_EXTENSION_ENABLED,
990 content::Source<Profile>(profile_),
991 content::Details<const Extension>(extension));
992
[email protected]f8aefb132013-10-30 09:29:52993 if (extension_sync_service_)
994 extension_sync_service_->SyncEnableExtension(*extension);
[email protected]0c6da502009-08-14 22:32:39995}
996
[email protected]44d62b62012-04-11 00:06:03997void ExtensionService::DisableExtension(
998 const std::string& extension_id,
999 Extension::DisableReason disable_reason) {
[email protected]a29a517a2011-01-21 21:11:121000 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]a8af9fdb2010-10-28 21:52:201001
[email protected]b2ba9962009-12-10 20:10:151002 // The extension may have been disabled already.
[email protected]06f92562011-04-29 19:27:311003 if (!IsExtensionEnabled(extension_id))
[email protected]1784e83a2009-09-08 21:01:521004 return;
[email protected]1784e83a2009-09-08 21:01:521005
[email protected]06f92562011-04-29 19:27:311006 const Extension* extension = GetInstalledExtension(extension_id);
1007 // |extension| can be NULL if sync disables an extension that is not
1008 // installed yet.
[email protected]65187152012-06-02 13:14:141009 if (extension &&
[email protected]505ccdc2013-06-20 20:15:351010 disable_reason != Extension::DISABLE_RELOAD &&
[email protected]65187152012-06-02 13:14:141011 !system_->management_policy()->UserMayModifySettings(extension, NULL)) {
[email protected]95da88c42011-03-31 10:07:331012 return;
[email protected]65187152012-06-02 13:14:141013 }
[email protected]95da88c42011-03-31 10:07:331014
[email protected]b3317ad2011-04-28 23:46:001015 extension_prefs_->SetExtensionState(extension_id, Extension::DISABLED);
[email protected]eb5e4f92012-08-15 23:33:281016 extension_prefs_->AddDisableReason(extension_id, disable_reason);
[email protected]1784e83a2009-09-08 21:01:521017
[email protected]695b5712012-12-06 23:55:281018 int include_mask = INCLUDE_EVERYTHING & ~INCLUDE_DISABLED;
1019 extension = GetExtensionById(extension_id, include_mask);
[email protected]06f92562011-04-29 19:27:311020 if (!extension)
1021 return;
1022
[email protected]64742de32013-04-22 08:44:341023 // Reset the background_page_ready flag
1024 if (extensions::BackgroundInfo::HasBackgroundPage(extension))
1025 extension_runtime_data_[extension->id()].background_page_ready = false;
1026
[email protected]5c094792012-09-07 19:44:531027 // Move it over to the disabled list. Don't send a second unload notification
1028 // for terminated extensions being disabled.
[email protected]195c1582013-10-29 18:42:231029 disabled_extensions_.Insert(make_scoped_refptr(extension));
[email protected]5c094792012-09-07 19:44:531030 if (extensions_.Contains(extension->id())) {
[email protected]84df8332011-12-06 18:22:461031 extensions_.Remove(extension->id());
[email protected]b0af4792013-10-23 09:12:131032 NotifyExtensionUnloaded(extension, UnloadedExtensionInfo::REASON_DISABLE);
[email protected]5c094792012-09-07 19:44:531033 } else {
[email protected]84df8332011-12-06 18:22:461034 terminated_extensions_.Remove(extension->id());
[email protected]5c094792012-09-07 19:44:531035 }
[email protected]3bdba0d2011-08-23 07:17:301036
[email protected]f8aefb132013-10-30 09:29:521037 if (extension_sync_service_)
1038 extension_sync_service_->SyncDisableExtension(*extension);
[email protected]1784e83a2009-09-08 21:01:521039}
1040
[email protected]1abf05e2013-07-09 17:04:361041void ExtensionService::DisableUserExtensions(
1042 const std::vector<std::string>& except_ids) {
[email protected]e516e4c2013-06-12 17:41:141043 extensions::ManagementPolicy* management_policy =
1044 system_->management_policy();
1045 extensions::ExtensionList to_disable;
1046
1047 for (ExtensionSet::const_iterator extension = extensions_.begin();
1048 extension != extensions_.end(); ++extension) {
[email protected]198b5902013-06-27 10:36:111049 if (management_policy->UserMayModifySettings(extension->get(), NULL))
[email protected]e516e4c2013-06-12 17:41:141050 to_disable.push_back(*extension);
1051 }
1052 for (ExtensionSet::const_iterator extension = terminated_extensions_.begin();
1053 extension != terminated_extensions_.end(); ++extension) {
[email protected]198b5902013-06-27 10:36:111054 if (management_policy->UserMayModifySettings(extension->get(), NULL))
[email protected]e516e4c2013-06-12 17:41:141055 to_disable.push_back(*extension);
1056 }
1057
1058 for (extensions::ExtensionList::const_iterator extension = to_disable.begin();
1059 extension != to_disable.end(); ++extension) {
[email protected]3082fe32013-08-06 11:12:381060 if ((*extension)->was_installed_by_default() &&
1061 extension_urls::IsWebstoreUpdateUrl(
1062 extensions::ManifestURL::GetUpdateURL(*extension)))
1063 continue;
[email protected]1abf05e2013-07-09 17:04:361064 const std::string& id = (*extension)->id();
1065 if (except_ids.end() == std::find(except_ids.begin(), except_ids.end(), id))
1066 DisableExtension(id, extensions::Extension::DISABLE_USER_ACTION);
[email protected]e516e4c2013-06-12 17:41:141067 }
1068}
1069
[email protected]eaa7dd182010-12-14 11:09:001070void ExtensionService::GrantPermissionsAndEnableExtension(
[email protected]009633c2013-03-07 22:08:281071 const Extension* extension) {
1072 GrantPermissions(extension);
[email protected]fe2dd7742011-04-19 22:52:491073 RecordPermissionMessagesHistogram(
1074 extension, "Extensions.Permissions_ReEnable");
[email protected]8d888c12010-11-30 00:00:251075 extension_prefs_->SetDidExtensionEscalatePermissions(extension, false);
1076 EnableExtension(extension->id());
1077}
1078
[email protected]009633c2013-03-07 22:08:281079void ExtensionService::GrantPermissions(const Extension* extension) {
[email protected]be083862012-09-01 03:53:451080 CHECK(extension);
1081 extensions::PermissionsUpdater perms_updater(profile());
[email protected]009633c2013-03-07 22:08:281082 perms_updater.GrantActivePermissions(extension);
[email protected]be083862012-09-01 03:53:451083}
1084
[email protected]fe2dd7742011-04-19 22:52:491085// static
1086void ExtensionService::RecordPermissionMessagesHistogram(
[email protected]13c68b62013-05-17 11:29:051087 const Extension* extension, const char* histogram) {
[email protected]de415552013-01-23 04:12:171088 // Since this is called from multiple sources, and since the histogram macros
1089 // use statics, we need to manually lookup the histogram ourselves.
1090 base::HistogramBase* counter = base::LinearHistogram::FactoryGet(
[email protected]fe2dd7742011-04-19 22:52:491091 histogram,
1092 1,
[email protected]c2e66e12012-06-27 06:27:061093 PermissionMessage::kEnumBoundary,
1094 PermissionMessage::kEnumBoundary + 1,
[email protected]de415552013-01-23 04:12:171095 base::HistogramBase::kUmaTargetedHistogramFlag);
[email protected]fe2dd7742011-04-19 22:52:491096
[email protected]13c68b62013-05-17 11:29:051097 PermissionMessages permissions =
1098 extensions::PermissionsData::GetPermissionMessages(extension);
[email protected]fe2dd7742011-04-19 22:52:491099 if (permissions.empty()) {
[email protected]c2e66e12012-06-27 06:27:061100 counter->Add(PermissionMessage::kNone);
[email protected]fe2dd7742011-04-19 22:52:491101 } else {
[email protected]c2e66e12012-06-27 06:27:061102 for (PermissionMessages::iterator it = permissions.begin();
[email protected]0d3e4a22011-06-23 19:02:521103 it != permissions.end(); ++it)
1104 counter->Add(it->id());
[email protected]fe2dd7742011-04-19 22:52:491105 }
1106}
1107
[email protected]eaa7dd182010-12-14 11:09:001108void ExtensionService::NotifyExtensionLoaded(const Extension* extension) {
[email protected]57a777f72010-03-31 01:09:421109 // The ChromeURLRequestContexts need to be first to know that the extension
[email protected]62d30f42009-10-01 22:36:061110 // was loaded, otherwise a race can arise where a renderer that is created
1111 // for the extension may try to load an extension URL with an extension id
[email protected]57a777f72010-03-31 01:09:421112 // that the request context doesn't yet know about. The profile is responsible
1113 // for ensuring its URLRequestContexts appropriately discover the loaded
1114 // extension.
[email protected]31d8f5f22012-04-02 15:22:081115 system_->RegisterExtensionWithRequestContexts(extension);
[email protected]62d30f42009-10-01 22:36:061116
[email protected]d5949312012-12-03 22:13:301117 // Tell renderers about the new extension, unless it's a theme (renderers
1118 // don't need to know about themes).
[email protected]a58f599c2012-12-01 03:08:191119 if (!extension->is_theme()) {
[email protected]19647262011-12-16 09:57:491120 for (content::RenderProcessHost::iterator i(
1121 content::RenderProcessHost::AllHostsIterator());
1122 !i.IsAtEnd(); i.Advance()) {
1123 content::RenderProcessHost* host = i.GetCurrentValue();
1124 Profile* host_profile =
1125 Profile::FromBrowserContext(host->GetBrowserContext());
1126 if (host_profile->GetOriginalProfile() ==
1127 profile_->GetOriginalProfile()) {
1128 std::vector<ExtensionMsg_Loaded_Params> loaded_extensions(
1129 1, ExtensionMsg_Loaded_Params(extension));
1130 host->Send(
1131 new ExtensionMsg_Loaded(loaded_extensions));
1132 }
[email protected]c8d407e2011-04-28 21:27:171133 }
[email protected]77a6970c2011-04-23 16:58:561134 }
1135
[email protected]3442a662012-01-12 08:06:171136 // Tell subsystems that use the EXTENSION_LOADED notification about the new
1137 // extension.
1138 //
1139 // NOTE: It is important that this happen after notifying the renderers about
1140 // the new extensions so that if we navigate to an extension URL in
1141 // NOTIFICATION_EXTENSION_LOADED, the renderer is guaranteed to know about it.
1142 content::NotificationService::current()->Notify(
1143 chrome::NOTIFICATION_EXTENSION_LOADED,
1144 content::Source<Profile>(profile_),
1145 content::Details<const Extension>(extension));
1146
[email protected]c8d407e2011-04-28 21:27:171147 // Tell a random-ass collection of other subsystems about the new extension.
1148 // TODO(aa): What should we do with all this goop? Can it move into the
1149 // relevant objects via EXTENSION_LOADED?
1150
1151 profile_->GetExtensionSpecialStoragePolicy()->
1152 GrantRightsForExtension(extension);
1153
1154 UpdateActiveExtensionsInCrashReporter();
1155
[email protected]c8d407e2011-04-28 21:27:171156 // If the extension has permission to load chrome://favicon/ resources we need
1157 // to make sure that the FaviconSource is registered with the
1158 // ChromeURLDataManager.
[email protected]13c68b62013-05-17 11:29:051159 if (extensions::PermissionsData::HasHostPermission(
1160 extension, GURL(chrome::kChromeUIFaviconURL))) {
[email protected]c8d407e2011-04-28 21:27:171161 FaviconSource* favicon_source = new FaviconSource(profile_,
1162 FaviconSource::FAVICON);
[email protected]24ea7a12013-01-27 23:54:531163 content::URLDataSource::Add(profile_, favicon_source);
[email protected]c8d407e2011-04-28 21:27:171164 }
[email protected]b07e606e2012-09-15 20:16:151165
1166#if !defined(OS_ANDROID)
1167 // Same for chrome://theme/ resources.
[email protected]13c68b62013-05-17 11:29:051168 if (extensions::PermissionsData::HasHostPermission(
1169 extension, GURL(chrome::kChromeUIThemeURL))) {
[email protected]b07e606e2012-09-15 20:16:151170 ThemeSource* theme_source = new ThemeSource(profile_);
[email protected]24ea7a12013-01-27 23:54:531171 content::URLDataSource::Add(profile_, theme_source);
[email protected]b07e606e2012-09-15 20:16:151172 }
1173#endif
1174
[email protected]5eddc3e2011-10-26 04:33:311175 // Same for chrome://thumb/ resources.
[email protected]13c68b62013-05-17 11:29:051176 if (extensions::PermissionsData::HasHostPermission(
1177 extension, GURL(chrome::kChromeUIThumbnailURL))) {
[email protected]420e6d92013-09-17 01:48:511178 ThumbnailSource* thumbnail_source = new ThumbnailSource(profile_, false);
[email protected]24ea7a12013-01-27 23:54:531179 content::URLDataSource::Add(profile_, thumbnail_source);
[email protected]5eddc3e2011-10-26 04:33:311180 }
[email protected]62d30f42009-10-01 22:36:061181}
1182
[email protected]a9f39a312010-12-23 22:14:271183void ExtensionService::NotifyExtensionUnloaded(
[email protected]814a7bf0f2011-08-13 05:30:591184 const Extension* extension,
[email protected]b0af4792013-10-23 09:12:131185 UnloadedExtensionInfo::Reason reason) {
[email protected]a9f39a312010-12-23 22:14:271186 UnloadedExtensionInfo details(extension, reason);
[email protected]ad50def52011-10-19 23:17:071187 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271188 chrome::NOTIFICATION_EXTENSION_UNLOADED,
[email protected]6c2381d2011-10-19 02:52:531189 content::Source<Profile>(profile_),
1190 content::Details<UnloadedExtensionInfo>(&details));
[email protected]62d30f42009-10-01 22:36:061191
[email protected]f3b1a082011-11-18 00:34:301192 for (content::RenderProcessHost::iterator i(
1193 content::RenderProcessHost::AllHostsIterator());
[email protected]77a6970c2011-04-23 16:58:561194 !i.IsAtEnd(); i.Advance()) {
[email protected]f3b1a082011-11-18 00:34:301195 content::RenderProcessHost* host = i.GetCurrentValue();
[email protected]9b62ecf2011-07-27 20:23:081196 Profile* host_profile =
[email protected]f3b1a082011-11-18 00:34:301197 Profile::FromBrowserContext(host->GetBrowserContext());
[email protected]9b62ecf2011-07-27 20:23:081198 if (host_profile->GetOriginalProfile() == profile_->GetOriginalProfile())
[email protected]c8d407e2011-04-28 21:27:171199 host->Send(new ExtensionMsg_Unloaded(extension->id()));
[email protected]77a6970c2011-04-23 16:58:561200 }
1201
[email protected]31d8f5f22012-04-02 15:22:081202 system_->UnregisterExtensionWithRequestContexts(extension->id(), reason);
[email protected]c8d407e2011-04-28 21:27:171203 profile_->GetExtensionSpecialStoragePolicy()->
1204 RevokeRightsForExtension(extension);
1205
[email protected]b777b332011-04-16 04:01:081206#if defined(OS_CHROMEOS)
[email protected]ac66e452013-01-11 09:21:231207 // Revoke external file access for the extension from its file system context.
1208 // It is safe to access the extension's storage partition at this point. The
1209 // storage partition may get destroyed only after the extension gets unloaded.
1210 GURL site = extensions::ExtensionSystem::Get(profile_)->extension_service()->
1211 GetSiteForExtensionId(extension->id());
[email protected]10eb28162012-09-18 03:04:091212 fileapi::FileSystemContext* filesystem_context =
[email protected]ac66e452013-01-11 09:21:231213 BrowserContext::GetStoragePartitionForSite(profile_, site)->
[email protected]10eb28162012-09-18 03:04:091214 GetFileSystemContext();
[email protected]f19bbf62013-07-09 01:22:321215 if (filesystem_context && filesystem_context->external_backend()) {
1216 filesystem_context->external_backend()->
[email protected]c8d407e2011-04-28 21:27:171217 RevokeAccessForExtension(extension->id());
[email protected]62d30f42009-10-01 22:36:061218 }
[email protected]c8d407e2011-04-28 21:27:171219#endif
1220
1221 UpdateActiveExtensionsInCrashReporter();
[email protected]62d30f42009-10-01 22:36:061222}
1223
[email protected]0a071a32011-02-08 00:18:241224Profile* ExtensionService::profile() {
1225 return profile_;
1226}
1227
[email protected]45759612012-07-10 17:21:231228extensions::ExtensionPrefs* ExtensionService::extension_prefs() {
[email protected]ddb1e5a2010-12-13 20:10:451229 return extension_prefs_;
1230}
1231
[email protected]a7ff4b72013-10-17 20:56:021232const extensions::ExtensionPrefs* ExtensionService::extension_prefs() const {
1233 return extension_prefs_;
1234}
1235
[email protected]0d9a2202011-11-09 13:48:411236extensions::SettingsFrontend* ExtensionService::settings_frontend() {
[email protected]cccdf0aa2011-11-11 03:43:381237 return settings_frontend_.get();
[email protected]b7f853e282011-08-10 09:24:201238}
1239
[email protected]e2d720aa2012-05-17 00:11:351240extensions::ContentSettingsStore* ExtensionService::GetContentSettingsStore() {
[email protected]b790b072011-05-20 09:46:441241 return extension_prefs()->content_settings_store();
1242}
1243
[email protected]25ae0152011-11-18 14:40:021244bool ExtensionService::is_ready() {
[email protected]4a10006a2013-05-17 23:18:351245 return ready_->is_signaled();
[email protected]25ae0152011-11-18 14:40:021246}
1247
[email protected]7f8f24f2012-11-15 19:40:141248base::SequencedTaskRunner* ExtensionService::GetFileTaskRunner() {
[email protected]dc24976f2013-06-02 21:15:091249 if (file_task_runner_.get())
1250 return file_task_runner_.get();
[email protected]7f8f24f2012-11-15 19:40:141251
1252 // We should be able to interrupt any part of extension install process during
1253 // shutdown. SKIP_ON_SHUTDOWN ensures that not started extension install tasks
1254 // will be ignored/deleted while we will block on started tasks.
1255 std::string token("ext_install-");
1256 token.append(profile_->GetPath().AsUTF8Unsafe());
1257 file_task_runner_ = BrowserThread::GetBlockingPool()->
1258 GetSequencedTaskRunnerWithShutdownBehavior(
1259 BrowserThread::GetBlockingPool()->GetNamedSequenceToken(token),
1260 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN);
[email protected]dc24976f2013-06-02 21:15:091261 return file_task_runner_.get();
[email protected]7f8f24f2012-11-15 19:40:141262}
1263
[email protected]42a08162012-03-16 18:09:111264extensions::ExtensionUpdater* ExtensionService::updater() {
[email protected]2859946f2011-04-04 18:18:061265 return updater_.get();
1266}
1267
[email protected]4ee07c62012-08-21 12:40:421268void ExtensionService::CheckManagementPolicy() {
[email protected]0d54b682013-11-05 14:15:361269 std::vector<std::string> to_unload;
1270 std::map<std::string, Extension::DisableReason> to_disable;
[email protected]695b5712012-12-06 23:55:281271
[email protected]0d54b682013-11-05 14:15:361272 // Loop through the extensions list, finding extensions we need to unload or
1273 // disable.
[email protected]84df8332011-12-06 18:22:461274 for (ExtensionSet::const_iterator iter = extensions_.begin();
[email protected]aa96d3a2010-08-21 08:45:251275 iter != extensions_.end(); ++iter) {
[email protected]cadac622013-06-11 16:46:361276 const Extension* extension = (iter->get());
[email protected]4ee07c62012-08-21 12:40:421277 if (!system_->management_policy()->UserMayLoad(extension, NULL))
[email protected]0d54b682013-11-05 14:15:361278 to_unload.push_back(extension->id());
1279 Extension::DisableReason disable_reason = Extension::DISABLE_NONE;
1280 if (system_->management_policy()->MustRemainDisabled(
1281 extension, &disable_reason, NULL))
1282 to_disable[extension->id()] = disable_reason;
[email protected]aa96d3a2010-08-21 08:45:251283 }
1284
[email protected]0d54b682013-11-05 14:15:361285 for (size_t i = 0; i < to_unload.size(); ++i)
1286 UnloadExtension(to_unload[i], UnloadedExtensionInfo::REASON_DISABLE);
1287
1288 for (std::map<std::string, Extension::DisableReason>::const_iterator i =
1289 to_disable.begin(); i != to_disable.end(); ++i)
1290 DisableExtension(i->first, i->second);
[email protected]aa96d3a2010-08-21 08:45:251291}
1292
[email protected]31206602011-04-13 23:07:321293void ExtensionService::CheckForUpdatesSoon() {
[email protected]c3cfb012011-04-06 22:07:351294 if (updater()) {
[email protected]94fde232012-04-27 10:22:301295 if (AreAllExternalProvidersReady()) {
1296 updater()->CheckSoon();
1297 } else {
1298 // Sync can start updating before all the external providers are ready
1299 // during startup. Start the update as soon as those providers are ready,
1300 // but not before.
1301 update_once_all_providers_are_ready_ = true;
1302 }
[email protected]c3cfb012011-04-06 22:07:351303 } else {
[email protected]31206602011-04-13 23:07:321304 LOG(WARNING) << "CheckForUpdatesSoon() called with auto-update turned off";
[email protected]c3cfb012011-04-06 22:07:351305 }
1306}
1307
[email protected]168389f2011-12-20 17:12:481308void ExtensionService::OnExtensionMoved(
1309 const std::string& moved_extension_id,
1310 const std::string& predecessor_extension_id,
1311 const std::string& successor_extension_id) {
[email protected]74474042013-11-21 12:03:541312 extension_prefs_->app_sorting()->OnExtensionMoved(
[email protected]3569b502012-01-12 20:08:231313 moved_extension_id,
1314 predecessor_extension_id,
1315 successor_extension_id);
[email protected]168389f2011-12-20 17:12:481316
1317 const Extension* extension = GetInstalledExtension(moved_extension_id);
[email protected]f8aefb132013-10-30 09:29:521318 if (extension_sync_service_ && extension) {
1319 extension_sync_service_->SyncExtensionChangeIfNeeded(*extension);
1320 }
[email protected]168389f2011-12-20 17:12:481321}
1322
[email protected]8e4560b62011-01-14 10:09:141323// Some extensions will autoupdate themselves externally from Chrome. These
1324// are typically part of some larger client application package. To support
1325// these, the extension will register its location in the the preferences file
1326// (and also, on Windows, in the registry) and this code will periodically
1327// check that location for a .crx file, which it will then install locally if
1328// a new version is available.
1329// Errors are reported through ExtensionErrorReporter. Succcess is not
1330// reported.
[email protected]eaa7dd182010-12-14 11:09:001331void ExtensionService::CheckForExternalUpdates() {
[email protected]a29a517a2011-01-21 21:11:121332 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]8e4560b62011-01-14 10:09:141333
1334 // Note that this installation is intentionally silent (since it didn't
1335 // go through the front-end). Extensions that are registered in this
1336 // way are effectively considered 'pre-bundled', and so implicitly
1337 // trusted. In general, if something has HKLM or filesystem access,
1338 // they could install an extension manually themselves anyway.
[email protected]a29a517a2011-01-21 21:11:121339
[email protected]8e4560b62011-01-14 10:09:141340 // Ask each external extension provider to give us a call back for each
1341 // extension they know about. See OnExternalExtension(File|UpdateUrl)Found.
[email protected]5df038b2012-07-16 19:03:271342 extensions::ProviderCollection::const_iterator i;
[email protected]8e4560b62011-01-14 10:09:141343 for (i = external_extension_providers_.begin();
1344 i != external_extension_providers_.end(); ++i) {
[email protected]5df038b2012-07-16 19:03:271345 extensions::ExternalProviderInterface* provider = i->get();
[email protected]8e4560b62011-01-14 10:09:141346 provider->VisitRegisteredExtension();
1347 }
1348
[email protected]50067e52011-10-20 23:17:071349 // Do any required work that we would have done after completion of all
1350 // providers.
1351 if (external_extension_providers_.empty()) {
1352 OnAllExternalProvidersReady();
1353 }
[email protected]9f1087e2009-06-15 17:29:321354}
1355
[email protected]50067e52011-10-20 23:17:071356void ExtensionService::OnExternalProviderReady(
[email protected]5df038b2012-07-16 19:03:271357 const extensions::ExternalProviderInterface* provider) {
[email protected]a29a517a2011-01-21 21:11:121358 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]50067e52011-10-20 23:17:071359 CHECK(provider->IsReady());
[email protected]a29a517a2011-01-21 21:11:121360
1361 // An external provider has finished loading. We only take action
[email protected]8e4560b62011-01-14 10:09:141362 // if all of them are finished. So we check them first.
[email protected]94fde232012-04-27 10:22:301363 if (AreAllExternalProvidersReady())
1364 OnAllExternalProvidersReady();
1365}
1366
1367bool ExtensionService::AreAllExternalProvidersReady() const {
[email protected]5df038b2012-07-16 19:03:271368 extensions::ProviderCollection::const_iterator i;
[email protected]8e4560b62011-01-14 10:09:141369 for (i = external_extension_providers_.begin();
1370 i != external_extension_providers_.end(); ++i) {
[email protected]94fde232012-04-27 10:22:301371 if (!i->get()->IsReady())
1372 return false;
[email protected]8e4560b62011-01-14 10:09:141373 }
[email protected]94fde232012-04-27 10:22:301374 return true;
[email protected]50067e52011-10-20 23:17:071375}
1376
1377void ExtensionService::OnAllExternalProvidersReady() {
1378 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]94fde232012-04-27 10:22:301379 base::TimeDelta elapsed = base::Time::Now() - profile_->GetStartTime();
1380 UMA_HISTOGRAM_TIMES("Extension.ExternalProvidersReadyAfter", elapsed);
[email protected]50067e52011-10-20 23:17:071381
1382 // Install any pending extensions.
[email protected]94fde232012-04-27 10:22:301383 if (update_once_all_providers_are_ready_ && updater()) {
1384 update_once_all_providers_are_ready_ = false;
[email protected]4e9b59d2013-12-18 06:47:141385 extensions::ExtensionUpdater::CheckParams params;
1386 params.callback = external_updates_finished_callback_;
1387 updater()->CheckNow(params);
[email protected]8e4560b62011-01-14 10:09:141388 }
1389
1390 // Uninstall all the unclaimed extensions.
[email protected]45759612012-07-10 17:21:231391 scoped_ptr<extensions::ExtensionPrefs::ExtensionsInfo> extensions_info(
[email protected]8e4560b62011-01-14 10:09:141392 extension_prefs_->GetInstalledExtensionsInfo());
1393 for (size_t i = 0; i < extensions_info->size(); ++i) {
1394 ExtensionInfo* info = extensions_info->at(i).get();
[email protected]1d5e58b2013-01-31 08:41:401395 if (Manifest::IsExternalLocation(info->extension_location))
[email protected]8e4560b62011-01-14 10:09:141396 CheckExternalUninstall(info->extension_id);
1397 }
[email protected]e5af875f2011-10-10 21:09:141398 IdentifyAlertableExtensions();
[email protected]e5af875f2011-10-10 21:09:141399}
1400
1401void ExtensionService::IdentifyAlertableExtensions() {
1402 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1403
[email protected]07c9f2f42012-02-29 18:45:221404 // Build up the lists of extensions that require acknowledgment. If this is
1405 // the first time, grandfather extensions that would have caused
1406 // notification.
[email protected]89226982012-07-16 20:09:181407 extension_error_ui_.reset(ExtensionErrorUI::Create(this));
[email protected]e5af875f2011-10-10 21:09:141408
[email protected]a9aa5932012-01-25 08:27:401409 bool did_show_alert = false;
[email protected]89226982012-07-16 20:09:181410 if (PopulateExtensionErrorUI(extension_error_ui_.get())) {
[email protected]460c6712013-04-24 07:20:011411 if (!is_first_run_) {
[email protected]a9aa5932012-01-25 08:27:401412 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]89226982012-07-16 20:09:181413 did_show_alert = extension_error_ui_->ShowErrorInBubbleView();
[email protected]e5af875f2011-10-10 21:09:141414 } else {
1415 // First run. Just acknowledge all the extensions, silently, by
1416 // shortcutting the display of the UI and going straight to the
1417 // callback for pressing the Accept button.
[email protected]a9aa5932012-01-25 08:27:401418 HandleExtensionAlertAccept();
[email protected]e5af875f2011-10-10 21:09:141419 }
1420 }
[email protected]a9aa5932012-01-25 08:27:401421
[email protected]612a1cb12012-10-17 13:18:031422 UpdateExternalExtensionAlert();
1423
[email protected]a9aa5932012-01-25 08:27:401424 if (!did_show_alert)
[email protected]89226982012-07-16 20:09:181425 extension_error_ui_.reset();
[email protected]e5af875f2011-10-10 21:09:141426}
1427
[email protected]89226982012-07-16 20:09:181428bool ExtensionService::PopulateExtensionErrorUI(
1429 ExtensionErrorUI* extension_error_ui) {
[email protected]07c9f2f42012-02-29 18:45:221430 bool needs_alert = false;
[email protected]695b5712012-12-06 23:55:281431
1432 // Extensions that are blacklisted.
1433 for (ExtensionSet::const_iterator it = blacklisted_extensions_.begin();
1434 it != blacklisted_extensions_.end(); ++it) {
1435 std::string id = (*it)->id();
1436 if (!extension_prefs_->IsBlacklistedExtensionAcknowledged(id)) {
1437 extension_error_ui->AddBlacklistedExtension(id);
1438 needs_alert = true;
1439 }
1440 }
1441
[email protected]07c9f2f42012-02-29 18:45:221442 for (ExtensionSet::const_iterator iter = extensions_.begin();
1443 iter != extensions_.end(); ++iter) {
[email protected]cadac622013-06-11 16:46:361444 const Extension* e = iter->get();
[email protected]695b5712012-12-06 23:55:281445
1446 // Extensions disabled by policy. Note: this no longer includes blacklisted
1447 // extensions, though we still show the same UI.
[email protected]fdd679b2012-11-15 20:49:391448 if (!system_->management_policy()->UserMayLoad(e, NULL)) {
[email protected]07c9f2f42012-02-29 18:45:221449 if (!extension_prefs_->IsBlacklistedExtensionAcknowledged(e->id())) {
[email protected]89226982012-07-16 20:09:181450 extension_error_ui->AddBlacklistedExtension(e->id());
[email protected]07c9f2f42012-02-29 18:45:221451 needs_alert = true;
1452 }
1453 }
[email protected]07c9f2f42012-02-29 18:45:221454 }
[email protected]695b5712012-12-06 23:55:281455
[email protected]07c9f2f42012-02-29 18:45:221456 return needs_alert;
1457}
1458
[email protected]a9aa5932012-01-25 08:27:401459void ExtensionService::HandleExtensionAlertClosed() {
[email protected]612a1cb12012-10-17 13:18:031460 const ExtensionIdSet* extension_ids =
1461 extension_error_ui_->get_blacklisted_extension_ids();
[email protected]e5af875f2011-10-10 21:09:141462 for (ExtensionIdSet::const_iterator iter = extension_ids->begin();
1463 iter != extension_ids->end(); ++iter) {
1464 extension_prefs_->AcknowledgeBlacklistedExtension(*iter);
1465 }
[email protected]879a6092013-03-06 04:12:501466 extension_error_ui_.reset();
1467}
1468
1469void ExtensionService::HandleExtensionAlertAccept() {
[email protected]73a85e012013-04-04 10:45:301470 extension_error_ui_->Close();
[email protected]e5af875f2011-10-10 21:09:141471}
1472
[email protected]47fc70c2011-12-06 07:29:511473void ExtensionService::AcknowledgeExternalExtension(const std::string& id) {
1474 extension_prefs_->AcknowledgeExternalExtension(id);
[email protected]612a1cb12012-10-17 13:18:031475 UpdateExternalExtensionAlert();
[email protected]47fc70c2011-12-06 07:29:511476}
1477
[email protected]d96eb512012-11-01 23:44:081478bool ExtensionService::IsUnacknowledgedExternalExtension(
1479 const Extension* extension) {
[email protected]b82d18da2012-11-09 00:11:321480 if (!FeatureSwitch::prompt_for_external_extensions()->IsEnabled())
1481 return false;
1482
[email protected]1d5e58b2013-01-31 08:41:401483 return (Manifest::IsExternalLocation(extension->location()) &&
[email protected]d96eb512012-11-01 23:44:081484 !extension_prefs_->IsExternalExtensionAcknowledged(extension->id()) &&
1485 !(extension_prefs_->GetDisableReasons(extension->id()) &
1486 Extension::DISABLE_SIDELOAD_WIPEOUT));
1487}
1488
[email protected]59ee99d2013-10-11 15:46:161489void ExtensionService::ReconcileKnownDisabled() {
[email protected]60a8bc962013-12-03 03:17:271490 ExtensionIdSet known_disabled_ids;
1491 if (!extension_prefs_->GetKnownDisabled(&known_disabled_ids)) {
[email protected]018a5682013-11-20 02:41:211492 extension_prefs_->SetKnownDisabled(disabled_extensions_.GetIDs());
1493 UMA_HISTOGRAM_BOOLEAN("Extensions.KnownDisabledInitialized", true);
1494 return;
[email protected]59ee99d2013-10-11 15:46:161495 }
[email protected]195c1582013-10-29 18:42:231496
[email protected]018a5682013-11-20 02:41:211497 // Both |known_disabled_ids| and |extensions_| are ordered (by definition
1498 // of std::map and std::set). Iterate forward over both sets in parallel
1499 // to find matching IDs and disable the corresponding extensions.
1500 ExtensionSet::const_iterator extensions_it = extensions_.begin();
1501 ExtensionIdSet::const_iterator known_disabled_ids_it =
1502 known_disabled_ids.begin();
1503 int known_disabled_count = 0;
1504 while (extensions_it != extensions_.end() &&
1505 known_disabled_ids_it != known_disabled_ids.end()) {
1506 const std::string& extension_id = extensions_it->get()->id();
1507 const int comparison = extension_id.compare(*known_disabled_ids_it);
1508 if (comparison < 0) {
1509 ++extensions_it;
1510 } else if (comparison > 0) {
1511 ++known_disabled_ids_it;
1512 } else {
1513 ++known_disabled_count;
1514 // Advance |extensions_it| immediately as it will be invalidated upon
1515 // disabling the extension it points to.
1516 ++extensions_it;
1517 ++known_disabled_ids_it;
1518 DisableExtension(extension_id, Extension::DISABLE_KNOWN_DISABLED);
1519 }
1520 }
1521 UMA_HISTOGRAM_COUNTS_100("Extensions.KnownDisabledReDisabled",
1522 known_disabled_count);
1523
[email protected]195c1582013-10-29 18:42:231524 // Update the list of known disabled to reflect every change to
1525 // |disabled_extensions_| from this point forward.
1526 disabled_extensions_.set_modification_callback(
1527 base::Bind(&extensions::ExtensionPrefs::SetKnownDisabled,
1528 base::Unretained(extension_prefs_)));
[email protected]59ee99d2013-10-11 15:46:161529}
1530
[email protected]89226982012-07-16 20:09:181531void ExtensionService::HandleExtensionAlertDetails() {
1532 extension_error_ui_->ShowExtensions();
[email protected]73a85e012013-04-04 10:45:301533 // ShowExtensions may cause the error UI to close synchronously, e.g. if it
1534 // causes a navigation.
1535 if (extension_error_ui_)
1536 extension_error_ui_->Close();
[email protected]6c751e72010-11-23 10:11:101537}
1538
[email protected]612a1cb12012-10-17 13:18:031539void ExtensionService::UpdateExternalExtensionAlert() {
[email protected]41070e8d2012-10-24 01:34:361540 if (!FeatureSwitch::prompt_for_external_extensions()->IsEnabled())
[email protected]612a1cb12012-10-17 13:18:031541 return;
1542
1543 const Extension* extension = NULL;
1544 for (ExtensionSet::const_iterator iter = disabled_extensions_.begin();
1545 iter != disabled_extensions_.end(); ++iter) {
[email protected]cadac622013-06-11 16:46:361546 const Extension* e = iter->get();
[email protected]d96eb512012-11-01 23:44:081547 if (IsUnacknowledgedExternalExtension(e)) {
1548 extension = e;
1549 break;
[email protected]612a1cb12012-10-17 13:18:031550 }
1551 }
1552
1553 if (extension) {
[email protected]d96eb512012-11-01 23:44:081554 if (!extensions::HasExternalInstallError(this)) {
1555 if (extension_prefs_->IncrementAcknowledgePromptCount(extension->id()) >
[email protected]612a1cb12012-10-17 13:18:031556 kMaxExtensionAcknowledgePromptCount) {
[email protected]d96eb512012-11-01 23:44:081557 // Stop prompting for this extension, and check if there's another
1558 // one that needs prompting.
[email protected]612a1cb12012-10-17 13:18:031559 extension_prefs_->AcknowledgeExternalExtension(extension->id());
[email protected]d96eb512012-11-01 23:44:081560 UpdateExternalExtensionAlert();
1561 UMA_HISTOGRAM_ENUMERATION("Extensions.ExternalExtensionEvent",
1562 EXTERNAL_EXTENSION_IGNORED,
1563 EXTERNAL_EXTENSION_BUCKET_BOUNDARY);
[email protected]446e37e2013-08-07 00:30:021564 if (extensions::ManifestURL::UpdatesFromGallery(extension)) {
1565 UMA_HISTOGRAM_ENUMERATION(
1566 "Extensions.ExternalExtensionEventWebstore",
1567 EXTERNAL_EXTENSION_IGNORED,
1568 EXTERNAL_EXTENSION_BUCKET_BOUNDARY);
1569 } else {
1570 UMA_HISTOGRAM_ENUMERATION(
1571 "Extensions.ExternalExtensionEventNonWebstore",
1572 EXTERNAL_EXTENSION_IGNORED,
1573 EXTERNAL_EXTENSION_BUCKET_BOUNDARY);
1574 }
[email protected]d96eb512012-11-01 23:44:081575 return;
[email protected]612a1cb12012-10-17 13:18:031576 }
[email protected]b3aa7182013-04-25 04:45:231577 if (is_first_run_)
1578 extension_prefs_->SetExternalInstallFirstRun(extension->id());
1579 // first_run is true if the extension was installed during a first run
1580 // (even if it's post-first run now).
1581 bool first_run = extension_prefs_->IsExternalInstallFirstRun(
1582 extension->id());
1583 extensions::AddExternalInstallError(this, extension, first_run);
[email protected]612a1cb12012-10-17 13:18:031584 }
1585 } else {
1586 extensions::RemoveExternalInstallError(this);
1587 }
[email protected]612a1cb12012-10-17 13:18:031588}
1589
[email protected]a9f39a312010-12-23 22:14:271590void ExtensionService::UnloadExtension(
1591 const std::string& extension_id,
[email protected]b0af4792013-10-23 09:12:131592 UnloadedExtensionInfo::Reason reason) {
[email protected]27e469a2010-01-11 20:35:091593 // Make sure the extension gets deleted after we return from this function.
[email protected]695b5712012-12-06 23:55:281594 int include_mask = INCLUDE_EVERYTHING & ~INCLUDE_TERMINATED;
[email protected]9adb9692010-10-29 23:14:021595 scoped_refptr<const Extension> extension(
[email protected]695b5712012-12-06 23:55:281596 GetExtensionById(extension_id, include_mask));
[email protected]631cf822009-05-15 07:01:251597
[email protected]fa0c96732010-11-17 00:14:231598 // This method can be called via PostTask, so the extension may have been
1599 // unloaded by the time this runs.
[email protected]dc24976f2013-06-02 21:15:091600 if (!extension.get()) {
[email protected]dd163fb02011-05-04 22:22:171601 // In case the extension may have crashed/uninstalled. Allow the profile to
1602 // clean up its RequestContexts.
[email protected]31d8f5f22012-04-02 15:22:081603 system_->UnregisterExtensionWithRequestContexts(extension_id, reason);
[email protected]fa0c96732010-11-17 00:14:231604 return;
[email protected]dd163fb02011-05-04 22:22:171605 }
[email protected]0c6da502009-08-14 22:32:391606
[email protected]1eb175082010-02-10 09:26:161607 // Keep information about the extension so that we can reload it later
1608 // even if it's not permanently installed.
1609 unloaded_extension_paths_[extension->id()] = extension->path();
1610
[email protected]f17dbd42010-08-16 23:21:101611 // Clean up if the extension is meant to be enabled after a reload.
[email protected]b914e2952013-04-26 07:10:031612 reloading_extensions_.erase(extension->id());
[email protected]f17dbd42010-08-16 23:21:101613
[email protected]d7e9a862010-11-03 21:57:491614 // Clean up runtime data.
1615 extension_runtime_data_.erase(extension_id);
1616
[email protected]060d4972012-07-19 17:22:391617 if (disabled_extensions_.Contains(extension->id())) {
[email protected]84df8332011-12-06 18:22:461618 disabled_extensions_.Remove(extension->id());
[email protected]dd163fb02011-05-04 22:22:171619 // Make sure the profile cleans up its RequestContexts when an already
1620 // disabled extension is unloaded (since they are also tracking the disabled
1621 // extensions).
[email protected]31d8f5f22012-04-02 15:22:081622 system_->UnregisterExtensionWithRequestContexts(extension_id, reason);
[email protected]60a174a2013-08-02 20:29:281623 } else {
1624 // Remove the extension from our list.
1625 extensions_.Remove(extension->id());
1626 NotifyExtensionUnloaded(extension.get(), reason);
[email protected]0c6da502009-08-14 22:32:391627 }
1628
[email protected]fb789532013-08-27 02:40:211629 content::NotificationService::current()->Notify(
1630 chrome::NOTIFICATION_EXTENSION_REMOVED,
1631 content::Source<Profile>(profile_),
1632 content::Details<const Extension>(extension.get()));
[email protected]631cf822009-05-15 07:01:251633}
1634
[email protected]8b1ec202013-09-05 02:09:501635void ExtensionService::RemoveComponentExtension(
1636 const std::string& extension_id) {
1637 scoped_refptr<const Extension> extension(
1638 GetExtensionById(extension_id, false));
[email protected]b0af4792013-10-23 09:12:131639 UnloadExtension(extension_id, UnloadedExtensionInfo::REASON_UNINSTALL);
[email protected]8b1ec202013-09-05 02:09:501640 content::NotificationService::current()->Notify(
1641 chrome::NOTIFICATION_EXTENSION_UNINSTALLED,
1642 content::Source<Profile>(profile_),
1643 content::Details<const Extension>(extension.get()));
1644}
1645
[email protected]eaa7dd182010-12-14 11:09:001646void ExtensionService::UnloadAllExtensions() {
[email protected]31bb5ee62012-09-12 22:58:401647 profile_->GetExtensionSpecialStoragePolicy()->RevokeRightsForAllExtensions();
[email protected]c8d407e2011-04-28 21:27:171648
[email protected]84df8332011-12-06 18:22:461649 extensions_.Clear();
1650 disabled_extensions_.Clear();
1651 terminated_extensions_.Clear();
[email protected]d7e9a862010-11-03 21:57:491652 extension_runtime_data_.clear();
[email protected]cd500f72010-06-25 23:44:321653
[email protected]c6e4a3412009-06-24 15:45:291654 // TODO(erikkay) should there be a notification for this? We can't use
1655 // EXTENSION_UNLOADED since that implies that the extension has been disabled
1656 // or uninstalled, and UnloadAll is just part of shutdown.
[email protected]9f1087e2009-06-15 17:29:321657}
1658
[email protected]eaa7dd182010-12-14 11:09:001659void ExtensionService::ReloadExtensions() {
[email protected]9f1087e2009-06-15 17:29:321660 UnloadAllExtensions();
[email protected]eac88332012-12-26 17:57:451661 component_loader_->LoadAll();
[email protected]d8c8f25f2011-11-02 18:18:011662 extensions::InstalledLoader(this).LoadAllExtensions();
[email protected]4a10006a2013-05-17 23:18:351663 // Don't call SetReadyAndNotifyListeners() since tests call this multiple
1664 // times.
[email protected]9f1087e2009-06-15 17:29:321665}
1666
[email protected]eaa7dd182010-12-14 11:09:001667void ExtensionService::GarbageCollectExtensions() {
[email protected]c04fd3dd2013-09-05 08:20:101668#if defined(OS_CHROMEOS)
1669 if (disable_garbage_collection_)
1670 return;
1671#endif
1672
[email protected]2f8757c32012-06-19 19:17:471673 if (extension_prefs_->pref_service()->ReadOnly())
1674 return;
1675
[email protected]9bd9a6862012-11-29 09:24:221676 if (pending_extension_manager()->HasPendingExtensions()) {
1677 // Don't garbage collect while there are pending installations, which may
1678 // be using the temporary installation directory. Try to garbage collect
1679 // again later.
[email protected]b3a25092013-05-28 22:08:161680 base::MessageLoop::current()->PostDelayedTask(
[email protected]9bd9a6862012-11-29 09:24:221681 FROM_HERE,
1682 base::Bind(&ExtensionService::GarbageCollectExtensions, AsWeakPtr()),
1683 base::TimeDelta::FromSeconds(kGarbageCollectRetryDelay));
1684 return;
1685 }
1686
[email protected]45759612012-07-10 17:21:231687 scoped_ptr<extensions::ExtensionPrefs::ExtensionsInfo> info(
[email protected]2f8757c32012-06-19 19:17:471688 extension_prefs_->GetInstalledExtensionsInfo());
1689
[email protected]650b2d52013-02-10 03:41:451690 std::multimap<std::string, base::FilePath> extension_paths;
[email protected]2f8757c32012-06-19 19:17:471691 for (size_t i = 0; i < info->size(); ++i)
[email protected]0db124b02012-11-07 04:55:051692 extension_paths.insert(std::make_pair(info->at(i)->extension_id,
1693 info->at(i)->extension_path));
1694
[email protected]399583b2012-12-11 09:33:421695 info = extension_prefs_->GetAllDelayedInstallInfo();
[email protected]0db124b02012-11-07 04:55:051696 for (size_t i = 0; i < info->size(); ++i)
1697 extension_paths.insert(std::make_pair(info->at(i)->extension_id,
1698 info->at(i)->extension_path));
[email protected]2f8757c32012-06-19 19:17:471699
[email protected]7f8f24f2012-11-15 19:40:141700 if (!GetFileTaskRunner()->PostTask(
1701 FROM_HERE,
[email protected]2f8757c32012-06-19 19:17:471702 base::Bind(
1703 &extension_file_util::GarbageCollectExtensions,
1704 install_directory_,
[email protected]31bb5ee62012-09-12 22:58:401705 extension_paths))) {
[email protected]2f8757c32012-06-19 19:17:471706 NOTREACHED();
[email protected]31bb5ee62012-09-12 22:58:401707 }
[email protected]3cf4f0992009-02-03 23:00:301708}
1709
[email protected]820d9bd2013-04-03 03:46:031710void ExtensionService::SetReadyAndNotifyListeners() {
[email protected]4a10006a2013-05-17 23:18:351711 ready_->Signal();
[email protected]820d9bd2013-04-03 03:46:031712 content::NotificationService::current()->Notify(
1713 chrome::NOTIFICATION_EXTENSIONS_READY,
1714 content::Source<Profile>(profile_),
1715 content::NotificationService::NoDetails());
1716}
1717
[email protected]eaa7dd182010-12-14 11:09:001718void ExtensionService::OnLoadedInstalledExtensions() {
[email protected]3eeddd892013-04-17 17:00:111719 if (updater_)
[email protected]93fd78f42009-07-10 16:43:171720 updater_->Start();
[email protected]fa6a9102010-11-22 15:38:501721
[email protected]bc151cf92013-02-12 04:57:261722 OnBlacklistUpdated();
[email protected]e72e8eb82009-06-18 17:21:511723}
1724
[email protected]fcb58a862012-05-01 01:03:151725void ExtensionService::AddExtension(const Extension* extension) {
[email protected]c8d407e2011-04-28 21:27:171726 // TODO(jstritar): We may be able to get rid of this branch by overriding the
1727 // default extension state to DISABLED when the --disable-extensions flag
1728 // is set (http://crbug.com/29067).
1729 if (!extensions_enabled() &&
1730 !extension->is_theme() &&
[email protected]1d5e58b2013-01-31 08:41:401731 extension->location() != Manifest::COMPONENT &&
1732 !Manifest::IsExternalLocation(extension->location())) {
[email protected]fcb58a862012-05-01 01:03:151733 return;
[email protected]330840c2012-08-29 22:21:011734 }
[email protected]c8d407e2011-04-28 21:27:171735
[email protected]b914e2952013-04-26 07:10:031736 bool is_extension_upgrade = false;
[email protected]116d40e2013-08-08 17:23:171737 bool is_extension_installed = false;
1738 const Extension* old = GetInstalledExtension(extension->id());
1739 if (old) {
1740 is_extension_installed = true;
1741 int version_compare_result =
1742 extension->version()->CompareTo(*(old->version()));
1743 is_extension_upgrade = version_compare_result > 0;
[email protected]b914e2952013-04-26 07:10:031744 // Other than for unpacked extensions, CrxInstaller should have guaranteed
1745 // that we aren't downgrading.
1746 if (!Manifest::IsUnpackedLocation(extension->location()))
[email protected]116d40e2013-08-08 17:23:171747 CHECK_GE(version_compare_result, 0);
[email protected]b914e2952013-04-26 07:10:031748 }
1749 SetBeingUpgraded(extension, is_extension_upgrade);
[email protected]c8d407e2011-04-28 21:27:171750
[email protected]1eb175082010-02-10 09:26:161751 // The extension is now loaded, remove its data from unloaded extension map.
1752 unloaded_extension_paths_.erase(extension->id());
1753
[email protected]bb7f40952011-01-13 00:21:201754 // If a terminated extension is loaded, remove it from the terminated list.
1755 UntrackTerminatedExtension(extension->id());
1756
[email protected]f17dbd42010-08-16 23:21:101757 // If the extension was disabled for a reload, then enable it.
[email protected]ca2e82022013-04-29 16:48:411758 bool reloading = reloading_extensions_.erase(extension->id()) > 0;
[email protected]f17dbd42010-08-16 23:21:101759
[email protected]b914e2952013-04-26 07:10:031760 // Check if the extension's privileges have changed and mark the
1761 // extension disabled if necessary.
[email protected]116d40e2013-08-08 17:23:171762 CheckPermissionsIncrease(extension, is_extension_installed);
[email protected]b914e2952013-04-26 07:10:031763
[email protected]116d40e2013-08-08 17:23:171764 if (is_extension_installed && !reloading) {
[email protected]ca2e82022013-04-29 16:48:411765 // To upgrade an extension in place, unload the old one and then load the
1766 // new one. ReloadExtension disables the extension, which is sufficient.
[email protected]b0af4792013-10-23 09:12:131767 UnloadExtension(extension->id(), UnloadedExtensionInfo::REASON_UPDATE);
[email protected]b914e2952013-04-26 07:10:031768 }
[email protected]0c6da502009-08-14 22:32:391769
[email protected]695b5712012-12-06 23:55:281770 if (extension_prefs_->IsExtensionBlacklisted(extension->id())) {
[email protected]ac875372013-02-28 04:36:091771 // Only prefs is checked for the blacklist. We rely on callers to check the
1772 // blacklist before calling into here, e.g. CrxInstaller checks before
[email protected]9f3c8532013-07-31 19:52:071773 // installation then threads through the install and pending install flow
1774 // of this class, and we check when loading installed extensions.
[email protected]695b5712012-12-06 23:55:281775 blacklisted_extensions_.Insert(extension);
[email protected]ca2e82022013-04-29 16:48:411776 } else if (!reloading &&
1777 extension_prefs_->IsExtensionDisabled(extension->id())) {
[email protected]6f6101832012-11-27 22:10:481778 disabled_extensions_.Insert(extension);
[email protected]f8aefb132013-10-30 09:29:521779 if (extension_sync_service_)
1780 extension_sync_service_->SyncExtensionChangeIfNeeded(*extension);
[email protected]44d62b62012-04-11 00:06:031781 content::NotificationService::current()->Notify(
1782 chrome::NOTIFICATION_EXTENSION_UPDATE_DISABLED,
1783 content::Source<Profile>(profile_),
1784 content::Details<const Extension>(extension));
[email protected]62f051c2012-03-29 17:04:441785
[email protected]7e9e2422012-12-13 19:54:191786 // Show the extension disabled error if a permissions increase was the
1787 // only reason it was disabled.
1788 if (extension_prefs_->GetDisableReasons(extension->id()) ==
[email protected]44d62b62012-04-11 00:06:031789 Extension::DISABLE_PERMISSIONS_INCREASE) {
[email protected]62f051c2012-03-29 17:04:441790 extensions::AddExtensionDisabledError(this, extension);
1791 }
[email protected]ca2e82022013-04-29 16:48:411792 } else if (reloading) {
1793 // Replace the old extension with the new version.
1794 CHECK(!disabled_extensions_.Insert(extension));
1795 EnableExtension(extension->id());
[email protected]695b5712012-12-06 23:55:281796 } else {
1797 // All apps that are displayed in the launcher are ordered by their ordinals
1798 // so we must ensure they have valid ordinals.
1799 if (extension->RequiresSortOrdinal()) {
[email protected]bd36b652013-02-27 02:13:251800 if (!extension->ShouldDisplayInNewTabPage()) {
[email protected]74474042013-11-21 12:03:541801 extension_prefs_->app_sorting()->MarkExtensionAsHidden(extension->id());
[email protected]bd36b652013-02-27 02:13:251802 }
[email protected]74474042013-11-21 12:03:541803 extension_prefs_->app_sorting()->EnsureValidOrdinals(
[email protected]695b5712012-12-06 23:55:281804 extension->id(), syncer::StringOrdinal());
1805 }
1806
1807 extensions_.Insert(extension);
[email protected]f8aefb132013-10-30 09:29:521808 if (extension_sync_service_)
1809 extension_sync_service_->SyncExtensionChangeIfNeeded(*extension);
[email protected]695b5712012-12-06 23:55:281810 NotifyExtensionLoaded(extension);
[email protected]f574c402012-12-04 23:20:311811 }
[email protected]b914e2952013-04-26 07:10:031812 SetBeingUpgraded(extension, false);
[email protected]aab98a52009-12-02 03:22:351813}
1814
[email protected]8c484b742012-11-29 06:05:361815void ExtensionService::AddComponentExtension(const Extension* extension) {
1816 const std::string old_version_string(
1817 extension_prefs_->GetVersionString(extension->id()));
1818 const Version old_version(old_version_string);
1819
[email protected]0181a7d2013-11-12 01:08:421820 VLOG(1) << "AddComponentExtension " << extension->name();
[email protected]8c484b742012-11-29 06:05:361821 if (!old_version.IsValid() || !old_version.Equals(*extension->version())) {
1822 VLOG(1) << "Component extension " << extension->name() << " ("
1823 << extension->id() << ") installing/upgrading from '"
1824 << old_version_string << "' to " << extension->version()->GetString();
1825
1826 AddNewOrUpdatedExtension(extension,
[email protected]399583b2012-12-11 09:33:421827 Extension::ENABLED_COMPONENT,
[email protected]8e289f0b2013-12-17 17:49:071828 extensions::NOT_BLACKLISTED,
[email protected]399583b2012-12-11 09:33:421829 syncer::StringOrdinal());
[email protected]8c484b742012-11-29 06:05:361830 return;
1831 }
1832
1833 AddExtension(extension);
1834}
1835
[email protected]b914e2952013-04-26 07:10:031836void ExtensionService::UpdateActivePermissions(const Extension* extension) {
[email protected]902fd7b2011-07-27 18:42:311837 // If the extension has used the optional permissions API, it will have a
1838 // custom set of active permissions defined in the extension prefs. Here,
1839 // we update the extension's active permissions based on the prefs.
[email protected]c2e66e12012-06-27 06:27:061840 scoped_refptr<PermissionSet> active_permissions =
[email protected]902fd7b2011-07-27 18:42:311841 extension_prefs()->GetActivePermissions(extension->id());
1842
[email protected]dc24976f2013-06-02 21:15:091843 if (active_permissions.get()) {
[email protected]902fd7b2011-07-27 18:42:311844 // We restrict the active permissions to be within the bounds defined in the
1845 // extension's manifest.
1846 // a) active permissions must be a subset of optional + default permissions
1847 // b) active permissions must contains all default permissions
[email protected]c2e66e12012-06-27 06:27:061848 scoped_refptr<PermissionSet> total_permissions =
1849 PermissionSet::CreateUnion(
[email protected]2cb5e302013-05-09 05:00:061850 extensions::PermissionsData::GetRequiredPermissions(extension),
1851 extensions::PermissionsData::GetOptionalPermissions(extension));
[email protected]902fd7b2011-07-27 18:42:311852
1853 // Make sure the active permissions contain no more than optional + default.
[email protected]c2e66e12012-06-27 06:27:061854 scoped_refptr<PermissionSet> adjusted_active =
1855 PermissionSet::CreateIntersection(
[email protected]902fd7b2011-07-27 18:42:311856 total_permissions.get(), active_permissions.get());
1857
1858 // Make sure the active permissions contain the default permissions.
[email protected]c2e66e12012-06-27 06:27:061859 adjusted_active = PermissionSet::CreateUnion(
[email protected]2cb5e302013-05-09 05:00:061860 extensions::PermissionsData::GetRequiredPermissions(extension),
1861 adjusted_active.get());
[email protected]902fd7b2011-07-27 18:42:311862
[email protected]c333e792012-01-06 16:57:391863 extensions::PermissionsUpdater perms_updater(profile());
[email protected]dc24976f2013-06-02 21:15:091864 perms_updater.UpdateActivePermissions(extension, adjusted_active.get());
[email protected]902fd7b2011-07-27 18:42:311865 }
[email protected]b914e2952013-04-26 07:10:031866}
1867
1868void ExtensionService::CheckPermissionsIncrease(const Extension* extension,
[email protected]116d40e2013-08-08 17:23:171869 bool is_extension_installed) {
[email protected]b914e2952013-04-26 07:10:031870 UpdateActivePermissions(extension);
[email protected]902fd7b2011-07-27 18:42:311871
[email protected]8d888c12010-11-30 00:00:251872 // We keep track of all permissions the user has granted each extension.
1873 // This allows extensions to gracefully support backwards compatibility
1874 // by including unknown permissions in their manifests. When the user
1875 // installs the extension, only the recognized permissions are recorded.
1876 // When the unknown permissions become recognized (e.g., through browser
1877 // upgrade), we can prompt the user to accept these new permissions.
1878 // Extensions can also silently upgrade to less permissions, and then
1879 // silently upgrade to a version that adds these permissions back.
1880 //
1881 // For example, pretend that Chrome 10 includes a permission "omnibox"
1882 // for an API that adds suggestions to the omnibox. An extension can
1883 // maintain backwards compatibility while still having "omnibox" in the
1884 // manifest. If a user installs the extension on Chrome 9, the browser
1885 // will record the permissions it recognized, not including "omnibox."
1886 // When upgrading to Chrome 10, "omnibox" will be recognized and Chrome
1887 // will disable the extension and prompt the user to approve the increase
1888 // in privileges. The extension could then release a new version that
1889 // removes the "omnibox" permission. When the user upgrades, Chrome will
1890 // still remember that "omnibox" had been granted, so that if the
1891 // extension once again includes "omnibox" in an upgrade, the extension
1892 // can upgrade without requiring this user's approval.
[email protected]eb5e4f92012-08-15 23:33:281893 int disable_reasons = extension_prefs_->GetDisableReasons(extension->id());
[email protected]8d888c12010-11-30 00:00:251894
[email protected]211a3f32013-05-28 21:48:181895 bool auto_grant_permission =
[email protected]1b563df2013-10-30 16:49:361896 (!is_extension_installed && extension->was_installed_by_default()) ||
[email protected]45928b682013-11-28 08:20:271897 extensions::ExtensionsBrowserClient::Get()->IsRunningInForcedAppMode();
[email protected]b914e2952013-04-26 07:10:031898 // Silently grant all active permissions to default apps only on install.
1899 // After install they should behave like other apps.
[email protected]211a3f32013-05-28 21:48:181900 // Silently grant all active permissions to apps install in kiosk mode on both
1901 // install and update.
1902 if (auto_grant_permission)
[email protected]b914e2952013-04-26 07:10:031903 GrantPermissions(extension);
1904
1905 bool is_privilege_increase = false;
1906 // We only need to compare the granted permissions to the current permissions
1907 // if the extension is not allowed to silently increase its permissions.
[email protected]13c68b62013-05-17 11:29:051908 if (!extensions::PermissionsData::CanSilentlyIncreasePermissions(extension) &&
[email protected]211a3f32013-05-28 21:48:181909 !auto_grant_permission) {
[email protected]8d888c12010-11-30 00:00:251910 // Add all the recognized permissions if the granted permissions list
1911 // hasn't been initialized yet.
[email protected]c2e66e12012-06-27 06:27:061912 scoped_refptr<PermissionSet> granted_permissions =
[email protected]902fd7b2011-07-27 18:42:311913 extension_prefs_->GetGrantedPermissions(extension->id());
[email protected]0d3e4a22011-06-23 19:02:521914 CHECK(granted_permissions.get());
[email protected]8d888c12010-11-30 00:00:251915
1916 // Here, we check if an extension's privileges have increased in a manner
1917 // that requires the user's approval. This could occur because the browser
1918 // upgraded and recognized additional privileges, or an extension upgrades
1919 // to a version that requires additional privileges.
[email protected]c41003472013-10-19 15:37:251920 is_privilege_increase =
1921 extensions::PermissionMessageProvider::Get()->IsPrivilegeIncrease(
1922 granted_permissions,
1923 extension->GetActivePermissions().get(),
1924 extension->GetType());
[email protected]8d888c12010-11-30 00:00:251925 }
1926
[email protected]116d40e2013-08-08 17:23:171927 if (is_extension_installed) {
[email protected]44d62b62012-04-11 00:06:031928 // If the extension was already disabled, suppress any alerts for becoming
1929 // disabled on permissions increase.
[email protected]b914e2952013-04-26 07:10:031930 bool previously_disabled =
1931 extension_prefs_->IsExtensionDisabled(extension->id());
[email protected]7e9e2422012-12-13 19:54:191932 // Legacy disabled extensions do not have a disable reason. Infer that if
1933 // there was no permission increase, it was likely disabled by the user.
1934 if (previously_disabled && disable_reasons == Extension::DISABLE_NONE &&
[email protected]b914e2952013-04-26 07:10:031935 !extension_prefs_->DidExtensionEscalatePermissions(extension->id())) {
[email protected]7e9e2422012-12-13 19:54:191936 disable_reasons |= Extension::DISABLE_USER_ACTION;
[email protected]44d62b62012-04-11 00:06:031937 }
[email protected]7e9e2422012-12-13 19:54:191938 // Extensions that came to us disabled from sync need a similar inference,
1939 // except based on the new version's permissions.
1940 if (previously_disabled &&
1941 disable_reasons == Extension::DISABLE_UNKNOWN_FROM_SYNC) {
1942 // Remove the DISABLE_UNKNOWN_FROM_SYNC reason.
1943 extension_prefs_->ClearDisableReasons(extension->id());
1944 if (!is_privilege_increase)
1945 disable_reasons |= Extension::DISABLE_USER_ACTION;
1946 }
[email protected]b914e2952013-04-26 07:10:031947 disable_reasons &= ~Extension::DISABLE_UNKNOWN_FROM_SYNC;
[email protected]8d888c12010-11-30 00:00:251948 }
1949
1950 // Extension has changed permissions significantly. Disable it. A
1951 // notification should be sent by the caller.
1952 if (is_privilege_increase) {
[email protected]7e9e2422012-12-13 19:54:191953 disable_reasons |= Extension::DISABLE_PERMISSIONS_INCREASE;
[email protected]fe2dd7742011-04-19 22:52:491954 if (!extension_prefs_->DidExtensionEscalatePermissions(extension->id())) {
1955 RecordPermissionMessagesHistogram(
1956 extension, "Extensions.Permissions_AutoDisable");
1957 }
[email protected]195c1582013-10-29 18:42:231958 extension_prefs_->SetExtensionState(extension->id(), Extension::DISABLED);
[email protected]8d888c12010-11-30 00:00:251959 extension_prefs_->SetDidExtensionEscalatePermissions(extension, true);
[email protected]b914e2952013-04-26 07:10:031960 }
1961 if (disable_reasons != Extension::DISABLE_NONE) {
[email protected]eb5e4f92012-08-15 23:33:281962 extension_prefs_->AddDisableReason(
1963 extension->id(),
1964 static_cast<Extension::DisableReason>(disable_reasons));
[email protected]8d888c12010-11-30 00:00:251965 }
1966}
1967
[email protected]eaa7dd182010-12-14 11:09:001968void ExtensionService::UpdateActiveExtensionsInCrashReporter() {
[email protected]c8865962009-12-16 07:47:391969 std::set<std::string> extension_ids;
[email protected]84df8332011-12-06 18:22:461970 for (ExtensionSet::const_iterator iter = extensions_.begin();
1971 iter != extensions_.end(); ++iter) {
[email protected]cadac622013-06-11 16:46:361972 const Extension* extension = iter->get();
[email protected]1d5e58b2013-01-31 08:41:401973 if (!extension->is_theme() && extension->location() != Manifest::COMPONENT)
[email protected]84df8332011-12-06 18:22:461974 extension_ids.insert(extension->id());
[email protected]aab98a52009-12-02 03:22:351975 }
1976
[email protected]f6431be82013-09-07 02:53:451977 crash_keys::SetActiveExtensions(extension_ids);
[email protected]6014d672008-12-05 00:38:251978}
1979
[email protected]669b2372013-10-17 15:04:581980ExtensionService::ImportStatus ExtensionService::CheckImports(
1981 const extensions::Extension* extension,
1982 std::list<SharedModuleInfo::ImportInfo>* missing_modules,
1983 std::list<SharedModuleInfo::ImportInfo>* outdated_modules) {
1984 DCHECK(extension);
1985 DCHECK(missing_modules && missing_modules->empty());
1986 DCHECK(outdated_modules && outdated_modules->empty());
[email protected]9f4e4f082013-06-21 07:11:191987 ImportStatus status = IMPORT_STATUS_OK;
[email protected]9f4e4f082013-06-21 07:11:191988 if (SharedModuleInfo::ImportsModules(extension)) {
1989 const std::vector<SharedModuleInfo::ImportInfo>& imports =
1990 SharedModuleInfo::GetImports(extension);
1991 std::vector<SharedModuleInfo::ImportInfo>::const_iterator i;
1992 for (i = imports.begin(); i != imports.end(); ++i) {
1993 Version version_required(i->minimum_version);
1994 const Extension* imported_module =
1995 GetExtensionById(i->extension_id, true);
1996 if (!imported_module) {
1997 if (extension->from_webstore()) {
1998 status = IMPORT_STATUS_UNSATISFIED;
[email protected]669b2372013-10-17 15:04:581999 missing_modules->push_back(*i);
[email protected]9f4e4f082013-06-21 07:11:192000 } else {
2001 return IMPORT_STATUS_UNRECOVERABLE;
2002 }
2003 } else if (!SharedModuleInfo::IsSharedModule(imported_module)) {
2004 return IMPORT_STATUS_UNRECOVERABLE;
2005 } else if (version_required.IsValid() &&
2006 imported_module->version()->CompareTo(version_required) < 0) {
2007 if (imported_module->from_webstore()) {
[email protected]669b2372013-10-17 15:04:582008 outdated_modules->push_back(*i);
[email protected]9f4e4f082013-06-21 07:11:192009 status = IMPORT_STATUS_UNSATISFIED;
2010 } else {
2011 return IMPORT_STATUS_UNRECOVERABLE;
2012 }
2013 }
2014 }
2015 }
[email protected]669b2372013-10-17 15:04:582016 return status;
2017}
2018
2019ExtensionService::ImportStatus ExtensionService::SatisfyImports(
2020 const Extension* extension) {
2021 std::list<SharedModuleInfo::ImportInfo> noinstalled;
2022 std::list<SharedModuleInfo::ImportInfo> outdated;
2023 ImportStatus status = CheckImports(extension, &noinstalled, &outdated);
2024 if (status == IMPORT_STATUS_UNRECOVERABLE)
2025 return status;
[email protected]9f4e4f082013-06-21 07:11:192026 if (status == IMPORT_STATUS_UNSATISFIED) {
[email protected]669b2372013-10-17 15:04:582027 std::list<SharedModuleInfo::ImportInfo>::const_iterator iter;
2028 for (iter = noinstalled.begin(); iter != noinstalled.end(); ++iter) {
[email protected]9f4e4f082013-06-21 07:11:192029 pending_extension_manager()->AddFromExtensionImport(
[email protected]669b2372013-10-17 15:04:582030 iter->extension_id,
[email protected]9f4e4f082013-06-21 07:11:192031 extension_urls::GetWebstoreUpdateUrl(),
2032 IsSharedModule);
2033 }
2034 CheckForUpdatesSoon();
2035 }
2036 return status;
2037}
2038
2039scoped_ptr<const ExtensionSet>
2040 ExtensionService::GetDependentExtensions(const Extension* extension) {
2041 scoped_ptr<ExtensionSet> dependents(new ExtensionSet());
2042 scoped_ptr<ExtensionSet> set_to_check(new ExtensionSet());
2043 if (SharedModuleInfo::IsSharedModule(extension)) {
2044 set_to_check->InsertAll(disabled_extensions_);
2045 set_to_check->InsertAll(delayed_installs_);
2046 set_to_check->InsertAll(extensions_);
2047 for (ExtensionSet::const_iterator iter = set_to_check->begin();
2048 iter != set_to_check->end(); ++iter) {
[email protected]198b5902013-06-27 10:36:112049 if (SharedModuleInfo::ImportsExtensionById(iter->get(),
2050 extension->id())) {
[email protected]9f4e4f082013-06-21 07:11:192051 dependents->Insert(*iter);
2052 }
2053 }
2054 }
2055 return dependents.PassAs<const ExtensionSet>();
2056}
2057
2058void ExtensionService::PruneSharedModulesOnUninstall(
2059 const Extension* extension) {
2060 if (SharedModuleInfo::ImportsModules(extension)) {
2061 const std::vector<SharedModuleInfo::ImportInfo>& imports =
2062 SharedModuleInfo::GetImports(extension);
2063 std::vector<SharedModuleInfo::ImportInfo>::const_iterator i;
2064 for (i = imports.begin(); i != imports.end(); ++i) {
2065 const Extension* imported_module =
2066 GetExtensionById(i->extension_id, true);
2067 if (imported_module && imported_module->from_webstore()) {
2068 scoped_ptr<const ExtensionSet> dependents =
2069 GetDependentExtensions(imported_module);
2070 if (dependents->size() == 0) {
[email protected]4c9201c42013-08-16 04:56:212071 UninstallExtension(i->extension_id, true, NULL);
[email protected]9f4e4f082013-06-21 07:11:192072 }
2073 }
2074 }
2075 }
2076}
2077
[email protected]8266d662011-07-12 21:53:262078void ExtensionService::OnExtensionInstalled(
[email protected]36a5c4c2011-12-14 16:34:502079 const Extension* extension,
[email protected]98270432012-09-11 20:51:242080 const syncer::StringOrdinal& page_ordinal,
[email protected]0db124b02012-11-07 04:55:052081 bool has_requirement_errors,
[email protected]8e289f0b2013-12-17 17:49:072082 extensions::BlacklistState blacklist_state,
[email protected]0db124b02012-11-07 04:55:052083 bool wait_for_idle) {
[email protected]a29a517a2011-01-21 21:11:122084 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]a8af9fdb2010-10-28 21:52:202085
[email protected]c3cfb012011-04-06 22:07:352086 const std::string& id = extension->id();
[email protected]612a1cb12012-10-17 13:18:032087 bool initial_enable = ShouldEnableOnInstall(extension);
[email protected]3f213ad2012-07-26 23:39:412088 const extensions::PendingExtensionInfo* pending_extension_info = NULL;
[email protected]51a3bf8b2012-06-08 22:53:062089 if ((pending_extension_info = pending_extension_manager()->GetById(id))) {
[email protected]8f3bcbd2013-06-05 08:42:402090 if (!pending_extension_info->ShouldAllowInstall(extension)) {
[email protected]51a3bf8b2012-06-08 22:53:062091 pending_extension_manager()->Remove(id);
[email protected]8ef78fd2010-08-19 17:14:322092
[email protected]31bb5ee62012-09-12 22:58:402093 LOG(WARNING) << "ShouldAllowInstall() returned false for "
2094 << id << " of type " << extension->GetType()
[email protected]65348062013-01-15 07:27:222095 << " and update URL "
2096 << extensions::ManifestURL::GetUpdateURL(extension).spec()
[email protected]31bb5ee62012-09-12 22:58:402097 << "; not installing";
[email protected]ae6cb3022011-04-04 20:11:542098
[email protected]4416c5a2010-06-26 01:28:572099 // Delete the extension directory since we're not going to
2100 // load it.
[email protected]7f8f24f2012-11-15 19:40:142101 if (!GetFileTaskRunner()->PostTask(
2102 FROM_HERE,
[email protected]53612e82011-10-18 18:00:362103 base::Bind(&extension_file_util::DeleteFile,
[email protected]31bb5ee62012-09-12 22:58:402104 extension->path(), true))) {
[email protected]14908b72011-04-20 06:54:362105 NOTREACHED();
[email protected]31bb5ee62012-09-12 22:58:402106 }
[email protected]4416c5a2010-06-26 01:28:572107 return;
2108 }
[email protected]51a3bf8b2012-06-08 22:53:062109
2110 pending_extension_manager()->Remove(id);
[email protected]4416c5a2010-06-26 01:28:572111 } else {
[email protected]c3cfb012011-04-06 22:07:352112 // We explicitly want to re-enable an uninstalled external
2113 // extension; if we're here, that means the user is manually
2114 // installing the extension.
[email protected]6cc7dbae2011-04-29 21:18:332115 if (IsExternalExtensionUninstalled(id)) {
2116 initial_enable = true;
2117 }
[email protected]aa142702010-03-26 01:26:332118 }
2119
[email protected]98270432012-09-11 20:51:242120 // Unsupported requirements overrides the management policy.
2121 if (has_requirement_errors) {
2122 initial_enable = false;
2123 extension_prefs_->AddDisableReason(
2124 id, Extension::DISABLE_UNSUPPORTED_REQUIREMENT);
2125 // If the extension was disabled because of unsupported requirements but
2126 // now supports all requirements after an update and there are not other
2127 // disable reasons, enable it.
2128 } else if (extension_prefs_->GetDisableReasons(id) ==
2129 Extension::DISABLE_UNSUPPORTED_REQUIREMENT) {
2130 initial_enable = true;
2131 extension_prefs_->ClearDisableReasons(id);
2132 }
2133
[email protected]8e289f0b2013-12-17 17:49:072134 if (blacklist_state == extensions::BLACKLISTED_MALWARE) {
[email protected]9f3c8532013-07-31 19:52:072135 // Installation of a blacklisted extension can happen from sync, policy,
2136 // etc, where to maintain consistency we need to install it, just never
2137 // load it (see AddExtension). Usually it should be the job of callers to
2138 // incercept blacklisted extension earlier (e.g. CrxInstaller, before even
2139 // showing the install dialogue).
2140 extension_prefs()->AcknowledgeBlacklistedExtension(id);
2141 UMA_HISTOGRAM_ENUMERATION("ExtensionBlacklist.SilentInstall",
2142 extension->location(),
2143 Manifest::NUM_LOCATIONS);
2144 }
2145
[email protected]695b5712012-12-06 23:55:282146 if (!GetInstalledExtension(extension->id())) {
[email protected]07533022011-06-27 20:42:552147 UMA_HISTOGRAM_ENUMERATION("Extensions.InstallType",
2148 extension->GetType(), 100);
[email protected]69084dc2012-11-17 07:39:302149 UMA_HISTOGRAM_ENUMERATION("Extensions.InstallSource",
[email protected]1d5e58b2013-01-31 08:41:402150 extension->location(), Manifest::NUM_LOCATIONS);
[email protected]07533022011-06-27 20:42:552151 RecordPermissionMessagesHistogram(
2152 extension, "Extensions.Permissions_Install");
[email protected]69084dc2012-11-17 07:39:302153 } else {
2154 UMA_HISTOGRAM_ENUMERATION("Extensions.UpdateType",
2155 extension->GetType(), 100);
2156 UMA_HISTOGRAM_ENUMERATION("Extensions.UpdateSource",
[email protected]1d5e58b2013-01-31 08:41:402157 extension->location(), Manifest::NUM_LOCATIONS);
[email protected]07533022011-06-27 20:42:552158 }
2159
[email protected]a39921b42012-02-28 03:42:542160 // Certain extension locations are specific enough that we can
2161 // auto-acknowledge any extension that came from one of them.
[email protected]9bb691632013-09-26 18:50:122162 if (Manifest::IsPolicyLocation(extension->location()))
[email protected]a39921b42012-02-28 03:42:542163 AcknowledgeExternalExtension(extension->id());
[email protected]399583b2012-12-11 09:33:422164 const Extension::State initial_state =
2165 initial_enable ? Extension::ENABLED : Extension::DISABLED;
[email protected]0f9e6262013-11-05 23:49:192166 const bool blacklisted_for_malware =
[email protected]8e289f0b2013-12-17 17:49:072167 blacklist_state == extensions::BLACKLISTED_MALWARE;
[email protected]e7aa7b7e2012-11-27 04:51:222168 if (ShouldDelayExtensionUpdate(id, wait_for_idle)) {
[email protected]9f3c8532013-07-31 19:52:072169 extension_prefs_->SetDelayedInstallInfo(
2170 extension,
2171 initial_state,
[email protected]0f9e6262013-11-05 23:49:192172 blacklisted_for_malware,
[email protected]9f3c8532013-07-31 19:52:072173 extensions::ExtensionPrefs::DELAY_REASON_WAIT_FOR_IDLE,
2174 page_ordinal);
[email protected]0db124b02012-11-07 04:55:052175
2176 // Transfer ownership of |extension|.
[email protected]9f4e4f082013-06-21 07:11:192177 delayed_installs_.Insert(extension);
[email protected]0db124b02012-11-07 04:55:052178
[email protected]75bdcb872013-03-13 00:41:452179 // Notify observers that app update is available.
2180 FOR_EACH_OBSERVER(extensions::UpdateObserver, update_observers_,
[email protected]a9aa62b312013-11-29 05:35:062181 OnAppUpdateAvailable(extension));
[email protected]0db124b02012-11-07 04:55:052182 return;
2183 }
2184
[email protected]9f4e4f082013-06-21 07:11:192185 ImportStatus status = SatisfyImports(extension);
2186 if (installs_delayed_for_gc()) {
[email protected]9f3c8532013-07-31 19:52:072187 extension_prefs_->SetDelayedInstallInfo(
2188 extension,
2189 initial_state,
[email protected]0f9e6262013-11-05 23:49:192190 blacklisted_for_malware,
[email protected]9f3c8532013-07-31 19:52:072191 extensions::ExtensionPrefs::DELAY_REASON_GC,
2192 page_ordinal);
[email protected]399583b2012-12-11 09:33:422193 delayed_installs_.Insert(extension);
[email protected]9f4e4f082013-06-21 07:11:192194 } else if (status != IMPORT_STATUS_OK) {
2195 if (status == IMPORT_STATUS_UNSATISFIED) {
[email protected]9f3c8532013-07-31 19:52:072196 extension_prefs_->SetDelayedInstallInfo(
2197 extension,
2198 initial_state,
[email protected]0f9e6262013-11-05 23:49:192199 blacklisted_for_malware,
[email protected]9f4e4f082013-06-21 07:11:192200 extensions::ExtensionPrefs::DELAY_REASON_WAIT_FOR_IMPORTS,
2201 page_ordinal);
2202 delayed_installs_.Insert(extension);
2203 }
[email protected]399583b2012-12-11 09:33:422204 } else {
[email protected]9f3c8532013-07-31 19:52:072205 AddNewOrUpdatedExtension(extension,
2206 initial_state,
2207 blacklist_state,
2208 page_ordinal);
[email protected]399583b2012-12-11 09:33:422209 }
[email protected]8c484b742012-11-29 06:05:362210}
2211
2212void ExtensionService::AddNewOrUpdatedExtension(
2213 const Extension* extension,
[email protected]399583b2012-12-11 09:33:422214 Extension::State initial_state,
[email protected]8e289f0b2013-12-17 17:49:072215 extensions::BlacklistState blacklist_state,
[email protected]399583b2012-12-11 09:33:422216 const syncer::StringOrdinal& page_ordinal) {
[email protected]8c484b742012-11-29 06:05:362217 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]0f9e6262013-11-05 23:49:192218 const bool blacklisted_for_malware =
[email protected]8e289f0b2013-12-17 17:49:072219 blacklist_state == extensions::BLACKLISTED_MALWARE;
[email protected]9f3c8532013-07-31 19:52:072220 extension_prefs_->OnExtensionInstalled(extension,
2221 initial_state,
[email protected]0f9e6262013-11-05 23:49:192222 blacklisted_for_malware,
[email protected]9f3c8532013-07-31 19:52:072223 page_ordinal);
[email protected]9e9c1d12013-07-31 01:58:122224 delayed_installs_.Remove(extension->id());
[email protected]ffd2f79e2013-11-14 00:11:462225 if (extensions::ManifestURL::UpdatesFromGallery(extension)) {
2226 extensions::ExtensionSystem::Get(profile_)->install_verifier()->Add(
2227 extension->id(), InstallVerifier::AddResultCallback());
2228 }
[email protected]6f6101832012-11-27 22:10:482229 FinishInstallation(extension);
2230}
2231
2232void ExtensionService::MaybeFinishDelayedInstallation(
2233 const std::string& extension_id) {
[email protected]9f4e4f082013-06-21 07:11:192234 // Check if the extension already got installed.
2235 if (!delayed_installs_.Contains(extension_id))
[email protected]6f6101832012-11-27 22:10:482236 return;
[email protected]9f4e4f082013-06-21 07:11:192237 extensions::ExtensionPrefs::DelayReason reason =
2238 extension_prefs_->GetDelayedInstallReason(extension_id);
2239
2240 // Check if the extension is idle. DELAY_REASON_NONE is used for older
2241 // preferences files that will not have set this field but it was previously
2242 // only used for idle updates.
2243 if ((reason == extensions::ExtensionPrefs::DELAY_REASON_WAIT_FOR_IDLE ||
2244 reason == extensions::ExtensionPrefs::DELAY_REASON_NONE) &&
2245 is_ready() && !IsExtensionIdle(extension_id))
[email protected]6f6101832012-11-27 22:10:482246 return;
2247
[email protected]9f4e4f082013-06-21 07:11:192248 const Extension* extension = delayed_installs_.GetByID(extension_id);
2249 if (reason == extensions::ExtensionPrefs::DELAY_REASON_WAIT_FOR_IMPORTS) {
2250 ImportStatus status = SatisfyImports(extension);
2251 if (status != IMPORT_STATUS_OK) {
2252 if (status == IMPORT_STATUS_UNRECOVERABLE) {
2253 delayed_installs_.Remove(extension_id);
2254 // Make sure no version of the extension is actually installed, (i.e.,
2255 // that this delayed install was not an update).
2256 CHECK(!extension_prefs_->GetInstalledExtensionInfo(extension_id).get());
2257 extension_prefs_->DeleteExtensionPrefs(extension_id);
2258 }
2259 return;
2260 }
2261 }
2262
[email protected]6f6101832012-11-27 22:10:482263 FinishDelayedInstallation(extension_id);
2264}
2265
2266void ExtensionService::FinishDelayedInstallation(
2267 const std::string& extension_id) {
2268 scoped_refptr<const Extension> extension(
2269 GetPendingExtensionUpdate(extension_id));
[email protected]dc24976f2013-06-02 21:15:092270 CHECK(extension.get());
[email protected]9f4e4f082013-06-21 07:11:192271 delayed_installs_.Remove(extension_id);
[email protected]6f6101832012-11-27 22:10:482272
[email protected]399583b2012-12-11 09:33:422273 if (!extension_prefs_->FinishDelayedInstallInfo(extension_id))
[email protected]6f6101832012-11-27 22:10:482274 NOTREACHED();
2275
[email protected]dc24976f2013-06-02 21:15:092276 FinishInstallation(extension.get());
[email protected]6f6101832012-11-27 22:10:482277}
2278
2279void ExtensionService::FinishInstallation(const Extension* extension) {
[email protected]e7554c3f2013-05-29 00:36:562280 const extensions::Extension* existing_extension =
2281 GetInstalledExtension(extension->id());
2282 bool is_update = false;
2283 std::string old_name;
2284 if (existing_extension) {
2285 is_update = true;
2286 old_name = existing_extension->name();
2287 }
2288 extensions::InstalledExtensionInfo details(extension, is_update, old_name);
[email protected]fcb58a862012-05-01 01:03:152289 content::NotificationService::current()->Notify(
2290 chrome::NOTIFICATION_EXTENSION_INSTALLED,
2291 content::Source<Profile>(profile_),
[email protected]41bb80bd2013-05-03 10:56:022292 content::Details<const extensions::InstalledExtensionInfo>(&details));
[email protected]fcb58a862012-05-01 01:03:152293
[email protected]d96eb512012-11-01 23:44:082294 bool unacknowledged_external = IsUnacknowledgedExternalExtension(extension);
[email protected]41070e8d2012-10-24 01:34:362295
[email protected]399583b2012-12-11 09:33:422296 // Unpacked extensions default to allowing file access, but if that has been
2297 // overridden, don't reset the value.
[email protected]1d5e58b2013-01-31 08:41:402298 if (Manifest::ShouldAlwaysAllowFileAccess(extension->location()) &&
[email protected]399583b2012-12-11 09:33:422299 !extension_prefs_->HasAllowFileAccessSetting(extension->id())) {
2300 extension_prefs_->SetAllowFileAccess(extension->id(), true);
2301 }
2302
[email protected]6f6101832012-11-27 22:10:482303 AddExtension(extension);
[email protected]612a1cb12012-10-17 13:18:032304
2305 // If this is a new external extension that was disabled, alert the user
[email protected]d96eb512012-11-01 23:44:082306 // so he can reenable it. We do this last so that it has already been
2307 // added to our list of extensions.
[email protected]3e3fafbb2013-08-17 13:33:162308 if (unacknowledged_external && !is_update) {
[email protected]612a1cb12012-10-17 13:18:032309 UpdateExternalExtensionAlert();
[email protected]d96eb512012-11-01 23:44:082310 UMA_HISTOGRAM_ENUMERATION("Extensions.ExternalExtensionEvent",
2311 EXTERNAL_EXTENSION_INSTALLED,
2312 EXTERNAL_EXTENSION_BUCKET_BOUNDARY);
[email protected]446e37e2013-08-07 00:30:022313 if (extensions::ManifestURL::UpdatesFromGallery(extension)) {
2314 UMA_HISTOGRAM_ENUMERATION("Extensions.ExternalExtensionEventWebstore",
2315 EXTERNAL_EXTENSION_INSTALLED,
2316 EXTERNAL_EXTENSION_BUCKET_BOUNDARY);
2317 } else {
2318 UMA_HISTOGRAM_ENUMERATION("Extensions.ExternalExtensionEventNonWebstore",
2319 EXTERNAL_EXTENSION_INSTALLED,
2320 EXTERNAL_EXTENSION_BUCKET_BOUNDARY);
2321 }
[email protected]d96eb512012-11-01 23:44:082322 }
[email protected]9f4e4f082013-06-21 07:11:192323
2324 // Check extensions that may have been delayed only because this shared module
2325 // was not available.
2326 if (SharedModuleInfo::IsSharedModule(extension)) {
2327 MaybeFinishDelayedInstallations();
2328 }
[email protected]4a190632009-05-09 01:07:422329}
2330
[email protected]76b65442012-11-17 14:11:482331const Extension* ExtensionService::GetPendingExtensionUpdate(
2332 const std::string& id) const {
[email protected]9f4e4f082013-06-21 07:11:192333 return delayed_installs_.GetByID(id);
[email protected]76b65442012-11-17 14:11:482334}
2335
[email protected]bb7f40952011-01-13 00:21:202336void ExtensionService::TrackTerminatedExtension(const Extension* extension) {
[email protected]84df8332011-12-06 18:22:462337 if (!terminated_extensions_.Contains(extension->id()))
2338 terminated_extensions_.Insert(make_scoped_refptr(extension));
[email protected]fa2416f2011-05-03 08:41:202339
[email protected]b0af4792013-10-23 09:12:132340 UnloadExtension(extension->id(), UnloadedExtensionInfo::REASON_TERMINATE);
[email protected]bb7f40952011-01-13 00:21:202341}
2342
2343void ExtensionService::UntrackTerminatedExtension(const std::string& id) {
[email protected]fa2416f2011-05-03 08:41:202344 std::string lowercase_id = StringToLowerASCII(id);
[email protected]60a174a2013-08-02 20:29:282345 const Extension* extension = terminated_extensions_.GetByID(lowercase_id);
[email protected]84df8332011-12-06 18:22:462346 terminated_extensions_.Remove(lowercase_id);
[email protected]fb789532013-08-27 02:40:212347 if (extension) {
2348 content::NotificationService::current()->Notify(
2349 chrome::NOTIFICATION_EXTENSION_REMOVED,
2350 content::Source<Profile>(profile_),
2351 content::Details<const Extension>(extension));
2352 }
[email protected]bb7f40952011-01-13 00:21:202353}
2354
[email protected]0dfe05c2011-02-23 23:03:362355const Extension* ExtensionService::GetTerminatedExtension(
[email protected]8001df22011-04-28 19:59:472356 const std::string& id) const {
[email protected]695b5712012-12-06 23:55:282357 return GetExtensionById(id, INCLUDE_TERMINATED);
[email protected]8001df22011-04-28 19:59:472358}
2359
2360const Extension* ExtensionService::GetInstalledExtension(
2361 const std::string& id) const {
[email protected]695b5712012-12-06 23:55:282362 int include_mask = INCLUDE_ENABLED |
2363 INCLUDE_DISABLED |
2364 INCLUDE_TERMINATED |
2365 INCLUDE_BLACKLISTED;
2366 return GetExtensionById(id, include_mask);
[email protected]0dfe05c2011-02-23 23:03:362367}
2368
[email protected]eaa7dd182010-12-14 11:09:002369bool ExtensionService::ExtensionBindingsAllowed(const GURL& url) {
[email protected]615d88f2011-12-13 01:47:442370 // Allow bindings for all packaged extensions and component hosted apps.
[email protected]be9915fb2013-07-18 09:28:552371 const Extension* extension = extensions_.GetExtensionOrAppByURL(url);
[email protected]615d88f2011-12-13 01:47:442372 return extension && (!extension->is_hosted_app() ||
[email protected]1d5e58b2013-01-31 08:41:402373 extension->location() == Manifest::COMPONENT);
[email protected]6d2e60bd2010-06-03 22:37:392374}
2375
[email protected]4d007b312012-10-17 03:00:482376bool ExtensionService::ShouldBlockUrlInBrowserTab(GURL* url) {
[email protected]be9915fb2013-07-18 09:28:552377 const Extension* extension = extensions_.GetExtensionOrAppByURL(*url);
[email protected]4d007b312012-10-17 03:00:482378 if (extension && extension->is_platform_app()) {
2379 *url = GURL(chrome::kExtensionInvalidRequestURL);
2380 return true;
2381 }
2382
2383 return false;
2384}
2385
[email protected]9060d8b02012-01-13 02:14:302386bool ExtensionService::OnExternalExtensionFileFound(
[email protected]8ef78fd2010-08-19 17:14:322387 const std::string& id,
[email protected]8e4560b62011-01-14 10:09:142388 const Version* version,
[email protected]650b2d52013-02-10 03:41:452389 const base::FilePath& path,
[email protected]1d5e58b2013-01-31 08:41:402390 Manifest::Location location,
[email protected]47fc70c2011-12-06 07:29:512391 int creation_flags,
2392 bool mark_acknowledged) {
[email protected]ab22ba42011-01-14 16:36:382393 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
2394 CHECK(Extension::IdIsValid(id));
[email protected]79c833b52011-04-05 18:31:012395 if (extension_prefs_->IsExternalExtensionUninstalled(id))
[email protected]9060d8b02012-01-13 02:14:302396 return false;
[email protected]a8af9fdb2010-10-28 21:52:202397
[email protected]7577a5c52009-07-30 06:21:582398 // Before even bothering to unpack, check and see if we already have this
[email protected]4c967932009-07-31 01:15:492399 // version. This is important because these extensions are going to get
[email protected]7577a5c52009-07-30 06:21:582400 // installed on every startup.
[email protected]9adb9692010-10-29 23:14:022401 const Extension* existing = GetExtensionById(id, true);
[email protected]910f72ce2012-08-24 01:38:352402
[email protected]7577a5c52009-07-30 06:21:582403 if (existing) {
[email protected]910f72ce2012-08-24 01:38:352404 // The default apps will have the location set as INTERNAL. Since older
2405 // default apps are installed as EXTERNAL, we override them. However, if the
2406 // app is already installed as internal, then do the version check.
[email protected]31bb5ee62012-09-12 22:58:402407 // TODO(grv) : Remove after Q1-2013.
[email protected]910f72ce2012-08-24 01:38:352408 bool is_default_apps_migration =
[email protected]1d5e58b2013-01-31 08:41:402409 (location == Manifest::INTERNAL &&
2410 Manifest::IsExternalLocation(existing->location()));
[email protected]910f72ce2012-08-24 01:38:352411
2412 if (!is_default_apps_migration) {
2413 DCHECK(version);
2414
2415 switch (existing->version()->CompareTo(*version)) {
2416 case -1: // existing version is older, we should upgrade
2417 break;
2418 case 0: // existing version is same, do nothing
2419 return false;
2420 case 1: // existing version is newer, uh-oh
2421 LOG(WARNING) << "Found external version of extension " << id
2422 << "that is older than current version. Current version "
2423 << "is: " << existing->VersionString() << ". New "
2424 << "version is: " << version->GetString()
2425 << ". Keeping current version.";
2426 return false;
2427 }
[email protected]7577a5c52009-07-30 06:21:582428 }
2429 }
2430
[email protected]9060d8b02012-01-13 02:14:302431 // If the extension is already pending, don't start an install.
[email protected]e3987852012-05-04 10:06:302432 if (!pending_extension_manager()->AddFromExternalFile(
[email protected]464213a2013-10-15 01:06:482433 id, location, *version, creation_flags, mark_acknowledged)) {
[email protected]9060d8b02012-01-13 02:14:302434 return false;
[email protected]e3987852012-05-04 10:06:302435 }
[email protected]9c635f22010-12-02 09:36:362436
[email protected]14908b72011-04-20 06:54:362437 // no client (silent install)
[email protected]f8636f92013-08-09 21:02:372438 scoped_refptr<CrxInstaller> installer(CrxInstaller::CreateSilent(this));
[email protected]6dfbbf82010-03-12 23:09:162439 installer->set_install_source(location);
2440 installer->set_expected_id(id);
[email protected]cb0e50312011-05-09 15:03:072441 installer->set_expected_version(*version);
2442 installer->set_install_cause(extension_misc::INSTALL_CAUSE_EXTERNAL_FILE);
[email protected]1bf73cc32011-10-26 22:38:312443 installer->set_creation_flags(creation_flags);
[email protected]88e8ec9152013-01-17 04:05:182444#if defined(OS_CHROMEOS)
2445 extensions::InstallLimiter::Get(profile_)->Add(installer, path);
2446#else
[email protected]6dfbbf82010-03-12 23:09:162447 installer->InstallCrx(path);
[email protected]88e8ec9152013-01-17 04:05:182448#endif
[email protected]47fc70c2011-12-06 07:29:512449
2450 // Depending on the source, a new external extension might not need a user
2451 // notification on installation. For such extensions, mark them acknowledged
2452 // now to suppress the notification.
2453 if (mark_acknowledged)
2454 AcknowledgeExternalExtension(id);
[email protected]9060d8b02012-01-13 02:14:302455
2456 return true;
[email protected]7577a5c52009-07-30 06:21:582457}
2458
[email protected]b5a507b22013-11-08 20:41:572459scoped_ptr<DictionaryValue> ExtensionService::GetExtensionInfo(
2460 const std::string& extension_id) const {
2461 scoped_ptr<DictionaryValue> dictionary(new DictionaryValue);
2462 const extensions::Extension* extension = extensions_.GetByID(extension_id);
2463 if (extension) {
2464 GURL icon = extensions::ExtensionIconSource::GetIconURL(
2465 extension, extension_misc::EXTENSION_ICON_SMALLISH,
2466 ExtensionIconSet::MATCH_BIGGER, false, NULL);
2467 dictionary->SetString("id", extension_id);
2468 dictionary->SetString("name", extension->name());
2469 dictionary->SetString("icon", icon.spec());
2470 }
2471 return dictionary.Pass();
2472}
2473
[email protected]eaa7dd182010-12-14 11:09:002474void ExtensionService::ReportExtensionLoadError(
[email protected]650b2d52013-02-10 03:41:452475 const base::FilePath& extension_path,
[email protected]d11c8e92009-10-20 23:26:402476 const std::string &error,
[email protected]d11c8e92009-10-20 23:26:402477 bool be_noisy) {
[email protected]d8c8f25f2011-11-02 18:18:012478 content::NotificationService::current()->Notify(
2479 chrome::NOTIFICATION_EXTENSION_LOAD_ERROR,
2480 content::Source<Profile>(profile_),
2481 content::Details<const std::string>(&error));
[email protected]d11c8e92009-10-20 23:26:402482
[email protected]8a205c02011-02-04 20:41:332483 std::string path_str = UTF16ToUTF8(extension_path.LossyDisplayName());
[email protected]439f1e32013-12-09 20:09:092484 base::string16 message = UTF8ToUTF16(base::StringPrintf(
[email protected]18d4b6c2010-09-21 03:21:042485 "Could not load extension from '%s'. %s",
[email protected]fc670822011-12-17 09:33:492486 path_str.c_str(), error.c_str()));
[email protected]d11c8e92009-10-20 23:26:402487 ExtensionErrorReporter::GetInstance()->ReportError(message, be_noisy);
2488}
2489
[email protected]eaa7dd182010-12-14 11:09:002490void ExtensionService::DidCreateRenderViewForBackgroundPage(
[email protected]3a1dc572012-07-31 22:25:132491 extensions::ExtensionHost* host) {
[email protected]406027c02010-09-27 08:03:182492 OrphanedDevTools::iterator iter =
[email protected]2d2f6cfc2011-05-06 21:09:332493 orphaned_dev_tools_.find(host->extension_id());
[email protected]406027c02010-09-27 08:03:182494 if (iter == orphaned_dev_tools_.end())
2495 return;
2496
[email protected]04ea1bb2013-07-10 09:26:092497 iter->second->ConnectRenderViewHost(host->render_view_host());
[email protected]406027c02010-09-27 08:03:182498 orphaned_dev_tools_.erase(iter);
2499}
2500
[email protected]432115822011-07-10 15:52:272501void ExtensionService::Observe(int type,
[email protected]6c2381d2011-10-19 02:52:532502 const content::NotificationSource& source,
2503 const content::NotificationDetails& details) {
[email protected]432115822011-07-10 15:52:272504 switch (type) {
[email protected]3c4abc82012-10-22 22:25:542505 case chrome::NOTIFICATION_APP_TERMINATING:
2506 // Shutdown has started. Don't start any more extension installs.
2507 // (We cannot use ExtensionService::Shutdown() for this because it
2508 // happens too late in browser teardown.)
2509 browser_terminating_ = true;
2510 break;
[email protected]432115822011-07-10 15:52:272511 case chrome::NOTIFICATION_EXTENSION_PROCESS_TERMINATED: {
[email protected]6c2381d2011-10-19 02:52:532512 if (profile_ !=
2513 content::Source<Profile>(source).ptr()->GetOriginalProfile()) {
[email protected]bc535ee52010-08-31 18:40:322514 break;
[email protected]6c2381d2011-10-19 02:52:532515 }
[email protected]a4ed6282009-12-14 20:51:162516
[email protected]3a1dc572012-07-31 22:25:132517 extensions::ExtensionHost* host =
2518 content::Details<extensions::ExtensionHost>(details).ptr();
[email protected]f128af42010-08-05 18:05:262519
[email protected]fa2416f2011-05-03 08:41:202520 // Mark the extension as terminated and Unload it. We want it to
2521 // be in a consistent state: either fully working or not loaded
2522 // at all, but never half-crashed. We do it in a PostTask so
2523 // that other handlers of this notification will still have
2524 // access to the Extension and ExtensionHost.
[email protected]b3a25092013-05-28 22:08:162525 base::MessageLoop::current()->PostTask(
[email protected]14908b72011-04-20 06:54:362526 FROM_HERE,
[email protected]53612e82011-10-18 18:00:362527 base::Bind(
[email protected]fa2416f2011-05-03 08:41:202528 &ExtensionService::TrackTerminatedExtension,
[email protected]d8c8f25f2011-11-02 18:18:012529 AsWeakPtr(),
[email protected]fa2416f2011-05-03 08:41:202530 host->extension()));
[email protected]31f77262009-12-02 20:48:532531 break;
2532 }
[email protected]432115822011-07-10 15:52:272533 case content::NOTIFICATION_RENDERER_PROCESS_CREATED: {
[email protected]f3b1a082011-11-18 00:34:302534 content::RenderProcessHost* process =
2535 content::Source<content::RenderProcessHost>(source).ptr();
[email protected]fc30ef082011-08-18 04:07:192536 Profile* host_profile =
[email protected]f3b1a082011-11-18 00:34:302537 Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]fc30ef082011-08-18 04:07:192538 if (!profile_->IsSameProfile(host_profile->GetOriginalProfile()))
2539 break;
2540
[email protected]15397b42012-05-16 23:56:062541 // Extensions need to know the channel for API restrictions.
2542 process->Send(new ExtensionMsg_SetChannel(
[email protected]15d4d2d2013-08-09 06:49:032543 extensions::GetCurrentChannel()));
[email protected]15397b42012-05-16 23:56:062544
[email protected]4941fe92013-06-13 23:21:012545 // Platform apps need to know the system font.
2546 scoped_ptr<base::DictionaryValue> fonts(new base::DictionaryValue);
2547 webui::SetFontAndTextDirection(fonts.get());
2548 std::string font_family, font_size;
2549 fonts->GetString("fontfamily", &font_family);
2550 fonts->GetString("fontsize", &font_size);
2551 process->Send(new ExtensionMsg_SetSystemFont(
2552 font_family, font_size));
2553
[email protected]77a6970c2011-04-23 16:58:562554 // Valid extension function names, used to setup bindings in renderer.
2555 std::vector<std::string> function_names;
2556 ExtensionFunctionDispatcher::GetAllFunctionNames(&function_names);
2557 process->Send(new ExtensionMsg_SetFunctionNames(function_names));
[email protected]31f77262009-12-02 20:48:532558
[email protected]77a6970c2011-04-23 16:58:562559 // Scripting whitelist. This is modified by tests and must be communicated
2560 // to renderers.
2561 process->Send(new ExtensionMsg_SetScriptingWhitelist(
[email protected]c81f5d32013-10-26 10:38:422562 extensions::ExtensionsClient::Get()->GetScriptingWhitelist()));
[email protected]77a6970c2011-04-23 16:58:562563
2564 // Loaded extensions.
[email protected]9776e82e2011-11-15 02:17:532565 std::vector<ExtensionMsg_Loaded_Params> loaded_extensions;
[email protected]84df8332011-12-06 18:22:462566 for (ExtensionSet::const_iterator iter = extensions_.begin();
2567 iter != extensions_.end(); ++iter) {
[email protected]19647262011-12-16 09:57:492568 // Renderers don't need to know about themes.
2569 if (!(*iter)->is_theme())
[email protected]cadac622013-06-11 16:46:362570 loaded_extensions.push_back(ExtensionMsg_Loaded_Params(iter->get()));
[email protected]77a6970c2011-04-23 16:58:562571 }
[email protected]9776e82e2011-11-15 02:17:532572 process->Send(new ExtensionMsg_Loaded(loaded_extensions));
[email protected]77a6970c2011-04-23 16:58:562573 break;
2574 }
[email protected]432115822011-07-10 15:52:272575 case content::NOTIFICATION_RENDERER_PROCESS_TERMINATED: {
[email protected]f3b1a082011-11-18 00:34:302576 content::RenderProcessHost* process =
2577 content::Source<content::RenderProcessHost>(source).ptr();
[email protected]fc30ef082011-08-18 04:07:192578 Profile* host_profile =
[email protected]f3b1a082011-11-18 00:34:302579 Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]fc30ef082011-08-18 04:07:192580 if (!profile_->IsSameProfile(host_profile->GetOriginalProfile()))
2581 break;
2582
[email protected]52b76592013-11-02 17:59:032583 if (process_map_.Contains(process->GetID())) {
2584 // An extension process was terminated, this might have resulted in an
2585 // app or extension becoming idle.
2586 std::set<std::string> extension_ids =
2587 process_map_.GetExtensionsInProcess(process->GetID());
2588 for (std::set<std::string>::const_iterator it = extension_ids.begin();
2589 it != extension_ids.end(); ++it) {
2590 if (delayed_installs_.Contains(*it)) {
2591 base::MessageLoop::current()->PostDelayedTask(
2592 FROM_HERE,
2593 base::Bind(&ExtensionService::MaybeFinishDelayedInstallation,
2594 AsWeakPtr(), *it),
2595 base::TimeDelta::FromSeconds(kUpdateIdleDelay));
2596 }
2597 }
2598 }
2599
[email protected]6bc04fd82011-12-04 02:29:352600 process_map_.RemoveAllFromProcess(process->GetID());
[email protected]6f371442011-11-09 06:45:462601 BrowserThread::PostTask(
[email protected]38427a12013-11-09 17:34:202602 BrowserThread::IO,
2603 FROM_HERE,
2604 base::Bind(&extensions::InfoMap::UnregisterAllExtensionsInProcess,
[email protected]31d8f5f22012-04-02 15:22:082605 system_->info_map(),
[email protected]f3b1a082011-11-18 00:34:302606 process->GetID()));
[email protected]da5683db2011-04-23 17:12:212607 break;
2608 }
[email protected]92dd8d92013-02-26 00:41:082609 case chrome::NOTIFICATION_UPGRADE_RECOMMENDED: {
[email protected]75bdcb872013-03-13 00:41:452610 // Notify observers that chrome update is available.
2611 FOR_EACH_OBSERVER(extensions::UpdateObserver, update_observers_,
2612 OnChromeUpdateAvailable());
[email protected]92dd8d92013-02-26 00:41:082613 break;
2614 }
[email protected]aa96d3a2010-08-21 08:45:252615
[email protected]4814b512009-11-07 00:12:292616 default:
2617 NOTREACHED() << "Unexpected notification type.";
2618 }
2619}
2620
[email protected]90bb38d2012-11-14 18:36:032621void ExtensionService::OnExtensionInstallPrefChanged() {
[email protected]a6a7ced2012-11-01 17:24:182622 IdentifyAlertableExtensions();
2623 CheckManagementPolicy();
2624}
2625
[email protected]eaa7dd182010-12-14 11:09:002626bool ExtensionService::HasApps() const {
[email protected]ec5b50d2010-10-09 16:35:182627 return !GetAppIds().empty();
2628}
[email protected]377011d2010-07-20 04:18:502629
[email protected]eaa7dd182010-12-14 11:09:002630ExtensionIdSet ExtensionService::GetAppIds() const {
[email protected]ec5b50d2010-10-09 16:35:182631 ExtensionIdSet result;
[email protected]84df8332011-12-06 18:22:462632 for (ExtensionSet::const_iterator it = extensions_.begin();
[email protected]377011d2010-07-20 04:18:502633 it != extensions_.end(); ++it) {
[email protected]1d5e58b2013-01-31 08:41:402634 if ((*it)->is_app() && (*it)->location() != Manifest::COMPONENT)
[email protected]ec5b50d2010-10-09 16:35:182635 result.insert((*it)->id());
[email protected]377011d2010-07-20 04:18:502636 }
2637
[email protected]ec5b50d2010-10-09 16:35:182638 return result;
[email protected]377011d2010-07-20 04:18:502639}
[email protected]d7e9a862010-11-03 21:57:492640
[email protected]dc9a74f72012-08-17 18:07:212641bool ExtensionService::IsBackgroundPageReady(const Extension* extension) const {
[email protected]9367eabc2013-03-01 01:29:292642 if (!extensions::BackgroundInfo::HasPersistentBackgroundPage(extension))
[email protected]dc9a74f72012-08-17 18:07:212643 return true;
2644 ExtensionRuntimeDataMap::const_iterator it =
2645 extension_runtime_data_.find(extension->id());
2646 return it == extension_runtime_data_.end() ? false :
2647 it->second.background_page_ready;
[email protected]d7e9a862010-11-03 21:57:492648}
2649
[email protected]eaa7dd182010-12-14 11:09:002650void ExtensionService::SetBackgroundPageReady(const Extension* extension) {
[email protected]9367eabc2013-03-01 01:29:292651 DCHECK(extensions::BackgroundInfo::HasBackgroundPage(extension));
[email protected]d7e9a862010-11-03 21:57:492652 extension_runtime_data_[extension->id()].background_page_ready = true;
[email protected]ad50def52011-10-19 23:17:072653 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:272654 chrome::NOTIFICATION_EXTENSION_BACKGROUND_PAGE_READY,
[email protected]6c2381d2011-10-19 02:52:532655 content::Source<const Extension>(extension),
[email protected]ad50def52011-10-19 23:17:072656 content::NotificationService::NoDetails());
[email protected]d7e9a862010-11-03 21:57:492657}
2658
[email protected]dc9a74f72012-08-17 18:07:212659bool ExtensionService::IsBeingUpgraded(const Extension* extension) const {
2660 ExtensionRuntimeDataMap::const_iterator it =
2661 extension_runtime_data_.find(extension->id());
2662 return it == extension_runtime_data_.end() ? false :
2663 it->second.being_upgraded;
[email protected]d7e9a862010-11-03 21:57:492664}
2665
[email protected]eaa7dd182010-12-14 11:09:002666void ExtensionService::SetBeingUpgraded(const Extension* extension,
[email protected]b914e2952013-04-26 07:10:032667 bool value) {
[email protected]d7e9a862010-11-03 21:57:492668 extension_runtime_data_[extension->id()].being_upgraded = value;
2669}
[email protected]1bead0712010-11-27 17:41:532670
[email protected]e178ad92013-06-28 02:29:252671bool ExtensionService::IsBeingReloaded(
2672 const std::string& extension_id) const {
2673 return ContainsKey(extensions_being_reloaded_, extension_id);
2674}
2675
2676void ExtensionService::SetBeingReloaded(const std::string& extension_id,
[email protected]5e7015c2013-07-23 23:29:432677 bool isBeingReloaded) {
2678 if (isBeingReloaded)
[email protected]e178ad92013-06-28 02:29:252679 extensions_being_reloaded_.insert(extension_id);
[email protected]5e7015c2013-07-23 23:29:432680 else
[email protected]e178ad92013-06-28 02:29:252681 extensions_being_reloaded_.erase(extension_id);
[email protected]e178ad92013-06-28 02:29:252682}
2683
[email protected]dc9a74f72012-08-17 18:07:212684bool ExtensionService::HasUsedWebRequest(const Extension* extension) const {
2685 ExtensionRuntimeDataMap::const_iterator it =
2686 extension_runtime_data_.find(extension->id());
2687 return it == extension_runtime_data_.end() ? false :
2688 it->second.has_used_webrequest;
[email protected]39a5b532011-10-22 01:47:072689}
2690
2691void ExtensionService::SetHasUsedWebRequest(const Extension* extension,
2692 bool value) {
2693 extension_runtime_data_[extension->id()].has_used_webrequest = value;
2694}
2695
[email protected]612a1cb12012-10-17 13:18:032696bool ExtensionService::ShouldEnableOnInstall(const Extension* extension) {
2697 // Extensions installed by policy can't be disabled. So even if a previous
2698 // installation disabled the extension, make sure it is now enabled.
2699 if (system_->management_policy()->MustRemainEnabled(extension, NULL))
2700 return true;
2701
2702 if (extension_prefs_->IsExtensionDisabled(extension->id()))
2703 return false;
2704
[email protected]41070e8d2012-10-24 01:34:362705 if (FeatureSwitch::prompt_for_external_extensions()->IsEnabled()) {
[email protected]612a1cb12012-10-17 13:18:032706 // External extensions are initially disabled. We prompt the user before
[email protected]2c495c42013-01-04 21:49:542707 // enabling them. Hosted apps are excepted because they are not dangerous
2708 // (they need to be launched by the user anyway).
[email protected]1d5e58b2013-01-31 08:41:402709 if (extension->GetType() != Manifest::TYPE_HOSTED_APP &&
2710 Manifest::IsExternalLocation(extension->location()) &&
[email protected]612a1cb12012-10-17 13:18:032711 !extension_prefs_->IsExternalExtensionAcknowledged(extension->id())) {
2712 return false;
2713 }
2714 }
[email protected]612a1cb12012-10-17 13:18:032715
2716 return true;
2717}
[email protected]0db124b02012-11-07 04:55:052718
2719bool ExtensionService::IsExtensionIdle(const std::string& extension_id) const {
[email protected]98b6d942013-11-10 00:34:072720 extensions::ProcessManager* process_manager = system_->process_manager();
[email protected]fc332ae2012-11-14 20:17:332721 DCHECK(process_manager);
[email protected]0db124b02012-11-07 04:55:052722 extensions::ExtensionHost* host =
[email protected]d9a61e12012-11-14 02:43:472723 process_manager->GetBackgroundHostForExtension(extension_id);
[email protected]e7aa7b7e2012-11-27 04:51:222724 if (host)
2725 return false;
[email protected]52b76592013-11-02 17:59:032726
2727 content::SiteInstance* site_instance = process_manager->GetSiteInstanceForURL(
2728 Extension::GetBaseURLFromExtensionId(extension_id));
2729 if (site_instance && site_instance->HasProcess()) {
2730 return false;
2731 }
2732
[email protected]e7aa7b7e2012-11-27 04:51:222733 return process_manager->GetRenderViewHostsForExtension(extension_id).empty();
2734}
2735
2736bool ExtensionService::ShouldDelayExtensionUpdate(
2737 const std::string& extension_id,
2738 bool wait_for_idle) const {
2739 const char kOnUpdateAvailableEvent[] = "runtime.onUpdateAvailable";
2740
2741 // If delayed updates are globally disabled, or just for this extension,
2742 // don't delay.
2743 if (!install_updates_when_idle_ || !wait_for_idle)
2744 return false;
2745
[email protected]695b5712012-12-06 23:55:282746 const Extension* old = GetInstalledExtension(extension_id);
[email protected]e7aa7b7e2012-11-27 04:51:222747 // If there is no old extension, this is not an update, so don't delay.
2748 if (!old)
2749 return false;
2750
[email protected]9367eabc2013-03-01 01:29:292751 if (extensions::BackgroundInfo::HasPersistentBackgroundPage(old)) {
[email protected]e7aa7b7e2012-11-27 04:51:222752 // Delay installation if the extension listens for the onUpdateAvailable
2753 // event.
2754 return system_->event_router()->ExtensionHasEventListener(
2755 extension_id, kOnUpdateAvailableEvent);
2756 } else {
2757 // Delay installation if the extension is not idle.
2758 return !IsExtensionIdle(extension_id);
2759 }
[email protected]0db124b02012-11-07 04:55:052760}
[email protected]fdd679b2012-11-15 20:49:392761
[email protected]399583b2012-12-11 09:33:422762void ExtensionService::GarbageCollectIsolatedStorage() {
[email protected]650b2d52013-02-10 03:41:452763 scoped_ptr<base::hash_set<base::FilePath> > active_paths(
2764 new base::hash_set<base::FilePath>());
[email protected]399583b2012-12-11 09:33:422765 for (ExtensionSet::const_iterator it = extensions_.begin();
2766 it != extensions_.end(); ++it) {
[email protected]cadac622013-06-11 16:46:362767 if (extensions::AppIsolationInfo::HasIsolatedStorage(it->get())) {
2768 active_paths->insert(BrowserContext::GetStoragePartitionForSite(
2769 profile_, GetSiteForExtensionId((*it)->id()))->GetPath());
[email protected]399583b2012-12-11 09:33:422770 }
2771 }
2772
[email protected]9f4e4f082013-06-21 07:11:192773 DCHECK(!installs_delayed_for_gc());
2774 set_installs_delayed_for_gc(true);
[email protected]399583b2012-12-11 09:33:422775 BrowserContext::GarbageCollectStoragePartitions(
2776 profile_, active_paths.Pass(),
2777 base::Bind(&ExtensionService::OnGarbageCollectIsolatedStorageFinished,
2778 AsWeakPtr()));
2779}
2780
2781void ExtensionService::OnGarbageCollectIsolatedStorageFinished() {
[email protected]9f4e4f082013-06-21 07:11:192782 set_installs_delayed_for_gc(false);
2783 MaybeFinishDelayedInstallations();
2784}
2785
2786void ExtensionService::MaybeFinishDelayedInstallations() {
2787 std::vector<std::string> to_be_installed;
[email protected]399583b2012-12-11 09:33:422788 for (ExtensionSet::const_iterator it = delayed_installs_.begin();
2789 it != delayed_installs_.end();
2790 ++it) {
[email protected]9f4e4f082013-06-21 07:11:192791 to_be_installed.push_back((*it)->id());
[email protected]399583b2012-12-11 09:33:422792 }
[email protected]9f4e4f082013-06-21 07:11:192793 for (std::vector<std::string>::const_iterator it = to_be_installed.begin();
2794 it != to_be_installed.end();
[email protected]399583b2012-12-11 09:33:422795 ++it) {
[email protected]9f4e4f082013-06-21 07:11:192796 MaybeFinishDelayedInstallation(*it);
[email protected]399583b2012-12-11 09:33:422797 }
[email protected]399583b2012-12-11 09:33:422798}
2799
2800void ExtensionService::OnNeedsToGarbageCollectIsolatedStorage() {
2801 extension_prefs_->SetNeedsStorageGarbageCollection(true);
2802}
2803
[email protected]fdd679b2012-11-15 20:49:392804void ExtensionService::OnBlacklistUpdated() {
[email protected]48a359342013-10-30 00:22:002805 blacklist_->GetMalwareIDs(
[email protected]695b5712012-12-06 23:55:282806 GenerateInstalledExtensionsSet()->GetIDs(),
[email protected]3f2a2fa2013-09-24 02:55:252807 base::Bind(&ExtensionService::ManageBlacklist, AsWeakPtr()));
[email protected]695b5712012-12-06 23:55:282808}
2809
[email protected]3f2a2fa2013-09-24 02:55:252810void ExtensionService::ManageBlacklist(const std::set<std::string>& updated) {
[email protected]695b5712012-12-06 23:55:282811 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
2812
[email protected]3f2a2fa2013-09-24 02:55:252813 std::set<std::string> before = blacklisted_extensions_.GetIDs();
[email protected]16bf7ba72013-08-23 11:52:542814 std::set<std::string> no_longer_blacklisted =
[email protected]3f2a2fa2013-09-24 02:55:252815 base::STLSetDifference<std::set<std::string> >(before, updated);
[email protected]16bf7ba72013-08-23 11:52:542816 std::set<std::string> not_yet_blacklisted =
[email protected]3f2a2fa2013-09-24 02:55:252817 base::STLSetDifference<std::set<std::string> >(updated, before);
[email protected]695b5712012-12-06 23:55:282818
2819 for (std::set<std::string>::iterator it = no_longer_blacklisted.begin();
2820 it != no_longer_blacklisted.end(); ++it) {
2821 scoped_refptr<const Extension> extension =
2822 blacklisted_extensions_.GetByID(*it);
[email protected]3f2a2fa2013-09-24 02:55:252823 if (!extension.get()) {
2824 NOTREACHED() << "Extension " << *it << " no longer blacklisted, "
2825 << "but it was never blacklisted.";
[email protected]695b5712012-12-06 23:55:282826 continue;
[email protected]3f2a2fa2013-09-24 02:55:252827 }
[email protected]695b5712012-12-06 23:55:282828 blacklisted_extensions_.Remove(*it);
[email protected]3f2a2fa2013-09-24 02:55:252829 extension_prefs_->SetExtensionBlacklisted(extension->id(), false);
[email protected]dc24976f2013-06-02 21:15:092830 AddExtension(extension.get());
[email protected]ac875372013-02-28 04:36:092831 UMA_HISTOGRAM_ENUMERATION("ExtensionBlacklist.UnblacklistInstalled",
[email protected]dc24976f2013-06-02 21:15:092832 extension->location(),
2833 Manifest::NUM_LOCATIONS);
[email protected]695b5712012-12-06 23:55:282834 }
2835
2836 for (std::set<std::string>::iterator it = not_yet_blacklisted.begin();
2837 it != not_yet_blacklisted.end(); ++it) {
2838 scoped_refptr<const Extension> extension = GetInstalledExtension(*it);
[email protected]3f2a2fa2013-09-24 02:55:252839 if (!extension.get()) {
2840 NOTREACHED() << "Extension " << *it << " needs to be "
2841 << "blacklisted, but it's not installed.";
[email protected]695b5712012-12-06 23:55:282842 continue;
[email protected]3f2a2fa2013-09-24 02:55:252843 }
[email protected]695b5712012-12-06 23:55:282844 blacklisted_extensions_.Insert(extension);
[email protected]3f2a2fa2013-09-24 02:55:252845 extension_prefs_->SetExtensionBlacklisted(extension->id(), true);
[email protected]b0af4792013-10-23 09:12:132846 UnloadExtension(*it, UnloadedExtensionInfo::REASON_BLACKLIST);
[email protected]ac875372013-02-28 04:36:092847 UMA_HISTOGRAM_ENUMERATION("ExtensionBlacklist.BlacklistInstalled",
2848 extension->location(), Manifest::NUM_LOCATIONS);
[email protected]695b5712012-12-06 23:55:282849 }
2850
2851 IdentifyAlertableExtensions();
[email protected]fdd679b2012-11-15 20:49:392852}
[email protected]75bdcb872013-03-13 00:41:452853
2854void ExtensionService::AddUpdateObserver(extensions::UpdateObserver* observer) {
2855 update_observers_.AddObserver(observer);
2856}
2857
2858void ExtensionService::RemoveUpdateObserver(
2859 extensions::UpdateObserver* observer) {
2860 update_observers_.RemoveObserver(observer);
2861}