blob: d9a5370a3087961d943638f15307656aa2f2bb17 [file] [log] [blame]
[email protected]098fa7a2013-03-08 22:11:171// Copyright (c) 2013 The Chromium Authors. All rights reserved.
[email protected]6014d672008-12-05 00:38:252// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]eaa7dd182010-12-14 11:09:005#include "chrome/browser/extensions/extension_service.h"
[email protected]6014d672008-12-05 00:38:256
[email protected]654512b2010-09-01 02:09:427#include <algorithm>
[email protected]695b5712012-12-06 23:55:288#include <iterator>
[email protected]97d2f1d2011-01-15 00:41:089#include <set>
[email protected]654512b2010-09-01 02:09:4210
[email protected]62433d32011-10-12 22:33:1211#include "base/command_line.h"
[email protected]835d7c82010-10-14 04:38:3812#include "base/metrics/histogram.h"
[email protected]3ea1b182013-02-08 22:38:4113#include "base/strings/string_number_conversions.h"
[email protected]00e7bef2013-06-10 20:35:1714#include "base/strings/stringprintf.h"
[email protected]112158af2013-06-07 23:46:1815#include "base/strings/utf_string_conversions.h"
[email protected]7f8f24f2012-11-15 19:40:1416#include "base/threading/sequenced_worker_pool.h"
[email protected]34b99632011-01-01 01:01:0617#include "base/threading/thread_restrictions.h"
[email protected]41a17c52013-06-28 00:27:5318#include "base/time/time.h"
[email protected]15730c42009-09-03 00:03:2019#include "chrome/browser/browser_process.h"
[email protected]9ea0cd32013-07-12 01:50:3620#include "chrome/browser/chrome_notification_types.h"
[email protected]ad445762013-01-23 00:47:4421#include "chrome/browser/extensions/api/extension_action/extension_action_api.h"
[email protected]d8c8f25f2011-11-02 18:18:0122#include "chrome/browser/extensions/component_loader.h"
[email protected]e0785902011-05-19 23:34:1723#include "chrome/browser/extensions/crx_installer.h"
[email protected]d9ede582012-08-14 19:21:3824#include "chrome/browser/extensions/data_deleter.h"
[email protected]5a145e82014-05-29 22:19:0725#include "chrome/browser/extensions/extension_assets_manager.h"
[email protected]62f051c2012-03-29 17:04:4426#include "chrome/browser/extensions/extension_disabled_ui.h"
[email protected]373daf972014-04-10 01:50:4427#include "chrome/browser/extensions/extension_error_controller.h"
[email protected]00b38242012-07-18 18:43:2228#include "chrome/browser/extensions/extension_install_ui.h"
[email protected]19eb80152011-02-26 00:28:4329#include "chrome/browser/extensions/extension_special_storage_policy.h"
[email protected]f8aefb132013-10-30 09:29:5230#include "chrome/browser/extensions/extension_sync_service.h"
[email protected]617342a42013-12-18 23:34:0331#include "chrome/browser/extensions/extension_util.h"
[email protected]e5d6b4712014-06-04 20:07:2332#include "chrome/browser/extensions/external_install_ui.h"
[email protected]5df038b2012-07-16 19:03:2733#include "chrome/browser/extensions/external_provider_impl.h"
[email protected]ffd2f79e2013-11-14 00:11:4634#include "chrome/browser/extensions/install_verifier.h"
[email protected]d8c8f25f2011-11-02 18:18:0135#include "chrome/browser/extensions/installed_loader.h"
[email protected]f3d3b382014-03-14 21:19:2836#include "chrome/browser/extensions/pending_extension_manager.h"
[email protected]c333e792012-01-06 16:57:3937#include "chrome/browser/extensions/permissions_updater.h"
[email protected]90878c52014-04-04 18:21:0238#include "chrome/browser/extensions/shared_module_service.h"
[email protected]d8c8f25f2011-11-02 18:18:0139#include "chrome/browser/extensions/unpacked_installer.h"
[email protected]044e86992014-01-24 22:59:1140#include "chrome/browser/extensions/updater/extension_cache.h"
[email protected]42a08162012-03-16 18:09:1141#include "chrome/browser/extensions/updater/extension_updater.h"
[email protected]8ecad5e2010-12-02 21:18:3342#include "chrome/browser/profiles/profile.h"
[email protected]b5a507b22013-11-08 20:41:5743#include "chrome/browser/ui/webui/extensions/extension_icon_source.h"
[email protected]c8d407e2011-04-28 21:27:1744#include "chrome/browser/ui/webui/favicon_source.h"
[email protected]5eddc3e2011-10-26 04:33:3145#include "chrome/browser/ui/webui/ntp/thumbnail_source.h"
[email protected]b07e606e2012-09-15 20:16:1546#include "chrome/browser/ui/webui/theme_source.h"
[email protected]e2eb43112009-05-29 21:19:5447#include "chrome/common/chrome_switches.h"
[email protected]f6431be82013-09-07 02:53:4548#include "chrome/common/crash_keys.h"
[email protected]9f4e4f082013-06-21 07:11:1949#include "chrome/common/extensions/extension_constants.h"
[email protected]15d4d2d2013-08-09 06:49:0350#include "chrome/common/extensions/features/feature_channel.h"
[email protected]65348062013-01-15 07:27:2251#include "chrome/common/extensions/manifest_url_handler.h"
[email protected]25b34332009-06-05 21:53:1952#include "chrome/common/pref_names.h"
[email protected]a57209872009-05-04 22:53:1453#include "chrome/common/url_constants.h"
[email protected]7a83dd072013-09-03 12:09:1754#include "components/startup_metric_utils/startup_metric_utils.h"
[email protected]dccba4f82014-05-29 00:52:5655#include "content/public/browser/devtools_agent_host.h"
[email protected]05aad2da2011-10-28 10:12:3756#include "content/public/browser/notification_service.h"
[email protected]f3b1a082011-11-18 00:34:3057#include "content/public/browser/render_process_host.h"
[email protected]399583b2012-12-11 09:33:4258#include "content/public/browser/storage_partition.h"
[email protected]34423532013-11-21 18:13:1059#include "extensions/browser/event_router.h"
[email protected]22401dc2014-03-21 01:38:5760#include "extensions/browser/extension_host.h"
[email protected]dccba4f82014-05-29 00:52:5661#include "extensions/browser/extension_prefs.h"
[email protected]bb1bc9b32013-12-21 03:09:1462#include "extensions/browser/extension_registry.h"
[email protected]59b0e602014-01-30 00:41:2463#include "extensions/browser/extension_system.h"
[email protected]4a1d9c0d2014-06-13 12:50:1164#include "extensions/browser/install_flag.h"
[email protected]234fc5ff2014-01-16 23:32:2865#include "extensions/browser/pref_names.h"
[email protected]45f5b7d2014-01-22 23:47:1366#include "extensions/browser/runtime_data.h"
[email protected]a9aa62b312013-11-29 05:35:0667#include "extensions/browser/update_observer.h"
[email protected]fb820c02014-03-13 15:07:0868#include "extensions/common/extension_messages.h"
[email protected]5ef835a2013-11-08 20:42:5769#include "extensions/common/feature_switch.h"
[email protected]85df9d12014-04-15 17:02:1470#include "extensions/common/file_util.h"
[email protected]0c3c9732013-09-16 08:53:4171#include "extensions/common/manifest_constants.h"
[email protected]558878cc82013-11-09 01:25:5172#include "extensions/common/manifest_handlers/background_info.h"
[email protected]d695bb12014-06-05 16:16:3073#include "extensions/common/manifest_handlers/permissions_parser.h"
[email protected]dccba4f82014-05-29 00:52:5674#include "extensions/common/one_shot_event.h"
[email protected]c41003472013-10-19 15:37:2575#include "extensions/common/permissions/permission_message_provider.h"
[email protected]e4452d32013-11-15 23:07:4176#include "extensions/common/permissions/permissions_data.h"
[email protected]79a60642012-10-20 21:03:1877
[email protected]eed367e2011-04-12 03:43:3178#if defined(OS_CHROMEOS)
[email protected]88e8ec9152013-01-17 04:05:1879#include "chrome/browser/chromeos/extensions/install_limiter.h"
[email protected]f19bbf62013-07-09 01:22:3280#include "webkit/browser/fileapi/file_system_backend.h"
[email protected]c6f9203a2013-05-28 02:08:0781#include "webkit/browser/fileapi/file_system_context.h"
[email protected]eed367e2011-04-12 03:43:3182#endif
83
[email protected]55eb70e762012-02-20 17:38:3984using content::BrowserContext;
[email protected]631bb742011-11-02 11:29:3985using content::BrowserThread;
[email protected]98f66112012-12-25 12:59:3686using content::DevToolsAgentHost;
[email protected]bf3d9df2012-07-24 23:20:2787using extensions::CrxInstaller;
[email protected]1c321ee52012-05-21 03:02:3488using extensions::Extension;
89using extensions::ExtensionIdSet;
90using extensions::ExtensionInfo;
[email protected]599539802014-01-07 23:06:0091using extensions::ExtensionRegistry;
[email protected]289c44b2013-12-17 03:26:5792using extensions::ExtensionSet;
[email protected]215a7be2012-10-22 19:53:4293using extensions::FeatureSwitch;
[email protected]ffd2f79e2013-11-14 00:11:4694using extensions::InstallVerifier;
[email protected]0d54b682013-11-05 14:15:3695using extensions::ManagementPolicy;
[email protected]1d5e58b2013-01-31 08:41:4096using extensions::Manifest;
[email protected]c2e66e12012-06-27 06:27:0697using extensions::PermissionMessage;
98using extensions::PermissionMessages;
99using extensions::PermissionSet;
[email protected]9f4e4f082013-06-21 07:11:19100using extensions::SharedModuleInfo;
[email protected]90878c52014-04-04 18:21:02101using extensions::SharedModuleService;
[email protected]e410b5f2012-12-14 14:02:24102using extensions::UnloadedExtensionInfo;
[email protected]5ef47ec2010-01-28 05:58:05103
[email protected]0c3c9732013-09-16 08:53:41104namespace errors = extensions::manifest_errors;
[email protected]c6d474f82009-12-16 21:11:06105
[email protected]b6ab96d2009-08-20 18:58:19106namespace {
107
[email protected]d96eb512012-11-01 23:44:08108// Histogram values for logging events related to externally installed
109// extensions.
110enum ExternalExtensionEvent {
111 EXTERNAL_EXTENSION_INSTALLED = 0,
112 EXTERNAL_EXTENSION_IGNORED,
113 EXTERNAL_EXTENSION_REENABLED,
114 EXTERNAL_EXTENSION_UNINSTALLED,
115 EXTERNAL_EXTENSION_BUCKET_BOUNDARY,
116};
117
[email protected]612a1cb12012-10-17 13:18:03118// Prompt the user this many times before considering an extension acknowledged.
119static const int kMaxExtensionAcknowledgePromptCount = 3;
120
[email protected]0db124b02012-11-07 04:55:05121// Wait this many seconds after an extensions becomes idle before updating it.
122static const int kUpdateIdleDelay = 5;
123
[email protected]4c9201c42013-08-16 04:56:21124static bool IsCWSSharedModule(const Extension* extension) {
[email protected]90878c52014-04-04 18:21:02125 return extension->from_webstore() &&
126 SharedModuleInfo::IsSharedModule(extension);
[email protected]4c9201c42013-08-16 04:56:21127}
128
129class SharedModuleProvider : public extensions::ManagementPolicy::Provider {
130 public:
131 SharedModuleProvider() {}
132 virtual ~SharedModuleProvider() {}
133
134 virtual std::string GetDebugPolicyProviderName() const OVERRIDE {
135 return "SharedModuleProvider";
136 }
137
138 virtual bool UserMayModifySettings(const Extension* extension,
[email protected]439f1e32013-12-09 20:09:09139 base::string16* error) const OVERRIDE {
[email protected]4c9201c42013-08-16 04:56:21140 return !IsCWSSharedModule(extension);
141 }
142
143 virtual bool MustRemainEnabled(const Extension* extension,
[email protected]439f1e32013-12-09 20:09:09144 base::string16* error) const OVERRIDE {
[email protected]4c9201c42013-08-16 04:56:21145 return IsCWSSharedModule(extension);
146 }
147
148 private:
149 DISALLOW_COPY_AND_ASSIGN(SharedModuleProvider);
150};
151
[email protected]c6d474f82009-12-16 21:11:06152} // namespace
[email protected]b6ab96d2009-08-20 18:58:19153
[email protected]eaa7dd182010-12-14 11:09:00154// ExtensionService.
[email protected]6014d672008-12-05 00:38:25155
[email protected]8e4560b62011-01-14 10:09:14156void ExtensionService::CheckExternalUninstall(const std::string& id) {
[email protected]a29a517a2011-01-21 21:11:12157 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]a8af9fdb2010-10-28 21:52:20158
[email protected]7a4c6852010-09-16 03:44:22159 // Check if the providers know about this extension.
[email protected]5df038b2012-07-16 19:03:27160 extensions::ProviderCollection::const_iterator i;
[email protected]0a60a2e2010-10-25 16:15:21161 for (i = external_extension_providers_.begin();
162 i != external_extension_providers_.end(); ++i) {
[email protected]8e4560b62011-01-14 10:09:14163 DCHECK(i->get()->IsReady());
[email protected]0a60a2e2010-10-25 16:15:21164 if (i->get()->HasExtension(id))
165 return; // Yup, known extension, don't uninstall.
[email protected]7a4c6852010-09-16 03:44:22166 }
167
[email protected]0f48fca2011-05-19 18:46:35168 // We get the list of external extensions to check from preferences.
169 // It is possible that an extension has preferences but is not loaded.
170 // For example, an extension that requires experimental permissions
171 // will not be loaded if the experimental command line flag is not used.
172 // In this case, do not uninstall.
[email protected]31bb5ee62012-09-12 22:58:40173 if (!GetInstalledExtension(id)) {
[email protected]0f48fca2011-05-19 18:46:35174 // We can't call UninstallExtension with an unloaded/invalid
175 // extension ID.
176 LOG(WARNING) << "Attempted uninstallation of unloaded/invalid extension "
177 << "with id: " << id;
178 return;
179 }
[email protected]d6ebc9792011-04-07 18:18:33180 UninstallExtension(id, true, NULL);
[email protected]7a4c6852010-09-16 03:44:22181}
182
[email protected]7f8f24f2012-11-15 19:40:14183void ExtensionService::SetFileTaskRunnerForTesting(
184 base::SequencedTaskRunner* task_runner) {
185 file_task_runner_ = task_runner;
186}
187
[email protected]8e4560b62011-01-14 10:09:14188void ExtensionService::ClearProvidersForTesting() {
[email protected]7a4c6852010-09-16 03:44:22189 external_extension_providers_.clear();
190}
191
[email protected]8e4560b62011-01-14 10:09:14192void ExtensionService::AddProviderForTesting(
[email protected]5df038b2012-07-16 19:03:27193 extensions::ExternalProviderInterface* test_provider) {
[email protected]a29a517a2011-01-21 21:11:12194 CHECK(test_provider);
[email protected]0a60a2e2010-10-25 16:15:21195 external_extension_providers_.push_back(
[email protected]5df038b2012-07-16 19:03:27196 linked_ptr<extensions::ExternalProviderInterface>(test_provider));
[email protected]7a4c6852010-09-16 03:44:22197}
198
[email protected]9060d8b02012-01-13 02:14:30199bool ExtensionService::OnExternalExtensionUpdateUrlFound(
[email protected]7a4c6852010-09-16 03:44:22200 const std::string& id,
[email protected]d8fd0fd2014-03-24 13:16:06201 const std::string& install_parameter,
[email protected]21a5a672010-11-04 10:47:42202 const GURL& update_url,
[email protected]464213a2013-10-15 01:06:48203 Manifest::Location location,
204 int creation_flags,
205 bool mark_acknowledged) {
[email protected]ab22ba42011-01-14 16:36:38206 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
207 CHECK(Extension::IdIsValid(id));
[email protected]a8af9fdb2010-10-28 21:52:20208
[email protected]044e86992014-01-24 22:59:11209 if (Manifest::IsExternalLocation(location)) {
210 // All extensions that are not user specific can be cached.
211 extensions::ExtensionCache::GetInstance()->AllowCaching(id);
212 }
213
[email protected]8a87a5332011-08-11 17:54:59214 const Extension* extension = GetExtensionById(id, true);
215 if (extension) {
216 // Already installed. Skip this install if the current location has
217 // higher priority than |location|.
[email protected]1d5e58b2013-01-31 08:41:40218 Manifest::Location current = extension->location();
219 if (current == Manifest::GetHigherPriorityLocation(current, location))
[email protected]9060d8b02012-01-13 02:14:30220 return false;
[email protected]8a87a5332011-08-11 17:54:59221 // Otherwise, overwrite the current installation.
[email protected]7a4c6852010-09-16 03:44:22222 }
[email protected]9060d8b02012-01-13 02:14:30223
224 // Add |id| to the set of pending extensions. If it can not be added,
225 // then there is already a pending record from a higher-priority install
226 // source. In this case, signal that this extension will not be
227 // installed by returning false.
228 if (!pending_extension_manager()->AddFromExternalUpdateUrl(
[email protected]d8fd0fd2014-03-24 13:16:06229 id,
230 install_parameter,
231 update_url,
232 location,
233 creation_flags,
234 mark_acknowledged)) {
[email protected]9060d8b02012-01-13 02:14:30235 return false;
[email protected]31bb5ee62012-09-12 22:58:40236 }
[email protected]9060d8b02012-01-13 02:14:30237
[email protected]94fde232012-04-27 10:22:30238 update_once_all_providers_are_ready_ = true;
[email protected]9060d8b02012-01-13 02:14:30239 return true;
[email protected]7a4c6852010-09-16 03:44:22240}
241
[email protected]6aeac8342010-10-01 20:21:18242// static
[email protected]d6ebc9792011-04-07 18:18:33243// This function is used to implement the command-line switch
[email protected]3bdba0d2011-08-23 07:17:30244// --uninstall-extension, and to uninstall an extension via sync. The LOG
245// statements within this function are used to inform the user if the uninstall
246// cannot be done.
[email protected]eaa7dd182010-12-14 11:09:00247bool ExtensionService::UninstallExtensionHelper(
248 ExtensionService* extensions_service,
[email protected]6aeac8342010-10-01 20:21:18249 const std::string& extension_id) {
[email protected]d6ebc9792011-04-07 18:18:33250 // We can't call UninstallExtension with an invalid extension ID.
[email protected]31bb5ee62012-09-12 22:58:40251 if (!extensions_service->GetInstalledExtension(extension_id)) {
[email protected]6aeac8342010-10-01 20:21:18252 LOG(WARNING) << "Attempted uninstallation of non-existent extension with "
[email protected]95da88c42011-03-31 10:07:33253 << "id: " << extension_id;
254 return false;
[email protected]6aeac8342010-10-01 20:21:18255 }
256
[email protected]d6ebc9792011-04-07 18:18:33257 // The following call to UninstallExtension will not allow an uninstall of a
258 // policy-controlled extension.
[email protected]439f1e32013-12-09 20:09:09259 base::string16 error;
[email protected]d6ebc9792011-04-07 18:18:33260 if (!extensions_service->UninstallExtension(extension_id, false, &error)) {
261 LOG(WARNING) << "Cannot uninstall extension with id " << extension_id
262 << ": " << error;
263 return false;
264 }
[email protected]95da88c42011-03-31 10:07:33265
[email protected]6aeac8342010-10-01 20:21:18266 return true;
267}
268
[email protected]eaa7dd182010-12-14 11:09:00269ExtensionService::ExtensionService(Profile* profile,
[email protected]f0841cd2011-01-19 15:07:24270 const CommandLine* command_line,
[email protected]650b2d52013-02-10 03:41:45271 const base::FilePath& install_directory,
[email protected]45759612012-07-10 17:21:23272 extensions::ExtensionPrefs* extension_prefs,
[email protected]fdd679b2012-11-15 20:49:39273 extensions::Blacklist* blacklist,
[email protected]0436b102011-04-15 18:30:03274 bool autoupdate_enabled,
[email protected]4a10006a2013-05-17 23:18:35275 bool extensions_enabled,
276 extensions::OneShotEvent* ready)
[email protected]fdd679b2012-11-15 20:49:39277 : extensions::Blacklist::Observer(blacklist),
278 profile_(profile),
[email protected]bd306722012-07-11 20:43:59279 system_(extensions::ExtensionSystem::Get(profile)),
[email protected]73c47932010-12-06 18:13:43280 extension_prefs_(extension_prefs),
[email protected]695b5712012-12-06 23:55:28281 blacklist_(blacklist),
[email protected]f8aefb132013-10-30 09:29:52282 extension_sync_service_(NULL),
[email protected]5fdfa562013-12-27 17:43:59283 registry_(extensions::ExtensionRegistry::Get(profile)),
[email protected]6c9bedf2014-05-21 03:55:51284 pending_extension_manager_(profile),
[email protected]a9b00ac2009-06-25 21:03:23285 install_directory_(install_directory),
[email protected]0436b102011-04-15 18:30:03286 extensions_enabled_(extensions_enabled),
[email protected]e81dba32009-06-19 20:19:13287 show_extensions_prompts_(true),
[email protected]fc332ae2012-11-14 20:17:33288 install_updates_when_idle_(true),
[email protected]4a10006a2013-05-17 23:18:35289 ready_(ready),
[email protected]dff1e042012-04-27 10:59:18290 update_once_all_providers_are_ready_(false),
[email protected]3c4abc82012-10-22 22:25:54291 browser_terminating_(false),
[email protected]9f4e4f082013-06-21 07:11:19292 installs_delayed_for_gc_(false),
[email protected]e5f8fffe2014-04-02 00:30:44293 is_first_run_(false),
[email protected]90878c52014-04-04 18:21:02294 shared_module_service_(new extensions::SharedModuleService(profile_)) {
[email protected]a29a517a2011-01-21 21:11:12295 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]a8af9fdb2010-10-28 21:52:20296
[email protected]36a784c2009-06-23 06:21:08297 // Figure out if extension installation should be enabled.
[email protected]367d9b172013-12-03 00:31:02298 if (extensions::ExtensionsBrowserClient::Get()->AreExtensionsDisabled(
299 *command_line, profile))
[email protected]6d60703b2009-08-29 01:29:23300 extensions_enabled_ = false;
[email protected]36a784c2009-06-23 06:21:08301
[email protected]3c4abc82012-10-22 22:25:54302 registrar_.Add(this, chrome::NOTIFICATION_APP_TERMINATING,
303 content::NotificationService::AllBrowserContextsAndSources());
[email protected]432115822011-07-10 15:52:27304 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_PROCESS_TERMINATED,
[email protected]ad50def52011-10-19 23:17:07305 content::NotificationService::AllBrowserContextsAndSources());
[email protected]432115822011-07-10 15:52:27306 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_TERMINATED,
[email protected]ad50def52011-10-19 23:17:07307 content::NotificationService::AllBrowserContextsAndSources());
[email protected]92dd8d92013-02-26 00:41:08308 registrar_.Add(this, chrome::NOTIFICATION_UPGRADE_RECOMMENDED,
309 content::NotificationService::AllBrowserContextsAndSources());
[email protected]ebe07772014-05-22 04:16:06310 registrar_.Add(this,
311 chrome::NOTIFICATION_PROFILE_DESTRUCTION_STARTED,
312 content::Source<Profile>(profile_));
[email protected]2fb7dc982010-09-29 12:24:28313 pref_change_registrar_.Init(profile->GetPrefs());
[email protected]90bb38d2012-11-14 18:36:03314 base::Closure callback =
315 base::Bind(&ExtensionService::OnExtensionInstallPrefChanged,
316 base::Unretained(this));
[email protected]234fc5ff2014-01-16 23:32:28317 pref_change_registrar_.Add(extensions::pref_names::kInstallAllowList,
318 callback);
319 pref_change_registrar_.Add(extensions::pref_names::kInstallDenyList,
320 callback);
321 pref_change_registrar_.Add(extensions::pref_names::kAllowedTypes, callback);
[email protected]4814b512009-11-07 00:12:29322
[email protected]93fd78f42009-07-10 16:43:17323 // Set up the ExtensionUpdater
324 if (autoupdate_enabled) {
[email protected]501105b2013-09-26 05:42:02325 int update_frequency = extensions::kDefaultUpdateFrequencySeconds;
[email protected]93fd78f42009-07-10 16:43:17326 if (command_line->HasSwitch(switches::kExtensionsUpdateFrequency)) {
[email protected]e83326f2010-07-31 17:29:25327 base::StringToInt(command_line->GetSwitchValueASCII(
328 switches::kExtensionsUpdateFrequency),
329 &update_frequency);
[email protected]93fd78f42009-07-10 16:43:17330 }
[email protected]044e86992014-01-24 22:59:11331 updater_.reset(new extensions::ExtensionUpdater(
332 this,
333 extension_prefs,
334 profile->GetPrefs(),
335 profile,
336 update_frequency,
337 extensions::ExtensionCache::GetInstance()));
[email protected]93fd78f42009-07-10 16:43:17338 }
339
[email protected]25ae0152011-11-18 14:40:02340 component_loader_.reset(
341 new extensions::ComponentLoader(this,
342 profile->GetPrefs(),
[email protected]55e16cd2013-12-18 04:36:08343 g_browser_process->local_state(),
344 profile));
[email protected]8e4560b62011-01-14 10:09:14345
[email protected]0436b102011-04-15 18:30:03346 if (extensions_enabled_) {
[email protected]ae4c37e2012-12-21 01:16:25347 extensions::ExternalProviderImpl::CreateExternalProviders(
348 this, profile_, &external_extension_providers_);
[email protected]873531342011-03-09 12:16:05349 }
[email protected]b671760b2010-07-15 21:13:47350
[email protected]74474042013-11-21 12:03:54351 // Set this as the ExtensionService for app sorting to ensure it causes syncs
352 // if required.
[email protected]b3aa7182013-04-25 04:45:23353 is_first_run_ = !extension_prefs_->SetAlertSystemFirstRun();
354
[email protected]373daf972014-04-10 01:50:44355 error_controller_.reset(
356 new extensions::ExtensionErrorController(profile_, is_first_run_));
357
[email protected]9ce11d22012-08-08 23:20:13358#if defined(ENABLE_EXTENSIONS)
[email protected]c77f2352012-08-08 22:07:58359 extension_action_storage_manager_.reset(
360 new extensions::ExtensionActionStorageManager(profile_));
[email protected]9ce11d22012-08-08 23:20:13361#endif
[email protected]c77f2352012-08-08 22:07:58362
[email protected]4c9201c42013-08-16 04:56:21363 shared_module_policy_provider_.reset(new SharedModuleProvider);
364
[email protected]cb0e50312011-05-09 15:03:07365 // How long is the path to the Extensions directory?
366 UMA_HISTOGRAM_CUSTOM_COUNTS("Extensions.ExtensionRootPathLength",
367 install_directory_.value().length(), 0, 500, 100);
[email protected]6014d672008-12-05 00:38:25368}
369
[email protected]84df8332011-12-06 18:22:46370const ExtensionSet* ExtensionService::extensions() const {
[email protected]bb1bc9b32013-12-21 03:09:14371 return &registry_->enabled_extensions();
[email protected]ddb1e5a2010-12-13 20:10:45372}
373
[email protected]3f213ad2012-07-26 23:39:41374extensions::PendingExtensionManager*
375 ExtensionService::pending_extension_manager() {
[email protected]b2907fd2011-03-25 16:43:37376 return &pending_extension_manager_;
[email protected]ddb1e5a2010-12-13 20:10:45377}
378
[email protected]eaa7dd182010-12-14 11:09:00379ExtensionService::~ExtensionService() {
[email protected]c8d407e2011-04-28 21:27:17380 // No need to unload extensions here because they are profile-scoped, and the
381 // profile is in the process of being deleted.
[email protected]94b4ffc2011-02-04 05:55:17382
[email protected]5df038b2012-07-16 19:03:27383 extensions::ProviderCollection::const_iterator i;
[email protected]8e4560b62011-01-14 10:09:14384 for (i = external_extension_providers_.begin();
385 i != external_extension_providers_.end(); ++i) {
[email protected]5df038b2012-07-16 19:03:27386 extensions::ExternalProviderInterface* provider = i->get();
[email protected]8e4560b62011-01-14 10:09:14387 provider->ServiceShutdown();
388 }
[email protected]6014d672008-12-05 00:38:25389}
390
[email protected]037228a2012-10-05 01:36:16391void ExtensionService::Shutdown() {
[email protected]4c9201c42013-08-16 04:56:21392 system_->management_policy()->UnregisterProvider(
393 shared_module_policy_provider_.get());
[email protected]037228a2012-10-05 01:36:16394}
395
[email protected]b2907fd2011-03-25 16:43:37396const Extension* ExtensionService::GetExtensionById(
397 const std::string& id, bool include_disabled) const {
[email protected]599539802014-01-07 23:06:00398 int include_mask = ExtensionRegistry::ENABLED;
[email protected]695b5712012-12-06 23:55:28399 if (include_disabled) {
400 // Include blacklisted extensions here because there are hundreds of
401 // callers of this function, and many might assume that this includes those
402 // that have been disabled due to blacklisting.
[email protected]599539802014-01-07 23:06:00403 include_mask |= ExtensionRegistry::DISABLED |
404 ExtensionRegistry::BLACKLISTED;
[email protected]695b5712012-12-06 23:55:28405 }
[email protected]599539802014-01-07 23:06:00406 return registry_->GetExtensionById(id, include_mask);
[email protected]695b5712012-12-06 23:55:28407}
408
[email protected]eaa7dd182010-12-14 11:09:00409void ExtensionService::Init() {
[email protected]a29a517a2011-01-21 21:11:12410 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]a8af9fdb2010-10-28 21:52:20411
[email protected]3350d712013-11-18 09:32:24412 base::Time begin_time = base::Time::Now();
413
[email protected]4a10006a2013-05-17 23:18:35414 DCHECK(!is_ready()); // Can't redo init.
[email protected]bb1bc9b32013-12-21 03:09:14415 DCHECK_EQ(registry_->enabled_extensions().size(), 0u);
[email protected]9f1087e2009-06-15 17:29:32416
[email protected]820d9bd2013-04-03 03:46:03417 const CommandLine* cmd_line = CommandLine::ForCurrentProcess();
[email protected]820d9bd2013-04-03 03:46:03418 if (cmd_line->HasSwitch(switches::kInstallFromWebstore) ||
419 cmd_line->HasSwitch(switches::kLimitedInstallFromWebstore)) {
420 // The sole purpose of this launch is to install a new extension from CWS
421 // and immediately terminate: loading already installed extensions is
422 // unnecessary and may interfere with the inline install dialog (e.g. if an
423 // extension listens to onStartup and opens a window).
424 SetReadyAndNotifyListeners();
[email protected]ae4c37e2012-12-21 01:16:25425 } else {
[email protected]47b60072013-06-20 10:35:56426 // LoadAllExtensions() calls OnLoadedInstalledExtensions().
427 component_loader_->LoadAll();
428 extensions::InstalledLoader(this).LoadAllExtensions();
[email protected]9f4e4f082013-06-21 07:11:19429
[email protected]59ee99d2013-10-11 15:46:16430 ReconcileKnownDisabled();
431
[email protected]2edd57852013-08-14 22:07:40432 // Attempt to re-enable extensions whose only disable reason is reloading.
433 std::vector<std::string> extensions_to_enable;
[email protected]bb1bc9b32013-12-21 03:09:14434 const ExtensionSet& disabled_extensions = registry_->disabled_extensions();
435 for (ExtensionSet::const_iterator iter = disabled_extensions.begin();
436 iter != disabled_extensions.end(); ++iter) {
[email protected]2edd57852013-08-14 22:07:40437 const Extension* e = iter->get();
438 if (extension_prefs_->GetDisableReasons(e->id()) ==
439 Extension::DISABLE_RELOAD) {
440 extensions_to_enable.push_back(e->id());
441 }
442 }
443 for (std::vector<std::string>::iterator it = extensions_to_enable.begin();
444 it != extensions_to_enable.end(); ++it) {
445 EnableExtension(*it);
446 }
447
[email protected]9f4e4f082013-06-21 07:11:19448 // Finish install (if possible) of extensions that were still delayed while
449 // the browser was shut down.
450 scoped_ptr<extensions::ExtensionPrefs::ExtensionsInfo> delayed_info(
451 extension_prefs_->GetAllDelayedInstallInfo());
452 for (size_t i = 0; i < delayed_info->size(); ++i) {
453 ExtensionInfo* info = delayed_info->at(i).get();
454 scoped_refptr<const Extension> extension(NULL);
455 if (info->extension_manifest) {
456 std::string error;
457 extension = Extension::Create(
458 info->extension_path,
459 info->extension_location,
460 *info->extension_manifest,
461 extension_prefs_->GetDelayedInstallCreationFlags(
462 info->extension_id),
463 info->extension_id,
464 &error);
465 if (extension.get())
466 delayed_installs_.Insert(extension);
467 }
468 }
469 MaybeFinishDelayedInstallations();
470
471 scoped_ptr<extensions::ExtensionPrefs::ExtensionsInfo> delayed_info2(
472 extension_prefs_->GetAllDelayedInstallInfo());
473 UMA_HISTOGRAM_COUNTS_100("Extensions.UpdateOnLoad",
474 delayed_info2->size() - delayed_info->size());
475
[email protected]47b60072013-06-20 10:35:56476 SetReadyAndNotifyListeners();
[email protected]ae4c37e2012-12-21 01:16:25477
[email protected]47b60072013-06-20 10:35:56478 // TODO(erikkay) this should probably be deferred to a future point
479 // rather than running immediately at startup.
480 CheckForExternalUpdates();
[email protected]894bb502009-05-21 22:39:57481
[email protected]4c9201c42013-08-16 04:56:21482 system_->management_policy()->RegisterProvider(
483 shared_module_policy_provider_.get());
[email protected]2d19eb6e2014-01-27 17:30:00484
485 LoadGreylistFromPrefs();
[email protected]399583b2012-12-11 09:33:42486 }
[email protected]3350d712013-11-18 09:32:24487
488 UMA_HISTOGRAM_TIMES("Extensions.ExtensionServiceInitTime",
489 base::Time::Now() - begin_time);
[email protected]6014d672008-12-05 00:38:25490}
491
[email protected]2d19eb6e2014-01-27 17:30:00492void ExtensionService::LoadGreylistFromPrefs() {
[email protected]f47f7172014-03-19 19:27:10493 scoped_ptr<ExtensionSet> all_extensions =
494 registry_->GenerateInstalledExtensionsSet();
[email protected]2d19eb6e2014-01-27 17:30:00495
496 for (ExtensionSet::const_iterator it = all_extensions->begin();
497 it != all_extensions->end(); ++it) {
498 extensions::BlacklistState state =
499 extension_prefs_->GetExtensionBlacklistState((*it)->id());
500 if (state == extensions::BLACKLISTED_SECURITY_VULNERABILITY ||
501 state == extensions::BLACKLISTED_POTENTIALLY_UNWANTED ||
502 state == extensions::BLACKLISTED_CWS_POLICY_VIOLATION)
503 greylist_.Insert(*it);
504 }
505}
506
[email protected]31bb5ee62012-09-12 22:58:40507bool ExtensionService::UpdateExtension(const std::string& id,
[email protected]650b2d52013-02-10 03:41:45508 const base::FilePath& extension_path,
[email protected]044e86992014-01-24 22:59:11509 bool file_ownership_passed,
[email protected]31bb5ee62012-09-12 22:58:40510 CrxInstaller** out_crx_installer) {
[email protected]a29a517a2011-01-21 21:11:12511 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]3c4abc82012-10-22 22:25:54512 if (browser_terminating_) {
513 LOG(WARNING) << "Skipping UpdateExtension due to browser shutdown";
514 // Leak the temp file at extension_path. We don't want to add to the disk
515 // I/O burden at shutdown, we can't rely on the I/O completing anyway, and
516 // the file is in the OS temp directory which should be cleaned up for us.
517 return false;
518 }
[email protected]a8af9fdb2010-10-28 21:52:20519
[email protected]3f213ad2012-07-26 23:39:41520 const extensions::PendingExtensionInfo* pending_extension_info =
[email protected]51a3bf8b2012-06-08 22:53:06521 pending_extension_manager()->GetById(id);
[email protected]8ef78fd2010-08-19 17:14:32522
[email protected]695b5712012-12-06 23:55:28523 const Extension* extension = GetInstalledExtension(id);
[email protected]51a3bf8b2012-06-08 22:53:06524 if (!pending_extension_info && !extension) {
[email protected]aa142702010-03-26 01:26:33525 LOG(WARNING) << "Will not update extension " << id
526 << " because it is not installed or pending";
527 // Delete extension_path since we're not creating a CrxInstaller
528 // that would do it for us.
[email protected]7f8f24f2012-11-15 19:40:14529 if (!GetFileTaskRunner()->PostTask(
530 FROM_HERE,
[email protected]53612e82011-10-18 18:00:36531 base::Bind(
[email protected]85df9d12014-04-15 17:02:14532 &extensions::file_util::DeleteFile, extension_path, false)))
[email protected]14908b72011-04-20 06:54:36533 NOTREACHED();
[email protected]420a0ec2011-06-01 01:07:03534
535 return false;
[email protected]e957fe52009-06-23 16:51:05536 }
537
[email protected]aa142702010-03-26 01:26:33538 // We want a silent install only for non-pending extensions and
539 // pending extensions that have install_silently set.
[email protected]f8636f92013-08-09 21:02:37540 scoped_ptr<ExtensionInstallPrompt> client;
[email protected]91e51d612012-10-21 23:03:05541 if (pending_extension_info && !pending_extension_info->install_silently())
[email protected]f8636f92013-08-09 21:02:37542 client.reset(ExtensionInstallUI::CreateInstallPromptWithProfile(profile_));
[email protected]aa142702010-03-26 01:26:33543
[email protected]f8636f92013-08-09 21:02:37544 scoped_refptr<CrxInstaller> installer(
545 CrxInstaller::Create(this, client.Pass()));
[email protected]6dfbbf82010-03-12 23:09:16546 installer->set_expected_id(id);
[email protected]464213a2013-10-15 01:06:48547 int creation_flags = Extension::NO_FLAGS;
[email protected]51a3bf8b2012-06-08 22:53:06548 if (pending_extension_info) {
549 installer->set_install_source(pending_extension_info->install_source());
550 if (pending_extension_info->install_silently())
551 installer->set_allow_silent_install(true);
[email protected]21db9ef2014-05-16 02:06:27552 if (pending_extension_info->remote_install())
553 installer->set_grant_permissions(false);
[email protected]464213a2013-10-15 01:06:48554 creation_flags = pending_extension_info->creation_flags();
555 if (pending_extension_info->mark_acknowledged())
556 AcknowledgeExternalExtension(id);
[email protected]51a3bf8b2012-06-08 22:53:06557 } else if (extension) {
[email protected]5eb375e92010-11-26 07:50:41558 installer->set_install_source(extension->location());
[email protected]51a3bf8b2012-06-08 22:53:06559 }
[email protected]7d8b7072012-04-07 01:07:46560 // If the extension was installed from or has migrated to the webstore, or
[email protected]fcb2c2c2012-10-17 21:08:45561 // its auto-update URL is from the webstore, treat it as a webstore install.
562 // Note that we ignore some older extensions with blank auto-update URLs
563 // because we are mostly concerned with restrictions on NaCl extensions,
564 // which are newer.
[email protected]75764512011-12-19 19:54:28565 if ((extension && extension->from_webstore()) ||
[email protected]4a5fe3e22013-06-04 07:06:38566 (extension && extensions::ManifestURL::UpdatesFromGallery(extension)) ||
[email protected]963d13c2012-09-29 17:13:35567 (!extension && extension_urls::IsWebstoreUpdateUrl(
[email protected]51a3bf8b2012-06-08 22:53:06568 pending_extension_info->update_url()))) {
[email protected]a12ce8b22012-01-17 18:40:53569 creation_flags |= Extension::FROM_WEBSTORE;
570 }
571
572 // Bookmark apps being updated is kind of a contradiction, but that's because
573 // we mark the default apps as bookmark apps, and they're hosted in the web
574 // store, thus they can get updated. See http://crbug.com/101605 for more
575 // details.
576 if (extension && extension->from_bookmark())
577 creation_flags |= Extension::FROM_BOOKMARK;
578
[email protected]e33bbc22012-08-27 22:05:46579 if (extension && extension->was_installed_by_default())
580 creation_flags |= Extension::WAS_INSTALLED_BY_DEFAULT;
581
[email protected]acc3c7c22014-03-19 06:23:39582 if (extension && extension->was_installed_by_oem())
583 creation_flags |= Extension::WAS_INSTALLED_BY_OEM;
584
[email protected]658eae52014-06-14 20:28:05585 if (extension) {
[email protected]411f8ae2014-05-22 11:12:23586 installer->set_is_ephemeral(extension_prefs_->IsEphemeralApp(id));
[email protected]658eae52014-06-14 20:28:05587 installer->set_install_flag(extensions::kInstallFlagDoNotSync,
588 extension_prefs_->DoNotSync(id));
589 }
[email protected]ab6c7be42014-01-16 02:05:54590
[email protected]a12ce8b22012-01-17 18:40:53591 installer->set_creation_flags(creation_flags);
592
[email protected]044e86992014-01-24 22:59:11593 installer->set_delete_source(file_ownership_passed);
[email protected]cb0e50312011-05-09 15:03:07594 installer->set_install_cause(extension_misc::INSTALL_CAUSE_UPDATE);
[email protected]6dfbbf82010-03-12 23:09:16595 installer->InstallCrx(extension_path);
[email protected]420a0ec2011-06-01 01:07:03596
597 if (out_crx_installer)
[email protected]dc24976f2013-06-02 21:15:09598 *out_crx_installer = installer.get();
[email protected]420a0ec2011-06-01 01:07:03599
600 return true;
[email protected]e957fe52009-06-23 16:51:05601}
602
[email protected]757d60a2014-05-23 00:11:44603void ExtensionService::ReloadExtension(
604 // "transient" because the process of reloading may cause the reference
605 // to become invalid. Instead, use |extension_id|, a copy.
606 const std::string& transient_extension_id) {
[email protected]a29a517a2011-01-21 21:11:12607 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]2a947202013-03-06 04:58:05608
609 // If the extension is already reloading, don't reload again.
[email protected]757d60a2014-05-23 00:11:44610 if (extension_prefs_->GetDisableReasons(transient_extension_id) &
[email protected]2a947202013-03-06 04:58:05611 Extension::DISABLE_RELOAD) {
612 return;
613 }
614
[email protected]757d60a2014-05-23 00:11:44615 // Ignore attempts to reload a blacklisted extension. Sometimes this can
616 // happen in a convoluted reload sequence triggered by the termination of a
617 // blacklisted extension and a naive attempt to reload it. For an example see
618 // http://crbug.com/373842.
619 if (registry_->blacklisted_extensions().Contains(transient_extension_id))
620 return;
621
[email protected]650b2d52013-02-10 03:41:45622 base::FilePath path;
[email protected]757d60a2014-05-23 00:11:44623
624 std::string extension_id = transient_extension_id;
625 const Extension* transient_current_extension =
626 GetExtensionById(extension_id, false);
[email protected]9cddd4702009-07-27 22:09:40627
[email protected]f17dbd42010-08-16 23:21:10628 // Disable the extension if it's loaded. It might not be loaded if it crashed.
[email protected]757d60a2014-05-23 00:11:44629 if (transient_current_extension) {
[email protected]4814b512009-11-07 00:12:29630 // If the extension has an inspector open for its background page, detach
631 // the inspector and hang onto a cookie for it, so that we can reattach
632 // later.
[email protected]31d8f5f22012-04-02 15:22:08633 // TODO(yoz): this is not incognito-safe!
[email protected]98b6d942013-11-10 00:34:07634 extensions::ProcessManager* manager = system_->process_manager();
[email protected]3a1dc572012-07-31 22:25:13635 extensions::ExtensionHost* host =
636 manager->GetBackgroundHostForExtension(extension_id);
[email protected]98f66112012-12-25 12:59:36637 if (host && DevToolsAgentHost::HasFor(host->render_view_host())) {
[email protected]4814b512009-11-07 00:12:29638 // Look for an open inspector for the background page.
[email protected]04ea1bb2013-07-10 09:26:09639 scoped_refptr<DevToolsAgentHost> agent_host =
640 DevToolsAgentHost::GetOrCreateFor(host->render_view_host());
641 agent_host->DisconnectRenderViewHost();
642 orphaned_dev_tools_[extension_id] = agent_host;
[email protected]4814b512009-11-07 00:12:29643 }
644
[email protected]757d60a2014-05-23 00:11:44645 path = transient_current_extension->path();
[email protected]58076192013-07-19 19:43:50646 // BeingUpgraded is set back to false when the extension is added.
[email protected]757d60a2014-05-23 00:11:44647 system_->runtime_data()->SetBeingUpgraded(transient_current_extension,
648 true);
[email protected]44d62b62012-04-11 00:06:03649 DisableExtension(extension_id, Extension::DISABLE_RELOAD);
[email protected]b914e2952013-04-26 07:10:03650 reloading_extensions_.insert(extension_id);
[email protected]1eb175082010-02-10 09:26:16651 } else {
652 path = unloaded_extension_paths_[extension_id];
[email protected]b65272f2009-08-31 15:47:06653 }
654
[email protected]757d60a2014-05-23 00:11:44655 transient_current_extension = NULL;
656
[email protected]9f4e4f082013-06-21 07:11:19657 if (delayed_installs_.Contains(extension_id)) {
[email protected]6f6101832012-11-27 22:10:48658 FinishDelayedInstallation(extension_id);
[email protected]0db124b02012-11-07 04:55:05659 return;
660 }
661
[email protected]43ceb002012-02-10 23:19:15662 // If we're reloading a component extension, use the component extension
663 // loader's reloader.
664 if (component_loader_->Exists(extension_id)) {
[email protected]e178ad92013-06-28 02:29:25665 SetBeingReloaded(extension_id, true);
[email protected]43ceb002012-02-10 23:19:15666 component_loader_->Reload(extension_id);
[email protected]e178ad92013-06-28 02:29:25667 SetBeingReloaded(extension_id, false);
[email protected]43ceb002012-02-10 23:19:15668 return;
669 }
670
[email protected]e6090e42010-03-23 22:44:08671 // Check the installed extensions to see if what we're reloading was already
672 // installed.
[email protected]e178ad92013-06-28 02:29:25673 SetBeingReloaded(extension_id, true);
[email protected]e6090e42010-03-23 22:44:08674 scoped_ptr<ExtensionInfo> installed_extension(
675 extension_prefs_->GetInstalledExtensionInfo(extension_id));
676 if (installed_extension.get() &&
677 installed_extension->extension_manifest.get()) {
[email protected]d8c8f25f2011-11-02 18:18:01678 extensions::InstalledLoader(this).Load(*installed_extension, false);
[email protected]e6090e42010-03-23 22:44:08679 } else {
[email protected]d8c8f25f2011-11-02 18:18:01680 // Otherwise, the extension is unpacked (location LOAD).
[email protected]e6090e42010-03-23 22:44:08681 // We should always be able to remember the extension's path. If it's not in
682 // the map, someone failed to update |unloaded_extension_paths_|.
683 CHECK(!path.empty());
[email protected]d8c8f25f2011-11-02 18:18:01684 extensions::UnpackedInstaller::Create(this)->Load(path);
[email protected]e6090e42010-03-23 22:44:08685 }
[email protected]e178ad92013-06-28 02:29:25686 // When reloading is done, mark this extension as done reloading.
687 SetBeingReloaded(extension_id, false);
[email protected]9cddd4702009-07-27 22:09:40688}
689
[email protected]757d60a2014-05-23 00:11:44690bool ExtensionService::UninstallExtension(
691 // "transient" because the process of uninstalling may cause the reference
692 // to become invalid. Instead, use |extenson->id()|.
693 const std::string& transient_extension_id,
694 bool external_uninstall,
695 base::string16* error) {
[email protected]a29a517a2011-01-21 21:11:12696 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]a8af9fdb2010-10-28 21:52:20697
[email protected]757d60a2014-05-23 00:11:44698 scoped_refptr<const Extension> extension =
699 GetInstalledExtension(transient_extension_id);
[email protected]631cf822009-05-15 07:01:25700
[email protected]e7afe2452010-08-22 16:19:13701 // Callers should not send us nonexistent extensions.
[email protected]dc24976f2013-06-02 21:15:09702 CHECK(extension.get());
[email protected]9f1087e2009-06-15 17:29:32703
[email protected]95da88c42011-03-31 10:07:33704 // Policy change which triggers an uninstall will always set
705 // |external_uninstall| to true so this is the only way to uninstall
706 // managed extensions.
[email protected]90878c52014-04-04 18:21:02707 // Shared modules being uninstalled will also set |external_uninstall| to true
708 // so that we can guarantee users don't uninstall a shared module.
709 // (crbug.com/273300)
710 // TODO(rdevlin.cronin): This is probably not right. We should do something
711 // else, like include an enum IS_INTERNAL_UNINSTALL or IS_USER_UNINSTALL so
712 // we don't do this.
[email protected]65187152012-06-02 13:14:14713 if (!external_uninstall &&
714 !system_->management_policy()->UserMayModifySettings(
715 extension.get(), error)) {
[email protected]ad50def52011-10-19 23:17:07716 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:27717 chrome::NOTIFICATION_EXTENSION_UNINSTALL_NOT_ALLOWED,
[email protected]6c2381d2011-10-19 02:52:53718 content::Source<Profile>(profile_),
[email protected]dc24976f2013-06-02 21:15:09719 content::Details<const Extension>(extension.get()));
[email protected]d6ebc9792011-04-07 18:18:33720 return false;
721 }
[email protected]95da88c42011-03-31 10:07:33722
[email protected]65f173552012-06-28 22:43:58723 syncer::SyncChange sync_change;
[email protected]f8aefb132013-10-30 09:29:52724 if (extension_sync_service_) {
725 sync_change = extension_sync_service_->PrepareToSyncUninstallExtension(
726 extension.get(), is_ready());
[email protected]3bdba0d2011-08-23 07:17:30727 }
728
[email protected]d820bc52014-03-13 05:35:23729 system_->install_verifier()->Remove(extension->id());
[email protected]ffd2f79e2013-11-14 00:11:46730
[email protected]dc24976f2013-06-02 21:15:09731 if (IsUnacknowledgedExternalExtension(extension.get())) {
[email protected]d96eb512012-11-01 23:44:08732 UMA_HISTOGRAM_ENUMERATION("Extensions.ExternalExtensionEvent",
733 EXTERNAL_EXTENSION_UNINSTALLED,
734 EXTERNAL_EXTENSION_BUCKET_BOUNDARY);
[email protected]446e37e2013-08-07 00:30:02735 if (extensions::ManifestURL::UpdatesFromGallery(extension.get())) {
736 UMA_HISTOGRAM_ENUMERATION("Extensions.ExternalExtensionEventWebstore",
737 EXTERNAL_EXTENSION_UNINSTALLED,
738 EXTERNAL_EXTENSION_BUCKET_BOUNDARY);
739 } else {
740 UMA_HISTOGRAM_ENUMERATION("Extensions.ExternalExtensionEventNonWebstore",
741 EXTERNAL_EXTENSION_UNINSTALLED,
742 EXTERNAL_EXTENSION_BUCKET_BOUNDARY);
743 }
[email protected]d96eb512012-11-01 23:44:08744 }
[email protected]9b217652010-10-08 22:04:23745 UMA_HISTOGRAM_ENUMERATION("Extensions.UninstallType",
[email protected]7fa19f82010-12-21 19:40:08746 extension->GetType(), 100);
[email protected]dc24976f2013-06-02 21:15:09747 RecordPermissionMessagesHistogram(extension.get(),
[email protected]4c86be582014-06-04 08:39:11748 "Extensions.Permissions_Uninstall2");
[email protected]9b217652010-10-08 22:04:23749
[email protected]831aa212010-03-26 13:55:19750 // Unload before doing more cleanup to ensure that nothing is hanging on to
751 // any of these resources.
[email protected]757d60a2014-05-23 00:11:44752 UnloadExtension(extension->id(), UnloadedExtensionInfo::REASON_UNINSTALL);
[email protected]831aa212010-03-26 13:55:19753
[email protected]9f1087e2009-06-15 17:29:32754 // Tell the backend to start deleting installed extensions on the file thread.
[email protected]12075d12013-02-27 05:38:05755 if (!Manifest::IsUnpackedLocation(extension->location())) {
[email protected]7f8f24f2012-11-15 19:40:14756 if (!GetFileTaskRunner()->PostTask(
757 FROM_HERE,
[email protected]5a145e82014-05-29 22:19:07758 base::Bind(&ExtensionService::UninstallExtensionOnFileThread,
759 extension->id(),
760 profile_,
[email protected]85df9d12014-04-15 17:02:14761 install_directory_,
[email protected]5a145e82014-05-29 22:19:07762 extension->path())))
[email protected]14908b72011-04-20 06:54:36763 NOTREACHED();
[email protected]9f1087e2009-06-15 17:29:32764 }
765
[email protected]ca0336342014-03-21 12:58:34766 // Do not remove the data of ephemeral apps. They will be garbage collected by
767 // EphemeralAppService.
[email protected]757d60a2014-05-23 00:11:44768 if (!extension_prefs_->IsEphemeralApp(extension->id()))
[email protected]ca0336342014-03-21 12:58:34769 extensions::DataDeleter::StartDeleting(profile_, extension.get());
[email protected]0d6ec3a72011-09-02 02:09:43770
[email protected]757d60a2014-05-23 00:11:44771 UntrackTerminatedExtension(extension->id());
[email protected]211030342010-09-30 18:41:06772
773 // Notify interested parties that we've uninstalled this extension.
[email protected]ad50def52011-10-19 23:17:07774 content::NotificationService::current()->Notify(
[email protected]bbf8d30b2014-05-29 16:45:07775 chrome::NOTIFICATION_EXTENSION_UNINSTALLED_DEPRECATED,
[email protected]6c2381d2011-10-19 02:52:53776 content::Source<Profile>(profile_),
[email protected]dc24976f2013-06-02 21:15:09777 content::Details<const Extension>(extension.get()));
[email protected]1d7f2482014-05-24 00:11:51778 ExtensionRegistry::Get(profile_)->TriggerOnUninstalled(extension.get());
[email protected]d6ebc9792011-04-07 18:18:33779
[email protected]f8aefb132013-10-30 09:29:52780 if (extension_sync_service_) {
[email protected]757d60a2014-05-23 00:11:44781 extension_sync_service_->ProcessSyncUninstallExtension(extension->id(),
[email protected]f8aefb132013-10-30 09:29:52782 sync_change);
[email protected]3bdba0d2011-08-23 07:17:30783 }
784
[email protected]757d60a2014-05-23 00:11:44785 delayed_installs_.Remove(extension->id());
[email protected]0db124b02012-11-07 04:55:05786
[email protected]757d60a2014-05-23 00:11:44787 extension_prefs_->OnExtensionUninstalled(
788 extension->id(), extension->location(), external_uninstall);
[email protected]d4eda592013-09-18 03:37:57789
[email protected]333b1de2011-09-12 18:28:50790 // Track the uninstallation.
[email protected]49098f702011-10-13 03:47:18791 UMA_HISTOGRAM_ENUMERATION("Extensions.ExtensionUninstalled", 1, 2);
792
[email protected]d6ebc9792011-04-07 18:18:33793 return true;
[email protected]c10da4b02010-03-25 14:38:32794}
795
[email protected]5a145e82014-05-29 22:19:07796// static
797void ExtensionService::UninstallExtensionOnFileThread(
798 const std::string& id,
799 Profile* profile,
800 const base::FilePath& install_dir,
801 const base::FilePath& extension_path) {
802 extensions::ExtensionAssetsManager* assets_manager =
803 extensions::ExtensionAssetsManager::GetInstance();
804 assets_manager->UninstallExtension(id, profile, install_dir, extension_path);
805}
806
[email protected]c3cfb012011-04-06 22:07:35807bool ExtensionService::IsExtensionEnabled(
808 const std::string& extension_id) const {
[email protected]bb1bc9b32013-12-21 03:09:14809 if (registry_->enabled_extensions().Contains(extension_id) ||
810 registry_->terminated_extensions().Contains(extension_id)) {
[email protected]36429da2011-07-11 20:25:18811 return true;
[email protected]dc9a74f72012-08-17 18:07:21812 }
[email protected]36429da2011-07-11 20:25:18813
[email protected]bb1bc9b32013-12-21 03:09:14814 if (registry_->disabled_extensions().Contains(extension_id) ||
815 registry_->blacklisted_extensions().Contains(extension_id)) {
[email protected]ad83ca242011-07-29 01:32:25816 return false;
[email protected]695b5712012-12-06 23:55:28817 }
[email protected]ad83ca242011-07-29 01:32:25818
819 // If the extension hasn't been loaded yet, check the prefs for it. Assume
820 // enabled unless otherwise noted.
821 return !extension_prefs_->IsExtensionDisabled(extension_id) &&
[email protected]27e528322014-05-27 20:54:30822 !extension_prefs_->IsExtensionBlacklisted(extension_id) &&
[email protected]f574c402012-12-04 23:20:31823 !extension_prefs_->IsExternalExtensionUninstalled(extension_id);
[email protected]c3cfb012011-04-06 22:07:35824}
825
[email protected]eaa7dd182010-12-14 11:09:00826void ExtensionService::EnableExtension(const std::string& extension_id) {
[email protected]a29a517a2011-01-21 21:11:12827 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]a8af9fdb2010-10-28 21:52:20828
[email protected]06f92562011-04-29 19:27:31829 if (IsExtensionEnabled(extension_id))
[email protected]0c6da502009-08-14 22:32:39830 return;
[email protected]bb1bc9b32013-12-21 03:09:14831 const Extension* extension =
832 registry_->disabled_extensions().GetByID(extension_id);
[email protected]0d54b682013-11-05 14:15:36833
834 ManagementPolicy* policy = system_->management_policy();
835 if (extension && policy->MustRemainDisabled(extension, NULL, NULL)) {
836 UMA_HISTOGRAM_COUNTS_100("Extensions.EnableDeniedByPolicy", 1);
837 return;
838 }
[email protected]0c6da502009-08-14 22:32:39839
[email protected]b3317ad2011-04-28 23:46:00840 extension_prefs_->SetExtensionState(extension_id, Extension::ENABLED);
[email protected]eb5e4f92012-08-15 23:33:28841 extension_prefs_->ClearDisableReasons(extension_id);
[email protected]1784e83a2009-09-08 21:01:52842
[email protected]06f92562011-04-29 19:27:31843 // This can happen if sync enables an extension that is not
844 // installed yet.
845 if (!extension)
846 return;
847
[email protected]d96eb512012-11-01 23:44:08848 if (IsUnacknowledgedExternalExtension(extension)) {
849 UMA_HISTOGRAM_ENUMERATION("Extensions.ExternalExtensionEvent",
850 EXTERNAL_EXTENSION_REENABLED,
851 EXTERNAL_EXTENSION_BUCKET_BOUNDARY);
[email protected]446e37e2013-08-07 00:30:02852 if (extensions::ManifestURL::UpdatesFromGallery(extension)) {
853 UMA_HISTOGRAM_ENUMERATION("Extensions.ExternalExtensionEventWebstore",
854 EXTERNAL_EXTENSION_REENABLED,
855 EXTERNAL_EXTENSION_BUCKET_BOUNDARY);
856 } else {
857 UMA_HISTOGRAM_ENUMERATION("Extensions.ExternalExtensionEventNonWebstore",
858 EXTERNAL_EXTENSION_REENABLED,
859 EXTERNAL_EXTENSION_BUCKET_BOUNDARY);
860 }
[email protected]612a1cb12012-10-17 13:18:03861 AcknowledgeExternalExtension(extension->id());
[email protected]d96eb512012-11-01 23:44:08862 }
[email protected]612a1cb12012-10-17 13:18:03863
[email protected]0c6da502009-08-14 22:32:39864 // Move it over to the enabled list.
[email protected]bb1bc9b32013-12-21 03:09:14865 registry_->AddEnabled(make_scoped_refptr(extension));
866 registry_->RemoveDisabled(extension->id());
[email protected]0c6da502009-08-14 22:32:39867
[email protected]62d30f42009-10-01 22:36:06868 NotifyExtensionLoaded(extension);
[email protected]3bdba0d2011-08-23 07:17:30869
[email protected]f74d7f32012-06-19 19:22:51870 // Notify listeners that the extension was enabled.
871 content::NotificationService::current()->Notify(
872 chrome::NOTIFICATION_EXTENSION_ENABLED,
873 content::Source<Profile>(profile_),
874 content::Details<const Extension>(extension));
875
[email protected]f8aefb132013-10-30 09:29:52876 if (extension_sync_service_)
877 extension_sync_service_->SyncEnableExtension(*extension);
[email protected]0c6da502009-08-14 22:32:39878}
879
[email protected]44d62b62012-04-11 00:06:03880void ExtensionService::DisableExtension(
881 const std::string& extension_id,
882 Extension::DisableReason disable_reason) {
[email protected]a29a517a2011-01-21 21:11:12883 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]a8af9fdb2010-10-28 21:52:20884
[email protected]b2ba9962009-12-10 20:10:15885 // The extension may have been disabled already.
[email protected]06f92562011-04-29 19:27:31886 if (!IsExtensionEnabled(extension_id))
[email protected]1784e83a2009-09-08 21:01:52887 return;
[email protected]1784e83a2009-09-08 21:01:52888
[email protected]06f92562011-04-29 19:27:31889 const Extension* extension = GetInstalledExtension(extension_id);
890 // |extension| can be NULL if sync disables an extension that is not
891 // installed yet.
[email protected]65187152012-06-02 13:14:14892 if (extension &&
[email protected]505ccdc2013-06-20 20:15:35893 disable_reason != Extension::DISABLE_RELOAD &&
[email protected]65187152012-06-02 13:14:14894 !system_->management_policy()->UserMayModifySettings(extension, NULL)) {
[email protected]95da88c42011-03-31 10:07:33895 return;
[email protected]65187152012-06-02 13:14:14896 }
[email protected]95da88c42011-03-31 10:07:33897
[email protected]b3317ad2011-04-28 23:46:00898 extension_prefs_->SetExtensionState(extension_id, Extension::DISABLED);
[email protected]eb5e4f92012-08-15 23:33:28899 extension_prefs_->AddDisableReason(extension_id, disable_reason);
[email protected]1784e83a2009-09-08 21:01:52900
[email protected]599539802014-01-07 23:06:00901 int include_mask =
902 ExtensionRegistry::EVERYTHING & ~ExtensionRegistry::DISABLED;
903 extension = registry_->GetExtensionById(extension_id, include_mask);
[email protected]06f92562011-04-29 19:27:31904 if (!extension)
905 return;
906
[email protected]45f5b7d2014-01-22 23:47:13907 // The extension is either enabled or terminated.
908 DCHECK(registry_->enabled_extensions().Contains(extension->id()) ||
909 registry_->terminated_extensions().Contains(extension->id()));
[email protected]64742de32013-04-22 08:44:34910
[email protected]5c094792012-09-07 19:44:53911 // Move it over to the disabled list. Don't send a second unload notification
912 // for terminated extensions being disabled.
[email protected]bb1bc9b32013-12-21 03:09:14913 registry_->AddDisabled(make_scoped_refptr(extension));
914 if (registry_->enabled_extensions().Contains(extension->id())) {
915 registry_->RemoveEnabled(extension->id());
[email protected]b0af4792013-10-23 09:12:13916 NotifyExtensionUnloaded(extension, UnloadedExtensionInfo::REASON_DISABLE);
[email protected]5c094792012-09-07 19:44:53917 } else {
[email protected]bb1bc9b32013-12-21 03:09:14918 registry_->RemoveTerminated(extension->id());
[email protected]5c094792012-09-07 19:44:53919 }
[email protected]3bdba0d2011-08-23 07:17:30920
[email protected]f8aefb132013-10-30 09:29:52921 if (extension_sync_service_)
922 extension_sync_service_->SyncDisableExtension(*extension);
[email protected]1784e83a2009-09-08 21:01:52923}
924
[email protected]1abf05e2013-07-09 17:04:36925void ExtensionService::DisableUserExtensions(
926 const std::vector<std::string>& except_ids) {
[email protected]e516e4c2013-06-12 17:41:14927 extensions::ManagementPolicy* management_policy =
928 system_->management_policy();
929 extensions::ExtensionList to_disable;
930
[email protected]75181f62014-03-19 21:41:12931 // TODO(rlp): Clean up this code. crbug.com/353266.
[email protected]bb1bc9b32013-12-21 03:09:14932 const ExtensionSet& enabled_set = registry_->enabled_extensions();
933 for (ExtensionSet::const_iterator extension = enabled_set.begin();
934 extension != enabled_set.end(); ++extension) {
[email protected]75181f62014-03-19 21:41:12935 if (management_policy->UserMayModifySettings(extension->get(), NULL) &&
936 extension->get()->location() != Manifest::EXTERNAL_COMPONENT)
[email protected]e516e4c2013-06-12 17:41:14937 to_disable.push_back(*extension);
938 }
[email protected]bb1bc9b32013-12-21 03:09:14939 const ExtensionSet& terminated_set = registry_->terminated_extensions();
940 for (ExtensionSet::const_iterator extension = terminated_set.begin();
941 extension != terminated_set.end(); ++extension) {
[email protected]75181f62014-03-19 21:41:12942 if (management_policy->UserMayModifySettings(extension->get(), NULL) &&
943 extension->get()->location() != Manifest::EXTERNAL_COMPONENT)
[email protected]e516e4c2013-06-12 17:41:14944 to_disable.push_back(*extension);
945 }
946
947 for (extensions::ExtensionList::const_iterator extension = to_disable.begin();
948 extension != to_disable.end(); ++extension) {
[email protected]3082fe32013-08-06 11:12:38949 if ((*extension)->was_installed_by_default() &&
950 extension_urls::IsWebstoreUpdateUrl(
951 extensions::ManifestURL::GetUpdateURL(*extension)))
952 continue;
[email protected]1abf05e2013-07-09 17:04:36953 const std::string& id = (*extension)->id();
954 if (except_ids.end() == std::find(except_ids.begin(), except_ids.end(), id))
955 DisableExtension(id, extensions::Extension::DISABLE_USER_ACTION);
[email protected]e516e4c2013-06-12 17:41:14956 }
957}
958
[email protected]eaa7dd182010-12-14 11:09:00959void ExtensionService::GrantPermissionsAndEnableExtension(
[email protected]009633c2013-03-07 22:08:28960 const Extension* extension) {
961 GrantPermissions(extension);
[email protected]4c86be582014-06-04 08:39:11962 RecordPermissionMessagesHistogram(extension,
963 "Extensions.Permissions_ReEnable2");
[email protected]8d888c12010-11-30 00:00:25964 extension_prefs_->SetDidExtensionEscalatePermissions(extension, false);
965 EnableExtension(extension->id());
966}
967
[email protected]009633c2013-03-07 22:08:28968void ExtensionService::GrantPermissions(const Extension* extension) {
[email protected]be083862012-09-01 03:53:45969 CHECK(extension);
970 extensions::PermissionsUpdater perms_updater(profile());
[email protected]009633c2013-03-07 22:08:28971 perms_updater.GrantActivePermissions(extension);
[email protected]be083862012-09-01 03:53:45972}
973
[email protected]fe2dd7742011-04-19 22:52:49974// static
975void ExtensionService::RecordPermissionMessagesHistogram(
[email protected]13c68b62013-05-17 11:29:05976 const Extension* extension, const char* histogram) {
[email protected]de415552013-01-23 04:12:17977 // Since this is called from multiple sources, and since the histogram macros
978 // use statics, we need to manually lookup the histogram ourselves.
979 base::HistogramBase* counter = base::LinearHistogram::FactoryGet(
[email protected]fe2dd7742011-04-19 22:52:49980 histogram,
981 1,
[email protected]c2e66e12012-06-27 06:27:06982 PermissionMessage::kEnumBoundary,
983 PermissionMessage::kEnumBoundary + 1,
[email protected]de415552013-01-23 04:12:17984 base::HistogramBase::kUmaTargetedHistogramFlag);
[email protected]fe2dd7742011-04-19 22:52:49985
[email protected]a6910e72014-06-06 05:04:36986 PermissionMessages permissions =
987 extension->permissions_data()->GetPermissionMessages();
[email protected]fe2dd7742011-04-19 22:52:49988 if (permissions.empty()) {
[email protected]c2e66e12012-06-27 06:27:06989 counter->Add(PermissionMessage::kNone);
[email protected]fe2dd7742011-04-19 22:52:49990 } else {
[email protected]c2e66e12012-06-27 06:27:06991 for (PermissionMessages::iterator it = permissions.begin();
[email protected]0d3e4a22011-06-23 19:02:52992 it != permissions.end(); ++it)
993 counter->Add(it->id());
[email protected]fe2dd7742011-04-19 22:52:49994 }
995}
996
[email protected]eaa7dd182010-12-14 11:09:00997void ExtensionService::NotifyExtensionLoaded(const Extension* extension) {
[email protected]57a777f72010-03-31 01:09:42998 // The ChromeURLRequestContexts need to be first to know that the extension
[email protected]62d30f42009-10-01 22:36:06999 // was loaded, otherwise a race can arise where a renderer that is created
1000 // for the extension may try to load an extension URL with an extension id
[email protected]57a777f72010-03-31 01:09:421001 // that the request context doesn't yet know about. The profile is responsible
1002 // for ensuring its URLRequestContexts appropriately discover the loaded
1003 // extension.
[email protected]31d8f5f22012-04-02 15:22:081004 system_->RegisterExtensionWithRequestContexts(extension);
[email protected]62d30f42009-10-01 22:36:061005
[email protected]d5949312012-12-03 22:13:301006 // Tell renderers about the new extension, unless it's a theme (renderers
1007 // don't need to know about themes).
[email protected]a58f599c2012-12-01 03:08:191008 if (!extension->is_theme()) {
[email protected]19647262011-12-16 09:57:491009 for (content::RenderProcessHost::iterator i(
1010 content::RenderProcessHost::AllHostsIterator());
1011 !i.IsAtEnd(); i.Advance()) {
1012 content::RenderProcessHost* host = i.GetCurrentValue();
1013 Profile* host_profile =
1014 Profile::FromBrowserContext(host->GetBrowserContext());
1015 if (host_profile->GetOriginalProfile() ==
1016 profile_->GetOriginalProfile()) {
1017 std::vector<ExtensionMsg_Loaded_Params> loaded_extensions(
1018 1, ExtensionMsg_Loaded_Params(extension));
1019 host->Send(
1020 new ExtensionMsg_Loaded(loaded_extensions));
1021 }
[email protected]c8d407e2011-04-28 21:27:171022 }
[email protected]77a6970c2011-04-23 16:58:561023 }
1024
[email protected]3442a662012-01-12 08:06:171025 // Tell subsystems that use the EXTENSION_LOADED notification about the new
1026 // extension.
1027 //
1028 // NOTE: It is important that this happen after notifying the renderers about
1029 // the new extensions so that if we navigate to an extension URL in
[email protected]fdc76192014-04-20 21:54:411030 // ExtensionRegistryObserver::OnLoaded or
1031 // NOTIFICATION_EXTENSION_LOADED_DEPRECATED, the
[email protected]dcc47642014-03-26 22:03:491032 // renderer is guaranteed to know about it.
1033 registry_->TriggerOnLoaded(extension);
1034
[email protected]3442a662012-01-12 08:06:171035 content::NotificationService::current()->Notify(
[email protected]fdc76192014-04-20 21:54:411036 chrome::NOTIFICATION_EXTENSION_LOADED_DEPRECATED,
[email protected]3442a662012-01-12 08:06:171037 content::Source<Profile>(profile_),
1038 content::Details<const Extension>(extension));
1039
[email protected]dcc47642014-03-26 22:03:491040 // TODO(kalman): Convert ExtensionSpecialStoragePolicy to a
1041 // BrowserContextKeyedService and use ExtensionRegistryObserver.
[email protected]c8d407e2011-04-28 21:27:171042 profile_->GetExtensionSpecialStoragePolicy()->
1043 GrantRightsForExtension(extension);
1044
[email protected]dcc47642014-03-26 22:03:491045 // TODO(kalman): This is broken. The crash reporter is process-wide so doesn't
1046 // work properly multi-profile. Besides which, it should be using
1047 // ExtensionRegistryObserver. See http://crbug.com/355029.
[email protected]c8d407e2011-04-28 21:27:171048 UpdateActiveExtensionsInCrashReporter();
1049
[email protected]d695bb12014-06-05 16:16:301050 const extensions::PermissionsData* permissions_data =
[email protected]a6910e72014-06-06 05:04:361051 extension->permissions_data();
[email protected]d695bb12014-06-05 16:16:301052
[email protected]c8d407e2011-04-28 21:27:171053 // If the extension has permission to load chrome://favicon/ resources we need
1054 // to make sure that the FaviconSource is registered with the
1055 // ChromeURLDataManager.
[email protected]d695bb12014-06-05 16:16:301056 if (permissions_data->HasHostPermission(GURL(chrome::kChromeUIFaviconURL))) {
[email protected]c8d407e2011-04-28 21:27:171057 FaviconSource* favicon_source = new FaviconSource(profile_,
1058 FaviconSource::FAVICON);
[email protected]24ea7a12013-01-27 23:54:531059 content::URLDataSource::Add(profile_, favicon_source);
[email protected]c8d407e2011-04-28 21:27:171060 }
[email protected]b07e606e2012-09-15 20:16:151061
1062#if !defined(OS_ANDROID)
1063 // Same for chrome://theme/ resources.
[email protected]d695bb12014-06-05 16:16:301064 if (permissions_data->HasHostPermission(GURL(chrome::kChromeUIThemeURL))) {
[email protected]b07e606e2012-09-15 20:16:151065 ThemeSource* theme_source = new ThemeSource(profile_);
[email protected]24ea7a12013-01-27 23:54:531066 content::URLDataSource::Add(profile_, theme_source);
[email protected]b07e606e2012-09-15 20:16:151067 }
[email protected]b07e606e2012-09-15 20:16:151068
[email protected]5eddc3e2011-10-26 04:33:311069 // Same for chrome://thumb/ resources.
[email protected]d695bb12014-06-05 16:16:301070 if (permissions_data->HasHostPermission(
1071 GURL(chrome::kChromeUIThumbnailURL))) {
[email protected]420e6d92013-09-17 01:48:511072 ThumbnailSource* thumbnail_source = new ThumbnailSource(profile_, false);
[email protected]24ea7a12013-01-27 23:54:531073 content::URLDataSource::Add(profile_, thumbnail_source);
[email protected]5eddc3e2011-10-26 04:33:311074 }
[email protected]54b25a82014-04-30 21:47:051075#endif
[email protected]62d30f42009-10-01 22:36:061076}
1077
[email protected]a9f39a312010-12-23 22:14:271078void ExtensionService::NotifyExtensionUnloaded(
[email protected]814a7bf0f2011-08-13 05:30:591079 const Extension* extension,
[email protected]b0af4792013-10-23 09:12:131080 UnloadedExtensionInfo::Reason reason) {
[email protected]a9f39a312010-12-23 22:14:271081 UnloadedExtensionInfo details(extension, reason);
[email protected]e51232f32014-04-18 20:05:361082
1083 registry_->TriggerOnUnloaded(extension, reason);
1084
[email protected]ad50def52011-10-19 23:17:071085 content::NotificationService::current()->Notify(
[email protected]ec870532014-03-19 20:24:051086 chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED,
[email protected]6c2381d2011-10-19 02:52:531087 content::Source<Profile>(profile_),
1088 content::Details<UnloadedExtensionInfo>(&details));
[email protected]62d30f42009-10-01 22:36:061089
[email protected]f3b1a082011-11-18 00:34:301090 for (content::RenderProcessHost::iterator i(
1091 content::RenderProcessHost::AllHostsIterator());
[email protected]77a6970c2011-04-23 16:58:561092 !i.IsAtEnd(); i.Advance()) {
[email protected]f3b1a082011-11-18 00:34:301093 content::RenderProcessHost* host = i.GetCurrentValue();
[email protected]9b62ecf2011-07-27 20:23:081094 Profile* host_profile =
[email protected]f3b1a082011-11-18 00:34:301095 Profile::FromBrowserContext(host->GetBrowserContext());
[email protected]9b62ecf2011-07-27 20:23:081096 if (host_profile->GetOriginalProfile() == profile_->GetOriginalProfile())
[email protected]c8d407e2011-04-28 21:27:171097 host->Send(new ExtensionMsg_Unloaded(extension->id()));
[email protected]77a6970c2011-04-23 16:58:561098 }
1099
[email protected]31d8f5f22012-04-02 15:22:081100 system_->UnregisterExtensionWithRequestContexts(extension->id(), reason);
[email protected]dcc47642014-03-26 22:03:491101
1102 // TODO(kalman): Convert ExtensionSpecialStoragePolicy to a
1103 // BrowserContextKeyedService and use ExtensionRegistryObserver.
[email protected]c8d407e2011-04-28 21:27:171104 profile_->GetExtensionSpecialStoragePolicy()->
1105 RevokeRightsForExtension(extension);
1106
[email protected]b777b332011-04-16 04:01:081107#if defined(OS_CHROMEOS)
[email protected]ac66e452013-01-11 09:21:231108 // Revoke external file access for the extension from its file system context.
1109 // It is safe to access the extension's storage partition at this point. The
1110 // storage partition may get destroyed only after the extension gets unloaded.
[email protected]3a746ec2014-03-15 05:30:561111 GURL site =
1112 extensions::util::GetSiteForExtensionId(extension->id(), profile_);
[email protected]10eb28162012-09-18 03:04:091113 fileapi::FileSystemContext* filesystem_context =
[email protected]ac66e452013-01-11 09:21:231114 BrowserContext::GetStoragePartitionForSite(profile_, site)->
[email protected]10eb28162012-09-18 03:04:091115 GetFileSystemContext();
[email protected]f19bbf62013-07-09 01:22:321116 if (filesystem_context && filesystem_context->external_backend()) {
1117 filesystem_context->external_backend()->
[email protected]c8d407e2011-04-28 21:27:171118 RevokeAccessForExtension(extension->id());
[email protected]62d30f42009-10-01 22:36:061119 }
[email protected]c8d407e2011-04-28 21:27:171120#endif
1121
[email protected]dcc47642014-03-26 22:03:491122 // TODO(kalman): This is broken. The crash reporter is process-wide so doesn't
1123 // work properly multi-profile. Besides which, it should be using
1124 // ExtensionRegistryObserver::OnExtensionLoaded. See http://crbug.com/355029.
[email protected]c8d407e2011-04-28 21:27:171125 UpdateActiveExtensionsInCrashReporter();
[email protected]62d30f42009-10-01 22:36:061126}
1127
[email protected]599539802014-01-07 23:06:001128content::BrowserContext* ExtensionService::GetBrowserContext() const {
1129 // Implemented in the .cc file to avoid adding a profile.h dependency to
1130 // extension_service.h.
1131 return profile_;
1132}
1133
[email protected]25ae0152011-11-18 14:40:021134bool ExtensionService::is_ready() {
[email protected]4a10006a2013-05-17 23:18:351135 return ready_->is_signaled();
[email protected]25ae0152011-11-18 14:40:021136}
1137
[email protected]7f8f24f2012-11-15 19:40:141138base::SequencedTaskRunner* ExtensionService::GetFileTaskRunner() {
[email protected]dc24976f2013-06-02 21:15:091139 if (file_task_runner_.get())
1140 return file_task_runner_.get();
[email protected]7f8f24f2012-11-15 19:40:141141
1142 // We should be able to interrupt any part of extension install process during
1143 // shutdown. SKIP_ON_SHUTDOWN ensures that not started extension install tasks
1144 // will be ignored/deleted while we will block on started tasks.
1145 std::string token("ext_install-");
1146 token.append(profile_->GetPath().AsUTF8Unsafe());
1147 file_task_runner_ = BrowserThread::GetBlockingPool()->
1148 GetSequencedTaskRunnerWithShutdownBehavior(
1149 BrowserThread::GetBlockingPool()->GetNamedSequenceToken(token),
1150 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN);
[email protected]dc24976f2013-06-02 21:15:091151 return file_task_runner_.get();
[email protected]7f8f24f2012-11-15 19:40:141152}
1153
[email protected]4ee07c62012-08-21 12:40:421154void ExtensionService::CheckManagementPolicy() {
[email protected]0d54b682013-11-05 14:15:361155 std::vector<std::string> to_unload;
1156 std::map<std::string, Extension::DisableReason> to_disable;
[email protected]695b5712012-12-06 23:55:281157
[email protected]0d54b682013-11-05 14:15:361158 // Loop through the extensions list, finding extensions we need to unload or
1159 // disable.
[email protected]bb1bc9b32013-12-21 03:09:141160 const ExtensionSet& extensions = registry_->enabled_extensions();
1161 for (ExtensionSet::const_iterator iter = extensions.begin();
1162 iter != extensions.end(); ++iter) {
[email protected]cadac622013-06-11 16:46:361163 const Extension* extension = (iter->get());
[email protected]4ee07c62012-08-21 12:40:421164 if (!system_->management_policy()->UserMayLoad(extension, NULL))
[email protected]0d54b682013-11-05 14:15:361165 to_unload.push_back(extension->id());
1166 Extension::DisableReason disable_reason = Extension::DISABLE_NONE;
1167 if (system_->management_policy()->MustRemainDisabled(
1168 extension, &disable_reason, NULL))
1169 to_disable[extension->id()] = disable_reason;
[email protected]aa96d3a2010-08-21 08:45:251170 }
1171
[email protected]0d54b682013-11-05 14:15:361172 for (size_t i = 0; i < to_unload.size(); ++i)
1173 UnloadExtension(to_unload[i], UnloadedExtensionInfo::REASON_DISABLE);
1174
1175 for (std::map<std::string, Extension::DisableReason>::const_iterator i =
1176 to_disable.begin(); i != to_disable.end(); ++i)
1177 DisableExtension(i->first, i->second);
[email protected]aa96d3a2010-08-21 08:45:251178}
1179
[email protected]31206602011-04-13 23:07:321180void ExtensionService::CheckForUpdatesSoon() {
[email protected]90878c52014-04-04 18:21:021181 // This can legitimately happen in unit tests.
1182 if (!updater_.get())
1183 return;
1184
1185 if (AreAllExternalProvidersReady()) {
1186 updater_->CheckSoon();
[email protected]c3cfb012011-04-06 22:07:351187 } else {
[email protected]90878c52014-04-04 18:21:021188 // Sync can start updating before all the external providers are ready
1189 // during startup. Start the update as soon as those providers are ready,
1190 // but not before.
1191 update_once_all_providers_are_ready_ = true;
[email protected]c3cfb012011-04-06 22:07:351192 }
1193}
1194
[email protected]8e4560b62011-01-14 10:09:141195// Some extensions will autoupdate themselves externally from Chrome. These
1196// are typically part of some larger client application package. To support
1197// these, the extension will register its location in the the preferences file
1198// (and also, on Windows, in the registry) and this code will periodically
1199// check that location for a .crx file, which it will then install locally if
1200// a new version is available.
1201// Errors are reported through ExtensionErrorReporter. Succcess is not
1202// reported.
[email protected]eaa7dd182010-12-14 11:09:001203void ExtensionService::CheckForExternalUpdates() {
[email protected]a29a517a2011-01-21 21:11:121204 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]8e4560b62011-01-14 10:09:141205
1206 // Note that this installation is intentionally silent (since it didn't
1207 // go through the front-end). Extensions that are registered in this
1208 // way are effectively considered 'pre-bundled', and so implicitly
1209 // trusted. In general, if something has HKLM or filesystem access,
1210 // they could install an extension manually themselves anyway.
[email protected]a29a517a2011-01-21 21:11:121211
[email protected]8e4560b62011-01-14 10:09:141212 // Ask each external extension provider to give us a call back for each
1213 // extension they know about. See OnExternalExtension(File|UpdateUrl)Found.
[email protected]5df038b2012-07-16 19:03:271214 extensions::ProviderCollection::const_iterator i;
[email protected]8e4560b62011-01-14 10:09:141215 for (i = external_extension_providers_.begin();
1216 i != external_extension_providers_.end(); ++i) {
[email protected]5df038b2012-07-16 19:03:271217 extensions::ExternalProviderInterface* provider = i->get();
[email protected]8e4560b62011-01-14 10:09:141218 provider->VisitRegisteredExtension();
1219 }
1220
[email protected]50067e52011-10-20 23:17:071221 // Do any required work that we would have done after completion of all
1222 // providers.
[email protected]373daf972014-04-10 01:50:441223 if (external_extension_providers_.empty())
[email protected]50067e52011-10-20 23:17:071224 OnAllExternalProvidersReady();
[email protected]9f1087e2009-06-15 17:29:321225}
1226
[email protected]50067e52011-10-20 23:17:071227void ExtensionService::OnExternalProviderReady(
[email protected]5df038b2012-07-16 19:03:271228 const extensions::ExternalProviderInterface* provider) {
[email protected]a29a517a2011-01-21 21:11:121229 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]50067e52011-10-20 23:17:071230 CHECK(provider->IsReady());
[email protected]a29a517a2011-01-21 21:11:121231
1232 // An external provider has finished loading. We only take action
[email protected]8e4560b62011-01-14 10:09:141233 // if all of them are finished. So we check them first.
[email protected]94fde232012-04-27 10:22:301234 if (AreAllExternalProvidersReady())
1235 OnAllExternalProvidersReady();
1236}
1237
1238bool ExtensionService::AreAllExternalProvidersReady() const {
[email protected]5df038b2012-07-16 19:03:271239 extensions::ProviderCollection::const_iterator i;
[email protected]8e4560b62011-01-14 10:09:141240 for (i = external_extension_providers_.begin();
1241 i != external_extension_providers_.end(); ++i) {
[email protected]94fde232012-04-27 10:22:301242 if (!i->get()->IsReady())
1243 return false;
[email protected]8e4560b62011-01-14 10:09:141244 }
[email protected]94fde232012-04-27 10:22:301245 return true;
[email protected]50067e52011-10-20 23:17:071246}
1247
1248void ExtensionService::OnAllExternalProvidersReady() {
1249 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]94fde232012-04-27 10:22:301250 base::TimeDelta elapsed = base::Time::Now() - profile_->GetStartTime();
1251 UMA_HISTOGRAM_TIMES("Extension.ExternalProvidersReadyAfter", elapsed);
[email protected]50067e52011-10-20 23:17:071252
1253 // Install any pending extensions.
[email protected]94fde232012-04-27 10:22:301254 if (update_once_all_providers_are_ready_ && updater()) {
1255 update_once_all_providers_are_ready_ = false;
[email protected]4e9b59d2013-12-18 06:47:141256 extensions::ExtensionUpdater::CheckParams params;
1257 params.callback = external_updates_finished_callback_;
1258 updater()->CheckNow(params);
[email protected]8e4560b62011-01-14 10:09:141259 }
1260
1261 // Uninstall all the unclaimed extensions.
[email protected]45759612012-07-10 17:21:231262 scoped_ptr<extensions::ExtensionPrefs::ExtensionsInfo> extensions_info(
[email protected]8e4560b62011-01-14 10:09:141263 extension_prefs_->GetInstalledExtensionsInfo());
1264 for (size_t i = 0; i < extensions_info->size(); ++i) {
1265 ExtensionInfo* info = extensions_info->at(i).get();
[email protected]1d5e58b2013-01-31 08:41:401266 if (Manifest::IsExternalLocation(info->extension_location))
[email protected]8e4560b62011-01-14 10:09:141267 CheckExternalUninstall(info->extension_id);
1268 }
[email protected]e5af875f2011-10-10 21:09:141269
[email protected]373daf972014-04-10 01:50:441270 error_controller_->ShowErrorIfNeeded();
[email protected]a9aa5932012-01-25 08:27:401271
[email protected]612a1cb12012-10-17 13:18:031272 UpdateExternalExtensionAlert();
[email protected]e5af875f2011-10-10 21:09:141273}
1274
[email protected]47fc70c2011-12-06 07:29:511275void ExtensionService::AcknowledgeExternalExtension(const std::string& id) {
1276 extension_prefs_->AcknowledgeExternalExtension(id);
[email protected]612a1cb12012-10-17 13:18:031277 UpdateExternalExtensionAlert();
[email protected]47fc70c2011-12-06 07:29:511278}
1279
[email protected]d96eb512012-11-01 23:44:081280bool ExtensionService::IsUnacknowledgedExternalExtension(
1281 const Extension* extension) {
[email protected]b82d18da2012-11-09 00:11:321282 if (!FeatureSwitch::prompt_for_external_extensions()->IsEnabled())
1283 return false;
1284
[email protected]1d5e58b2013-01-31 08:41:401285 return (Manifest::IsExternalLocation(extension->location()) &&
[email protected]d96eb512012-11-01 23:44:081286 !extension_prefs_->IsExternalExtensionAcknowledged(extension->id()) &&
1287 !(extension_prefs_->GetDisableReasons(extension->id()) &
1288 Extension::DISABLE_SIDELOAD_WIPEOUT));
1289}
1290
[email protected]59ee99d2013-10-11 15:46:161291void ExtensionService::ReconcileKnownDisabled() {
[email protected]60a8bc962013-12-03 03:17:271292 ExtensionIdSet known_disabled_ids;
1293 if (!extension_prefs_->GetKnownDisabled(&known_disabled_ids)) {
[email protected]bb1bc9b32013-12-21 03:09:141294 extension_prefs_->SetKnownDisabled(
1295 registry_->disabled_extensions().GetIDs());
[email protected]018a5682013-11-20 02:41:211296 UMA_HISTOGRAM_BOOLEAN("Extensions.KnownDisabledInitialized", true);
1297 return;
[email protected]59ee99d2013-10-11 15:46:161298 }
[email protected]195c1582013-10-29 18:42:231299
[email protected]bb1bc9b32013-12-21 03:09:141300 // Both |known_disabled_ids| and |extensions| are ordered (by definition
[email protected]018a5682013-11-20 02:41:211301 // of std::map and std::set). Iterate forward over both sets in parallel
1302 // to find matching IDs and disable the corresponding extensions.
[email protected]bb1bc9b32013-12-21 03:09:141303 const ExtensionSet& enabled_set = registry_->enabled_extensions();
1304 ExtensionSet::const_iterator extensions_it = enabled_set.begin();
[email protected]018a5682013-11-20 02:41:211305 ExtensionIdSet::const_iterator known_disabled_ids_it =
1306 known_disabled_ids.begin();
1307 int known_disabled_count = 0;
[email protected]bb1bc9b32013-12-21 03:09:141308 while (extensions_it != enabled_set.end() &&
[email protected]018a5682013-11-20 02:41:211309 known_disabled_ids_it != known_disabled_ids.end()) {
1310 const std::string& extension_id = extensions_it->get()->id();
1311 const int comparison = extension_id.compare(*known_disabled_ids_it);
1312 if (comparison < 0) {
1313 ++extensions_it;
1314 } else if (comparison > 0) {
1315 ++known_disabled_ids_it;
1316 } else {
1317 ++known_disabled_count;
1318 // Advance |extensions_it| immediately as it will be invalidated upon
1319 // disabling the extension it points to.
1320 ++extensions_it;
1321 ++known_disabled_ids_it;
1322 DisableExtension(extension_id, Extension::DISABLE_KNOWN_DISABLED);
1323 }
1324 }
1325 UMA_HISTOGRAM_COUNTS_100("Extensions.KnownDisabledReDisabled",
1326 known_disabled_count);
1327
[email protected]195c1582013-10-29 18:42:231328 // Update the list of known disabled to reflect every change to
1329 // |disabled_extensions_| from this point forward.
[email protected]bb1bc9b32013-12-21 03:09:141330 registry_->SetDisabledModificationCallback(
[email protected]195c1582013-10-29 18:42:231331 base::Bind(&extensions::ExtensionPrefs::SetKnownDisabled,
1332 base::Unretained(extension_prefs_)));
[email protected]59ee99d2013-10-11 15:46:161333}
1334
[email protected]612a1cb12012-10-17 13:18:031335void ExtensionService::UpdateExternalExtensionAlert() {
[email protected]41070e8d2012-10-24 01:34:361336 if (!FeatureSwitch::prompt_for_external_extensions()->IsEnabled())
[email protected]612a1cb12012-10-17 13:18:031337 return;
1338
1339 const Extension* extension = NULL;
[email protected]bb1bc9b32013-12-21 03:09:141340 const ExtensionSet& disabled_extensions = registry_->disabled_extensions();
1341 for (ExtensionSet::const_iterator iter = disabled_extensions.begin();
1342 iter != disabled_extensions.end(); ++iter) {
[email protected]cadac622013-06-11 16:46:361343 const Extension* e = iter->get();
[email protected]d96eb512012-11-01 23:44:081344 if (IsUnacknowledgedExternalExtension(e)) {
1345 extension = e;
1346 break;
[email protected]612a1cb12012-10-17 13:18:031347 }
1348 }
1349
1350 if (extension) {
[email protected]e5d6b4712014-06-04 20:07:231351 if (!extensions::HasExternalInstallError(this)) {
[email protected]d96eb512012-11-01 23:44:081352 if (extension_prefs_->IncrementAcknowledgePromptCount(extension->id()) >
[email protected]612a1cb12012-10-17 13:18:031353 kMaxExtensionAcknowledgePromptCount) {
[email protected]d96eb512012-11-01 23:44:081354 // Stop prompting for this extension, and check if there's another
1355 // one that needs prompting.
[email protected]612a1cb12012-10-17 13:18:031356 extension_prefs_->AcknowledgeExternalExtension(extension->id());
[email protected]d96eb512012-11-01 23:44:081357 UpdateExternalExtensionAlert();
1358 UMA_HISTOGRAM_ENUMERATION("Extensions.ExternalExtensionEvent",
1359 EXTERNAL_EXTENSION_IGNORED,
1360 EXTERNAL_EXTENSION_BUCKET_BOUNDARY);
[email protected]446e37e2013-08-07 00:30:021361 if (extensions::ManifestURL::UpdatesFromGallery(extension)) {
1362 UMA_HISTOGRAM_ENUMERATION(
1363 "Extensions.ExternalExtensionEventWebstore",
1364 EXTERNAL_EXTENSION_IGNORED,
1365 EXTERNAL_EXTENSION_BUCKET_BOUNDARY);
1366 } else {
1367 UMA_HISTOGRAM_ENUMERATION(
1368 "Extensions.ExternalExtensionEventNonWebstore",
1369 EXTERNAL_EXTENSION_IGNORED,
1370 EXTERNAL_EXTENSION_BUCKET_BOUNDARY);
1371 }
[email protected]d96eb512012-11-01 23:44:081372 return;
[email protected]612a1cb12012-10-17 13:18:031373 }
[email protected]b3aa7182013-04-25 04:45:231374 if (is_first_run_)
1375 extension_prefs_->SetExternalInstallFirstRun(extension->id());
1376 // first_run is true if the extension was installed during a first run
1377 // (even if it's post-first run now).
1378 bool first_run = extension_prefs_->IsExternalInstallFirstRun(
1379 extension->id());
[email protected]e5d6b4712014-06-04 20:07:231380 extensions::AddExternalInstallError(this, extension, first_run);
[email protected]612a1cb12012-10-17 13:18:031381 }
[email protected]e5d6b4712014-06-04 20:07:231382 } else {
1383 extensions::RemoveExternalInstallError(this);
[email protected]612a1cb12012-10-17 13:18:031384 }
[email protected]612a1cb12012-10-17 13:18:031385}
1386
[email protected]a9f39a312010-12-23 22:14:271387void ExtensionService::UnloadExtension(
1388 const std::string& extension_id,
[email protected]b0af4792013-10-23 09:12:131389 UnloadedExtensionInfo::Reason reason) {
[email protected]27e469a2010-01-11 20:35:091390 // Make sure the extension gets deleted after we return from this function.
[email protected]599539802014-01-07 23:06:001391 int include_mask =
1392 ExtensionRegistry::EVERYTHING & ~ExtensionRegistry::TERMINATED;
[email protected]9adb9692010-10-29 23:14:021393 scoped_refptr<const Extension> extension(
[email protected]599539802014-01-07 23:06:001394 registry_->GetExtensionById(extension_id, include_mask));
[email protected]631cf822009-05-15 07:01:251395
[email protected]fa0c96732010-11-17 00:14:231396 // This method can be called via PostTask, so the extension may have been
1397 // unloaded by the time this runs.
[email protected]dc24976f2013-06-02 21:15:091398 if (!extension.get()) {
[email protected]dd163fb02011-05-04 22:22:171399 // In case the extension may have crashed/uninstalled. Allow the profile to
1400 // clean up its RequestContexts.
[email protected]31d8f5f22012-04-02 15:22:081401 system_->UnregisterExtensionWithRequestContexts(extension_id, reason);
[email protected]fa0c96732010-11-17 00:14:231402 return;
[email protected]dd163fb02011-05-04 22:22:171403 }
[email protected]0c6da502009-08-14 22:32:391404
[email protected]1eb175082010-02-10 09:26:161405 // Keep information about the extension so that we can reload it later
1406 // even if it's not permanently installed.
1407 unloaded_extension_paths_[extension->id()] = extension->path();
1408
[email protected]f17dbd42010-08-16 23:21:101409 // Clean up if the extension is meant to be enabled after a reload.
[email protected]b914e2952013-04-26 07:10:031410 reloading_extensions_.erase(extension->id());
[email protected]f17dbd42010-08-16 23:21:101411
[email protected]bb1bc9b32013-12-21 03:09:141412 if (registry_->disabled_extensions().Contains(extension->id())) {
1413 registry_->RemoveDisabled(extension->id());
[email protected]dd163fb02011-05-04 22:22:171414 // Make sure the profile cleans up its RequestContexts when an already
1415 // disabled extension is unloaded (since they are also tracking the disabled
1416 // extensions).
[email protected]31d8f5f22012-04-02 15:22:081417 system_->UnregisterExtensionWithRequestContexts(extension_id, reason);
[email protected]45f5b7d2014-01-22 23:47:131418 // Don't send the unloaded notification. It was sent when the extension
1419 // was disabled.
[email protected]60a174a2013-08-02 20:29:281420 } else {
[email protected]bb1bc9b32013-12-21 03:09:141421 // Remove the extension from the enabled list.
1422 registry_->RemoveEnabled(extension->id());
[email protected]60a174a2013-08-02 20:29:281423 NotifyExtensionUnloaded(extension.get(), reason);
[email protected]0c6da502009-08-14 22:32:391424 }
1425
[email protected]fb789532013-08-27 02:40:211426 content::NotificationService::current()->Notify(
1427 chrome::NOTIFICATION_EXTENSION_REMOVED,
1428 content::Source<Profile>(profile_),
1429 content::Details<const Extension>(extension.get()));
[email protected]631cf822009-05-15 07:01:251430}
1431
[email protected]8b1ec202013-09-05 02:09:501432void ExtensionService::RemoveComponentExtension(
1433 const std::string& extension_id) {
1434 scoped_refptr<const Extension> extension(
1435 GetExtensionById(extension_id, false));
[email protected]b0af4792013-10-23 09:12:131436 UnloadExtension(extension_id, UnloadedExtensionInfo::REASON_UNINSTALL);
[email protected]ebe07772014-05-22 04:16:061437 if (extension.get()) {
1438 content::NotificationService::current()->Notify(
[email protected]bbf8d30b2014-05-29 16:45:071439 chrome::NOTIFICATION_EXTENSION_UNINSTALLED_DEPRECATED,
[email protected]ebe07772014-05-22 04:16:061440 content::Source<Profile>(profile_),
1441 content::Details<const Extension>(extension.get()));
[email protected]1d7f2482014-05-24 00:11:511442 ExtensionRegistry::Get(profile_)->TriggerOnUninstalled(extension.get());
[email protected]ebe07772014-05-22 04:16:061443 }
[email protected]8b1ec202013-09-05 02:09:501444}
1445
[email protected]bb1bc9b32013-12-21 03:09:141446void ExtensionService::UnloadAllExtensionsForTest() {
1447 UnloadAllExtensionsInternal();
[email protected]9f1087e2009-06-15 17:29:321448}
1449
[email protected]bb1bc9b32013-12-21 03:09:141450void ExtensionService::ReloadExtensionsForTest() {
1451 // Calling UnloadAllExtensionsForTest here triggers a false-positive presubmit
1452 // warning about calling test code in production.
1453 UnloadAllExtensionsInternal();
[email protected]eac88332012-12-26 17:57:451454 component_loader_->LoadAll();
[email protected]d8c8f25f2011-11-02 18:18:011455 extensions::InstalledLoader(this).LoadAllExtensions();
[email protected]4a10006a2013-05-17 23:18:351456 // Don't call SetReadyAndNotifyListeners() since tests call this multiple
1457 // times.
[email protected]9f1087e2009-06-15 17:29:321458}
1459
[email protected]820d9bd2013-04-03 03:46:031460void ExtensionService::SetReadyAndNotifyListeners() {
[email protected]4a10006a2013-05-17 23:18:351461 ready_->Signal();
[email protected]820d9bd2013-04-03 03:46:031462 content::NotificationService::current()->Notify(
1463 chrome::NOTIFICATION_EXTENSIONS_READY,
1464 content::Source<Profile>(profile_),
1465 content::NotificationService::NoDetails());
1466}
1467
[email protected]eaa7dd182010-12-14 11:09:001468void ExtensionService::OnLoadedInstalledExtensions() {
[email protected]3eeddd892013-04-17 17:00:111469 if (updater_)
[email protected]93fd78f42009-07-10 16:43:171470 updater_->Start();
[email protected]fa6a9102010-11-22 15:38:501471
[email protected]bc151cf92013-02-12 04:57:261472 OnBlacklistUpdated();
[email protected]e72e8eb82009-06-18 17:21:511473}
1474
[email protected]fcb58a862012-05-01 01:03:151475void ExtensionService::AddExtension(const Extension* extension) {
[email protected]c8d407e2011-04-28 21:27:171476 // TODO(jstritar): We may be able to get rid of this branch by overriding the
1477 // default extension state to DISABLED when the --disable-extensions flag
1478 // is set (http://crbug.com/29067).
1479 if (!extensions_enabled() &&
1480 !extension->is_theme() &&
[email protected]1d5e58b2013-01-31 08:41:401481 extension->location() != Manifest::COMPONENT &&
1482 !Manifest::IsExternalLocation(extension->location())) {
[email protected]fcb58a862012-05-01 01:03:151483 return;
[email protected]330840c2012-08-29 22:21:011484 }
[email protected]c8d407e2011-04-28 21:27:171485
[email protected]b914e2952013-04-26 07:10:031486 bool is_extension_upgrade = false;
[email protected]116d40e2013-08-08 17:23:171487 bool is_extension_installed = false;
1488 const Extension* old = GetInstalledExtension(extension->id());
1489 if (old) {
1490 is_extension_installed = true;
1491 int version_compare_result =
1492 extension->version()->CompareTo(*(old->version()));
1493 is_extension_upgrade = version_compare_result > 0;
[email protected]b914e2952013-04-26 07:10:031494 // Other than for unpacked extensions, CrxInstaller should have guaranteed
1495 // that we aren't downgrading.
1496 if (!Manifest::IsUnpackedLocation(extension->location()))
[email protected]116d40e2013-08-08 17:23:171497 CHECK_GE(version_compare_result, 0);
[email protected]b914e2952013-04-26 07:10:031498 }
[email protected]45f5b7d2014-01-22 23:47:131499 system_->runtime_data()->SetBeingUpgraded(extension, is_extension_upgrade);
[email protected]c8d407e2011-04-28 21:27:171500
[email protected]1eb175082010-02-10 09:26:161501 // The extension is now loaded, remove its data from unloaded extension map.
1502 unloaded_extension_paths_.erase(extension->id());
1503
[email protected]bb7f40952011-01-13 00:21:201504 // If a terminated extension is loaded, remove it from the terminated list.
1505 UntrackTerminatedExtension(extension->id());
1506
[email protected]f17dbd42010-08-16 23:21:101507 // If the extension was disabled for a reload, then enable it.
[email protected]ca2e82022013-04-29 16:48:411508 bool reloading = reloading_extensions_.erase(extension->id()) > 0;
[email protected]f17dbd42010-08-16 23:21:101509
[email protected]b914e2952013-04-26 07:10:031510 // Check if the extension's privileges have changed and mark the
1511 // extension disabled if necessary.
[email protected]116d40e2013-08-08 17:23:171512 CheckPermissionsIncrease(extension, is_extension_installed);
[email protected]b914e2952013-04-26 07:10:031513
[email protected]116d40e2013-08-08 17:23:171514 if (is_extension_installed && !reloading) {
[email protected]ca2e82022013-04-29 16:48:411515 // To upgrade an extension in place, unload the old one and then load the
1516 // new one. ReloadExtension disables the extension, which is sufficient.
[email protected]b0af4792013-10-23 09:12:131517 UnloadExtension(extension->id(), UnloadedExtensionInfo::REASON_UPDATE);
[email protected]b914e2952013-04-26 07:10:031518 }
[email protected]0c6da502009-08-14 22:32:391519
[email protected]695b5712012-12-06 23:55:281520 if (extension_prefs_->IsExtensionBlacklisted(extension->id())) {
[email protected]ac875372013-02-28 04:36:091521 // Only prefs is checked for the blacklist. We rely on callers to check the
1522 // blacklist before calling into here, e.g. CrxInstaller checks before
[email protected]9f3c8532013-07-31 19:52:071523 // installation then threads through the install and pending install flow
1524 // of this class, and we check when loading installed extensions.
[email protected]bb1bc9b32013-12-21 03:09:141525 registry_->AddBlacklisted(extension);
[email protected]ca2e82022013-04-29 16:48:411526 } else if (!reloading &&
1527 extension_prefs_->IsExtensionDisabled(extension->id())) {
[email protected]bb1bc9b32013-12-21 03:09:141528 registry_->AddDisabled(extension);
[email protected]f8aefb132013-10-30 09:29:521529 if (extension_sync_service_)
1530 extension_sync_service_->SyncExtensionChangeIfNeeded(*extension);
[email protected]44d62b62012-04-11 00:06:031531 content::NotificationService::current()->Notify(
1532 chrome::NOTIFICATION_EXTENSION_UPDATE_DISABLED,
1533 content::Source<Profile>(profile_),
1534 content::Details<const Extension>(extension));
[email protected]62f051c2012-03-29 17:04:441535
[email protected]21db9ef2014-05-16 02:06:271536 // Show the extension disabled error if a permissions increase or a remote
1537 // installation is the reason it was disabled, and no other reasons exist.
1538 int reasons = extension_prefs_->GetDisableReasons(extension->id());
1539 const int kReasonMask = Extension::DISABLE_PERMISSIONS_INCREASE |
1540 Extension::DISABLE_REMOTE_INSTALL;
1541 if (reasons & kReasonMask && !(reasons & ~kReasonMask)) {
1542 extensions::AddExtensionDisabledError(
1543 this,
1544 extension,
1545 extension_prefs_->HasDisableReason(
1546 extension->id(), Extension::DISABLE_REMOTE_INSTALL));
[email protected]62f051c2012-03-29 17:04:441547 }
[email protected]ca2e82022013-04-29 16:48:411548 } else if (reloading) {
1549 // Replace the old extension with the new version.
[email protected]bb1bc9b32013-12-21 03:09:141550 CHECK(!registry_->AddDisabled(extension));
[email protected]ca2e82022013-04-29 16:48:411551 EnableExtension(extension->id());
[email protected]695b5712012-12-06 23:55:281552 } else {
1553 // All apps that are displayed in the launcher are ordered by their ordinals
1554 // so we must ensure they have valid ordinals.
1555 if (extension->RequiresSortOrdinal()) {
[email protected]bd36b652013-02-27 02:13:251556 if (!extension->ShouldDisplayInNewTabPage()) {
[email protected]74474042013-11-21 12:03:541557 extension_prefs_->app_sorting()->MarkExtensionAsHidden(extension->id());
[email protected]bd36b652013-02-27 02:13:251558 }
[email protected]74474042013-11-21 12:03:541559 extension_prefs_->app_sorting()->EnsureValidOrdinals(
[email protected]695b5712012-12-06 23:55:281560 extension->id(), syncer::StringOrdinal());
1561 }
1562
[email protected]bb1bc9b32013-12-21 03:09:141563 registry_->AddEnabled(extension);
[email protected]f8aefb132013-10-30 09:29:521564 if (extension_sync_service_)
1565 extension_sync_service_->SyncExtensionChangeIfNeeded(*extension);
[email protected]695b5712012-12-06 23:55:281566 NotifyExtensionLoaded(extension);
[email protected]f574c402012-12-04 23:20:311567 }
[email protected]45f5b7d2014-01-22 23:47:131568 system_->runtime_data()->SetBeingUpgraded(extension, false);
[email protected]aab98a52009-12-02 03:22:351569}
1570
[email protected]8c484b742012-11-29 06:05:361571void ExtensionService::AddComponentExtension(const Extension* extension) {
1572 const std::string old_version_string(
1573 extension_prefs_->GetVersionString(extension->id()));
[email protected]c5e4a2222014-01-03 16:06:131574 const Version old_version(old_version_string);
[email protected]8c484b742012-11-29 06:05:361575
[email protected]0181a7d2013-11-12 01:08:421576 VLOG(1) << "AddComponentExtension " << extension->name();
[email protected]8c484b742012-11-29 06:05:361577 if (!old_version.IsValid() || !old_version.Equals(*extension->version())) {
1578 VLOG(1) << "Component extension " << extension->name() << " ("
1579 << extension->id() << ") installing/upgrading from '"
1580 << old_version_string << "' to " << extension->version()->GetString();
1581
1582 AddNewOrUpdatedExtension(extension,
[email protected]399583b2012-12-11 09:33:421583 Extension::ENABLED_COMPONENT,
[email protected]4a1d9c0d2014-06-13 12:50:111584 extensions::kInstallFlagNone,
[email protected]d8fd0fd2014-03-24 13:16:061585 syncer::StringOrdinal(),
1586 std::string());
[email protected]8c484b742012-11-29 06:05:361587 return;
1588 }
1589
1590 AddExtension(extension);
1591}
1592
[email protected]b914e2952013-04-26 07:10:031593void ExtensionService::UpdateActivePermissions(const Extension* extension) {
[email protected]902fd7b2011-07-27 18:42:311594 // If the extension has used the optional permissions API, it will have a
1595 // custom set of active permissions defined in the extension prefs. Here,
1596 // we update the extension's active permissions based on the prefs.
[email protected]c2e66e12012-06-27 06:27:061597 scoped_refptr<PermissionSet> active_permissions =
[email protected]7c82539c2014-02-19 06:09:171598 extension_prefs_->GetActivePermissions(extension->id());
[email protected]902fd7b2011-07-27 18:42:311599
[email protected]dc24976f2013-06-02 21:15:091600 if (active_permissions.get()) {
[email protected]902fd7b2011-07-27 18:42:311601 // We restrict the active permissions to be within the bounds defined in the
1602 // extension's manifest.
1603 // a) active permissions must be a subset of optional + default permissions
1604 // b) active permissions must contains all default permissions
[email protected]d695bb12014-06-05 16:16:301605 scoped_refptr<PermissionSet> total_permissions = PermissionSet::CreateUnion(
1606 extensions::PermissionsParser::GetRequiredPermissions(extension),
1607 extensions::PermissionsParser::GetOptionalPermissions(extension));
[email protected]902fd7b2011-07-27 18:42:311608
1609 // Make sure the active permissions contain no more than optional + default.
[email protected]c2e66e12012-06-27 06:27:061610 scoped_refptr<PermissionSet> adjusted_active =
1611 PermissionSet::CreateIntersection(
[email protected]902fd7b2011-07-27 18:42:311612 total_permissions.get(), active_permissions.get());
1613
1614 // Make sure the active permissions contain the default permissions.
[email protected]c2e66e12012-06-27 06:27:061615 adjusted_active = PermissionSet::CreateUnion(
[email protected]d695bb12014-06-05 16:16:301616 extensions::PermissionsParser::GetRequiredPermissions(extension),
[email protected]2cb5e302013-05-09 05:00:061617 adjusted_active.get());
[email protected]902fd7b2011-07-27 18:42:311618
[email protected]c333e792012-01-06 16:57:391619 extensions::PermissionsUpdater perms_updater(profile());
[email protected]dc24976f2013-06-02 21:15:091620 perms_updater.UpdateActivePermissions(extension, adjusted_active.get());
[email protected]902fd7b2011-07-27 18:42:311621 }
[email protected]b914e2952013-04-26 07:10:031622}
1623
1624void ExtensionService::CheckPermissionsIncrease(const Extension* extension,
[email protected]116d40e2013-08-08 17:23:171625 bool is_extension_installed) {
[email protected]b914e2952013-04-26 07:10:031626 UpdateActivePermissions(extension);
[email protected]902fd7b2011-07-27 18:42:311627
[email protected]8d888c12010-11-30 00:00:251628 // We keep track of all permissions the user has granted each extension.
1629 // This allows extensions to gracefully support backwards compatibility
1630 // by including unknown permissions in their manifests. When the user
1631 // installs the extension, only the recognized permissions are recorded.
1632 // When the unknown permissions become recognized (e.g., through browser
1633 // upgrade), we can prompt the user to accept these new permissions.
1634 // Extensions can also silently upgrade to less permissions, and then
1635 // silently upgrade to a version that adds these permissions back.
1636 //
1637 // For example, pretend that Chrome 10 includes a permission "omnibox"
1638 // for an API that adds suggestions to the omnibox. An extension can
1639 // maintain backwards compatibility while still having "omnibox" in the
1640 // manifest. If a user installs the extension on Chrome 9, the browser
1641 // will record the permissions it recognized, not including "omnibox."
1642 // When upgrading to Chrome 10, "omnibox" will be recognized and Chrome
1643 // will disable the extension and prompt the user to approve the increase
1644 // in privileges. The extension could then release a new version that
1645 // removes the "omnibox" permission. When the user upgrades, Chrome will
1646 // still remember that "omnibox" had been granted, so that if the
1647 // extension once again includes "omnibox" in an upgrade, the extension
1648 // can upgrade without requiring this user's approval.
[email protected]eb5e4f92012-08-15 23:33:281649 int disable_reasons = extension_prefs_->GetDisableReasons(extension->id());
[email protected]8d888c12010-11-30 00:00:251650
[email protected]211a3f32013-05-28 21:48:181651 bool auto_grant_permission =
[email protected]1b563df2013-10-30 16:49:361652 (!is_extension_installed && extension->was_installed_by_default()) ||
[email protected]45928b682013-11-28 08:20:271653 extensions::ExtensionsBrowserClient::Get()->IsRunningInForcedAppMode();
[email protected]b914e2952013-04-26 07:10:031654 // Silently grant all active permissions to default apps only on install.
1655 // After install they should behave like other apps.
[email protected]211a3f32013-05-28 21:48:181656 // Silently grant all active permissions to apps install in kiosk mode on both
1657 // install and update.
1658 if (auto_grant_permission)
[email protected]b914e2952013-04-26 07:10:031659 GrantPermissions(extension);
1660
1661 bool is_privilege_increase = false;
1662 // We only need to compare the granted permissions to the current permissions
1663 // if the extension is not allowed to silently increase its permissions.
[email protected]13c68b62013-05-17 11:29:051664 if (!extensions::PermissionsData::CanSilentlyIncreasePermissions(extension) &&
[email protected]211a3f32013-05-28 21:48:181665 !auto_grant_permission) {
[email protected]8d888c12010-11-30 00:00:251666 // Add all the recognized permissions if the granted permissions list
1667 // hasn't been initialized yet.
[email protected]c2e66e12012-06-27 06:27:061668 scoped_refptr<PermissionSet> granted_permissions =
[email protected]902fd7b2011-07-27 18:42:311669 extension_prefs_->GetGrantedPermissions(extension->id());
[email protected]0d3e4a22011-06-23 19:02:521670 CHECK(granted_permissions.get());
[email protected]8d888c12010-11-30 00:00:251671
1672 // Here, we check if an extension's privileges have increased in a manner
1673 // that requires the user's approval. This could occur because the browser
1674 // upgraded and recognized additional privileges, or an extension upgrades
1675 // to a version that requires additional privileges.
[email protected]c41003472013-10-19 15:37:251676 is_privilege_increase =
1677 extensions::PermissionMessageProvider::Get()->IsPrivilegeIncrease(
[email protected]076ebeda2014-06-06 21:47:261678 granted_permissions,
1679 extension->permissions_data()->active_permissions().get(),
1680 extension->GetType());
[email protected]8d888c12010-11-30 00:00:251681 }
1682
[email protected]116d40e2013-08-08 17:23:171683 if (is_extension_installed) {
[email protected]44d62b62012-04-11 00:06:031684 // If the extension was already disabled, suppress any alerts for becoming
1685 // disabled on permissions increase.
[email protected]b914e2952013-04-26 07:10:031686 bool previously_disabled =
1687 extension_prefs_->IsExtensionDisabled(extension->id());
[email protected]7e9e2422012-12-13 19:54:191688 // Legacy disabled extensions do not have a disable reason. Infer that if
1689 // there was no permission increase, it was likely disabled by the user.
1690 if (previously_disabled && disable_reasons == Extension::DISABLE_NONE &&
[email protected]b914e2952013-04-26 07:10:031691 !extension_prefs_->DidExtensionEscalatePermissions(extension->id())) {
[email protected]7e9e2422012-12-13 19:54:191692 disable_reasons |= Extension::DISABLE_USER_ACTION;
[email protected]44d62b62012-04-11 00:06:031693 }
[email protected]7e9e2422012-12-13 19:54:191694 // Extensions that came to us disabled from sync need a similar inference,
1695 // except based on the new version's permissions.
1696 if (previously_disabled &&
1697 disable_reasons == Extension::DISABLE_UNKNOWN_FROM_SYNC) {
1698 // Remove the DISABLE_UNKNOWN_FROM_SYNC reason.
1699 extension_prefs_->ClearDisableReasons(extension->id());
1700 if (!is_privilege_increase)
1701 disable_reasons |= Extension::DISABLE_USER_ACTION;
1702 }
[email protected]b914e2952013-04-26 07:10:031703 disable_reasons &= ~Extension::DISABLE_UNKNOWN_FROM_SYNC;
[email protected]8d888c12010-11-30 00:00:251704 }
1705
1706 // Extension has changed permissions significantly. Disable it. A
[email protected]21db9ef2014-05-16 02:06:271707 // notification should be sent by the caller. If the extension is already
1708 // disabled because it was installed remotely, don't add another disable
1709 // reason, but instead always set the "did escalate permissions" flag, to
1710 // ensure enabling it will always show a warning.
1711 if (disable_reasons == Extension::DISABLE_REMOTE_INSTALL) {
1712 extension_prefs_->SetDidExtensionEscalatePermissions(extension, true);
1713 } else if (is_privilege_increase) {
[email protected]7e9e2422012-12-13 19:54:191714 disable_reasons |= Extension::DISABLE_PERMISSIONS_INCREASE;
[email protected]fe2dd7742011-04-19 22:52:491715 if (!extension_prefs_->DidExtensionEscalatePermissions(extension->id())) {
[email protected]4c86be582014-06-04 08:39:111716 RecordPermissionMessagesHistogram(extension,
1717 "Extensions.Permissions_AutoDisable2");
[email protected]fe2dd7742011-04-19 22:52:491718 }
[email protected]195c1582013-10-29 18:42:231719 extension_prefs_->SetExtensionState(extension->id(), Extension::DISABLED);
[email protected]8d888c12010-11-30 00:00:251720 extension_prefs_->SetDidExtensionEscalatePermissions(extension, true);
[email protected]b914e2952013-04-26 07:10:031721 }
1722 if (disable_reasons != Extension::DISABLE_NONE) {
[email protected]eb5e4f92012-08-15 23:33:281723 extension_prefs_->AddDisableReason(
1724 extension->id(),
1725 static_cast<Extension::DisableReason>(disable_reasons));
[email protected]8d888c12010-11-30 00:00:251726 }
1727}
1728
[email protected]eaa7dd182010-12-14 11:09:001729void ExtensionService::UpdateActiveExtensionsInCrashReporter() {
[email protected]c8865962009-12-16 07:47:391730 std::set<std::string> extension_ids;
[email protected]bb1bc9b32013-12-21 03:09:141731 const ExtensionSet& extensions = registry_->enabled_extensions();
1732 for (ExtensionSet::const_iterator iter = extensions.begin();
1733 iter != extensions.end(); ++iter) {
[email protected]cadac622013-06-11 16:46:361734 const Extension* extension = iter->get();
[email protected]1d5e58b2013-01-31 08:41:401735 if (!extension->is_theme() && extension->location() != Manifest::COMPONENT)
[email protected]84df8332011-12-06 18:22:461736 extension_ids.insert(extension->id());
[email protected]aab98a52009-12-02 03:22:351737 }
1738
[email protected]dcc47642014-03-26 22:03:491739 // TODO(kalman): This is broken. ExtensionService is per-profile.
1740 // crash_keys::SetActiveExtensions is per-process. See
1741 // http://crbug.com/355029.
[email protected]f6431be82013-09-07 02:53:451742 crash_keys::SetActiveExtensions(extension_ids);
[email protected]6014d672008-12-05 00:38:251743}
1744
[email protected]8266d662011-07-12 21:53:261745void ExtensionService::OnExtensionInstalled(
[email protected]36a5c4c2011-12-14 16:34:501746 const Extension* extension,
[email protected]98270432012-09-11 20:51:241747 const syncer::StringOrdinal& page_ordinal,
[email protected]4a1d9c0d2014-06-13 12:50:111748 int install_flags) {
[email protected]a29a517a2011-01-21 21:11:121749 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]a8af9fdb2010-10-28 21:52:201750
[email protected]c3cfb012011-04-06 22:07:351751 const std::string& id = extension->id();
[email protected]612a1cb12012-10-17 13:18:031752 bool initial_enable = ShouldEnableOnInstall(extension);
[email protected]d8fd0fd2014-03-24 13:16:061753 std::string install_parameter;
[email protected]3f213ad2012-07-26 23:39:411754 const extensions::PendingExtensionInfo* pending_extension_info = NULL;
[email protected]51a3bf8b2012-06-08 22:53:061755 if ((pending_extension_info = pending_extension_manager()->GetById(id))) {
[email protected]8f3bcbd2013-06-05 08:42:401756 if (!pending_extension_info->ShouldAllowInstall(extension)) {
[email protected]51a3bf8b2012-06-08 22:53:061757 pending_extension_manager()->Remove(id);
[email protected]8ef78fd2010-08-19 17:14:321758
[email protected]31bb5ee62012-09-12 22:58:401759 LOG(WARNING) << "ShouldAllowInstall() returned false for "
1760 << id << " of type " << extension->GetType()
[email protected]65348062013-01-15 07:27:221761 << " and update URL "
1762 << extensions::ManifestURL::GetUpdateURL(extension).spec()
[email protected]31bb5ee62012-09-12 22:58:401763 << "; not installing";
[email protected]ae6cb3022011-04-04 20:11:541764
[email protected]4416c5a2010-06-26 01:28:571765 // Delete the extension directory since we're not going to
1766 // load it.
[email protected]7f8f24f2012-11-15 19:40:141767 if (!GetFileTaskRunner()->PostTask(
1768 FROM_HERE,
[email protected]85df9d12014-04-15 17:02:141769 base::Bind(&extensions::file_util::DeleteFile,
1770 extension->path(),
1771 true))) {
[email protected]14908b72011-04-20 06:54:361772 NOTREACHED();
[email protected]31bb5ee62012-09-12 22:58:401773 }
[email protected]4416c5a2010-06-26 01:28:571774 return;
1775 }
[email protected]51a3bf8b2012-06-08 22:53:061776
[email protected]d8fd0fd2014-03-24 13:16:061777 install_parameter = pending_extension_info->install_parameter();
[email protected]51a3bf8b2012-06-08 22:53:061778 pending_extension_manager()->Remove(id);
[email protected]4416c5a2010-06-26 01:28:571779 } else {
[email protected]c3cfb012011-04-06 22:07:351780 // We explicitly want to re-enable an uninstalled external
1781 // extension; if we're here, that means the user is manually
1782 // installing the extension.
[email protected]46f3e102014-03-25 01:22:451783 if (extension_prefs_->IsExternalExtensionUninstalled(id)) {
[email protected]6cc7dbae2011-04-29 21:18:331784 initial_enable = true;
1785 }
[email protected]aa142702010-03-26 01:26:331786 }
1787
[email protected]98270432012-09-11 20:51:241788 // Unsupported requirements overrides the management policy.
[email protected]4a1d9c0d2014-06-13 12:50:111789 if (install_flags & extensions::kInstallFlagHasRequirementErrors) {
[email protected]98270432012-09-11 20:51:241790 initial_enable = false;
1791 extension_prefs_->AddDisableReason(
1792 id, Extension::DISABLE_UNSUPPORTED_REQUIREMENT);
1793 // If the extension was disabled because of unsupported requirements but
1794 // now supports all requirements after an update and there are not other
1795 // disable reasons, enable it.
1796 } else if (extension_prefs_->GetDisableReasons(id) ==
1797 Extension::DISABLE_UNSUPPORTED_REQUIREMENT) {
1798 initial_enable = true;
1799 extension_prefs_->ClearDisableReasons(id);
1800 }
1801
[email protected]4a1d9c0d2014-06-13 12:50:111802 if (install_flags & extensions::kInstallFlagIsBlacklistedForMalware) {
[email protected]9f3c8532013-07-31 19:52:071803 // Installation of a blacklisted extension can happen from sync, policy,
1804 // etc, where to maintain consistency we need to install it, just never
1805 // load it (see AddExtension). Usually it should be the job of callers to
1806 // incercept blacklisted extension earlier (e.g. CrxInstaller, before even
1807 // showing the install dialogue).
[email protected]7c82539c2014-02-19 06:09:171808 extension_prefs_->AcknowledgeBlacklistedExtension(id);
[email protected]9f3c8532013-07-31 19:52:071809 UMA_HISTOGRAM_ENUMERATION("ExtensionBlacklist.SilentInstall",
1810 extension->location(),
1811 Manifest::NUM_LOCATIONS);
1812 }
1813
[email protected]695b5712012-12-06 23:55:281814 if (!GetInstalledExtension(extension->id())) {
[email protected]07533022011-06-27 20:42:551815 UMA_HISTOGRAM_ENUMERATION("Extensions.InstallType",
1816 extension->GetType(), 100);
[email protected]69084dc2012-11-17 07:39:301817 UMA_HISTOGRAM_ENUMERATION("Extensions.InstallSource",
[email protected]1d5e58b2013-01-31 08:41:401818 extension->location(), Manifest::NUM_LOCATIONS);
[email protected]4c86be582014-06-04 08:39:111819 RecordPermissionMessagesHistogram(extension,
1820 "Extensions.Permissions_Install2");
[email protected]69084dc2012-11-17 07:39:301821 } else {
1822 UMA_HISTOGRAM_ENUMERATION("Extensions.UpdateType",
1823 extension->GetType(), 100);
1824 UMA_HISTOGRAM_ENUMERATION("Extensions.UpdateSource",
[email protected]1d5e58b2013-01-31 08:41:401825 extension->location(), Manifest::NUM_LOCATIONS);
[email protected]07533022011-06-27 20:42:551826 }
1827
[email protected]a39921b42012-02-28 03:42:541828 // Certain extension locations are specific enough that we can
1829 // auto-acknowledge any extension that came from one of them.
[email protected]4eef4352014-02-12 02:21:361830 if (Manifest::IsPolicyLocation(extension->location()) ||
1831 extension->location() == Manifest::EXTERNAL_COMPONENT)
[email protected]a39921b42012-02-28 03:42:541832 AcknowledgeExternalExtension(extension->id());
[email protected]399583b2012-12-11 09:33:421833 const Extension::State initial_state =
1834 initial_enable ? Extension::ENABLED : Extension::DISABLED;
[email protected]4a1d9c0d2014-06-13 12:50:111835 if (ShouldDelayExtensionUpdate(
1836 id,
1837 !!(install_flags & extensions::kInstallFlagInstallImmediately))) {
[email protected]9f3c8532013-07-31 19:52:071838 extension_prefs_->SetDelayedInstallInfo(
1839 extension,
1840 initial_state,
[email protected]4a1d9c0d2014-06-13 12:50:111841 install_flags,
[email protected]9f3c8532013-07-31 19:52:071842 extensions::ExtensionPrefs::DELAY_REASON_WAIT_FOR_IDLE,
[email protected]d8fd0fd2014-03-24 13:16:061843 page_ordinal,
1844 install_parameter);
[email protected]0db124b02012-11-07 04:55:051845
1846 // Transfer ownership of |extension|.
[email protected]9f4e4f082013-06-21 07:11:191847 delayed_installs_.Insert(extension);
[email protected]0db124b02012-11-07 04:55:051848
[email protected]75bdcb872013-03-13 00:41:451849 // Notify observers that app update is available.
1850 FOR_EACH_OBSERVER(extensions::UpdateObserver, update_observers_,
[email protected]a9aa62b312013-11-29 05:35:061851 OnAppUpdateAvailable(extension));
[email protected]0db124b02012-11-07 04:55:051852 return;
1853 }
1854
[email protected]90878c52014-04-04 18:21:021855 extensions::SharedModuleService::ImportStatus status =
1856 shared_module_service_->SatisfyImports(extension);
[email protected]e5f8fffe2014-04-02 00:30:441857 if (installs_delayed_for_gc_) {
[email protected]9f3c8532013-07-31 19:52:071858 extension_prefs_->SetDelayedInstallInfo(
1859 extension,
1860 initial_state,
[email protected]4a1d9c0d2014-06-13 12:50:111861 install_flags,
[email protected]9f3c8532013-07-31 19:52:071862 extensions::ExtensionPrefs::DELAY_REASON_GC,
[email protected]d8fd0fd2014-03-24 13:16:061863 page_ordinal,
1864 install_parameter);
[email protected]399583b2012-12-11 09:33:421865 delayed_installs_.Insert(extension);
[email protected]90878c52014-04-04 18:21:021866 } else if (status != SharedModuleService::IMPORT_STATUS_OK) {
1867 if (status == SharedModuleService::IMPORT_STATUS_UNSATISFIED) {
[email protected]9f3c8532013-07-31 19:52:071868 extension_prefs_->SetDelayedInstallInfo(
1869 extension,
1870 initial_state,
[email protected]4a1d9c0d2014-06-13 12:50:111871 install_flags,
[email protected]9f4e4f082013-06-21 07:11:191872 extensions::ExtensionPrefs::DELAY_REASON_WAIT_FOR_IMPORTS,
[email protected]d8fd0fd2014-03-24 13:16:061873 page_ordinal,
1874 install_parameter);
[email protected]9f4e4f082013-06-21 07:11:191875 delayed_installs_.Insert(extension);
1876 }
[email protected]399583b2012-12-11 09:33:421877 } else {
[email protected]9f3c8532013-07-31 19:52:071878 AddNewOrUpdatedExtension(extension,
1879 initial_state,
[email protected]4a1d9c0d2014-06-13 12:50:111880 install_flags,
[email protected]d8fd0fd2014-03-24 13:16:061881 page_ordinal,
1882 install_parameter);
[email protected]399583b2012-12-11 09:33:421883 }
[email protected]8c484b742012-11-29 06:05:361884}
1885
1886void ExtensionService::AddNewOrUpdatedExtension(
1887 const Extension* extension,
[email protected]399583b2012-12-11 09:33:421888 Extension::State initial_state,
[email protected]4a1d9c0d2014-06-13 12:50:111889 int install_flags,
[email protected]d8fd0fd2014-03-24 13:16:061890 const syncer::StringOrdinal& page_ordinal,
1891 const std::string& install_parameter) {
[email protected]8c484b742012-11-29 06:05:361892 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]760f743b2014-05-28 13:52:021893 bool was_ephemeral = extension_prefs_->IsEphemeralApp(extension->id());
[email protected]4a1d9c0d2014-06-13 12:50:111894 extension_prefs_->OnExtensionInstalled(
1895 extension, initial_state, page_ordinal, install_flags, install_parameter);
[email protected]9e9c1d12013-07-31 01:58:121896 delayed_installs_.Remove(extension->id());
[email protected]913ffca92014-03-27 15:26:161897 if (InstallVerifier::NeedsVerification(*extension))
1898 system_->install_verifier()->VerifyExtension(extension->id());
[email protected]760f743b2014-05-28 13:52:021899 FinishInstallation(extension, was_ephemeral);
[email protected]6f6101832012-11-27 22:10:481900}
1901
1902void ExtensionService::MaybeFinishDelayedInstallation(
1903 const std::string& extension_id) {
[email protected]9f4e4f082013-06-21 07:11:191904 // Check if the extension already got installed.
1905 if (!delayed_installs_.Contains(extension_id))
[email protected]6f6101832012-11-27 22:10:481906 return;
[email protected]9f4e4f082013-06-21 07:11:191907 extensions::ExtensionPrefs::DelayReason reason =
1908 extension_prefs_->GetDelayedInstallReason(extension_id);
1909
1910 // Check if the extension is idle. DELAY_REASON_NONE is used for older
1911 // preferences files that will not have set this field but it was previously
1912 // only used for idle updates.
1913 if ((reason == extensions::ExtensionPrefs::DELAY_REASON_WAIT_FOR_IDLE ||
1914 reason == extensions::ExtensionPrefs::DELAY_REASON_NONE) &&
[email protected]1d5cf4142014-01-24 18:25:221915 is_ready() && !extensions::util::IsExtensionIdle(extension_id, profile_))
[email protected]6f6101832012-11-27 22:10:481916 return;
1917
[email protected]9f4e4f082013-06-21 07:11:191918 const Extension* extension = delayed_installs_.GetByID(extension_id);
1919 if (reason == extensions::ExtensionPrefs::DELAY_REASON_WAIT_FOR_IMPORTS) {
[email protected]90878c52014-04-04 18:21:021920 extensions::SharedModuleService::ImportStatus status =
1921 shared_module_service_->SatisfyImports(extension);
1922 if (status != SharedModuleService::IMPORT_STATUS_OK) {
1923 if (status == SharedModuleService::IMPORT_STATUS_UNRECOVERABLE) {
[email protected]9f4e4f082013-06-21 07:11:191924 delayed_installs_.Remove(extension_id);
1925 // Make sure no version of the extension is actually installed, (i.e.,
1926 // that this delayed install was not an update).
1927 CHECK(!extension_prefs_->GetInstalledExtensionInfo(extension_id).get());
1928 extension_prefs_->DeleteExtensionPrefs(extension_id);
1929 }
1930 return;
1931 }
1932 }
1933
[email protected]6f6101832012-11-27 22:10:481934 FinishDelayedInstallation(extension_id);
1935}
1936
1937void ExtensionService::FinishDelayedInstallation(
1938 const std::string& extension_id) {
1939 scoped_refptr<const Extension> extension(
1940 GetPendingExtensionUpdate(extension_id));
[email protected]dc24976f2013-06-02 21:15:091941 CHECK(extension.get());
[email protected]9f4e4f082013-06-21 07:11:191942 delayed_installs_.Remove(extension_id);
[email protected]6f6101832012-11-27 22:10:481943
[email protected]760f743b2014-05-28 13:52:021944 bool was_ephemeral = extension_prefs_->IsEphemeralApp(extension->id());
[email protected]399583b2012-12-11 09:33:421945 if (!extension_prefs_->FinishDelayedInstallInfo(extension_id))
[email protected]6f6101832012-11-27 22:10:481946 NOTREACHED();
1947
[email protected]760f743b2014-05-28 13:52:021948 FinishInstallation(extension.get(), was_ephemeral);
[email protected]6f6101832012-11-27 22:10:481949}
1950
[email protected]760f743b2014-05-28 13:52:021951void ExtensionService::FinishInstallation(
1952 const Extension* extension, bool was_ephemeral) {
[email protected]e7554c3f2013-05-29 00:36:561953 const extensions::Extension* existing_extension =
1954 GetInstalledExtension(extension->id());
1955 bool is_update = false;
1956 std::string old_name;
1957 if (existing_extension) {
1958 is_update = true;
1959 old_name = existing_extension->name();
1960 }
[email protected]760f743b2014-05-28 13:52:021961 bool from_ephemeral =
1962 was_ephemeral && !extension_prefs_->IsEphemeralApp(extension->id());
1963 extensions::InstalledExtensionInfo details(
1964 extension, is_update, from_ephemeral, old_name);
[email protected]fcb58a862012-05-01 01:03:151965 content::NotificationService::current()->Notify(
[email protected]0403d4e2014-05-23 07:56:361966 chrome::NOTIFICATION_EXTENSION_INSTALLED_DEPRECATED,
[email protected]fcb58a862012-05-01 01:03:151967 content::Source<Profile>(profile_),
[email protected]41bb80bd2013-05-03 10:56:021968 content::Details<const extensions::InstalledExtensionInfo>(&details));
[email protected]fcb58a862012-05-01 01:03:151969
[email protected]bc44b5da2014-06-12 14:20:001970 registry_->TriggerOnWillBeInstalled(
[email protected]760f743b2014-05-28 13:52:021971 extension, is_update, from_ephemeral, old_name);
[email protected]17f07822014-05-22 08:45:151972
[email protected]d96eb512012-11-01 23:44:081973 bool unacknowledged_external = IsUnacknowledgedExternalExtension(extension);
[email protected]41070e8d2012-10-24 01:34:361974
[email protected]399583b2012-12-11 09:33:421975 // Unpacked extensions default to allowing file access, but if that has been
1976 // overridden, don't reset the value.
[email protected]1d5e58b2013-01-31 08:41:401977 if (Manifest::ShouldAlwaysAllowFileAccess(extension->location()) &&
[email protected]399583b2012-12-11 09:33:421978 !extension_prefs_->HasAllowFileAccessSetting(extension->id())) {
1979 extension_prefs_->SetAllowFileAccess(extension->id(), true);
1980 }
1981
[email protected]6f6101832012-11-27 22:10:481982 AddExtension(extension);
[email protected]612a1cb12012-10-17 13:18:031983
[email protected]bc44b5da2014-06-12 14:20:001984 // Notify observers that need to know when an installation is complete.
1985 registry_->TriggerOnInstalled(extension);
1986
[email protected]612a1cb12012-10-17 13:18:031987 // If this is a new external extension that was disabled, alert the user
[email protected]d96eb512012-11-01 23:44:081988 // so he can reenable it. We do this last so that it has already been
1989 // added to our list of extensions.
[email protected]3e3fafbb2013-08-17 13:33:161990 if (unacknowledged_external && !is_update) {
[email protected]612a1cb12012-10-17 13:18:031991 UpdateExternalExtensionAlert();
[email protected]d96eb512012-11-01 23:44:081992 UMA_HISTOGRAM_ENUMERATION("Extensions.ExternalExtensionEvent",
1993 EXTERNAL_EXTENSION_INSTALLED,
1994 EXTERNAL_EXTENSION_BUCKET_BOUNDARY);
[email protected]446e37e2013-08-07 00:30:021995 if (extensions::ManifestURL::UpdatesFromGallery(extension)) {
1996 UMA_HISTOGRAM_ENUMERATION("Extensions.ExternalExtensionEventWebstore",
1997 EXTERNAL_EXTENSION_INSTALLED,
1998 EXTERNAL_EXTENSION_BUCKET_BOUNDARY);
1999 } else {
2000 UMA_HISTOGRAM_ENUMERATION("Extensions.ExternalExtensionEventNonWebstore",
2001 EXTERNAL_EXTENSION_INSTALLED,
2002 EXTERNAL_EXTENSION_BUCKET_BOUNDARY);
2003 }
[email protected]d96eb512012-11-01 23:44:082004 }
[email protected]9f4e4f082013-06-21 07:11:192005
2006 // Check extensions that may have been delayed only because this shared module
2007 // was not available.
2008 if (SharedModuleInfo::IsSharedModule(extension)) {
2009 MaybeFinishDelayedInstallations();
2010 }
[email protected]4a190632009-05-09 01:07:422011}
2012
[email protected]760f743b2014-05-28 13:52:022013void ExtensionService::PromoteEphemeralApp(
2014 const extensions::Extension* extension, bool is_from_sync) {
2015 DCHECK(GetInstalledExtension(extension->id()) &&
2016 extension_prefs_->IsEphemeralApp(extension->id()));
2017
2018 if (!is_from_sync) {
2019 if (extension->RequiresSortOrdinal()) {
2020 // Reset the sort ordinals of the app to ensure it is added to the default
2021 // position, like newly installed apps would.
2022 extension_prefs_->app_sorting()->ClearOrdinals(extension->id());
2023 extension_prefs_->app_sorting()->EnsureValidOrdinals(
2024 extension->id(), syncer::StringOrdinal());
2025 }
2026
2027 if (extension_prefs_->IsExtensionDisabled(extension->id()) &&
2028 !extension_prefs_->IsExtensionBlacklisted(extension->id())) {
2029 // If the extension is not blacklisted and was disabled due to permission
2030 // increase or user action only, we can enable it because the user was
2031 // prompted.
2032 extension_prefs_->RemoveDisableReason(
2033 extension->id(),
2034 Extension::DISABLE_PERMISSIONS_INCREASE);
2035 extension_prefs_->RemoveDisableReason(
2036 extension->id(),
2037 Extension::DISABLE_USER_ACTION);
2038 if (!extension_prefs_->GetDisableReasons(extension->id()))
2039 EnableExtension(extension->id());
2040 }
2041 }
2042
2043 // Remove the ephemeral flags from the preferences.
2044 extension_prefs_->OnEphemeralAppPromoted(extension->id());
2045
2046 // Fire install-related events to allow observers to handle the promotion
2047 // of the ephemeral app.
2048 extensions::InstalledExtensionInfo details(
2049 extension,
2050 true /* is update */,
2051 true /* from ephemeral */,
2052 extension->name() /* old name */);
2053 content::NotificationService::current()->Notify(
2054 chrome::NOTIFICATION_EXTENSION_INSTALLED_DEPRECATED,
2055 content::Source<Profile>(profile_),
2056 content::Details<const extensions::InstalledExtensionInfo>(&details));
2057
2058 registry_->TriggerOnWillBeInstalled(
2059 extension,
2060 true /* is update */,
2061 true /* from ephemeral */,
2062 extension->name() /* old name */);
2063
2064 if (registry_->enabled_extensions().Contains(extension->id())) {
2065 content::NotificationService::current()->Notify(
2066 chrome::NOTIFICATION_EXTENSION_LOADED_DEPRECATED,
2067 content::Source<Profile>(profile_),
2068 content::Details<const Extension>(extension));
2069
2070 registry_->TriggerOnLoaded(extension);
2071 }
2072
[email protected]bc44b5da2014-06-12 14:20:002073 registry_->TriggerOnInstalled(extension);
2074
[email protected]760f743b2014-05-28 13:52:022075 if (!is_from_sync && extension_sync_service_)
2076 extension_sync_service_->SyncExtensionChangeIfNeeded(*extension);
2077}
2078
[email protected]76b65442012-11-17 14:11:482079const Extension* ExtensionService::GetPendingExtensionUpdate(
2080 const std::string& id) const {
[email protected]9f4e4f082013-06-21 07:11:192081 return delayed_installs_.GetByID(id);
[email protected]76b65442012-11-17 14:11:482082}
2083
[email protected]bb7f40952011-01-13 00:21:202084void ExtensionService::TrackTerminatedExtension(const Extension* extension) {
[email protected]bb1bc9b32013-12-21 03:09:142085 // No need to check for duplicates; inserting a duplicate is a no-op.
2086 registry_->AddTerminated(make_scoped_refptr(extension));
[email protected]3964e572014-02-13 21:57:412087 extensions_being_terminated_.erase(extension->id());
[email protected]b0af4792013-10-23 09:12:132088 UnloadExtension(extension->id(), UnloadedExtensionInfo::REASON_TERMINATE);
[email protected]bb7f40952011-01-13 00:21:202089}
2090
[email protected]e9d7496e2014-04-18 01:25:462091void ExtensionService::TerminateExtension(const std::string& extension_id) {
2092 const Extension* extension = GetInstalledExtension(extension_id);
2093 TrackTerminatedExtension(extension);
2094}
2095
[email protected]bb7f40952011-01-13 00:21:202096void ExtensionService::UntrackTerminatedExtension(const std::string& id) {
[email protected]fa2416f2011-05-03 08:41:202097 std::string lowercase_id = StringToLowerASCII(id);
[email protected]bb1bc9b32013-12-21 03:09:142098 const Extension* extension =
2099 registry_->terminated_extensions().GetByID(lowercase_id);
2100 registry_->RemoveTerminated(lowercase_id);
[email protected]fb789532013-08-27 02:40:212101 if (extension) {
2102 content::NotificationService::current()->Notify(
2103 chrome::NOTIFICATION_EXTENSION_REMOVED,
2104 content::Source<Profile>(profile_),
2105 content::Details<const Extension>(extension));
2106 }
[email protected]bb7f40952011-01-13 00:21:202107}
2108
[email protected]8001df22011-04-28 19:59:472109const Extension* ExtensionService::GetInstalledExtension(
2110 const std::string& id) const {
[email protected]599539802014-01-07 23:06:002111 return registry_->GetExtensionById(id, ExtensionRegistry::EVERYTHING);
[email protected]0dfe05c2011-02-23 23:03:362112}
2113
[email protected]9060d8b02012-01-13 02:14:302114bool ExtensionService::OnExternalExtensionFileFound(
[email protected]8ef78fd2010-08-19 17:14:322115 const std::string& id,
[email protected]c5e4a2222014-01-03 16:06:132116 const Version* version,
[email protected]650b2d52013-02-10 03:41:452117 const base::FilePath& path,
[email protected]1d5e58b2013-01-31 08:41:402118 Manifest::Location location,
[email protected]47fc70c2011-12-06 07:29:512119 int creation_flags,
2120 bool mark_acknowledged) {
[email protected]ab22ba42011-01-14 16:36:382121 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
2122 CHECK(Extension::IdIsValid(id));
[email protected]79c833b52011-04-05 18:31:012123 if (extension_prefs_->IsExternalExtensionUninstalled(id))
[email protected]9060d8b02012-01-13 02:14:302124 return false;
[email protected]a8af9fdb2010-10-28 21:52:202125
[email protected]7577a5c52009-07-30 06:21:582126 // Before even bothering to unpack, check and see if we already have this
[email protected]4c967932009-07-31 01:15:492127 // version. This is important because these extensions are going to get
[email protected]7577a5c52009-07-30 06:21:582128 // installed on every startup.
[email protected]9adb9692010-10-29 23:14:022129 const Extension* existing = GetExtensionById(id, true);
[email protected]910f72ce2012-08-24 01:38:352130
[email protected]7577a5c52009-07-30 06:21:582131 if (existing) {
[email protected]910f72ce2012-08-24 01:38:352132 // The default apps will have the location set as INTERNAL. Since older
2133 // default apps are installed as EXTERNAL, we override them. However, if the
2134 // app is already installed as internal, then do the version check.
[email protected]31bb5ee62012-09-12 22:58:402135 // TODO(grv) : Remove after Q1-2013.
[email protected]910f72ce2012-08-24 01:38:352136 bool is_default_apps_migration =
[email protected]1d5e58b2013-01-31 08:41:402137 (location == Manifest::INTERNAL &&
2138 Manifest::IsExternalLocation(existing->location()));
[email protected]910f72ce2012-08-24 01:38:352139
2140 if (!is_default_apps_migration) {
2141 DCHECK(version);
2142
2143 switch (existing->version()->CompareTo(*version)) {
2144 case -1: // existing version is older, we should upgrade
2145 break;
2146 case 0: // existing version is same, do nothing
2147 return false;
2148 case 1: // existing version is newer, uh-oh
2149 LOG(WARNING) << "Found external version of extension " << id
2150 << "that is older than current version. Current version "
2151 << "is: " << existing->VersionString() << ". New "
2152 << "version is: " << version->GetString()
2153 << ". Keeping current version.";
2154 return false;
2155 }
[email protected]7577a5c52009-07-30 06:21:582156 }
2157 }
2158
[email protected]9060d8b02012-01-13 02:14:302159 // If the extension is already pending, don't start an install.
[email protected]e3987852012-05-04 10:06:302160 if (!pending_extension_manager()->AddFromExternalFile(
[email protected]464213a2013-10-15 01:06:482161 id, location, *version, creation_flags, mark_acknowledged)) {
[email protected]9060d8b02012-01-13 02:14:302162 return false;
[email protected]e3987852012-05-04 10:06:302163 }
[email protected]9c635f22010-12-02 09:36:362164
[email protected]14908b72011-04-20 06:54:362165 // no client (silent install)
[email protected]f8636f92013-08-09 21:02:372166 scoped_refptr<CrxInstaller> installer(CrxInstaller::CreateSilent(this));
[email protected]6dfbbf82010-03-12 23:09:162167 installer->set_install_source(location);
2168 installer->set_expected_id(id);
[email protected]cb0e50312011-05-09 15:03:072169 installer->set_expected_version(*version);
2170 installer->set_install_cause(extension_misc::INSTALL_CAUSE_EXTERNAL_FILE);
[email protected]1bf73cc32011-10-26 22:38:312171 installer->set_creation_flags(creation_flags);
[email protected]88e8ec9152013-01-17 04:05:182172#if defined(OS_CHROMEOS)
2173 extensions::InstallLimiter::Get(profile_)->Add(installer, path);
2174#else
[email protected]6dfbbf82010-03-12 23:09:162175 installer->InstallCrx(path);
[email protected]88e8ec9152013-01-17 04:05:182176#endif
[email protected]47fc70c2011-12-06 07:29:512177
2178 // Depending on the source, a new external extension might not need a user
2179 // notification on installation. For such extensions, mark them acknowledged
2180 // now to suppress the notification.
2181 if (mark_acknowledged)
2182 AcknowledgeExternalExtension(id);
[email protected]9060d8b02012-01-13 02:14:302183
2184 return true;
[email protected]7577a5c52009-07-30 06:21:582185}
2186
[email protected]eaa7dd182010-12-14 11:09:002187void ExtensionService::DidCreateRenderViewForBackgroundPage(
[email protected]3a1dc572012-07-31 22:25:132188 extensions::ExtensionHost* host) {
[email protected]406027c02010-09-27 08:03:182189 OrphanedDevTools::iterator iter =
[email protected]2d2f6cfc2011-05-06 21:09:332190 orphaned_dev_tools_.find(host->extension_id());
[email protected]406027c02010-09-27 08:03:182191 if (iter == orphaned_dev_tools_.end())
2192 return;
2193
[email protected]04ea1bb2013-07-10 09:26:092194 iter->second->ConnectRenderViewHost(host->render_view_host());
[email protected]406027c02010-09-27 08:03:182195 orphaned_dev_tools_.erase(iter);
2196}
2197
[email protected]432115822011-07-10 15:52:272198void ExtensionService::Observe(int type,
[email protected]6c2381d2011-10-19 02:52:532199 const content::NotificationSource& source,
2200 const content::NotificationDetails& details) {
[email protected]432115822011-07-10 15:52:272201 switch (type) {
[email protected]3c4abc82012-10-22 22:25:542202 case chrome::NOTIFICATION_APP_TERMINATING:
2203 // Shutdown has started. Don't start any more extension installs.
2204 // (We cannot use ExtensionService::Shutdown() for this because it
2205 // happens too late in browser teardown.)
2206 browser_terminating_ = true;
2207 break;
[email protected]432115822011-07-10 15:52:272208 case chrome::NOTIFICATION_EXTENSION_PROCESS_TERMINATED: {
[email protected]6c2381d2011-10-19 02:52:532209 if (profile_ !=
2210 content::Source<Profile>(source).ptr()->GetOriginalProfile()) {
[email protected]bc535ee52010-08-31 18:40:322211 break;
[email protected]6c2381d2011-10-19 02:52:532212 }
[email protected]a4ed6282009-12-14 20:51:162213
[email protected]3a1dc572012-07-31 22:25:132214 extensions::ExtensionHost* host =
2215 content::Details<extensions::ExtensionHost>(details).ptr();
[email protected]f128af42010-08-05 18:05:262216
[email protected]3964e572014-02-13 21:57:412217 // If the extension is already being terminated, there is nothing left to
2218 // do.
2219 if (!extensions_being_terminated_.insert(host->extension_id()).second)
2220 break;
2221
[email protected]fa2416f2011-05-03 08:41:202222 // Mark the extension as terminated and Unload it. We want it to
2223 // be in a consistent state: either fully working or not loaded
2224 // at all, but never half-crashed. We do it in a PostTask so
2225 // that other handlers of this notification will still have
2226 // access to the Extension and ExtensionHost.
[email protected]b3a25092013-05-28 22:08:162227 base::MessageLoop::current()->PostTask(
[email protected]14908b72011-04-20 06:54:362228 FROM_HERE,
[email protected]53612e82011-10-18 18:00:362229 base::Bind(
[email protected]fa2416f2011-05-03 08:41:202230 &ExtensionService::TrackTerminatedExtension,
[email protected]d8c8f25f2011-11-02 18:18:012231 AsWeakPtr(),
[email protected]fa2416f2011-05-03 08:41:202232 host->extension()));
[email protected]31f77262009-12-02 20:48:532233 break;
2234 }
[email protected]432115822011-07-10 15:52:272235 case content::NOTIFICATION_RENDERER_PROCESS_TERMINATED: {
[email protected]f3b1a082011-11-18 00:34:302236 content::RenderProcessHost* process =
2237 content::Source<content::RenderProcessHost>(source).ptr();
[email protected]fc30ef082011-08-18 04:07:192238 Profile* host_profile =
[email protected]f3b1a082011-11-18 00:34:302239 Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]fc30ef082011-08-18 04:07:192240 if (!profile_->IsSameProfile(host_profile->GetOriginalProfile()))
2241 break;
2242
[email protected]fafdc842014-01-17 18:09:082243 extensions::ProcessMap* process_map =
2244 extensions::ProcessMap::Get(profile_);
2245 if (process_map->Contains(process->GetID())) {
[email protected]52b76592013-11-02 17:59:032246 // An extension process was terminated, this might have resulted in an
2247 // app or extension becoming idle.
2248 std::set<std::string> extension_ids =
[email protected]fafdc842014-01-17 18:09:082249 process_map->GetExtensionsInProcess(process->GetID());
[email protected]52b76592013-11-02 17:59:032250 for (std::set<std::string>::const_iterator it = extension_ids.begin();
2251 it != extension_ids.end(); ++it) {
2252 if (delayed_installs_.Contains(*it)) {
2253 base::MessageLoop::current()->PostDelayedTask(
2254 FROM_HERE,
2255 base::Bind(&ExtensionService::MaybeFinishDelayedInstallation,
2256 AsWeakPtr(), *it),
2257 base::TimeDelta::FromSeconds(kUpdateIdleDelay));
2258 }
2259 }
2260 }
2261
[email protected]fafdc842014-01-17 18:09:082262 process_map->RemoveAllFromProcess(process->GetID());
[email protected]6f371442011-11-09 06:45:462263 BrowserThread::PostTask(
[email protected]38427a12013-11-09 17:34:202264 BrowserThread::IO,
2265 FROM_HERE,
2266 base::Bind(&extensions::InfoMap::UnregisterAllExtensionsInProcess,
[email protected]31d8f5f22012-04-02 15:22:082267 system_->info_map(),
[email protected]f3b1a082011-11-18 00:34:302268 process->GetID()));
[email protected]da5683db2011-04-23 17:12:212269 break;
2270 }
[email protected]92dd8d92013-02-26 00:41:082271 case chrome::NOTIFICATION_UPGRADE_RECOMMENDED: {
[email protected]75bdcb872013-03-13 00:41:452272 // Notify observers that chrome update is available.
2273 FOR_EACH_OBSERVER(extensions::UpdateObserver, update_observers_,
2274 OnChromeUpdateAvailable());
[email protected]92dd8d92013-02-26 00:41:082275 break;
2276 }
[email protected]ebe07772014-05-22 04:16:062277 case chrome::NOTIFICATION_PROFILE_DESTRUCTION_STARTED: {
2278 OnProfileDestructionStarted();
2279 break;
2280 }
[email protected]aa96d3a2010-08-21 08:45:252281
[email protected]4814b512009-11-07 00:12:292282 default:
2283 NOTREACHED() << "Unexpected notification type.";
2284 }
2285}
2286
[email protected]90bb38d2012-11-14 18:36:032287void ExtensionService::OnExtensionInstallPrefChanged() {
[email protected]373daf972014-04-10 01:50:442288 error_controller_->ShowErrorIfNeeded();
[email protected]a6a7ced2012-11-01 17:24:182289 CheckManagementPolicy();
2290}
2291
[email protected]e178ad92013-06-28 02:29:252292bool ExtensionService::IsBeingReloaded(
2293 const std::string& extension_id) const {
2294 return ContainsKey(extensions_being_reloaded_, extension_id);
2295}
2296
2297void ExtensionService::SetBeingReloaded(const std::string& extension_id,
[email protected]5e7015c2013-07-23 23:29:432298 bool isBeingReloaded) {
2299 if (isBeingReloaded)
[email protected]e178ad92013-06-28 02:29:252300 extensions_being_reloaded_.insert(extension_id);
[email protected]5e7015c2013-07-23 23:29:432301 else
[email protected]e178ad92013-06-28 02:29:252302 extensions_being_reloaded_.erase(extension_id);
[email protected]e178ad92013-06-28 02:29:252303}
2304
[email protected]612a1cb12012-10-17 13:18:032305bool ExtensionService::ShouldEnableOnInstall(const Extension* extension) {
2306 // Extensions installed by policy can't be disabled. So even if a previous
2307 // installation disabled the extension, make sure it is now enabled.
[email protected]75181f62014-03-19 21:41:122308 // TODO(rlp): Clean up the special case for external components as noted
2309 // in crbug.com/353266. For now, EXTERNAL_COMPONENT apps should be
2310 // default enabled on install as before.
2311 if (system_->management_policy()->MustRemainEnabled(extension, NULL) ||
2312 extension->location() == Manifest::EXTERNAL_COMPONENT) {
[email protected]612a1cb12012-10-17 13:18:032313 return true;
[email protected]75181f62014-03-19 21:41:122314 }
[email protected]612a1cb12012-10-17 13:18:032315
2316 if (extension_prefs_->IsExtensionDisabled(extension->id()))
2317 return false;
2318
[email protected]41070e8d2012-10-24 01:34:362319 if (FeatureSwitch::prompt_for_external_extensions()->IsEnabled()) {
[email protected]612a1cb12012-10-17 13:18:032320 // External extensions are initially disabled. We prompt the user before
[email protected]2c495c42013-01-04 21:49:542321 // enabling them. Hosted apps are excepted because they are not dangerous
2322 // (they need to be launched by the user anyway).
[email protected]1d5e58b2013-01-31 08:41:402323 if (extension->GetType() != Manifest::TYPE_HOSTED_APP &&
2324 Manifest::IsExternalLocation(extension->location()) &&
[email protected]612a1cb12012-10-17 13:18:032325 !extension_prefs_->IsExternalExtensionAcknowledged(extension->id())) {
2326 return false;
2327 }
2328 }
[email protected]612a1cb12012-10-17 13:18:032329
2330 return true;
2331}
[email protected]0db124b02012-11-07 04:55:052332
[email protected]e7aa7b7e2012-11-27 04:51:222333bool ExtensionService::ShouldDelayExtensionUpdate(
2334 const std::string& extension_id,
[email protected]4a1d9c0d2014-06-13 12:50:112335 bool install_immediately) const {
[email protected]e7aa7b7e2012-11-27 04:51:222336 const char kOnUpdateAvailableEvent[] = "runtime.onUpdateAvailable";
2337
2338 // If delayed updates are globally disabled, or just for this extension,
2339 // don't delay.
[email protected]4a1d9c0d2014-06-13 12:50:112340 if (!install_updates_when_idle_ || install_immediately)
[email protected]e7aa7b7e2012-11-27 04:51:222341 return false;
2342
[email protected]695b5712012-12-06 23:55:282343 const Extension* old = GetInstalledExtension(extension_id);
[email protected]e7aa7b7e2012-11-27 04:51:222344 // If there is no old extension, this is not an update, so don't delay.
2345 if (!old)
2346 return false;
2347
[email protected]9367eabc2013-03-01 01:29:292348 if (extensions::BackgroundInfo::HasPersistentBackgroundPage(old)) {
[email protected]e7aa7b7e2012-11-27 04:51:222349 // Delay installation if the extension listens for the onUpdateAvailable
2350 // event.
2351 return system_->event_router()->ExtensionHasEventListener(
2352 extension_id, kOnUpdateAvailableEvent);
2353 } else {
2354 // Delay installation if the extension is not idle.
[email protected]1d5cf4142014-01-24 18:25:222355 return !extensions::util::IsExtensionIdle(extension_id, profile_);
[email protected]e7aa7b7e2012-11-27 04:51:222356 }
[email protected]0db124b02012-11-07 04:55:052357}
[email protected]fdd679b2012-11-15 20:49:392358
[email protected]e5f8fffe2014-04-02 00:30:442359void ExtensionService::OnGarbageCollectIsolatedStorageStart() {
2360 DCHECK(!installs_delayed_for_gc_);
2361 installs_delayed_for_gc_ = true;
[email protected]399583b2012-12-11 09:33:422362}
2363
2364void ExtensionService::OnGarbageCollectIsolatedStorageFinished() {
[email protected]e5f8fffe2014-04-02 00:30:442365 DCHECK(installs_delayed_for_gc_);
2366 installs_delayed_for_gc_ = false;
[email protected]9f4e4f082013-06-21 07:11:192367 MaybeFinishDelayedInstallations();
2368}
2369
2370void ExtensionService::MaybeFinishDelayedInstallations() {
2371 std::vector<std::string> to_be_installed;
[email protected]399583b2012-12-11 09:33:422372 for (ExtensionSet::const_iterator it = delayed_installs_.begin();
2373 it != delayed_installs_.end();
2374 ++it) {
[email protected]9f4e4f082013-06-21 07:11:192375 to_be_installed.push_back((*it)->id());
[email protected]399583b2012-12-11 09:33:422376 }
[email protected]9f4e4f082013-06-21 07:11:192377 for (std::vector<std::string>::const_iterator it = to_be_installed.begin();
2378 it != to_be_installed.end();
[email protected]399583b2012-12-11 09:33:422379 ++it) {
[email protected]9f4e4f082013-06-21 07:11:192380 MaybeFinishDelayedInstallation(*it);
[email protected]399583b2012-12-11 09:33:422381 }
[email protected]399583b2012-12-11 09:33:422382}
2383
[email protected]fdd679b2012-11-15 20:49:392384void ExtensionService::OnBlacklistUpdated() {
[email protected]2d19eb6e2014-01-27 17:30:002385 blacklist_->GetBlacklistedIDs(
[email protected]f47f7172014-03-19 19:27:102386 registry_->GenerateInstalledExtensionsSet()->GetIDs(),
[email protected]3f2a2fa2013-09-24 02:55:252387 base::Bind(&ExtensionService::ManageBlacklist, AsWeakPtr()));
[email protected]695b5712012-12-06 23:55:282388}
2389
[email protected]2d19eb6e2014-01-27 17:30:002390void ExtensionService::ManageBlacklist(
2391 const extensions::Blacklist::BlacklistStateMap& state_map) {
[email protected]54ee8192014-03-29 17:37:242392 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]695b5712012-12-06 23:55:282393
[email protected]2d19eb6e2014-01-27 17:30:002394 std::set<std::string> blocked;
2395 ExtensionIdSet greylist;
2396 ExtensionIdSet unchanged;
2397 for (extensions::Blacklist::BlacklistStateMap::const_iterator it =
2398 state_map.begin();
2399 it != state_map.end();
2400 ++it) {
2401 switch (it->second) {
2402 case extensions::NOT_BLACKLISTED:
2403 break;
[email protected]695b5712012-12-06 23:55:282404
[email protected]2d19eb6e2014-01-27 17:30:002405 case extensions::BLACKLISTED_MALWARE:
2406 blocked.insert(it->first);
2407 break;
2408
2409 case extensions::BLACKLISTED_SECURITY_VULNERABILITY:
2410 case extensions::BLACKLISTED_CWS_POLICY_VIOLATION:
2411 case extensions::BLACKLISTED_POTENTIALLY_UNWANTED:
2412 greylist.insert(it->first);
2413 break;
2414
2415 case extensions::BLACKLISTED_UNKNOWN:
2416 unchanged.insert(it->first);
2417 break;
2418 }
2419 }
2420
2421 UpdateBlockedExtensions(blocked, unchanged);
2422 UpdateGreylistedExtensions(greylist, unchanged, state_map);
2423
[email protected]373daf972014-04-10 01:50:442424 error_controller_->ShowErrorIfNeeded();
[email protected]2d19eb6e2014-01-27 17:30:002425}
2426
2427namespace {
2428void Partition(const ExtensionIdSet& before,
2429 const ExtensionIdSet& after,
2430 const ExtensionIdSet& unchanged,
2431 ExtensionIdSet* no_longer,
2432 ExtensionIdSet* not_yet) {
2433 *not_yet = base::STLSetDifference<ExtensionIdSet>(after, before);
2434 *no_longer = base::STLSetDifference<ExtensionIdSet>(before, after);
2435 *no_longer = base::STLSetDifference<ExtensionIdSet>(*no_longer, unchanged);
2436}
2437} // namespace
2438
2439void ExtensionService::UpdateBlockedExtensions(
2440 const ExtensionIdSet& blocked,
2441 const ExtensionIdSet& unchanged) {
2442 ExtensionIdSet not_yet_blocked, no_longer_blocked;
2443 Partition(registry_->blacklisted_extensions().GetIDs(),
2444 blocked, unchanged,
2445 &no_longer_blocked, &not_yet_blocked);
2446
2447 for (ExtensionIdSet::iterator it = no_longer_blocked.begin();
2448 it != no_longer_blocked.end(); ++it) {
[email protected]695b5712012-12-06 23:55:282449 scoped_refptr<const Extension> extension =
[email protected]bb1bc9b32013-12-21 03:09:142450 registry_->blacklisted_extensions().GetByID(*it);
[email protected]3f2a2fa2013-09-24 02:55:252451 if (!extension.get()) {
[email protected]2d19eb6e2014-01-27 17:30:002452 NOTREACHED() << "Extension " << *it << " no longer blocked, "
2453 << "but it was never blocked.";
[email protected]695b5712012-12-06 23:55:282454 continue;
[email protected]3f2a2fa2013-09-24 02:55:252455 }
[email protected]bb1bc9b32013-12-21 03:09:142456 registry_->RemoveBlacklisted(*it);
[email protected]3f2a2fa2013-09-24 02:55:252457 extension_prefs_->SetExtensionBlacklisted(extension->id(), false);
[email protected]dc24976f2013-06-02 21:15:092458 AddExtension(extension.get());
[email protected]ac875372013-02-28 04:36:092459 UMA_HISTOGRAM_ENUMERATION("ExtensionBlacklist.UnblacklistInstalled",
[email protected]dc24976f2013-06-02 21:15:092460 extension->location(),
2461 Manifest::NUM_LOCATIONS);
[email protected]695b5712012-12-06 23:55:282462 }
2463
[email protected]2d19eb6e2014-01-27 17:30:002464 for (ExtensionIdSet::iterator it = not_yet_blocked.begin();
2465 it != not_yet_blocked.end(); ++it) {
[email protected]695b5712012-12-06 23:55:282466 scoped_refptr<const Extension> extension = GetInstalledExtension(*it);
[email protected]3f2a2fa2013-09-24 02:55:252467 if (!extension.get()) {
2468 NOTREACHED() << "Extension " << *it << " needs to be "
2469 << "blacklisted, but it's not installed.";
[email protected]695b5712012-12-06 23:55:282470 continue;
[email protected]3f2a2fa2013-09-24 02:55:252471 }
[email protected]bb1bc9b32013-12-21 03:09:142472 registry_->AddBlacklisted(extension);
[email protected]2d19eb6e2014-01-27 17:30:002473 extension_prefs_->SetExtensionBlacklistState(
2474 extension->id(), extensions::BLACKLISTED_MALWARE);
[email protected]b0af4792013-10-23 09:12:132475 UnloadExtension(*it, UnloadedExtensionInfo::REASON_BLACKLIST);
[email protected]ac875372013-02-28 04:36:092476 UMA_HISTOGRAM_ENUMERATION("ExtensionBlacklist.BlacklistInstalled",
2477 extension->location(), Manifest::NUM_LOCATIONS);
[email protected]695b5712012-12-06 23:55:282478 }
[email protected]2d19eb6e2014-01-27 17:30:002479}
[email protected]695b5712012-12-06 23:55:282480
[email protected]2d19eb6e2014-01-27 17:30:002481// TODO(oleg): UMA logging
2482void ExtensionService::UpdateGreylistedExtensions(
2483 const ExtensionIdSet& greylist,
2484 const ExtensionIdSet& unchanged,
2485 const extensions::Blacklist::BlacklistStateMap& state_map) {
2486 ExtensionIdSet not_yet_greylisted, no_longer_greylisted;
2487 Partition(greylist_.GetIDs(),
2488 greylist, unchanged,
2489 &no_longer_greylisted, &not_yet_greylisted);
2490
2491 for (ExtensionIdSet::iterator it = no_longer_greylisted.begin();
2492 it != no_longer_greylisted.end(); ++it) {
2493 scoped_refptr<const Extension> extension = greylist_.GetByID(*it);
2494 if (!extension.get()) {
2495 NOTREACHED() << "Extension " << *it << " no longer greylisted, "
2496 << "but it was not marked as greylisted.";
2497 continue;
2498 }
2499
2500 greylist_.Remove(*it);
2501 extension_prefs_->SetExtensionBlacklistState(extension->id(),
2502 extensions::NOT_BLACKLISTED);
2503 if (extension_prefs_->GetDisableReasons(extension->id()) &
2504 extensions::Extension::DISABLE_GREYLIST)
2505 EnableExtension(*it);
2506 }
2507
2508 for (ExtensionIdSet::iterator it = not_yet_greylisted.begin();
2509 it != not_yet_greylisted.end(); ++it) {
2510 scoped_refptr<const Extension> extension = GetInstalledExtension(*it);
2511 if (!extension.get()) {
2512 NOTREACHED() << "Extension " << *it << " needs to be "
2513 << "disabled, but it's not installed.";
2514 continue;
2515 }
2516 greylist_.Insert(extension);
2517 extension_prefs_->SetExtensionBlacklistState(extension->id(),
2518 state_map.find(*it)->second);
2519 if (registry_->enabled_extensions().Contains(extension->id()))
2520 DisableExtension(*it, extensions::Extension::DISABLE_GREYLIST);
2521 }
[email protected]fdd679b2012-11-15 20:49:392522}
[email protected]75bdcb872013-03-13 00:41:452523
2524void ExtensionService::AddUpdateObserver(extensions::UpdateObserver* observer) {
2525 update_observers_.AddObserver(observer);
2526}
2527
2528void ExtensionService::RemoveUpdateObserver(
2529 extensions::UpdateObserver* observer) {
2530 update_observers_.RemoveObserver(observer);
2531}
[email protected]bb1bc9b32013-12-21 03:09:142532
2533// Used only by test code.
2534void ExtensionService::UnloadAllExtensionsInternal() {
2535 profile_->GetExtensionSpecialStoragePolicy()->RevokeRightsForAllExtensions();
2536
2537 registry_->ClearAll();
[email protected]45f5b7d2014-01-22 23:47:132538 system_->runtime_data()->ClearAll();
[email protected]bb1bc9b32013-12-21 03:09:142539
2540 // TODO(erikkay) should there be a notification for this? We can't use
2541 // EXTENSION_UNLOADED since that implies that the extension has been disabled
2542 // or uninstalled.
2543}
[email protected]ebe07772014-05-22 04:16:062544
2545void ExtensionService::OnProfileDestructionStarted() {
2546 ExtensionIdSet ids_to_unload = registry_->enabled_extensions().GetIDs();
2547 for (ExtensionIdSet::iterator it = ids_to_unload.begin();
2548 it != ids_to_unload.end();
2549 ++it) {
2550 UnloadExtension(*it, UnloadedExtensionInfo::REASON_PROFILE_SHUTDOWN);
2551 }
2552}