blob: 96b9ad2f4f15a4013603f5eff92c51453a142685 [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]97d2f1d2011-01-15 00:41:088#include <set>
[email protected]654512b2010-09-01 02:09:429
[email protected]24b538a2010-02-27 01:22:4410#include "base/basictypes.h"
[email protected]05aad2da2011-10-28 10:12:3711#include "base/bind.h"
[email protected]e5af875f2011-10-10 21:09:1412#include "base/callback.h"
[email protected]62433d32011-10-12 22:33:1213#include "base/command_line.h"
[email protected]6014d672008-12-05 00:38:2514#include "base/file_util.h"
[email protected]14908b72011-04-20 06:54:3615#include "base/logging.h"
[email protected]49098f702011-10-13 03:47:1816#include "base/metrics/field_trial.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]34b99632011-01-01 01:01:0623#include "base/threading/thread_restrictions.h"
[email protected]cc2c3432009-11-06 17:24:3624#include "base/time.h"
[email protected]ce7f62e32010-08-10 23:43:5925#include "base/utf_string_conversions.h"
[email protected]cc655912009-01-29 23:19:1926#include "base/values.h"
[email protected]aa142702010-03-26 01:26:3327#include "base/version.h"
[email protected]a692a952011-11-28 08:23:5428#include "chrome/browser/accessibility/accessibility_extension_api.h"
[email protected]23d5f172011-10-25 05:49:5329#include "chrome/browser/bookmarks/bookmark_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]dfba8762011-09-02 12:49:5432#include "chrome/browser/chrome_plugin_service_filter.h"
[email protected]92ba7b012012-05-16 03:36:1733#include "chrome/browser/extensions/api/cookies/cookies_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]91aa8a32012-08-07 10:35:3336#include "chrome/browser/extensions/api/font_settings/font_settings_api.h"
[email protected]9c70e0d92012-07-16 08:39:4437#include "chrome/browser/extensions/api/managed_mode/managed_mode_api.h"
[email protected]7e7b782e2012-08-03 01:13:5738#include "chrome/browser/extensions/api/management/management_api.h"
[email protected]31bb5ee62012-09-12 22:58:4039#include "chrome/browser/extensions/api/media_galleries_private/media_galleries_private_event_router.h"
[email protected]bc500fa2012-09-06 09:03:3040#include "chrome/browser/extensions/api/processes/processes_api.h"
[email protected]5ebd6a62012-08-01 23:54:3941#include "chrome/browser/extensions/api/push_messaging/push_messaging_api.h"
[email protected]895a1e52012-05-15 02:50:1242#include "chrome/browser/extensions/api/web_navigation/web_navigation_api.h"
[email protected]af9db5f2011-10-05 05:13:1543#include "chrome/browser/extensions/app_notification_manager.h"
[email protected]5db9ada2012-04-11 13:48:2044#include "chrome/browser/extensions/app_sync_data.h"
[email protected]5a38dfd2012-07-23 23:22:1045#include "chrome/browser/extensions/browser_event_router.h"
[email protected]d8c8f25f2011-11-02 18:18:0146#include "chrome/browser/extensions/component_loader.h"
[email protected]e0785902011-05-19 23:34:1747#include "chrome/browser/extensions/crx_installer.h"
[email protected]d9ede582012-08-14 19:21:3848#include "chrome/browser/extensions/data_deleter.h"
[email protected]49098f702011-10-13 03:47:1849#include "chrome/browser/extensions/default_apps_trial.h"
[email protected]62f051c2012-03-29 17:04:4450#include "chrome/browser/extensions/extension_disabled_ui.h"
[email protected]14a000d2010-04-29 21:44:2451#include "chrome/browser/extensions/extension_error_reporter.h"
[email protected]89226982012-07-16 20:09:1852#include "chrome/browser/extensions/extension_error_ui.h"
[email protected]b1748b1d82009-11-30 20:32:5653#include "chrome/browser/extensions/extension_host.h"
[email protected]00b38242012-07-18 18:43:2254#include "chrome/browser/extensions/extension_install_ui.h"
[email protected]118de7892011-03-16 13:31:4055#include "chrome/browser/extensions/extension_preference_api.h"
[email protected]4814b512009-11-07 00:12:2956#include "chrome/browser/extensions/extension_process_manager.h"
[email protected]3569b502012-01-12 20:08:2357#include "chrome/browser/extensions/extension_sorting.h"
[email protected]19eb80152011-02-26 00:28:4358#include "chrome/browser/extensions/extension_special_storage_policy.h"
[email protected]90310d92011-04-17 07:35:0459#include "chrome/browser/extensions/extension_sync_data.h"
[email protected]31d8f5f22012-04-02 15:22:0860#include "chrome/browser/extensions/extension_system.h"
[email protected]8f9d4eb2011-02-05 01:39:1061#include "chrome/browser/extensions/extension_web_ui.h"
[email protected]5df038b2012-07-16 19:03:2762#include "chrome/browser/extensions/external_provider_impl.h"
63#include "chrome/browser/extensions/external_provider_interface.h"
[email protected]d8c8f25f2011-11-02 18:18:0164#include "chrome/browser/extensions/installed_loader.h"
[email protected]6cafe35a2012-08-27 22:40:5065#include "chrome/browser/extensions/lazy_background_task_queue.h"
[email protected]b2907fd2011-03-25 16:43:3766#include "chrome/browser/extensions/pending_extension_manager.h"
[email protected]c333e792012-01-06 16:57:3967#include "chrome/browser/extensions/permissions_updater.h"
[email protected]6cafe35a2012-08-27 22:40:5068#include "chrome/browser/extensions/platform_app_launcher.h"
[email protected]cccdf0aa2011-11-11 03:43:3869#include "chrome/browser/extensions/settings/settings_frontend.h"
[email protected]6cafe35a2012-08-27 22:40:5070#include "chrome/browser/extensions/shell_window_registry.h"
[email protected]d8c8f25f2011-11-02 18:18:0171#include "chrome/browser/extensions/unpacked_installer.h"
[email protected]42a08162012-03-16 18:09:1172#include "chrome/browser/extensions/updater/extension_updater.h"
[email protected]163ed192012-07-24 19:31:0773#include "chrome/browser/extensions/window_event_router.h"
[email protected]d2e6bd62011-10-24 20:29:0774#include "chrome/browser/history/history_extension_api.h"
[email protected]56ad3792010-05-28 17:45:3375#include "chrome/browser/net/chrome_url_request_context.h"
[email protected]37858e52010-08-26 00:22:0276#include "chrome/browser/prefs/pref_service.h"
[email protected]8ecad5e2010-12-02 21:18:3377#include "chrome/browser/profiles/profile.h"
[email protected]cf593af2011-12-30 05:44:3978#include "chrome/browser/profiles/profile_manager.h"
[email protected]8e5c89a2011-06-07 18:13:3379#include "chrome/browser/search_engines/template_url_service.h"
80#include "chrome/browser/search_engines/template_url_service_factory.h"
[email protected]18280372011-03-22 18:05:2281#include "chrome/browser/themes/theme_service.h"
[email protected]a0ea76c2011-03-23 17:36:4282#include "chrome/browser/themes/theme_service_factory.h"
[email protected]c8d407e2011-04-28 21:27:1783#include "chrome/browser/ui/webui/chrome_url_data_manager.h"
84#include "chrome/browser/ui/webui/favicon_source.h"
[email protected]5eddc3e2011-10-26 04:33:3185#include "chrome/browser/ui/webui/ntp/thumbnail_source.h"
[email protected]b07e606e2012-09-15 20:16:1586#include "chrome/browser/ui/webui/theme_source.h"
[email protected]aab98a52009-12-02 03:22:3587#include "chrome/common/child_process_logging.h"
[email protected]432115822011-07-10 15:52:2788#include "chrome/common/chrome_notification_types.h"
[email protected]1e127022011-11-29 21:11:4789#include "chrome/common/chrome_paths.h"
[email protected]e2eb43112009-05-29 21:19:5490#include "chrome/common/chrome_switches.h"
[email protected]15397b42012-05-16 23:56:0691#include "chrome/common/chrome_version_info.h"
[email protected]5b1a0e22009-05-26 19:00:5892#include "chrome/common/extensions/extension.h"
[email protected]05c82182010-06-24 17:49:0893#include "chrome/common/extensions/extension_error_utils.h"
[email protected]7c927b62010-02-24 09:54:1394#include "chrome/common/extensions/extension_file_util.h"
[email protected]895a1e52012-05-15 02:50:1295#include "chrome/common/extensions/extension_manifest_constants.h"
[email protected]77a6970c2011-04-23 16:58:5696#include "chrome/common/extensions/extension_messages.h"
[email protected]a315ba92010-11-16 14:12:2197#include "chrome/common/extensions/extension_resource.h"
[email protected]5243df072012-07-11 21:41:0198#include "chrome/common/extensions/features/feature.h"
[email protected]25b34332009-06-05 21:53:1999#include "chrome/common/pref_names.h"
[email protected]a57209872009-05-04 22:53:14100#include "chrome/common/url_constants.h"
[email protected]c38831a12011-10-28 12:44:49101#include "content/public/browser/browser_thread.h"
[email protected]0e12d7d2011-12-01 16:21:44102#include "content/public/browser/devtools_agent_host_registry.h"
103#include "content/public/browser/devtools_manager.h"
[email protected]05aad2da2011-10-28 10:12:37104#include "content/public/browser/notification_service.h"
[email protected]0d6e9bd2011-10-18 04:29:16105#include "content/public/browser/notification_types.h"
[email protected]3a5180ae2011-12-21 02:39:38106#include "content/public/browser/plugin_service.h"
[email protected]f3b1a082011-11-18 00:34:30107#include "content/public/browser/render_process_host.h"
[email protected]1e127022011-11-29 21:11:47108#include "content/public/common/pepper_plugin_info.h"
[email protected]c10da4b02010-03-25 14:38:32109#include "googleurl/src/gurl.h"
[email protected]65187152012-06-02 13:14:14110#include "grit/generated_resources.h"
[email protected]be28b5f42012-07-20 11:31:25111#include "net/base/registry_controlled_domains/registry_controlled_domain.h"
[email protected]895a1e52012-05-15 02:50:12112#include "sync/api/sync_change.h"
113#include "sync/api/sync_error_factory.h"
[email protected]24b538a2010-02-27 01:22:44114#include "webkit/database/database_tracker.h"
115#include "webkit/database/database_util.h"
[email protected]eed367e2011-04-12 03:43:31116#if defined(OS_CHROMEOS)
[email protected]14da67b02011-08-02 05:49:13117#include "chrome/browser/chromeos/cros/cros_library.h"
[email protected]f463bc92012-03-22 16:38:23118#include "chrome/browser/chromeos/extensions/bluetooth_event_router.h"
[email protected]eed367e2011-04-12 03:43:31119#include "chrome/browser/chromeos/extensions/file_browser_event_router.h"
[email protected]be5bd5742011-07-14 07:21:01120#include "chrome/browser/chromeos/extensions/input_method_event_router.h"
[email protected]ce9802042011-05-27 10:11:40121#include "chrome/browser/chromeos/extensions/media_player_event_router.h"
[email protected]14da67b02011-08-02 05:49:13122#include "chrome/browser/chromeos/input_method/input_method_manager.h"
[email protected]1364c6d2012-07-24 11:57:19123#include "chrome/browser/extensions/api/input_ime/input_ime_api.h"
[email protected]10eb28162012-09-18 03:04:09124#include "content/public/browser/storage_partition.h"
[email protected]b777b332011-04-16 04:01:08125#include "webkit/fileapi/file_system_context.h"
126#include "webkit/fileapi/file_system_mount_point_provider.h"
[email protected]eed367e2011-04-12 03:43:31127#endif
128
[email protected]55eb70e762012-02-20 17:38:39129using content::BrowserContext;
[email protected]631bb742011-11-02 11:29:39130using content::BrowserThread;
[email protected]0e12d7d2011-12-01 16:21:44131using content::DevToolsAgentHost;
132using content::DevToolsAgentHostRegistry;
[email protected]3a5180ae2011-12-21 02:39:38133using content::PluginService;
[email protected]bf3d9df2012-07-24 23:20:27134using extensions::CrxInstaller;
[email protected]1c321ee52012-05-21 03:02:34135using extensions::Extension;
136using extensions::ExtensionIdSet;
137using extensions::ExtensionInfo;
138using extensions::UnloadedExtensionInfo;
[email protected]c2e66e12012-06-27 06:27:06139using extensions::PermissionMessage;
140using extensions::PermissionMessages;
141using extensions::PermissionSet;
[email protected]5ef47ec2010-01-28 05:58:05142
[email protected]c6d474f82009-12-16 21:11:06143namespace errors = extension_manifest_errors;
144
[email protected]b6ab96d2009-08-20 18:58:19145namespace {
146
[email protected]29d0d4ac2010-09-08 21:10:31147#if defined(OS_LINUX)
148static const int kOmniboxIconPaddingLeft = 2;
149static const int kOmniboxIconPaddingRight = 2;
150#elif defined(OS_MACOSX)
151static const int kOmniboxIconPaddingLeft = 0;
152static const int kOmniboxIconPaddingRight = 2;
153#else
154static const int kOmniboxIconPaddingLeft = 0;
155static const int kOmniboxIconPaddingRight = 0;
156#endif
157
[email protected]300c0ea2011-07-15 23:04:33158const char* kNaClPluginMimeType = "application/x-nacl";
159
[email protected]3bdba0d2011-08-23 07:17:30160static bool IsSyncableExtension(const Extension& extension) {
161 return extension.GetSyncType() == Extension::SYNC_TYPE_EXTENSION;
162}
163
164static bool IsSyncableApp(const Extension& extension) {
165 return extension.GetSyncType() == Extension::SYNC_TYPE_APP;
166}
167
[email protected]c6d474f82009-12-16 21:11:06168} // namespace
[email protected]b6ab96d2009-08-20 18:58:19169
[email protected]eaa7dd182010-12-14 11:09:00170ExtensionService::ExtensionRuntimeData::ExtensionRuntimeData()
[email protected]d7e9a862010-11-03 21:57:49171 : background_page_ready(false),
[email protected]f8bf5992011-10-24 22:38:57172 being_upgraded(false),
173 has_used_webrequest(false) {
[email protected]d7e9a862010-11-03 21:57:49174}
175
[email protected]eaa7dd182010-12-14 11:09:00176ExtensionService::ExtensionRuntimeData::~ExtensionRuntimeData() {
[email protected]d7e9a862010-11-03 21:57:49177}
178
[email protected]cebc3dc2011-04-18 17:15:00179ExtensionService::NaClModuleInfo::NaClModuleInfo() {
180}
181
182ExtensionService::NaClModuleInfo::~NaClModuleInfo() {
183}
184
[email protected]eaa7dd182010-12-14 11:09:00185// ExtensionService.
[email protected]6014d672008-12-05 00:38:25186
[email protected]31bb5ee62012-09-12 22:58:40187const char ExtensionService::kInstallDirectoryName[] = "Extensions";
[email protected]15d5b472011-11-24 04:17:24188
[email protected]31bb5ee62012-09-12 22:58:40189const char ExtensionService::kLocalAppSettingsDirectoryName[] =
[email protected]15d5b472011-11-24 04:17:24190 "Local App Settings";
[email protected]31bb5ee62012-09-12 22:58:40191const char ExtensionService::kLocalExtensionSettingsDirectoryName[] =
[email protected]15d5b472011-11-24 04:17:24192 "Local Extension Settings";
[email protected]31bb5ee62012-09-12 22:58:40193const char ExtensionService::kSyncAppSettingsDirectoryName[] =
[email protected]15d5b472011-11-24 04:17:24194 "Sync App Settings";
[email protected]31bb5ee62012-09-12 22:58:40195const char ExtensionService::kSyncExtensionSettingsDirectoryName[] =
[email protected]15d5b472011-11-24 04:17:24196 "Sync Extension Settings";
[email protected]31bb5ee62012-09-12 22:58:40197const char ExtensionService::kStateStoreName[] = "Extension State";
[email protected]494c06e2009-07-25 01:06:42198
[email protected]8e4560b62011-01-14 10:09:14199void ExtensionService::CheckExternalUninstall(const std::string& id) {
[email protected]a29a517a2011-01-21 21:11:12200 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]a8af9fdb2010-10-28 21:52:20201
[email protected]7a4c6852010-09-16 03:44:22202 // Check if the providers know about this extension.
[email protected]5df038b2012-07-16 19:03:27203 extensions::ProviderCollection::const_iterator i;
[email protected]0a60a2e2010-10-25 16:15:21204 for (i = external_extension_providers_.begin();
205 i != external_extension_providers_.end(); ++i) {
[email protected]8e4560b62011-01-14 10:09:14206 DCHECK(i->get()->IsReady());
[email protected]0a60a2e2010-10-25 16:15:21207 if (i->get()->HasExtension(id))
208 return; // Yup, known extension, don't uninstall.
[email protected]7a4c6852010-09-16 03:44:22209 }
210
[email protected]0f48fca2011-05-19 18:46:35211 // We get the list of external extensions to check from preferences.
212 // It is possible that an extension has preferences but is not loaded.
213 // For example, an extension that requires experimental permissions
214 // will not be loaded if the experimental command line flag is not used.
215 // In this case, do not uninstall.
[email protected]31bb5ee62012-09-12 22:58:40216 if (!GetInstalledExtension(id)) {
[email protected]0f48fca2011-05-19 18:46:35217 // We can't call UninstallExtension with an unloaded/invalid
218 // extension ID.
219 LOG(WARNING) << "Attempted uninstallation of unloaded/invalid extension "
220 << "with id: " << id;
221 return;
222 }
[email protected]d6ebc9792011-04-07 18:18:33223 UninstallExtension(id, true, NULL);
[email protected]7a4c6852010-09-16 03:44:22224}
225
[email protected]8e4560b62011-01-14 10:09:14226void ExtensionService::ClearProvidersForTesting() {
[email protected]7a4c6852010-09-16 03:44:22227 external_extension_providers_.clear();
228}
229
[email protected]8e4560b62011-01-14 10:09:14230void ExtensionService::AddProviderForTesting(
[email protected]5df038b2012-07-16 19:03:27231 extensions::ExternalProviderInterface* test_provider) {
[email protected]a29a517a2011-01-21 21:11:12232 CHECK(test_provider);
[email protected]0a60a2e2010-10-25 16:15:21233 external_extension_providers_.push_back(
[email protected]5df038b2012-07-16 19:03:27234 linked_ptr<extensions::ExternalProviderInterface>(test_provider));
[email protected]7a4c6852010-09-16 03:44:22235}
236
[email protected]9060d8b02012-01-13 02:14:30237bool ExtensionService::OnExternalExtensionUpdateUrlFound(
[email protected]7a4c6852010-09-16 03:44:22238 const std::string& id,
[email protected]21a5a672010-11-04 10:47:42239 const GURL& update_url,
240 Extension::Location location) {
[email protected]ab22ba42011-01-14 16:36:38241 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
242 CHECK(Extension::IdIsValid(id));
[email protected]a8af9fdb2010-10-28 21:52:20243
[email protected]8a87a5332011-08-11 17:54:59244 const Extension* extension = GetExtensionById(id, true);
245 if (extension) {
246 // Already installed. Skip this install if the current location has
247 // higher priority than |location|.
248 Extension::Location current = extension->location();
249 if (current == Extension::GetHigherPriorityLocation(current, location))
[email protected]9060d8b02012-01-13 02:14:30250 return false;
[email protected]8a87a5332011-08-11 17:54:59251 // Otherwise, overwrite the current installation.
[email protected]7a4c6852010-09-16 03:44:22252 }
[email protected]9060d8b02012-01-13 02:14:30253
254 // Add |id| to the set of pending extensions. If it can not be added,
255 // then there is already a pending record from a higher-priority install
256 // source. In this case, signal that this extension will not be
257 // installed by returning false.
258 if (!pending_extension_manager()->AddFromExternalUpdateUrl(
[email protected]31bb5ee62012-09-12 22:58:40259 id, update_url, location)) {
[email protected]9060d8b02012-01-13 02:14:30260 return false;
[email protected]31bb5ee62012-09-12 22:58:40261 }
[email protected]9060d8b02012-01-13 02:14:30262
[email protected]94fde232012-04-27 10:22:30263 update_once_all_providers_are_ready_ = true;
[email protected]9060d8b02012-01-13 02:14:30264 return true;
[email protected]7a4c6852010-09-16 03:44:22265}
266
[email protected]dc9a74f72012-08-17 18:07:21267const Extension* ExtensionService::GetInstalledApp(const GURL& url) const {
[email protected]615d88f2011-12-13 01:47:44268 const Extension* extension = extensions_.GetExtensionOrAppByURL(
269 ExtensionURLInfo(url));
[email protected]dc9a74f72012-08-17 18:07:21270 return (extension && extension->is_app()) ? extension : NULL;
[email protected]d9696672011-03-15 22:45:09271}
272
[email protected]dc9a74f72012-08-17 18:07:21273bool ExtensionService::IsInstalledApp(const GURL& url) const {
[email protected]d9696672011-03-15 22:45:09274 return !!GetInstalledApp(url);
[email protected]ffb204f22010-12-05 23:20:27275}
276
[email protected]da5683db2011-04-23 17:12:21277void ExtensionService::SetInstalledAppForRenderer(int renderer_child_id,
278 const Extension* app) {
279 installed_app_hosts_[renderer_child_id] = app;
280}
281
282const Extension* ExtensionService::GetInstalledAppForRenderer(
[email protected]dc9a74f72012-08-17 18:07:21283 int renderer_child_id) const {
284 InstalledAppMap::const_iterator i =
285 installed_app_hosts_.find(renderer_child_id);
286 return i == installed_app_hosts_.end() ? NULL : i->second;
[email protected]da5683db2011-04-23 17:12:21287}
288
[email protected]6aeac8342010-10-01 20:21:18289// static
[email protected]d6ebc9792011-04-07 18:18:33290// This function is used to implement the command-line switch
[email protected]3bdba0d2011-08-23 07:17:30291// --uninstall-extension, and to uninstall an extension via sync. The LOG
292// statements within this function are used to inform the user if the uninstall
293// cannot be done.
[email protected]eaa7dd182010-12-14 11:09:00294bool ExtensionService::UninstallExtensionHelper(
295 ExtensionService* extensions_service,
[email protected]6aeac8342010-10-01 20:21:18296 const std::string& extension_id) {
[email protected]d6ebc9792011-04-07 18:18:33297 // We can't call UninstallExtension with an invalid extension ID.
[email protected]31bb5ee62012-09-12 22:58:40298 if (!extensions_service->GetInstalledExtension(extension_id)) {
[email protected]6aeac8342010-10-01 20:21:18299 LOG(WARNING) << "Attempted uninstallation of non-existent extension with "
[email protected]95da88c42011-03-31 10:07:33300 << "id: " << extension_id;
301 return false;
[email protected]6aeac8342010-10-01 20:21:18302 }
303
[email protected]d6ebc9792011-04-07 18:18:33304 // The following call to UninstallExtension will not allow an uninstall of a
305 // policy-controlled extension.
[email protected]65187152012-06-02 13:14:14306 string16 error;
[email protected]d6ebc9792011-04-07 18:18:33307 if (!extensions_service->UninstallExtension(extension_id, false, &error)) {
308 LOG(WARNING) << "Cannot uninstall extension with id " << extension_id
309 << ": " << error;
310 return false;
311 }
[email protected]95da88c42011-03-31 10:07:33312
[email protected]6aeac8342010-10-01 20:21:18313 return true;
314}
315
[email protected]eaa7dd182010-12-14 11:09:00316ExtensionService::ExtensionService(Profile* profile,
[email protected]f0841cd2011-01-19 15:07:24317 const CommandLine* command_line,
318 const FilePath& install_directory,
[email protected]45759612012-07-10 17:21:23319 extensions::ExtensionPrefs* extension_prefs,
[email protected]0436b102011-04-15 18:30:03320 bool autoupdate_enabled,
321 bool extensions_enabled)
[email protected]d8c8f25f2011-11-02 18:18:01322 : profile_(profile),
[email protected]bd306722012-07-11 20:43:59323 system_(extensions::ExtensionSystem::Get(profile)),
[email protected]73c47932010-12-06 18:13:43324 extension_prefs_(extension_prefs),
[email protected]cccdf0aa2011-11-11 03:43:38325 settings_frontend_(extensions::SettingsFrontend::Create(profile)),
[email protected]14908b72011-04-20 06:54:36326 pending_extension_manager_(*ALLOW_THIS_IN_INITIALIZER_LIST(this)),
[email protected]a9b00ac2009-06-25 21:03:23327 install_directory_(install_directory),
[email protected]0436b102011-04-15 18:30:03328 extensions_enabled_(extensions_enabled),
[email protected]e81dba32009-06-19 20:19:13329 show_extensions_prompts_(true),
[email protected]3ecda252010-11-18 19:50:55330 ready_(false),
[email protected]14908b72011-04-20 06:54:36331 toolbar_model_(ALLOW_THIS_IN_INITIALIZER_LIST(this)),
[email protected]8b280302011-10-13 22:22:23332 menu_manager_(profile),
[email protected]8d92e0382012-08-01 18:06:52333 app_notification_manager_(
334 new extensions::AppNotificationManager(profile)),
[email protected]7c1490da2011-10-11 18:53:25335 event_routers_initialized_(false),
[email protected]dff1e042012-04-27 10:59:18336 update_once_all_providers_are_ready_(false),
[email protected]5db9ada2012-04-11 13:48:20337 app_sync_bundle_(ALLOW_THIS_IN_INITIALIZER_LIST(this)),
338 extension_sync_bundle_(ALLOW_THIS_IN_INITIALIZER_LIST(this)),
[email protected]a1755bd2011-12-09 00:40:20339 extension_warnings_(profile),
[email protected]178f8512012-02-09 01:49:36340 app_shortcut_manager_(profile) {
[email protected]a29a517a2011-01-21 21:11:12341 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]a8af9fdb2010-10-28 21:52:20342
[email protected]36a784c2009-06-23 06:21:08343 // Figure out if extension installation should be enabled.
[email protected]31bb5ee62012-09-12 22:58:40344 if (command_line->HasSwitch(switches::kDisableExtensions) ||
345 profile->GetPrefs()->GetBoolean(prefs::kDisableExtensions)) {
[email protected]6d60703b2009-08-29 01:29:23346 extensions_enabled_ = false;
[email protected]6b75ec32009-08-14 06:37:18347 }
[email protected]36a784c2009-06-23 06:21:08348
[email protected]432115822011-07-10 15:52:27349 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_PROCESS_TERMINATED,
[email protected]ad50def52011-10-19 23:17:07350 content::NotificationService::AllBrowserContextsAndSources());
[email protected]432115822011-07-10 15:52:27351 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_CREATED,
[email protected]ad50def52011-10-19 23:17:07352 content::NotificationService::AllBrowserContextsAndSources());
[email protected]432115822011-07-10 15:52:27353 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_TERMINATED,
[email protected]ad50def52011-10-19 23:17:07354 content::NotificationService::AllBrowserContextsAndSources());
[email protected]2fb7dc982010-09-29 12:24:28355 pref_change_registrar_.Init(profile->GetPrefs());
356 pref_change_registrar_.Add(prefs::kExtensionInstallAllowList, this);
357 pref_change_registrar_.Add(prefs::kExtensionInstallDenyList, this);
[email protected]4814b512009-11-07 00:12:29358
[email protected]93fd78f42009-07-10 16:43:17359 // Set up the ExtensionUpdater
360 if (autoupdate_enabled) {
361 int update_frequency = kDefaultUpdateFrequencySeconds;
362 if (command_line->HasSwitch(switches::kExtensionsUpdateFrequency)) {
[email protected]e83326f2010-07-31 17:29:25363 base::StringToInt(command_line->GetSwitchValueASCII(
364 switches::kExtensionsUpdateFrequency),
365 &update_frequency);
[email protected]93fd78f42009-07-10 16:43:17366 }
[email protected]42a08162012-03-16 18:09:11367 updater_.reset(new extensions::ExtensionUpdater(this,
368 extension_prefs,
369 profile->GetPrefs(),
370 profile,
371 update_frequency));
[email protected]93fd78f42009-07-10 16:43:17372 }
373
[email protected]25ae0152011-11-18 14:40:02374 component_loader_.reset(
375 new extensions::ComponentLoader(this,
376 profile->GetPrefs(),
377 g_browser_process->local_state()));
[email protected]8e4560b62011-01-14 10:09:14378
[email protected]af9db5f2011-10-05 05:13:15379 app_notification_manager_->Init();
380
[email protected]0436b102011-04-15 18:30:03381 if (extensions_enabled_) {
[email protected]1f2f3002011-12-28 00:40:21382 if (!command_line->HasSwitch(switches::kImport) &&
383 !command_line->HasSwitch(switches::kImportFromFile)) {
[email protected]5df038b2012-07-16 19:03:27384 extensions::ExternalProviderImpl::CreateExternalProviders(
[email protected]1f2f3002011-12-28 00:40:21385 this, profile_, &external_extension_providers_);
386 }
[email protected]873531342011-03-09 12:16:05387 }
[email protected]b671760b2010-07-15 21:13:47388
[email protected]aa96d3a2010-08-21 08:45:25389 // Use monochrome icons for Omnibox icons.
[email protected]29d0d4ac2010-09-08 21:10:31390 omnibox_popup_icon_manager_.set_monochrome(true);
[email protected]b671760b2010-07-15 21:13:47391 omnibox_icon_manager_.set_monochrome(true);
[email protected]29d0d4ac2010-09-08 21:10:31392 omnibox_icon_manager_.set_padding(gfx::Insets(0, kOmniboxIconPaddingLeft,
393 0, kOmniboxIconPaddingRight));
[email protected]cb0e50312011-05-09 15:03:07394
[email protected]fb82dcd2012-03-21 14:15:46395 // Set this as the ExtensionService for extension sorting to ensure it
396 // cause syncs if required.
397 extension_prefs_->extension_sorting()->SetExtensionService(this);
398
[email protected]9ce11d22012-08-08 23:20:13399#if defined(ENABLE_EXTENSIONS)
[email protected]c77f2352012-08-08 22:07:58400 extension_action_storage_manager_.reset(
401 new extensions::ExtensionActionStorageManager(profile_));
[email protected]9ce11d22012-08-08 23:20:13402#endif
[email protected]c77f2352012-08-08 22:07:58403
[email protected]cb0e50312011-05-09 15:03:07404 // How long is the path to the Extensions directory?
405 UMA_HISTOGRAM_CUSTOM_COUNTS("Extensions.ExtensionRootPathLength",
406 install_directory_.value().length(), 0, 500, 100);
[email protected]6014d672008-12-05 00:38:25407}
408
[email protected]84df8332011-12-06 18:22:46409const ExtensionSet* ExtensionService::extensions() const {
[email protected]ddb1e5a2010-12-13 20:10:45410 return &extensions_;
411}
412
[email protected]84df8332011-12-06 18:22:46413const ExtensionSet* ExtensionService::disabled_extensions() const {
[email protected]ddb1e5a2010-12-13 20:10:45414 return &disabled_extensions_;
415}
416
[email protected]84df8332011-12-06 18:22:46417const ExtensionSet* ExtensionService::terminated_extensions() const {
[email protected]bb7f40952011-01-13 00:21:20418 return &terminated_extensions_;
419}
420
[email protected]7f4308d2012-01-18 07:43:01421const ExtensionSet* ExtensionService::GenerateInstalledExtensionsSet() const {
422 ExtensionSet* installed_extensions = new ExtensionSet();
423 installed_extensions->InsertAll(extensions_);
424 installed_extensions->InsertAll(disabled_extensions_);
425 installed_extensions->InsertAll(terminated_extensions_);
426 return installed_extensions;
427}
428
[email protected]3f213ad2012-07-26 23:39:41429extensions::PendingExtensionManager*
430 ExtensionService::pending_extension_manager() {
[email protected]b2907fd2011-03-25 16:43:37431 return &pending_extension_manager_;
[email protected]ddb1e5a2010-12-13 20:10:45432}
433
[email protected]eaa7dd182010-12-14 11:09:00434ExtensionService::~ExtensionService() {
[email protected]c8d407e2011-04-28 21:27:17435 // No need to unload extensions here because they are profile-scoped, and the
436 // profile is in the process of being deleted.
[email protected]94b4ffc2011-02-04 05:55:17437
[email protected]5df038b2012-07-16 19:03:27438 extensions::ProviderCollection::const_iterator i;
[email protected]8e4560b62011-01-14 10:09:14439 for (i = external_extension_providers_.begin();
440 i != external_extension_providers_.end(); ++i) {
[email protected]5df038b2012-07-16 19:03:27441 extensions::ExternalProviderInterface* provider = i->get();
[email protected]8e4560b62011-01-14 10:09:14442 provider->ServiceShutdown();
443 }
[email protected]6014d672008-12-05 00:38:25444}
445
[email protected]d91268022011-08-26 13:17:37446void ExtensionService::InitEventRoutersAfterImport() {
[email protected]cf593af2011-12-30 05:44:39447 RegisterForImportFinished();
448}
449
450void ExtensionService::RegisterForImportFinished() {
451 if (!registrar_.IsRegistered(this, chrome::NOTIFICATION_IMPORT_FINISHED,
452 content::Source<Profile>(profile_))) {
453 registrar_.Add(this, chrome::NOTIFICATION_IMPORT_FINISHED,
454 content::Source<Profile>(profile_));
455 }
456}
457
458void ExtensionService::InitAfterImport() {
459 CheckForExternalUpdates();
460
461 GarbageCollectExtensions();
462
463 // Idempotent, so although there is a possible race if the import
464 // process finished sometime in the middle of ProfileImpl::InitExtensions,
465 // it cannot happen twice.
466 InitEventRouters();
[email protected]d91268022011-08-26 13:17:37467}
468
[email protected]eaa7dd182010-12-14 11:09:00469void ExtensionService::InitEventRouters() {
[email protected]b3d62312b12010-10-14 21:10:18470 if (event_routers_initialized_)
471 return;
472
[email protected]6a3cd37e2012-04-17 17:13:34473#if defined(ENABLE_EXTENSIONS)
[email protected]d2e6bd62011-10-24 20:29:07474 history_event_router_.reset(new HistoryExtensionEventRouter());
[email protected]f825df22011-06-28 17:36:10475 history_event_router_->ObserveProfile(profile_);
[email protected]5a38dfd2012-07-23 23:22:10476 browser_event_router_.reset(new extensions::BrowserEventRouter(profile_));
[email protected]34517242012-05-25 02:37:18477 browser_event_router_->Init();
[email protected]163ed192012-07-24 19:31:07478 window_event_router_.reset(new extensions::WindowEventRouter(profile_));
479 window_event_router_->Init();
[email protected]118de7892011-03-16 13:31:40480 preference_event_router_.reset(new ExtensionPreferenceEventRouter(profile_));
[email protected]23d5f172011-10-25 05:49:53481 bookmark_event_router_.reset(new BookmarkExtensionEventRouter(
[email protected]e07f2da2012-08-01 22:46:12482 BookmarkModelFactory::GetForProfile(profile_)));
[email protected]f825df22011-06-28 17:36:10483 bookmark_event_router_->Init();
[email protected]31bb5ee62012-09-12 22:58:40484 cookies_event_router_.reset(
485 new extensions::ExtensionCookiesEventRouter(profile_));
[email protected]f825df22011-06-28 17:36:10486 cookies_event_router_->Init();
487 management_event_router_.reset(new ExtensionManagementEventRouter(profile_));
488 management_event_router_->Init();
[email protected]bc500fa2012-09-06 09:03:30489 extensions::ProcessesEventRouter::GetInstance()->ObserveProfile(profile_);
[email protected]f825df22011-06-28 17:36:10490 web_navigation_event_router_.reset(
[email protected]017ecde92012-04-04 09:11:26491 new extensions::WebNavigationEventRouter(profile_));
[email protected]f825df22011-06-28 17:36:10492 web_navigation_event_router_->Init();
[email protected]bdd34452012-04-16 15:58:40493 font_settings_event_router_.reset(
[email protected]91aa8a32012-08-07 10:35:33494 new extensions::FontSettingsEventRouter(profile_));
[email protected]bdd34452012-04-16 15:58:40495 font_settings_event_router_->Init();
[email protected]8a4cf842012-05-16 13:35:30496 managed_mode_event_router_.reset(
[email protected]9c70e0d92012-07-16 08:39:44497 new extensions::ExtensionManagedModeEventRouter(profile_));
[email protected]8a4cf842012-05-16 13:35:30498 managed_mode_event_router_->Init();
[email protected]5ebd6a62012-08-01 23:54:39499 push_messaging_event_router_.reset(
500 new extensions::PushMessagingEventRouter(profile_));
501 push_messaging_event_router_->Init();
[email protected]31bb5ee62012-09-12 22:58:40502 media_galleries_private_event_router_.reset(
503 new extensions::MediaGalleriesPrivateEventRouter(profile_));
[email protected]27072cad2011-05-09 19:46:40504
[email protected]eed367e2011-04-12 03:43:31505#if defined(OS_CHROMEOS)
[email protected]2a72c9f2012-03-17 15:10:30506 FileBrowserEventRouterFactory::GetForProfile(
507 profile_)->ObserveFileSystemEvents();
[email protected]771a6182011-10-05 16:32:52508
[email protected]f463bc92012-03-22 16:38:23509 bluetooth_event_router_.reset(
510 new chromeos::ExtensionBluetoothEventRouter(profile_));
511
[email protected]771a6182011-10-05 16:32:52512 input_method_event_router_.reset(
513 new chromeos::ExtensionInputMethodEventRouter);
[email protected]be5bd5742011-07-14 07:21:01514
[email protected]c8bf09be2011-06-25 03:22:27515 ExtensionMediaPlayerEventRouter::GetInstance()->Init(profile_);
[email protected]1364c6d2012-07-24 11:57:19516 extensions::InputImeEventRouter::GetInstance()->Init();
[email protected]31bb5ee62012-09-12 22:58:40517#endif // defined(OS_CHROMEOS)
[email protected]6a3cd37e2012-04-17 17:13:34518#endif // defined(ENABLE_EXTENSIONS)
[email protected]b3d62312b12010-10-14 21:10:18519 event_routers_initialized_ = true;
[email protected]c5ae74ab2010-04-15 18:14:37520}
521
[email protected]47b896562012-08-22 23:55:15522void ExtensionService::Shutdown() {
[email protected]b5f12622012-08-23 20:59:33523 if (push_messaging_event_router_.get())
524 push_messaging_event_router_->Shutdown();
[email protected]47b896562012-08-22 23:55:15525}
526
[email protected]b2907fd2011-03-25 16:43:37527const Extension* ExtensionService::GetExtensionById(
528 const std::string& id, bool include_disabled) const {
[email protected]81f0d162012-08-15 04:21:47529 int include_mask = INCLUDE_ENABLED;
[email protected]31bb5ee62012-09-12 22:58:40530 if (include_disabled)
[email protected]81f0d162012-08-15 04:21:47531 include_mask |= INCLUDE_DISABLED;
[email protected]81f0d162012-08-15 04:21:47532 return GetExtensionByIdInternal(id, include_mask);
[email protected]78994ab02010-12-08 18:06:44533}
534
[email protected]eaa7dd182010-12-14 11:09:00535void ExtensionService::Init() {
[email protected]a29a517a2011-01-21 21:11:12536 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]a8af9fdb2010-10-28 21:52:20537
[email protected]fa6a9102010-11-22 15:38:50538 DCHECK(!ready_); // Can't redo init.
[email protected]93fd78f42009-07-10 16:43:17539 DCHECK_EQ(extensions_.size(), 0u);
[email protected]9f1087e2009-06-15 17:29:32540
[email protected]d8c8f25f2011-11-02 18:18:01541 component_loader_->LoadAll();
542 extensions::InstalledLoader(this).LoadAllExtensions();
[email protected]894bb502009-05-21 22:39:57543
[email protected]7a161db2011-12-15 20:45:51544 // If we are running in the import process, don't bother initializing the
545 // extension service since this can interfere with the main browser process
546 // that is already running an extension service for this profile.
547 // TODO(aa): can we start up even less of ExtensionService?
548 // http://crbug.com/107636
[email protected]1f2f3002011-12-28 00:40:21549 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kImport) &&
550 !CommandLine::ForCurrentProcess()->HasSwitch(switches::kImportFromFile)) {
[email protected]cf593af2011-12-30 05:44:39551 if (g_browser_process->profile_manager() &&
552 g_browser_process->profile_manager()->will_import()) {
553 RegisterForImportFinished();
554 } else {
555 // TODO(erikkay) this should probably be deferred to a future point
556 // rather than running immediately at startup.
557 CheckForExternalUpdates();
[email protected]894bb502009-05-21 22:39:57558
[email protected]cf593af2011-12-30 05:44:39559 // TODO(erikkay) this should probably be deferred as well.
560 GarbageCollectExtensions();
561 }
[email protected]7a161db2011-12-15 20:45:51562 }
[email protected]6014d672008-12-05 00:38:25563}
564
[email protected]31bb5ee62012-09-12 22:58:40565bool ExtensionService::UpdateExtension(const std::string& id,
566 const FilePath& extension_path,
567 const GURL& download_url,
568 CrxInstaller** out_crx_installer) {
[email protected]a29a517a2011-01-21 21:11:12569 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]a8af9fdb2010-10-28 21:52:20570
[email protected]3f213ad2012-07-26 23:39:41571 const extensions::PendingExtensionInfo* pending_extension_info =
[email protected]51a3bf8b2012-06-08 22:53:06572 pending_extension_manager()->GetById(id);
[email protected]8ef78fd2010-08-19 17:14:32573
[email protected]31bb5ee62012-09-12 22:58:40574 int include_mask = INCLUDE_ENABLED | INCLUDE_DISABLED;
[email protected]8001df22011-04-28 19:59:47575 const Extension* extension =
[email protected]81f0d162012-08-15 04:21:47576 GetExtensionByIdInternal(id, include_mask);
[email protected]51a3bf8b2012-06-08 22:53:06577 if (!pending_extension_info && !extension) {
[email protected]aa142702010-03-26 01:26:33578 LOG(WARNING) << "Will not update extension " << id
579 << " because it is not installed or pending";
580 // Delete extension_path since we're not creating a CrxInstaller
581 // that would do it for us.
[email protected]14908b72011-04-20 06:54:36582 if (!BrowserThread::PostTask(
583 BrowserThread::FILE, FROM_HERE,
[email protected]53612e82011-10-18 18:00:36584 base::Bind(
[email protected]7296f2762011-11-21 19:23:44585 &extension_file_util::DeleteFile, extension_path, false)))
[email protected]14908b72011-04-20 06:54:36586 NOTREACHED();
[email protected]420a0ec2011-06-01 01:07:03587
588 return false;
[email protected]e957fe52009-06-23 16:51:05589 }
590
[email protected]aa142702010-03-26 01:26:33591 // We want a silent install only for non-pending extensions and
592 // pending extensions that have install_silently set.
[email protected]c82da8c42012-06-08 19:49:11593 ExtensionInstallPrompt* client =
[email protected]51a3bf8b2012-06-08 22:53:06594 (!pending_extension_info || pending_extension_info->install_silently()) ?
[email protected]00b38242012-07-18 18:43:22595 NULL : ExtensionInstallUI::CreateInstallPromptWithProfile(profile_);
[email protected]aa142702010-03-26 01:26:33596
[email protected]d8c8f25f2011-11-02 18:18:01597 scoped_refptr<CrxInstaller> installer(CrxInstaller::Create(this, client));
[email protected]6dfbbf82010-03-12 23:09:16598 installer->set_expected_id(id);
[email protected]51a3bf8b2012-06-08 22:53:06599 if (pending_extension_info) {
600 installer->set_install_source(pending_extension_info->install_source());
601 if (pending_extension_info->install_silently())
602 installer->set_allow_silent_install(true);
603 } else if (extension) {
[email protected]5eb375e92010-11-26 07:50:41604 installer->set_install_source(extension->location());
[email protected]51a3bf8b2012-06-08 22:53:06605 }
[email protected]7d8b7072012-04-07 01:07:46606 // If the extension was installed from or has migrated to the webstore, or
607 // if the extension came from sync and its auto-update URL is from the
[email protected]75764512011-12-19 19:54:28608 // webstore, treat it as a webstore install. Note that we ignore some older
609 // extensions with blank auto-update URLs because we are mostly concerned
610 // with restrictions on NaCl extensions, which are newer.
[email protected]a12ce8b22012-01-17 18:40:53611 int creation_flags = Extension::NO_FLAGS;
[email protected]75764512011-12-19 19:54:28612 if ((extension && extension->from_webstore()) ||
[email protected]7d8b7072012-04-07 01:07:46613 (extension && extension->UpdatesFromGallery()) ||
[email protected]51a3bf8b2012-06-08 22:53:06614 (!extension && pending_extension_info->is_from_sync() &&
[email protected]75764512011-12-19 19:54:28615 extension_urls::IsWebstoreUpdateUrl(
[email protected]51a3bf8b2012-06-08 22:53:06616 pending_extension_info->update_url()))) {
[email protected]a12ce8b22012-01-17 18:40:53617 creation_flags |= Extension::FROM_WEBSTORE;
618 }
619
620 // Bookmark apps being updated is kind of a contradiction, but that's because
621 // we mark the default apps as bookmark apps, and they're hosted in the web
622 // store, thus they can get updated. See http://crbug.com/101605 for more
623 // details.
624 if (extension && extension->from_bookmark())
625 creation_flags |= Extension::FROM_BOOKMARK;
626
[email protected]e33bbc22012-08-27 22:05:46627 if (extension && extension->was_installed_by_default())
628 creation_flags |= Extension::WAS_INSTALLED_BY_DEFAULT;
629
[email protected]a12ce8b22012-01-17 18:40:53630 installer->set_creation_flags(creation_flags);
631
[email protected]6dfbbf82010-03-12 23:09:16632 installer->set_delete_source(true);
[email protected]655b2b1a2011-10-13 17:13:06633 installer->set_download_url(download_url);
[email protected]cb0e50312011-05-09 15:03:07634 installer->set_install_cause(extension_misc::INSTALL_CAUSE_UPDATE);
[email protected]6dfbbf82010-03-12 23:09:16635 installer->InstallCrx(extension_path);
[email protected]420a0ec2011-06-01 01:07:03636
637 if (out_crx_installer)
638 *out_crx_installer = installer;
639
640 return true;
[email protected]e957fe52009-06-23 16:51:05641}
642
[email protected]eaa7dd182010-12-14 11:09:00643void ExtensionService::ReloadExtension(const std::string& extension_id) {
[email protected]a29a517a2011-01-21 21:11:12644 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]b65272f2009-08-31 15:47:06645 FilePath path;
[email protected]9adb9692010-10-29 23:14:02646 const Extension* current_extension = GetExtensionById(extension_id, false);
[email protected]9cddd4702009-07-27 22:09:40647
[email protected]f17dbd42010-08-16 23:21:10648 // Disable the extension if it's loaded. It might not be loaded if it crashed.
[email protected]b65272f2009-08-31 15:47:06649 if (current_extension) {
[email protected]4814b512009-11-07 00:12:29650 // If the extension has an inspector open for its background page, detach
651 // the inspector and hang onto a cookie for it, so that we can reattach
652 // later.
[email protected]31d8f5f22012-04-02 15:22:08653 // TODO(yoz): this is not incognito-safe!
654 ExtensionProcessManager* manager = system_->process_manager();
[email protected]3a1dc572012-07-31 22:25:13655 extensions::ExtensionHost* host =
656 manager->GetBackgroundHostForExtension(extension_id);
[email protected]0e12d7d2011-12-01 16:21:44657 if (host && DevToolsAgentHostRegistry::HasDevToolsAgentHost(
658 host->render_view_host())) {
[email protected]4814b512009-11-07 00:12:29659 // Look for an open inspector for the background page.
[email protected]0e12d7d2011-12-01 16:21:44660 DevToolsAgentHost* agent =
661 DevToolsAgentHostRegistry::GetDevToolsAgentHost(
662 host->render_view_host());
663 int devtools_cookie =
664 content::DevToolsManager::GetInstance()->DetachClientHost(agent);
[email protected]4814b512009-11-07 00:12:29665 if (devtools_cookie >= 0)
666 orphaned_dev_tools_[extension_id] = devtools_cookie;
667 }
668
[email protected]6cafe35a2012-08-27 22:40:50669 if (current_extension->is_platform_app() &&
670 !extensions::ShellWindowRegistry::Get(profile_)->
671 GetShellWindowsForApp(extension_id).empty()) {
672 relaunch_app_ids_.insert(extension_id);
673 }
674
[email protected]b65272f2009-08-31 15:47:06675 path = current_extension->path();
[email protected]44d62b62012-04-11 00:06:03676 DisableExtension(extension_id, Extension::DISABLE_RELOAD);
[email protected]f17dbd42010-08-16 23:21:10677 disabled_extension_paths_[extension_id] = path;
[email protected]1eb175082010-02-10 09:26:16678 } else {
679 path = unloaded_extension_paths_[extension_id];
[email protected]b65272f2009-08-31 15:47:06680 }
681
[email protected]43ceb002012-02-10 23:19:15682 // If we're reloading a component extension, use the component extension
683 // loader's reloader.
684 if (component_loader_->Exists(extension_id)) {
685 component_loader_->Reload(extension_id);
686 return;
687 }
688
[email protected]e6090e42010-03-23 22:44:08689 // Check the installed extensions to see if what we're reloading was already
690 // installed.
691 scoped_ptr<ExtensionInfo> installed_extension(
692 extension_prefs_->GetInstalledExtensionInfo(extension_id));
693 if (installed_extension.get() &&
694 installed_extension->extension_manifest.get()) {
[email protected]d8c8f25f2011-11-02 18:18:01695 extensions::InstalledLoader(this).Load(*installed_extension, false);
[email protected]e6090e42010-03-23 22:44:08696 } else {
[email protected]d8c8f25f2011-11-02 18:18:01697 // Otherwise, the extension is unpacked (location LOAD).
[email protected]e6090e42010-03-23 22:44:08698 // We should always be able to remember the extension's path. If it's not in
699 // the map, someone failed to update |unloaded_extension_paths_|.
700 CHECK(!path.empty());
[email protected]d8c8f25f2011-11-02 18:18:01701 extensions::UnpackedInstaller::Create(this)->Load(path);
[email protected]e6090e42010-03-23 22:44:08702 }
[email protected]9cddd4702009-07-27 22:09:40703}
704
[email protected]fa2416f2011-05-03 08:41:20705bool ExtensionService::UninstallExtension(
[email protected]a12c706e2011-12-01 00:58:08706 std::string extension_id,
[email protected]fa2416f2011-05-03 08:41:20707 bool external_uninstall,
[email protected]65187152012-06-02 13:14:14708 string16* error) {
[email protected]a29a517a2011-01-21 21:11:12709 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]a8af9fdb2010-10-28 21:52:20710
[email protected]0d6ec3a72011-09-02 02:09:43711 scoped_refptr<const Extension> extension(GetInstalledExtension(extension_id));
[email protected]631cf822009-05-15 07:01:25712
[email protected]e7afe2452010-08-22 16:19:13713 // Callers should not send us nonexistent extensions.
[email protected]aebe23a32010-12-10 22:15:48714 CHECK(extension);
[email protected]9f1087e2009-06-15 17:29:32715
[email protected]95da88c42011-03-31 10:07:33716 // Policy change which triggers an uninstall will always set
717 // |external_uninstall| to true so this is the only way to uninstall
718 // managed extensions.
[email protected]65187152012-06-02 13:14:14719 if (!external_uninstall &&
720 !system_->management_policy()->UserMayModifySettings(
721 extension.get(), error)) {
[email protected]ad50def52011-10-19 23:17:07722 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:27723 chrome::NOTIFICATION_EXTENSION_UNINSTALL_NOT_ALLOWED,
[email protected]6c2381d2011-10-19 02:52:53724 content::Source<Profile>(profile_),
725 content::Details<const Extension>(extension));
[email protected]d6ebc9792011-04-07 18:18:33726 return false;
727 }
[email protected]95da88c42011-03-31 10:07:33728
[email protected]3bdba0d2011-08-23 07:17:30729 // Extract the data we need for sync now, but don't actually sync until we've
730 // completed the uninstallation.
[email protected]65f173552012-06-28 22:43:58731 syncer::SyncChange sync_change;
[email protected]5db9ada2012-04-11 13:48:20732 if (app_sync_bundle_.HandlesApp(*extension)) {
733 sync_change = app_sync_bundle_.CreateSyncChangeToDelete(extension);
734 } else if (extension_sync_bundle_.HandlesExtension(*extension)) {
735 sync_change = extension_sync_bundle_.CreateSyncChangeToDelete(extension);
[email protected]3bdba0d2011-08-23 07:17:30736 }
737
[email protected]9b217652010-10-08 22:04:23738 UMA_HISTOGRAM_ENUMERATION("Extensions.UninstallType",
[email protected]7fa19f82010-12-21 19:40:08739 extension->GetType(), 100);
[email protected]fe2dd7742011-04-19 22:52:49740 RecordPermissionMessagesHistogram(
741 extension, "Extensions.Permissions_Uninstall");
[email protected]9b217652010-10-08 22:04:23742
[email protected]8e5c89a2011-06-07 18:13:33743 TemplateURLService* url_service =
744 TemplateURLServiceFactory::GetForProfile(profile_);
745 if (url_service)
746 url_service->UnregisterExtensionKeyword(extension);
[email protected]56ad3792010-05-28 17:45:33747
[email protected]831aa212010-03-26 13:55:19748 // Unload before doing more cleanup to ensure that nothing is hanging on to
749 // any of these resources.
[email protected]814a7bf0f2011-08-13 05:30:59750 UnloadExtension(extension_id, extension_misc::UNLOAD_REASON_UNINSTALL);
[email protected]831aa212010-03-26 13:55:19751
[email protected]0d6ec3a72011-09-02 02:09:43752 extension_prefs_->OnExtensionUninstalled(extension_id, extension->location(),
[email protected]831aa212010-03-26 13:55:19753 external_uninstall);
[email protected]9f1087e2009-06-15 17:29:32754
755 // Tell the backend to start deleting installed extensions on the file thread.
[email protected]0d6ec3a72011-09-02 02:09:43756 if (Extension::LOAD != extension->location()) {
[email protected]14908b72011-04-20 06:54:36757 if (!BrowserThread::PostTask(
758 BrowserThread::FILE, FROM_HERE,
[email protected]53612e82011-10-18 18:00:36759 base::Bind(
[email protected]14908b72011-04-20 06:54:36760 &extension_file_util::UninstallExtension,
761 install_directory_,
[email protected]fa2416f2011-05-03 08:41:20762 extension_id)))
[email protected]14908b72011-04-20 06:54:36763 NOTREACHED();
[email protected]9f1087e2009-06-15 17:29:32764 }
765
[email protected]0d6ec3a72011-09-02 02:09:43766 GURL launch_web_url_origin(extension->launch_web_url());
767 launch_web_url_origin = launch_web_url_origin.GetOrigin();
[email protected]605fb8102012-05-04 01:36:55768 bool is_storage_isolated = extension->is_storage_isolated();
[email protected]0d6ec3a72011-09-02 02:09:43769
770 if (extension->is_hosted_app() &&
771 !profile_->GetExtensionSpecialStoragePolicy()->
772 IsStorageProtected(launch_web_url_origin)) {
[email protected]d9ede582012-08-14 19:21:38773 extensions::DataDeleter::StartDeleting(
[email protected]dc0b5a12011-10-14 00:06:13774 profile_, extension_id, launch_web_url_origin, is_storage_isolated);
[email protected]0d6ec3a72011-09-02 02:09:43775 }
[email protected]d9ede582012-08-14 19:21:38776 extensions::DataDeleter::StartDeleting(
[email protected]dc0b5a12011-10-14 00:06:13777 profile_, extension_id, extension->url(), is_storage_isolated);
[email protected]0d6ec3a72011-09-02 02:09:43778
[email protected]0dfe05c2011-02-23 23:03:36779 UntrackTerminatedExtension(extension_id);
[email protected]211030342010-09-30 18:41:06780
781 // Notify interested parties that we've uninstalled this extension.
[email protected]ad50def52011-10-19 23:17:07782 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:27783 chrome::NOTIFICATION_EXTENSION_UNINSTALLED,
[email protected]6c2381d2011-10-19 02:52:53784 content::Source<Profile>(profile_),
[email protected]d67d9412012-07-17 17:19:42785 content::Details<const Extension>(extension));
[email protected]d6ebc9792011-04-07 18:18:33786
[email protected]5db9ada2012-04-11 13:48:20787 if (app_sync_bundle_.HasExtensionId(extension_id) &&
[email protected]a4a147652012-07-03 23:41:32788 sync_change.sync_data().GetDataType() == syncer::APPS) {
[email protected]5db9ada2012-04-11 13:48:20789 app_sync_bundle_.ProcessDeletion(extension_id, sync_change);
790 } else if (extension_sync_bundle_.HasExtensionId(extension_id) &&
[email protected]a4a147652012-07-03 23:41:32791 sync_change.sync_data().GetDataType() == syncer::EXTENSIONS) {
[email protected]5db9ada2012-04-11 13:48:20792 extension_sync_bundle_.ProcessDeletion(extension_id, sync_change);
[email protected]3bdba0d2011-08-23 07:17:30793 }
794
[email protected]333b1de2011-09-12 18:28:50795 // Track the uninstallation.
[email protected]49098f702011-10-13 03:47:18796 UMA_HISTOGRAM_ENUMERATION("Extensions.ExtensionUninstalled", 1, 2);
797
798 static bool default_apps_trial_exists =
[email protected]568c3312011-12-06 15:36:04799 base::FieldTrialList::TrialExists(kDefaultAppsTrialName);
[email protected]49098f702011-10-13 03:47:18800 if (default_apps_trial_exists) {
801 UMA_HISTOGRAM_ENUMERATION(
802 base::FieldTrial::MakeName("Extensions.ExtensionUninstalled",
[email protected]568c3312011-12-06 15:36:04803 kDefaultAppsTrialName),
[email protected]49098f702011-10-13 03:47:18804 1, 2);
805 }
[email protected]333b1de2011-09-12 18:28:50806
[email protected]7c1490da2011-10-11 18:53:25807 // Uninstalling one extension might have solved the problems of others.
808 // Therefore, we clear warnings of this type for all extensions.
809 std::set<ExtensionWarningSet::WarningType> warnings;
810 extension_warnings_.GetWarningsAffectingExtension(extension_id, &warnings);
811 extension_warnings_.ClearWarnings(warnings);
812
[email protected]d6ebc9792011-04-07 18:18:33813 return true;
[email protected]c10da4b02010-03-25 14:38:32814}
815
[email protected]c3cfb012011-04-06 22:07:35816bool ExtensionService::IsExtensionEnabled(
817 const std::string& extension_id) const {
[email protected]84df8332011-12-06 18:22:46818 if (extensions_.Contains(extension_id) ||
[email protected]dc9a74f72012-08-17 18:07:21819 terminated_extensions_.Contains(extension_id)) {
[email protected]36429da2011-07-11 20:25:18820 return true;
[email protected]dc9a74f72012-08-17 18:07:21821 }
[email protected]36429da2011-07-11 20:25:18822
[email protected]84df8332011-12-06 18:22:46823 if (disabled_extensions_.Contains(extension_id))
[email protected]ad83ca242011-07-29 01:32:25824 return false;
825
826 // If the extension hasn't been loaded yet, check the prefs for it. Assume
827 // enabled unless otherwise noted.
828 return !extension_prefs_->IsExtensionDisabled(extension_id) &&
829 !extension_prefs_->IsExternalExtensionUninstalled(extension_id);
[email protected]c3cfb012011-04-06 22:07:35830}
831
832bool ExtensionService::IsExternalExtensionUninstalled(
833 const std::string& extension_id) const {
834 return extension_prefs_->IsExternalExtensionUninstalled(extension_id);
835}
836
[email protected]eaa7dd182010-12-14 11:09:00837void ExtensionService::EnableExtension(const std::string& extension_id) {
[email protected]a29a517a2011-01-21 21:11:12838 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]a8af9fdb2010-10-28 21:52:20839
[email protected]06f92562011-04-29 19:27:31840 if (IsExtensionEnabled(extension_id))
[email protected]0c6da502009-08-14 22:32:39841 return;
[email protected]0c6da502009-08-14 22:32:39842
[email protected]b3317ad2011-04-28 23:46:00843 extension_prefs_->SetExtensionState(extension_id, Extension::ENABLED);
[email protected]eb5e4f92012-08-15 23:33:28844 extension_prefs_->ClearDisableReasons(extension_id);
[email protected]1784e83a2009-09-08 21:01:52845
[email protected]81f0d162012-08-15 04:21:47846 const Extension* extension = GetExtensionByIdInternal(extension_id,
847 INCLUDE_DISABLED);
[email protected]06f92562011-04-29 19:27:31848 // This can happen if sync enables an extension that is not
849 // installed yet.
850 if (!extension)
851 return;
852
[email protected]0c6da502009-08-14 22:32:39853 // Move it over to the enabled list.
[email protected]84df8332011-12-06 18:22:46854 extensions_.Insert(make_scoped_refptr(extension));
855 disabled_extensions_.Remove(extension->id());
[email protected]0c6da502009-08-14 22:32:39856
[email protected]f681c782010-11-19 11:19:39857 // Make sure any browser action contained within it is not hidden.
858 extension_prefs_->SetBrowserActionVisibility(extension, true);
859
[email protected]62d30f42009-10-01 22:36:06860 NotifyExtensionLoaded(extension);
[email protected]3bdba0d2011-08-23 07:17:30861
[email protected]f74d7f32012-06-19 19:22:51862 // Notify listeners that the extension was enabled.
863 content::NotificationService::current()->Notify(
864 chrome::NOTIFICATION_EXTENSION_ENABLED,
865 content::Source<Profile>(profile_),
866 content::Details<const Extension>(extension));
867
[email protected]3bdba0d2011-08-23 07:17:30868 SyncExtensionChangeIfNeeded(*extension);
[email protected]0c6da502009-08-14 22:32:39869}
870
[email protected]44d62b62012-04-11 00:06:03871void ExtensionService::DisableExtension(
872 const std::string& extension_id,
873 Extension::DisableReason disable_reason) {
[email protected]a29a517a2011-01-21 21:11:12874 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]a8af9fdb2010-10-28 21:52:20875
[email protected]b2ba9962009-12-10 20:10:15876 // The extension may have been disabled already.
[email protected]06f92562011-04-29 19:27:31877 if (!IsExtensionEnabled(extension_id))
[email protected]1784e83a2009-09-08 21:01:52878 return;
[email protected]1784e83a2009-09-08 21:01:52879
[email protected]06f92562011-04-29 19:27:31880 const Extension* extension = GetInstalledExtension(extension_id);
881 // |extension| can be NULL if sync disables an extension that is not
882 // installed yet.
[email protected]65187152012-06-02 13:14:14883 if (extension &&
884 !system_->management_policy()->UserMayModifySettings(extension, NULL)) {
[email protected]95da88c42011-03-31 10:07:33885 return;
[email protected]65187152012-06-02 13:14:14886 }
[email protected]95da88c42011-03-31 10:07:33887
[email protected]b3317ad2011-04-28 23:46:00888 extension_prefs_->SetExtensionState(extension_id, Extension::DISABLED);
[email protected]eb5e4f92012-08-15 23:33:28889 extension_prefs_->AddDisableReason(extension_id, disable_reason);
[email protected]1784e83a2009-09-08 21:01:52890
[email protected]31bb5ee62012-09-12 22:58:40891 int include_mask = INCLUDE_ENABLED | INCLUDE_TERMINATED;
[email protected]81f0d162012-08-15 04:21:47892 extension = GetExtensionByIdInternal(extension_id, include_mask);
[email protected]06f92562011-04-29 19:27:31893 if (!extension)
894 return;
895
[email protected]5c094792012-09-07 19:44:53896 // Move it over to the disabled list. Don't send a second unload notification
897 // for terminated extensions being disabled.
[email protected]84df8332011-12-06 18:22:46898 disabled_extensions_.Insert(make_scoped_refptr(extension));
[email protected]5c094792012-09-07 19:44:53899 if (extensions_.Contains(extension->id())) {
[email protected]84df8332011-12-06 18:22:46900 extensions_.Remove(extension->id());
[email protected]5c094792012-09-07 19:44:53901 NotifyExtensionUnloaded(extension, extension_misc::UNLOAD_REASON_DISABLE);
902 } else {
[email protected]84df8332011-12-06 18:22:46903 terminated_extensions_.Remove(extension->id());
[email protected]5c094792012-09-07 19:44:53904 }
[email protected]3bdba0d2011-08-23 07:17:30905
906 SyncExtensionChangeIfNeeded(*extension);
[email protected]7c1490da2011-10-11 18:53:25907
908 // Deactivating one extension might have solved the problems of others.
909 // Therefore, we clear warnings of this type for all extensions.
910 std::set<ExtensionWarningSet::WarningType> warnings;
911 extension_warnings_.GetWarningsAffectingExtension(extension_id, &warnings);
912 extension_warnings_.ClearWarnings(warnings);
[email protected]1784e83a2009-09-08 21:01:52913}
914
[email protected]eaa7dd182010-12-14 11:09:00915void ExtensionService::GrantPermissionsAndEnableExtension(
[email protected]b70a2d92012-06-28 19:51:21916 const Extension* extension, bool record_oauth2_grant) {
[email protected]be083862012-09-01 03:53:45917 GrantPermissions(extension, record_oauth2_grant);
[email protected]fe2dd7742011-04-19 22:52:49918 RecordPermissionMessagesHistogram(
919 extension, "Extensions.Permissions_ReEnable");
[email protected]8d888c12010-11-30 00:00:25920 extension_prefs_->SetDidExtensionEscalatePermissions(extension, false);
921 EnableExtension(extension->id());
922}
923
[email protected]be083862012-09-01 03:53:45924void ExtensionService::GrantPermissions(const Extension* extension,
925 bool record_oauth2_grant) {
926 CHECK(extension);
927 extensions::PermissionsUpdater perms_updater(profile());
928 perms_updater.GrantActivePermissions(extension, record_oauth2_grant);
929}
930
[email protected]fe2dd7742011-04-19 22:52:49931// static
932void ExtensionService::RecordPermissionMessagesHistogram(
933 const Extension* e, const char* histogram) {
934 // Since this is called from multiple sources, and since the Histogram macros
935 // use statics, we need to manually lookup the Histogram ourselves.
936 base::Histogram* counter = base::LinearHistogram::FactoryGet(
937 histogram,
938 1,
[email protected]c2e66e12012-06-27 06:27:06939 PermissionMessage::kEnumBoundary,
940 PermissionMessage::kEnumBoundary + 1,
[email protected]fe2dd7742011-04-19 22:52:49941 base::Histogram::kUmaTargetedHistogramFlag);
942
[email protected]c2e66e12012-06-27 06:27:06943 PermissionMessages permissions = e->GetPermissionMessages();
[email protected]fe2dd7742011-04-19 22:52:49944 if (permissions.empty()) {
[email protected]c2e66e12012-06-27 06:27:06945 counter->Add(PermissionMessage::kNone);
[email protected]fe2dd7742011-04-19 22:52:49946 } else {
[email protected]c2e66e12012-06-27 06:27:06947 for (PermissionMessages::iterator it = permissions.begin();
[email protected]0d3e4a22011-06-23 19:02:52948 it != permissions.end(); ++it)
949 counter->Add(it->id());
[email protected]fe2dd7742011-04-19 22:52:49950 }
951}
952
[email protected]eaa7dd182010-12-14 11:09:00953void ExtensionService::NotifyExtensionLoaded(const Extension* extension) {
[email protected]57a777f72010-03-31 01:09:42954 // The ChromeURLRequestContexts need to be first to know that the extension
[email protected]62d30f42009-10-01 22:36:06955 // was loaded, otherwise a race can arise where a renderer that is created
956 // for the extension may try to load an extension URL with an extension id
[email protected]57a777f72010-03-31 01:09:42957 // that the request context doesn't yet know about. The profile is responsible
958 // for ensuring its URLRequestContexts appropriately discover the loaded
959 // extension.
[email protected]31d8f5f22012-04-02 15:22:08960 system_->RegisterExtensionWithRequestContexts(extension);
[email protected]62d30f42009-10-01 22:36:06961
[email protected]19647262011-12-16 09:57:49962 // Tell renderers about the new extension, unless it's a theme (renderers
963 // don't need to know about themes).
964 if (!extension->is_theme()) {
965 for (content::RenderProcessHost::iterator i(
966 content::RenderProcessHost::AllHostsIterator());
967 !i.IsAtEnd(); i.Advance()) {
968 content::RenderProcessHost* host = i.GetCurrentValue();
969 Profile* host_profile =
970 Profile::FromBrowserContext(host->GetBrowserContext());
971 if (host_profile->GetOriginalProfile() ==
972 profile_->GetOriginalProfile()) {
973 std::vector<ExtensionMsg_Loaded_Params> loaded_extensions(
974 1, ExtensionMsg_Loaded_Params(extension));
975 host->Send(
976 new ExtensionMsg_Loaded(loaded_extensions));
977 }
[email protected]c8d407e2011-04-28 21:27:17978 }
[email protected]77a6970c2011-04-23 16:58:56979 }
980
[email protected]3442a662012-01-12 08:06:17981 // Tell subsystems that use the EXTENSION_LOADED notification about the new
982 // extension.
983 //
984 // NOTE: It is important that this happen after notifying the renderers about
985 // the new extensions so that if we navigate to an extension URL in
986 // NOTIFICATION_EXTENSION_LOADED, the renderer is guaranteed to know about it.
987 content::NotificationService::current()->Notify(
988 chrome::NOTIFICATION_EXTENSION_LOADED,
989 content::Source<Profile>(profile_),
990 content::Details<const Extension>(extension));
991
[email protected]c8d407e2011-04-28 21:27:17992 // Tell a random-ass collection of other subsystems about the new extension.
993 // TODO(aa): What should we do with all this goop? Can it move into the
994 // relevant objects via EXTENSION_LOADED?
995
996 profile_->GetExtensionSpecialStoragePolicy()->
997 GrantRightsForExtension(extension);
998
999 UpdateActiveExtensionsInCrashReporter();
1000
1001 ExtensionWebUI::RegisterChromeURLOverrides(
1002 profile_, extension->GetChromeURLOverrides());
1003
[email protected]8e5c89a2011-06-07 18:13:331004 TemplateURLService* url_service =
1005 TemplateURLServiceFactory::GetForProfile(profile_);
1006 if (url_service)
1007 url_service->RegisterExtensionKeyword(extension);
[email protected]c8d407e2011-04-28 21:27:171008
1009 // Load the icon for omnibox-enabled extensions so it will be ready to display
1010 // in the URL bar.
1011 if (!extension->omnibox_keyword().empty()) {
1012 omnibox_popup_icon_manager_.LoadIcon(extension);
1013 omnibox_icon_manager_.LoadIcon(extension);
1014 }
1015
1016 // If the extension has permission to load chrome://favicon/ resources we need
1017 // to make sure that the FaviconSource is registered with the
1018 // ChromeURLDataManager.
1019 if (extension->HasHostPermission(GURL(chrome::kChromeUIFaviconURL))) {
1020 FaviconSource* favicon_source = new FaviconSource(profile_,
1021 FaviconSource::FAVICON);
[email protected]ef92e172012-04-25 19:40:411022 ChromeURLDataManager::AddDataSource(profile_, favicon_source);
[email protected]c8d407e2011-04-28 21:27:171023 }
[email protected]b07e606e2012-09-15 20:16:151024
1025#if !defined(OS_ANDROID)
1026 // Same for chrome://theme/ resources.
1027 if (extension->HasHostPermission(GURL(chrome::kChromeUIThemeURL))) {
1028 ThemeSource* theme_source = new ThemeSource(profile_);
1029 ChromeURLDataManager::AddDataSource(profile_, theme_source);
1030 }
1031#endif
1032
[email protected]5eddc3e2011-10-26 04:33:311033 // Same for chrome://thumb/ resources.
1034 if (extension->HasHostPermission(GURL(chrome::kChromeUIThumbnailURL))) {
1035 ThumbnailSource* thumbnail_source = new ThumbnailSource(profile_);
[email protected]ef92e172012-04-25 19:40:411036 ChromeURLDataManagerFactory::GetForProfile(profile_)->
1037 AddDataSource(thumbnail_source);
[email protected]5eddc3e2011-10-26 04:33:311038 }
[email protected]c8d407e2011-04-28 21:27:171039
1040 // TODO(mpcomplete): This ends up affecting all profiles. See crbug.com/80757.
[email protected]2de307592011-04-05 21:16:581041 bool plugins_changed = false;
1042 for (size_t i = 0; i < extension->plugins().size(); ++i) {
1043 const Extension::PluginInfo& plugin = extension->plugins()[i];
[email protected]f520b5b2011-11-08 02:42:141044 PluginService::GetInstance()->RefreshPlugins();
1045 PluginService::GetInstance()->AddExtraPluginPath(plugin.path);
[email protected]2de307592011-04-05 21:16:581046 plugins_changed = true;
[email protected]476a27032011-09-13 13:40:491047 ChromePluginServiceFilter* filter =
1048 ChromePluginServiceFilter::GetInstance();
1049 if (plugin.is_public) {
1050 filter->RestrictPluginToProfileAndOrigin(
1051 plugin.path, profile_, GURL());
1052 } else {
1053 filter->RestrictPluginToProfileAndOrigin(
1054 plugin.path, profile_, extension->url());
[email protected]2de307592011-04-05 21:16:581055 }
1056 }
[email protected]84396dbc2011-04-14 06:33:421057
1058 bool nacl_modules_changed = false;
1059 for (size_t i = 0; i < extension->nacl_modules().size(); ++i) {
1060 const Extension::NaClModuleInfo& module = extension->nacl_modules()[i];
[email protected]cebc3dc2011-04-18 17:15:001061 RegisterNaClModule(module.url, module.mime_type);
[email protected]84396dbc2011-04-14 06:33:421062 nacl_modules_changed = true;
1063 }
1064
[email protected]ed0ba002011-05-26 16:55:131065 if (nacl_modules_changed)
1066 UpdatePluginListWithNaClModules();
[email protected]84396dbc2011-04-14 06:33:421067
1068 if (plugins_changed || nacl_modules_changed)
[email protected]45a22e62011-10-12 09:48:021069 PluginService::GetInstance()->PurgePluginListCache(profile_, false);
[email protected]b4d9d122011-06-17 01:58:541070
[email protected]14da67b02011-08-02 05:49:131071#if defined(OS_CHROMEOS)
[email protected]b4d9d122011-06-17 01:58:541072 for (std::vector<Extension::InputComponentInfo>::const_iterator component =
1073 extension->input_components().begin();
1074 component != extension->input_components().end();
1075 ++component) {
[email protected]14da67b02011-08-02 05:49:131076 if (component->type == Extension::INPUT_COMPONENT_TYPE_IME) {
[email protected]1364c6d2012-07-24 11:57:191077 extensions::InputImeEventRouter::GetInstance()->RegisterIme(
[email protected]14da67b02011-08-02 05:49:131078 profile_, extension->id(), *component);
1079 }
[email protected]b4d9d122011-06-17 01:58:541080 }
1081#endif
[email protected]62d30f42009-10-01 22:36:061082}
1083
[email protected]a9f39a312010-12-23 22:14:271084void ExtensionService::NotifyExtensionUnloaded(
[email protected]814a7bf0f2011-08-13 05:30:591085 const Extension* extension,
1086 extension_misc::UnloadedExtensionReason reason) {
[email protected]a9f39a312010-12-23 22:14:271087 UnloadedExtensionInfo details(extension, reason);
[email protected]ad50def52011-10-19 23:17:071088 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271089 chrome::NOTIFICATION_EXTENSION_UNLOADED,
[email protected]6c2381d2011-10-19 02:52:531090 content::Source<Profile>(profile_),
1091 content::Details<UnloadedExtensionInfo>(&details));
[email protected]62d30f42009-10-01 22:36:061092
[email protected]f3b1a082011-11-18 00:34:301093 for (content::RenderProcessHost::iterator i(
1094 content::RenderProcessHost::AllHostsIterator());
[email protected]77a6970c2011-04-23 16:58:561095 !i.IsAtEnd(); i.Advance()) {
[email protected]f3b1a082011-11-18 00:34:301096 content::RenderProcessHost* host = i.GetCurrentValue();
[email protected]9b62ecf2011-07-27 20:23:081097 Profile* host_profile =
[email protected]f3b1a082011-11-18 00:34:301098 Profile::FromBrowserContext(host->GetBrowserContext());
[email protected]9b62ecf2011-07-27 20:23:081099 if (host_profile->GetOriginalProfile() == profile_->GetOriginalProfile())
[email protected]c8d407e2011-04-28 21:27:171100 host->Send(new ExtensionMsg_Unloaded(extension->id()));
[email protected]77a6970c2011-04-23 16:58:561101 }
1102
[email protected]31d8f5f22012-04-02 15:22:081103 system_->UnregisterExtensionWithRequestContexts(extension->id(), reason);
[email protected]c8d407e2011-04-28 21:27:171104 profile_->GetExtensionSpecialStoragePolicy()->
1105 RevokeRightsForExtension(extension);
1106
1107 ExtensionWebUI::UnregisterChromeURLOverrides(
1108 profile_, extension->GetChromeURLOverrides());
1109
[email protected]b777b332011-04-16 04:01:081110#if defined(OS_CHROMEOS)
[email protected]10eb28162012-09-18 03:04:091111 // Revoke external file access to third party extensions.
1112 fileapi::FileSystemContext* filesystem_context =
1113 BrowserContext::GetDefaultStoragePartition(profile_)->
1114 GetFileSystemContext();
1115 if (filesystem_context && filesystem_context->external_provider()) {
1116 filesystem_context->external_provider()->
[email protected]c8d407e2011-04-28 21:27:171117 RevokeAccessForExtension(extension->id());
[email protected]62d30f42009-10-01 22:36:061118 }
[email protected]54ccafa2011-12-06 23:36:321119
1120 if (extension->input_components().size() > 0) {
[email protected]1364c6d2012-07-24 11:57:191121 extensions::InputImeEventRouter::GetInstance()->UnregisterAllImes(
[email protected]54ccafa2011-12-06 23:36:321122 profile_, extension->id());
1123 }
[email protected]c8d407e2011-04-28 21:27:171124#endif
1125
1126 UpdateActiveExtensionsInCrashReporter();
[email protected]2de307592011-04-05 21:16:581127
1128 bool plugins_changed = false;
1129 for (size_t i = 0; i < extension->plugins().size(); ++i) {
1130 const Extension::PluginInfo& plugin = extension->plugins()[i];
[email protected]b6a2f8de2012-01-31 17:28:491131 PluginService::GetInstance()->ForcePluginShutdown(plugin.path);
[email protected]f520b5b2011-11-08 02:42:141132 PluginService::GetInstance()->RefreshPlugins();
1133 PluginService::GetInstance()->RemoveExtraPluginPath(plugin.path);
[email protected]2de307592011-04-05 21:16:581134 plugins_changed = true;
[email protected]476a27032011-09-13 13:40:491135 ChromePluginServiceFilter::GetInstance()->UnrestrictPlugin(plugin.path);
[email protected]2de307592011-04-05 21:16:581136 }
[email protected]84396dbc2011-04-14 06:33:421137
1138 bool nacl_modules_changed = false;
1139 for (size_t i = 0; i < extension->nacl_modules().size(); ++i) {
1140 const Extension::NaClModuleInfo& module = extension->nacl_modules()[i];
[email protected]cebc3dc2011-04-18 17:15:001141 UnregisterNaClModule(module.url);
[email protected]84396dbc2011-04-14 06:33:421142 nacl_modules_changed = true;
1143 }
1144
[email protected]ed0ba002011-05-26 16:55:131145 if (nacl_modules_changed)
1146 UpdatePluginListWithNaClModules();
[email protected]84396dbc2011-04-14 06:33:421147
1148 if (plugins_changed || nacl_modules_changed)
[email protected]45a22e62011-10-12 09:48:021149 PluginService::GetInstance()->PurgePluginListCache(profile_, false);
[email protected]62d30f42009-10-01 22:36:061150}
1151
[email protected]eaa7dd182010-12-14 11:09:001152void ExtensionService::UpdateExtensionBlacklist(
[email protected]6b75ec32009-08-14 06:37:181153 const std::vector<std::string>& blacklist) {
1154 // Use this set to indicate if an extension in the blacklist has been used.
1155 std::set<std::string> blacklist_set;
1156 for (unsigned int i = 0; i < blacklist.size(); ++i) {
[email protected]4ee07c62012-08-21 12:40:421157 if (Extension::IdIsValid(blacklist[i]))
[email protected]6b75ec32009-08-14 06:37:181158 blacklist_set.insert(blacklist[i]);
[email protected]6b75ec32009-08-14 06:37:181159 }
1160 extension_prefs_->UpdateBlacklist(blacklist_set);
[email protected]4ee07c62012-08-21 12:40:421161 CheckManagementPolicy();
[email protected]6b75ec32009-08-14 06:37:181162}
1163
[email protected]0a071a32011-02-08 00:18:241164Profile* ExtensionService::profile() {
1165 return profile_;
1166}
1167
[email protected]45759612012-07-10 17:21:231168extensions::ExtensionPrefs* ExtensionService::extension_prefs() {
[email protected]ddb1e5a2010-12-13 20:10:451169 return extension_prefs_;
1170}
1171
[email protected]0d9a2202011-11-09 13:48:411172extensions::SettingsFrontend* ExtensionService::settings_frontend() {
[email protected]cccdf0aa2011-11-11 03:43:381173 return settings_frontend_.get();
[email protected]b7f853e282011-08-10 09:24:201174}
1175
[email protected]e2d720aa2012-05-17 00:11:351176extensions::ContentSettingsStore* ExtensionService::GetContentSettingsStore() {
[email protected]b790b072011-05-20 09:46:441177 return extension_prefs()->content_settings_store();
1178}
1179
[email protected]25ae0152011-11-18 14:40:021180bool ExtensionService::is_ready() {
1181 return ready_;
1182}
1183
[email protected]42a08162012-03-16 18:09:111184extensions::ExtensionUpdater* ExtensionService::updater() {
[email protected]2859946f2011-04-04 18:18:061185 return updater_.get();
1186}
1187
[email protected]4ee07c62012-08-21 12:40:421188void ExtensionService::CheckManagementPolicy() {
[email protected]aa96d3a2010-08-21 08:45:251189 std::vector<std::string> to_be_removed;
1190 // Loop through extensions list, unload installed extensions.
[email protected]84df8332011-12-06 18:22:461191 for (ExtensionSet::const_iterator iter = extensions_.begin();
[email protected]aa96d3a2010-08-21 08:45:251192 iter != extensions_.end(); ++iter) {
[email protected]9adb9692010-10-29 23:14:021193 const Extension* extension = (*iter);
[email protected]4ee07c62012-08-21 12:40:421194 if (!system_->management_policy()->UserMayLoad(extension, NULL))
[email protected]aa96d3a2010-08-21 08:45:251195 to_be_removed.push_back(extension->id());
1196 }
1197
1198 // UnloadExtension will change the extensions_ list. So, we should
1199 // call it outside the iterator loop.
[email protected]31bb5ee62012-09-12 22:58:401200 for (size_t i = 0; i < to_be_removed.size(); ++i)
[email protected]814a7bf0f2011-08-13 05:30:591201 UnloadExtension(to_be_removed[i], extension_misc::UNLOAD_REASON_DISABLE);
[email protected]aa96d3a2010-08-21 08:45:251202}
1203
[email protected]31206602011-04-13 23:07:321204void ExtensionService::CheckForUpdatesSoon() {
[email protected]c3cfb012011-04-06 22:07:351205 if (updater()) {
[email protected]94fde232012-04-27 10:22:301206 if (AreAllExternalProvidersReady()) {
1207 updater()->CheckSoon();
1208 } else {
1209 // Sync can start updating before all the external providers are ready
1210 // during startup. Start the update as soon as those providers are ready,
1211 // but not before.
1212 update_once_all_providers_are_ready_ = true;
1213 }
[email protected]c3cfb012011-04-06 22:07:351214 } else {
[email protected]31206602011-04-13 23:07:321215 LOG(WARNING) << "CheckForUpdatesSoon() called with auto-update turned off";
[email protected]c3cfb012011-04-06 22:07:351216 }
1217}
1218
[email protected]65f173552012-06-28 22:43:581219syncer::SyncError ExtensionService::MergeDataAndStartSyncing(
[email protected]a4a147652012-07-03 23:41:321220 syncer::ModelType type,
[email protected]65f173552012-06-28 22:43:581221 const syncer::SyncDataList& initial_sync_data,
1222 scoped_ptr<syncer::SyncChangeProcessor> sync_processor,
1223 scoped_ptr<syncer::SyncErrorFactory> sync_error_factory) {
[email protected]5db9ada2012-04-11 13:48:201224 CHECK(sync_processor.get());
[email protected]5d36e052012-04-20 20:12:281225 CHECK(sync_error_factory.get());
[email protected]3bdba0d2011-08-23 07:17:301226
1227 switch (type) {
[email protected]a4a147652012-07-03 23:41:321228 case syncer::EXTENSIONS:
[email protected]5db9ada2012-04-11 13:48:201229 extension_sync_bundle_.SetupSync(sync_processor.release(),
[email protected]5d36e052012-04-20 20:12:281230 sync_error_factory.release(),
[email protected]5db9ada2012-04-11 13:48:201231 initial_sync_data);
[email protected]3bdba0d2011-08-23 07:17:301232 break;
1233
[email protected]a4a147652012-07-03 23:41:321234 case syncer::APPS:
[email protected]5d36e052012-04-20 20:12:281235 app_sync_bundle_.SetupSync(sync_processor.release(),
1236 sync_error_factory.release(),
1237 initial_sync_data);
[email protected]3bdba0d2011-08-23 07:17:301238 break;
1239
1240 default:
1241 LOG(FATAL) << "Got " << type << " ModelType";
1242 }
[email protected]3bdba0d2011-08-23 07:17:301243
[email protected]b1417ab2011-12-15 17:09:111244 // Process local extensions.
1245 // TODO(yoz): Determine whether pending extensions should be considered too.
1246 // See crbug.com/104399.
[email protected]65f173552012-06-28 22:43:581247 syncer::SyncDataList sync_data_list = GetAllSyncData(type);
1248 syncer::SyncChangeList sync_change_list;
1249 for (syncer::SyncDataList::const_iterator i = sync_data_list.begin();
[email protected]3bdba0d2011-08-23 07:17:301250 i != sync_data_list.end();
1251 ++i) {
[email protected]5db9ada2012-04-11 13:48:201252 switch (type) {
[email protected]a4a147652012-07-03 23:41:321253 case syncer::EXTENSIONS:
[email protected]5db9ada2012-04-11 13:48:201254 sync_change_list.push_back(
1255 extension_sync_bundle_.CreateSyncChange(*i));
1256 break;
[email protected]a4a147652012-07-03 23:41:321257 case syncer::APPS:
[email protected]5db9ada2012-04-11 13:48:201258 sync_change_list.push_back(app_sync_bundle_.CreateSyncChange(*i));
1259 break;
1260 default:
1261 LOG(FATAL) << "Got " << type << " ModelType";
[email protected]31bb5ee62012-09-12 22:58:401262 }
[email protected]3bdba0d2011-08-23 07:17:301263 }
[email protected]3bdba0d2011-08-23 07:17:301264
[email protected]5db9ada2012-04-11 13:48:201265
[email protected]a4a147652012-07-03 23:41:321266 if (type == syncer::EXTENSIONS) {
[email protected]5db9ada2012-04-11 13:48:201267 extension_sync_bundle_.ProcessSyncChangeList(sync_change_list);
[email protected]a4a147652012-07-03 23:41:321268 } else if (type == syncer::APPS) {
[email protected]5db9ada2012-04-11 13:48:201269 app_sync_bundle_.ProcessSyncChangeList(sync_change_list);
1270 }
[email protected]0ffd9e52012-01-26 21:44:341271
[email protected]65f173552012-06-28 22:43:581272 return syncer::SyncError();
[email protected]3bdba0d2011-08-23 07:17:301273}
1274
[email protected]a4a147652012-07-03 23:41:321275void ExtensionService::StopSyncing(syncer::ModelType type) {
1276 if (type == syncer::APPS) {
[email protected]5db9ada2012-04-11 13:48:201277 app_sync_bundle_.Reset();
[email protected]a4a147652012-07-03 23:41:321278 } else if (type == syncer::EXTENSIONS) {
[email protected]5db9ada2012-04-11 13:48:201279 extension_sync_bundle_.Reset();
1280 }
[email protected]3bdba0d2011-08-23 07:17:301281}
1282
[email protected]65f173552012-06-28 22:43:581283syncer::SyncDataList ExtensionService::GetAllSyncData(
[email protected]a4a147652012-07-03 23:41:321284 syncer::ModelType type) const {
[email protected]31bb5ee62012-09-12 22:58:401285 if (type == syncer::EXTENSIONS)
[email protected]5db9ada2012-04-11 13:48:201286 return extension_sync_bundle_.GetAllSyncData();
[email protected]31bb5ee62012-09-12 22:58:401287 if (type == syncer::APPS)
[email protected]5db9ada2012-04-11 13:48:201288 return app_sync_bundle_.GetAllSyncData();
[email protected]5db9ada2012-04-11 13:48:201289
1290 // We should only get sync data for extensions and apps.
1291 NOTREACHED();
1292
[email protected]65f173552012-06-28 22:43:581293 return syncer::SyncDataList();
[email protected]3bdba0d2011-08-23 07:17:301294}
1295
[email protected]65f173552012-06-28 22:43:581296syncer::SyncError ExtensionService::ProcessSyncChanges(
[email protected]3bdba0d2011-08-23 07:17:301297 const tracked_objects::Location& from_here,
[email protected]65f173552012-06-28 22:43:581298 const syncer::SyncChangeList& change_list) {
1299 for (syncer::SyncChangeList::const_iterator i = change_list.begin();
[email protected]3bdba0d2011-08-23 07:17:301300 i != change_list.end();
1301 ++i) {
[email protected]a4a147652012-07-03 23:41:321302 syncer::ModelType type = i->sync_data().GetDataType();
1303 if (type == syncer::EXTENSIONS) {
[email protected]5db9ada2012-04-11 13:48:201304 extension_sync_bundle_.ProcessSyncChange(
1305 extensions::ExtensionSyncData(*i));
[email protected]a4a147652012-07-03 23:41:321306 } else if (type == syncer::APPS) {
[email protected]5db9ada2012-04-11 13:48:201307 app_sync_bundle_.ProcessSyncChange(extensions::AppSyncData(*i));
1308 }
[email protected]3bdba0d2011-08-23 07:17:301309 }
1310
[email protected]0ffd9e52012-01-26 21:44:341311 extension_prefs()->extension_sorting()->FixNTPOrdinalCollisions();
1312
[email protected]65f173552012-06-28 22:43:581313 return syncer::SyncError();
[email protected]b05fb9ff2011-04-23 00:07:561314}
1315
[email protected]5db9ada2012-04-11 13:48:201316extensions::ExtensionSyncData ExtensionService::GetExtensionSyncData(
1317 const Extension& extension) const {
1318 return extensions::ExtensionSyncData(extension,
1319 IsExtensionEnabled(extension.id()),
1320 IsIncognitoEnabled(extension.id()));
[email protected]b05fb9ff2011-04-23 00:07:561321}
1322
[email protected]5db9ada2012-04-11 13:48:201323extensions::AppSyncData ExtensionService::GetAppSyncData(
1324 const Extension& extension) const {
1325 return extensions::AppSyncData(
1326 extension,
1327 IsExtensionEnabled(extension.id()),
1328 IsIncognitoEnabled(extension.id()),
1329 extension_prefs_->GetAppNotificationClientId(extension.id()),
1330 extension_prefs_->IsAppNotificationDisabled(extension.id()),
1331 extension_prefs_->extension_sorting()->GetAppLaunchOrdinal(
1332 extension.id()),
1333 extension_prefs_->extension_sorting()->GetPageOrdinal(extension.id()));
1334}
[email protected]3bdba0d2011-08-23 07:17:301335
[email protected]5db9ada2012-04-11 13:48:201336std::vector<extensions::ExtensionSyncData>
1337 ExtensionService::GetExtensionSyncDataList() const {
1338 std::vector<extensions::ExtensionSyncData> extension_sync_list;
1339 extension_sync_bundle_.GetExtensionSyncDataListHelper(extensions_,
1340 &extension_sync_list);
1341 extension_sync_bundle_.GetExtensionSyncDataListHelper(disabled_extensions_,
1342 &extension_sync_list);
1343 extension_sync_bundle_.GetExtensionSyncDataListHelper(terminated_extensions_,
1344 &extension_sync_list);
1345
1346 std::vector<extensions::ExtensionSyncData> pending_extensions =
1347 extension_sync_bundle_.GetPendingData();
1348 extension_sync_list.insert(extension_sync_list.begin(),
1349 pending_extensions.begin(),
1350 pending_extensions.end());
[email protected]3bdba0d2011-08-23 07:17:301351
1352 return extension_sync_list;
[email protected]b05fb9ff2011-04-23 00:07:561353}
1354
[email protected]5db9ada2012-04-11 13:48:201355std::vector<extensions::AppSyncData> ExtensionService::GetAppSyncDataList()
1356 const {
1357 std::vector<extensions::AppSyncData> app_sync_list;
1358 app_sync_bundle_.GetAppSyncDataListHelper(extensions_, &app_sync_list);
1359 app_sync_bundle_.GetAppSyncDataListHelper(disabled_extensions_,
1360 &app_sync_list);
1361 app_sync_bundle_.GetAppSyncDataListHelper(terminated_extensions_,
1362 &app_sync_list);
1363
1364 std::vector<extensions::AppSyncData> pending_apps =
1365 app_sync_bundle_.GetPendingData();
1366 app_sync_list.insert(app_sync_list.begin(),
1367 pending_apps.begin(),
1368 pending_apps.end());
1369
1370 return app_sync_list;
1371}
1372
1373bool ExtensionService::ProcessExtensionSyncData(
1374 const extensions::ExtensionSyncData& extension_sync_data) {
1375 if (!ProcessExtensionSyncDataHelper(extension_sync_data,
[email protected]a4a147652012-07-03 23:41:321376 syncer::EXTENSIONS)) {
[email protected]5db9ada2012-04-11 13:48:201377 extension_sync_bundle_.AddPendingExtension(extension_sync_data.id(),
1378 extension_sync_data);
1379 CheckForUpdatesSoon();
1380 return false;
1381 }
1382
1383 return true;
1384}
1385
1386bool ExtensionService::ProcessAppSyncData(
1387 const extensions::AppSyncData& app_sync_data) {
1388 const std::string& id = app_sync_data.id();
1389 const Extension* extension = GetInstalledExtension(id);
1390 bool extension_installed = (extension != NULL);
1391
1392 if (app_sync_data.app_launch_ordinal().IsValid() &&
1393 app_sync_data.page_ordinal().IsValid()) {
1394 extension_prefs_->extension_sorting()->SetAppLaunchOrdinal(
1395 id,
1396 app_sync_data.app_launch_ordinal());
1397 extension_prefs_->extension_sorting()->SetPageOrdinal(
1398 id,
1399 app_sync_data.page_ordinal());
1400 }
1401
1402 if (extension_installed) {
1403 if (app_sync_data.notifications_disabled() !=
1404 extension_prefs_->IsAppNotificationDisabled(id)) {
1405 extension_prefs_->SetAppNotificationDisabled(
1406 id, app_sync_data.notifications_disabled());
1407 }
1408 }
1409
1410 if (!ProcessExtensionSyncDataHelper(app_sync_data.extension_sync_data(),
[email protected]a4a147652012-07-03 23:41:321411 syncer::APPS)) {
[email protected]5db9ada2012-04-11 13:48:201412 app_sync_bundle_.AddPendingApp(id, app_sync_data);
1413 CheckForUpdatesSoon();
1414 return false;
1415 }
1416
1417 return true;
1418}
1419
1420bool ExtensionService::IsCorrectSyncType(const Extension& extension,
[email protected]a4a147652012-07-03 23:41:321421 syncer::ModelType type) const {
1422 if (type == syncer::EXTENSIONS &&
[email protected]31bb5ee62012-09-12 22:58:401423 extension.GetSyncType() == Extension::SYNC_TYPE_EXTENSION) {
[email protected]5db9ada2012-04-11 13:48:201424 return true;
[email protected]31bb5ee62012-09-12 22:58:401425 }
[email protected]5db9ada2012-04-11 13:48:201426
[email protected]a4a147652012-07-03 23:41:321427 if (type == syncer::APPS &&
[email protected]31bb5ee62012-09-12 22:58:401428 extension.GetSyncType() == Extension::SYNC_TYPE_APP) {
[email protected]5db9ada2012-04-11 13:48:201429 return true;
[email protected]31bb5ee62012-09-12 22:58:401430 }
[email protected]5db9ada2012-04-11 13:48:201431
1432 return false;
1433}
1434
1435bool ExtensionService::ProcessExtensionSyncDataHelper(
1436 const extensions::ExtensionSyncData& extension_sync_data,
[email protected]a4a147652012-07-03 23:41:321437 syncer::ModelType type) {
[email protected]3bdba0d2011-08-23 07:17:301438 const std::string& id = extension_sync_data.id();
[email protected]96e989b2011-08-30 19:35:061439 const Extension* extension = GetInstalledExtension(id);
1440
1441 // TODO(bolms): we should really handle this better. The particularly bad
1442 // case is where an app becomes an extension or vice versa, and we end up with
1443 // a zombie extension that won't go away.
[email protected]5db9ada2012-04-11 13:48:201444 if (extension && !IsCorrectSyncType(*extension, type))
1445 return true;
[email protected]90310d92011-04-17 07:35:041446
1447 // Handle uninstalls first.
[email protected]3bdba0d2011-08-23 07:17:301448 if (extension_sync_data.uninstalled()) {
[email protected]90310d92011-04-17 07:35:041449 std::string error;
1450 if (!UninstallExtensionHelper(this, id)) {
1451 LOG(WARNING) << "Could not uninstall extension " << id
1452 << " for sync";
1453 }
[email protected]5db9ada2012-04-11 13:48:201454 return true;
[email protected]90310d92011-04-17 07:35:041455 }
1456
[email protected]caf2d442012-05-04 10:00:501457 // Extension from sync was uninstalled by the user as external extensions.
1458 // Honor user choice and skip installation/enabling.
1459 if (IsExternalExtensionUninstalled(id)) {
1460 LOG(WARNING) << "Extension with id " << id
1461 << " from sync was uninstalled as external extension";
1462 return true;
1463 }
1464
[email protected]06f92562011-04-29 19:27:311465 // Set user settings.
[email protected]31bb5ee62012-09-12 22:58:401466 if (extension_sync_data.enabled())
[email protected]06f92562011-04-29 19:27:311467 EnableExtension(id);
[email protected]31bb5ee62012-09-12 22:58:401468 else
[email protected]44d62b62012-04-11 00:06:031469 DisableExtension(id, Extension::DISABLE_USER_ACTION);
[email protected]81b14cc2011-04-29 00:39:371470
[email protected]406b5a92011-11-08 11:58:261471 // We need to cache some version information here because setting the
1472 // incognito flag invalidates the |extension| pointer (it reloads the
1473 // extension).
[email protected]9060d8b02012-01-13 02:14:301474 bool extension_installed = (extension != NULL);
[email protected]406b5a92011-11-08 11:58:261475 int result = extension ?
1476 extension->version()->CompareTo(extension_sync_data.version()) : 0;
1477 SetIsIncognitoEnabled(id, extension_sync_data.incognito_enabled());
1478 extension = NULL; // No longer safe to use.
1479
1480 if (extension_installed) {
[email protected]06f92562011-04-29 19:27:311481 // If the extension is already installed, check if it's outdated.
[email protected]90310d92011-04-17 07:35:041482 if (result < 0) {
1483 // Extension is outdated.
[email protected]5db9ada2012-04-11 13:48:201484 return false;
[email protected]b020dc12011-12-06 04:35:421485 }
[email protected]06f92562011-04-29 19:27:311486 } else {
[email protected]06f92562011-04-29 19:27:311487 // TODO(akalin): Replace silent update with a list of enabled
1488 // permissions.
[email protected]6cc7dbae2011-04-29 21:18:331489 const bool kInstallSilently = true;
[email protected]5db9ada2012-04-11 13:48:201490
[email protected]a4a147652012-07-03 23:41:321491 CHECK(type == syncer::EXTENSIONS || type == syncer::APPS);
[email protected]5db9ada2012-04-11 13:48:201492 ExtensionFilter filter =
[email protected]a4a147652012-07-03 23:41:321493 (type == syncer::APPS) ? IsSyncableApp : IsSyncableExtension;
[email protected]5db9ada2012-04-11 13:48:201494
[email protected]06f92562011-04-29 19:27:311495 if (!pending_extension_manager()->AddFromSync(
1496 id,
[email protected]3bdba0d2011-08-23 07:17:301497 extension_sync_data.update_url(),
[email protected]5db9ada2012-04-11 13:48:201498 filter,
[email protected]6cc7dbae2011-04-29 21:18:331499 kInstallSilently)) {
[email protected]06f92562011-04-29 19:27:311500 LOG(WARNING) << "Could not add pending extension for " << id;
[email protected]3bdba0d2011-08-23 07:17:301501 // This means that the extension is already pending installation, with a
1502 // non-INTERNAL location. Add to pending_sync_data, even though it will
1503 // never be removed (we'll never install a syncable version of the
1504 // extension), so that GetAllSyncData() continues to send it.
[email protected]06f92562011-04-29 19:27:311505 }
[email protected]3bdba0d2011-08-23 07:17:301506 // Track pending extensions so that we can return them in GetAllSyncData().
[email protected]5db9ada2012-04-11 13:48:201507 return false;
[email protected]90310d92011-04-17 07:35:041508 }
[email protected]5db9ada2012-04-11 13:48:201509
1510 return true;
[email protected]90310d92011-04-17 07:35:041511}
1512
[email protected]c3cfb012011-04-06 22:07:351513bool ExtensionService::IsIncognitoEnabled(
1514 const std::string& extension_id) const {
1515 // If this is an existing component extension we always allow it to
1516 // work in incognito mode.
[email protected]81b14cc2011-04-29 00:39:371517 const Extension* extension = GetInstalledExtension(extension_id);
[email protected]c3cfb012011-04-06 22:07:351518 if (extension && extension->location() == Extension::COMPONENT)
[email protected]cb0ce1e022010-03-10 19:54:411519 return true;
1520
1521 // Check the prefs.
[email protected]c3cfb012011-04-06 22:07:351522 return extension_prefs_->IsIncognitoEnabled(extension_id);
[email protected]db7331a2010-02-25 22:10:501523}
[email protected]55a35692010-02-11 23:25:211524
[email protected]c3cfb012011-04-06 22:07:351525void ExtensionService::SetIsIncognitoEnabled(
1526 const std::string& extension_id, bool enabled) {
[email protected]81b14cc2011-04-29 00:39:371527 const Extension* extension = GetInstalledExtension(extension_id);
[email protected]c3cfb012011-04-06 22:07:351528 if (extension && extension->location() == Extension::COMPONENT) {
[email protected]b873cd92012-02-09 21:51:481529 // This shouldn't be called for component extensions unless they are
1530 // syncable.
1531 DCHECK(extension->IsSyncable());
1532
1533 // If we are here, make sure the we aren't trying to change the value.
1534 DCHECK_EQ(enabled, IsIncognitoEnabled(extension_id));
1535
[email protected]c3cfb012011-04-06 22:07:351536 return;
1537 }
1538
[email protected]8c6c8c22011-03-09 12:52:341539 // Broadcast unloaded and loaded events to update browser state. Only bother
1540 // if the value changed and the extension is actually enabled, since there is
1541 // no UI otherwise.
[email protected]c3cfb012011-04-06 22:07:351542 bool old_enabled = extension_prefs_->IsIncognitoEnabled(extension_id);
[email protected]8c6c8c22011-03-09 12:52:341543 if (enabled == old_enabled)
1544 return;
1545
[email protected]c3cfb012011-04-06 22:07:351546 extension_prefs_->SetIsIncognitoEnabled(extension_id, enabled);
[email protected]81b14cc2011-04-29 00:39:371547
[email protected]ffbf3f12011-12-09 22:10:331548 bool extension_is_enabled = extensions_.Contains(extension_id);
[email protected]bd9892eb2011-11-11 19:41:341549
1550 // When we reload the extension the ID may be invalidated if we've passed it
1551 // by const ref everywhere. Make a copy to be safe.
1552 std::string id = extension_id;
[email protected]406b5a92011-11-08 11:58:261553 if (extension_is_enabled)
[email protected]ffbf3f12011-12-09 22:10:331554 ReloadExtension(id);
[email protected]3bdba0d2011-08-23 07:17:301555
[email protected]406b5a92011-11-08 11:58:261556 // Reloading the extension invalidates the |extension| pointer.
[email protected]bd9892eb2011-11-11 19:41:341557 extension = GetInstalledExtension(id);
[email protected]3bdba0d2011-08-23 07:17:301558 if (extension)
1559 SyncExtensionChangeIfNeeded(*extension);
[email protected]55a35692010-02-11 23:25:211560}
1561
[email protected]aa7599d2011-10-28 07:24:321562void ExtensionService::SetAppNotificationSetupDone(
1563 const std::string& extension_id,
[email protected]b2689a902011-12-01 00:41:091564 const std::string& oauth_client_id) {
[email protected]aa7599d2011-10-28 07:24:321565 const Extension* extension = GetInstalledExtension(extension_id);
1566 // This method is called when the user sets up app notifications.
1567 // So it is not expected to be called until the extension is installed.
1568 if (!extension) {
1569 NOTREACHED();
1570 return;
1571 }
[email protected]b2689a902011-12-01 00:41:091572 extension_prefs_->SetAppNotificationClientId(extension_id, oauth_client_id);
[email protected]aa7599d2011-10-28 07:24:321573 SyncExtensionChangeIfNeeded(*extension);
1574}
1575
1576void ExtensionService::SetAppNotificationDisabled(
1577 const std::string& extension_id,
1578 bool value) {
1579 const Extension* extension = GetInstalledExtension(extension_id);
1580 // This method is called when the user enables/disables app notifications.
1581 // So it is not expected to be called until the extension is installed.
1582 if (!extension) {
1583 NOTREACHED();
1584 return;
1585 }
[email protected]97e856b12011-12-14 00:21:131586 if (value)
1587 UMA_HISTOGRAM_COUNTS("Apps.SetAppNotificationsDisabled", 1);
1588 else
1589 UMA_HISTOGRAM_COUNTS("Apps.SetAppNotificationsEnabled", 1);
[email protected]aa7599d2011-10-28 07:24:321590 extension_prefs_->SetAppNotificationDisabled(extension_id, value);
1591 SyncExtensionChangeIfNeeded(*extension);
1592}
1593
[email protected]dc9a74f72012-08-17 18:07:211594bool ExtensionService::CanCrossIncognito(const Extension* extension) const {
[email protected]2a8f24e2010-11-03 21:37:051595 // We allow the extension to see events and data from another profile iff it
1596 // uses "spanning" behavior and it has incognito access. "split" mode
1597 // extensions only see events for a matching profile.
[email protected]0c41298f2011-09-13 21:17:221598 CHECK(extension);
[email protected]c3cfb012011-04-06 22:07:351599 return IsIncognitoEnabled(extension->id()) &&
1600 !extension->incognito_split_mode();
[email protected]2a8f24e2010-11-03 21:37:051601}
1602
[email protected]5ef7b002011-05-12 23:16:201603bool ExtensionService::CanLoadInIncognito(const Extension* extension) const {
1604 if (extension->is_hosted_app())
1605 return true;
1606 // Packaged apps and regular extensions need to be enabled specifically for
1607 // incognito (and split mode should be set).
1608 return extension->incognito_split_mode() &&
1609 IsIncognitoEnabled(extension->id());
1610}
1611
[email protected]168389f2011-12-20 17:12:481612void ExtensionService::OnExtensionMoved(
1613 const std::string& moved_extension_id,
1614 const std::string& predecessor_extension_id,
1615 const std::string& successor_extension_id) {
[email protected]3569b502012-01-12 20:08:231616 extension_prefs_->extension_sorting()->OnExtensionMoved(
1617 moved_extension_id,
1618 predecessor_extension_id,
1619 successor_extension_id);
[email protected]168389f2011-12-20 17:12:481620
1621 const Extension* extension = GetInstalledExtension(moved_extension_id);
1622 if (extension)
1623 SyncExtensionChangeIfNeeded(*extension);
1624}
1625
[email protected]dc9a74f72012-08-17 18:07:211626bool ExtensionService::AllowFileAccess(const Extension* extension) const {
[email protected]05c82182010-06-24 17:49:081627 return (CommandLine::ForCurrentProcess()->HasSwitch(
[email protected]334e04a2010-06-24 23:34:441628 switches::kDisableExtensionsFileAccessCheck) ||
[email protected]05c82182010-06-24 17:49:081629 extension_prefs_->AllowFileAccess(extension->id()));
1630}
1631
[email protected]eaa7dd182010-12-14 11:09:001632void ExtensionService::SetAllowFileAccess(const Extension* extension,
[email protected]3aff9ad2011-04-01 20:26:481633 bool allow) {
1634 // Reload to update browser state. Only bother if the value changed and the
1635 // extension is actually enabled, since there is no UI otherwise.
1636 bool old_allow = AllowFileAccess(extension);
1637 if (allow == old_allow)
1638 return;
1639
[email protected]05c82182010-06-24 17:49:081640 extension_prefs_->SetAllowFileAccess(extension->id(), allow);
[email protected]3aff9ad2011-04-01 20:26:481641
[email protected]84df8332011-12-06 18:22:461642 bool extension_is_enabled = extensions_.Contains(extension->id());
[email protected]3aff9ad2011-04-01 20:26:481643 if (extension_is_enabled)
1644 ReloadExtension(extension->id());
[email protected]05c82182010-06-24 17:49:081645}
1646
[email protected]8e4560b62011-01-14 10:09:141647// Some extensions will autoupdate themselves externally from Chrome. These
1648// are typically part of some larger client application package. To support
1649// these, the extension will register its location in the the preferences file
1650// (and also, on Windows, in the registry) and this code will periodically
1651// check that location for a .crx file, which it will then install locally if
1652// a new version is available.
1653// Errors are reported through ExtensionErrorReporter. Succcess is not
1654// reported.
[email protected]eaa7dd182010-12-14 11:09:001655void ExtensionService::CheckForExternalUpdates() {
[email protected]a29a517a2011-01-21 21:11:121656 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]8e4560b62011-01-14 10:09:141657
1658 // Note that this installation is intentionally silent (since it didn't
1659 // go through the front-end). Extensions that are registered in this
1660 // way are effectively considered 'pre-bundled', and so implicitly
1661 // trusted. In general, if something has HKLM or filesystem access,
1662 // they could install an extension manually themselves anyway.
[email protected]a29a517a2011-01-21 21:11:121663
[email protected]8e4560b62011-01-14 10:09:141664 // Ask each external extension provider to give us a call back for each
1665 // extension they know about. See OnExternalExtension(File|UpdateUrl)Found.
[email protected]5df038b2012-07-16 19:03:271666 extensions::ProviderCollection::const_iterator i;
[email protected]8e4560b62011-01-14 10:09:141667 for (i = external_extension_providers_.begin();
1668 i != external_extension_providers_.end(); ++i) {
[email protected]5df038b2012-07-16 19:03:271669 extensions::ExternalProviderInterface* provider = i->get();
[email protected]8e4560b62011-01-14 10:09:141670 provider->VisitRegisteredExtension();
1671 }
1672
[email protected]50067e52011-10-20 23:17:071673 // Do any required work that we would have done after completion of all
1674 // providers.
1675 if (external_extension_providers_.empty()) {
1676 OnAllExternalProvidersReady();
1677 }
[email protected]9f1087e2009-06-15 17:29:321678}
1679
[email protected]50067e52011-10-20 23:17:071680void ExtensionService::OnExternalProviderReady(
[email protected]5df038b2012-07-16 19:03:271681 const extensions::ExternalProviderInterface* provider) {
[email protected]a29a517a2011-01-21 21:11:121682 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]50067e52011-10-20 23:17:071683 CHECK(provider->IsReady());
[email protected]a29a517a2011-01-21 21:11:121684
1685 // An external provider has finished loading. We only take action
[email protected]8e4560b62011-01-14 10:09:141686 // if all of them are finished. So we check them first.
[email protected]94fde232012-04-27 10:22:301687 if (AreAllExternalProvidersReady())
1688 OnAllExternalProvidersReady();
1689}
1690
1691bool ExtensionService::AreAllExternalProvidersReady() const {
[email protected]5df038b2012-07-16 19:03:271692 extensions::ProviderCollection::const_iterator i;
[email protected]8e4560b62011-01-14 10:09:141693 for (i = external_extension_providers_.begin();
1694 i != external_extension_providers_.end(); ++i) {
[email protected]94fde232012-04-27 10:22:301695 if (!i->get()->IsReady())
1696 return false;
[email protected]8e4560b62011-01-14 10:09:141697 }
[email protected]94fde232012-04-27 10:22:301698 return true;
[email protected]50067e52011-10-20 23:17:071699}
1700
1701void ExtensionService::OnAllExternalProvidersReady() {
1702 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]94fde232012-04-27 10:22:301703 base::TimeDelta elapsed = base::Time::Now() - profile_->GetStartTime();
1704 UMA_HISTOGRAM_TIMES("Extension.ExternalProvidersReadyAfter", elapsed);
[email protected]50067e52011-10-20 23:17:071705
1706 // Install any pending extensions.
[email protected]94fde232012-04-27 10:22:301707 if (update_once_all_providers_are_ready_ && updater()) {
1708 update_once_all_providers_are_ready_ = false;
[email protected]8e4560b62011-01-14 10:09:141709 updater()->CheckNow();
1710 }
1711
1712 // Uninstall all the unclaimed extensions.
[email protected]45759612012-07-10 17:21:231713 scoped_ptr<extensions::ExtensionPrefs::ExtensionsInfo> extensions_info(
[email protected]8e4560b62011-01-14 10:09:141714 extension_prefs_->GetInstalledExtensionsInfo());
1715 for (size_t i = 0; i < extensions_info->size(); ++i) {
1716 ExtensionInfo* info = extensions_info->at(i).get();
1717 if (Extension::IsExternalLocation(info->extension_location))
1718 CheckExternalUninstall(info->extension_id);
1719 }
[email protected]e5af875f2011-10-10 21:09:141720 IdentifyAlertableExtensions();
[email protected]e5af875f2011-10-10 21:09:141721}
1722
1723void ExtensionService::IdentifyAlertableExtensions() {
1724 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1725
[email protected]07c9f2f42012-02-29 18:45:221726 // Build up the lists of extensions that require acknowledgment. If this is
1727 // the first time, grandfather extensions that would have caused
1728 // notification.
[email protected]89226982012-07-16 20:09:181729 extension_error_ui_.reset(ExtensionErrorUI::Create(this));
[email protected]e5af875f2011-10-10 21:09:141730
[email protected]a9aa5932012-01-25 08:27:401731 bool did_show_alert = false;
[email protected]89226982012-07-16 20:09:181732 if (PopulateExtensionErrorUI(extension_error_ui_.get())) {
[email protected]e5af875f2011-10-10 21:09:141733 if (extension_prefs_->SetAlertSystemFirstRun()) {
[email protected]a9aa5932012-01-25 08:27:401734 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]89226982012-07-16 20:09:181735 did_show_alert = extension_error_ui_->ShowErrorInBubbleView();
[email protected]e5af875f2011-10-10 21:09:141736 } else {
1737 // First run. Just acknowledge all the extensions, silently, by
1738 // shortcutting the display of the UI and going straight to the
1739 // callback for pressing the Accept button.
[email protected]a9aa5932012-01-25 08:27:401740 HandleExtensionAlertAccept();
[email protected]e5af875f2011-10-10 21:09:141741 }
1742 }
[email protected]a9aa5932012-01-25 08:27:401743
1744 if (!did_show_alert)
[email protected]89226982012-07-16 20:09:181745 extension_error_ui_.reset();
[email protected]e5af875f2011-10-10 21:09:141746}
1747
[email protected]89226982012-07-16 20:09:181748bool ExtensionService::PopulateExtensionErrorUI(
1749 ExtensionErrorUI* extension_error_ui) {
[email protected]07c9f2f42012-02-29 18:45:221750 bool needs_alert = false;
1751 for (ExtensionSet::const_iterator iter = extensions_.begin();
1752 iter != extensions_.end(); ++iter) {
1753 const Extension* e = *iter;
1754 if (Extension::IsExternalLocation(e->location())) {
1755 if (!e->is_hosted_app()) {
1756 if (!extension_prefs_->IsExternalExtensionAcknowledged(e->id())) {
[email protected]89226982012-07-16 20:09:181757 extension_error_ui->AddExternalExtension(e->id());
[email protected]07c9f2f42012-02-29 18:45:221758 needs_alert = true;
1759 }
1760 }
1761 }
[email protected]4ee07c62012-08-21 12:40:421762 if (!extension_prefs_->UserMayLoad(e, NULL)) {
[email protected]07c9f2f42012-02-29 18:45:221763 if (!extension_prefs_->IsBlacklistedExtensionAcknowledged(e->id())) {
[email protected]89226982012-07-16 20:09:181764 extension_error_ui->AddBlacklistedExtension(e->id());
[email protected]07c9f2f42012-02-29 18:45:221765 needs_alert = true;
1766 }
1767 }
1768 if (extension_prefs_->IsExtensionOrphaned(e->id())) {
1769 if (!extension_prefs_->IsOrphanedExtensionAcknowledged(e->id())) {
[email protected]89226982012-07-16 20:09:181770 extension_error_ui->AddOrphanedExtension(e->id());
[email protected]07c9f2f42012-02-29 18:45:221771 needs_alert = true;
1772 }
1773 }
1774 }
1775 return needs_alert;
1776}
1777
[email protected]a9aa5932012-01-25 08:27:401778void ExtensionService::HandleExtensionAlertClosed() {
[email protected]89226982012-07-16 20:09:181779 extension_error_ui_.reset();
[email protected]62433d32011-10-12 22:33:121780}
1781
[email protected]a9aa5932012-01-25 08:27:401782void ExtensionService::HandleExtensionAlertAccept() {
[email protected]e5af875f2011-10-10 21:09:141783 const ExtensionIdSet *extension_ids =
[email protected]89226982012-07-16 20:09:181784 extension_error_ui_->get_external_extension_ids();
[email protected]e5af875f2011-10-10 21:09:141785 for (ExtensionIdSet::const_iterator iter = extension_ids->begin();
1786 iter != extension_ids->end(); ++iter) {
[email protected]47fc70c2011-12-06 07:29:511787 AcknowledgeExternalExtension(*iter);
[email protected]e5af875f2011-10-10 21:09:141788 }
[email protected]89226982012-07-16 20:09:181789 extension_ids = extension_error_ui_->get_blacklisted_extension_ids();
[email protected]e5af875f2011-10-10 21:09:141790 for (ExtensionIdSet::const_iterator iter = extension_ids->begin();
1791 iter != extension_ids->end(); ++iter) {
1792 extension_prefs_->AcknowledgeBlacklistedExtension(*iter);
1793 }
[email protected]89226982012-07-16 20:09:181794 extension_ids = extension_error_ui_->get_orphaned_extension_ids();
[email protected]e5af875f2011-10-10 21:09:141795 for (ExtensionIdSet::const_iterator iter = extension_ids->begin();
1796 iter != extension_ids->end(); ++iter) {
1797 extension_prefs_->AcknowledgeOrphanedExtension(*iter);
1798 }
1799}
1800
[email protected]47fc70c2011-12-06 07:29:511801void ExtensionService::AcknowledgeExternalExtension(const std::string& id) {
1802 extension_prefs_->AcknowledgeExternalExtension(id);
1803}
1804
[email protected]89226982012-07-16 20:09:181805void ExtensionService::HandleExtensionAlertDetails() {
1806 extension_error_ui_->ShowExtensions();
[email protected]6c751e72010-11-23 10:11:101807}
1808
[email protected]a9f39a312010-12-23 22:14:271809void ExtensionService::UnloadExtension(
1810 const std::string& extension_id,
[email protected]814a7bf0f2011-08-13 05:30:591811 extension_misc::UnloadedExtensionReason reason) {
[email protected]27e469a2010-01-11 20:35:091812 // Make sure the extension gets deleted after we return from this function.
[email protected]31bb5ee62012-09-12 22:58:401813 int include_mask = INCLUDE_ENABLED | INCLUDE_DISABLED;
[email protected]9adb9692010-10-29 23:14:021814 scoped_refptr<const Extension> extension(
[email protected]81f0d162012-08-15 04:21:471815 GetExtensionByIdInternal(extension_id, include_mask));
[email protected]631cf822009-05-15 07:01:251816
[email protected]fa0c96732010-11-17 00:14:231817 // This method can be called via PostTask, so the extension may have been
1818 // unloaded by the time this runs.
[email protected]dd163fb02011-05-04 22:22:171819 if (!extension) {
1820 // In case the extension may have crashed/uninstalled. Allow the profile to
1821 // clean up its RequestContexts.
[email protected]31d8f5f22012-04-02 15:22:081822 system_->UnregisterExtensionWithRequestContexts(extension_id, reason);
[email protected]fa0c96732010-11-17 00:14:231823 return;
[email protected]dd163fb02011-05-04 22:22:171824 }
[email protected]0c6da502009-08-14 22:32:391825
[email protected]1eb175082010-02-10 09:26:161826 // Keep information about the extension so that we can reload it later
1827 // even if it's not permanently installed.
1828 unloaded_extension_paths_[extension->id()] = extension->path();
1829
[email protected]f17dbd42010-08-16 23:21:101830 // Clean up if the extension is meant to be enabled after a reload.
1831 disabled_extension_paths_.erase(extension->id());
1832
[email protected]d7e9a862010-11-03 21:57:491833 // Clean up runtime data.
1834 extension_runtime_data_.erase(extension_id);
1835
[email protected]060d4972012-07-19 17:22:391836 if (disabled_extensions_.Contains(extension->id())) {
[email protected]a9f39a312010-12-23 22:14:271837 UnloadedExtensionInfo details(extension, reason);
1838 details.already_disabled = true;
[email protected]84df8332011-12-06 18:22:461839 disabled_extensions_.Remove(extension->id());
[email protected]ad50def52011-10-19 23:17:071840 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271841 chrome::NOTIFICATION_EXTENSION_UNLOADED,
[email protected]6c2381d2011-10-19 02:52:531842 content::Source<Profile>(profile_),
1843 content::Details<UnloadedExtensionInfo>(&details));
[email protected]dd163fb02011-05-04 22:22:171844 // Make sure the profile cleans up its RequestContexts when an already
1845 // disabled extension is unloaded (since they are also tracking the disabled
1846 // extensions).
[email protected]31d8f5f22012-04-02 15:22:081847 system_->UnregisterExtensionWithRequestContexts(extension_id, reason);
[email protected]0c6da502009-08-14 22:32:391848 return;
1849 }
1850
[email protected]060d4972012-07-19 17:22:391851 // Remove the extension from our list.
[email protected]84df8332011-12-06 18:22:461852 extensions_.Remove(extension->id());
[email protected]631cf822009-05-15 07:01:251853
[email protected]a9f39a312010-12-23 22:14:271854 NotifyExtensionUnloaded(extension.get(), reason);
[email protected]631cf822009-05-15 07:01:251855}
1856
[email protected]eaa7dd182010-12-14 11:09:001857void ExtensionService::UnloadAllExtensions() {
[email protected]31bb5ee62012-09-12 22:58:401858 profile_->GetExtensionSpecialStoragePolicy()->RevokeRightsForAllExtensions();
[email protected]c8d407e2011-04-28 21:27:171859
[email protected]84df8332011-12-06 18:22:461860 extensions_.Clear();
1861 disabled_extensions_.Clear();
1862 terminated_extensions_.Clear();
[email protected]d7e9a862010-11-03 21:57:491863 extension_runtime_data_.clear();
[email protected]cd500f72010-06-25 23:44:321864
[email protected]c6e4a3412009-06-24 15:45:291865 // TODO(erikkay) should there be a notification for this? We can't use
1866 // EXTENSION_UNLOADED since that implies that the extension has been disabled
1867 // or uninstalled, and UnloadAll is just part of shutdown.
[email protected]9f1087e2009-06-15 17:29:321868}
1869
[email protected]eaa7dd182010-12-14 11:09:001870void ExtensionService::ReloadExtensions() {
[email protected]9f1087e2009-06-15 17:29:321871 UnloadAllExtensions();
[email protected]d8c8f25f2011-11-02 18:18:011872 component_loader_->LoadAll();
1873 extensions::InstalledLoader(this).LoadAllExtensions();
[email protected]9f1087e2009-06-15 17:29:321874}
1875
[email protected]eaa7dd182010-12-14 11:09:001876void ExtensionService::GarbageCollectExtensions() {
[email protected]2f8757c32012-06-19 19:17:471877 if (extension_prefs_->pref_service()->ReadOnly())
1878 return;
1879
[email protected]45759612012-07-10 17:21:231880 scoped_ptr<extensions::ExtensionPrefs::ExtensionsInfo> info(
[email protected]2f8757c32012-06-19 19:17:471881 extension_prefs_->GetInstalledExtensionsInfo());
1882
1883 std::map<std::string, FilePath> extension_paths;
1884 for (size_t i = 0; i < info->size(); ++i)
1885 extension_paths[info->at(i)->extension_id] = info->at(i)->extension_path;
1886
1887 if (!BrowserThread::PostTask(
1888 BrowserThread::FILE, FROM_HERE,
1889 base::Bind(
1890 &extension_file_util::GarbageCollectExtensions,
1891 install_directory_,
[email protected]31bb5ee62012-09-12 22:58:401892 extension_paths))) {
[email protected]2f8757c32012-06-19 19:17:471893 NOTREACHED();
[email protected]31bb5ee62012-09-12 22:58:401894 }
[email protected]f6ccd652010-11-17 00:48:341895
[email protected]f766a9d2012-07-11 01:57:441896#if defined(ENABLE_THEMES)
[email protected]f6ccd652010-11-17 00:48:341897 // Also garbage-collect themes. We check |profile_| to be
1898 // defensive; in the future, we may call GarbageCollectExtensions()
1899 // from somewhere other than Init() (e.g., in a timer).
1900 if (profile_) {
[email protected]18280372011-03-22 18:05:221901 ThemeServiceFactory::GetForProfile(profile_)->RemoveUnusedThemes();
[email protected]f6ccd652010-11-17 00:48:341902 }
[email protected]f766a9d2012-07-11 01:57:441903#endif
[email protected]3cf4f0992009-02-03 23:00:301904}
1905
[email protected]fb82dcd2012-03-21 14:15:461906void ExtensionService::SyncExtensionChangeIfNeeded(const Extension& extension) {
[email protected]5db9ada2012-04-11 13:48:201907 if (app_sync_bundle_.HandlesApp(extension)) {
1908 app_sync_bundle_.SyncChangeIfNeeded(extension);
1909 } else if (extension_sync_bundle_.HandlesExtension(extension)) {
1910 extension_sync_bundle_.SyncChangeIfNeeded(extension);
[email protected]fb82dcd2012-03-21 14:15:461911 }
1912}
1913
[email protected]eaa7dd182010-12-14 11:09:001914void ExtensionService::OnLoadedInstalledExtensions() {
[email protected]31bb5ee62012-09-12 22:58:401915 if (updater_.get())
[email protected]93fd78f42009-07-10 16:43:171916 updater_->Start();
[email protected]fa6a9102010-11-22 15:38:501917
1918 ready_ = true;
[email protected]ad50def52011-10-19 23:17:071919 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271920 chrome::NOTIFICATION_EXTENSIONS_READY,
[email protected]6c2381d2011-10-19 02:52:531921 content::Source<Profile>(profile_),
[email protected]ad50def52011-10-19 23:17:071922 content::NotificationService::NoDetails());
[email protected]e72e8eb82009-06-18 17:21:511923}
1924
[email protected]fcb58a862012-05-01 01:03:151925void ExtensionService::AddExtension(const Extension* extension) {
[email protected]ae09ca62009-08-21 19:46:461926 // Ensure extension is deleted unless we transfer ownership.
[email protected]9adb9692010-10-29 23:14:021927 scoped_refptr<const Extension> scoped_extension(extension);
[email protected]9f1087e2009-06-15 17:29:321928
[email protected]c8d407e2011-04-28 21:27:171929 // TODO(jstritar): We may be able to get rid of this branch by overriding the
1930 // default extension state to DISABLED when the --disable-extensions flag
1931 // is set (http://crbug.com/29067).
1932 if (!extensions_enabled() &&
1933 !extension->is_theme() &&
1934 extension->location() != Extension::COMPONENT &&
[email protected]330840c2012-08-29 22:21:011935 !Extension::IsExternalLocation(extension->location())) {
[email protected]fcb58a862012-05-01 01:03:151936 return;
[email protected]330840c2012-08-29 22:21:011937 }
[email protected]c8d407e2011-04-28 21:27:171938
1939 SetBeingUpgraded(extension, false);
1940
[email protected]1eb175082010-02-10 09:26:161941 // The extension is now loaded, remove its data from unloaded extension map.
1942 unloaded_extension_paths_.erase(extension->id());
1943
[email protected]bb7f40952011-01-13 00:21:201944 // If a terminated extension is loaded, remove it from the terminated list.
1945 UntrackTerminatedExtension(extension->id());
1946
[email protected]f17dbd42010-08-16 23:21:101947 // If the extension was disabled for a reload, then enable it.
1948 if (disabled_extension_paths_.erase(extension->id()) > 0)
1949 EnableExtension(extension->id());
1950
[email protected]d728e002010-12-08 04:46:231951 // Check if the extension's privileges have changed and disable the
1952 // extension if necessary.
[email protected]902fd7b2011-07-27 18:42:311953 InitializePermissions(extension);
[email protected]0c6da502009-08-14 22:32:391954
[email protected]31bb5ee62012-09-12 22:58:401955 if (extension_prefs_->IsExtensionDisabled(extension->id())) {
[email protected]84df8332011-12-06 18:22:461956 disabled_extensions_.Insert(scoped_extension);
[email protected]3bdba0d2011-08-23 07:17:301957 SyncExtensionChangeIfNeeded(*extension);
[email protected]44d62b62012-04-11 00:06:031958 content::NotificationService::current()->Notify(
1959 chrome::NOTIFICATION_EXTENSION_UPDATE_DISABLED,
1960 content::Source<Profile>(profile_),
1961 content::Details<const Extension>(extension));
[email protected]62f051c2012-03-29 17:04:441962
[email protected]eb5e4f92012-08-15 23:33:281963 if (extension_prefs_->GetDisableReasons(extension->id()) &
[email protected]44d62b62012-04-11 00:06:031964 Extension::DISABLE_PERMISSIONS_INCREASE) {
[email protected]62f051c2012-03-29 17:04:441965 extensions::AddExtensionDisabledError(this, extension);
1966 }
[email protected]fcb58a862012-05-01 01:03:151967 return;
[email protected]e72e8eb82009-06-18 17:21:511968 }
[email protected]aab98a52009-12-02 03:22:351969
[email protected]b873cd92012-02-09 21:51:481970 // All apps that are displayed in the launcher are ordered by their ordinals
1971 // so we must ensure they have valid ordinals.
1972 if (extension->ShouldDisplayInLauncher())
1973 extension_prefs_->extension_sorting()->EnsureValidOrdinals(extension->id());
1974
[email protected]84df8332011-12-06 18:22:461975 extensions_.Insert(scoped_extension);
[email protected]3bdba0d2011-08-23 07:17:301976 SyncExtensionChangeIfNeeded(*extension);
[email protected]c8d407e2011-04-28 21:27:171977 NotifyExtensionLoaded(extension);
[email protected]6cafe35a2012-08-27 22:40:501978 QueueRestoreAppWindow(extension);
[email protected]aab98a52009-12-02 03:22:351979}
1980
[email protected]902fd7b2011-07-27 18:42:311981void ExtensionService::InitializePermissions(const Extension* extension) {
1982 // If the extension has used the optional permissions API, it will have a
1983 // custom set of active permissions defined in the extension prefs. Here,
1984 // we update the extension's active permissions based on the prefs.
[email protected]c2e66e12012-06-27 06:27:061985 scoped_refptr<PermissionSet> active_permissions =
[email protected]902fd7b2011-07-27 18:42:311986 extension_prefs()->GetActivePermissions(extension->id());
1987
1988 if (active_permissions.get()) {
1989 // We restrict the active permissions to be within the bounds defined in the
1990 // extension's manifest.
1991 // a) active permissions must be a subset of optional + default permissions
1992 // b) active permissions must contains all default permissions
[email protected]c2e66e12012-06-27 06:27:061993 scoped_refptr<PermissionSet> total_permissions =
1994 PermissionSet::CreateUnion(
[email protected]902fd7b2011-07-27 18:42:311995 extension->required_permission_set(),
1996 extension->optional_permission_set());
1997
1998 // Make sure the active permissions contain no more than optional + default.
[email protected]c2e66e12012-06-27 06:27:061999 scoped_refptr<PermissionSet> adjusted_active =
2000 PermissionSet::CreateIntersection(
[email protected]902fd7b2011-07-27 18:42:312001 total_permissions.get(), active_permissions.get());
2002
2003 // Make sure the active permissions contain the default permissions.
[email protected]c2e66e12012-06-27 06:27:062004 adjusted_active = PermissionSet::CreateUnion(
[email protected]902fd7b2011-07-27 18:42:312005 extension->required_permission_set(), adjusted_active.get());
2006
[email protected]c333e792012-01-06 16:57:392007 extensions::PermissionsUpdater perms_updater(profile());
2008 perms_updater.UpdateActivePermissions(extension, adjusted_active);
[email protected]902fd7b2011-07-27 18:42:312009 }
2010
[email protected]8d888c12010-11-30 00:00:252011 // We keep track of all permissions the user has granted each extension.
2012 // This allows extensions to gracefully support backwards compatibility
2013 // by including unknown permissions in their manifests. When the user
2014 // installs the extension, only the recognized permissions are recorded.
2015 // When the unknown permissions become recognized (e.g., through browser
2016 // upgrade), we can prompt the user to accept these new permissions.
2017 // Extensions can also silently upgrade to less permissions, and then
2018 // silently upgrade to a version that adds these permissions back.
2019 //
2020 // For example, pretend that Chrome 10 includes a permission "omnibox"
2021 // for an API that adds suggestions to the omnibox. An extension can
2022 // maintain backwards compatibility while still having "omnibox" in the
2023 // manifest. If a user installs the extension on Chrome 9, the browser
2024 // will record the permissions it recognized, not including "omnibox."
2025 // When upgrading to Chrome 10, "omnibox" will be recognized and Chrome
2026 // will disable the extension and prompt the user to approve the increase
2027 // in privileges. The extension could then release a new version that
2028 // removes the "omnibox" permission. When the user upgrades, Chrome will
2029 // still remember that "omnibox" had been granted, so that if the
2030 // extension once again includes "omnibox" in an upgrade, the extension
2031 // can upgrade without requiring this user's approval.
[email protected]31bb5ee62012-09-12 22:58:402032 int include_mask = INCLUDE_ENABLED | INCLUDE_DISABLED;
[email protected]81f0d162012-08-15 04:21:472033 const Extension* old =
2034 GetExtensionByIdInternal(extension->id(), include_mask);
[email protected]8d888c12010-11-30 00:00:252035 bool is_extension_upgrade = old != NULL;
2036 bool is_privilege_increase = false;
[email protected]44d62b62012-04-11 00:06:032037 bool previously_disabled = false;
[email protected]eb5e4f92012-08-15 23:33:282038 int disable_reasons = extension_prefs_->GetDisableReasons(extension->id());
[email protected]8d888c12010-11-30 00:00:252039
[email protected]902fd7b2011-07-27 18:42:312040 // We only need to compare the granted permissions to the current permissions
2041 // if the extension is not allowed to silently increase its permissions.
[email protected]be083862012-09-01 03:53:452042 bool is_default_app_install =
2043 (!is_extension_upgrade && extension->was_installed_by_default());
2044 if (!(extension->CanSilentlyIncreasePermissions()
2045 || is_default_app_install)) {
[email protected]8d888c12010-11-30 00:00:252046 // Add all the recognized permissions if the granted permissions list
2047 // hasn't been initialized yet.
[email protected]c2e66e12012-06-27 06:27:062048 scoped_refptr<PermissionSet> granted_permissions =
[email protected]902fd7b2011-07-27 18:42:312049 extension_prefs_->GetGrantedPermissions(extension->id());
[email protected]0d3e4a22011-06-23 19:02:522050 CHECK(granted_permissions.get());
[email protected]8d888c12010-11-30 00:00:252051
2052 // Here, we check if an extension's privileges have increased in a manner
2053 // that requires the user's approval. This could occur because the browser
2054 // upgraded and recognized additional privileges, or an extension upgrades
2055 // to a version that requires additional privileges.
[email protected]0d3e4a22011-06-23 19:02:522056 is_privilege_increase =
[email protected]902fd7b2011-07-27 18:42:312057 granted_permissions->HasLessPrivilegesThan(
2058 extension->GetActivePermissions());
[email protected]8d888c12010-11-30 00:00:252059 }
2060
[email protected]be083862012-09-01 03:53:452061 // Silently grant all active permissions to default apps only on install.
2062 // After install they should behave like other apps.
[email protected]31bb5ee62012-09-12 22:58:402063 if (is_default_app_install)
[email protected]be083862012-09-01 03:53:452064 GrantPermissions(extension, true);
[email protected]be083862012-09-01 03:53:452065
[email protected]8d888c12010-11-30 00:00:252066 if (is_extension_upgrade) {
[email protected]66e26872010-12-03 20:07:252067 // Other than for unpacked extensions, CrxInstaller should have guaranteed
2068 // that we aren't downgrading.
2069 if (extension->location() != Extension::LOAD)
[email protected]31bb5ee62012-09-12 22:58:402070 CHECK_GE(extension->version()->CompareTo(*(old->version())), 0);
[email protected]8d888c12010-11-30 00:00:252071
2072 // Extensions get upgraded if the privileges are allowed to increase or
2073 // the privileges haven't increased.
2074 if (!is_privilege_increase) {
2075 SetBeingUpgraded(old, true);
2076 SetBeingUpgraded(extension, true);
2077 }
2078
[email protected]44d62b62012-04-11 00:06:032079 // If the extension was already disabled, suppress any alerts for becoming
2080 // disabled on permissions increase.
2081 previously_disabled = extension_prefs_->IsExtensionDisabled(old->id());
2082 if (previously_disabled) {
[email protected]eb5e4f92012-08-15 23:33:282083 int reasons = extension_prefs_->GetDisableReasons(old->id());
2084 if (reasons == Extension::DISABLE_NONE) {
[email protected]44d62b62012-04-11 00:06:032085 // Initialize the reason for legacy disabled extensions from whether the
2086 // extension already exceeded granted permissions.
2087 if (extension_prefs_->DidExtensionEscalatePermissions(old->id()))
[email protected]eb5e4f92012-08-15 23:33:282088 disable_reasons = Extension::DISABLE_PERMISSIONS_INCREASE;
[email protected]44d62b62012-04-11 00:06:032089 else
[email protected]eb5e4f92012-08-15 23:33:282090 disable_reasons = Extension::DISABLE_USER_ACTION;
[email protected]44d62b62012-04-11 00:06:032091 }
2092 } else {
[email protected]eb5e4f92012-08-15 23:33:282093 disable_reasons = Extension::DISABLE_PERMISSIONS_INCREASE;
[email protected]44d62b62012-04-11 00:06:032094 }
2095
[email protected]8d888c12010-11-30 00:00:252096 // To upgrade an extension in place, unload the old one and
2097 // then load the new one.
[email protected]814a7bf0f2011-08-13 05:30:592098 UnloadExtension(old->id(), extension_misc::UNLOAD_REASON_UPDATE);
[email protected]8d888c12010-11-30 00:00:252099 old = NULL;
2100 }
2101
2102 // Extension has changed permissions significantly. Disable it. A
2103 // notification should be sent by the caller.
2104 if (is_privilege_increase) {
[email protected]fe2dd7742011-04-19 22:52:492105 if (!extension_prefs_->DidExtensionEscalatePermissions(extension->id())) {
2106 RecordPermissionMessagesHistogram(
2107 extension, "Extensions.Permissions_AutoDisable");
2108 }
[email protected]b3317ad2011-04-28 23:46:002109 extension_prefs_->SetExtensionState(extension->id(), Extension::DISABLED);
[email protected]8d888c12010-11-30 00:00:252110 extension_prefs_->SetDidExtensionEscalatePermissions(extension, true);
[email protected]eb5e4f92012-08-15 23:33:282111 extension_prefs_->AddDisableReason(
2112 extension->id(),
2113 static_cast<Extension::DisableReason>(disable_reasons));
[email protected]8d888c12010-11-30 00:00:252114 }
2115}
2116
[email protected]eaa7dd182010-12-14 11:09:002117void ExtensionService::UpdateActiveExtensionsInCrashReporter() {
[email protected]c8865962009-12-16 07:47:392118 std::set<std::string> extension_ids;
[email protected]84df8332011-12-06 18:22:462119 for (ExtensionSet::const_iterator iter = extensions_.begin();
2120 iter != extensions_.end(); ++iter) {
2121 const Extension* extension = *iter;
2122 if (!extension->is_theme() && extension->location() != Extension::COMPONENT)
2123 extension_ids.insert(extension->id());
[email protected]aab98a52009-12-02 03:22:352124 }
2125
2126 child_process_logging::SetActiveExtensions(extension_ids);
[email protected]6014d672008-12-05 00:38:252127}
2128
[email protected]8266d662011-07-12 21:53:262129void ExtensionService::OnExtensionInstalled(
[email protected]36a5c4c2011-12-14 16:34:502130 const Extension* extension,
2131 bool from_webstore,
[email protected]98270432012-09-11 20:51:242132 const syncer::StringOrdinal& page_ordinal,
2133 bool has_requirement_errors) {
[email protected]a29a517a2011-01-21 21:11:122134 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]a8af9fdb2010-10-28 21:52:202135
[email protected]4416c5a2010-06-26 01:28:572136 // Ensure extension is deleted unless we transfer ownership.
[email protected]9adb9692010-10-29 23:14:022137 scoped_refptr<const Extension> scoped_extension(extension);
[email protected]c3cfb012011-04-06 22:07:352138 const std::string& id = extension->id();
[email protected]8a87a5332011-08-11 17:54:592139 // Extensions installed by policy can't be disabled. So even if a previous
2140 // installation disabled the extension, make sure it is now enabled.
2141 bool initial_enable =
2142 !extension_prefs_->IsExtensionDisabled(id) ||
[email protected]65187152012-06-02 13:14:142143 system_->management_policy()->MustRemainEnabled(extension, NULL);
[email protected]3f213ad2012-07-26 23:39:412144 const extensions::PendingExtensionInfo* pending_extension_info = NULL;
[email protected]51a3bf8b2012-06-08 22:53:062145 if ((pending_extension_info = pending_extension_manager()->GetById(id))) {
2146 if (!pending_extension_info->ShouldAllowInstall(*extension)) {
2147 pending_extension_manager()->Remove(id);
[email protected]8ef78fd2010-08-19 17:14:322148
[email protected]31bb5ee62012-09-12 22:58:402149 LOG(WARNING) << "ShouldAllowInstall() returned false for "
2150 << id << " of type " << extension->GetType()
2151 << " and update URL " << extension->update_url().spec()
2152 << "; not installing";
[email protected]ae6cb3022011-04-04 20:11:542153
[email protected]ad50def52011-10-19 23:17:072154 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:272155 chrome::NOTIFICATION_EXTENSION_INSTALL_NOT_ALLOWED,
[email protected]6c2381d2011-10-19 02:52:532156 content::Source<Profile>(profile_),
2157 content::Details<const Extension>(extension));
[email protected]ae6cb3022011-04-04 20:11:542158
[email protected]4416c5a2010-06-26 01:28:572159 // Delete the extension directory since we're not going to
2160 // load it.
[email protected]14908b72011-04-20 06:54:362161 if (!BrowserThread::PostTask(
2162 BrowserThread::FILE, FROM_HERE,
[email protected]53612e82011-10-18 18:00:362163 base::Bind(&extension_file_util::DeleteFile,
[email protected]31bb5ee62012-09-12 22:58:402164 extension->path(), true))) {
[email protected]14908b72011-04-20 06:54:362165 NOTREACHED();
[email protected]31bb5ee62012-09-12 22:58:402166 }
[email protected]4416c5a2010-06-26 01:28:572167 return;
2168 }
[email protected]51a3bf8b2012-06-08 22:53:062169
2170 pending_extension_manager()->Remove(id);
[email protected]4416c5a2010-06-26 01:28:572171 } else {
[email protected]c3cfb012011-04-06 22:07:352172 // We explicitly want to re-enable an uninstalled external
2173 // extension; if we're here, that means the user is manually
2174 // installing the extension.
[email protected]6cc7dbae2011-04-29 21:18:332175 if (IsExternalExtensionUninstalled(id)) {
2176 initial_enable = true;
2177 }
[email protected]aa142702010-03-26 01:26:332178 }
2179
[email protected]98270432012-09-11 20:51:242180 // Unsupported requirements overrides the management policy.
2181 if (has_requirement_errors) {
2182 initial_enable = false;
2183 extension_prefs_->AddDisableReason(
2184 id, Extension::DISABLE_UNSUPPORTED_REQUIREMENT);
2185 // If the extension was disabled because of unsupported requirements but
2186 // now supports all requirements after an update and there are not other
2187 // disable reasons, enable it.
2188 } else if (extension_prefs_->GetDisableReasons(id) ==
2189 Extension::DISABLE_UNSUPPORTED_REQUIREMENT) {
2190 initial_enable = true;
2191 extension_prefs_->ClearDisableReasons(id);
2192 }
2193
[email protected]31bb5ee62012-09-12 22:58:402194 int include_mask = INCLUDE_ENABLED | INCLUDE_DISABLED;
[email protected]07533022011-06-27 20:42:552195 // Do not record the install histograms for upgrades.
[email protected]81f0d162012-08-15 04:21:472196 if (!GetExtensionByIdInternal(extension->id(), include_mask)) {
[email protected]07533022011-06-27 20:42:552197 UMA_HISTOGRAM_ENUMERATION("Extensions.InstallType",
2198 extension->GetType(), 100);
2199 RecordPermissionMessagesHistogram(
2200 extension, "Extensions.Permissions_Install");
2201 }
2202
[email protected]a39921b42012-02-28 03:42:542203 // Certain extension locations are specific enough that we can
2204 // auto-acknowledge any extension that came from one of them.
[email protected]31bb5ee62012-09-12 22:58:402205 if (extension->location() == Extension::EXTERNAL_POLICY_DOWNLOAD)
[email protected]a39921b42012-02-28 03:42:542206 AcknowledgeExternalExtension(extension->id());
[email protected]a39921b42012-02-28 03:42:542207
[email protected]4416c5a2010-06-26 01:28:572208 extension_prefs_->OnExtensionInstalled(
[email protected]8266d662011-07-12 21:53:262209 extension,
2210 initial_enable ? Extension::ENABLED : Extension::DISABLED,
[email protected]cc829cf2011-08-22 21:01:352211 from_webstore,
[email protected]36a5c4c2011-12-14 16:34:502212 page_ordinal);
[email protected]25b34332009-06-05 21:53:192213
[email protected]cdfca9702011-08-08 16:07:012214 // Unpacked extensions default to allowing file access, but if that has been
2215 // overridden, don't reset the value.
[email protected]b6e64fd2011-08-09 19:49:192216 if (Extension::ShouldAlwaysAllowFileAccess(extension->location()) &&
[email protected]cdfca9702011-08-08 16:07:012217 !extension_prefs_->HasAllowFileAccessSetting(id)) {
2218 extension_prefs_->SetAllowFileAccess(id, true);
2219 }
2220
[email protected]fcb58a862012-05-01 01:03:152221 content::NotificationService::current()->Notify(
2222 chrome::NOTIFICATION_EXTENSION_INSTALLED,
2223 content::Source<Profile>(profile_),
2224 content::Details<const Extension>(extension));
2225
[email protected]49cd1572011-02-08 21:38:452226 // Transfer ownership of |extension| to AddExtension.
[email protected]fcb58a862012-05-01 01:03:152227 AddExtension(scoped_extension);
[email protected]4a190632009-05-09 01:07:422228}
2229
[email protected]eaa7dd182010-12-14 11:09:002230const Extension* ExtensionService::GetExtensionByIdInternal(
[email protected]81f0d162012-08-15 04:21:472231 const std::string& id, int include_mask) const {
[email protected]e957fe52009-06-23 16:51:052232 std::string lowercase_id = StringToLowerASCII(id);
[email protected]81f0d162012-08-15 04:21:472233 if (include_mask & INCLUDE_ENABLED) {
[email protected]84df8332011-12-06 18:22:462234 const Extension* extension = extensions_.GetByID(lowercase_id);
2235 if (extension)
2236 return extension;
[email protected]0c6da502009-08-14 22:32:392237 }
[email protected]81f0d162012-08-15 04:21:472238 if (include_mask & INCLUDE_DISABLED) {
[email protected]84df8332011-12-06 18:22:462239 const Extension* extension = disabled_extensions_.GetByID(lowercase_id);
2240 if (extension)
2241 return extension;
[email protected]ce5c4502009-05-06 16:46:112242 }
[email protected]81f0d162012-08-15 04:21:472243 if (include_mask & INCLUDE_TERMINATED) {
[email protected]84df8332011-12-06 18:22:462244 const Extension* extension = terminated_extensions_.GetByID(lowercase_id);
2245 if (extension)
2246 return extension;
[email protected]8001df22011-04-28 19:59:472247 }
[email protected]ce5c4502009-05-06 16:46:112248 return NULL;
2249}
2250
[email protected]bb7f40952011-01-13 00:21:202251void ExtensionService::TrackTerminatedExtension(const Extension* extension) {
[email protected]84df8332011-12-06 18:22:462252 if (!terminated_extensions_.Contains(extension->id()))
2253 terminated_extensions_.Insert(make_scoped_refptr(extension));
[email protected]fa2416f2011-05-03 08:41:202254
[email protected]b3f7fe22011-11-11 19:27:562255 UnloadExtension(extension->id(), extension_misc::UNLOAD_REASON_TERMINATE);
[email protected]bb7f40952011-01-13 00:21:202256}
2257
2258void ExtensionService::UntrackTerminatedExtension(const std::string& id) {
[email protected]fa2416f2011-05-03 08:41:202259 std::string lowercase_id = StringToLowerASCII(id);
[email protected]84df8332011-12-06 18:22:462260 terminated_extensions_.Remove(lowercase_id);
[email protected]bb7f40952011-01-13 00:21:202261}
2262
[email protected]0dfe05c2011-02-23 23:03:362263const Extension* ExtensionService::GetTerminatedExtension(
[email protected]8001df22011-04-28 19:59:472264 const std::string& id) const {
[email protected]81f0d162012-08-15 04:21:472265 return GetExtensionByIdInternal(id, INCLUDE_TERMINATED);
[email protected]8001df22011-04-28 19:59:472266}
2267
2268const Extension* ExtensionService::GetInstalledExtension(
2269 const std::string& id) const {
[email protected]31bb5ee62012-09-12 22:58:402270 int include_mask = INCLUDE_ENABLED | INCLUDE_DISABLED | INCLUDE_TERMINATED;
[email protected]81f0d162012-08-15 04:21:472271 return GetExtensionByIdInternal(id, include_mask);
[email protected]0dfe05c2011-02-23 23:03:362272}
2273
[email protected]eaa7dd182010-12-14 11:09:002274bool ExtensionService::ExtensionBindingsAllowed(const GURL& url) {
[email protected]615d88f2011-12-13 01:47:442275 // Allow bindings for all packaged extensions and component hosted apps.
2276 const Extension* extension = extensions_.GetExtensionOrAppByURL(
2277 ExtensionURLInfo(url));
2278 return extension && (!extension->is_hosted_app() ||
2279 extension->location() == Extension::COMPONENT);
[email protected]6d2e60bd2010-06-03 22:37:392280}
2281
[email protected]e8476c992012-08-20 20:27:592282gfx::Image ExtensionService::GetOmniboxIcon(
[email protected]b671760b2010-07-15 21:13:472283 const std::string& extension_id) {
[email protected]e8476c992012-08-20 20:27:592284 return gfx::Image(omnibox_icon_manager_.GetIcon(extension_id));
[email protected]b671760b2010-07-15 21:13:472285}
2286
[email protected]e8476c992012-08-20 20:27:592287gfx::Image ExtensionService::GetOmniboxPopupIcon(
[email protected]29d0d4ac2010-09-08 21:10:312288 const std::string& extension_id) {
[email protected]e8476c992012-08-20 20:27:592289 return gfx::Image(omnibox_popup_icon_manager_.GetIcon(extension_id));
[email protected]29d0d4ac2010-09-08 21:10:312290}
2291
[email protected]9060d8b02012-01-13 02:14:302292bool ExtensionService::OnExternalExtensionFileFound(
[email protected]8ef78fd2010-08-19 17:14:322293 const std::string& id,
[email protected]8e4560b62011-01-14 10:09:142294 const Version* version,
[email protected]8ef78fd2010-08-19 17:14:322295 const FilePath& path,
[email protected]1bf73cc32011-10-26 22:38:312296 Extension::Location location,
[email protected]47fc70c2011-12-06 07:29:512297 int creation_flags,
2298 bool mark_acknowledged) {
[email protected]ab22ba42011-01-14 16:36:382299 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
2300 CHECK(Extension::IdIsValid(id));
[email protected]79c833b52011-04-05 18:31:012301 if (extension_prefs_->IsExternalExtensionUninstalled(id))
[email protected]9060d8b02012-01-13 02:14:302302 return false;
[email protected]a8af9fdb2010-10-28 21:52:202303
[email protected]7577a5c52009-07-30 06:21:582304 // Before even bothering to unpack, check and see if we already have this
[email protected]4c967932009-07-31 01:15:492305 // version. This is important because these extensions are going to get
[email protected]7577a5c52009-07-30 06:21:582306 // installed on every startup.
[email protected]9adb9692010-10-29 23:14:022307 const Extension* existing = GetExtensionById(id, true);
[email protected]910f72ce2012-08-24 01:38:352308
[email protected]7577a5c52009-07-30 06:21:582309 if (existing) {
[email protected]910f72ce2012-08-24 01:38:352310 // The default apps will have the location set as INTERNAL. Since older
2311 // default apps are installed as EXTERNAL, we override them. However, if the
2312 // app is already installed as internal, then do the version check.
[email protected]31bb5ee62012-09-12 22:58:402313 // TODO(grv) : Remove after Q1-2013.
[email protected]910f72ce2012-08-24 01:38:352314 bool is_default_apps_migration =
2315 (location == Extension::INTERNAL &&
2316 Extension::IsExternalLocation(existing->location()));
2317
2318 if (!is_default_apps_migration) {
2319 DCHECK(version);
2320
2321 switch (existing->version()->CompareTo(*version)) {
2322 case -1: // existing version is older, we should upgrade
2323 break;
2324 case 0: // existing version is same, do nothing
2325 return false;
2326 case 1: // existing version is newer, uh-oh
2327 LOG(WARNING) << "Found external version of extension " << id
2328 << "that is older than current version. Current version "
2329 << "is: " << existing->VersionString() << ". New "
2330 << "version is: " << version->GetString()
2331 << ". Keeping current version.";
2332 return false;
2333 }
[email protected]7577a5c52009-07-30 06:21:582334 }
2335 }
2336
[email protected]9060d8b02012-01-13 02:14:302337 // If the extension is already pending, don't start an install.
[email protected]e3987852012-05-04 10:06:302338 if (!pending_extension_manager()->AddFromExternalFile(
2339 id, location, *version)) {
[email protected]9060d8b02012-01-13 02:14:302340 return false;
[email protected]e3987852012-05-04 10:06:302341 }
[email protected]9c635f22010-12-02 09:36:362342
[email protected]14908b72011-04-20 06:54:362343 // no client (silent install)
[email protected]d8c8f25f2011-11-02 18:18:012344 scoped_refptr<CrxInstaller> installer(CrxInstaller::Create(this, NULL));
[email protected]6dfbbf82010-03-12 23:09:162345 installer->set_install_source(location);
2346 installer->set_expected_id(id);
[email protected]cb0e50312011-05-09 15:03:072347 installer->set_expected_version(*version);
2348 installer->set_install_cause(extension_misc::INSTALL_CAUSE_EXTERNAL_FILE);
[email protected]1bf73cc32011-10-26 22:38:312349 installer->set_creation_flags(creation_flags);
[email protected]6dfbbf82010-03-12 23:09:162350 installer->InstallCrx(path);
[email protected]47fc70c2011-12-06 07:29:512351
2352 // Depending on the source, a new external extension might not need a user
2353 // notification on installation. For such extensions, mark them acknowledged
2354 // now to suppress the notification.
2355 if (mark_acknowledged)
2356 AcknowledgeExternalExtension(id);
[email protected]9060d8b02012-01-13 02:14:302357
2358 return true;
[email protected]7577a5c52009-07-30 06:21:582359}
2360
[email protected]eaa7dd182010-12-14 11:09:002361void ExtensionService::ReportExtensionLoadError(
[email protected]d11c8e92009-10-20 23:26:402362 const FilePath& extension_path,
2363 const std::string &error,
[email protected]d11c8e92009-10-20 23:26:402364 bool be_noisy) {
[email protected]d8c8f25f2011-11-02 18:18:012365 content::NotificationService::current()->Notify(
2366 chrome::NOTIFICATION_EXTENSION_LOAD_ERROR,
2367 content::Source<Profile>(profile_),
2368 content::Details<const std::string>(&error));
[email protected]d11c8e92009-10-20 23:26:402369
[email protected]8a205c02011-02-04 20:41:332370 std::string path_str = UTF16ToUTF8(extension_path.LossyDisplayName());
[email protected]438afb12012-07-05 03:18:212371 string16 message = UTF8ToUTF16(base::StringPrintf(
[email protected]18d4b6c2010-09-21 03:21:042372 "Could not load extension from '%s'. %s",
[email protected]fc670822011-12-17 09:33:492373 path_str.c_str(), error.c_str()));
[email protected]d11c8e92009-10-20 23:26:402374 ExtensionErrorReporter::GetInstance()->ReportError(message, be_noisy);
2375}
2376
[email protected]eaa7dd182010-12-14 11:09:002377void ExtensionService::DidCreateRenderViewForBackgroundPage(
[email protected]3a1dc572012-07-31 22:25:132378 extensions::ExtensionHost* host) {
[email protected]406027c02010-09-27 08:03:182379 OrphanedDevTools::iterator iter =
[email protected]2d2f6cfc2011-05-06 21:09:332380 orphaned_dev_tools_.find(host->extension_id());
[email protected]406027c02010-09-27 08:03:182381 if (iter == orphaned_dev_tools_.end())
2382 return;
2383
[email protected]0e12d7d2011-12-01 16:21:442384 DevToolsAgentHost* agent = DevToolsAgentHostRegistry::GetDevToolsAgentHost(
2385 host->render_view_host());
2386 content::DevToolsManager::GetInstance()->AttachClientHost(iter->second,
2387 agent);
[email protected]406027c02010-09-27 08:03:182388 orphaned_dev_tools_.erase(iter);
2389}
2390
[email protected]432115822011-07-10 15:52:272391void ExtensionService::Observe(int type,
[email protected]6c2381d2011-10-19 02:52:532392 const content::NotificationSource& source,
2393 const content::NotificationDetails& details) {
[email protected]432115822011-07-10 15:52:272394 switch (type) {
2395 case chrome::NOTIFICATION_EXTENSION_PROCESS_TERMINATED: {
[email protected]6c2381d2011-10-19 02:52:532396 if (profile_ !=
2397 content::Source<Profile>(source).ptr()->GetOriginalProfile()) {
[email protected]bc535ee52010-08-31 18:40:322398 break;
[email protected]6c2381d2011-10-19 02:52:532399 }
[email protected]a4ed6282009-12-14 20:51:162400
[email protected]3a1dc572012-07-31 22:25:132401 extensions::ExtensionHost* host =
2402 content::Details<extensions::ExtensionHost>(details).ptr();
[email protected]f128af42010-08-05 18:05:262403
[email protected]fa2416f2011-05-03 08:41:202404 // Mark the extension as terminated and Unload it. We want it to
2405 // be in a consistent state: either fully working or not loaded
2406 // at all, but never half-crashed. We do it in a PostTask so
2407 // that other handlers of this notification will still have
2408 // access to the Extension and ExtensionHost.
[email protected]14908b72011-04-20 06:54:362409 MessageLoop::current()->PostTask(
2410 FROM_HERE,
[email protected]53612e82011-10-18 18:00:362411 base::Bind(
[email protected]fa2416f2011-05-03 08:41:202412 &ExtensionService::TrackTerminatedExtension,
[email protected]d8c8f25f2011-11-02 18:18:012413 AsWeakPtr(),
[email protected]fa2416f2011-05-03 08:41:202414 host->extension()));
[email protected]31f77262009-12-02 20:48:532415 break;
2416 }
[email protected]432115822011-07-10 15:52:272417 case content::NOTIFICATION_RENDERER_PROCESS_CREATED: {
[email protected]f3b1a082011-11-18 00:34:302418 content::RenderProcessHost* process =
2419 content::Source<content::RenderProcessHost>(source).ptr();
[email protected]fc30ef082011-08-18 04:07:192420 Profile* host_profile =
[email protected]f3b1a082011-11-18 00:34:302421 Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]fc30ef082011-08-18 04:07:192422 if (!profile_->IsSameProfile(host_profile->GetOriginalProfile()))
2423 break;
2424
[email protected]15397b42012-05-16 23:56:062425 // Extensions need to know the channel for API restrictions.
2426 process->Send(new ExtensionMsg_SetChannel(
[email protected]5243df072012-07-11 21:41:012427 extensions::Feature::GetCurrentChannel()));
[email protected]15397b42012-05-16 23:56:062428
[email protected]77a6970c2011-04-23 16:58:562429 // Valid extension function names, used to setup bindings in renderer.
2430 std::vector<std::string> function_names;
2431 ExtensionFunctionDispatcher::GetAllFunctionNames(&function_names);
2432 process->Send(new ExtensionMsg_SetFunctionNames(function_names));
[email protected]31f77262009-12-02 20:48:532433
[email protected]77a6970c2011-04-23 16:58:562434 // Scripting whitelist. This is modified by tests and must be communicated
2435 // to renderers.
2436 process->Send(new ExtensionMsg_SetScriptingWhitelist(
2437 *Extension::GetScriptingWhitelist()));
2438
2439 // Loaded extensions.
[email protected]9776e82e2011-11-15 02:17:532440 std::vector<ExtensionMsg_Loaded_Params> loaded_extensions;
[email protected]84df8332011-12-06 18:22:462441 for (ExtensionSet::const_iterator iter = extensions_.begin();
2442 iter != extensions_.end(); ++iter) {
[email protected]19647262011-12-16 09:57:492443 // Renderers don't need to know about themes.
2444 if (!(*iter)->is_theme())
2445 loaded_extensions.push_back(ExtensionMsg_Loaded_Params(*iter));
[email protected]77a6970c2011-04-23 16:58:562446 }
[email protected]9776e82e2011-11-15 02:17:532447 process->Send(new ExtensionMsg_Loaded(loaded_extensions));
[email protected]77a6970c2011-04-23 16:58:562448 break;
2449 }
[email protected]432115822011-07-10 15:52:272450 case content::NOTIFICATION_RENDERER_PROCESS_TERMINATED: {
[email protected]f3b1a082011-11-18 00:34:302451 content::RenderProcessHost* process =
2452 content::Source<content::RenderProcessHost>(source).ptr();
[email protected]fc30ef082011-08-18 04:07:192453 Profile* host_profile =
[email protected]f3b1a082011-11-18 00:34:302454 Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]fc30ef082011-08-18 04:07:192455 if (!profile_->IsSameProfile(host_profile->GetOriginalProfile()))
2456 break;
2457
[email protected]f3b1a082011-11-18 00:34:302458 installed_app_hosts_.erase(process->GetID());
[email protected]6f371442011-11-09 06:45:462459
[email protected]6bc04fd82011-12-04 02:29:352460 process_map_.RemoveAllFromProcess(process->GetID());
[email protected]6f371442011-11-09 06:45:462461 BrowserThread::PostTask(
2462 BrowserThread::IO, FROM_HERE,
2463 base::Bind(&ExtensionInfoMap::UnregisterAllExtensionsInProcess,
[email protected]31d8f5f22012-04-02 15:22:082464 system_->info_map(),
[email protected]f3b1a082011-11-18 00:34:302465 process->GetID()));
[email protected]da5683db2011-04-23 17:12:212466 break;
2467 }
[email protected]432115822011-07-10 15:52:272468 case chrome::NOTIFICATION_PREF_CHANGED: {
[email protected]6c2381d2011-10-19 02:52:532469 std::string* pref_name = content::Details<std::string>(details).ptr();
[email protected]6c751e72010-11-23 10:11:102470 if (*pref_name == prefs::kExtensionInstallAllowList ||
2471 *pref_name == prefs::kExtensionInstallDenyList) {
[email protected]4ee07c62012-08-21 12:40:422472 IdentifyAlertableExtensions();
2473 CheckManagementPolicy();
[email protected]6c751e72010-11-23 10:11:102474 } else {
2475 NOTREACHED() << "Unexpected preference name.";
2476 }
[email protected]aa96d3a2010-08-21 08:45:252477 break;
2478 }
[email protected]d91268022011-08-26 13:17:372479 case chrome::NOTIFICATION_IMPORT_FINISHED: {
[email protected]cf593af2011-12-30 05:44:392480 InitAfterImport();
[email protected]d91268022011-08-26 13:17:372481 break;
2482 }
[email protected]aa96d3a2010-08-21 08:45:252483
[email protected]4814b512009-11-07 00:12:292484 default:
2485 NOTREACHED() << "Unexpected notification type.";
2486 }
2487}
2488
[email protected]eaa7dd182010-12-14 11:09:002489bool ExtensionService::HasApps() const {
[email protected]ec5b50d2010-10-09 16:35:182490 return !GetAppIds().empty();
2491}
[email protected]377011d2010-07-20 04:18:502492
[email protected]eaa7dd182010-12-14 11:09:002493ExtensionIdSet ExtensionService::GetAppIds() const {
[email protected]ec5b50d2010-10-09 16:35:182494 ExtensionIdSet result;
[email protected]84df8332011-12-06 18:22:462495 for (ExtensionSet::const_iterator it = extensions_.begin();
[email protected]377011d2010-07-20 04:18:502496 it != extensions_.end(); ++it) {
[email protected]ec5b50d2010-10-09 16:35:182497 if ((*it)->is_app() && (*it)->location() != Extension::COMPONENT)
2498 result.insert((*it)->id());
[email protected]377011d2010-07-20 04:18:502499 }
2500
[email protected]ec5b50d2010-10-09 16:35:182501 return result;
[email protected]377011d2010-07-20 04:18:502502}
[email protected]d7e9a862010-11-03 21:57:492503
[email protected]dc9a74f72012-08-17 18:07:212504bool ExtensionService::IsBackgroundPageReady(const Extension* extension) const {
2505 if (!extension->has_persistent_background_page())
2506 return true;
2507 ExtensionRuntimeDataMap::const_iterator it =
2508 extension_runtime_data_.find(extension->id());
2509 return it == extension_runtime_data_.end() ? false :
2510 it->second.background_page_ready;
[email protected]d7e9a862010-11-03 21:57:492511}
2512
[email protected]eaa7dd182010-12-14 11:09:002513void ExtensionService::SetBackgroundPageReady(const Extension* extension) {
[email protected]a03d4448f2012-01-10 23:25:282514 DCHECK(extension->has_background_page());
[email protected]d7e9a862010-11-03 21:57:492515 extension_runtime_data_[extension->id()].background_page_ready = true;
[email protected]ad50def52011-10-19 23:17:072516 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:272517 chrome::NOTIFICATION_EXTENSION_BACKGROUND_PAGE_READY,
[email protected]6c2381d2011-10-19 02:52:532518 content::Source<const Extension>(extension),
[email protected]ad50def52011-10-19 23:17:072519 content::NotificationService::NoDetails());
[email protected]d7e9a862010-11-03 21:57:492520}
2521
[email protected]dc9a74f72012-08-17 18:07:212522bool ExtensionService::IsBeingUpgraded(const Extension* extension) const {
2523 ExtensionRuntimeDataMap::const_iterator it =
2524 extension_runtime_data_.find(extension->id());
2525 return it == extension_runtime_data_.end() ? false :
2526 it->second.being_upgraded;
[email protected]d7e9a862010-11-03 21:57:492527}
2528
[email protected]eaa7dd182010-12-14 11:09:002529void ExtensionService::SetBeingUpgraded(const Extension* extension,
[email protected]d7e9a862010-11-03 21:57:492530 bool value) {
2531 extension_runtime_data_[extension->id()].being_upgraded = value;
2532}
[email protected]1bead0712010-11-27 17:41:532533
[email protected]dc9a74f72012-08-17 18:07:212534bool ExtensionService::HasUsedWebRequest(const Extension* extension) const {
2535 ExtensionRuntimeDataMap::const_iterator it =
2536 extension_runtime_data_.find(extension->id());
2537 return it == extension_runtime_data_.end() ? false :
2538 it->second.has_used_webrequest;
[email protected]39a5b532011-10-22 01:47:072539}
2540
2541void ExtensionService::SetHasUsedWebRequest(const Extension* extension,
2542 bool value) {
2543 extension_runtime_data_[extension->id()].has_used_webrequest = value;
2544}
2545
[email protected]cebc3dc2011-04-18 17:15:002546void ExtensionService::RegisterNaClModule(const GURL& url,
2547 const std::string& mime_type) {
2548 NaClModuleInfo info;
2549 info.url = url;
2550 info.mime_type = mime_type;
2551
2552 DCHECK(FindNaClModule(url) == nacl_module_list_.end());
2553 nacl_module_list_.push_front(info);
2554}
2555
2556void ExtensionService::UnregisterNaClModule(const GURL& url) {
2557 NaClModuleInfoList::iterator iter = FindNaClModule(url);
2558 DCHECK(iter != nacl_module_list_.end());
2559 nacl_module_list_.erase(iter);
2560}
2561
[email protected]ed0ba002011-05-26 16:55:132562void ExtensionService::UpdatePluginListWithNaClModules() {
[email protected]300c0ea2011-07-15 23:04:332563 // An extension has been added which has a nacl_module component, which means
2564 // there is a MIME type that module wants to handle, so we need to add that
2565 // MIME type to plugins which handle NaCl modules in order to allow the
2566 // individual modules to handle these types.
[email protected]1e127022011-11-29 21:11:472567 FilePath path;
2568 if (!PathService::Get(chrome::FILE_NACL_PLUGIN, &path))
2569 return;
2570 const content::PepperPluginInfo* pepper_info =
2571 PluginService::GetInstance()->GetRegisteredPpapiPluginInfo(path);
2572 if (!pepper_info)
2573 return;
[email protected]300c0ea2011-07-15 23:04:332574
[email protected]1e127022011-11-29 21:11:472575 std::vector<webkit::WebPluginMimeType>::const_iterator mime_iter;
2576 // Check each MIME type the plugins handle for the NaCl MIME type.
2577 for (mime_iter = pepper_info->mime_types.begin();
2578 mime_iter != pepper_info->mime_types.end(); ++mime_iter) {
2579 if (mime_iter->mime_type == kNaClPluginMimeType) {
2580 // This plugin handles "application/x-nacl".
[email protected]300c0ea2011-07-15 23:04:332581
[email protected]1e127022011-11-29 21:11:472582 PluginService::GetInstance()->
2583 UnregisterInternalPlugin(pepper_info->path);
[email protected]300c0ea2011-07-15 23:04:332584
[email protected]1e127022011-11-29 21:11:472585 webkit::WebPluginInfo info = pepper_info->ToWebPluginInfo();
[email protected]300c0ea2011-07-15 23:04:332586
[email protected]1e127022011-11-29 21:11:472587 for (ExtensionService::NaClModuleInfoList::const_iterator iter =
2588 nacl_module_list_.begin();
2589 iter != nacl_module_list_.end(); ++iter) {
2590 // Add the MIME type specified in the extension to this NaCl plugin,
2591 // With an extra "nacl" argument to specify the location of the NaCl
2592 // manifest file.
2593 webkit::WebPluginMimeType mime_type_info;
2594 mime_type_info.mime_type = iter->mime_type;
2595 mime_type_info.additional_param_names.push_back(UTF8ToUTF16("nacl"));
2596 mime_type_info.additional_param_values.push_back(
2597 UTF8ToUTF16(iter->url.spec()));
2598 info.mime_types.push_back(mime_type_info);
[email protected]300c0ea2011-07-15 23:04:332599 }
[email protected]1e127022011-11-29 21:11:472600
2601 PluginService::GetInstance()->RefreshPlugins();
[email protected]c6f3dea2012-01-14 02:23:112602 PluginService::GetInstance()->RegisterInternalPlugin(info, true);
[email protected]1e127022011-11-29 21:11:472603 // This plugin has been modified, no need to check the rest of its
2604 // types, but continue checking other plugins.
2605 break;
[email protected]ed0ba002011-05-26 16:55:132606 }
2607 }
[email protected]ed0ba002011-05-26 16:55:132608}
2609
[email protected]cebc3dc2011-04-18 17:15:002610ExtensionService::NaClModuleInfoList::iterator
2611 ExtensionService::FindNaClModule(const GURL& url) {
2612 for (NaClModuleInfoList::iterator iter = nacl_module_list_.begin();
2613 iter != nacl_module_list_.end(); ++iter) {
2614 if (iter->url == url)
2615 return iter;
2616 }
2617 return nacl_module_list_.end();
2618}
[email protected]6cafe35a2012-08-27 22:40:502619
2620void ExtensionService::QueueRestoreAppWindow(const Extension* extension) {
2621 std::set<std::string>::iterator relaunch_iter =
2622 relaunch_app_ids_.find(extension->id());
2623 if (relaunch_iter != relaunch_app_ids_.end()) {
2624 extensions::LazyBackgroundTaskQueue* queue =
2625 system_->lazy_background_task_queue();
2626 if (queue->ShouldEnqueueTask(profile(), extension)) {
2627 queue->AddPendingTask(profile(), extension->id(),
2628 base::Bind(&ExtensionService::LaunchApplication));
2629 }
2630
2631 relaunch_app_ids_.erase(relaunch_iter);
2632 }
2633}
2634
2635// static
2636void ExtensionService::LaunchApplication(
2637 extensions::ExtensionHost* extension_host) {
2638 if (!extension_host)
2639 return;
2640
2641#if !defined(OS_ANDROID)
2642 extensions::LaunchPlatformApp(extension_host->profile(),
2643 extension_host->extension(),
2644 NULL, FilePath());
2645#endif
2646}