blob: 82c2e0a112a6c78586944576b93340f5ecaed574 [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]5ebd6a62012-08-01 23:54:3939#include "chrome/browser/extensions/api/push_messaging/push_messaging_api.h"
[email protected]895a1e52012-05-15 02:50:1240#include "chrome/browser/extensions/api/web_navigation/web_navigation_api.h"
[email protected]af9db5f2011-10-05 05:13:1541#include "chrome/browser/extensions/app_notification_manager.h"
[email protected]5db9ada2012-04-11 13:48:2042#include "chrome/browser/extensions/app_sync_data.h"
[email protected]5a38dfd2012-07-23 23:22:1043#include "chrome/browser/extensions/browser_event_router.h"
[email protected]d8c8f25f2011-11-02 18:18:0144#include "chrome/browser/extensions/component_loader.h"
[email protected]e0785902011-05-19 23:34:1745#include "chrome/browser/extensions/crx_installer.h"
[email protected]d9ede582012-08-14 19:21:3846#include "chrome/browser/extensions/data_deleter.h"
[email protected]49098f702011-10-13 03:47:1847#include "chrome/browser/extensions/default_apps_trial.h"
[email protected]62f051c2012-03-29 17:04:4448#include "chrome/browser/extensions/extension_disabled_ui.h"
[email protected]14a000d2010-04-29 21:44:2449#include "chrome/browser/extensions/extension_error_reporter.h"
[email protected]89226982012-07-16 20:09:1850#include "chrome/browser/extensions/extension_error_ui.h"
[email protected]b1748b1d82009-11-30 20:32:5651#include "chrome/browser/extensions/extension_host.h"
[email protected]00b38242012-07-18 18:43:2252#include "chrome/browser/extensions/extension_install_ui.h"
[email protected]118de7892011-03-16 13:31:4053#include "chrome/browser/extensions/extension_preference_api.h"
[email protected]4814b512009-11-07 00:12:2954#include "chrome/browser/extensions/extension_process_manager.h"
[email protected]8a661f82010-10-19 21:47:1155#include "chrome/browser/extensions/extension_processes_api.h"
[email protected]3569b502012-01-12 20:08:2356#include "chrome/browser/extensions/extension_sorting.h"
[email protected]19eb80152011-02-26 00:28:4357#include "chrome/browser/extensions/extension_special_storage_policy.h"
[email protected]90310d92011-04-17 07:35:0458#include "chrome/browser/extensions/extension_sync_data.h"
[email protected]31d8f5f22012-04-02 15:22:0859#include "chrome/browser/extensions/extension_system.h"
[email protected]8f9d4eb2011-02-05 01:39:1060#include "chrome/browser/extensions/extension_web_ui.h"
[email protected]5df038b2012-07-16 19:03:2761#include "chrome/browser/extensions/external_provider_impl.h"
62#include "chrome/browser/extensions/external_provider_interface.h"
[email protected]d8c8f25f2011-11-02 18:18:0163#include "chrome/browser/extensions/installed_loader.h"
[email protected]6cafe35a2012-08-27 22:40:5064#include "chrome/browser/extensions/lazy_background_task_queue.h"
[email protected]b2907fd2011-03-25 16:43:3765#include "chrome/browser/extensions/pending_extension_manager.h"
[email protected]c333e792012-01-06 16:57:3966#include "chrome/browser/extensions/permissions_updater.h"
[email protected]6cafe35a2012-08-27 22:40:5067#include "chrome/browser/extensions/platform_app_launcher.h"
[email protected]cccdf0aa2011-11-11 03:43:3868#include "chrome/browser/extensions/settings/settings_frontend.h"
[email protected]6cafe35a2012-08-27 22:40:5069#include "chrome/browser/extensions/shell_window_registry.h"
[email protected]d8c8f25f2011-11-02 18:18:0170#include "chrome/browser/extensions/unpacked_installer.h"
[email protected]42a08162012-03-16 18:09:1171#include "chrome/browser/extensions/updater/extension_updater.h"
[email protected]163ed192012-07-24 19:31:0772#include "chrome/browser/extensions/window_event_router.h"
[email protected]d2e6bd62011-10-24 20:29:0773#include "chrome/browser/history/history_extension_api.h"
[email protected]56ad3792010-05-28 17:45:3374#include "chrome/browser/net/chrome_url_request_context.h"
[email protected]37858e52010-08-26 00:22:0275#include "chrome/browser/prefs/pref_service.h"
[email protected]8ecad5e2010-12-02 21:18:3376#include "chrome/browser/profiles/profile.h"
[email protected]cf593af2011-12-30 05:44:3977#include "chrome/browser/profiles/profile_manager.h"
[email protected]8e5c89a2011-06-07 18:13:3378#include "chrome/browser/search_engines/template_url_service.h"
79#include "chrome/browser/search_engines/template_url_service_factory.h"
[email protected]18280372011-03-22 18:05:2280#include "chrome/browser/themes/theme_service.h"
[email protected]a0ea76c2011-03-23 17:36:4281#include "chrome/browser/themes/theme_service_factory.h"
[email protected]c8d407e2011-04-28 21:27:1782#include "chrome/browser/ui/webui/chrome_url_data_manager.h"
83#include "chrome/browser/ui/webui/favicon_source.h"
[email protected]5eddc3e2011-10-26 04:33:3184#include "chrome/browser/ui/webui/ntp/thumbnail_source.h"
[email protected]aab98a52009-12-02 03:22:3585#include "chrome/common/child_process_logging.h"
[email protected]432115822011-07-10 15:52:2786#include "chrome/common/chrome_notification_types.h"
[email protected]1e127022011-11-29 21:11:4787#include "chrome/common/chrome_paths.h"
[email protected]e2eb43112009-05-29 21:19:5488#include "chrome/common/chrome_switches.h"
[email protected]15397b42012-05-16 23:56:0689#include "chrome/common/chrome_version_info.h"
[email protected]5b1a0e22009-05-26 19:00:5890#include "chrome/common/extensions/extension.h"
[email protected]05c82182010-06-24 17:49:0891#include "chrome/common/extensions/extension_error_utils.h"
[email protected]7c927b62010-02-24 09:54:1392#include "chrome/common/extensions/extension_file_util.h"
[email protected]895a1e52012-05-15 02:50:1293#include "chrome/common/extensions/extension_manifest_constants.h"
[email protected]77a6970c2011-04-23 16:58:5694#include "chrome/common/extensions/extension_messages.h"
[email protected]a315ba92010-11-16 14:12:2195#include "chrome/common/extensions/extension_resource.h"
[email protected]5243df072012-07-11 21:41:0196#include "chrome/common/extensions/features/feature.h"
[email protected]25b34332009-06-05 21:53:1997#include "chrome/common/pref_names.h"
[email protected]a57209872009-05-04 22:53:1498#include "chrome/common/url_constants.h"
[email protected]c38831a12011-10-28 12:44:4999#include "content/public/browser/browser_thread.h"
[email protected]0e12d7d2011-12-01 16:21:44100#include "content/public/browser/devtools_agent_host_registry.h"
101#include "content/public/browser/devtools_manager.h"
[email protected]05aad2da2011-10-28 10:12:37102#include "content/public/browser/notification_service.h"
[email protected]0d6e9bd2011-10-18 04:29:16103#include "content/public/browser/notification_types.h"
[email protected]3a5180ae2011-12-21 02:39:38104#include "content/public/browser/plugin_service.h"
[email protected]f3b1a082011-11-18 00:34:30105#include "content/public/browser/render_process_host.h"
[email protected]1e127022011-11-29 21:11:47106#include "content/public/common/pepper_plugin_info.h"
[email protected]c10da4b02010-03-25 14:38:32107#include "googleurl/src/gurl.h"
[email protected]65187152012-06-02 13:14:14108#include "grit/generated_resources.h"
[email protected]be28b5f42012-07-20 11:31:25109#include "net/base/registry_controlled_domains/registry_controlled_domain.h"
[email protected]895a1e52012-05-15 02:50:12110#include "sync/api/sync_change.h"
111#include "sync/api/sync_error_factory.h"
[email protected]24b538a2010-02-27 01:22:44112#include "webkit/database/database_tracker.h"
113#include "webkit/database/database_util.h"
[email protected]eed367e2011-04-12 03:43:31114#if defined(OS_CHROMEOS)
[email protected]14da67b02011-08-02 05:49:13115#include "chrome/browser/chromeos/cros/cros_library.h"
[email protected]f463bc92012-03-22 16:38:23116#include "chrome/browser/chromeos/extensions/bluetooth_event_router.h"
[email protected]eed367e2011-04-12 03:43:31117#include "chrome/browser/chromeos/extensions/file_browser_event_router.h"
[email protected]be5bd5742011-07-14 07:21:01118#include "chrome/browser/chromeos/extensions/input_method_event_router.h"
[email protected]ce9802042011-05-27 10:11:40119#include "chrome/browser/chromeos/extensions/media_player_event_router.h"
[email protected]14da67b02011-08-02 05:49:13120#include "chrome/browser/chromeos/input_method/input_method_manager.h"
[email protected]1364c6d2012-07-24 11:57:19121#include "chrome/browser/extensions/api/input_ime/input_ime_api.h"
[email protected]b777b332011-04-16 04:01:08122#include "webkit/fileapi/file_system_context.h"
123#include "webkit/fileapi/file_system_mount_point_provider.h"
[email protected]eed367e2011-04-12 03:43:31124#endif
125
[email protected]55eb70e762012-02-20 17:38:39126using content::BrowserContext;
[email protected]631bb742011-11-02 11:29:39127using content::BrowserThread;
[email protected]0e12d7d2011-12-01 16:21:44128using content::DevToolsAgentHost;
129using content::DevToolsAgentHostRegistry;
[email protected]3a5180ae2011-12-21 02:39:38130using content::PluginService;
[email protected]bf3d9df2012-07-24 23:20:27131using extensions::CrxInstaller;
[email protected]1c321ee52012-05-21 03:02:34132using extensions::Extension;
133using extensions::ExtensionIdSet;
134using extensions::ExtensionInfo;
135using extensions::UnloadedExtensionInfo;
[email protected]c2e66e12012-06-27 06:27:06136using extensions::PermissionMessage;
137using extensions::PermissionMessages;
138using extensions::PermissionSet;
[email protected]5ef47ec2010-01-28 05:58:05139
[email protected]c6d474f82009-12-16 21:11:06140namespace errors = extension_manifest_errors;
141
[email protected]b6ab96d2009-08-20 18:58:19142namespace {
143
[email protected]29d0d4ac2010-09-08 21:10:31144#if defined(OS_LINUX)
145static const int kOmniboxIconPaddingLeft = 2;
146static const int kOmniboxIconPaddingRight = 2;
147#elif defined(OS_MACOSX)
148static const int kOmniboxIconPaddingLeft = 0;
149static const int kOmniboxIconPaddingRight = 2;
150#else
151static const int kOmniboxIconPaddingLeft = 0;
152static const int kOmniboxIconPaddingRight = 0;
153#endif
154
[email protected]300c0ea2011-07-15 23:04:33155const char* kNaClPluginMimeType = "application/x-nacl";
156
[email protected]3bdba0d2011-08-23 07:17:30157static bool IsSyncableExtension(const Extension& extension) {
158 return extension.GetSyncType() == Extension::SYNC_TYPE_EXTENSION;
159}
160
161static bool IsSyncableApp(const Extension& extension) {
162 return extension.GetSyncType() == Extension::SYNC_TYPE_APP;
163}
164
[email protected]c6d474f82009-12-16 21:11:06165} // namespace
[email protected]b6ab96d2009-08-20 18:58:19166
[email protected]eaa7dd182010-12-14 11:09:00167ExtensionService::ExtensionRuntimeData::ExtensionRuntimeData()
[email protected]d7e9a862010-11-03 21:57:49168 : background_page_ready(false),
[email protected]f8bf5992011-10-24 22:38:57169 being_upgraded(false),
170 has_used_webrequest(false) {
[email protected]d7e9a862010-11-03 21:57:49171}
172
[email protected]eaa7dd182010-12-14 11:09:00173ExtensionService::ExtensionRuntimeData::~ExtensionRuntimeData() {
[email protected]d7e9a862010-11-03 21:57:49174}
175
[email protected]cebc3dc2011-04-18 17:15:00176ExtensionService::NaClModuleInfo::NaClModuleInfo() {
177}
178
179ExtensionService::NaClModuleInfo::~NaClModuleInfo() {
180}
181
[email protected]eaa7dd182010-12-14 11:09:00182// ExtensionService.
[email protected]6014d672008-12-05 00:38:25183
[email protected]eaa7dd182010-12-14 11:09:00184const char* ExtensionService::kInstallDirectoryName = "Extensions";
[email protected]15d5b472011-11-24 04:17:24185
186const char* ExtensionService::kLocalAppSettingsDirectoryName =
187 "Local App Settings";
188const char* ExtensionService::kLocalExtensionSettingsDirectoryName =
189 "Local Extension Settings";
190const char* ExtensionService::kSyncAppSettingsDirectoryName =
191 "Sync App Settings";
192const char* ExtensionService::kSyncExtensionSettingsDirectoryName =
193 "Sync Extension Settings";
[email protected]90e800c2012-06-12 23:11:00194const char* ExtensionService::kStateStoreName = "Extension State";
[email protected]494c06e2009-07-25 01:06:42195
[email protected]8e4560b62011-01-14 10:09:14196void ExtensionService::CheckExternalUninstall(const std::string& id) {
[email protected]a29a517a2011-01-21 21:11:12197 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]a8af9fdb2010-10-28 21:52:20198
[email protected]7a4c6852010-09-16 03:44:22199 // Check if the providers know about this extension.
[email protected]5df038b2012-07-16 19:03:27200 extensions::ProviderCollection::const_iterator i;
[email protected]0a60a2e2010-10-25 16:15:21201 for (i = external_extension_providers_.begin();
202 i != external_extension_providers_.end(); ++i) {
[email protected]8e4560b62011-01-14 10:09:14203 DCHECK(i->get()->IsReady());
[email protected]0a60a2e2010-10-25 16:15:21204 if (i->get()->HasExtension(id))
205 return; // Yup, known extension, don't uninstall.
[email protected]7a4c6852010-09-16 03:44:22206 }
207
[email protected]0f48fca2011-05-19 18:46:35208 // We get the list of external extensions to check from preferences.
209 // It is possible that an extension has preferences but is not loaded.
210 // For example, an extension that requires experimental permissions
211 // will not be loaded if the experimental command line flag is not used.
212 // In this case, do not uninstall.
213 const Extension* extension = GetInstalledExtension(id);
214 if (!extension) {
215 // We can't call UninstallExtension with an unloaded/invalid
216 // extension ID.
217 LOG(WARNING) << "Attempted uninstallation of unloaded/invalid extension "
218 << "with id: " << id;
219 return;
220 }
[email protected]d6ebc9792011-04-07 18:18:33221 UninstallExtension(id, true, NULL);
[email protected]7a4c6852010-09-16 03:44:22222}
223
[email protected]8e4560b62011-01-14 10:09:14224void ExtensionService::ClearProvidersForTesting() {
[email protected]7a4c6852010-09-16 03:44:22225 external_extension_providers_.clear();
226}
227
[email protected]8e4560b62011-01-14 10:09:14228void ExtensionService::AddProviderForTesting(
[email protected]5df038b2012-07-16 19:03:27229 extensions::ExternalProviderInterface* test_provider) {
[email protected]a29a517a2011-01-21 21:11:12230 CHECK(test_provider);
[email protected]0a60a2e2010-10-25 16:15:21231 external_extension_providers_.push_back(
[email protected]5df038b2012-07-16 19:03:27232 linked_ptr<extensions::ExternalProviderInterface>(test_provider));
[email protected]7a4c6852010-09-16 03:44:22233}
234
[email protected]9060d8b02012-01-13 02:14:30235bool ExtensionService::OnExternalExtensionUpdateUrlFound(
[email protected]7a4c6852010-09-16 03:44:22236 const std::string& id,
[email protected]21a5a672010-11-04 10:47:42237 const GURL& update_url,
238 Extension::Location location) {
[email protected]ab22ba42011-01-14 16:36:38239 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
240 CHECK(Extension::IdIsValid(id));
[email protected]a8af9fdb2010-10-28 21:52:20241
[email protected]8a87a5332011-08-11 17:54:59242 const Extension* extension = GetExtensionById(id, true);
243 if (extension) {
244 // Already installed. Skip this install if the current location has
245 // higher priority than |location|.
246 Extension::Location current = extension->location();
247 if (current == Extension::GetHigherPriorityLocation(current, location))
[email protected]9060d8b02012-01-13 02:14:30248 return false;
[email protected]8a87a5332011-08-11 17:54:59249 // Otherwise, overwrite the current installation.
[email protected]7a4c6852010-09-16 03:44:22250 }
[email protected]9060d8b02012-01-13 02:14:30251
252 // Add |id| to the set of pending extensions. If it can not be added,
253 // then there is already a pending record from a higher-priority install
254 // source. In this case, signal that this extension will not be
255 // installed by returning false.
256 if (!pending_extension_manager()->AddFromExternalUpdateUrl(
257 id, update_url, location))
258 return false;
259
[email protected]94fde232012-04-27 10:22:30260 update_once_all_providers_are_ready_ = true;
[email protected]9060d8b02012-01-13 02:14:30261 return true;
[email protected]7a4c6852010-09-16 03:44:22262}
263
[email protected]dc9a74f72012-08-17 18:07:21264const Extension* ExtensionService::GetInstalledApp(const GURL& url) const {
[email protected]615d88f2011-12-13 01:47:44265 const Extension* extension = extensions_.GetExtensionOrAppByURL(
266 ExtensionURLInfo(url));
[email protected]dc9a74f72012-08-17 18:07:21267 return (extension && extension->is_app()) ? extension : NULL;
[email protected]d9696672011-03-15 22:45:09268}
269
[email protected]dc9a74f72012-08-17 18:07:21270bool ExtensionService::IsInstalledApp(const GURL& url) const {
[email protected]d9696672011-03-15 22:45:09271 return !!GetInstalledApp(url);
[email protected]ffb204f22010-12-05 23:20:27272}
273
[email protected]da5683db2011-04-23 17:12:21274void ExtensionService::SetInstalledAppForRenderer(int renderer_child_id,
275 const Extension* app) {
276 installed_app_hosts_[renderer_child_id] = app;
277}
278
279const Extension* ExtensionService::GetInstalledAppForRenderer(
[email protected]dc9a74f72012-08-17 18:07:21280 int renderer_child_id) const {
281 InstalledAppMap::const_iterator i =
282 installed_app_hosts_.find(renderer_child_id);
283 return i == installed_app_hosts_.end() ? NULL : i->second;
[email protected]da5683db2011-04-23 17:12:21284}
285
[email protected]6aeac8342010-10-01 20:21:18286// static
[email protected]d6ebc9792011-04-07 18:18:33287// This function is used to implement the command-line switch
[email protected]3bdba0d2011-08-23 07:17:30288// --uninstall-extension, and to uninstall an extension via sync. The LOG
289// statements within this function are used to inform the user if the uninstall
290// cannot be done.
[email protected]eaa7dd182010-12-14 11:09:00291bool ExtensionService::UninstallExtensionHelper(
292 ExtensionService* extensions_service,
[email protected]6aeac8342010-10-01 20:21:18293 const std::string& extension_id) {
[email protected]6aeac8342010-10-01 20:21:18294
[email protected]95da88c42011-03-31 10:07:33295 const Extension* extension =
[email protected]8001df22011-04-28 19:59:47296 extensions_service->GetInstalledExtension(extension_id);
[email protected]95da88c42011-03-31 10:07:33297
[email protected]d6ebc9792011-04-07 18:18:33298 // We can't call UninstallExtension with an invalid extension ID.
[email protected]95da88c42011-03-31 10:07:33299 if (!extension) {
[email protected]6aeac8342010-10-01 20:21:18300 LOG(WARNING) << "Attempted uninstallation of non-existent extension with "
[email protected]95da88c42011-03-31 10:07:33301 << "id: " << extension_id;
302 return false;
[email protected]6aeac8342010-10-01 20:21:18303 }
304
[email protected]d6ebc9792011-04-07 18:18:33305 // The following call to UninstallExtension will not allow an uninstall of a
306 // policy-controlled extension.
[email protected]65187152012-06-02 13:14:14307 string16 error;
[email protected]d6ebc9792011-04-07 18:18:33308 if (!extensions_service->UninstallExtension(extension_id, false, &error)) {
309 LOG(WARNING) << "Cannot uninstall extension with id " << extension_id
310 << ": " << error;
311 return false;
312 }
[email protected]95da88c42011-03-31 10:07:33313
[email protected]6aeac8342010-10-01 20:21:18314 return true;
315}
316
[email protected]eaa7dd182010-12-14 11:09:00317ExtensionService::ExtensionService(Profile* profile,
[email protected]f0841cd2011-01-19 15:07:24318 const CommandLine* command_line,
319 const FilePath& install_directory,
[email protected]45759612012-07-10 17:21:23320 extensions::ExtensionPrefs* extension_prefs,
[email protected]0436b102011-04-15 18:30:03321 bool autoupdate_enabled,
322 bool extensions_enabled)
[email protected]d8c8f25f2011-11-02 18:18:01323 : profile_(profile),
[email protected]bd306722012-07-11 20:43:59324 system_(extensions::ExtensionSystem::Get(profile)),
[email protected]73c47932010-12-06 18:13:43325 extension_prefs_(extension_prefs),
[email protected]cccdf0aa2011-11-11 03:43:38326 settings_frontend_(extensions::SettingsFrontend::Create(profile)),
[email protected]14908b72011-04-20 06:54:36327 pending_extension_manager_(*ALLOW_THIS_IN_INITIALIZER_LIST(this)),
[email protected]a9b00ac2009-06-25 21:03:23328 install_directory_(install_directory),
[email protected]0436b102011-04-15 18:30:03329 extensions_enabled_(extensions_enabled),
[email protected]e81dba32009-06-19 20:19:13330 show_extensions_prompts_(true),
[email protected]3ecda252010-11-18 19:50:55331 ready_(false),
[email protected]14908b72011-04-20 06:54:36332 toolbar_model_(ALLOW_THIS_IN_INITIALIZER_LIST(this)),
[email protected]8b280302011-10-13 22:22:23333 menu_manager_(profile),
[email protected]8d92e0382012-08-01 18:06:52334 app_notification_manager_(
335 new extensions::AppNotificationManager(profile)),
[email protected]7c1490da2011-10-11 18:53:25336 event_routers_initialized_(false),
[email protected]dff1e042012-04-27 10:59:18337 update_once_all_providers_are_ready_(false),
[email protected]5db9ada2012-04-11 13:48:20338 app_sync_bundle_(ALLOW_THIS_IN_INITIALIZER_LIST(this)),
339 extension_sync_bundle_(ALLOW_THIS_IN_INITIALIZER_LIST(this)),
[email protected]a1755bd2011-12-09 00:40:20340 extension_warnings_(profile),
[email protected]178f8512012-02-09 01:49:36341 app_shortcut_manager_(profile) {
[email protected]a29a517a2011-01-21 21:11:12342 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]a8af9fdb2010-10-28 21:52:20343
[email protected]36a784c2009-06-23 06:21:08344 // Figure out if extension installation should be enabled.
[email protected]6d60703b2009-08-29 01:29:23345 if (command_line->HasSwitch(switches::kDisableExtensions)) {
346 extensions_enabled_ = false;
347 } else if (profile->GetPrefs()->GetBoolean(prefs::kDisableExtensions)) {
348 extensions_enabled_ = false;
[email protected]6b75ec32009-08-14 06:37:18349 }
[email protected]36a784c2009-06-23 06:21:08350
[email protected]432115822011-07-10 15:52:27351 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_PROCESS_TERMINATED,
[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_CREATED,
[email protected]ad50def52011-10-19 23:17:07354 content::NotificationService::AllBrowserContextsAndSources());
[email protected]432115822011-07-10 15:52:27355 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_TERMINATED,
[email protected]ad50def52011-10-19 23:17:07356 content::NotificationService::AllBrowserContextsAndSources());
[email protected]2fb7dc982010-09-29 12:24:28357 pref_change_registrar_.Init(profile->GetPrefs());
358 pref_change_registrar_.Add(prefs::kExtensionInstallAllowList, this);
359 pref_change_registrar_.Add(prefs::kExtensionInstallDenyList, this);
[email protected]4814b512009-11-07 00:12:29360
[email protected]93fd78f42009-07-10 16:43:17361 // Set up the ExtensionUpdater
362 if (autoupdate_enabled) {
363 int update_frequency = kDefaultUpdateFrequencySeconds;
364 if (command_line->HasSwitch(switches::kExtensionsUpdateFrequency)) {
[email protected]e83326f2010-07-31 17:29:25365 base::StringToInt(command_line->GetSwitchValueASCII(
366 switches::kExtensionsUpdateFrequency),
367 &update_frequency);
[email protected]93fd78f42009-07-10 16:43:17368 }
[email protected]42a08162012-03-16 18:09:11369 updater_.reset(new extensions::ExtensionUpdater(this,
370 extension_prefs,
371 profile->GetPrefs(),
372 profile,
373 update_frequency));
[email protected]93fd78f42009-07-10 16:43:17374 }
375
[email protected]25ae0152011-11-18 14:40:02376 component_loader_.reset(
377 new extensions::ComponentLoader(this,
378 profile->GetPrefs(),
379 g_browser_process->local_state()));
[email protected]8e4560b62011-01-14 10:09:14380
[email protected]af9db5f2011-10-05 05:13:15381 app_notification_manager_->Init();
382
[email protected]0436b102011-04-15 18:30:03383 if (extensions_enabled_) {
[email protected]1f2f3002011-12-28 00:40:21384 if (!command_line->HasSwitch(switches::kImport) &&
385 !command_line->HasSwitch(switches::kImportFromFile)) {
[email protected]5df038b2012-07-16 19:03:27386 extensions::ExternalProviderImpl::CreateExternalProviders(
[email protected]1f2f3002011-12-28 00:40:21387 this, profile_, &external_extension_providers_);
388 }
[email protected]873531342011-03-09 12:16:05389 }
[email protected]b671760b2010-07-15 21:13:47390
[email protected]aa96d3a2010-08-21 08:45:25391 // Use monochrome icons for Omnibox icons.
[email protected]29d0d4ac2010-09-08 21:10:31392 omnibox_popup_icon_manager_.set_monochrome(true);
[email protected]b671760b2010-07-15 21:13:47393 omnibox_icon_manager_.set_monochrome(true);
[email protected]29d0d4ac2010-09-08 21:10:31394 omnibox_icon_manager_.set_padding(gfx::Insets(0, kOmniboxIconPaddingLeft,
395 0, kOmniboxIconPaddingRight));
[email protected]cb0e50312011-05-09 15:03:07396
[email protected]fb82dcd2012-03-21 14:15:46397 // Set this as the ExtensionService for extension sorting to ensure it
398 // cause syncs if required.
399 extension_prefs_->extension_sorting()->SetExtensionService(this);
400
[email protected]9ce11d22012-08-08 23:20:13401#if defined(ENABLE_EXTENSIONS)
[email protected]c77f2352012-08-08 22:07:58402 extension_action_storage_manager_.reset(
403 new extensions::ExtensionActionStorageManager(profile_));
[email protected]9ce11d22012-08-08 23:20:13404#endif
[email protected]c77f2352012-08-08 22:07:58405
[email protected]cb0e50312011-05-09 15:03:07406 // How long is the path to the Extensions directory?
407 UMA_HISTOGRAM_CUSTOM_COUNTS("Extensions.ExtensionRootPathLength",
408 install_directory_.value().length(), 0, 500, 100);
[email protected]6014d672008-12-05 00:38:25409}
410
[email protected]84df8332011-12-06 18:22:46411const ExtensionSet* ExtensionService::extensions() const {
[email protected]ddb1e5a2010-12-13 20:10:45412 return &extensions_;
413}
414
[email protected]84df8332011-12-06 18:22:46415const ExtensionSet* ExtensionService::disabled_extensions() const {
[email protected]ddb1e5a2010-12-13 20:10:45416 return &disabled_extensions_;
417}
418
[email protected]84df8332011-12-06 18:22:46419const ExtensionSet* ExtensionService::terminated_extensions() const {
[email protected]bb7f40952011-01-13 00:21:20420 return &terminated_extensions_;
421}
422
[email protected]7f4308d2012-01-18 07:43:01423const ExtensionSet* ExtensionService::GenerateInstalledExtensionsSet() const {
424 ExtensionSet* installed_extensions = new ExtensionSet();
425 installed_extensions->InsertAll(extensions_);
426 installed_extensions->InsertAll(disabled_extensions_);
427 installed_extensions->InsertAll(terminated_extensions_);
428 return installed_extensions;
429}
430
[email protected]3f213ad2012-07-26 23:39:41431extensions::PendingExtensionManager*
432 ExtensionService::pending_extension_manager() {
[email protected]b2907fd2011-03-25 16:43:37433 return &pending_extension_manager_;
[email protected]ddb1e5a2010-12-13 20:10:45434}
435
[email protected]eaa7dd182010-12-14 11:09:00436ExtensionService::~ExtensionService() {
[email protected]c8d407e2011-04-28 21:27:17437 // No need to unload extensions here because they are profile-scoped, and the
438 // profile is in the process of being deleted.
[email protected]94b4ffc2011-02-04 05:55:17439
[email protected]5df038b2012-07-16 19:03:27440 extensions::ProviderCollection::const_iterator i;
[email protected]8e4560b62011-01-14 10:09:14441 for (i = external_extension_providers_.begin();
442 i != external_extension_providers_.end(); ++i) {
[email protected]5df038b2012-07-16 19:03:27443 extensions::ExternalProviderInterface* provider = i->get();
[email protected]8e4560b62011-01-14 10:09:14444 provider->ServiceShutdown();
445 }
[email protected]6014d672008-12-05 00:38:25446}
447
[email protected]d91268022011-08-26 13:17:37448void ExtensionService::InitEventRoutersAfterImport() {
[email protected]cf593af2011-12-30 05:44:39449 RegisterForImportFinished();
450}
451
452void ExtensionService::RegisterForImportFinished() {
453 if (!registrar_.IsRegistered(this, chrome::NOTIFICATION_IMPORT_FINISHED,
454 content::Source<Profile>(profile_))) {
455 registrar_.Add(this, chrome::NOTIFICATION_IMPORT_FINISHED,
456 content::Source<Profile>(profile_));
457 }
458}
459
460void ExtensionService::InitAfterImport() {
461 CheckForExternalUpdates();
462
463 GarbageCollectExtensions();
464
465 // Idempotent, so although there is a possible race if the import
466 // process finished sometime in the middle of ProfileImpl::InitExtensions,
467 // it cannot happen twice.
468 InitEventRouters();
[email protected]d91268022011-08-26 13:17:37469}
470
[email protected]eaa7dd182010-12-14 11:09:00471void ExtensionService::InitEventRouters() {
[email protected]b3d62312b12010-10-14 21:10:18472 if (event_routers_initialized_)
473 return;
474
[email protected]6a3cd37e2012-04-17 17:13:34475#if defined(ENABLE_EXTENSIONS)
[email protected]d2e6bd62011-10-24 20:29:07476 history_event_router_.reset(new HistoryExtensionEventRouter());
[email protected]f825df22011-06-28 17:36:10477 history_event_router_->ObserveProfile(profile_);
[email protected]5a38dfd2012-07-23 23:22:10478 browser_event_router_.reset(new extensions::BrowserEventRouter(profile_));
[email protected]34517242012-05-25 02:37:18479 browser_event_router_->Init();
[email protected]163ed192012-07-24 19:31:07480 window_event_router_.reset(new extensions::WindowEventRouter(profile_));
481 window_event_router_->Init();
[email protected]118de7892011-03-16 13:31:40482 preference_event_router_.reset(new ExtensionPreferenceEventRouter(profile_));
[email protected]23d5f172011-10-25 05:49:53483 bookmark_event_router_.reset(new BookmarkExtensionEventRouter(
[email protected]e07f2da2012-08-01 22:46:12484 BookmarkModelFactory::GetForProfile(profile_)));
[email protected]f825df22011-06-28 17:36:10485 bookmark_event_router_->Init();
[email protected]92ba7b012012-05-16 03:36:17486 cookies_event_router_.reset(new
487 extensions::ExtensionCookiesEventRouter(profile_));
[email protected]f825df22011-06-28 17:36:10488 cookies_event_router_->Init();
489 management_event_router_.reset(new ExtensionManagementEventRouter(profile_));
490 management_event_router_->Init();
[email protected]7da9a8232011-05-27 21:07:11491 ExtensionProcessesEventRouter::GetInstance()->ObserveProfile(profile_);
[email protected]f825df22011-06-28 17:36:10492 web_navigation_event_router_.reset(
[email protected]017ecde92012-04-04 09:11:26493 new extensions::WebNavigationEventRouter(profile_));
[email protected]f825df22011-06-28 17:36:10494 web_navigation_event_router_->Init();
[email protected]bdd34452012-04-16 15:58:40495 font_settings_event_router_.reset(
[email protected]91aa8a32012-08-07 10:35:33496 new extensions::FontSettingsEventRouter(profile_));
[email protected]bdd34452012-04-16 15:58:40497 font_settings_event_router_->Init();
[email protected]8a4cf842012-05-16 13:35:30498 managed_mode_event_router_.reset(
[email protected]9c70e0d92012-07-16 08:39:44499 new extensions::ExtensionManagedModeEventRouter(profile_));
[email protected]8a4cf842012-05-16 13:35:30500 managed_mode_event_router_->Init();
[email protected]5ebd6a62012-08-01 23:54:39501 push_messaging_event_router_.reset(
502 new extensions::PushMessagingEventRouter(profile_));
503 push_messaging_event_router_->Init();
[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]eed367e2011-04-12 03:43:31517#endif
[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;
530 if (include_disabled) {
531 include_mask |= INCLUDE_DISABLED;
532 }
533 return GetExtensionByIdInternal(id, include_mask);
[email protected]78994ab02010-12-08 18:06:44534}
535
[email protected]eaa7dd182010-12-14 11:09:00536void ExtensionService::Init() {
[email protected]a29a517a2011-01-21 21:11:12537 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]a8af9fdb2010-10-28 21:52:20538
[email protected]fa6a9102010-11-22 15:38:50539 DCHECK(!ready_); // Can't redo init.
[email protected]93fd78f42009-07-10 16:43:17540 DCHECK_EQ(extensions_.size(), 0u);
[email protected]9f1087e2009-06-15 17:29:32541
[email protected]d8c8f25f2011-11-02 18:18:01542 component_loader_->LoadAll();
543 extensions::InstalledLoader(this).LoadAllExtensions();
[email protected]894bb502009-05-21 22:39:57544
[email protected]7a161db2011-12-15 20:45:51545 // If we are running in the import process, don't bother initializing the
546 // extension service since this can interfere with the main browser process
547 // that is already running an extension service for this profile.
548 // TODO(aa): can we start up even less of ExtensionService?
549 // http://crbug.com/107636
[email protected]1f2f3002011-12-28 00:40:21550 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kImport) &&
551 !CommandLine::ForCurrentProcess()->HasSwitch(switches::kImportFromFile)) {
[email protected]cf593af2011-12-30 05:44:39552 if (g_browser_process->profile_manager() &&
553 g_browser_process->profile_manager()->will_import()) {
554 RegisterForImportFinished();
555 } else {
556 // TODO(erikkay) this should probably be deferred to a future point
557 // rather than running immediately at startup.
558 CheckForExternalUpdates();
[email protected]894bb502009-05-21 22:39:57559
[email protected]cf593af2011-12-30 05:44:39560 // TODO(erikkay) this should probably be deferred as well.
561 GarbageCollectExtensions();
562 }
[email protected]7a161db2011-12-15 20:45:51563 }
[email protected]6014d672008-12-05 00:38:25564}
565
[email protected]420a0ec2011-06-01 01:07:03566bool ExtensionService::UpdateExtension(
567 const std::string& id,
568 const FilePath& extension_path,
569 const GURL& download_url,
570 CrxInstaller** out_crx_installer) {
[email protected]a29a517a2011-01-21 21:11:12571 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]a8af9fdb2010-10-28 21:52:20572
[email protected]3f213ad2012-07-26 23:39:41573 const extensions::PendingExtensionInfo* pending_extension_info =
[email protected]51a3bf8b2012-06-08 22:53:06574 pending_extension_manager()->GetById(id);
[email protected]8ef78fd2010-08-19 17:14:32575
[email protected]81f0d162012-08-15 04:21:47576 int include_mask = INCLUDE_ENABLED;
577 include_mask |= INCLUDE_DISABLED;
[email protected]8001df22011-04-28 19:59:47578 const Extension* extension =
[email protected]81f0d162012-08-15 04:21:47579 GetExtensionByIdInternal(id, include_mask);
[email protected]51a3bf8b2012-06-08 22:53:06580 if (!pending_extension_info && !extension) {
[email protected]aa142702010-03-26 01:26:33581 LOG(WARNING) << "Will not update extension " << id
582 << " because it is not installed or pending";
583 // Delete extension_path since we're not creating a CrxInstaller
584 // that would do it for us.
[email protected]14908b72011-04-20 06:54:36585 if (!BrowserThread::PostTask(
586 BrowserThread::FILE, FROM_HERE,
[email protected]53612e82011-10-18 18:00:36587 base::Bind(
[email protected]7296f2762011-11-21 19:23:44588 &extension_file_util::DeleteFile, extension_path, false)))
[email protected]14908b72011-04-20 06:54:36589 NOTREACHED();
[email protected]420a0ec2011-06-01 01:07:03590
591 return false;
[email protected]e957fe52009-06-23 16:51:05592 }
593
[email protected]aa142702010-03-26 01:26:33594 // We want a silent install only for non-pending extensions and
595 // pending extensions that have install_silently set.
[email protected]c82da8c42012-06-08 19:49:11596 ExtensionInstallPrompt* client =
[email protected]51a3bf8b2012-06-08 22:53:06597 (!pending_extension_info || pending_extension_info->install_silently()) ?
[email protected]00b38242012-07-18 18:43:22598 NULL : ExtensionInstallUI::CreateInstallPromptWithProfile(profile_);
[email protected]aa142702010-03-26 01:26:33599
[email protected]d8c8f25f2011-11-02 18:18:01600 scoped_refptr<CrxInstaller> installer(CrxInstaller::Create(this, client));
[email protected]6dfbbf82010-03-12 23:09:16601 installer->set_expected_id(id);
[email protected]51a3bf8b2012-06-08 22:53:06602 if (pending_extension_info) {
603 installer->set_install_source(pending_extension_info->install_source());
604 if (pending_extension_info->install_silently())
605 installer->set_allow_silent_install(true);
606 } else if (extension) {
[email protected]5eb375e92010-11-26 07:50:41607 installer->set_install_source(extension->location());
[email protected]51a3bf8b2012-06-08 22:53:06608 }
[email protected]7d8b7072012-04-07 01:07:46609 // If the extension was installed from or has migrated to the webstore, or
610 // if the extension came from sync and its auto-update URL is from the
[email protected]75764512011-12-19 19:54:28611 // webstore, treat it as a webstore install. Note that we ignore some older
612 // extensions with blank auto-update URLs because we are mostly concerned
613 // with restrictions on NaCl extensions, which are newer.
[email protected]a12ce8b22012-01-17 18:40:53614 int creation_flags = Extension::NO_FLAGS;
[email protected]75764512011-12-19 19:54:28615 if ((extension && extension->from_webstore()) ||
[email protected]7d8b7072012-04-07 01:07:46616 (extension && extension->UpdatesFromGallery()) ||
[email protected]51a3bf8b2012-06-08 22:53:06617 (!extension && pending_extension_info->is_from_sync() &&
[email protected]75764512011-12-19 19:54:28618 extension_urls::IsWebstoreUpdateUrl(
[email protected]51a3bf8b2012-06-08 22:53:06619 pending_extension_info->update_url()))) {
[email protected]a12ce8b22012-01-17 18:40:53620 creation_flags |= Extension::FROM_WEBSTORE;
621 }
622
623 // Bookmark apps being updated is kind of a contradiction, but that's because
624 // we mark the default apps as bookmark apps, and they're hosted in the web
625 // store, thus they can get updated. See http://crbug.com/101605 for more
626 // details.
627 if (extension && extension->from_bookmark())
628 creation_flags |= Extension::FROM_BOOKMARK;
629
[email protected]e33bbc22012-08-27 22:05:46630 if (extension && extension->was_installed_by_default())
631 creation_flags |= Extension::WAS_INSTALLED_BY_DEFAULT;
632
[email protected]a12ce8b22012-01-17 18:40:53633 installer->set_creation_flags(creation_flags);
634
[email protected]6dfbbf82010-03-12 23:09:16635 installer->set_delete_source(true);
[email protected]655b2b1a2011-10-13 17:13:06636 installer->set_download_url(download_url);
[email protected]cb0e50312011-05-09 15:03:07637 installer->set_install_cause(extension_misc::INSTALL_CAUSE_UPDATE);
[email protected]6dfbbf82010-03-12 23:09:16638 installer->InstallCrx(extension_path);
[email protected]420a0ec2011-06-01 01:07:03639
640 if (out_crx_installer)
641 *out_crx_installer = installer;
642
643 return true;
[email protected]e957fe52009-06-23 16:51:05644}
645
[email protected]eaa7dd182010-12-14 11:09:00646void ExtensionService::ReloadExtension(const std::string& extension_id) {
[email protected]a29a517a2011-01-21 21:11:12647 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]b65272f2009-08-31 15:47:06648 FilePath path;
[email protected]9adb9692010-10-29 23:14:02649 const Extension* current_extension = GetExtensionById(extension_id, false);
[email protected]9cddd4702009-07-27 22:09:40650
[email protected]f17dbd42010-08-16 23:21:10651 // Disable the extension if it's loaded. It might not be loaded if it crashed.
[email protected]b65272f2009-08-31 15:47:06652 if (current_extension) {
[email protected]4814b512009-11-07 00:12:29653 // If the extension has an inspector open for its background page, detach
654 // the inspector and hang onto a cookie for it, so that we can reattach
655 // later.
[email protected]31d8f5f22012-04-02 15:22:08656 // TODO(yoz): this is not incognito-safe!
657 ExtensionProcessManager* manager = system_->process_manager();
[email protected]3a1dc572012-07-31 22:25:13658 extensions::ExtensionHost* host =
659 manager->GetBackgroundHostForExtension(extension_id);
[email protected]0e12d7d2011-12-01 16:21:44660 if (host && DevToolsAgentHostRegistry::HasDevToolsAgentHost(
661 host->render_view_host())) {
[email protected]4814b512009-11-07 00:12:29662 // Look for an open inspector for the background page.
[email protected]0e12d7d2011-12-01 16:21:44663 DevToolsAgentHost* agent =
664 DevToolsAgentHostRegistry::GetDevToolsAgentHost(
665 host->render_view_host());
666 int devtools_cookie =
667 content::DevToolsManager::GetInstance()->DetachClientHost(agent);
[email protected]4814b512009-11-07 00:12:29668 if (devtools_cookie >= 0)
669 orphaned_dev_tools_[extension_id] = devtools_cookie;
670 }
671
[email protected]6cafe35a2012-08-27 22:40:50672 if (current_extension->is_platform_app() &&
673 !extensions::ShellWindowRegistry::Get(profile_)->
674 GetShellWindowsForApp(extension_id).empty()) {
675 relaunch_app_ids_.insert(extension_id);
676 }
677
[email protected]b65272f2009-08-31 15:47:06678 path = current_extension->path();
[email protected]44d62b62012-04-11 00:06:03679 DisableExtension(extension_id, Extension::DISABLE_RELOAD);
[email protected]f17dbd42010-08-16 23:21:10680 disabled_extension_paths_[extension_id] = path;
[email protected]1eb175082010-02-10 09:26:16681 } else {
682 path = unloaded_extension_paths_[extension_id];
[email protected]b65272f2009-08-31 15:47:06683 }
684
[email protected]43ceb002012-02-10 23:19:15685 // If we're reloading a component extension, use the component extension
686 // loader's reloader.
687 if (component_loader_->Exists(extension_id)) {
688 component_loader_->Reload(extension_id);
689 return;
690 }
691
[email protected]e6090e42010-03-23 22:44:08692 // Check the installed extensions to see if what we're reloading was already
693 // installed.
694 scoped_ptr<ExtensionInfo> installed_extension(
695 extension_prefs_->GetInstalledExtensionInfo(extension_id));
696 if (installed_extension.get() &&
697 installed_extension->extension_manifest.get()) {
[email protected]d8c8f25f2011-11-02 18:18:01698 extensions::InstalledLoader(this).Load(*installed_extension, false);
[email protected]e6090e42010-03-23 22:44:08699 } else {
[email protected]d8c8f25f2011-11-02 18:18:01700 // Otherwise, the extension is unpacked (location LOAD).
[email protected]e6090e42010-03-23 22:44:08701 // We should always be able to remember the extension's path. If it's not in
702 // the map, someone failed to update |unloaded_extension_paths_|.
703 CHECK(!path.empty());
[email protected]d8c8f25f2011-11-02 18:18:01704 extensions::UnpackedInstaller::Create(this)->Load(path);
[email protected]e6090e42010-03-23 22:44:08705 }
[email protected]9cddd4702009-07-27 22:09:40706}
707
[email protected]fa2416f2011-05-03 08:41:20708bool ExtensionService::UninstallExtension(
[email protected]a12c706e2011-12-01 00:58:08709 std::string extension_id,
[email protected]fa2416f2011-05-03 08:41:20710 bool external_uninstall,
[email protected]65187152012-06-02 13:14:14711 string16* error) {
[email protected]a29a517a2011-01-21 21:11:12712 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]a8af9fdb2010-10-28 21:52:20713
[email protected]0d6ec3a72011-09-02 02:09:43714 scoped_refptr<const Extension> extension(GetInstalledExtension(extension_id));
[email protected]631cf822009-05-15 07:01:25715
[email protected]e7afe2452010-08-22 16:19:13716 // Callers should not send us nonexistent extensions.
[email protected]aebe23a32010-12-10 22:15:48717 CHECK(extension);
[email protected]9f1087e2009-06-15 17:29:32718
[email protected]95da88c42011-03-31 10:07:33719 // Policy change which triggers an uninstall will always set
720 // |external_uninstall| to true so this is the only way to uninstall
721 // managed extensions.
[email protected]65187152012-06-02 13:14:14722 if (!external_uninstall &&
723 !system_->management_policy()->UserMayModifySettings(
724 extension.get(), error)) {
[email protected]ad50def52011-10-19 23:17:07725 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:27726 chrome::NOTIFICATION_EXTENSION_UNINSTALL_NOT_ALLOWED,
[email protected]6c2381d2011-10-19 02:52:53727 content::Source<Profile>(profile_),
728 content::Details<const Extension>(extension));
[email protected]d6ebc9792011-04-07 18:18:33729 return false;
730 }
[email protected]95da88c42011-03-31 10:07:33731
[email protected]3bdba0d2011-08-23 07:17:30732 // Extract the data we need for sync now, but don't actually sync until we've
733 // completed the uninstallation.
[email protected]65f173552012-06-28 22:43:58734 syncer::SyncChange sync_change;
[email protected]5db9ada2012-04-11 13:48:20735 if (app_sync_bundle_.HandlesApp(*extension)) {
736 sync_change = app_sync_bundle_.CreateSyncChangeToDelete(extension);
737 } else if (extension_sync_bundle_.HandlesExtension(*extension)) {
738 sync_change = extension_sync_bundle_.CreateSyncChangeToDelete(extension);
[email protected]3bdba0d2011-08-23 07:17:30739 }
740
[email protected]9b217652010-10-08 22:04:23741 UMA_HISTOGRAM_ENUMERATION("Extensions.UninstallType",
[email protected]7fa19f82010-12-21 19:40:08742 extension->GetType(), 100);
[email protected]fe2dd7742011-04-19 22:52:49743 RecordPermissionMessagesHistogram(
744 extension, "Extensions.Permissions_Uninstall");
[email protected]9b217652010-10-08 22:04:23745
[email protected]8e5c89a2011-06-07 18:13:33746 TemplateURLService* url_service =
747 TemplateURLServiceFactory::GetForProfile(profile_);
748 if (url_service)
749 url_service->UnregisterExtensionKeyword(extension);
[email protected]56ad3792010-05-28 17:45:33750
[email protected]831aa212010-03-26 13:55:19751 // Unload before doing more cleanup to ensure that nothing is hanging on to
752 // any of these resources.
[email protected]814a7bf0f2011-08-13 05:30:59753 UnloadExtension(extension_id, extension_misc::UNLOAD_REASON_UNINSTALL);
[email protected]831aa212010-03-26 13:55:19754
[email protected]0d6ec3a72011-09-02 02:09:43755 extension_prefs_->OnExtensionUninstalled(extension_id, extension->location(),
[email protected]831aa212010-03-26 13:55:19756 external_uninstall);
[email protected]9f1087e2009-06-15 17:29:32757
758 // Tell the backend to start deleting installed extensions on the file thread.
[email protected]0d6ec3a72011-09-02 02:09:43759 if (Extension::LOAD != extension->location()) {
[email protected]14908b72011-04-20 06:54:36760 if (!BrowserThread::PostTask(
761 BrowserThread::FILE, FROM_HERE,
[email protected]53612e82011-10-18 18:00:36762 base::Bind(
[email protected]14908b72011-04-20 06:54:36763 &extension_file_util::UninstallExtension,
764 install_directory_,
[email protected]fa2416f2011-05-03 08:41:20765 extension_id)))
[email protected]14908b72011-04-20 06:54:36766 NOTREACHED();
[email protected]9f1087e2009-06-15 17:29:32767 }
768
[email protected]0d6ec3a72011-09-02 02:09:43769 GURL launch_web_url_origin(extension->launch_web_url());
770 launch_web_url_origin = launch_web_url_origin.GetOrigin();
[email protected]605fb8102012-05-04 01:36:55771 bool is_storage_isolated = extension->is_storage_isolated();
[email protected]0d6ec3a72011-09-02 02:09:43772
773 if (extension->is_hosted_app() &&
774 !profile_->GetExtensionSpecialStoragePolicy()->
775 IsStorageProtected(launch_web_url_origin)) {
[email protected]d9ede582012-08-14 19:21:38776 extensions::DataDeleter::StartDeleting(
[email protected]dc0b5a12011-10-14 00:06:13777 profile_, extension_id, launch_web_url_origin, is_storage_isolated);
[email protected]0d6ec3a72011-09-02 02:09:43778 }
[email protected]d9ede582012-08-14 19:21:38779 extensions::DataDeleter::StartDeleting(
[email protected]dc0b5a12011-10-14 00:06:13780 profile_, extension_id, extension->url(), is_storage_isolated);
[email protected]0d6ec3a72011-09-02 02:09:43781
[email protected]0dfe05c2011-02-23 23:03:36782 UntrackTerminatedExtension(extension_id);
[email protected]211030342010-09-30 18:41:06783
784 // Notify interested parties that we've uninstalled this extension.
[email protected]ad50def52011-10-19 23:17:07785 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:27786 chrome::NOTIFICATION_EXTENSION_UNINSTALLED,
[email protected]6c2381d2011-10-19 02:52:53787 content::Source<Profile>(profile_),
[email protected]d67d9412012-07-17 17:19:42788 content::Details<const Extension>(extension));
[email protected]d6ebc9792011-04-07 18:18:33789
[email protected]5db9ada2012-04-11 13:48:20790 if (app_sync_bundle_.HasExtensionId(extension_id) &&
[email protected]a4a147652012-07-03 23:41:32791 sync_change.sync_data().GetDataType() == syncer::APPS) {
[email protected]5db9ada2012-04-11 13:48:20792 app_sync_bundle_.ProcessDeletion(extension_id, sync_change);
793 } else if (extension_sync_bundle_.HasExtensionId(extension_id) &&
[email protected]a4a147652012-07-03 23:41:32794 sync_change.sync_data().GetDataType() == syncer::EXTENSIONS) {
[email protected]5db9ada2012-04-11 13:48:20795 extension_sync_bundle_.ProcessDeletion(extension_id, sync_change);
[email protected]3bdba0d2011-08-23 07:17:30796 }
797
[email protected]333b1de2011-09-12 18:28:50798 // Track the uninstallation.
[email protected]49098f702011-10-13 03:47:18799 UMA_HISTOGRAM_ENUMERATION("Extensions.ExtensionUninstalled", 1, 2);
800
801 static bool default_apps_trial_exists =
[email protected]568c3312011-12-06 15:36:04802 base::FieldTrialList::TrialExists(kDefaultAppsTrialName);
[email protected]49098f702011-10-13 03:47:18803 if (default_apps_trial_exists) {
804 UMA_HISTOGRAM_ENUMERATION(
805 base::FieldTrial::MakeName("Extensions.ExtensionUninstalled",
[email protected]568c3312011-12-06 15:36:04806 kDefaultAppsTrialName),
[email protected]49098f702011-10-13 03:47:18807 1, 2);
808 }
[email protected]333b1de2011-09-12 18:28:50809
[email protected]7c1490da2011-10-11 18:53:25810 // Uninstalling one extension might have solved the problems of others.
811 // Therefore, we clear warnings of this type for all extensions.
812 std::set<ExtensionWarningSet::WarningType> warnings;
813 extension_warnings_.GetWarningsAffectingExtension(extension_id, &warnings);
814 extension_warnings_.ClearWarnings(warnings);
815
[email protected]d6ebc9792011-04-07 18:18:33816 return true;
[email protected]c10da4b02010-03-25 14:38:32817}
818
[email protected]c3cfb012011-04-06 22:07:35819bool ExtensionService::IsExtensionEnabled(
820 const std::string& extension_id) const {
[email protected]84df8332011-12-06 18:22:46821 if (extensions_.Contains(extension_id) ||
[email protected]dc9a74f72012-08-17 18:07:21822 terminated_extensions_.Contains(extension_id)) {
[email protected]36429da2011-07-11 20:25:18823 return true;
[email protected]dc9a74f72012-08-17 18:07:21824 }
[email protected]36429da2011-07-11 20:25:18825
[email protected]84df8332011-12-06 18:22:46826 if (disabled_extensions_.Contains(extension_id))
[email protected]ad83ca242011-07-29 01:32:25827 return false;
828
829 // If the extension hasn't been loaded yet, check the prefs for it. Assume
830 // enabled unless otherwise noted.
831 return !extension_prefs_->IsExtensionDisabled(extension_id) &&
832 !extension_prefs_->IsExternalExtensionUninstalled(extension_id);
[email protected]c3cfb012011-04-06 22:07:35833}
834
835bool ExtensionService::IsExternalExtensionUninstalled(
836 const std::string& extension_id) const {
837 return extension_prefs_->IsExternalExtensionUninstalled(extension_id);
838}
839
[email protected]eaa7dd182010-12-14 11:09:00840void ExtensionService::EnableExtension(const std::string& extension_id) {
[email protected]a29a517a2011-01-21 21:11:12841 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]a8af9fdb2010-10-28 21:52:20842
[email protected]06f92562011-04-29 19:27:31843 if (IsExtensionEnabled(extension_id))
[email protected]0c6da502009-08-14 22:32:39844 return;
[email protected]0c6da502009-08-14 22:32:39845
[email protected]b3317ad2011-04-28 23:46:00846 extension_prefs_->SetExtensionState(extension_id, Extension::ENABLED);
[email protected]eb5e4f92012-08-15 23:33:28847 extension_prefs_->ClearDisableReasons(extension_id);
[email protected]1784e83a2009-09-08 21:01:52848
[email protected]81f0d162012-08-15 04:21:47849 const Extension* extension = GetExtensionByIdInternal(extension_id,
850 INCLUDE_DISABLED);
[email protected]06f92562011-04-29 19:27:31851 // This can happen if sync enables an extension that is not
852 // installed yet.
853 if (!extension)
854 return;
855
[email protected]0c6da502009-08-14 22:32:39856 // Move it over to the enabled list.
[email protected]84df8332011-12-06 18:22:46857 extensions_.Insert(make_scoped_refptr(extension));
858 disabled_extensions_.Remove(extension->id());
[email protected]0c6da502009-08-14 22:32:39859
[email protected]f681c782010-11-19 11:19:39860 // Make sure any browser action contained within it is not hidden.
861 extension_prefs_->SetBrowserActionVisibility(extension, true);
862
[email protected]62d30f42009-10-01 22:36:06863 NotifyExtensionLoaded(extension);
[email protected]3bdba0d2011-08-23 07:17:30864
[email protected]f74d7f32012-06-19 19:22:51865 // Notify listeners that the extension was enabled.
866 content::NotificationService::current()->Notify(
867 chrome::NOTIFICATION_EXTENSION_ENABLED,
868 content::Source<Profile>(profile_),
869 content::Details<const Extension>(extension));
870
[email protected]3bdba0d2011-08-23 07:17:30871 SyncExtensionChangeIfNeeded(*extension);
[email protected]0c6da502009-08-14 22:32:39872}
873
[email protected]44d62b62012-04-11 00:06:03874void ExtensionService::DisableExtension(
875 const std::string& extension_id,
876 Extension::DisableReason disable_reason) {
[email protected]a29a517a2011-01-21 21:11:12877 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]a8af9fdb2010-10-28 21:52:20878
[email protected]b2ba9962009-12-10 20:10:15879 // The extension may have been disabled already.
[email protected]06f92562011-04-29 19:27:31880 if (!IsExtensionEnabled(extension_id))
[email protected]1784e83a2009-09-08 21:01:52881 return;
[email protected]1784e83a2009-09-08 21:01:52882
[email protected]06f92562011-04-29 19:27:31883 const Extension* extension = GetInstalledExtension(extension_id);
884 // |extension| can be NULL if sync disables an extension that is not
885 // installed yet.
[email protected]65187152012-06-02 13:14:14886 if (extension &&
887 !system_->management_policy()->UserMayModifySettings(extension, NULL)) {
[email protected]95da88c42011-03-31 10:07:33888 return;
[email protected]65187152012-06-02 13:14:14889 }
[email protected]95da88c42011-03-31 10:07:33890
[email protected]b3317ad2011-04-28 23:46:00891 extension_prefs_->SetExtensionState(extension_id, Extension::DISABLED);
[email protected]eb5e4f92012-08-15 23:33:28892 extension_prefs_->AddDisableReason(extension_id, disable_reason);
[email protected]1784e83a2009-09-08 21:01:52893
[email protected]81f0d162012-08-15 04:21:47894 int include_mask = INCLUDE_ENABLED;
895 include_mask |= INCLUDE_TERMINATED;
896 extension = GetExtensionByIdInternal(extension_id, include_mask);
[email protected]06f92562011-04-29 19:27:31897 if (!extension)
898 return;
899
[email protected]1784e83a2009-09-08 21:01:52900 // Move it over to the disabled list.
[email protected]84df8332011-12-06 18:22:46901 disabled_extensions_.Insert(make_scoped_refptr(extension));
902 if (extensions_.Contains(extension->id()))
903 extensions_.Remove(extension->id());
904 else
905 terminated_extensions_.Remove(extension->id());
[email protected]1784e83a2009-09-08 21:01:52906
[email protected]814a7bf0f2011-08-13 05:30:59907 NotifyExtensionUnloaded(extension, extension_misc::UNLOAD_REASON_DISABLE);
[email protected]3bdba0d2011-08-23 07:17:30908
909 SyncExtensionChangeIfNeeded(*extension);
[email protected]7c1490da2011-10-11 18:53:25910
911 // Deactivating one extension might have solved the problems of others.
912 // Therefore, we clear warnings of this type for all extensions.
913 std::set<ExtensionWarningSet::WarningType> warnings;
914 extension_warnings_.GetWarningsAffectingExtension(extension_id, &warnings);
915 extension_warnings_.ClearWarnings(warnings);
[email protected]1784e83a2009-09-08 21:01:52916}
917
[email protected]eaa7dd182010-12-14 11:09:00918void ExtensionService::GrantPermissionsAndEnableExtension(
[email protected]b70a2d92012-06-28 19:51:21919 const Extension* extension, bool record_oauth2_grant) {
[email protected]8d888c12010-11-30 00:00:25920 CHECK(extension);
[email protected]fe2dd7742011-04-19 22:52:49921 RecordPermissionMessagesHistogram(
922 extension, "Extensions.Permissions_ReEnable");
[email protected]c333e792012-01-06 16:57:39923 extensions::PermissionsUpdater perms_updater(profile());
[email protected]b70a2d92012-06-28 19:51:21924 perms_updater.GrantActivePermissions(extension, record_oauth2_grant);
[email protected]8d888c12010-11-30 00:00:25925 extension_prefs_->SetDidExtensionEscalatePermissions(extension, false);
926 EnableExtension(extension->id());
927}
928
[email protected]fe2dd7742011-04-19 22:52:49929// static
930void ExtensionService::RecordPermissionMessagesHistogram(
931 const Extension* e, const char* histogram) {
932 // Since this is called from multiple sources, and since the Histogram macros
933 // use statics, we need to manually lookup the Histogram ourselves.
934 base::Histogram* counter = base::LinearHistogram::FactoryGet(
935 histogram,
936 1,
[email protected]c2e66e12012-06-27 06:27:06937 PermissionMessage::kEnumBoundary,
938 PermissionMessage::kEnumBoundary + 1,
[email protected]fe2dd7742011-04-19 22:52:49939 base::Histogram::kUmaTargetedHistogramFlag);
940
[email protected]c2e66e12012-06-27 06:27:06941 PermissionMessages permissions = e->GetPermissionMessages();
[email protected]fe2dd7742011-04-19 22:52:49942 if (permissions.empty()) {
[email protected]c2e66e12012-06-27 06:27:06943 counter->Add(PermissionMessage::kNone);
[email protected]fe2dd7742011-04-19 22:52:49944 } else {
[email protected]c2e66e12012-06-27 06:27:06945 for (PermissionMessages::iterator it = permissions.begin();
[email protected]0d3e4a22011-06-23 19:02:52946 it != permissions.end(); ++it)
947 counter->Add(it->id());
[email protected]fe2dd7742011-04-19 22:52:49948 }
949}
950
[email protected]eaa7dd182010-12-14 11:09:00951void ExtensionService::NotifyExtensionLoaded(const Extension* extension) {
[email protected]57a777f72010-03-31 01:09:42952 // The ChromeURLRequestContexts need to be first to know that the extension
[email protected]62d30f42009-10-01 22:36:06953 // was loaded, otherwise a race can arise where a renderer that is created
954 // for the extension may try to load an extension URL with an extension id
[email protected]57a777f72010-03-31 01:09:42955 // that the request context doesn't yet know about. The profile is responsible
956 // for ensuring its URLRequestContexts appropriately discover the loaded
957 // extension.
[email protected]31d8f5f22012-04-02 15:22:08958 system_->RegisterExtensionWithRequestContexts(extension);
[email protected]62d30f42009-10-01 22:36:06959
[email protected]19647262011-12-16 09:57:49960 // Tell renderers about the new extension, unless it's a theme (renderers
961 // don't need to know about themes).
962 if (!extension->is_theme()) {
963 for (content::RenderProcessHost::iterator i(
964 content::RenderProcessHost::AllHostsIterator());
965 !i.IsAtEnd(); i.Advance()) {
966 content::RenderProcessHost* host = i.GetCurrentValue();
967 Profile* host_profile =
968 Profile::FromBrowserContext(host->GetBrowserContext());
969 if (host_profile->GetOriginalProfile() ==
970 profile_->GetOriginalProfile()) {
971 std::vector<ExtensionMsg_Loaded_Params> loaded_extensions(
972 1, ExtensionMsg_Loaded_Params(extension));
973 host->Send(
974 new ExtensionMsg_Loaded(loaded_extensions));
975 }
[email protected]c8d407e2011-04-28 21:27:17976 }
[email protected]77a6970c2011-04-23 16:58:56977 }
978
[email protected]3442a662012-01-12 08:06:17979 // Tell subsystems that use the EXTENSION_LOADED notification about the new
980 // extension.
981 //
982 // NOTE: It is important that this happen after notifying the renderers about
983 // the new extensions so that if we navigate to an extension URL in
984 // NOTIFICATION_EXTENSION_LOADED, the renderer is guaranteed to know about it.
985 content::NotificationService::current()->Notify(
986 chrome::NOTIFICATION_EXTENSION_LOADED,
987 content::Source<Profile>(profile_),
988 content::Details<const Extension>(extension));
989
[email protected]c8d407e2011-04-28 21:27:17990 // Tell a random-ass collection of other subsystems about the new extension.
991 // TODO(aa): What should we do with all this goop? Can it move into the
992 // relevant objects via EXTENSION_LOADED?
993
994 profile_->GetExtensionSpecialStoragePolicy()->
995 GrantRightsForExtension(extension);
996
997 UpdateActiveExtensionsInCrashReporter();
998
999 ExtensionWebUI::RegisterChromeURLOverrides(
1000 profile_, extension->GetChromeURLOverrides());
1001
[email protected]8e5c89a2011-06-07 18:13:331002 TemplateURLService* url_service =
1003 TemplateURLServiceFactory::GetForProfile(profile_);
1004 if (url_service)
1005 url_service->RegisterExtensionKeyword(extension);
[email protected]c8d407e2011-04-28 21:27:171006
1007 // Load the icon for omnibox-enabled extensions so it will be ready to display
1008 // in the URL bar.
1009 if (!extension->omnibox_keyword().empty()) {
1010 omnibox_popup_icon_manager_.LoadIcon(extension);
1011 omnibox_icon_manager_.LoadIcon(extension);
1012 }
1013
1014 // If the extension has permission to load chrome://favicon/ resources we need
1015 // to make sure that the FaviconSource is registered with the
1016 // ChromeURLDataManager.
1017 if (extension->HasHostPermission(GURL(chrome::kChromeUIFaviconURL))) {
1018 FaviconSource* favicon_source = new FaviconSource(profile_,
1019 FaviconSource::FAVICON);
[email protected]ef92e172012-04-25 19:40:411020 ChromeURLDataManager::AddDataSource(profile_, favicon_source);
[email protected]c8d407e2011-04-28 21:27:171021 }
[email protected]5eddc3e2011-10-26 04:33:311022 // Same for chrome://thumb/ resources.
1023 if (extension->HasHostPermission(GURL(chrome::kChromeUIThumbnailURL))) {
1024 ThumbnailSource* thumbnail_source = new ThumbnailSource(profile_);
[email protected]ef92e172012-04-25 19:40:411025 ChromeURLDataManagerFactory::GetForProfile(profile_)->
1026 AddDataSource(thumbnail_source);
[email protected]5eddc3e2011-10-26 04:33:311027 }
[email protected]c8d407e2011-04-28 21:27:171028
1029 // TODO(mpcomplete): This ends up affecting all profiles. See crbug.com/80757.
[email protected]2de307592011-04-05 21:16:581030 bool plugins_changed = false;
1031 for (size_t i = 0; i < extension->plugins().size(); ++i) {
1032 const Extension::PluginInfo& plugin = extension->plugins()[i];
[email protected]f520b5b2011-11-08 02:42:141033 PluginService::GetInstance()->RefreshPlugins();
1034 PluginService::GetInstance()->AddExtraPluginPath(plugin.path);
[email protected]2de307592011-04-05 21:16:581035 plugins_changed = true;
[email protected]476a27032011-09-13 13:40:491036 ChromePluginServiceFilter* filter =
1037 ChromePluginServiceFilter::GetInstance();
1038 if (plugin.is_public) {
1039 filter->RestrictPluginToProfileAndOrigin(
1040 plugin.path, profile_, GURL());
1041 } else {
1042 filter->RestrictPluginToProfileAndOrigin(
1043 plugin.path, profile_, extension->url());
[email protected]2de307592011-04-05 21:16:581044 }
1045 }
[email protected]84396dbc2011-04-14 06:33:421046
1047 bool nacl_modules_changed = false;
1048 for (size_t i = 0; i < extension->nacl_modules().size(); ++i) {
1049 const Extension::NaClModuleInfo& module = extension->nacl_modules()[i];
[email protected]cebc3dc2011-04-18 17:15:001050 RegisterNaClModule(module.url, module.mime_type);
[email protected]84396dbc2011-04-14 06:33:421051 nacl_modules_changed = true;
1052 }
1053
[email protected]ed0ba002011-05-26 16:55:131054 if (nacl_modules_changed)
1055 UpdatePluginListWithNaClModules();
[email protected]84396dbc2011-04-14 06:33:421056
1057 if (plugins_changed || nacl_modules_changed)
[email protected]45a22e62011-10-12 09:48:021058 PluginService::GetInstance()->PurgePluginListCache(profile_, false);
[email protected]b4d9d122011-06-17 01:58:541059
[email protected]14da67b02011-08-02 05:49:131060#if defined(OS_CHROMEOS)
[email protected]b4d9d122011-06-17 01:58:541061 for (std::vector<Extension::InputComponentInfo>::const_iterator component =
1062 extension->input_components().begin();
1063 component != extension->input_components().end();
1064 ++component) {
[email protected]14da67b02011-08-02 05:49:131065 if (component->type == Extension::INPUT_COMPONENT_TYPE_IME) {
[email protected]1364c6d2012-07-24 11:57:191066 extensions::InputImeEventRouter::GetInstance()->RegisterIme(
[email protected]14da67b02011-08-02 05:49:131067 profile_, extension->id(), *component);
1068 }
[email protected]b4d9d122011-06-17 01:58:541069 }
1070#endif
[email protected]62d30f42009-10-01 22:36:061071}
1072
[email protected]a9f39a312010-12-23 22:14:271073void ExtensionService::NotifyExtensionUnloaded(
[email protected]814a7bf0f2011-08-13 05:30:591074 const Extension* extension,
1075 extension_misc::UnloadedExtensionReason reason) {
[email protected]a9f39a312010-12-23 22:14:271076 UnloadedExtensionInfo details(extension, reason);
[email protected]ad50def52011-10-19 23:17:071077 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271078 chrome::NOTIFICATION_EXTENSION_UNLOADED,
[email protected]6c2381d2011-10-19 02:52:531079 content::Source<Profile>(profile_),
1080 content::Details<UnloadedExtensionInfo>(&details));
[email protected]62d30f42009-10-01 22:36:061081
[email protected]f3b1a082011-11-18 00:34:301082 for (content::RenderProcessHost::iterator i(
1083 content::RenderProcessHost::AllHostsIterator());
[email protected]77a6970c2011-04-23 16:58:561084 !i.IsAtEnd(); i.Advance()) {
[email protected]f3b1a082011-11-18 00:34:301085 content::RenderProcessHost* host = i.GetCurrentValue();
[email protected]9b62ecf2011-07-27 20:23:081086 Profile* host_profile =
[email protected]f3b1a082011-11-18 00:34:301087 Profile::FromBrowserContext(host->GetBrowserContext());
[email protected]9b62ecf2011-07-27 20:23:081088 if (host_profile->GetOriginalProfile() == profile_->GetOriginalProfile())
[email protected]c8d407e2011-04-28 21:27:171089 host->Send(new ExtensionMsg_Unloaded(extension->id()));
[email protected]77a6970c2011-04-23 16:58:561090 }
1091
[email protected]31d8f5f22012-04-02 15:22:081092 system_->UnregisterExtensionWithRequestContexts(extension->id(), reason);
[email protected]c8d407e2011-04-28 21:27:171093 profile_->GetExtensionSpecialStoragePolicy()->
1094 RevokeRightsForExtension(extension);
1095
1096 ExtensionWebUI::UnregisterChromeURLOverrides(
1097 profile_, extension->GetChromeURLOverrides());
1098
[email protected]b777b332011-04-16 04:01:081099#if defined(OS_CHROMEOS)
1100 // Revoke external file access to
[email protected]55eb70e762012-02-20 17:38:391101 if (BrowserContext::GetFileSystemContext(profile_) &&
1102 BrowserContext::GetFileSystemContext(profile_)->external_provider()) {
1103 BrowserContext::GetFileSystemContext(profile_)->external_provider()->
[email protected]c8d407e2011-04-28 21:27:171104 RevokeAccessForExtension(extension->id());
[email protected]62d30f42009-10-01 22:36:061105 }
[email protected]54ccafa2011-12-06 23:36:321106
1107 if (extension->input_components().size() > 0) {
[email protected]1364c6d2012-07-24 11:57:191108 extensions::InputImeEventRouter::GetInstance()->UnregisterAllImes(
[email protected]54ccafa2011-12-06 23:36:321109 profile_, extension->id());
1110 }
[email protected]c8d407e2011-04-28 21:27:171111#endif
1112
1113 UpdateActiveExtensionsInCrashReporter();
[email protected]2de307592011-04-05 21:16:581114
1115 bool plugins_changed = false;
1116 for (size_t i = 0; i < extension->plugins().size(); ++i) {
1117 const Extension::PluginInfo& plugin = extension->plugins()[i];
[email protected]b6a2f8de2012-01-31 17:28:491118 PluginService::GetInstance()->ForcePluginShutdown(plugin.path);
[email protected]f520b5b2011-11-08 02:42:141119 PluginService::GetInstance()->RefreshPlugins();
1120 PluginService::GetInstance()->RemoveExtraPluginPath(plugin.path);
[email protected]2de307592011-04-05 21:16:581121 plugins_changed = true;
[email protected]476a27032011-09-13 13:40:491122 ChromePluginServiceFilter::GetInstance()->UnrestrictPlugin(plugin.path);
[email protected]2de307592011-04-05 21:16:581123 }
[email protected]84396dbc2011-04-14 06:33:421124
1125 bool nacl_modules_changed = false;
1126 for (size_t i = 0; i < extension->nacl_modules().size(); ++i) {
1127 const Extension::NaClModuleInfo& module = extension->nacl_modules()[i];
[email protected]cebc3dc2011-04-18 17:15:001128 UnregisterNaClModule(module.url);
[email protected]84396dbc2011-04-14 06:33:421129 nacl_modules_changed = true;
1130 }
1131
[email protected]ed0ba002011-05-26 16:55:131132 if (nacl_modules_changed)
1133 UpdatePluginListWithNaClModules();
[email protected]84396dbc2011-04-14 06:33:421134
1135 if (plugins_changed || nacl_modules_changed)
[email protected]45a22e62011-10-12 09:48:021136 PluginService::GetInstance()->PurgePluginListCache(profile_, false);
[email protected]62d30f42009-10-01 22:36:061137}
1138
[email protected]eaa7dd182010-12-14 11:09:001139void ExtensionService::UpdateExtensionBlacklist(
[email protected]6b75ec32009-08-14 06:37:181140 const std::vector<std::string>& blacklist) {
1141 // Use this set to indicate if an extension in the blacklist has been used.
1142 std::set<std::string> blacklist_set;
1143 for (unsigned int i = 0; i < blacklist.size(); ++i) {
[email protected]4ee07c62012-08-21 12:40:421144 if (Extension::IdIsValid(blacklist[i]))
[email protected]6b75ec32009-08-14 06:37:181145 blacklist_set.insert(blacklist[i]);
[email protected]6b75ec32009-08-14 06:37:181146 }
1147 extension_prefs_->UpdateBlacklist(blacklist_set);
[email protected]4ee07c62012-08-21 12:40:421148 CheckManagementPolicy();
[email protected]6b75ec32009-08-14 06:37:181149}
1150
[email protected]0a071a32011-02-08 00:18:241151Profile* ExtensionService::profile() {
1152 return profile_;
1153}
1154
[email protected]45759612012-07-10 17:21:231155extensions::ExtensionPrefs* ExtensionService::extension_prefs() {
[email protected]ddb1e5a2010-12-13 20:10:451156 return extension_prefs_;
1157}
1158
[email protected]0d9a2202011-11-09 13:48:411159extensions::SettingsFrontend* ExtensionService::settings_frontend() {
[email protected]cccdf0aa2011-11-11 03:43:381160 return settings_frontend_.get();
[email protected]b7f853e282011-08-10 09:24:201161}
1162
[email protected]e2d720aa2012-05-17 00:11:351163extensions::ContentSettingsStore* ExtensionService::GetContentSettingsStore() {
[email protected]b790b072011-05-20 09:46:441164 return extension_prefs()->content_settings_store();
1165}
1166
[email protected]25ae0152011-11-18 14:40:021167bool ExtensionService::is_ready() {
1168 return ready_;
1169}
1170
[email protected]42a08162012-03-16 18:09:111171extensions::ExtensionUpdater* ExtensionService::updater() {
[email protected]2859946f2011-04-04 18:18:061172 return updater_.get();
1173}
1174
[email protected]4ee07c62012-08-21 12:40:421175void ExtensionService::CheckManagementPolicy() {
[email protected]aa96d3a2010-08-21 08:45:251176 std::vector<std::string> to_be_removed;
1177 // Loop through extensions list, unload installed extensions.
[email protected]84df8332011-12-06 18:22:461178 for (ExtensionSet::const_iterator iter = extensions_.begin();
[email protected]aa96d3a2010-08-21 08:45:251179 iter != extensions_.end(); ++iter) {
[email protected]9adb9692010-10-29 23:14:021180 const Extension* extension = (*iter);
[email protected]4ee07c62012-08-21 12:40:421181 if (!system_->management_policy()->UserMayLoad(extension, NULL))
[email protected]aa96d3a2010-08-21 08:45:251182 to_be_removed.push_back(extension->id());
1183 }
1184
1185 // UnloadExtension will change the extensions_ list. So, we should
1186 // call it outside the iterator loop.
1187 for (unsigned int i = 0; i < to_be_removed.size(); ++i)
[email protected]814a7bf0f2011-08-13 05:30:591188 UnloadExtension(to_be_removed[i], extension_misc::UNLOAD_REASON_DISABLE);
[email protected]aa96d3a2010-08-21 08:45:251189}
1190
[email protected]31206602011-04-13 23:07:321191void ExtensionService::CheckForUpdatesSoon() {
[email protected]c3cfb012011-04-06 22:07:351192 if (updater()) {
[email protected]94fde232012-04-27 10:22:301193 if (AreAllExternalProvidersReady()) {
1194 updater()->CheckSoon();
1195 } else {
1196 // Sync can start updating before all the external providers are ready
1197 // during startup. Start the update as soon as those providers are ready,
1198 // but not before.
1199 update_once_all_providers_are_ready_ = true;
1200 }
[email protected]c3cfb012011-04-06 22:07:351201 } else {
[email protected]31206602011-04-13 23:07:321202 LOG(WARNING) << "CheckForUpdatesSoon() called with auto-update turned off";
[email protected]c3cfb012011-04-06 22:07:351203 }
1204}
1205
[email protected]65f173552012-06-28 22:43:581206syncer::SyncError ExtensionService::MergeDataAndStartSyncing(
[email protected]a4a147652012-07-03 23:41:321207 syncer::ModelType type,
[email protected]65f173552012-06-28 22:43:581208 const syncer::SyncDataList& initial_sync_data,
1209 scoped_ptr<syncer::SyncChangeProcessor> sync_processor,
1210 scoped_ptr<syncer::SyncErrorFactory> sync_error_factory) {
[email protected]5db9ada2012-04-11 13:48:201211 CHECK(sync_processor.get());
[email protected]5d36e052012-04-20 20:12:281212 CHECK(sync_error_factory.get());
[email protected]3bdba0d2011-08-23 07:17:301213
1214 switch (type) {
[email protected]a4a147652012-07-03 23:41:321215 case syncer::EXTENSIONS:
[email protected]5db9ada2012-04-11 13:48:201216 extension_sync_bundle_.SetupSync(sync_processor.release(),
[email protected]5d36e052012-04-20 20:12:281217 sync_error_factory.release(),
[email protected]5db9ada2012-04-11 13:48:201218 initial_sync_data);
[email protected]3bdba0d2011-08-23 07:17:301219 break;
1220
[email protected]a4a147652012-07-03 23:41:321221 case syncer::APPS:
[email protected]5d36e052012-04-20 20:12:281222 app_sync_bundle_.SetupSync(sync_processor.release(),
1223 sync_error_factory.release(),
1224 initial_sync_data);
[email protected]3bdba0d2011-08-23 07:17:301225 break;
1226
1227 default:
1228 LOG(FATAL) << "Got " << type << " ModelType";
1229 }
[email protected]3bdba0d2011-08-23 07:17:301230
[email protected]b1417ab2011-12-15 17:09:111231 // Process local extensions.
1232 // TODO(yoz): Determine whether pending extensions should be considered too.
1233 // See crbug.com/104399.
[email protected]65f173552012-06-28 22:43:581234 syncer::SyncDataList sync_data_list = GetAllSyncData(type);
1235 syncer::SyncChangeList sync_change_list;
1236 for (syncer::SyncDataList::const_iterator i = sync_data_list.begin();
[email protected]3bdba0d2011-08-23 07:17:301237 i != sync_data_list.end();
1238 ++i) {
[email protected]5db9ada2012-04-11 13:48:201239 switch (type) {
[email protected]a4a147652012-07-03 23:41:321240 case syncer::EXTENSIONS:
[email protected]5db9ada2012-04-11 13:48:201241 sync_change_list.push_back(
1242 extension_sync_bundle_.CreateSyncChange(*i));
1243 break;
[email protected]a4a147652012-07-03 23:41:321244 case syncer::APPS:
[email protected]5db9ada2012-04-11 13:48:201245 sync_change_list.push_back(app_sync_bundle_.CreateSyncChange(*i));
1246 break;
1247 default:
1248 LOG(FATAL) << "Got " << type << " ModelType";
1249 }
[email protected]3bdba0d2011-08-23 07:17:301250 }
[email protected]3bdba0d2011-08-23 07:17:301251
[email protected]5db9ada2012-04-11 13:48:201252
[email protected]a4a147652012-07-03 23:41:321253 if (type == syncer::EXTENSIONS) {
[email protected]5db9ada2012-04-11 13:48:201254 extension_sync_bundle_.ProcessSyncChangeList(sync_change_list);
[email protected]a4a147652012-07-03 23:41:321255 } else if (type == syncer::APPS) {
[email protected]5db9ada2012-04-11 13:48:201256 app_sync_bundle_.ProcessSyncChangeList(sync_change_list);
1257 }
[email protected]0ffd9e52012-01-26 21:44:341258
[email protected]65f173552012-06-28 22:43:581259 return syncer::SyncError();
[email protected]3bdba0d2011-08-23 07:17:301260}
1261
[email protected]a4a147652012-07-03 23:41:321262void ExtensionService::StopSyncing(syncer::ModelType type) {
1263 if (type == syncer::APPS) {
[email protected]5db9ada2012-04-11 13:48:201264 app_sync_bundle_.Reset();
[email protected]a4a147652012-07-03 23:41:321265 } else if (type == syncer::EXTENSIONS) {
[email protected]5db9ada2012-04-11 13:48:201266 extension_sync_bundle_.Reset();
1267 }
[email protected]3bdba0d2011-08-23 07:17:301268}
1269
[email protected]65f173552012-06-28 22:43:581270syncer::SyncDataList ExtensionService::GetAllSyncData(
[email protected]a4a147652012-07-03 23:41:321271 syncer::ModelType type) const {
1272 if (type == syncer::EXTENSIONS) {
[email protected]5db9ada2012-04-11 13:48:201273 return extension_sync_bundle_.GetAllSyncData();
1274
[email protected]a4a147652012-07-03 23:41:321275 } else if (type == syncer::APPS) {
[email protected]5db9ada2012-04-11 13:48:201276 return app_sync_bundle_.GetAllSyncData();
[email protected]3bdba0d2011-08-23 07:17:301277 }
[email protected]5db9ada2012-04-11 13:48:201278
1279 // We should only get sync data for extensions and apps.
1280 NOTREACHED();
1281
[email protected]65f173552012-06-28 22:43:581282 return syncer::SyncDataList();
[email protected]3bdba0d2011-08-23 07:17:301283}
1284
[email protected]65f173552012-06-28 22:43:581285syncer::SyncError ExtensionService::ProcessSyncChanges(
[email protected]3bdba0d2011-08-23 07:17:301286 const tracked_objects::Location& from_here,
[email protected]65f173552012-06-28 22:43:581287 const syncer::SyncChangeList& change_list) {
1288 for (syncer::SyncChangeList::const_iterator i = change_list.begin();
[email protected]3bdba0d2011-08-23 07:17:301289 i != change_list.end();
1290 ++i) {
[email protected]a4a147652012-07-03 23:41:321291 syncer::ModelType type = i->sync_data().GetDataType();
1292 if (type == syncer::EXTENSIONS) {
[email protected]5db9ada2012-04-11 13:48:201293 extension_sync_bundle_.ProcessSyncChange(
1294 extensions::ExtensionSyncData(*i));
[email protected]a4a147652012-07-03 23:41:321295 } else if (type == syncer::APPS) {
[email protected]5db9ada2012-04-11 13:48:201296 app_sync_bundle_.ProcessSyncChange(extensions::AppSyncData(*i));
1297 }
[email protected]3bdba0d2011-08-23 07:17:301298 }
1299
[email protected]0ffd9e52012-01-26 21:44:341300 extension_prefs()->extension_sorting()->FixNTPOrdinalCollisions();
1301
[email protected]65f173552012-06-28 22:43:581302 return syncer::SyncError();
[email protected]b05fb9ff2011-04-23 00:07:561303}
1304
[email protected]5db9ada2012-04-11 13:48:201305extensions::ExtensionSyncData ExtensionService::GetExtensionSyncData(
1306 const Extension& extension) const {
1307 return extensions::ExtensionSyncData(extension,
1308 IsExtensionEnabled(extension.id()),
1309 IsIncognitoEnabled(extension.id()));
[email protected]b05fb9ff2011-04-23 00:07:561310}
1311
[email protected]5db9ada2012-04-11 13:48:201312extensions::AppSyncData ExtensionService::GetAppSyncData(
1313 const Extension& extension) const {
1314 return extensions::AppSyncData(
1315 extension,
1316 IsExtensionEnabled(extension.id()),
1317 IsIncognitoEnabled(extension.id()),
1318 extension_prefs_->GetAppNotificationClientId(extension.id()),
1319 extension_prefs_->IsAppNotificationDisabled(extension.id()),
1320 extension_prefs_->extension_sorting()->GetAppLaunchOrdinal(
1321 extension.id()),
1322 extension_prefs_->extension_sorting()->GetPageOrdinal(extension.id()));
1323}
[email protected]3bdba0d2011-08-23 07:17:301324
[email protected]5db9ada2012-04-11 13:48:201325std::vector<extensions::ExtensionSyncData>
1326 ExtensionService::GetExtensionSyncDataList() const {
1327 std::vector<extensions::ExtensionSyncData> extension_sync_list;
1328 extension_sync_bundle_.GetExtensionSyncDataListHelper(extensions_,
1329 &extension_sync_list);
1330 extension_sync_bundle_.GetExtensionSyncDataListHelper(disabled_extensions_,
1331 &extension_sync_list);
1332 extension_sync_bundle_.GetExtensionSyncDataListHelper(terminated_extensions_,
1333 &extension_sync_list);
1334
1335 std::vector<extensions::ExtensionSyncData> pending_extensions =
1336 extension_sync_bundle_.GetPendingData();
1337 extension_sync_list.insert(extension_sync_list.begin(),
1338 pending_extensions.begin(),
1339 pending_extensions.end());
[email protected]3bdba0d2011-08-23 07:17:301340
1341 return extension_sync_list;
[email protected]b05fb9ff2011-04-23 00:07:561342}
1343
[email protected]5db9ada2012-04-11 13:48:201344std::vector<extensions::AppSyncData> ExtensionService::GetAppSyncDataList()
1345 const {
1346 std::vector<extensions::AppSyncData> app_sync_list;
1347 app_sync_bundle_.GetAppSyncDataListHelper(extensions_, &app_sync_list);
1348 app_sync_bundle_.GetAppSyncDataListHelper(disabled_extensions_,
1349 &app_sync_list);
1350 app_sync_bundle_.GetAppSyncDataListHelper(terminated_extensions_,
1351 &app_sync_list);
1352
1353 std::vector<extensions::AppSyncData> pending_apps =
1354 app_sync_bundle_.GetPendingData();
1355 app_sync_list.insert(app_sync_list.begin(),
1356 pending_apps.begin(),
1357 pending_apps.end());
1358
1359 return app_sync_list;
1360}
1361
1362bool ExtensionService::ProcessExtensionSyncData(
1363 const extensions::ExtensionSyncData& extension_sync_data) {
1364 if (!ProcessExtensionSyncDataHelper(extension_sync_data,
[email protected]a4a147652012-07-03 23:41:321365 syncer::EXTENSIONS)) {
[email protected]5db9ada2012-04-11 13:48:201366 extension_sync_bundle_.AddPendingExtension(extension_sync_data.id(),
1367 extension_sync_data);
1368 CheckForUpdatesSoon();
1369 return false;
1370 }
1371
1372 return true;
1373}
1374
1375bool ExtensionService::ProcessAppSyncData(
1376 const extensions::AppSyncData& app_sync_data) {
1377 const std::string& id = app_sync_data.id();
1378 const Extension* extension = GetInstalledExtension(id);
1379 bool extension_installed = (extension != NULL);
1380
1381 if (app_sync_data.app_launch_ordinal().IsValid() &&
1382 app_sync_data.page_ordinal().IsValid()) {
1383 extension_prefs_->extension_sorting()->SetAppLaunchOrdinal(
1384 id,
1385 app_sync_data.app_launch_ordinal());
1386 extension_prefs_->extension_sorting()->SetPageOrdinal(
1387 id,
1388 app_sync_data.page_ordinal());
1389 }
1390
1391 if (extension_installed) {
1392 if (app_sync_data.notifications_disabled() !=
1393 extension_prefs_->IsAppNotificationDisabled(id)) {
1394 extension_prefs_->SetAppNotificationDisabled(
1395 id, app_sync_data.notifications_disabled());
1396 }
1397 }
1398
1399 if (!ProcessExtensionSyncDataHelper(app_sync_data.extension_sync_data(),
[email protected]a4a147652012-07-03 23:41:321400 syncer::APPS)) {
[email protected]5db9ada2012-04-11 13:48:201401 app_sync_bundle_.AddPendingApp(id, app_sync_data);
1402 CheckForUpdatesSoon();
1403 return false;
1404 }
1405
1406 return true;
1407}
1408
1409bool ExtensionService::IsCorrectSyncType(const Extension& extension,
[email protected]a4a147652012-07-03 23:41:321410 syncer::ModelType type) const {
1411 if (type == syncer::EXTENSIONS &&
[email protected]5db9ada2012-04-11 13:48:201412 extension.GetSyncType() == Extension::SYNC_TYPE_EXTENSION)
1413 return true;
1414
[email protected]a4a147652012-07-03 23:41:321415 if (type == syncer::APPS &&
[email protected]5db9ada2012-04-11 13:48:201416 extension.GetSyncType() == Extension::SYNC_TYPE_APP)
1417 return true;
1418
1419 return false;
1420}
1421
1422bool ExtensionService::ProcessExtensionSyncDataHelper(
1423 const extensions::ExtensionSyncData& extension_sync_data,
[email protected]a4a147652012-07-03 23:41:321424 syncer::ModelType type) {
[email protected]3bdba0d2011-08-23 07:17:301425 const std::string& id = extension_sync_data.id();
[email protected]96e989b2011-08-30 19:35:061426 const Extension* extension = GetInstalledExtension(id);
1427
1428 // TODO(bolms): we should really handle this better. The particularly bad
1429 // case is where an app becomes an extension or vice versa, and we end up with
1430 // a zombie extension that won't go away.
[email protected]5db9ada2012-04-11 13:48:201431 if (extension && !IsCorrectSyncType(*extension, type))
1432 return true;
[email protected]90310d92011-04-17 07:35:041433
1434 // Handle uninstalls first.
[email protected]3bdba0d2011-08-23 07:17:301435 if (extension_sync_data.uninstalled()) {
[email protected]90310d92011-04-17 07:35:041436 std::string error;
1437 if (!UninstallExtensionHelper(this, id)) {
1438 LOG(WARNING) << "Could not uninstall extension " << id
1439 << " for sync";
1440 }
[email protected]5db9ada2012-04-11 13:48:201441 return true;
[email protected]90310d92011-04-17 07:35:041442 }
1443
[email protected]caf2d442012-05-04 10:00:501444 // Extension from sync was uninstalled by the user as external extensions.
1445 // Honor user choice and skip installation/enabling.
1446 if (IsExternalExtensionUninstalled(id)) {
1447 LOG(WARNING) << "Extension with id " << id
1448 << " from sync was uninstalled as external extension";
1449 return true;
1450 }
1451
[email protected]06f92562011-04-29 19:27:311452 // Set user settings.
[email protected]3bdba0d2011-08-23 07:17:301453 if (extension_sync_data.enabled()) {
[email protected]06f92562011-04-29 19:27:311454 EnableExtension(id);
1455 } else {
[email protected]44d62b62012-04-11 00:06:031456 DisableExtension(id, Extension::DISABLE_USER_ACTION);
[email protected]06f92562011-04-29 19:27:311457 }
[email protected]81b14cc2011-04-29 00:39:371458
[email protected]406b5a92011-11-08 11:58:261459 // We need to cache some version information here because setting the
1460 // incognito flag invalidates the |extension| pointer (it reloads the
1461 // extension).
[email protected]9060d8b02012-01-13 02:14:301462 bool extension_installed = (extension != NULL);
[email protected]406b5a92011-11-08 11:58:261463 int result = extension ?
1464 extension->version()->CompareTo(extension_sync_data.version()) : 0;
1465 SetIsIncognitoEnabled(id, extension_sync_data.incognito_enabled());
1466 extension = NULL; // No longer safe to use.
1467
1468 if (extension_installed) {
[email protected]06f92562011-04-29 19:27:311469 // If the extension is already installed, check if it's outdated.
[email protected]90310d92011-04-17 07:35:041470 if (result < 0) {
1471 // Extension is outdated.
[email protected]5db9ada2012-04-11 13:48:201472 return false;
[email protected]b020dc12011-12-06 04:35:421473 }
[email protected]06f92562011-04-29 19:27:311474 } else {
[email protected]06f92562011-04-29 19:27:311475 // TODO(akalin): Replace silent update with a list of enabled
1476 // permissions.
[email protected]6cc7dbae2011-04-29 21:18:331477 const bool kInstallSilently = true;
[email protected]5db9ada2012-04-11 13:48:201478
[email protected]a4a147652012-07-03 23:41:321479 CHECK(type == syncer::EXTENSIONS || type == syncer::APPS);
[email protected]5db9ada2012-04-11 13:48:201480 ExtensionFilter filter =
[email protected]a4a147652012-07-03 23:41:321481 (type == syncer::APPS) ? IsSyncableApp : IsSyncableExtension;
[email protected]5db9ada2012-04-11 13:48:201482
[email protected]06f92562011-04-29 19:27:311483 if (!pending_extension_manager()->AddFromSync(
1484 id,
[email protected]3bdba0d2011-08-23 07:17:301485 extension_sync_data.update_url(),
[email protected]5db9ada2012-04-11 13:48:201486 filter,
[email protected]6cc7dbae2011-04-29 21:18:331487 kInstallSilently)) {
[email protected]06f92562011-04-29 19:27:311488 LOG(WARNING) << "Could not add pending extension for " << id;
[email protected]3bdba0d2011-08-23 07:17:301489 // This means that the extension is already pending installation, with a
1490 // non-INTERNAL location. Add to pending_sync_data, even though it will
1491 // never be removed (we'll never install a syncable version of the
1492 // extension), so that GetAllSyncData() continues to send it.
[email protected]06f92562011-04-29 19:27:311493 }
[email protected]3bdba0d2011-08-23 07:17:301494 // Track pending extensions so that we can return them in GetAllSyncData().
[email protected]5db9ada2012-04-11 13:48:201495 return false;
[email protected]90310d92011-04-17 07:35:041496 }
[email protected]5db9ada2012-04-11 13:48:201497
1498 return true;
[email protected]90310d92011-04-17 07:35:041499}
1500
[email protected]c3cfb012011-04-06 22:07:351501bool ExtensionService::IsIncognitoEnabled(
1502 const std::string& extension_id) const {
1503 // If this is an existing component extension we always allow it to
1504 // work in incognito mode.
[email protected]81b14cc2011-04-29 00:39:371505 const Extension* extension = GetInstalledExtension(extension_id);
[email protected]c3cfb012011-04-06 22:07:351506 if (extension && extension->location() == Extension::COMPONENT)
[email protected]cb0ce1e022010-03-10 19:54:411507 return true;
1508
1509 // Check the prefs.
[email protected]c3cfb012011-04-06 22:07:351510 return extension_prefs_->IsIncognitoEnabled(extension_id);
[email protected]db7331a2010-02-25 22:10:501511}
[email protected]55a35692010-02-11 23:25:211512
[email protected]c3cfb012011-04-06 22:07:351513void ExtensionService::SetIsIncognitoEnabled(
1514 const std::string& extension_id, bool enabled) {
[email protected]81b14cc2011-04-29 00:39:371515 const Extension* extension = GetInstalledExtension(extension_id);
[email protected]c3cfb012011-04-06 22:07:351516 if (extension && extension->location() == Extension::COMPONENT) {
[email protected]b873cd92012-02-09 21:51:481517 // This shouldn't be called for component extensions unless they are
1518 // syncable.
1519 DCHECK(extension->IsSyncable());
1520
1521 // If we are here, make sure the we aren't trying to change the value.
1522 DCHECK_EQ(enabled, IsIncognitoEnabled(extension_id));
1523
[email protected]c3cfb012011-04-06 22:07:351524 return;
1525 }
1526
[email protected]8c6c8c22011-03-09 12:52:341527 // Broadcast unloaded and loaded events to update browser state. Only bother
1528 // if the value changed and the extension is actually enabled, since there is
1529 // no UI otherwise.
[email protected]c3cfb012011-04-06 22:07:351530 bool old_enabled = extension_prefs_->IsIncognitoEnabled(extension_id);
[email protected]8c6c8c22011-03-09 12:52:341531 if (enabled == old_enabled)
1532 return;
1533
[email protected]c3cfb012011-04-06 22:07:351534 extension_prefs_->SetIsIncognitoEnabled(extension_id, enabled);
[email protected]81b14cc2011-04-29 00:39:371535
[email protected]ffbf3f12011-12-09 22:10:331536 bool extension_is_enabled = extensions_.Contains(extension_id);
[email protected]bd9892eb2011-11-11 19:41:341537
1538 // When we reload the extension the ID may be invalidated if we've passed it
1539 // by const ref everywhere. Make a copy to be safe.
1540 std::string id = extension_id;
[email protected]406b5a92011-11-08 11:58:261541 if (extension_is_enabled)
[email protected]ffbf3f12011-12-09 22:10:331542 ReloadExtension(id);
[email protected]3bdba0d2011-08-23 07:17:301543
[email protected]406b5a92011-11-08 11:58:261544 // Reloading the extension invalidates the |extension| pointer.
[email protected]bd9892eb2011-11-11 19:41:341545 extension = GetInstalledExtension(id);
[email protected]3bdba0d2011-08-23 07:17:301546 if (extension)
1547 SyncExtensionChangeIfNeeded(*extension);
[email protected]55a35692010-02-11 23:25:211548}
1549
[email protected]aa7599d2011-10-28 07:24:321550void ExtensionService::SetAppNotificationSetupDone(
1551 const std::string& extension_id,
[email protected]b2689a902011-12-01 00:41:091552 const std::string& oauth_client_id) {
[email protected]aa7599d2011-10-28 07:24:321553 const Extension* extension = GetInstalledExtension(extension_id);
1554 // This method is called when the user sets up app notifications.
1555 // So it is not expected to be called until the extension is installed.
1556 if (!extension) {
1557 NOTREACHED();
1558 return;
1559 }
[email protected]b2689a902011-12-01 00:41:091560 extension_prefs_->SetAppNotificationClientId(extension_id, oauth_client_id);
[email protected]aa7599d2011-10-28 07:24:321561 SyncExtensionChangeIfNeeded(*extension);
1562}
1563
1564void ExtensionService::SetAppNotificationDisabled(
1565 const std::string& extension_id,
1566 bool value) {
1567 const Extension* extension = GetInstalledExtension(extension_id);
1568 // This method is called when the user enables/disables app notifications.
1569 // So it is not expected to be called until the extension is installed.
1570 if (!extension) {
1571 NOTREACHED();
1572 return;
1573 }
[email protected]97e856b12011-12-14 00:21:131574 if (value)
1575 UMA_HISTOGRAM_COUNTS("Apps.SetAppNotificationsDisabled", 1);
1576 else
1577 UMA_HISTOGRAM_COUNTS("Apps.SetAppNotificationsEnabled", 1);
[email protected]aa7599d2011-10-28 07:24:321578 extension_prefs_->SetAppNotificationDisabled(extension_id, value);
1579 SyncExtensionChangeIfNeeded(*extension);
1580}
1581
[email protected]dc9a74f72012-08-17 18:07:211582bool ExtensionService::CanCrossIncognito(const Extension* extension) const {
[email protected]2a8f24e2010-11-03 21:37:051583 // We allow the extension to see events and data from another profile iff it
1584 // uses "spanning" behavior and it has incognito access. "split" mode
1585 // extensions only see events for a matching profile.
[email protected]0c41298f2011-09-13 21:17:221586 CHECK(extension);
[email protected]c3cfb012011-04-06 22:07:351587 return IsIncognitoEnabled(extension->id()) &&
1588 !extension->incognito_split_mode();
[email protected]2a8f24e2010-11-03 21:37:051589}
1590
[email protected]5ef7b002011-05-12 23:16:201591bool ExtensionService::CanLoadInIncognito(const Extension* extension) const {
1592 if (extension->is_hosted_app())
1593 return true;
1594 // Packaged apps and regular extensions need to be enabled specifically for
1595 // incognito (and split mode should be set).
1596 return extension->incognito_split_mode() &&
1597 IsIncognitoEnabled(extension->id());
1598}
1599
[email protected]168389f2011-12-20 17:12:481600void ExtensionService::OnExtensionMoved(
1601 const std::string& moved_extension_id,
1602 const std::string& predecessor_extension_id,
1603 const std::string& successor_extension_id) {
[email protected]3569b502012-01-12 20:08:231604 extension_prefs_->extension_sorting()->OnExtensionMoved(
1605 moved_extension_id,
1606 predecessor_extension_id,
1607 successor_extension_id);
[email protected]168389f2011-12-20 17:12:481608
1609 const Extension* extension = GetInstalledExtension(moved_extension_id);
1610 if (extension)
1611 SyncExtensionChangeIfNeeded(*extension);
1612}
1613
[email protected]dc9a74f72012-08-17 18:07:211614bool ExtensionService::AllowFileAccess(const Extension* extension) const {
[email protected]05c82182010-06-24 17:49:081615 return (CommandLine::ForCurrentProcess()->HasSwitch(
[email protected]334e04a2010-06-24 23:34:441616 switches::kDisableExtensionsFileAccessCheck) ||
[email protected]05c82182010-06-24 17:49:081617 extension_prefs_->AllowFileAccess(extension->id()));
1618}
1619
[email protected]eaa7dd182010-12-14 11:09:001620void ExtensionService::SetAllowFileAccess(const Extension* extension,
[email protected]3aff9ad2011-04-01 20:26:481621 bool allow) {
1622 // Reload to update browser state. Only bother if the value changed and the
1623 // extension is actually enabled, since there is no UI otherwise.
1624 bool old_allow = AllowFileAccess(extension);
1625 if (allow == old_allow)
1626 return;
1627
[email protected]05c82182010-06-24 17:49:081628 extension_prefs_->SetAllowFileAccess(extension->id(), allow);
[email protected]3aff9ad2011-04-01 20:26:481629
[email protected]84df8332011-12-06 18:22:461630 bool extension_is_enabled = extensions_.Contains(extension->id());
[email protected]3aff9ad2011-04-01 20:26:481631 if (extension_is_enabled)
1632 ReloadExtension(extension->id());
[email protected]05c82182010-06-24 17:49:081633}
1634
[email protected]8e4560b62011-01-14 10:09:141635// Some extensions will autoupdate themselves externally from Chrome. These
1636// are typically part of some larger client application package. To support
1637// these, the extension will register its location in the the preferences file
1638// (and also, on Windows, in the registry) and this code will periodically
1639// check that location for a .crx file, which it will then install locally if
1640// a new version is available.
1641// Errors are reported through ExtensionErrorReporter. Succcess is not
1642// reported.
[email protected]eaa7dd182010-12-14 11:09:001643void ExtensionService::CheckForExternalUpdates() {
[email protected]a29a517a2011-01-21 21:11:121644 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]8e4560b62011-01-14 10:09:141645
1646 // Note that this installation is intentionally silent (since it didn't
1647 // go through the front-end). Extensions that are registered in this
1648 // way are effectively considered 'pre-bundled', and so implicitly
1649 // trusted. In general, if something has HKLM or filesystem access,
1650 // they could install an extension manually themselves anyway.
[email protected]a29a517a2011-01-21 21:11:121651
[email protected]8e4560b62011-01-14 10:09:141652 // Ask each external extension provider to give us a call back for each
1653 // extension they know about. See OnExternalExtension(File|UpdateUrl)Found.
[email protected]5df038b2012-07-16 19:03:271654 extensions::ProviderCollection::const_iterator i;
[email protected]8e4560b62011-01-14 10:09:141655 for (i = external_extension_providers_.begin();
1656 i != external_extension_providers_.end(); ++i) {
[email protected]5df038b2012-07-16 19:03:271657 extensions::ExternalProviderInterface* provider = i->get();
[email protected]8e4560b62011-01-14 10:09:141658 provider->VisitRegisteredExtension();
1659 }
1660
[email protected]50067e52011-10-20 23:17:071661 // Do any required work that we would have done after completion of all
1662 // providers.
1663 if (external_extension_providers_.empty()) {
1664 OnAllExternalProvidersReady();
1665 }
[email protected]9f1087e2009-06-15 17:29:321666}
1667
[email protected]50067e52011-10-20 23:17:071668void ExtensionService::OnExternalProviderReady(
[email protected]5df038b2012-07-16 19:03:271669 const extensions::ExternalProviderInterface* provider) {
[email protected]a29a517a2011-01-21 21:11:121670 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]50067e52011-10-20 23:17:071671 CHECK(provider->IsReady());
[email protected]a29a517a2011-01-21 21:11:121672
1673 // An external provider has finished loading. We only take action
[email protected]8e4560b62011-01-14 10:09:141674 // if all of them are finished. So we check them first.
[email protected]94fde232012-04-27 10:22:301675 if (AreAllExternalProvidersReady())
1676 OnAllExternalProvidersReady();
1677}
1678
1679bool ExtensionService::AreAllExternalProvidersReady() const {
[email protected]5df038b2012-07-16 19:03:271680 extensions::ProviderCollection::const_iterator i;
[email protected]8e4560b62011-01-14 10:09:141681 for (i = external_extension_providers_.begin();
1682 i != external_extension_providers_.end(); ++i) {
[email protected]94fde232012-04-27 10:22:301683 if (!i->get()->IsReady())
1684 return false;
[email protected]8e4560b62011-01-14 10:09:141685 }
[email protected]94fde232012-04-27 10:22:301686 return true;
[email protected]50067e52011-10-20 23:17:071687}
1688
1689void ExtensionService::OnAllExternalProvidersReady() {
1690 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]94fde232012-04-27 10:22:301691 base::TimeDelta elapsed = base::Time::Now() - profile_->GetStartTime();
1692 UMA_HISTOGRAM_TIMES("Extension.ExternalProvidersReadyAfter", elapsed);
[email protected]50067e52011-10-20 23:17:071693
1694 // Install any pending extensions.
[email protected]94fde232012-04-27 10:22:301695 if (update_once_all_providers_are_ready_ && updater()) {
1696 update_once_all_providers_are_ready_ = false;
[email protected]8e4560b62011-01-14 10:09:141697 updater()->CheckNow();
1698 }
1699
1700 // Uninstall all the unclaimed extensions.
[email protected]45759612012-07-10 17:21:231701 scoped_ptr<extensions::ExtensionPrefs::ExtensionsInfo> extensions_info(
[email protected]8e4560b62011-01-14 10:09:141702 extension_prefs_->GetInstalledExtensionsInfo());
1703 for (size_t i = 0; i < extensions_info->size(); ++i) {
1704 ExtensionInfo* info = extensions_info->at(i).get();
1705 if (Extension::IsExternalLocation(info->extension_location))
1706 CheckExternalUninstall(info->extension_id);
1707 }
[email protected]e5af875f2011-10-10 21:09:141708 IdentifyAlertableExtensions();
[email protected]e5af875f2011-10-10 21:09:141709}
1710
1711void ExtensionService::IdentifyAlertableExtensions() {
1712 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1713
[email protected]07c9f2f42012-02-29 18:45:221714 // Build up the lists of extensions that require acknowledgment. If this is
1715 // the first time, grandfather extensions that would have caused
1716 // notification.
[email protected]89226982012-07-16 20:09:181717 extension_error_ui_.reset(ExtensionErrorUI::Create(this));
[email protected]e5af875f2011-10-10 21:09:141718
[email protected]a9aa5932012-01-25 08:27:401719 bool did_show_alert = false;
[email protected]89226982012-07-16 20:09:181720 if (PopulateExtensionErrorUI(extension_error_ui_.get())) {
[email protected]e5af875f2011-10-10 21:09:141721 if (extension_prefs_->SetAlertSystemFirstRun()) {
[email protected]a9aa5932012-01-25 08:27:401722 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]89226982012-07-16 20:09:181723 did_show_alert = extension_error_ui_->ShowErrorInBubbleView();
[email protected]e5af875f2011-10-10 21:09:141724 } else {
1725 // First run. Just acknowledge all the extensions, silently, by
1726 // shortcutting the display of the UI and going straight to the
1727 // callback for pressing the Accept button.
[email protected]a9aa5932012-01-25 08:27:401728 HandleExtensionAlertAccept();
[email protected]e5af875f2011-10-10 21:09:141729 }
1730 }
[email protected]a9aa5932012-01-25 08:27:401731
1732 if (!did_show_alert)
[email protected]89226982012-07-16 20:09:181733 extension_error_ui_.reset();
[email protected]e5af875f2011-10-10 21:09:141734}
1735
[email protected]89226982012-07-16 20:09:181736bool ExtensionService::PopulateExtensionErrorUI(
1737 ExtensionErrorUI* extension_error_ui) {
[email protected]07c9f2f42012-02-29 18:45:221738 bool needs_alert = false;
1739 for (ExtensionSet::const_iterator iter = extensions_.begin();
1740 iter != extensions_.end(); ++iter) {
1741 const Extension* e = *iter;
1742 if (Extension::IsExternalLocation(e->location())) {
1743 if (!e->is_hosted_app()) {
1744 if (!extension_prefs_->IsExternalExtensionAcknowledged(e->id())) {
[email protected]89226982012-07-16 20:09:181745 extension_error_ui->AddExternalExtension(e->id());
[email protected]07c9f2f42012-02-29 18:45:221746 needs_alert = true;
1747 }
1748 }
1749 }
[email protected]4ee07c62012-08-21 12:40:421750 if (!extension_prefs_->UserMayLoad(e, NULL)) {
[email protected]07c9f2f42012-02-29 18:45:221751 if (!extension_prefs_->IsBlacklistedExtensionAcknowledged(e->id())) {
[email protected]89226982012-07-16 20:09:181752 extension_error_ui->AddBlacklistedExtension(e->id());
[email protected]07c9f2f42012-02-29 18:45:221753 needs_alert = true;
1754 }
1755 }
1756 if (extension_prefs_->IsExtensionOrphaned(e->id())) {
1757 if (!extension_prefs_->IsOrphanedExtensionAcknowledged(e->id())) {
[email protected]89226982012-07-16 20:09:181758 extension_error_ui->AddOrphanedExtension(e->id());
[email protected]07c9f2f42012-02-29 18:45:221759 needs_alert = true;
1760 }
1761 }
1762 }
1763 return needs_alert;
1764}
1765
[email protected]a9aa5932012-01-25 08:27:401766void ExtensionService::HandleExtensionAlertClosed() {
[email protected]89226982012-07-16 20:09:181767 extension_error_ui_.reset();
[email protected]62433d32011-10-12 22:33:121768}
1769
[email protected]a9aa5932012-01-25 08:27:401770void ExtensionService::HandleExtensionAlertAccept() {
[email protected]e5af875f2011-10-10 21:09:141771 const ExtensionIdSet *extension_ids =
[email protected]89226982012-07-16 20:09:181772 extension_error_ui_->get_external_extension_ids();
[email protected]e5af875f2011-10-10 21:09:141773 for (ExtensionIdSet::const_iterator iter = extension_ids->begin();
1774 iter != extension_ids->end(); ++iter) {
[email protected]47fc70c2011-12-06 07:29:511775 AcknowledgeExternalExtension(*iter);
[email protected]e5af875f2011-10-10 21:09:141776 }
[email protected]89226982012-07-16 20:09:181777 extension_ids = extension_error_ui_->get_blacklisted_extension_ids();
[email protected]e5af875f2011-10-10 21:09:141778 for (ExtensionIdSet::const_iterator iter = extension_ids->begin();
1779 iter != extension_ids->end(); ++iter) {
1780 extension_prefs_->AcknowledgeBlacklistedExtension(*iter);
1781 }
[email protected]89226982012-07-16 20:09:181782 extension_ids = extension_error_ui_->get_orphaned_extension_ids();
[email protected]e5af875f2011-10-10 21:09:141783 for (ExtensionIdSet::const_iterator iter = extension_ids->begin();
1784 iter != extension_ids->end(); ++iter) {
1785 extension_prefs_->AcknowledgeOrphanedExtension(*iter);
1786 }
1787}
1788
[email protected]47fc70c2011-12-06 07:29:511789void ExtensionService::AcknowledgeExternalExtension(const std::string& id) {
1790 extension_prefs_->AcknowledgeExternalExtension(id);
1791}
1792
[email protected]89226982012-07-16 20:09:181793void ExtensionService::HandleExtensionAlertDetails() {
1794 extension_error_ui_->ShowExtensions();
[email protected]6c751e72010-11-23 10:11:101795}
1796
[email protected]a9f39a312010-12-23 22:14:271797void ExtensionService::UnloadExtension(
1798 const std::string& extension_id,
[email protected]814a7bf0f2011-08-13 05:30:591799 extension_misc::UnloadedExtensionReason reason) {
[email protected]27e469a2010-01-11 20:35:091800 // Make sure the extension gets deleted after we return from this function.
[email protected]81f0d162012-08-15 04:21:471801 int include_mask = INCLUDE_ENABLED;
1802 include_mask |= INCLUDE_DISABLED;
[email protected]9adb9692010-10-29 23:14:021803 scoped_refptr<const Extension> extension(
[email protected]81f0d162012-08-15 04:21:471804 GetExtensionByIdInternal(extension_id, include_mask));
[email protected]631cf822009-05-15 07:01:251805
[email protected]fa0c96732010-11-17 00:14:231806 // This method can be called via PostTask, so the extension may have been
1807 // unloaded by the time this runs.
[email protected]dd163fb02011-05-04 22:22:171808 if (!extension) {
1809 // In case the extension may have crashed/uninstalled. Allow the profile to
1810 // clean up its RequestContexts.
[email protected]31d8f5f22012-04-02 15:22:081811 system_->UnregisterExtensionWithRequestContexts(extension_id, reason);
[email protected]fa0c96732010-11-17 00:14:231812 return;
[email protected]dd163fb02011-05-04 22:22:171813 }
[email protected]0c6da502009-08-14 22:32:391814
[email protected]1eb175082010-02-10 09:26:161815 // Keep information about the extension so that we can reload it later
1816 // even if it's not permanently installed.
1817 unloaded_extension_paths_[extension->id()] = extension->path();
1818
[email protected]f17dbd42010-08-16 23:21:101819 // Clean up if the extension is meant to be enabled after a reload.
1820 disabled_extension_paths_.erase(extension->id());
1821
[email protected]d7e9a862010-11-03 21:57:491822 // Clean up runtime data.
1823 extension_runtime_data_.erase(extension_id);
1824
[email protected]060d4972012-07-19 17:22:391825 if (disabled_extensions_.Contains(extension->id())) {
[email protected]a9f39a312010-12-23 22:14:271826 UnloadedExtensionInfo details(extension, reason);
1827 details.already_disabled = true;
[email protected]84df8332011-12-06 18:22:461828 disabled_extensions_.Remove(extension->id());
[email protected]ad50def52011-10-19 23:17:071829 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271830 chrome::NOTIFICATION_EXTENSION_UNLOADED,
[email protected]6c2381d2011-10-19 02:52:531831 content::Source<Profile>(profile_),
1832 content::Details<UnloadedExtensionInfo>(&details));
[email protected]dd163fb02011-05-04 22:22:171833 // Make sure the profile cleans up its RequestContexts when an already
1834 // disabled extension is unloaded (since they are also tracking the disabled
1835 // extensions).
[email protected]31d8f5f22012-04-02 15:22:081836 system_->UnregisterExtensionWithRequestContexts(extension_id, reason);
[email protected]0c6da502009-08-14 22:32:391837 return;
1838 }
1839
[email protected]060d4972012-07-19 17:22:391840 // Remove the extension from our list.
[email protected]84df8332011-12-06 18:22:461841 extensions_.Remove(extension->id());
[email protected]631cf822009-05-15 07:01:251842
[email protected]a9f39a312010-12-23 22:14:271843 NotifyExtensionUnloaded(extension.get(), reason);
[email protected]631cf822009-05-15 07:01:251844}
1845
[email protected]eaa7dd182010-12-14 11:09:001846void ExtensionService::UnloadAllExtensions() {
[email protected]c8d407e2011-04-28 21:27:171847 profile_->GetExtensionSpecialStoragePolicy()->
1848 RevokeRightsForAllExtensions();
1849
[email protected]84df8332011-12-06 18:22:461850 extensions_.Clear();
1851 disabled_extensions_.Clear();
1852 terminated_extensions_.Clear();
[email protected]d7e9a862010-11-03 21:57:491853 extension_runtime_data_.clear();
[email protected]cd500f72010-06-25 23:44:321854
[email protected]c6e4a3412009-06-24 15:45:291855 // TODO(erikkay) should there be a notification for this? We can't use
1856 // EXTENSION_UNLOADED since that implies that the extension has been disabled
1857 // or uninstalled, and UnloadAll is just part of shutdown.
[email protected]9f1087e2009-06-15 17:29:321858}
1859
[email protected]eaa7dd182010-12-14 11:09:001860void ExtensionService::ReloadExtensions() {
[email protected]9f1087e2009-06-15 17:29:321861 UnloadAllExtensions();
[email protected]d8c8f25f2011-11-02 18:18:011862 component_loader_->LoadAll();
1863 extensions::InstalledLoader(this).LoadAllExtensions();
[email protected]9f1087e2009-06-15 17:29:321864}
1865
[email protected]eaa7dd182010-12-14 11:09:001866void ExtensionService::GarbageCollectExtensions() {
[email protected]2f8757c32012-06-19 19:17:471867 if (extension_prefs_->pref_service()->ReadOnly())
1868 return;
1869
[email protected]45759612012-07-10 17:21:231870 scoped_ptr<extensions::ExtensionPrefs::ExtensionsInfo> info(
[email protected]2f8757c32012-06-19 19:17:471871 extension_prefs_->GetInstalledExtensionsInfo());
1872
1873 std::map<std::string, FilePath> extension_paths;
1874 for (size_t i = 0; i < info->size(); ++i)
1875 extension_paths[info->at(i)->extension_id] = info->at(i)->extension_path;
1876
1877 if (!BrowserThread::PostTask(
1878 BrowserThread::FILE, FROM_HERE,
1879 base::Bind(
1880 &extension_file_util::GarbageCollectExtensions,
1881 install_directory_,
1882 extension_paths)))
1883 NOTREACHED();
[email protected]f6ccd652010-11-17 00:48:341884
[email protected]f766a9d2012-07-11 01:57:441885#if defined(ENABLE_THEMES)
[email protected]f6ccd652010-11-17 00:48:341886 // Also garbage-collect themes. We check |profile_| to be
1887 // defensive; in the future, we may call GarbageCollectExtensions()
1888 // from somewhere other than Init() (e.g., in a timer).
1889 if (profile_) {
[email protected]18280372011-03-22 18:05:221890 ThemeServiceFactory::GetForProfile(profile_)->RemoveUnusedThemes();
[email protected]f6ccd652010-11-17 00:48:341891 }
[email protected]f766a9d2012-07-11 01:57:441892#endif
[email protected]3cf4f0992009-02-03 23:00:301893}
1894
[email protected]fb82dcd2012-03-21 14:15:461895void ExtensionService::SyncExtensionChangeIfNeeded(const Extension& extension) {
[email protected]5db9ada2012-04-11 13:48:201896 if (app_sync_bundle_.HandlesApp(extension)) {
1897 app_sync_bundle_.SyncChangeIfNeeded(extension);
1898 } else if (extension_sync_bundle_.HandlesExtension(extension)) {
1899 extension_sync_bundle_.SyncChangeIfNeeded(extension);
[email protected]fb82dcd2012-03-21 14:15:461900 }
1901}
1902
[email protected]eaa7dd182010-12-14 11:09:001903void ExtensionService::OnLoadedInstalledExtensions() {
[email protected]93fd78f42009-07-10 16:43:171904 if (updater_.get()) {
1905 updater_->Start();
1906 }
[email protected]fa6a9102010-11-22 15:38:501907
1908 ready_ = true;
[email protected]ad50def52011-10-19 23:17:071909 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271910 chrome::NOTIFICATION_EXTENSIONS_READY,
[email protected]6c2381d2011-10-19 02:52:531911 content::Source<Profile>(profile_),
[email protected]ad50def52011-10-19 23:17:071912 content::NotificationService::NoDetails());
[email protected]e72e8eb82009-06-18 17:21:511913}
1914
[email protected]fcb58a862012-05-01 01:03:151915void ExtensionService::AddExtension(const Extension* extension) {
[email protected]ae09ca62009-08-21 19:46:461916 // Ensure extension is deleted unless we transfer ownership.
[email protected]9adb9692010-10-29 23:14:021917 scoped_refptr<const Extension> scoped_extension(extension);
[email protected]9f1087e2009-06-15 17:29:321918
[email protected]c8d407e2011-04-28 21:27:171919 // TODO(jstritar): We may be able to get rid of this branch by overriding the
1920 // default extension state to DISABLED when the --disable-extensions flag
1921 // is set (http://crbug.com/29067).
1922 if (!extensions_enabled() &&
1923 !extension->is_theme() &&
1924 extension->location() != Extension::COMPONENT &&
1925 !Extension::IsExternalLocation(extension->location()))
[email protected]fcb58a862012-05-01 01:03:151926 return;
[email protected]c8d407e2011-04-28 21:27:171927
1928 SetBeingUpgraded(extension, false);
1929
[email protected]1eb175082010-02-10 09:26:161930 // The extension is now loaded, remove its data from unloaded extension map.
1931 unloaded_extension_paths_.erase(extension->id());
1932
[email protected]bb7f40952011-01-13 00:21:201933 // If a terminated extension is loaded, remove it from the terminated list.
1934 UntrackTerminatedExtension(extension->id());
1935
[email protected]f17dbd42010-08-16 23:21:101936 // If the extension was disabled for a reload, then enable it.
1937 if (disabled_extension_paths_.erase(extension->id()) > 0)
1938 EnableExtension(extension->id());
1939
[email protected]d728e002010-12-08 04:46:231940 // Check if the extension's privileges have changed and disable the
1941 // extension if necessary.
[email protected]902fd7b2011-07-27 18:42:311942 InitializePermissions(extension);
[email protected]0c6da502009-08-14 22:32:391943
[email protected]ad83ca242011-07-29 01:32:251944 bool disabled = extension_prefs_->IsExtensionDisabled(extension->id());
[email protected]36429da2011-07-11 20:25:181945 if (disabled) {
[email protected]84df8332011-12-06 18:22:461946 disabled_extensions_.Insert(scoped_extension);
[email protected]3bdba0d2011-08-23 07:17:301947 SyncExtensionChangeIfNeeded(*extension);
[email protected]44d62b62012-04-11 00:06:031948 content::NotificationService::current()->Notify(
1949 chrome::NOTIFICATION_EXTENSION_UPDATE_DISABLED,
1950 content::Source<Profile>(profile_),
1951 content::Details<const Extension>(extension));
[email protected]62f051c2012-03-29 17:04:441952
[email protected]eb5e4f92012-08-15 23:33:281953 if (extension_prefs_->GetDisableReasons(extension->id()) &
[email protected]44d62b62012-04-11 00:06:031954 Extension::DISABLE_PERMISSIONS_INCREASE) {
[email protected]62f051c2012-03-29 17:04:441955 extensions::AddExtensionDisabledError(this, extension);
1956 }
[email protected]fcb58a862012-05-01 01:03:151957 return;
[email protected]e72e8eb82009-06-18 17:21:511958 }
[email protected]aab98a52009-12-02 03:22:351959
[email protected]b873cd92012-02-09 21:51:481960 // All apps that are displayed in the launcher are ordered by their ordinals
1961 // so we must ensure they have valid ordinals.
1962 if (extension->ShouldDisplayInLauncher())
1963 extension_prefs_->extension_sorting()->EnsureValidOrdinals(extension->id());
1964
[email protected]84df8332011-12-06 18:22:461965 extensions_.Insert(scoped_extension);
[email protected]3bdba0d2011-08-23 07:17:301966 SyncExtensionChangeIfNeeded(*extension);
[email protected]c8d407e2011-04-28 21:27:171967 NotifyExtensionLoaded(extension);
[email protected]6cafe35a2012-08-27 22:40:501968 QueueRestoreAppWindow(extension);
[email protected]aab98a52009-12-02 03:22:351969}
1970
[email protected]902fd7b2011-07-27 18:42:311971void ExtensionService::InitializePermissions(const Extension* extension) {
1972 // If the extension has used the optional permissions API, it will have a
1973 // custom set of active permissions defined in the extension prefs. Here,
1974 // we update the extension's active permissions based on the prefs.
[email protected]c2e66e12012-06-27 06:27:061975 scoped_refptr<PermissionSet> active_permissions =
[email protected]902fd7b2011-07-27 18:42:311976 extension_prefs()->GetActivePermissions(extension->id());
1977
1978 if (active_permissions.get()) {
1979 // We restrict the active permissions to be within the bounds defined in the
1980 // extension's manifest.
1981 // a) active permissions must be a subset of optional + default permissions
1982 // b) active permissions must contains all default permissions
[email protected]c2e66e12012-06-27 06:27:061983 scoped_refptr<PermissionSet> total_permissions =
1984 PermissionSet::CreateUnion(
[email protected]902fd7b2011-07-27 18:42:311985 extension->required_permission_set(),
1986 extension->optional_permission_set());
1987
1988 // Make sure the active permissions contain no more than optional + default.
[email protected]c2e66e12012-06-27 06:27:061989 scoped_refptr<PermissionSet> adjusted_active =
1990 PermissionSet::CreateIntersection(
[email protected]902fd7b2011-07-27 18:42:311991 total_permissions.get(), active_permissions.get());
1992
1993 // Make sure the active permissions contain the default permissions.
[email protected]c2e66e12012-06-27 06:27:061994 adjusted_active = PermissionSet::CreateUnion(
[email protected]902fd7b2011-07-27 18:42:311995 extension->required_permission_set(), adjusted_active.get());
1996
[email protected]c333e792012-01-06 16:57:391997 extensions::PermissionsUpdater perms_updater(profile());
1998 perms_updater.UpdateActivePermissions(extension, adjusted_active);
[email protected]902fd7b2011-07-27 18:42:311999 }
2000
[email protected]8d888c12010-11-30 00:00:252001 // We keep track of all permissions the user has granted each extension.
2002 // This allows extensions to gracefully support backwards compatibility
2003 // by including unknown permissions in their manifests. When the user
2004 // installs the extension, only the recognized permissions are recorded.
2005 // When the unknown permissions become recognized (e.g., through browser
2006 // upgrade), we can prompt the user to accept these new permissions.
2007 // Extensions can also silently upgrade to less permissions, and then
2008 // silently upgrade to a version that adds these permissions back.
2009 //
2010 // For example, pretend that Chrome 10 includes a permission "omnibox"
2011 // for an API that adds suggestions to the omnibox. An extension can
2012 // maintain backwards compatibility while still having "omnibox" in the
2013 // manifest. If a user installs the extension on Chrome 9, the browser
2014 // will record the permissions it recognized, not including "omnibox."
2015 // When upgrading to Chrome 10, "omnibox" will be recognized and Chrome
2016 // will disable the extension and prompt the user to approve the increase
2017 // in privileges. The extension could then release a new version that
2018 // removes the "omnibox" permission. When the user upgrades, Chrome will
2019 // still remember that "omnibox" had been granted, so that if the
2020 // extension once again includes "omnibox" in an upgrade, the extension
2021 // can upgrade without requiring this user's approval.
[email protected]81f0d162012-08-15 04:21:472022 int include_mask = INCLUDE_ENABLED;
2023 include_mask |= INCLUDE_DISABLED;
2024 const Extension* old =
2025 GetExtensionByIdInternal(extension->id(), include_mask);
[email protected]8d888c12010-11-30 00:00:252026 bool is_extension_upgrade = old != NULL;
2027 bool is_privilege_increase = false;
[email protected]44d62b62012-04-11 00:06:032028 bool previously_disabled = false;
[email protected]eb5e4f92012-08-15 23:33:282029 int disable_reasons = extension_prefs_->GetDisableReasons(extension->id());
[email protected]8d888c12010-11-30 00:00:252030
[email protected]902fd7b2011-07-27 18:42:312031 // We only need to compare the granted permissions to the current permissions
2032 // if the extension is not allowed to silently increase its permissions.
2033 if (!extension->CanSilentlyIncreasePermissions()) {
[email protected]8d888c12010-11-30 00:00:252034 // Add all the recognized permissions if the granted permissions list
2035 // hasn't been initialized yet.
[email protected]c2e66e12012-06-27 06:27:062036 scoped_refptr<PermissionSet> granted_permissions =
[email protected]902fd7b2011-07-27 18:42:312037 extension_prefs_->GetGrantedPermissions(extension->id());
[email protected]0d3e4a22011-06-23 19:02:522038 CHECK(granted_permissions.get());
[email protected]8d888c12010-11-30 00:00:252039
2040 // Here, we check if an extension's privileges have increased in a manner
2041 // that requires the user's approval. This could occur because the browser
2042 // upgraded and recognized additional privileges, or an extension upgrades
2043 // to a version that requires additional privileges.
[email protected]0d3e4a22011-06-23 19:02:522044 is_privilege_increase =
[email protected]902fd7b2011-07-27 18:42:312045 granted_permissions->HasLessPrivilegesThan(
2046 extension->GetActivePermissions());
[email protected]8d888c12010-11-30 00:00:252047 }
2048
2049 if (is_extension_upgrade) {
[email protected]66e26872010-12-03 20:07:252050 // Other than for unpacked extensions, CrxInstaller should have guaranteed
2051 // that we aren't downgrading.
2052 if (extension->location() != Extension::LOAD)
[email protected]2f8757c32012-06-19 19:17:472053 CHECK(extension->version()->CompareTo(*(old->version())) >= 0);
[email protected]8d888c12010-11-30 00:00:252054
2055 // Extensions get upgraded if the privileges are allowed to increase or
2056 // the privileges haven't increased.
2057 if (!is_privilege_increase) {
2058 SetBeingUpgraded(old, true);
2059 SetBeingUpgraded(extension, true);
2060 }
2061
[email protected]44d62b62012-04-11 00:06:032062 // If the extension was already disabled, suppress any alerts for becoming
2063 // disabled on permissions increase.
2064 previously_disabled = extension_prefs_->IsExtensionDisabled(old->id());
2065 if (previously_disabled) {
[email protected]eb5e4f92012-08-15 23:33:282066 int reasons = extension_prefs_->GetDisableReasons(old->id());
2067 if (reasons == Extension::DISABLE_NONE) {
[email protected]44d62b62012-04-11 00:06:032068 // Initialize the reason for legacy disabled extensions from whether the
2069 // extension already exceeded granted permissions.
2070 if (extension_prefs_->DidExtensionEscalatePermissions(old->id()))
[email protected]eb5e4f92012-08-15 23:33:282071 disable_reasons = Extension::DISABLE_PERMISSIONS_INCREASE;
[email protected]44d62b62012-04-11 00:06:032072 else
[email protected]eb5e4f92012-08-15 23:33:282073 disable_reasons = Extension::DISABLE_USER_ACTION;
[email protected]44d62b62012-04-11 00:06:032074 }
2075 } else {
[email protected]eb5e4f92012-08-15 23:33:282076 disable_reasons = Extension::DISABLE_PERMISSIONS_INCREASE;
[email protected]44d62b62012-04-11 00:06:032077 }
2078
[email protected]8d888c12010-11-30 00:00:252079 // To upgrade an extension in place, unload the old one and
2080 // then load the new one.
[email protected]814a7bf0f2011-08-13 05:30:592081 UnloadExtension(old->id(), extension_misc::UNLOAD_REASON_UPDATE);
[email protected]8d888c12010-11-30 00:00:252082 old = NULL;
2083 }
2084
2085 // Extension has changed permissions significantly. Disable it. A
2086 // notification should be sent by the caller.
2087 if (is_privilege_increase) {
[email protected]fe2dd7742011-04-19 22:52:492088 if (!extension_prefs_->DidExtensionEscalatePermissions(extension->id())) {
2089 RecordPermissionMessagesHistogram(
2090 extension, "Extensions.Permissions_AutoDisable");
2091 }
[email protected]b3317ad2011-04-28 23:46:002092 extension_prefs_->SetExtensionState(extension->id(), Extension::DISABLED);
[email protected]8d888c12010-11-30 00:00:252093 extension_prefs_->SetDidExtensionEscalatePermissions(extension, true);
[email protected]eb5e4f92012-08-15 23:33:282094 extension_prefs_->AddDisableReason(
2095 extension->id(),
2096 static_cast<Extension::DisableReason>(disable_reasons));
[email protected]8d888c12010-11-30 00:00:252097 }
2098}
2099
[email protected]eaa7dd182010-12-14 11:09:002100void ExtensionService::UpdateActiveExtensionsInCrashReporter() {
[email protected]c8865962009-12-16 07:47:392101 std::set<std::string> extension_ids;
[email protected]84df8332011-12-06 18:22:462102 for (ExtensionSet::const_iterator iter = extensions_.begin();
2103 iter != extensions_.end(); ++iter) {
2104 const Extension* extension = *iter;
2105 if (!extension->is_theme() && extension->location() != Extension::COMPONENT)
2106 extension_ids.insert(extension->id());
[email protected]aab98a52009-12-02 03:22:352107 }
2108
2109 child_process_logging::SetActiveExtensions(extension_ids);
[email protected]6014d672008-12-05 00:38:252110}
2111
[email protected]8266d662011-07-12 21:53:262112void ExtensionService::OnExtensionInstalled(
[email protected]36a5c4c2011-12-14 16:34:502113 const Extension* extension,
2114 bool from_webstore,
2115 const StringOrdinal& page_ordinal) {
[email protected]a29a517a2011-01-21 21:11:122116 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]a8af9fdb2010-10-28 21:52:202117
[email protected]4416c5a2010-06-26 01:28:572118 // Ensure extension is deleted unless we transfer ownership.
[email protected]9adb9692010-10-29 23:14:022119 scoped_refptr<const Extension> scoped_extension(extension);
[email protected]c3cfb012011-04-06 22:07:352120 const std::string& id = extension->id();
[email protected]8a87a5332011-08-11 17:54:592121 // Extensions installed by policy can't be disabled. So even if a previous
2122 // installation disabled the extension, make sure it is now enabled.
2123 bool initial_enable =
2124 !extension_prefs_->IsExtensionDisabled(id) ||
[email protected]65187152012-06-02 13:14:142125 system_->management_policy()->MustRemainEnabled(extension, NULL);
[email protected]3f213ad2012-07-26 23:39:412126 const extensions::PendingExtensionInfo* pending_extension_info = NULL;
[email protected]51a3bf8b2012-06-08 22:53:062127 if ((pending_extension_info = pending_extension_manager()->GetById(id))) {
2128 if (!pending_extension_info->ShouldAllowInstall(*extension)) {
2129 pending_extension_manager()->Remove(id);
[email protected]8ef78fd2010-08-19 17:14:322130
[email protected]4416c5a2010-06-26 01:28:572131 LOG(WARNING)
[email protected]ae6cb3022011-04-04 20:11:542132 << "ShouldAllowInstall() returned false for "
[email protected]c3cfb012011-04-06 22:07:352133 << id << " of type " << extension->GetType()
[email protected]7fa19f82010-12-21 19:40:082134 << " and update URL " << extension->update_url().spec()
2135 << "; not installing";
[email protected]ae6cb3022011-04-04 20:11:542136
[email protected]ad50def52011-10-19 23:17:072137 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:272138 chrome::NOTIFICATION_EXTENSION_INSTALL_NOT_ALLOWED,
[email protected]6c2381d2011-10-19 02:52:532139 content::Source<Profile>(profile_),
2140 content::Details<const Extension>(extension));
[email protected]ae6cb3022011-04-04 20:11:542141
[email protected]4416c5a2010-06-26 01:28:572142 // Delete the extension directory since we're not going to
2143 // load it.
[email protected]14908b72011-04-20 06:54:362144 if (!BrowserThread::PostTask(
2145 BrowserThread::FILE, FROM_HERE,
[email protected]53612e82011-10-18 18:00:362146 base::Bind(&extension_file_util::DeleteFile,
2147 extension->path(), true)))
[email protected]14908b72011-04-20 06:54:362148 NOTREACHED();
[email protected]4416c5a2010-06-26 01:28:572149 return;
2150 }
[email protected]51a3bf8b2012-06-08 22:53:062151
2152 pending_extension_manager()->Remove(id);
[email protected]4416c5a2010-06-26 01:28:572153 } else {
[email protected]c3cfb012011-04-06 22:07:352154 // We explicitly want to re-enable an uninstalled external
2155 // extension; if we're here, that means the user is manually
2156 // installing the extension.
[email protected]6cc7dbae2011-04-29 21:18:332157 if (IsExternalExtensionUninstalled(id)) {
2158 initial_enable = true;
2159 }
[email protected]aa142702010-03-26 01:26:332160 }
2161
[email protected]81f0d162012-08-15 04:21:472162 int include_mask = INCLUDE_ENABLED;
2163 include_mask |= INCLUDE_DISABLED;
[email protected]07533022011-06-27 20:42:552164 // Do not record the install histograms for upgrades.
[email protected]81f0d162012-08-15 04:21:472165 if (!GetExtensionByIdInternal(extension->id(), include_mask)) {
[email protected]07533022011-06-27 20:42:552166 UMA_HISTOGRAM_ENUMERATION("Extensions.InstallType",
2167 extension->GetType(), 100);
2168 RecordPermissionMessagesHistogram(
2169 extension, "Extensions.Permissions_Install");
2170 }
2171
[email protected]a39921b42012-02-28 03:42:542172 // Certain extension locations are specific enough that we can
2173 // auto-acknowledge any extension that came from one of them.
2174 if (extension->location() == Extension::EXTERNAL_POLICY_DOWNLOAD) {
2175 AcknowledgeExternalExtension(extension->id());
2176 }
2177
[email protected]4416c5a2010-06-26 01:28:572178 extension_prefs_->OnExtensionInstalled(
[email protected]8266d662011-07-12 21:53:262179 extension,
2180 initial_enable ? Extension::ENABLED : Extension::DISABLED,
[email protected]cc829cf2011-08-22 21:01:352181 from_webstore,
[email protected]36a5c4c2011-12-14 16:34:502182 page_ordinal);
[email protected]25b34332009-06-05 21:53:192183
[email protected]cdfca9702011-08-08 16:07:012184 // Unpacked extensions default to allowing file access, but if that has been
2185 // overridden, don't reset the value.
[email protected]b6e64fd2011-08-09 19:49:192186 if (Extension::ShouldAlwaysAllowFileAccess(extension->location()) &&
[email protected]cdfca9702011-08-08 16:07:012187 !extension_prefs_->HasAllowFileAccessSetting(id)) {
2188 extension_prefs_->SetAllowFileAccess(id, true);
2189 }
2190
[email protected]fcb58a862012-05-01 01:03:152191 content::NotificationService::current()->Notify(
2192 chrome::NOTIFICATION_EXTENSION_INSTALLED,
2193 content::Source<Profile>(profile_),
2194 content::Details<const Extension>(extension));
2195
[email protected]49cd1572011-02-08 21:38:452196 // Transfer ownership of |extension| to AddExtension.
[email protected]fcb58a862012-05-01 01:03:152197 AddExtension(scoped_extension);
[email protected]4a190632009-05-09 01:07:422198}
2199
[email protected]eaa7dd182010-12-14 11:09:002200const Extension* ExtensionService::GetExtensionByIdInternal(
[email protected]81f0d162012-08-15 04:21:472201 const std::string& id, int include_mask) const {
[email protected]e957fe52009-06-23 16:51:052202 std::string lowercase_id = StringToLowerASCII(id);
[email protected]81f0d162012-08-15 04:21:472203 if (include_mask & INCLUDE_ENABLED) {
[email protected]84df8332011-12-06 18:22:462204 const Extension* extension = extensions_.GetByID(lowercase_id);
2205 if (extension)
2206 return extension;
[email protected]0c6da502009-08-14 22:32:392207 }
[email protected]81f0d162012-08-15 04:21:472208 if (include_mask & INCLUDE_DISABLED) {
[email protected]84df8332011-12-06 18:22:462209 const Extension* extension = disabled_extensions_.GetByID(lowercase_id);
2210 if (extension)
2211 return extension;
[email protected]ce5c4502009-05-06 16:46:112212 }
[email protected]81f0d162012-08-15 04:21:472213 if (include_mask & INCLUDE_TERMINATED) {
[email protected]84df8332011-12-06 18:22:462214 const Extension* extension = terminated_extensions_.GetByID(lowercase_id);
2215 if (extension)
2216 return extension;
[email protected]8001df22011-04-28 19:59:472217 }
[email protected]ce5c4502009-05-06 16:46:112218 return NULL;
2219}
2220
[email protected]bb7f40952011-01-13 00:21:202221void ExtensionService::TrackTerminatedExtension(const Extension* extension) {
[email protected]84df8332011-12-06 18:22:462222 if (!terminated_extensions_.Contains(extension->id()))
2223 terminated_extensions_.Insert(make_scoped_refptr(extension));
[email protected]fa2416f2011-05-03 08:41:202224
[email protected]b3f7fe22011-11-11 19:27:562225 UnloadExtension(extension->id(), extension_misc::UNLOAD_REASON_TERMINATE);
[email protected]bb7f40952011-01-13 00:21:202226}
2227
2228void ExtensionService::UntrackTerminatedExtension(const std::string& id) {
[email protected]fa2416f2011-05-03 08:41:202229 std::string lowercase_id = StringToLowerASCII(id);
[email protected]84df8332011-12-06 18:22:462230 terminated_extensions_.Remove(lowercase_id);
[email protected]bb7f40952011-01-13 00:21:202231}
2232
[email protected]0dfe05c2011-02-23 23:03:362233const Extension* ExtensionService::GetTerminatedExtension(
[email protected]8001df22011-04-28 19:59:472234 const std::string& id) const {
[email protected]81f0d162012-08-15 04:21:472235 return GetExtensionByIdInternal(id, INCLUDE_TERMINATED);
[email protected]8001df22011-04-28 19:59:472236}
2237
2238const Extension* ExtensionService::GetInstalledExtension(
2239 const std::string& id) const {
[email protected]81f0d162012-08-15 04:21:472240 int include_mask = INCLUDE_ENABLED;
2241 include_mask |= INCLUDE_DISABLED;
2242 include_mask |= INCLUDE_TERMINATED;
2243 return GetExtensionByIdInternal(id, include_mask);
[email protected]0dfe05c2011-02-23 23:03:362244}
2245
[email protected]eaa7dd182010-12-14 11:09:002246bool ExtensionService::ExtensionBindingsAllowed(const GURL& url) {
[email protected]615d88f2011-12-13 01:47:442247 // Allow bindings for all packaged extensions and component hosted apps.
2248 const Extension* extension = extensions_.GetExtensionOrAppByURL(
2249 ExtensionURLInfo(url));
2250 return extension && (!extension->is_hosted_app() ||
2251 extension->location() == Extension::COMPONENT);
[email protected]6d2e60bd2010-06-03 22:37:392252}
2253
[email protected]e8476c992012-08-20 20:27:592254gfx::Image ExtensionService::GetOmniboxIcon(
[email protected]b671760b2010-07-15 21:13:472255 const std::string& extension_id) {
[email protected]e8476c992012-08-20 20:27:592256 return gfx::Image(omnibox_icon_manager_.GetIcon(extension_id));
[email protected]b671760b2010-07-15 21:13:472257}
2258
[email protected]e8476c992012-08-20 20:27:592259gfx::Image ExtensionService::GetOmniboxPopupIcon(
[email protected]29d0d4ac2010-09-08 21:10:312260 const std::string& extension_id) {
[email protected]e8476c992012-08-20 20:27:592261 return gfx::Image(omnibox_popup_icon_manager_.GetIcon(extension_id));
[email protected]29d0d4ac2010-09-08 21:10:312262}
2263
[email protected]9060d8b02012-01-13 02:14:302264bool ExtensionService::OnExternalExtensionFileFound(
[email protected]8ef78fd2010-08-19 17:14:322265 const std::string& id,
[email protected]8e4560b62011-01-14 10:09:142266 const Version* version,
[email protected]8ef78fd2010-08-19 17:14:322267 const FilePath& path,
[email protected]1bf73cc32011-10-26 22:38:312268 Extension::Location location,
[email protected]47fc70c2011-12-06 07:29:512269 int creation_flags,
2270 bool mark_acknowledged) {
[email protected]ab22ba42011-01-14 16:36:382271 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
2272 CHECK(Extension::IdIsValid(id));
[email protected]79c833b52011-04-05 18:31:012273 if (extension_prefs_->IsExternalExtensionUninstalled(id))
[email protected]9060d8b02012-01-13 02:14:302274 return false;
[email protected]a8af9fdb2010-10-28 21:52:202275
[email protected]7577a5c52009-07-30 06:21:582276 // Before even bothering to unpack, check and see if we already have this
[email protected]4c967932009-07-31 01:15:492277 // version. This is important because these extensions are going to get
[email protected]7577a5c52009-07-30 06:21:582278 // installed on every startup.
[email protected]9adb9692010-10-29 23:14:022279 const Extension* existing = GetExtensionById(id, true);
[email protected]910f72ce2012-08-24 01:38:352280
[email protected]7577a5c52009-07-30 06:21:582281 if (existing) {
[email protected]910f72ce2012-08-24 01:38:352282 // The default apps will have the location set as INTERNAL. Since older
2283 // default apps are installed as EXTERNAL, we override them. However, if the
2284 // app is already installed as internal, then do the version check.
2285 // TODO (grv) : Remove after Q1-2013.
2286 bool is_default_apps_migration =
2287 (location == Extension::INTERNAL &&
2288 Extension::IsExternalLocation(existing->location()));
2289
2290 if (!is_default_apps_migration) {
2291 DCHECK(version);
2292
2293 switch (existing->version()->CompareTo(*version)) {
2294 case -1: // existing version is older, we should upgrade
2295 break;
2296 case 0: // existing version is same, do nothing
2297 return false;
2298 case 1: // existing version is newer, uh-oh
2299 LOG(WARNING) << "Found external version of extension " << id
2300 << "that is older than current version. Current version "
2301 << "is: " << existing->VersionString() << ". New "
2302 << "version is: " << version->GetString()
2303 << ". Keeping current version.";
2304 return false;
2305 }
[email protected]7577a5c52009-07-30 06:21:582306 }
2307 }
2308
[email protected]9060d8b02012-01-13 02:14:302309 // If the extension is already pending, don't start an install.
[email protected]e3987852012-05-04 10:06:302310 if (!pending_extension_manager()->AddFromExternalFile(
2311 id, location, *version)) {
[email protected]9060d8b02012-01-13 02:14:302312 return false;
[email protected]e3987852012-05-04 10:06:302313 }
[email protected]9c635f22010-12-02 09:36:362314
[email protected]14908b72011-04-20 06:54:362315 // no client (silent install)
[email protected]d8c8f25f2011-11-02 18:18:012316 scoped_refptr<CrxInstaller> installer(CrxInstaller::Create(this, NULL));
[email protected]6dfbbf82010-03-12 23:09:162317 installer->set_install_source(location);
2318 installer->set_expected_id(id);
[email protected]cb0e50312011-05-09 15:03:072319 installer->set_expected_version(*version);
2320 installer->set_install_cause(extension_misc::INSTALL_CAUSE_EXTERNAL_FILE);
[email protected]1bf73cc32011-10-26 22:38:312321 installer->set_creation_flags(creation_flags);
[email protected]6dfbbf82010-03-12 23:09:162322 installer->InstallCrx(path);
[email protected]47fc70c2011-12-06 07:29:512323
2324 // Depending on the source, a new external extension might not need a user
2325 // notification on installation. For such extensions, mark them acknowledged
2326 // now to suppress the notification.
2327 if (mark_acknowledged)
2328 AcknowledgeExternalExtension(id);
[email protected]9060d8b02012-01-13 02:14:302329
2330 return true;
[email protected]7577a5c52009-07-30 06:21:582331}
2332
[email protected]eaa7dd182010-12-14 11:09:002333void ExtensionService::ReportExtensionLoadError(
[email protected]d11c8e92009-10-20 23:26:402334 const FilePath& extension_path,
2335 const std::string &error,
[email protected]d11c8e92009-10-20 23:26:402336 bool be_noisy) {
[email protected]d8c8f25f2011-11-02 18:18:012337 content::NotificationService::current()->Notify(
2338 chrome::NOTIFICATION_EXTENSION_LOAD_ERROR,
2339 content::Source<Profile>(profile_),
2340 content::Details<const std::string>(&error));
[email protected]d11c8e92009-10-20 23:26:402341
[email protected]8a205c02011-02-04 20:41:332342 std::string path_str = UTF16ToUTF8(extension_path.LossyDisplayName());
[email protected]438afb12012-07-05 03:18:212343 string16 message = UTF8ToUTF16(base::StringPrintf(
[email protected]18d4b6c2010-09-21 03:21:042344 "Could not load extension from '%s'. %s",
[email protected]fc670822011-12-17 09:33:492345 path_str.c_str(), error.c_str()));
[email protected]d11c8e92009-10-20 23:26:402346 ExtensionErrorReporter::GetInstance()->ReportError(message, be_noisy);
2347}
2348
[email protected]eaa7dd182010-12-14 11:09:002349void ExtensionService::DidCreateRenderViewForBackgroundPage(
[email protected]3a1dc572012-07-31 22:25:132350 extensions::ExtensionHost* host) {
[email protected]406027c02010-09-27 08:03:182351 OrphanedDevTools::iterator iter =
[email protected]2d2f6cfc2011-05-06 21:09:332352 orphaned_dev_tools_.find(host->extension_id());
[email protected]406027c02010-09-27 08:03:182353 if (iter == orphaned_dev_tools_.end())
2354 return;
2355
[email protected]0e12d7d2011-12-01 16:21:442356 DevToolsAgentHost* agent = DevToolsAgentHostRegistry::GetDevToolsAgentHost(
2357 host->render_view_host());
2358 content::DevToolsManager::GetInstance()->AttachClientHost(iter->second,
2359 agent);
[email protected]406027c02010-09-27 08:03:182360 orphaned_dev_tools_.erase(iter);
2361}
2362
[email protected]432115822011-07-10 15:52:272363void ExtensionService::Observe(int type,
[email protected]6c2381d2011-10-19 02:52:532364 const content::NotificationSource& source,
2365 const content::NotificationDetails& details) {
[email protected]432115822011-07-10 15:52:272366 switch (type) {
2367 case chrome::NOTIFICATION_EXTENSION_PROCESS_TERMINATED: {
[email protected]6c2381d2011-10-19 02:52:532368 if (profile_ !=
2369 content::Source<Profile>(source).ptr()->GetOriginalProfile()) {
[email protected]bc535ee52010-08-31 18:40:322370 break;
[email protected]6c2381d2011-10-19 02:52:532371 }
[email protected]a4ed6282009-12-14 20:51:162372
[email protected]3a1dc572012-07-31 22:25:132373 extensions::ExtensionHost* host =
2374 content::Details<extensions::ExtensionHost>(details).ptr();
[email protected]f128af42010-08-05 18:05:262375
[email protected]fa2416f2011-05-03 08:41:202376 // Mark the extension as terminated and Unload it. We want it to
2377 // be in a consistent state: either fully working or not loaded
2378 // at all, but never half-crashed. We do it in a PostTask so
2379 // that other handlers of this notification will still have
2380 // access to the Extension and ExtensionHost.
[email protected]14908b72011-04-20 06:54:362381 MessageLoop::current()->PostTask(
2382 FROM_HERE,
[email protected]53612e82011-10-18 18:00:362383 base::Bind(
[email protected]fa2416f2011-05-03 08:41:202384 &ExtensionService::TrackTerminatedExtension,
[email protected]d8c8f25f2011-11-02 18:18:012385 AsWeakPtr(),
[email protected]fa2416f2011-05-03 08:41:202386 host->extension()));
[email protected]31f77262009-12-02 20:48:532387 break;
2388 }
[email protected]432115822011-07-10 15:52:272389 case content::NOTIFICATION_RENDERER_PROCESS_CREATED: {
[email protected]f3b1a082011-11-18 00:34:302390 content::RenderProcessHost* process =
2391 content::Source<content::RenderProcessHost>(source).ptr();
[email protected]fc30ef082011-08-18 04:07:192392 Profile* host_profile =
[email protected]f3b1a082011-11-18 00:34:302393 Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]fc30ef082011-08-18 04:07:192394 if (!profile_->IsSameProfile(host_profile->GetOriginalProfile()))
2395 break;
2396
[email protected]15397b42012-05-16 23:56:062397 // Extensions need to know the channel for API restrictions.
2398 process->Send(new ExtensionMsg_SetChannel(
[email protected]5243df072012-07-11 21:41:012399 extensions::Feature::GetCurrentChannel()));
[email protected]15397b42012-05-16 23:56:062400
[email protected]77a6970c2011-04-23 16:58:562401 // Valid extension function names, used to setup bindings in renderer.
2402 std::vector<std::string> function_names;
2403 ExtensionFunctionDispatcher::GetAllFunctionNames(&function_names);
2404 process->Send(new ExtensionMsg_SetFunctionNames(function_names));
[email protected]31f77262009-12-02 20:48:532405
[email protected]77a6970c2011-04-23 16:58:562406 // Scripting whitelist. This is modified by tests and must be communicated
2407 // to renderers.
2408 process->Send(new ExtensionMsg_SetScriptingWhitelist(
2409 *Extension::GetScriptingWhitelist()));
2410
2411 // Loaded extensions.
[email protected]9776e82e2011-11-15 02:17:532412 std::vector<ExtensionMsg_Loaded_Params> loaded_extensions;
[email protected]84df8332011-12-06 18:22:462413 for (ExtensionSet::const_iterator iter = extensions_.begin();
2414 iter != extensions_.end(); ++iter) {
[email protected]19647262011-12-16 09:57:492415 // Renderers don't need to know about themes.
2416 if (!(*iter)->is_theme())
2417 loaded_extensions.push_back(ExtensionMsg_Loaded_Params(*iter));
[email protected]77a6970c2011-04-23 16:58:562418 }
[email protected]9776e82e2011-11-15 02:17:532419 process->Send(new ExtensionMsg_Loaded(loaded_extensions));
[email protected]77a6970c2011-04-23 16:58:562420 break;
2421 }
[email protected]432115822011-07-10 15:52:272422 case content::NOTIFICATION_RENDERER_PROCESS_TERMINATED: {
[email protected]f3b1a082011-11-18 00:34:302423 content::RenderProcessHost* process =
2424 content::Source<content::RenderProcessHost>(source).ptr();
[email protected]fc30ef082011-08-18 04:07:192425 Profile* host_profile =
[email protected]f3b1a082011-11-18 00:34:302426 Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]fc30ef082011-08-18 04:07:192427 if (!profile_->IsSameProfile(host_profile->GetOriginalProfile()))
2428 break;
2429
[email protected]f3b1a082011-11-18 00:34:302430 installed_app_hosts_.erase(process->GetID());
[email protected]6f371442011-11-09 06:45:462431
[email protected]6bc04fd82011-12-04 02:29:352432 process_map_.RemoveAllFromProcess(process->GetID());
[email protected]6f371442011-11-09 06:45:462433 BrowserThread::PostTask(
2434 BrowserThread::IO, FROM_HERE,
2435 base::Bind(&ExtensionInfoMap::UnregisterAllExtensionsInProcess,
[email protected]31d8f5f22012-04-02 15:22:082436 system_->info_map(),
[email protected]f3b1a082011-11-18 00:34:302437 process->GetID()));
[email protected]da5683db2011-04-23 17:12:212438 break;
2439 }
[email protected]432115822011-07-10 15:52:272440 case chrome::NOTIFICATION_PREF_CHANGED: {
[email protected]6c2381d2011-10-19 02:52:532441 std::string* pref_name = content::Details<std::string>(details).ptr();
[email protected]6c751e72010-11-23 10:11:102442 if (*pref_name == prefs::kExtensionInstallAllowList ||
2443 *pref_name == prefs::kExtensionInstallDenyList) {
[email protected]4ee07c62012-08-21 12:40:422444 IdentifyAlertableExtensions();
2445 CheckManagementPolicy();
[email protected]6c751e72010-11-23 10:11:102446 } else {
2447 NOTREACHED() << "Unexpected preference name.";
2448 }
[email protected]aa96d3a2010-08-21 08:45:252449 break;
2450 }
[email protected]d91268022011-08-26 13:17:372451 case chrome::NOTIFICATION_IMPORT_FINISHED: {
[email protected]cf593af2011-12-30 05:44:392452 InitAfterImport();
[email protected]d91268022011-08-26 13:17:372453 break;
2454 }
[email protected]aa96d3a2010-08-21 08:45:252455
[email protected]4814b512009-11-07 00:12:292456 default:
2457 NOTREACHED() << "Unexpected notification type.";
2458 }
2459}
2460
[email protected]eaa7dd182010-12-14 11:09:002461bool ExtensionService::HasApps() const {
[email protected]ec5b50d2010-10-09 16:35:182462 return !GetAppIds().empty();
2463}
[email protected]377011d2010-07-20 04:18:502464
[email protected]eaa7dd182010-12-14 11:09:002465ExtensionIdSet ExtensionService::GetAppIds() const {
[email protected]ec5b50d2010-10-09 16:35:182466 ExtensionIdSet result;
[email protected]84df8332011-12-06 18:22:462467 for (ExtensionSet::const_iterator it = extensions_.begin();
[email protected]377011d2010-07-20 04:18:502468 it != extensions_.end(); ++it) {
[email protected]ec5b50d2010-10-09 16:35:182469 if ((*it)->is_app() && (*it)->location() != Extension::COMPONENT)
2470 result.insert((*it)->id());
[email protected]377011d2010-07-20 04:18:502471 }
2472
[email protected]ec5b50d2010-10-09 16:35:182473 return result;
[email protected]377011d2010-07-20 04:18:502474}
[email protected]d7e9a862010-11-03 21:57:492475
[email protected]dc9a74f72012-08-17 18:07:212476bool ExtensionService::IsBackgroundPageReady(const Extension* extension) const {
2477 if (!extension->has_persistent_background_page())
2478 return true;
2479 ExtensionRuntimeDataMap::const_iterator it =
2480 extension_runtime_data_.find(extension->id());
2481 return it == extension_runtime_data_.end() ? false :
2482 it->second.background_page_ready;
[email protected]d7e9a862010-11-03 21:57:492483}
2484
[email protected]eaa7dd182010-12-14 11:09:002485void ExtensionService::SetBackgroundPageReady(const Extension* extension) {
[email protected]a03d4448f2012-01-10 23:25:282486 DCHECK(extension->has_background_page());
[email protected]d7e9a862010-11-03 21:57:492487 extension_runtime_data_[extension->id()].background_page_ready = true;
[email protected]ad50def52011-10-19 23:17:072488 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:272489 chrome::NOTIFICATION_EXTENSION_BACKGROUND_PAGE_READY,
[email protected]6c2381d2011-10-19 02:52:532490 content::Source<const Extension>(extension),
[email protected]ad50def52011-10-19 23:17:072491 content::NotificationService::NoDetails());
[email protected]d7e9a862010-11-03 21:57:492492}
2493
[email protected]dc9a74f72012-08-17 18:07:212494bool ExtensionService::IsBeingUpgraded(const Extension* extension) const {
2495 ExtensionRuntimeDataMap::const_iterator it =
2496 extension_runtime_data_.find(extension->id());
2497 return it == extension_runtime_data_.end() ? false :
2498 it->second.being_upgraded;
[email protected]d7e9a862010-11-03 21:57:492499}
2500
[email protected]eaa7dd182010-12-14 11:09:002501void ExtensionService::SetBeingUpgraded(const Extension* extension,
[email protected]d7e9a862010-11-03 21:57:492502 bool value) {
2503 extension_runtime_data_[extension->id()].being_upgraded = value;
2504}
[email protected]1bead0712010-11-27 17:41:532505
[email protected]dc9a74f72012-08-17 18:07:212506bool ExtensionService::HasUsedWebRequest(const Extension* extension) const {
2507 ExtensionRuntimeDataMap::const_iterator it =
2508 extension_runtime_data_.find(extension->id());
2509 return it == extension_runtime_data_.end() ? false :
2510 it->second.has_used_webrequest;
[email protected]39a5b532011-10-22 01:47:072511}
2512
2513void ExtensionService::SetHasUsedWebRequest(const Extension* extension,
2514 bool value) {
2515 extension_runtime_data_[extension->id()].has_used_webrequest = value;
2516}
2517
[email protected]cebc3dc2011-04-18 17:15:002518void ExtensionService::RegisterNaClModule(const GURL& url,
2519 const std::string& mime_type) {
2520 NaClModuleInfo info;
2521 info.url = url;
2522 info.mime_type = mime_type;
2523
2524 DCHECK(FindNaClModule(url) == nacl_module_list_.end());
2525 nacl_module_list_.push_front(info);
2526}
2527
2528void ExtensionService::UnregisterNaClModule(const GURL& url) {
2529 NaClModuleInfoList::iterator iter = FindNaClModule(url);
2530 DCHECK(iter != nacl_module_list_.end());
2531 nacl_module_list_.erase(iter);
2532}
2533
[email protected]ed0ba002011-05-26 16:55:132534void ExtensionService::UpdatePluginListWithNaClModules() {
[email protected]300c0ea2011-07-15 23:04:332535 // An extension has been added which has a nacl_module component, which means
2536 // there is a MIME type that module wants to handle, so we need to add that
2537 // MIME type to plugins which handle NaCl modules in order to allow the
2538 // individual modules to handle these types.
[email protected]1e127022011-11-29 21:11:472539 FilePath path;
2540 if (!PathService::Get(chrome::FILE_NACL_PLUGIN, &path))
2541 return;
2542 const content::PepperPluginInfo* pepper_info =
2543 PluginService::GetInstance()->GetRegisteredPpapiPluginInfo(path);
2544 if (!pepper_info)
2545 return;
[email protected]300c0ea2011-07-15 23:04:332546
[email protected]1e127022011-11-29 21:11:472547 std::vector<webkit::WebPluginMimeType>::const_iterator mime_iter;
2548 // Check each MIME type the plugins handle for the NaCl MIME type.
2549 for (mime_iter = pepper_info->mime_types.begin();
2550 mime_iter != pepper_info->mime_types.end(); ++mime_iter) {
2551 if (mime_iter->mime_type == kNaClPluginMimeType) {
2552 // This plugin handles "application/x-nacl".
[email protected]300c0ea2011-07-15 23:04:332553
[email protected]1e127022011-11-29 21:11:472554 PluginService::GetInstance()->
2555 UnregisterInternalPlugin(pepper_info->path);
[email protected]300c0ea2011-07-15 23:04:332556
[email protected]1e127022011-11-29 21:11:472557 webkit::WebPluginInfo info = pepper_info->ToWebPluginInfo();
[email protected]300c0ea2011-07-15 23:04:332558
[email protected]1e127022011-11-29 21:11:472559 for (ExtensionService::NaClModuleInfoList::const_iterator iter =
2560 nacl_module_list_.begin();
2561 iter != nacl_module_list_.end(); ++iter) {
2562 // Add the MIME type specified in the extension to this NaCl plugin,
2563 // With an extra "nacl" argument to specify the location of the NaCl
2564 // manifest file.
2565 webkit::WebPluginMimeType mime_type_info;
2566 mime_type_info.mime_type = iter->mime_type;
2567 mime_type_info.additional_param_names.push_back(UTF8ToUTF16("nacl"));
2568 mime_type_info.additional_param_values.push_back(
2569 UTF8ToUTF16(iter->url.spec()));
2570 info.mime_types.push_back(mime_type_info);
[email protected]300c0ea2011-07-15 23:04:332571 }
[email protected]1e127022011-11-29 21:11:472572
2573 PluginService::GetInstance()->RefreshPlugins();
[email protected]c6f3dea2012-01-14 02:23:112574 PluginService::GetInstance()->RegisterInternalPlugin(info, true);
[email protected]1e127022011-11-29 21:11:472575 // This plugin has been modified, no need to check the rest of its
2576 // types, but continue checking other plugins.
2577 break;
[email protected]ed0ba002011-05-26 16:55:132578 }
2579 }
[email protected]ed0ba002011-05-26 16:55:132580}
2581
[email protected]cebc3dc2011-04-18 17:15:002582ExtensionService::NaClModuleInfoList::iterator
2583 ExtensionService::FindNaClModule(const GURL& url) {
2584 for (NaClModuleInfoList::iterator iter = nacl_module_list_.begin();
2585 iter != nacl_module_list_.end(); ++iter) {
2586 if (iter->url == url)
2587 return iter;
2588 }
2589 return nacl_module_list_.end();
2590}
[email protected]6cafe35a2012-08-27 22:40:502591
2592void ExtensionService::QueueRestoreAppWindow(const Extension* extension) {
2593 std::set<std::string>::iterator relaunch_iter =
2594 relaunch_app_ids_.find(extension->id());
2595 if (relaunch_iter != relaunch_app_ids_.end()) {
2596 extensions::LazyBackgroundTaskQueue* queue =
2597 system_->lazy_background_task_queue();
2598 if (queue->ShouldEnqueueTask(profile(), extension)) {
2599 queue->AddPendingTask(profile(), extension->id(),
2600 base::Bind(&ExtensionService::LaunchApplication));
2601 }
2602
2603 relaunch_app_ids_.erase(relaunch_iter);
2604 }
2605}
2606
2607// static
2608void ExtensionService::LaunchApplication(
2609 extensions::ExtensionHost* extension_host) {
2610 if (!extension_host)
2611 return;
2612
2613#if !defined(OS_ANDROID)
2614 extensions::LaunchPlatformApp(extension_host->profile(),
2615 extension_host->extension(),
2616 NULL, FilePath());
2617#endif
2618}