blob: a0c3ef90f18c9afb44361e00ee69f08937e3e7dc [file] [log] [blame]
[email protected]16d900042012-01-04 21:24:321// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]6014d672008-12-05 00:38:252// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]eaa7dd182010-12-14 11:09:005#include "chrome/browser/extensions/extension_service.h"
[email protected]6014d672008-12-05 00:38:256
[email protected]654512b2010-09-01 02:09:427#include <algorithm>
[email protected]695b5712012-12-06 23:55:288#include <iterator>
[email protected]97d2f1d2011-01-15 00:41:089#include <set>
[email protected]654512b2010-09-01 02:09:4210
[email protected]24b538a2010-02-27 01:22:4411#include "base/basictypes.h"
[email protected]05aad2da2011-10-28 10:12:3712#include "base/bind.h"
[email protected]e5af875f2011-10-10 21:09:1413#include "base/callback.h"
[email protected]62433d32011-10-12 22:33:1214#include "base/command_line.h"
[email protected]6014d672008-12-05 00:38:2515#include "base/file_util.h"
[email protected]14908b72011-04-20 06:54:3616#include "base/logging.h"
[email protected]835d7c82010-10-14 04:38:3817#include "base/metrics/histogram.h"
[email protected]1e127022011-11-29 21:11:4718#include "base/path_service.h"
[email protected]7286e3fc2011-07-19 22:13:2419#include "base/stl_util.h"
[email protected]e83326f2010-07-31 17:29:2520#include "base/string_number_conversions.h"
[email protected]6014d672008-12-05 00:38:2521#include "base/string_util.h"
[email protected]18d4b6c2010-09-21 03:21:0422#include "base/stringprintf.h"
[email protected]7f8f24f2012-11-15 19:40:1423#include "base/threading/sequenced_worker_pool.h"
[email protected]34b99632011-01-01 01:01:0624#include "base/threading/thread_restrictions.h"
[email protected]cc2c3432009-11-06 17:24:3625#include "base/time.h"
[email protected]ce7f62e32010-08-10 23:43:5926#include "base/utf_string_conversions.h"
[email protected]cc655912009-01-29 23:19:1927#include "base/values.h"
[email protected]aa142702010-03-26 01:26:3328#include "base/version.h"
[email protected]a692a952011-11-28 08:23:5429#include "chrome/browser/accessibility/accessibility_extension_api.h"
[email protected]e07f2da2012-08-01 22:46:1230#include "chrome/browser/bookmarks/bookmark_model_factory.h"
[email protected]15730c42009-09-03 00:03:2031#include "chrome/browser/browser_process.h"
[email protected]70019152012-12-19 11:44:1932#include "chrome/browser/devtools/devtools_window.h"
[email protected]32b36c62012-10-24 05:37:4133#include "chrome/browser/extensions/api/app_runtime/app_runtime_api.h"
[email protected]895a1e52012-05-15 02:50:1234#include "chrome/browser/extensions/api/declarative/rules_registry_service.h"
[email protected]c77f2352012-08-08 22:07:5835#include "chrome/browser/extensions/api/extension_action/extension_actions_api.h"
[email protected]c39df1a2013-01-08 18:22:0736#include "chrome/browser/extensions/api/profile_keyed_api_factory.h"
37#include "chrome/browser/extensions/api/push_messaging/push_messaging_api.h"
[email protected]e9f541a2012-11-19 21:52:3138#include "chrome/browser/extensions/api/runtime/runtime_api.h"
[email protected]4636c832013-01-11 02:10:1139#include "chrome/browser/extensions/api/storage/settings_frontend.h"
[email protected]af9db5f2011-10-05 05:13:1540#include "chrome/browser/extensions/app_notification_manager.h"
[email protected]5db9ada2012-04-11 13:48:2041#include "chrome/browser/extensions/app_sync_data.h"
[email protected]5a38dfd2012-07-23 23:22:1042#include "chrome/browser/extensions/browser_event_router.h"
[email protected]d8c8f25f2011-11-02 18:18:0143#include "chrome/browser/extensions/component_loader.h"
[email protected]e0785902011-05-19 23:34:1744#include "chrome/browser/extensions/crx_installer.h"
[email protected]d9ede582012-08-14 19:21:3845#include "chrome/browser/extensions/data_deleter.h"
[email protected]62f051c2012-03-29 17:04:4446#include "chrome/browser/extensions/extension_disabled_ui.h"
[email protected]14a000d2010-04-29 21:44:2447#include "chrome/browser/extensions/extension_error_reporter.h"
[email protected]89226982012-07-16 20:09:1848#include "chrome/browser/extensions/extension_error_ui.h"
[email protected]b1748b1d82009-11-30 20:32:5649#include "chrome/browser/extensions/extension_host.h"
[email protected]00b38242012-07-18 18:43:2250#include "chrome/browser/extensions/extension_install_ui.h"
[email protected]4814b512009-11-07 00:12:2951#include "chrome/browser/extensions/extension_process_manager.h"
[email protected]3569b502012-01-12 20:08:2352#include "chrome/browser/extensions/extension_sorting.h"
[email protected]19eb80152011-02-26 00:28:4353#include "chrome/browser/extensions/extension_special_storage_policy.h"
[email protected]90310d92011-04-17 07:35:0454#include "chrome/browser/extensions/extension_sync_data.h"
[email protected]31d8f5f22012-04-02 15:22:0855#include "chrome/browser/extensions/extension_system.h"
[email protected]8f9d4eb2011-02-05 01:39:1056#include "chrome/browser/extensions/extension_web_ui.h"
[email protected]612a1cb12012-10-17 13:18:0357#include "chrome/browser/extensions/external_install_ui.h"
[email protected]5df038b2012-07-16 19:03:2758#include "chrome/browser/extensions/external_provider_impl.h"
59#include "chrome/browser/extensions/external_provider_interface.h"
[email protected]d8c8f25f2011-11-02 18:18:0160#include "chrome/browser/extensions/installed_loader.h"
[email protected]6cafe35a2012-08-27 22:40:5061#include "chrome/browser/extensions/lazy_background_task_queue.h"
[email protected]fdd679b2012-11-15 20:49:3962#include "chrome/browser/extensions/management_policy.h"
[email protected]b2907fd2011-03-25 16:43:3763#include "chrome/browser/extensions/pending_extension_manager.h"
[email protected]c333e792012-01-06 16:57:3964#include "chrome/browser/extensions/permissions_updater.h"
[email protected]6cafe35a2012-08-27 22:40:5065#include "chrome/browser/extensions/platform_app_launcher.h"
[email protected]6cafe35a2012-08-27 22:40:5066#include "chrome/browser/extensions/shell_window_registry.h"
[email protected]d8c8f25f2011-11-02 18:18:0167#include "chrome/browser/extensions/unpacked_installer.h"
[email protected]42a08162012-03-16 18:09:1168#include "chrome/browser/extensions/updater/extension_updater.h"
[email protected]56ad3792010-05-28 17:45:3369#include "chrome/browser/net/chrome_url_request_context.h"
[email protected]c2295f72013-01-03 22:18:5670#include "chrome/browser/plugins/chrome_plugin_service_filter.h"
[email protected]37858e52010-08-26 00:22:0271#include "chrome/browser/prefs/pref_service.h"
[email protected]8ecad5e2010-12-02 21:18:3372#include "chrome/browser/profiles/profile.h"
[email protected]cf593af2011-12-30 05:44:3973#include "chrome/browser/profiles/profile_manager.h"
[email protected]d5949312012-12-03 22:13:3074#include "chrome/browser/themes/theme_service.h"
75#include "chrome/browser/themes/theme_service_factory.h"
[email protected]c8d407e2011-04-28 21:27:1776#include "chrome/browser/ui/webui/chrome_url_data_manager.h"
77#include "chrome/browser/ui/webui/favicon_source.h"
[email protected]5eddc3e2011-10-26 04:33:3178#include "chrome/browser/ui/webui/ntp/thumbnail_source.h"
[email protected]b07e606e2012-09-15 20:16:1579#include "chrome/browser/ui/webui/theme_source.h"
[email protected]aab98a52009-12-02 03:22:3580#include "chrome/common/child_process_logging.h"
[email protected]432115822011-07-10 15:52:2781#include "chrome/common/chrome_notification_types.h"
[email protected]1e127022011-11-29 21:11:4782#include "chrome/common/chrome_paths.h"
[email protected]e2eb43112009-05-29 21:19:5483#include "chrome/common/chrome_switches.h"
[email protected]15397b42012-05-16 23:56:0684#include "chrome/common/chrome_version_info.h"
[email protected]5b1a0e22009-05-26 19:00:5885#include "chrome/common/extensions/extension.h"
[email protected]7c927b62010-02-24 09:54:1386#include "chrome/common/extensions/extension_file_util.h"
[email protected]895a1e52012-05-15 02:50:1287#include "chrome/common/extensions/extension_manifest_constants.h"
[email protected]77a6970c2011-04-23 16:58:5688#include "chrome/common/extensions/extension_messages.h"
[email protected]a315ba92010-11-16 14:12:2189#include "chrome/common/extensions/extension_resource.h"
[email protected]612a1cb12012-10-17 13:18:0390#include "chrome/common/extensions/feature_switch.h"
[email protected]e9f541a2012-11-19 21:52:3191#include "chrome/common/extensions/features/feature.h"
[email protected]0db124b02012-11-07 04:55:0592#include "chrome/common/extensions/manifest.h"
[email protected]25b34332009-06-05 21:53:1993#include "chrome/common/pref_names.h"
[email protected]a57209872009-05-04 22:53:1494#include "chrome/common/url_constants.h"
[email protected]c38831a12011-10-28 12:44:4995#include "content/public/browser/browser_thread.h"
[email protected]98f66112012-12-25 12:59:3696#include "content/public/browser/devtools_agent_host.h"
[email protected]0e12d7d2011-12-01 16:21:4497#include "content/public/browser/devtools_manager.h"
[email protected]05aad2da2011-10-28 10:12:3798#include "content/public/browser/notification_service.h"
[email protected]0d6e9bd2011-10-18 04:29:1699#include "content/public/browser/notification_types.h"
[email protected]3a5180ae2011-12-21 02:39:38100#include "content/public/browser/plugin_service.h"
[email protected]f3b1a082011-11-18 00:34:30101#include "content/public/browser/render_process_host.h"
[email protected]399583b2012-12-11 09:33:42102#include "content/public/browser/site_instance.h"
103#include "content/public/browser/storage_partition.h"
[email protected]1e127022011-11-29 21:11:47104#include "content/public/common/pepper_plugin_info.h"
[email protected]e9f541a2012-11-19 21:52:31105#include "extensions/common/error_utils.h"
[email protected]c10da4b02010-03-25 14:38:32106#include "googleurl/src/gurl.h"
[email protected]65187152012-06-02 13:14:14107#include "grit/generated_resources.h"
[email protected]be28b5f42012-07-20 11:31:25108#include "net/base/registry_controlled_domains/registry_controlled_domain.h"
[email protected]895a1e52012-05-15 02:50:12109#include "sync/api/sync_change.h"
110#include "sync/api/sync_error_factory.h"
[email protected]24b538a2010-02-27 01:22:44111#include "webkit/database/database_tracker.h"
112#include "webkit/database/database_util.h"
[email protected]79a60642012-10-20 21:03:18113
[email protected]eed367e2011-04-12 03:43:31114#if defined(OS_CHROMEOS)
[email protected]14da67b02011-08-02 05:49:13115#include "chrome/browser/chromeos/cros/cros_library.h"
[email protected]14da67b02011-08-02 05:49:13116#include "chrome/browser/chromeos/input_method/input_method_manager.h"
[email protected]10eb28162012-09-18 03:04:09117#include "content/public/browser/storage_partition.h"
[email protected]b777b332011-04-16 04:01:08118#include "webkit/fileapi/file_system_context.h"
119#include "webkit/fileapi/file_system_mount_point_provider.h"
[email protected]eed367e2011-04-12 03:43:31120#endif
121
[email protected]55eb70e762012-02-20 17:38:39122using content::BrowserContext;
[email protected]631bb742011-11-02 11:29:39123using content::BrowserThread;
[email protected]98f66112012-12-25 12:59:36124using content::DevToolsAgentHost;
[email protected]3a5180ae2011-12-21 02:39:38125using content::PluginService;
[email protected]bf3d9df2012-07-24 23:20:27126using extensions::CrxInstaller;
[email protected]1c321ee52012-05-21 03:02:34127using extensions::Extension;
128using extensions::ExtensionIdSet;
129using extensions::ExtensionInfo;
[email protected]215a7be2012-10-22 19:53:42130using extensions::FeatureSwitch;
[email protected]c2e66e12012-06-27 06:27:06131using extensions::PermissionMessage;
132using extensions::PermissionMessages;
133using extensions::PermissionSet;
[email protected]e410b5f2012-12-14 14:02:24134using extensions::UnloadedExtensionInfo;
[email protected]5ef47ec2010-01-28 05:58:05135
[email protected]c6d474f82009-12-16 21:11:06136namespace errors = extension_manifest_errors;
137
[email protected]b6ab96d2009-08-20 18:58:19138namespace {
139
[email protected]d96eb512012-11-01 23:44:08140// Histogram values for logging events related to externally installed
141// extensions.
142enum ExternalExtensionEvent {
143 EXTERNAL_EXTENSION_INSTALLED = 0,
144 EXTERNAL_EXTENSION_IGNORED,
145 EXTERNAL_EXTENSION_REENABLED,
146 EXTERNAL_EXTENSION_UNINSTALLED,
147 EXTERNAL_EXTENSION_BUCKET_BOUNDARY,
148};
149
[email protected]612a1cb12012-10-17 13:18:03150// Prompt the user this many times before considering an extension acknowledged.
151static const int kMaxExtensionAcknowledgePromptCount = 3;
152
[email protected]0db124b02012-11-07 04:55:05153// Wait this many seconds after an extensions becomes idle before updating it.
154static const int kUpdateIdleDelay = 5;
155
[email protected]9bd9a6862012-11-29 09:24:22156// Wait this many seconds before trying to garbage collect extensions again.
157static const int kGarbageCollectRetryDelay = 30;
158
[email protected]300c0ea2011-07-15 23:04:33159const char* kNaClPluginMimeType = "application/x-nacl";
160
[email protected]3bdba0d2011-08-23 07:17:30161static bool IsSyncableExtension(const Extension& extension) {
162 return extension.GetSyncType() == Extension::SYNC_TYPE_EXTENSION;
163}
164
165static bool IsSyncableApp(const Extension& extension) {
166 return extension.GetSyncType() == Extension::SYNC_TYPE_APP;
167}
168
[email protected]c6d474f82009-12-16 21:11:06169} // namespace
[email protected]b6ab96d2009-08-20 18:58:19170
[email protected]eaa7dd182010-12-14 11:09:00171ExtensionService::ExtensionRuntimeData::ExtensionRuntimeData()
[email protected]d7e9a862010-11-03 21:57:49172 : background_page_ready(false),
[email protected]f8bf5992011-10-24 22:38:57173 being_upgraded(false),
174 has_used_webrequest(false) {
[email protected]d7e9a862010-11-03 21:57:49175}
176
[email protected]eaa7dd182010-12-14 11:09:00177ExtensionService::ExtensionRuntimeData::~ExtensionRuntimeData() {
[email protected]d7e9a862010-11-03 21:57:49178}
179
[email protected]cebc3dc2011-04-18 17:15:00180ExtensionService::NaClModuleInfo::NaClModuleInfo() {
181}
182
183ExtensionService::NaClModuleInfo::~NaClModuleInfo() {
184}
185
[email protected]eaa7dd182010-12-14 11:09:00186// ExtensionService.
[email protected]6014d672008-12-05 00:38:25187
[email protected]31bb5ee62012-09-12 22:58:40188const char ExtensionService::kInstallDirectoryName[] = "Extensions";
[email protected]15d5b472011-11-24 04:17:24189
[email protected]31bb5ee62012-09-12 22:58:40190const char ExtensionService::kLocalAppSettingsDirectoryName[] =
[email protected]15d5b472011-11-24 04:17:24191 "Local App Settings";
[email protected]31bb5ee62012-09-12 22:58:40192const char ExtensionService::kLocalExtensionSettingsDirectoryName[] =
[email protected]15d5b472011-11-24 04:17:24193 "Local Extension Settings";
[email protected]31bb5ee62012-09-12 22:58:40194const char ExtensionService::kSyncAppSettingsDirectoryName[] =
[email protected]15d5b472011-11-24 04:17:24195 "Sync App Settings";
[email protected]31bb5ee62012-09-12 22:58:40196const char ExtensionService::kSyncExtensionSettingsDirectoryName[] =
[email protected]15d5b472011-11-24 04:17:24197 "Sync Extension Settings";
[email protected]675bb01012012-12-14 22:03:29198const char ExtensionService::kManagedSettingsDirectoryName[] =
199 "Managed Extension Settings";
[email protected]31bb5ee62012-09-12 22:58:40200const char ExtensionService::kStateStoreName[] = "Extension State";
[email protected]a690e292012-12-19 19:22:49201const char ExtensionService::kRulesStoreName[] = "Extension Rules";
[email protected]494c06e2009-07-25 01:06:42202
[email protected]8e4560b62011-01-14 10:09:14203void ExtensionService::CheckExternalUninstall(const std::string& id) {
[email protected]a29a517a2011-01-21 21:11:12204 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]a8af9fdb2010-10-28 21:52:20205
[email protected]7a4c6852010-09-16 03:44:22206 // Check if the providers know about this extension.
[email protected]5df038b2012-07-16 19:03:27207 extensions::ProviderCollection::const_iterator i;
[email protected]0a60a2e2010-10-25 16:15:21208 for (i = external_extension_providers_.begin();
209 i != external_extension_providers_.end(); ++i) {
[email protected]8e4560b62011-01-14 10:09:14210 DCHECK(i->get()->IsReady());
[email protected]0a60a2e2010-10-25 16:15:21211 if (i->get()->HasExtension(id))
212 return; // Yup, known extension, don't uninstall.
[email protected]7a4c6852010-09-16 03:44:22213 }
214
[email protected]0f48fca2011-05-19 18:46:35215 // We get the list of external extensions to check from preferences.
216 // It is possible that an extension has preferences but is not loaded.
217 // For example, an extension that requires experimental permissions
218 // will not be loaded if the experimental command line flag is not used.
219 // In this case, do not uninstall.
[email protected]31bb5ee62012-09-12 22:58:40220 if (!GetInstalledExtension(id)) {
[email protected]0f48fca2011-05-19 18:46:35221 // We can't call UninstallExtension with an unloaded/invalid
222 // extension ID.
223 LOG(WARNING) << "Attempted uninstallation of unloaded/invalid extension "
224 << "with id: " << id;
225 return;
226 }
[email protected]d6ebc9792011-04-07 18:18:33227 UninstallExtension(id, true, NULL);
[email protected]7a4c6852010-09-16 03:44:22228}
229
[email protected]7f8f24f2012-11-15 19:40:14230void ExtensionService::SetFileTaskRunnerForTesting(
231 base::SequencedTaskRunner* task_runner) {
232 file_task_runner_ = task_runner;
233}
234
[email protected]8e4560b62011-01-14 10:09:14235void ExtensionService::ClearProvidersForTesting() {
[email protected]7a4c6852010-09-16 03:44:22236 external_extension_providers_.clear();
237}
238
[email protected]8e4560b62011-01-14 10:09:14239void ExtensionService::AddProviderForTesting(
[email protected]5df038b2012-07-16 19:03:27240 extensions::ExternalProviderInterface* test_provider) {
[email protected]a29a517a2011-01-21 21:11:12241 CHECK(test_provider);
[email protected]0a60a2e2010-10-25 16:15:21242 external_extension_providers_.push_back(
[email protected]5df038b2012-07-16 19:03:27243 linked_ptr<extensions::ExternalProviderInterface>(test_provider));
[email protected]7a4c6852010-09-16 03:44:22244}
245
[email protected]9060d8b02012-01-13 02:14:30246bool ExtensionService::OnExternalExtensionUpdateUrlFound(
[email protected]7a4c6852010-09-16 03:44:22247 const std::string& id,
[email protected]21a5a672010-11-04 10:47:42248 const GURL& update_url,
249 Extension::Location location) {
[email protected]ab22ba42011-01-14 16:36:38250 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
251 CHECK(Extension::IdIsValid(id));
[email protected]a8af9fdb2010-10-28 21:52:20252
[email protected]8a87a5332011-08-11 17:54:59253 const Extension* extension = GetExtensionById(id, true);
254 if (extension) {
255 // Already installed. Skip this install if the current location has
256 // higher priority than |location|.
257 Extension::Location current = extension->location();
258 if (current == Extension::GetHigherPriorityLocation(current, location))
[email protected]9060d8b02012-01-13 02:14:30259 return false;
[email protected]8a87a5332011-08-11 17:54:59260 // Otherwise, overwrite the current installation.
[email protected]7a4c6852010-09-16 03:44:22261 }
[email protected]9060d8b02012-01-13 02:14:30262
263 // Add |id| to the set of pending extensions. If it can not be added,
264 // then there is already a pending record from a higher-priority install
265 // source. In this case, signal that this extension will not be
266 // installed by returning false.
267 if (!pending_extension_manager()->AddFromExternalUpdateUrl(
[email protected]31bb5ee62012-09-12 22:58:40268 id, update_url, location)) {
[email protected]9060d8b02012-01-13 02:14:30269 return false;
[email protected]31bb5ee62012-09-12 22:58:40270 }
[email protected]9060d8b02012-01-13 02:14:30271
[email protected]94fde232012-04-27 10:22:30272 update_once_all_providers_are_ready_ = true;
[email protected]9060d8b02012-01-13 02:14:30273 return true;
[email protected]7a4c6852010-09-16 03:44:22274}
275
[email protected]dc9a74f72012-08-17 18:07:21276const Extension* ExtensionService::GetInstalledApp(const GURL& url) const {
[email protected]615d88f2011-12-13 01:47:44277 const Extension* extension = extensions_.GetExtensionOrAppByURL(
278 ExtensionURLInfo(url));
[email protected]dc9a74f72012-08-17 18:07:21279 return (extension && extension->is_app()) ? extension : NULL;
[email protected]d9696672011-03-15 22:45:09280}
281
[email protected]dc9a74f72012-08-17 18:07:21282bool ExtensionService::IsInstalledApp(const GURL& url) const {
[email protected]d9696672011-03-15 22:45:09283 return !!GetInstalledApp(url);
[email protected]ffb204f22010-12-05 23:20:27284}
285
[email protected]404fb002012-10-02 21:06:17286const Extension* ExtensionService::GetIsolatedAppForRenderer(
[email protected]dc9a74f72012-08-17 18:07:21287 int renderer_child_id) const {
[email protected]404fb002012-10-02 21:06:17288 std::set<std::string> extension_ids =
289 process_map_.GetExtensionsInProcess(renderer_child_id);
290 // All apps in one process share the same partition.
291 // It is only possible for the app to have isolated storage
292 // if there is only 1 app in the process.
293 if (extension_ids.size() != 1)
294 return NULL;
295
296 const extensions::Extension* extension =
297 extensions_.GetByID(*(extension_ids.begin()));
298 // We still need to check is_storage_isolated(),
299 // because it's common for there to be one extension in a process
300 // with is_storage_isolated() == false.
301 if (extension && extension->is_storage_isolated())
302 return extension;
303
304 return NULL;
[email protected]da5683db2011-04-23 17:12:21305}
306
[email protected]6aeac8342010-10-01 20:21:18307// static
[email protected]d6ebc9792011-04-07 18:18:33308// This function is used to implement the command-line switch
[email protected]3bdba0d2011-08-23 07:17:30309// --uninstall-extension, and to uninstall an extension via sync. The LOG
310// statements within this function are used to inform the user if the uninstall
311// cannot be done.
[email protected]eaa7dd182010-12-14 11:09:00312bool ExtensionService::UninstallExtensionHelper(
313 ExtensionService* extensions_service,
[email protected]6aeac8342010-10-01 20:21:18314 const std::string& extension_id) {
[email protected]d6ebc9792011-04-07 18:18:33315 // We can't call UninstallExtension with an invalid extension ID.
[email protected]31bb5ee62012-09-12 22:58:40316 if (!extensions_service->GetInstalledExtension(extension_id)) {
[email protected]6aeac8342010-10-01 20:21:18317 LOG(WARNING) << "Attempted uninstallation of non-existent extension with "
[email protected]95da88c42011-03-31 10:07:33318 << "id: " << extension_id;
319 return false;
[email protected]6aeac8342010-10-01 20:21:18320 }
321
[email protected]d6ebc9792011-04-07 18:18:33322 // The following call to UninstallExtension will not allow an uninstall of a
323 // policy-controlled extension.
[email protected]65187152012-06-02 13:14:14324 string16 error;
[email protected]d6ebc9792011-04-07 18:18:33325 if (!extensions_service->UninstallExtension(extension_id, false, &error)) {
326 LOG(WARNING) << "Cannot uninstall extension with id " << extension_id
327 << ": " << error;
328 return false;
329 }
[email protected]95da88c42011-03-31 10:07:33330
[email protected]6aeac8342010-10-01 20:21:18331 return true;
332}
333
[email protected]eaa7dd182010-12-14 11:09:00334ExtensionService::ExtensionService(Profile* profile,
[email protected]f0841cd2011-01-19 15:07:24335 const CommandLine* command_line,
336 const FilePath& install_directory,
[email protected]45759612012-07-10 17:21:23337 extensions::ExtensionPrefs* extension_prefs,
[email protected]fdd679b2012-11-15 20:49:39338 extensions::Blacklist* blacklist,
[email protected]0436b102011-04-15 18:30:03339 bool autoupdate_enabled,
340 bool extensions_enabled)
[email protected]fdd679b2012-11-15 20:49:39341 : extensions::Blacklist::Observer(blacklist),
342 profile_(profile),
[email protected]bd306722012-07-11 20:43:59343 system_(extensions::ExtensionSystem::Get(profile)),
[email protected]73c47932010-12-06 18:13:43344 extension_prefs_(extension_prefs),
[email protected]695b5712012-12-06 23:55:28345 blacklist_(blacklist),
[email protected]cccdf0aa2011-11-11 03:43:38346 settings_frontend_(extensions::SettingsFrontend::Create(profile)),
[email protected]14908b72011-04-20 06:54:36347 pending_extension_manager_(*ALLOW_THIS_IN_INITIALIZER_LIST(this)),
[email protected]a9b00ac2009-06-25 21:03:23348 install_directory_(install_directory),
[email protected]0436b102011-04-15 18:30:03349 extensions_enabled_(extensions_enabled),
[email protected]e81dba32009-06-19 20:19:13350 show_extensions_prompts_(true),
[email protected]fc332ae2012-11-14 20:17:33351 install_updates_when_idle_(true),
[email protected]3ecda252010-11-18 19:50:55352 ready_(false),
[email protected]14908b72011-04-20 06:54:36353 toolbar_model_(ALLOW_THIS_IN_INITIALIZER_LIST(this)),
[email protected]8b280302011-10-13 22:22:23354 menu_manager_(profile),
[email protected]8d92e0382012-08-01 18:06:52355 app_notification_manager_(
356 new extensions::AppNotificationManager(profile)),
[email protected]7c1490da2011-10-11 18:53:25357 event_routers_initialized_(false),
[email protected]dff1e042012-04-27 10:59:18358 update_once_all_providers_are_ready_(false),
[email protected]3c4abc82012-10-22 22:25:54359 browser_terminating_(false),
[email protected]399583b2012-12-11 09:33:42360 installs_delayed_(false),
[email protected]1ff4d282012-12-08 00:39:21361 wipeout_is_active_(false),
[email protected]5db9ada2012-04-11 13:48:20362 app_sync_bundle_(ALLOW_THIS_IN_INITIALIZER_LIST(this)),
363 extension_sync_bundle_(ALLOW_THIS_IN_INITIALIZER_LIST(this)),
[email protected]178f8512012-02-09 01:49:36364 app_shortcut_manager_(profile) {
[email protected]a29a517a2011-01-21 21:11:12365 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]a8af9fdb2010-10-28 21:52:20366
[email protected]36a784c2009-06-23 06:21:08367 // Figure out if extension installation should be enabled.
[email protected]31bb5ee62012-09-12 22:58:40368 if (command_line->HasSwitch(switches::kDisableExtensions) ||
369 profile->GetPrefs()->GetBoolean(prefs::kDisableExtensions)) {
[email protected]6d60703b2009-08-29 01:29:23370 extensions_enabled_ = false;
[email protected]6b75ec32009-08-14 06:37:18371 }
[email protected]36a784c2009-06-23 06:21:08372
[email protected]3c4abc82012-10-22 22:25:54373 registrar_.Add(this, chrome::NOTIFICATION_APP_TERMINATING,
374 content::NotificationService::AllBrowserContextsAndSources());
[email protected]432115822011-07-10 15:52:27375 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_PROCESS_TERMINATED,
[email protected]ad50def52011-10-19 23:17:07376 content::NotificationService::AllBrowserContextsAndSources());
[email protected]432115822011-07-10 15:52:27377 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_CREATED,
[email protected]ad50def52011-10-19 23:17:07378 content::NotificationService::AllBrowserContextsAndSources());
[email protected]432115822011-07-10 15:52:27379 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_TERMINATED,
[email protected]ad50def52011-10-19 23:17:07380 content::NotificationService::AllBrowserContextsAndSources());
[email protected]0db124b02012-11-07 04:55:05381 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED,
382 content::NotificationService::AllBrowserContextsAndSources());
[email protected]2fb7dc982010-09-29 12:24:28383 pref_change_registrar_.Init(profile->GetPrefs());
[email protected]90bb38d2012-11-14 18:36:03384 base::Closure callback =
385 base::Bind(&ExtensionService::OnExtensionInstallPrefChanged,
386 base::Unretained(this));
387 pref_change_registrar_.Add(prefs::kExtensionInstallAllowList, callback);
388 pref_change_registrar_.Add(prefs::kExtensionInstallDenyList, callback);
[email protected]e410b5f2012-12-14 14:02:24389 pref_change_registrar_.Add(prefs::kExtensionAllowedTypes, callback);
[email protected]4814b512009-11-07 00:12:29390
[email protected]93fd78f42009-07-10 16:43:17391 // Set up the ExtensionUpdater
392 if (autoupdate_enabled) {
393 int update_frequency = kDefaultUpdateFrequencySeconds;
394 if (command_line->HasSwitch(switches::kExtensionsUpdateFrequency)) {
[email protected]e83326f2010-07-31 17:29:25395 base::StringToInt(command_line->GetSwitchValueASCII(
396 switches::kExtensionsUpdateFrequency),
397 &update_frequency);
[email protected]93fd78f42009-07-10 16:43:17398 }
[email protected]42a08162012-03-16 18:09:11399 updater_.reset(new extensions::ExtensionUpdater(this,
400 extension_prefs,
401 profile->GetPrefs(),
402 profile,
[email protected]fdd679b2012-11-15 20:49:39403 blacklist,
[email protected]42a08162012-03-16 18:09:11404 update_frequency));
[email protected]93fd78f42009-07-10 16:43:17405 }
406
[email protected]25ae0152011-11-18 14:40:02407 component_loader_.reset(
408 new extensions::ComponentLoader(this,
409 profile->GetPrefs(),
410 g_browser_process->local_state()));
[email protected]8e4560b62011-01-14 10:09:14411
[email protected]af9db5f2011-10-05 05:13:15412 app_notification_manager_->Init();
413
[email protected]0436b102011-04-15 18:30:03414 if (extensions_enabled_) {
[email protected]ae4c37e2012-12-21 01:16:25415 CHECK(!ProfileManager::IsImportProcess(*command_line));
416 extensions::ExternalProviderImpl::CreateExternalProviders(
417 this, profile_, &external_extension_providers_);
[email protected]873531342011-03-09 12:16:05418 }
[email protected]b671760b2010-07-15 21:13:47419
[email protected]fb82dcd2012-03-21 14:15:46420 // Set this as the ExtensionService for extension sorting to ensure it
421 // cause syncs if required.
422 extension_prefs_->extension_sorting()->SetExtensionService(this);
423
[email protected]9ce11d22012-08-08 23:20:13424#if defined(ENABLE_EXTENSIONS)
[email protected]c77f2352012-08-08 22:07:58425 extension_action_storage_manager_.reset(
426 new extensions::ExtensionActionStorageManager(profile_));
[email protected]9ce11d22012-08-08 23:20:13427#endif
[email protected]c77f2352012-08-08 22:07:58428
[email protected]1ff4d282012-12-08 00:39:21429 // Before loading any extensions, determine whether Sideload Wipeout is on.
430 wipeout_is_active_ = FeatureSwitch::sideload_wipeout()->IsEnabled() &&
431 !extension_prefs_->GetSideloadWipeoutDone();
432
[email protected]cb0e50312011-05-09 15:03:07433 // How long is the path to the Extensions directory?
434 UMA_HISTOGRAM_CUSTOM_COUNTS("Extensions.ExtensionRootPathLength",
435 install_directory_.value().length(), 0, 500, 100);
[email protected]6014d672008-12-05 00:38:25436}
437
[email protected]84df8332011-12-06 18:22:46438const ExtensionSet* ExtensionService::extensions() const {
[email protected]ddb1e5a2010-12-13 20:10:45439 return &extensions_;
440}
441
[email protected]84df8332011-12-06 18:22:46442const ExtensionSet* ExtensionService::disabled_extensions() const {
[email protected]ddb1e5a2010-12-13 20:10:45443 return &disabled_extensions_;
444}
445
[email protected]84df8332011-12-06 18:22:46446const ExtensionSet* ExtensionService::terminated_extensions() const {
[email protected]bb7f40952011-01-13 00:21:20447 return &terminated_extensions_;
448}
449
[email protected]695b5712012-12-06 23:55:28450const ExtensionSet* ExtensionService::blacklisted_extensions() const {
451 return &blacklisted_extensions_;
452}
453
454scoped_ptr<const ExtensionSet>
455 ExtensionService::GenerateInstalledExtensionsSet() const {
456 scoped_ptr<ExtensionSet> installed_extensions(new ExtensionSet());
[email protected]7f4308d2012-01-18 07:43:01457 installed_extensions->InsertAll(extensions_);
458 installed_extensions->InsertAll(disabled_extensions_);
459 installed_extensions->InsertAll(terminated_extensions_);
[email protected]695b5712012-12-06 23:55:28460 installed_extensions->InsertAll(blacklisted_extensions_);
461 return installed_extensions.PassAs<const ExtensionSet>();
[email protected]7f4308d2012-01-18 07:43:01462}
463
[email protected]695b5712012-12-06 23:55:28464scoped_ptr<const ExtensionSet> ExtensionService::GetWipedOutExtensions() const {
465 scoped_ptr<ExtensionSet> extension_set(new ExtensionSet());
[email protected]215a7be2012-10-22 19:53:42466 for (ExtensionSet::const_iterator iter = disabled_extensions_.begin();
467 iter != disabled_extensions_.end(); ++iter) {
468 int disabled_reason = extension_prefs_->GetDisableReasons((*iter)->id());
469 if ((disabled_reason & Extension::DISABLE_SIDELOAD_WIPEOUT) != 0)
470 extension_set->Insert(*iter);
471 }
[email protected]695b5712012-12-06 23:55:28472 return extension_set.PassAs<const ExtensionSet>();
[email protected]215a7be2012-10-22 19:53:42473}
474
[email protected]3f213ad2012-07-26 23:39:41475extensions::PendingExtensionManager*
476 ExtensionService::pending_extension_manager() {
[email protected]b2907fd2011-03-25 16:43:37477 return &pending_extension_manager_;
[email protected]ddb1e5a2010-12-13 20:10:45478}
479
[email protected]eaa7dd182010-12-14 11:09:00480ExtensionService::~ExtensionService() {
[email protected]c8d407e2011-04-28 21:27:17481 // No need to unload extensions here because they are profile-scoped, and the
482 // profile is in the process of being deleted.
[email protected]94b4ffc2011-02-04 05:55:17483
[email protected]5df038b2012-07-16 19:03:27484 extensions::ProviderCollection::const_iterator i;
[email protected]8e4560b62011-01-14 10:09:14485 for (i = external_extension_providers_.begin();
486 i != external_extension_providers_.end(); ++i) {
[email protected]5df038b2012-07-16 19:03:27487 extensions::ExternalProviderInterface* provider = i->get();
[email protected]8e4560b62011-01-14 10:09:14488 provider->ServiceShutdown();
489 }
[email protected]6014d672008-12-05 00:38:25490}
491
[email protected]d91268022011-08-26 13:17:37492void ExtensionService::InitEventRoutersAfterImport() {
[email protected]cf593af2011-12-30 05:44:39493 RegisterForImportFinished();
494}
495
496void ExtensionService::RegisterForImportFinished() {
497 if (!registrar_.IsRegistered(this, chrome::NOTIFICATION_IMPORT_FINISHED,
498 content::Source<Profile>(profile_))) {
499 registrar_.Add(this, chrome::NOTIFICATION_IMPORT_FINISHED,
500 content::Source<Profile>(profile_));
501 }
502}
503
504void ExtensionService::InitAfterImport() {
[email protected]eac88332012-12-26 17:57:45505 component_loader_->LoadAll();
[email protected]ae4c37e2012-12-21 01:16:25506
[email protected]cf593af2011-12-30 05:44:39507 CheckForExternalUpdates();
508
509 GarbageCollectExtensions();
510
511 // Idempotent, so although there is a possible race if the import
512 // process finished sometime in the middle of ProfileImpl::InitExtensions,
513 // it cannot happen twice.
514 InitEventRouters();
[email protected]d91268022011-08-26 13:17:37515}
516
[email protected]eaa7dd182010-12-14 11:09:00517void ExtensionService::InitEventRouters() {
[email protected]b3d62312b12010-10-14 21:10:18518 if (event_routers_initialized_)
519 return;
520
[email protected]6a3cd37e2012-04-17 17:13:34521#if defined(ENABLE_EXTENSIONS)
[email protected]5a38dfd2012-07-23 23:22:10522 browser_event_router_.reset(new extensions::BrowserEventRouter(profile_));
[email protected]27072cad2011-05-09 19:46:40523
[email protected]c39df1a2013-01-08 18:22:07524 extensions::ProfileKeyedAPIFactory<extensions::PushMessagingAPI>::
525 GetForProfile(profile_);
[email protected]6a3cd37e2012-04-17 17:13:34526#endif // defined(ENABLE_EXTENSIONS)
[email protected]b3d62312b12010-10-14 21:10:18527 event_routers_initialized_ = true;
[email protected]c5ae74ab2010-04-15 18:14:37528}
529
[email protected]037228a2012-10-05 01:36:16530void ExtensionService::Shutdown() {
531 // Do nothing for now.
532}
533
[email protected]b2907fd2011-03-25 16:43:37534const Extension* ExtensionService::GetExtensionById(
535 const std::string& id, bool include_disabled) const {
[email protected]81f0d162012-08-15 04:21:47536 int include_mask = INCLUDE_ENABLED;
[email protected]695b5712012-12-06 23:55:28537 if (include_disabled) {
538 // Include blacklisted extensions here because there are hundreds of
539 // callers of this function, and many might assume that this includes those
540 // that have been disabled due to blacklisting.
541 include_mask |= INCLUDE_DISABLED | INCLUDE_BLACKLISTED;
542 }
543 return GetExtensionById(id, include_mask);
544}
545
[email protected]399583b2012-12-11 09:33:42546GURL ExtensionService::GetSiteForExtensionId(const std::string& extension_id) {
547 return content::SiteInstance::GetSiteForURL(
548 profile_,
549 Extension::GetBaseURLFromExtensionId(extension_id));
550}
551
[email protected]695b5712012-12-06 23:55:28552const Extension* ExtensionService::GetExtensionById(
553 const std::string& id, int include_mask) const {
554 std::string lowercase_id = StringToLowerASCII(id);
555 if (include_mask & INCLUDE_ENABLED) {
556 const Extension* extension = extensions_.GetByID(lowercase_id);
557 if (extension)
558 return extension;
559 }
560 if (include_mask & INCLUDE_DISABLED) {
561 const Extension* extension = disabled_extensions_.GetByID(lowercase_id);
562 if (extension)
563 return extension;
564 }
565 if (include_mask & INCLUDE_TERMINATED) {
566 const Extension* extension = terminated_extensions_.GetByID(lowercase_id);
567 if (extension)
568 return extension;
569 }
570 if (include_mask & INCLUDE_BLACKLISTED) {
571 const Extension* extension = blacklisted_extensions_.GetByID(lowercase_id);
572 if (extension)
573 return extension;
574 }
575 return NULL;
[email protected]78994ab02010-12-08 18:06:44576}
577
[email protected]eaa7dd182010-12-14 11:09:00578void ExtensionService::Init() {
[email protected]a29a517a2011-01-21 21:11:12579 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]a8af9fdb2010-10-28 21:52:20580
[email protected]fa6a9102010-11-22 15:38:50581 DCHECK(!ready_); // Can't redo init.
[email protected]93fd78f42009-07-10 16:43:17582 DCHECK_EQ(extensions_.size(), 0u);
[email protected]9f1087e2009-06-15 17:29:32583
[email protected]ae4c37e2012-12-21 01:16:25584 CHECK(!ProfileManager::IsImportProcess(*CommandLine::ForCurrentProcess()));
585
[email protected]399583b2012-12-11 09:33:42586 // TODO(mek): It might be cleaner to do the FinishDelayedInstallInfo stuff
587 // here instead of in installedloader.
[email protected]ae4c37e2012-12-21 01:16:25588 if (g_browser_process->profile_manager() &&
589 g_browser_process->profile_manager()->will_import()) {
[email protected]eac88332012-12-26 17:57:45590 // Do not load any component extensions, since they may conflict with the
591 // import process.
[email protected]ae4c37e2012-12-21 01:16:25592
[email protected]ae4c37e2012-12-21 01:16:25593 extensions::InstalledLoader(this).LoadAllExtensions();
594 RegisterForImportFinished();
595 } else {
[email protected]eac88332012-12-26 17:57:45596 component_loader_->LoadAll();
[email protected]ae4c37e2012-12-21 01:16:25597 extensions::InstalledLoader(this).LoadAllExtensions();
598
599 // TODO(erikkay) this should probably be deferred to a future point
600 // rather than running immediately at startup.
601 CheckForExternalUpdates();
602
603 // TODO(erikkay) this should probably be deferred as well.
604 GarbageCollectExtensions();
605 }
[email protected]894bb502009-05-21 22:39:57606
[email protected]215a7be2012-10-22 19:53:42607 // The Sideload Wipeout effort takes place during load (see above), so once
608 // that is done the flag can be set so that we don't have to check again.
[email protected]1ff4d282012-12-08 00:39:21609 if (wipeout_is_active_) {
[email protected]215a7be2012-10-22 19:53:42610 extension_prefs_->SetSideloadWipeoutDone();
[email protected]1ff4d282012-12-08 00:39:21611 wipeout_is_active_ = false; // Wipeout is only on during load.
612 }
[email protected]215a7be2012-10-22 19:53:42613
[email protected]399583b2012-12-11 09:33:42614 if (extension_prefs_->NeedsStorageGarbageCollection()) {
615 GarbageCollectIsolatedStorage();
616 extension_prefs_->SetNeedsStorageGarbageCollection(false);
617 }
[email protected]6014d672008-12-05 00:38:25618}
619
[email protected]31bb5ee62012-09-12 22:58:40620bool ExtensionService::UpdateExtension(const std::string& id,
621 const FilePath& extension_path,
622 const GURL& download_url,
623 CrxInstaller** out_crx_installer) {
[email protected]a29a517a2011-01-21 21:11:12624 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]3c4abc82012-10-22 22:25:54625 if (browser_terminating_) {
626 LOG(WARNING) << "Skipping UpdateExtension due to browser shutdown";
627 // Leak the temp file at extension_path. We don't want to add to the disk
628 // I/O burden at shutdown, we can't rely on the I/O completing anyway, and
629 // the file is in the OS temp directory which should be cleaned up for us.
630 return false;
631 }
[email protected]a8af9fdb2010-10-28 21:52:20632
[email protected]3f213ad2012-07-26 23:39:41633 const extensions::PendingExtensionInfo* pending_extension_info =
[email protected]51a3bf8b2012-06-08 22:53:06634 pending_extension_manager()->GetById(id);
[email protected]8ef78fd2010-08-19 17:14:32635
[email protected]695b5712012-12-06 23:55:28636 const Extension* extension = GetInstalledExtension(id);
[email protected]51a3bf8b2012-06-08 22:53:06637 if (!pending_extension_info && !extension) {
[email protected]aa142702010-03-26 01:26:33638 LOG(WARNING) << "Will not update extension " << id
639 << " because it is not installed or pending";
640 // Delete extension_path since we're not creating a CrxInstaller
641 // that would do it for us.
[email protected]7f8f24f2012-11-15 19:40:14642 if (!GetFileTaskRunner()->PostTask(
643 FROM_HERE,
[email protected]53612e82011-10-18 18:00:36644 base::Bind(
[email protected]7296f2762011-11-21 19:23:44645 &extension_file_util::DeleteFile, extension_path, false)))
[email protected]14908b72011-04-20 06:54:36646 NOTREACHED();
[email protected]420a0ec2011-06-01 01:07:03647
648 return false;
[email protected]e957fe52009-06-23 16:51:05649 }
650
[email protected]aa142702010-03-26 01:26:33651 // We want a silent install only for non-pending extensions and
652 // pending extensions that have install_silently set.
[email protected]91e51d612012-10-21 23:03:05653 ExtensionInstallPrompt* client = NULL;
654 if (pending_extension_info && !pending_extension_info->install_silently())
655 client = ExtensionInstallUI::CreateInstallPromptWithProfile(profile_);
[email protected]aa142702010-03-26 01:26:33656
[email protected]d8c8f25f2011-11-02 18:18:01657 scoped_refptr<CrxInstaller> installer(CrxInstaller::Create(this, client));
[email protected]6dfbbf82010-03-12 23:09:16658 installer->set_expected_id(id);
[email protected]51a3bf8b2012-06-08 22:53:06659 if (pending_extension_info) {
660 installer->set_install_source(pending_extension_info->install_source());
661 if (pending_extension_info->install_silently())
662 installer->set_allow_silent_install(true);
663 } else if (extension) {
[email protected]5eb375e92010-11-26 07:50:41664 installer->set_install_source(extension->location());
[email protected]51a3bf8b2012-06-08 22:53:06665 }
[email protected]7d8b7072012-04-07 01:07:46666 // If the extension was installed from or has migrated to the webstore, or
[email protected]fcb2c2c2012-10-17 21:08:45667 // its auto-update URL is from the webstore, treat it as a webstore install.
668 // Note that we ignore some older extensions with blank auto-update URLs
669 // because we are mostly concerned with restrictions on NaCl extensions,
670 // which are newer.
[email protected]a12ce8b22012-01-17 18:40:53671 int creation_flags = Extension::NO_FLAGS;
[email protected]75764512011-12-19 19:54:28672 if ((extension && extension->from_webstore()) ||
[email protected]7d8b7072012-04-07 01:07:46673 (extension && extension->UpdatesFromGallery()) ||
[email protected]963d13c2012-09-29 17:13:35674 (!extension && extension_urls::IsWebstoreUpdateUrl(
[email protected]51a3bf8b2012-06-08 22:53:06675 pending_extension_info->update_url()))) {
[email protected]a12ce8b22012-01-17 18:40:53676 creation_flags |= Extension::FROM_WEBSTORE;
677 }
678
679 // Bookmark apps being updated is kind of a contradiction, but that's because
680 // we mark the default apps as bookmark apps, and they're hosted in the web
681 // store, thus they can get updated. See http://crbug.com/101605 for more
682 // details.
683 if (extension && extension->from_bookmark())
684 creation_flags |= Extension::FROM_BOOKMARK;
685
[email protected]e33bbc22012-08-27 22:05:46686 if (extension && extension->was_installed_by_default())
687 creation_flags |= Extension::WAS_INSTALLED_BY_DEFAULT;
688
[email protected]a12ce8b22012-01-17 18:40:53689 installer->set_creation_flags(creation_flags);
690
[email protected]6dfbbf82010-03-12 23:09:16691 installer->set_delete_source(true);
[email protected]655b2b1a2011-10-13 17:13:06692 installer->set_download_url(download_url);
[email protected]cb0e50312011-05-09 15:03:07693 installer->set_install_cause(extension_misc::INSTALL_CAUSE_UPDATE);
[email protected]6dfbbf82010-03-12 23:09:16694 installer->InstallCrx(extension_path);
[email protected]420a0ec2011-06-01 01:07:03695
696 if (out_crx_installer)
697 *out_crx_installer = installer;
698
699 return true;
[email protected]e957fe52009-06-23 16:51:05700}
701
[email protected]eaa7dd182010-12-14 11:09:00702void ExtensionService::ReloadExtension(const std::string& extension_id) {
[email protected]32b36c62012-10-24 05:37:41703 int events = HasShellWindows(extension_id) ? EVENT_LAUNCHED : EVENT_NONE;
704 ReloadExtensionWithEvents(extension_id, events);
705}
706
707void ExtensionService::RestartExtension(const std::string& extension_id) {
[email protected]2380c6b2013-01-09 02:33:13708 ReloadExtensionWithEvents(extension_id, EVENT_RESTARTED);
[email protected]32b36c62012-10-24 05:37:41709}
710
711void ExtensionService::ReloadExtensionWithEvents(
712 const std::string& extension_id,
713 int events) {
[email protected]a29a517a2011-01-21 21:11:12714 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]b65272f2009-08-31 15:47:06715 FilePath path;
[email protected]9adb9692010-10-29 23:14:02716 const Extension* current_extension = GetExtensionById(extension_id, false);
[email protected]9cddd4702009-07-27 22:09:40717
[email protected]f17dbd42010-08-16 23:21:10718 // Disable the extension if it's loaded. It might not be loaded if it crashed.
[email protected]b65272f2009-08-31 15:47:06719 if (current_extension) {
[email protected]4814b512009-11-07 00:12:29720 // If the extension has an inspector open for its background page, detach
721 // the inspector and hang onto a cookie for it, so that we can reattach
722 // later.
[email protected]31d8f5f22012-04-02 15:22:08723 // TODO(yoz): this is not incognito-safe!
724 ExtensionProcessManager* manager = system_->process_manager();
[email protected]3a1dc572012-07-31 22:25:13725 extensions::ExtensionHost* host =
726 manager->GetBackgroundHostForExtension(extension_id);
[email protected]98f66112012-12-25 12:59:36727 if (host && DevToolsAgentHost::HasFor(host->render_view_host())) {
[email protected]4814b512009-11-07 00:12:29728 // Look for an open inspector for the background page.
[email protected]98f66112012-12-25 12:59:36729 int devtools_cookie = DevToolsAgentHost::DisconnectRenderViewHost(
[email protected]562e20c2012-12-24 18:27:20730 host->render_view_host());
[email protected]4814b512009-11-07 00:12:29731 if (devtools_cookie >= 0)
732 orphaned_dev_tools_[extension_id] = devtools_cookie;
733 }
734
[email protected]32b36c62012-10-24 05:37:41735 on_load_events_[extension_id] = events;
[email protected]6cafe35a2012-08-27 22:40:50736
[email protected]b65272f2009-08-31 15:47:06737 path = current_extension->path();
[email protected]44d62b62012-04-11 00:06:03738 DisableExtension(extension_id, Extension::DISABLE_RELOAD);
[email protected]f17dbd42010-08-16 23:21:10739 disabled_extension_paths_[extension_id] = path;
[email protected]1eb175082010-02-10 09:26:16740 } else {
741 path = unloaded_extension_paths_[extension_id];
[email protected]b65272f2009-08-31 15:47:06742 }
743
[email protected]399583b2012-12-11 09:33:42744 if (delayed_updates_for_idle_.Contains(extension_id)) {
[email protected]6f6101832012-11-27 22:10:48745 FinishDelayedInstallation(extension_id);
[email protected]0db124b02012-11-07 04:55:05746 return;
747 }
748
[email protected]43ceb002012-02-10 23:19:15749 // If we're reloading a component extension, use the component extension
750 // loader's reloader.
751 if (component_loader_->Exists(extension_id)) {
752 component_loader_->Reload(extension_id);
753 return;
754 }
755
[email protected]e6090e42010-03-23 22:44:08756 // Check the installed extensions to see if what we're reloading was already
757 // installed.
758 scoped_ptr<ExtensionInfo> installed_extension(
759 extension_prefs_->GetInstalledExtensionInfo(extension_id));
760 if (installed_extension.get() &&
761 installed_extension->extension_manifest.get()) {
[email protected]d8c8f25f2011-11-02 18:18:01762 extensions::InstalledLoader(this).Load(*installed_extension, false);
[email protected]e6090e42010-03-23 22:44:08763 } else {
[email protected]d8c8f25f2011-11-02 18:18:01764 // Otherwise, the extension is unpacked (location LOAD).
[email protected]e6090e42010-03-23 22:44:08765 // We should always be able to remember the extension's path. If it's not in
766 // the map, someone failed to update |unloaded_extension_paths_|.
767 CHECK(!path.empty());
[email protected]d8c8f25f2011-11-02 18:18:01768 extensions::UnpackedInstaller::Create(this)->Load(path);
[email protected]e6090e42010-03-23 22:44:08769 }
[email protected]9cddd4702009-07-27 22:09:40770}
771
[email protected]fa2416f2011-05-03 08:41:20772bool ExtensionService::UninstallExtension(
[email protected]a12c706e2011-12-01 00:58:08773 std::string extension_id,
[email protected]fa2416f2011-05-03 08:41:20774 bool external_uninstall,
[email protected]65187152012-06-02 13:14:14775 string16* error) {
[email protected]a29a517a2011-01-21 21:11:12776 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]a8af9fdb2010-10-28 21:52:20777
[email protected]0d6ec3a72011-09-02 02:09:43778 scoped_refptr<const Extension> extension(GetInstalledExtension(extension_id));
[email protected]631cf822009-05-15 07:01:25779
[email protected]e7afe2452010-08-22 16:19:13780 // Callers should not send us nonexistent extensions.
[email protected]aebe23a32010-12-10 22:15:48781 CHECK(extension);
[email protected]9f1087e2009-06-15 17:29:32782
[email protected]95da88c42011-03-31 10:07:33783 // Policy change which triggers an uninstall will always set
784 // |external_uninstall| to true so this is the only way to uninstall
785 // managed extensions.
[email protected]65187152012-06-02 13:14:14786 if (!external_uninstall &&
787 !system_->management_policy()->UserMayModifySettings(
788 extension.get(), error)) {
[email protected]ad50def52011-10-19 23:17:07789 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:27790 chrome::NOTIFICATION_EXTENSION_UNINSTALL_NOT_ALLOWED,
[email protected]6c2381d2011-10-19 02:52:53791 content::Source<Profile>(profile_),
792 content::Details<const Extension>(extension));
[email protected]d6ebc9792011-04-07 18:18:33793 return false;
794 }
[email protected]95da88c42011-03-31 10:07:33795
[email protected]3bdba0d2011-08-23 07:17:30796 // Extract the data we need for sync now, but don't actually sync until we've
797 // completed the uninstallation.
[email protected]65f173552012-06-28 22:43:58798 syncer::SyncChange sync_change;
[email protected]5db9ada2012-04-11 13:48:20799 if (app_sync_bundle_.HandlesApp(*extension)) {
800 sync_change = app_sync_bundle_.CreateSyncChangeToDelete(extension);
801 } else if (extension_sync_bundle_.HandlesExtension(*extension)) {
802 sync_change = extension_sync_bundle_.CreateSyncChangeToDelete(extension);
[email protected]3bdba0d2011-08-23 07:17:30803 }
804
[email protected]d96eb512012-11-01 23:44:08805 if (IsUnacknowledgedExternalExtension(extension)) {
806 UMA_HISTOGRAM_ENUMERATION("Extensions.ExternalExtensionEvent",
807 EXTERNAL_EXTENSION_UNINSTALLED,
808 EXTERNAL_EXTENSION_BUCKET_BOUNDARY);
809 }
[email protected]9b217652010-10-08 22:04:23810 UMA_HISTOGRAM_ENUMERATION("Extensions.UninstallType",
[email protected]7fa19f82010-12-21 19:40:08811 extension->GetType(), 100);
[email protected]fe2dd7742011-04-19 22:52:49812 RecordPermissionMessagesHistogram(
813 extension, "Extensions.Permissions_Uninstall");
[email protected]9b217652010-10-08 22:04:23814
[email protected]831aa212010-03-26 13:55:19815 // Unload before doing more cleanup to ensure that nothing is hanging on to
816 // any of these resources.
[email protected]814a7bf0f2011-08-13 05:30:59817 UnloadExtension(extension_id, extension_misc::UNLOAD_REASON_UNINSTALL);
[email protected]831aa212010-03-26 13:55:19818
[email protected]0d6ec3a72011-09-02 02:09:43819 extension_prefs_->OnExtensionUninstalled(extension_id, extension->location(),
[email protected]831aa212010-03-26 13:55:19820 external_uninstall);
[email protected]9f1087e2009-06-15 17:29:32821
822 // Tell the backend to start deleting installed extensions on the file thread.
[email protected]0d6ec3a72011-09-02 02:09:43823 if (Extension::LOAD != extension->location()) {
[email protected]7f8f24f2012-11-15 19:40:14824 if (!GetFileTaskRunner()->PostTask(
825 FROM_HERE,
[email protected]53612e82011-10-18 18:00:36826 base::Bind(
[email protected]14908b72011-04-20 06:54:36827 &extension_file_util::UninstallExtension,
828 install_directory_,
[email protected]fa2416f2011-05-03 08:41:20829 extension_id)))
[email protected]14908b72011-04-20 06:54:36830 NOTREACHED();
[email protected]9f1087e2009-06-15 17:29:32831 }
832
[email protected]0d6ec3a72011-09-02 02:09:43833 GURL launch_web_url_origin(extension->launch_web_url());
834 launch_web_url_origin = launch_web_url_origin.GetOrigin();
[email protected]605fb8102012-05-04 01:36:55835 bool is_storage_isolated = extension->is_storage_isolated();
[email protected]0d6ec3a72011-09-02 02:09:43836
[email protected]399583b2012-12-11 09:33:42837 if (is_storage_isolated) {
838 BrowserContext::AsyncObliterateStoragePartition(
839 profile_,
840 GetSiteForExtensionId(extension_id),
841 base::Bind(&ExtensionService::OnNeedsToGarbageCollectIsolatedStorage,
842 AsWeakPtr()));
843 } else {
844 if (extension->is_hosted_app() &&
845 !profile_->GetExtensionSpecialStoragePolicy()->
846 IsStorageProtected(launch_web_url_origin)) {
847 extensions::DataDeleter::StartDeleting(
848 profile_, extension_id, launch_web_url_origin);
849 }
850 extensions::DataDeleter::StartDeleting(profile_, extension_id,
851 extension->url());
[email protected]0d6ec3a72011-09-02 02:09:43852 }
[email protected]0d6ec3a72011-09-02 02:09:43853
[email protected]0dfe05c2011-02-23 23:03:36854 UntrackTerminatedExtension(extension_id);
[email protected]211030342010-09-30 18:41:06855
856 // Notify interested parties that we've uninstalled this extension.
[email protected]ad50def52011-10-19 23:17:07857 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:27858 chrome::NOTIFICATION_EXTENSION_UNINSTALLED,
[email protected]6c2381d2011-10-19 02:52:53859 content::Source<Profile>(profile_),
[email protected]d67d9412012-07-17 17:19:42860 content::Details<const Extension>(extension));
[email protected]d6ebc9792011-04-07 18:18:33861
[email protected]5db9ada2012-04-11 13:48:20862 if (app_sync_bundle_.HasExtensionId(extension_id) &&
[email protected]a4a147652012-07-03 23:41:32863 sync_change.sync_data().GetDataType() == syncer::APPS) {
[email protected]5db9ada2012-04-11 13:48:20864 app_sync_bundle_.ProcessDeletion(extension_id, sync_change);
865 } else if (extension_sync_bundle_.HasExtensionId(extension_id) &&
[email protected]a4a147652012-07-03 23:41:32866 sync_change.sync_data().GetDataType() == syncer::EXTENSIONS) {
[email protected]5db9ada2012-04-11 13:48:20867 extension_sync_bundle_.ProcessDeletion(extension_id, sync_change);
[email protected]3bdba0d2011-08-23 07:17:30868 }
869
[email protected]399583b2012-12-11 09:33:42870 delayed_updates_for_idle_.Remove(extension_id);
871 delayed_installs_.Remove(extension_id);
[email protected]0db124b02012-11-07 04:55:05872
[email protected]333b1de2011-09-12 18:28:50873 // Track the uninstallation.
[email protected]49098f702011-10-13 03:47:18874 UMA_HISTOGRAM_ENUMERATION("Extensions.ExtensionUninstalled", 1, 2);
875
[email protected]d6ebc9792011-04-07 18:18:33876 return true;
[email protected]c10da4b02010-03-25 14:38:32877}
878
[email protected]c3cfb012011-04-06 22:07:35879bool ExtensionService::IsExtensionEnabled(
880 const std::string& extension_id) const {
[email protected]84df8332011-12-06 18:22:46881 if (extensions_.Contains(extension_id) ||
[email protected]dc9a74f72012-08-17 18:07:21882 terminated_extensions_.Contains(extension_id)) {
[email protected]36429da2011-07-11 20:25:18883 return true;
[email protected]dc9a74f72012-08-17 18:07:21884 }
[email protected]36429da2011-07-11 20:25:18885
[email protected]695b5712012-12-06 23:55:28886 if (disabled_extensions_.Contains(extension_id) ||
887 blacklisted_extensions_.Contains(extension_id)) {
[email protected]ad83ca242011-07-29 01:32:25888 return false;
[email protected]695b5712012-12-06 23:55:28889 }
[email protected]ad83ca242011-07-29 01:32:25890
891 // If the extension hasn't been loaded yet, check the prefs for it. Assume
892 // enabled unless otherwise noted.
893 return !extension_prefs_->IsExtensionDisabled(extension_id) &&
[email protected]f574c402012-12-04 23:20:31894 !extension_prefs_->IsExternalExtensionUninstalled(extension_id);
[email protected]c3cfb012011-04-06 22:07:35895}
896
897bool ExtensionService::IsExternalExtensionUninstalled(
898 const std::string& extension_id) const {
899 return extension_prefs_->IsExternalExtensionUninstalled(extension_id);
900}
901
[email protected]eaa7dd182010-12-14 11:09:00902void ExtensionService::EnableExtension(const std::string& extension_id) {
[email protected]a29a517a2011-01-21 21:11:12903 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]a8af9fdb2010-10-28 21:52:20904
[email protected]06f92562011-04-29 19:27:31905 if (IsExtensionEnabled(extension_id))
[email protected]0c6da502009-08-14 22:32:39906 return;
[email protected]0c6da502009-08-14 22:32:39907
[email protected]c0231d72012-11-26 22:37:57908 int disable_reasons = extension_prefs_->GetDisableReasons(extension_id);
[email protected]b3317ad2011-04-28 23:46:00909 extension_prefs_->SetExtensionState(extension_id, Extension::ENABLED);
[email protected]eb5e4f92012-08-15 23:33:28910 extension_prefs_->ClearDisableReasons(extension_id);
[email protected]1784e83a2009-09-08 21:01:52911
[email protected]695b5712012-12-06 23:55:28912 const Extension* extension = disabled_extensions_.GetByID(extension_id);
[email protected]06f92562011-04-29 19:27:31913 // This can happen if sync enables an extension that is not
914 // installed yet.
915 if (!extension)
916 return;
917
[email protected]d96eb512012-11-01 23:44:08918 if (IsUnacknowledgedExternalExtension(extension)) {
919 UMA_HISTOGRAM_ENUMERATION("Extensions.ExternalExtensionEvent",
920 EXTERNAL_EXTENSION_REENABLED,
921 EXTERNAL_EXTENSION_BUCKET_BOUNDARY);
[email protected]612a1cb12012-10-17 13:18:03922 AcknowledgeExternalExtension(extension->id());
[email protected]d96eb512012-11-01 23:44:08923 }
[email protected]612a1cb12012-10-17 13:18:03924
[email protected]c0231d72012-11-26 22:37:57925 if (disable_reasons & Extension::DISABLE_SIDELOAD_WIPEOUT)
[email protected]94e14592012-11-19 10:49:42926 UMA_HISTOGRAM_BOOLEAN("DisabledExtension.ExtensionWipedStatus", false);
927
[email protected]0c6da502009-08-14 22:32:39928 // Move it over to the enabled list.
[email protected]84df8332011-12-06 18:22:46929 extensions_.Insert(make_scoped_refptr(extension));
930 disabled_extensions_.Remove(extension->id());
[email protected]0c6da502009-08-14 22:32:39931
[email protected]62d30f42009-10-01 22:36:06932 NotifyExtensionLoaded(extension);
[email protected]3bdba0d2011-08-23 07:17:30933
[email protected]f74d7f32012-06-19 19:22:51934 // Notify listeners that the extension was enabled.
935 content::NotificationService::current()->Notify(
936 chrome::NOTIFICATION_EXTENSION_ENABLED,
937 content::Source<Profile>(profile_),
938 content::Details<const Extension>(extension));
939
[email protected]3bdba0d2011-08-23 07:17:30940 SyncExtensionChangeIfNeeded(*extension);
[email protected]0c6da502009-08-14 22:32:39941}
942
[email protected]44d62b62012-04-11 00:06:03943void ExtensionService::DisableExtension(
944 const std::string& extension_id,
945 Extension::DisableReason disable_reason) {
[email protected]a29a517a2011-01-21 21:11:12946 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]a8af9fdb2010-10-28 21:52:20947
[email protected]b2ba9962009-12-10 20:10:15948 // The extension may have been disabled already.
[email protected]06f92562011-04-29 19:27:31949 if (!IsExtensionEnabled(extension_id))
[email protected]1784e83a2009-09-08 21:01:52950 return;
[email protected]1784e83a2009-09-08 21:01:52951
[email protected]06f92562011-04-29 19:27:31952 const Extension* extension = GetInstalledExtension(extension_id);
953 // |extension| can be NULL if sync disables an extension that is not
954 // installed yet.
[email protected]65187152012-06-02 13:14:14955 if (extension &&
956 !system_->management_policy()->UserMayModifySettings(extension, NULL)) {
[email protected]95da88c42011-03-31 10:07:33957 return;
[email protected]65187152012-06-02 13:14:14958 }
[email protected]95da88c42011-03-31 10:07:33959
[email protected]b3317ad2011-04-28 23:46:00960 extension_prefs_->SetExtensionState(extension_id, Extension::DISABLED);
[email protected]eb5e4f92012-08-15 23:33:28961 extension_prefs_->AddDisableReason(extension_id, disable_reason);
[email protected]1784e83a2009-09-08 21:01:52962
[email protected]695b5712012-12-06 23:55:28963 int include_mask = INCLUDE_EVERYTHING & ~INCLUDE_DISABLED;
964 extension = GetExtensionById(extension_id, include_mask);
[email protected]06f92562011-04-29 19:27:31965 if (!extension)
966 return;
967
[email protected]5c094792012-09-07 19:44:53968 // Move it over to the disabled list. Don't send a second unload notification
969 // for terminated extensions being disabled.
[email protected]84df8332011-12-06 18:22:46970 disabled_extensions_.Insert(make_scoped_refptr(extension));
[email protected]5c094792012-09-07 19:44:53971 if (extensions_.Contains(extension->id())) {
[email protected]84df8332011-12-06 18:22:46972 extensions_.Remove(extension->id());
[email protected]5c094792012-09-07 19:44:53973 NotifyExtensionUnloaded(extension, extension_misc::UNLOAD_REASON_DISABLE);
974 } else {
[email protected]84df8332011-12-06 18:22:46975 terminated_extensions_.Remove(extension->id());
[email protected]5c094792012-09-07 19:44:53976 }
[email protected]3bdba0d2011-08-23 07:17:30977
978 SyncExtensionChangeIfNeeded(*extension);
[email protected]1784e83a2009-09-08 21:01:52979}
980
[email protected]eaa7dd182010-12-14 11:09:00981void ExtensionService::GrantPermissionsAndEnableExtension(
[email protected]b70a2d92012-06-28 19:51:21982 const Extension* extension, bool record_oauth2_grant) {
[email protected]be083862012-09-01 03:53:45983 GrantPermissions(extension, record_oauth2_grant);
[email protected]fe2dd7742011-04-19 22:52:49984 RecordPermissionMessagesHistogram(
985 extension, "Extensions.Permissions_ReEnable");
[email protected]8d888c12010-11-30 00:00:25986 extension_prefs_->SetDidExtensionEscalatePermissions(extension, false);
987 EnableExtension(extension->id());
988}
989
[email protected]be083862012-09-01 03:53:45990void ExtensionService::GrantPermissions(const Extension* extension,
991 bool record_oauth2_grant) {
992 CHECK(extension);
993 extensions::PermissionsUpdater perms_updater(profile());
994 perms_updater.GrantActivePermissions(extension, record_oauth2_grant);
995}
996
[email protected]fe2dd7742011-04-19 22:52:49997// static
998void ExtensionService::RecordPermissionMessagesHistogram(
999 const Extension* e, const char* histogram) {
1000 // Since this is called from multiple sources, and since the Histogram macros
1001 // use statics, we need to manually lookup the Histogram ourselves.
1002 base::Histogram* counter = base::LinearHistogram::FactoryGet(
1003 histogram,
1004 1,
[email protected]c2e66e12012-06-27 06:27:061005 PermissionMessage::kEnumBoundary,
1006 PermissionMessage::kEnumBoundary + 1,
[email protected]fe2dd7742011-04-19 22:52:491007 base::Histogram::kUmaTargetedHistogramFlag);
1008
[email protected]c2e66e12012-06-27 06:27:061009 PermissionMessages permissions = e->GetPermissionMessages();
[email protected]fe2dd7742011-04-19 22:52:491010 if (permissions.empty()) {
[email protected]c2e66e12012-06-27 06:27:061011 counter->Add(PermissionMessage::kNone);
[email protected]fe2dd7742011-04-19 22:52:491012 } else {
[email protected]c2e66e12012-06-27 06:27:061013 for (PermissionMessages::iterator it = permissions.begin();
[email protected]0d3e4a22011-06-23 19:02:521014 it != permissions.end(); ++it)
1015 counter->Add(it->id());
[email protected]fe2dd7742011-04-19 22:52:491016 }
1017}
1018
[email protected]eaa7dd182010-12-14 11:09:001019void ExtensionService::NotifyExtensionLoaded(const Extension* extension) {
[email protected]57a777f72010-03-31 01:09:421020 // The ChromeURLRequestContexts need to be first to know that the extension
[email protected]62d30f42009-10-01 22:36:061021 // was loaded, otherwise a race can arise where a renderer that is created
1022 // for the extension may try to load an extension URL with an extension id
[email protected]57a777f72010-03-31 01:09:421023 // that the request context doesn't yet know about. The profile is responsible
1024 // for ensuring its URLRequestContexts appropriately discover the loaded
1025 // extension.
[email protected]31d8f5f22012-04-02 15:22:081026 system_->RegisterExtensionWithRequestContexts(extension);
[email protected]62d30f42009-10-01 22:36:061027
[email protected]d5949312012-12-03 22:13:301028 // Tell renderers about the new extension, unless it's a theme (renderers
1029 // don't need to know about themes).
[email protected]a58f599c2012-12-01 03:08:191030 if (!extension->is_theme()) {
[email protected]19647262011-12-16 09:57:491031 for (content::RenderProcessHost::iterator i(
1032 content::RenderProcessHost::AllHostsIterator());
1033 !i.IsAtEnd(); i.Advance()) {
1034 content::RenderProcessHost* host = i.GetCurrentValue();
1035 Profile* host_profile =
1036 Profile::FromBrowserContext(host->GetBrowserContext());
1037 if (host_profile->GetOriginalProfile() ==
1038 profile_->GetOriginalProfile()) {
1039 std::vector<ExtensionMsg_Loaded_Params> loaded_extensions(
1040 1, ExtensionMsg_Loaded_Params(extension));
1041 host->Send(
1042 new ExtensionMsg_Loaded(loaded_extensions));
1043 }
[email protected]c8d407e2011-04-28 21:27:171044 }
[email protected]77a6970c2011-04-23 16:58:561045 }
1046
[email protected]3442a662012-01-12 08:06:171047 // Tell subsystems that use the EXTENSION_LOADED notification about the new
1048 // extension.
1049 //
1050 // NOTE: It is important that this happen after notifying the renderers about
1051 // the new extensions so that if we navigate to an extension URL in
1052 // NOTIFICATION_EXTENSION_LOADED, the renderer is guaranteed to know about it.
1053 content::NotificationService::current()->Notify(
1054 chrome::NOTIFICATION_EXTENSION_LOADED,
1055 content::Source<Profile>(profile_),
1056 content::Details<const Extension>(extension));
1057
[email protected]c8d407e2011-04-28 21:27:171058 // Tell a random-ass collection of other subsystems about the new extension.
1059 // TODO(aa): What should we do with all this goop? Can it move into the
1060 // relevant objects via EXTENSION_LOADED?
1061
1062 profile_->GetExtensionSpecialStoragePolicy()->
1063 GrantRightsForExtension(extension);
1064
1065 UpdateActiveExtensionsInCrashReporter();
1066
1067 ExtensionWebUI::RegisterChromeURLOverrides(
1068 profile_, extension->GetChromeURLOverrides());
1069
[email protected]c8d407e2011-04-28 21:27:171070 // If the extension has permission to load chrome://favicon/ resources we need
1071 // to make sure that the FaviconSource is registered with the
1072 // ChromeURLDataManager.
1073 if (extension->HasHostPermission(GURL(chrome::kChromeUIFaviconURL))) {
1074 FaviconSource* favicon_source = new FaviconSource(profile_,
1075 FaviconSource::FAVICON);
[email protected]ef92e172012-04-25 19:40:411076 ChromeURLDataManager::AddDataSource(profile_, favicon_source);
[email protected]c8d407e2011-04-28 21:27:171077 }
[email protected]b07e606e2012-09-15 20:16:151078
1079#if !defined(OS_ANDROID)
1080 // Same for chrome://theme/ resources.
1081 if (extension->HasHostPermission(GURL(chrome::kChromeUIThemeURL))) {
1082 ThemeSource* theme_source = new ThemeSource(profile_);
1083 ChromeURLDataManager::AddDataSource(profile_, theme_source);
1084 }
1085#endif
1086
[email protected]5eddc3e2011-10-26 04:33:311087 // Same for chrome://thumb/ resources.
1088 if (extension->HasHostPermission(GURL(chrome::kChromeUIThumbnailURL))) {
1089 ThumbnailSource* thumbnail_source = new ThumbnailSource(profile_);
[email protected]ef92e172012-04-25 19:40:411090 ChromeURLDataManagerFactory::GetForProfile(profile_)->
1091 AddDataSource(thumbnail_source);
[email protected]5eddc3e2011-10-26 04:33:311092 }
[email protected]c8d407e2011-04-28 21:27:171093
[email protected]ebd71962012-12-20 02:56:551094#if defined(ENABLE_PLUGINS)
[email protected]c8d407e2011-04-28 21:27:171095 // TODO(mpcomplete): This ends up affecting all profiles. See crbug.com/80757.
[email protected]2de307592011-04-05 21:16:581096 bool plugins_changed = false;
1097 for (size_t i = 0; i < extension->plugins().size(); ++i) {
1098 const Extension::PluginInfo& plugin = extension->plugins()[i];
[email protected]f520b5b2011-11-08 02:42:141099 PluginService::GetInstance()->RefreshPlugins();
1100 PluginService::GetInstance()->AddExtraPluginPath(plugin.path);
[email protected]2de307592011-04-05 21:16:581101 plugins_changed = true;
[email protected]476a27032011-09-13 13:40:491102 ChromePluginServiceFilter* filter =
1103 ChromePluginServiceFilter::GetInstance();
1104 if (plugin.is_public) {
1105 filter->RestrictPluginToProfileAndOrigin(
1106 plugin.path, profile_, GURL());
1107 } else {
1108 filter->RestrictPluginToProfileAndOrigin(
1109 plugin.path, profile_, extension->url());
[email protected]2de307592011-04-05 21:16:581110 }
1111 }
[email protected]84396dbc2011-04-14 06:33:421112
1113 bool nacl_modules_changed = false;
1114 for (size_t i = 0; i < extension->nacl_modules().size(); ++i) {
1115 const Extension::NaClModuleInfo& module = extension->nacl_modules()[i];
[email protected]cebc3dc2011-04-18 17:15:001116 RegisterNaClModule(module.url, module.mime_type);
[email protected]84396dbc2011-04-14 06:33:421117 nacl_modules_changed = true;
1118 }
1119
[email protected]ed0ba002011-05-26 16:55:131120 if (nacl_modules_changed)
1121 UpdatePluginListWithNaClModules();
[email protected]84396dbc2011-04-14 06:33:421122
1123 if (plugins_changed || nacl_modules_changed)
[email protected]45a22e62011-10-12 09:48:021124 PluginService::GetInstance()->PurgePluginListCache(profile_, false);
[email protected]ebd71962012-12-20 02:56:551125#endif // defined(ENABLE_PLUGINS)
[email protected]62d30f42009-10-01 22:36:061126}
1127
[email protected]a9f39a312010-12-23 22:14:271128void ExtensionService::NotifyExtensionUnloaded(
[email protected]814a7bf0f2011-08-13 05:30:591129 const Extension* extension,
1130 extension_misc::UnloadedExtensionReason reason) {
[email protected]a9f39a312010-12-23 22:14:271131 UnloadedExtensionInfo details(extension, reason);
[email protected]ad50def52011-10-19 23:17:071132 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271133 chrome::NOTIFICATION_EXTENSION_UNLOADED,
[email protected]6c2381d2011-10-19 02:52:531134 content::Source<Profile>(profile_),
1135 content::Details<UnloadedExtensionInfo>(&details));
[email protected]62d30f42009-10-01 22:36:061136
[email protected]903d70a2012-12-04 13:00:171137#if defined(ENABLE_THEMES)
1138 // If the current theme is being unloaded, tell ThemeService to revert back
1139 // to the default theme.
1140 if (reason != extension_misc::UNLOAD_REASON_UPDATE && extension->is_theme()) {
1141 ThemeService* theme_service = ThemeServiceFactory::GetForProfile(profile_);
1142 if (extension->id() == theme_service->GetThemeID())
1143 theme_service->UseDefaultTheme();
1144 }
1145#endif
1146
[email protected]f3b1a082011-11-18 00:34:301147 for (content::RenderProcessHost::iterator i(
1148 content::RenderProcessHost::AllHostsIterator());
[email protected]77a6970c2011-04-23 16:58:561149 !i.IsAtEnd(); i.Advance()) {
[email protected]f3b1a082011-11-18 00:34:301150 content::RenderProcessHost* host = i.GetCurrentValue();
[email protected]9b62ecf2011-07-27 20:23:081151 Profile* host_profile =
[email protected]f3b1a082011-11-18 00:34:301152 Profile::FromBrowserContext(host->GetBrowserContext());
[email protected]9b62ecf2011-07-27 20:23:081153 if (host_profile->GetOriginalProfile() == profile_->GetOriginalProfile())
[email protected]c8d407e2011-04-28 21:27:171154 host->Send(new ExtensionMsg_Unloaded(extension->id()));
[email protected]77a6970c2011-04-23 16:58:561155 }
1156
[email protected]31d8f5f22012-04-02 15:22:081157 system_->UnregisterExtensionWithRequestContexts(extension->id(), reason);
[email protected]c8d407e2011-04-28 21:27:171158 profile_->GetExtensionSpecialStoragePolicy()->
1159 RevokeRightsForExtension(extension);
1160
1161 ExtensionWebUI::UnregisterChromeURLOverrides(
1162 profile_, extension->GetChromeURLOverrides());
1163
[email protected]b777b332011-04-16 04:01:081164#if defined(OS_CHROMEOS)
[email protected]ac66e452013-01-11 09:21:231165 // Revoke external file access for the extension from its file system context.
1166 // It is safe to access the extension's storage partition at this point. The
1167 // storage partition may get destroyed only after the extension gets unloaded.
1168 GURL site = extensions::ExtensionSystem::Get(profile_)->extension_service()->
1169 GetSiteForExtensionId(extension->id());
[email protected]10eb28162012-09-18 03:04:091170 fileapi::FileSystemContext* filesystem_context =
[email protected]ac66e452013-01-11 09:21:231171 BrowserContext::GetStoragePartitionForSite(profile_, site)->
[email protected]10eb28162012-09-18 03:04:091172 GetFileSystemContext();
1173 if (filesystem_context && filesystem_context->external_provider()) {
1174 filesystem_context->external_provider()->
[email protected]c8d407e2011-04-28 21:27:171175 RevokeAccessForExtension(extension->id());
[email protected]62d30f42009-10-01 22:36:061176 }
[email protected]c8d407e2011-04-28 21:27:171177#endif
1178
1179 UpdateActiveExtensionsInCrashReporter();
[email protected]2de307592011-04-05 21:16:581180
[email protected]ebd71962012-12-20 02:56:551181#if defined(ENABLE_PLUGINS)
[email protected]2de307592011-04-05 21:16:581182 bool plugins_changed = false;
1183 for (size_t i = 0; i < extension->plugins().size(); ++i) {
1184 const Extension::PluginInfo& plugin = extension->plugins()[i];
[email protected]b6a2f8de2012-01-31 17:28:491185 PluginService::GetInstance()->ForcePluginShutdown(plugin.path);
[email protected]f520b5b2011-11-08 02:42:141186 PluginService::GetInstance()->RefreshPlugins();
1187 PluginService::GetInstance()->RemoveExtraPluginPath(plugin.path);
[email protected]2de307592011-04-05 21:16:581188 plugins_changed = true;
[email protected]476a27032011-09-13 13:40:491189 ChromePluginServiceFilter::GetInstance()->UnrestrictPlugin(plugin.path);
[email protected]2de307592011-04-05 21:16:581190 }
[email protected]84396dbc2011-04-14 06:33:421191
1192 bool nacl_modules_changed = false;
1193 for (size_t i = 0; i < extension->nacl_modules().size(); ++i) {
1194 const Extension::NaClModuleInfo& module = extension->nacl_modules()[i];
[email protected]cebc3dc2011-04-18 17:15:001195 UnregisterNaClModule(module.url);
[email protected]84396dbc2011-04-14 06:33:421196 nacl_modules_changed = true;
1197 }
1198
[email protected]ed0ba002011-05-26 16:55:131199 if (nacl_modules_changed)
1200 UpdatePluginListWithNaClModules();
[email protected]84396dbc2011-04-14 06:33:421201
1202 if (plugins_changed || nacl_modules_changed)
[email protected]45a22e62011-10-12 09:48:021203 PluginService::GetInstance()->PurgePluginListCache(profile_, false);
[email protected]ebd71962012-12-20 02:56:551204#endif // defined(ENABLE_PLUGINS)
[email protected]62d30f42009-10-01 22:36:061205}
1206
[email protected]0a071a32011-02-08 00:18:241207Profile* ExtensionService::profile() {
1208 return profile_;
1209}
1210
[email protected]45759612012-07-10 17:21:231211extensions::ExtensionPrefs* ExtensionService::extension_prefs() {
[email protected]ddb1e5a2010-12-13 20:10:451212 return extension_prefs_;
1213}
1214
[email protected]0d9a2202011-11-09 13:48:411215extensions::SettingsFrontend* ExtensionService::settings_frontend() {
[email protected]cccdf0aa2011-11-11 03:43:381216 return settings_frontend_.get();
[email protected]b7f853e282011-08-10 09:24:201217}
1218
[email protected]e2d720aa2012-05-17 00:11:351219extensions::ContentSettingsStore* ExtensionService::GetContentSettingsStore() {
[email protected]b790b072011-05-20 09:46:441220 return extension_prefs()->content_settings_store();
1221}
1222
[email protected]25ae0152011-11-18 14:40:021223bool ExtensionService::is_ready() {
1224 return ready_;
1225}
1226
[email protected]7f8f24f2012-11-15 19:40:141227base::SequencedTaskRunner* ExtensionService::GetFileTaskRunner() {
1228 if (file_task_runner_)
1229 return file_task_runner_;
1230
1231 // We should be able to interrupt any part of extension install process during
1232 // shutdown. SKIP_ON_SHUTDOWN ensures that not started extension install tasks
1233 // will be ignored/deleted while we will block on started tasks.
1234 std::string token("ext_install-");
1235 token.append(profile_->GetPath().AsUTF8Unsafe());
1236 file_task_runner_ = BrowserThread::GetBlockingPool()->
1237 GetSequencedTaskRunnerWithShutdownBehavior(
1238 BrowserThread::GetBlockingPool()->GetNamedSequenceToken(token),
1239 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN);
1240 return file_task_runner_;
1241}
1242
[email protected]42a08162012-03-16 18:09:111243extensions::ExtensionUpdater* ExtensionService::updater() {
[email protected]2859946f2011-04-04 18:18:061244 return updater_.get();
1245}
1246
[email protected]4ee07c62012-08-21 12:40:421247void ExtensionService::CheckManagementPolicy() {
[email protected]aa96d3a2010-08-21 08:45:251248 std::vector<std::string> to_be_removed;
[email protected]695b5712012-12-06 23:55:281249
[email protected]aa96d3a2010-08-21 08:45:251250 // Loop through extensions list, unload installed extensions.
[email protected]84df8332011-12-06 18:22:461251 for (ExtensionSet::const_iterator iter = extensions_.begin();
[email protected]aa96d3a2010-08-21 08:45:251252 iter != extensions_.end(); ++iter) {
[email protected]9adb9692010-10-29 23:14:021253 const Extension* extension = (*iter);
[email protected]4ee07c62012-08-21 12:40:421254 if (!system_->management_policy()->UserMayLoad(extension, NULL))
[email protected]aa96d3a2010-08-21 08:45:251255 to_be_removed.push_back(extension->id());
1256 }
1257
1258 // UnloadExtension will change the extensions_ list. So, we should
1259 // call it outside the iterator loop.
[email protected]31bb5ee62012-09-12 22:58:401260 for (size_t i = 0; i < to_be_removed.size(); ++i)
[email protected]814a7bf0f2011-08-13 05:30:591261 UnloadExtension(to_be_removed[i], extension_misc::UNLOAD_REASON_DISABLE);
[email protected]aa96d3a2010-08-21 08:45:251262}
1263
[email protected]31206602011-04-13 23:07:321264void ExtensionService::CheckForUpdatesSoon() {
[email protected]c3cfb012011-04-06 22:07:351265 if (updater()) {
[email protected]94fde232012-04-27 10:22:301266 if (AreAllExternalProvidersReady()) {
1267 updater()->CheckSoon();
1268 } else {
1269 // Sync can start updating before all the external providers are ready
1270 // during startup. Start the update as soon as those providers are ready,
1271 // but not before.
1272 update_once_all_providers_are_ready_ = true;
1273 }
[email protected]c3cfb012011-04-06 22:07:351274 } else {
[email protected]31206602011-04-13 23:07:321275 LOG(WARNING) << "CheckForUpdatesSoon() called with auto-update turned off";
[email protected]c3cfb012011-04-06 22:07:351276 }
1277}
1278
[email protected]3f98fd92012-11-17 15:54:291279syncer::SyncMergeResult ExtensionService::MergeDataAndStartSyncing(
[email protected]a4a147652012-07-03 23:41:321280 syncer::ModelType type,
[email protected]65f173552012-06-28 22:43:581281 const syncer::SyncDataList& initial_sync_data,
1282 scoped_ptr<syncer::SyncChangeProcessor> sync_processor,
1283 scoped_ptr<syncer::SyncErrorFactory> sync_error_factory) {
[email protected]5db9ada2012-04-11 13:48:201284 CHECK(sync_processor.get());
[email protected]5d36e052012-04-20 20:12:281285 CHECK(sync_error_factory.get());
[email protected]3bdba0d2011-08-23 07:17:301286
1287 switch (type) {
[email protected]a4a147652012-07-03 23:41:321288 case syncer::EXTENSIONS:
[email protected]5db9ada2012-04-11 13:48:201289 extension_sync_bundle_.SetupSync(sync_processor.release(),
[email protected]5d36e052012-04-20 20:12:281290 sync_error_factory.release(),
[email protected]5db9ada2012-04-11 13:48:201291 initial_sync_data);
[email protected]3bdba0d2011-08-23 07:17:301292 break;
1293
[email protected]a4a147652012-07-03 23:41:321294 case syncer::APPS:
[email protected]5d36e052012-04-20 20:12:281295 app_sync_bundle_.SetupSync(sync_processor.release(),
1296 sync_error_factory.release(),
1297 initial_sync_data);
[email protected]3bdba0d2011-08-23 07:17:301298 break;
1299
1300 default:
1301 LOG(FATAL) << "Got " << type << " ModelType";
1302 }
[email protected]3bdba0d2011-08-23 07:17:301303
[email protected]b1417ab2011-12-15 17:09:111304 // Process local extensions.
1305 // TODO(yoz): Determine whether pending extensions should be considered too.
1306 // See crbug.com/104399.
[email protected]65f173552012-06-28 22:43:581307 syncer::SyncDataList sync_data_list = GetAllSyncData(type);
1308 syncer::SyncChangeList sync_change_list;
1309 for (syncer::SyncDataList::const_iterator i = sync_data_list.begin();
[email protected]3bdba0d2011-08-23 07:17:301310 i != sync_data_list.end();
1311 ++i) {
[email protected]5db9ada2012-04-11 13:48:201312 switch (type) {
[email protected]a4a147652012-07-03 23:41:321313 case syncer::EXTENSIONS:
[email protected]5db9ada2012-04-11 13:48:201314 sync_change_list.push_back(
1315 extension_sync_bundle_.CreateSyncChange(*i));
1316 break;
[email protected]a4a147652012-07-03 23:41:321317 case syncer::APPS:
[email protected]5db9ada2012-04-11 13:48:201318 sync_change_list.push_back(app_sync_bundle_.CreateSyncChange(*i));
1319 break;
1320 default:
1321 LOG(FATAL) << "Got " << type << " ModelType";
[email protected]31bb5ee62012-09-12 22:58:401322 }
[email protected]3bdba0d2011-08-23 07:17:301323 }
[email protected]3bdba0d2011-08-23 07:17:301324
[email protected]5db9ada2012-04-11 13:48:201325
[email protected]a4a147652012-07-03 23:41:321326 if (type == syncer::EXTENSIONS) {
[email protected]5db9ada2012-04-11 13:48:201327 extension_sync_bundle_.ProcessSyncChangeList(sync_change_list);
[email protected]a4a147652012-07-03 23:41:321328 } else if (type == syncer::APPS) {
[email protected]5db9ada2012-04-11 13:48:201329 app_sync_bundle_.ProcessSyncChangeList(sync_change_list);
1330 }
[email protected]0ffd9e52012-01-26 21:44:341331
[email protected]3f98fd92012-11-17 15:54:291332 return syncer::SyncMergeResult(type);
[email protected]3bdba0d2011-08-23 07:17:301333}
1334
[email protected]a4a147652012-07-03 23:41:321335void ExtensionService::StopSyncing(syncer::ModelType type) {
1336 if (type == syncer::APPS) {
[email protected]5db9ada2012-04-11 13:48:201337 app_sync_bundle_.Reset();
[email protected]a4a147652012-07-03 23:41:321338 } else if (type == syncer::EXTENSIONS) {
[email protected]5db9ada2012-04-11 13:48:201339 extension_sync_bundle_.Reset();
1340 }
[email protected]3bdba0d2011-08-23 07:17:301341}
1342
[email protected]65f173552012-06-28 22:43:581343syncer::SyncDataList ExtensionService::GetAllSyncData(
[email protected]a4a147652012-07-03 23:41:321344 syncer::ModelType type) const {
[email protected]31bb5ee62012-09-12 22:58:401345 if (type == syncer::EXTENSIONS)
[email protected]5db9ada2012-04-11 13:48:201346 return extension_sync_bundle_.GetAllSyncData();
[email protected]31bb5ee62012-09-12 22:58:401347 if (type == syncer::APPS)
[email protected]5db9ada2012-04-11 13:48:201348 return app_sync_bundle_.GetAllSyncData();
[email protected]5db9ada2012-04-11 13:48:201349
1350 // We should only get sync data for extensions and apps.
1351 NOTREACHED();
1352
[email protected]65f173552012-06-28 22:43:581353 return syncer::SyncDataList();
[email protected]3bdba0d2011-08-23 07:17:301354}
1355
[email protected]65f173552012-06-28 22:43:581356syncer::SyncError ExtensionService::ProcessSyncChanges(
[email protected]3bdba0d2011-08-23 07:17:301357 const tracked_objects::Location& from_here,
[email protected]65f173552012-06-28 22:43:581358 const syncer::SyncChangeList& change_list) {
1359 for (syncer::SyncChangeList::const_iterator i = change_list.begin();
[email protected]3bdba0d2011-08-23 07:17:301360 i != change_list.end();
1361 ++i) {
[email protected]a4a147652012-07-03 23:41:321362 syncer::ModelType type = i->sync_data().GetDataType();
1363 if (type == syncer::EXTENSIONS) {
[email protected]5db9ada2012-04-11 13:48:201364 extension_sync_bundle_.ProcessSyncChange(
1365 extensions::ExtensionSyncData(*i));
[email protected]a4a147652012-07-03 23:41:321366 } else if (type == syncer::APPS) {
[email protected]5db9ada2012-04-11 13:48:201367 app_sync_bundle_.ProcessSyncChange(extensions::AppSyncData(*i));
1368 }
[email protected]3bdba0d2011-08-23 07:17:301369 }
1370
[email protected]0ffd9e52012-01-26 21:44:341371 extension_prefs()->extension_sorting()->FixNTPOrdinalCollisions();
1372
[email protected]65f173552012-06-28 22:43:581373 return syncer::SyncError();
[email protected]b05fb9ff2011-04-23 00:07:561374}
1375
[email protected]5db9ada2012-04-11 13:48:201376extensions::ExtensionSyncData ExtensionService::GetExtensionSyncData(
1377 const Extension& extension) const {
1378 return extensions::ExtensionSyncData(extension,
1379 IsExtensionEnabled(extension.id()),
1380 IsIncognitoEnabled(extension.id()));
[email protected]b05fb9ff2011-04-23 00:07:561381}
1382
[email protected]5db9ada2012-04-11 13:48:201383extensions::AppSyncData ExtensionService::GetAppSyncData(
1384 const Extension& extension) const {
1385 return extensions::AppSyncData(
1386 extension,
1387 IsExtensionEnabled(extension.id()),
1388 IsIncognitoEnabled(extension.id()),
1389 extension_prefs_->GetAppNotificationClientId(extension.id()),
1390 extension_prefs_->IsAppNotificationDisabled(extension.id()),
1391 extension_prefs_->extension_sorting()->GetAppLaunchOrdinal(
1392 extension.id()),
1393 extension_prefs_->extension_sorting()->GetPageOrdinal(extension.id()));
1394}
[email protected]3bdba0d2011-08-23 07:17:301395
[email protected]5db9ada2012-04-11 13:48:201396std::vector<extensions::ExtensionSyncData>
1397 ExtensionService::GetExtensionSyncDataList() const {
1398 std::vector<extensions::ExtensionSyncData> extension_sync_list;
1399 extension_sync_bundle_.GetExtensionSyncDataListHelper(extensions_,
1400 &extension_sync_list);
1401 extension_sync_bundle_.GetExtensionSyncDataListHelper(disabled_extensions_,
1402 &extension_sync_list);
1403 extension_sync_bundle_.GetExtensionSyncDataListHelper(terminated_extensions_,
1404 &extension_sync_list);
1405
1406 std::vector<extensions::ExtensionSyncData> pending_extensions =
1407 extension_sync_bundle_.GetPendingData();
1408 extension_sync_list.insert(extension_sync_list.begin(),
1409 pending_extensions.begin(),
1410 pending_extensions.end());
[email protected]3bdba0d2011-08-23 07:17:301411
1412 return extension_sync_list;
[email protected]b05fb9ff2011-04-23 00:07:561413}
1414
[email protected]5db9ada2012-04-11 13:48:201415std::vector<extensions::AppSyncData> ExtensionService::GetAppSyncDataList()
1416 const {
1417 std::vector<extensions::AppSyncData> app_sync_list;
1418 app_sync_bundle_.GetAppSyncDataListHelper(extensions_, &app_sync_list);
1419 app_sync_bundle_.GetAppSyncDataListHelper(disabled_extensions_,
1420 &app_sync_list);
1421 app_sync_bundle_.GetAppSyncDataListHelper(terminated_extensions_,
1422 &app_sync_list);
1423
1424 std::vector<extensions::AppSyncData> pending_apps =
1425 app_sync_bundle_.GetPendingData();
1426 app_sync_list.insert(app_sync_list.begin(),
1427 pending_apps.begin(),
1428 pending_apps.end());
1429
1430 return app_sync_list;
1431}
1432
1433bool ExtensionService::ProcessExtensionSyncData(
1434 const extensions::ExtensionSyncData& extension_sync_data) {
1435 if (!ProcessExtensionSyncDataHelper(extension_sync_data,
[email protected]a4a147652012-07-03 23:41:321436 syncer::EXTENSIONS)) {
[email protected]5db9ada2012-04-11 13:48:201437 extension_sync_bundle_.AddPendingExtension(extension_sync_data.id(),
1438 extension_sync_data);
1439 CheckForUpdatesSoon();
1440 return false;
1441 }
1442
1443 return true;
1444}
1445
1446bool ExtensionService::ProcessAppSyncData(
1447 const extensions::AppSyncData& app_sync_data) {
1448 const std::string& id = app_sync_data.id();
1449 const Extension* extension = GetInstalledExtension(id);
1450 bool extension_installed = (extension != NULL);
1451
1452 if (app_sync_data.app_launch_ordinal().IsValid() &&
1453 app_sync_data.page_ordinal().IsValid()) {
1454 extension_prefs_->extension_sorting()->SetAppLaunchOrdinal(
1455 id,
1456 app_sync_data.app_launch_ordinal());
1457 extension_prefs_->extension_sorting()->SetPageOrdinal(
1458 id,
1459 app_sync_data.page_ordinal());
1460 }
1461
1462 if (extension_installed) {
1463 if (app_sync_data.notifications_disabled() !=
1464 extension_prefs_->IsAppNotificationDisabled(id)) {
1465 extension_prefs_->SetAppNotificationDisabled(
1466 id, app_sync_data.notifications_disabled());
1467 }
1468 }
1469
1470 if (!ProcessExtensionSyncDataHelper(app_sync_data.extension_sync_data(),
[email protected]a4a147652012-07-03 23:41:321471 syncer::APPS)) {
[email protected]5db9ada2012-04-11 13:48:201472 app_sync_bundle_.AddPendingApp(id, app_sync_data);
1473 CheckForUpdatesSoon();
1474 return false;
1475 }
1476
1477 return true;
1478}
1479
1480bool ExtensionService::IsCorrectSyncType(const Extension& extension,
[email protected]a4a147652012-07-03 23:41:321481 syncer::ModelType type) const {
1482 if (type == syncer::EXTENSIONS &&
[email protected]31bb5ee62012-09-12 22:58:401483 extension.GetSyncType() == Extension::SYNC_TYPE_EXTENSION) {
[email protected]5db9ada2012-04-11 13:48:201484 return true;
[email protected]31bb5ee62012-09-12 22:58:401485 }
[email protected]5db9ada2012-04-11 13:48:201486
[email protected]a4a147652012-07-03 23:41:321487 if (type == syncer::APPS &&
[email protected]31bb5ee62012-09-12 22:58:401488 extension.GetSyncType() == Extension::SYNC_TYPE_APP) {
[email protected]5db9ada2012-04-11 13:48:201489 return true;
[email protected]31bb5ee62012-09-12 22:58:401490 }
[email protected]5db9ada2012-04-11 13:48:201491
1492 return false;
1493}
1494
1495bool ExtensionService::ProcessExtensionSyncDataHelper(
1496 const extensions::ExtensionSyncData& extension_sync_data,
[email protected]a4a147652012-07-03 23:41:321497 syncer::ModelType type) {
[email protected]3bdba0d2011-08-23 07:17:301498 const std::string& id = extension_sync_data.id();
[email protected]96e989b2011-08-30 19:35:061499 const Extension* extension = GetInstalledExtension(id);
1500
1501 // TODO(bolms): we should really handle this better. The particularly bad
1502 // case is where an app becomes an extension or vice versa, and we end up with
1503 // a zombie extension that won't go away.
[email protected]5db9ada2012-04-11 13:48:201504 if (extension && !IsCorrectSyncType(*extension, type))
1505 return true;
[email protected]90310d92011-04-17 07:35:041506
1507 // Handle uninstalls first.
[email protected]3bdba0d2011-08-23 07:17:301508 if (extension_sync_data.uninstalled()) {
[email protected]90310d92011-04-17 07:35:041509 std::string error;
1510 if (!UninstallExtensionHelper(this, id)) {
1511 LOG(WARNING) << "Could not uninstall extension " << id
1512 << " for sync";
1513 }
[email protected]5db9ada2012-04-11 13:48:201514 return true;
[email protected]90310d92011-04-17 07:35:041515 }
1516
[email protected]caf2d442012-05-04 10:00:501517 // Extension from sync was uninstalled by the user as external extensions.
1518 // Honor user choice and skip installation/enabling.
1519 if (IsExternalExtensionUninstalled(id)) {
1520 LOG(WARNING) << "Extension with id " << id
1521 << " from sync was uninstalled as external extension";
1522 return true;
1523 }
1524
[email protected]06f92562011-04-29 19:27:311525 // Set user settings.
[email protected]7e9e2422012-12-13 19:54:191526 // If the extension has been disabled from sync, it may not have
1527 // been installed yet, so we don't know if the disable reason was a
1528 // permissions increase. That will be updated once InitializePermissions
1529 // is called for it.
[email protected]31bb5ee62012-09-12 22:58:401530 if (extension_sync_data.enabled())
[email protected]06f92562011-04-29 19:27:311531 EnableExtension(id);
[email protected]31bb5ee62012-09-12 22:58:401532 else
[email protected]7e9e2422012-12-13 19:54:191533 DisableExtension(id, Extension::DISABLE_UNKNOWN_FROM_SYNC);
[email protected]81b14cc2011-04-29 00:39:371534
[email protected]406b5a92011-11-08 11:58:261535 // We need to cache some version information here because setting the
1536 // incognito flag invalidates the |extension| pointer (it reloads the
1537 // extension).
[email protected]9060d8b02012-01-13 02:14:301538 bool extension_installed = (extension != NULL);
[email protected]406b5a92011-11-08 11:58:261539 int result = extension ?
1540 extension->version()->CompareTo(extension_sync_data.version()) : 0;
1541 SetIsIncognitoEnabled(id, extension_sync_data.incognito_enabled());
1542 extension = NULL; // No longer safe to use.
1543
1544 if (extension_installed) {
[email protected]06f92562011-04-29 19:27:311545 // If the extension is already installed, check if it's outdated.
[email protected]90310d92011-04-17 07:35:041546 if (result < 0) {
1547 // Extension is outdated.
[email protected]5db9ada2012-04-11 13:48:201548 return false;
[email protected]b020dc12011-12-06 04:35:421549 }
[email protected]06f92562011-04-29 19:27:311550 } else {
[email protected]06f92562011-04-29 19:27:311551 // TODO(akalin): Replace silent update with a list of enabled
1552 // permissions.
[email protected]6cc7dbae2011-04-29 21:18:331553 const bool kInstallSilently = true;
[email protected]5db9ada2012-04-11 13:48:201554
[email protected]a4a147652012-07-03 23:41:321555 CHECK(type == syncer::EXTENSIONS || type == syncer::APPS);
[email protected]5db9ada2012-04-11 13:48:201556 ExtensionFilter filter =
[email protected]a4a147652012-07-03 23:41:321557 (type == syncer::APPS) ? IsSyncableApp : IsSyncableExtension;
[email protected]5db9ada2012-04-11 13:48:201558
[email protected]06f92562011-04-29 19:27:311559 if (!pending_extension_manager()->AddFromSync(
1560 id,
[email protected]3bdba0d2011-08-23 07:17:301561 extension_sync_data.update_url(),
[email protected]5db9ada2012-04-11 13:48:201562 filter,
[email protected]6cc7dbae2011-04-29 21:18:331563 kInstallSilently)) {
[email protected]06f92562011-04-29 19:27:311564 LOG(WARNING) << "Could not add pending extension for " << id;
[email protected]3bdba0d2011-08-23 07:17:301565 // This means that the extension is already pending installation, with a
1566 // non-INTERNAL location. Add to pending_sync_data, even though it will
1567 // never be removed (we'll never install a syncable version of the
1568 // extension), so that GetAllSyncData() continues to send it.
[email protected]06f92562011-04-29 19:27:311569 }
[email protected]3bdba0d2011-08-23 07:17:301570 // Track pending extensions so that we can return them in GetAllSyncData().
[email protected]5db9ada2012-04-11 13:48:201571 return false;
[email protected]90310d92011-04-17 07:35:041572 }
[email protected]5db9ada2012-04-11 13:48:201573
1574 return true;
[email protected]90310d92011-04-17 07:35:041575}
1576
[email protected]c3cfb012011-04-06 22:07:351577bool ExtensionService::IsIncognitoEnabled(
1578 const std::string& extension_id) const {
[email protected]cdc7b1f42012-12-07 19:39:481579 const Extension* extension = GetInstalledExtension(extension_id);
1580 if (extension && !extension->can_be_incognito_enabled())
1581 return false;
[email protected]c3cfb012011-04-06 22:07:351582 // If this is an existing component extension we always allow it to
1583 // work in incognito mode.
[email protected]c3cfb012011-04-06 22:07:351584 if (extension && extension->location() == Extension::COMPONENT)
[email protected]cb0ce1e022010-03-10 19:54:411585 return true;
1586
1587 // Check the prefs.
[email protected]c3cfb012011-04-06 22:07:351588 return extension_prefs_->IsIncognitoEnabled(extension_id);
[email protected]db7331a2010-02-25 22:10:501589}
[email protected]55a35692010-02-11 23:25:211590
[email protected]c3cfb012011-04-06 22:07:351591void ExtensionService::SetIsIncognitoEnabled(
1592 const std::string& extension_id, bool enabled) {
[email protected]81b14cc2011-04-29 00:39:371593 const Extension* extension = GetInstalledExtension(extension_id);
[email protected]cdc7b1f42012-12-07 19:39:481594 if (extension && !extension->can_be_incognito_enabled())
1595 return;
[email protected]c3cfb012011-04-06 22:07:351596 if (extension && extension->location() == Extension::COMPONENT) {
[email protected]b873cd92012-02-09 21:51:481597 // This shouldn't be called for component extensions unless they are
1598 // syncable.
1599 DCHECK(extension->IsSyncable());
1600
1601 // If we are here, make sure the we aren't trying to change the value.
1602 DCHECK_EQ(enabled, IsIncognitoEnabled(extension_id));
1603
[email protected]c3cfb012011-04-06 22:07:351604 return;
1605 }
1606
[email protected]8c6c8c22011-03-09 12:52:341607 // Broadcast unloaded and loaded events to update browser state. Only bother
1608 // if the value changed and the extension is actually enabled, since there is
1609 // no UI otherwise.
[email protected]c3cfb012011-04-06 22:07:351610 bool old_enabled = extension_prefs_->IsIncognitoEnabled(extension_id);
[email protected]8c6c8c22011-03-09 12:52:341611 if (enabled == old_enabled)
1612 return;
1613
[email protected]c3cfb012011-04-06 22:07:351614 extension_prefs_->SetIsIncognitoEnabled(extension_id, enabled);
[email protected]81b14cc2011-04-29 00:39:371615
[email protected]ffbf3f12011-12-09 22:10:331616 bool extension_is_enabled = extensions_.Contains(extension_id);
[email protected]bd9892eb2011-11-11 19:41:341617
1618 // When we reload the extension the ID may be invalidated if we've passed it
1619 // by const ref everywhere. Make a copy to be safe.
1620 std::string id = extension_id;
[email protected]406b5a92011-11-08 11:58:261621 if (extension_is_enabled)
[email protected]ffbf3f12011-12-09 22:10:331622 ReloadExtension(id);
[email protected]3bdba0d2011-08-23 07:17:301623
[email protected]406b5a92011-11-08 11:58:261624 // Reloading the extension invalidates the |extension| pointer.
[email protected]bd9892eb2011-11-11 19:41:341625 extension = GetInstalledExtension(id);
[email protected]3bdba0d2011-08-23 07:17:301626 if (extension)
1627 SyncExtensionChangeIfNeeded(*extension);
[email protected]55a35692010-02-11 23:25:211628}
1629
[email protected]aa7599d2011-10-28 07:24:321630void ExtensionService::SetAppNotificationSetupDone(
1631 const std::string& extension_id,
[email protected]b2689a902011-12-01 00:41:091632 const std::string& oauth_client_id) {
[email protected]aa7599d2011-10-28 07:24:321633 const Extension* extension = GetInstalledExtension(extension_id);
1634 // This method is called when the user sets up app notifications.
1635 // So it is not expected to be called until the extension is installed.
1636 if (!extension) {
1637 NOTREACHED();
1638 return;
1639 }
[email protected]b2689a902011-12-01 00:41:091640 extension_prefs_->SetAppNotificationClientId(extension_id, oauth_client_id);
[email protected]aa7599d2011-10-28 07:24:321641 SyncExtensionChangeIfNeeded(*extension);
1642}
1643
1644void ExtensionService::SetAppNotificationDisabled(
1645 const std::string& extension_id,
1646 bool value) {
1647 const Extension* extension = GetInstalledExtension(extension_id);
1648 // This method is called when the user enables/disables app notifications.
1649 // So it is not expected to be called until the extension is installed.
1650 if (!extension) {
1651 NOTREACHED();
1652 return;
1653 }
[email protected]97e856b12011-12-14 00:21:131654 if (value)
1655 UMA_HISTOGRAM_COUNTS("Apps.SetAppNotificationsDisabled", 1);
1656 else
1657 UMA_HISTOGRAM_COUNTS("Apps.SetAppNotificationsEnabled", 1);
[email protected]aa7599d2011-10-28 07:24:321658 extension_prefs_->SetAppNotificationDisabled(extension_id, value);
1659 SyncExtensionChangeIfNeeded(*extension);
1660}
1661
[email protected]dc9a74f72012-08-17 18:07:211662bool ExtensionService::CanCrossIncognito(const Extension* extension) const {
[email protected]2a8f24e2010-11-03 21:37:051663 // We allow the extension to see events and data from another profile iff it
1664 // uses "spanning" behavior and it has incognito access. "split" mode
1665 // extensions only see events for a matching profile.
[email protected]0c41298f2011-09-13 21:17:221666 CHECK(extension);
[email protected]c3cfb012011-04-06 22:07:351667 return IsIncognitoEnabled(extension->id()) &&
1668 !extension->incognito_split_mode();
[email protected]2a8f24e2010-11-03 21:37:051669}
1670
[email protected]5ef7b002011-05-12 23:16:201671bool ExtensionService::CanLoadInIncognito(const Extension* extension) const {
1672 if (extension->is_hosted_app())
1673 return true;
1674 // Packaged apps and regular extensions need to be enabled specifically for
1675 // incognito (and split mode should be set).
1676 return extension->incognito_split_mode() &&
1677 IsIncognitoEnabled(extension->id());
1678}
1679
[email protected]168389f2011-12-20 17:12:481680void ExtensionService::OnExtensionMoved(
1681 const std::string& moved_extension_id,
1682 const std::string& predecessor_extension_id,
1683 const std::string& successor_extension_id) {
[email protected]3569b502012-01-12 20:08:231684 extension_prefs_->extension_sorting()->OnExtensionMoved(
1685 moved_extension_id,
1686 predecessor_extension_id,
1687 successor_extension_id);
[email protected]168389f2011-12-20 17:12:481688
1689 const Extension* extension = GetInstalledExtension(moved_extension_id);
1690 if (extension)
1691 SyncExtensionChangeIfNeeded(*extension);
1692}
1693
[email protected]dc9a74f72012-08-17 18:07:211694bool ExtensionService::AllowFileAccess(const Extension* extension) const {
[email protected]05c82182010-06-24 17:49:081695 return (CommandLine::ForCurrentProcess()->HasSwitch(
[email protected]334e04a2010-06-24 23:34:441696 switches::kDisableExtensionsFileAccessCheck) ||
[email protected]05c82182010-06-24 17:49:081697 extension_prefs_->AllowFileAccess(extension->id()));
1698}
1699
[email protected]eaa7dd182010-12-14 11:09:001700void ExtensionService::SetAllowFileAccess(const Extension* extension,
[email protected]3aff9ad2011-04-01 20:26:481701 bool allow) {
1702 // Reload to update browser state. Only bother if the value changed and the
1703 // extension is actually enabled, since there is no UI otherwise.
1704 bool old_allow = AllowFileAccess(extension);
1705 if (allow == old_allow)
1706 return;
1707
[email protected]05c82182010-06-24 17:49:081708 extension_prefs_->SetAllowFileAccess(extension->id(), allow);
[email protected]3aff9ad2011-04-01 20:26:481709
[email protected]84df8332011-12-06 18:22:461710 bool extension_is_enabled = extensions_.Contains(extension->id());
[email protected]3aff9ad2011-04-01 20:26:481711 if (extension_is_enabled)
1712 ReloadExtension(extension->id());
[email protected]05c82182010-06-24 17:49:081713}
1714
[email protected]8e4560b62011-01-14 10:09:141715// Some extensions will autoupdate themselves externally from Chrome. These
1716// are typically part of some larger client application package. To support
1717// these, the extension will register its location in the the preferences file
1718// (and also, on Windows, in the registry) and this code will periodically
1719// check that location for a .crx file, which it will then install locally if
1720// a new version is available.
1721// Errors are reported through ExtensionErrorReporter. Succcess is not
1722// reported.
[email protected]eaa7dd182010-12-14 11:09:001723void ExtensionService::CheckForExternalUpdates() {
[email protected]a29a517a2011-01-21 21:11:121724 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]8e4560b62011-01-14 10:09:141725
1726 // Note that this installation is intentionally silent (since it didn't
1727 // go through the front-end). Extensions that are registered in this
1728 // way are effectively considered 'pre-bundled', and so implicitly
1729 // trusted. In general, if something has HKLM or filesystem access,
1730 // they could install an extension manually themselves anyway.
[email protected]a29a517a2011-01-21 21:11:121731
[email protected]8e4560b62011-01-14 10:09:141732 // Ask each external extension provider to give us a call back for each
1733 // extension they know about. See OnExternalExtension(File|UpdateUrl)Found.
[email protected]5df038b2012-07-16 19:03:271734 extensions::ProviderCollection::const_iterator i;
[email protected]8e4560b62011-01-14 10:09:141735 for (i = external_extension_providers_.begin();
1736 i != external_extension_providers_.end(); ++i) {
[email protected]5df038b2012-07-16 19:03:271737 extensions::ExternalProviderInterface* provider = i->get();
[email protected]8e4560b62011-01-14 10:09:141738 provider->VisitRegisteredExtension();
1739 }
1740
[email protected]50067e52011-10-20 23:17:071741 // Do any required work that we would have done after completion of all
1742 // providers.
1743 if (external_extension_providers_.empty()) {
1744 OnAllExternalProvidersReady();
1745 }
[email protected]9f1087e2009-06-15 17:29:321746}
1747
[email protected]50067e52011-10-20 23:17:071748void ExtensionService::OnExternalProviderReady(
[email protected]5df038b2012-07-16 19:03:271749 const extensions::ExternalProviderInterface* provider) {
[email protected]a29a517a2011-01-21 21:11:121750 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]50067e52011-10-20 23:17:071751 CHECK(provider->IsReady());
[email protected]a29a517a2011-01-21 21:11:121752
1753 // An external provider has finished loading. We only take action
[email protected]8e4560b62011-01-14 10:09:141754 // if all of them are finished. So we check them first.
[email protected]94fde232012-04-27 10:22:301755 if (AreAllExternalProvidersReady())
1756 OnAllExternalProvidersReady();
1757}
1758
1759bool ExtensionService::AreAllExternalProvidersReady() const {
[email protected]5df038b2012-07-16 19:03:271760 extensions::ProviderCollection::const_iterator i;
[email protected]8e4560b62011-01-14 10:09:141761 for (i = external_extension_providers_.begin();
1762 i != external_extension_providers_.end(); ++i) {
[email protected]94fde232012-04-27 10:22:301763 if (!i->get()->IsReady())
1764 return false;
[email protected]8e4560b62011-01-14 10:09:141765 }
[email protected]94fde232012-04-27 10:22:301766 return true;
[email protected]50067e52011-10-20 23:17:071767}
1768
1769void ExtensionService::OnAllExternalProvidersReady() {
1770 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]94fde232012-04-27 10:22:301771 base::TimeDelta elapsed = base::Time::Now() - profile_->GetStartTime();
1772 UMA_HISTOGRAM_TIMES("Extension.ExternalProvidersReadyAfter", elapsed);
[email protected]50067e52011-10-20 23:17:071773
1774 // Install any pending extensions.
[email protected]94fde232012-04-27 10:22:301775 if (update_once_all_providers_are_ready_ && updater()) {
1776 update_once_all_providers_are_ready_ = false;
[email protected]42774e42012-11-14 21:01:061777 updater()->CheckNow(extensions::ExtensionUpdater::CheckParams());
[email protected]8e4560b62011-01-14 10:09:141778 }
1779
1780 // Uninstall all the unclaimed extensions.
[email protected]45759612012-07-10 17:21:231781 scoped_ptr<extensions::ExtensionPrefs::ExtensionsInfo> extensions_info(
[email protected]8e4560b62011-01-14 10:09:141782 extension_prefs_->GetInstalledExtensionsInfo());
1783 for (size_t i = 0; i < extensions_info->size(); ++i) {
1784 ExtensionInfo* info = extensions_info->at(i).get();
1785 if (Extension::IsExternalLocation(info->extension_location))
1786 CheckExternalUninstall(info->extension_id);
1787 }
[email protected]e5af875f2011-10-10 21:09:141788 IdentifyAlertableExtensions();
[email protected]e5af875f2011-10-10 21:09:141789}
1790
1791void ExtensionService::IdentifyAlertableExtensions() {
1792 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1793
[email protected]07c9f2f42012-02-29 18:45:221794 // Build up the lists of extensions that require acknowledgment. If this is
1795 // the first time, grandfather extensions that would have caused
1796 // notification.
[email protected]89226982012-07-16 20:09:181797 extension_error_ui_.reset(ExtensionErrorUI::Create(this));
[email protected]e5af875f2011-10-10 21:09:141798
[email protected]a9aa5932012-01-25 08:27:401799 bool did_show_alert = false;
[email protected]89226982012-07-16 20:09:181800 if (PopulateExtensionErrorUI(extension_error_ui_.get())) {
[email protected]e5af875f2011-10-10 21:09:141801 if (extension_prefs_->SetAlertSystemFirstRun()) {
[email protected]a9aa5932012-01-25 08:27:401802 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]89226982012-07-16 20:09:181803 did_show_alert = extension_error_ui_->ShowErrorInBubbleView();
[email protected]e5af875f2011-10-10 21:09:141804 } else {
1805 // First run. Just acknowledge all the extensions, silently, by
1806 // shortcutting the display of the UI and going straight to the
1807 // callback for pressing the Accept button.
[email protected]a9aa5932012-01-25 08:27:401808 HandleExtensionAlertAccept();
[email protected]e5af875f2011-10-10 21:09:141809 }
1810 }
[email protected]a9aa5932012-01-25 08:27:401811
[email protected]612a1cb12012-10-17 13:18:031812 UpdateExternalExtensionAlert();
1813
[email protected]a9aa5932012-01-25 08:27:401814 if (!did_show_alert)
[email protected]89226982012-07-16 20:09:181815 extension_error_ui_.reset();
[email protected]e5af875f2011-10-10 21:09:141816}
1817
[email protected]89226982012-07-16 20:09:181818bool ExtensionService::PopulateExtensionErrorUI(
1819 ExtensionErrorUI* extension_error_ui) {
[email protected]07c9f2f42012-02-29 18:45:221820 bool needs_alert = false;
[email protected]695b5712012-12-06 23:55:281821
1822 // Extensions that are blacklisted.
1823 for (ExtensionSet::const_iterator it = blacklisted_extensions_.begin();
1824 it != blacklisted_extensions_.end(); ++it) {
1825 std::string id = (*it)->id();
1826 if (!extension_prefs_->IsBlacklistedExtensionAcknowledged(id)) {
1827 extension_error_ui->AddBlacklistedExtension(id);
1828 needs_alert = true;
1829 }
1830 }
1831
[email protected]07c9f2f42012-02-29 18:45:221832 for (ExtensionSet::const_iterator iter = extensions_.begin();
1833 iter != extensions_.end(); ++iter) {
1834 const Extension* e = *iter;
[email protected]695b5712012-12-06 23:55:281835
1836 // Extensions disabled by policy. Note: this no longer includes blacklisted
1837 // extensions, though we still show the same UI.
[email protected]fdd679b2012-11-15 20:49:391838 if (!system_->management_policy()->UserMayLoad(e, NULL)) {
[email protected]07c9f2f42012-02-29 18:45:221839 if (!extension_prefs_->IsBlacklistedExtensionAcknowledged(e->id())) {
[email protected]89226982012-07-16 20:09:181840 extension_error_ui->AddBlacklistedExtension(e->id());
[email protected]07c9f2f42012-02-29 18:45:221841 needs_alert = true;
1842 }
1843 }
[email protected]695b5712012-12-06 23:55:281844
1845 // Orphaned extensions.
[email protected]07c9f2f42012-02-29 18:45:221846 if (extension_prefs_->IsExtensionOrphaned(e->id())) {
1847 if (!extension_prefs_->IsOrphanedExtensionAcknowledged(e->id())) {
[email protected]89226982012-07-16 20:09:181848 extension_error_ui->AddOrphanedExtension(e->id());
[email protected]07c9f2f42012-02-29 18:45:221849 needs_alert = true;
1850 }
1851 }
1852 }
[email protected]695b5712012-12-06 23:55:281853
[email protected]07c9f2f42012-02-29 18:45:221854 return needs_alert;
1855}
1856
[email protected]a9aa5932012-01-25 08:27:401857void ExtensionService::HandleExtensionAlertClosed() {
[email protected]89226982012-07-16 20:09:181858 extension_error_ui_.reset();
[email protected]62433d32011-10-12 22:33:121859}
1860
[email protected]a9aa5932012-01-25 08:27:401861void ExtensionService::HandleExtensionAlertAccept() {
[email protected]612a1cb12012-10-17 13:18:031862 const ExtensionIdSet* extension_ids =
1863 extension_error_ui_->get_blacklisted_extension_ids();
[email protected]e5af875f2011-10-10 21:09:141864 for (ExtensionIdSet::const_iterator iter = extension_ids->begin();
1865 iter != extension_ids->end(); ++iter) {
1866 extension_prefs_->AcknowledgeBlacklistedExtension(*iter);
1867 }
[email protected]89226982012-07-16 20:09:181868 extension_ids = extension_error_ui_->get_orphaned_extension_ids();
[email protected]e5af875f2011-10-10 21:09:141869 for (ExtensionIdSet::const_iterator iter = extension_ids->begin();
1870 iter != extension_ids->end(); ++iter) {
1871 extension_prefs_->AcknowledgeOrphanedExtension(*iter);
1872 }
1873}
1874
[email protected]47fc70c2011-12-06 07:29:511875void ExtensionService::AcknowledgeExternalExtension(const std::string& id) {
1876 extension_prefs_->AcknowledgeExternalExtension(id);
[email protected]612a1cb12012-10-17 13:18:031877 UpdateExternalExtensionAlert();
[email protected]47fc70c2011-12-06 07:29:511878}
1879
[email protected]d96eb512012-11-01 23:44:081880bool ExtensionService::IsUnacknowledgedExternalExtension(
1881 const Extension* extension) {
[email protected]b82d18da2012-11-09 00:11:321882 if (!FeatureSwitch::prompt_for_external_extensions()->IsEnabled())
1883 return false;
1884
[email protected]d96eb512012-11-01 23:44:081885 return (Extension::IsExternalLocation(extension->location()) &&
1886 !extension_prefs_->IsExternalExtensionAcknowledged(extension->id()) &&
1887 !(extension_prefs_->GetDisableReasons(extension->id()) &
1888 Extension::DISABLE_SIDELOAD_WIPEOUT));
1889}
1890
[email protected]89226982012-07-16 20:09:181891void ExtensionService::HandleExtensionAlertDetails() {
1892 extension_error_ui_->ShowExtensions();
[email protected]6c751e72010-11-23 10:11:101893}
1894
[email protected]612a1cb12012-10-17 13:18:031895void ExtensionService::UpdateExternalExtensionAlert() {
[email protected]41070e8d2012-10-24 01:34:361896 if (!FeatureSwitch::prompt_for_external_extensions()->IsEnabled())
[email protected]612a1cb12012-10-17 13:18:031897 return;
1898
1899 const Extension* extension = NULL;
1900 for (ExtensionSet::const_iterator iter = disabled_extensions_.begin();
1901 iter != disabled_extensions_.end(); ++iter) {
1902 const Extension* e = *iter;
[email protected]d96eb512012-11-01 23:44:081903 if (IsUnacknowledgedExternalExtension(e)) {
1904 extension = e;
1905 break;
[email protected]612a1cb12012-10-17 13:18:031906 }
1907 }
1908
1909 if (extension) {
[email protected]d96eb512012-11-01 23:44:081910 if (!extensions::HasExternalInstallError(this)) {
1911 if (extension_prefs_->IncrementAcknowledgePromptCount(extension->id()) >
[email protected]612a1cb12012-10-17 13:18:031912 kMaxExtensionAcknowledgePromptCount) {
[email protected]d96eb512012-11-01 23:44:081913 // Stop prompting for this extension, and check if there's another
1914 // one that needs prompting.
[email protected]612a1cb12012-10-17 13:18:031915 extension_prefs_->AcknowledgeExternalExtension(extension->id());
[email protected]d96eb512012-11-01 23:44:081916 UpdateExternalExtensionAlert();
1917 UMA_HISTOGRAM_ENUMERATION("Extensions.ExternalExtensionEvent",
1918 EXTERNAL_EXTENSION_IGNORED,
1919 EXTERNAL_EXTENSION_BUCKET_BOUNDARY);
1920 return;
[email protected]612a1cb12012-10-17 13:18:031921 }
[email protected]d96eb512012-11-01 23:44:081922 extensions::AddExternalInstallError(this, extension);
[email protected]612a1cb12012-10-17 13:18:031923 }
1924 } else {
1925 extensions::RemoveExternalInstallError(this);
1926 }
[email protected]612a1cb12012-10-17 13:18:031927}
1928
[email protected]a9f39a312010-12-23 22:14:271929void ExtensionService::UnloadExtension(
1930 const std::string& extension_id,
[email protected]814a7bf0f2011-08-13 05:30:591931 extension_misc::UnloadedExtensionReason reason) {
[email protected]27e469a2010-01-11 20:35:091932 // Make sure the extension gets deleted after we return from this function.
[email protected]695b5712012-12-06 23:55:281933 int include_mask = INCLUDE_EVERYTHING & ~INCLUDE_TERMINATED;
[email protected]9adb9692010-10-29 23:14:021934 scoped_refptr<const Extension> extension(
[email protected]695b5712012-12-06 23:55:281935 GetExtensionById(extension_id, include_mask));
[email protected]631cf822009-05-15 07:01:251936
[email protected]fa0c96732010-11-17 00:14:231937 // This method can be called via PostTask, so the extension may have been
1938 // unloaded by the time this runs.
[email protected]dd163fb02011-05-04 22:22:171939 if (!extension) {
1940 // In case the extension may have crashed/uninstalled. Allow the profile to
1941 // clean up its RequestContexts.
[email protected]31d8f5f22012-04-02 15:22:081942 system_->UnregisterExtensionWithRequestContexts(extension_id, reason);
[email protected]fa0c96732010-11-17 00:14:231943 return;
[email protected]dd163fb02011-05-04 22:22:171944 }
[email protected]0c6da502009-08-14 22:32:391945
[email protected]1eb175082010-02-10 09:26:161946 // Keep information about the extension so that we can reload it later
1947 // even if it's not permanently installed.
1948 unloaded_extension_paths_[extension->id()] = extension->path();
1949
[email protected]f17dbd42010-08-16 23:21:101950 // Clean up if the extension is meant to be enabled after a reload.
1951 disabled_extension_paths_.erase(extension->id());
1952
[email protected]d7e9a862010-11-03 21:57:491953 // Clean up runtime data.
1954 extension_runtime_data_.erase(extension_id);
1955
[email protected]060d4972012-07-19 17:22:391956 if (disabled_extensions_.Contains(extension->id())) {
[email protected]a9f39a312010-12-23 22:14:271957 UnloadedExtensionInfo details(extension, reason);
1958 details.already_disabled = true;
[email protected]84df8332011-12-06 18:22:461959 disabled_extensions_.Remove(extension->id());
[email protected]ad50def52011-10-19 23:17:071960 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271961 chrome::NOTIFICATION_EXTENSION_UNLOADED,
[email protected]6c2381d2011-10-19 02:52:531962 content::Source<Profile>(profile_),
1963 content::Details<UnloadedExtensionInfo>(&details));
[email protected]dd163fb02011-05-04 22:22:171964 // Make sure the profile cleans up its RequestContexts when an already
1965 // disabled extension is unloaded (since they are also tracking the disabled
1966 // extensions).
[email protected]31d8f5f22012-04-02 15:22:081967 system_->UnregisterExtensionWithRequestContexts(extension_id, reason);
[email protected]0c6da502009-08-14 22:32:391968 return;
1969 }
1970
[email protected]060d4972012-07-19 17:22:391971 // Remove the extension from our list.
[email protected]84df8332011-12-06 18:22:461972 extensions_.Remove(extension->id());
[email protected]631cf822009-05-15 07:01:251973
[email protected]a9f39a312010-12-23 22:14:271974 NotifyExtensionUnloaded(extension.get(), reason);
[email protected]631cf822009-05-15 07:01:251975}
1976
[email protected]eaa7dd182010-12-14 11:09:001977void ExtensionService::UnloadAllExtensions() {
[email protected]31bb5ee62012-09-12 22:58:401978 profile_->GetExtensionSpecialStoragePolicy()->RevokeRightsForAllExtensions();
[email protected]c8d407e2011-04-28 21:27:171979
[email protected]84df8332011-12-06 18:22:461980 extensions_.Clear();
1981 disabled_extensions_.Clear();
1982 terminated_extensions_.Clear();
[email protected]d7e9a862010-11-03 21:57:491983 extension_runtime_data_.clear();
[email protected]cd500f72010-06-25 23:44:321984
[email protected]c6e4a3412009-06-24 15:45:291985 // TODO(erikkay) should there be a notification for this? We can't use
1986 // EXTENSION_UNLOADED since that implies that the extension has been disabled
1987 // or uninstalled, and UnloadAll is just part of shutdown.
[email protected]9f1087e2009-06-15 17:29:321988}
1989
[email protected]eaa7dd182010-12-14 11:09:001990void ExtensionService::ReloadExtensions() {
[email protected]9f1087e2009-06-15 17:29:321991 UnloadAllExtensions();
[email protected]eac88332012-12-26 17:57:451992 component_loader_->LoadAll();
[email protected]d8c8f25f2011-11-02 18:18:011993 extensions::InstalledLoader(this).LoadAllExtensions();
[email protected]9f1087e2009-06-15 17:29:321994}
1995
[email protected]eaa7dd182010-12-14 11:09:001996void ExtensionService::GarbageCollectExtensions() {
[email protected]2f8757c32012-06-19 19:17:471997 if (extension_prefs_->pref_service()->ReadOnly())
1998 return;
1999
[email protected]9bd9a6862012-11-29 09:24:222000 if (pending_extension_manager()->HasPendingExtensions()) {
2001 // Don't garbage collect while there are pending installations, which may
2002 // be using the temporary installation directory. Try to garbage collect
2003 // again later.
2004 MessageLoop::current()->PostDelayedTask(
2005 FROM_HERE,
2006 base::Bind(&ExtensionService::GarbageCollectExtensions, AsWeakPtr()),
2007 base::TimeDelta::FromSeconds(kGarbageCollectRetryDelay));
2008 return;
2009 }
2010
[email protected]45759612012-07-10 17:21:232011 scoped_ptr<extensions::ExtensionPrefs::ExtensionsInfo> info(
[email protected]2f8757c32012-06-19 19:17:472012 extension_prefs_->GetInstalledExtensionsInfo());
2013
[email protected]0db124b02012-11-07 04:55:052014 std::multimap<std::string, FilePath> extension_paths;
[email protected]2f8757c32012-06-19 19:17:472015 for (size_t i = 0; i < info->size(); ++i)
[email protected]0db124b02012-11-07 04:55:052016 extension_paths.insert(std::make_pair(info->at(i)->extension_id,
2017 info->at(i)->extension_path));
2018
[email protected]399583b2012-12-11 09:33:422019 info = extension_prefs_->GetAllDelayedInstallInfo();
[email protected]0db124b02012-11-07 04:55:052020 for (size_t i = 0; i < info->size(); ++i)
2021 extension_paths.insert(std::make_pair(info->at(i)->extension_id,
2022 info->at(i)->extension_path));
[email protected]2f8757c32012-06-19 19:17:472023
[email protected]7f8f24f2012-11-15 19:40:142024 if (!GetFileTaskRunner()->PostTask(
2025 FROM_HERE,
[email protected]2f8757c32012-06-19 19:17:472026 base::Bind(
2027 &extension_file_util::GarbageCollectExtensions,
2028 install_directory_,
[email protected]31bb5ee62012-09-12 22:58:402029 extension_paths))) {
[email protected]2f8757c32012-06-19 19:17:472030 NOTREACHED();
[email protected]31bb5ee62012-09-12 22:58:402031 }
[email protected]f6ccd652010-11-17 00:48:342032
[email protected]f766a9d2012-07-11 01:57:442033#if defined(ENABLE_THEMES)
[email protected]f6ccd652010-11-17 00:48:342034 // Also garbage-collect themes. We check |profile_| to be
2035 // defensive; in the future, we may call GarbageCollectExtensions()
2036 // from somewhere other than Init() (e.g., in a timer).
2037 if (profile_) {
[email protected]d5949312012-12-03 22:13:302038 ThemeServiceFactory::GetForProfile(profile_)->RemoveUnusedThemes();
[email protected]f6ccd652010-11-17 00:48:342039 }
[email protected]f766a9d2012-07-11 01:57:442040#endif
[email protected]3cf4f0992009-02-03 23:00:302041}
2042
[email protected]fb82dcd2012-03-21 14:15:462043void ExtensionService::SyncExtensionChangeIfNeeded(const Extension& extension) {
[email protected]5db9ada2012-04-11 13:48:202044 if (app_sync_bundle_.HandlesApp(extension)) {
2045 app_sync_bundle_.SyncChangeIfNeeded(extension);
2046 } else if (extension_sync_bundle_.HandlesExtension(extension)) {
2047 extension_sync_bundle_.SyncChangeIfNeeded(extension);
[email protected]fb82dcd2012-03-21 14:15:462048 }
2049}
2050
[email protected]eaa7dd182010-12-14 11:09:002051void ExtensionService::OnLoadedInstalledExtensions() {
[email protected]31bb5ee62012-09-12 22:58:402052 if (updater_.get())
[email protected]93fd78f42009-07-10 16:43:172053 updater_->Start();
[email protected]fa6a9102010-11-22 15:38:502054
2055 ready_ = true;
[email protected]ad50def52011-10-19 23:17:072056 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:272057 chrome::NOTIFICATION_EXTENSIONS_READY,
[email protected]6c2381d2011-10-19 02:52:532058 content::Source<Profile>(profile_),
[email protected]ad50def52011-10-19 23:17:072059 content::NotificationService::NoDetails());
[email protected]e72e8eb82009-06-18 17:21:512060}
2061
[email protected]fcb58a862012-05-01 01:03:152062void ExtensionService::AddExtension(const Extension* extension) {
[email protected]c8d407e2011-04-28 21:27:172063 // TODO(jstritar): We may be able to get rid of this branch by overriding the
2064 // default extension state to DISABLED when the --disable-extensions flag
2065 // is set (http://crbug.com/29067).
2066 if (!extensions_enabled() &&
2067 !extension->is_theme() &&
2068 extension->location() != Extension::COMPONENT &&
[email protected]330840c2012-08-29 22:21:012069 !Extension::IsExternalLocation(extension->location())) {
[email protected]fcb58a862012-05-01 01:03:152070 return;
[email protected]330840c2012-08-29 22:21:012071 }
[email protected]c8d407e2011-04-28 21:27:172072
2073 SetBeingUpgraded(extension, false);
2074
[email protected]1eb175082010-02-10 09:26:162075 // The extension is now loaded, remove its data from unloaded extension map.
2076 unloaded_extension_paths_.erase(extension->id());
2077
[email protected]bb7f40952011-01-13 00:21:202078 // If a terminated extension is loaded, remove it from the terminated list.
2079 UntrackTerminatedExtension(extension->id());
2080
[email protected]f17dbd42010-08-16 23:21:102081 // If the extension was disabled for a reload, then enable it.
2082 if (disabled_extension_paths_.erase(extension->id()) > 0)
2083 EnableExtension(extension->id());
2084
[email protected]d728e002010-12-08 04:46:232085 // Check if the extension's privileges have changed and disable the
2086 // extension if necessary.
[email protected]902fd7b2011-07-27 18:42:312087 InitializePermissions(extension);
[email protected]0c6da502009-08-14 22:32:392088
[email protected]215a7be2012-10-22 19:53:422089 // If this extension is a sideloaded extension and we've not performed a
2090 // wipeout before, we might disable this extension here.
2091 MaybeWipeout(extension);
2092
[email protected]695b5712012-12-06 23:55:282093 // Communicated to the Blacklist.
2094 std::set<std::string> already_in_blacklist;
2095
2096 if (extension_prefs_->IsExtensionBlacklisted(extension->id())) {
2097 // Don't check the Blacklist yet because it's asynchronous (we do it at
2098 // the end). This pre-emptive check is because we will always store the
2099 // blacklisted state of *installed* extensions in prefs, and it's important
2100 // not to re-enable blacklisted extensions.
2101 blacklisted_extensions_.Insert(extension);
2102 already_in_blacklist.insert(extension->id());
2103 } else if (extension_prefs_->IsExtensionDisabled(extension->id())) {
[email protected]6f6101832012-11-27 22:10:482104 disabled_extensions_.Insert(extension);
[email protected]3bdba0d2011-08-23 07:17:302105 SyncExtensionChangeIfNeeded(*extension);
[email protected]44d62b62012-04-11 00:06:032106 content::NotificationService::current()->Notify(
2107 chrome::NOTIFICATION_EXTENSION_UPDATE_DISABLED,
2108 content::Source<Profile>(profile_),
2109 content::Details<const Extension>(extension));
[email protected]62f051c2012-03-29 17:04:442110
[email protected]7e9e2422012-12-13 19:54:192111 // Show the extension disabled error if a permissions increase was the
2112 // only reason it was disabled.
2113 if (extension_prefs_->GetDisableReasons(extension->id()) ==
[email protected]44d62b62012-04-11 00:06:032114 Extension::DISABLE_PERMISSIONS_INCREASE) {
[email protected]62f051c2012-03-29 17:04:442115 extensions::AddExtensionDisabledError(this, extension);
2116 }
[email protected]695b5712012-12-06 23:55:282117 } else {
2118 // All apps that are displayed in the launcher are ordered by their ordinals
2119 // so we must ensure they have valid ordinals.
2120 if (extension->RequiresSortOrdinal()) {
2121 extension_prefs_->extension_sorting()->EnsureValidOrdinals(
2122 extension->id(), syncer::StringOrdinal());
2123 }
2124
2125 extensions_.Insert(extension);
2126 SyncExtensionChangeIfNeeded(*extension);
2127 NotifyExtensionLoaded(extension);
2128 DoPostLoadTasks(extension);
[email protected]f574c402012-12-04 23:20:312129 }
2130
[email protected]695b5712012-12-06 23:55:282131 // Lastly, begin the process for checking the blacklist status of extensions.
2132 // This may need to go to other threads so is asynchronous.
2133 std::set<std::string> id_set;
2134 id_set.insert(extension->id());
2135 blacklist_->GetBlacklistedIDs(
2136 id_set,
2137 base::Bind(&ExtensionService::ManageBlacklist,
2138 AsWeakPtr(),
2139 already_in_blacklist));
[email protected]aab98a52009-12-02 03:22:352140}
2141
[email protected]8c484b742012-11-29 06:05:362142void ExtensionService::AddComponentExtension(const Extension* extension) {
2143 const std::string old_version_string(
2144 extension_prefs_->GetVersionString(extension->id()));
2145 const Version old_version(old_version_string);
2146
2147 if (!old_version.IsValid() || !old_version.Equals(*extension->version())) {
2148 VLOG(1) << "Component extension " << extension->name() << " ("
2149 << extension->id() << ") installing/upgrading from '"
2150 << old_version_string << "' to " << extension->version()->GetString();
2151
2152 AddNewOrUpdatedExtension(extension,
[email protected]399583b2012-12-11 09:33:422153 Extension::ENABLED_COMPONENT,
2154 syncer::StringOrdinal());
[email protected]8c484b742012-11-29 06:05:362155 return;
2156 }
2157
2158 AddExtension(extension);
2159}
2160
[email protected]902fd7b2011-07-27 18:42:312161void ExtensionService::InitializePermissions(const Extension* extension) {
2162 // If the extension has used the optional permissions API, it will have a
2163 // custom set of active permissions defined in the extension prefs. Here,
2164 // we update the extension's active permissions based on the prefs.
[email protected]c2e66e12012-06-27 06:27:062165 scoped_refptr<PermissionSet> active_permissions =
[email protected]902fd7b2011-07-27 18:42:312166 extension_prefs()->GetActivePermissions(extension->id());
2167
2168 if (active_permissions.get()) {
2169 // We restrict the active permissions to be within the bounds defined in the
2170 // extension's manifest.
2171 // a) active permissions must be a subset of optional + default permissions
2172 // b) active permissions must contains all default permissions
[email protected]c2e66e12012-06-27 06:27:062173 scoped_refptr<PermissionSet> total_permissions =
2174 PermissionSet::CreateUnion(
[email protected]902fd7b2011-07-27 18:42:312175 extension->required_permission_set(),
2176 extension->optional_permission_set());
2177
2178 // Make sure the active permissions contain no more than optional + default.
[email protected]c2e66e12012-06-27 06:27:062179 scoped_refptr<PermissionSet> adjusted_active =
2180 PermissionSet::CreateIntersection(
[email protected]902fd7b2011-07-27 18:42:312181 total_permissions.get(), active_permissions.get());
2182
2183 // Make sure the active permissions contain the default permissions.
[email protected]c2e66e12012-06-27 06:27:062184 adjusted_active = PermissionSet::CreateUnion(
[email protected]902fd7b2011-07-27 18:42:312185 extension->required_permission_set(), adjusted_active.get());
2186
[email protected]c333e792012-01-06 16:57:392187 extensions::PermissionsUpdater perms_updater(profile());
2188 perms_updater.UpdateActivePermissions(extension, adjusted_active);
[email protected]902fd7b2011-07-27 18:42:312189 }
2190
[email protected]8d888c12010-11-30 00:00:252191 // We keep track of all permissions the user has granted each extension.
2192 // This allows extensions to gracefully support backwards compatibility
2193 // by including unknown permissions in their manifests. When the user
2194 // installs the extension, only the recognized permissions are recorded.
2195 // When the unknown permissions become recognized (e.g., through browser
2196 // upgrade), we can prompt the user to accept these new permissions.
2197 // Extensions can also silently upgrade to less permissions, and then
2198 // silently upgrade to a version that adds these permissions back.
2199 //
2200 // For example, pretend that Chrome 10 includes a permission "omnibox"
2201 // for an API that adds suggestions to the omnibox. An extension can
2202 // maintain backwards compatibility while still having "omnibox" in the
2203 // manifest. If a user installs the extension on Chrome 9, the browser
2204 // will record the permissions it recognized, not including "omnibox."
2205 // When upgrading to Chrome 10, "omnibox" will be recognized and Chrome
2206 // will disable the extension and prompt the user to approve the increase
2207 // in privileges. The extension could then release a new version that
2208 // removes the "omnibox" permission. When the user upgrades, Chrome will
2209 // still remember that "omnibox" had been granted, so that if the
2210 // extension once again includes "omnibox" in an upgrade, the extension
2211 // can upgrade without requiring this user's approval.
[email protected]695b5712012-12-06 23:55:282212 const Extension* old = GetInstalledExtension(extension->id());
[email protected]8d888c12010-11-30 00:00:252213 bool is_extension_upgrade = old != NULL;
2214 bool is_privilege_increase = false;
[email protected]44d62b62012-04-11 00:06:032215 bool previously_disabled = false;
[email protected]eb5e4f92012-08-15 23:33:282216 int disable_reasons = extension_prefs_->GetDisableReasons(extension->id());
[email protected]8d888c12010-11-30 00:00:252217
[email protected]902fd7b2011-07-27 18:42:312218 // We only need to compare the granted permissions to the current permissions
2219 // if the extension is not allowed to silently increase its permissions.
[email protected]be083862012-09-01 03:53:452220 bool is_default_app_install =
2221 (!is_extension_upgrade && extension->was_installed_by_default());
2222 if (!(extension->CanSilentlyIncreasePermissions()
2223 || is_default_app_install)) {
[email protected]8d888c12010-11-30 00:00:252224 // Add all the recognized permissions if the granted permissions list
2225 // hasn't been initialized yet.
[email protected]c2e66e12012-06-27 06:27:062226 scoped_refptr<PermissionSet> granted_permissions =
[email protected]902fd7b2011-07-27 18:42:312227 extension_prefs_->GetGrantedPermissions(extension->id());
[email protected]0d3e4a22011-06-23 19:02:522228 CHECK(granted_permissions.get());
[email protected]8d888c12010-11-30 00:00:252229
2230 // Here, we check if an extension's privileges have increased in a manner
2231 // that requires the user's approval. This could occur because the browser
2232 // upgraded and recognized additional privileges, or an extension upgrades
2233 // to a version that requires additional privileges.
[email protected]0d3e4a22011-06-23 19:02:522234 is_privilege_increase =
[email protected]902fd7b2011-07-27 18:42:312235 granted_permissions->HasLessPrivilegesThan(
2236 extension->GetActivePermissions());
[email protected]8d888c12010-11-30 00:00:252237 }
2238
[email protected]be083862012-09-01 03:53:452239 // Silently grant all active permissions to default apps only on install.
2240 // After install they should behave like other apps.
[email protected]c856e9762012-10-12 19:42:382241 if (is_default_app_install)
2242 GrantPermissions(extension, true);
[email protected]be083862012-09-01 03:53:452243
[email protected]8d888c12010-11-30 00:00:252244 if (is_extension_upgrade) {
[email protected]66e26872010-12-03 20:07:252245 // Other than for unpacked extensions, CrxInstaller should have guaranteed
2246 // that we aren't downgrading.
2247 if (extension->location() != Extension::LOAD)
[email protected]31bb5ee62012-09-12 22:58:402248 CHECK_GE(extension->version()->CompareTo(*(old->version())), 0);
[email protected]8d888c12010-11-30 00:00:252249
2250 // Extensions get upgraded if the privileges are allowed to increase or
2251 // the privileges haven't increased.
2252 if (!is_privilege_increase) {
2253 SetBeingUpgraded(old, true);
2254 SetBeingUpgraded(extension, true);
2255 }
2256
[email protected]44d62b62012-04-11 00:06:032257 // If the extension was already disabled, suppress any alerts for becoming
2258 // disabled on permissions increase.
2259 previously_disabled = extension_prefs_->IsExtensionDisabled(old->id());
[email protected]7e9e2422012-12-13 19:54:192260 // Legacy disabled extensions do not have a disable reason. Infer that if
2261 // there was no permission increase, it was likely disabled by the user.
2262 if (previously_disabled && disable_reasons == Extension::DISABLE_NONE &&
2263 !extension_prefs_->DidExtensionEscalatePermissions(old->id())) {
2264 disable_reasons |= Extension::DISABLE_USER_ACTION;
[email protected]44d62b62012-04-11 00:06:032265 }
[email protected]7e9e2422012-12-13 19:54:192266 // Extensions that came to us disabled from sync need a similar inference,
2267 // except based on the new version's permissions.
2268 if (previously_disabled &&
2269 disable_reasons == Extension::DISABLE_UNKNOWN_FROM_SYNC) {
2270 // Remove the DISABLE_UNKNOWN_FROM_SYNC reason.
2271 extension_prefs_->ClearDisableReasons(extension->id());
2272 if (!is_privilege_increase)
2273 disable_reasons |= Extension::DISABLE_USER_ACTION;
2274 }
2275 if (disable_reasons != Extension::DISABLE_NONE)
2276 disable_reasons &= ~Extension::DISABLE_UNKNOWN_FROM_SYNC;
[email protected]44d62b62012-04-11 00:06:032277
[email protected]8d888c12010-11-30 00:00:252278 // To upgrade an extension in place, unload the old one and
2279 // then load the new one.
[email protected]814a7bf0f2011-08-13 05:30:592280 UnloadExtension(old->id(), extension_misc::UNLOAD_REASON_UPDATE);
[email protected]8d888c12010-11-30 00:00:252281 old = NULL;
2282 }
2283
2284 // Extension has changed permissions significantly. Disable it. A
2285 // notification should be sent by the caller.
2286 if (is_privilege_increase) {
[email protected]7e9e2422012-12-13 19:54:192287 disable_reasons |= Extension::DISABLE_PERMISSIONS_INCREASE;
[email protected]fe2dd7742011-04-19 22:52:492288 if (!extension_prefs_->DidExtensionEscalatePermissions(extension->id())) {
2289 RecordPermissionMessagesHistogram(
2290 extension, "Extensions.Permissions_AutoDisable");
2291 }
[email protected]b3317ad2011-04-28 23:46:002292 extension_prefs_->SetExtensionState(extension->id(), Extension::DISABLED);
[email protected]8d888c12010-11-30 00:00:252293 extension_prefs_->SetDidExtensionEscalatePermissions(extension, true);
[email protected]eb5e4f92012-08-15 23:33:282294 extension_prefs_->AddDisableReason(
2295 extension->id(),
2296 static_cast<Extension::DisableReason>(disable_reasons));
[email protected]8d888c12010-11-30 00:00:252297 }
2298}
2299
[email protected]215a7be2012-10-22 19:53:422300void ExtensionService::MaybeWipeout(
2301 const extensions::Extension* extension) {
[email protected]1ff4d282012-12-08 00:39:212302 if (!wipeout_is_active_)
[email protected]215a7be2012-10-22 19:53:422303 return;
2304
[email protected]1ff4d282012-12-08 00:39:212305 if (extension->GetType() != Extension::TYPE_EXTENSION)
[email protected]215a7be2012-10-22 19:53:422306 return;
2307
[email protected]1ff4d282012-12-08 00:39:212308 Extension::Location location = extension->location();
[email protected]eea97032012-12-14 00:16:182309 if (location != Extension::EXTERNAL_REGISTRY)
[email protected]1ff4d282012-12-08 00:39:212310 return;
2311
2312 if (extension_prefs_->IsExternalExtensionExcludedFromWipeout(extension->id()))
2313 return;
2314
[email protected]215a7be2012-10-22 19:53:422315 int disable_reasons = extension_prefs_->GetDisableReasons(extension->id());
[email protected]1ff4d282012-12-08 00:39:212316 if (disable_reasons == Extension::DISABLE_NONE) {
2317 extension_prefs_->SetExtensionState(extension->id(), Extension::DISABLED);
2318 extension_prefs_->AddDisableReason(
2319 extension->id(),
2320 static_cast<Extension::DisableReason>(
2321 Extension::DISABLE_SIDELOAD_WIPEOUT));
2322 UMA_HISTOGRAM_BOOLEAN("DisabledExtension.ExtensionWipedStatus", true);
[email protected]215a7be2012-10-22 19:53:422323 }
2324}
2325
[email protected]eaa7dd182010-12-14 11:09:002326void ExtensionService::UpdateActiveExtensionsInCrashReporter() {
[email protected]c8865962009-12-16 07:47:392327 std::set<std::string> extension_ids;
[email protected]84df8332011-12-06 18:22:462328 for (ExtensionSet::const_iterator iter = extensions_.begin();
2329 iter != extensions_.end(); ++iter) {
2330 const Extension* extension = *iter;
2331 if (!extension->is_theme() && extension->location() != Extension::COMPONENT)
2332 extension_ids.insert(extension->id());
[email protected]aab98a52009-12-02 03:22:352333 }
2334
2335 child_process_logging::SetActiveExtensions(extension_ids);
[email protected]6014d672008-12-05 00:38:252336}
2337
[email protected]8266d662011-07-12 21:53:262338void ExtensionService::OnExtensionInstalled(
[email protected]36a5c4c2011-12-14 16:34:502339 const Extension* extension,
[email protected]98270432012-09-11 20:51:242340 const syncer::StringOrdinal& page_ordinal,
[email protected]0db124b02012-11-07 04:55:052341 bool has_requirement_errors,
2342 bool wait_for_idle) {
[email protected]a29a517a2011-01-21 21:11:122343 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]a8af9fdb2010-10-28 21:52:202344
[email protected]c3cfb012011-04-06 22:07:352345 const std::string& id = extension->id();
[email protected]612a1cb12012-10-17 13:18:032346 bool initial_enable = ShouldEnableOnInstall(extension);
[email protected]3f213ad2012-07-26 23:39:412347 const extensions::PendingExtensionInfo* pending_extension_info = NULL;
[email protected]51a3bf8b2012-06-08 22:53:062348 if ((pending_extension_info = pending_extension_manager()->GetById(id))) {
2349 if (!pending_extension_info->ShouldAllowInstall(*extension)) {
2350 pending_extension_manager()->Remove(id);
[email protected]8ef78fd2010-08-19 17:14:322351
[email protected]31bb5ee62012-09-12 22:58:402352 LOG(WARNING) << "ShouldAllowInstall() returned false for "
2353 << id << " of type " << extension->GetType()
2354 << " and update URL " << extension->update_url().spec()
2355 << "; not installing";
[email protected]ae6cb3022011-04-04 20:11:542356
[email protected]ad50def52011-10-19 23:17:072357 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:272358 chrome::NOTIFICATION_EXTENSION_INSTALL_NOT_ALLOWED,
[email protected]6c2381d2011-10-19 02:52:532359 content::Source<Profile>(profile_),
2360 content::Details<const Extension>(extension));
[email protected]ae6cb3022011-04-04 20:11:542361
[email protected]4416c5a2010-06-26 01:28:572362 // Delete the extension directory since we're not going to
2363 // load it.
[email protected]7f8f24f2012-11-15 19:40:142364 if (!GetFileTaskRunner()->PostTask(
2365 FROM_HERE,
[email protected]53612e82011-10-18 18:00:362366 base::Bind(&extension_file_util::DeleteFile,
[email protected]31bb5ee62012-09-12 22:58:402367 extension->path(), true))) {
[email protected]14908b72011-04-20 06:54:362368 NOTREACHED();
[email protected]31bb5ee62012-09-12 22:58:402369 }
[email protected]4416c5a2010-06-26 01:28:572370 return;
2371 }
[email protected]51a3bf8b2012-06-08 22:53:062372
2373 pending_extension_manager()->Remove(id);
[email protected]4416c5a2010-06-26 01:28:572374 } else {
[email protected]c3cfb012011-04-06 22:07:352375 // We explicitly want to re-enable an uninstalled external
2376 // extension; if we're here, that means the user is manually
2377 // installing the extension.
[email protected]6cc7dbae2011-04-29 21:18:332378 if (IsExternalExtensionUninstalled(id)) {
2379 initial_enable = true;
2380 }
[email protected]aa142702010-03-26 01:26:332381 }
2382
[email protected]98270432012-09-11 20:51:242383 // Unsupported requirements overrides the management policy.
2384 if (has_requirement_errors) {
2385 initial_enable = false;
2386 extension_prefs_->AddDisableReason(
2387 id, Extension::DISABLE_UNSUPPORTED_REQUIREMENT);
2388 // If the extension was disabled because of unsupported requirements but
2389 // now supports all requirements after an update and there are not other
2390 // disable reasons, enable it.
2391 } else if (extension_prefs_->GetDisableReasons(id) ==
2392 Extension::DISABLE_UNSUPPORTED_REQUIREMENT) {
2393 initial_enable = true;
2394 extension_prefs_->ClearDisableReasons(id);
2395 }
2396
[email protected]695b5712012-12-06 23:55:282397 if (!GetInstalledExtension(extension->id())) {
[email protected]07533022011-06-27 20:42:552398 UMA_HISTOGRAM_ENUMERATION("Extensions.InstallType",
2399 extension->GetType(), 100);
[email protected]69084dc2012-11-17 07:39:302400 UMA_HISTOGRAM_ENUMERATION("Extensions.InstallSource",
2401 extension->location(), Extension::NUM_LOCATIONS);
[email protected]07533022011-06-27 20:42:552402 RecordPermissionMessagesHistogram(
2403 extension, "Extensions.Permissions_Install");
[email protected]69084dc2012-11-17 07:39:302404 } else {
2405 UMA_HISTOGRAM_ENUMERATION("Extensions.UpdateType",
2406 extension->GetType(), 100);
2407 UMA_HISTOGRAM_ENUMERATION("Extensions.UpdateSource",
2408 extension->location(), Extension::NUM_LOCATIONS);
[email protected]07533022011-06-27 20:42:552409 }
2410
[email protected]a39921b42012-02-28 03:42:542411 // Certain extension locations are specific enough that we can
2412 // auto-acknowledge any extension that came from one of them.
[email protected]31bb5ee62012-09-12 22:58:402413 if (extension->location() == Extension::EXTERNAL_POLICY_DOWNLOAD)
[email protected]a39921b42012-02-28 03:42:542414 AcknowledgeExternalExtension(extension->id());
[email protected]399583b2012-12-11 09:33:422415 const Extension::State initial_state =
2416 initial_enable ? Extension::ENABLED : Extension::DISABLED;
[email protected]e7aa7b7e2012-11-27 04:51:222417 if (ShouldDelayExtensionUpdate(id, wait_for_idle)) {
[email protected]399583b2012-12-11 09:33:422418 extension_prefs_->SetDelayedInstallInfo(extension, initial_state,
2419 page_ordinal);
[email protected]0db124b02012-11-07 04:55:052420
2421 // Transfer ownership of |extension|.
[email protected]399583b2012-12-11 09:33:422422 delayed_updates_for_idle_.Insert(extension);
[email protected]0db124b02012-11-07 04:55:052423
2424 // Notify extension of available update.
2425 extensions::RuntimeEventRouter::DispatchOnUpdateAvailableEvent(
2426 profile_, id, extension->manifest()->value());
2427 return;
2428 }
2429
[email protected]399583b2012-12-11 09:33:422430 if (installs_delayed()) {
2431 extension_prefs_->SetDelayedInstallInfo(extension, initial_state,
2432 page_ordinal);
2433 delayed_installs_.Insert(extension);
2434 } else {
2435 AddNewOrUpdatedExtension(extension, initial_state, page_ordinal);
2436 }
[email protected]8c484b742012-11-29 06:05:362437}
2438
2439void ExtensionService::AddNewOrUpdatedExtension(
2440 const Extension* extension,
[email protected]399583b2012-12-11 09:33:422441 Extension::State initial_state,
2442 const syncer::StringOrdinal& page_ordinal) {
[email protected]8c484b742012-11-29 06:05:362443 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
2444
[email protected]4416c5a2010-06-26 01:28:572445 extension_prefs_->OnExtensionInstalled(
[email protected]8266d662011-07-12 21:53:262446 extension,
[email protected]8c484b742012-11-29 06:05:362447 initial_state,
[email protected]36a5c4c2011-12-14 16:34:502448 page_ordinal);
[email protected]25b34332009-06-05 21:53:192449
[email protected]6f6101832012-11-27 22:10:482450 FinishInstallation(extension);
2451}
2452
2453void ExtensionService::MaybeFinishDelayedInstallation(
2454 const std::string& extension_id) {
2455 // Check if the extension already got updated.
[email protected]399583b2012-12-11 09:33:422456 if (!delayed_updates_for_idle_.Contains(extension_id))
[email protected]6f6101832012-11-27 22:10:482457 return;
2458 // Check if the extension is idle.
2459 if (!IsExtensionIdle(extension_id))
2460 return;
2461
2462 FinishDelayedInstallation(extension_id);
2463}
2464
2465void ExtensionService::FinishDelayedInstallation(
2466 const std::string& extension_id) {
2467 scoped_refptr<const Extension> extension(
2468 GetPendingExtensionUpdate(extension_id));
2469 CHECK(extension);
[email protected]399583b2012-12-11 09:33:422470 delayed_updates_for_idle_.Remove(extension_id);
[email protected]6f6101832012-11-27 22:10:482471
[email protected]399583b2012-12-11 09:33:422472 if (!extension_prefs_->FinishDelayedInstallInfo(extension_id))
[email protected]6f6101832012-11-27 22:10:482473 NOTREACHED();
2474
2475 FinishInstallation(extension);
2476}
2477
2478void ExtensionService::FinishInstallation(const Extension* extension) {
[email protected]fcb58a862012-05-01 01:03:152479 content::NotificationService::current()->Notify(
2480 chrome::NOTIFICATION_EXTENSION_INSTALLED,
2481 content::Source<Profile>(profile_),
2482 content::Details<const Extension>(extension));
2483
[email protected]d96eb512012-11-01 23:44:082484 bool unacknowledged_external = IsUnacknowledgedExternalExtension(extension);
[email protected]41070e8d2012-10-24 01:34:362485
[email protected]399583b2012-12-11 09:33:422486 // Unpacked extensions default to allowing file access, but if that has been
2487 // overridden, don't reset the value.
2488 if (Extension::ShouldAlwaysAllowFileAccess(extension->location()) &&
2489 !extension_prefs_->HasAllowFileAccessSetting(extension->id())) {
2490 extension_prefs_->SetAllowFileAccess(extension->id(), true);
2491 }
2492
[email protected]6f6101832012-11-27 22:10:482493 AddExtension(extension);
[email protected]612a1cb12012-10-17 13:18:032494
[email protected]a51c9e92012-12-09 09:19:202495#if defined(ENABLE_THEMES)
2496 // We do this here since AddExtension() is always called on browser
2497 // startup, and we only really care about the last theme installed.
2498 // If that ever changes and we have to move this code somewhere
2499 // else, it should be somewhere that's not in the startup path.
2500 if (extension->is_theme() && extensions_.GetByID(extension->id())) {
2501 DCHECK_EQ(extensions_.GetByID(extension->id()), extension);
2502 // Now that the theme extension is visible from outside the
2503 // ExtensionService, notify the ThemeService about the
2504 // newly-installed theme.
2505 ThemeServiceFactory::GetForProfile(profile_)->SetTheme(extension);
2506 }
2507#endif
2508
[email protected]612a1cb12012-10-17 13:18:032509 // If this is a new external extension that was disabled, alert the user
[email protected]d96eb512012-11-01 23:44:082510 // so he can reenable it. We do this last so that it has already been
2511 // added to our list of extensions.
2512 if (unacknowledged_external) {
[email protected]612a1cb12012-10-17 13:18:032513 UpdateExternalExtensionAlert();
[email protected]d96eb512012-11-01 23:44:082514 UMA_HISTOGRAM_ENUMERATION("Extensions.ExternalExtensionEvent",
2515 EXTERNAL_EXTENSION_INSTALLED,
2516 EXTERNAL_EXTENSION_BUCKET_BOUNDARY);
2517 }
[email protected]4a190632009-05-09 01:07:422518}
2519
[email protected]76b65442012-11-17 14:11:482520const Extension* ExtensionService::GetPendingExtensionUpdate(
2521 const std::string& id) const {
[email protected]399583b2012-12-11 09:33:422522 return delayed_updates_for_idle_.GetByID(id);
[email protected]76b65442012-11-17 14:11:482523}
2524
[email protected]bb7f40952011-01-13 00:21:202525void ExtensionService::TrackTerminatedExtension(const Extension* extension) {
[email protected]84df8332011-12-06 18:22:462526 if (!terminated_extensions_.Contains(extension->id()))
2527 terminated_extensions_.Insert(make_scoped_refptr(extension));
[email protected]fa2416f2011-05-03 08:41:202528
[email protected]b3f7fe22011-11-11 19:27:562529 UnloadExtension(extension->id(), extension_misc::UNLOAD_REASON_TERMINATE);
[email protected]bb7f40952011-01-13 00:21:202530}
2531
2532void ExtensionService::UntrackTerminatedExtension(const std::string& id) {
[email protected]fa2416f2011-05-03 08:41:202533 std::string lowercase_id = StringToLowerASCII(id);
[email protected]84df8332011-12-06 18:22:462534 terminated_extensions_.Remove(lowercase_id);
[email protected]bb7f40952011-01-13 00:21:202535}
2536
[email protected]0dfe05c2011-02-23 23:03:362537const Extension* ExtensionService::GetTerminatedExtension(
[email protected]8001df22011-04-28 19:59:472538 const std::string& id) const {
[email protected]695b5712012-12-06 23:55:282539 return GetExtensionById(id, INCLUDE_TERMINATED);
[email protected]8001df22011-04-28 19:59:472540}
2541
2542const Extension* ExtensionService::GetInstalledExtension(
2543 const std::string& id) const {
[email protected]695b5712012-12-06 23:55:282544 int include_mask = INCLUDE_ENABLED |
2545 INCLUDE_DISABLED |
2546 INCLUDE_TERMINATED |
2547 INCLUDE_BLACKLISTED;
2548 return GetExtensionById(id, include_mask);
[email protected]0dfe05c2011-02-23 23:03:362549}
2550
[email protected]eaa7dd182010-12-14 11:09:002551bool ExtensionService::ExtensionBindingsAllowed(const GURL& url) {
[email protected]615d88f2011-12-13 01:47:442552 // Allow bindings for all packaged extensions and component hosted apps.
2553 const Extension* extension = extensions_.GetExtensionOrAppByURL(
2554 ExtensionURLInfo(url));
2555 return extension && (!extension->is_hosted_app() ||
2556 extension->location() == Extension::COMPONENT);
[email protected]6d2e60bd2010-06-03 22:37:392557}
2558
[email protected]4d007b312012-10-17 03:00:482559bool ExtensionService::ShouldBlockUrlInBrowserTab(GURL* url) {
2560 const Extension* extension = extensions_.GetExtensionOrAppByURL(
2561 ExtensionURLInfo(*url));
2562 if (extension && extension->is_platform_app()) {
2563 *url = GURL(chrome::kExtensionInvalidRequestURL);
2564 return true;
2565 }
2566
2567 return false;
2568}
2569
[email protected]9060d8b02012-01-13 02:14:302570bool ExtensionService::OnExternalExtensionFileFound(
[email protected]8ef78fd2010-08-19 17:14:322571 const std::string& id,
[email protected]8e4560b62011-01-14 10:09:142572 const Version* version,
[email protected]8ef78fd2010-08-19 17:14:322573 const FilePath& path,
[email protected]1bf73cc32011-10-26 22:38:312574 Extension::Location location,
[email protected]47fc70c2011-12-06 07:29:512575 int creation_flags,
2576 bool mark_acknowledged) {
[email protected]ab22ba42011-01-14 16:36:382577 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
2578 CHECK(Extension::IdIsValid(id));
[email protected]79c833b52011-04-05 18:31:012579 if (extension_prefs_->IsExternalExtensionUninstalled(id))
[email protected]9060d8b02012-01-13 02:14:302580 return false;
[email protected]a8af9fdb2010-10-28 21:52:202581
[email protected]7577a5c52009-07-30 06:21:582582 // Before even bothering to unpack, check and see if we already have this
[email protected]4c967932009-07-31 01:15:492583 // version. This is important because these extensions are going to get
[email protected]7577a5c52009-07-30 06:21:582584 // installed on every startup.
[email protected]9adb9692010-10-29 23:14:022585 const Extension* existing = GetExtensionById(id, true);
[email protected]910f72ce2012-08-24 01:38:352586
[email protected]7577a5c52009-07-30 06:21:582587 if (existing) {
[email protected]910f72ce2012-08-24 01:38:352588 // The default apps will have the location set as INTERNAL. Since older
2589 // default apps are installed as EXTERNAL, we override them. However, if the
2590 // app is already installed as internal, then do the version check.
[email protected]31bb5ee62012-09-12 22:58:402591 // TODO(grv) : Remove after Q1-2013.
[email protected]910f72ce2012-08-24 01:38:352592 bool is_default_apps_migration =
2593 (location == Extension::INTERNAL &&
2594 Extension::IsExternalLocation(existing->location()));
2595
2596 if (!is_default_apps_migration) {
2597 DCHECK(version);
2598
2599 switch (existing->version()->CompareTo(*version)) {
2600 case -1: // existing version is older, we should upgrade
2601 break;
2602 case 0: // existing version is same, do nothing
2603 return false;
2604 case 1: // existing version is newer, uh-oh
2605 LOG(WARNING) << "Found external version of extension " << id
2606 << "that is older than current version. Current version "
2607 << "is: " << existing->VersionString() << ". New "
2608 << "version is: " << version->GetString()
2609 << ". Keeping current version.";
2610 return false;
2611 }
[email protected]7577a5c52009-07-30 06:21:582612 }
2613 }
2614
[email protected]9060d8b02012-01-13 02:14:302615 // If the extension is already pending, don't start an install.
[email protected]e3987852012-05-04 10:06:302616 if (!pending_extension_manager()->AddFromExternalFile(
2617 id, location, *version)) {
[email protected]9060d8b02012-01-13 02:14:302618 return false;
[email protected]e3987852012-05-04 10:06:302619 }
[email protected]9c635f22010-12-02 09:36:362620
[email protected]14908b72011-04-20 06:54:362621 // no client (silent install)
[email protected]d8c8f25f2011-11-02 18:18:012622 scoped_refptr<CrxInstaller> installer(CrxInstaller::Create(this, NULL));
[email protected]6dfbbf82010-03-12 23:09:162623 installer->set_install_source(location);
2624 installer->set_expected_id(id);
[email protected]cb0e50312011-05-09 15:03:072625 installer->set_expected_version(*version);
2626 installer->set_install_cause(extension_misc::INSTALL_CAUSE_EXTERNAL_FILE);
[email protected]1bf73cc32011-10-26 22:38:312627 installer->set_creation_flags(creation_flags);
[email protected]6dfbbf82010-03-12 23:09:162628 installer->InstallCrx(path);
[email protected]47fc70c2011-12-06 07:29:512629
2630 // Depending on the source, a new external extension might not need a user
2631 // notification on installation. For such extensions, mark them acknowledged
2632 // now to suppress the notification.
2633 if (mark_acknowledged)
2634 AcknowledgeExternalExtension(id);
[email protected]9060d8b02012-01-13 02:14:302635
2636 return true;
[email protected]7577a5c52009-07-30 06:21:582637}
2638
[email protected]eaa7dd182010-12-14 11:09:002639void ExtensionService::ReportExtensionLoadError(
[email protected]d11c8e92009-10-20 23:26:402640 const FilePath& extension_path,
2641 const std::string &error,
[email protected]d11c8e92009-10-20 23:26:402642 bool be_noisy) {
[email protected]d8c8f25f2011-11-02 18:18:012643 content::NotificationService::current()->Notify(
2644 chrome::NOTIFICATION_EXTENSION_LOAD_ERROR,
2645 content::Source<Profile>(profile_),
2646 content::Details<const std::string>(&error));
[email protected]d11c8e92009-10-20 23:26:402647
[email protected]8a205c02011-02-04 20:41:332648 std::string path_str = UTF16ToUTF8(extension_path.LossyDisplayName());
[email protected]438afb12012-07-05 03:18:212649 string16 message = UTF8ToUTF16(base::StringPrintf(
[email protected]18d4b6c2010-09-21 03:21:042650 "Could not load extension from '%s'. %s",
[email protected]fc670822011-12-17 09:33:492651 path_str.c_str(), error.c_str()));
[email protected]d11c8e92009-10-20 23:26:402652 ExtensionErrorReporter::GetInstance()->ReportError(message, be_noisy);
2653}
2654
[email protected]eaa7dd182010-12-14 11:09:002655void ExtensionService::DidCreateRenderViewForBackgroundPage(
[email protected]3a1dc572012-07-31 22:25:132656 extensions::ExtensionHost* host) {
[email protected]406027c02010-09-27 08:03:182657 OrphanedDevTools::iterator iter =
[email protected]2d2f6cfc2011-05-06 21:09:332658 orphaned_dev_tools_.find(host->extension_id());
[email protected]406027c02010-09-27 08:03:182659 if (iter == orphaned_dev_tools_.end())
2660 return;
2661
[email protected]98f66112012-12-25 12:59:362662 DevToolsAgentHost::ConnectRenderViewHost(iter->second,
2663 host->render_view_host());
[email protected]406027c02010-09-27 08:03:182664 orphaned_dev_tools_.erase(iter);
2665}
2666
[email protected]432115822011-07-10 15:52:272667void ExtensionService::Observe(int type,
[email protected]6c2381d2011-10-19 02:52:532668 const content::NotificationSource& source,
2669 const content::NotificationDetails& details) {
[email protected]432115822011-07-10 15:52:272670 switch (type) {
[email protected]3c4abc82012-10-22 22:25:542671 case chrome::NOTIFICATION_APP_TERMINATING:
2672 // Shutdown has started. Don't start any more extension installs.
2673 // (We cannot use ExtensionService::Shutdown() for this because it
2674 // happens too late in browser teardown.)
2675 browser_terminating_ = true;
2676 break;
[email protected]432115822011-07-10 15:52:272677 case chrome::NOTIFICATION_EXTENSION_PROCESS_TERMINATED: {
[email protected]6c2381d2011-10-19 02:52:532678 if (profile_ !=
2679 content::Source<Profile>(source).ptr()->GetOriginalProfile()) {
[email protected]bc535ee52010-08-31 18:40:322680 break;
[email protected]6c2381d2011-10-19 02:52:532681 }
[email protected]a4ed6282009-12-14 20:51:162682
[email protected]3a1dc572012-07-31 22:25:132683 extensions::ExtensionHost* host =
2684 content::Details<extensions::ExtensionHost>(details).ptr();
[email protected]f128af42010-08-05 18:05:262685
[email protected]fa2416f2011-05-03 08:41:202686 // Mark the extension as terminated and Unload it. We want it to
2687 // be in a consistent state: either fully working or not loaded
2688 // at all, but never half-crashed. We do it in a PostTask so
2689 // that other handlers of this notification will still have
2690 // access to the Extension and ExtensionHost.
[email protected]14908b72011-04-20 06:54:362691 MessageLoop::current()->PostTask(
2692 FROM_HERE,
[email protected]53612e82011-10-18 18:00:362693 base::Bind(
[email protected]fa2416f2011-05-03 08:41:202694 &ExtensionService::TrackTerminatedExtension,
[email protected]d8c8f25f2011-11-02 18:18:012695 AsWeakPtr(),
[email protected]fa2416f2011-05-03 08:41:202696 host->extension()));
[email protected]31f77262009-12-02 20:48:532697 break;
2698 }
[email protected]432115822011-07-10 15:52:272699 case content::NOTIFICATION_RENDERER_PROCESS_CREATED: {
[email protected]f3b1a082011-11-18 00:34:302700 content::RenderProcessHost* process =
2701 content::Source<content::RenderProcessHost>(source).ptr();
[email protected]fc30ef082011-08-18 04:07:192702 Profile* host_profile =
[email protected]f3b1a082011-11-18 00:34:302703 Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]fc30ef082011-08-18 04:07:192704 if (!profile_->IsSameProfile(host_profile->GetOriginalProfile()))
2705 break;
2706
[email protected]15397b42012-05-16 23:56:062707 // Extensions need to know the channel for API restrictions.
2708 process->Send(new ExtensionMsg_SetChannel(
[email protected]5243df072012-07-11 21:41:012709 extensions::Feature::GetCurrentChannel()));
[email protected]15397b42012-05-16 23:56:062710
[email protected]77a6970c2011-04-23 16:58:562711 // Valid extension function names, used to setup bindings in renderer.
2712 std::vector<std::string> function_names;
2713 ExtensionFunctionDispatcher::GetAllFunctionNames(&function_names);
2714 process->Send(new ExtensionMsg_SetFunctionNames(function_names));
[email protected]31f77262009-12-02 20:48:532715
[email protected]77a6970c2011-04-23 16:58:562716 // Scripting whitelist. This is modified by tests and must be communicated
2717 // to renderers.
2718 process->Send(new ExtensionMsg_SetScriptingWhitelist(
2719 *Extension::GetScriptingWhitelist()));
2720
2721 // Loaded extensions.
[email protected]9776e82e2011-11-15 02:17:532722 std::vector<ExtensionMsg_Loaded_Params> loaded_extensions;
[email protected]84df8332011-12-06 18:22:462723 for (ExtensionSet::const_iterator iter = extensions_.begin();
2724 iter != extensions_.end(); ++iter) {
[email protected]19647262011-12-16 09:57:492725 // Renderers don't need to know about themes.
2726 if (!(*iter)->is_theme())
2727 loaded_extensions.push_back(ExtensionMsg_Loaded_Params(*iter));
[email protected]77a6970c2011-04-23 16:58:562728 }
[email protected]9776e82e2011-11-15 02:17:532729 process->Send(new ExtensionMsg_Loaded(loaded_extensions));
[email protected]77a6970c2011-04-23 16:58:562730 break;
2731 }
[email protected]432115822011-07-10 15:52:272732 case content::NOTIFICATION_RENDERER_PROCESS_TERMINATED: {
[email protected]f3b1a082011-11-18 00:34:302733 content::RenderProcessHost* process =
2734 content::Source<content::RenderProcessHost>(source).ptr();
[email protected]fc30ef082011-08-18 04:07:192735 Profile* host_profile =
[email protected]f3b1a082011-11-18 00:34:302736 Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]fc30ef082011-08-18 04:07:192737 if (!profile_->IsSameProfile(host_profile->GetOriginalProfile()))
2738 break;
2739
[email protected]6bc04fd82011-12-04 02:29:352740 process_map_.RemoveAllFromProcess(process->GetID());
[email protected]6f371442011-11-09 06:45:462741 BrowserThread::PostTask(
2742 BrowserThread::IO, FROM_HERE,
2743 base::Bind(&ExtensionInfoMap::UnregisterAllExtensionsInProcess,
[email protected]31d8f5f22012-04-02 15:22:082744 system_->info_map(),
[email protected]f3b1a082011-11-18 00:34:302745 process->GetID()));
[email protected]da5683db2011-04-23 17:12:212746 break;
2747 }
[email protected]d91268022011-08-26 13:17:372748 case chrome::NOTIFICATION_IMPORT_FINISHED: {
[email protected]cf593af2011-12-30 05:44:392749 InitAfterImport();
[email protected]d91268022011-08-26 13:17:372750 break;
2751 }
[email protected]0db124b02012-11-07 04:55:052752 case chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED: {
2753 extensions::ExtensionHost* host =
2754 content::Details<extensions::ExtensionHost>(details).ptr();
[email protected]e7aa7b7e2012-11-27 04:51:222755 std::string extension_id = host->extension_id();
[email protected]399583b2012-12-11 09:33:422756 if (delayed_updates_for_idle_.Contains(extension_id)) {
[email protected]e7aa7b7e2012-11-27 04:51:222757 // We were waiting for this extension to become idle, it now might have,
2758 // so maybe finish installation.
2759 MessageLoop::current()->PostDelayedTask(
[email protected]0db124b02012-11-07 04:55:052760 FROM_HERE,
[email protected]6f6101832012-11-27 22:10:482761 base::Bind(&ExtensionService::MaybeFinishDelayedInstallation,
[email protected]0db124b02012-11-07 04:55:052762 AsWeakPtr(), extension_id),
2763 base::TimeDelta::FromSeconds(kUpdateIdleDelay));
[email protected]0db124b02012-11-07 04:55:052764 }
2765 break;
2766 }
[email protected]aa96d3a2010-08-21 08:45:252767
[email protected]4814b512009-11-07 00:12:292768 default:
2769 NOTREACHED() << "Unexpected notification type.";
2770 }
2771}
2772
[email protected]90bb38d2012-11-14 18:36:032773void ExtensionService::OnExtensionInstallPrefChanged() {
[email protected]a6a7ced2012-11-01 17:24:182774 IdentifyAlertableExtensions();
2775 CheckManagementPolicy();
2776}
2777
[email protected]eaa7dd182010-12-14 11:09:002778bool ExtensionService::HasApps() const {
[email protected]ec5b50d2010-10-09 16:35:182779 return !GetAppIds().empty();
2780}
[email protected]377011d2010-07-20 04:18:502781
[email protected]eaa7dd182010-12-14 11:09:002782ExtensionIdSet ExtensionService::GetAppIds() const {
[email protected]ec5b50d2010-10-09 16:35:182783 ExtensionIdSet result;
[email protected]84df8332011-12-06 18:22:462784 for (ExtensionSet::const_iterator it = extensions_.begin();
[email protected]377011d2010-07-20 04:18:502785 it != extensions_.end(); ++it) {
[email protected]ec5b50d2010-10-09 16:35:182786 if ((*it)->is_app() && (*it)->location() != Extension::COMPONENT)
2787 result.insert((*it)->id());
[email protected]377011d2010-07-20 04:18:502788 }
2789
[email protected]ec5b50d2010-10-09 16:35:182790 return result;
[email protected]377011d2010-07-20 04:18:502791}
[email protected]d7e9a862010-11-03 21:57:492792
[email protected]dc9a74f72012-08-17 18:07:212793bool ExtensionService::IsBackgroundPageReady(const Extension* extension) const {
2794 if (!extension->has_persistent_background_page())
2795 return true;
2796 ExtensionRuntimeDataMap::const_iterator it =
2797 extension_runtime_data_.find(extension->id());
2798 return it == extension_runtime_data_.end() ? false :
2799 it->second.background_page_ready;
[email protected]d7e9a862010-11-03 21:57:492800}
2801
[email protected]eaa7dd182010-12-14 11:09:002802void ExtensionService::SetBackgroundPageReady(const Extension* extension) {
[email protected]a03d4448f2012-01-10 23:25:282803 DCHECK(extension->has_background_page());
[email protected]d7e9a862010-11-03 21:57:492804 extension_runtime_data_[extension->id()].background_page_ready = true;
[email protected]ad50def52011-10-19 23:17:072805 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:272806 chrome::NOTIFICATION_EXTENSION_BACKGROUND_PAGE_READY,
[email protected]6c2381d2011-10-19 02:52:532807 content::Source<const Extension>(extension),
[email protected]ad50def52011-10-19 23:17:072808 content::NotificationService::NoDetails());
[email protected]d7e9a862010-11-03 21:57:492809}
2810
[email protected]65992d52012-09-19 23:05:312811void ExtensionService::InspectBackgroundPage(const Extension* extension) {
2812 DCHECK(extension);
2813
[email protected]fdd679b2012-11-15 20:49:392814 ExtensionProcessManager* pm = system_->process_manager();
[email protected]65992d52012-09-19 23:05:312815 extensions::LazyBackgroundTaskQueue* queue =
[email protected]fdd679b2012-11-15 20:49:392816 system_->lazy_background_task_queue();
[email protected]65992d52012-09-19 23:05:312817
2818 extensions::ExtensionHost* host =
2819 pm->GetBackgroundHostForExtension(extension->id());
2820 if (host) {
2821 InspectExtensionHost(host);
2822 } else {
2823 queue->AddPendingTask(
2824 profile_, extension->id(),
2825 base::Bind(&ExtensionService::InspectExtensionHost,
2826 base::Unretained(this)));
2827 }
2828}
2829
[email protected]dc9a74f72012-08-17 18:07:212830bool ExtensionService::IsBeingUpgraded(const Extension* extension) const {
2831 ExtensionRuntimeDataMap::const_iterator it =
2832 extension_runtime_data_.find(extension->id());
2833 return it == extension_runtime_data_.end() ? false :
2834 it->second.being_upgraded;
[email protected]d7e9a862010-11-03 21:57:492835}
2836
[email protected]eaa7dd182010-12-14 11:09:002837void ExtensionService::SetBeingUpgraded(const Extension* extension,
[email protected]d7e9a862010-11-03 21:57:492838 bool value) {
2839 extension_runtime_data_[extension->id()].being_upgraded = value;
2840}
[email protected]1bead0712010-11-27 17:41:532841
[email protected]dc9a74f72012-08-17 18:07:212842bool ExtensionService::HasUsedWebRequest(const Extension* extension) const {
2843 ExtensionRuntimeDataMap::const_iterator it =
2844 extension_runtime_data_.find(extension->id());
2845 return it == extension_runtime_data_.end() ? false :
2846 it->second.has_used_webrequest;
[email protected]39a5b532011-10-22 01:47:072847}
2848
2849void ExtensionService::SetHasUsedWebRequest(const Extension* extension,
2850 bool value) {
2851 extension_runtime_data_[extension->id()].has_used_webrequest = value;
2852}
2853
[email protected]cebc3dc2011-04-18 17:15:002854void ExtensionService::RegisterNaClModule(const GURL& url,
2855 const std::string& mime_type) {
2856 NaClModuleInfo info;
2857 info.url = url;
2858 info.mime_type = mime_type;
2859
2860 DCHECK(FindNaClModule(url) == nacl_module_list_.end());
2861 nacl_module_list_.push_front(info);
2862}
2863
2864void ExtensionService::UnregisterNaClModule(const GURL& url) {
2865 NaClModuleInfoList::iterator iter = FindNaClModule(url);
2866 DCHECK(iter != nacl_module_list_.end());
2867 nacl_module_list_.erase(iter);
2868}
2869
[email protected]ed0ba002011-05-26 16:55:132870void ExtensionService::UpdatePluginListWithNaClModules() {
[email protected]300c0ea2011-07-15 23:04:332871 // An extension has been added which has a nacl_module component, which means
2872 // there is a MIME type that module wants to handle, so we need to add that
2873 // MIME type to plugins which handle NaCl modules in order to allow the
2874 // individual modules to handle these types.
[email protected]1e127022011-11-29 21:11:472875 FilePath path;
2876 if (!PathService::Get(chrome::FILE_NACL_PLUGIN, &path))
2877 return;
2878 const content::PepperPluginInfo* pepper_info =
2879 PluginService::GetInstance()->GetRegisteredPpapiPluginInfo(path);
2880 if (!pepper_info)
2881 return;
[email protected]300c0ea2011-07-15 23:04:332882
[email protected]1e127022011-11-29 21:11:472883 std::vector<webkit::WebPluginMimeType>::const_iterator mime_iter;
2884 // Check each MIME type the plugins handle for the NaCl MIME type.
2885 for (mime_iter = pepper_info->mime_types.begin();
2886 mime_iter != pepper_info->mime_types.end(); ++mime_iter) {
2887 if (mime_iter->mime_type == kNaClPluginMimeType) {
2888 // This plugin handles "application/x-nacl".
[email protected]300c0ea2011-07-15 23:04:332889
[email protected]1e127022011-11-29 21:11:472890 PluginService::GetInstance()->
2891 UnregisterInternalPlugin(pepper_info->path);
[email protected]300c0ea2011-07-15 23:04:332892
[email protected]1e127022011-11-29 21:11:472893 webkit::WebPluginInfo info = pepper_info->ToWebPluginInfo();
[email protected]300c0ea2011-07-15 23:04:332894
[email protected]1e127022011-11-29 21:11:472895 for (ExtensionService::NaClModuleInfoList::const_iterator iter =
2896 nacl_module_list_.begin();
2897 iter != nacl_module_list_.end(); ++iter) {
2898 // Add the MIME type specified in the extension to this NaCl plugin,
2899 // With an extra "nacl" argument to specify the location of the NaCl
2900 // manifest file.
2901 webkit::WebPluginMimeType mime_type_info;
2902 mime_type_info.mime_type = iter->mime_type;
2903 mime_type_info.additional_param_names.push_back(UTF8ToUTF16("nacl"));
2904 mime_type_info.additional_param_values.push_back(
2905 UTF8ToUTF16(iter->url.spec()));
2906 info.mime_types.push_back(mime_type_info);
[email protected]300c0ea2011-07-15 23:04:332907 }
[email protected]1e127022011-11-29 21:11:472908
2909 PluginService::GetInstance()->RefreshPlugins();
[email protected]c6f3dea2012-01-14 02:23:112910 PluginService::GetInstance()->RegisterInternalPlugin(info, true);
[email protected]1e127022011-11-29 21:11:472911 // This plugin has been modified, no need to check the rest of its
2912 // types, but continue checking other plugins.
2913 break;
[email protected]ed0ba002011-05-26 16:55:132914 }
2915 }
[email protected]ed0ba002011-05-26 16:55:132916}
2917
[email protected]cebc3dc2011-04-18 17:15:002918ExtensionService::NaClModuleInfoList::iterator
2919 ExtensionService::FindNaClModule(const GURL& url) {
2920 for (NaClModuleInfoList::iterator iter = nacl_module_list_.begin();
2921 iter != nacl_module_list_.end(); ++iter) {
2922 if (iter->url == url)
2923 return iter;
2924 }
2925 return nacl_module_list_.end();
2926}
[email protected]6cafe35a2012-08-27 22:40:502927
[email protected]32b36c62012-10-24 05:37:412928void ExtensionService::DoPostLoadTasks(const Extension* extension) {
2929 std::map<std::string, int>::iterator it =
2930 on_load_events_.find(extension->id());
2931 if (it == on_load_events_.end())
2932 return;
2933
2934 int events_to_fire = it->second;
2935 extensions::LazyBackgroundTaskQueue* queue =
2936 system_->lazy_background_task_queue();
2937 if (queue->ShouldEnqueueTask(profile(), extension)) {
2938 if (events_to_fire & EVENT_LAUNCHED)
[email protected]6cafe35a2012-08-27 22:40:502939 queue->AddPendingTask(profile(), extension->id(),
2940 base::Bind(&ExtensionService::LaunchApplication));
[email protected]32b36c62012-10-24 05:37:412941 if (events_to_fire & EVENT_RESTARTED)
2942 queue->AddPendingTask(profile(), extension->id(),
2943 base::Bind(&ExtensionService::RestartApplication));
[email protected]6cafe35a2012-08-27 22:40:502944 }
[email protected]32b36c62012-10-24 05:37:412945
2946 on_load_events_.erase(it);
[email protected]6cafe35a2012-08-27 22:40:502947}
2948
2949// static
2950void ExtensionService::LaunchApplication(
2951 extensions::ExtensionHost* extension_host) {
2952 if (!extension_host)
2953 return;
2954
2955#if !defined(OS_ANDROID)
2956 extensions::LaunchPlatformApp(extension_host->profile(),
2957 extension_host->extension(),
2958 NULL, FilePath());
2959#endif
2960}
[email protected]65992d52012-09-19 23:05:312961
[email protected]32b36c62012-10-24 05:37:412962// static
2963void ExtensionService::RestartApplication(
2964 extensions::ExtensionHost* extension_host) {
2965 if (!extension_host)
2966 return;
2967
2968#if !defined(OS_ANDROID)
2969 extensions::AppEventRouter::DispatchOnRestartedEvent(
2970 extension_host->profile(), extension_host->extension());
2971#endif
2972}
2973
2974bool ExtensionService::HasShellWindows(const std::string& extension_id) {
2975 const Extension* current_extension = GetExtensionById(extension_id, false);
2976 return current_extension && current_extension->is_platform_app() &&
2977 !extensions::ShellWindowRegistry::Get(profile_)->
2978 GetShellWindowsForApp(extension_id).empty();
2979}
2980
[email protected]65992d52012-09-19 23:05:312981void ExtensionService::InspectExtensionHost(
2982 extensions::ExtensionHost* host) {
2983 if (host)
2984 DevToolsWindow::OpenDevToolsWindow(host->render_view_host());
2985}
[email protected]612a1cb12012-10-17 13:18:032986
2987bool ExtensionService::ShouldEnableOnInstall(const Extension* extension) {
2988 // Extensions installed by policy can't be disabled. So even if a previous
2989 // installation disabled the extension, make sure it is now enabled.
2990 if (system_->management_policy()->MustRemainEnabled(extension, NULL))
2991 return true;
2992
2993 if (extension_prefs_->IsExtensionDisabled(extension->id()))
2994 return false;
2995
[email protected]41070e8d2012-10-24 01:34:362996 if (FeatureSwitch::prompt_for_external_extensions()->IsEnabled()) {
[email protected]612a1cb12012-10-17 13:18:032997 // External extensions are initially disabled. We prompt the user before
[email protected]2c495c42013-01-04 21:49:542998 // enabling them. Hosted apps are excepted because they are not dangerous
2999 // (they need to be launched by the user anyway).
3000 if (extension->GetType() != Extension::TYPE_HOSTED_APP &&
3001 Extension::IsExternalLocation(extension->location()) &&
[email protected]612a1cb12012-10-17 13:18:033002 !extension_prefs_->IsExternalExtensionAcknowledged(extension->id())) {
3003 return false;
3004 }
3005 }
[email protected]612a1cb12012-10-17 13:18:033006
3007 return true;
3008}
[email protected]0db124b02012-11-07 04:55:053009
3010bool ExtensionService::IsExtensionIdle(const std::string& extension_id) const {
[email protected]d9a61e12012-11-14 02:43:473011 ExtensionProcessManager* process_manager = system_->process_manager();
[email protected]fc332ae2012-11-14 20:17:333012 DCHECK(process_manager);
[email protected]0db124b02012-11-07 04:55:053013 extensions::ExtensionHost* host =
[email protected]d9a61e12012-11-14 02:43:473014 process_manager->GetBackgroundHostForExtension(extension_id);
[email protected]e7aa7b7e2012-11-27 04:51:223015 if (host)
3016 return false;
3017 return process_manager->GetRenderViewHostsForExtension(extension_id).empty();
3018}
3019
3020bool ExtensionService::ShouldDelayExtensionUpdate(
3021 const std::string& extension_id,
3022 bool wait_for_idle) const {
3023 const char kOnUpdateAvailableEvent[] = "runtime.onUpdateAvailable";
3024
3025 // If delayed updates are globally disabled, or just for this extension,
3026 // don't delay.
3027 if (!install_updates_when_idle_ || !wait_for_idle)
3028 return false;
3029
[email protected]695b5712012-12-06 23:55:283030 const Extension* old = GetInstalledExtension(extension_id);
[email protected]e7aa7b7e2012-11-27 04:51:223031 // If there is no old extension, this is not an update, so don't delay.
3032 if (!old)
3033 return false;
3034
3035 if (old->has_persistent_background_page()) {
3036 // Delay installation if the extension listens for the onUpdateAvailable
3037 // event.
3038 return system_->event_router()->ExtensionHasEventListener(
3039 extension_id, kOnUpdateAvailableEvent);
3040 } else {
3041 // Delay installation if the extension is not idle.
3042 return !IsExtensionIdle(extension_id);
3043 }
[email protected]0db124b02012-11-07 04:55:053044}
[email protected]fdd679b2012-11-15 20:49:393045
[email protected]399583b2012-12-11 09:33:423046void ExtensionService::GarbageCollectIsolatedStorage() {
3047 scoped_ptr<base::hash_set<FilePath> > active_paths(
3048 new base::hash_set<FilePath>());
3049 for (ExtensionSet::const_iterator it = extensions_.begin();
3050 it != extensions_.end(); ++it) {
3051 if ((*it)->is_storage_isolated()) {
3052 active_paths->insert(
3053 BrowserContext::GetStoragePartitionForSite(
3054 profile_,
3055 GetSiteForExtensionId((*it)->id()))->GetPath());
3056 }
3057 }
3058
3059 DCHECK(!installs_delayed());
3060 set_installs_delayed(true);
3061 BrowserContext::GarbageCollectStoragePartitions(
3062 profile_, active_paths.Pass(),
3063 base::Bind(&ExtensionService::OnGarbageCollectIsolatedStorageFinished,
3064 AsWeakPtr()));
3065}
3066
3067void ExtensionService::OnGarbageCollectIsolatedStorageFinished() {
3068 set_installs_delayed(false);
3069 for (ExtensionSet::const_iterator it = delayed_installs_.begin();
3070 it != delayed_installs_.end();
3071 ++it) {
3072 FinishDelayedInstallation((*it)->id());
3073 }
3074 for (ExtensionSet::const_iterator it = delayed_updates_for_idle_.begin();
3075 it != delayed_updates_for_idle_.end();
3076 ++it) {
3077 MaybeFinishDelayedInstallation((*it)->id());
3078 }
3079 delayed_installs_.Clear();
3080}
3081
3082void ExtensionService::OnNeedsToGarbageCollectIsolatedStorage() {
3083 extension_prefs_->SetNeedsStorageGarbageCollection(true);
3084}
3085
[email protected]fdd679b2012-11-15 20:49:393086void ExtensionService::OnBlacklistUpdated() {
[email protected]695b5712012-12-06 23:55:283087 blacklist_->GetBlacklistedIDs(
3088 GenerateInstalledExtensionsSet()->GetIDs(),
3089 base::Bind(&ExtensionService::ManageBlacklist,
3090 AsWeakPtr(),
3091 blacklisted_extensions_.GetIDs()));
3092}
3093
3094void ExtensionService::ManageBlacklist(
3095 const std::set<std::string>& old_blacklisted_ids,
3096 const std::set<std::string>& new_blacklisted_ids) {
3097 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
3098
3099 std::set<std::string> no_longer_blacklisted;
3100 std::set_difference(old_blacklisted_ids.begin(), old_blacklisted_ids.end(),
3101 new_blacklisted_ids.begin(), new_blacklisted_ids.end(),
3102 std::inserter(no_longer_blacklisted,
3103 no_longer_blacklisted.begin()));
3104 std::set<std::string> not_yet_blacklisted;
3105 std::set_difference(new_blacklisted_ids.begin(), new_blacklisted_ids.end(),
3106 old_blacklisted_ids.begin(), old_blacklisted_ids.end(),
3107 std::inserter(not_yet_blacklisted,
3108 not_yet_blacklisted.begin()));
3109
3110 for (std::set<std::string>::iterator it = no_longer_blacklisted.begin();
3111 it != no_longer_blacklisted.end(); ++it) {
3112 scoped_refptr<const Extension> extension =
3113 blacklisted_extensions_.GetByID(*it);
3114 DCHECK(extension);
3115 if (!extension)
3116 continue;
3117 blacklisted_extensions_.Remove(*it);
3118 AddExtension(extension);
3119 }
3120
3121 for (std::set<std::string>::iterator it = not_yet_blacklisted.begin();
3122 it != not_yet_blacklisted.end(); ++it) {
3123 scoped_refptr<const Extension> extension = GetInstalledExtension(*it);
3124 DCHECK(extension);
3125 if (!extension)
3126 continue;
3127 blacklisted_extensions_.Insert(extension);
3128 UnloadExtension(*it, extension_misc::UNLOAD_REASON_BLACKLIST);
3129 }
3130
3131 IdentifyAlertableExtensions();
[email protected]fdd679b2012-11-15 20:49:393132}