blob: 56388a1489b5d29bc56f232a3907394247188c32 [file] [log] [blame]
[email protected]098fa7a2013-03-08 22:11:171// Copyright (c) 2013 The Chromium Authors. All rights reserved.
[email protected]6014d672008-12-05 00:38:252// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]eaa7dd182010-12-14 11:09:005#include "chrome/browser/extensions/extension_service.h"
[email protected]6014d672008-12-05 00:38:256
[email protected]654512b2010-09-01 02:09:427#include <algorithm>
[email protected]695b5712012-12-06 23:55:288#include <iterator>
[email protected]97d2f1d2011-01-15 00:41:089#include <set>
[email protected]654512b2010-09-01 02:09:4210
[email protected]24b538a2010-02-27 01:22:4411#include "base/basictypes.h"
[email protected]05aad2da2011-10-28 10:12:3712#include "base/bind.h"
[email protected]e5af875f2011-10-10 21:09:1413#include "base/callback.h"
[email protected]62433d32011-10-12 22:33:1214#include "base/command_line.h"
[email protected]6014d672008-12-05 00:38:2515#include "base/file_util.h"
[email protected]14908b72011-04-20 06:54:3616#include "base/logging.h"
[email protected]835d7c82010-10-14 04:38:3817#include "base/metrics/histogram.h"
[email protected]3853a4c2013-02-11 17:15:5718#include "base/prefs/pref_service.h"
[email protected]7286e3fc2011-07-19 22:13:2419#include "base/stl_util.h"
[email protected]3ea1b182013-02-08 22:38:4120#include "base/strings/string_number_conversions.h"
[email protected]00e7bef2013-06-10 20:35:1721#include "base/strings/string_util.h"
22#include "base/strings/stringprintf.h"
[email protected]112158af2013-06-07 23:46:1823#include "base/strings/utf_string_conversions.h"
[email protected]7f8f24f2012-11-15 19:40:1424#include "base/threading/sequenced_worker_pool.h"
[email protected]34b99632011-01-01 01:01:0625#include "base/threading/thread_restrictions.h"
[email protected]41a17c52013-06-28 00:27:5326#include "base/time/time.h"
[email protected]cc655912009-01-29 23:19:1927#include "base/values.h"
[email protected]aa142702010-03-26 01:26:3328#include "base/version.h"
[email protected]15730c42009-09-03 00:03:2029#include "chrome/browser/browser_process.h"
[email protected]9ea0cd32013-07-12 01:50:3630#include "chrome/browser/chrome_notification_types.h"
[email protected]ad445762013-01-23 00:47:4431#include "chrome/browser/extensions/api/extension_action/extension_action_api.h"
[email protected]4636c832013-01-11 02:10:1132#include "chrome/browser/extensions/api/storage/settings_frontend.h"
[email protected]d8c8f25f2011-11-02 18:18:0133#include "chrome/browser/extensions/component_loader.h"
[email protected]e0785902011-05-19 23:34:1734#include "chrome/browser/extensions/crx_installer.h"
[email protected]d9ede582012-08-14 19:21:3835#include "chrome/browser/extensions/data_deleter.h"
[email protected]62f051c2012-03-29 17:04:4436#include "chrome/browser/extensions/extension_disabled_ui.h"
[email protected]14a000d2010-04-29 21:44:2437#include "chrome/browser/extensions/extension_error_reporter.h"
[email protected]89226982012-07-16 20:09:1838#include "chrome/browser/extensions/extension_error_ui.h"
[email protected]b1748b1d82009-11-30 20:32:5639#include "chrome/browser/extensions/extension_host.h"
[email protected]00b38242012-07-18 18:43:2240#include "chrome/browser/extensions/extension_install_ui.h"
[email protected]19eb80152011-02-26 00:28:4341#include "chrome/browser/extensions/extension_special_storage_policy.h"
[email protected]f8aefb132013-10-30 09:29:5242#include "chrome/browser/extensions/extension_sync_service.h"
[email protected]617342a42013-12-18 23:34:0343#include "chrome/browser/extensions/extension_util.h"
[email protected]612a1cb12012-10-17 13:18:0344#include "chrome/browser/extensions/external_install_ui.h"
[email protected]5df038b2012-07-16 19:03:2745#include "chrome/browser/extensions/external_provider_impl.h"
[email protected]ffd2f79e2013-11-14 00:11:4646#include "chrome/browser/extensions/install_verifier.h"
[email protected]d8c8f25f2011-11-02 18:18:0147#include "chrome/browser/extensions/installed_loader.h"
[email protected]c333e792012-01-06 16:57:3948#include "chrome/browser/extensions/permissions_updater.h"
[email protected]d8c8f25f2011-11-02 18:18:0149#include "chrome/browser/extensions/unpacked_installer.h"
[email protected]044e86992014-01-24 22:59:1150#include "chrome/browser/extensions/updater/extension_cache.h"
[email protected]42a08162012-03-16 18:09:1151#include "chrome/browser/extensions/updater/extension_updater.h"
[email protected]8ecad5e2010-12-02 21:18:3352#include "chrome/browser/profiles/profile.h"
[email protected]b5a507b22013-11-08 20:41:5753#include "chrome/browser/ui/webui/extensions/extension_icon_source.h"
[email protected]c8d407e2011-04-28 21:27:1754#include "chrome/browser/ui/webui/favicon_source.h"
[email protected]5eddc3e2011-10-26 04:33:3155#include "chrome/browser/ui/webui/ntp/thumbnail_source.h"
[email protected]b07e606e2012-09-15 20:16:1556#include "chrome/browser/ui/webui/theme_source.h"
[email protected]e2eb43112009-05-29 21:19:5457#include "chrome/common/chrome_switches.h"
[email protected]f6431be82013-09-07 02:53:4558#include "chrome/common/crash_keys.h"
[email protected]9f4e4f082013-06-21 07:11:1959#include "chrome/common/extensions/extension_constants.h"
[email protected]7c927b62010-02-24 09:54:1360#include "chrome/common/extensions/extension_file_util.h"
[email protected]77a6970c2011-04-23 16:58:5661#include "chrome/common/extensions/extension_messages.h"
[email protected]15d4d2d2013-08-09 06:49:0362#include "chrome/common/extensions/features/feature_channel.h"
[email protected]561e33d52013-04-03 06:58:4363#include "chrome/common/extensions/manifest_handlers/app_isolation_info.h"
[email protected]65348062013-01-15 07:27:2264#include "chrome/common/extensions/manifest_url_handler.h"
[email protected]25b34332009-06-05 21:53:1965#include "chrome/common/pref_names.h"
[email protected]a57209872009-05-04 22:53:1466#include "chrome/common/url_constants.h"
[email protected]7a83dd072013-09-03 12:09:1767#include "components/startup_metric_utils/startup_metric_utils.h"
[email protected]c38831a12011-10-28 12:44:4968#include "content/public/browser/browser_thread.h"
[email protected]98f66112012-12-25 12:59:3669#include "content/public/browser/devtools_agent_host.h"
[email protected]05aad2da2011-10-28 10:12:3770#include "content/public/browser/notification_service.h"
[email protected]0d6e9bd2011-10-18 04:29:1671#include "content/public/browser/notification_types.h"
[email protected]f3b1a082011-11-18 00:34:3072#include "content/public/browser/render_process_host.h"
[email protected]399583b2012-12-11 09:33:4273#include "content/public/browser/site_instance.h"
74#include "content/public/browser/storage_partition.h"
[email protected]24ea7a12013-01-27 23:54:5375#include "content/public/browser/url_data_source.h"
[email protected]74474042013-11-21 12:03:5476#include "extensions/browser/app_sorting.h"
[email protected]34423532013-11-21 18:13:1077#include "extensions/browser/event_router.h"
[email protected]bb1bc9b32013-12-21 03:09:1478#include "extensions/browser/extension_registry.h"
[email protected]59b0e602014-01-30 00:41:2479#include "extensions/browser/extension_system.h"
[email protected]45928b682013-11-28 08:20:2780#include "extensions/browser/extensions_browser_client.h"
[email protected]301116c62013-11-26 10:37:4581#include "extensions/browser/external_provider_interface.h"
82#include "extensions/browser/management_policy.h"
[email protected]b52f8ca2013-11-28 08:25:2283#include "extensions/browser/pending_extension_manager.h"
[email protected]234fc5ff2014-01-16 23:32:2884#include "extensions/browser/pref_names.h"
[email protected]98b6d942013-11-10 00:34:0785#include "extensions/browser/process_manager.h"
[email protected]fafdc842014-01-17 18:09:0886#include "extensions/browser/process_map.h"
[email protected]45f5b7d2014-01-22 23:47:1387#include "extensions/browser/runtime_data.h"
[email protected]a9aa62b312013-11-29 05:35:0688#include "extensions/browser/update_observer.h"
[email protected]836e2982013-05-16 08:07:4289#include "extensions/common/constants.h"
[email protected]e9f541a2012-11-19 21:52:3190#include "extensions/common/error_utils.h"
[email protected]e4452d32013-11-15 23:07:4191#include "extensions/common/extension.h"
[email protected]c81f5d32013-10-26 10:38:4292#include "extensions/common/extensions_client.h"
[email protected]5ef835a2013-11-08 20:42:5793#include "extensions/common/feature_switch.h"
[email protected]d42c11152013-08-22 19:36:3294#include "extensions/common/manifest.h"
[email protected]0c3c9732013-09-16 08:53:4195#include "extensions/common/manifest_constants.h"
[email protected]558878cc82013-11-09 01:25:5196#include "extensions/common/manifest_handlers/background_info.h"
[email protected]1f7de252013-11-06 22:02:0097#include "extensions/common/manifest_handlers/incognito_info.h"
[email protected]301116c62013-11-26 10:37:4598#include "extensions/common/manifest_handlers/shared_module_info.h"
[email protected]c41003472013-10-19 15:37:2599#include "extensions/common/permissions/permission_message_provider.h"
[email protected]e4452d32013-11-15 23:07:41100#include "extensions/common/permissions/permissions_data.h"
[email protected]65187152012-06-02 13:14:14101#include "grit/generated_resources.h"
[email protected]be28b5f42012-07-20 11:31:25102#include "net/base/registry_controlled_domains/registry_controlled_domain.h"
[email protected]cd67ed52013-10-15 01:22:13103#include "ui/base/webui/web_ui_util.h"
[email protected]a6483d22013-07-03 22:11:00104#include "url/gurl.h"
[email protected]08b1f75f2013-05-22 22:02:38105#include "webkit/browser/database/database_tracker.h"
106#include "webkit/browser/database/database_util.h"
[email protected]79a60642012-10-20 21:03:18107
[email protected]eed367e2011-04-12 03:43:31108#if defined(OS_CHROMEOS)
[email protected]88e8ec9152013-01-17 04:05:18109#include "chrome/browser/chromeos/extensions/install_limiter.h"
[email protected]f19bbf62013-07-09 01:22:32110#include "webkit/browser/fileapi/file_system_backend.h"
[email protected]c6f9203a2013-05-28 02:08:07111#include "webkit/browser/fileapi/file_system_context.h"
[email protected]eed367e2011-04-12 03:43:31112#endif
113
[email protected]55eb70e762012-02-20 17:38:39114using content::BrowserContext;
[email protected]631bb742011-11-02 11:29:39115using content::BrowserThread;
[email protected]98f66112012-12-25 12:59:36116using content::DevToolsAgentHost;
[email protected]bf3d9df2012-07-24 23:20:27117using extensions::CrxInstaller;
[email protected]1c321ee52012-05-21 03:02:34118using extensions::Extension;
119using extensions::ExtensionIdSet;
120using extensions::ExtensionInfo;
[email protected]599539802014-01-07 23:06:00121using extensions::ExtensionRegistry;
[email protected]289c44b2013-12-17 03:26:57122using extensions::ExtensionSet;
[email protected]215a7be2012-10-22 19:53:42123using extensions::FeatureSwitch;
[email protected]ffd2f79e2013-11-14 00:11:46124using extensions::InstallVerifier;
[email protected]0d54b682013-11-05 14:15:36125using extensions::ManagementPolicy;
[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,
[email protected]439f1e32013-12-09 20:09:09178 base::string16* error) const OVERRIDE {
[email protected]4c9201c42013-08-16 04:56:21179 return !IsCWSSharedModule(extension);
180 }
181
182 virtual bool MustRemainEnabled(const Extension* extension,
[email protected]439f1e32013-12-09 20:09:09183 base::string16* error) const OVERRIDE {
[email protected]4c9201c42013-08-16 04:56:21184 return IsCWSSharedModule(extension);
185 }
186
187 private:
188 DISALLOW_COPY_AND_ASSIGN(SharedModuleProvider);
189};
190
[email protected]74564482014-01-30 13:55:42191enum VerifyAllSuccess {
192 VERIFY_ALL_BOOTSTRAP_SUCCESS = 0,
193 VERIFY_ALL_BOOTSTRAP_FAILURE,
194 VERIFY_ALL_NON_BOOTSTRAP_SUCCESS,
195 VERIFY_ALL_NON_BOOTSTRAP_FAILURE,
196
197 // Used in histograms. Do not remove/reorder any entries above, and the below
198 // MAX entry should always come last.
199
200 VERIFY_ALL_SUCCESS_MAX
201};
202
203void LogVerifyAllSuccessHistogram(bool bootstrap, bool success) {
204 VerifyAllSuccess result;
205 if (bootstrap && success)
206 result = VERIFY_ALL_BOOTSTRAP_SUCCESS;
207 else if (bootstrap && !success)
208 result = VERIFY_ALL_BOOTSTRAP_FAILURE;
209 else if (!bootstrap && success)
210 result = VERIFY_ALL_NON_BOOTSTRAP_SUCCESS;
211 else
212 result = VERIFY_ALL_NON_BOOTSTRAP_FAILURE;
213
214 UMA_HISTOGRAM_ENUMERATION("ExtensionService.VerifyAllSuccess",
215 result, VERIFY_ALL_SUCCESS_MAX);
216}
217
218void LogAddVerifiedSuccess(bool success) {
219 UMA_HISTOGRAM_BOOLEAN("ExtensionService.AddVerified", success);
220}
[email protected]4c9201c42013-08-16 04:56:21221
[email protected]c6d474f82009-12-16 21:11:06222} // namespace
[email protected]b6ab96d2009-08-20 18:58:19223
[email protected]eaa7dd182010-12-14 11:09:00224// ExtensionService.
[email protected]6014d672008-12-05 00:38:25225
[email protected]8e4560b62011-01-14 10:09:14226void ExtensionService::CheckExternalUninstall(const std::string& id) {
[email protected]a29a517a2011-01-21 21:11:12227 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]a8af9fdb2010-10-28 21:52:20228
[email protected]7a4c6852010-09-16 03:44:22229 // Check if the providers know about this extension.
[email protected]5df038b2012-07-16 19:03:27230 extensions::ProviderCollection::const_iterator i;
[email protected]0a60a2e2010-10-25 16:15:21231 for (i = external_extension_providers_.begin();
232 i != external_extension_providers_.end(); ++i) {
[email protected]8e4560b62011-01-14 10:09:14233 DCHECK(i->get()->IsReady());
[email protected]0a60a2e2010-10-25 16:15:21234 if (i->get()->HasExtension(id))
235 return; // Yup, known extension, don't uninstall.
[email protected]7a4c6852010-09-16 03:44:22236 }
237
[email protected]0f48fca2011-05-19 18:46:35238 // We get the list of external extensions to check from preferences.
239 // It is possible that an extension has preferences but is not loaded.
240 // For example, an extension that requires experimental permissions
241 // will not be loaded if the experimental command line flag is not used.
242 // In this case, do not uninstall.
[email protected]31bb5ee62012-09-12 22:58:40243 if (!GetInstalledExtension(id)) {
[email protected]0f48fca2011-05-19 18:46:35244 // We can't call UninstallExtension with an unloaded/invalid
245 // extension ID.
246 LOG(WARNING) << "Attempted uninstallation of unloaded/invalid extension "
247 << "with id: " << id;
248 return;
249 }
[email protected]d6ebc9792011-04-07 18:18:33250 UninstallExtension(id, true, NULL);
[email protected]7a4c6852010-09-16 03:44:22251}
252
[email protected]7f8f24f2012-11-15 19:40:14253void ExtensionService::SetFileTaskRunnerForTesting(
254 base::SequencedTaskRunner* task_runner) {
255 file_task_runner_ = task_runner;
256}
257
[email protected]8e4560b62011-01-14 10:09:14258void ExtensionService::ClearProvidersForTesting() {
[email protected]7a4c6852010-09-16 03:44:22259 external_extension_providers_.clear();
260}
261
[email protected]8e4560b62011-01-14 10:09:14262void ExtensionService::AddProviderForTesting(
[email protected]5df038b2012-07-16 19:03:27263 extensions::ExternalProviderInterface* test_provider) {
[email protected]a29a517a2011-01-21 21:11:12264 CHECK(test_provider);
[email protected]0a60a2e2010-10-25 16:15:21265 external_extension_providers_.push_back(
[email protected]5df038b2012-07-16 19:03:27266 linked_ptr<extensions::ExternalProviderInterface>(test_provider));
[email protected]7a4c6852010-09-16 03:44:22267}
268
[email protected]9060d8b02012-01-13 02:14:30269bool ExtensionService::OnExternalExtensionUpdateUrlFound(
[email protected]7a4c6852010-09-16 03:44:22270 const std::string& id,
[email protected]21a5a672010-11-04 10:47:42271 const GURL& update_url,
[email protected]464213a2013-10-15 01:06:48272 Manifest::Location location,
273 int creation_flags,
274 bool mark_acknowledged) {
[email protected]ab22ba42011-01-14 16:36:38275 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
276 CHECK(Extension::IdIsValid(id));
[email protected]a8af9fdb2010-10-28 21:52:20277
[email protected]044e86992014-01-24 22:59:11278 if (Manifest::IsExternalLocation(location)) {
279 // All extensions that are not user specific can be cached.
280 extensions::ExtensionCache::GetInstance()->AllowCaching(id);
281 }
282
[email protected]8a87a5332011-08-11 17:54:59283 const Extension* extension = GetExtensionById(id, true);
284 if (extension) {
285 // Already installed. Skip this install if the current location has
286 // higher priority than |location|.
[email protected]1d5e58b2013-01-31 08:41:40287 Manifest::Location current = extension->location();
288 if (current == Manifest::GetHigherPriorityLocation(current, location))
[email protected]9060d8b02012-01-13 02:14:30289 return false;
[email protected]8a87a5332011-08-11 17:54:59290 // Otherwise, overwrite the current installation.
[email protected]7a4c6852010-09-16 03:44:22291 }
[email protected]9060d8b02012-01-13 02:14:30292
293 // Add |id| to the set of pending extensions. If it can not be added,
294 // then there is already a pending record from a higher-priority install
295 // source. In this case, signal that this extension will not be
296 // installed by returning false.
297 if (!pending_extension_manager()->AddFromExternalUpdateUrl(
[email protected]464213a2013-10-15 01:06:48298 id, update_url, location, creation_flags, mark_acknowledged)) {
[email protected]9060d8b02012-01-13 02:14:30299 return false;
[email protected]31bb5ee62012-09-12 22:58:40300 }
[email protected]9060d8b02012-01-13 02:14:30301
[email protected]94fde232012-04-27 10:22:30302 update_once_all_providers_are_ready_ = true;
[email protected]9060d8b02012-01-13 02:14:30303 return true;
[email protected]7a4c6852010-09-16 03:44:22304}
305
[email protected]400c4392013-12-13 14:41:58306const Extension* ExtensionService::GetInstalledExtensionByUrl(
307 const GURL& url) const {
[email protected]bb1bc9b32013-12-21 03:09:14308 return registry_->enabled_extensions().GetExtensionOrAppByURL(url);
[email protected]400c4392013-12-13 14:41:58309}
310
[email protected]dc9a74f72012-08-17 18:07:21311const Extension* ExtensionService::GetInstalledApp(const GURL& url) const {
[email protected]400c4392013-12-13 14:41:58312 const Extension* extension = GetInstalledExtensionByUrl(url);
[email protected]dc9a74f72012-08-17 18:07:21313 return (extension && extension->is_app()) ? extension : NULL;
[email protected]d9696672011-03-15 22:45:09314}
315
[email protected]dc9a74f72012-08-17 18:07:21316bool ExtensionService::IsInstalledApp(const GURL& url) const {
[email protected]d9696672011-03-15 22:45:09317 return !!GetInstalledApp(url);
[email protected]ffb204f22010-12-05 23:20:27318}
319
[email protected]6aeac8342010-10-01 20:21:18320// static
[email protected]d6ebc9792011-04-07 18:18:33321// This function is used to implement the command-line switch
[email protected]3bdba0d2011-08-23 07:17:30322// --uninstall-extension, and to uninstall an extension via sync. The LOG
323// statements within this function are used to inform the user if the uninstall
324// cannot be done.
[email protected]eaa7dd182010-12-14 11:09:00325bool ExtensionService::UninstallExtensionHelper(
326 ExtensionService* extensions_service,
[email protected]6aeac8342010-10-01 20:21:18327 const std::string& extension_id) {
[email protected]d6ebc9792011-04-07 18:18:33328 // We can't call UninstallExtension with an invalid extension ID.
[email protected]31bb5ee62012-09-12 22:58:40329 if (!extensions_service->GetInstalledExtension(extension_id)) {
[email protected]6aeac8342010-10-01 20:21:18330 LOG(WARNING) << "Attempted uninstallation of non-existent extension with "
[email protected]95da88c42011-03-31 10:07:33331 << "id: " << extension_id;
332 return false;
[email protected]6aeac8342010-10-01 20:21:18333 }
334
[email protected]d6ebc9792011-04-07 18:18:33335 // The following call to UninstallExtension will not allow an uninstall of a
336 // policy-controlled extension.
[email protected]439f1e32013-12-09 20:09:09337 base::string16 error;
[email protected]d6ebc9792011-04-07 18:18:33338 if (!extensions_service->UninstallExtension(extension_id, false, &error)) {
339 LOG(WARNING) << "Cannot uninstall extension with id " << extension_id
340 << ": " << error;
341 return false;
342 }
[email protected]95da88c42011-03-31 10:07:33343
[email protected]6aeac8342010-10-01 20:21:18344 return true;
345}
346
[email protected]eaa7dd182010-12-14 11:09:00347ExtensionService::ExtensionService(Profile* profile,
[email protected]f0841cd2011-01-19 15:07:24348 const CommandLine* command_line,
[email protected]650b2d52013-02-10 03:41:45349 const base::FilePath& install_directory,
[email protected]45759612012-07-10 17:21:23350 extensions::ExtensionPrefs* extension_prefs,
[email protected]fdd679b2012-11-15 20:49:39351 extensions::Blacklist* blacklist,
[email protected]0436b102011-04-15 18:30:03352 bool autoupdate_enabled,
[email protected]4a10006a2013-05-17 23:18:35353 bool extensions_enabled,
354 extensions::OneShotEvent* ready)
[email protected]fdd679b2012-11-15 20:49:39355 : extensions::Blacklist::Observer(blacklist),
356 profile_(profile),
[email protected]bd306722012-07-11 20:43:59357 system_(extensions::ExtensionSystem::Get(profile)),
[email protected]73c47932010-12-06 18:13:43358 extension_prefs_(extension_prefs),
[email protected]695b5712012-12-06 23:55:28359 blacklist_(blacklist),
[email protected]cccdf0aa2011-11-11 03:43:38360 settings_frontend_(extensions::SettingsFrontend::Create(profile)),
[email protected]f8aefb132013-10-30 09:29:52361 extension_sync_service_(NULL),
[email protected]5fdfa562013-12-27 17:43:59362 registry_(extensions::ExtensionRegistry::Get(profile)),
[email protected]9c009092013-05-01 03:14:09363 pending_extension_manager_(*this),
[email protected]a9b00ac2009-06-25 21:03:23364 install_directory_(install_directory),
[email protected]0436b102011-04-15 18:30:03365 extensions_enabled_(extensions_enabled),
[email protected]e81dba32009-06-19 20:19:13366 show_extensions_prompts_(true),
[email protected]fc332ae2012-11-14 20:17:33367 install_updates_when_idle_(true),
[email protected]4a10006a2013-05-17 23:18:35368 ready_(ready),
[email protected]dff1e042012-04-27 10:59:18369 update_once_all_providers_are_ready_(false),
[email protected]3c4abc82012-10-22 22:25:54370 browser_terminating_(false),
[email protected]9f4e4f082013-06-21 07:11:19371 installs_delayed_for_gc_(false),
[email protected]f8aefb132013-10-30 09:29:52372 is_first_run_(false) {
[email protected]c04fd3dd2013-09-05 08:20:10373#if defined(OS_CHROMEOS)
374 disable_garbage_collection_ = false;
375#endif
[email protected]a29a517a2011-01-21 21:11:12376 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]a8af9fdb2010-10-28 21:52:20377
[email protected]36a784c2009-06-23 06:21:08378 // Figure out if extension installation should be enabled.
[email protected]367d9b172013-12-03 00:31:02379 if (extensions::ExtensionsBrowserClient::Get()->AreExtensionsDisabled(
380 *command_line, profile))
[email protected]6d60703b2009-08-29 01:29:23381 extensions_enabled_ = false;
[email protected]36a784c2009-06-23 06:21:08382
[email protected]3c4abc82012-10-22 22:25:54383 registrar_.Add(this, chrome::NOTIFICATION_APP_TERMINATING,
384 content::NotificationService::AllBrowserContextsAndSources());
[email protected]432115822011-07-10 15:52:27385 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_PROCESS_TERMINATED,
[email protected]ad50def52011-10-19 23:17:07386 content::NotificationService::AllBrowserContextsAndSources());
[email protected]432115822011-07-10 15:52:27387 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_TERMINATED,
[email protected]ad50def52011-10-19 23:17:07388 content::NotificationService::AllBrowserContextsAndSources());
[email protected]92dd8d92013-02-26 00:41:08389 registrar_.Add(this, chrome::NOTIFICATION_UPGRADE_RECOMMENDED,
390 content::NotificationService::AllBrowserContextsAndSources());
[email protected]2fb7dc982010-09-29 12:24:28391 pref_change_registrar_.Init(profile->GetPrefs());
[email protected]90bb38d2012-11-14 18:36:03392 base::Closure callback =
393 base::Bind(&ExtensionService::OnExtensionInstallPrefChanged,
394 base::Unretained(this));
[email protected]234fc5ff2014-01-16 23:32:28395 pref_change_registrar_.Add(extensions::pref_names::kInstallAllowList,
396 callback);
397 pref_change_registrar_.Add(extensions::pref_names::kInstallDenyList,
398 callback);
399 pref_change_registrar_.Add(extensions::pref_names::kAllowedTypes, callback);
[email protected]4814b512009-11-07 00:12:29400
[email protected]93fd78f42009-07-10 16:43:17401 // Set up the ExtensionUpdater
402 if (autoupdate_enabled) {
[email protected]501105b2013-09-26 05:42:02403 int update_frequency = extensions::kDefaultUpdateFrequencySeconds;
[email protected]93fd78f42009-07-10 16:43:17404 if (command_line->HasSwitch(switches::kExtensionsUpdateFrequency)) {
[email protected]e83326f2010-07-31 17:29:25405 base::StringToInt(command_line->GetSwitchValueASCII(
406 switches::kExtensionsUpdateFrequency),
407 &update_frequency);
[email protected]93fd78f42009-07-10 16:43:17408 }
[email protected]044e86992014-01-24 22:59:11409 updater_.reset(new extensions::ExtensionUpdater(
410 this,
411 extension_prefs,
412 profile->GetPrefs(),
413 profile,
414 update_frequency,
415 extensions::ExtensionCache::GetInstance()));
[email protected]93fd78f42009-07-10 16:43:17416 }
417
[email protected]25ae0152011-11-18 14:40:02418 component_loader_.reset(
419 new extensions::ComponentLoader(this,
420 profile->GetPrefs(),
[email protected]55e16cd2013-12-18 04:36:08421 g_browser_process->local_state(),
422 profile));
[email protected]8e4560b62011-01-14 10:09:14423
[email protected]0436b102011-04-15 18:30:03424 if (extensions_enabled_) {
[email protected]ae4c37e2012-12-21 01:16:25425 extensions::ExternalProviderImpl::CreateExternalProviders(
426 this, profile_, &external_extension_providers_);
[email protected]873531342011-03-09 12:16:05427 }
[email protected]b671760b2010-07-15 21:13:47428
[email protected]74474042013-11-21 12:03:54429 // Set this as the ExtensionService for app sorting to ensure it causes syncs
430 // if required.
[email protected]b3aa7182013-04-25 04:45:23431 is_first_run_ = !extension_prefs_->SetAlertSystemFirstRun();
432
[email protected]9ce11d22012-08-08 23:20:13433#if defined(ENABLE_EXTENSIONS)
[email protected]c77f2352012-08-08 22:07:58434 extension_action_storage_manager_.reset(
435 new extensions::ExtensionActionStorageManager(profile_));
[email protected]9ce11d22012-08-08 23:20:13436#endif
[email protected]c77f2352012-08-08 22:07:58437
[email protected]4c9201c42013-08-16 04:56:21438 shared_module_policy_provider_.reset(new SharedModuleProvider);
439
[email protected]cb0e50312011-05-09 15:03:07440 // How long is the path to the Extensions directory?
441 UMA_HISTOGRAM_CUSTOM_COUNTS("Extensions.ExtensionRootPathLength",
442 install_directory_.value().length(), 0, 500, 100);
[email protected]6014d672008-12-05 00:38:25443}
444
[email protected]84df8332011-12-06 18:22:46445const ExtensionSet* ExtensionService::extensions() const {
[email protected]bb1bc9b32013-12-21 03:09:14446 return &registry_->enabled_extensions();
[email protected]ddb1e5a2010-12-13 20:10:45447}
448
[email protected]9e9c1d12013-07-31 01:58:12449const ExtensionSet* ExtensionService::delayed_installs() const {
450 return &delayed_installs_;
451}
452
[email protected]620b5a62013-11-18 04:21:08453scoped_ptr<ExtensionSet>
[email protected]695b5712012-12-06 23:55:28454 ExtensionService::GenerateInstalledExtensionsSet() const {
455 scoped_ptr<ExtensionSet> installed_extensions(new ExtensionSet());
[email protected]bb1bc9b32013-12-21 03:09:14456 installed_extensions->InsertAll(registry_->enabled_extensions());
457 installed_extensions->InsertAll(registry_->disabled_extensions());
458 installed_extensions->InsertAll(registry_->terminated_extensions());
459 installed_extensions->InsertAll(registry_->blacklisted_extensions());
460 return installed_extensions.Pass();
[email protected]7f4308d2012-01-18 07:43:01461}
462
[email protected]3f213ad2012-07-26 23:39:41463extensions::PendingExtensionManager*
464 ExtensionService::pending_extension_manager() {
[email protected]b2907fd2011-03-25 16:43:37465 return &pending_extension_manager_;
[email protected]ddb1e5a2010-12-13 20:10:45466}
467
[email protected]eaa7dd182010-12-14 11:09:00468ExtensionService::~ExtensionService() {
[email protected]c8d407e2011-04-28 21:27:17469 // No need to unload extensions here because they are profile-scoped, and the
470 // profile is in the process of being deleted.
[email protected]94b4ffc2011-02-04 05:55:17471
[email protected]5df038b2012-07-16 19:03:27472 extensions::ProviderCollection::const_iterator i;
[email protected]8e4560b62011-01-14 10:09:14473 for (i = external_extension_providers_.begin();
474 i != external_extension_providers_.end(); ++i) {
[email protected]5df038b2012-07-16 19:03:27475 extensions::ExternalProviderInterface* provider = i->get();
[email protected]8e4560b62011-01-14 10:09:14476 provider->ServiceShutdown();
477 }
[email protected]6014d672008-12-05 00:38:25478}
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]599539802014-01-07 23:06:00487 int include_mask = ExtensionRegistry::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.
[email protected]599539802014-01-07 23:06:00492 include_mask |= ExtensionRegistry::DISABLED |
493 ExtensionRegistry::BLACKLISTED;
[email protected]695b5712012-12-06 23:55:28494 }
[email protected]599539802014-01-07 23:06:00495 return registry_->GetExtensionById(id, include_mask);
[email protected]695b5712012-12-06 23:55:28496}
497
[email protected]399583b2012-12-11 09:33:42498GURL ExtensionService::GetSiteForExtensionId(const std::string& extension_id) {
499 return content::SiteInstance::GetSiteForURL(
500 profile_,
501 Extension::GetBaseURLFromExtensionId(extension_id));
502}
503
[email protected]eaa7dd182010-12-14 11:09:00504void ExtensionService::Init() {
[email protected]a29a517a2011-01-21 21:11:12505 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]a8af9fdb2010-10-28 21:52:20506
[email protected]3350d712013-11-18 09:32:24507 base::Time begin_time = base::Time::Now();
508
[email protected]4a10006a2013-05-17 23:18:35509 DCHECK(!is_ready()); // Can't redo init.
[email protected]bb1bc9b32013-12-21 03:09:14510 DCHECK_EQ(registry_->enabled_extensions().size(), 0u);
[email protected]9f1087e2009-06-15 17:29:32511
[email protected]820d9bd2013-04-03 03:46:03512 const CommandLine* cmd_line = CommandLine::ForCurrentProcess();
[email protected]820d9bd2013-04-03 03:46:03513 if (cmd_line->HasSwitch(switches::kInstallFromWebstore) ||
514 cmd_line->HasSwitch(switches::kLimitedInstallFromWebstore)) {
515 // The sole purpose of this launch is to install a new extension from CWS
516 // and immediately terminate: loading already installed extensions is
517 // unnecessary and may interfere with the inline install dialog (e.g. if an
518 // extension listens to onStartup and opens a window).
519 SetReadyAndNotifyListeners();
[email protected]ae4c37e2012-12-21 01:16:25520 } else {
[email protected]47b60072013-06-20 10:35:56521 // LoadAllExtensions() calls OnLoadedInstalledExtensions().
522 component_loader_->LoadAll();
523 extensions::InstalledLoader(this).LoadAllExtensions();
[email protected]9f4e4f082013-06-21 07:11:19524
[email protected]59ee99d2013-10-11 15:46:16525 ReconcileKnownDisabled();
526
[email protected]2edd57852013-08-14 22:07:40527 // Attempt to re-enable extensions whose only disable reason is reloading.
528 std::vector<std::string> extensions_to_enable;
[email protected]bb1bc9b32013-12-21 03:09:14529 const ExtensionSet& disabled_extensions = registry_->disabled_extensions();
530 for (ExtensionSet::const_iterator iter = disabled_extensions.begin();
531 iter != disabled_extensions.end(); ++iter) {
[email protected]2edd57852013-08-14 22:07:40532 const Extension* e = iter->get();
533 if (extension_prefs_->GetDisableReasons(e->id()) ==
534 Extension::DISABLE_RELOAD) {
535 extensions_to_enable.push_back(e->id());
536 }
537 }
538 for (std::vector<std::string>::iterator it = extensions_to_enable.begin();
539 it != extensions_to_enable.end(); ++it) {
540 EnableExtension(*it);
541 }
542
[email protected]9f4e4f082013-06-21 07:11:19543 // Finish install (if possible) of extensions that were still delayed while
544 // the browser was shut down.
545 scoped_ptr<extensions::ExtensionPrefs::ExtensionsInfo> delayed_info(
546 extension_prefs_->GetAllDelayedInstallInfo());
547 for (size_t i = 0; i < delayed_info->size(); ++i) {
548 ExtensionInfo* info = delayed_info->at(i).get();
549 scoped_refptr<const Extension> extension(NULL);
550 if (info->extension_manifest) {
551 std::string error;
552 extension = Extension::Create(
553 info->extension_path,
554 info->extension_location,
555 *info->extension_manifest,
556 extension_prefs_->GetDelayedInstallCreationFlags(
557 info->extension_id),
558 info->extension_id,
559 &error);
560 if (extension.get())
561 delayed_installs_.Insert(extension);
562 }
563 }
564 MaybeFinishDelayedInstallations();
565
566 scoped_ptr<extensions::ExtensionPrefs::ExtensionsInfo> delayed_info2(
567 extension_prefs_->GetAllDelayedInstallInfo());
568 UMA_HISTOGRAM_COUNTS_100("Extensions.UpdateOnLoad",
569 delayed_info2->size() - delayed_info->size());
570
[email protected]47b60072013-06-20 10:35:56571 SetReadyAndNotifyListeners();
[email protected]ae4c37e2012-12-21 01:16:25572
[email protected]47b60072013-06-20 10:35:56573 // TODO(erikkay) this should probably be deferred to a future point
574 // rather than running immediately at startup.
575 CheckForExternalUpdates();
[email protected]894bb502009-05-21 22:39:57576
[email protected]33dc0c62014-02-13 00:00:38577 MaybeBootstrapVerifier();
[email protected]47b60072013-06-20 10:35:56578 base::MessageLoop::current()->PostDelayedTask(
579 FROM_HERE,
580 base::Bind(&ExtensionService::GarbageCollectExtensions, AsWeakPtr()),
581 base::TimeDelta::FromSeconds(kGarbageCollectStartupDelay));
[email protected]215a7be2012-10-22 19:53:42582
[email protected]820d9bd2013-04-03 03:46:03583 if (extension_prefs_->NeedsStorageGarbageCollection()) {
584 GarbageCollectIsolatedStorage();
585 extension_prefs_->SetNeedsStorageGarbageCollection(false);
586 }
[email protected]4c9201c42013-08-16 04:56:21587 system_->management_policy()->RegisterProvider(
588 shared_module_policy_provider_.get());
[email protected]2d19eb6e2014-01-27 17:30:00589
590 LoadGreylistFromPrefs();
[email protected]399583b2012-12-11 09:33:42591 }
[email protected]3350d712013-11-18 09:32:24592
593 UMA_HISTOGRAM_TIMES("Extensions.ExtensionServiceInitTime",
594 base::Time::Now() - begin_time);
[email protected]6014d672008-12-05 00:38:25595}
596
[email protected]2d19eb6e2014-01-27 17:30:00597void ExtensionService::LoadGreylistFromPrefs() {
598 scoped_ptr<ExtensionSet> all_extensions = GenerateInstalledExtensionsSet();
599
600 for (ExtensionSet::const_iterator it = all_extensions->begin();
601 it != all_extensions->end(); ++it) {
602 extensions::BlacklistState state =
603 extension_prefs_->GetExtensionBlacklistState((*it)->id());
604 if (state == extensions::BLACKLISTED_SECURITY_VULNERABILITY ||
605 state == extensions::BLACKLISTED_POTENTIALLY_UNWANTED ||
606 state == extensions::BLACKLISTED_CWS_POLICY_VIOLATION)
607 greylist_.Insert(*it);
608 }
609}
610
[email protected]33dc0c62014-02-13 00:00:38611void ExtensionService::MaybeBootstrapVerifier() {
612 InstallVerifier* verifier =
613 extensions::ExtensionSystem::Get(profile_)->install_verifier();
614 bool do_bootstrap = false;
615
616 if (verifier->NeedsBootstrap()) {
617 do_bootstrap = true;
618 } else {
619 // If any of the installed extensions have an install time newer than the
620 // signature's timestamp, we need to bootstrap because our signature may
621 // be missing valid extensions.
622 base::Time timestamp = verifier->SignatureTimestamp();
623 for (extensions::ExtensionSet::const_iterator i = extensions()->begin();
624 i != extensions()->end();
625 ++i) {
626 const Extension& extension = **i;
627 base::Time install_time =
628 extension_prefs_->GetInstallTime(extension.id());
629 if (verifier->NeedsVerification(extension) &&
630 install_time < base::Time::Now() && install_time >= timestamp) {
631 do_bootstrap = true;
632 break;
633 }
634 }
635 }
636 if (do_bootstrap)
637 VerifyAllExtensions(true); // bootstrap=true.
638}
639
[email protected]74564482014-01-30 13:55:42640void ExtensionService::VerifyAllExtensions(bool bootstrap) {
[email protected]68e5cc72013-12-17 02:41:53641 ExtensionIdSet to_add;
642 scoped_ptr<ExtensionSet> all_extensions = GenerateInstalledExtensionsSet();
643
644 for (ExtensionSet::const_iterator i = all_extensions->begin();
645 i != all_extensions->end(); ++i) {
646 const Extension& extension = **i;
647
[email protected]88622932014-01-16 17:59:12648 if (InstallVerifier::NeedsVerification(extension))
[email protected]68e5cc72013-12-17 02:41:53649 to_add.insert(extension.id());
650 }
651 extensions::ExtensionSystem::Get(profile_)->install_verifier()->AddMany(
652 to_add, base::Bind(&ExtensionService::FinishVerifyAllExtensions,
[email protected]74564482014-01-30 13:55:42653 AsWeakPtr(), bootstrap));
[email protected]68e5cc72013-12-17 02:41:53654}
655
[email protected]74564482014-01-30 13:55:42656void ExtensionService::FinishVerifyAllExtensions(bool bootstrap, bool success) {
657 LogVerifyAllSuccessHistogram(bootstrap, success);
[email protected]68e5cc72013-12-17 02:41:53658 if (success) {
659 // Check to see if any currently unverified extensions became verified.
660 InstallVerifier* verifier =
661 extensions::ExtensionSystem::Get(profile_)->install_verifier();
[email protected]bb1bc9b32013-12-21 03:09:14662 const ExtensionSet& disabled_extensions = registry_->disabled_extensions();
663 for (ExtensionSet::const_iterator i = disabled_extensions.begin();
664 i != disabled_extensions.end(); ++i) {
[email protected]68e5cc72013-12-17 02:41:53665 const Extension& extension = **i;
666 int disable_reasons = extension_prefs_->GetDisableReasons(extension.id());
667 if (disable_reasons & Extension::DISABLE_NOT_VERIFIED &&
668 !verifier->MustRemainDisabled(&extension, NULL, NULL)) {
669 extension_prefs_->RemoveDisableReason(extension.id(),
670 Extension::DISABLE_NOT_VERIFIED);
671 // Notify interested observers (eg the extensions settings page) by
672 // sending an UNLOADED notification.
673 //
674 // TODO(asargent) - this is a slight hack because it's already
675 // disabled; the right solution might be to add a separate listener
676 // interface for DisableReason's changing. http://crbug.com/328916
677 UnloadedExtensionInfo details(&extension,
678 UnloadedExtensionInfo::REASON_DISABLE);
679 content::NotificationService::current()->Notify(
680 chrome::NOTIFICATION_EXTENSION_UNLOADED,
681 content::Source<Profile>(profile_),
682 content::Details<UnloadedExtensionInfo>(&details));
683 }
684 }
685 // Might disable some extensions.
686 CheckManagementPolicy();
687 }
688}
689
[email protected]31bb5ee62012-09-12 22:58:40690bool ExtensionService::UpdateExtension(const std::string& id,
[email protected]650b2d52013-02-10 03:41:45691 const base::FilePath& extension_path,
[email protected]044e86992014-01-24 22:59:11692 bool file_ownership_passed,
[email protected]31bb5ee62012-09-12 22:58:40693 const GURL& download_url,
694 CrxInstaller** out_crx_installer) {
[email protected]a29a517a2011-01-21 21:11:12695 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]3c4abc82012-10-22 22:25:54696 if (browser_terminating_) {
697 LOG(WARNING) << "Skipping UpdateExtension due to browser shutdown";
698 // Leak the temp file at extension_path. We don't want to add to the disk
699 // I/O burden at shutdown, we can't rely on the I/O completing anyway, and
700 // the file is in the OS temp directory which should be cleaned up for us.
701 return false;
702 }
[email protected]a8af9fdb2010-10-28 21:52:20703
[email protected]3f213ad2012-07-26 23:39:41704 const extensions::PendingExtensionInfo* pending_extension_info =
[email protected]51a3bf8b2012-06-08 22:53:06705 pending_extension_manager()->GetById(id);
[email protected]8ef78fd2010-08-19 17:14:32706
[email protected]695b5712012-12-06 23:55:28707 const Extension* extension = GetInstalledExtension(id);
[email protected]51a3bf8b2012-06-08 22:53:06708 if (!pending_extension_info && !extension) {
[email protected]aa142702010-03-26 01:26:33709 LOG(WARNING) << "Will not update extension " << id
710 << " because it is not installed or pending";
711 // Delete extension_path since we're not creating a CrxInstaller
712 // that would do it for us.
[email protected]7f8f24f2012-11-15 19:40:14713 if (!GetFileTaskRunner()->PostTask(
714 FROM_HERE,
[email protected]53612e82011-10-18 18:00:36715 base::Bind(
[email protected]7296f2762011-11-21 19:23:44716 &extension_file_util::DeleteFile, extension_path, false)))
[email protected]14908b72011-04-20 06:54:36717 NOTREACHED();
[email protected]420a0ec2011-06-01 01:07:03718
719 return false;
[email protected]e957fe52009-06-23 16:51:05720 }
721
[email protected]aa142702010-03-26 01:26:33722 // We want a silent install only for non-pending extensions and
723 // pending extensions that have install_silently set.
[email protected]f8636f92013-08-09 21:02:37724 scoped_ptr<ExtensionInstallPrompt> client;
[email protected]91e51d612012-10-21 23:03:05725 if (pending_extension_info && !pending_extension_info->install_silently())
[email protected]f8636f92013-08-09 21:02:37726 client.reset(ExtensionInstallUI::CreateInstallPromptWithProfile(profile_));
[email protected]aa142702010-03-26 01:26:33727
[email protected]f8636f92013-08-09 21:02:37728 scoped_refptr<CrxInstaller> installer(
729 CrxInstaller::Create(this, client.Pass()));
[email protected]6dfbbf82010-03-12 23:09:16730 installer->set_expected_id(id);
[email protected]464213a2013-10-15 01:06:48731 int creation_flags = Extension::NO_FLAGS;
[email protected]51a3bf8b2012-06-08 22:53:06732 if (pending_extension_info) {
733 installer->set_install_source(pending_extension_info->install_source());
734 if (pending_extension_info->install_silently())
735 installer->set_allow_silent_install(true);
[email protected]464213a2013-10-15 01:06:48736 creation_flags = pending_extension_info->creation_flags();
737 if (pending_extension_info->mark_acknowledged())
738 AcknowledgeExternalExtension(id);
[email protected]51a3bf8b2012-06-08 22:53:06739 } else if (extension) {
[email protected]5eb375e92010-11-26 07:50:41740 installer->set_install_source(extension->location());
[email protected]51a3bf8b2012-06-08 22:53:06741 }
[email protected]7d8b7072012-04-07 01:07:46742 // If the extension was installed from or has migrated to the webstore, or
[email protected]fcb2c2c2012-10-17 21:08:45743 // its auto-update URL is from the webstore, treat it as a webstore install.
744 // Note that we ignore some older extensions with blank auto-update URLs
745 // because we are mostly concerned with restrictions on NaCl extensions,
746 // which are newer.
[email protected]75764512011-12-19 19:54:28747 if ((extension && extension->from_webstore()) ||
[email protected]4a5fe3e22013-06-04 07:06:38748 (extension && extensions::ManifestURL::UpdatesFromGallery(extension)) ||
[email protected]963d13c2012-09-29 17:13:35749 (!extension && extension_urls::IsWebstoreUpdateUrl(
[email protected]51a3bf8b2012-06-08 22:53:06750 pending_extension_info->update_url()))) {
[email protected]a12ce8b22012-01-17 18:40:53751 creation_flags |= Extension::FROM_WEBSTORE;
752 }
753
754 // Bookmark apps being updated is kind of a contradiction, but that's because
755 // we mark the default apps as bookmark apps, and they're hosted in the web
756 // store, thus they can get updated. See http://crbug.com/101605 for more
757 // details.
758 if (extension && extension->from_bookmark())
759 creation_flags |= Extension::FROM_BOOKMARK;
760
[email protected]e33bbc22012-08-27 22:05:46761 if (extension && extension->was_installed_by_default())
762 creation_flags |= Extension::WAS_INSTALLED_BY_DEFAULT;
763
[email protected]ab6c7be42014-01-16 02:05:54764 if (extension && extension->is_ephemeral())
765 creation_flags |= Extension::IS_EPHEMERAL;
766
[email protected]a12ce8b22012-01-17 18:40:53767 installer->set_creation_flags(creation_flags);
768
[email protected]044e86992014-01-24 22:59:11769 installer->set_delete_source(file_ownership_passed);
[email protected]655b2b1a2011-10-13 17:13:06770 installer->set_download_url(download_url);
[email protected]cb0e50312011-05-09 15:03:07771 installer->set_install_cause(extension_misc::INSTALL_CAUSE_UPDATE);
[email protected]6dfbbf82010-03-12 23:09:16772 installer->InstallCrx(extension_path);
[email protected]420a0ec2011-06-01 01:07:03773
774 if (out_crx_installer)
[email protected]dc24976f2013-06-02 21:15:09775 *out_crx_installer = installer.get();
[email protected]420a0ec2011-06-01 01:07:03776
777 return true;
[email protected]e957fe52009-06-23 16:51:05778}
779
[email protected]e178ad92013-06-28 02:29:25780void ExtensionService::ReloadExtension(const std::string extension_id) {
[email protected]a29a517a2011-01-21 21:11:12781 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]2a947202013-03-06 04:58:05782
783 // If the extension is already reloading, don't reload again.
784 if (extension_prefs_->GetDisableReasons(extension_id) &
785 Extension::DISABLE_RELOAD) {
786 return;
787 }
788
[email protected]650b2d52013-02-10 03:41:45789 base::FilePath path;
[email protected]9adb9692010-10-29 23:14:02790 const Extension* current_extension = GetExtensionById(extension_id, false);
[email protected]9cddd4702009-07-27 22:09:40791
[email protected]f17dbd42010-08-16 23:21:10792 // Disable the extension if it's loaded. It might not be loaded if it crashed.
[email protected]b65272f2009-08-31 15:47:06793 if (current_extension) {
[email protected]4814b512009-11-07 00:12:29794 // If the extension has an inspector open for its background page, detach
795 // the inspector and hang onto a cookie for it, so that we can reattach
796 // later.
[email protected]31d8f5f22012-04-02 15:22:08797 // TODO(yoz): this is not incognito-safe!
[email protected]98b6d942013-11-10 00:34:07798 extensions::ProcessManager* manager = system_->process_manager();
[email protected]3a1dc572012-07-31 22:25:13799 extensions::ExtensionHost* host =
800 manager->GetBackgroundHostForExtension(extension_id);
[email protected]98f66112012-12-25 12:59:36801 if (host && DevToolsAgentHost::HasFor(host->render_view_host())) {
[email protected]4814b512009-11-07 00:12:29802 // Look for an open inspector for the background page.
[email protected]04ea1bb2013-07-10 09:26:09803 scoped_refptr<DevToolsAgentHost> agent_host =
804 DevToolsAgentHost::GetOrCreateFor(host->render_view_host());
805 agent_host->DisconnectRenderViewHost();
806 orphaned_dev_tools_[extension_id] = agent_host;
[email protected]4814b512009-11-07 00:12:29807 }
808
[email protected]b65272f2009-08-31 15:47:06809 path = current_extension->path();
[email protected]58076192013-07-19 19:43:50810 // BeingUpgraded is set back to false when the extension is added.
[email protected]45f5b7d2014-01-22 23:47:13811 system_->runtime_data()->SetBeingUpgraded(current_extension, true);
[email protected]44d62b62012-04-11 00:06:03812 DisableExtension(extension_id, Extension::DISABLE_RELOAD);
[email protected]b914e2952013-04-26 07:10:03813 reloading_extensions_.insert(extension_id);
[email protected]1eb175082010-02-10 09:26:16814 } else {
815 path = unloaded_extension_paths_[extension_id];
[email protected]b65272f2009-08-31 15:47:06816 }
817
[email protected]9f4e4f082013-06-21 07:11:19818 if (delayed_installs_.Contains(extension_id)) {
[email protected]6f6101832012-11-27 22:10:48819 FinishDelayedInstallation(extension_id);
[email protected]0db124b02012-11-07 04:55:05820 return;
821 }
822
[email protected]43ceb002012-02-10 23:19:15823 // If we're reloading a component extension, use the component extension
824 // loader's reloader.
825 if (component_loader_->Exists(extension_id)) {
[email protected]e178ad92013-06-28 02:29:25826 SetBeingReloaded(extension_id, true);
[email protected]43ceb002012-02-10 23:19:15827 component_loader_->Reload(extension_id);
[email protected]e178ad92013-06-28 02:29:25828 SetBeingReloaded(extension_id, false);
[email protected]43ceb002012-02-10 23:19:15829 return;
830 }
831
[email protected]e6090e42010-03-23 22:44:08832 // Check the installed extensions to see if what we're reloading was already
833 // installed.
[email protected]e178ad92013-06-28 02:29:25834 SetBeingReloaded(extension_id, true);
[email protected]e6090e42010-03-23 22:44:08835 scoped_ptr<ExtensionInfo> installed_extension(
836 extension_prefs_->GetInstalledExtensionInfo(extension_id));
837 if (installed_extension.get() &&
838 installed_extension->extension_manifest.get()) {
[email protected]d8c8f25f2011-11-02 18:18:01839 extensions::InstalledLoader(this).Load(*installed_extension, false);
[email protected]e6090e42010-03-23 22:44:08840 } else {
[email protected]d8c8f25f2011-11-02 18:18:01841 // Otherwise, the extension is unpacked (location LOAD).
[email protected]e6090e42010-03-23 22:44:08842 // We should always be able to remember the extension's path. If it's not in
843 // the map, someone failed to update |unloaded_extension_paths_|.
844 CHECK(!path.empty());
[email protected]d8c8f25f2011-11-02 18:18:01845 extensions::UnpackedInstaller::Create(this)->Load(path);
[email protected]e6090e42010-03-23 22:44:08846 }
[email protected]e178ad92013-06-28 02:29:25847 // When reloading is done, mark this extension as done reloading.
848 SetBeingReloaded(extension_id, false);
[email protected]9cddd4702009-07-27 22:09:40849}
850
[email protected]fa2416f2011-05-03 08:41:20851bool ExtensionService::UninstallExtension(
[email protected]a12c706e2011-12-01 00:58:08852 std::string extension_id,
[email protected]fa2416f2011-05-03 08:41:20853 bool external_uninstall,
[email protected]439f1e32013-12-09 20:09:09854 base::string16* error) {
[email protected]a29a517a2011-01-21 21:11:12855 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]a8af9fdb2010-10-28 21:52:20856
[email protected]0d6ec3a72011-09-02 02:09:43857 scoped_refptr<const Extension> extension(GetInstalledExtension(extension_id));
[email protected]631cf822009-05-15 07:01:25858
[email protected]e7afe2452010-08-22 16:19:13859 // Callers should not send us nonexistent extensions.
[email protected]dc24976f2013-06-02 21:15:09860 CHECK(extension.get());
[email protected]9f1087e2009-06-15 17:29:32861
[email protected]95da88c42011-03-31 10:07:33862 // Policy change which triggers an uninstall will always set
863 // |external_uninstall| to true so this is the only way to uninstall
864 // managed extensions.
[email protected]65187152012-06-02 13:14:14865 if (!external_uninstall &&
866 !system_->management_policy()->UserMayModifySettings(
867 extension.get(), error)) {
[email protected]ad50def52011-10-19 23:17:07868 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:27869 chrome::NOTIFICATION_EXTENSION_UNINSTALL_NOT_ALLOWED,
[email protected]6c2381d2011-10-19 02:52:53870 content::Source<Profile>(profile_),
[email protected]dc24976f2013-06-02 21:15:09871 content::Details<const Extension>(extension.get()));
[email protected]d6ebc9792011-04-07 18:18:33872 return false;
873 }
[email protected]95da88c42011-03-31 10:07:33874
[email protected]65f173552012-06-28 22:43:58875 syncer::SyncChange sync_change;
[email protected]f8aefb132013-10-30 09:29:52876 if (extension_sync_service_) {
877 sync_change = extension_sync_service_->PrepareToSyncUninstallExtension(
878 extension.get(), is_ready());
[email protected]3bdba0d2011-08-23 07:17:30879 }
880
[email protected]ffd2f79e2013-11-14 00:11:46881 extensions::ExtensionSystem::Get(profile_)->install_verifier()->Remove(
882 extension->id());
883
[email protected]dc24976f2013-06-02 21:15:09884 if (IsUnacknowledgedExternalExtension(extension.get())) {
[email protected]d96eb512012-11-01 23:44:08885 UMA_HISTOGRAM_ENUMERATION("Extensions.ExternalExtensionEvent",
886 EXTERNAL_EXTENSION_UNINSTALLED,
887 EXTERNAL_EXTENSION_BUCKET_BOUNDARY);
[email protected]446e37e2013-08-07 00:30:02888 if (extensions::ManifestURL::UpdatesFromGallery(extension.get())) {
889 UMA_HISTOGRAM_ENUMERATION("Extensions.ExternalExtensionEventWebstore",
890 EXTERNAL_EXTENSION_UNINSTALLED,
891 EXTERNAL_EXTENSION_BUCKET_BOUNDARY);
892 } else {
893 UMA_HISTOGRAM_ENUMERATION("Extensions.ExternalExtensionEventNonWebstore",
894 EXTERNAL_EXTENSION_UNINSTALLED,
895 EXTERNAL_EXTENSION_BUCKET_BOUNDARY);
896 }
[email protected]d96eb512012-11-01 23:44:08897 }
[email protected]9b217652010-10-08 22:04:23898 UMA_HISTOGRAM_ENUMERATION("Extensions.UninstallType",
[email protected]7fa19f82010-12-21 19:40:08899 extension->GetType(), 100);
[email protected]dc24976f2013-06-02 21:15:09900 RecordPermissionMessagesHistogram(extension.get(),
901 "Extensions.Permissions_Uninstall");
[email protected]9b217652010-10-08 22:04:23902
[email protected]831aa212010-03-26 13:55:19903 // Unload before doing more cleanup to ensure that nothing is hanging on to
904 // any of these resources.
[email protected]b0af4792013-10-23 09:12:13905 UnloadExtension(extension_id, UnloadedExtensionInfo::REASON_UNINSTALL);
[email protected]831aa212010-03-26 13:55:19906
[email protected]9f1087e2009-06-15 17:29:32907 // Tell the backend to start deleting installed extensions on the file thread.
[email protected]12075d12013-02-27 05:38:05908 if (!Manifest::IsUnpackedLocation(extension->location())) {
[email protected]7f8f24f2012-11-15 19:40:14909 if (!GetFileTaskRunner()->PostTask(
910 FROM_HERE,
[email protected]53612e82011-10-18 18:00:36911 base::Bind(
[email protected]14908b72011-04-20 06:54:36912 &extension_file_util::UninstallExtension,
913 install_directory_,
[email protected]fa2416f2011-05-03 08:41:20914 extension_id)))
[email protected]14908b72011-04-20 06:54:36915 NOTREACHED();
[email protected]9f1087e2009-06-15 17:29:32916 }
917
[email protected]d656595b2014-01-09 14:09:35918 extensions::DataDeleter::StartDeleting(profile_, extension.get());
[email protected]0d6ec3a72011-09-02 02:09:43919
[email protected]0dfe05c2011-02-23 23:03:36920 UntrackTerminatedExtension(extension_id);
[email protected]211030342010-09-30 18:41:06921
922 // Notify interested parties that we've uninstalled this extension.
[email protected]ad50def52011-10-19 23:17:07923 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:27924 chrome::NOTIFICATION_EXTENSION_UNINSTALLED,
[email protected]6c2381d2011-10-19 02:52:53925 content::Source<Profile>(profile_),
[email protected]dc24976f2013-06-02 21:15:09926 content::Details<const Extension>(extension.get()));
[email protected]d6ebc9792011-04-07 18:18:33927
[email protected]f8aefb132013-10-30 09:29:52928 if (extension_sync_service_) {
929 extension_sync_service_->ProcessSyncUninstallExtension(extension_id,
930 sync_change);
[email protected]3bdba0d2011-08-23 07:17:30931 }
932
[email protected]399583b2012-12-11 09:33:42933 delayed_installs_.Remove(extension_id);
[email protected]0db124b02012-11-07 04:55:05934
[email protected]198b5902013-06-27 10:36:11935 PruneSharedModulesOnUninstall(extension.get());
[email protected]9f4e4f082013-06-21 07:11:19936
[email protected]d4eda592013-09-18 03:37:57937 extension_prefs_->OnExtensionUninstalled(extension_id, extension->location(),
938 external_uninstall);
939
[email protected]333b1de2011-09-12 18:28:50940 // Track the uninstallation.
[email protected]49098f702011-10-13 03:47:18941 UMA_HISTOGRAM_ENUMERATION("Extensions.ExtensionUninstalled", 1, 2);
942
[email protected]d6ebc9792011-04-07 18:18:33943 return true;
[email protected]c10da4b02010-03-25 14:38:32944}
945
[email protected]c3cfb012011-04-06 22:07:35946bool ExtensionService::IsExtensionEnabled(
947 const std::string& extension_id) const {
[email protected]bb1bc9b32013-12-21 03:09:14948 if (registry_->enabled_extensions().Contains(extension_id) ||
949 registry_->terminated_extensions().Contains(extension_id)) {
[email protected]36429da2011-07-11 20:25:18950 return true;
[email protected]dc9a74f72012-08-17 18:07:21951 }
[email protected]36429da2011-07-11 20:25:18952
[email protected]bb1bc9b32013-12-21 03:09:14953 if (registry_->disabled_extensions().Contains(extension_id) ||
954 registry_->blacklisted_extensions().Contains(extension_id)) {
[email protected]ad83ca242011-07-29 01:32:25955 return false;
[email protected]695b5712012-12-06 23:55:28956 }
[email protected]ad83ca242011-07-29 01:32:25957
958 // If the extension hasn't been loaded yet, check the prefs for it. Assume
959 // enabled unless otherwise noted.
960 return !extension_prefs_->IsExtensionDisabled(extension_id) &&
[email protected]f574c402012-12-04 23:20:31961 !extension_prefs_->IsExternalExtensionUninstalled(extension_id);
[email protected]c3cfb012011-04-06 22:07:35962}
963
964bool ExtensionService::IsExternalExtensionUninstalled(
965 const std::string& extension_id) const {
966 return extension_prefs_->IsExternalExtensionUninstalled(extension_id);
967}
968
[email protected]eaa7dd182010-12-14 11:09:00969void ExtensionService::EnableExtension(const std::string& extension_id) {
[email protected]a29a517a2011-01-21 21:11:12970 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]a8af9fdb2010-10-28 21:52:20971
[email protected]06f92562011-04-29 19:27:31972 if (IsExtensionEnabled(extension_id))
[email protected]0c6da502009-08-14 22:32:39973 return;
[email protected]bb1bc9b32013-12-21 03:09:14974 const Extension* extension =
975 registry_->disabled_extensions().GetByID(extension_id);
[email protected]0d54b682013-11-05 14:15:36976
977 ManagementPolicy* policy = system_->management_policy();
978 if (extension && policy->MustRemainDisabled(extension, NULL, NULL)) {
979 UMA_HISTOGRAM_COUNTS_100("Extensions.EnableDeniedByPolicy", 1);
980 return;
981 }
[email protected]0c6da502009-08-14 22:32:39982
[email protected]b3317ad2011-04-28 23:46:00983 extension_prefs_->SetExtensionState(extension_id, Extension::ENABLED);
[email protected]eb5e4f92012-08-15 23:33:28984 extension_prefs_->ClearDisableReasons(extension_id);
[email protected]1784e83a2009-09-08 21:01:52985
[email protected]06f92562011-04-29 19:27:31986 // This can happen if sync enables an extension that is not
987 // installed yet.
988 if (!extension)
989 return;
990
[email protected]d96eb512012-11-01 23:44:08991 if (IsUnacknowledgedExternalExtension(extension)) {
992 UMA_HISTOGRAM_ENUMERATION("Extensions.ExternalExtensionEvent",
993 EXTERNAL_EXTENSION_REENABLED,
994 EXTERNAL_EXTENSION_BUCKET_BOUNDARY);
[email protected]446e37e2013-08-07 00:30:02995 if (extensions::ManifestURL::UpdatesFromGallery(extension)) {
996 UMA_HISTOGRAM_ENUMERATION("Extensions.ExternalExtensionEventWebstore",
997 EXTERNAL_EXTENSION_REENABLED,
998 EXTERNAL_EXTENSION_BUCKET_BOUNDARY);
999 } else {
1000 UMA_HISTOGRAM_ENUMERATION("Extensions.ExternalExtensionEventNonWebstore",
1001 EXTERNAL_EXTENSION_REENABLED,
1002 EXTERNAL_EXTENSION_BUCKET_BOUNDARY);
1003 }
[email protected]612a1cb12012-10-17 13:18:031004 AcknowledgeExternalExtension(extension->id());
[email protected]d96eb512012-11-01 23:44:081005 }
[email protected]612a1cb12012-10-17 13:18:031006
[email protected]0c6da502009-08-14 22:32:391007 // Move it over to the enabled list.
[email protected]bb1bc9b32013-12-21 03:09:141008 registry_->AddEnabled(make_scoped_refptr(extension));
1009 registry_->RemoveDisabled(extension->id());
[email protected]0c6da502009-08-14 22:32:391010
[email protected]62d30f42009-10-01 22:36:061011 NotifyExtensionLoaded(extension);
[email protected]3bdba0d2011-08-23 07:17:301012
[email protected]f74d7f32012-06-19 19:22:511013 // Notify listeners that the extension was enabled.
1014 content::NotificationService::current()->Notify(
1015 chrome::NOTIFICATION_EXTENSION_ENABLED,
1016 content::Source<Profile>(profile_),
1017 content::Details<const Extension>(extension));
1018
[email protected]f8aefb132013-10-30 09:29:521019 if (extension_sync_service_)
1020 extension_sync_service_->SyncEnableExtension(*extension);
[email protected]0c6da502009-08-14 22:32:391021}
1022
[email protected]44d62b62012-04-11 00:06:031023void ExtensionService::DisableExtension(
1024 const std::string& extension_id,
1025 Extension::DisableReason disable_reason) {
[email protected]a29a517a2011-01-21 21:11:121026 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]a8af9fdb2010-10-28 21:52:201027
[email protected]b2ba9962009-12-10 20:10:151028 // The extension may have been disabled already.
[email protected]06f92562011-04-29 19:27:311029 if (!IsExtensionEnabled(extension_id))
[email protected]1784e83a2009-09-08 21:01:521030 return;
[email protected]1784e83a2009-09-08 21:01:521031
[email protected]06f92562011-04-29 19:27:311032 const Extension* extension = GetInstalledExtension(extension_id);
1033 // |extension| can be NULL if sync disables an extension that is not
1034 // installed yet.
[email protected]65187152012-06-02 13:14:141035 if (extension &&
[email protected]505ccdc2013-06-20 20:15:351036 disable_reason != Extension::DISABLE_RELOAD &&
[email protected]65187152012-06-02 13:14:141037 !system_->management_policy()->UserMayModifySettings(extension, NULL)) {
[email protected]95da88c42011-03-31 10:07:331038 return;
[email protected]65187152012-06-02 13:14:141039 }
[email protected]95da88c42011-03-31 10:07:331040
[email protected]b3317ad2011-04-28 23:46:001041 extension_prefs_->SetExtensionState(extension_id, Extension::DISABLED);
[email protected]eb5e4f92012-08-15 23:33:281042 extension_prefs_->AddDisableReason(extension_id, disable_reason);
[email protected]1784e83a2009-09-08 21:01:521043
[email protected]599539802014-01-07 23:06:001044 int include_mask =
1045 ExtensionRegistry::EVERYTHING & ~ExtensionRegistry::DISABLED;
1046 extension = registry_->GetExtensionById(extension_id, include_mask);
[email protected]06f92562011-04-29 19:27:311047 if (!extension)
1048 return;
1049
[email protected]45f5b7d2014-01-22 23:47:131050 // The extension is either enabled or terminated.
1051 DCHECK(registry_->enabled_extensions().Contains(extension->id()) ||
1052 registry_->terminated_extensions().Contains(extension->id()));
[email protected]64742de32013-04-22 08:44:341053
[email protected]5c094792012-09-07 19:44:531054 // Move it over to the disabled list. Don't send a second unload notification
1055 // for terminated extensions being disabled.
[email protected]bb1bc9b32013-12-21 03:09:141056 registry_->AddDisabled(make_scoped_refptr(extension));
1057 if (registry_->enabled_extensions().Contains(extension->id())) {
1058 registry_->RemoveEnabled(extension->id());
[email protected]b0af4792013-10-23 09:12:131059 NotifyExtensionUnloaded(extension, UnloadedExtensionInfo::REASON_DISABLE);
[email protected]5c094792012-09-07 19:44:531060 } else {
[email protected]bb1bc9b32013-12-21 03:09:141061 registry_->RemoveTerminated(extension->id());
[email protected]5c094792012-09-07 19:44:531062 }
[email protected]3bdba0d2011-08-23 07:17:301063
[email protected]f8aefb132013-10-30 09:29:521064 if (extension_sync_service_)
1065 extension_sync_service_->SyncDisableExtension(*extension);
[email protected]1784e83a2009-09-08 21:01:521066}
1067
[email protected]1abf05e2013-07-09 17:04:361068void ExtensionService::DisableUserExtensions(
1069 const std::vector<std::string>& except_ids) {
[email protected]e516e4c2013-06-12 17:41:141070 extensions::ManagementPolicy* management_policy =
1071 system_->management_policy();
1072 extensions::ExtensionList to_disable;
1073
[email protected]bb1bc9b32013-12-21 03:09:141074 const ExtensionSet& enabled_set = registry_->enabled_extensions();
1075 for (ExtensionSet::const_iterator extension = enabled_set.begin();
1076 extension != enabled_set.end(); ++extension) {
[email protected]198b5902013-06-27 10:36:111077 if (management_policy->UserMayModifySettings(extension->get(), NULL))
[email protected]e516e4c2013-06-12 17:41:141078 to_disable.push_back(*extension);
1079 }
[email protected]bb1bc9b32013-12-21 03:09:141080 const ExtensionSet& terminated_set = registry_->terminated_extensions();
1081 for (ExtensionSet::const_iterator extension = terminated_set.begin();
1082 extension != terminated_set.end(); ++extension) {
[email protected]198b5902013-06-27 10:36:111083 if (management_policy->UserMayModifySettings(extension->get(), NULL))
[email protected]e516e4c2013-06-12 17:41:141084 to_disable.push_back(*extension);
1085 }
1086
1087 for (extensions::ExtensionList::const_iterator extension = to_disable.begin();
1088 extension != to_disable.end(); ++extension) {
[email protected]3082fe32013-08-06 11:12:381089 if ((*extension)->was_installed_by_default() &&
1090 extension_urls::IsWebstoreUpdateUrl(
1091 extensions::ManifestURL::GetUpdateURL(*extension)))
1092 continue;
[email protected]1abf05e2013-07-09 17:04:361093 const std::string& id = (*extension)->id();
1094 if (except_ids.end() == std::find(except_ids.begin(), except_ids.end(), id))
1095 DisableExtension(id, extensions::Extension::DISABLE_USER_ACTION);
[email protected]e516e4c2013-06-12 17:41:141096 }
1097}
1098
[email protected]eaa7dd182010-12-14 11:09:001099void ExtensionService::GrantPermissionsAndEnableExtension(
[email protected]009633c2013-03-07 22:08:281100 const Extension* extension) {
1101 GrantPermissions(extension);
[email protected]fe2dd7742011-04-19 22:52:491102 RecordPermissionMessagesHistogram(
1103 extension, "Extensions.Permissions_ReEnable");
[email protected]8d888c12010-11-30 00:00:251104 extension_prefs_->SetDidExtensionEscalatePermissions(extension, false);
1105 EnableExtension(extension->id());
1106}
1107
[email protected]009633c2013-03-07 22:08:281108void ExtensionService::GrantPermissions(const Extension* extension) {
[email protected]be083862012-09-01 03:53:451109 CHECK(extension);
1110 extensions::PermissionsUpdater perms_updater(profile());
[email protected]009633c2013-03-07 22:08:281111 perms_updater.GrantActivePermissions(extension);
[email protected]be083862012-09-01 03:53:451112}
1113
[email protected]fe2dd7742011-04-19 22:52:491114// static
1115void ExtensionService::RecordPermissionMessagesHistogram(
[email protected]13c68b62013-05-17 11:29:051116 const Extension* extension, const char* histogram) {
[email protected]de415552013-01-23 04:12:171117 // Since this is called from multiple sources, and since the histogram macros
1118 // use statics, we need to manually lookup the histogram ourselves.
1119 base::HistogramBase* counter = base::LinearHistogram::FactoryGet(
[email protected]fe2dd7742011-04-19 22:52:491120 histogram,
1121 1,
[email protected]c2e66e12012-06-27 06:27:061122 PermissionMessage::kEnumBoundary,
1123 PermissionMessage::kEnumBoundary + 1,
[email protected]de415552013-01-23 04:12:171124 base::HistogramBase::kUmaTargetedHistogramFlag);
[email protected]fe2dd7742011-04-19 22:52:491125
[email protected]13c68b62013-05-17 11:29:051126 PermissionMessages permissions =
1127 extensions::PermissionsData::GetPermissionMessages(extension);
[email protected]fe2dd7742011-04-19 22:52:491128 if (permissions.empty()) {
[email protected]c2e66e12012-06-27 06:27:061129 counter->Add(PermissionMessage::kNone);
[email protected]fe2dd7742011-04-19 22:52:491130 } else {
[email protected]c2e66e12012-06-27 06:27:061131 for (PermissionMessages::iterator it = permissions.begin();
[email protected]0d3e4a22011-06-23 19:02:521132 it != permissions.end(); ++it)
1133 counter->Add(it->id());
[email protected]fe2dd7742011-04-19 22:52:491134 }
1135}
1136
[email protected]eaa7dd182010-12-14 11:09:001137void ExtensionService::NotifyExtensionLoaded(const Extension* extension) {
[email protected]57a777f72010-03-31 01:09:421138 // The ChromeURLRequestContexts need to be first to know that the extension
[email protected]62d30f42009-10-01 22:36:061139 // was loaded, otherwise a race can arise where a renderer that is created
1140 // for the extension may try to load an extension URL with an extension id
[email protected]57a777f72010-03-31 01:09:421141 // that the request context doesn't yet know about. The profile is responsible
1142 // for ensuring its URLRequestContexts appropriately discover the loaded
1143 // extension.
[email protected]31d8f5f22012-04-02 15:22:081144 system_->RegisterExtensionWithRequestContexts(extension);
[email protected]62d30f42009-10-01 22:36:061145
[email protected]d5949312012-12-03 22:13:301146 // Tell renderers about the new extension, unless it's a theme (renderers
1147 // don't need to know about themes).
[email protected]a58f599c2012-12-01 03:08:191148 if (!extension->is_theme()) {
[email protected]19647262011-12-16 09:57:491149 for (content::RenderProcessHost::iterator i(
1150 content::RenderProcessHost::AllHostsIterator());
1151 !i.IsAtEnd(); i.Advance()) {
1152 content::RenderProcessHost* host = i.GetCurrentValue();
1153 Profile* host_profile =
1154 Profile::FromBrowserContext(host->GetBrowserContext());
1155 if (host_profile->GetOriginalProfile() ==
1156 profile_->GetOriginalProfile()) {
1157 std::vector<ExtensionMsg_Loaded_Params> loaded_extensions(
1158 1, ExtensionMsg_Loaded_Params(extension));
1159 host->Send(
1160 new ExtensionMsg_Loaded(loaded_extensions));
1161 }
[email protected]c8d407e2011-04-28 21:27:171162 }
[email protected]77a6970c2011-04-23 16:58:561163 }
1164
[email protected]3442a662012-01-12 08:06:171165 // Tell subsystems that use the EXTENSION_LOADED notification about the new
1166 // extension.
1167 //
1168 // NOTE: It is important that this happen after notifying the renderers about
1169 // the new extensions so that if we navigate to an extension URL in
1170 // NOTIFICATION_EXTENSION_LOADED, the renderer is guaranteed to know about it.
1171 content::NotificationService::current()->Notify(
1172 chrome::NOTIFICATION_EXTENSION_LOADED,
1173 content::Source<Profile>(profile_),
1174 content::Details<const Extension>(extension));
1175
[email protected]c8d407e2011-04-28 21:27:171176 // Tell a random-ass collection of other subsystems about the new extension.
1177 // TODO(aa): What should we do with all this goop? Can it move into the
1178 // relevant objects via EXTENSION_LOADED?
1179
1180 profile_->GetExtensionSpecialStoragePolicy()->
1181 GrantRightsForExtension(extension);
1182
1183 UpdateActiveExtensionsInCrashReporter();
1184
[email protected]c8d407e2011-04-28 21:27:171185 // If the extension has permission to load chrome://favicon/ resources we need
1186 // to make sure that the FaviconSource is registered with the
1187 // ChromeURLDataManager.
[email protected]13c68b62013-05-17 11:29:051188 if (extensions::PermissionsData::HasHostPermission(
1189 extension, GURL(chrome::kChromeUIFaviconURL))) {
[email protected]c8d407e2011-04-28 21:27:171190 FaviconSource* favicon_source = new FaviconSource(profile_,
1191 FaviconSource::FAVICON);
[email protected]24ea7a12013-01-27 23:54:531192 content::URLDataSource::Add(profile_, favicon_source);
[email protected]c8d407e2011-04-28 21:27:171193 }
[email protected]b07e606e2012-09-15 20:16:151194
1195#if !defined(OS_ANDROID)
1196 // Same for chrome://theme/ resources.
[email protected]13c68b62013-05-17 11:29:051197 if (extensions::PermissionsData::HasHostPermission(
1198 extension, GURL(chrome::kChromeUIThemeURL))) {
[email protected]b07e606e2012-09-15 20:16:151199 ThemeSource* theme_source = new ThemeSource(profile_);
[email protected]24ea7a12013-01-27 23:54:531200 content::URLDataSource::Add(profile_, theme_source);
[email protected]b07e606e2012-09-15 20:16:151201 }
1202#endif
1203
[email protected]5eddc3e2011-10-26 04:33:311204 // Same for chrome://thumb/ resources.
[email protected]13c68b62013-05-17 11:29:051205 if (extensions::PermissionsData::HasHostPermission(
1206 extension, GURL(chrome::kChromeUIThumbnailURL))) {
[email protected]420e6d92013-09-17 01:48:511207 ThumbnailSource* thumbnail_source = new ThumbnailSource(profile_, false);
[email protected]24ea7a12013-01-27 23:54:531208 content::URLDataSource::Add(profile_, thumbnail_source);
[email protected]5eddc3e2011-10-26 04:33:311209 }
[email protected]62d30f42009-10-01 22:36:061210}
1211
[email protected]a9f39a312010-12-23 22:14:271212void ExtensionService::NotifyExtensionUnloaded(
[email protected]814a7bf0f2011-08-13 05:30:591213 const Extension* extension,
[email protected]b0af4792013-10-23 09:12:131214 UnloadedExtensionInfo::Reason reason) {
[email protected]45f5b7d2014-01-22 23:47:131215 registry_->TriggerOnUnloaded(extension);
1216
[email protected]a9f39a312010-12-23 22:14:271217 UnloadedExtensionInfo details(extension, reason);
[email protected]ad50def52011-10-19 23:17:071218 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271219 chrome::NOTIFICATION_EXTENSION_UNLOADED,
[email protected]6c2381d2011-10-19 02:52:531220 content::Source<Profile>(profile_),
1221 content::Details<UnloadedExtensionInfo>(&details));
[email protected]62d30f42009-10-01 22:36:061222
[email protected]f3b1a082011-11-18 00:34:301223 for (content::RenderProcessHost::iterator i(
1224 content::RenderProcessHost::AllHostsIterator());
[email protected]77a6970c2011-04-23 16:58:561225 !i.IsAtEnd(); i.Advance()) {
[email protected]f3b1a082011-11-18 00:34:301226 content::RenderProcessHost* host = i.GetCurrentValue();
[email protected]9b62ecf2011-07-27 20:23:081227 Profile* host_profile =
[email protected]f3b1a082011-11-18 00:34:301228 Profile::FromBrowserContext(host->GetBrowserContext());
[email protected]9b62ecf2011-07-27 20:23:081229 if (host_profile->GetOriginalProfile() == profile_->GetOriginalProfile())
[email protected]c8d407e2011-04-28 21:27:171230 host->Send(new ExtensionMsg_Unloaded(extension->id()));
[email protected]77a6970c2011-04-23 16:58:561231 }
1232
[email protected]31d8f5f22012-04-02 15:22:081233 system_->UnregisterExtensionWithRequestContexts(extension->id(), reason);
[email protected]c8d407e2011-04-28 21:27:171234 profile_->GetExtensionSpecialStoragePolicy()->
1235 RevokeRightsForExtension(extension);
1236
[email protected]b777b332011-04-16 04:01:081237#if defined(OS_CHROMEOS)
[email protected]ac66e452013-01-11 09:21:231238 // Revoke external file access for the extension from its file system context.
1239 // It is safe to access the extension's storage partition at this point. The
1240 // storage partition may get destroyed only after the extension gets unloaded.
1241 GURL site = extensions::ExtensionSystem::Get(profile_)->extension_service()->
1242 GetSiteForExtensionId(extension->id());
[email protected]10eb28162012-09-18 03:04:091243 fileapi::FileSystemContext* filesystem_context =
[email protected]ac66e452013-01-11 09:21:231244 BrowserContext::GetStoragePartitionForSite(profile_, site)->
[email protected]10eb28162012-09-18 03:04:091245 GetFileSystemContext();
[email protected]f19bbf62013-07-09 01:22:321246 if (filesystem_context && filesystem_context->external_backend()) {
1247 filesystem_context->external_backend()->
[email protected]c8d407e2011-04-28 21:27:171248 RevokeAccessForExtension(extension->id());
[email protected]62d30f42009-10-01 22:36:061249 }
[email protected]c8d407e2011-04-28 21:27:171250#endif
1251
1252 UpdateActiveExtensionsInCrashReporter();
[email protected]62d30f42009-10-01 22:36:061253}
1254
[email protected]0a071a32011-02-08 00:18:241255Profile* ExtensionService::profile() {
1256 return profile_;
1257}
1258
[email protected]599539802014-01-07 23:06:001259content::BrowserContext* ExtensionService::GetBrowserContext() const {
1260 // Implemented in the .cc file to avoid adding a profile.h dependency to
1261 // extension_service.h.
1262 return profile_;
1263}
1264
[email protected]0d9a2202011-11-09 13:48:411265extensions::SettingsFrontend* ExtensionService::settings_frontend() {
[email protected]cccdf0aa2011-11-11 03:43:381266 return settings_frontend_.get();
[email protected]b7f853e282011-08-10 09:24:201267}
1268
[email protected]e2d720aa2012-05-17 00:11:351269extensions::ContentSettingsStore* ExtensionService::GetContentSettingsStore() {
[email protected]7c82539c2014-02-19 06:09:171270 return extension_prefs_->content_settings_store();
[email protected]b790b072011-05-20 09:46:441271}
1272
[email protected]25ae0152011-11-18 14:40:021273bool ExtensionService::is_ready() {
[email protected]4a10006a2013-05-17 23:18:351274 return ready_->is_signaled();
[email protected]25ae0152011-11-18 14:40:021275}
1276
[email protected]7f8f24f2012-11-15 19:40:141277base::SequencedTaskRunner* ExtensionService::GetFileTaskRunner() {
[email protected]dc24976f2013-06-02 21:15:091278 if (file_task_runner_.get())
1279 return file_task_runner_.get();
[email protected]7f8f24f2012-11-15 19:40:141280
1281 // We should be able to interrupt any part of extension install process during
1282 // shutdown. SKIP_ON_SHUTDOWN ensures that not started extension install tasks
1283 // will be ignored/deleted while we will block on started tasks.
1284 std::string token("ext_install-");
1285 token.append(profile_->GetPath().AsUTF8Unsafe());
1286 file_task_runner_ = BrowserThread::GetBlockingPool()->
1287 GetSequencedTaskRunnerWithShutdownBehavior(
1288 BrowserThread::GetBlockingPool()->GetNamedSequenceToken(token),
1289 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN);
[email protected]dc24976f2013-06-02 21:15:091290 return file_task_runner_.get();
[email protected]7f8f24f2012-11-15 19:40:141291}
1292
[email protected]42a08162012-03-16 18:09:111293extensions::ExtensionUpdater* ExtensionService::updater() {
[email protected]2859946f2011-04-04 18:18:061294 return updater_.get();
1295}
1296
[email protected]4ee07c62012-08-21 12:40:421297void ExtensionService::CheckManagementPolicy() {
[email protected]0d54b682013-11-05 14:15:361298 std::vector<std::string> to_unload;
1299 std::map<std::string, Extension::DisableReason> to_disable;
[email protected]695b5712012-12-06 23:55:281300
[email protected]0d54b682013-11-05 14:15:361301 // Loop through the extensions list, finding extensions we need to unload or
1302 // disable.
[email protected]bb1bc9b32013-12-21 03:09:141303 const ExtensionSet& extensions = registry_->enabled_extensions();
1304 for (ExtensionSet::const_iterator iter = extensions.begin();
1305 iter != extensions.end(); ++iter) {
[email protected]cadac622013-06-11 16:46:361306 const Extension* extension = (iter->get());
[email protected]4ee07c62012-08-21 12:40:421307 if (!system_->management_policy()->UserMayLoad(extension, NULL))
[email protected]0d54b682013-11-05 14:15:361308 to_unload.push_back(extension->id());
1309 Extension::DisableReason disable_reason = Extension::DISABLE_NONE;
1310 if (system_->management_policy()->MustRemainDisabled(
1311 extension, &disable_reason, NULL))
1312 to_disable[extension->id()] = disable_reason;
[email protected]aa96d3a2010-08-21 08:45:251313 }
1314
[email protected]0d54b682013-11-05 14:15:361315 for (size_t i = 0; i < to_unload.size(); ++i)
1316 UnloadExtension(to_unload[i], UnloadedExtensionInfo::REASON_DISABLE);
1317
1318 for (std::map<std::string, Extension::DisableReason>::const_iterator i =
1319 to_disable.begin(); i != to_disable.end(); ++i)
1320 DisableExtension(i->first, i->second);
[email protected]aa96d3a2010-08-21 08:45:251321}
1322
[email protected]31206602011-04-13 23:07:321323void ExtensionService::CheckForUpdatesSoon() {
[email protected]c3cfb012011-04-06 22:07:351324 if (updater()) {
[email protected]94fde232012-04-27 10:22:301325 if (AreAllExternalProvidersReady()) {
1326 updater()->CheckSoon();
1327 } else {
1328 // Sync can start updating before all the external providers are ready
1329 // during startup. Start the update as soon as those providers are ready,
1330 // but not before.
1331 update_once_all_providers_are_ready_ = true;
1332 }
[email protected]c3cfb012011-04-06 22:07:351333 } else {
[email protected]31206602011-04-13 23:07:321334 LOG(WARNING) << "CheckForUpdatesSoon() called with auto-update turned off";
[email protected]c3cfb012011-04-06 22:07:351335 }
1336}
1337
[email protected]168389f2011-12-20 17:12:481338void ExtensionService::OnExtensionMoved(
1339 const std::string& moved_extension_id,
1340 const std::string& predecessor_extension_id,
1341 const std::string& successor_extension_id) {
[email protected]74474042013-11-21 12:03:541342 extension_prefs_->app_sorting()->OnExtensionMoved(
[email protected]3569b502012-01-12 20:08:231343 moved_extension_id,
1344 predecessor_extension_id,
1345 successor_extension_id);
[email protected]168389f2011-12-20 17:12:481346
1347 const Extension* extension = GetInstalledExtension(moved_extension_id);
[email protected]f8aefb132013-10-30 09:29:521348 if (extension_sync_service_ && extension) {
1349 extension_sync_service_->SyncExtensionChangeIfNeeded(*extension);
1350 }
[email protected]168389f2011-12-20 17:12:481351}
1352
[email protected]8e4560b62011-01-14 10:09:141353// Some extensions will autoupdate themselves externally from Chrome. These
1354// are typically part of some larger client application package. To support
1355// these, the extension will register its location in the the preferences file
1356// (and also, on Windows, in the registry) and this code will periodically
1357// check that location for a .crx file, which it will then install locally if
1358// a new version is available.
1359// Errors are reported through ExtensionErrorReporter. Succcess is not
1360// reported.
[email protected]eaa7dd182010-12-14 11:09:001361void ExtensionService::CheckForExternalUpdates() {
[email protected]a29a517a2011-01-21 21:11:121362 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]8e4560b62011-01-14 10:09:141363
1364 // Note that this installation is intentionally silent (since it didn't
1365 // go through the front-end). Extensions that are registered in this
1366 // way are effectively considered 'pre-bundled', and so implicitly
1367 // trusted. In general, if something has HKLM or filesystem access,
1368 // they could install an extension manually themselves anyway.
[email protected]a29a517a2011-01-21 21:11:121369
[email protected]8e4560b62011-01-14 10:09:141370 // Ask each external extension provider to give us a call back for each
1371 // extension they know about. See OnExternalExtension(File|UpdateUrl)Found.
[email protected]5df038b2012-07-16 19:03:271372 extensions::ProviderCollection::const_iterator i;
[email protected]8e4560b62011-01-14 10:09:141373 for (i = external_extension_providers_.begin();
1374 i != external_extension_providers_.end(); ++i) {
[email protected]5df038b2012-07-16 19:03:271375 extensions::ExternalProviderInterface* provider = i->get();
[email protected]8e4560b62011-01-14 10:09:141376 provider->VisitRegisteredExtension();
1377 }
1378
[email protected]50067e52011-10-20 23:17:071379 // Do any required work that we would have done after completion of all
1380 // providers.
1381 if (external_extension_providers_.empty()) {
1382 OnAllExternalProvidersReady();
1383 }
[email protected]9f1087e2009-06-15 17:29:321384}
1385
[email protected]50067e52011-10-20 23:17:071386void ExtensionService::OnExternalProviderReady(
[email protected]5df038b2012-07-16 19:03:271387 const extensions::ExternalProviderInterface* provider) {
[email protected]a29a517a2011-01-21 21:11:121388 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]50067e52011-10-20 23:17:071389 CHECK(provider->IsReady());
[email protected]a29a517a2011-01-21 21:11:121390
1391 // An external provider has finished loading. We only take action
[email protected]8e4560b62011-01-14 10:09:141392 // if all of them are finished. So we check them first.
[email protected]94fde232012-04-27 10:22:301393 if (AreAllExternalProvidersReady())
1394 OnAllExternalProvidersReady();
1395}
1396
1397bool ExtensionService::AreAllExternalProvidersReady() const {
[email protected]5df038b2012-07-16 19:03:271398 extensions::ProviderCollection::const_iterator i;
[email protected]8e4560b62011-01-14 10:09:141399 for (i = external_extension_providers_.begin();
1400 i != external_extension_providers_.end(); ++i) {
[email protected]94fde232012-04-27 10:22:301401 if (!i->get()->IsReady())
1402 return false;
[email protected]8e4560b62011-01-14 10:09:141403 }
[email protected]94fde232012-04-27 10:22:301404 return true;
[email protected]50067e52011-10-20 23:17:071405}
1406
1407void ExtensionService::OnAllExternalProvidersReady() {
1408 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]94fde232012-04-27 10:22:301409 base::TimeDelta elapsed = base::Time::Now() - profile_->GetStartTime();
1410 UMA_HISTOGRAM_TIMES("Extension.ExternalProvidersReadyAfter", elapsed);
[email protected]50067e52011-10-20 23:17:071411
1412 // Install any pending extensions.
[email protected]94fde232012-04-27 10:22:301413 if (update_once_all_providers_are_ready_ && updater()) {
1414 update_once_all_providers_are_ready_ = false;
[email protected]4e9b59d2013-12-18 06:47:141415 extensions::ExtensionUpdater::CheckParams params;
1416 params.callback = external_updates_finished_callback_;
1417 updater()->CheckNow(params);
[email protected]8e4560b62011-01-14 10:09:141418 }
1419
1420 // Uninstall all the unclaimed extensions.
[email protected]45759612012-07-10 17:21:231421 scoped_ptr<extensions::ExtensionPrefs::ExtensionsInfo> extensions_info(
[email protected]8e4560b62011-01-14 10:09:141422 extension_prefs_->GetInstalledExtensionsInfo());
1423 for (size_t i = 0; i < extensions_info->size(); ++i) {
1424 ExtensionInfo* info = extensions_info->at(i).get();
[email protected]1d5e58b2013-01-31 08:41:401425 if (Manifest::IsExternalLocation(info->extension_location))
[email protected]8e4560b62011-01-14 10:09:141426 CheckExternalUninstall(info->extension_id);
1427 }
[email protected]e5af875f2011-10-10 21:09:141428 IdentifyAlertableExtensions();
[email protected]e5af875f2011-10-10 21:09:141429}
1430
1431void ExtensionService::IdentifyAlertableExtensions() {
1432 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1433
[email protected]07c9f2f42012-02-29 18:45:221434 // Build up the lists of extensions that require acknowledgment. If this is
1435 // the first time, grandfather extensions that would have caused
1436 // notification.
[email protected]89226982012-07-16 20:09:181437 extension_error_ui_.reset(ExtensionErrorUI::Create(this));
[email protected]e5af875f2011-10-10 21:09:141438
[email protected]a9aa5932012-01-25 08:27:401439 bool did_show_alert = false;
[email protected]89226982012-07-16 20:09:181440 if (PopulateExtensionErrorUI(extension_error_ui_.get())) {
[email protected]460c6712013-04-24 07:20:011441 if (!is_first_run_) {
[email protected]a9aa5932012-01-25 08:27:401442 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]89226982012-07-16 20:09:181443 did_show_alert = extension_error_ui_->ShowErrorInBubbleView();
[email protected]e5af875f2011-10-10 21:09:141444 } else {
1445 // First run. Just acknowledge all the extensions, silently, by
1446 // shortcutting the display of the UI and going straight to the
1447 // callback for pressing the Accept button.
[email protected]a9aa5932012-01-25 08:27:401448 HandleExtensionAlertAccept();
[email protected]e5af875f2011-10-10 21:09:141449 }
1450 }
[email protected]a9aa5932012-01-25 08:27:401451
[email protected]612a1cb12012-10-17 13:18:031452 UpdateExternalExtensionAlert();
1453
[email protected]a9aa5932012-01-25 08:27:401454 if (!did_show_alert)
[email protected]89226982012-07-16 20:09:181455 extension_error_ui_.reset();
[email protected]e5af875f2011-10-10 21:09:141456}
1457
[email protected]89226982012-07-16 20:09:181458bool ExtensionService::PopulateExtensionErrorUI(
1459 ExtensionErrorUI* extension_error_ui) {
[email protected]07c9f2f42012-02-29 18:45:221460 bool needs_alert = false;
[email protected]695b5712012-12-06 23:55:281461
1462 // Extensions that are blacklisted.
[email protected]bb1bc9b32013-12-21 03:09:141463 const ExtensionSet& blacklisted_set = registry_->blacklisted_extensions();
1464 for (ExtensionSet::const_iterator it = blacklisted_set.begin();
1465 it != blacklisted_set.end(); ++it) {
[email protected]695b5712012-12-06 23:55:281466 std::string id = (*it)->id();
1467 if (!extension_prefs_->IsBlacklistedExtensionAcknowledged(id)) {
1468 extension_error_ui->AddBlacklistedExtension(id);
1469 needs_alert = true;
1470 }
1471 }
1472
[email protected]bb1bc9b32013-12-21 03:09:141473 const ExtensionSet& enabled_set = registry_->enabled_extensions();
1474 for (ExtensionSet::const_iterator iter = enabled_set.begin();
1475 iter != enabled_set.end(); ++iter) {
[email protected]cadac622013-06-11 16:46:361476 const Extension* e = iter->get();
[email protected]695b5712012-12-06 23:55:281477
[email protected]870f5572013-12-19 12:30:151478 // Skip for extensions that have pending updates. They will be checked again
1479 // once the pending update is finished.
1480 if (pending_extension_manager()->IsIdPending(e->id()))
1481 continue;
1482
[email protected]695b5712012-12-06 23:55:281483 // Extensions disabled by policy. Note: this no longer includes blacklisted
1484 // extensions, though we still show the same UI.
[email protected]fdd679b2012-11-15 20:49:391485 if (!system_->management_policy()->UserMayLoad(e, NULL)) {
[email protected]07c9f2f42012-02-29 18:45:221486 if (!extension_prefs_->IsBlacklistedExtensionAcknowledged(e->id())) {
[email protected]89226982012-07-16 20:09:181487 extension_error_ui->AddBlacklistedExtension(e->id());
[email protected]07c9f2f42012-02-29 18:45:221488 needs_alert = true;
1489 }
1490 }
[email protected]07c9f2f42012-02-29 18:45:221491 }
[email protected]695b5712012-12-06 23:55:281492
[email protected]07c9f2f42012-02-29 18:45:221493 return needs_alert;
1494}
1495
[email protected]a9aa5932012-01-25 08:27:401496void ExtensionService::HandleExtensionAlertClosed() {
[email protected]612a1cb12012-10-17 13:18:031497 const ExtensionIdSet* extension_ids =
1498 extension_error_ui_->get_blacklisted_extension_ids();
[email protected]e5af875f2011-10-10 21:09:141499 for (ExtensionIdSet::const_iterator iter = extension_ids->begin();
1500 iter != extension_ids->end(); ++iter) {
1501 extension_prefs_->AcknowledgeBlacklistedExtension(*iter);
1502 }
[email protected]879a6092013-03-06 04:12:501503 extension_error_ui_.reset();
1504}
1505
1506void ExtensionService::HandleExtensionAlertAccept() {
[email protected]73a85e012013-04-04 10:45:301507 extension_error_ui_->Close();
[email protected]e5af875f2011-10-10 21:09:141508}
1509
[email protected]47fc70c2011-12-06 07:29:511510void ExtensionService::AcknowledgeExternalExtension(const std::string& id) {
1511 extension_prefs_->AcknowledgeExternalExtension(id);
[email protected]612a1cb12012-10-17 13:18:031512 UpdateExternalExtensionAlert();
[email protected]47fc70c2011-12-06 07:29:511513}
1514
[email protected]d96eb512012-11-01 23:44:081515bool ExtensionService::IsUnacknowledgedExternalExtension(
1516 const Extension* extension) {
[email protected]b82d18da2012-11-09 00:11:321517 if (!FeatureSwitch::prompt_for_external_extensions()->IsEnabled())
1518 return false;
1519
[email protected]1d5e58b2013-01-31 08:41:401520 return (Manifest::IsExternalLocation(extension->location()) &&
[email protected]d96eb512012-11-01 23:44:081521 !extension_prefs_->IsExternalExtensionAcknowledged(extension->id()) &&
1522 !(extension_prefs_->GetDisableReasons(extension->id()) &
1523 Extension::DISABLE_SIDELOAD_WIPEOUT));
1524}
1525
[email protected]59ee99d2013-10-11 15:46:161526void ExtensionService::ReconcileKnownDisabled() {
[email protected]60a8bc962013-12-03 03:17:271527 ExtensionIdSet known_disabled_ids;
1528 if (!extension_prefs_->GetKnownDisabled(&known_disabled_ids)) {
[email protected]bb1bc9b32013-12-21 03:09:141529 extension_prefs_->SetKnownDisabled(
1530 registry_->disabled_extensions().GetIDs());
[email protected]018a5682013-11-20 02:41:211531 UMA_HISTOGRAM_BOOLEAN("Extensions.KnownDisabledInitialized", true);
1532 return;
[email protected]59ee99d2013-10-11 15:46:161533 }
[email protected]195c1582013-10-29 18:42:231534
[email protected]bb1bc9b32013-12-21 03:09:141535 // Both |known_disabled_ids| and |extensions| are ordered (by definition
[email protected]018a5682013-11-20 02:41:211536 // of std::map and std::set). Iterate forward over both sets in parallel
1537 // to find matching IDs and disable the corresponding extensions.
[email protected]bb1bc9b32013-12-21 03:09:141538 const ExtensionSet& enabled_set = registry_->enabled_extensions();
1539 ExtensionSet::const_iterator extensions_it = enabled_set.begin();
[email protected]018a5682013-11-20 02:41:211540 ExtensionIdSet::const_iterator known_disabled_ids_it =
1541 known_disabled_ids.begin();
1542 int known_disabled_count = 0;
[email protected]bb1bc9b32013-12-21 03:09:141543 while (extensions_it != enabled_set.end() &&
[email protected]018a5682013-11-20 02:41:211544 known_disabled_ids_it != known_disabled_ids.end()) {
1545 const std::string& extension_id = extensions_it->get()->id();
1546 const int comparison = extension_id.compare(*known_disabled_ids_it);
1547 if (comparison < 0) {
1548 ++extensions_it;
1549 } else if (comparison > 0) {
1550 ++known_disabled_ids_it;
1551 } else {
1552 ++known_disabled_count;
1553 // Advance |extensions_it| immediately as it will be invalidated upon
1554 // disabling the extension it points to.
1555 ++extensions_it;
1556 ++known_disabled_ids_it;
1557 DisableExtension(extension_id, Extension::DISABLE_KNOWN_DISABLED);
1558 }
1559 }
1560 UMA_HISTOGRAM_COUNTS_100("Extensions.KnownDisabledReDisabled",
1561 known_disabled_count);
1562
[email protected]195c1582013-10-29 18:42:231563 // Update the list of known disabled to reflect every change to
1564 // |disabled_extensions_| from this point forward.
[email protected]bb1bc9b32013-12-21 03:09:141565 registry_->SetDisabledModificationCallback(
[email protected]195c1582013-10-29 18:42:231566 base::Bind(&extensions::ExtensionPrefs::SetKnownDisabled,
1567 base::Unretained(extension_prefs_)));
[email protected]59ee99d2013-10-11 15:46:161568}
1569
[email protected]89226982012-07-16 20:09:181570void ExtensionService::HandleExtensionAlertDetails() {
1571 extension_error_ui_->ShowExtensions();
[email protected]73a85e012013-04-04 10:45:301572 // ShowExtensions may cause the error UI to close synchronously, e.g. if it
1573 // causes a navigation.
1574 if (extension_error_ui_)
1575 extension_error_ui_->Close();
[email protected]6c751e72010-11-23 10:11:101576}
1577
[email protected]612a1cb12012-10-17 13:18:031578void ExtensionService::UpdateExternalExtensionAlert() {
[email protected]41070e8d2012-10-24 01:34:361579 if (!FeatureSwitch::prompt_for_external_extensions()->IsEnabled())
[email protected]612a1cb12012-10-17 13:18:031580 return;
1581
1582 const Extension* extension = NULL;
[email protected]bb1bc9b32013-12-21 03:09:141583 const ExtensionSet& disabled_extensions = registry_->disabled_extensions();
1584 for (ExtensionSet::const_iterator iter = disabled_extensions.begin();
1585 iter != disabled_extensions.end(); ++iter) {
[email protected]cadac622013-06-11 16:46:361586 const Extension* e = iter->get();
[email protected]d96eb512012-11-01 23:44:081587 if (IsUnacknowledgedExternalExtension(e)) {
1588 extension = e;
1589 break;
[email protected]612a1cb12012-10-17 13:18:031590 }
1591 }
1592
1593 if (extension) {
[email protected]d96eb512012-11-01 23:44:081594 if (!extensions::HasExternalInstallError(this)) {
1595 if (extension_prefs_->IncrementAcknowledgePromptCount(extension->id()) >
[email protected]612a1cb12012-10-17 13:18:031596 kMaxExtensionAcknowledgePromptCount) {
[email protected]d96eb512012-11-01 23:44:081597 // Stop prompting for this extension, and check if there's another
1598 // one that needs prompting.
[email protected]612a1cb12012-10-17 13:18:031599 extension_prefs_->AcknowledgeExternalExtension(extension->id());
[email protected]d96eb512012-11-01 23:44:081600 UpdateExternalExtensionAlert();
1601 UMA_HISTOGRAM_ENUMERATION("Extensions.ExternalExtensionEvent",
1602 EXTERNAL_EXTENSION_IGNORED,
1603 EXTERNAL_EXTENSION_BUCKET_BOUNDARY);
[email protected]446e37e2013-08-07 00:30:021604 if (extensions::ManifestURL::UpdatesFromGallery(extension)) {
1605 UMA_HISTOGRAM_ENUMERATION(
1606 "Extensions.ExternalExtensionEventWebstore",
1607 EXTERNAL_EXTENSION_IGNORED,
1608 EXTERNAL_EXTENSION_BUCKET_BOUNDARY);
1609 } else {
1610 UMA_HISTOGRAM_ENUMERATION(
1611 "Extensions.ExternalExtensionEventNonWebstore",
1612 EXTERNAL_EXTENSION_IGNORED,
1613 EXTERNAL_EXTENSION_BUCKET_BOUNDARY);
1614 }
[email protected]d96eb512012-11-01 23:44:081615 return;
[email protected]612a1cb12012-10-17 13:18:031616 }
[email protected]b3aa7182013-04-25 04:45:231617 if (is_first_run_)
1618 extension_prefs_->SetExternalInstallFirstRun(extension->id());
1619 // first_run is true if the extension was installed during a first run
1620 // (even if it's post-first run now).
1621 bool first_run = extension_prefs_->IsExternalInstallFirstRun(
1622 extension->id());
1623 extensions::AddExternalInstallError(this, extension, first_run);
[email protected]612a1cb12012-10-17 13:18:031624 }
1625 } else {
1626 extensions::RemoveExternalInstallError(this);
1627 }
[email protected]612a1cb12012-10-17 13:18:031628}
1629
[email protected]a9f39a312010-12-23 22:14:271630void ExtensionService::UnloadExtension(
1631 const std::string& extension_id,
[email protected]b0af4792013-10-23 09:12:131632 UnloadedExtensionInfo::Reason reason) {
[email protected]27e469a2010-01-11 20:35:091633 // Make sure the extension gets deleted after we return from this function.
[email protected]599539802014-01-07 23:06:001634 int include_mask =
1635 ExtensionRegistry::EVERYTHING & ~ExtensionRegistry::TERMINATED;
[email protected]9adb9692010-10-29 23:14:021636 scoped_refptr<const Extension> extension(
[email protected]599539802014-01-07 23:06:001637 registry_->GetExtensionById(extension_id, include_mask));
[email protected]631cf822009-05-15 07:01:251638
[email protected]fa0c96732010-11-17 00:14:231639 // This method can be called via PostTask, so the extension may have been
1640 // unloaded by the time this runs.
[email protected]dc24976f2013-06-02 21:15:091641 if (!extension.get()) {
[email protected]dd163fb02011-05-04 22:22:171642 // In case the extension may have crashed/uninstalled. Allow the profile to
1643 // clean up its RequestContexts.
[email protected]31d8f5f22012-04-02 15:22:081644 system_->UnregisterExtensionWithRequestContexts(extension_id, reason);
[email protected]fa0c96732010-11-17 00:14:231645 return;
[email protected]dd163fb02011-05-04 22:22:171646 }
[email protected]0c6da502009-08-14 22:32:391647
[email protected]1eb175082010-02-10 09:26:161648 // Keep information about the extension so that we can reload it later
1649 // even if it's not permanently installed.
1650 unloaded_extension_paths_[extension->id()] = extension->path();
1651
[email protected]f17dbd42010-08-16 23:21:101652 // Clean up if the extension is meant to be enabled after a reload.
[email protected]b914e2952013-04-26 07:10:031653 reloading_extensions_.erase(extension->id());
[email protected]f17dbd42010-08-16 23:21:101654
[email protected]bb1bc9b32013-12-21 03:09:141655 if (registry_->disabled_extensions().Contains(extension->id())) {
1656 registry_->RemoveDisabled(extension->id());
[email protected]dd163fb02011-05-04 22:22:171657 // Make sure the profile cleans up its RequestContexts when an already
1658 // disabled extension is unloaded (since they are also tracking the disabled
1659 // extensions).
[email protected]31d8f5f22012-04-02 15:22:081660 system_->UnregisterExtensionWithRequestContexts(extension_id, reason);
[email protected]45f5b7d2014-01-22 23:47:131661 // Don't send the unloaded notification. It was sent when the extension
1662 // was disabled.
[email protected]60a174a2013-08-02 20:29:281663 } else {
[email protected]bb1bc9b32013-12-21 03:09:141664 // Remove the extension from the enabled list.
1665 registry_->RemoveEnabled(extension->id());
[email protected]60a174a2013-08-02 20:29:281666 NotifyExtensionUnloaded(extension.get(), reason);
[email protected]0c6da502009-08-14 22:32:391667 }
1668
[email protected]fb789532013-08-27 02:40:211669 content::NotificationService::current()->Notify(
1670 chrome::NOTIFICATION_EXTENSION_REMOVED,
1671 content::Source<Profile>(profile_),
1672 content::Details<const Extension>(extension.get()));
[email protected]631cf822009-05-15 07:01:251673}
1674
[email protected]8b1ec202013-09-05 02:09:501675void ExtensionService::RemoveComponentExtension(
1676 const std::string& extension_id) {
1677 scoped_refptr<const Extension> extension(
1678 GetExtensionById(extension_id, false));
[email protected]b0af4792013-10-23 09:12:131679 UnloadExtension(extension_id, UnloadedExtensionInfo::REASON_UNINSTALL);
[email protected]8b1ec202013-09-05 02:09:501680 content::NotificationService::current()->Notify(
1681 chrome::NOTIFICATION_EXTENSION_UNINSTALLED,
1682 content::Source<Profile>(profile_),
1683 content::Details<const Extension>(extension.get()));
1684}
1685
[email protected]bb1bc9b32013-12-21 03:09:141686void ExtensionService::UnloadAllExtensionsForTest() {
1687 UnloadAllExtensionsInternal();
[email protected]9f1087e2009-06-15 17:29:321688}
1689
[email protected]bb1bc9b32013-12-21 03:09:141690void ExtensionService::ReloadExtensionsForTest() {
1691 // Calling UnloadAllExtensionsForTest here triggers a false-positive presubmit
1692 // warning about calling test code in production.
1693 UnloadAllExtensionsInternal();
[email protected]eac88332012-12-26 17:57:451694 component_loader_->LoadAll();
[email protected]d8c8f25f2011-11-02 18:18:011695 extensions::InstalledLoader(this).LoadAllExtensions();
[email protected]4a10006a2013-05-17 23:18:351696 // Don't call SetReadyAndNotifyListeners() since tests call this multiple
1697 // times.
[email protected]9f1087e2009-06-15 17:29:321698}
1699
[email protected]eaa7dd182010-12-14 11:09:001700void ExtensionService::GarbageCollectExtensions() {
[email protected]c04fd3dd2013-09-05 08:20:101701#if defined(OS_CHROMEOS)
1702 if (disable_garbage_collection_)
1703 return;
1704#endif
1705
[email protected]2f8757c32012-06-19 19:17:471706 if (extension_prefs_->pref_service()->ReadOnly())
1707 return;
1708
[email protected]e8107c12014-01-14 15:38:011709 bool clean_temp_dir = true;
1710
[email protected]9bd9a6862012-11-29 09:24:221711 if (pending_extension_manager()->HasPendingExtensions()) {
[email protected]e8107c12014-01-14 15:38:011712 // Don't garbage collect temp dir while there are pending installations,
1713 // which may be using the temporary installation directory. Try to garbage
1714 // collect again later.
1715 clean_temp_dir = false;
[email protected]b3a25092013-05-28 22:08:161716 base::MessageLoop::current()->PostDelayedTask(
[email protected]9bd9a6862012-11-29 09:24:221717 FROM_HERE,
1718 base::Bind(&ExtensionService::GarbageCollectExtensions, AsWeakPtr()),
1719 base::TimeDelta::FromSeconds(kGarbageCollectRetryDelay));
[email protected]9bd9a6862012-11-29 09:24:221720 }
1721
[email protected]45759612012-07-10 17:21:231722 scoped_ptr<extensions::ExtensionPrefs::ExtensionsInfo> info(
[email protected]2f8757c32012-06-19 19:17:471723 extension_prefs_->GetInstalledExtensionsInfo());
1724
[email protected]650b2d52013-02-10 03:41:451725 std::multimap<std::string, base::FilePath> extension_paths;
[email protected]2f8757c32012-06-19 19:17:471726 for (size_t i = 0; i < info->size(); ++i)
[email protected]0db124b02012-11-07 04:55:051727 extension_paths.insert(std::make_pair(info->at(i)->extension_id,
1728 info->at(i)->extension_path));
1729
[email protected]399583b2012-12-11 09:33:421730 info = extension_prefs_->GetAllDelayedInstallInfo();
[email protected]0db124b02012-11-07 04:55:051731 for (size_t i = 0; i < info->size(); ++i)
1732 extension_paths.insert(std::make_pair(info->at(i)->extension_id,
1733 info->at(i)->extension_path));
[email protected]2f8757c32012-06-19 19:17:471734
[email protected]7f8f24f2012-11-15 19:40:141735 if (!GetFileTaskRunner()->PostTask(
1736 FROM_HERE,
[email protected]2f8757c32012-06-19 19:17:471737 base::Bind(
1738 &extension_file_util::GarbageCollectExtensions,
1739 install_directory_,
[email protected]e8107c12014-01-14 15:38:011740 extension_paths,
1741 clean_temp_dir))) {
[email protected]2f8757c32012-06-19 19:17:471742 NOTREACHED();
[email protected]31bb5ee62012-09-12 22:58:401743 }
[email protected]3cf4f0992009-02-03 23:00:301744}
1745
[email protected]820d9bd2013-04-03 03:46:031746void ExtensionService::SetReadyAndNotifyListeners() {
[email protected]4a10006a2013-05-17 23:18:351747 ready_->Signal();
[email protected]820d9bd2013-04-03 03:46:031748 content::NotificationService::current()->Notify(
1749 chrome::NOTIFICATION_EXTENSIONS_READY,
1750 content::Source<Profile>(profile_),
1751 content::NotificationService::NoDetails());
1752}
1753
[email protected]eaa7dd182010-12-14 11:09:001754void ExtensionService::OnLoadedInstalledExtensions() {
[email protected]3eeddd892013-04-17 17:00:111755 if (updater_)
[email protected]93fd78f42009-07-10 16:43:171756 updater_->Start();
[email protected]fa6a9102010-11-22 15:38:501757
[email protected]bc151cf92013-02-12 04:57:261758 OnBlacklistUpdated();
[email protected]e72e8eb82009-06-18 17:21:511759}
1760
[email protected]fcb58a862012-05-01 01:03:151761void ExtensionService::AddExtension(const Extension* extension) {
[email protected]c8d407e2011-04-28 21:27:171762 // TODO(jstritar): We may be able to get rid of this branch by overriding the
1763 // default extension state to DISABLED when the --disable-extensions flag
1764 // is set (http://crbug.com/29067).
1765 if (!extensions_enabled() &&
1766 !extension->is_theme() &&
[email protected]1d5e58b2013-01-31 08:41:401767 extension->location() != Manifest::COMPONENT &&
1768 !Manifest::IsExternalLocation(extension->location())) {
[email protected]fcb58a862012-05-01 01:03:151769 return;
[email protected]330840c2012-08-29 22:21:011770 }
[email protected]c8d407e2011-04-28 21:27:171771
[email protected]b914e2952013-04-26 07:10:031772 bool is_extension_upgrade = false;
[email protected]116d40e2013-08-08 17:23:171773 bool is_extension_installed = false;
1774 const Extension* old = GetInstalledExtension(extension->id());
1775 if (old) {
1776 is_extension_installed = true;
1777 int version_compare_result =
1778 extension->version()->CompareTo(*(old->version()));
1779 is_extension_upgrade = version_compare_result > 0;
[email protected]b914e2952013-04-26 07:10:031780 // Other than for unpacked extensions, CrxInstaller should have guaranteed
1781 // that we aren't downgrading.
1782 if (!Manifest::IsUnpackedLocation(extension->location()))
[email protected]116d40e2013-08-08 17:23:171783 CHECK_GE(version_compare_result, 0);
[email protected]b914e2952013-04-26 07:10:031784 }
[email protected]45f5b7d2014-01-22 23:47:131785 system_->runtime_data()->SetBeingUpgraded(extension, is_extension_upgrade);
[email protected]c8d407e2011-04-28 21:27:171786
[email protected]1eb175082010-02-10 09:26:161787 // The extension is now loaded, remove its data from unloaded extension map.
1788 unloaded_extension_paths_.erase(extension->id());
1789
[email protected]bb7f40952011-01-13 00:21:201790 // If a terminated extension is loaded, remove it from the terminated list.
1791 UntrackTerminatedExtension(extension->id());
1792
[email protected]f17dbd42010-08-16 23:21:101793 // If the extension was disabled for a reload, then enable it.
[email protected]ca2e82022013-04-29 16:48:411794 bool reloading = reloading_extensions_.erase(extension->id()) > 0;
[email protected]f17dbd42010-08-16 23:21:101795
[email protected]b914e2952013-04-26 07:10:031796 // Check if the extension's privileges have changed and mark the
1797 // extension disabled if necessary.
[email protected]116d40e2013-08-08 17:23:171798 CheckPermissionsIncrease(extension, is_extension_installed);
[email protected]b914e2952013-04-26 07:10:031799
[email protected]116d40e2013-08-08 17:23:171800 if (is_extension_installed && !reloading) {
[email protected]ca2e82022013-04-29 16:48:411801 // To upgrade an extension in place, unload the old one and then load the
1802 // new one. ReloadExtension disables the extension, which is sufficient.
[email protected]b0af4792013-10-23 09:12:131803 UnloadExtension(extension->id(), UnloadedExtensionInfo::REASON_UPDATE);
[email protected]b914e2952013-04-26 07:10:031804 }
[email protected]0c6da502009-08-14 22:32:391805
[email protected]695b5712012-12-06 23:55:281806 if (extension_prefs_->IsExtensionBlacklisted(extension->id())) {
[email protected]ac875372013-02-28 04:36:091807 // Only prefs is checked for the blacklist. We rely on callers to check the
1808 // blacklist before calling into here, e.g. CrxInstaller checks before
[email protected]9f3c8532013-07-31 19:52:071809 // installation then threads through the install and pending install flow
1810 // of this class, and we check when loading installed extensions.
[email protected]bb1bc9b32013-12-21 03:09:141811 registry_->AddBlacklisted(extension);
[email protected]ca2e82022013-04-29 16:48:411812 } else if (!reloading &&
1813 extension_prefs_->IsExtensionDisabled(extension->id())) {
[email protected]bb1bc9b32013-12-21 03:09:141814 registry_->AddDisabled(extension);
[email protected]f8aefb132013-10-30 09:29:521815 if (extension_sync_service_)
1816 extension_sync_service_->SyncExtensionChangeIfNeeded(*extension);
[email protected]44d62b62012-04-11 00:06:031817 content::NotificationService::current()->Notify(
1818 chrome::NOTIFICATION_EXTENSION_UPDATE_DISABLED,
1819 content::Source<Profile>(profile_),
1820 content::Details<const Extension>(extension));
[email protected]62f051c2012-03-29 17:04:441821
[email protected]7e9e2422012-12-13 19:54:191822 // Show the extension disabled error if a permissions increase was the
1823 // only reason it was disabled.
1824 if (extension_prefs_->GetDisableReasons(extension->id()) ==
[email protected]44d62b62012-04-11 00:06:031825 Extension::DISABLE_PERMISSIONS_INCREASE) {
[email protected]62f051c2012-03-29 17:04:441826 extensions::AddExtensionDisabledError(this, extension);
1827 }
[email protected]ca2e82022013-04-29 16:48:411828 } else if (reloading) {
1829 // Replace the old extension with the new version.
[email protected]bb1bc9b32013-12-21 03:09:141830 CHECK(!registry_->AddDisabled(extension));
[email protected]ca2e82022013-04-29 16:48:411831 EnableExtension(extension->id());
[email protected]695b5712012-12-06 23:55:281832 } else {
1833 // All apps that are displayed in the launcher are ordered by their ordinals
1834 // so we must ensure they have valid ordinals.
1835 if (extension->RequiresSortOrdinal()) {
[email protected]bd36b652013-02-27 02:13:251836 if (!extension->ShouldDisplayInNewTabPage()) {
[email protected]74474042013-11-21 12:03:541837 extension_prefs_->app_sorting()->MarkExtensionAsHidden(extension->id());
[email protected]bd36b652013-02-27 02:13:251838 }
[email protected]74474042013-11-21 12:03:541839 extension_prefs_->app_sorting()->EnsureValidOrdinals(
[email protected]695b5712012-12-06 23:55:281840 extension->id(), syncer::StringOrdinal());
1841 }
1842
[email protected]bb1bc9b32013-12-21 03:09:141843 registry_->AddEnabled(extension);
[email protected]f8aefb132013-10-30 09:29:521844 if (extension_sync_service_)
1845 extension_sync_service_->SyncExtensionChangeIfNeeded(*extension);
[email protected]695b5712012-12-06 23:55:281846 NotifyExtensionLoaded(extension);
[email protected]f574c402012-12-04 23:20:311847 }
[email protected]45f5b7d2014-01-22 23:47:131848 system_->runtime_data()->SetBeingUpgraded(extension, false);
[email protected]aab98a52009-12-02 03:22:351849}
1850
[email protected]8c484b742012-11-29 06:05:361851void ExtensionService::AddComponentExtension(const Extension* extension) {
1852 const std::string old_version_string(
1853 extension_prefs_->GetVersionString(extension->id()));
[email protected]c5e4a2222014-01-03 16:06:131854 const Version old_version(old_version_string);
[email protected]8c484b742012-11-29 06:05:361855
[email protected]0181a7d2013-11-12 01:08:421856 VLOG(1) << "AddComponentExtension " << extension->name();
[email protected]8c484b742012-11-29 06:05:361857 if (!old_version.IsValid() || !old_version.Equals(*extension->version())) {
1858 VLOG(1) << "Component extension " << extension->name() << " ("
1859 << extension->id() << ") installing/upgrading from '"
1860 << old_version_string << "' to " << extension->version()->GetString();
1861
1862 AddNewOrUpdatedExtension(extension,
[email protected]399583b2012-12-11 09:33:421863 Extension::ENABLED_COMPONENT,
[email protected]8e289f0b2013-12-17 17:49:071864 extensions::NOT_BLACKLISTED,
[email protected]399583b2012-12-11 09:33:421865 syncer::StringOrdinal());
[email protected]8c484b742012-11-29 06:05:361866 return;
1867 }
1868
1869 AddExtension(extension);
1870}
1871
[email protected]b914e2952013-04-26 07:10:031872void ExtensionService::UpdateActivePermissions(const Extension* extension) {
[email protected]902fd7b2011-07-27 18:42:311873 // If the extension has used the optional permissions API, it will have a
1874 // custom set of active permissions defined in the extension prefs. Here,
1875 // we update the extension's active permissions based on the prefs.
[email protected]c2e66e12012-06-27 06:27:061876 scoped_refptr<PermissionSet> active_permissions =
[email protected]7c82539c2014-02-19 06:09:171877 extension_prefs_->GetActivePermissions(extension->id());
[email protected]902fd7b2011-07-27 18:42:311878
[email protected]dc24976f2013-06-02 21:15:091879 if (active_permissions.get()) {
[email protected]902fd7b2011-07-27 18:42:311880 // We restrict the active permissions to be within the bounds defined in the
1881 // extension's manifest.
1882 // a) active permissions must be a subset of optional + default permissions
1883 // b) active permissions must contains all default permissions
[email protected]c2e66e12012-06-27 06:27:061884 scoped_refptr<PermissionSet> total_permissions =
1885 PermissionSet::CreateUnion(
[email protected]2cb5e302013-05-09 05:00:061886 extensions::PermissionsData::GetRequiredPermissions(extension),
1887 extensions::PermissionsData::GetOptionalPermissions(extension));
[email protected]902fd7b2011-07-27 18:42:311888
1889 // Make sure the active permissions contain no more than optional + default.
[email protected]c2e66e12012-06-27 06:27:061890 scoped_refptr<PermissionSet> adjusted_active =
1891 PermissionSet::CreateIntersection(
[email protected]902fd7b2011-07-27 18:42:311892 total_permissions.get(), active_permissions.get());
1893
1894 // Make sure the active permissions contain the default permissions.
[email protected]c2e66e12012-06-27 06:27:061895 adjusted_active = PermissionSet::CreateUnion(
[email protected]2cb5e302013-05-09 05:00:061896 extensions::PermissionsData::GetRequiredPermissions(extension),
1897 adjusted_active.get());
[email protected]902fd7b2011-07-27 18:42:311898
[email protected]c333e792012-01-06 16:57:391899 extensions::PermissionsUpdater perms_updater(profile());
[email protected]dc24976f2013-06-02 21:15:091900 perms_updater.UpdateActivePermissions(extension, adjusted_active.get());
[email protected]902fd7b2011-07-27 18:42:311901 }
[email protected]b914e2952013-04-26 07:10:031902}
1903
1904void ExtensionService::CheckPermissionsIncrease(const Extension* extension,
[email protected]116d40e2013-08-08 17:23:171905 bool is_extension_installed) {
[email protected]b914e2952013-04-26 07:10:031906 UpdateActivePermissions(extension);
[email protected]902fd7b2011-07-27 18:42:311907
[email protected]8d888c12010-11-30 00:00:251908 // We keep track of all permissions the user has granted each extension.
1909 // This allows extensions to gracefully support backwards compatibility
1910 // by including unknown permissions in their manifests. When the user
1911 // installs the extension, only the recognized permissions are recorded.
1912 // When the unknown permissions become recognized (e.g., through browser
1913 // upgrade), we can prompt the user to accept these new permissions.
1914 // Extensions can also silently upgrade to less permissions, and then
1915 // silently upgrade to a version that adds these permissions back.
1916 //
1917 // For example, pretend that Chrome 10 includes a permission "omnibox"
1918 // for an API that adds suggestions to the omnibox. An extension can
1919 // maintain backwards compatibility while still having "omnibox" in the
1920 // manifest. If a user installs the extension on Chrome 9, the browser
1921 // will record the permissions it recognized, not including "omnibox."
1922 // When upgrading to Chrome 10, "omnibox" will be recognized and Chrome
1923 // will disable the extension and prompt the user to approve the increase
1924 // in privileges. The extension could then release a new version that
1925 // removes the "omnibox" permission. When the user upgrades, Chrome will
1926 // still remember that "omnibox" had been granted, so that if the
1927 // extension once again includes "omnibox" in an upgrade, the extension
1928 // can upgrade without requiring this user's approval.
[email protected]eb5e4f92012-08-15 23:33:281929 int disable_reasons = extension_prefs_->GetDisableReasons(extension->id());
[email protected]8d888c12010-11-30 00:00:251930
[email protected]211a3f32013-05-28 21:48:181931 bool auto_grant_permission =
[email protected]1b563df2013-10-30 16:49:361932 (!is_extension_installed && extension->was_installed_by_default()) ||
[email protected]45928b682013-11-28 08:20:271933 extensions::ExtensionsBrowserClient::Get()->IsRunningInForcedAppMode();
[email protected]b914e2952013-04-26 07:10:031934 // Silently grant all active permissions to default apps only on install.
1935 // After install they should behave like other apps.
[email protected]211a3f32013-05-28 21:48:181936 // Silently grant all active permissions to apps install in kiosk mode on both
1937 // install and update.
1938 if (auto_grant_permission)
[email protected]b914e2952013-04-26 07:10:031939 GrantPermissions(extension);
1940
1941 bool is_privilege_increase = false;
1942 // We only need to compare the granted permissions to the current permissions
1943 // if the extension is not allowed to silently increase its permissions.
[email protected]13c68b62013-05-17 11:29:051944 if (!extensions::PermissionsData::CanSilentlyIncreasePermissions(extension) &&
[email protected]211a3f32013-05-28 21:48:181945 !auto_grant_permission) {
[email protected]8d888c12010-11-30 00:00:251946 // Add all the recognized permissions if the granted permissions list
1947 // hasn't been initialized yet.
[email protected]c2e66e12012-06-27 06:27:061948 scoped_refptr<PermissionSet> granted_permissions =
[email protected]902fd7b2011-07-27 18:42:311949 extension_prefs_->GetGrantedPermissions(extension->id());
[email protected]0d3e4a22011-06-23 19:02:521950 CHECK(granted_permissions.get());
[email protected]8d888c12010-11-30 00:00:251951
1952 // Here, we check if an extension's privileges have increased in a manner
1953 // that requires the user's approval. This could occur because the browser
1954 // upgraded and recognized additional privileges, or an extension upgrades
1955 // to a version that requires additional privileges.
[email protected]c41003472013-10-19 15:37:251956 is_privilege_increase =
1957 extensions::PermissionMessageProvider::Get()->IsPrivilegeIncrease(
1958 granted_permissions,
1959 extension->GetActivePermissions().get(),
1960 extension->GetType());
[email protected]8d888c12010-11-30 00:00:251961 }
1962
[email protected]116d40e2013-08-08 17:23:171963 if (is_extension_installed) {
[email protected]44d62b62012-04-11 00:06:031964 // If the extension was already disabled, suppress any alerts for becoming
1965 // disabled on permissions increase.
[email protected]b914e2952013-04-26 07:10:031966 bool previously_disabled =
1967 extension_prefs_->IsExtensionDisabled(extension->id());
[email protected]7e9e2422012-12-13 19:54:191968 // Legacy disabled extensions do not have a disable reason. Infer that if
1969 // there was no permission increase, it was likely disabled by the user.
1970 if (previously_disabled && disable_reasons == Extension::DISABLE_NONE &&
[email protected]b914e2952013-04-26 07:10:031971 !extension_prefs_->DidExtensionEscalatePermissions(extension->id())) {
[email protected]7e9e2422012-12-13 19:54:191972 disable_reasons |= Extension::DISABLE_USER_ACTION;
[email protected]44d62b62012-04-11 00:06:031973 }
[email protected]7e9e2422012-12-13 19:54:191974 // Extensions that came to us disabled from sync need a similar inference,
1975 // except based on the new version's permissions.
1976 if (previously_disabled &&
1977 disable_reasons == Extension::DISABLE_UNKNOWN_FROM_SYNC) {
1978 // Remove the DISABLE_UNKNOWN_FROM_SYNC reason.
1979 extension_prefs_->ClearDisableReasons(extension->id());
1980 if (!is_privilege_increase)
1981 disable_reasons |= Extension::DISABLE_USER_ACTION;
1982 }
[email protected]b914e2952013-04-26 07:10:031983 disable_reasons &= ~Extension::DISABLE_UNKNOWN_FROM_SYNC;
[email protected]8d888c12010-11-30 00:00:251984 }
1985
1986 // Extension has changed permissions significantly. Disable it. A
1987 // notification should be sent by the caller.
1988 if (is_privilege_increase) {
[email protected]7e9e2422012-12-13 19:54:191989 disable_reasons |= Extension::DISABLE_PERMISSIONS_INCREASE;
[email protected]fe2dd7742011-04-19 22:52:491990 if (!extension_prefs_->DidExtensionEscalatePermissions(extension->id())) {
1991 RecordPermissionMessagesHistogram(
1992 extension, "Extensions.Permissions_AutoDisable");
1993 }
[email protected]195c1582013-10-29 18:42:231994 extension_prefs_->SetExtensionState(extension->id(), Extension::DISABLED);
[email protected]8d888c12010-11-30 00:00:251995 extension_prefs_->SetDidExtensionEscalatePermissions(extension, true);
[email protected]b914e2952013-04-26 07:10:031996 }
1997 if (disable_reasons != Extension::DISABLE_NONE) {
[email protected]eb5e4f92012-08-15 23:33:281998 extension_prefs_->AddDisableReason(
1999 extension->id(),
2000 static_cast<Extension::DisableReason>(disable_reasons));
[email protected]8d888c12010-11-30 00:00:252001 }
2002}
2003
[email protected]eaa7dd182010-12-14 11:09:002004void ExtensionService::UpdateActiveExtensionsInCrashReporter() {
[email protected]c8865962009-12-16 07:47:392005 std::set<std::string> extension_ids;
[email protected]bb1bc9b32013-12-21 03:09:142006 const ExtensionSet& extensions = registry_->enabled_extensions();
2007 for (ExtensionSet::const_iterator iter = extensions.begin();
2008 iter != extensions.end(); ++iter) {
[email protected]cadac622013-06-11 16:46:362009 const Extension* extension = iter->get();
[email protected]1d5e58b2013-01-31 08:41:402010 if (!extension->is_theme() && extension->location() != Manifest::COMPONENT)
[email protected]84df8332011-12-06 18:22:462011 extension_ids.insert(extension->id());
[email protected]aab98a52009-12-02 03:22:352012 }
2013
[email protected]f6431be82013-09-07 02:53:452014 crash_keys::SetActiveExtensions(extension_ids);
[email protected]6014d672008-12-05 00:38:252015}
2016
[email protected]669b2372013-10-17 15:04:582017ExtensionService::ImportStatus ExtensionService::CheckImports(
2018 const extensions::Extension* extension,
2019 std::list<SharedModuleInfo::ImportInfo>* missing_modules,
2020 std::list<SharedModuleInfo::ImportInfo>* outdated_modules) {
2021 DCHECK(extension);
2022 DCHECK(missing_modules && missing_modules->empty());
2023 DCHECK(outdated_modules && outdated_modules->empty());
[email protected]9f4e4f082013-06-21 07:11:192024 ImportStatus status = IMPORT_STATUS_OK;
[email protected]9f4e4f082013-06-21 07:11:192025 if (SharedModuleInfo::ImportsModules(extension)) {
2026 const std::vector<SharedModuleInfo::ImportInfo>& imports =
2027 SharedModuleInfo::GetImports(extension);
2028 std::vector<SharedModuleInfo::ImportInfo>::const_iterator i;
2029 for (i = imports.begin(); i != imports.end(); ++i) {
[email protected]c5e4a2222014-01-03 16:06:132030 Version version_required(i->minimum_version);
[email protected]9f4e4f082013-06-21 07:11:192031 const Extension* imported_module =
2032 GetExtensionById(i->extension_id, true);
2033 if (!imported_module) {
2034 if (extension->from_webstore()) {
2035 status = IMPORT_STATUS_UNSATISFIED;
[email protected]669b2372013-10-17 15:04:582036 missing_modules->push_back(*i);
[email protected]9f4e4f082013-06-21 07:11:192037 } else {
2038 return IMPORT_STATUS_UNRECOVERABLE;
2039 }
2040 } else if (!SharedModuleInfo::IsSharedModule(imported_module)) {
2041 return IMPORT_STATUS_UNRECOVERABLE;
2042 } else if (version_required.IsValid() &&
2043 imported_module->version()->CompareTo(version_required) < 0) {
2044 if (imported_module->from_webstore()) {
[email protected]669b2372013-10-17 15:04:582045 outdated_modules->push_back(*i);
[email protected]9f4e4f082013-06-21 07:11:192046 status = IMPORT_STATUS_UNSATISFIED;
2047 } else {
2048 return IMPORT_STATUS_UNRECOVERABLE;
2049 }
2050 }
2051 }
2052 }
[email protected]669b2372013-10-17 15:04:582053 return status;
2054}
2055
2056ExtensionService::ImportStatus ExtensionService::SatisfyImports(
2057 const Extension* extension) {
2058 std::list<SharedModuleInfo::ImportInfo> noinstalled;
2059 std::list<SharedModuleInfo::ImportInfo> outdated;
2060 ImportStatus status = CheckImports(extension, &noinstalled, &outdated);
2061 if (status == IMPORT_STATUS_UNRECOVERABLE)
2062 return status;
[email protected]9f4e4f082013-06-21 07:11:192063 if (status == IMPORT_STATUS_UNSATISFIED) {
[email protected]669b2372013-10-17 15:04:582064 std::list<SharedModuleInfo::ImportInfo>::const_iterator iter;
2065 for (iter = noinstalled.begin(); iter != noinstalled.end(); ++iter) {
[email protected]9f4e4f082013-06-21 07:11:192066 pending_extension_manager()->AddFromExtensionImport(
[email protected]669b2372013-10-17 15:04:582067 iter->extension_id,
[email protected]9f4e4f082013-06-21 07:11:192068 extension_urls::GetWebstoreUpdateUrl(),
2069 IsSharedModule);
2070 }
2071 CheckForUpdatesSoon();
2072 }
2073 return status;
2074}
2075
2076scoped_ptr<const ExtensionSet>
2077 ExtensionService::GetDependentExtensions(const Extension* extension) {
2078 scoped_ptr<ExtensionSet> dependents(new ExtensionSet());
2079 scoped_ptr<ExtensionSet> set_to_check(new ExtensionSet());
2080 if (SharedModuleInfo::IsSharedModule(extension)) {
[email protected]bb1bc9b32013-12-21 03:09:142081 set_to_check->InsertAll(registry_->disabled_extensions());
[email protected]9f4e4f082013-06-21 07:11:192082 set_to_check->InsertAll(delayed_installs_);
[email protected]bb1bc9b32013-12-21 03:09:142083 set_to_check->InsertAll(registry_->enabled_extensions());
[email protected]9f4e4f082013-06-21 07:11:192084 for (ExtensionSet::const_iterator iter = set_to_check->begin();
2085 iter != set_to_check->end(); ++iter) {
[email protected]198b5902013-06-27 10:36:112086 if (SharedModuleInfo::ImportsExtensionById(iter->get(),
2087 extension->id())) {
[email protected]9f4e4f082013-06-21 07:11:192088 dependents->Insert(*iter);
2089 }
2090 }
2091 }
2092 return dependents.PassAs<const ExtensionSet>();
2093}
2094
2095void ExtensionService::PruneSharedModulesOnUninstall(
2096 const Extension* extension) {
2097 if (SharedModuleInfo::ImportsModules(extension)) {
2098 const std::vector<SharedModuleInfo::ImportInfo>& imports =
2099 SharedModuleInfo::GetImports(extension);
2100 std::vector<SharedModuleInfo::ImportInfo>::const_iterator i;
2101 for (i = imports.begin(); i != imports.end(); ++i) {
2102 const Extension* imported_module =
2103 GetExtensionById(i->extension_id, true);
2104 if (imported_module && imported_module->from_webstore()) {
2105 scoped_ptr<const ExtensionSet> dependents =
2106 GetDependentExtensions(imported_module);
2107 if (dependents->size() == 0) {
[email protected]4c9201c42013-08-16 04:56:212108 UninstallExtension(i->extension_id, true, NULL);
[email protected]9f4e4f082013-06-21 07:11:192109 }
2110 }
2111 }
2112 }
2113}
2114
[email protected]8266d662011-07-12 21:53:262115void ExtensionService::OnExtensionInstalled(
[email protected]36a5c4c2011-12-14 16:34:502116 const Extension* extension,
[email protected]98270432012-09-11 20:51:242117 const syncer::StringOrdinal& page_ordinal,
[email protected]0db124b02012-11-07 04:55:052118 bool has_requirement_errors,
[email protected]8e289f0b2013-12-17 17:49:072119 extensions::BlacklistState blacklist_state,
[email protected]0db124b02012-11-07 04:55:052120 bool wait_for_idle) {
[email protected]a29a517a2011-01-21 21:11:122121 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]a8af9fdb2010-10-28 21:52:202122
[email protected]c3cfb012011-04-06 22:07:352123 const std::string& id = extension->id();
[email protected]612a1cb12012-10-17 13:18:032124 bool initial_enable = ShouldEnableOnInstall(extension);
[email protected]3f213ad2012-07-26 23:39:412125 const extensions::PendingExtensionInfo* pending_extension_info = NULL;
[email protected]51a3bf8b2012-06-08 22:53:062126 if ((pending_extension_info = pending_extension_manager()->GetById(id))) {
[email protected]8f3bcbd2013-06-05 08:42:402127 if (!pending_extension_info->ShouldAllowInstall(extension)) {
[email protected]51a3bf8b2012-06-08 22:53:062128 pending_extension_manager()->Remove(id);
[email protected]8ef78fd2010-08-19 17:14:322129
[email protected]31bb5ee62012-09-12 22:58:402130 LOG(WARNING) << "ShouldAllowInstall() returned false for "
2131 << id << " of type " << extension->GetType()
[email protected]65348062013-01-15 07:27:222132 << " and update URL "
2133 << extensions::ManifestURL::GetUpdateURL(extension).spec()
[email protected]31bb5ee62012-09-12 22:58:402134 << "; not installing";
[email protected]ae6cb3022011-04-04 20:11:542135
[email protected]4416c5a2010-06-26 01:28:572136 // Delete the extension directory since we're not going to
2137 // load it.
[email protected]7f8f24f2012-11-15 19:40:142138 if (!GetFileTaskRunner()->PostTask(
2139 FROM_HERE,
[email protected]53612e82011-10-18 18:00:362140 base::Bind(&extension_file_util::DeleteFile,
[email protected]31bb5ee62012-09-12 22:58:402141 extension->path(), true))) {
[email protected]14908b72011-04-20 06:54:362142 NOTREACHED();
[email protected]31bb5ee62012-09-12 22:58:402143 }
[email protected]4416c5a2010-06-26 01:28:572144 return;
2145 }
[email protected]51a3bf8b2012-06-08 22:53:062146
2147 pending_extension_manager()->Remove(id);
[email protected]4416c5a2010-06-26 01:28:572148 } else {
[email protected]c3cfb012011-04-06 22:07:352149 // We explicitly want to re-enable an uninstalled external
2150 // extension; if we're here, that means the user is manually
2151 // installing the extension.
[email protected]6cc7dbae2011-04-29 21:18:332152 if (IsExternalExtensionUninstalled(id)) {
2153 initial_enable = true;
2154 }
[email protected]aa142702010-03-26 01:26:332155 }
2156
[email protected]98270432012-09-11 20:51:242157 // Unsupported requirements overrides the management policy.
2158 if (has_requirement_errors) {
2159 initial_enable = false;
2160 extension_prefs_->AddDisableReason(
2161 id, Extension::DISABLE_UNSUPPORTED_REQUIREMENT);
2162 // If the extension was disabled because of unsupported requirements but
2163 // now supports all requirements after an update and there are not other
2164 // disable reasons, enable it.
2165 } else if (extension_prefs_->GetDisableReasons(id) ==
2166 Extension::DISABLE_UNSUPPORTED_REQUIREMENT) {
2167 initial_enable = true;
2168 extension_prefs_->ClearDisableReasons(id);
2169 }
2170
[email protected]8e289f0b2013-12-17 17:49:072171 if (blacklist_state == extensions::BLACKLISTED_MALWARE) {
[email protected]9f3c8532013-07-31 19:52:072172 // Installation of a blacklisted extension can happen from sync, policy,
2173 // etc, where to maintain consistency we need to install it, just never
2174 // load it (see AddExtension). Usually it should be the job of callers to
2175 // incercept blacklisted extension earlier (e.g. CrxInstaller, before even
2176 // showing the install dialogue).
[email protected]7c82539c2014-02-19 06:09:172177 extension_prefs_->AcknowledgeBlacklistedExtension(id);
[email protected]9f3c8532013-07-31 19:52:072178 UMA_HISTOGRAM_ENUMERATION("ExtensionBlacklist.SilentInstall",
2179 extension->location(),
2180 Manifest::NUM_LOCATIONS);
2181 }
2182
[email protected]695b5712012-12-06 23:55:282183 if (!GetInstalledExtension(extension->id())) {
[email protected]07533022011-06-27 20:42:552184 UMA_HISTOGRAM_ENUMERATION("Extensions.InstallType",
2185 extension->GetType(), 100);
[email protected]69084dc2012-11-17 07:39:302186 UMA_HISTOGRAM_ENUMERATION("Extensions.InstallSource",
[email protected]1d5e58b2013-01-31 08:41:402187 extension->location(), Manifest::NUM_LOCATIONS);
[email protected]07533022011-06-27 20:42:552188 RecordPermissionMessagesHistogram(
2189 extension, "Extensions.Permissions_Install");
[email protected]69084dc2012-11-17 07:39:302190 } else {
2191 UMA_HISTOGRAM_ENUMERATION("Extensions.UpdateType",
2192 extension->GetType(), 100);
2193 UMA_HISTOGRAM_ENUMERATION("Extensions.UpdateSource",
[email protected]1d5e58b2013-01-31 08:41:402194 extension->location(), Manifest::NUM_LOCATIONS);
[email protected]07533022011-06-27 20:42:552195 }
2196
[email protected]a39921b42012-02-28 03:42:542197 // Certain extension locations are specific enough that we can
2198 // auto-acknowledge any extension that came from one of them.
[email protected]4eef4352014-02-12 02:21:362199 if (Manifest::IsPolicyLocation(extension->location()) ||
2200 extension->location() == Manifest::EXTERNAL_COMPONENT)
[email protected]a39921b42012-02-28 03:42:542201 AcknowledgeExternalExtension(extension->id());
[email protected]399583b2012-12-11 09:33:422202 const Extension::State initial_state =
2203 initial_enable ? Extension::ENABLED : Extension::DISABLED;
[email protected]0f9e6262013-11-05 23:49:192204 const bool blacklisted_for_malware =
[email protected]8e289f0b2013-12-17 17:49:072205 blacklist_state == extensions::BLACKLISTED_MALWARE;
[email protected]e7aa7b7e2012-11-27 04:51:222206 if (ShouldDelayExtensionUpdate(id, wait_for_idle)) {
[email protected]9f3c8532013-07-31 19:52:072207 extension_prefs_->SetDelayedInstallInfo(
2208 extension,
2209 initial_state,
[email protected]0f9e6262013-11-05 23:49:192210 blacklisted_for_malware,
[email protected]9f3c8532013-07-31 19:52:072211 extensions::ExtensionPrefs::DELAY_REASON_WAIT_FOR_IDLE,
2212 page_ordinal);
[email protected]0db124b02012-11-07 04:55:052213
2214 // Transfer ownership of |extension|.
[email protected]9f4e4f082013-06-21 07:11:192215 delayed_installs_.Insert(extension);
[email protected]0db124b02012-11-07 04:55:052216
[email protected]75bdcb872013-03-13 00:41:452217 // Notify observers that app update is available.
2218 FOR_EACH_OBSERVER(extensions::UpdateObserver, update_observers_,
[email protected]a9aa62b312013-11-29 05:35:062219 OnAppUpdateAvailable(extension));
[email protected]0db124b02012-11-07 04:55:052220 return;
2221 }
2222
[email protected]9f4e4f082013-06-21 07:11:192223 ImportStatus status = SatisfyImports(extension);
2224 if (installs_delayed_for_gc()) {
[email protected]9f3c8532013-07-31 19:52:072225 extension_prefs_->SetDelayedInstallInfo(
2226 extension,
2227 initial_state,
[email protected]0f9e6262013-11-05 23:49:192228 blacklisted_for_malware,
[email protected]9f3c8532013-07-31 19:52:072229 extensions::ExtensionPrefs::DELAY_REASON_GC,
2230 page_ordinal);
[email protected]399583b2012-12-11 09:33:422231 delayed_installs_.Insert(extension);
[email protected]9f4e4f082013-06-21 07:11:192232 } else if (status != IMPORT_STATUS_OK) {
2233 if (status == IMPORT_STATUS_UNSATISFIED) {
[email protected]9f3c8532013-07-31 19:52:072234 extension_prefs_->SetDelayedInstallInfo(
2235 extension,
2236 initial_state,
[email protected]0f9e6262013-11-05 23:49:192237 blacklisted_for_malware,
[email protected]9f4e4f082013-06-21 07:11:192238 extensions::ExtensionPrefs::DELAY_REASON_WAIT_FOR_IMPORTS,
2239 page_ordinal);
2240 delayed_installs_.Insert(extension);
2241 }
[email protected]399583b2012-12-11 09:33:422242 } else {
[email protected]9f3c8532013-07-31 19:52:072243 AddNewOrUpdatedExtension(extension,
2244 initial_state,
2245 blacklist_state,
2246 page_ordinal);
[email protected]399583b2012-12-11 09:33:422247 }
[email protected]8c484b742012-11-29 06:05:362248}
2249
2250void ExtensionService::AddNewOrUpdatedExtension(
2251 const Extension* extension,
[email protected]399583b2012-12-11 09:33:422252 Extension::State initial_state,
[email protected]8e289f0b2013-12-17 17:49:072253 extensions::BlacklistState blacklist_state,
[email protected]399583b2012-12-11 09:33:422254 const syncer::StringOrdinal& page_ordinal) {
[email protected]8c484b742012-11-29 06:05:362255 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]0f9e6262013-11-05 23:49:192256 const bool blacklisted_for_malware =
[email protected]8e289f0b2013-12-17 17:49:072257 blacklist_state == extensions::BLACKLISTED_MALWARE;
[email protected]9f3c8532013-07-31 19:52:072258 extension_prefs_->OnExtensionInstalled(extension,
2259 initial_state,
[email protected]0f9e6262013-11-05 23:49:192260 blacklisted_for_malware,
[email protected]9f3c8532013-07-31 19:52:072261 page_ordinal);
[email protected]9e9c1d12013-07-31 01:58:122262 delayed_installs_.Remove(extension->id());
[email protected]88622932014-01-16 17:59:122263 if (InstallVerifier::NeedsVerification(*extension)) {
[email protected]ffd2f79e2013-11-14 00:11:462264 extensions::ExtensionSystem::Get(profile_)->install_verifier()->Add(
[email protected]74564482014-01-30 13:55:422265 extension->id(), base::Bind(LogAddVerifiedSuccess));
[email protected]ffd2f79e2013-11-14 00:11:462266 }
[email protected]6f6101832012-11-27 22:10:482267 FinishInstallation(extension);
2268}
2269
2270void ExtensionService::MaybeFinishDelayedInstallation(
2271 const std::string& extension_id) {
[email protected]9f4e4f082013-06-21 07:11:192272 // Check if the extension already got installed.
2273 if (!delayed_installs_.Contains(extension_id))
[email protected]6f6101832012-11-27 22:10:482274 return;
[email protected]9f4e4f082013-06-21 07:11:192275 extensions::ExtensionPrefs::DelayReason reason =
2276 extension_prefs_->GetDelayedInstallReason(extension_id);
2277
2278 // Check if the extension is idle. DELAY_REASON_NONE is used for older
2279 // preferences files that will not have set this field but it was previously
2280 // only used for idle updates.
2281 if ((reason == extensions::ExtensionPrefs::DELAY_REASON_WAIT_FOR_IDLE ||
2282 reason == extensions::ExtensionPrefs::DELAY_REASON_NONE) &&
[email protected]1d5cf4142014-01-24 18:25:222283 is_ready() && !extensions::util::IsExtensionIdle(extension_id, profile_))
[email protected]6f6101832012-11-27 22:10:482284 return;
2285
[email protected]9f4e4f082013-06-21 07:11:192286 const Extension* extension = delayed_installs_.GetByID(extension_id);
2287 if (reason == extensions::ExtensionPrefs::DELAY_REASON_WAIT_FOR_IMPORTS) {
2288 ImportStatus status = SatisfyImports(extension);
2289 if (status != IMPORT_STATUS_OK) {
2290 if (status == IMPORT_STATUS_UNRECOVERABLE) {
2291 delayed_installs_.Remove(extension_id);
2292 // Make sure no version of the extension is actually installed, (i.e.,
2293 // that this delayed install was not an update).
2294 CHECK(!extension_prefs_->GetInstalledExtensionInfo(extension_id).get());
2295 extension_prefs_->DeleteExtensionPrefs(extension_id);
2296 }
2297 return;
2298 }
2299 }
2300
[email protected]6f6101832012-11-27 22:10:482301 FinishDelayedInstallation(extension_id);
2302}
2303
2304void ExtensionService::FinishDelayedInstallation(
2305 const std::string& extension_id) {
2306 scoped_refptr<const Extension> extension(
2307 GetPendingExtensionUpdate(extension_id));
[email protected]dc24976f2013-06-02 21:15:092308 CHECK(extension.get());
[email protected]9f4e4f082013-06-21 07:11:192309 delayed_installs_.Remove(extension_id);
[email protected]6f6101832012-11-27 22:10:482310
[email protected]399583b2012-12-11 09:33:422311 if (!extension_prefs_->FinishDelayedInstallInfo(extension_id))
[email protected]6f6101832012-11-27 22:10:482312 NOTREACHED();
2313
[email protected]dc24976f2013-06-02 21:15:092314 FinishInstallation(extension.get());
[email protected]6f6101832012-11-27 22:10:482315}
2316
2317void ExtensionService::FinishInstallation(const Extension* extension) {
[email protected]e7554c3f2013-05-29 00:36:562318 const extensions::Extension* existing_extension =
2319 GetInstalledExtension(extension->id());
2320 bool is_update = false;
2321 std::string old_name;
2322 if (existing_extension) {
2323 is_update = true;
2324 old_name = existing_extension->name();
2325 }
2326 extensions::InstalledExtensionInfo details(extension, is_update, old_name);
[email protected]fcb58a862012-05-01 01:03:152327 content::NotificationService::current()->Notify(
2328 chrome::NOTIFICATION_EXTENSION_INSTALLED,
2329 content::Source<Profile>(profile_),
[email protected]41bb80bd2013-05-03 10:56:022330 content::Details<const extensions::InstalledExtensionInfo>(&details));
[email protected]fcb58a862012-05-01 01:03:152331
[email protected]d96eb512012-11-01 23:44:082332 bool unacknowledged_external = IsUnacknowledgedExternalExtension(extension);
[email protected]41070e8d2012-10-24 01:34:362333
[email protected]399583b2012-12-11 09:33:422334 // Unpacked extensions default to allowing file access, but if that has been
2335 // overridden, don't reset the value.
[email protected]1d5e58b2013-01-31 08:41:402336 if (Manifest::ShouldAlwaysAllowFileAccess(extension->location()) &&
[email protected]399583b2012-12-11 09:33:422337 !extension_prefs_->HasAllowFileAccessSetting(extension->id())) {
2338 extension_prefs_->SetAllowFileAccess(extension->id(), true);
2339 }
2340
[email protected]6f6101832012-11-27 22:10:482341 AddExtension(extension);
[email protected]612a1cb12012-10-17 13:18:032342
2343 // If this is a new external extension that was disabled, alert the user
[email protected]d96eb512012-11-01 23:44:082344 // so he can reenable it. We do this last so that it has already been
2345 // added to our list of extensions.
[email protected]3e3fafbb2013-08-17 13:33:162346 if (unacknowledged_external && !is_update) {
[email protected]612a1cb12012-10-17 13:18:032347 UpdateExternalExtensionAlert();
[email protected]d96eb512012-11-01 23:44:082348 UMA_HISTOGRAM_ENUMERATION("Extensions.ExternalExtensionEvent",
2349 EXTERNAL_EXTENSION_INSTALLED,
2350 EXTERNAL_EXTENSION_BUCKET_BOUNDARY);
[email protected]446e37e2013-08-07 00:30:022351 if (extensions::ManifestURL::UpdatesFromGallery(extension)) {
2352 UMA_HISTOGRAM_ENUMERATION("Extensions.ExternalExtensionEventWebstore",
2353 EXTERNAL_EXTENSION_INSTALLED,
2354 EXTERNAL_EXTENSION_BUCKET_BOUNDARY);
2355 } else {
2356 UMA_HISTOGRAM_ENUMERATION("Extensions.ExternalExtensionEventNonWebstore",
2357 EXTERNAL_EXTENSION_INSTALLED,
2358 EXTERNAL_EXTENSION_BUCKET_BOUNDARY);
2359 }
[email protected]d96eb512012-11-01 23:44:082360 }
[email protected]9f4e4f082013-06-21 07:11:192361
2362 // Check extensions that may have been delayed only because this shared module
2363 // was not available.
2364 if (SharedModuleInfo::IsSharedModule(extension)) {
2365 MaybeFinishDelayedInstallations();
2366 }
[email protected]4a190632009-05-09 01:07:422367}
2368
[email protected]76b65442012-11-17 14:11:482369const Extension* ExtensionService::GetPendingExtensionUpdate(
2370 const std::string& id) const {
[email protected]9f4e4f082013-06-21 07:11:192371 return delayed_installs_.GetByID(id);
[email protected]76b65442012-11-17 14:11:482372}
2373
[email protected]bb7f40952011-01-13 00:21:202374void ExtensionService::TrackTerminatedExtension(const Extension* extension) {
[email protected]bb1bc9b32013-12-21 03:09:142375 // No need to check for duplicates; inserting a duplicate is a no-op.
2376 registry_->AddTerminated(make_scoped_refptr(extension));
[email protected]3964e572014-02-13 21:57:412377 extensions_being_terminated_.erase(extension->id());
[email protected]b0af4792013-10-23 09:12:132378 UnloadExtension(extension->id(), UnloadedExtensionInfo::REASON_TERMINATE);
[email protected]bb7f40952011-01-13 00:21:202379}
2380
2381void ExtensionService::UntrackTerminatedExtension(const std::string& id) {
[email protected]fa2416f2011-05-03 08:41:202382 std::string lowercase_id = StringToLowerASCII(id);
[email protected]bb1bc9b32013-12-21 03:09:142383 const Extension* extension =
2384 registry_->terminated_extensions().GetByID(lowercase_id);
2385 registry_->RemoveTerminated(lowercase_id);
[email protected]fb789532013-08-27 02:40:212386 if (extension) {
2387 content::NotificationService::current()->Notify(
2388 chrome::NOTIFICATION_EXTENSION_REMOVED,
2389 content::Source<Profile>(profile_),
2390 content::Details<const Extension>(extension));
2391 }
[email protected]bb7f40952011-01-13 00:21:202392}
2393
[email protected]0dfe05c2011-02-23 23:03:362394const Extension* ExtensionService::GetTerminatedExtension(
[email protected]8001df22011-04-28 19:59:472395 const std::string& id) const {
[email protected]599539802014-01-07 23:06:002396 return registry_->GetExtensionById(id, ExtensionRegistry::TERMINATED);
[email protected]8001df22011-04-28 19:59:472397}
2398
2399const Extension* ExtensionService::GetInstalledExtension(
2400 const std::string& id) const {
[email protected]599539802014-01-07 23:06:002401 return registry_->GetExtensionById(id, ExtensionRegistry::EVERYTHING);
[email protected]0dfe05c2011-02-23 23:03:362402}
2403
[email protected]eaa7dd182010-12-14 11:09:002404bool ExtensionService::ExtensionBindingsAllowed(const GURL& url) {
[email protected]615d88f2011-12-13 01:47:442405 // Allow bindings for all packaged extensions and component hosted apps.
[email protected]bb1bc9b32013-12-21 03:09:142406 const Extension* extension =
2407 registry_->enabled_extensions().GetExtensionOrAppByURL(url);
[email protected]615d88f2011-12-13 01:47:442408 return extension && (!extension->is_hosted_app() ||
[email protected]1d5e58b2013-01-31 08:41:402409 extension->location() == Manifest::COMPONENT);
[email protected]6d2e60bd2010-06-03 22:37:392410}
2411
[email protected]4d007b312012-10-17 03:00:482412bool ExtensionService::ShouldBlockUrlInBrowserTab(GURL* url) {
[email protected]bb1bc9b32013-12-21 03:09:142413 const Extension* extension =
2414 registry_->enabled_extensions().GetExtensionOrAppByURL(*url);
[email protected]4d007b312012-10-17 03:00:482415 if (extension && extension->is_platform_app()) {
2416 *url = GURL(chrome::kExtensionInvalidRequestURL);
2417 return true;
2418 }
2419
2420 return false;
2421}
2422
[email protected]9060d8b02012-01-13 02:14:302423bool ExtensionService::OnExternalExtensionFileFound(
[email protected]8ef78fd2010-08-19 17:14:322424 const std::string& id,
[email protected]c5e4a2222014-01-03 16:06:132425 const Version* version,
[email protected]650b2d52013-02-10 03:41:452426 const base::FilePath& path,
[email protected]1d5e58b2013-01-31 08:41:402427 Manifest::Location location,
[email protected]47fc70c2011-12-06 07:29:512428 int creation_flags,
2429 bool mark_acknowledged) {
[email protected]ab22ba42011-01-14 16:36:382430 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
2431 CHECK(Extension::IdIsValid(id));
[email protected]79c833b52011-04-05 18:31:012432 if (extension_prefs_->IsExternalExtensionUninstalled(id))
[email protected]9060d8b02012-01-13 02:14:302433 return false;
[email protected]a8af9fdb2010-10-28 21:52:202434
[email protected]7577a5c52009-07-30 06:21:582435 // Before even bothering to unpack, check and see if we already have this
[email protected]4c967932009-07-31 01:15:492436 // version. This is important because these extensions are going to get
[email protected]7577a5c52009-07-30 06:21:582437 // installed on every startup.
[email protected]9adb9692010-10-29 23:14:022438 const Extension* existing = GetExtensionById(id, true);
[email protected]910f72ce2012-08-24 01:38:352439
[email protected]7577a5c52009-07-30 06:21:582440 if (existing) {
[email protected]910f72ce2012-08-24 01:38:352441 // The default apps will have the location set as INTERNAL. Since older
2442 // default apps are installed as EXTERNAL, we override them. However, if the
2443 // app is already installed as internal, then do the version check.
[email protected]31bb5ee62012-09-12 22:58:402444 // TODO(grv) : Remove after Q1-2013.
[email protected]910f72ce2012-08-24 01:38:352445 bool is_default_apps_migration =
[email protected]1d5e58b2013-01-31 08:41:402446 (location == Manifest::INTERNAL &&
2447 Manifest::IsExternalLocation(existing->location()));
[email protected]910f72ce2012-08-24 01:38:352448
2449 if (!is_default_apps_migration) {
2450 DCHECK(version);
2451
2452 switch (existing->version()->CompareTo(*version)) {
2453 case -1: // existing version is older, we should upgrade
2454 break;
2455 case 0: // existing version is same, do nothing
2456 return false;
2457 case 1: // existing version is newer, uh-oh
2458 LOG(WARNING) << "Found external version of extension " << id
2459 << "that is older than current version. Current version "
2460 << "is: " << existing->VersionString() << ". New "
2461 << "version is: " << version->GetString()
2462 << ". Keeping current version.";
2463 return false;
2464 }
[email protected]7577a5c52009-07-30 06:21:582465 }
2466 }
2467
[email protected]9060d8b02012-01-13 02:14:302468 // If the extension is already pending, don't start an install.
[email protected]e3987852012-05-04 10:06:302469 if (!pending_extension_manager()->AddFromExternalFile(
[email protected]464213a2013-10-15 01:06:482470 id, location, *version, creation_flags, mark_acknowledged)) {
[email protected]9060d8b02012-01-13 02:14:302471 return false;
[email protected]e3987852012-05-04 10:06:302472 }
[email protected]9c635f22010-12-02 09:36:362473
[email protected]14908b72011-04-20 06:54:362474 // no client (silent install)
[email protected]f8636f92013-08-09 21:02:372475 scoped_refptr<CrxInstaller> installer(CrxInstaller::CreateSilent(this));
[email protected]6dfbbf82010-03-12 23:09:162476 installer->set_install_source(location);
2477 installer->set_expected_id(id);
[email protected]cb0e50312011-05-09 15:03:072478 installer->set_expected_version(*version);
2479 installer->set_install_cause(extension_misc::INSTALL_CAUSE_EXTERNAL_FILE);
[email protected]1bf73cc32011-10-26 22:38:312480 installer->set_creation_flags(creation_flags);
[email protected]88e8ec9152013-01-17 04:05:182481#if defined(OS_CHROMEOS)
2482 extensions::InstallLimiter::Get(profile_)->Add(installer, path);
2483#else
[email protected]6dfbbf82010-03-12 23:09:162484 installer->InstallCrx(path);
[email protected]88e8ec9152013-01-17 04:05:182485#endif
[email protected]47fc70c2011-12-06 07:29:512486
2487 // Depending on the source, a new external extension might not need a user
2488 // notification on installation. For such extensions, mark them acknowledged
2489 // now to suppress the notification.
2490 if (mark_acknowledged)
2491 AcknowledgeExternalExtension(id);
[email protected]9060d8b02012-01-13 02:14:302492
2493 return true;
[email protected]7577a5c52009-07-30 06:21:582494}
2495
[email protected]023b3d12013-12-23 18:46:492496scoped_ptr<base::DictionaryValue> ExtensionService::GetExtensionInfo(
[email protected]b5a507b22013-11-08 20:41:572497 const std::string& extension_id) const {
[email protected]023b3d12013-12-23 18:46:492498 scoped_ptr<base::DictionaryValue> dictionary(new base::DictionaryValue);
[email protected]bb1bc9b32013-12-21 03:09:142499 const extensions::Extension* extension =
2500 registry_->enabled_extensions().GetByID(extension_id);
[email protected]b5a507b22013-11-08 20:41:572501 if (extension) {
2502 GURL icon = extensions::ExtensionIconSource::GetIconURL(
2503 extension, extension_misc::EXTENSION_ICON_SMALLISH,
2504 ExtensionIconSet::MATCH_BIGGER, false, NULL);
2505 dictionary->SetString("id", extension_id);
2506 dictionary->SetString("name", extension->name());
2507 dictionary->SetString("icon", icon.spec());
2508 }
2509 return dictionary.Pass();
2510}
2511
[email protected]eaa7dd182010-12-14 11:09:002512void ExtensionService::ReportExtensionLoadError(
[email protected]650b2d52013-02-10 03:41:452513 const base::FilePath& extension_path,
[email protected]d11c8e92009-10-20 23:26:402514 const std::string &error,
[email protected]d11c8e92009-10-20 23:26:402515 bool be_noisy) {
[email protected]d8c8f25f2011-11-02 18:18:012516 content::NotificationService::current()->Notify(
2517 chrome::NOTIFICATION_EXTENSION_LOAD_ERROR,
2518 content::Source<Profile>(profile_),
2519 content::Details<const std::string>(&error));
[email protected]d11c8e92009-10-20 23:26:402520
[email protected]04338722013-12-24 23:18:052521 std::string path_str = base::UTF16ToUTF8(extension_path.LossyDisplayName());
2522 base::string16 message = base::UTF8ToUTF16(base::StringPrintf(
[email protected]18d4b6c2010-09-21 03:21:042523 "Could not load extension from '%s'. %s",
[email protected]fc670822011-12-17 09:33:492524 path_str.c_str(), error.c_str()));
[email protected]d11c8e92009-10-20 23:26:402525 ExtensionErrorReporter::GetInstance()->ReportError(message, be_noisy);
2526}
2527
[email protected]eaa7dd182010-12-14 11:09:002528void ExtensionService::DidCreateRenderViewForBackgroundPage(
[email protected]3a1dc572012-07-31 22:25:132529 extensions::ExtensionHost* host) {
[email protected]406027c02010-09-27 08:03:182530 OrphanedDevTools::iterator iter =
[email protected]2d2f6cfc2011-05-06 21:09:332531 orphaned_dev_tools_.find(host->extension_id());
[email protected]406027c02010-09-27 08:03:182532 if (iter == orphaned_dev_tools_.end())
2533 return;
2534
[email protected]04ea1bb2013-07-10 09:26:092535 iter->second->ConnectRenderViewHost(host->render_view_host());
[email protected]406027c02010-09-27 08:03:182536 orphaned_dev_tools_.erase(iter);
2537}
2538
[email protected]432115822011-07-10 15:52:272539void ExtensionService::Observe(int type,
[email protected]6c2381d2011-10-19 02:52:532540 const content::NotificationSource& source,
2541 const content::NotificationDetails& details) {
[email protected]432115822011-07-10 15:52:272542 switch (type) {
[email protected]3c4abc82012-10-22 22:25:542543 case chrome::NOTIFICATION_APP_TERMINATING:
2544 // Shutdown has started. Don't start any more extension installs.
2545 // (We cannot use ExtensionService::Shutdown() for this because it
2546 // happens too late in browser teardown.)
2547 browser_terminating_ = true;
2548 break;
[email protected]432115822011-07-10 15:52:272549 case chrome::NOTIFICATION_EXTENSION_PROCESS_TERMINATED: {
[email protected]6c2381d2011-10-19 02:52:532550 if (profile_ !=
2551 content::Source<Profile>(source).ptr()->GetOriginalProfile()) {
[email protected]bc535ee52010-08-31 18:40:322552 break;
[email protected]6c2381d2011-10-19 02:52:532553 }
[email protected]a4ed6282009-12-14 20:51:162554
[email protected]3a1dc572012-07-31 22:25:132555 extensions::ExtensionHost* host =
2556 content::Details<extensions::ExtensionHost>(details).ptr();
[email protected]f128af42010-08-05 18:05:262557
[email protected]3964e572014-02-13 21:57:412558 // If the extension is already being terminated, there is nothing left to
2559 // do.
2560 if (!extensions_being_terminated_.insert(host->extension_id()).second)
2561 break;
2562
[email protected]fa2416f2011-05-03 08:41:202563 // Mark the extension as terminated and Unload it. We want it to
2564 // be in a consistent state: either fully working or not loaded
2565 // at all, but never half-crashed. We do it in a PostTask so
2566 // that other handlers of this notification will still have
2567 // access to the Extension and ExtensionHost.
[email protected]b3a25092013-05-28 22:08:162568 base::MessageLoop::current()->PostTask(
[email protected]14908b72011-04-20 06:54:362569 FROM_HERE,
[email protected]53612e82011-10-18 18:00:362570 base::Bind(
[email protected]fa2416f2011-05-03 08:41:202571 &ExtensionService::TrackTerminatedExtension,
[email protected]d8c8f25f2011-11-02 18:18:012572 AsWeakPtr(),
[email protected]fa2416f2011-05-03 08:41:202573 host->extension()));
[email protected]31f77262009-12-02 20:48:532574 break;
2575 }
[email protected]432115822011-07-10 15:52:272576 case content::NOTIFICATION_RENDERER_PROCESS_TERMINATED: {
[email protected]f3b1a082011-11-18 00:34:302577 content::RenderProcessHost* process =
2578 content::Source<content::RenderProcessHost>(source).ptr();
[email protected]fc30ef082011-08-18 04:07:192579 Profile* host_profile =
[email protected]f3b1a082011-11-18 00:34:302580 Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]fc30ef082011-08-18 04:07:192581 if (!profile_->IsSameProfile(host_profile->GetOriginalProfile()))
2582 break;
2583
[email protected]fafdc842014-01-17 18:09:082584 extensions::ProcessMap* process_map =
2585 extensions::ProcessMap::Get(profile_);
2586 if (process_map->Contains(process->GetID())) {
[email protected]52b76592013-11-02 17:59:032587 // An extension process was terminated, this might have resulted in an
2588 // app or extension becoming idle.
2589 std::set<std::string> extension_ids =
[email protected]fafdc842014-01-17 18:09:082590 process_map->GetExtensionsInProcess(process->GetID());
[email protected]52b76592013-11-02 17:59:032591 for (std::set<std::string>::const_iterator it = extension_ids.begin();
2592 it != extension_ids.end(); ++it) {
2593 if (delayed_installs_.Contains(*it)) {
2594 base::MessageLoop::current()->PostDelayedTask(
2595 FROM_HERE,
2596 base::Bind(&ExtensionService::MaybeFinishDelayedInstallation,
2597 AsWeakPtr(), *it),
2598 base::TimeDelta::FromSeconds(kUpdateIdleDelay));
2599 }
2600 }
2601 }
2602
[email protected]fafdc842014-01-17 18:09:082603 process_map->RemoveAllFromProcess(process->GetID());
[email protected]6f371442011-11-09 06:45:462604 BrowserThread::PostTask(
[email protected]38427a12013-11-09 17:34:202605 BrowserThread::IO,
2606 FROM_HERE,
2607 base::Bind(&extensions::InfoMap::UnregisterAllExtensionsInProcess,
[email protected]31d8f5f22012-04-02 15:22:082608 system_->info_map(),
[email protected]f3b1a082011-11-18 00:34:302609 process->GetID()));
[email protected]da5683db2011-04-23 17:12:212610 break;
2611 }
[email protected]92dd8d92013-02-26 00:41:082612 case chrome::NOTIFICATION_UPGRADE_RECOMMENDED: {
[email protected]75bdcb872013-03-13 00:41:452613 // Notify observers that chrome update is available.
2614 FOR_EACH_OBSERVER(extensions::UpdateObserver, update_observers_,
2615 OnChromeUpdateAvailable());
[email protected]92dd8d92013-02-26 00:41:082616 break;
2617 }
[email protected]aa96d3a2010-08-21 08:45:252618
[email protected]4814b512009-11-07 00:12:292619 default:
2620 NOTREACHED() << "Unexpected notification type.";
2621 }
2622}
2623
[email protected]90bb38d2012-11-14 18:36:032624void ExtensionService::OnExtensionInstallPrefChanged() {
[email protected]a6a7ced2012-11-01 17:24:182625 IdentifyAlertableExtensions();
2626 CheckManagementPolicy();
2627}
2628
[email protected]eaa7dd182010-12-14 11:09:002629bool ExtensionService::HasApps() const {
[email protected]ec5b50d2010-10-09 16:35:182630 return !GetAppIds().empty();
2631}
[email protected]377011d2010-07-20 04:18:502632
[email protected]eaa7dd182010-12-14 11:09:002633ExtensionIdSet ExtensionService::GetAppIds() const {
[email protected]ec5b50d2010-10-09 16:35:182634 ExtensionIdSet result;
[email protected]bb1bc9b32013-12-21 03:09:142635 const ExtensionSet& extensions = registry_->enabled_extensions();
2636 for (ExtensionSet::const_iterator it = extensions.begin();
2637 it != extensions.end(); ++it) {
[email protected]1d5e58b2013-01-31 08:41:402638 if ((*it)->is_app() && (*it)->location() != Manifest::COMPONENT)
[email protected]ec5b50d2010-10-09 16:35:182639 result.insert((*it)->id());
[email protected]377011d2010-07-20 04:18:502640 }
2641
[email protected]ec5b50d2010-10-09 16:35:182642 return result;
[email protected]377011d2010-07-20 04:18:502643}
[email protected]d7e9a862010-11-03 21:57:492644
[email protected]e178ad92013-06-28 02:29:252645bool ExtensionService::IsBeingReloaded(
2646 const std::string& extension_id) const {
2647 return ContainsKey(extensions_being_reloaded_, extension_id);
2648}
2649
2650void ExtensionService::SetBeingReloaded(const std::string& extension_id,
[email protected]5e7015c2013-07-23 23:29:432651 bool isBeingReloaded) {
2652 if (isBeingReloaded)
[email protected]e178ad92013-06-28 02:29:252653 extensions_being_reloaded_.insert(extension_id);
[email protected]5e7015c2013-07-23 23:29:432654 else
[email protected]e178ad92013-06-28 02:29:252655 extensions_being_reloaded_.erase(extension_id);
[email protected]e178ad92013-06-28 02:29:252656}
2657
[email protected]612a1cb12012-10-17 13:18:032658bool ExtensionService::ShouldEnableOnInstall(const Extension* extension) {
2659 // Extensions installed by policy can't be disabled. So even if a previous
2660 // installation disabled the extension, make sure it is now enabled.
2661 if (system_->management_policy()->MustRemainEnabled(extension, NULL))
2662 return true;
2663
2664 if (extension_prefs_->IsExtensionDisabled(extension->id()))
2665 return false;
2666
[email protected]41070e8d2012-10-24 01:34:362667 if (FeatureSwitch::prompt_for_external_extensions()->IsEnabled()) {
[email protected]612a1cb12012-10-17 13:18:032668 // External extensions are initially disabled. We prompt the user before
[email protected]2c495c42013-01-04 21:49:542669 // enabling them. Hosted apps are excepted because they are not dangerous
2670 // (they need to be launched by the user anyway).
[email protected]1d5e58b2013-01-31 08:41:402671 if (extension->GetType() != Manifest::TYPE_HOSTED_APP &&
2672 Manifest::IsExternalLocation(extension->location()) &&
[email protected]612a1cb12012-10-17 13:18:032673 !extension_prefs_->IsExternalExtensionAcknowledged(extension->id())) {
2674 return false;
2675 }
2676 }
[email protected]612a1cb12012-10-17 13:18:032677
2678 return true;
2679}
[email protected]0db124b02012-11-07 04:55:052680
[email protected]e7aa7b7e2012-11-27 04:51:222681bool ExtensionService::ShouldDelayExtensionUpdate(
2682 const std::string& extension_id,
2683 bool wait_for_idle) const {
2684 const char kOnUpdateAvailableEvent[] = "runtime.onUpdateAvailable";
2685
2686 // If delayed updates are globally disabled, or just for this extension,
2687 // don't delay.
2688 if (!install_updates_when_idle_ || !wait_for_idle)
2689 return false;
2690
[email protected]695b5712012-12-06 23:55:282691 const Extension* old = GetInstalledExtension(extension_id);
[email protected]e7aa7b7e2012-11-27 04:51:222692 // If there is no old extension, this is not an update, so don't delay.
2693 if (!old)
2694 return false;
2695
[email protected]9367eabc2013-03-01 01:29:292696 if (extensions::BackgroundInfo::HasPersistentBackgroundPage(old)) {
[email protected]e7aa7b7e2012-11-27 04:51:222697 // Delay installation if the extension listens for the onUpdateAvailable
2698 // event.
2699 return system_->event_router()->ExtensionHasEventListener(
2700 extension_id, kOnUpdateAvailableEvent);
2701 } else {
2702 // Delay installation if the extension is not idle.
[email protected]1d5cf4142014-01-24 18:25:222703 return !extensions::util::IsExtensionIdle(extension_id, profile_);
[email protected]e7aa7b7e2012-11-27 04:51:222704 }
[email protected]0db124b02012-11-07 04:55:052705}
[email protected]fdd679b2012-11-15 20:49:392706
[email protected]399583b2012-12-11 09:33:422707void ExtensionService::GarbageCollectIsolatedStorage() {
[email protected]650b2d52013-02-10 03:41:452708 scoped_ptr<base::hash_set<base::FilePath> > active_paths(
2709 new base::hash_set<base::FilePath>());
[email protected]bb1bc9b32013-12-21 03:09:142710 const ExtensionSet& extensions = registry_->enabled_extensions();
2711 for (ExtensionSet::const_iterator it = extensions.begin();
2712 it != extensions.end(); ++it) {
[email protected]cadac622013-06-11 16:46:362713 if (extensions::AppIsolationInfo::HasIsolatedStorage(it->get())) {
2714 active_paths->insert(BrowserContext::GetStoragePartitionForSite(
2715 profile_, GetSiteForExtensionId((*it)->id()))->GetPath());
[email protected]399583b2012-12-11 09:33:422716 }
2717 }
2718
[email protected]9f4e4f082013-06-21 07:11:192719 DCHECK(!installs_delayed_for_gc());
2720 set_installs_delayed_for_gc(true);
[email protected]399583b2012-12-11 09:33:422721 BrowserContext::GarbageCollectStoragePartitions(
2722 profile_, active_paths.Pass(),
2723 base::Bind(&ExtensionService::OnGarbageCollectIsolatedStorageFinished,
2724 AsWeakPtr()));
2725}
2726
2727void ExtensionService::OnGarbageCollectIsolatedStorageFinished() {
[email protected]9f4e4f082013-06-21 07:11:192728 set_installs_delayed_for_gc(false);
2729 MaybeFinishDelayedInstallations();
2730}
2731
2732void ExtensionService::MaybeFinishDelayedInstallations() {
2733 std::vector<std::string> to_be_installed;
[email protected]399583b2012-12-11 09:33:422734 for (ExtensionSet::const_iterator it = delayed_installs_.begin();
2735 it != delayed_installs_.end();
2736 ++it) {
[email protected]9f4e4f082013-06-21 07:11:192737 to_be_installed.push_back((*it)->id());
[email protected]399583b2012-12-11 09:33:422738 }
[email protected]9f4e4f082013-06-21 07:11:192739 for (std::vector<std::string>::const_iterator it = to_be_installed.begin();
2740 it != to_be_installed.end();
[email protected]399583b2012-12-11 09:33:422741 ++it) {
[email protected]9f4e4f082013-06-21 07:11:192742 MaybeFinishDelayedInstallation(*it);
[email protected]399583b2012-12-11 09:33:422743 }
[email protected]399583b2012-12-11 09:33:422744}
2745
[email protected]fdd679b2012-11-15 20:49:392746void ExtensionService::OnBlacklistUpdated() {
[email protected]2d19eb6e2014-01-27 17:30:002747 blacklist_->GetBlacklistedIDs(
[email protected]695b5712012-12-06 23:55:282748 GenerateInstalledExtensionsSet()->GetIDs(),
[email protected]3f2a2fa2013-09-24 02:55:252749 base::Bind(&ExtensionService::ManageBlacklist, AsWeakPtr()));
[email protected]695b5712012-12-06 23:55:282750}
2751
[email protected]2d19eb6e2014-01-27 17:30:002752void ExtensionService::ManageBlacklist(
2753 const extensions::Blacklist::BlacklistStateMap& state_map) {
[email protected]695b5712012-12-06 23:55:282754 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
2755
[email protected]2d19eb6e2014-01-27 17:30:002756 std::set<std::string> blocked;
2757 ExtensionIdSet greylist;
2758 ExtensionIdSet unchanged;
2759 for (extensions::Blacklist::BlacklistStateMap::const_iterator it =
2760 state_map.begin();
2761 it != state_map.end();
2762 ++it) {
2763 switch (it->second) {
2764 case extensions::NOT_BLACKLISTED:
2765 break;
[email protected]695b5712012-12-06 23:55:282766
[email protected]2d19eb6e2014-01-27 17:30:002767 case extensions::BLACKLISTED_MALWARE:
2768 blocked.insert(it->first);
2769 break;
2770
2771 case extensions::BLACKLISTED_SECURITY_VULNERABILITY:
2772 case extensions::BLACKLISTED_CWS_POLICY_VIOLATION:
2773 case extensions::BLACKLISTED_POTENTIALLY_UNWANTED:
2774 greylist.insert(it->first);
2775 break;
2776
2777 case extensions::BLACKLISTED_UNKNOWN:
2778 unchanged.insert(it->first);
2779 break;
2780 }
2781 }
2782
2783 UpdateBlockedExtensions(blocked, unchanged);
2784 UpdateGreylistedExtensions(greylist, unchanged, state_map);
2785
2786 IdentifyAlertableExtensions();
2787}
2788
2789namespace {
2790void Partition(const ExtensionIdSet& before,
2791 const ExtensionIdSet& after,
2792 const ExtensionIdSet& unchanged,
2793 ExtensionIdSet* no_longer,
2794 ExtensionIdSet* not_yet) {
2795 *not_yet = base::STLSetDifference<ExtensionIdSet>(after, before);
2796 *no_longer = base::STLSetDifference<ExtensionIdSet>(before, after);
2797 *no_longer = base::STLSetDifference<ExtensionIdSet>(*no_longer, unchanged);
2798}
2799} // namespace
2800
2801void ExtensionService::UpdateBlockedExtensions(
2802 const ExtensionIdSet& blocked,
2803 const ExtensionIdSet& unchanged) {
2804 ExtensionIdSet not_yet_blocked, no_longer_blocked;
2805 Partition(registry_->blacklisted_extensions().GetIDs(),
2806 blocked, unchanged,
2807 &no_longer_blocked, &not_yet_blocked);
2808
2809 for (ExtensionIdSet::iterator it = no_longer_blocked.begin();
2810 it != no_longer_blocked.end(); ++it) {
[email protected]695b5712012-12-06 23:55:282811 scoped_refptr<const Extension> extension =
[email protected]bb1bc9b32013-12-21 03:09:142812 registry_->blacklisted_extensions().GetByID(*it);
[email protected]3f2a2fa2013-09-24 02:55:252813 if (!extension.get()) {
[email protected]2d19eb6e2014-01-27 17:30:002814 NOTREACHED() << "Extension " << *it << " no longer blocked, "
2815 << "but it was never blocked.";
[email protected]695b5712012-12-06 23:55:282816 continue;
[email protected]3f2a2fa2013-09-24 02:55:252817 }
[email protected]bb1bc9b32013-12-21 03:09:142818 registry_->RemoveBlacklisted(*it);
[email protected]3f2a2fa2013-09-24 02:55:252819 extension_prefs_->SetExtensionBlacklisted(extension->id(), false);
[email protected]dc24976f2013-06-02 21:15:092820 AddExtension(extension.get());
[email protected]ac875372013-02-28 04:36:092821 UMA_HISTOGRAM_ENUMERATION("ExtensionBlacklist.UnblacklistInstalled",
[email protected]dc24976f2013-06-02 21:15:092822 extension->location(),
2823 Manifest::NUM_LOCATIONS);
[email protected]695b5712012-12-06 23:55:282824 }
2825
[email protected]2d19eb6e2014-01-27 17:30:002826 for (ExtensionIdSet::iterator it = not_yet_blocked.begin();
2827 it != not_yet_blocked.end(); ++it) {
[email protected]695b5712012-12-06 23:55:282828 scoped_refptr<const Extension> extension = GetInstalledExtension(*it);
[email protected]3f2a2fa2013-09-24 02:55:252829 if (!extension.get()) {
2830 NOTREACHED() << "Extension " << *it << " needs to be "
2831 << "blacklisted, but it's not installed.";
[email protected]695b5712012-12-06 23:55:282832 continue;
[email protected]3f2a2fa2013-09-24 02:55:252833 }
[email protected]bb1bc9b32013-12-21 03:09:142834 registry_->AddBlacklisted(extension);
[email protected]2d19eb6e2014-01-27 17:30:002835 extension_prefs_->SetExtensionBlacklistState(
2836 extension->id(), extensions::BLACKLISTED_MALWARE);
[email protected]b0af4792013-10-23 09:12:132837 UnloadExtension(*it, UnloadedExtensionInfo::REASON_BLACKLIST);
[email protected]ac875372013-02-28 04:36:092838 UMA_HISTOGRAM_ENUMERATION("ExtensionBlacklist.BlacklistInstalled",
2839 extension->location(), Manifest::NUM_LOCATIONS);
[email protected]695b5712012-12-06 23:55:282840 }
[email protected]2d19eb6e2014-01-27 17:30:002841}
[email protected]695b5712012-12-06 23:55:282842
[email protected]2d19eb6e2014-01-27 17:30:002843// TODO(oleg): UMA logging
2844void ExtensionService::UpdateGreylistedExtensions(
2845 const ExtensionIdSet& greylist,
2846 const ExtensionIdSet& unchanged,
2847 const extensions::Blacklist::BlacklistStateMap& state_map) {
2848 ExtensionIdSet not_yet_greylisted, no_longer_greylisted;
2849 Partition(greylist_.GetIDs(),
2850 greylist, unchanged,
2851 &no_longer_greylisted, &not_yet_greylisted);
2852
2853 for (ExtensionIdSet::iterator it = no_longer_greylisted.begin();
2854 it != no_longer_greylisted.end(); ++it) {
2855 scoped_refptr<const Extension> extension = greylist_.GetByID(*it);
2856 if (!extension.get()) {
2857 NOTREACHED() << "Extension " << *it << " no longer greylisted, "
2858 << "but it was not marked as greylisted.";
2859 continue;
2860 }
2861
2862 greylist_.Remove(*it);
2863 extension_prefs_->SetExtensionBlacklistState(extension->id(),
2864 extensions::NOT_BLACKLISTED);
2865 if (extension_prefs_->GetDisableReasons(extension->id()) &
2866 extensions::Extension::DISABLE_GREYLIST)
2867 EnableExtension(*it);
2868 }
2869
2870 for (ExtensionIdSet::iterator it = not_yet_greylisted.begin();
2871 it != not_yet_greylisted.end(); ++it) {
2872 scoped_refptr<const Extension> extension = GetInstalledExtension(*it);
2873 if (!extension.get()) {
2874 NOTREACHED() << "Extension " << *it << " needs to be "
2875 << "disabled, but it's not installed.";
2876 continue;
2877 }
2878 greylist_.Insert(extension);
2879 extension_prefs_->SetExtensionBlacklistState(extension->id(),
2880 state_map.find(*it)->second);
2881 if (registry_->enabled_extensions().Contains(extension->id()))
2882 DisableExtension(*it, extensions::Extension::DISABLE_GREYLIST);
2883 }
[email protected]fdd679b2012-11-15 20:49:392884}
[email protected]75bdcb872013-03-13 00:41:452885
2886void ExtensionService::AddUpdateObserver(extensions::UpdateObserver* observer) {
2887 update_observers_.AddObserver(observer);
2888}
2889
2890void ExtensionService::RemoveUpdateObserver(
2891 extensions::UpdateObserver* observer) {
2892 update_observers_.RemoveObserver(observer);
2893}
[email protected]bb1bc9b32013-12-21 03:09:142894
2895// Used only by test code.
2896void ExtensionService::UnloadAllExtensionsInternal() {
2897 profile_->GetExtensionSpecialStoragePolicy()->RevokeRightsForAllExtensions();
2898
2899 registry_->ClearAll();
[email protected]45f5b7d2014-01-22 23:47:132900 system_->runtime_data()->ClearAll();
[email protected]bb1bc9b32013-12-21 03:09:142901
2902 // TODO(erikkay) should there be a notification for this? We can't use
2903 // EXTENSION_UNLOADED since that implies that the extension has been disabled
2904 // or uninstalled.
2905}