blob: c560220f40845cf4201795328763131b5eedb789 [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]211a3f32013-05-28 21:48:1829#include "chrome/browser/app_mode/app_mode_utils.h"
[email protected]15730c42009-09-03 00:03:2030#include "chrome/browser/browser_process.h"
[email protected]9ea0cd32013-07-12 01:50:3631#include "chrome/browser/chrome_notification_types.h"
[email protected]32b36c62012-10-24 05:37:4132#include "chrome/browser/extensions/api/app_runtime/app_runtime_api.h"
[email protected]895a1e52012-05-15 02:50:1233#include "chrome/browser/extensions/api/declarative/rules_registry_service.h"
[email protected]ad445762013-01-23 00:47:4434#include "chrome/browser/extensions/api/extension_action/extension_action_api.h"
[email protected]c39df1a2013-01-08 18:22:0735#include "chrome/browser/extensions/api/profile_keyed_api_factory.h"
[email protected]e9f541a2012-11-19 21:52:3136#include "chrome/browser/extensions/api/runtime/runtime_api.h"
[email protected]4636c832013-01-11 02:10:1137#include "chrome/browser/extensions/api/storage/settings_frontend.h"
[email protected]5db9ada2012-04-11 13:48:2038#include "chrome/browser/extensions/app_sync_data.h"
[email protected]d8c8f25f2011-11-02 18:18:0139#include "chrome/browser/extensions/component_loader.h"
[email protected]e0785902011-05-19 23:34:1740#include "chrome/browser/extensions/crx_installer.h"
[email protected]d9ede582012-08-14 19:21:3841#include "chrome/browser/extensions/data_deleter.h"
[email protected]ebc8d932013-09-11 23:47:2942#include "chrome/browser/extensions/event_router.h"
[email protected]62f051c2012-03-29 17:04:4443#include "chrome/browser/extensions/extension_disabled_ui.h"
[email protected]14a000d2010-04-29 21:44:2444#include "chrome/browser/extensions/extension_error_reporter.h"
[email protected]89226982012-07-16 20:09:1845#include "chrome/browser/extensions/extension_error_ui.h"
[email protected]b1748b1d82009-11-30 20:32:5646#include "chrome/browser/extensions/extension_host.h"
[email protected]00b38242012-07-18 18:43:2247#include "chrome/browser/extensions/extension_install_ui.h"
[email protected]4814b512009-11-07 00:12:2948#include "chrome/browser/extensions/extension_process_manager.h"
[email protected]3569b502012-01-12 20:08:2349#include "chrome/browser/extensions/extension_sorting.h"
[email protected]19eb80152011-02-26 00:28:4350#include "chrome/browser/extensions/extension_special_storage_policy.h"
[email protected]90310d92011-04-17 07:35:0451#include "chrome/browser/extensions/extension_sync_data.h"
[email protected]31d8f5f22012-04-02 15:22:0852#include "chrome/browser/extensions/extension_system.h"
[email protected]a7ff4b72013-10-17 20:56:0253#include "chrome/browser/extensions/extension_util.h"
[email protected]612a1cb12012-10-17 13:18:0354#include "chrome/browser/extensions/external_install_ui.h"
[email protected]5df038b2012-07-16 19:03:2755#include "chrome/browser/extensions/external_provider_impl.h"
56#include "chrome/browser/extensions/external_provider_interface.h"
[email protected]d8c8f25f2011-11-02 18:18:0157#include "chrome/browser/extensions/installed_loader.h"
[email protected]fdd679b2012-11-15 20:49:3958#include "chrome/browser/extensions/management_policy.h"
[email protected]b2907fd2011-03-25 16:43:3759#include "chrome/browser/extensions/pending_extension_manager.h"
[email protected]c333e792012-01-06 16:57:3960#include "chrome/browser/extensions/permissions_updater.h"
[email protected]d8c8f25f2011-11-02 18:18:0161#include "chrome/browser/extensions/unpacked_installer.h"
[email protected]75bdcb872013-03-13 00:41:4562#include "chrome/browser/extensions/update_observer.h"
[email protected]42a08162012-03-16 18:09:1163#include "chrome/browser/extensions/updater/extension_updater.h"
[email protected]8ecad5e2010-12-02 21:18:3364#include "chrome/browser/profiles/profile.h"
[email protected]cf593af2011-12-30 05:44:3965#include "chrome/browser/profiles/profile_manager.h"
[email protected]50736a12013-09-26 08:58:3466#include "chrome/browser/sync/sync_prefs.h"
[email protected]c8d407e2011-04-28 21:27:1767#include "chrome/browser/ui/webui/favicon_source.h"
[email protected]5eddc3e2011-10-26 04:33:3168#include "chrome/browser/ui/webui/ntp/thumbnail_source.h"
[email protected]b07e606e2012-09-15 20:16:1569#include "chrome/browser/ui/webui/theme_source.h"
[email protected]e2eb43112009-05-29 21:19:5470#include "chrome/common/chrome_switches.h"
[email protected]15397b42012-05-16 23:56:0671#include "chrome/common/chrome_version_info.h"
[email protected]f6431be82013-09-07 02:53:4572#include "chrome/common/crash_keys.h"
[email protected]9367eabc2013-03-01 01:29:2973#include "chrome/common/extensions/background_info.h"
[email protected]5b1a0e22009-05-26 19:00:5874#include "chrome/common/extensions/extension.h"
[email protected]9f4e4f082013-06-21 07:11:1975#include "chrome/common/extensions/extension_constants.h"
[email protected]7c927b62010-02-24 09:54:1376#include "chrome/common/extensions/extension_file_util.h"
[email protected]77a6970c2011-04-23 16:58:5677#include "chrome/common/extensions/extension_messages.h"
[email protected]612a1cb12012-10-17 13:18:0378#include "chrome/common/extensions/feature_switch.h"
[email protected]15d4d2d2013-08-09 06:49:0379#include "chrome/common/extensions/features/feature_channel.h"
[email protected]06492ed2013-03-24 22:13:1480#include "chrome/common/extensions/incognito_handler.h"
[email protected]561e33d52013-04-03 06:58:4381#include "chrome/common/extensions/manifest_handlers/app_isolation_info.h"
[email protected]6b414c232013-06-05 07:53:3482#include "chrome/common/extensions/manifest_handlers/app_launch_info.h"
[email protected]9f4e4f082013-06-21 07:11:1983#include "chrome/common/extensions/manifest_handlers/shared_module_info.h"
[email protected]65348062013-01-15 07:27:2284#include "chrome/common/extensions/manifest_url_handler.h"
[email protected]2cb5e302013-05-09 05:00:0685#include "chrome/common/extensions/permissions/permissions_data.h"
[email protected]8f3bcbd2013-06-05 08:42:4086#include "chrome/common/extensions/sync_helper.h"
[email protected]25b34332009-06-05 21:53:1987#include "chrome/common/pref_names.h"
[email protected]a57209872009-05-04 22:53:1488#include "chrome/common/url_constants.h"
[email protected]7a83dd072013-09-03 12:09:1789#include "components/startup_metric_utils/startup_metric_utils.h"
[email protected]c38831a12011-10-28 12:44:4990#include "content/public/browser/browser_thread.h"
[email protected]98f66112012-12-25 12:59:3691#include "content/public/browser/devtools_agent_host.h"
[email protected]05aad2da2011-10-28 10:12:3792#include "content/public/browser/notification_service.h"
[email protected]0d6e9bd2011-10-18 04:29:1693#include "content/public/browser/notification_types.h"
[email protected]f3b1a082011-11-18 00:34:3094#include "content/public/browser/render_process_host.h"
[email protected]399583b2012-12-11 09:33:4295#include "content/public/browser/site_instance.h"
96#include "content/public/browser/storage_partition.h"
[email protected]24ea7a12013-01-27 23:54:5397#include "content/public/browser/url_data_source.h"
[email protected]836e2982013-05-16 08:07:4298#include "extensions/common/constants.h"
[email protected]e9f541a2012-11-19 21:52:3199#include "extensions/common/error_utils.h"
[email protected]d42c11152013-08-22 19:36:32100#include "extensions/common/manifest.h"
[email protected]0c3c9732013-09-16 08:53:41101#include "extensions/common/manifest_constants.h"
[email protected]c41003472013-10-19 15:37:25102#include "extensions/common/permissions/permission_message_provider.h"
[email protected]65187152012-06-02 13:14:14103#include "grit/generated_resources.h"
[email protected]be28b5f42012-07-20 11:31:25104#include "net/base/registry_controlled_domains/registry_controlled_domain.h"
[email protected]895a1e52012-05-15 02:50:12105#include "sync/api/sync_change.h"
106#include "sync/api/sync_error_factory.h"
[email protected]cd67ed52013-10-15 01:22:13107#include "ui/base/webui/web_ui_util.h"
[email protected]a6483d22013-07-03 22:11:00108#include "url/gurl.h"
[email protected]08b1f75f2013-05-22 22:02:38109#include "webkit/browser/database/database_tracker.h"
110#include "webkit/browser/database/database_util.h"
[email protected]79a60642012-10-20 21:03:18111
[email protected]eed367e2011-04-12 03:43:31112#if defined(OS_CHROMEOS)
[email protected]88e8ec9152013-01-17 04:05:18113#include "chrome/browser/chromeos/extensions/install_limiter.h"
[email protected]f19bbf62013-07-09 01:22:32114#include "webkit/browser/fileapi/file_system_backend.h"
[email protected]c6f9203a2013-05-28 02:08:07115#include "webkit/browser/fileapi/file_system_context.h"
[email protected]eed367e2011-04-12 03:43:31116#endif
117
[email protected]55eb70e762012-02-20 17:38:39118using content::BrowserContext;
[email protected]631bb742011-11-02 11:29:39119using content::BrowserThread;
[email protected]98f66112012-12-25 12:59:36120using content::DevToolsAgentHost;
[email protected]bf3d9df2012-07-24 23:20:27121using extensions::CrxInstaller;
[email protected]1c321ee52012-05-21 03:02:34122using extensions::Extension;
123using extensions::ExtensionIdSet;
124using extensions::ExtensionInfo;
[email protected]215a7be2012-10-22 19:53:42125using extensions::FeatureSwitch;
[email protected]1d5e58b2013-01-31 08:41:40126using extensions::Manifest;
[email protected]c2e66e12012-06-27 06:27:06127using extensions::PermissionMessage;
128using extensions::PermissionMessages;
129using extensions::PermissionSet;
[email protected]9f4e4f082013-06-21 07:11:19130using extensions::SharedModuleInfo;
[email protected]e410b5f2012-12-14 14:02:24131using extensions::UnloadedExtensionInfo;
[email protected]5ef47ec2010-01-28 05:58:05132
[email protected]0c3c9732013-09-16 08:53:41133namespace errors = extensions::manifest_errors;
[email protected]c6d474f82009-12-16 21:11:06134
[email protected]b6ab96d2009-08-20 18:58:19135namespace {
136
[email protected]d96eb512012-11-01 23:44:08137// Histogram values for logging events related to externally installed
138// extensions.
139enum ExternalExtensionEvent {
140 EXTERNAL_EXTENSION_INSTALLED = 0,
141 EXTERNAL_EXTENSION_IGNORED,
142 EXTERNAL_EXTENSION_REENABLED,
143 EXTERNAL_EXTENSION_UNINSTALLED,
144 EXTERNAL_EXTENSION_BUCKET_BOUNDARY,
145};
146
[email protected]612a1cb12012-10-17 13:18:03147// Prompt the user this many times before considering an extension acknowledged.
148static const int kMaxExtensionAcknowledgePromptCount = 3;
149
[email protected]0db124b02012-11-07 04:55:05150// Wait this many seconds after an extensions becomes idle before updating it.
151static const int kUpdateIdleDelay = 5;
152
[email protected]9bd9a6862012-11-29 09:24:22153// Wait this many seconds before trying to garbage collect extensions again.
154static const int kGarbageCollectRetryDelay = 30;
155
[email protected]36fc54f2013-06-14 02:49:34156// Wait this many seconds after startup to see if there are any extensions
157// which can be garbage collected.
158static const int kGarbageCollectStartupDelay = 30;
159
[email protected]9f4e4f082013-06-21 07:11:19160static bool IsSharedModule(const Extension* extension) {
161 return SharedModuleInfo::IsSharedModule(extension);
162}
163
[email protected]4c9201c42013-08-16 04:56:21164static bool IsCWSSharedModule(const Extension* extension) {
165 return extension->from_webstore() && IsSharedModule(extension);
166}
167
168class SharedModuleProvider : public extensions::ManagementPolicy::Provider {
169 public:
170 SharedModuleProvider() {}
171 virtual ~SharedModuleProvider() {}
172
173 virtual std::string GetDebugPolicyProviderName() const OVERRIDE {
174 return "SharedModuleProvider";
175 }
176
177 virtual bool UserMayModifySettings(const Extension* extension,
178 string16* error) const OVERRIDE {
179 return !IsCWSSharedModule(extension);
180 }
181
182 virtual bool MustRemainEnabled(const Extension* extension,
183 string16* error) const OVERRIDE {
184 return IsCWSSharedModule(extension);
185 }
186
187 private:
188 DISALLOW_COPY_AND_ASSIGN(SharedModuleProvider);
189};
190
191
[email protected]c6d474f82009-12-16 21:11:06192} // namespace
[email protected]b6ab96d2009-08-20 18:58:19193
[email protected]eaa7dd182010-12-14 11:09:00194ExtensionService::ExtensionRuntimeData::ExtensionRuntimeData()
[email protected]d7e9a862010-11-03 21:57:49195 : background_page_ready(false),
[email protected]f8bf5992011-10-24 22:38:57196 being_upgraded(false),
197 has_used_webrequest(false) {
[email protected]d7e9a862010-11-03 21:57:49198}
199
[email protected]eaa7dd182010-12-14 11:09:00200ExtensionService::ExtensionRuntimeData::~ExtensionRuntimeData() {
[email protected]d7e9a862010-11-03 21:57:49201}
202
[email protected]eaa7dd182010-12-14 11:09:00203// ExtensionService.
[email protected]6014d672008-12-05 00:38:25204
[email protected]8e4560b62011-01-14 10:09:14205void ExtensionService::CheckExternalUninstall(const std::string& id) {
[email protected]a29a517a2011-01-21 21:11:12206 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]a8af9fdb2010-10-28 21:52:20207
[email protected]7a4c6852010-09-16 03:44:22208 // Check if the providers know about this extension.
[email protected]5df038b2012-07-16 19:03:27209 extensions::ProviderCollection::const_iterator i;
[email protected]0a60a2e2010-10-25 16:15:21210 for (i = external_extension_providers_.begin();
211 i != external_extension_providers_.end(); ++i) {
[email protected]8e4560b62011-01-14 10:09:14212 DCHECK(i->get()->IsReady());
[email protected]0a60a2e2010-10-25 16:15:21213 if (i->get()->HasExtension(id))
214 return; // Yup, known extension, don't uninstall.
[email protected]7a4c6852010-09-16 03:44:22215 }
216
[email protected]0f48fca2011-05-19 18:46:35217 // We get the list of external extensions to check from preferences.
218 // It is possible that an extension has preferences but is not loaded.
219 // For example, an extension that requires experimental permissions
220 // will not be loaded if the experimental command line flag is not used.
221 // In this case, do not uninstall.
[email protected]31bb5ee62012-09-12 22:58:40222 if (!GetInstalledExtension(id)) {
[email protected]0f48fca2011-05-19 18:46:35223 // We can't call UninstallExtension with an unloaded/invalid
224 // extension ID.
225 LOG(WARNING) << "Attempted uninstallation of unloaded/invalid extension "
226 << "with id: " << id;
227 return;
228 }
[email protected]d6ebc9792011-04-07 18:18:33229 UninstallExtension(id, true, NULL);
[email protected]7a4c6852010-09-16 03:44:22230}
231
[email protected]7f8f24f2012-11-15 19:40:14232void ExtensionService::SetFileTaskRunnerForTesting(
233 base::SequencedTaskRunner* task_runner) {
234 file_task_runner_ = task_runner;
235}
236
[email protected]8e4560b62011-01-14 10:09:14237void ExtensionService::ClearProvidersForTesting() {
[email protected]7a4c6852010-09-16 03:44:22238 external_extension_providers_.clear();
239}
240
[email protected]8e4560b62011-01-14 10:09:14241void ExtensionService::AddProviderForTesting(
[email protected]5df038b2012-07-16 19:03:27242 extensions::ExternalProviderInterface* test_provider) {
[email protected]a29a517a2011-01-21 21:11:12243 CHECK(test_provider);
[email protected]0a60a2e2010-10-25 16:15:21244 external_extension_providers_.push_back(
[email protected]5df038b2012-07-16 19:03:27245 linked_ptr<extensions::ExternalProviderInterface>(test_provider));
[email protected]7a4c6852010-09-16 03:44:22246}
247
[email protected]9060d8b02012-01-13 02:14:30248bool ExtensionService::OnExternalExtensionUpdateUrlFound(
[email protected]7a4c6852010-09-16 03:44:22249 const std::string& id,
[email protected]21a5a672010-11-04 10:47:42250 const GURL& update_url,
[email protected]464213a2013-10-15 01:06:48251 Manifest::Location location,
252 int creation_flags,
253 bool mark_acknowledged) {
[email protected]ab22ba42011-01-14 16:36:38254 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
255 CHECK(Extension::IdIsValid(id));
[email protected]a8af9fdb2010-10-28 21:52:20256
[email protected]8a87a5332011-08-11 17:54:59257 const Extension* extension = GetExtensionById(id, true);
258 if (extension) {
259 // Already installed. Skip this install if the current location has
260 // higher priority than |location|.
[email protected]1d5e58b2013-01-31 08:41:40261 Manifest::Location current = extension->location();
262 if (current == Manifest::GetHigherPriorityLocation(current, location))
[email protected]9060d8b02012-01-13 02:14:30263 return false;
[email protected]8a87a5332011-08-11 17:54:59264 // Otherwise, overwrite the current installation.
[email protected]7a4c6852010-09-16 03:44:22265 }
[email protected]9060d8b02012-01-13 02:14:30266
267 // Add |id| to the set of pending extensions. If it can not be added,
268 // then there is already a pending record from a higher-priority install
269 // source. In this case, signal that this extension will not be
270 // installed by returning false.
271 if (!pending_extension_manager()->AddFromExternalUpdateUrl(
[email protected]464213a2013-10-15 01:06:48272 id, update_url, location, creation_flags, mark_acknowledged)) {
[email protected]9060d8b02012-01-13 02:14:30273 return false;
[email protected]31bb5ee62012-09-12 22:58:40274 }
[email protected]9060d8b02012-01-13 02:14:30275
[email protected]94fde232012-04-27 10:22:30276 update_once_all_providers_are_ready_ = true;
[email protected]9060d8b02012-01-13 02:14:30277 return true;
[email protected]7a4c6852010-09-16 03:44:22278}
279
[email protected]dc9a74f72012-08-17 18:07:21280const Extension* ExtensionService::GetInstalledApp(const GURL& url) const {
[email protected]be9915fb2013-07-18 09:28:55281 const Extension* extension = extensions_.GetExtensionOrAppByURL(url);
[email protected]dc9a74f72012-08-17 18:07:21282 return (extension && extension->is_app()) ? extension : NULL;
[email protected]d9696672011-03-15 22:45:09283}
284
[email protected]dc9a74f72012-08-17 18:07:21285bool ExtensionService::IsInstalledApp(const GURL& url) const {
[email protected]d9696672011-03-15 22:45:09286 return !!GetInstalledApp(url);
[email protected]ffb204f22010-12-05 23:20:27287}
288
[email protected]6aeac8342010-10-01 20:21:18289// static
[email protected]d6ebc9792011-04-07 18:18:33290// This function is used to implement the command-line switch
[email protected]3bdba0d2011-08-23 07:17:30291// --uninstall-extension, and to uninstall an extension via sync. The LOG
292// statements within this function are used to inform the user if the uninstall
293// cannot be done.
[email protected]eaa7dd182010-12-14 11:09:00294bool ExtensionService::UninstallExtensionHelper(
295 ExtensionService* extensions_service,
[email protected]6aeac8342010-10-01 20:21:18296 const std::string& extension_id) {
[email protected]d6ebc9792011-04-07 18:18:33297 // We can't call UninstallExtension with an invalid extension ID.
[email protected]31bb5ee62012-09-12 22:58:40298 if (!extensions_service->GetInstalledExtension(extension_id)) {
[email protected]6aeac8342010-10-01 20:21:18299 LOG(WARNING) << "Attempted uninstallation of non-existent extension with "
[email protected]95da88c42011-03-31 10:07:33300 << "id: " << extension_id;
301 return false;
[email protected]6aeac8342010-10-01 20:21:18302 }
303
[email protected]d6ebc9792011-04-07 18:18:33304 // The following call to UninstallExtension will not allow an uninstall of a
305 // policy-controlled extension.
[email protected]65187152012-06-02 13:14:14306 string16 error;
[email protected]d6ebc9792011-04-07 18:18:33307 if (!extensions_service->UninstallExtension(extension_id, false, &error)) {
308 LOG(WARNING) << "Cannot uninstall extension with id " << extension_id
309 << ": " << error;
310 return false;
311 }
[email protected]95da88c42011-03-31 10:07:33312
[email protected]6aeac8342010-10-01 20:21:18313 return true;
314}
315
[email protected]eaa7dd182010-12-14 11:09:00316ExtensionService::ExtensionService(Profile* profile,
[email protected]f0841cd2011-01-19 15:07:24317 const CommandLine* command_line,
[email protected]650b2d52013-02-10 03:41:45318 const base::FilePath& install_directory,
[email protected]45759612012-07-10 17:21:23319 extensions::ExtensionPrefs* extension_prefs,
[email protected]fdd679b2012-11-15 20:49:39320 extensions::Blacklist* blacklist,
[email protected]0436b102011-04-15 18:30:03321 bool autoupdate_enabled,
[email protected]4a10006a2013-05-17 23:18:35322 bool extensions_enabled,
323 extensions::OneShotEvent* ready)
[email protected]fdd679b2012-11-15 20:49:39324 : extensions::Blacklist::Observer(blacklist),
325 profile_(profile),
[email protected]bd306722012-07-11 20:43:59326 system_(extensions::ExtensionSystem::Get(profile)),
[email protected]73c47932010-12-06 18:13:43327 extension_prefs_(extension_prefs),
[email protected]695b5712012-12-06 23:55:28328 blacklist_(blacklist),
[email protected]cccdf0aa2011-11-11 03:43:38329 settings_frontend_(extensions::SettingsFrontend::Create(profile)),
[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]9c009092013-05-01 03:14:09336 toolbar_model_(this),
[email protected]8b280302011-10-13 22:22:23337 menu_manager_(profile),
[email protected]dff1e042012-04-27 10:59:18338 update_once_all_providers_are_ready_(false),
[email protected]3c4abc82012-10-22 22:25:54339 browser_terminating_(false),
[email protected]9f4e4f082013-06-21 07:11:19340 installs_delayed_for_gc_(false),
[email protected]460c6712013-04-24 07:20:01341 is_first_run_(false),
[email protected]9c009092013-05-01 03:14:09342 app_sync_bundle_(this),
[email protected]50736a12013-09-26 08:58:34343 extension_sync_bundle_(this),
344 pending_app_enables_(
345 make_scoped_ptr(new browser_sync::SyncPrefs(
346 extension_prefs_->pref_service())),
347 &app_sync_bundle_,
348 syncer::APPS),
349 pending_extension_enables_(
350 make_scoped_ptr(new browser_sync::SyncPrefs(
351 extension_prefs_->pref_service())),
352 &extension_sync_bundle_,
353 syncer::EXTENSIONS) {
[email protected]c04fd3dd2013-09-05 08:20:10354#if defined(OS_CHROMEOS)
355 disable_garbage_collection_ = false;
356#endif
[email protected]a29a517a2011-01-21 21:11:12357 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]a8af9fdb2010-10-28 21:52:20358
[email protected]36a784c2009-06-23 06:21:08359 // Figure out if extension installation should be enabled.
[email protected]31bb5ee62012-09-12 22:58:40360 if (command_line->HasSwitch(switches::kDisableExtensions) ||
361 profile->GetPrefs()->GetBoolean(prefs::kDisableExtensions)) {
[email protected]6d60703b2009-08-29 01:29:23362 extensions_enabled_ = false;
[email protected]6b75ec32009-08-14 06:37:18363 }
[email protected]36a784c2009-06-23 06:21:08364
[email protected]3c4abc82012-10-22 22:25:54365 registrar_.Add(this, chrome::NOTIFICATION_APP_TERMINATING,
366 content::NotificationService::AllBrowserContextsAndSources());
[email protected]432115822011-07-10 15:52:27367 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_PROCESS_TERMINATED,
[email protected]ad50def52011-10-19 23:17:07368 content::NotificationService::AllBrowserContextsAndSources());
[email protected]432115822011-07-10 15:52:27369 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_CREATED,
[email protected]ad50def52011-10-19 23:17:07370 content::NotificationService::AllBrowserContextsAndSources());
[email protected]432115822011-07-10 15:52:27371 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_TERMINATED,
[email protected]ad50def52011-10-19 23:17:07372 content::NotificationService::AllBrowserContextsAndSources());
[email protected]0db124b02012-11-07 04:55:05373 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED,
374 content::NotificationService::AllBrowserContextsAndSources());
[email protected]92dd8d92013-02-26 00:41:08375 registrar_.Add(this, chrome::NOTIFICATION_UPGRADE_RECOMMENDED,
376 content::NotificationService::AllBrowserContextsAndSources());
[email protected]2fb7dc982010-09-29 12:24:28377 pref_change_registrar_.Init(profile->GetPrefs());
[email protected]90bb38d2012-11-14 18:36:03378 base::Closure callback =
379 base::Bind(&ExtensionService::OnExtensionInstallPrefChanged,
380 base::Unretained(this));
381 pref_change_registrar_.Add(prefs::kExtensionInstallAllowList, callback);
382 pref_change_registrar_.Add(prefs::kExtensionInstallDenyList, callback);
[email protected]e410b5f2012-12-14 14:02:24383 pref_change_registrar_.Add(prefs::kExtensionAllowedTypes, callback);
[email protected]4814b512009-11-07 00:12:29384
[email protected]93fd78f42009-07-10 16:43:17385 // Set up the ExtensionUpdater
386 if (autoupdate_enabled) {
[email protected]501105b2013-09-26 05:42:02387 int update_frequency = extensions::kDefaultUpdateFrequencySeconds;
[email protected]93fd78f42009-07-10 16:43:17388 if (command_line->HasSwitch(switches::kExtensionsUpdateFrequency)) {
[email protected]e83326f2010-07-31 17:29:25389 base::StringToInt(command_line->GetSwitchValueASCII(
390 switches::kExtensionsUpdateFrequency),
391 &update_frequency);
[email protected]93fd78f42009-07-10 16:43:17392 }
[email protected]42a08162012-03-16 18:09:11393 updater_.reset(new extensions::ExtensionUpdater(this,
394 extension_prefs,
395 profile->GetPrefs(),
396 profile,
397 update_frequency));
[email protected]93fd78f42009-07-10 16:43:17398 }
399
[email protected]25ae0152011-11-18 14:40:02400 component_loader_.reset(
401 new extensions::ComponentLoader(this,
402 profile->GetPrefs(),
403 g_browser_process->local_state()));
[email protected]8e4560b62011-01-14 10:09:14404
[email protected]0436b102011-04-15 18:30:03405 if (extensions_enabled_) {
[email protected]ae4c37e2012-12-21 01:16:25406 extensions::ExternalProviderImpl::CreateExternalProviders(
407 this, profile_, &external_extension_providers_);
[email protected]873531342011-03-09 12:16:05408 }
[email protected]b671760b2010-07-15 21:13:47409
[email protected]fb82dcd2012-03-21 14:15:46410 // Set this as the ExtensionService for extension sorting to ensure it
411 // cause syncs if required.
412 extension_prefs_->extension_sorting()->SetExtensionService(this);
413
[email protected]b3aa7182013-04-25 04:45:23414 is_first_run_ = !extension_prefs_->SetAlertSystemFirstRun();
415
[email protected]9ce11d22012-08-08 23:20:13416#if defined(ENABLE_EXTENSIONS)
[email protected]c77f2352012-08-08 22:07:58417 extension_action_storage_manager_.reset(
418 new extensions::ExtensionActionStorageManager(profile_));
[email protected]9ce11d22012-08-08 23:20:13419#endif
[email protected]c77f2352012-08-08 22:07:58420
[email protected]4c9201c42013-08-16 04:56:21421 shared_module_policy_provider_.reset(new SharedModuleProvider);
422
[email protected]cb0e50312011-05-09 15:03:07423 // How long is the path to the Extensions directory?
424 UMA_HISTOGRAM_CUSTOM_COUNTS("Extensions.ExtensionRootPathLength",
425 install_directory_.value().length(), 0, 500, 100);
[email protected]6014d672008-12-05 00:38:25426}
427
[email protected]84df8332011-12-06 18:22:46428const ExtensionSet* ExtensionService::extensions() const {
[email protected]ddb1e5a2010-12-13 20:10:45429 return &extensions_;
430}
431
[email protected]84df8332011-12-06 18:22:46432const ExtensionSet* ExtensionService::disabled_extensions() const {
[email protected]ddb1e5a2010-12-13 20:10:45433 return &disabled_extensions_;
434}
435
[email protected]84df8332011-12-06 18:22:46436const ExtensionSet* ExtensionService::terminated_extensions() const {
[email protected]bb7f40952011-01-13 00:21:20437 return &terminated_extensions_;
438}
439
[email protected]695b5712012-12-06 23:55:28440const ExtensionSet* ExtensionService::blacklisted_extensions() const {
441 return &blacklisted_extensions_;
442}
443
[email protected]9e9c1d12013-07-31 01:58:12444const ExtensionSet* ExtensionService::delayed_installs() const {
445 return &delayed_installs_;
446}
447
[email protected]695b5712012-12-06 23:55:28448scoped_ptr<const ExtensionSet>
449 ExtensionService::GenerateInstalledExtensionsSet() const {
450 scoped_ptr<ExtensionSet> installed_extensions(new ExtensionSet());
[email protected]7f4308d2012-01-18 07:43:01451 installed_extensions->InsertAll(extensions_);
452 installed_extensions->InsertAll(disabled_extensions_);
453 installed_extensions->InsertAll(terminated_extensions_);
[email protected]695b5712012-12-06 23:55:28454 installed_extensions->InsertAll(blacklisted_extensions_);
455 return installed_extensions.PassAs<const ExtensionSet>();
[email protected]7f4308d2012-01-18 07:43:01456}
457
[email protected]3f213ad2012-07-26 23:39:41458extensions::PendingExtensionManager*
459 ExtensionService::pending_extension_manager() {
[email protected]b2907fd2011-03-25 16:43:37460 return &pending_extension_manager_;
[email protected]ddb1e5a2010-12-13 20:10:45461}
462
[email protected]eaa7dd182010-12-14 11:09:00463ExtensionService::~ExtensionService() {
[email protected]c8d407e2011-04-28 21:27:17464 // No need to unload extensions here because they are profile-scoped, and the
465 // profile is in the process of being deleted.
[email protected]94b4ffc2011-02-04 05:55:17466
[email protected]5df038b2012-07-16 19:03:27467 extensions::ProviderCollection::const_iterator i;
[email protected]8e4560b62011-01-14 10:09:14468 for (i = external_extension_providers_.begin();
469 i != external_extension_providers_.end(); ++i) {
[email protected]5df038b2012-07-16 19:03:27470 extensions::ExternalProviderInterface* provider = i->get();
[email protected]8e4560b62011-01-14 10:09:14471 provider->ServiceShutdown();
472 }
[email protected]6014d672008-12-05 00:38:25473}
474
[email protected]6d147912013-07-09 08:02:14475void ExtensionService::SetSyncStartFlare(
476 const syncer::SyncableService::StartSyncFlare& flare) {
477 flare_ = flare;
478}
479
[email protected]037228a2012-10-05 01:36:16480void ExtensionService::Shutdown() {
[email protected]4c9201c42013-08-16 04:56:21481 system_->management_policy()->UnregisterProvider(
482 shared_module_policy_provider_.get());
[email protected]037228a2012-10-05 01:36:16483}
484
[email protected]b2907fd2011-03-25 16:43:37485const Extension* ExtensionService::GetExtensionById(
486 const std::string& id, bool include_disabled) const {
[email protected]81f0d162012-08-15 04:21:47487 int include_mask = INCLUDE_ENABLED;
[email protected]695b5712012-12-06 23:55:28488 if (include_disabled) {
489 // Include blacklisted extensions here because there are hundreds of
490 // callers of this function, and many might assume that this includes those
491 // that have been disabled due to blacklisting.
492 include_mask |= INCLUDE_DISABLED | INCLUDE_BLACKLISTED;
493 }
494 return GetExtensionById(id, include_mask);
495}
496
[email protected]399583b2012-12-11 09:33:42497GURL ExtensionService::GetSiteForExtensionId(const std::string& extension_id) {
498 return content::SiteInstance::GetSiteForURL(
499 profile_,
500 Extension::GetBaseURLFromExtensionId(extension_id));
501}
502
[email protected]695b5712012-12-06 23:55:28503const Extension* ExtensionService::GetExtensionById(
504 const std::string& id, int include_mask) const {
505 std::string lowercase_id = StringToLowerASCII(id);
506 if (include_mask & INCLUDE_ENABLED) {
507 const Extension* extension = extensions_.GetByID(lowercase_id);
508 if (extension)
509 return extension;
510 }
511 if (include_mask & INCLUDE_DISABLED) {
512 const Extension* extension = disabled_extensions_.GetByID(lowercase_id);
513 if (extension)
514 return extension;
515 }
516 if (include_mask & INCLUDE_TERMINATED) {
517 const Extension* extension = terminated_extensions_.GetByID(lowercase_id);
518 if (extension)
519 return extension;
520 }
521 if (include_mask & INCLUDE_BLACKLISTED) {
522 const Extension* extension = blacklisted_extensions_.GetByID(lowercase_id);
523 if (extension)
524 return extension;
525 }
526 return NULL;
[email protected]78994ab02010-12-08 18:06:44527}
528
[email protected]eaa7dd182010-12-14 11:09:00529void ExtensionService::Init() {
[email protected]a29a517a2011-01-21 21:11:12530 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]a8af9fdb2010-10-28 21:52:20531
[email protected]4a10006a2013-05-17 23:18:35532 DCHECK(!is_ready()); // Can't redo init.
[email protected]93fd78f42009-07-10 16:43:17533 DCHECK_EQ(extensions_.size(), 0u);
[email protected]9f1087e2009-06-15 17:29:32534
[email protected]820d9bd2013-04-03 03:46:03535 const CommandLine* cmd_line = CommandLine::ForCurrentProcess();
[email protected]820d9bd2013-04-03 03:46:03536 if (cmd_line->HasSwitch(switches::kInstallFromWebstore) ||
537 cmd_line->HasSwitch(switches::kLimitedInstallFromWebstore)) {
538 // The sole purpose of this launch is to install a new extension from CWS
539 // and immediately terminate: loading already installed extensions is
540 // unnecessary and may interfere with the inline install dialog (e.g. if an
541 // extension listens to onStartup and opens a window).
542 SetReadyAndNotifyListeners();
[email protected]ae4c37e2012-12-21 01:16:25543 } else {
[email protected]47b60072013-06-20 10:35:56544 // LoadAllExtensions() calls OnLoadedInstalledExtensions().
545 component_loader_->LoadAll();
546 extensions::InstalledLoader(this).LoadAllExtensions();
[email protected]9f4e4f082013-06-21 07:11:19547
[email protected]59ee99d2013-10-11 15:46:16548 ReconcileKnownDisabled();
549
[email protected]2edd57852013-08-14 22:07:40550 // Attempt to re-enable extensions whose only disable reason is reloading.
551 std::vector<std::string> extensions_to_enable;
552 for (ExtensionSet::const_iterator iter = disabled_extensions_.begin();
553 iter != disabled_extensions_.end(); ++iter) {
554 const Extension* e = iter->get();
555 if (extension_prefs_->GetDisableReasons(e->id()) ==
556 Extension::DISABLE_RELOAD) {
557 extensions_to_enable.push_back(e->id());
558 }
559 }
560 for (std::vector<std::string>::iterator it = extensions_to_enable.begin();
561 it != extensions_to_enable.end(); ++it) {
562 EnableExtension(*it);
563 }
564
[email protected]9f4e4f082013-06-21 07:11:19565 // Finish install (if possible) of extensions that were still delayed while
566 // the browser was shut down.
567 scoped_ptr<extensions::ExtensionPrefs::ExtensionsInfo> delayed_info(
568 extension_prefs_->GetAllDelayedInstallInfo());
569 for (size_t i = 0; i < delayed_info->size(); ++i) {
570 ExtensionInfo* info = delayed_info->at(i).get();
571 scoped_refptr<const Extension> extension(NULL);
572 if (info->extension_manifest) {
573 std::string error;
574 extension = Extension::Create(
575 info->extension_path,
576 info->extension_location,
577 *info->extension_manifest,
578 extension_prefs_->GetDelayedInstallCreationFlags(
579 info->extension_id),
580 info->extension_id,
581 &error);
582 if (extension.get())
583 delayed_installs_.Insert(extension);
584 }
585 }
586 MaybeFinishDelayedInstallations();
587
588 scoped_ptr<extensions::ExtensionPrefs::ExtensionsInfo> delayed_info2(
589 extension_prefs_->GetAllDelayedInstallInfo());
590 UMA_HISTOGRAM_COUNTS_100("Extensions.UpdateOnLoad",
591 delayed_info2->size() - delayed_info->size());
592
[email protected]47b60072013-06-20 10:35:56593 SetReadyAndNotifyListeners();
[email protected]ae4c37e2012-12-21 01:16:25594
[email protected]47b60072013-06-20 10:35:56595 // TODO(erikkay) this should probably be deferred to a future point
596 // rather than running immediately at startup.
597 CheckForExternalUpdates();
[email protected]894bb502009-05-21 22:39:57598
[email protected]47b60072013-06-20 10:35:56599 base::MessageLoop::current()->PostDelayedTask(
600 FROM_HERE,
601 base::Bind(&ExtensionService::GarbageCollectExtensions, AsWeakPtr()),
602 base::TimeDelta::FromSeconds(kGarbageCollectStartupDelay));
[email protected]215a7be2012-10-22 19:53:42603
[email protected]820d9bd2013-04-03 03:46:03604 if (extension_prefs_->NeedsStorageGarbageCollection()) {
605 GarbageCollectIsolatedStorage();
606 extension_prefs_->SetNeedsStorageGarbageCollection(false);
607 }
[email protected]4c9201c42013-08-16 04:56:21608 system_->management_policy()->RegisterProvider(
609 shared_module_policy_provider_.get());
[email protected]399583b2012-12-11 09:33:42610 }
[email protected]6014d672008-12-05 00:38:25611}
612
[email protected]31bb5ee62012-09-12 22:58:40613bool ExtensionService::UpdateExtension(const std::string& id,
[email protected]650b2d52013-02-10 03:41:45614 const base::FilePath& extension_path,
[email protected]31bb5ee62012-09-12 22:58:40615 const GURL& download_url,
616 CrxInstaller** out_crx_installer) {
[email protected]a29a517a2011-01-21 21:11:12617 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]3c4abc82012-10-22 22:25:54618 if (browser_terminating_) {
619 LOG(WARNING) << "Skipping UpdateExtension due to browser shutdown";
620 // Leak the temp file at extension_path. We don't want to add to the disk
621 // I/O burden at shutdown, we can't rely on the I/O completing anyway, and
622 // the file is in the OS temp directory which should be cleaned up for us.
623 return false;
624 }
[email protected]a8af9fdb2010-10-28 21:52:20625
[email protected]3f213ad2012-07-26 23:39:41626 const extensions::PendingExtensionInfo* pending_extension_info =
[email protected]51a3bf8b2012-06-08 22:53:06627 pending_extension_manager()->GetById(id);
[email protected]8ef78fd2010-08-19 17:14:32628
[email protected]695b5712012-12-06 23:55:28629 const Extension* extension = GetInstalledExtension(id);
[email protected]51a3bf8b2012-06-08 22:53:06630 if (!pending_extension_info && !extension) {
[email protected]aa142702010-03-26 01:26:33631 LOG(WARNING) << "Will not update extension " << id
632 << " because it is not installed or pending";
633 // Delete extension_path since we're not creating a CrxInstaller
634 // that would do it for us.
[email protected]7f8f24f2012-11-15 19:40:14635 if (!GetFileTaskRunner()->PostTask(
636 FROM_HERE,
[email protected]53612e82011-10-18 18:00:36637 base::Bind(
[email protected]7296f2762011-11-21 19:23:44638 &extension_file_util::DeleteFile, extension_path, false)))
[email protected]14908b72011-04-20 06:54:36639 NOTREACHED();
[email protected]420a0ec2011-06-01 01:07:03640
641 return false;
[email protected]e957fe52009-06-23 16:51:05642 }
643
[email protected]aa142702010-03-26 01:26:33644 // We want a silent install only for non-pending extensions and
645 // pending extensions that have install_silently set.
[email protected]f8636f92013-08-09 21:02:37646 scoped_ptr<ExtensionInstallPrompt> client;
[email protected]91e51d612012-10-21 23:03:05647 if (pending_extension_info && !pending_extension_info->install_silently())
[email protected]f8636f92013-08-09 21:02:37648 client.reset(ExtensionInstallUI::CreateInstallPromptWithProfile(profile_));
[email protected]aa142702010-03-26 01:26:33649
[email protected]f8636f92013-08-09 21:02:37650 scoped_refptr<CrxInstaller> installer(
651 CrxInstaller::Create(this, client.Pass()));
[email protected]6dfbbf82010-03-12 23:09:16652 installer->set_expected_id(id);
[email protected]464213a2013-10-15 01:06:48653 int creation_flags = Extension::NO_FLAGS;
[email protected]51a3bf8b2012-06-08 22:53:06654 if (pending_extension_info) {
655 installer->set_install_source(pending_extension_info->install_source());
656 if (pending_extension_info->install_silently())
657 installer->set_allow_silent_install(true);
[email protected]464213a2013-10-15 01:06:48658 creation_flags = pending_extension_info->creation_flags();
659 if (pending_extension_info->mark_acknowledged())
660 AcknowledgeExternalExtension(id);
[email protected]51a3bf8b2012-06-08 22:53:06661 } else if (extension) {
[email protected]5eb375e92010-11-26 07:50:41662 installer->set_install_source(extension->location());
[email protected]51a3bf8b2012-06-08 22:53:06663 }
[email protected]7d8b7072012-04-07 01:07:46664 // If the extension was installed from or has migrated to the webstore, or
[email protected]fcb2c2c2012-10-17 21:08:45665 // its auto-update URL is from the webstore, treat it as a webstore install.
666 // Note that we ignore some older extensions with blank auto-update URLs
667 // because we are mostly concerned with restrictions on NaCl extensions,
668 // which are newer.
[email protected]75764512011-12-19 19:54:28669 if ((extension && extension->from_webstore()) ||
[email protected]4a5fe3e22013-06-04 07:06:38670 (extension && extensions::ManifestURL::UpdatesFromGallery(extension)) ||
[email protected]963d13c2012-09-29 17:13:35671 (!extension && extension_urls::IsWebstoreUpdateUrl(
[email protected]51a3bf8b2012-06-08 22:53:06672 pending_extension_info->update_url()))) {
[email protected]a12ce8b22012-01-17 18:40:53673 creation_flags |= Extension::FROM_WEBSTORE;
674 }
675
676 // Bookmark apps being updated is kind of a contradiction, but that's because
677 // we mark the default apps as bookmark apps, and they're hosted in the web
678 // store, thus they can get updated. See http://crbug.com/101605 for more
679 // details.
680 if (extension && extension->from_bookmark())
681 creation_flags |= Extension::FROM_BOOKMARK;
682
[email protected]e33bbc22012-08-27 22:05:46683 if (extension && extension->was_installed_by_default())
684 creation_flags |= Extension::WAS_INSTALLED_BY_DEFAULT;
685
[email protected]464213a2013-10-15 01:06:48686 if (extension && extension->requires_permissions_consent())
687 creation_flags |= Extension::REQUIRE_PERMISSIONS_CONSENT;
688
[email protected]a12ce8b22012-01-17 18:40:53689 installer->set_creation_flags(creation_flags);
690
[email protected]6dfbbf82010-03-12 23:09:16691 installer->set_delete_source(true);
[email protected]655b2b1a2011-10-13 17:13:06692 installer->set_download_url(download_url);
[email protected]cb0e50312011-05-09 15:03:07693 installer->set_install_cause(extension_misc::INSTALL_CAUSE_UPDATE);
[email protected]6dfbbf82010-03-12 23:09:16694 installer->InstallCrx(extension_path);
[email protected]420a0ec2011-06-01 01:07:03695
696 if (out_crx_installer)
[email protected]dc24976f2013-06-02 21:15:09697 *out_crx_installer = installer.get();
[email protected]420a0ec2011-06-01 01:07:03698
699 return true;
[email protected]e957fe52009-06-23 16:51:05700}
701
[email protected]e178ad92013-06-28 02:29:25702void ExtensionService::ReloadExtension(const std::string extension_id) {
[email protected]a29a517a2011-01-21 21:11:12703 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]2a947202013-03-06 04:58:05704
705 // If the extension is already reloading, don't reload again.
706 if (extension_prefs_->GetDisableReasons(extension_id) &
707 Extension::DISABLE_RELOAD) {
708 return;
709 }
710
[email protected]650b2d52013-02-10 03:41:45711 base::FilePath path;
[email protected]9adb9692010-10-29 23:14:02712 const Extension* current_extension = GetExtensionById(extension_id, false);
[email protected]9cddd4702009-07-27 22:09:40713
[email protected]f17dbd42010-08-16 23:21:10714 // Disable the extension if it's loaded. It might not be loaded if it crashed.
[email protected]b65272f2009-08-31 15:47:06715 if (current_extension) {
[email protected]4814b512009-11-07 00:12:29716 // If the extension has an inspector open for its background page, detach
717 // the inspector and hang onto a cookie for it, so that we can reattach
718 // later.
[email protected]31d8f5f22012-04-02 15:22:08719 // TODO(yoz): this is not incognito-safe!
720 ExtensionProcessManager* manager = system_->process_manager();
[email protected]3a1dc572012-07-31 22:25:13721 extensions::ExtensionHost* host =
722 manager->GetBackgroundHostForExtension(extension_id);
[email protected]98f66112012-12-25 12:59:36723 if (host && DevToolsAgentHost::HasFor(host->render_view_host())) {
[email protected]4814b512009-11-07 00:12:29724 // Look for an open inspector for the background page.
[email protected]04ea1bb2013-07-10 09:26:09725 scoped_refptr<DevToolsAgentHost> agent_host =
726 DevToolsAgentHost::GetOrCreateFor(host->render_view_host());
727 agent_host->DisconnectRenderViewHost();
728 orphaned_dev_tools_[extension_id] = agent_host;
[email protected]4814b512009-11-07 00:12:29729 }
730
[email protected]b65272f2009-08-31 15:47:06731 path = current_extension->path();
[email protected]58076192013-07-19 19:43:50732 // BeingUpgraded is set back to false when the extension is added.
733 SetBeingUpgraded(current_extension, true);
[email protected]44d62b62012-04-11 00:06:03734 DisableExtension(extension_id, Extension::DISABLE_RELOAD);
[email protected]b914e2952013-04-26 07:10:03735 reloading_extensions_.insert(extension_id);
[email protected]1eb175082010-02-10 09:26:16736 } else {
737 path = unloaded_extension_paths_[extension_id];
[email protected]b65272f2009-08-31 15:47:06738 }
739
[email protected]9f4e4f082013-06-21 07:11:19740 if (delayed_installs_.Contains(extension_id)) {
[email protected]6f6101832012-11-27 22:10:48741 FinishDelayedInstallation(extension_id);
[email protected]0db124b02012-11-07 04:55:05742 return;
743 }
744
[email protected]43ceb002012-02-10 23:19:15745 // If we're reloading a component extension, use the component extension
746 // loader's reloader.
747 if (component_loader_->Exists(extension_id)) {
[email protected]e178ad92013-06-28 02:29:25748 SetBeingReloaded(extension_id, true);
[email protected]43ceb002012-02-10 23:19:15749 component_loader_->Reload(extension_id);
[email protected]e178ad92013-06-28 02:29:25750 SetBeingReloaded(extension_id, false);
[email protected]43ceb002012-02-10 23:19:15751 return;
752 }
753
[email protected]e6090e42010-03-23 22:44:08754 // Check the installed extensions to see if what we're reloading was already
755 // installed.
[email protected]e178ad92013-06-28 02:29:25756 SetBeingReloaded(extension_id, true);
[email protected]e6090e42010-03-23 22:44:08757 scoped_ptr<ExtensionInfo> installed_extension(
758 extension_prefs_->GetInstalledExtensionInfo(extension_id));
759 if (installed_extension.get() &&
760 installed_extension->extension_manifest.get()) {
[email protected]d8c8f25f2011-11-02 18:18:01761 extensions::InstalledLoader(this).Load(*installed_extension, false);
[email protected]e6090e42010-03-23 22:44:08762 } else {
[email protected]d8c8f25f2011-11-02 18:18:01763 // Otherwise, the extension is unpacked (location LOAD).
[email protected]e6090e42010-03-23 22:44:08764 // We should always be able to remember the extension's path. If it's not in
765 // the map, someone failed to update |unloaded_extension_paths_|.
766 CHECK(!path.empty());
[email protected]d8c8f25f2011-11-02 18:18:01767 extensions::UnpackedInstaller::Create(this)->Load(path);
[email protected]e6090e42010-03-23 22:44:08768 }
[email protected]e178ad92013-06-28 02:29:25769 // When reloading is done, mark this extension as done reloading.
770 SetBeingReloaded(extension_id, false);
[email protected]9cddd4702009-07-27 22:09:40771}
772
[email protected]fa2416f2011-05-03 08:41:20773bool ExtensionService::UninstallExtension(
[email protected]a12c706e2011-12-01 00:58:08774 std::string extension_id,
[email protected]fa2416f2011-05-03 08:41:20775 bool external_uninstall,
[email protected]65187152012-06-02 13:14:14776 string16* error) {
[email protected]a29a517a2011-01-21 21:11:12777 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]a8af9fdb2010-10-28 21:52:20778
[email protected]0d6ec3a72011-09-02 02:09:43779 scoped_refptr<const Extension> extension(GetInstalledExtension(extension_id));
[email protected]631cf822009-05-15 07:01:25780
[email protected]e7afe2452010-08-22 16:19:13781 // Callers should not send us nonexistent extensions.
[email protected]dc24976f2013-06-02 21:15:09782 CHECK(extension.get());
[email protected]9f1087e2009-06-15 17:29:32783
[email protected]95da88c42011-03-31 10:07:33784 // Policy change which triggers an uninstall will always set
785 // |external_uninstall| to true so this is the only way to uninstall
786 // managed extensions.
[email protected]65187152012-06-02 13:14:14787 if (!external_uninstall &&
788 !system_->management_policy()->UserMayModifySettings(
789 extension.get(), error)) {
[email protected]ad50def52011-10-19 23:17:07790 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:27791 chrome::NOTIFICATION_EXTENSION_UNINSTALL_NOT_ALLOWED,
[email protected]6c2381d2011-10-19 02:52:53792 content::Source<Profile>(profile_),
[email protected]dc24976f2013-06-02 21:15:09793 content::Details<const Extension>(extension.get()));
[email protected]d6ebc9792011-04-07 18:18:33794 return false;
795 }
[email protected]95da88c42011-03-31 10:07:33796
[email protected]3bdba0d2011-08-23 07:17:30797 // Extract the data we need for sync now, but don't actually sync until we've
798 // completed the uninstallation.
[email protected]6d147912013-07-09 08:02:14799 // TODO(tim): If we get here and IsSyncing is false, this will cause
800 // "back from the dead" style bugs, because sync will add-back the extension
801 // that was uninstalled here when MergeDataAndStartSyncing is called.
802 // See crbug.com/256795.
[email protected]65f173552012-06-28 22:43:58803 syncer::SyncChange sync_change;
[email protected]6d147912013-07-09 08:02:14804 if (extensions::sync_helper::IsSyncableApp(extension.get())) {
805 if (app_sync_bundle_.IsSyncing())
806 sync_change = app_sync_bundle_.CreateSyncChangeToDelete(extension.get());
807 else if (is_ready() && !flare_.is_null())
808 flare_.Run(syncer::APPS); // Tell sync to start ASAP.
809 } else if (extensions::sync_helper::IsSyncableExtension(extension.get())) {
810 if (extension_sync_bundle_.IsSyncing())
811 sync_change = extension_sync_bundle_.CreateSyncChangeToDelete(extension);
812 else if (is_ready() && !flare_.is_null())
813 flare_.Run(syncer::EXTENSIONS); // Tell sync to start ASAP.
[email protected]3bdba0d2011-08-23 07:17:30814 }
815
[email protected]dc24976f2013-06-02 21:15:09816 if (IsUnacknowledgedExternalExtension(extension.get())) {
[email protected]d96eb512012-11-01 23:44:08817 UMA_HISTOGRAM_ENUMERATION("Extensions.ExternalExtensionEvent",
818 EXTERNAL_EXTENSION_UNINSTALLED,
819 EXTERNAL_EXTENSION_BUCKET_BOUNDARY);
[email protected]446e37e2013-08-07 00:30:02820 if (extensions::ManifestURL::UpdatesFromGallery(extension.get())) {
821 UMA_HISTOGRAM_ENUMERATION("Extensions.ExternalExtensionEventWebstore",
822 EXTERNAL_EXTENSION_UNINSTALLED,
823 EXTERNAL_EXTENSION_BUCKET_BOUNDARY);
824 } else {
825 UMA_HISTOGRAM_ENUMERATION("Extensions.ExternalExtensionEventNonWebstore",
826 EXTERNAL_EXTENSION_UNINSTALLED,
827 EXTERNAL_EXTENSION_BUCKET_BOUNDARY);
828 }
[email protected]d96eb512012-11-01 23:44:08829 }
[email protected]9b217652010-10-08 22:04:23830 UMA_HISTOGRAM_ENUMERATION("Extensions.UninstallType",
[email protected]7fa19f82010-12-21 19:40:08831 extension->GetType(), 100);
[email protected]dc24976f2013-06-02 21:15:09832 RecordPermissionMessagesHistogram(extension.get(),
833 "Extensions.Permissions_Uninstall");
[email protected]9b217652010-10-08 22:04:23834
[email protected]831aa212010-03-26 13:55:19835 // Unload before doing more cleanup to ensure that nothing is hanging on to
836 // any of these resources.
[email protected]814a7bf0f2011-08-13 05:30:59837 UnloadExtension(extension_id, extension_misc::UNLOAD_REASON_UNINSTALL);
[email protected]831aa212010-03-26 13:55:19838
[email protected]9f1087e2009-06-15 17:29:32839 // Tell the backend to start deleting installed extensions on the file thread.
[email protected]12075d12013-02-27 05:38:05840 if (!Manifest::IsUnpackedLocation(extension->location())) {
[email protected]7f8f24f2012-11-15 19:40:14841 if (!GetFileTaskRunner()->PostTask(
842 FROM_HERE,
[email protected]53612e82011-10-18 18:00:36843 base::Bind(
[email protected]14908b72011-04-20 06:54:36844 &extension_file_util::UninstallExtension,
845 install_directory_,
[email protected]fa2416f2011-05-03 08:41:20846 extension_id)))
[email protected]14908b72011-04-20 06:54:36847 NOTREACHED();
[email protected]9f1087e2009-06-15 17:29:32848 }
849
[email protected]6b414c232013-06-05 07:53:34850 GURL launch_web_url_origin(
[email protected]cadac622013-06-11 16:46:36851 extensions::AppLaunchInfo::GetLaunchWebURL(extension.get()).GetOrigin());
[email protected]561e33d52013-04-03 06:58:43852 bool is_storage_isolated =
[email protected]dc24976f2013-06-02 21:15:09853 extensions::AppIsolationInfo::HasIsolatedStorage(extension.get());
[email protected]0d6ec3a72011-09-02 02:09:43854
[email protected]399583b2012-12-11 09:33:42855 if (is_storage_isolated) {
856 BrowserContext::AsyncObliterateStoragePartition(
857 profile_,
858 GetSiteForExtensionId(extension_id),
859 base::Bind(&ExtensionService::OnNeedsToGarbageCollectIsolatedStorage,
860 AsWeakPtr()));
861 } else {
862 if (extension->is_hosted_app() &&
863 !profile_->GetExtensionSpecialStoragePolicy()->
864 IsStorageProtected(launch_web_url_origin)) {
865 extensions::DataDeleter::StartDeleting(
866 profile_, extension_id, launch_web_url_origin);
867 }
868 extensions::DataDeleter::StartDeleting(profile_, extension_id,
869 extension->url());
[email protected]0d6ec3a72011-09-02 02:09:43870 }
[email protected]0d6ec3a72011-09-02 02:09:43871
[email protected]0dfe05c2011-02-23 23:03:36872 UntrackTerminatedExtension(extension_id);
[email protected]211030342010-09-30 18:41:06873
874 // Notify interested parties that we've uninstalled this extension.
[email protected]ad50def52011-10-19 23:17:07875 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:27876 chrome::NOTIFICATION_EXTENSION_UNINSTALLED,
[email protected]6c2381d2011-10-19 02:52:53877 content::Source<Profile>(profile_),
[email protected]dc24976f2013-06-02 21:15:09878 content::Details<const Extension>(extension.get()));
[email protected]d6ebc9792011-04-07 18:18:33879
[email protected]5db9ada2012-04-11 13:48:20880 if (app_sync_bundle_.HasExtensionId(extension_id) &&
[email protected]a4a147652012-07-03 23:41:32881 sync_change.sync_data().GetDataType() == syncer::APPS) {
[email protected]5db9ada2012-04-11 13:48:20882 app_sync_bundle_.ProcessDeletion(extension_id, sync_change);
883 } else if (extension_sync_bundle_.HasExtensionId(extension_id) &&
[email protected]a4a147652012-07-03 23:41:32884 sync_change.sync_data().GetDataType() == syncer::EXTENSIONS) {
[email protected]5db9ada2012-04-11 13:48:20885 extension_sync_bundle_.ProcessDeletion(extension_id, sync_change);
[email protected]3bdba0d2011-08-23 07:17:30886 }
887
[email protected]399583b2012-12-11 09:33:42888 delayed_installs_.Remove(extension_id);
[email protected]0db124b02012-11-07 04:55:05889
[email protected]198b5902013-06-27 10:36:11890 PruneSharedModulesOnUninstall(extension.get());
[email protected]9f4e4f082013-06-21 07:11:19891
[email protected]d4eda592013-09-18 03:37:57892 extension_prefs_->OnExtensionUninstalled(extension_id, extension->location(),
893 external_uninstall);
894
[email protected]333b1de2011-09-12 18:28:50895 // Track the uninstallation.
[email protected]49098f702011-10-13 03:47:18896 UMA_HISTOGRAM_ENUMERATION("Extensions.ExtensionUninstalled", 1, 2);
897
[email protected]d6ebc9792011-04-07 18:18:33898 return true;
[email protected]c10da4b02010-03-25 14:38:32899}
900
[email protected]c3cfb012011-04-06 22:07:35901bool ExtensionService::IsExtensionEnabled(
902 const std::string& extension_id) const {
[email protected]84df8332011-12-06 18:22:46903 if (extensions_.Contains(extension_id) ||
[email protected]dc9a74f72012-08-17 18:07:21904 terminated_extensions_.Contains(extension_id)) {
[email protected]36429da2011-07-11 20:25:18905 return true;
[email protected]dc9a74f72012-08-17 18:07:21906 }
[email protected]36429da2011-07-11 20:25:18907
[email protected]695b5712012-12-06 23:55:28908 if (disabled_extensions_.Contains(extension_id) ||
909 blacklisted_extensions_.Contains(extension_id)) {
[email protected]ad83ca242011-07-29 01:32:25910 return false;
[email protected]695b5712012-12-06 23:55:28911 }
[email protected]ad83ca242011-07-29 01:32:25912
913 // If the extension hasn't been loaded yet, check the prefs for it. Assume
914 // enabled unless otherwise noted.
915 return !extension_prefs_->IsExtensionDisabled(extension_id) &&
[email protected]f574c402012-12-04 23:20:31916 !extension_prefs_->IsExternalExtensionUninstalled(extension_id);
[email protected]c3cfb012011-04-06 22:07:35917}
918
919bool ExtensionService::IsExternalExtensionUninstalled(
920 const std::string& extension_id) const {
921 return extension_prefs_->IsExternalExtensionUninstalled(extension_id);
922}
923
[email protected]e2377032013-01-18 17:53:22924bool ExtensionService::IsExtensionEnabledForLauncher(
925 const std::string& extension_id) const {
926 return IsExtensionEnabled(extension_id) &&
927 !GetTerminatedExtension(extension_id);
928}
929
[email protected]aa5a5472013-10-04 03:41:04930bool ExtensionService::DoesExtensionRequirePermissionConsent(
931 const std::string& extension_id) const {
932 return extension_prefs_->IsExtensionDisabled(extension_id) &&
933 (extension_prefs_->GetDisableReasons(extension_id) &
934 Extension::DISABLE_PERMISSIONS_CONSENT);
935}
936
[email protected]eaa7dd182010-12-14 11:09:00937void ExtensionService::EnableExtension(const std::string& extension_id) {
[email protected]a29a517a2011-01-21 21:11:12938 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]a8af9fdb2010-10-28 21:52:20939
[email protected]06f92562011-04-29 19:27:31940 if (IsExtensionEnabled(extension_id))
[email protected]0c6da502009-08-14 22:32:39941 return;
[email protected]0c6da502009-08-14 22:32:39942
[email protected]b3317ad2011-04-28 23:46:00943 extension_prefs_->SetExtensionState(extension_id, Extension::ENABLED);
[email protected]eb5e4f92012-08-15 23:33:28944 extension_prefs_->ClearDisableReasons(extension_id);
[email protected]1784e83a2009-09-08 21:01:52945
[email protected]695b5712012-12-06 23:55:28946 const Extension* extension = disabled_extensions_.GetByID(extension_id);
[email protected]06f92562011-04-29 19:27:31947 // This can happen if sync enables an extension that is not
948 // installed yet.
949 if (!extension)
950 return;
951
[email protected]d96eb512012-11-01 23:44:08952 if (IsUnacknowledgedExternalExtension(extension)) {
953 UMA_HISTOGRAM_ENUMERATION("Extensions.ExternalExtensionEvent",
954 EXTERNAL_EXTENSION_REENABLED,
955 EXTERNAL_EXTENSION_BUCKET_BOUNDARY);
[email protected]446e37e2013-08-07 00:30:02956 if (extensions::ManifestURL::UpdatesFromGallery(extension)) {
957 UMA_HISTOGRAM_ENUMERATION("Extensions.ExternalExtensionEventWebstore",
958 EXTERNAL_EXTENSION_REENABLED,
959 EXTERNAL_EXTENSION_BUCKET_BOUNDARY);
960 } else {
961 UMA_HISTOGRAM_ENUMERATION("Extensions.ExternalExtensionEventNonWebstore",
962 EXTERNAL_EXTENSION_REENABLED,
963 EXTERNAL_EXTENSION_BUCKET_BOUNDARY);
964 }
[email protected]612a1cb12012-10-17 13:18:03965 AcknowledgeExternalExtension(extension->id());
[email protected]d96eb512012-11-01 23:44:08966 }
[email protected]612a1cb12012-10-17 13:18:03967
[email protected]0c6da502009-08-14 22:32:39968 // Move it over to the enabled list.
[email protected]84df8332011-12-06 18:22:46969 extensions_.Insert(make_scoped_refptr(extension));
[email protected]59ee99d2013-10-11 15:46:16970 if (disabled_extensions_.Remove(extension->id()))
971 extension_prefs_->SetKnownDisabled(disabled_extensions_.GetIDs());
[email protected]0c6da502009-08-14 22:32:39972
[email protected]62d30f42009-10-01 22:36:06973 NotifyExtensionLoaded(extension);
[email protected]3bdba0d2011-08-23 07:17:30974
[email protected]f74d7f32012-06-19 19:22:51975 // Notify listeners that the extension was enabled.
976 content::NotificationService::current()->Notify(
977 chrome::NOTIFICATION_EXTENSION_ENABLED,
978 content::Source<Profile>(profile_),
979 content::Details<const Extension>(extension));
980
[email protected]50736a12013-09-26 08:58:34981 // Syncing may not have started yet, so handle pending enables.
982 if (extensions::sync_helper::IsSyncableApp(extension))
983 pending_app_enables_.OnExtensionEnabled(extension->id());
984
985 if (extensions::sync_helper::IsSyncableExtension(extension))
986 pending_extension_enables_.OnExtensionEnabled(extension->id());
987
[email protected]3bdba0d2011-08-23 07:17:30988 SyncExtensionChangeIfNeeded(*extension);
[email protected]0c6da502009-08-14 22:32:39989}
990
[email protected]44d62b62012-04-11 00:06:03991void ExtensionService::DisableExtension(
992 const std::string& extension_id,
993 Extension::DisableReason disable_reason) {
[email protected]a29a517a2011-01-21 21:11:12994 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]a8af9fdb2010-10-28 21:52:20995
[email protected]b2ba9962009-12-10 20:10:15996 // The extension may have been disabled already.
[email protected]06f92562011-04-29 19:27:31997 if (!IsExtensionEnabled(extension_id))
[email protected]1784e83a2009-09-08 21:01:52998 return;
[email protected]1784e83a2009-09-08 21:01:52999
[email protected]06f92562011-04-29 19:27:311000 const Extension* extension = GetInstalledExtension(extension_id);
1001 // |extension| can be NULL if sync disables an extension that is not
1002 // installed yet.
[email protected]65187152012-06-02 13:14:141003 if (extension &&
[email protected]505ccdc2013-06-20 20:15:351004 disable_reason != Extension::DISABLE_RELOAD &&
[email protected]65187152012-06-02 13:14:141005 !system_->management_policy()->UserMayModifySettings(extension, NULL)) {
[email protected]95da88c42011-03-31 10:07:331006 return;
[email protected]65187152012-06-02 13:14:141007 }
[email protected]95da88c42011-03-31 10:07:331008
[email protected]b3317ad2011-04-28 23:46:001009 extension_prefs_->SetExtensionState(extension_id, Extension::DISABLED);
[email protected]eb5e4f92012-08-15 23:33:281010 extension_prefs_->AddDisableReason(extension_id, disable_reason);
[email protected]1784e83a2009-09-08 21:01:521011
[email protected]695b5712012-12-06 23:55:281012 int include_mask = INCLUDE_EVERYTHING & ~INCLUDE_DISABLED;
1013 extension = GetExtensionById(extension_id, include_mask);
[email protected]06f92562011-04-29 19:27:311014 if (!extension)
1015 return;
1016
[email protected]64742de32013-04-22 08:44:341017 // Reset the background_page_ready flag
1018 if (extensions::BackgroundInfo::HasBackgroundPage(extension))
1019 extension_runtime_data_[extension->id()].background_page_ready = false;
1020
[email protected]5c094792012-09-07 19:44:531021 // Move it over to the disabled list. Don't send a second unload notification
1022 // for terminated extensions being disabled.
[email protected]59ee99d2013-10-11 15:46:161023 if (disabled_extensions_.Insert(make_scoped_refptr(extension)))
1024 extension_prefs_->SetKnownDisabled(disabled_extensions_.GetIDs());
[email protected]5c094792012-09-07 19:44:531025 if (extensions_.Contains(extension->id())) {
[email protected]84df8332011-12-06 18:22:461026 extensions_.Remove(extension->id());
[email protected]5c094792012-09-07 19:44:531027 NotifyExtensionUnloaded(extension, extension_misc::UNLOAD_REASON_DISABLE);
1028 } else {
[email protected]84df8332011-12-06 18:22:461029 terminated_extensions_.Remove(extension->id());
[email protected]5c094792012-09-07 19:44:531030 }
[email protected]3bdba0d2011-08-23 07:17:301031
[email protected]50736a12013-09-26 08:58:341032 // Syncing may not have started yet, so handle pending enables.
1033 if (extensions::sync_helper::IsSyncableApp(extension))
1034 pending_app_enables_.OnExtensionDisabled(extension->id());
1035
1036 if (extensions::sync_helper::IsSyncableExtension(extension))
1037 pending_extension_enables_.OnExtensionDisabled(extension->id());
1038
[email protected]3bdba0d2011-08-23 07:17:301039 SyncExtensionChangeIfNeeded(*extension);
[email protected]1784e83a2009-09-08 21:01:521040}
1041
[email protected]1abf05e2013-07-09 17:04:361042void ExtensionService::DisableUserExtensions(
1043 const std::vector<std::string>& except_ids) {
[email protected]e516e4c2013-06-12 17:41:141044 extensions::ManagementPolicy* management_policy =
1045 system_->management_policy();
1046 extensions::ExtensionList to_disable;
1047
1048 for (ExtensionSet::const_iterator extension = extensions_.begin();
1049 extension != extensions_.end(); ++extension) {
[email protected]198b5902013-06-27 10:36:111050 if (management_policy->UserMayModifySettings(extension->get(), NULL))
[email protected]e516e4c2013-06-12 17:41:141051 to_disable.push_back(*extension);
1052 }
1053 for (ExtensionSet::const_iterator extension = terminated_extensions_.begin();
1054 extension != terminated_extensions_.end(); ++extension) {
[email protected]198b5902013-06-27 10:36:111055 if (management_policy->UserMayModifySettings(extension->get(), NULL))
[email protected]e516e4c2013-06-12 17:41:141056 to_disable.push_back(*extension);
1057 }
1058
1059 for (extensions::ExtensionList::const_iterator extension = to_disable.begin();
1060 extension != to_disable.end(); ++extension) {
[email protected]3082fe32013-08-06 11:12:381061 if ((*extension)->was_installed_by_default() &&
1062 extension_urls::IsWebstoreUpdateUrl(
1063 extensions::ManifestURL::GetUpdateURL(*extension)))
1064 continue;
[email protected]1abf05e2013-07-09 17:04:361065 const std::string& id = (*extension)->id();
1066 if (except_ids.end() == std::find(except_ids.begin(), except_ids.end(), id))
1067 DisableExtension(id, extensions::Extension::DISABLE_USER_ACTION);
[email protected]e516e4c2013-06-12 17:41:141068 }
1069}
1070
[email protected]eaa7dd182010-12-14 11:09:001071void ExtensionService::GrantPermissionsAndEnableExtension(
[email protected]009633c2013-03-07 22:08:281072 const Extension* extension) {
1073 GrantPermissions(extension);
[email protected]fe2dd7742011-04-19 22:52:491074 RecordPermissionMessagesHistogram(
1075 extension, "Extensions.Permissions_ReEnable");
[email protected]8d888c12010-11-30 00:00:251076 extension_prefs_->SetDidExtensionEscalatePermissions(extension, false);
1077 EnableExtension(extension->id());
1078}
1079
[email protected]009633c2013-03-07 22:08:281080void ExtensionService::GrantPermissions(const Extension* extension) {
[email protected]be083862012-09-01 03:53:451081 CHECK(extension);
1082 extensions::PermissionsUpdater perms_updater(profile());
[email protected]009633c2013-03-07 22:08:281083 perms_updater.GrantActivePermissions(extension);
[email protected]be083862012-09-01 03:53:451084}
1085
[email protected]fe2dd7742011-04-19 22:52:491086// static
1087void ExtensionService::RecordPermissionMessagesHistogram(
[email protected]13c68b62013-05-17 11:29:051088 const Extension* extension, const char* histogram) {
[email protected]de415552013-01-23 04:12:171089 // Since this is called from multiple sources, and since the histogram macros
1090 // use statics, we need to manually lookup the histogram ourselves.
1091 base::HistogramBase* counter = base::LinearHistogram::FactoryGet(
[email protected]fe2dd7742011-04-19 22:52:491092 histogram,
1093 1,
[email protected]c2e66e12012-06-27 06:27:061094 PermissionMessage::kEnumBoundary,
1095 PermissionMessage::kEnumBoundary + 1,
[email protected]de415552013-01-23 04:12:171096 base::HistogramBase::kUmaTargetedHistogramFlag);
[email protected]fe2dd7742011-04-19 22:52:491097
[email protected]13c68b62013-05-17 11:29:051098 PermissionMessages permissions =
1099 extensions::PermissionsData::GetPermissionMessages(extension);
[email protected]fe2dd7742011-04-19 22:52:491100 if (permissions.empty()) {
[email protected]c2e66e12012-06-27 06:27:061101 counter->Add(PermissionMessage::kNone);
[email protected]fe2dd7742011-04-19 22:52:491102 } else {
[email protected]c2e66e12012-06-27 06:27:061103 for (PermissionMessages::iterator it = permissions.begin();
[email protected]0d3e4a22011-06-23 19:02:521104 it != permissions.end(); ++it)
1105 counter->Add(it->id());
[email protected]fe2dd7742011-04-19 22:52:491106 }
1107}
1108
[email protected]eaa7dd182010-12-14 11:09:001109void ExtensionService::NotifyExtensionLoaded(const Extension* extension) {
[email protected]57a777f72010-03-31 01:09:421110 // The ChromeURLRequestContexts need to be first to know that the extension
[email protected]62d30f42009-10-01 22:36:061111 // was loaded, otherwise a race can arise where a renderer that is created
1112 // for the extension may try to load an extension URL with an extension id
[email protected]57a777f72010-03-31 01:09:421113 // that the request context doesn't yet know about. The profile is responsible
1114 // for ensuring its URLRequestContexts appropriately discover the loaded
1115 // extension.
[email protected]31d8f5f22012-04-02 15:22:081116 system_->RegisterExtensionWithRequestContexts(extension);
[email protected]62d30f42009-10-01 22:36:061117
[email protected]d5949312012-12-03 22:13:301118 // Tell renderers about the new extension, unless it's a theme (renderers
1119 // don't need to know about themes).
[email protected]a58f599c2012-12-01 03:08:191120 if (!extension->is_theme()) {
[email protected]19647262011-12-16 09:57:491121 for (content::RenderProcessHost::iterator i(
1122 content::RenderProcessHost::AllHostsIterator());
1123 !i.IsAtEnd(); i.Advance()) {
1124 content::RenderProcessHost* host = i.GetCurrentValue();
1125 Profile* host_profile =
1126 Profile::FromBrowserContext(host->GetBrowserContext());
1127 if (host_profile->GetOriginalProfile() ==
1128 profile_->GetOriginalProfile()) {
1129 std::vector<ExtensionMsg_Loaded_Params> loaded_extensions(
1130 1, ExtensionMsg_Loaded_Params(extension));
1131 host->Send(
1132 new ExtensionMsg_Loaded(loaded_extensions));
1133 }
[email protected]c8d407e2011-04-28 21:27:171134 }
[email protected]77a6970c2011-04-23 16:58:561135 }
1136
[email protected]3442a662012-01-12 08:06:171137 // Tell subsystems that use the EXTENSION_LOADED notification about the new
1138 // extension.
1139 //
1140 // NOTE: It is important that this happen after notifying the renderers about
1141 // the new extensions so that if we navigate to an extension URL in
1142 // NOTIFICATION_EXTENSION_LOADED, the renderer is guaranteed to know about it.
1143 content::NotificationService::current()->Notify(
1144 chrome::NOTIFICATION_EXTENSION_LOADED,
1145 content::Source<Profile>(profile_),
1146 content::Details<const Extension>(extension));
1147
[email protected]c8d407e2011-04-28 21:27:171148 // Tell a random-ass collection of other subsystems about the new extension.
1149 // TODO(aa): What should we do with all this goop? Can it move into the
1150 // relevant objects via EXTENSION_LOADED?
1151
1152 profile_->GetExtensionSpecialStoragePolicy()->
1153 GrantRightsForExtension(extension);
1154
1155 UpdateActiveExtensionsInCrashReporter();
1156
[email protected]c8d407e2011-04-28 21:27:171157 // If the extension has permission to load chrome://favicon/ resources we need
1158 // to make sure that the FaviconSource is registered with the
1159 // ChromeURLDataManager.
[email protected]13c68b62013-05-17 11:29:051160 if (extensions::PermissionsData::HasHostPermission(
1161 extension, GURL(chrome::kChromeUIFaviconURL))) {
[email protected]c8d407e2011-04-28 21:27:171162 FaviconSource* favicon_source = new FaviconSource(profile_,
1163 FaviconSource::FAVICON);
[email protected]24ea7a12013-01-27 23:54:531164 content::URLDataSource::Add(profile_, favicon_source);
[email protected]c8d407e2011-04-28 21:27:171165 }
[email protected]b07e606e2012-09-15 20:16:151166
1167#if !defined(OS_ANDROID)
1168 // Same for chrome://theme/ resources.
[email protected]13c68b62013-05-17 11:29:051169 if (extensions::PermissionsData::HasHostPermission(
1170 extension, GURL(chrome::kChromeUIThemeURL))) {
[email protected]b07e606e2012-09-15 20:16:151171 ThemeSource* theme_source = new ThemeSource(profile_);
[email protected]24ea7a12013-01-27 23:54:531172 content::URLDataSource::Add(profile_, theme_source);
[email protected]b07e606e2012-09-15 20:16:151173 }
1174#endif
1175
[email protected]5eddc3e2011-10-26 04:33:311176 // Same for chrome://thumb/ resources.
[email protected]13c68b62013-05-17 11:29:051177 if (extensions::PermissionsData::HasHostPermission(
1178 extension, GURL(chrome::kChromeUIThumbnailURL))) {
[email protected]420e6d92013-09-17 01:48:511179 ThumbnailSource* thumbnail_source = new ThumbnailSource(profile_, false);
[email protected]24ea7a12013-01-27 23:54:531180 content::URLDataSource::Add(profile_, thumbnail_source);
[email protected]5eddc3e2011-10-26 04:33:311181 }
[email protected]62d30f42009-10-01 22:36:061182}
1183
[email protected]a9f39a312010-12-23 22:14:271184void ExtensionService::NotifyExtensionUnloaded(
[email protected]814a7bf0f2011-08-13 05:30:591185 const Extension* extension,
1186 extension_misc::UnloadedExtensionReason reason) {
[email protected]a9f39a312010-12-23 22:14:271187 UnloadedExtensionInfo details(extension, reason);
[email protected]ad50def52011-10-19 23:17:071188 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271189 chrome::NOTIFICATION_EXTENSION_UNLOADED,
[email protected]6c2381d2011-10-19 02:52:531190 content::Source<Profile>(profile_),
1191 content::Details<UnloadedExtensionInfo>(&details));
[email protected]62d30f42009-10-01 22:36:061192
[email protected]f3b1a082011-11-18 00:34:301193 for (content::RenderProcessHost::iterator i(
1194 content::RenderProcessHost::AllHostsIterator());
[email protected]77a6970c2011-04-23 16:58:561195 !i.IsAtEnd(); i.Advance()) {
[email protected]f3b1a082011-11-18 00:34:301196 content::RenderProcessHost* host = i.GetCurrentValue();
[email protected]9b62ecf2011-07-27 20:23:081197 Profile* host_profile =
[email protected]f3b1a082011-11-18 00:34:301198 Profile::FromBrowserContext(host->GetBrowserContext());
[email protected]9b62ecf2011-07-27 20:23:081199 if (host_profile->GetOriginalProfile() == profile_->GetOriginalProfile())
[email protected]c8d407e2011-04-28 21:27:171200 host->Send(new ExtensionMsg_Unloaded(extension->id()));
[email protected]77a6970c2011-04-23 16:58:561201 }
1202
[email protected]31d8f5f22012-04-02 15:22:081203 system_->UnregisterExtensionWithRequestContexts(extension->id(), reason);
[email protected]c8d407e2011-04-28 21:27:171204 profile_->GetExtensionSpecialStoragePolicy()->
1205 RevokeRightsForExtension(extension);
1206
[email protected]b777b332011-04-16 04:01:081207#if defined(OS_CHROMEOS)
[email protected]ac66e452013-01-11 09:21:231208 // Revoke external file access for the extension from its file system context.
1209 // It is safe to access the extension's storage partition at this point. The
1210 // storage partition may get destroyed only after the extension gets unloaded.
1211 GURL site = extensions::ExtensionSystem::Get(profile_)->extension_service()->
1212 GetSiteForExtensionId(extension->id());
[email protected]10eb28162012-09-18 03:04:091213 fileapi::FileSystemContext* filesystem_context =
[email protected]ac66e452013-01-11 09:21:231214 BrowserContext::GetStoragePartitionForSite(profile_, site)->
[email protected]10eb28162012-09-18 03:04:091215 GetFileSystemContext();
[email protected]f19bbf62013-07-09 01:22:321216 if (filesystem_context && filesystem_context->external_backend()) {
1217 filesystem_context->external_backend()->
[email protected]c8d407e2011-04-28 21:27:171218 RevokeAccessForExtension(extension->id());
[email protected]62d30f42009-10-01 22:36:061219 }
[email protected]c8d407e2011-04-28 21:27:171220#endif
1221
1222 UpdateActiveExtensionsInCrashReporter();
[email protected]62d30f42009-10-01 22:36:061223}
1224
[email protected]0a071a32011-02-08 00:18:241225Profile* ExtensionService::profile() {
1226 return profile_;
1227}
1228
[email protected]45759612012-07-10 17:21:231229extensions::ExtensionPrefs* ExtensionService::extension_prefs() {
[email protected]ddb1e5a2010-12-13 20:10:451230 return extension_prefs_;
1231}
1232
[email protected]a7ff4b72013-10-17 20:56:021233const extensions::ExtensionPrefs* ExtensionService::extension_prefs() const {
1234 return extension_prefs_;
1235}
1236
[email protected]0d9a2202011-11-09 13:48:411237extensions::SettingsFrontend* ExtensionService::settings_frontend() {
[email protected]cccdf0aa2011-11-11 03:43:381238 return settings_frontend_.get();
[email protected]b7f853e282011-08-10 09:24:201239}
1240
[email protected]e2d720aa2012-05-17 00:11:351241extensions::ContentSettingsStore* ExtensionService::GetContentSettingsStore() {
[email protected]b790b072011-05-20 09:46:441242 return extension_prefs()->content_settings_store();
1243}
1244
[email protected]25ae0152011-11-18 14:40:021245bool ExtensionService::is_ready() {
[email protected]4a10006a2013-05-17 23:18:351246 return ready_->is_signaled();
[email protected]25ae0152011-11-18 14:40:021247}
1248
[email protected]7f8f24f2012-11-15 19:40:141249base::SequencedTaskRunner* ExtensionService::GetFileTaskRunner() {
[email protected]dc24976f2013-06-02 21:15:091250 if (file_task_runner_.get())
1251 return file_task_runner_.get();
[email protected]7f8f24f2012-11-15 19:40:141252
1253 // We should be able to interrupt any part of extension install process during
1254 // shutdown. SKIP_ON_SHUTDOWN ensures that not started extension install tasks
1255 // will be ignored/deleted while we will block on started tasks.
1256 std::string token("ext_install-");
1257 token.append(profile_->GetPath().AsUTF8Unsafe());
1258 file_task_runner_ = BrowserThread::GetBlockingPool()->
1259 GetSequencedTaskRunnerWithShutdownBehavior(
1260 BrowserThread::GetBlockingPool()->GetNamedSequenceToken(token),
1261 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN);
[email protected]dc24976f2013-06-02 21:15:091262 return file_task_runner_.get();
[email protected]7f8f24f2012-11-15 19:40:141263}
1264
[email protected]42a08162012-03-16 18:09:111265extensions::ExtensionUpdater* ExtensionService::updater() {
[email protected]2859946f2011-04-04 18:18:061266 return updater_.get();
1267}
1268
[email protected]4ee07c62012-08-21 12:40:421269void ExtensionService::CheckManagementPolicy() {
[email protected]aa96d3a2010-08-21 08:45:251270 std::vector<std::string> to_be_removed;
[email protected]695b5712012-12-06 23:55:281271
[email protected]aa96d3a2010-08-21 08:45:251272 // Loop through extensions list, unload installed extensions.
[email protected]84df8332011-12-06 18:22:461273 for (ExtensionSet::const_iterator iter = extensions_.begin();
[email protected]aa96d3a2010-08-21 08:45:251274 iter != extensions_.end(); ++iter) {
[email protected]cadac622013-06-11 16:46:361275 const Extension* extension = (iter->get());
[email protected]4ee07c62012-08-21 12:40:421276 if (!system_->management_policy()->UserMayLoad(extension, NULL))
[email protected]aa96d3a2010-08-21 08:45:251277 to_be_removed.push_back(extension->id());
1278 }
1279
1280 // UnloadExtension will change the extensions_ list. So, we should
1281 // call it outside the iterator loop.
[email protected]31bb5ee62012-09-12 22:58:401282 for (size_t i = 0; i < to_be_removed.size(); ++i)
[email protected]814a7bf0f2011-08-13 05:30:591283 UnloadExtension(to_be_removed[i], extension_misc::UNLOAD_REASON_DISABLE);
[email protected]aa96d3a2010-08-21 08:45:251284}
1285
[email protected]31206602011-04-13 23:07:321286void ExtensionService::CheckForUpdatesSoon() {
[email protected]c3cfb012011-04-06 22:07:351287 if (updater()) {
[email protected]94fde232012-04-27 10:22:301288 if (AreAllExternalProvidersReady()) {
1289 updater()->CheckSoon();
1290 } else {
1291 // Sync can start updating before all the external providers are ready
1292 // during startup. Start the update as soon as those providers are ready,
1293 // but not before.
1294 update_once_all_providers_are_ready_ = true;
1295 }
[email protected]c3cfb012011-04-06 22:07:351296 } else {
[email protected]31206602011-04-13 23:07:321297 LOG(WARNING) << "CheckForUpdatesSoon() called with auto-update turned off";
[email protected]c3cfb012011-04-06 22:07:351298 }
1299}
1300
[email protected]3f98fd92012-11-17 15:54:291301syncer::SyncMergeResult ExtensionService::MergeDataAndStartSyncing(
[email protected]a4a147652012-07-03 23:41:321302 syncer::ModelType type,
[email protected]65f173552012-06-28 22:43:581303 const syncer::SyncDataList& initial_sync_data,
1304 scoped_ptr<syncer::SyncChangeProcessor> sync_processor,
1305 scoped_ptr<syncer::SyncErrorFactory> sync_error_factory) {
[email protected]5db9ada2012-04-11 13:48:201306 CHECK(sync_processor.get());
[email protected]5d36e052012-04-20 20:12:281307 CHECK(sync_error_factory.get());
[email protected]3bdba0d2011-08-23 07:17:301308
1309 switch (type) {
[email protected]a4a147652012-07-03 23:41:321310 case syncer::EXTENSIONS:
[email protected]5db9ada2012-04-11 13:48:201311 extension_sync_bundle_.SetupSync(sync_processor.release(),
[email protected]5d36e052012-04-20 20:12:281312 sync_error_factory.release(),
[email protected]5db9ada2012-04-11 13:48:201313 initial_sync_data);
[email protected]50736a12013-09-26 08:58:341314 pending_extension_enables_.OnSyncStarted(this);
[email protected]3bdba0d2011-08-23 07:17:301315 break;
1316
[email protected]a4a147652012-07-03 23:41:321317 case syncer::APPS:
[email protected]5d36e052012-04-20 20:12:281318 app_sync_bundle_.SetupSync(sync_processor.release(),
1319 sync_error_factory.release(),
1320 initial_sync_data);
[email protected]50736a12013-09-26 08:58:341321 pending_app_enables_.OnSyncStarted(this);
[email protected]3bdba0d2011-08-23 07:17:301322 break;
1323
1324 default:
1325 LOG(FATAL) << "Got " << type << " ModelType";
1326 }
[email protected]3bdba0d2011-08-23 07:17:301327
[email protected]b1417ab2011-12-15 17:09:111328 // Process local extensions.
1329 // TODO(yoz): Determine whether pending extensions should be considered too.
1330 // See crbug.com/104399.
[email protected]65f173552012-06-28 22:43:581331 syncer::SyncDataList sync_data_list = GetAllSyncData(type);
1332 syncer::SyncChangeList sync_change_list;
1333 for (syncer::SyncDataList::const_iterator i = sync_data_list.begin();
[email protected]3bdba0d2011-08-23 07:17:301334 i != sync_data_list.end();
1335 ++i) {
[email protected]5db9ada2012-04-11 13:48:201336 switch (type) {
[email protected]a4a147652012-07-03 23:41:321337 case syncer::EXTENSIONS:
[email protected]5db9ada2012-04-11 13:48:201338 sync_change_list.push_back(
1339 extension_sync_bundle_.CreateSyncChange(*i));
1340 break;
[email protected]a4a147652012-07-03 23:41:321341 case syncer::APPS:
[email protected]5db9ada2012-04-11 13:48:201342 sync_change_list.push_back(app_sync_bundle_.CreateSyncChange(*i));
1343 break;
1344 default:
1345 LOG(FATAL) << "Got " << type << " ModelType";
[email protected]31bb5ee62012-09-12 22:58:401346 }
[email protected]3bdba0d2011-08-23 07:17:301347 }
[email protected]3bdba0d2011-08-23 07:17:301348
[email protected]5db9ada2012-04-11 13:48:201349
[email protected]a4a147652012-07-03 23:41:321350 if (type == syncer::EXTENSIONS) {
[email protected]5db9ada2012-04-11 13:48:201351 extension_sync_bundle_.ProcessSyncChangeList(sync_change_list);
[email protected]a4a147652012-07-03 23:41:321352 } else if (type == syncer::APPS) {
[email protected]5db9ada2012-04-11 13:48:201353 app_sync_bundle_.ProcessSyncChangeList(sync_change_list);
1354 }
[email protected]0ffd9e52012-01-26 21:44:341355
[email protected]3f98fd92012-11-17 15:54:291356 return syncer::SyncMergeResult(type);
[email protected]3bdba0d2011-08-23 07:17:301357}
1358
[email protected]a4a147652012-07-03 23:41:321359void ExtensionService::StopSyncing(syncer::ModelType type) {
1360 if (type == syncer::APPS) {
[email protected]5db9ada2012-04-11 13:48:201361 app_sync_bundle_.Reset();
[email protected]a4a147652012-07-03 23:41:321362 } else if (type == syncer::EXTENSIONS) {
[email protected]5db9ada2012-04-11 13:48:201363 extension_sync_bundle_.Reset();
1364 }
[email protected]3bdba0d2011-08-23 07:17:301365}
1366
[email protected]65f173552012-06-28 22:43:581367syncer::SyncDataList ExtensionService::GetAllSyncData(
[email protected]a4a147652012-07-03 23:41:321368 syncer::ModelType type) const {
[email protected]31bb5ee62012-09-12 22:58:401369 if (type == syncer::EXTENSIONS)
[email protected]5db9ada2012-04-11 13:48:201370 return extension_sync_bundle_.GetAllSyncData();
[email protected]31bb5ee62012-09-12 22:58:401371 if (type == syncer::APPS)
[email protected]5db9ada2012-04-11 13:48:201372 return app_sync_bundle_.GetAllSyncData();
[email protected]5db9ada2012-04-11 13:48:201373
1374 // We should only get sync data for extensions and apps.
1375 NOTREACHED();
1376
[email protected]65f173552012-06-28 22:43:581377 return syncer::SyncDataList();
[email protected]3bdba0d2011-08-23 07:17:301378}
1379
[email protected]65f173552012-06-28 22:43:581380syncer::SyncError ExtensionService::ProcessSyncChanges(
[email protected]3bdba0d2011-08-23 07:17:301381 const tracked_objects::Location& from_here,
[email protected]65f173552012-06-28 22:43:581382 const syncer::SyncChangeList& change_list) {
1383 for (syncer::SyncChangeList::const_iterator i = change_list.begin();
[email protected]3bdba0d2011-08-23 07:17:301384 i != change_list.end();
1385 ++i) {
[email protected]a4a147652012-07-03 23:41:321386 syncer::ModelType type = i->sync_data().GetDataType();
1387 if (type == syncer::EXTENSIONS) {
[email protected]5db9ada2012-04-11 13:48:201388 extension_sync_bundle_.ProcessSyncChange(
1389 extensions::ExtensionSyncData(*i));
[email protected]a4a147652012-07-03 23:41:321390 } else if (type == syncer::APPS) {
[email protected]5db9ada2012-04-11 13:48:201391 app_sync_bundle_.ProcessSyncChange(extensions::AppSyncData(*i));
1392 }
[email protected]3bdba0d2011-08-23 07:17:301393 }
1394
[email protected]0ffd9e52012-01-26 21:44:341395 extension_prefs()->extension_sorting()->FixNTPOrdinalCollisions();
1396
[email protected]65f173552012-06-28 22:43:581397 return syncer::SyncError();
[email protected]b05fb9ff2011-04-23 00:07:561398}
1399
[email protected]5db9ada2012-04-11 13:48:201400extensions::ExtensionSyncData ExtensionService::GetExtensionSyncData(
1401 const Extension& extension) const {
[email protected]a7ff4b72013-10-17 20:56:021402 return extensions::ExtensionSyncData(
1403 extension,
1404 IsExtensionEnabled(extension.id()),
1405 extension_util::IsIncognitoEnabled(extension.id(), this));
[email protected]b05fb9ff2011-04-23 00:07:561406}
1407
[email protected]5db9ada2012-04-11 13:48:201408extensions::AppSyncData ExtensionService::GetAppSyncData(
1409 const Extension& extension) const {
1410 return extensions::AppSyncData(
1411 extension,
1412 IsExtensionEnabled(extension.id()),
[email protected]a7ff4b72013-10-17 20:56:021413 extension_util::IsIncognitoEnabled(extension.id(), this),
[email protected]5db9ada2012-04-11 13:48:201414 extension_prefs_->extension_sorting()->GetAppLaunchOrdinal(
1415 extension.id()),
1416 extension_prefs_->extension_sorting()->GetPageOrdinal(extension.id()));
1417}
[email protected]3bdba0d2011-08-23 07:17:301418
[email protected]5db9ada2012-04-11 13:48:201419std::vector<extensions::ExtensionSyncData>
1420 ExtensionService::GetExtensionSyncDataList() const {
1421 std::vector<extensions::ExtensionSyncData> extension_sync_list;
1422 extension_sync_bundle_.GetExtensionSyncDataListHelper(extensions_,
1423 &extension_sync_list);
1424 extension_sync_bundle_.GetExtensionSyncDataListHelper(disabled_extensions_,
1425 &extension_sync_list);
1426 extension_sync_bundle_.GetExtensionSyncDataListHelper(terminated_extensions_,
1427 &extension_sync_list);
1428
1429 std::vector<extensions::ExtensionSyncData> pending_extensions =
1430 extension_sync_bundle_.GetPendingData();
1431 extension_sync_list.insert(extension_sync_list.begin(),
1432 pending_extensions.begin(),
1433 pending_extensions.end());
[email protected]3bdba0d2011-08-23 07:17:301434
1435 return extension_sync_list;
[email protected]b05fb9ff2011-04-23 00:07:561436}
1437
[email protected]5db9ada2012-04-11 13:48:201438std::vector<extensions::AppSyncData> ExtensionService::GetAppSyncDataList()
1439 const {
1440 std::vector<extensions::AppSyncData> app_sync_list;
1441 app_sync_bundle_.GetAppSyncDataListHelper(extensions_, &app_sync_list);
1442 app_sync_bundle_.GetAppSyncDataListHelper(disabled_extensions_,
1443 &app_sync_list);
1444 app_sync_bundle_.GetAppSyncDataListHelper(terminated_extensions_,
1445 &app_sync_list);
1446
1447 std::vector<extensions::AppSyncData> pending_apps =
1448 app_sync_bundle_.GetPendingData();
1449 app_sync_list.insert(app_sync_list.begin(),
1450 pending_apps.begin(),
1451 pending_apps.end());
1452
1453 return app_sync_list;
1454}
1455
1456bool ExtensionService::ProcessExtensionSyncData(
1457 const extensions::ExtensionSyncData& extension_sync_data) {
1458 if (!ProcessExtensionSyncDataHelper(extension_sync_data,
[email protected]a4a147652012-07-03 23:41:321459 syncer::EXTENSIONS)) {
[email protected]5db9ada2012-04-11 13:48:201460 extension_sync_bundle_.AddPendingExtension(extension_sync_data.id(),
1461 extension_sync_data);
1462 CheckForUpdatesSoon();
1463 return false;
1464 }
1465
1466 return true;
1467}
1468
1469bool ExtensionService::ProcessAppSyncData(
1470 const extensions::AppSyncData& app_sync_data) {
1471 const std::string& id = app_sync_data.id();
[email protected]5db9ada2012-04-11 13:48:201472
1473 if (app_sync_data.app_launch_ordinal().IsValid() &&
1474 app_sync_data.page_ordinal().IsValid()) {
1475 extension_prefs_->extension_sorting()->SetAppLaunchOrdinal(
1476 id,
1477 app_sync_data.app_launch_ordinal());
1478 extension_prefs_->extension_sorting()->SetPageOrdinal(
1479 id,
1480 app_sync_data.page_ordinal());
1481 }
1482
[email protected]5db9ada2012-04-11 13:48:201483 if (!ProcessExtensionSyncDataHelper(app_sync_data.extension_sync_data(),
[email protected]a4a147652012-07-03 23:41:321484 syncer::APPS)) {
[email protected]5db9ada2012-04-11 13:48:201485 app_sync_bundle_.AddPendingApp(id, app_sync_data);
1486 CheckForUpdatesSoon();
1487 return false;
1488 }
1489
1490 return true;
1491}
1492
1493bool ExtensionService::IsCorrectSyncType(const Extension& extension,
[email protected]a4a147652012-07-03 23:41:321494 syncer::ModelType type) const {
1495 if (type == syncer::EXTENSIONS &&
[email protected]8f3bcbd2013-06-05 08:42:401496 extensions::sync_helper::IsSyncableExtension(&extension)) {
[email protected]5db9ada2012-04-11 13:48:201497 return true;
[email protected]31bb5ee62012-09-12 22:58:401498 }
[email protected]5db9ada2012-04-11 13:48:201499
[email protected]a4a147652012-07-03 23:41:321500 if (type == syncer::APPS &&
[email protected]8f3bcbd2013-06-05 08:42:401501 extensions::sync_helper::IsSyncableApp(&extension)) {
[email protected]5db9ada2012-04-11 13:48:201502 return true;
[email protected]31bb5ee62012-09-12 22:58:401503 }
[email protected]5db9ada2012-04-11 13:48:201504
1505 return false;
1506}
1507
[email protected]50736a12013-09-26 08:58:341508bool ExtensionService::IsPendingEnable(const std::string& extension_id) const {
1509 return pending_app_enables_.Contains(extension_id) ||
1510 pending_extension_enables_.Contains(extension_id);
1511}
1512
[email protected]5db9ada2012-04-11 13:48:201513bool ExtensionService::ProcessExtensionSyncDataHelper(
1514 const extensions::ExtensionSyncData& extension_sync_data,
[email protected]a4a147652012-07-03 23:41:321515 syncer::ModelType type) {
[email protected]3bdba0d2011-08-23 07:17:301516 const std::string& id = extension_sync_data.id();
[email protected]96e989b2011-08-30 19:35:061517 const Extension* extension = GetInstalledExtension(id);
1518
1519 // TODO(bolms): we should really handle this better. The particularly bad
1520 // case is where an app becomes an extension or vice versa, and we end up with
1521 // a zombie extension that won't go away.
[email protected]5db9ada2012-04-11 13:48:201522 if (extension && !IsCorrectSyncType(*extension, type))
1523 return true;
[email protected]90310d92011-04-17 07:35:041524
1525 // Handle uninstalls first.
[email protected]3bdba0d2011-08-23 07:17:301526 if (extension_sync_data.uninstalled()) {
[email protected]90310d92011-04-17 07:35:041527 if (!UninstallExtensionHelper(this, id)) {
1528 LOG(WARNING) << "Could not uninstall extension " << id
1529 << " for sync";
1530 }
[email protected]5db9ada2012-04-11 13:48:201531 return true;
[email protected]90310d92011-04-17 07:35:041532 }
1533
[email protected]caf2d442012-05-04 10:00:501534 // Extension from sync was uninstalled by the user as external extensions.
1535 // Honor user choice and skip installation/enabling.
1536 if (IsExternalExtensionUninstalled(id)) {
1537 LOG(WARNING) << "Extension with id " << id
1538 << " from sync was uninstalled as external extension";
1539 return true;
1540 }
1541
[email protected]06f92562011-04-29 19:27:311542 // Set user settings.
[email protected]7e9e2422012-12-13 19:54:191543 // If the extension has been disabled from sync, it may not have
1544 // been installed yet, so we don't know if the disable reason was a
[email protected]b914e2952013-04-26 07:10:031545 // permissions increase. That will be updated once CheckPermissionsIncrease
[email protected]7e9e2422012-12-13 19:54:191546 // is called for it.
[email protected]31bb5ee62012-09-12 22:58:401547 if (extension_sync_data.enabled())
[email protected]06f92562011-04-29 19:27:311548 EnableExtension(id);
[email protected]50736a12013-09-26 08:58:341549 else if (!IsPendingEnable(id))
[email protected]7e9e2422012-12-13 19:54:191550 DisableExtension(id, Extension::DISABLE_UNKNOWN_FROM_SYNC);
[email protected]81b14cc2011-04-29 00:39:371551
[email protected]406b5a92011-11-08 11:58:261552 // We need to cache some version information here because setting the
1553 // incognito flag invalidates the |extension| pointer (it reloads the
1554 // extension).
[email protected]9060d8b02012-01-13 02:14:301555 bool extension_installed = (extension != NULL);
[email protected]406b5a92011-11-08 11:58:261556 int result = extension ?
1557 extension->version()->CompareTo(extension_sync_data.version()) : 0;
[email protected]a7ff4b72013-10-17 20:56:021558 extension_util::SetIsIncognitoEnabled(
1559 id, this, extension_sync_data.incognito_enabled());
[email protected]406b5a92011-11-08 11:58:261560 extension = NULL; // No longer safe to use.
1561
1562 if (extension_installed) {
[email protected]06f92562011-04-29 19:27:311563 // If the extension is already installed, check if it's outdated.
[email protected]90310d92011-04-17 07:35:041564 if (result < 0) {
1565 // Extension is outdated.
[email protected]5db9ada2012-04-11 13:48:201566 return false;
[email protected]b020dc12011-12-06 04:35:421567 }
[email protected]06f92562011-04-29 19:27:311568 } else {
[email protected]06f92562011-04-29 19:27:311569 // TODO(akalin): Replace silent update with a list of enabled
1570 // permissions.
[email protected]6cc7dbae2011-04-29 21:18:331571 const bool kInstallSilently = true;
[email protected]5db9ada2012-04-11 13:48:201572
[email protected]a4a147652012-07-03 23:41:321573 CHECK(type == syncer::EXTENSIONS || type == syncer::APPS);
[email protected]8f3bcbd2013-06-05 08:42:401574 extensions::PendingExtensionInfo::ShouldAllowInstallPredicate filter =
1575 (type == syncer::APPS) ? extensions::sync_helper::IsSyncableApp :
1576 extensions::sync_helper::IsSyncableExtension;
[email protected]5db9ada2012-04-11 13:48:201577
[email protected]06f92562011-04-29 19:27:311578 if (!pending_extension_manager()->AddFromSync(
1579 id,
[email protected]3bdba0d2011-08-23 07:17:301580 extension_sync_data.update_url(),
[email protected]5db9ada2012-04-11 13:48:201581 filter,
[email protected]6cc7dbae2011-04-29 21:18:331582 kInstallSilently)) {
[email protected]06f92562011-04-29 19:27:311583 LOG(WARNING) << "Could not add pending extension for " << id;
[email protected]3bdba0d2011-08-23 07:17:301584 // This means that the extension is already pending installation, with a
1585 // non-INTERNAL location. Add to pending_sync_data, even though it will
1586 // never be removed (we'll never install a syncable version of the
1587 // extension), so that GetAllSyncData() continues to send it.
[email protected]06f92562011-04-29 19:27:311588 }
[email protected]3bdba0d2011-08-23 07:17:301589 // Track pending extensions so that we can return them in GetAllSyncData().
[email protected]5db9ada2012-04-11 13:48:201590 return false;
[email protected]90310d92011-04-17 07:35:041591 }
[email protected]5db9ada2012-04-11 13:48:201592
1593 return true;
[email protected]90310d92011-04-17 07:35:041594}
1595
[email protected]168389f2011-12-20 17:12:481596void ExtensionService::OnExtensionMoved(
1597 const std::string& moved_extension_id,
1598 const std::string& predecessor_extension_id,
1599 const std::string& successor_extension_id) {
[email protected]3569b502012-01-12 20:08:231600 extension_prefs_->extension_sorting()->OnExtensionMoved(
1601 moved_extension_id,
1602 predecessor_extension_id,
1603 successor_extension_id);
[email protected]168389f2011-12-20 17:12:481604
1605 const Extension* extension = GetInstalledExtension(moved_extension_id);
1606 if (extension)
1607 SyncExtensionChangeIfNeeded(*extension);
1608}
1609
[email protected]8e4560b62011-01-14 10:09:141610// Some extensions will autoupdate themselves externally from Chrome. These
1611// are typically part of some larger client application package. To support
1612// these, the extension will register its location in the the preferences file
1613// (and also, on Windows, in the registry) and this code will periodically
1614// check that location for a .crx file, which it will then install locally if
1615// a new version is available.
1616// Errors are reported through ExtensionErrorReporter. Succcess is not
1617// reported.
[email protected]eaa7dd182010-12-14 11:09:001618void ExtensionService::CheckForExternalUpdates() {
[email protected]a29a517a2011-01-21 21:11:121619 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]8e4560b62011-01-14 10:09:141620
1621 // Note that this installation is intentionally silent (since it didn't
1622 // go through the front-end). Extensions that are registered in this
1623 // way are effectively considered 'pre-bundled', and so implicitly
1624 // trusted. In general, if something has HKLM or filesystem access,
1625 // they could install an extension manually themselves anyway.
[email protected]a29a517a2011-01-21 21:11:121626
[email protected]8e4560b62011-01-14 10:09:141627 // Ask each external extension provider to give us a call back for each
1628 // extension they know about. See OnExternalExtension(File|UpdateUrl)Found.
[email protected]5df038b2012-07-16 19:03:271629 extensions::ProviderCollection::const_iterator i;
[email protected]8e4560b62011-01-14 10:09:141630 for (i = external_extension_providers_.begin();
1631 i != external_extension_providers_.end(); ++i) {
[email protected]5df038b2012-07-16 19:03:271632 extensions::ExternalProviderInterface* provider = i->get();
[email protected]8e4560b62011-01-14 10:09:141633 provider->VisitRegisteredExtension();
1634 }
1635
[email protected]50067e52011-10-20 23:17:071636 // Do any required work that we would have done after completion of all
1637 // providers.
1638 if (external_extension_providers_.empty()) {
1639 OnAllExternalProvidersReady();
1640 }
[email protected]9f1087e2009-06-15 17:29:321641}
1642
[email protected]50067e52011-10-20 23:17:071643void ExtensionService::OnExternalProviderReady(
[email protected]5df038b2012-07-16 19:03:271644 const extensions::ExternalProviderInterface* provider) {
[email protected]a29a517a2011-01-21 21:11:121645 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]50067e52011-10-20 23:17:071646 CHECK(provider->IsReady());
[email protected]a29a517a2011-01-21 21:11:121647
1648 // An external provider has finished loading. We only take action
[email protected]8e4560b62011-01-14 10:09:141649 // if all of them are finished. So we check them first.
[email protected]94fde232012-04-27 10:22:301650 if (AreAllExternalProvidersReady())
1651 OnAllExternalProvidersReady();
1652}
1653
1654bool ExtensionService::AreAllExternalProvidersReady() const {
[email protected]5df038b2012-07-16 19:03:271655 extensions::ProviderCollection::const_iterator i;
[email protected]8e4560b62011-01-14 10:09:141656 for (i = external_extension_providers_.begin();
1657 i != external_extension_providers_.end(); ++i) {
[email protected]94fde232012-04-27 10:22:301658 if (!i->get()->IsReady())
1659 return false;
[email protected]8e4560b62011-01-14 10:09:141660 }
[email protected]94fde232012-04-27 10:22:301661 return true;
[email protected]50067e52011-10-20 23:17:071662}
1663
1664void ExtensionService::OnAllExternalProvidersReady() {
1665 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]94fde232012-04-27 10:22:301666 base::TimeDelta elapsed = base::Time::Now() - profile_->GetStartTime();
1667 UMA_HISTOGRAM_TIMES("Extension.ExternalProvidersReadyAfter", elapsed);
[email protected]50067e52011-10-20 23:17:071668
1669 // Install any pending extensions.
[email protected]94fde232012-04-27 10:22:301670 if (update_once_all_providers_are_ready_ && updater()) {
1671 update_once_all_providers_are_ready_ = false;
[email protected]42774e42012-11-14 21:01:061672 updater()->CheckNow(extensions::ExtensionUpdater::CheckParams());
[email protected]8e4560b62011-01-14 10:09:141673 }
1674
1675 // Uninstall all the unclaimed extensions.
[email protected]45759612012-07-10 17:21:231676 scoped_ptr<extensions::ExtensionPrefs::ExtensionsInfo> extensions_info(
[email protected]8e4560b62011-01-14 10:09:141677 extension_prefs_->GetInstalledExtensionsInfo());
1678 for (size_t i = 0; i < extensions_info->size(); ++i) {
1679 ExtensionInfo* info = extensions_info->at(i).get();
[email protected]1d5e58b2013-01-31 08:41:401680 if (Manifest::IsExternalLocation(info->extension_location))
[email protected]8e4560b62011-01-14 10:09:141681 CheckExternalUninstall(info->extension_id);
1682 }
[email protected]e5af875f2011-10-10 21:09:141683 IdentifyAlertableExtensions();
[email protected]e5af875f2011-10-10 21:09:141684}
1685
1686void ExtensionService::IdentifyAlertableExtensions() {
1687 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1688
[email protected]07c9f2f42012-02-29 18:45:221689 // Build up the lists of extensions that require acknowledgment. If this is
1690 // the first time, grandfather extensions that would have caused
1691 // notification.
[email protected]89226982012-07-16 20:09:181692 extension_error_ui_.reset(ExtensionErrorUI::Create(this));
[email protected]e5af875f2011-10-10 21:09:141693
[email protected]a9aa5932012-01-25 08:27:401694 bool did_show_alert = false;
[email protected]89226982012-07-16 20:09:181695 if (PopulateExtensionErrorUI(extension_error_ui_.get())) {
[email protected]460c6712013-04-24 07:20:011696 if (!is_first_run_) {
[email protected]a9aa5932012-01-25 08:27:401697 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]89226982012-07-16 20:09:181698 did_show_alert = extension_error_ui_->ShowErrorInBubbleView();
[email protected]e5af875f2011-10-10 21:09:141699 } else {
1700 // First run. Just acknowledge all the extensions, silently, by
1701 // shortcutting the display of the UI and going straight to the
1702 // callback for pressing the Accept button.
[email protected]a9aa5932012-01-25 08:27:401703 HandleExtensionAlertAccept();
[email protected]e5af875f2011-10-10 21:09:141704 }
1705 }
[email protected]a9aa5932012-01-25 08:27:401706
[email protected]612a1cb12012-10-17 13:18:031707 UpdateExternalExtensionAlert();
1708
[email protected]a9aa5932012-01-25 08:27:401709 if (!did_show_alert)
[email protected]89226982012-07-16 20:09:181710 extension_error_ui_.reset();
[email protected]e5af875f2011-10-10 21:09:141711}
1712
[email protected]89226982012-07-16 20:09:181713bool ExtensionService::PopulateExtensionErrorUI(
1714 ExtensionErrorUI* extension_error_ui) {
[email protected]07c9f2f42012-02-29 18:45:221715 bool needs_alert = false;
[email protected]695b5712012-12-06 23:55:281716
1717 // Extensions that are blacklisted.
1718 for (ExtensionSet::const_iterator it = blacklisted_extensions_.begin();
1719 it != blacklisted_extensions_.end(); ++it) {
1720 std::string id = (*it)->id();
1721 if (!extension_prefs_->IsBlacklistedExtensionAcknowledged(id)) {
1722 extension_error_ui->AddBlacklistedExtension(id);
1723 needs_alert = true;
1724 }
1725 }
1726
[email protected]07c9f2f42012-02-29 18:45:221727 for (ExtensionSet::const_iterator iter = extensions_.begin();
1728 iter != extensions_.end(); ++iter) {
[email protected]cadac622013-06-11 16:46:361729 const Extension* e = iter->get();
[email protected]695b5712012-12-06 23:55:281730
1731 // Extensions disabled by policy. Note: this no longer includes blacklisted
1732 // extensions, though we still show the same UI.
[email protected]fdd679b2012-11-15 20:49:391733 if (!system_->management_policy()->UserMayLoad(e, NULL)) {
[email protected]07c9f2f42012-02-29 18:45:221734 if (!extension_prefs_->IsBlacklistedExtensionAcknowledged(e->id())) {
[email protected]89226982012-07-16 20:09:181735 extension_error_ui->AddBlacklistedExtension(e->id());
[email protected]07c9f2f42012-02-29 18:45:221736 needs_alert = true;
1737 }
1738 }
[email protected]07c9f2f42012-02-29 18:45:221739 }
[email protected]695b5712012-12-06 23:55:281740
[email protected]07c9f2f42012-02-29 18:45:221741 return needs_alert;
1742}
1743
[email protected]a9aa5932012-01-25 08:27:401744void ExtensionService::HandleExtensionAlertClosed() {
[email protected]612a1cb12012-10-17 13:18:031745 const ExtensionIdSet* extension_ids =
1746 extension_error_ui_->get_blacklisted_extension_ids();
[email protected]e5af875f2011-10-10 21:09:141747 for (ExtensionIdSet::const_iterator iter = extension_ids->begin();
1748 iter != extension_ids->end(); ++iter) {
1749 extension_prefs_->AcknowledgeBlacklistedExtension(*iter);
1750 }
[email protected]879a6092013-03-06 04:12:501751 extension_error_ui_.reset();
1752}
1753
1754void ExtensionService::HandleExtensionAlertAccept() {
[email protected]73a85e012013-04-04 10:45:301755 extension_error_ui_->Close();
[email protected]e5af875f2011-10-10 21:09:141756}
1757
[email protected]47fc70c2011-12-06 07:29:511758void ExtensionService::AcknowledgeExternalExtension(const std::string& id) {
1759 extension_prefs_->AcknowledgeExternalExtension(id);
[email protected]612a1cb12012-10-17 13:18:031760 UpdateExternalExtensionAlert();
[email protected]47fc70c2011-12-06 07:29:511761}
1762
[email protected]d96eb512012-11-01 23:44:081763bool ExtensionService::IsUnacknowledgedExternalExtension(
1764 const Extension* extension) {
[email protected]b82d18da2012-11-09 00:11:321765 if (!FeatureSwitch::prompt_for_external_extensions()->IsEnabled())
1766 return false;
1767
[email protected]1d5e58b2013-01-31 08:41:401768 return (Manifest::IsExternalLocation(extension->location()) &&
[email protected]d96eb512012-11-01 23:44:081769 !extension_prefs_->IsExternalExtensionAcknowledged(extension->id()) &&
1770 !(extension_prefs_->GetDisableReasons(extension->id()) &
1771 Extension::DISABLE_SIDELOAD_WIPEOUT));
1772}
1773
[email protected]59ee99d2013-10-11 15:46:161774void ExtensionService::ReconcileKnownDisabled() {
1775 ExtensionIdSet known_disabled_ids = extension_prefs_->GetKnownDisabled();
1776 if (known_disabled_ids.empty()) {
1777 if (!disabled_extensions_.is_empty()) {
1778 extension_prefs_->SetKnownDisabled(disabled_extensions_.GetIDs());
1779 UMA_HISTOGRAM_BOOLEAN("Extensions.KnownDisabledInitialized", true);
1780 }
1781 } else {
1782 // Both |known_disabled_ids| and |extensions_| are ordered (by definition
1783 // of std::map and std::set). Iterate forward over both sets in parallel
1784 // to find matching IDs and disable the corresponding extensions.
1785 ExtensionSet::const_iterator extensions_it = extensions_.begin();
1786 ExtensionIdSet::const_iterator known_disabled_ids_it =
1787 known_disabled_ids.begin();
1788 int known_disabled_count = 0;
1789 while (extensions_it != extensions_.end() &&
1790 known_disabled_ids_it != known_disabled_ids.end()) {
1791 const std::string& extension_id = extensions_it->get()->id();
1792 const int comparison = extension_id.compare(*known_disabled_ids_it);
1793 if (comparison < 0) {
1794 ++extensions_it;
1795 } else if (comparison > 0) {
1796 ++known_disabled_ids_it;
1797 } else {
1798 ++known_disabled_count;
1799 // Advance |extensions_it| immediately as it will be invalidated upon
1800 // disabling the extension it points to.
1801 ++extensions_it;
1802 ++known_disabled_ids_it;
1803 DisableExtension(extension_id, Extension::DISABLE_KNOWN_DISABLED);
1804 }
1805 }
1806 UMA_HISTOGRAM_COUNTS_100("Extensions.KnownDisabledReDisabled",
1807 known_disabled_count);
1808 }
1809}
1810
[email protected]89226982012-07-16 20:09:181811void ExtensionService::HandleExtensionAlertDetails() {
1812 extension_error_ui_->ShowExtensions();
[email protected]73a85e012013-04-04 10:45:301813 // ShowExtensions may cause the error UI to close synchronously, e.g. if it
1814 // causes a navigation.
1815 if (extension_error_ui_)
1816 extension_error_ui_->Close();
[email protected]6c751e72010-11-23 10:11:101817}
1818
[email protected]612a1cb12012-10-17 13:18:031819void ExtensionService::UpdateExternalExtensionAlert() {
[email protected]41070e8d2012-10-24 01:34:361820 if (!FeatureSwitch::prompt_for_external_extensions()->IsEnabled())
[email protected]612a1cb12012-10-17 13:18:031821 return;
1822
1823 const Extension* extension = NULL;
1824 for (ExtensionSet::const_iterator iter = disabled_extensions_.begin();
1825 iter != disabled_extensions_.end(); ++iter) {
[email protected]cadac622013-06-11 16:46:361826 const Extension* e = iter->get();
[email protected]d96eb512012-11-01 23:44:081827 if (IsUnacknowledgedExternalExtension(e)) {
1828 extension = e;
1829 break;
[email protected]612a1cb12012-10-17 13:18:031830 }
1831 }
1832
1833 if (extension) {
[email protected]d96eb512012-11-01 23:44:081834 if (!extensions::HasExternalInstallError(this)) {
1835 if (extension_prefs_->IncrementAcknowledgePromptCount(extension->id()) >
[email protected]612a1cb12012-10-17 13:18:031836 kMaxExtensionAcknowledgePromptCount) {
[email protected]d96eb512012-11-01 23:44:081837 // Stop prompting for this extension, and check if there's another
1838 // one that needs prompting.
[email protected]612a1cb12012-10-17 13:18:031839 extension_prefs_->AcknowledgeExternalExtension(extension->id());
[email protected]d96eb512012-11-01 23:44:081840 UpdateExternalExtensionAlert();
1841 UMA_HISTOGRAM_ENUMERATION("Extensions.ExternalExtensionEvent",
1842 EXTERNAL_EXTENSION_IGNORED,
1843 EXTERNAL_EXTENSION_BUCKET_BOUNDARY);
[email protected]446e37e2013-08-07 00:30:021844 if (extensions::ManifestURL::UpdatesFromGallery(extension)) {
1845 UMA_HISTOGRAM_ENUMERATION(
1846 "Extensions.ExternalExtensionEventWebstore",
1847 EXTERNAL_EXTENSION_IGNORED,
1848 EXTERNAL_EXTENSION_BUCKET_BOUNDARY);
1849 } else {
1850 UMA_HISTOGRAM_ENUMERATION(
1851 "Extensions.ExternalExtensionEventNonWebstore",
1852 EXTERNAL_EXTENSION_IGNORED,
1853 EXTERNAL_EXTENSION_BUCKET_BOUNDARY);
1854 }
[email protected]d96eb512012-11-01 23:44:081855 return;
[email protected]612a1cb12012-10-17 13:18:031856 }
[email protected]b3aa7182013-04-25 04:45:231857 if (is_first_run_)
1858 extension_prefs_->SetExternalInstallFirstRun(extension->id());
1859 // first_run is true if the extension was installed during a first run
1860 // (even if it's post-first run now).
1861 bool first_run = extension_prefs_->IsExternalInstallFirstRun(
1862 extension->id());
1863 extensions::AddExternalInstallError(this, extension, first_run);
[email protected]612a1cb12012-10-17 13:18:031864 }
1865 } else {
1866 extensions::RemoveExternalInstallError(this);
1867 }
[email protected]612a1cb12012-10-17 13:18:031868}
1869
[email protected]a9f39a312010-12-23 22:14:271870void ExtensionService::UnloadExtension(
1871 const std::string& extension_id,
[email protected]814a7bf0f2011-08-13 05:30:591872 extension_misc::UnloadedExtensionReason reason) {
[email protected]27e469a2010-01-11 20:35:091873 // Make sure the extension gets deleted after we return from this function.
[email protected]695b5712012-12-06 23:55:281874 int include_mask = INCLUDE_EVERYTHING & ~INCLUDE_TERMINATED;
[email protected]9adb9692010-10-29 23:14:021875 scoped_refptr<const Extension> extension(
[email protected]695b5712012-12-06 23:55:281876 GetExtensionById(extension_id, include_mask));
[email protected]631cf822009-05-15 07:01:251877
[email protected]fa0c96732010-11-17 00:14:231878 // This method can be called via PostTask, so the extension may have been
1879 // unloaded by the time this runs.
[email protected]dc24976f2013-06-02 21:15:091880 if (!extension.get()) {
[email protected]dd163fb02011-05-04 22:22:171881 // In case the extension may have crashed/uninstalled. Allow the profile to
1882 // clean up its RequestContexts.
[email protected]31d8f5f22012-04-02 15:22:081883 system_->UnregisterExtensionWithRequestContexts(extension_id, reason);
[email protected]fa0c96732010-11-17 00:14:231884 return;
[email protected]dd163fb02011-05-04 22:22:171885 }
[email protected]0c6da502009-08-14 22:32:391886
[email protected]20c8b942013-05-26 02:03:401887 // If uninstalling let RuntimeEventRouter know.
1888 if (reason == extension_misc::UNLOAD_REASON_UNINSTALL)
1889 extensions::RuntimeEventRouter::OnExtensionUninstalled(
1890 profile_, extension_id);
1891
[email protected]1eb175082010-02-10 09:26:161892 // Keep information about the extension so that we can reload it later
1893 // even if it's not permanently installed.
1894 unloaded_extension_paths_[extension->id()] = extension->path();
1895
[email protected]f17dbd42010-08-16 23:21:101896 // Clean up if the extension is meant to be enabled after a reload.
[email protected]b914e2952013-04-26 07:10:031897 reloading_extensions_.erase(extension->id());
[email protected]f17dbd42010-08-16 23:21:101898
[email protected]d7e9a862010-11-03 21:57:491899 // Clean up runtime data.
1900 extension_runtime_data_.erase(extension_id);
1901
[email protected]060d4972012-07-19 17:22:391902 if (disabled_extensions_.Contains(extension->id())) {
[email protected]84df8332011-12-06 18:22:461903 disabled_extensions_.Remove(extension->id());
[email protected]dd163fb02011-05-04 22:22:171904 // Make sure the profile cleans up its RequestContexts when an already
1905 // disabled extension is unloaded (since they are also tracking the disabled
1906 // extensions).
[email protected]31d8f5f22012-04-02 15:22:081907 system_->UnregisterExtensionWithRequestContexts(extension_id, reason);
[email protected]60a174a2013-08-02 20:29:281908 } else {
1909 // Remove the extension from our list.
1910 extensions_.Remove(extension->id());
1911 NotifyExtensionUnloaded(extension.get(), reason);
[email protected]0c6da502009-08-14 22:32:391912 }
1913
[email protected]fb789532013-08-27 02:40:211914 content::NotificationService::current()->Notify(
1915 chrome::NOTIFICATION_EXTENSION_REMOVED,
1916 content::Source<Profile>(profile_),
1917 content::Details<const Extension>(extension.get()));
[email protected]631cf822009-05-15 07:01:251918}
1919
[email protected]8b1ec202013-09-05 02:09:501920void ExtensionService::RemoveComponentExtension(
1921 const std::string& extension_id) {
1922 scoped_refptr<const Extension> extension(
1923 GetExtensionById(extension_id, false));
1924 UnloadExtension(extension_id, extension_misc::UNLOAD_REASON_UNINSTALL);
1925 content::NotificationService::current()->Notify(
1926 chrome::NOTIFICATION_EXTENSION_UNINSTALLED,
1927 content::Source<Profile>(profile_),
1928 content::Details<const Extension>(extension.get()));
1929}
1930
[email protected]eaa7dd182010-12-14 11:09:001931void ExtensionService::UnloadAllExtensions() {
[email protected]31bb5ee62012-09-12 22:58:401932 profile_->GetExtensionSpecialStoragePolicy()->RevokeRightsForAllExtensions();
[email protected]c8d407e2011-04-28 21:27:171933
[email protected]84df8332011-12-06 18:22:461934 extensions_.Clear();
1935 disabled_extensions_.Clear();
1936 terminated_extensions_.Clear();
[email protected]d7e9a862010-11-03 21:57:491937 extension_runtime_data_.clear();
[email protected]cd500f72010-06-25 23:44:321938
[email protected]c6e4a3412009-06-24 15:45:291939 // TODO(erikkay) should there be a notification for this? We can't use
1940 // EXTENSION_UNLOADED since that implies that the extension has been disabled
1941 // or uninstalled, and UnloadAll is just part of shutdown.
[email protected]9f1087e2009-06-15 17:29:321942}
1943
[email protected]eaa7dd182010-12-14 11:09:001944void ExtensionService::ReloadExtensions() {
[email protected]9f1087e2009-06-15 17:29:321945 UnloadAllExtensions();
[email protected]eac88332012-12-26 17:57:451946 component_loader_->LoadAll();
[email protected]d8c8f25f2011-11-02 18:18:011947 extensions::InstalledLoader(this).LoadAllExtensions();
[email protected]4a10006a2013-05-17 23:18:351948 // Don't call SetReadyAndNotifyListeners() since tests call this multiple
1949 // times.
[email protected]9f1087e2009-06-15 17:29:321950}
1951
[email protected]eaa7dd182010-12-14 11:09:001952void ExtensionService::GarbageCollectExtensions() {
[email protected]c04fd3dd2013-09-05 08:20:101953#if defined(OS_CHROMEOS)
1954 if (disable_garbage_collection_)
1955 return;
1956#endif
1957
[email protected]2f8757c32012-06-19 19:17:471958 if (extension_prefs_->pref_service()->ReadOnly())
1959 return;
1960
[email protected]9bd9a6862012-11-29 09:24:221961 if (pending_extension_manager()->HasPendingExtensions()) {
1962 // Don't garbage collect while there are pending installations, which may
1963 // be using the temporary installation directory. Try to garbage collect
1964 // again later.
[email protected]b3a25092013-05-28 22:08:161965 base::MessageLoop::current()->PostDelayedTask(
[email protected]9bd9a6862012-11-29 09:24:221966 FROM_HERE,
1967 base::Bind(&ExtensionService::GarbageCollectExtensions, AsWeakPtr()),
1968 base::TimeDelta::FromSeconds(kGarbageCollectRetryDelay));
1969 return;
1970 }
1971
[email protected]45759612012-07-10 17:21:231972 scoped_ptr<extensions::ExtensionPrefs::ExtensionsInfo> info(
[email protected]2f8757c32012-06-19 19:17:471973 extension_prefs_->GetInstalledExtensionsInfo());
1974
[email protected]650b2d52013-02-10 03:41:451975 std::multimap<std::string, base::FilePath> extension_paths;
[email protected]2f8757c32012-06-19 19:17:471976 for (size_t i = 0; i < info->size(); ++i)
[email protected]0db124b02012-11-07 04:55:051977 extension_paths.insert(std::make_pair(info->at(i)->extension_id,
1978 info->at(i)->extension_path));
1979
[email protected]399583b2012-12-11 09:33:421980 info = extension_prefs_->GetAllDelayedInstallInfo();
[email protected]0db124b02012-11-07 04:55:051981 for (size_t i = 0; i < info->size(); ++i)
1982 extension_paths.insert(std::make_pair(info->at(i)->extension_id,
1983 info->at(i)->extension_path));
[email protected]2f8757c32012-06-19 19:17:471984
[email protected]7f8f24f2012-11-15 19:40:141985 if (!GetFileTaskRunner()->PostTask(
1986 FROM_HERE,
[email protected]2f8757c32012-06-19 19:17:471987 base::Bind(
1988 &extension_file_util::GarbageCollectExtensions,
1989 install_directory_,
[email protected]31bb5ee62012-09-12 22:58:401990 extension_paths))) {
[email protected]2f8757c32012-06-19 19:17:471991 NOTREACHED();
[email protected]31bb5ee62012-09-12 22:58:401992 }
[email protected]3cf4f0992009-02-03 23:00:301993}
1994
[email protected]fb82dcd2012-03-21 14:15:461995void ExtensionService::SyncExtensionChangeIfNeeded(const Extension& extension) {
[email protected]6d147912013-07-09 08:02:141996 if (extensions::sync_helper::IsSyncableApp(&extension)) {
1997 if (app_sync_bundle_.IsSyncing())
1998 app_sync_bundle_.SyncChangeIfNeeded(extension);
1999 else if (is_ready() && !flare_.is_null())
2000 flare_.Run(syncer::APPS);
2001 } else if (extensions::sync_helper::IsSyncableExtension(&extension)) {
2002 if (extension_sync_bundle_.IsSyncing())
2003 extension_sync_bundle_.SyncChangeIfNeeded(extension);
2004 else if (is_ready() && !flare_.is_null())
2005 flare_.Run(syncer::EXTENSIONS);
[email protected]fb82dcd2012-03-21 14:15:462006 }
2007}
2008
[email protected]820d9bd2013-04-03 03:46:032009void ExtensionService::SetReadyAndNotifyListeners() {
[email protected]4a10006a2013-05-17 23:18:352010 ready_->Signal();
[email protected]820d9bd2013-04-03 03:46:032011 content::NotificationService::current()->Notify(
2012 chrome::NOTIFICATION_EXTENSIONS_READY,
2013 content::Source<Profile>(profile_),
2014 content::NotificationService::NoDetails());
2015}
2016
[email protected]eaa7dd182010-12-14 11:09:002017void ExtensionService::OnLoadedInstalledExtensions() {
[email protected]3eeddd892013-04-17 17:00:112018 if (updater_)
[email protected]93fd78f42009-07-10 16:43:172019 updater_->Start();
[email protected]fa6a9102010-11-22 15:38:502020
[email protected]bc151cf92013-02-12 04:57:262021 OnBlacklistUpdated();
[email protected]e72e8eb82009-06-18 17:21:512022}
2023
[email protected]fcb58a862012-05-01 01:03:152024void ExtensionService::AddExtension(const Extension* extension) {
[email protected]c8d407e2011-04-28 21:27:172025 // TODO(jstritar): We may be able to get rid of this branch by overriding the
2026 // default extension state to DISABLED when the --disable-extensions flag
2027 // is set (http://crbug.com/29067).
2028 if (!extensions_enabled() &&
2029 !extension->is_theme() &&
[email protected]1d5e58b2013-01-31 08:41:402030 extension->location() != Manifest::COMPONENT &&
2031 !Manifest::IsExternalLocation(extension->location())) {
[email protected]fcb58a862012-05-01 01:03:152032 return;
[email protected]330840c2012-08-29 22:21:012033 }
[email protected]c8d407e2011-04-28 21:27:172034
[email protected]b914e2952013-04-26 07:10:032035 bool is_extension_upgrade = false;
[email protected]116d40e2013-08-08 17:23:172036 bool is_extension_installed = false;
2037 const Extension* old = GetInstalledExtension(extension->id());
2038 if (old) {
2039 is_extension_installed = true;
2040 int version_compare_result =
2041 extension->version()->CompareTo(*(old->version()));
2042 is_extension_upgrade = version_compare_result > 0;
[email protected]b914e2952013-04-26 07:10:032043 // Other than for unpacked extensions, CrxInstaller should have guaranteed
2044 // that we aren't downgrading.
2045 if (!Manifest::IsUnpackedLocation(extension->location()))
[email protected]116d40e2013-08-08 17:23:172046 CHECK_GE(version_compare_result, 0);
[email protected]b914e2952013-04-26 07:10:032047 }
2048 SetBeingUpgraded(extension, is_extension_upgrade);
[email protected]c8d407e2011-04-28 21:27:172049
[email protected]1eb175082010-02-10 09:26:162050 // The extension is now loaded, remove its data from unloaded extension map.
2051 unloaded_extension_paths_.erase(extension->id());
2052
[email protected]bb7f40952011-01-13 00:21:202053 // If a terminated extension is loaded, remove it from the terminated list.
2054 UntrackTerminatedExtension(extension->id());
2055
[email protected]f17dbd42010-08-16 23:21:102056 // If the extension was disabled for a reload, then enable it.
[email protected]ca2e82022013-04-29 16:48:412057 bool reloading = reloading_extensions_.erase(extension->id()) > 0;
[email protected]f17dbd42010-08-16 23:21:102058
[email protected]b914e2952013-04-26 07:10:032059 // Check if the extension's privileges have changed and mark the
2060 // extension disabled if necessary.
[email protected]116d40e2013-08-08 17:23:172061 CheckPermissionsIncrease(extension, is_extension_installed);
[email protected]b914e2952013-04-26 07:10:032062
[email protected]116d40e2013-08-08 17:23:172063 if (is_extension_installed && !reloading) {
[email protected]ca2e82022013-04-29 16:48:412064 // To upgrade an extension in place, unload the old one and then load the
2065 // new one. ReloadExtension disables the extension, which is sufficient.
[email protected]b914e2952013-04-26 07:10:032066 UnloadExtension(extension->id(), extension_misc::UNLOAD_REASON_UPDATE);
2067 }
[email protected]0c6da502009-08-14 22:32:392068
[email protected]695b5712012-12-06 23:55:282069 if (extension_prefs_->IsExtensionBlacklisted(extension->id())) {
[email protected]ac875372013-02-28 04:36:092070 // Only prefs is checked for the blacklist. We rely on callers to check the
2071 // blacklist before calling into here, e.g. CrxInstaller checks before
[email protected]9f3c8532013-07-31 19:52:072072 // installation then threads through the install and pending install flow
2073 // of this class, and we check when loading installed extensions.
[email protected]695b5712012-12-06 23:55:282074 blacklisted_extensions_.Insert(extension);
[email protected]ca2e82022013-04-29 16:48:412075 } else if (!reloading &&
2076 extension_prefs_->IsExtensionDisabled(extension->id())) {
[email protected]6f6101832012-11-27 22:10:482077 disabled_extensions_.Insert(extension);
[email protected]3bdba0d2011-08-23 07:17:302078 SyncExtensionChangeIfNeeded(*extension);
[email protected]44d62b62012-04-11 00:06:032079 content::NotificationService::current()->Notify(
2080 chrome::NOTIFICATION_EXTENSION_UPDATE_DISABLED,
2081 content::Source<Profile>(profile_),
2082 content::Details<const Extension>(extension));
[email protected]62f051c2012-03-29 17:04:442083
[email protected]7e9e2422012-12-13 19:54:192084 // Show the extension disabled error if a permissions increase was the
2085 // only reason it was disabled.
2086 if (extension_prefs_->GetDisableReasons(extension->id()) ==
[email protected]44d62b62012-04-11 00:06:032087 Extension::DISABLE_PERMISSIONS_INCREASE) {
[email protected]62f051c2012-03-29 17:04:442088 extensions::AddExtensionDisabledError(this, extension);
2089 }
[email protected]ca2e82022013-04-29 16:48:412090 } else if (reloading) {
2091 // Replace the old extension with the new version.
2092 CHECK(!disabled_extensions_.Insert(extension));
2093 EnableExtension(extension->id());
[email protected]695b5712012-12-06 23:55:282094 } else {
2095 // All apps that are displayed in the launcher are ordered by their ordinals
2096 // so we must ensure they have valid ordinals.
2097 if (extension->RequiresSortOrdinal()) {
[email protected]bd36b652013-02-27 02:13:252098 if (!extension->ShouldDisplayInNewTabPage()) {
2099 extension_prefs_->extension_sorting()->MarkExtensionAsHidden(
2100 extension->id());
2101 }
[email protected]695b5712012-12-06 23:55:282102 extension_prefs_->extension_sorting()->EnsureValidOrdinals(
2103 extension->id(), syncer::StringOrdinal());
2104 }
2105
2106 extensions_.Insert(extension);
2107 SyncExtensionChangeIfNeeded(*extension);
2108 NotifyExtensionLoaded(extension);
[email protected]f574c402012-12-04 23:20:312109 }
[email protected]b914e2952013-04-26 07:10:032110 SetBeingUpgraded(extension, false);
[email protected]aab98a52009-12-02 03:22:352111}
2112
[email protected]8c484b742012-11-29 06:05:362113void ExtensionService::AddComponentExtension(const Extension* extension) {
2114 const std::string old_version_string(
2115 extension_prefs_->GetVersionString(extension->id()));
2116 const Version old_version(old_version_string);
2117
2118 if (!old_version.IsValid() || !old_version.Equals(*extension->version())) {
2119 VLOG(1) << "Component extension " << extension->name() << " ("
2120 << extension->id() << ") installing/upgrading from '"
2121 << old_version_string << "' to " << extension->version()->GetString();
2122
2123 AddNewOrUpdatedExtension(extension,
[email protected]399583b2012-12-11 09:33:422124 Extension::ENABLED_COMPONENT,
[email protected]9f3c8532013-07-31 19:52:072125 extensions::Blacklist::NOT_BLACKLISTED,
[email protected]399583b2012-12-11 09:33:422126 syncer::StringOrdinal());
[email protected]8c484b742012-11-29 06:05:362127 return;
2128 }
2129
2130 AddExtension(extension);
2131}
2132
[email protected]b914e2952013-04-26 07:10:032133void ExtensionService::UpdateActivePermissions(const Extension* extension) {
[email protected]902fd7b2011-07-27 18:42:312134 // If the extension has used the optional permissions API, it will have a
2135 // custom set of active permissions defined in the extension prefs. Here,
2136 // we update the extension's active permissions based on the prefs.
[email protected]c2e66e12012-06-27 06:27:062137 scoped_refptr<PermissionSet> active_permissions =
[email protected]902fd7b2011-07-27 18:42:312138 extension_prefs()->GetActivePermissions(extension->id());
2139
[email protected]dc24976f2013-06-02 21:15:092140 if (active_permissions.get()) {
[email protected]902fd7b2011-07-27 18:42:312141 // We restrict the active permissions to be within the bounds defined in the
2142 // extension's manifest.
2143 // a) active permissions must be a subset of optional + default permissions
2144 // b) active permissions must contains all default permissions
[email protected]c2e66e12012-06-27 06:27:062145 scoped_refptr<PermissionSet> total_permissions =
2146 PermissionSet::CreateUnion(
[email protected]2cb5e302013-05-09 05:00:062147 extensions::PermissionsData::GetRequiredPermissions(extension),
2148 extensions::PermissionsData::GetOptionalPermissions(extension));
[email protected]902fd7b2011-07-27 18:42:312149
2150 // Make sure the active permissions contain no more than optional + default.
[email protected]c2e66e12012-06-27 06:27:062151 scoped_refptr<PermissionSet> adjusted_active =
2152 PermissionSet::CreateIntersection(
[email protected]902fd7b2011-07-27 18:42:312153 total_permissions.get(), active_permissions.get());
2154
2155 // Make sure the active permissions contain the default permissions.
[email protected]c2e66e12012-06-27 06:27:062156 adjusted_active = PermissionSet::CreateUnion(
[email protected]2cb5e302013-05-09 05:00:062157 extensions::PermissionsData::GetRequiredPermissions(extension),
2158 adjusted_active.get());
[email protected]902fd7b2011-07-27 18:42:312159
[email protected]c333e792012-01-06 16:57:392160 extensions::PermissionsUpdater perms_updater(profile());
[email protected]dc24976f2013-06-02 21:15:092161 perms_updater.UpdateActivePermissions(extension, adjusted_active.get());
[email protected]902fd7b2011-07-27 18:42:312162 }
[email protected]b914e2952013-04-26 07:10:032163}
2164
2165void ExtensionService::CheckPermissionsIncrease(const Extension* extension,
[email protected]116d40e2013-08-08 17:23:172166 bool is_extension_installed) {
[email protected]b914e2952013-04-26 07:10:032167 UpdateActivePermissions(extension);
[email protected]902fd7b2011-07-27 18:42:312168
[email protected]8d888c12010-11-30 00:00:252169 // We keep track of all permissions the user has granted each extension.
2170 // This allows extensions to gracefully support backwards compatibility
2171 // by including unknown permissions in their manifests. When the user
2172 // installs the extension, only the recognized permissions are recorded.
2173 // When the unknown permissions become recognized (e.g., through browser
2174 // upgrade), we can prompt the user to accept these new permissions.
2175 // Extensions can also silently upgrade to less permissions, and then
2176 // silently upgrade to a version that adds these permissions back.
2177 //
2178 // For example, pretend that Chrome 10 includes a permission "omnibox"
2179 // for an API that adds suggestions to the omnibox. An extension can
2180 // maintain backwards compatibility while still having "omnibox" in the
2181 // manifest. If a user installs the extension on Chrome 9, the browser
2182 // will record the permissions it recognized, not including "omnibox."
2183 // When upgrading to Chrome 10, "omnibox" will be recognized and Chrome
2184 // will disable the extension and prompt the user to approve the increase
2185 // in privileges. The extension could then release a new version that
2186 // removes the "omnibox" permission. When the user upgrades, Chrome will
2187 // still remember that "omnibox" had been granted, so that if the
2188 // extension once again includes "omnibox" in an upgrade, the extension
2189 // can upgrade without requiring this user's approval.
[email protected]eb5e4f92012-08-15 23:33:282190 int disable_reasons = extension_prefs_->GetDisableReasons(extension->id());
[email protected]8d888c12010-11-30 00:00:252191
[email protected]211a3f32013-05-28 21:48:182192 bool auto_grant_permission =
[email protected]aa5a5472013-10-04 03:41:042193 (!is_extension_installed && extension->was_installed_by_default() &&
2194 !extension->requires_permissions_consent()) ||
[email protected]211a3f32013-05-28 21:48:182195 chrome::IsRunningInForcedAppMode();
[email protected]b914e2952013-04-26 07:10:032196 // Silently grant all active permissions to default apps only on install.
2197 // After install they should behave like other apps.
[email protected]211a3f32013-05-28 21:48:182198 // Silently grant all active permissions to apps install in kiosk mode on both
2199 // install and update.
2200 if (auto_grant_permission)
[email protected]b914e2952013-04-26 07:10:032201 GrantPermissions(extension);
2202
2203 bool is_privilege_increase = false;
2204 // We only need to compare the granted permissions to the current permissions
2205 // if the extension is not allowed to silently increase its permissions.
[email protected]13c68b62013-05-17 11:29:052206 if (!extensions::PermissionsData::CanSilentlyIncreasePermissions(extension) &&
[email protected]211a3f32013-05-28 21:48:182207 !auto_grant_permission) {
[email protected]8d888c12010-11-30 00:00:252208 // Add all the recognized permissions if the granted permissions list
2209 // hasn't been initialized yet.
[email protected]c2e66e12012-06-27 06:27:062210 scoped_refptr<PermissionSet> granted_permissions =
[email protected]902fd7b2011-07-27 18:42:312211 extension_prefs_->GetGrantedPermissions(extension->id());
[email protected]0d3e4a22011-06-23 19:02:522212 CHECK(granted_permissions.get());
[email protected]8d888c12010-11-30 00:00:252213
2214 // Here, we check if an extension's privileges have increased in a manner
2215 // that requires the user's approval. This could occur because the browser
2216 // upgraded and recognized additional privileges, or an extension upgrades
2217 // to a version that requires additional privileges.
[email protected]c41003472013-10-19 15:37:252218 is_privilege_increase =
2219 extensions::PermissionMessageProvider::Get()->IsPrivilegeIncrease(
2220 granted_permissions,
2221 extension->GetActivePermissions().get(),
2222 extension->GetType());
[email protected]8d888c12010-11-30 00:00:252223 }
2224
[email protected]116d40e2013-08-08 17:23:172225 if (is_extension_installed) {
[email protected]44d62b62012-04-11 00:06:032226 // If the extension was already disabled, suppress any alerts for becoming
2227 // disabled on permissions increase.
[email protected]b914e2952013-04-26 07:10:032228 bool previously_disabled =
2229 extension_prefs_->IsExtensionDisabled(extension->id());
[email protected]7e9e2422012-12-13 19:54:192230 // Legacy disabled extensions do not have a disable reason. Infer that if
2231 // there was no permission increase, it was likely disabled by the user.
2232 if (previously_disabled && disable_reasons == Extension::DISABLE_NONE &&
[email protected]b914e2952013-04-26 07:10:032233 !extension_prefs_->DidExtensionEscalatePermissions(extension->id())) {
[email protected]7e9e2422012-12-13 19:54:192234 disable_reasons |= Extension::DISABLE_USER_ACTION;
[email protected]44d62b62012-04-11 00:06:032235 }
[email protected]7e9e2422012-12-13 19:54:192236 // Extensions that came to us disabled from sync need a similar inference,
2237 // except based on the new version's permissions.
2238 if (previously_disabled &&
2239 disable_reasons == Extension::DISABLE_UNKNOWN_FROM_SYNC) {
2240 // Remove the DISABLE_UNKNOWN_FROM_SYNC reason.
2241 extension_prefs_->ClearDisableReasons(extension->id());
2242 if (!is_privilege_increase)
2243 disable_reasons |= Extension::DISABLE_USER_ACTION;
2244 }
[email protected]b914e2952013-04-26 07:10:032245 disable_reasons &= ~Extension::DISABLE_UNKNOWN_FROM_SYNC;
[email protected]aa5a5472013-10-04 03:41:042246 } else if (extension->requires_permissions_consent()) {
2247 disable_reasons |= Extension::DISABLE_PERMISSIONS_CONSENT;
2248 extension_prefs_->SetExtensionState(extension->id(), Extension::DISABLED);
[email protected]8d888c12010-11-30 00:00:252249 }
2250
2251 // Extension has changed permissions significantly. Disable it. A
2252 // notification should be sent by the caller.
2253 if (is_privilege_increase) {
[email protected]7e9e2422012-12-13 19:54:192254 disable_reasons |= Extension::DISABLE_PERMISSIONS_INCREASE;
[email protected]fe2dd7742011-04-19 22:52:492255 if (!extension_prefs_->DidExtensionEscalatePermissions(extension->id())) {
2256 RecordPermissionMessagesHistogram(
2257 extension, "Extensions.Permissions_AutoDisable");
2258 }
[email protected]59ee99d2013-10-11 15:46:162259 DisableExtension(extension->id(),
2260 static_cast<Extension::DisableReason>(disable_reasons));
[email protected]8d888c12010-11-30 00:00:252261 extension_prefs_->SetDidExtensionEscalatePermissions(extension, true);
[email protected]b914e2952013-04-26 07:10:032262 }
2263 if (disable_reasons != Extension::DISABLE_NONE) {
[email protected]eb5e4f92012-08-15 23:33:282264 extension_prefs_->AddDisableReason(
2265 extension->id(),
2266 static_cast<Extension::DisableReason>(disable_reasons));
[email protected]8d888c12010-11-30 00:00:252267 }
2268}
2269
[email protected]eaa7dd182010-12-14 11:09:002270void ExtensionService::UpdateActiveExtensionsInCrashReporter() {
[email protected]c8865962009-12-16 07:47:392271 std::set<std::string> extension_ids;
[email protected]84df8332011-12-06 18:22:462272 for (ExtensionSet::const_iterator iter = extensions_.begin();
2273 iter != extensions_.end(); ++iter) {
[email protected]cadac622013-06-11 16:46:362274 const Extension* extension = iter->get();
[email protected]1d5e58b2013-01-31 08:41:402275 if (!extension->is_theme() && extension->location() != Manifest::COMPONENT)
[email protected]84df8332011-12-06 18:22:462276 extension_ids.insert(extension->id());
[email protected]aab98a52009-12-02 03:22:352277 }
2278
[email protected]f6431be82013-09-07 02:53:452279 crash_keys::SetActiveExtensions(extension_ids);
[email protected]6014d672008-12-05 00:38:252280}
2281
[email protected]669b2372013-10-17 15:04:582282ExtensionService::ImportStatus ExtensionService::CheckImports(
2283 const extensions::Extension* extension,
2284 std::list<SharedModuleInfo::ImportInfo>* missing_modules,
2285 std::list<SharedModuleInfo::ImportInfo>* outdated_modules) {
2286 DCHECK(extension);
2287 DCHECK(missing_modules && missing_modules->empty());
2288 DCHECK(outdated_modules && outdated_modules->empty());
[email protected]9f4e4f082013-06-21 07:11:192289 ImportStatus status = IMPORT_STATUS_OK;
[email protected]9f4e4f082013-06-21 07:11:192290 if (SharedModuleInfo::ImportsModules(extension)) {
2291 const std::vector<SharedModuleInfo::ImportInfo>& imports =
2292 SharedModuleInfo::GetImports(extension);
2293 std::vector<SharedModuleInfo::ImportInfo>::const_iterator i;
2294 for (i = imports.begin(); i != imports.end(); ++i) {
2295 Version version_required(i->minimum_version);
2296 const Extension* imported_module =
2297 GetExtensionById(i->extension_id, true);
2298 if (!imported_module) {
2299 if (extension->from_webstore()) {
2300 status = IMPORT_STATUS_UNSATISFIED;
[email protected]669b2372013-10-17 15:04:582301 missing_modules->push_back(*i);
[email protected]9f4e4f082013-06-21 07:11:192302 } else {
2303 return IMPORT_STATUS_UNRECOVERABLE;
2304 }
2305 } else if (!SharedModuleInfo::IsSharedModule(imported_module)) {
2306 return IMPORT_STATUS_UNRECOVERABLE;
2307 } else if (version_required.IsValid() &&
2308 imported_module->version()->CompareTo(version_required) < 0) {
2309 if (imported_module->from_webstore()) {
[email protected]669b2372013-10-17 15:04:582310 outdated_modules->push_back(*i);
[email protected]9f4e4f082013-06-21 07:11:192311 status = IMPORT_STATUS_UNSATISFIED;
2312 } else {
2313 return IMPORT_STATUS_UNRECOVERABLE;
2314 }
2315 }
2316 }
2317 }
[email protected]669b2372013-10-17 15:04:582318 return status;
2319}
2320
2321ExtensionService::ImportStatus ExtensionService::SatisfyImports(
2322 const Extension* extension) {
2323 std::list<SharedModuleInfo::ImportInfo> noinstalled;
2324 std::list<SharedModuleInfo::ImportInfo> outdated;
2325 ImportStatus status = CheckImports(extension, &noinstalled, &outdated);
2326 if (status == IMPORT_STATUS_UNRECOVERABLE)
2327 return status;
[email protected]9f4e4f082013-06-21 07:11:192328 if (status == IMPORT_STATUS_UNSATISFIED) {
[email protected]669b2372013-10-17 15:04:582329 std::list<SharedModuleInfo::ImportInfo>::const_iterator iter;
2330 for (iter = noinstalled.begin(); iter != noinstalled.end(); ++iter) {
[email protected]9f4e4f082013-06-21 07:11:192331 pending_extension_manager()->AddFromExtensionImport(
[email protected]669b2372013-10-17 15:04:582332 iter->extension_id,
[email protected]9f4e4f082013-06-21 07:11:192333 extension_urls::GetWebstoreUpdateUrl(),
2334 IsSharedModule);
2335 }
2336 CheckForUpdatesSoon();
2337 }
2338 return status;
2339}
2340
2341scoped_ptr<const ExtensionSet>
2342 ExtensionService::GetDependentExtensions(const Extension* extension) {
2343 scoped_ptr<ExtensionSet> dependents(new ExtensionSet());
2344 scoped_ptr<ExtensionSet> set_to_check(new ExtensionSet());
2345 if (SharedModuleInfo::IsSharedModule(extension)) {
2346 set_to_check->InsertAll(disabled_extensions_);
2347 set_to_check->InsertAll(delayed_installs_);
2348 set_to_check->InsertAll(extensions_);
2349 for (ExtensionSet::const_iterator iter = set_to_check->begin();
2350 iter != set_to_check->end(); ++iter) {
[email protected]198b5902013-06-27 10:36:112351 if (SharedModuleInfo::ImportsExtensionById(iter->get(),
2352 extension->id())) {
[email protected]9f4e4f082013-06-21 07:11:192353 dependents->Insert(*iter);
2354 }
2355 }
2356 }
2357 return dependents.PassAs<const ExtensionSet>();
2358}
2359
2360void ExtensionService::PruneSharedModulesOnUninstall(
2361 const Extension* extension) {
2362 if (SharedModuleInfo::ImportsModules(extension)) {
2363 const std::vector<SharedModuleInfo::ImportInfo>& imports =
2364 SharedModuleInfo::GetImports(extension);
2365 std::vector<SharedModuleInfo::ImportInfo>::const_iterator i;
2366 for (i = imports.begin(); i != imports.end(); ++i) {
2367 const Extension* imported_module =
2368 GetExtensionById(i->extension_id, true);
2369 if (imported_module && imported_module->from_webstore()) {
2370 scoped_ptr<const ExtensionSet> dependents =
2371 GetDependentExtensions(imported_module);
2372 if (dependents->size() == 0) {
[email protected]4c9201c42013-08-16 04:56:212373 UninstallExtension(i->extension_id, true, NULL);
[email protected]9f4e4f082013-06-21 07:11:192374 }
2375 }
2376 }
2377 }
2378}
2379
[email protected]8266d662011-07-12 21:53:262380void ExtensionService::OnExtensionInstalled(
[email protected]36a5c4c2011-12-14 16:34:502381 const Extension* extension,
[email protected]98270432012-09-11 20:51:242382 const syncer::StringOrdinal& page_ordinal,
[email protected]0db124b02012-11-07 04:55:052383 bool has_requirement_errors,
[email protected]9f3c8532013-07-31 19:52:072384 extensions::Blacklist::BlacklistState blacklist_state,
[email protected]0db124b02012-11-07 04:55:052385 bool wait_for_idle) {
[email protected]a29a517a2011-01-21 21:11:122386 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]a8af9fdb2010-10-28 21:52:202387
[email protected]c3cfb012011-04-06 22:07:352388 const std::string& id = extension->id();
[email protected]612a1cb12012-10-17 13:18:032389 bool initial_enable = ShouldEnableOnInstall(extension);
[email protected]3f213ad2012-07-26 23:39:412390 const extensions::PendingExtensionInfo* pending_extension_info = NULL;
[email protected]51a3bf8b2012-06-08 22:53:062391 if ((pending_extension_info = pending_extension_manager()->GetById(id))) {
[email protected]8f3bcbd2013-06-05 08:42:402392 if (!pending_extension_info->ShouldAllowInstall(extension)) {
[email protected]51a3bf8b2012-06-08 22:53:062393 pending_extension_manager()->Remove(id);
[email protected]8ef78fd2010-08-19 17:14:322394
[email protected]31bb5ee62012-09-12 22:58:402395 LOG(WARNING) << "ShouldAllowInstall() returned false for "
2396 << id << " of type " << extension->GetType()
[email protected]65348062013-01-15 07:27:222397 << " and update URL "
2398 << extensions::ManifestURL::GetUpdateURL(extension).spec()
[email protected]31bb5ee62012-09-12 22:58:402399 << "; not installing";
[email protected]ae6cb3022011-04-04 20:11:542400
[email protected]4416c5a2010-06-26 01:28:572401 // Delete the extension directory since we're not going to
2402 // load it.
[email protected]7f8f24f2012-11-15 19:40:142403 if (!GetFileTaskRunner()->PostTask(
2404 FROM_HERE,
[email protected]53612e82011-10-18 18:00:362405 base::Bind(&extension_file_util::DeleteFile,
[email protected]31bb5ee62012-09-12 22:58:402406 extension->path(), true))) {
[email protected]14908b72011-04-20 06:54:362407 NOTREACHED();
[email protected]31bb5ee62012-09-12 22:58:402408 }
[email protected]4416c5a2010-06-26 01:28:572409 return;
2410 }
[email protected]51a3bf8b2012-06-08 22:53:062411
2412 pending_extension_manager()->Remove(id);
[email protected]4416c5a2010-06-26 01:28:572413 } else {
[email protected]c3cfb012011-04-06 22:07:352414 // We explicitly want to re-enable an uninstalled external
2415 // extension; if we're here, that means the user is manually
2416 // installing the extension.
[email protected]6cc7dbae2011-04-29 21:18:332417 if (IsExternalExtensionUninstalled(id)) {
2418 initial_enable = true;
2419 }
[email protected]aa142702010-03-26 01:26:332420 }
2421
[email protected]98270432012-09-11 20:51:242422 // Unsupported requirements overrides the management policy.
2423 if (has_requirement_errors) {
2424 initial_enable = false;
2425 extension_prefs_->AddDisableReason(
2426 id, Extension::DISABLE_UNSUPPORTED_REQUIREMENT);
2427 // If the extension was disabled because of unsupported requirements but
2428 // now supports all requirements after an update and there are not other
2429 // disable reasons, enable it.
2430 } else if (extension_prefs_->GetDisableReasons(id) ==
2431 Extension::DISABLE_UNSUPPORTED_REQUIREMENT) {
2432 initial_enable = true;
2433 extension_prefs_->ClearDisableReasons(id);
2434 }
2435
[email protected]9f3c8532013-07-31 19:52:072436 if (blacklist_state == extensions::Blacklist::BLACKLISTED) {
2437 // Installation of a blacklisted extension can happen from sync, policy,
2438 // etc, where to maintain consistency we need to install it, just never
2439 // load it (see AddExtension). Usually it should be the job of callers to
2440 // incercept blacklisted extension earlier (e.g. CrxInstaller, before even
2441 // showing the install dialogue).
2442 extension_prefs()->AcknowledgeBlacklistedExtension(id);
2443 UMA_HISTOGRAM_ENUMERATION("ExtensionBlacklist.SilentInstall",
2444 extension->location(),
2445 Manifest::NUM_LOCATIONS);
2446 }
2447
[email protected]695b5712012-12-06 23:55:282448 if (!GetInstalledExtension(extension->id())) {
[email protected]07533022011-06-27 20:42:552449 UMA_HISTOGRAM_ENUMERATION("Extensions.InstallType",
2450 extension->GetType(), 100);
[email protected]69084dc2012-11-17 07:39:302451 UMA_HISTOGRAM_ENUMERATION("Extensions.InstallSource",
[email protected]1d5e58b2013-01-31 08:41:402452 extension->location(), Manifest::NUM_LOCATIONS);
[email protected]07533022011-06-27 20:42:552453 RecordPermissionMessagesHistogram(
2454 extension, "Extensions.Permissions_Install");
[email protected]69084dc2012-11-17 07:39:302455 } else {
2456 UMA_HISTOGRAM_ENUMERATION("Extensions.UpdateType",
2457 extension->GetType(), 100);
2458 UMA_HISTOGRAM_ENUMERATION("Extensions.UpdateSource",
[email protected]1d5e58b2013-01-31 08:41:402459 extension->location(), Manifest::NUM_LOCATIONS);
[email protected]07533022011-06-27 20:42:552460 }
2461
[email protected]a39921b42012-02-28 03:42:542462 // Certain extension locations are specific enough that we can
2463 // auto-acknowledge any extension that came from one of them.
[email protected]9bb691632013-09-26 18:50:122464 if (Manifest::IsPolicyLocation(extension->location()))
[email protected]a39921b42012-02-28 03:42:542465 AcknowledgeExternalExtension(extension->id());
[email protected]399583b2012-12-11 09:33:422466 const Extension::State initial_state =
2467 initial_enable ? Extension::ENABLED : Extension::DISABLED;
[email protected]e7aa7b7e2012-11-27 04:51:222468 if (ShouldDelayExtensionUpdate(id, wait_for_idle)) {
[email protected]9f3c8532013-07-31 19:52:072469 extension_prefs_->SetDelayedInstallInfo(
2470 extension,
2471 initial_state,
2472 blacklist_state,
2473 extensions::ExtensionPrefs::DELAY_REASON_WAIT_FOR_IDLE,
2474 page_ordinal);
[email protected]0db124b02012-11-07 04:55:052475
2476 // Transfer ownership of |extension|.
[email protected]9f4e4f082013-06-21 07:11:192477 delayed_installs_.Insert(extension);
[email protected]0db124b02012-11-07 04:55:052478
2479 // Notify extension of available update.
2480 extensions::RuntimeEventRouter::DispatchOnUpdateAvailableEvent(
2481 profile_, id, extension->manifest()->value());
[email protected]75bdcb872013-03-13 00:41:452482
2483 // Notify observers that app update is available.
2484 FOR_EACH_OBSERVER(extensions::UpdateObserver, update_observers_,
2485 OnAppUpdateAvailable(extension->id()));
[email protected]0db124b02012-11-07 04:55:052486 return;
2487 }
2488
[email protected]9f4e4f082013-06-21 07:11:192489 ImportStatus status = SatisfyImports(extension);
2490 if (installs_delayed_for_gc()) {
[email protected]9f3c8532013-07-31 19:52:072491 extension_prefs_->SetDelayedInstallInfo(
2492 extension,
2493 initial_state,
2494 blacklist_state,
2495 extensions::ExtensionPrefs::DELAY_REASON_GC,
2496 page_ordinal);
[email protected]399583b2012-12-11 09:33:422497 delayed_installs_.Insert(extension);
[email protected]9f4e4f082013-06-21 07:11:192498 } else if (status != IMPORT_STATUS_OK) {
2499 if (status == IMPORT_STATUS_UNSATISFIED) {
[email protected]9f3c8532013-07-31 19:52:072500 extension_prefs_->SetDelayedInstallInfo(
2501 extension,
2502 initial_state,
2503 blacklist_state,
[email protected]9f4e4f082013-06-21 07:11:192504 extensions::ExtensionPrefs::DELAY_REASON_WAIT_FOR_IMPORTS,
2505 page_ordinal);
2506 delayed_installs_.Insert(extension);
2507 }
[email protected]399583b2012-12-11 09:33:422508 } else {
[email protected]9f3c8532013-07-31 19:52:072509 AddNewOrUpdatedExtension(extension,
2510 initial_state,
2511 blacklist_state,
2512 page_ordinal);
[email protected]399583b2012-12-11 09:33:422513 }
[email protected]8c484b742012-11-29 06:05:362514}
2515
2516void ExtensionService::AddNewOrUpdatedExtension(
2517 const Extension* extension,
[email protected]399583b2012-12-11 09:33:422518 Extension::State initial_state,
[email protected]9f3c8532013-07-31 19:52:072519 extensions::Blacklist::BlacklistState blacklist_state,
[email protected]399583b2012-12-11 09:33:422520 const syncer::StringOrdinal& page_ordinal) {
[email protected]8c484b742012-11-29 06:05:362521 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]9f3c8532013-07-31 19:52:072522 extension_prefs_->OnExtensionInstalled(extension,
2523 initial_state,
2524 blacklist_state,
2525 page_ordinal);
[email protected]9e9c1d12013-07-31 01:58:122526 delayed_installs_.Remove(extension->id());
[email protected]6f6101832012-11-27 22:10:482527 FinishInstallation(extension);
2528}
2529
2530void ExtensionService::MaybeFinishDelayedInstallation(
2531 const std::string& extension_id) {
[email protected]9f4e4f082013-06-21 07:11:192532 // Check if the extension already got installed.
2533 if (!delayed_installs_.Contains(extension_id))
[email protected]6f6101832012-11-27 22:10:482534 return;
[email protected]9f4e4f082013-06-21 07:11:192535 extensions::ExtensionPrefs::DelayReason reason =
2536 extension_prefs_->GetDelayedInstallReason(extension_id);
2537
2538 // Check if the extension is idle. DELAY_REASON_NONE is used for older
2539 // preferences files that will not have set this field but it was previously
2540 // only used for idle updates.
2541 if ((reason == extensions::ExtensionPrefs::DELAY_REASON_WAIT_FOR_IDLE ||
2542 reason == extensions::ExtensionPrefs::DELAY_REASON_NONE) &&
2543 is_ready() && !IsExtensionIdle(extension_id))
[email protected]6f6101832012-11-27 22:10:482544 return;
2545
[email protected]9f4e4f082013-06-21 07:11:192546 const Extension* extension = delayed_installs_.GetByID(extension_id);
2547 if (reason == extensions::ExtensionPrefs::DELAY_REASON_WAIT_FOR_IMPORTS) {
2548 ImportStatus status = SatisfyImports(extension);
2549 if (status != IMPORT_STATUS_OK) {
2550 if (status == IMPORT_STATUS_UNRECOVERABLE) {
2551 delayed_installs_.Remove(extension_id);
2552 // Make sure no version of the extension is actually installed, (i.e.,
2553 // that this delayed install was not an update).
2554 CHECK(!extension_prefs_->GetInstalledExtensionInfo(extension_id).get());
2555 extension_prefs_->DeleteExtensionPrefs(extension_id);
2556 }
2557 return;
2558 }
2559 }
2560
[email protected]6f6101832012-11-27 22:10:482561 FinishDelayedInstallation(extension_id);
2562}
2563
2564void ExtensionService::FinishDelayedInstallation(
2565 const std::string& extension_id) {
2566 scoped_refptr<const Extension> extension(
2567 GetPendingExtensionUpdate(extension_id));
[email protected]dc24976f2013-06-02 21:15:092568 CHECK(extension.get());
[email protected]9f4e4f082013-06-21 07:11:192569 delayed_installs_.Remove(extension_id);
[email protected]6f6101832012-11-27 22:10:482570
[email protected]399583b2012-12-11 09:33:422571 if (!extension_prefs_->FinishDelayedInstallInfo(extension_id))
[email protected]6f6101832012-11-27 22:10:482572 NOTREACHED();
2573
[email protected]dc24976f2013-06-02 21:15:092574 FinishInstallation(extension.get());
[email protected]6f6101832012-11-27 22:10:482575}
2576
2577void ExtensionService::FinishInstallation(const Extension* extension) {
[email protected]e7554c3f2013-05-29 00:36:562578 const extensions::Extension* existing_extension =
2579 GetInstalledExtension(extension->id());
2580 bool is_update = false;
2581 std::string old_name;
2582 if (existing_extension) {
2583 is_update = true;
2584 old_name = existing_extension->name();
2585 }
2586 extensions::InstalledExtensionInfo details(extension, is_update, old_name);
[email protected]fcb58a862012-05-01 01:03:152587 content::NotificationService::current()->Notify(
2588 chrome::NOTIFICATION_EXTENSION_INSTALLED,
2589 content::Source<Profile>(profile_),
[email protected]41bb80bd2013-05-03 10:56:022590 content::Details<const extensions::InstalledExtensionInfo>(&details));
[email protected]fcb58a862012-05-01 01:03:152591
[email protected]d96eb512012-11-01 23:44:082592 bool unacknowledged_external = IsUnacknowledgedExternalExtension(extension);
[email protected]41070e8d2012-10-24 01:34:362593
[email protected]399583b2012-12-11 09:33:422594 // Unpacked extensions default to allowing file access, but if that has been
2595 // overridden, don't reset the value.
[email protected]1d5e58b2013-01-31 08:41:402596 if (Manifest::ShouldAlwaysAllowFileAccess(extension->location()) &&
[email protected]399583b2012-12-11 09:33:422597 !extension_prefs_->HasAllowFileAccessSetting(extension->id())) {
2598 extension_prefs_->SetAllowFileAccess(extension->id(), true);
2599 }
2600
[email protected]6f6101832012-11-27 22:10:482601 AddExtension(extension);
[email protected]612a1cb12012-10-17 13:18:032602
2603 // If this is a new external extension that was disabled, alert the user
[email protected]d96eb512012-11-01 23:44:082604 // so he can reenable it. We do this last so that it has already been
2605 // added to our list of extensions.
[email protected]3e3fafbb2013-08-17 13:33:162606 if (unacknowledged_external && !is_update) {
[email protected]612a1cb12012-10-17 13:18:032607 UpdateExternalExtensionAlert();
[email protected]d96eb512012-11-01 23:44:082608 UMA_HISTOGRAM_ENUMERATION("Extensions.ExternalExtensionEvent",
2609 EXTERNAL_EXTENSION_INSTALLED,
2610 EXTERNAL_EXTENSION_BUCKET_BOUNDARY);
[email protected]446e37e2013-08-07 00:30:022611 if (extensions::ManifestURL::UpdatesFromGallery(extension)) {
2612 UMA_HISTOGRAM_ENUMERATION("Extensions.ExternalExtensionEventWebstore",
2613 EXTERNAL_EXTENSION_INSTALLED,
2614 EXTERNAL_EXTENSION_BUCKET_BOUNDARY);
2615 } else {
2616 UMA_HISTOGRAM_ENUMERATION("Extensions.ExternalExtensionEventNonWebstore",
2617 EXTERNAL_EXTENSION_INSTALLED,
2618 EXTERNAL_EXTENSION_BUCKET_BOUNDARY);
2619 }
[email protected]d96eb512012-11-01 23:44:082620 }
[email protected]9f4e4f082013-06-21 07:11:192621
2622 // Check extensions that may have been delayed only because this shared module
2623 // was not available.
2624 if (SharedModuleInfo::IsSharedModule(extension)) {
2625 MaybeFinishDelayedInstallations();
2626 }
[email protected]4a190632009-05-09 01:07:422627}
2628
[email protected]76b65442012-11-17 14:11:482629const Extension* ExtensionService::GetPendingExtensionUpdate(
2630 const std::string& id) const {
[email protected]9f4e4f082013-06-21 07:11:192631 return delayed_installs_.GetByID(id);
[email protected]76b65442012-11-17 14:11:482632}
2633
[email protected]bb7f40952011-01-13 00:21:202634void ExtensionService::TrackTerminatedExtension(const Extension* extension) {
[email protected]84df8332011-12-06 18:22:462635 if (!terminated_extensions_.Contains(extension->id()))
2636 terminated_extensions_.Insert(make_scoped_refptr(extension));
[email protected]fa2416f2011-05-03 08:41:202637
[email protected]b3f7fe22011-11-11 19:27:562638 UnloadExtension(extension->id(), extension_misc::UNLOAD_REASON_TERMINATE);
[email protected]bb7f40952011-01-13 00:21:202639}
2640
2641void ExtensionService::UntrackTerminatedExtension(const std::string& id) {
[email protected]fa2416f2011-05-03 08:41:202642 std::string lowercase_id = StringToLowerASCII(id);
[email protected]60a174a2013-08-02 20:29:282643 const Extension* extension = terminated_extensions_.GetByID(lowercase_id);
[email protected]84df8332011-12-06 18:22:462644 terminated_extensions_.Remove(lowercase_id);
[email protected]fb789532013-08-27 02:40:212645 if (extension) {
2646 content::NotificationService::current()->Notify(
2647 chrome::NOTIFICATION_EXTENSION_REMOVED,
2648 content::Source<Profile>(profile_),
2649 content::Details<const Extension>(extension));
2650 }
[email protected]bb7f40952011-01-13 00:21:202651}
2652
[email protected]0dfe05c2011-02-23 23:03:362653const Extension* ExtensionService::GetTerminatedExtension(
[email protected]8001df22011-04-28 19:59:472654 const std::string& id) const {
[email protected]695b5712012-12-06 23:55:282655 return GetExtensionById(id, INCLUDE_TERMINATED);
[email protected]8001df22011-04-28 19:59:472656}
2657
2658const Extension* ExtensionService::GetInstalledExtension(
2659 const std::string& id) const {
[email protected]695b5712012-12-06 23:55:282660 int include_mask = INCLUDE_ENABLED |
2661 INCLUDE_DISABLED |
2662 INCLUDE_TERMINATED |
2663 INCLUDE_BLACKLISTED;
2664 return GetExtensionById(id, include_mask);
[email protected]0dfe05c2011-02-23 23:03:362665}
2666
[email protected]eaa7dd182010-12-14 11:09:002667bool ExtensionService::ExtensionBindingsAllowed(const GURL& url) {
[email protected]615d88f2011-12-13 01:47:442668 // Allow bindings for all packaged extensions and component hosted apps.
[email protected]be9915fb2013-07-18 09:28:552669 const Extension* extension = extensions_.GetExtensionOrAppByURL(url);
[email protected]615d88f2011-12-13 01:47:442670 return extension && (!extension->is_hosted_app() ||
[email protected]1d5e58b2013-01-31 08:41:402671 extension->location() == Manifest::COMPONENT);
[email protected]6d2e60bd2010-06-03 22:37:392672}
2673
[email protected]4d007b312012-10-17 03:00:482674bool ExtensionService::ShouldBlockUrlInBrowserTab(GURL* url) {
[email protected]be9915fb2013-07-18 09:28:552675 const Extension* extension = extensions_.GetExtensionOrAppByURL(*url);
[email protected]4d007b312012-10-17 03:00:482676 if (extension && extension->is_platform_app()) {
2677 *url = GURL(chrome::kExtensionInvalidRequestURL);
2678 return true;
2679 }
2680
2681 return false;
2682}
2683
[email protected]9060d8b02012-01-13 02:14:302684bool ExtensionService::OnExternalExtensionFileFound(
[email protected]8ef78fd2010-08-19 17:14:322685 const std::string& id,
[email protected]8e4560b62011-01-14 10:09:142686 const Version* version,
[email protected]650b2d52013-02-10 03:41:452687 const base::FilePath& path,
[email protected]1d5e58b2013-01-31 08:41:402688 Manifest::Location location,
[email protected]47fc70c2011-12-06 07:29:512689 int creation_flags,
2690 bool mark_acknowledged) {
[email protected]ab22ba42011-01-14 16:36:382691 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
2692 CHECK(Extension::IdIsValid(id));
[email protected]79c833b52011-04-05 18:31:012693 if (extension_prefs_->IsExternalExtensionUninstalled(id))
[email protected]9060d8b02012-01-13 02:14:302694 return false;
[email protected]a8af9fdb2010-10-28 21:52:202695
[email protected]7577a5c52009-07-30 06:21:582696 // Before even bothering to unpack, check and see if we already have this
[email protected]4c967932009-07-31 01:15:492697 // version. This is important because these extensions are going to get
[email protected]7577a5c52009-07-30 06:21:582698 // installed on every startup.
[email protected]9adb9692010-10-29 23:14:022699 const Extension* existing = GetExtensionById(id, true);
[email protected]910f72ce2012-08-24 01:38:352700
[email protected]7577a5c52009-07-30 06:21:582701 if (existing) {
[email protected]910f72ce2012-08-24 01:38:352702 // The default apps will have the location set as INTERNAL. Since older
2703 // default apps are installed as EXTERNAL, we override them. However, if the
2704 // app is already installed as internal, then do the version check.
[email protected]31bb5ee62012-09-12 22:58:402705 // TODO(grv) : Remove after Q1-2013.
[email protected]910f72ce2012-08-24 01:38:352706 bool is_default_apps_migration =
[email protected]1d5e58b2013-01-31 08:41:402707 (location == Manifest::INTERNAL &&
2708 Manifest::IsExternalLocation(existing->location()));
[email protected]910f72ce2012-08-24 01:38:352709
2710 if (!is_default_apps_migration) {
2711 DCHECK(version);
2712
2713 switch (existing->version()->CompareTo(*version)) {
2714 case -1: // existing version is older, we should upgrade
2715 break;
2716 case 0: // existing version is same, do nothing
2717 return false;
2718 case 1: // existing version is newer, uh-oh
2719 LOG(WARNING) << "Found external version of extension " << id
2720 << "that is older than current version. Current version "
2721 << "is: " << existing->VersionString() << ". New "
2722 << "version is: " << version->GetString()
2723 << ". Keeping current version.";
2724 return false;
2725 }
[email protected]7577a5c52009-07-30 06:21:582726 }
2727 }
2728
[email protected]9060d8b02012-01-13 02:14:302729 // If the extension is already pending, don't start an install.
[email protected]e3987852012-05-04 10:06:302730 if (!pending_extension_manager()->AddFromExternalFile(
[email protected]464213a2013-10-15 01:06:482731 id, location, *version, creation_flags, mark_acknowledged)) {
[email protected]9060d8b02012-01-13 02:14:302732 return false;
[email protected]e3987852012-05-04 10:06:302733 }
[email protected]9c635f22010-12-02 09:36:362734
[email protected]14908b72011-04-20 06:54:362735 // no client (silent install)
[email protected]f8636f92013-08-09 21:02:372736 scoped_refptr<CrxInstaller> installer(CrxInstaller::CreateSilent(this));
[email protected]6dfbbf82010-03-12 23:09:162737 installer->set_install_source(location);
2738 installer->set_expected_id(id);
[email protected]cb0e50312011-05-09 15:03:072739 installer->set_expected_version(*version);
2740 installer->set_install_cause(extension_misc::INSTALL_CAUSE_EXTERNAL_FILE);
[email protected]1bf73cc32011-10-26 22:38:312741 installer->set_creation_flags(creation_flags);
[email protected]88e8ec9152013-01-17 04:05:182742#if defined(OS_CHROMEOS)
2743 extensions::InstallLimiter::Get(profile_)->Add(installer, path);
2744#else
[email protected]6dfbbf82010-03-12 23:09:162745 installer->InstallCrx(path);
[email protected]88e8ec9152013-01-17 04:05:182746#endif
[email protected]47fc70c2011-12-06 07:29:512747
2748 // Depending on the source, a new external extension might not need a user
2749 // notification on installation. For such extensions, mark them acknowledged
2750 // now to suppress the notification.
2751 if (mark_acknowledged)
2752 AcknowledgeExternalExtension(id);
[email protected]9060d8b02012-01-13 02:14:302753
2754 return true;
[email protected]7577a5c52009-07-30 06:21:582755}
2756
[email protected]eaa7dd182010-12-14 11:09:002757void ExtensionService::ReportExtensionLoadError(
[email protected]650b2d52013-02-10 03:41:452758 const base::FilePath& extension_path,
[email protected]d11c8e92009-10-20 23:26:402759 const std::string &error,
[email protected]d11c8e92009-10-20 23:26:402760 bool be_noisy) {
[email protected]d8c8f25f2011-11-02 18:18:012761 content::NotificationService::current()->Notify(
2762 chrome::NOTIFICATION_EXTENSION_LOAD_ERROR,
2763 content::Source<Profile>(profile_),
2764 content::Details<const std::string>(&error));
[email protected]d11c8e92009-10-20 23:26:402765
[email protected]8a205c02011-02-04 20:41:332766 std::string path_str = UTF16ToUTF8(extension_path.LossyDisplayName());
[email protected]438afb12012-07-05 03:18:212767 string16 message = UTF8ToUTF16(base::StringPrintf(
[email protected]18d4b6c2010-09-21 03:21:042768 "Could not load extension from '%s'. %s",
[email protected]fc670822011-12-17 09:33:492769 path_str.c_str(), error.c_str()));
[email protected]d11c8e92009-10-20 23:26:402770 ExtensionErrorReporter::GetInstance()->ReportError(message, be_noisy);
2771}
2772
[email protected]eaa7dd182010-12-14 11:09:002773void ExtensionService::DidCreateRenderViewForBackgroundPage(
[email protected]3a1dc572012-07-31 22:25:132774 extensions::ExtensionHost* host) {
[email protected]406027c02010-09-27 08:03:182775 OrphanedDevTools::iterator iter =
[email protected]2d2f6cfc2011-05-06 21:09:332776 orphaned_dev_tools_.find(host->extension_id());
[email protected]406027c02010-09-27 08:03:182777 if (iter == orphaned_dev_tools_.end())
2778 return;
2779
[email protected]04ea1bb2013-07-10 09:26:092780 iter->second->ConnectRenderViewHost(host->render_view_host());
[email protected]406027c02010-09-27 08:03:182781 orphaned_dev_tools_.erase(iter);
2782}
2783
[email protected]432115822011-07-10 15:52:272784void ExtensionService::Observe(int type,
[email protected]6c2381d2011-10-19 02:52:532785 const content::NotificationSource& source,
2786 const content::NotificationDetails& details) {
[email protected]432115822011-07-10 15:52:272787 switch (type) {
[email protected]3c4abc82012-10-22 22:25:542788 case chrome::NOTIFICATION_APP_TERMINATING:
2789 // Shutdown has started. Don't start any more extension installs.
2790 // (We cannot use ExtensionService::Shutdown() for this because it
2791 // happens too late in browser teardown.)
2792 browser_terminating_ = true;
2793 break;
[email protected]432115822011-07-10 15:52:272794 case chrome::NOTIFICATION_EXTENSION_PROCESS_TERMINATED: {
[email protected]6c2381d2011-10-19 02:52:532795 if (profile_ !=
2796 content::Source<Profile>(source).ptr()->GetOriginalProfile()) {
[email protected]bc535ee52010-08-31 18:40:322797 break;
[email protected]6c2381d2011-10-19 02:52:532798 }
[email protected]a4ed6282009-12-14 20:51:162799
[email protected]3a1dc572012-07-31 22:25:132800 extensions::ExtensionHost* host =
2801 content::Details<extensions::ExtensionHost>(details).ptr();
[email protected]f128af42010-08-05 18:05:262802
[email protected]fa2416f2011-05-03 08:41:202803 // Mark the extension as terminated and Unload it. We want it to
2804 // be in a consistent state: either fully working or not loaded
2805 // at all, but never half-crashed. We do it in a PostTask so
2806 // that other handlers of this notification will still have
2807 // access to the Extension and ExtensionHost.
[email protected]b3a25092013-05-28 22:08:162808 base::MessageLoop::current()->PostTask(
[email protected]14908b72011-04-20 06:54:362809 FROM_HERE,
[email protected]53612e82011-10-18 18:00:362810 base::Bind(
[email protected]fa2416f2011-05-03 08:41:202811 &ExtensionService::TrackTerminatedExtension,
[email protected]d8c8f25f2011-11-02 18:18:012812 AsWeakPtr(),
[email protected]fa2416f2011-05-03 08:41:202813 host->extension()));
[email protected]31f77262009-12-02 20:48:532814 break;
2815 }
[email protected]432115822011-07-10 15:52:272816 case content::NOTIFICATION_RENDERER_PROCESS_CREATED: {
[email protected]f3b1a082011-11-18 00:34:302817 content::RenderProcessHost* process =
2818 content::Source<content::RenderProcessHost>(source).ptr();
[email protected]fc30ef082011-08-18 04:07:192819 Profile* host_profile =
[email protected]f3b1a082011-11-18 00:34:302820 Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]fc30ef082011-08-18 04:07:192821 if (!profile_->IsSameProfile(host_profile->GetOriginalProfile()))
2822 break;
2823
[email protected]15397b42012-05-16 23:56:062824 // Extensions need to know the channel for API restrictions.
2825 process->Send(new ExtensionMsg_SetChannel(
[email protected]15d4d2d2013-08-09 06:49:032826 extensions::GetCurrentChannel()));
[email protected]15397b42012-05-16 23:56:062827
[email protected]4941fe92013-06-13 23:21:012828 // Platform apps need to know the system font.
2829 scoped_ptr<base::DictionaryValue> fonts(new base::DictionaryValue);
2830 webui::SetFontAndTextDirection(fonts.get());
2831 std::string font_family, font_size;
2832 fonts->GetString("fontfamily", &font_family);
2833 fonts->GetString("fontsize", &font_size);
2834 process->Send(new ExtensionMsg_SetSystemFont(
2835 font_family, font_size));
2836
[email protected]77a6970c2011-04-23 16:58:562837 // Valid extension function names, used to setup bindings in renderer.
2838 std::vector<std::string> function_names;
2839 ExtensionFunctionDispatcher::GetAllFunctionNames(&function_names);
2840 process->Send(new ExtensionMsg_SetFunctionNames(function_names));
[email protected]31f77262009-12-02 20:48:532841
[email protected]77a6970c2011-04-23 16:58:562842 // Scripting whitelist. This is modified by tests and must be communicated
2843 // to renderers.
2844 process->Send(new ExtensionMsg_SetScriptingWhitelist(
2845 *Extension::GetScriptingWhitelist()));
2846
2847 // Loaded extensions.
[email protected]9776e82e2011-11-15 02:17:532848 std::vector<ExtensionMsg_Loaded_Params> loaded_extensions;
[email protected]84df8332011-12-06 18:22:462849 for (ExtensionSet::const_iterator iter = extensions_.begin();
2850 iter != extensions_.end(); ++iter) {
[email protected]19647262011-12-16 09:57:492851 // Renderers don't need to know about themes.
2852 if (!(*iter)->is_theme())
[email protected]cadac622013-06-11 16:46:362853 loaded_extensions.push_back(ExtensionMsg_Loaded_Params(iter->get()));
[email protected]77a6970c2011-04-23 16:58:562854 }
[email protected]9776e82e2011-11-15 02:17:532855 process->Send(new ExtensionMsg_Loaded(loaded_extensions));
[email protected]77a6970c2011-04-23 16:58:562856 break;
2857 }
[email protected]432115822011-07-10 15:52:272858 case content::NOTIFICATION_RENDERER_PROCESS_TERMINATED: {
[email protected]f3b1a082011-11-18 00:34:302859 content::RenderProcessHost* process =
2860 content::Source<content::RenderProcessHost>(source).ptr();
[email protected]fc30ef082011-08-18 04:07:192861 Profile* host_profile =
[email protected]f3b1a082011-11-18 00:34:302862 Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]fc30ef082011-08-18 04:07:192863 if (!profile_->IsSameProfile(host_profile->GetOriginalProfile()))
2864 break;
2865
[email protected]6bc04fd82011-12-04 02:29:352866 process_map_.RemoveAllFromProcess(process->GetID());
[email protected]6f371442011-11-09 06:45:462867 BrowserThread::PostTask(
2868 BrowserThread::IO, FROM_HERE,
2869 base::Bind(&ExtensionInfoMap::UnregisterAllExtensionsInProcess,
[email protected]31d8f5f22012-04-02 15:22:082870 system_->info_map(),
[email protected]f3b1a082011-11-18 00:34:302871 process->GetID()));
[email protected]da5683db2011-04-23 17:12:212872 break;
2873 }
[email protected]0db124b02012-11-07 04:55:052874 case chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED: {
2875 extensions::ExtensionHost* host =
2876 content::Details<extensions::ExtensionHost>(details).ptr();
[email protected]e7aa7b7e2012-11-27 04:51:222877 std::string extension_id = host->extension_id();
[email protected]9f4e4f082013-06-21 07:11:192878 if (delayed_installs_.Contains(extension_id)) {
[email protected]e7aa7b7e2012-11-27 04:51:222879 // We were waiting for this extension to become idle, it now might have,
2880 // so maybe finish installation.
[email protected]b3a25092013-05-28 22:08:162881 base::MessageLoop::current()->PostDelayedTask(
[email protected]0db124b02012-11-07 04:55:052882 FROM_HERE,
[email protected]6f6101832012-11-27 22:10:482883 base::Bind(&ExtensionService::MaybeFinishDelayedInstallation,
[email protected]0db124b02012-11-07 04:55:052884 AsWeakPtr(), extension_id),
2885 base::TimeDelta::FromSeconds(kUpdateIdleDelay));
[email protected]0db124b02012-11-07 04:55:052886 }
2887 break;
2888 }
[email protected]92dd8d92013-02-26 00:41:082889 case chrome::NOTIFICATION_UPGRADE_RECOMMENDED: {
2890 // Notify extensions that chrome update is available.
2891 extensions::RuntimeEventRouter::DispatchOnBrowserUpdateAvailableEvent(
2892 profile_);
[email protected]75bdcb872013-03-13 00:41:452893
2894 // Notify observers that chrome update is available.
2895 FOR_EACH_OBSERVER(extensions::UpdateObserver, update_observers_,
2896 OnChromeUpdateAvailable());
[email protected]92dd8d92013-02-26 00:41:082897 break;
2898 }
[email protected]aa96d3a2010-08-21 08:45:252899
[email protected]4814b512009-11-07 00:12:292900 default:
2901 NOTREACHED() << "Unexpected notification type.";
2902 }
2903}
2904
[email protected]90bb38d2012-11-14 18:36:032905void ExtensionService::OnExtensionInstallPrefChanged() {
[email protected]a6a7ced2012-11-01 17:24:182906 IdentifyAlertableExtensions();
2907 CheckManagementPolicy();
2908}
2909
[email protected]eaa7dd182010-12-14 11:09:002910bool ExtensionService::HasApps() const {
[email protected]ec5b50d2010-10-09 16:35:182911 return !GetAppIds().empty();
2912}
[email protected]377011d2010-07-20 04:18:502913
[email protected]eaa7dd182010-12-14 11:09:002914ExtensionIdSet ExtensionService::GetAppIds() const {
[email protected]ec5b50d2010-10-09 16:35:182915 ExtensionIdSet result;
[email protected]84df8332011-12-06 18:22:462916 for (ExtensionSet::const_iterator it = extensions_.begin();
[email protected]377011d2010-07-20 04:18:502917 it != extensions_.end(); ++it) {
[email protected]1d5e58b2013-01-31 08:41:402918 if ((*it)->is_app() && (*it)->location() != Manifest::COMPONENT)
[email protected]ec5b50d2010-10-09 16:35:182919 result.insert((*it)->id());
[email protected]377011d2010-07-20 04:18:502920 }
2921
[email protected]ec5b50d2010-10-09 16:35:182922 return result;
[email protected]377011d2010-07-20 04:18:502923}
[email protected]d7e9a862010-11-03 21:57:492924
[email protected]dc9a74f72012-08-17 18:07:212925bool ExtensionService::IsBackgroundPageReady(const Extension* extension) const {
[email protected]9367eabc2013-03-01 01:29:292926 if (!extensions::BackgroundInfo::HasPersistentBackgroundPage(extension))
[email protected]dc9a74f72012-08-17 18:07:212927 return true;
2928 ExtensionRuntimeDataMap::const_iterator it =
2929 extension_runtime_data_.find(extension->id());
2930 return it == extension_runtime_data_.end() ? false :
2931 it->second.background_page_ready;
[email protected]d7e9a862010-11-03 21:57:492932}
2933
[email protected]eaa7dd182010-12-14 11:09:002934void ExtensionService::SetBackgroundPageReady(const Extension* extension) {
[email protected]9367eabc2013-03-01 01:29:292935 DCHECK(extensions::BackgroundInfo::HasBackgroundPage(extension));
[email protected]d7e9a862010-11-03 21:57:492936 extension_runtime_data_[extension->id()].background_page_ready = true;
[email protected]ad50def52011-10-19 23:17:072937 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:272938 chrome::NOTIFICATION_EXTENSION_BACKGROUND_PAGE_READY,
[email protected]6c2381d2011-10-19 02:52:532939 content::Source<const Extension>(extension),
[email protected]ad50def52011-10-19 23:17:072940 content::NotificationService::NoDetails());
[email protected]d7e9a862010-11-03 21:57:492941}
2942
[email protected]dc9a74f72012-08-17 18:07:212943bool ExtensionService::IsBeingUpgraded(const Extension* extension) const {
2944 ExtensionRuntimeDataMap::const_iterator it =
2945 extension_runtime_data_.find(extension->id());
2946 return it == extension_runtime_data_.end() ? false :
2947 it->second.being_upgraded;
[email protected]d7e9a862010-11-03 21:57:492948}
2949
[email protected]eaa7dd182010-12-14 11:09:002950void ExtensionService::SetBeingUpgraded(const Extension* extension,
[email protected]b914e2952013-04-26 07:10:032951 bool value) {
[email protected]d7e9a862010-11-03 21:57:492952 extension_runtime_data_[extension->id()].being_upgraded = value;
2953}
[email protected]1bead0712010-11-27 17:41:532954
[email protected]e178ad92013-06-28 02:29:252955bool ExtensionService::IsBeingReloaded(
2956 const std::string& extension_id) const {
2957 return ContainsKey(extensions_being_reloaded_, extension_id);
2958}
2959
2960void ExtensionService::SetBeingReloaded(const std::string& extension_id,
[email protected]5e7015c2013-07-23 23:29:432961 bool isBeingReloaded) {
2962 if (isBeingReloaded)
[email protected]e178ad92013-06-28 02:29:252963 extensions_being_reloaded_.insert(extension_id);
[email protected]5e7015c2013-07-23 23:29:432964 else
[email protected]e178ad92013-06-28 02:29:252965 extensions_being_reloaded_.erase(extension_id);
[email protected]e178ad92013-06-28 02:29:252966}
2967
[email protected]dc9a74f72012-08-17 18:07:212968bool ExtensionService::HasUsedWebRequest(const Extension* extension) const {
2969 ExtensionRuntimeDataMap::const_iterator it =
2970 extension_runtime_data_.find(extension->id());
2971 return it == extension_runtime_data_.end() ? false :
2972 it->second.has_used_webrequest;
[email protected]39a5b532011-10-22 01:47:072973}
2974
2975void ExtensionService::SetHasUsedWebRequest(const Extension* extension,
2976 bool value) {
2977 extension_runtime_data_[extension->id()].has_used_webrequest = value;
2978}
2979
[email protected]612a1cb12012-10-17 13:18:032980bool ExtensionService::ShouldEnableOnInstall(const Extension* extension) {
2981 // Extensions installed by policy can't be disabled. So even if a previous
2982 // installation disabled the extension, make sure it is now enabled.
2983 if (system_->management_policy()->MustRemainEnabled(extension, NULL))
2984 return true;
2985
2986 if (extension_prefs_->IsExtensionDisabled(extension->id()))
2987 return false;
2988
[email protected]41070e8d2012-10-24 01:34:362989 if (FeatureSwitch::prompt_for_external_extensions()->IsEnabled()) {
[email protected]612a1cb12012-10-17 13:18:032990 // External extensions are initially disabled. We prompt the user before
[email protected]2c495c42013-01-04 21:49:542991 // enabling them. Hosted apps are excepted because they are not dangerous
2992 // (they need to be launched by the user anyway).
[email protected]1d5e58b2013-01-31 08:41:402993 if (extension->GetType() != Manifest::TYPE_HOSTED_APP &&
2994 Manifest::IsExternalLocation(extension->location()) &&
[email protected]612a1cb12012-10-17 13:18:032995 !extension_prefs_->IsExternalExtensionAcknowledged(extension->id())) {
2996 return false;
2997 }
2998 }
[email protected]612a1cb12012-10-17 13:18:032999
3000 return true;
3001}
[email protected]0db124b02012-11-07 04:55:053002
3003bool ExtensionService::IsExtensionIdle(const std::string& extension_id) const {
[email protected]d9a61e12012-11-14 02:43:473004 ExtensionProcessManager* process_manager = system_->process_manager();
[email protected]fc332ae2012-11-14 20:17:333005 DCHECK(process_manager);
[email protected]0db124b02012-11-07 04:55:053006 extensions::ExtensionHost* host =
[email protected]d9a61e12012-11-14 02:43:473007 process_manager->GetBackgroundHostForExtension(extension_id);
[email protected]e7aa7b7e2012-11-27 04:51:223008 if (host)
3009 return false;
3010 return process_manager->GetRenderViewHostsForExtension(extension_id).empty();
3011}
3012
3013bool ExtensionService::ShouldDelayExtensionUpdate(
3014 const std::string& extension_id,
3015 bool wait_for_idle) const {
3016 const char kOnUpdateAvailableEvent[] = "runtime.onUpdateAvailable";
3017
3018 // If delayed updates are globally disabled, or just for this extension,
3019 // don't delay.
3020 if (!install_updates_when_idle_ || !wait_for_idle)
3021 return false;
3022
[email protected]695b5712012-12-06 23:55:283023 const Extension* old = GetInstalledExtension(extension_id);
[email protected]e7aa7b7e2012-11-27 04:51:223024 // If there is no old extension, this is not an update, so don't delay.
3025 if (!old)
3026 return false;
3027
[email protected]9367eabc2013-03-01 01:29:293028 if (extensions::BackgroundInfo::HasPersistentBackgroundPage(old)) {
[email protected]e7aa7b7e2012-11-27 04:51:223029 // Delay installation if the extension listens for the onUpdateAvailable
3030 // event.
3031 return system_->event_router()->ExtensionHasEventListener(
3032 extension_id, kOnUpdateAvailableEvent);
3033 } else {
3034 // Delay installation if the extension is not idle.
3035 return !IsExtensionIdle(extension_id);
3036 }
[email protected]0db124b02012-11-07 04:55:053037}
[email protected]fdd679b2012-11-15 20:49:393038
[email protected]399583b2012-12-11 09:33:423039void ExtensionService::GarbageCollectIsolatedStorage() {
[email protected]650b2d52013-02-10 03:41:453040 scoped_ptr<base::hash_set<base::FilePath> > active_paths(
3041 new base::hash_set<base::FilePath>());
[email protected]399583b2012-12-11 09:33:423042 for (ExtensionSet::const_iterator it = extensions_.begin();
3043 it != extensions_.end(); ++it) {
[email protected]cadac622013-06-11 16:46:363044 if (extensions::AppIsolationInfo::HasIsolatedStorage(it->get())) {
3045 active_paths->insert(BrowserContext::GetStoragePartitionForSite(
3046 profile_, GetSiteForExtensionId((*it)->id()))->GetPath());
[email protected]399583b2012-12-11 09:33:423047 }
3048 }
3049
[email protected]9f4e4f082013-06-21 07:11:193050 DCHECK(!installs_delayed_for_gc());
3051 set_installs_delayed_for_gc(true);
[email protected]399583b2012-12-11 09:33:423052 BrowserContext::GarbageCollectStoragePartitions(
3053 profile_, active_paths.Pass(),
3054 base::Bind(&ExtensionService::OnGarbageCollectIsolatedStorageFinished,
3055 AsWeakPtr()));
3056}
3057
3058void ExtensionService::OnGarbageCollectIsolatedStorageFinished() {
[email protected]9f4e4f082013-06-21 07:11:193059 set_installs_delayed_for_gc(false);
3060 MaybeFinishDelayedInstallations();
3061}
3062
3063void ExtensionService::MaybeFinishDelayedInstallations() {
3064 std::vector<std::string> to_be_installed;
[email protected]399583b2012-12-11 09:33:423065 for (ExtensionSet::const_iterator it = delayed_installs_.begin();
3066 it != delayed_installs_.end();
3067 ++it) {
[email protected]9f4e4f082013-06-21 07:11:193068 to_be_installed.push_back((*it)->id());
[email protected]399583b2012-12-11 09:33:423069 }
[email protected]9f4e4f082013-06-21 07:11:193070 for (std::vector<std::string>::const_iterator it = to_be_installed.begin();
3071 it != to_be_installed.end();
[email protected]399583b2012-12-11 09:33:423072 ++it) {
[email protected]9f4e4f082013-06-21 07:11:193073 MaybeFinishDelayedInstallation(*it);
[email protected]399583b2012-12-11 09:33:423074 }
[email protected]399583b2012-12-11 09:33:423075}
3076
3077void ExtensionService::OnNeedsToGarbageCollectIsolatedStorage() {
3078 extension_prefs_->SetNeedsStorageGarbageCollection(true);
3079}
3080
[email protected]fdd679b2012-11-15 20:49:393081void ExtensionService::OnBlacklistUpdated() {
[email protected]695b5712012-12-06 23:55:283082 blacklist_->GetBlacklistedIDs(
3083 GenerateInstalledExtensionsSet()->GetIDs(),
[email protected]3f2a2fa2013-09-24 02:55:253084 base::Bind(&ExtensionService::ManageBlacklist, AsWeakPtr()));
[email protected]695b5712012-12-06 23:55:283085}
3086
[email protected]3f2a2fa2013-09-24 02:55:253087void ExtensionService::ManageBlacklist(const std::set<std::string>& updated) {
[email protected]695b5712012-12-06 23:55:283088 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
3089
[email protected]3f2a2fa2013-09-24 02:55:253090 std::set<std::string> before = blacklisted_extensions_.GetIDs();
[email protected]16bf7ba72013-08-23 11:52:543091 std::set<std::string> no_longer_blacklisted =
[email protected]3f2a2fa2013-09-24 02:55:253092 base::STLSetDifference<std::set<std::string> >(before, updated);
[email protected]16bf7ba72013-08-23 11:52:543093 std::set<std::string> not_yet_blacklisted =
[email protected]3f2a2fa2013-09-24 02:55:253094 base::STLSetDifference<std::set<std::string> >(updated, before);
[email protected]695b5712012-12-06 23:55:283095
3096 for (std::set<std::string>::iterator it = no_longer_blacklisted.begin();
3097 it != no_longer_blacklisted.end(); ++it) {
3098 scoped_refptr<const Extension> extension =
3099 blacklisted_extensions_.GetByID(*it);
[email protected]3f2a2fa2013-09-24 02:55:253100 if (!extension.get()) {
3101 NOTREACHED() << "Extension " << *it << " no longer blacklisted, "
3102 << "but it was never blacklisted.";
[email protected]695b5712012-12-06 23:55:283103 continue;
[email protected]3f2a2fa2013-09-24 02:55:253104 }
[email protected]695b5712012-12-06 23:55:283105 blacklisted_extensions_.Remove(*it);
[email protected]3f2a2fa2013-09-24 02:55:253106 extension_prefs_->SetExtensionBlacklisted(extension->id(), false);
[email protected]dc24976f2013-06-02 21:15:093107 AddExtension(extension.get());
[email protected]ac875372013-02-28 04:36:093108 UMA_HISTOGRAM_ENUMERATION("ExtensionBlacklist.UnblacklistInstalled",
[email protected]dc24976f2013-06-02 21:15:093109 extension->location(),
3110 Manifest::NUM_LOCATIONS);
[email protected]695b5712012-12-06 23:55:283111 }
3112
3113 for (std::set<std::string>::iterator it = not_yet_blacklisted.begin();
3114 it != not_yet_blacklisted.end(); ++it) {
3115 scoped_refptr<const Extension> extension = GetInstalledExtension(*it);
[email protected]3f2a2fa2013-09-24 02:55:253116 if (!extension.get()) {
3117 NOTREACHED() << "Extension " << *it << " needs to be "
3118 << "blacklisted, but it's not installed.";
[email protected]695b5712012-12-06 23:55:283119 continue;
[email protected]3f2a2fa2013-09-24 02:55:253120 }
[email protected]695b5712012-12-06 23:55:283121 blacklisted_extensions_.Insert(extension);
[email protected]3f2a2fa2013-09-24 02:55:253122 extension_prefs_->SetExtensionBlacklisted(extension->id(), true);
[email protected]695b5712012-12-06 23:55:283123 UnloadExtension(*it, extension_misc::UNLOAD_REASON_BLACKLIST);
[email protected]ac875372013-02-28 04:36:093124 UMA_HISTOGRAM_ENUMERATION("ExtensionBlacklist.BlacklistInstalled",
3125 extension->location(), Manifest::NUM_LOCATIONS);
[email protected]695b5712012-12-06 23:55:283126 }
3127
3128 IdentifyAlertableExtensions();
[email protected]fdd679b2012-11-15 20:49:393129}
[email protected]75bdcb872013-03-13 00:41:453130
3131void ExtensionService::AddUpdateObserver(extensions::UpdateObserver* observer) {
3132 update_observers_.AddObserver(observer);
3133}
3134
3135void ExtensionService::RemoveUpdateObserver(
3136 extensions::UpdateObserver* observer) {
3137 update_observers_.RemoveObserver(observer);
3138}