[email protected] | 16d90004 | 2012-01-04 21:24:32 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | 6014d67 | 2008-12-05 00:38:25 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 5 | #include "chrome/browser/extensions/extension_service.h" |
[email protected] | 6014d67 | 2008-12-05 00:38:25 | [diff] [blame] | 6 | |
[email protected] | 654512b | 2010-09-01 02:09:42 | [diff] [blame] | 7 | #include <algorithm> |
[email protected] | 97d2f1d | 2011-01-15 00:41:08 | [diff] [blame] | 8 | #include <set> |
[email protected] | 654512b | 2010-09-01 02:09:42 | [diff] [blame] | 9 | |
[email protected] | 24b538a | 2010-02-27 01:22:44 | [diff] [blame] | 10 | #include "base/basictypes.h" |
[email protected] | 05aad2da | 2011-10-28 10:12:37 | [diff] [blame] | 11 | #include "base/bind.h" |
[email protected] | e5af875f | 2011-10-10 21:09:14 | [diff] [blame] | 12 | #include "base/callback.h" |
[email protected] | 62433d3 | 2011-10-12 22:33:12 | [diff] [blame] | 13 | #include "base/command_line.h" |
[email protected] | 6014d67 | 2008-12-05 00:38:25 | [diff] [blame] | 14 | #include "base/file_util.h" |
[email protected] | 14908b7 | 2011-04-20 06:54:36 | [diff] [blame] | 15 | #include "base/logging.h" |
[email protected] | 49098f70 | 2011-10-13 03:47:18 | [diff] [blame] | 16 | #include "base/metrics/field_trial.h" |
[email protected] | 835d7c8 | 2010-10-14 04:38:38 | [diff] [blame] | 17 | #include "base/metrics/histogram.h" |
[email protected] | 1e12702 | 2011-11-29 21:11:47 | [diff] [blame] | 18 | #include "base/path_service.h" |
[email protected] | 7286e3fc | 2011-07-19 22:13:24 | [diff] [blame] | 19 | #include "base/stl_util.h" |
[email protected] | 24b538a | 2010-02-27 01:22:44 | [diff] [blame] | 20 | #include "base/string16.h" |
[email protected] | e83326f | 2010-07-31 17:29:25 | [diff] [blame] | 21 | #include "base/string_number_conversions.h" |
[email protected] | 6014d67 | 2008-12-05 00:38:25 | [diff] [blame] | 22 | #include "base/string_util.h" |
[email protected] | 18d4b6c | 2010-09-21 03:21:04 | [diff] [blame] | 23 | #include "base/stringprintf.h" |
[email protected] | 34b9963 | 2011-01-01 01:01:06 | [diff] [blame] | 24 | #include "base/threading/thread_restrictions.h" |
[email protected] | cc2c343 | 2009-11-06 17:24:36 | [diff] [blame] | 25 | #include "base/time.h" |
[email protected] | ce7f62e3 | 2010-08-10 23:43:59 | [diff] [blame] | 26 | #include "base/utf_string_conversions.h" |
[email protected] | cc65591 | 2009-01-29 23:19:19 | [diff] [blame] | 27 | #include "base/values.h" |
[email protected] | aa14270 | 2010-03-26 01:26:33 | [diff] [blame] | 28 | #include "base/version.h" |
[email protected] | a692a95 | 2011-11-28 08:23:54 | [diff] [blame] | 29 | #include "chrome/browser/accessibility/accessibility_extension_api.h" |
[email protected] | 23d5f17 | 2011-10-25 05:49:53 | [diff] [blame] | 30 | #include "chrome/browser/bookmarks/bookmark_extension_api.h" |
[email protected] | 15730c4 | 2009-09-03 00:03:20 | [diff] [blame] | 31 | #include "chrome/browser/browser_process.h" |
[email protected] | dfba876 | 2011-09-02 12:49:54 | [diff] [blame] | 32 | #include "chrome/browser/chrome_plugin_service_filter.h" |
[email protected] | cdcf6024 | 2011-11-04 15:53:43 | [diff] [blame] | 33 | #include "chrome/browser/download/download_extension_api.h" |
[email protected] | a1755bd | 2011-12-09 00:40:20 | [diff] [blame] | 34 | #include "chrome/browser/extensions/api/socket/socket_api_controller.h" |
[email protected] | af9db5f | 2011-10-05 05:13:15 | [diff] [blame] | 35 | #include "chrome/browser/extensions/app_notification_manager.h" |
[email protected] | 18cc5a5 | 2011-04-15 16:03:38 | [diff] [blame] | 36 | #include "chrome/browser/extensions/apps_promo.h" |
[email protected] | d8c8f25f | 2011-11-02 18:18:01 | [diff] [blame] | 37 | #include "chrome/browser/extensions/component_loader.h" |
[email protected] | e078590 | 2011-05-19 23:34:17 | [diff] [blame] | 38 | #include "chrome/browser/extensions/crx_installer.h" |
[email protected] | 49098f70 | 2011-10-13 03:47:18 | [diff] [blame] | 39 | #include "chrome/browser/extensions/default_apps_trial.h" |
[email protected] | b68d5ed | 2009-04-16 02:41:28 | [diff] [blame] | 40 | #include "chrome/browser/extensions/extension_browser_event_router.h" |
[email protected] | 2c5e1e1 | 2010-06-10 13:14:44 | [diff] [blame] | 41 | #include "chrome/browser/extensions/extension_cookies_api.h" |
[email protected] | c10da4b0 | 2010-03-25 14:38:32 | [diff] [blame] | 42 | #include "chrome/browser/extensions/extension_data_deleter.h" |
[email protected] | 14a000d | 2010-04-29 21:44:24 | [diff] [blame] | 43 | #include "chrome/browser/extensions/extension_error_reporter.h" |
[email protected] | e5af875f | 2011-10-10 21:09:14 | [diff] [blame] | 44 | #include "chrome/browser/extensions/extension_global_error.h" |
[email protected] | b1748b1d8 | 2009-11-30 20:32:56 | [diff] [blame] | 45 | #include "chrome/browser/extensions/extension_host.h" |
[email protected] | 8baf0dbb | 2011-11-27 22:47:02 | [diff] [blame] | 46 | #include "chrome/browser/extensions/extension_input_ime_api.h" |
[email protected] | 7596ce7 | 2010-08-30 05:10:46 | [diff] [blame] | 47 | #include "chrome/browser/extensions/extension_management_api.h" |
[email protected] | 118de789 | 2011-03-16 13:31:40 | [diff] [blame] | 48 | #include "chrome/browser/extensions/extension_preference_api.h" |
[email protected] | 4814b51 | 2009-11-07 00:12:29 | [diff] [blame] | 49 | #include "chrome/browser/extensions/extension_process_manager.h" |
[email protected] | 8a661f8 | 2010-10-19 21:47:11 | [diff] [blame] | 50 | #include "chrome/browser/extensions/extension_processes_api.h" |
[email protected] | 3569b50 | 2012-01-12 20:08:23 | [diff] [blame^] | 51 | #include "chrome/browser/extensions/extension_sorting.h" |
[email protected] | 19eb8015 | 2011-02-26 00:28:43 | [diff] [blame] | 52 | #include "chrome/browser/extensions/extension_special_storage_policy.h" |
[email protected] | 90310d9 | 2011-04-17 07:35:04 | [diff] [blame] | 53 | #include "chrome/browser/extensions/extension_sync_data.h" |
[email protected] | 93fd78f4 | 2009-07-10 16:43:17 | [diff] [blame] | 54 | #include "chrome/browser/extensions/extension_updater.h" |
[email protected] | 8f9d4eb | 2011-02-05 01:39:10 | [diff] [blame] | 55 | #include "chrome/browser/extensions/extension_web_ui.h" |
[email protected] | 784688a6 | 2010-09-13 07:06:52 | [diff] [blame] | 56 | #include "chrome/browser/extensions/extension_webnavigation_api.h" |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 57 | #include "chrome/browser/extensions/external_extension_provider_impl.h" |
[email protected] | 42b79565 | 2011-02-22 23:32:38 | [diff] [blame] | 58 | #include "chrome/browser/extensions/external_extension_provider_interface.h" |
[email protected] | d8c8f25f | 2011-11-02 18:18:01 | [diff] [blame] | 59 | #include "chrome/browser/extensions/installed_loader.h" |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 60 | #include "chrome/browser/extensions/pending_extension_manager.h" |
[email protected] | c333e79 | 2012-01-06 16:57:39 | [diff] [blame] | 61 | #include "chrome/browser/extensions/permissions_updater.h" |
[email protected] | cccdf0aa | 2011-11-11 03:43:38 | [diff] [blame] | 62 | #include "chrome/browser/extensions/settings/settings_frontend.h" |
[email protected] | d8c8f25f | 2011-11-02 18:18:01 | [diff] [blame] | 63 | #include "chrome/browser/extensions/unpacked_installer.h" |
[email protected] | d2e6bd6 | 2011-10-24 20:29:07 | [diff] [blame] | 64 | #include "chrome/browser/history/history_extension_api.h" |
[email protected] | 56ad379 | 2010-05-28 17:45:33 | [diff] [blame] | 65 | #include "chrome/browser/net/chrome_url_request_context.h" |
[email protected] | 37858e5 | 2010-08-26 00:22:02 | [diff] [blame] | 66 | #include "chrome/browser/prefs/pref_service.h" |
[email protected] | 8ecad5e | 2010-12-02 21:18:33 | [diff] [blame] | 67 | #include "chrome/browser/profiles/profile.h" |
[email protected] | cf593af | 2011-12-30 05:44:39 | [diff] [blame] | 68 | #include "chrome/browser/profiles/profile_manager.h" |
[email protected] | 8e5c89a | 2011-06-07 18:13:33 | [diff] [blame] | 69 | #include "chrome/browser/search_engines/template_url_service.h" |
| 70 | #include "chrome/browser/search_engines/template_url_service_factory.h" |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 71 | #include "chrome/browser/sync/api/sync_change.h" |
[email protected] | 1828037 | 2011-03-22 18:05:22 | [diff] [blame] | 72 | #include "chrome/browser/themes/theme_service.h" |
[email protected] | a0ea76c | 2011-03-23 17:36:42 | [diff] [blame] | 73 | #include "chrome/browser/themes/theme_service_factory.h" |
[email protected] | e5af875f | 2011-10-10 21:09:14 | [diff] [blame] | 74 | #include "chrome/browser/ui/browser.h" |
[email protected] | 62433d3 | 2011-10-12 22:33:12 | [diff] [blame] | 75 | #include "chrome/browser/ui/browser_list.h" |
[email protected] | e5af875f | 2011-10-10 21:09:14 | [diff] [blame] | 76 | #include "chrome/browser/ui/global_error_service.h" |
| 77 | #include "chrome/browser/ui/global_error_service_factory.h" |
[email protected] | c8d407e | 2011-04-28 21:27:17 | [diff] [blame] | 78 | #include "chrome/browser/ui/webui/chrome_url_data_manager.h" |
[email protected] | c9c8b21 | 2011-12-13 23:59:40 | [diff] [blame] | 79 | #include "chrome/browser/ui/webui/extensions/extension_icon_source.h" |
[email protected] | c8d407e | 2011-04-28 21:27:17 | [diff] [blame] | 80 | #include "chrome/browser/ui/webui/favicon_source.h" |
[email protected] | 5eddc3e | 2011-10-26 04:33:31 | [diff] [blame] | 81 | #include "chrome/browser/ui/webui/ntp/thumbnail_source.h" |
[email protected] | 9de8328 | 2011-12-12 11:06:37 | [diff] [blame] | 82 | #include "chrome/browser/web_applications/web_app.h" |
[email protected] | aab98a5 | 2009-12-02 03:22:35 | [diff] [blame] | 83 | #include "chrome/common/child_process_logging.h" |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 84 | #include "chrome/common/chrome_notification_types.h" |
[email protected] | 1e12702 | 2011-11-29 21:11:47 | [diff] [blame] | 85 | #include "chrome/common/chrome_paths.h" |
[email protected] | e2eb4311 | 2009-05-29 21:19:54 | [diff] [blame] | 86 | #include "chrome/common/chrome_switches.h" |
[email protected] | 5b1a0e2 | 2009-05-26 19:00:58 | [diff] [blame] | 87 | #include "chrome/common/extensions/extension.h" |
[email protected] | d7b36dc | 2009-10-29 21:47:40 | [diff] [blame] | 88 | #include "chrome/common/extensions/extension_constants.h" |
[email protected] | 05c8218 | 2010-06-24 17:49:08 | [diff] [blame] | 89 | #include "chrome/common/extensions/extension_error_utils.h" |
[email protected] | 7c927b6 | 2010-02-24 09:54:13 | [diff] [blame] | 90 | #include "chrome/common/extensions/extension_file_util.h" |
[email protected] | 77a6970c | 2011-04-23 16:58:56 | [diff] [blame] | 91 | #include "chrome/common/extensions/extension_messages.h" |
[email protected] | a315ba9 | 2010-11-16 14:12:21 | [diff] [blame] | 92 | #include "chrome/common/extensions/extension_resource.h" |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 93 | #include "chrome/common/pref_names.h" |
[email protected] | a5720987 | 2009-05-04 22:53:14 | [diff] [blame] | 94 | #include "chrome/common/url_constants.h" |
[email protected] | 2de30759 | 2011-04-05 21:16:58 | [diff] [blame] | 95 | #include "content/browser/plugin_process_host.h" |
[email protected] | c38831a1 | 2011-10-28 12:44:49 | [diff] [blame] | 96 | #include "content/public/browser/browser_thread.h" |
[email protected] | 0e12d7d | 2011-12-01 16:21:44 | [diff] [blame] | 97 | #include "content/public/browser/devtools_agent_host_registry.h" |
| 98 | #include "content/public/browser/devtools_manager.h" |
[email protected] | 05aad2da | 2011-10-28 10:12:37 | [diff] [blame] | 99 | #include "content/public/browser/notification_service.h" |
[email protected] | 0d6e9bd | 2011-10-18 04:29:16 | [diff] [blame] | 100 | #include "content/public/browser/notification_types.h" |
[email protected] | 3a5180ae | 2011-12-21 02:39:38 | [diff] [blame] | 101 | #include "content/public/browser/plugin_service.h" |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 102 | #include "content/public/browser/render_process_host.h" |
[email protected] | 1e12702 | 2011-11-29 21:11:47 | [diff] [blame] | 103 | #include "content/public/common/pepper_plugin_info.h" |
[email protected] | c10da4b0 | 2010-03-25 14:38:32 | [diff] [blame] | 104 | #include "googleurl/src/gurl.h" |
[email protected] | 9de8328 | 2011-12-12 11:06:37 | [diff] [blame] | 105 | #include "grit/theme_resources.h" |
[email protected] | 1debbbb6 | 2010-10-06 17:23:44 | [diff] [blame] | 106 | #include "net/base/registry_controlled_domain.h" |
[email protected] | 24b538a | 2010-02-27 01:22:44 | [diff] [blame] | 107 | #include "webkit/database/database_tracker.h" |
| 108 | #include "webkit/database/database_util.h" |
[email protected] | c6463165 | 2009-04-29 22:24:31 | [diff] [blame] | 109 | |
[email protected] | eed367e | 2011-04-12 03:43:31 | [diff] [blame] | 110 | #if defined(OS_CHROMEOS) |
[email protected] | 14da67b0 | 2011-08-02 05:49:13 | [diff] [blame] | 111 | #include "chrome/browser/chromeos/cros/cros_library.h" |
[email protected] | eed367e | 2011-04-12 03:43:31 | [diff] [blame] | 112 | #include "chrome/browser/chromeos/extensions/file_browser_event_router.h" |
[email protected] | be5bd574 | 2011-07-14 07:21:01 | [diff] [blame] | 113 | #include "chrome/browser/chromeos/extensions/input_method_event_router.h" |
[email protected] | ce980204 | 2011-05-27 10:11:40 | [diff] [blame] | 114 | #include "chrome/browser/chromeos/extensions/media_player_event_router.h" |
[email protected] | 14da67b0 | 2011-08-02 05:49:13 | [diff] [blame] | 115 | #include "chrome/browser/chromeos/input_method/input_method_manager.h" |
[email protected] | 8baf0dbb | 2011-11-27 22:47:02 | [diff] [blame] | 116 | #include "chrome/browser/extensions/extension_input_ime_api.h" |
[email protected] | b777b33 | 2011-04-16 04:01:08 | [diff] [blame] | 117 | #include "webkit/fileapi/file_system_context.h" |
| 118 | #include "webkit/fileapi/file_system_mount_point_provider.h" |
[email protected] | eed367e | 2011-04-12 03:43:31 | [diff] [blame] | 119 | #endif |
| 120 | |
[email protected] | 9a2aebe0 | 2011-12-02 21:54:14 | [diff] [blame] | 121 | #if defined(OS_CHROMEOS) && defined(USE_VIRTUAL_KEYBOARD) |
[email protected] | 27072cad | 2011-05-09 19:46:40 | [diff] [blame] | 122 | #include "chrome/browser/extensions/extension_input_ui_api.h" |
| 123 | #endif |
| 124 | |
[email protected] | 5ef47ec | 2010-01-28 05:58:05 | [diff] [blame] | 125 | using base::Time; |
[email protected] | 631bb74 | 2011-11-02 11:29:39 | [diff] [blame] | 126 | using content::BrowserThread; |
[email protected] | 0e12d7d | 2011-12-01 16:21:44 | [diff] [blame] | 127 | using content::DevToolsAgentHost; |
| 128 | using content::DevToolsAgentHostRegistry; |
[email protected] | 3a5180ae | 2011-12-21 02:39:38 | [diff] [blame] | 129 | using content::PluginService; |
[email protected] | 5ef47ec | 2010-01-28 05:58:05 | [diff] [blame] | 130 | |
[email protected] | c6d474f8 | 2009-12-16 21:11:06 | [diff] [blame] | 131 | namespace errors = extension_manifest_errors; |
| 132 | |
[email protected] | b6ab96d | 2009-08-20 18:58:19 | [diff] [blame] | 133 | namespace { |
| 134 | |
[email protected] | 29d0d4ac | 2010-09-08 21:10:31 | [diff] [blame] | 135 | #if defined(OS_LINUX) |
| 136 | static const int kOmniboxIconPaddingLeft = 2; |
| 137 | static const int kOmniboxIconPaddingRight = 2; |
| 138 | #elif defined(OS_MACOSX) |
| 139 | static const int kOmniboxIconPaddingLeft = 0; |
| 140 | static const int kOmniboxIconPaddingRight = 2; |
| 141 | #else |
| 142 | static const int kOmniboxIconPaddingLeft = 0; |
| 143 | static const int kOmniboxIconPaddingRight = 0; |
| 144 | #endif |
| 145 | |
[email protected] | 300c0ea | 2011-07-15 23:04:33 | [diff] [blame] | 146 | const char* kNaClPluginMimeType = "application/x-nacl"; |
| 147 | |
[email protected] | 2de30759 | 2011-04-05 21:16:58 | [diff] [blame] | 148 | static void ForceShutdownPlugin(const FilePath& plugin_path) { |
| 149 | PluginProcessHost* plugin = |
| 150 | PluginService::GetInstance()->FindNpapiPluginProcess(plugin_path); |
| 151 | if (plugin) |
| 152 | plugin->ForceShutdown(); |
| 153 | } |
| 154 | |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 155 | static bool IsSyncableExtension(const Extension& extension) { |
| 156 | return extension.GetSyncType() == Extension::SYNC_TYPE_EXTENSION; |
| 157 | } |
| 158 | |
| 159 | static bool IsSyncableApp(const Extension& extension) { |
| 160 | return extension.GetSyncType() == Extension::SYNC_TYPE_APP; |
| 161 | } |
| 162 | |
[email protected] | c6d474f8 | 2009-12-16 21:11:06 | [diff] [blame] | 163 | } // namespace |
[email protected] | b6ab96d | 2009-08-20 18:58:19 | [diff] [blame] | 164 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 165 | ExtensionService::ExtensionRuntimeData::ExtensionRuntimeData() |
[email protected] | d7e9a86 | 2010-11-03 21:57:49 | [diff] [blame] | 166 | : background_page_ready(false), |
[email protected] | f8bf599 | 2011-10-24 22:38:57 | [diff] [blame] | 167 | being_upgraded(false), |
| 168 | has_used_webrequest(false) { |
[email protected] | d7e9a86 | 2010-11-03 21:57:49 | [diff] [blame] | 169 | } |
| 170 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 171 | ExtensionService::ExtensionRuntimeData::~ExtensionRuntimeData() { |
[email protected] | d7e9a86 | 2010-11-03 21:57:49 | [diff] [blame] | 172 | } |
| 173 | |
[email protected] | cebc3dc | 2011-04-18 17:15:00 | [diff] [blame] | 174 | ExtensionService::NaClModuleInfo::NaClModuleInfo() { |
| 175 | } |
| 176 | |
| 177 | ExtensionService::NaClModuleInfo::~NaClModuleInfo() { |
| 178 | } |
| 179 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 180 | // ExtensionService. |
[email protected] | 6014d67 | 2008-12-05 00:38:25 | [diff] [blame] | 181 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 182 | const char* ExtensionService::kInstallDirectoryName = "Extensions"; |
[email protected] | 15d5b47 | 2011-11-24 04:17:24 | [diff] [blame] | 183 | |
| 184 | const char* ExtensionService::kLocalAppSettingsDirectoryName = |
| 185 | "Local App Settings"; |
| 186 | const char* ExtensionService::kLocalExtensionSettingsDirectoryName = |
| 187 | "Local Extension Settings"; |
| 188 | const char* ExtensionService::kSyncAppSettingsDirectoryName = |
| 189 | "Sync App Settings"; |
| 190 | const char* ExtensionService::kSyncExtensionSettingsDirectoryName = |
| 191 | "Sync Extension Settings"; |
[email protected] | 494c06e | 2009-07-25 01:06:42 | [diff] [blame] | 192 | |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 193 | void ExtensionService::CheckExternalUninstall(const std::string& id) { |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 194 | CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
[email protected] | a8af9fdb | 2010-10-28 21:52:20 | [diff] [blame] | 195 | |
[email protected] | 7a4c685 | 2010-09-16 03:44:22 | [diff] [blame] | 196 | // Check if the providers know about this extension. |
[email protected] | 0a60a2e | 2010-10-25 16:15:21 | [diff] [blame] | 197 | ProviderCollection::const_iterator i; |
| 198 | for (i = external_extension_providers_.begin(); |
| 199 | i != external_extension_providers_.end(); ++i) { |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 200 | DCHECK(i->get()->IsReady()); |
[email protected] | 0a60a2e | 2010-10-25 16:15:21 | [diff] [blame] | 201 | if (i->get()->HasExtension(id)) |
| 202 | return; // Yup, known extension, don't uninstall. |
[email protected] | 7a4c685 | 2010-09-16 03:44:22 | [diff] [blame] | 203 | } |
| 204 | |
[email protected] | 0f48fca | 2011-05-19 18:46:35 | [diff] [blame] | 205 | // We get the list of external extensions to check from preferences. |
| 206 | // It is possible that an extension has preferences but is not loaded. |
| 207 | // For example, an extension that requires experimental permissions |
| 208 | // will not be loaded if the experimental command line flag is not used. |
| 209 | // In this case, do not uninstall. |
| 210 | const Extension* extension = GetInstalledExtension(id); |
| 211 | if (!extension) { |
| 212 | // We can't call UninstallExtension with an unloaded/invalid |
| 213 | // extension ID. |
| 214 | LOG(WARNING) << "Attempted uninstallation of unloaded/invalid extension " |
| 215 | << "with id: " << id; |
| 216 | return; |
| 217 | } |
[email protected] | d6ebc979 | 2011-04-07 18:18:33 | [diff] [blame] | 218 | UninstallExtension(id, true, NULL); |
[email protected] | 7a4c685 | 2010-09-16 03:44:22 | [diff] [blame] | 219 | } |
| 220 | |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 221 | void ExtensionService::ClearProvidersForTesting() { |
[email protected] | 7a4c685 | 2010-09-16 03:44:22 | [diff] [blame] | 222 | external_extension_providers_.clear(); |
| 223 | } |
| 224 | |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 225 | void ExtensionService::AddProviderForTesting( |
| 226 | ExternalExtensionProviderInterface* test_provider) { |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 227 | CHECK(test_provider); |
[email protected] | 0a60a2e | 2010-10-25 16:15:21 | [diff] [blame] | 228 | external_extension_providers_.push_back( |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 229 | linked_ptr<ExternalExtensionProviderInterface>(test_provider)); |
[email protected] | 7a4c685 | 2010-09-16 03:44:22 | [diff] [blame] | 230 | } |
| 231 | |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 232 | void ExtensionService::OnExternalExtensionUpdateUrlFound( |
[email protected] | 7a4c685 | 2010-09-16 03:44:22 | [diff] [blame] | 233 | const std::string& id, |
[email protected] | 21a5a67 | 2010-11-04 10:47:42 | [diff] [blame] | 234 | const GURL& update_url, |
| 235 | Extension::Location location) { |
[email protected] | ab22ba4 | 2011-01-14 16:36:38 | [diff] [blame] | 236 | CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 237 | CHECK(Extension::IdIsValid(id)); |
[email protected] | a8af9fdb | 2010-10-28 21:52:20 | [diff] [blame] | 238 | |
[email protected] | 8a87a533 | 2011-08-11 17:54:59 | [diff] [blame] | 239 | const Extension* extension = GetExtensionById(id, true); |
| 240 | if (extension) { |
| 241 | // Already installed. Skip this install if the current location has |
| 242 | // higher priority than |location|. |
| 243 | Extension::Location current = extension->location(); |
| 244 | if (current == Extension::GetHigherPriorityLocation(current, location)) |
| 245 | return; |
| 246 | // Otherwise, overwrite the current installation. |
[email protected] | 7a4c685 | 2010-09-16 03:44:22 | [diff] [blame] | 247 | } |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 248 | pending_extension_manager()->AddFromExternalUpdateUrl( |
| 249 | id, update_url, location); |
[email protected] | 50067e5 | 2011-10-20 23:17:07 | [diff] [blame] | 250 | external_extension_url_added_ = true; |
[email protected] | 7a4c685 | 2010-09-16 03:44:22 | [diff] [blame] | 251 | } |
| 252 | |
[email protected] | 454434f | 2011-08-24 04:00:00 | [diff] [blame] | 253 | // If a download url matches one of these patterns and has a referrer of the |
| 254 | // webstore, then we're willing to treat that as a gallery download. |
| 255 | static const char* kAllowedDownloadURLPatterns[] = { |
| 256 | "https://clients2.google.com/service/update2*", |
| 257 | "https://clients2.googleusercontent.com/crx/*" |
| 258 | }; |
| 259 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 260 | bool ExtensionService::IsDownloadFromGallery(const GURL& download_url, |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 261 | const GURL& referrer_url) { |
[email protected] | 615d88f | 2011-12-13 01:47:44 | [diff] [blame] | 262 | const Extension* download_extension = |
| 263 | extensions_.GetHostedAppByURL(ExtensionURLInfo(download_url)); |
| 264 | const Extension* referrer_extension = |
| 265 | extensions_.GetHostedAppByURL(ExtensionURLInfo(referrer_url)); |
[email protected] | 9adb969 | 2010-10-29 23:14:02 | [diff] [blame] | 266 | const Extension* webstore_app = GetWebStoreApp(); |
[email protected] | d307199 | 2010-10-08 15:24:07 | [diff] [blame] | 267 | |
| 268 | bool referrer_valid = (referrer_extension == webstore_app); |
| 269 | bool download_valid = (download_extension == webstore_app); |
| 270 | |
[email protected] | 454434f | 2011-08-24 04:00:00 | [diff] [blame] | 271 | // We also allow the download to be from a small set of trusted paths. |
| 272 | if (!download_valid) { |
| 273 | for (size_t i = 0; i < arraysize(kAllowedDownloadURLPatterns); i++) { |
| 274 | URLPattern pattern(URLPattern::SCHEME_HTTPS, |
| 275 | kAllowedDownloadURLPatterns[i]); |
| 276 | if (pattern.MatchesURL(download_url)) { |
| 277 | download_valid = true; |
| 278 | break; |
| 279 | } |
| 280 | } |
| 281 | } |
| 282 | |
[email protected] | d307199 | 2010-10-08 15:24:07 | [diff] [blame] | 283 | // If the command-line gallery URL is set, then be a bit more lenient. |
| 284 | GURL store_url = |
| 285 | GURL(CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 286 | switches::kAppsGalleryURL)); |
| 287 | if (!store_url.is_empty()) { |
| 288 | std::string store_tld = |
| 289 | net::RegistryControlledDomainService::GetDomainAndRegistry(store_url); |
| 290 | if (!referrer_valid) { |
| 291 | std::string referrer_tld = |
| 292 | net::RegistryControlledDomainService::GetDomainAndRegistry( |
| 293 | referrer_url); |
| 294 | // The referrer gets stripped when transitioning from https to http, |
| 295 | // or when hitting an unknown test cert and that commonly happens in |
| 296 | // testing environments. Given this, we allow an empty referrer when |
| 297 | // the command-line flag is set. |
| 298 | // Otherwise, the TLD must match the TLD of the command-line url. |
| 299 | referrer_valid = referrer_url.is_empty() || (referrer_tld == store_tld); |
| 300 | } |
| 301 | |
| 302 | if (!download_valid) { |
| 303 | std::string download_tld = |
| 304 | net::RegistryControlledDomainService::GetDomainAndRegistry( |
[email protected] | 04866c4 | 2011-05-03 20:03:50 | [diff] [blame] | 305 | download_url); |
[email protected] | d307199 | 2010-10-08 15:24:07 | [diff] [blame] | 306 | |
| 307 | // Otherwise, the TLD must match the TLD of the command-line url. |
| 308 | download_valid = (download_tld == store_tld); |
| 309 | } |
| 310 | } |
| 311 | |
| 312 | return (referrer_valid && download_valid); |
[email protected] | b7c2f25 | 2009-12-08 00:47:23 | [diff] [blame] | 313 | } |
| 314 | |
[email protected] | d969667 | 2011-03-15 22:45:09 | [diff] [blame] | 315 | const Extension* ExtensionService::GetInstalledApp(const GURL& url) { |
[email protected] | 615d88f | 2011-12-13 01:47:44 | [diff] [blame] | 316 | const Extension* extension = extensions_.GetExtensionOrAppByURL( |
| 317 | ExtensionURLInfo(url)); |
| 318 | if (extension && extension->is_app()) |
| 319 | return extension; |
[email protected] | d969667 | 2011-03-15 22:45:09 | [diff] [blame] | 320 | |
| 321 | return NULL; |
| 322 | } |
| 323 | |
| 324 | bool ExtensionService::IsInstalledApp(const GURL& url) { |
| 325 | return !!GetInstalledApp(url); |
[email protected] | ffb204f2 | 2010-12-05 23:20:27 | [diff] [blame] | 326 | } |
| 327 | |
[email protected] | da5683db | 2011-04-23 17:12:21 | [diff] [blame] | 328 | void ExtensionService::SetInstalledAppForRenderer(int renderer_child_id, |
| 329 | const Extension* app) { |
| 330 | installed_app_hosts_[renderer_child_id] = app; |
| 331 | } |
| 332 | |
| 333 | const Extension* ExtensionService::GetInstalledAppForRenderer( |
| 334 | int renderer_child_id) { |
| 335 | InstalledAppMap::iterator i = installed_app_hosts_.find(renderer_child_id); |
| 336 | if (i == installed_app_hosts_.end()) |
| 337 | return NULL; |
| 338 | return i->second; |
| 339 | } |
| 340 | |
[email protected] | 6aeac834 | 2010-10-01 20:21:18 | [diff] [blame] | 341 | // static |
[email protected] | d6ebc979 | 2011-04-07 18:18:33 | [diff] [blame] | 342 | // This function is used to implement the command-line switch |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 343 | // --uninstall-extension, and to uninstall an extension via sync. The LOG |
| 344 | // statements within this function are used to inform the user if the uninstall |
| 345 | // cannot be done. |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 346 | bool ExtensionService::UninstallExtensionHelper( |
| 347 | ExtensionService* extensions_service, |
[email protected] | 6aeac834 | 2010-10-01 20:21:18 | [diff] [blame] | 348 | const std::string& extension_id) { |
[email protected] | 6aeac834 | 2010-10-01 20:21:18 | [diff] [blame] | 349 | |
[email protected] | 95da88c4 | 2011-03-31 10:07:33 | [diff] [blame] | 350 | const Extension* extension = |
[email protected] | 8001df2 | 2011-04-28 19:59:47 | [diff] [blame] | 351 | extensions_service->GetInstalledExtension(extension_id); |
[email protected] | 95da88c4 | 2011-03-31 10:07:33 | [diff] [blame] | 352 | |
[email protected] | d6ebc979 | 2011-04-07 18:18:33 | [diff] [blame] | 353 | // We can't call UninstallExtension with an invalid extension ID. |
[email protected] | 95da88c4 | 2011-03-31 10:07:33 | [diff] [blame] | 354 | if (!extension) { |
[email protected] | 6aeac834 | 2010-10-01 20:21:18 | [diff] [blame] | 355 | LOG(WARNING) << "Attempted uninstallation of non-existent extension with " |
[email protected] | 95da88c4 | 2011-03-31 10:07:33 | [diff] [blame] | 356 | << "id: " << extension_id; |
| 357 | return false; |
[email protected] | 6aeac834 | 2010-10-01 20:21:18 | [diff] [blame] | 358 | } |
| 359 | |
[email protected] | d6ebc979 | 2011-04-07 18:18:33 | [diff] [blame] | 360 | // The following call to UninstallExtension will not allow an uninstall of a |
| 361 | // policy-controlled extension. |
| 362 | std::string error; |
| 363 | if (!extensions_service->UninstallExtension(extension_id, false, &error)) { |
| 364 | LOG(WARNING) << "Cannot uninstall extension with id " << extension_id |
| 365 | << ": " << error; |
| 366 | return false; |
| 367 | } |
[email protected] | 95da88c4 | 2011-03-31 10:07:33 | [diff] [blame] | 368 | |
[email protected] | 6aeac834 | 2010-10-01 20:21:18 | [diff] [blame] | 369 | return true; |
| 370 | } |
| 371 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 372 | ExtensionService::ExtensionService(Profile* profile, |
[email protected] | f0841cd | 2011-01-19 15:07:24 | [diff] [blame] | 373 | const CommandLine* command_line, |
| 374 | const FilePath& install_directory, |
| 375 | ExtensionPrefs* extension_prefs, |
[email protected] | 0436b10 | 2011-04-15 18:30:03 | [diff] [blame] | 376 | bool autoupdate_enabled, |
| 377 | bool extensions_enabled) |
[email protected] | d8c8f25f | 2011-11-02 18:18:01 | [diff] [blame] | 378 | : profile_(profile), |
[email protected] | 73c4793 | 2010-12-06 18:13:43 | [diff] [blame] | 379 | extension_prefs_(extension_prefs), |
[email protected] | cccdf0aa | 2011-11-11 03:43:38 | [diff] [blame] | 380 | settings_frontend_(extensions::SettingsFrontend::Create(profile)), |
[email protected] | 14908b7 | 2011-04-20 06:54:36 | [diff] [blame] | 381 | pending_extension_manager_(*ALLOW_THIS_IN_INITIALIZER_LIST(this)), |
[email protected] | a9b00ac | 2009-06-25 21:03:23 | [diff] [blame] | 382 | install_directory_(install_directory), |
[email protected] | 0436b10 | 2011-04-15 18:30:03 | [diff] [blame] | 383 | extensions_enabled_(extensions_enabled), |
[email protected] | e81dba3 | 2009-06-19 20:19:13 | [diff] [blame] | 384 | show_extensions_prompts_(true), |
[email protected] | 3ecda25 | 2010-11-18 19:50:55 | [diff] [blame] | 385 | ready_(false), |
[email protected] | 14908b7 | 2011-04-20 06:54:36 | [diff] [blame] | 386 | toolbar_model_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), |
[email protected] | 8b28030 | 2011-10-13 22:22:23 | [diff] [blame] | 387 | menu_manager_(profile), |
[email protected] | af9db5f | 2011-10-05 05:13:15 | [diff] [blame] | 388 | app_notification_manager_(new AppNotificationManager(profile)), |
[email protected] | 18cc5a5 | 2011-04-15 16:03:38 | [diff] [blame] | 389 | apps_promo_(profile->GetPrefs()), |
[email protected] | 7c1490da | 2011-10-11 18:53:25 | [diff] [blame] | 390 | event_routers_initialized_(false), |
[email protected] | a1755bd | 2011-12-09 00:40:20 | [diff] [blame] | 391 | extension_warnings_(profile), |
[email protected] | e1fae1c | 2011-12-13 22:17:17 | [diff] [blame] | 392 | socket_controller_(NULL), |
[email protected] | b39e7a88b | 2012-01-10 21:43:17 | [diff] [blame] | 393 | tracker_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 394 | CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
[email protected] | a8af9fdb | 2010-10-28 21:52:20 | [diff] [blame] | 395 | |
[email protected] | 36a784c | 2009-06-23 06:21:08 | [diff] [blame] | 396 | // Figure out if extension installation should be enabled. |
[email protected] | 6d60703b | 2009-08-29 01:29:23 | [diff] [blame] | 397 | if (command_line->HasSwitch(switches::kDisableExtensions)) { |
| 398 | extensions_enabled_ = false; |
| 399 | } else if (profile->GetPrefs()->GetBoolean(prefs::kDisableExtensions)) { |
| 400 | extensions_enabled_ = false; |
[email protected] | 6b75ec3 | 2009-08-14 06:37:18 | [diff] [blame] | 401 | } |
[email protected] | 36a784c | 2009-06-23 06:21:08 | [diff] [blame] | 402 | |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 403 | registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_PROCESS_TERMINATED, |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 404 | content::NotificationService::AllBrowserContextsAndSources()); |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 405 | registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_CREATED, |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 406 | content::NotificationService::AllBrowserContextsAndSources()); |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 407 | registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_TERMINATED, |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 408 | content::NotificationService::AllBrowserContextsAndSources()); |
[email protected] | 2fb7dc98 | 2010-09-29 12:24:28 | [diff] [blame] | 409 | pref_change_registrar_.Init(profile->GetPrefs()); |
| 410 | pref_change_registrar_.Add(prefs::kExtensionInstallAllowList, this); |
| 411 | pref_change_registrar_.Add(prefs::kExtensionInstallDenyList, this); |
[email protected] | 4814b51 | 2009-11-07 00:12:29 | [diff] [blame] | 412 | |
[email protected] | 93fd78f4 | 2009-07-10 16:43:17 | [diff] [blame] | 413 | // Set up the ExtensionUpdater |
| 414 | if (autoupdate_enabled) { |
| 415 | int update_frequency = kDefaultUpdateFrequencySeconds; |
| 416 | if (command_line->HasSwitch(switches::kExtensionsUpdateFrequency)) { |
[email protected] | e83326f | 2010-07-31 17:29:25 | [diff] [blame] | 417 | base::StringToInt(command_line->GetSwitchValueASCII( |
| 418 | switches::kExtensionsUpdateFrequency), |
| 419 | &update_frequency); |
[email protected] | 93fd78f4 | 2009-07-10 16:43:17 | [diff] [blame] | 420 | } |
[email protected] | 82b6e51 | 2011-04-12 20:33:27 | [diff] [blame] | 421 | updater_.reset(new ExtensionUpdater(this, |
| 422 | extension_prefs, |
| 423 | profile->GetPrefs(), |
| 424 | profile, |
| 425 | update_frequency)); |
[email protected] | 93fd78f4 | 2009-07-10 16:43:17 | [diff] [blame] | 426 | } |
| 427 | |
[email protected] | 25ae015 | 2011-11-18 14:40:02 | [diff] [blame] | 428 | component_loader_.reset( |
| 429 | new extensions::ComponentLoader(this, |
| 430 | profile->GetPrefs(), |
| 431 | g_browser_process->local_state())); |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 432 | |
[email protected] | af9db5f | 2011-10-05 05:13:15 | [diff] [blame] | 433 | app_notification_manager_->Init(); |
| 434 | |
[email protected] | 0436b10 | 2011-04-15 18:30:03 | [diff] [blame] | 435 | if (extensions_enabled_) { |
[email protected] | 1f2f300 | 2011-12-28 00:40:21 | [diff] [blame] | 436 | if (!command_line->HasSwitch(switches::kImport) && |
| 437 | !command_line->HasSwitch(switches::kImportFromFile)) { |
| 438 | ExternalExtensionProviderImpl::CreateExternalProviders( |
| 439 | this, profile_, &external_extension_providers_); |
| 440 | } |
[email protected] | 87353134 | 2011-03-09 12:16:05 | [diff] [blame] | 441 | } |
[email protected] | b671760b | 2010-07-15 21:13:47 | [diff] [blame] | 442 | |
[email protected] | aa96d3a | 2010-08-21 08:45:25 | [diff] [blame] | 443 | // Use monochrome icons for Omnibox icons. |
[email protected] | 29d0d4ac | 2010-09-08 21:10:31 | [diff] [blame] | 444 | omnibox_popup_icon_manager_.set_monochrome(true); |
[email protected] | b671760b | 2010-07-15 21:13:47 | [diff] [blame] | 445 | omnibox_icon_manager_.set_monochrome(true); |
[email protected] | 29d0d4ac | 2010-09-08 21:10:31 | [diff] [blame] | 446 | omnibox_icon_manager_.set_padding(gfx::Insets(0, kOmniboxIconPaddingLeft, |
| 447 | 0, kOmniboxIconPaddingRight)); |
[email protected] | cb0e5031 | 2011-05-09 15:03:07 | [diff] [blame] | 448 | |
| 449 | // How long is the path to the Extensions directory? |
| 450 | UMA_HISTOGRAM_CUSTOM_COUNTS("Extensions.ExtensionRootPathLength", |
| 451 | install_directory_.value().length(), 0, 500, 100); |
[email protected] | 6014d67 | 2008-12-05 00:38:25 | [diff] [blame] | 452 | } |
| 453 | |
[email protected] | 84df833 | 2011-12-06 18:22:46 | [diff] [blame] | 454 | const ExtensionSet* ExtensionService::extensions() const { |
[email protected] | ddb1e5a | 2010-12-13 20:10:45 | [diff] [blame] | 455 | return &extensions_; |
| 456 | } |
| 457 | |
[email protected] | 84df833 | 2011-12-06 18:22:46 | [diff] [blame] | 458 | const ExtensionSet* ExtensionService::disabled_extensions() const { |
[email protected] | ddb1e5a | 2010-12-13 20:10:45 | [diff] [blame] | 459 | return &disabled_extensions_; |
| 460 | } |
| 461 | |
[email protected] | 84df833 | 2011-12-06 18:22:46 | [diff] [blame] | 462 | const ExtensionSet* ExtensionService::terminated_extensions() const { |
[email protected] | bb7f4095 | 2011-01-13 00:21:20 | [diff] [blame] | 463 | return &terminated_extensions_; |
| 464 | } |
| 465 | |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 466 | PendingExtensionManager* ExtensionService::pending_extension_manager() { |
| 467 | return &pending_extension_manager_; |
[email protected] | ddb1e5a | 2010-12-13 20:10:45 | [diff] [blame] | 468 | } |
| 469 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 470 | ExtensionService::~ExtensionService() { |
[email protected] | c8d407e | 2011-04-28 21:27:17 | [diff] [blame] | 471 | // No need to unload extensions here because they are profile-scoped, and the |
| 472 | // profile is in the process of being deleted. |
[email protected] | 94b4ffc | 2011-02-04 05:55:17 | [diff] [blame] | 473 | |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 474 | ProviderCollection::const_iterator i; |
| 475 | for (i = external_extension_providers_.begin(); |
| 476 | i != external_extension_providers_.end(); ++i) { |
| 477 | ExternalExtensionProviderInterface* provider = i->get(); |
| 478 | provider->ServiceShutdown(); |
| 479 | } |
[email protected] | a1755bd | 2011-12-09 00:40:20 | [diff] [blame] | 480 | |
| 481 | // TODO(miket): if we find ourselves adding more and more per-API |
| 482 | // controllers, we should manage them all with an |
| 483 | // APIControllerController (still working on that name). |
[email protected] | e1fae1c | 2011-12-13 22:17:17 | [diff] [blame] | 484 | if (socket_controller_) { |
| 485 | // If this check failed, then a unit test was using sockets but didn't |
| 486 | // provide the IO thread message loop needed for those sockets to do their |
| 487 | // job (including destroying themselves at shutdown). |
| 488 | DCHECK(BrowserThread::IsMessageLoopValid(BrowserThread::IO)); |
[email protected] | cff06c57 | 2012-01-02 20:03:05 | [diff] [blame] | 489 | BrowserThread::DeleteSoon(BrowserThread::IO, FROM_HERE, socket_controller_); |
[email protected] | e1fae1c | 2011-12-13 22:17:17 | [diff] [blame] | 490 | } |
[email protected] | 6014d67 | 2008-12-05 00:38:25 | [diff] [blame] | 491 | } |
| 492 | |
[email protected] | d9126802 | 2011-08-26 13:17:37 | [diff] [blame] | 493 | void ExtensionService::InitEventRoutersAfterImport() { |
[email protected] | cf593af | 2011-12-30 05:44:39 | [diff] [blame] | 494 | RegisterForImportFinished(); |
| 495 | } |
| 496 | |
| 497 | void ExtensionService::RegisterForImportFinished() { |
| 498 | if (!registrar_.IsRegistered(this, chrome::NOTIFICATION_IMPORT_FINISHED, |
| 499 | content::Source<Profile>(profile_))) { |
| 500 | registrar_.Add(this, chrome::NOTIFICATION_IMPORT_FINISHED, |
| 501 | content::Source<Profile>(profile_)); |
| 502 | } |
| 503 | } |
| 504 | |
| 505 | void ExtensionService::InitAfterImport() { |
| 506 | CheckForExternalUpdates(); |
| 507 | |
| 508 | GarbageCollectExtensions(); |
| 509 | |
| 510 | // Idempotent, so although there is a possible race if the import |
| 511 | // process finished sometime in the middle of ProfileImpl::InitExtensions, |
| 512 | // it cannot happen twice. |
| 513 | InitEventRouters(); |
[email protected] | d9126802 | 2011-08-26 13:17:37 | [diff] [blame] | 514 | } |
| 515 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 516 | void ExtensionService::InitEventRouters() { |
[email protected] | b3d62312b1 | 2010-10-14 21:10:18 | [diff] [blame] | 517 | if (event_routers_initialized_) |
| 518 | return; |
| 519 | |
[email protected] | 370e950 | 2011-09-14 19:31:44 | [diff] [blame] | 520 | downloads_event_router_.reset(new ExtensionDownloadsEventRouter(profile_)); |
[email protected] | d2e6bd6 | 2011-10-24 20:29:07 | [diff] [blame] | 521 | history_event_router_.reset(new HistoryExtensionEventRouter()); |
[email protected] | f825df2 | 2011-06-28 17:36:10 | [diff] [blame] | 522 | history_event_router_->ObserveProfile(profile_); |
[email protected] | 97d2f1d | 2011-01-15 00:41:08 | [diff] [blame] | 523 | browser_event_router_.reset(new ExtensionBrowserEventRouter(profile_)); |
| 524 | browser_event_router_->Init(); |
[email protected] | 118de789 | 2011-03-16 13:31:40 | [diff] [blame] | 525 | preference_event_router_.reset(new ExtensionPreferenceEventRouter(profile_)); |
[email protected] | 23d5f17 | 2011-10-25 05:49:53 | [diff] [blame] | 526 | bookmark_event_router_.reset(new BookmarkExtensionEventRouter( |
[email protected] | f825df2 | 2011-06-28 17:36:10 | [diff] [blame] | 527 | profile_->GetBookmarkModel())); |
| 528 | bookmark_event_router_->Init(); |
| 529 | cookies_event_router_.reset(new ExtensionCookiesEventRouter(profile_)); |
| 530 | cookies_event_router_->Init(); |
| 531 | management_event_router_.reset(new ExtensionManagementEventRouter(profile_)); |
| 532 | management_event_router_->Init(); |
[email protected] | 7da9a823 | 2011-05-27 21:07:11 | [diff] [blame] | 533 | ExtensionProcessesEventRouter::GetInstance()->ObserveProfile(profile_); |
[email protected] | f825df2 | 2011-06-28 17:36:10 | [diff] [blame] | 534 | web_navigation_event_router_.reset( |
| 535 | new ExtensionWebNavigationEventRouter(profile_)); |
| 536 | web_navigation_event_router_->Init(); |
[email protected] | 27072cad | 2011-05-09 19:46:40 | [diff] [blame] | 537 | |
[email protected] | eed367e | 2011-04-12 03:43:31 | [diff] [blame] | 538 | #if defined(OS_CHROMEOS) |
[email protected] | b16fc2e | 2011-07-21 21:32:58 | [diff] [blame] | 539 | file_browser_event_router_.reset( |
| 540 | new ExtensionFileBrowserEventRouter(profile_)); |
| 541 | file_browser_event_router_->ObserveFileSystemEvents(); |
[email protected] | 771a618 | 2011-10-05 16:32:52 | [diff] [blame] | 542 | |
| 543 | input_method_event_router_.reset( |
| 544 | new chromeos::ExtensionInputMethodEventRouter); |
[email protected] | be5bd574 | 2011-07-14 07:21:01 | [diff] [blame] | 545 | |
[email protected] | c8bf09be | 2011-06-25 03:22:27 | [diff] [blame] | 546 | ExtensionMediaPlayerEventRouter::GetInstance()->Init(profile_); |
[email protected] | 8baf0dbb | 2011-11-27 22:47:02 | [diff] [blame] | 547 | ExtensionInputImeEventRouter::GetInstance()->Init(); |
[email protected] | eed367e | 2011-04-12 03:43:31 | [diff] [blame] | 548 | #endif |
[email protected] | 27072cad | 2011-05-09 19:46:40 | [diff] [blame] | 549 | |
[email protected] | 9a2aebe0 | 2011-12-02 21:54:14 | [diff] [blame] | 550 | #if defined(OS_CHROMEOS) && defined(USE_VIRTUAL_KEYBOARD) |
[email protected] | 27072cad | 2011-05-09 19:46:40 | [diff] [blame] | 551 | ExtensionInputUiEventRouter::GetInstance()->Init(); |
| 552 | #endif |
| 553 | |
[email protected] | b3d62312b1 | 2010-10-14 21:10:18 | [diff] [blame] | 554 | event_routers_initialized_ = true; |
[email protected] | c5ae74ab | 2010-04-15 18:14:37 | [diff] [blame] | 555 | } |
| 556 | |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 557 | const Extension* ExtensionService::GetExtensionById( |
| 558 | const std::string& id, bool include_disabled) const { |
[email protected] | 8001df2 | 2011-04-28 19:59:47 | [diff] [blame] | 559 | return GetExtensionByIdInternal(id, true, include_disabled, false); |
[email protected] | 78994ab0 | 2010-12-08 18:06:44 | [diff] [blame] | 560 | } |
| 561 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 562 | void ExtensionService::Init() { |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 563 | CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
[email protected] | a8af9fdb | 2010-10-28 21:52:20 | [diff] [blame] | 564 | |
[email protected] | fa6a910 | 2010-11-22 15:38:50 | [diff] [blame] | 565 | DCHECK(!ready_); // Can't redo init. |
[email protected] | 93fd78f4 | 2009-07-10 16:43:17 | [diff] [blame] | 566 | DCHECK_EQ(extensions_.size(), 0u); |
[email protected] | 9f1087e | 2009-06-15 17:29:32 | [diff] [blame] | 567 | |
[email protected] | d8c8f25f | 2011-11-02 18:18:01 | [diff] [blame] | 568 | component_loader_->LoadAll(); |
| 569 | extensions::InstalledLoader(this).LoadAllExtensions(); |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 570 | |
[email protected] | 7a161db | 2011-12-15 20:45:51 | [diff] [blame] | 571 | // If we are running in the import process, don't bother initializing the |
| 572 | // extension service since this can interfere with the main browser process |
| 573 | // that is already running an extension service for this profile. |
| 574 | // TODO(aa): can we start up even less of ExtensionService? |
| 575 | // http://crbug.com/107636 |
[email protected] | 1f2f300 | 2011-12-28 00:40:21 | [diff] [blame] | 576 | if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kImport) && |
| 577 | !CommandLine::ForCurrentProcess()->HasSwitch(switches::kImportFromFile)) { |
[email protected] | cf593af | 2011-12-30 05:44:39 | [diff] [blame] | 578 | if (g_browser_process->profile_manager() && |
| 579 | g_browser_process->profile_manager()->will_import()) { |
| 580 | RegisterForImportFinished(); |
| 581 | } else { |
| 582 | // TODO(erikkay) this should probably be deferred to a future point |
| 583 | // rather than running immediately at startup. |
| 584 | CheckForExternalUpdates(); |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 585 | |
[email protected] | cf593af | 2011-12-30 05:44:39 | [diff] [blame] | 586 | // TODO(erikkay) this should probably be deferred as well. |
| 587 | GarbageCollectExtensions(); |
| 588 | } |
[email protected] | 7a161db | 2011-12-15 20:45:51 | [diff] [blame] | 589 | } |
[email protected] | 6014d67 | 2008-12-05 00:38:25 | [diff] [blame] | 590 | } |
| 591 | |
[email protected] | 420a0ec | 2011-06-01 01:07:03 | [diff] [blame] | 592 | bool ExtensionService::UpdateExtension( |
| 593 | const std::string& id, |
| 594 | const FilePath& extension_path, |
| 595 | const GURL& download_url, |
| 596 | CrxInstaller** out_crx_installer) { |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 597 | CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
[email protected] | a8af9fdb | 2010-10-28 21:52:20 | [diff] [blame] | 598 | |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 599 | PendingExtensionInfo pending_extension_info; |
| 600 | bool is_pending_extension = pending_extension_manager_.GetById( |
| 601 | id, &pending_extension_info); |
[email protected] | 8ef78fd | 2010-08-19 17:14:32 | [diff] [blame] | 602 | |
[email protected] | 8001df2 | 2011-04-28 19:59:47 | [diff] [blame] | 603 | const Extension* extension = |
| 604 | GetExtensionByIdInternal(id, true, true, false); |
[email protected] | 5eb375e9 | 2010-11-26 07:50:41 | [diff] [blame] | 605 | if (!is_pending_extension && !extension) { |
[email protected] | aa14270 | 2010-03-26 01:26:33 | [diff] [blame] | 606 | LOG(WARNING) << "Will not update extension " << id |
| 607 | << " because it is not installed or pending"; |
| 608 | // Delete extension_path since we're not creating a CrxInstaller |
| 609 | // that would do it for us. |
[email protected] | 14908b7 | 2011-04-20 06:54:36 | [diff] [blame] | 610 | if (!BrowserThread::PostTask( |
| 611 | BrowserThread::FILE, FROM_HERE, |
[email protected] | 53612e8 | 2011-10-18 18:00:36 | [diff] [blame] | 612 | base::Bind( |
[email protected] | 7296f276 | 2011-11-21 19:23:44 | [diff] [blame] | 613 | &extension_file_util::DeleteFile, extension_path, false))) |
[email protected] | 14908b7 | 2011-04-20 06:54:36 | [diff] [blame] | 614 | NOTREACHED(); |
[email protected] | 420a0ec | 2011-06-01 01:07:03 | [diff] [blame] | 615 | |
| 616 | return false; |
[email protected] | e957fe5 | 2009-06-23 16:51:05 | [diff] [blame] | 617 | } |
| 618 | |
[email protected] | aa14270 | 2010-03-26 01:26:33 | [diff] [blame] | 619 | // We want a silent install only for non-pending extensions and |
| 620 | // pending extensions that have install_silently set. |
| 621 | ExtensionInstallUI* client = |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 622 | (!is_pending_extension || pending_extension_info.install_silently()) ? |
[email protected] | aa14270 | 2010-03-26 01:26:33 | [diff] [blame] | 623 | NULL : new ExtensionInstallUI(profile_); |
| 624 | |
[email protected] | d8c8f25f | 2011-11-02 18:18:01 | [diff] [blame] | 625 | scoped_refptr<CrxInstaller> installer(CrxInstaller::Create(this, client)); |
[email protected] | 6dfbbf8 | 2010-03-12 23:09:16 | [diff] [blame] | 626 | installer->set_expected_id(id); |
[email protected] | ec5b50d | 2010-10-09 16:35:18 | [diff] [blame] | 627 | if (is_pending_extension) |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 628 | installer->set_install_source(pending_extension_info.install_source()); |
[email protected] | 5eb375e9 | 2010-11-26 07:50:41 | [diff] [blame] | 629 | else if (extension) |
| 630 | installer->set_install_source(extension->location()); |
[email protected] | 0d3e4a2 | 2011-06-23 19:02:52 | [diff] [blame] | 631 | if (pending_extension_info.install_silently()) |
| 632 | installer->set_allow_silent_install(true); |
[email protected] | 7576451 | 2011-12-19 19:54:28 | [diff] [blame] | 633 | // If the extension came from sync and its auto-update URL is from the |
| 634 | // webstore, treat it as a webstore install. Note that we ignore some older |
| 635 | // extensions with blank auto-update URLs because we are mostly concerned |
| 636 | // with restrictions on NaCl extensions, which are newer. |
| 637 | if ((extension && extension->from_webstore()) || |
| 638 | (!extension && pending_extension_info.is_from_sync() && |
| 639 | extension_urls::IsWebstoreUpdateUrl( |
| 640 | pending_extension_info.update_url()))) |
[email protected] | 3d72972 | 2011-09-20 02:57:09 | [diff] [blame] | 641 | installer->set_is_gallery_install(true); |
[email protected] | 6dfbbf8 | 2010-03-12 23:09:16 | [diff] [blame] | 642 | installer->set_delete_source(true); |
[email protected] | 655b2b1a | 2011-10-13 17:13:06 | [diff] [blame] | 643 | installer->set_download_url(download_url); |
[email protected] | cb0e5031 | 2011-05-09 15:03:07 | [diff] [blame] | 644 | installer->set_install_cause(extension_misc::INSTALL_CAUSE_UPDATE); |
[email protected] | 6dfbbf8 | 2010-03-12 23:09:16 | [diff] [blame] | 645 | installer->InstallCrx(extension_path); |
[email protected] | 420a0ec | 2011-06-01 01:07:03 | [diff] [blame] | 646 | |
| 647 | if (out_crx_installer) |
| 648 | *out_crx_installer = installer; |
| 649 | |
| 650 | return true; |
[email protected] | e957fe5 | 2009-06-23 16:51:05 | [diff] [blame] | 651 | } |
| 652 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 653 | void ExtensionService::ReloadExtension(const std::string& extension_id) { |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 654 | CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
[email protected] | b65272f | 2009-08-31 15:47:06 | [diff] [blame] | 655 | FilePath path; |
[email protected] | 9adb969 | 2010-10-29 23:14:02 | [diff] [blame] | 656 | const Extension* current_extension = GetExtensionById(extension_id, false); |
[email protected] | 9cddd470 | 2009-07-27 22:09:40 | [diff] [blame] | 657 | |
[email protected] | f17dbd4 | 2010-08-16 23:21:10 | [diff] [blame] | 658 | // Disable the extension if it's loaded. It might not be loaded if it crashed. |
[email protected] | b65272f | 2009-08-31 15:47:06 | [diff] [blame] | 659 | if (current_extension) { |
[email protected] | 4814b51 | 2009-11-07 00:12:29 | [diff] [blame] | 660 | // If the extension has an inspector open for its background page, detach |
| 661 | // the inspector and hang onto a cookie for it, so that we can reattach |
| 662 | // later. |
| 663 | ExtensionProcessManager* manager = profile_->GetExtensionProcessManager(); |
[email protected] | 06024c6 | 2011-10-20 20:57:12 | [diff] [blame] | 664 | ExtensionHost* host = manager->GetBackgroundHostForExtension(extension_id); |
[email protected] | 0e12d7d | 2011-12-01 16:21:44 | [diff] [blame] | 665 | if (host && DevToolsAgentHostRegistry::HasDevToolsAgentHost( |
| 666 | host->render_view_host())) { |
[email protected] | 4814b51 | 2009-11-07 00:12:29 | [diff] [blame] | 667 | // Look for an open inspector for the background page. |
[email protected] | 0e12d7d | 2011-12-01 16:21:44 | [diff] [blame] | 668 | DevToolsAgentHost* agent = |
| 669 | DevToolsAgentHostRegistry::GetDevToolsAgentHost( |
| 670 | host->render_view_host()); |
| 671 | int devtools_cookie = |
| 672 | content::DevToolsManager::GetInstance()->DetachClientHost(agent); |
[email protected] | 4814b51 | 2009-11-07 00:12:29 | [diff] [blame] | 673 | if (devtools_cookie >= 0) |
| 674 | orphaned_dev_tools_[extension_id] = devtools_cookie; |
| 675 | } |
| 676 | |
[email protected] | b65272f | 2009-08-31 15:47:06 | [diff] [blame] | 677 | path = current_extension->path(); |
[email protected] | f17dbd4 | 2010-08-16 23:21:10 | [diff] [blame] | 678 | DisableExtension(extension_id); |
| 679 | disabled_extension_paths_[extension_id] = path; |
[email protected] | 1eb17508 | 2010-02-10 09:26:16 | [diff] [blame] | 680 | } else { |
| 681 | path = unloaded_extension_paths_[extension_id]; |
[email protected] | b65272f | 2009-08-31 15:47:06 | [diff] [blame] | 682 | } |
| 683 | |
[email protected] | e6090e4 | 2010-03-23 22:44:08 | [diff] [blame] | 684 | // Check the installed extensions to see if what we're reloading was already |
| 685 | // installed. |
| 686 | scoped_ptr<ExtensionInfo> installed_extension( |
| 687 | extension_prefs_->GetInstalledExtensionInfo(extension_id)); |
| 688 | if (installed_extension.get() && |
| 689 | installed_extension->extension_manifest.get()) { |
[email protected] | d8c8f25f | 2011-11-02 18:18:01 | [diff] [blame] | 690 | extensions::InstalledLoader(this).Load(*installed_extension, false); |
[email protected] | e6090e4 | 2010-03-23 22:44:08 | [diff] [blame] | 691 | } else { |
[email protected] | d8c8f25f | 2011-11-02 18:18:01 | [diff] [blame] | 692 | // Otherwise, the extension is unpacked (location LOAD). |
[email protected] | e6090e4 | 2010-03-23 22:44:08 | [diff] [blame] | 693 | // We should always be able to remember the extension's path. If it's not in |
| 694 | // the map, someone failed to update |unloaded_extension_paths_|. |
| 695 | CHECK(!path.empty()); |
[email protected] | d8c8f25f | 2011-11-02 18:18:01 | [diff] [blame] | 696 | extensions::UnpackedInstaller::Create(this)->Load(path); |
[email protected] | e6090e4 | 2010-03-23 22:44:08 | [diff] [blame] | 697 | } |
[email protected] | 9cddd470 | 2009-07-27 22:09:40 | [diff] [blame] | 698 | } |
| 699 | |
[email protected] | fa2416f | 2011-05-03 08:41:20 | [diff] [blame] | 700 | bool ExtensionService::UninstallExtension( |
[email protected] | a12c706e | 2011-12-01 00:58:08 | [diff] [blame] | 701 | std::string extension_id, |
[email protected] | fa2416f | 2011-05-03 08:41:20 | [diff] [blame] | 702 | bool external_uninstall, |
| 703 | std::string* error) { |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 704 | CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
[email protected] | a8af9fdb | 2010-10-28 21:52:20 | [diff] [blame] | 705 | |
[email protected] | 0d6ec3a7 | 2011-09-02 02:09:43 | [diff] [blame] | 706 | scoped_refptr<const Extension> extension(GetInstalledExtension(extension_id)); |
[email protected] | 631cf82 | 2009-05-15 07:01:25 | [diff] [blame] | 707 | |
[email protected] | e7afe245 | 2010-08-22 16:19:13 | [diff] [blame] | 708 | // Callers should not send us nonexistent extensions. |
[email protected] | aebe23a3 | 2010-12-10 22:15:48 | [diff] [blame] | 709 | CHECK(extension); |
[email protected] | 9f1087e | 2009-06-15 17:29:32 | [diff] [blame] | 710 | |
[email protected] | 95da88c4 | 2011-03-31 10:07:33 | [diff] [blame] | 711 | // Policy change which triggers an uninstall will always set |
| 712 | // |external_uninstall| to true so this is the only way to uninstall |
| 713 | // managed extensions. |
[email protected] | 0d6ec3a7 | 2011-09-02 02:09:43 | [diff] [blame] | 714 | if (!Extension::UserMayDisable(extension->location()) && |
| 715 | !external_uninstall) { |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 716 | content::NotificationService::current()->Notify( |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 717 | chrome::NOTIFICATION_EXTENSION_UNINSTALL_NOT_ALLOWED, |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 718 | content::Source<Profile>(profile_), |
| 719 | content::Details<const Extension>(extension)); |
[email protected] | d6ebc979 | 2011-04-07 18:18:33 | [diff] [blame] | 720 | if (error != NULL) { |
| 721 | *error = errors::kCannotUninstallManagedExtension; |
| 722 | } |
| 723 | return false; |
| 724 | } |
[email protected] | 95da88c4 | 2011-03-31 10:07:33 | [diff] [blame] | 725 | |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 726 | // Extract the data we need for sync now, but don't actually sync until we've |
| 727 | // completed the uninstallation. |
| 728 | SyncBundle* sync_bundle = GetSyncBundleForExtension(*extension); |
| 729 | |
| 730 | SyncChange sync_change; |
| 731 | if (sync_bundle) { |
[email protected] | aa7599d | 2011-10-28 07:24:32 | [diff] [blame] | 732 | ExtensionSyncData extension_sync_data( |
| 733 | *extension, |
| 734 | IsExtensionEnabled(extension_id), |
| 735 | IsIncognitoEnabled(extension_id), |
[email protected] | b2689a90 | 2011-12-01 00:41:09 | [diff] [blame] | 736 | extension_prefs_->GetAppNotificationClientId(extension_id), |
[email protected] | 168389f | 2011-12-20 17:12:48 | [diff] [blame] | 737 | extension_prefs_->IsAppNotificationDisabled(extension_id), |
| 738 | GetAppLaunchOrdinal(extension_id), |
| 739 | GetPageOrdinal(extension_id)); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 740 | sync_change = extension_sync_data.GetSyncChange(SyncChange::ACTION_DELETE); |
| 741 | } |
| 742 | |
[email protected] | 9b21765 | 2010-10-08 22:04:23 | [diff] [blame] | 743 | UMA_HISTOGRAM_ENUMERATION("Extensions.UninstallType", |
[email protected] | 7fa19f8 | 2010-12-21 19:40:08 | [diff] [blame] | 744 | extension->GetType(), 100); |
[email protected] | fe2dd774 | 2011-04-19 22:52:49 | [diff] [blame] | 745 | RecordPermissionMessagesHistogram( |
| 746 | extension, "Extensions.Permissions_Uninstall"); |
[email protected] | 9b21765 | 2010-10-08 22:04:23 | [diff] [blame] | 747 | |
[email protected] | 8e5c89a | 2011-06-07 18:13:33 | [diff] [blame] | 748 | TemplateURLService* url_service = |
| 749 | TemplateURLServiceFactory::GetForProfile(profile_); |
| 750 | if (url_service) |
| 751 | url_service->UnregisterExtensionKeyword(extension); |
[email protected] | 56ad379 | 2010-05-28 17:45:33 | [diff] [blame] | 752 | |
[email protected] | 831aa21 | 2010-03-26 13:55:19 | [diff] [blame] | 753 | // Unload before doing more cleanup to ensure that nothing is hanging on to |
| 754 | // any of these resources. |
[email protected] | 814a7bf0f | 2011-08-13 05:30:59 | [diff] [blame] | 755 | UnloadExtension(extension_id, extension_misc::UNLOAD_REASON_UNINSTALL); |
[email protected] | 831aa21 | 2010-03-26 13:55:19 | [diff] [blame] | 756 | |
[email protected] | 0d6ec3a7 | 2011-09-02 02:09:43 | [diff] [blame] | 757 | extension_prefs_->OnExtensionUninstalled(extension_id, extension->location(), |
[email protected] | 831aa21 | 2010-03-26 13:55:19 | [diff] [blame] | 758 | external_uninstall); |
[email protected] | 9f1087e | 2009-06-15 17:29:32 | [diff] [blame] | 759 | |
| 760 | // Tell the backend to start deleting installed extensions on the file thread. |
[email protected] | 0d6ec3a7 | 2011-09-02 02:09:43 | [diff] [blame] | 761 | if (Extension::LOAD != extension->location()) { |
[email protected] | 14908b7 | 2011-04-20 06:54:36 | [diff] [blame] | 762 | if (!BrowserThread::PostTask( |
| 763 | BrowserThread::FILE, FROM_HERE, |
[email protected] | 53612e8 | 2011-10-18 18:00:36 | [diff] [blame] | 764 | base::Bind( |
[email protected] | 14908b7 | 2011-04-20 06:54:36 | [diff] [blame] | 765 | &extension_file_util::UninstallExtension, |
| 766 | install_directory_, |
[email protected] | fa2416f | 2011-05-03 08:41:20 | [diff] [blame] | 767 | extension_id))) |
[email protected] | 14908b7 | 2011-04-20 06:54:36 | [diff] [blame] | 768 | NOTREACHED(); |
[email protected] | 9f1087e | 2009-06-15 17:29:32 | [diff] [blame] | 769 | } |
| 770 | |
[email protected] | 0d6ec3a7 | 2011-09-02 02:09:43 | [diff] [blame] | 771 | GURL launch_web_url_origin(extension->launch_web_url()); |
| 772 | launch_web_url_origin = launch_web_url_origin.GetOrigin(); |
| 773 | bool is_storage_isolated = |
| 774 | (extension->is_storage_isolated() && |
| 775 | extension->HasAPIPermission(ExtensionAPIPermission::kExperimental)); |
| 776 | |
| 777 | if (extension->is_hosted_app() && |
| 778 | !profile_->GetExtensionSpecialStoragePolicy()-> |
| 779 | IsStorageProtected(launch_web_url_origin)) { |
[email protected] | dc0b5a1 | 2011-10-14 00:06:13 | [diff] [blame] | 780 | ExtensionDataDeleter::StartDeleting( |
| 781 | profile_, extension_id, launch_web_url_origin, is_storage_isolated); |
[email protected] | 0d6ec3a7 | 2011-09-02 02:09:43 | [diff] [blame] | 782 | } |
[email protected] | dc0b5a1 | 2011-10-14 00:06:13 | [diff] [blame] | 783 | ExtensionDataDeleter::StartDeleting( |
| 784 | profile_, extension_id, extension->url(), is_storage_isolated); |
[email protected] | 0d6ec3a7 | 2011-09-02 02:09:43 | [diff] [blame] | 785 | |
[email protected] | 0dfe05c | 2011-02-23 23:03:36 | [diff] [blame] | 786 | UntrackTerminatedExtension(extension_id); |
[email protected] | 21103034 | 2010-09-30 18:41:06 | [diff] [blame] | 787 | |
| 788 | // Notify interested parties that we've uninstalled this extension. |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 789 | content::NotificationService::current()->Notify( |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 790 | chrome::NOTIFICATION_EXTENSION_UNINSTALLED, |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 791 | content::Source<Profile>(profile_), |
| 792 | content::Details<const std::string>(&extension_id)); |
[email protected] | d6ebc979 | 2011-04-07 18:18:33 | [diff] [blame] | 793 | |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 794 | if (sync_bundle && sync_bundle->HasExtensionId(extension_id)) { |
| 795 | sync_bundle->sync_processor->ProcessSyncChanges( |
| 796 | FROM_HERE, SyncChangeList(1, sync_change)); |
| 797 | sync_bundle->synced_extensions.erase(extension_id); |
| 798 | } |
| 799 | |
[email protected] | 333b1de | 2011-09-12 18:28:50 | [diff] [blame] | 800 | // Track the uninstallation. |
[email protected] | 49098f70 | 2011-10-13 03:47:18 | [diff] [blame] | 801 | UMA_HISTOGRAM_ENUMERATION("Extensions.ExtensionUninstalled", 1, 2); |
| 802 | |
| 803 | static bool default_apps_trial_exists = |
[email protected] | 568c331 | 2011-12-06 15:36:04 | [diff] [blame] | 804 | base::FieldTrialList::TrialExists(kDefaultAppsTrialName); |
[email protected] | 49098f70 | 2011-10-13 03:47:18 | [diff] [blame] | 805 | if (default_apps_trial_exists) { |
| 806 | UMA_HISTOGRAM_ENUMERATION( |
| 807 | base::FieldTrial::MakeName("Extensions.ExtensionUninstalled", |
[email protected] | 568c331 | 2011-12-06 15:36:04 | [diff] [blame] | 808 | kDefaultAppsTrialName), |
[email protected] | 49098f70 | 2011-10-13 03:47:18 | [diff] [blame] | 809 | 1, 2); |
| 810 | } |
[email protected] | 333b1de | 2011-09-12 18:28:50 | [diff] [blame] | 811 | |
[email protected] | 7c1490da | 2011-10-11 18:53:25 | [diff] [blame] | 812 | // Uninstalling one extension might have solved the problems of others. |
| 813 | // Therefore, we clear warnings of this type for all extensions. |
| 814 | std::set<ExtensionWarningSet::WarningType> warnings; |
| 815 | extension_warnings_.GetWarningsAffectingExtension(extension_id, &warnings); |
| 816 | extension_warnings_.ClearWarnings(warnings); |
| 817 | |
[email protected] | d6ebc979 | 2011-04-07 18:18:33 | [diff] [blame] | 818 | return true; |
[email protected] | c10da4b0 | 2010-03-25 14:38:32 | [diff] [blame] | 819 | } |
| 820 | |
[email protected] | c3cfb01 | 2011-04-06 22:07:35 | [diff] [blame] | 821 | bool ExtensionService::IsExtensionEnabled( |
| 822 | const std::string& extension_id) const { |
[email protected] | 84df833 | 2011-12-06 18:22:46 | [diff] [blame] | 823 | if (extensions_.Contains(extension_id) || |
| 824 | terminated_extensions_.Contains(extension_id)) |
[email protected] | 36429da | 2011-07-11 20:25:18 | [diff] [blame] | 825 | return true; |
| 826 | |
[email protected] | 84df833 | 2011-12-06 18:22:46 | [diff] [blame] | 827 | if (disabled_extensions_.Contains(extension_id)) |
[email protected] | ad83ca24 | 2011-07-29 01:32:25 | [diff] [blame] | 828 | return false; |
| 829 | |
| 830 | // If the extension hasn't been loaded yet, check the prefs for it. Assume |
| 831 | // enabled unless otherwise noted. |
| 832 | return !extension_prefs_->IsExtensionDisabled(extension_id) && |
| 833 | !extension_prefs_->IsExternalExtensionUninstalled(extension_id); |
[email protected] | c3cfb01 | 2011-04-06 22:07:35 | [diff] [blame] | 834 | } |
| 835 | |
| 836 | bool ExtensionService::IsExternalExtensionUninstalled( |
| 837 | const std::string& extension_id) const { |
| 838 | return extension_prefs_->IsExternalExtensionUninstalled(extension_id); |
| 839 | } |
| 840 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 841 | void ExtensionService::EnableExtension(const std::string& extension_id) { |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 842 | CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
[email protected] | a8af9fdb | 2010-10-28 21:52:20 | [diff] [blame] | 843 | |
[email protected] | 06f9256 | 2011-04-29 19:27:31 | [diff] [blame] | 844 | if (IsExtensionEnabled(extension_id)) |
[email protected] | 0c6da50 | 2009-08-14 22:32:39 | [diff] [blame] | 845 | return; |
[email protected] | 0c6da50 | 2009-08-14 22:32:39 | [diff] [blame] | 846 | |
[email protected] | b3317ad | 2011-04-28 23:46:00 | [diff] [blame] | 847 | extension_prefs_->SetExtensionState(extension_id, Extension::ENABLED); |
[email protected] | 1784e83a | 2009-09-08 21:01:52 | [diff] [blame] | 848 | |
[email protected] | 06f9256 | 2011-04-29 19:27:31 | [diff] [blame] | 849 | const Extension* extension = |
| 850 | GetExtensionByIdInternal(extension_id, false, true, false); |
| 851 | // This can happen if sync enables an extension that is not |
| 852 | // installed yet. |
| 853 | if (!extension) |
| 854 | return; |
| 855 | |
[email protected] | 0c6da50 | 2009-08-14 22:32:39 | [diff] [blame] | 856 | // Move it over to the enabled list. |
[email protected] | 84df833 | 2011-12-06 18:22:46 | [diff] [blame] | 857 | extensions_.Insert(make_scoped_refptr(extension)); |
| 858 | disabled_extensions_.Remove(extension->id()); |
[email protected] | 0c6da50 | 2009-08-14 22:32:39 | [diff] [blame] | 859 | |
[email protected] | f681c78 | 2010-11-19 11:19:39 | [diff] [blame] | 860 | // Make sure any browser action contained within it is not hidden. |
| 861 | extension_prefs_->SetBrowserActionVisibility(extension, true); |
| 862 | |
[email protected] | 62d30f4 | 2009-10-01 22:36:06 | [diff] [blame] | 863 | NotifyExtensionLoaded(extension); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 864 | |
| 865 | SyncExtensionChangeIfNeeded(*extension); |
[email protected] | 0c6da50 | 2009-08-14 22:32:39 | [diff] [blame] | 866 | } |
| 867 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 868 | void ExtensionService::DisableExtension(const std::string& extension_id) { |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 869 | CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
[email protected] | a8af9fdb | 2010-10-28 21:52:20 | [diff] [blame] | 870 | |
[email protected] | b2ba996 | 2009-12-10 20:10:15 | [diff] [blame] | 871 | // The extension may have been disabled already. |
[email protected] | 06f9256 | 2011-04-29 19:27:31 | [diff] [blame] | 872 | if (!IsExtensionEnabled(extension_id)) |
[email protected] | 1784e83a | 2009-09-08 21:01:52 | [diff] [blame] | 873 | return; |
[email protected] | 1784e83a | 2009-09-08 21:01:52 | [diff] [blame] | 874 | |
[email protected] | 06f9256 | 2011-04-29 19:27:31 | [diff] [blame] | 875 | const Extension* extension = GetInstalledExtension(extension_id); |
| 876 | // |extension| can be NULL if sync disables an extension that is not |
| 877 | // installed yet. |
| 878 | if (extension && !Extension::UserMayDisable(extension->location())) |
[email protected] | 95da88c4 | 2011-03-31 10:07:33 | [diff] [blame] | 879 | return; |
| 880 | |
[email protected] | b3317ad | 2011-04-28 23:46:00 | [diff] [blame] | 881 | extension_prefs_->SetExtensionState(extension_id, Extension::DISABLED); |
[email protected] | 1784e83a | 2009-09-08 21:01:52 | [diff] [blame] | 882 | |
[email protected] | 06f9256 | 2011-04-29 19:27:31 | [diff] [blame] | 883 | extension = GetExtensionByIdInternal(extension_id, true, false, true); |
| 884 | if (!extension) |
| 885 | return; |
| 886 | |
[email protected] | 1784e83a | 2009-09-08 21:01:52 | [diff] [blame] | 887 | // Move it over to the disabled list. |
[email protected] | 84df833 | 2011-12-06 18:22:46 | [diff] [blame] | 888 | disabled_extensions_.Insert(make_scoped_refptr(extension)); |
| 889 | if (extensions_.Contains(extension->id())) |
| 890 | extensions_.Remove(extension->id()); |
| 891 | else |
| 892 | terminated_extensions_.Remove(extension->id()); |
[email protected] | 1784e83a | 2009-09-08 21:01:52 | [diff] [blame] | 893 | |
[email protected] | 814a7bf0f | 2011-08-13 05:30:59 | [diff] [blame] | 894 | NotifyExtensionUnloaded(extension, extension_misc::UNLOAD_REASON_DISABLE); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 895 | |
| 896 | SyncExtensionChangeIfNeeded(*extension); |
[email protected] | 7c1490da | 2011-10-11 18:53:25 | [diff] [blame] | 897 | |
| 898 | // Deactivating one extension might have solved the problems of others. |
| 899 | // Therefore, we clear warnings of this type for all extensions. |
| 900 | std::set<ExtensionWarningSet::WarningType> warnings; |
| 901 | extension_warnings_.GetWarningsAffectingExtension(extension_id, &warnings); |
| 902 | extension_warnings_.ClearWarnings(warnings); |
[email protected] | 1784e83a | 2009-09-08 21:01:52 | [diff] [blame] | 903 | } |
| 904 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 905 | void ExtensionService::GrantPermissionsAndEnableExtension( |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 906 | const Extension* extension) { |
| 907 | CHECK(extension); |
[email protected] | fe2dd774 | 2011-04-19 22:52:49 | [diff] [blame] | 908 | RecordPermissionMessagesHistogram( |
| 909 | extension, "Extensions.Permissions_ReEnable"); |
[email protected] | c333e79 | 2012-01-06 16:57:39 | [diff] [blame] | 910 | extensions::PermissionsUpdater perms_updater(profile()); |
| 911 | perms_updater.GrantActivePermissions(extension); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 912 | extension_prefs_->SetDidExtensionEscalatePermissions(extension, false); |
| 913 | EnableExtension(extension->id()); |
| 914 | } |
| 915 | |
[email protected] | fe2dd774 | 2011-04-19 22:52:49 | [diff] [blame] | 916 | // static |
| 917 | void ExtensionService::RecordPermissionMessagesHistogram( |
| 918 | const Extension* e, const char* histogram) { |
| 919 | // Since this is called from multiple sources, and since the Histogram macros |
| 920 | // use statics, we need to manually lookup the Histogram ourselves. |
| 921 | base::Histogram* counter = base::LinearHistogram::FactoryGet( |
| 922 | histogram, |
| 923 | 1, |
[email protected] | 0d3e4a2 | 2011-06-23 19:02:52 | [diff] [blame] | 924 | ExtensionPermissionMessage::kEnumBoundary, |
| 925 | ExtensionPermissionMessage::kEnumBoundary + 1, |
[email protected] | fe2dd774 | 2011-04-19 22:52:49 | [diff] [blame] | 926 | base::Histogram::kUmaTargetedHistogramFlag); |
| 927 | |
[email protected] | 0d3e4a2 | 2011-06-23 19:02:52 | [diff] [blame] | 928 | ExtensionPermissionMessages permissions = e->GetPermissionMessages(); |
[email protected] | fe2dd774 | 2011-04-19 22:52:49 | [diff] [blame] | 929 | if (permissions.empty()) { |
[email protected] | 0d3e4a2 | 2011-06-23 19:02:52 | [diff] [blame] | 930 | counter->Add(ExtensionPermissionMessage::kNone); |
[email protected] | fe2dd774 | 2011-04-19 22:52:49 | [diff] [blame] | 931 | } else { |
[email protected] | 0d3e4a2 | 2011-06-23 19:02:52 | [diff] [blame] | 932 | for (ExtensionPermissionMessages::iterator it = permissions.begin(); |
| 933 | it != permissions.end(); ++it) |
| 934 | counter->Add(it->id()); |
[email protected] | fe2dd774 | 2011-04-19 22:52:49 | [diff] [blame] | 935 | } |
| 936 | } |
| 937 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 938 | void ExtensionService::NotifyExtensionLoaded(const Extension* extension) { |
[email protected] | 57a777f7 | 2010-03-31 01:09:42 | [diff] [blame] | 939 | // The ChromeURLRequestContexts need to be first to know that the extension |
[email protected] | 62d30f4 | 2009-10-01 22:36:06 | [diff] [blame] | 940 | // was loaded, otherwise a race can arise where a renderer that is created |
| 941 | // for the extension may try to load an extension URL with an extension id |
[email protected] | 57a777f7 | 2010-03-31 01:09:42 | [diff] [blame] | 942 | // that the request context doesn't yet know about. The profile is responsible |
| 943 | // for ensuring its URLRequestContexts appropriately discover the loaded |
| 944 | // extension. |
[email protected] | c8d407e | 2011-04-28 21:27:17 | [diff] [blame] | 945 | profile_->RegisterExtensionWithRequestContexts(extension); |
[email protected] | 62d30f4 | 2009-10-01 22:36:06 | [diff] [blame] | 946 | |
[email protected] | 1964726 | 2011-12-16 09:57:49 | [diff] [blame] | 947 | // Tell renderers about the new extension, unless it's a theme (renderers |
| 948 | // don't need to know about themes). |
| 949 | if (!extension->is_theme()) { |
| 950 | for (content::RenderProcessHost::iterator i( |
| 951 | content::RenderProcessHost::AllHostsIterator()); |
| 952 | !i.IsAtEnd(); i.Advance()) { |
| 953 | content::RenderProcessHost* host = i.GetCurrentValue(); |
| 954 | Profile* host_profile = |
| 955 | Profile::FromBrowserContext(host->GetBrowserContext()); |
| 956 | if (host_profile->GetOriginalProfile() == |
| 957 | profile_->GetOriginalProfile()) { |
| 958 | std::vector<ExtensionMsg_Loaded_Params> loaded_extensions( |
| 959 | 1, ExtensionMsg_Loaded_Params(extension)); |
| 960 | host->Send( |
| 961 | new ExtensionMsg_Loaded(loaded_extensions)); |
| 962 | } |
[email protected] | c8d407e | 2011-04-28 21:27:17 | [diff] [blame] | 963 | } |
[email protected] | 77a6970c | 2011-04-23 16:58:56 | [diff] [blame] | 964 | } |
| 965 | |
[email protected] | 3442a66 | 2012-01-12 08:06:17 | [diff] [blame] | 966 | // Tell subsystems that use the EXTENSION_LOADED notification about the new |
| 967 | // extension. |
| 968 | // |
| 969 | // NOTE: It is important that this happen after notifying the renderers about |
| 970 | // the new extensions so that if we navigate to an extension URL in |
| 971 | // NOTIFICATION_EXTENSION_LOADED, the renderer is guaranteed to know about it. |
| 972 | content::NotificationService::current()->Notify( |
| 973 | chrome::NOTIFICATION_EXTENSION_LOADED, |
| 974 | content::Source<Profile>(profile_), |
| 975 | content::Details<const Extension>(extension)); |
| 976 | |
[email protected] | c8d407e | 2011-04-28 21:27:17 | [diff] [blame] | 977 | // Tell a random-ass collection of other subsystems about the new extension. |
| 978 | // TODO(aa): What should we do with all this goop? Can it move into the |
| 979 | // relevant objects via EXTENSION_LOADED? |
| 980 | |
| 981 | profile_->GetExtensionSpecialStoragePolicy()-> |
| 982 | GrantRightsForExtension(extension); |
| 983 | |
| 984 | UpdateActiveExtensionsInCrashReporter(); |
| 985 | |
| 986 | ExtensionWebUI::RegisterChromeURLOverrides( |
| 987 | profile_, extension->GetChromeURLOverrides()); |
| 988 | |
[email protected] | 8e5c89a | 2011-06-07 18:13:33 | [diff] [blame] | 989 | TemplateURLService* url_service = |
| 990 | TemplateURLServiceFactory::GetForProfile(profile_); |
| 991 | if (url_service) |
| 992 | url_service->RegisterExtensionKeyword(extension); |
[email protected] | c8d407e | 2011-04-28 21:27:17 | [diff] [blame] | 993 | |
| 994 | // Load the icon for omnibox-enabled extensions so it will be ready to display |
| 995 | // in the URL bar. |
| 996 | if (!extension->omnibox_keyword().empty()) { |
| 997 | omnibox_popup_icon_manager_.LoadIcon(extension); |
| 998 | omnibox_icon_manager_.LoadIcon(extension); |
| 999 | } |
| 1000 | |
| 1001 | // If the extension has permission to load chrome://favicon/ resources we need |
| 1002 | // to make sure that the FaviconSource is registered with the |
| 1003 | // ChromeURLDataManager. |
| 1004 | if (extension->HasHostPermission(GURL(chrome::kChromeUIFaviconURL))) { |
| 1005 | FaviconSource* favicon_source = new FaviconSource(profile_, |
| 1006 | FaviconSource::FAVICON); |
| 1007 | profile_->GetChromeURLDataManager()->AddDataSource(favicon_source); |
| 1008 | } |
[email protected] | 5eddc3e | 2011-10-26 04:33:31 | [diff] [blame] | 1009 | // Same for chrome://thumb/ resources. |
| 1010 | if (extension->HasHostPermission(GURL(chrome::kChromeUIThumbnailURL))) { |
| 1011 | ThumbnailSource* thumbnail_source = new ThumbnailSource(profile_); |
| 1012 | profile_->GetChromeURLDataManager()->AddDataSource(thumbnail_source); |
| 1013 | } |
[email protected] | c8d407e | 2011-04-28 21:27:17 | [diff] [blame] | 1014 | |
| 1015 | // TODO(mpcomplete): This ends up affecting all profiles. See crbug.com/80757. |
[email protected] | 2de30759 | 2011-04-05 21:16:58 | [diff] [blame] | 1016 | bool plugins_changed = false; |
| 1017 | for (size_t i = 0; i < extension->plugins().size(); ++i) { |
| 1018 | const Extension::PluginInfo& plugin = extension->plugins()[i]; |
[email protected] | f520b5b | 2011-11-08 02:42:14 | [diff] [blame] | 1019 | PluginService::GetInstance()->RefreshPlugins(); |
| 1020 | PluginService::GetInstance()->AddExtraPluginPath(plugin.path); |
[email protected] | 2de30759 | 2011-04-05 21:16:58 | [diff] [blame] | 1021 | plugins_changed = true; |
[email protected] | 476a2703 | 2011-09-13 13:40:49 | [diff] [blame] | 1022 | ChromePluginServiceFilter* filter = |
| 1023 | ChromePluginServiceFilter::GetInstance(); |
| 1024 | if (plugin.is_public) { |
| 1025 | filter->RestrictPluginToProfileAndOrigin( |
| 1026 | plugin.path, profile_, GURL()); |
| 1027 | } else { |
| 1028 | filter->RestrictPluginToProfileAndOrigin( |
| 1029 | plugin.path, profile_, extension->url()); |
[email protected] | 2de30759 | 2011-04-05 21:16:58 | [diff] [blame] | 1030 | } |
| 1031 | } |
[email protected] | 84396dbc | 2011-04-14 06:33:42 | [diff] [blame] | 1032 | |
| 1033 | bool nacl_modules_changed = false; |
| 1034 | for (size_t i = 0; i < extension->nacl_modules().size(); ++i) { |
| 1035 | const Extension::NaClModuleInfo& module = extension->nacl_modules()[i]; |
[email protected] | cebc3dc | 2011-04-18 17:15:00 | [diff] [blame] | 1036 | RegisterNaClModule(module.url, module.mime_type); |
[email protected] | 84396dbc | 2011-04-14 06:33:42 | [diff] [blame] | 1037 | nacl_modules_changed = true; |
| 1038 | } |
| 1039 | |
[email protected] | ed0ba00 | 2011-05-26 16:55:13 | [diff] [blame] | 1040 | if (nacl_modules_changed) |
| 1041 | UpdatePluginListWithNaClModules(); |
[email protected] | 84396dbc | 2011-04-14 06:33:42 | [diff] [blame] | 1042 | |
| 1043 | if (plugins_changed || nacl_modules_changed) |
[email protected] | 45a22e6 | 2011-10-12 09:48:02 | [diff] [blame] | 1044 | PluginService::GetInstance()->PurgePluginListCache(profile_, false); |
[email protected] | b4d9d12 | 2011-06-17 01:58:54 | [diff] [blame] | 1045 | |
[email protected] | 14da67b0 | 2011-08-02 05:49:13 | [diff] [blame] | 1046 | #if defined(OS_CHROMEOS) |
[email protected] | b4d9d12 | 2011-06-17 01:58:54 | [diff] [blame] | 1047 | for (std::vector<Extension::InputComponentInfo>::const_iterator component = |
| 1048 | extension->input_components().begin(); |
| 1049 | component != extension->input_components().end(); |
| 1050 | ++component) { |
[email protected] | 14da67b0 | 2011-08-02 05:49:13 | [diff] [blame] | 1051 | if (component->type == Extension::INPUT_COMPONENT_TYPE_IME) { |
[email protected] | 8baf0dbb | 2011-11-27 22:47:02 | [diff] [blame] | 1052 | ExtensionInputImeEventRouter::GetInstance()->RegisterIme( |
[email protected] | 14da67b0 | 2011-08-02 05:49:13 | [diff] [blame] | 1053 | profile_, extension->id(), *component); |
| 1054 | } |
[email protected] | 9a2aebe0 | 2011-12-02 21:54:14 | [diff] [blame] | 1055 | #if defined(USE_VIRTUAL_KEYBOARD) |
[email protected] | b4d9d12 | 2011-06-17 01:58:54 | [diff] [blame] | 1056 | if (component->type == Extension::INPUT_COMPONENT_TYPE_VIRTUAL_KEYBOARD && |
| 1057 | !component->layouts.empty()) { |
[email protected] | a4215ac0 | 2011-12-04 04:11:56 | [diff] [blame] | 1058 | chromeos::input_method::InputMethodManager* input_method_manager = |
| 1059 | chromeos::input_method::InputMethodManager::GetInstance(); |
| 1060 | const bool is_system_keyboard = |
| 1061 | extension->location() == Extension::COMPONENT; |
[email protected] | cbd4c04 | 2011-08-13 18:22:19 | [diff] [blame] | 1062 | input_method_manager->RegisterVirtualKeyboard( |
| 1063 | extension->url(), |
| 1064 | component->name, // human-readable name of the keyboard extension. |
| 1065 | component->layouts, |
[email protected] | a4215ac0 | 2011-12-04 04:11:56 | [diff] [blame] | 1066 | is_system_keyboard); |
[email protected] | b4d9d12 | 2011-06-17 01:58:54 | [diff] [blame] | 1067 | } |
[email protected] | 14da67b0 | 2011-08-02 05:49:13 | [diff] [blame] | 1068 | #endif |
[email protected] | b4d9d12 | 2011-06-17 01:58:54 | [diff] [blame] | 1069 | } |
| 1070 | #endif |
[email protected] | 62d30f4 | 2009-10-01 22:36:06 | [diff] [blame] | 1071 | } |
| 1072 | |
[email protected] | a9f39a31 | 2010-12-23 22:14:27 | [diff] [blame] | 1073 | void ExtensionService::NotifyExtensionUnloaded( |
[email protected] | 814a7bf0f | 2011-08-13 05:30:59 | [diff] [blame] | 1074 | const Extension* extension, |
| 1075 | extension_misc::UnloadedExtensionReason reason) { |
[email protected] | a9f39a31 | 2010-12-23 22:14:27 | [diff] [blame] | 1076 | UnloadedExtensionInfo details(extension, reason); |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 1077 | content::NotificationService::current()->Notify( |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 1078 | chrome::NOTIFICATION_EXTENSION_UNLOADED, |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 1079 | content::Source<Profile>(profile_), |
| 1080 | content::Details<UnloadedExtensionInfo>(&details)); |
[email protected] | 62d30f4 | 2009-10-01 22:36:06 | [diff] [blame] | 1081 | |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 1082 | for (content::RenderProcessHost::iterator i( |
| 1083 | content::RenderProcessHost::AllHostsIterator()); |
[email protected] | 77a6970c | 2011-04-23 16:58:56 | [diff] [blame] | 1084 | !i.IsAtEnd(); i.Advance()) { |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 1085 | content::RenderProcessHost* host = i.GetCurrentValue(); |
[email protected] | 9b62ecf | 2011-07-27 20:23:08 | [diff] [blame] | 1086 | Profile* host_profile = |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 1087 | Profile::FromBrowserContext(host->GetBrowserContext()); |
[email protected] | 9b62ecf | 2011-07-27 20:23:08 | [diff] [blame] | 1088 | if (host_profile->GetOriginalProfile() == profile_->GetOriginalProfile()) |
[email protected] | c8d407e | 2011-04-28 21:27:17 | [diff] [blame] | 1089 | host->Send(new ExtensionMsg_Unloaded(extension->id())); |
[email protected] | 77a6970c | 2011-04-23 16:58:56 | [diff] [blame] | 1090 | } |
| 1091 | |
[email protected] | dd163fb0 | 2011-05-04 22:22:17 | [diff] [blame] | 1092 | profile_->UnregisterExtensionWithRequestContexts(extension->id(), reason); |
[email protected] | c8d407e | 2011-04-28 21:27:17 | [diff] [blame] | 1093 | profile_->GetExtensionSpecialStoragePolicy()-> |
| 1094 | RevokeRightsForExtension(extension); |
| 1095 | |
| 1096 | ExtensionWebUI::UnregisterChromeURLOverrides( |
| 1097 | profile_, extension->GetChromeURLOverrides()); |
| 1098 | |
[email protected] | b777b33 | 2011-04-16 04:01:08 | [diff] [blame] | 1099 | #if defined(OS_CHROMEOS) |
| 1100 | // Revoke external file access to |
[email protected] | c8d407e | 2011-04-28 21:27:17 | [diff] [blame] | 1101 | if (profile_->GetFileSystemContext() && |
[email protected] | e7e4673 | 2012-01-05 11:45:55 | [diff] [blame] | 1102 | profile_->GetFileSystemContext()->external_provider()) { |
| 1103 | profile_->GetFileSystemContext()->external_provider()-> |
[email protected] | c8d407e | 2011-04-28 21:27:17 | [diff] [blame] | 1104 | RevokeAccessForExtension(extension->id()); |
[email protected] | 62d30f4 | 2009-10-01 22:36:06 | [diff] [blame] | 1105 | } |
[email protected] | 54ccafa | 2011-12-06 23:36:32 | [diff] [blame] | 1106 | |
| 1107 | if (extension->input_components().size() > 0) { |
| 1108 | ExtensionInputImeEventRouter::GetInstance()->UnregisterAllImes( |
| 1109 | profile_, extension->id()); |
| 1110 | } |
[email protected] | c8d407e | 2011-04-28 21:27:17 | [diff] [blame] | 1111 | #endif |
| 1112 | |
| 1113 | UpdateActiveExtensionsInCrashReporter(); |
[email protected] | 2de30759 | 2011-04-05 21:16:58 | [diff] [blame] | 1114 | |
| 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] | 14908b7 | 2011-04-20 06:54:36 | [diff] [blame] | 1118 | if (!BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
[email protected] | 53612e8 | 2011-10-18 18:00:36 | [diff] [blame] | 1119 | base::Bind(&ForceShutdownPlugin, plugin.path))) |
[email protected] | 14908b7 | 2011-04-20 06:54:36 | [diff] [blame] | 1120 | NOTREACHED(); |
[email protected] | f520b5b | 2011-11-08 02:42:14 | [diff] [blame] | 1121 | PluginService::GetInstance()->RefreshPlugins(); |
| 1122 | PluginService::GetInstance()->RemoveExtraPluginPath(plugin.path); |
[email protected] | 2de30759 | 2011-04-05 21:16:58 | [diff] [blame] | 1123 | plugins_changed = true; |
[email protected] | 476a2703 | 2011-09-13 13:40:49 | [diff] [blame] | 1124 | ChromePluginServiceFilter::GetInstance()->UnrestrictPlugin(plugin.path); |
[email protected] | 2de30759 | 2011-04-05 21:16:58 | [diff] [blame] | 1125 | } |
[email protected] | 84396dbc | 2011-04-14 06:33:42 | [diff] [blame] | 1126 | |
| 1127 | bool nacl_modules_changed = false; |
| 1128 | for (size_t i = 0; i < extension->nacl_modules().size(); ++i) { |
| 1129 | const Extension::NaClModuleInfo& module = extension->nacl_modules()[i]; |
[email protected] | cebc3dc | 2011-04-18 17:15:00 | [diff] [blame] | 1130 | UnregisterNaClModule(module.url); |
[email protected] | 84396dbc | 2011-04-14 06:33:42 | [diff] [blame] | 1131 | nacl_modules_changed = true; |
| 1132 | } |
| 1133 | |
[email protected] | ed0ba00 | 2011-05-26 16:55:13 | [diff] [blame] | 1134 | if (nacl_modules_changed) |
| 1135 | UpdatePluginListWithNaClModules(); |
[email protected] | 84396dbc | 2011-04-14 06:33:42 | [diff] [blame] | 1136 | |
| 1137 | if (plugins_changed || nacl_modules_changed) |
[email protected] | 45a22e6 | 2011-10-12 09:48:02 | [diff] [blame] | 1138 | PluginService::GetInstance()->PurgePluginListCache(profile_, false); |
[email protected] | 62d30f4 | 2009-10-01 22:36:06 | [diff] [blame] | 1139 | } |
| 1140 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 1141 | void ExtensionService::UpdateExtensionBlacklist( |
[email protected] | 6b75ec3 | 2009-08-14 06:37:18 | [diff] [blame] | 1142 | const std::vector<std::string>& blacklist) { |
| 1143 | // Use this set to indicate if an extension in the blacklist has been used. |
| 1144 | std::set<std::string> blacklist_set; |
| 1145 | for (unsigned int i = 0; i < blacklist.size(); ++i) { |
| 1146 | if (Extension::IdIsValid(blacklist[i])) { |
| 1147 | blacklist_set.insert(blacklist[i]); |
| 1148 | } |
| 1149 | } |
| 1150 | extension_prefs_->UpdateBlacklist(blacklist_set); |
| 1151 | std::vector<std::string> to_be_removed; |
| 1152 | // Loop current extensions, unload installed extensions. |
[email protected] | 84df833 | 2011-12-06 18:22:46 | [diff] [blame] | 1153 | for (ExtensionSet::const_iterator iter = extensions_.begin(); |
[email protected] | 6b75ec3 | 2009-08-14 06:37:18 | [diff] [blame] | 1154 | iter != extensions_.end(); ++iter) { |
[email protected] | 9adb969 | 2010-10-29 23:14:02 | [diff] [blame] | 1155 | const Extension* extension = (*iter); |
[email protected] | 6b75ec3 | 2009-08-14 06:37:18 | [diff] [blame] | 1156 | if (blacklist_set.find(extension->id()) != blacklist_set.end()) { |
| 1157 | to_be_removed.push_back(extension->id()); |
| 1158 | } |
| 1159 | } |
| 1160 | |
| 1161 | // UnloadExtension will change the extensions_ list. So, we should |
| 1162 | // call it outside the iterator loop. |
| 1163 | for (unsigned int i = 0; i < to_be_removed.size(); ++i) { |
[email protected] | 814a7bf0f | 2011-08-13 05:30:59 | [diff] [blame] | 1164 | UnloadExtension(to_be_removed[i], extension_misc::UNLOAD_REASON_DISABLE); |
[email protected] | 6b75ec3 | 2009-08-14 06:37:18 | [diff] [blame] | 1165 | } |
| 1166 | } |
| 1167 | |
[email protected] | 0a071a3 | 2011-02-08 00:18:24 | [diff] [blame] | 1168 | Profile* ExtensionService::profile() { |
| 1169 | return profile_; |
| 1170 | } |
| 1171 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 1172 | ExtensionPrefs* ExtensionService::extension_prefs() { |
[email protected] | ddb1e5a | 2010-12-13 20:10:45 | [diff] [blame] | 1173 | return extension_prefs_; |
| 1174 | } |
| 1175 | |
[email protected] | 0d9a220 | 2011-11-09 13:48:41 | [diff] [blame] | 1176 | extensions::SettingsFrontend* ExtensionService::settings_frontend() { |
[email protected] | cccdf0aa | 2011-11-11 03:43:38 | [diff] [blame] | 1177 | return settings_frontend_.get(); |
[email protected] | b7f853e28 | 2011-08-10 09:24:20 | [diff] [blame] | 1178 | } |
| 1179 | |
[email protected] | b790b07 | 2011-05-20 09:46:44 | [diff] [blame] | 1180 | ExtensionContentSettingsStore* |
| 1181 | ExtensionService::GetExtensionContentSettingsStore() { |
| 1182 | return extension_prefs()->content_settings_store(); |
| 1183 | } |
| 1184 | |
[email protected] | 25ae015 | 2011-11-18 14:40:02 | [diff] [blame] | 1185 | bool ExtensionService::is_ready() { |
| 1186 | return ready_; |
| 1187 | } |
| 1188 | |
[email protected] | 2859946f | 2011-04-04 18:18:06 | [diff] [blame] | 1189 | ExtensionUpdater* ExtensionService::updater() { |
| 1190 | return updater_.get(); |
| 1191 | } |
| 1192 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 1193 | void ExtensionService::CheckAdminBlacklist() { |
[email protected] | aa96d3a | 2010-08-21 08:45:25 | [diff] [blame] | 1194 | std::vector<std::string> to_be_removed; |
| 1195 | // Loop through extensions list, unload installed extensions. |
[email protected] | 84df833 | 2011-12-06 18:22:46 | [diff] [blame] | 1196 | for (ExtensionSet::const_iterator iter = extensions_.begin(); |
[email protected] | aa96d3a | 2010-08-21 08:45:25 | [diff] [blame] | 1197 | iter != extensions_.end(); ++iter) { |
[email protected] | 9adb969 | 2010-10-29 23:14:02 | [diff] [blame] | 1198 | const Extension* extension = (*iter); |
[email protected] | 05aad2da | 2011-10-28 10:12:37 | [diff] [blame] | 1199 | if (!extension_prefs_->IsExtensionAllowedByPolicy(extension->id(), |
| 1200 | extension->location())) { |
[email protected] | aa96d3a | 2010-08-21 08:45:25 | [diff] [blame] | 1201 | to_be_removed.push_back(extension->id()); |
[email protected] | 05aad2da | 2011-10-28 10:12:37 | [diff] [blame] | 1202 | } |
[email protected] | aa96d3a | 2010-08-21 08:45:25 | [diff] [blame] | 1203 | } |
| 1204 | |
| 1205 | // UnloadExtension will change the extensions_ list. So, we should |
| 1206 | // call it outside the iterator loop. |
| 1207 | for (unsigned int i = 0; i < to_be_removed.size(); ++i) |
[email protected] | 814a7bf0f | 2011-08-13 05:30:59 | [diff] [blame] | 1208 | UnloadExtension(to_be_removed[i], extension_misc::UNLOAD_REASON_DISABLE); |
[email protected] | aa96d3a | 2010-08-21 08:45:25 | [diff] [blame] | 1209 | } |
| 1210 | |
[email protected] | 3120660 | 2011-04-13 23:07:32 | [diff] [blame] | 1211 | void ExtensionService::CheckForUpdatesSoon() { |
[email protected] | c3cfb01 | 2011-04-06 22:07:35 | [diff] [blame] | 1212 | if (updater()) { |
[email protected] | 3120660 | 2011-04-13 23:07:32 | [diff] [blame] | 1213 | updater()->CheckSoon(); |
[email protected] | c3cfb01 | 2011-04-06 22:07:35 | [diff] [blame] | 1214 | } else { |
[email protected] | 3120660 | 2011-04-13 23:07:32 | [diff] [blame] | 1215 | LOG(WARNING) << "CheckForUpdatesSoon() called with auto-update turned off"; |
[email protected] | c3cfb01 | 2011-04-06 22:07:35 | [diff] [blame] | 1216 | } |
| 1217 | } |
| 1218 | |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 1219 | namespace { |
| 1220 | bool IsSyncableNone(const Extension& extension) { return false; } |
[email protected] | 406b5a9 | 2011-11-08 11:58:26 | [diff] [blame] | 1221 | } // namespace |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 1222 | |
| 1223 | ExtensionService::SyncBundle::SyncBundle() |
| 1224 | : filter(IsSyncableNone), |
| 1225 | sync_processor(NULL) { |
[email protected] | b05fb9ff | 2011-04-23 00:07:56 | [diff] [blame] | 1226 | } |
| 1227 | |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 1228 | ExtensionService::SyncBundle::~SyncBundle() { |
| 1229 | } |
| 1230 | |
| 1231 | bool ExtensionService::SyncBundle::HasExtensionId(const std::string& id) const { |
| 1232 | return synced_extensions.find(id) != synced_extensions.end(); |
| 1233 | } |
| 1234 | |
| 1235 | bool ExtensionService::SyncBundle::HasPendingExtensionId(const std::string& id) |
| 1236 | const { |
| 1237 | return pending_sync_data.find(id) != pending_sync_data.end(); |
| 1238 | } |
| 1239 | |
| 1240 | void ExtensionService::SyncExtensionChangeIfNeeded(const Extension& extension) { |
| 1241 | SyncBundle* sync_bundle = GetSyncBundleForExtension(extension); |
| 1242 | if (sync_bundle) { |
[email protected] | aa7599d | 2011-10-28 07:24:32 | [diff] [blame] | 1243 | ExtensionSyncData extension_sync_data( |
| 1244 | extension, |
| 1245 | IsExtensionEnabled(extension.id()), |
| 1246 | IsIncognitoEnabled(extension.id()), |
[email protected] | b2689a90 | 2011-12-01 00:41:09 | [diff] [blame] | 1247 | extension_prefs_->GetAppNotificationClientId(extension.id()), |
[email protected] | 168389f | 2011-12-20 17:12:48 | [diff] [blame] | 1248 | extension_prefs_->IsAppNotificationDisabled(extension.id()), |
| 1249 | GetAppLaunchOrdinal(extension.id()), |
| 1250 | GetPageOrdinal(extension.id())); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 1251 | |
| 1252 | SyncChangeList sync_change_list(1, extension_sync_data.GetSyncChange( |
| 1253 | sync_bundle->HasExtensionId(extension.id()) ? |
| 1254 | SyncChange::ACTION_UPDATE : SyncChange::ACTION_ADD)); |
| 1255 | sync_bundle->sync_processor->ProcessSyncChanges( |
| 1256 | FROM_HERE, sync_change_list); |
| 1257 | sync_bundle->synced_extensions.insert(extension.id()); |
| 1258 | sync_bundle->pending_sync_data.erase(extension.id()); |
[email protected] | b05fb9ff | 2011-04-23 00:07:56 | [diff] [blame] | 1259 | } |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 1260 | } |
| 1261 | |
| 1262 | ExtensionService::SyncBundle* ExtensionService::GetSyncBundleForExtension( |
| 1263 | const Extension& extension) { |
| 1264 | if (app_sync_bundle_.filter(extension)) |
| 1265 | return &app_sync_bundle_; |
| 1266 | else if (extension_sync_bundle_.filter(extension)) |
| 1267 | return &extension_sync_bundle_; |
| 1268 | else |
| 1269 | return NULL; |
| 1270 | } |
| 1271 | |
| 1272 | ExtensionService::SyncBundle* |
| 1273 | ExtensionService::GetSyncBundleForExtensionSyncData( |
| 1274 | const ExtensionSyncData& extension_sync_data) { |
| 1275 | switch (extension_sync_data.type()) { |
| 1276 | case Extension::SYNC_TYPE_APP: |
| 1277 | return &app_sync_bundle_; |
| 1278 | case Extension::SYNC_TYPE_EXTENSION: |
| 1279 | return &extension_sync_bundle_; |
| 1280 | default: |
| 1281 | NOTREACHED(); |
| 1282 | return NULL; |
| 1283 | } |
| 1284 | } |
| 1285 | |
| 1286 | #define GET_SYNC_BUNDLE_FOR_MODEL_TYPE_BODY() \ |
| 1287 | do { \ |
| 1288 | switch (type) { \ |
| 1289 | case syncable::APPS: \ |
| 1290 | return &app_sync_bundle_; \ |
| 1291 | case syncable::EXTENSIONS: \ |
| 1292 | return &extension_sync_bundle_; \ |
| 1293 | default: \ |
| 1294 | NOTREACHED(); \ |
| 1295 | return NULL; \ |
| 1296 | } \ |
| 1297 | } while (0) |
| 1298 | |
| 1299 | const ExtensionService::SyncBundle* |
| 1300 | ExtensionService::GetSyncBundleForModelTypeConst( |
| 1301 | syncable::ModelType type) const { |
| 1302 | GET_SYNC_BUNDLE_FOR_MODEL_TYPE_BODY(); |
| 1303 | } |
| 1304 | |
| 1305 | ExtensionService::SyncBundle* ExtensionService::GetSyncBundleForModelType( |
| 1306 | syncable::ModelType type) { |
| 1307 | GET_SYNC_BUNDLE_FOR_MODEL_TYPE_BODY(); |
| 1308 | } |
| 1309 | |
| 1310 | #undef GET_SYNC_BUNDLE_FOR_MODEL_TYPE_BODY |
| 1311 | |
| 1312 | SyncError ExtensionService::MergeDataAndStartSyncing( |
| 1313 | syncable::ModelType type, |
| 1314 | const SyncDataList& initial_sync_data, |
| 1315 | SyncChangeProcessor* sync_processor) { |
| 1316 | CHECK(sync_processor); |
| 1317 | |
| 1318 | SyncBundle* bundle = NULL; |
| 1319 | |
| 1320 | switch (type) { |
| 1321 | case syncable::EXTENSIONS: |
| 1322 | bundle = &extension_sync_bundle_; |
| 1323 | bundle->filter = IsSyncableExtension; |
| 1324 | break; |
| 1325 | |
| 1326 | case syncable::APPS: |
| 1327 | bundle = &app_sync_bundle_; |
| 1328 | bundle->filter = IsSyncableApp; |
| 1329 | break; |
| 1330 | |
| 1331 | default: |
| 1332 | LOG(FATAL) << "Got " << type << " ModelType"; |
| 1333 | } |
| 1334 | |
| 1335 | bundle->sync_processor = sync_processor; |
| 1336 | |
[email protected] | b1417ab | 2011-12-15 17:09:11 | [diff] [blame] | 1337 | // Process extensions from sync. |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 1338 | for (SyncDataList::const_iterator i = initial_sync_data.begin(); |
| 1339 | i != initial_sync_data.end(); |
| 1340 | ++i) { |
| 1341 | ExtensionSyncData extension_sync_data = ExtensionSyncData(*i); |
| 1342 | bundle->synced_extensions.insert(extension_sync_data.id()); |
| 1343 | ProcessExtensionSyncData(extension_sync_data, *bundle); |
| 1344 | } |
| 1345 | |
[email protected] | b1417ab | 2011-12-15 17:09:11 | [diff] [blame] | 1346 | // Process local extensions. |
| 1347 | // TODO(yoz): Determine whether pending extensions should be considered too. |
| 1348 | // See crbug.com/104399. |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 1349 | SyncDataList sync_data_list = GetAllSyncData(type); |
| 1350 | SyncChangeList sync_change_list; |
| 1351 | for (SyncDataList::const_iterator i = sync_data_list.begin(); |
| 1352 | i != sync_data_list.end(); |
| 1353 | ++i) { |
[email protected] | b1417ab | 2011-12-15 17:09:11 | [diff] [blame] | 1354 | if (bundle->HasExtensionId(i->GetTag())) { |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 1355 | sync_change_list.push_back(SyncChange(SyncChange::ACTION_UPDATE, *i)); |
[email protected] | b1417ab | 2011-12-15 17:09:11 | [diff] [blame] | 1356 | } else { |
| 1357 | bundle->synced_extensions.insert(i->GetTag()); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 1358 | sync_change_list.push_back(SyncChange(SyncChange::ACTION_ADD, *i)); |
[email protected] | b1417ab | 2011-12-15 17:09:11 | [diff] [blame] | 1359 | } |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 1360 | } |
| 1361 | bundle->sync_processor->ProcessSyncChanges(FROM_HERE, sync_change_list); |
| 1362 | |
| 1363 | return SyncError(); |
| 1364 | } |
| 1365 | |
| 1366 | void ExtensionService::StopSyncing(syncable::ModelType type) { |
| 1367 | SyncBundle* bundle = GetSyncBundleForModelType(type); |
| 1368 | CHECK(bundle); |
| 1369 | // This is the simplest way to clear out the bundle. |
| 1370 | *bundle = SyncBundle(); |
| 1371 | } |
| 1372 | |
| 1373 | SyncDataList ExtensionService::GetAllSyncData(syncable::ModelType type) const { |
| 1374 | const SyncBundle* bundle = GetSyncBundleForModelTypeConst(type); |
| 1375 | CHECK(bundle); |
| 1376 | std::vector<ExtensionSyncData> extension_sync_data = GetSyncDataList(*bundle); |
| 1377 | SyncDataList result(extension_sync_data.size()); |
| 1378 | for (int i = 0; i < static_cast<int>(extension_sync_data.size()); ++i) { |
| 1379 | result[i] = extension_sync_data[i].GetSyncData(); |
| 1380 | } |
| 1381 | return result; |
| 1382 | } |
| 1383 | |
| 1384 | SyncError ExtensionService::ProcessSyncChanges( |
| 1385 | const tracked_objects::Location& from_here, |
| 1386 | const SyncChangeList& change_list) { |
| 1387 | for (SyncChangeList::const_iterator i = change_list.begin(); |
| 1388 | i != change_list.end(); |
| 1389 | ++i) { |
| 1390 | ExtensionSyncData extension_sync_data = ExtensionSyncData(*i); |
| 1391 | SyncBundle* bundle = GetSyncBundleForExtensionSyncData(extension_sync_data); |
| 1392 | CHECK(bundle); |
| 1393 | |
| 1394 | if (extension_sync_data.uninstalled()) |
| 1395 | bundle->synced_extensions.erase(extension_sync_data.id()); |
| 1396 | else |
| 1397 | bundle->synced_extensions.insert(extension_sync_data.id()); |
| 1398 | ProcessExtensionSyncData(extension_sync_data, *bundle); |
| 1399 | } |
| 1400 | |
| 1401 | return SyncError(); |
[email protected] | b05fb9ff | 2011-04-23 00:07:56 | [diff] [blame] | 1402 | } |
| 1403 | |
| 1404 | void ExtensionService::GetSyncDataListHelper( |
[email protected] | 84df833 | 2011-12-06 18:22:46 | [diff] [blame] | 1405 | const ExtensionSet& extensions, |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 1406 | const SyncBundle& bundle, |
[email protected] | b05fb9ff | 2011-04-23 00:07:56 | [diff] [blame] | 1407 | std::vector<ExtensionSyncData>* sync_data_list) const { |
[email protected] | 84df833 | 2011-12-06 18:22:46 | [diff] [blame] | 1408 | for (ExtensionSet::const_iterator it = extensions.begin(); |
[email protected] | b05fb9ff | 2011-04-23 00:07:56 | [diff] [blame] | 1409 | it != extensions.end(); ++it) { |
| 1410 | const Extension& extension = **it; |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 1411 | if (bundle.filter(extension) && |
| 1412 | // If we have pending extension data for this extension, then this |
| 1413 | // version is out of date. We'll sync back the version we got from |
| 1414 | // sync. |
| 1415 | !bundle.HasPendingExtensionId(extension.id())) { |
[email protected] | aa7599d | 2011-10-28 07:24:32 | [diff] [blame] | 1416 | sync_data_list->push_back(ExtensionSyncData( |
| 1417 | extension, |
| 1418 | IsExtensionEnabled(extension.id()), |
| 1419 | IsIncognitoEnabled(extension.id()), |
[email protected] | b2689a90 | 2011-12-01 00:41:09 | [diff] [blame] | 1420 | extension_prefs_->GetAppNotificationClientId(extension.id()), |
[email protected] | 168389f | 2011-12-20 17:12:48 | [diff] [blame] | 1421 | extension_prefs_->IsAppNotificationDisabled(extension.id()), |
| 1422 | GetAppLaunchOrdinal(extension.id()), |
| 1423 | GetPageOrdinal(extension.id()))); |
[email protected] | b05fb9ff | 2011-04-23 00:07:56 | [diff] [blame] | 1424 | } |
| 1425 | } |
| 1426 | } |
| 1427 | |
| 1428 | std::vector<ExtensionSyncData> ExtensionService::GetSyncDataList( |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 1429 | const SyncBundle& bundle) const { |
| 1430 | std::vector<ExtensionSyncData> extension_sync_list; |
| 1431 | GetSyncDataListHelper(extensions_, bundle, &extension_sync_list); |
| 1432 | GetSyncDataListHelper(disabled_extensions_, bundle, &extension_sync_list); |
| 1433 | GetSyncDataListHelper(terminated_extensions_, bundle, &extension_sync_list); |
| 1434 | |
| 1435 | for (std::map<std::string, ExtensionSyncData>::const_iterator i = |
| 1436 | bundle.pending_sync_data.begin(); |
| 1437 | i != bundle.pending_sync_data.end(); |
| 1438 | ++i) { |
| 1439 | extension_sync_list.push_back(i->second); |
| 1440 | } |
| 1441 | |
| 1442 | return extension_sync_list; |
[email protected] | b05fb9ff | 2011-04-23 00:07:56 | [diff] [blame] | 1443 | } |
| 1444 | |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 1445 | void ExtensionService::ProcessExtensionSyncData( |
[email protected] | 90310d9 | 2011-04-17 07:35:04 | [diff] [blame] | 1446 | const ExtensionSyncData& extension_sync_data, |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 1447 | SyncBundle& bundle) { |
| 1448 | const std::string& id = extension_sync_data.id(); |
[email protected] | 96e989b | 2011-08-30 19:35:06 | [diff] [blame] | 1449 | const Extension* extension = GetInstalledExtension(id); |
| 1450 | |
| 1451 | // TODO(bolms): we should really handle this better. The particularly bad |
| 1452 | // case is where an app becomes an extension or vice versa, and we end up with |
| 1453 | // a zombie extension that won't go away. |
| 1454 | if (extension && !bundle.filter(*extension)) |
| 1455 | return; |
[email protected] | 90310d9 | 2011-04-17 07:35:04 | [diff] [blame] | 1456 | |
| 1457 | // Handle uninstalls first. |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 1458 | if (extension_sync_data.uninstalled()) { |
[email protected] | 90310d9 | 2011-04-17 07:35:04 | [diff] [blame] | 1459 | std::string error; |
| 1460 | if (!UninstallExtensionHelper(this, id)) { |
| 1461 | LOG(WARNING) << "Could not uninstall extension " << id |
| 1462 | << " for sync"; |
| 1463 | } |
| 1464 | return; |
| 1465 | } |
| 1466 | |
[email protected] | 06f9256 | 2011-04-29 19:27:31 | [diff] [blame] | 1467 | // Set user settings. |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 1468 | if (extension_sync_data.enabled()) { |
[email protected] | 06f9256 | 2011-04-29 19:27:31 | [diff] [blame] | 1469 | EnableExtension(id); |
| 1470 | } else { |
| 1471 | DisableExtension(id); |
| 1472 | } |
[email protected] | 81b14cc | 2011-04-29 00:39:37 | [diff] [blame] | 1473 | |
[email protected] | 406b5a9 | 2011-11-08 11:58:26 | [diff] [blame] | 1474 | // We need to cache some version information here because setting the |
| 1475 | // incognito flag invalidates the |extension| pointer (it reloads the |
| 1476 | // extension). |
| 1477 | bool extension_installed = extension != NULL; |
| 1478 | int result = extension ? |
| 1479 | extension->version()->CompareTo(extension_sync_data.version()) : 0; |
| 1480 | SetIsIncognitoEnabled(id, extension_sync_data.incognito_enabled()); |
| 1481 | extension = NULL; // No longer safe to use. |
| 1482 | |
| 1483 | if (extension_installed) { |
[email protected] | 06f9256 | 2011-04-29 19:27:31 | [diff] [blame] | 1484 | // If the extension is already installed, check if it's outdated. |
[email protected] | 90310d9 | 2011-04-17 07:35:04 | [diff] [blame] | 1485 | if (result < 0) { |
| 1486 | // Extension is outdated. |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 1487 | bundle.pending_sync_data[extension_sync_data.id()] = extension_sync_data; |
[email protected] | 90310d9 | 2011-04-17 07:35:04 | [diff] [blame] | 1488 | CheckForUpdatesSoon(); |
[email protected] | 90310d9 | 2011-04-17 07:35:04 | [diff] [blame] | 1489 | } |
[email protected] | b10a4abe | 2011-12-10 02:31:23 | [diff] [blame] | 1490 | if (extension_sync_data.type() == Extension::SYNC_TYPE_APP && |
| 1491 | extension_sync_data.notifications_disabled() != |
[email protected] | b020dc1 | 2011-12-06 04:35:42 | [diff] [blame] | 1492 | extension_prefs_->IsAppNotificationDisabled(id)) { |
| 1493 | extension_prefs_->SetAppNotificationDisabled( |
| 1494 | id, extension_sync_data.notifications_disabled()); |
| 1495 | } |
[email protected] | 06f9256 | 2011-04-29 19:27:31 | [diff] [blame] | 1496 | } else { |
[email protected] | 06f9256 | 2011-04-29 19:27:31 | [diff] [blame] | 1497 | // TODO(akalin): Replace silent update with a list of enabled |
| 1498 | // permissions. |
[email protected] | 6cc7dbae | 2011-04-29 21:18:33 | [diff] [blame] | 1499 | const bool kInstallSilently = true; |
[email protected] | 06f9256 | 2011-04-29 19:27:31 | [diff] [blame] | 1500 | if (!pending_extension_manager()->AddFromSync( |
| 1501 | id, |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 1502 | extension_sync_data.update_url(), |
| 1503 | bundle.filter, |
[email protected] | 6cc7dbae | 2011-04-29 21:18:33 | [diff] [blame] | 1504 | kInstallSilently)) { |
[email protected] | 06f9256 | 2011-04-29 19:27:31 | [diff] [blame] | 1505 | LOG(WARNING) << "Could not add pending extension for " << id; |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 1506 | // This means that the extension is already pending installation, with a |
| 1507 | // non-INTERNAL location. Add to pending_sync_data, even though it will |
| 1508 | // never be removed (we'll never install a syncable version of the |
| 1509 | // extension), so that GetAllSyncData() continues to send it. |
[email protected] | 06f9256 | 2011-04-29 19:27:31 | [diff] [blame] | 1510 | } |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 1511 | // Track pending extensions so that we can return them in GetAllSyncData(). |
| 1512 | bundle.pending_sync_data[extension_sync_data.id()] = extension_sync_data; |
[email protected] | 06f9256 | 2011-04-29 19:27:31 | [diff] [blame] | 1513 | CheckForUpdatesSoon(); |
[email protected] | 90310d9 | 2011-04-17 07:35:04 | [diff] [blame] | 1514 | } |
[email protected] | 90310d9 | 2011-04-17 07:35:04 | [diff] [blame] | 1515 | } |
| 1516 | |
[email protected] | c3cfb01 | 2011-04-06 22:07:35 | [diff] [blame] | 1517 | bool ExtensionService::IsIncognitoEnabled( |
| 1518 | const std::string& extension_id) const { |
| 1519 | // If this is an existing component extension we always allow it to |
| 1520 | // work in incognito mode. |
[email protected] | 81b14cc | 2011-04-29 00:39:37 | [diff] [blame] | 1521 | const Extension* extension = GetInstalledExtension(extension_id); |
[email protected] | c3cfb01 | 2011-04-06 22:07:35 | [diff] [blame] | 1522 | if (extension && extension->location() == Extension::COMPONENT) |
[email protected] | cb0ce1e02 | 2010-03-10 19:54:41 | [diff] [blame] | 1523 | return true; |
| 1524 | |
| 1525 | // Check the prefs. |
[email protected] | c3cfb01 | 2011-04-06 22:07:35 | [diff] [blame] | 1526 | return extension_prefs_->IsIncognitoEnabled(extension_id); |
[email protected] | db7331a | 2010-02-25 22:10:50 | [diff] [blame] | 1527 | } |
[email protected] | 55a3569 | 2010-02-11 23:25:21 | [diff] [blame] | 1528 | |
[email protected] | c3cfb01 | 2011-04-06 22:07:35 | [diff] [blame] | 1529 | void ExtensionService::SetIsIncognitoEnabled( |
| 1530 | const std::string& extension_id, bool enabled) { |
[email protected] | 81b14cc | 2011-04-29 00:39:37 | [diff] [blame] | 1531 | const Extension* extension = GetInstalledExtension(extension_id); |
[email protected] | c3cfb01 | 2011-04-06 22:07:35 | [diff] [blame] | 1532 | if (extension && extension->location() == Extension::COMPONENT) { |
| 1533 | // This shouldn't be called for component extensions. |
| 1534 | NOTREACHED(); |
| 1535 | return; |
| 1536 | } |
| 1537 | |
[email protected] | 8c6c8c2 | 2011-03-09 12:52:34 | [diff] [blame] | 1538 | // Broadcast unloaded and loaded events to update browser state. Only bother |
| 1539 | // if the value changed and the extension is actually enabled, since there is |
| 1540 | // no UI otherwise. |
[email protected] | c3cfb01 | 2011-04-06 22:07:35 | [diff] [blame] | 1541 | bool old_enabled = extension_prefs_->IsIncognitoEnabled(extension_id); |
[email protected] | 8c6c8c2 | 2011-03-09 12:52:34 | [diff] [blame] | 1542 | if (enabled == old_enabled) |
| 1543 | return; |
| 1544 | |
[email protected] | c3cfb01 | 2011-04-06 22:07:35 | [diff] [blame] | 1545 | extension_prefs_->SetIsIncognitoEnabled(extension_id, enabled); |
[email protected] | 81b14cc | 2011-04-29 00:39:37 | [diff] [blame] | 1546 | |
[email protected] | ffbf3f1 | 2011-12-09 22:10:33 | [diff] [blame] | 1547 | bool extension_is_enabled = extensions_.Contains(extension_id); |
[email protected] | bd9892eb | 2011-11-11 19:41:34 | [diff] [blame] | 1548 | |
| 1549 | // When we reload the extension the ID may be invalidated if we've passed it |
| 1550 | // by const ref everywhere. Make a copy to be safe. |
| 1551 | std::string id = extension_id; |
[email protected] | 406b5a9 | 2011-11-08 11:58:26 | [diff] [blame] | 1552 | if (extension_is_enabled) |
[email protected] | ffbf3f1 | 2011-12-09 22:10:33 | [diff] [blame] | 1553 | ReloadExtension(id); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 1554 | |
[email protected] | 406b5a9 | 2011-11-08 11:58:26 | [diff] [blame] | 1555 | // Reloading the extension invalidates the |extension| pointer. |
[email protected] | bd9892eb | 2011-11-11 19:41:34 | [diff] [blame] | 1556 | extension = GetInstalledExtension(id); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 1557 | if (extension) |
| 1558 | SyncExtensionChangeIfNeeded(*extension); |
[email protected] | 55a3569 | 2010-02-11 23:25:21 | [diff] [blame] | 1559 | } |
| 1560 | |
[email protected] | aa7599d | 2011-10-28 07:24:32 | [diff] [blame] | 1561 | void ExtensionService::SetAppNotificationSetupDone( |
| 1562 | const std::string& extension_id, |
[email protected] | b2689a90 | 2011-12-01 00:41:09 | [diff] [blame] | 1563 | const std::string& oauth_client_id) { |
[email protected] | aa7599d | 2011-10-28 07:24:32 | [diff] [blame] | 1564 | const Extension* extension = GetInstalledExtension(extension_id); |
| 1565 | // This method is called when the user sets up app notifications. |
| 1566 | // So it is not expected to be called until the extension is installed. |
| 1567 | if (!extension) { |
| 1568 | NOTREACHED(); |
| 1569 | return; |
| 1570 | } |
[email protected] | b2689a90 | 2011-12-01 00:41:09 | [diff] [blame] | 1571 | extension_prefs_->SetAppNotificationClientId(extension_id, oauth_client_id); |
[email protected] | aa7599d | 2011-10-28 07:24:32 | [diff] [blame] | 1572 | SyncExtensionChangeIfNeeded(*extension); |
| 1573 | } |
| 1574 | |
| 1575 | void ExtensionService::SetAppNotificationDisabled( |
| 1576 | const std::string& extension_id, |
| 1577 | bool value) { |
| 1578 | const Extension* extension = GetInstalledExtension(extension_id); |
| 1579 | // This method is called when the user enables/disables app notifications. |
| 1580 | // So it is not expected to be called until the extension is installed. |
| 1581 | if (!extension) { |
| 1582 | NOTREACHED(); |
| 1583 | return; |
| 1584 | } |
[email protected] | 97e856b1 | 2011-12-14 00:21:13 | [diff] [blame] | 1585 | if (value) |
| 1586 | UMA_HISTOGRAM_COUNTS("Apps.SetAppNotificationsDisabled", 1); |
| 1587 | else |
| 1588 | UMA_HISTOGRAM_COUNTS("Apps.SetAppNotificationsEnabled", 1); |
[email protected] | aa7599d | 2011-10-28 07:24:32 | [diff] [blame] | 1589 | extension_prefs_->SetAppNotificationDisabled(extension_id, value); |
| 1590 | SyncExtensionChangeIfNeeded(*extension); |
| 1591 | } |
| 1592 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 1593 | bool ExtensionService::CanCrossIncognito(const Extension* extension) { |
[email protected] | 2a8f24e | 2010-11-03 21:37:05 | [diff] [blame] | 1594 | // We allow the extension to see events and data from another profile iff it |
| 1595 | // uses "spanning" behavior and it has incognito access. "split" mode |
| 1596 | // extensions only see events for a matching profile. |
[email protected] | 0c41298f | 2011-09-13 21:17:22 | [diff] [blame] | 1597 | CHECK(extension); |
[email protected] | c3cfb01 | 2011-04-06 22:07:35 | [diff] [blame] | 1598 | return IsIncognitoEnabled(extension->id()) && |
| 1599 | !extension->incognito_split_mode(); |
[email protected] | 2a8f24e | 2010-11-03 21:37:05 | [diff] [blame] | 1600 | } |
| 1601 | |
[email protected] | 5ef7b00 | 2011-05-12 23:16:20 | [diff] [blame] | 1602 | bool ExtensionService::CanLoadInIncognito(const Extension* extension) const { |
| 1603 | if (extension->is_hosted_app()) |
| 1604 | return true; |
| 1605 | // Packaged apps and regular extensions need to be enabled specifically for |
| 1606 | // incognito (and split mode should be set). |
| 1607 | return extension->incognito_split_mode() && |
| 1608 | IsIncognitoEnabled(extension->id()); |
| 1609 | } |
| 1610 | |
[email protected] | 168389f | 2011-12-20 17:12:48 | [diff] [blame] | 1611 | StringOrdinal ExtensionService::GetAppLaunchOrdinal( |
| 1612 | const std::string& extension_id) const { |
[email protected] | 3569b50 | 2012-01-12 20:08:23 | [diff] [blame^] | 1613 | return |
| 1614 | extension_prefs_->extension_sorting()->GetAppLaunchOrdinal(extension_id); |
[email protected] | 168389f | 2011-12-20 17:12:48 | [diff] [blame] | 1615 | } |
| 1616 | |
| 1617 | void ExtensionService::SetAppLaunchOrdinal( |
| 1618 | const std::string& extension_id, |
| 1619 | const StringOrdinal& app_launch_index) { |
| 1620 | const Extension* ext = GetExtensionById(extension_id, true); |
| 1621 | DCHECK(ext->is_app()); |
| 1622 | |
[email protected] | 3569b50 | 2012-01-12 20:08:23 | [diff] [blame^] | 1623 | extension_prefs_->extension_sorting()->SetAppLaunchOrdinal( |
| 1624 | extension_id, app_launch_index); |
[email protected] | 168389f | 2011-12-20 17:12:48 | [diff] [blame] | 1625 | |
| 1626 | const Extension* extension = GetInstalledExtension(extension_id); |
| 1627 | if (extension) |
| 1628 | SyncExtensionChangeIfNeeded(*extension); |
| 1629 | } |
| 1630 | |
| 1631 | StringOrdinal ExtensionService::GetPageOrdinal( |
| 1632 | const std::string& extension_id) const { |
[email protected] | 3569b50 | 2012-01-12 20:08:23 | [diff] [blame^] | 1633 | return extension_prefs_->extension_sorting()->GetPageOrdinal(extension_id); |
[email protected] | 168389f | 2011-12-20 17:12:48 | [diff] [blame] | 1634 | } |
| 1635 | |
| 1636 | void ExtensionService::SetPageOrdinal(const std::string& extension_id, |
| 1637 | const StringOrdinal& page_ordinal) { |
| 1638 | const Extension* ext = GetExtensionById(extension_id, true); |
| 1639 | DCHECK(ext->is_app()); |
| 1640 | |
[email protected] | 3569b50 | 2012-01-12 20:08:23 | [diff] [blame^] | 1641 | extension_prefs_->extension_sorting()->SetPageOrdinal( |
| 1642 | extension_id, page_ordinal); |
[email protected] | 168389f | 2011-12-20 17:12:48 | [diff] [blame] | 1643 | |
| 1644 | const Extension* extension = GetInstalledExtension(extension_id); |
| 1645 | if (extension) |
| 1646 | SyncExtensionChangeIfNeeded(*extension); |
| 1647 | } |
| 1648 | |
| 1649 | void ExtensionService::OnExtensionMoved( |
| 1650 | const std::string& moved_extension_id, |
| 1651 | const std::string& predecessor_extension_id, |
| 1652 | const std::string& successor_extension_id) { |
[email protected] | 3569b50 | 2012-01-12 20:08:23 | [diff] [blame^] | 1653 | extension_prefs_->extension_sorting()->OnExtensionMoved( |
| 1654 | moved_extension_id, |
| 1655 | predecessor_extension_id, |
| 1656 | successor_extension_id); |
[email protected] | 168389f | 2011-12-20 17:12:48 | [diff] [blame] | 1657 | |
| 1658 | const Extension* extension = GetInstalledExtension(moved_extension_id); |
| 1659 | if (extension) |
| 1660 | SyncExtensionChangeIfNeeded(*extension); |
| 1661 | } |
| 1662 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 1663 | bool ExtensionService::AllowFileAccess(const Extension* extension) { |
[email protected] | 05c8218 | 2010-06-24 17:49:08 | [diff] [blame] | 1664 | return (CommandLine::ForCurrentProcess()->HasSwitch( |
[email protected] | 334e04a | 2010-06-24 23:34:44 | [diff] [blame] | 1665 | switches::kDisableExtensionsFileAccessCheck) || |
[email protected] | 05c8218 | 2010-06-24 17:49:08 | [diff] [blame] | 1666 | extension_prefs_->AllowFileAccess(extension->id())); |
| 1667 | } |
| 1668 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 1669 | void ExtensionService::SetAllowFileAccess(const Extension* extension, |
[email protected] | 3aff9ad | 2011-04-01 20:26:48 | [diff] [blame] | 1670 | bool allow) { |
| 1671 | // Reload to update browser state. Only bother if the value changed and the |
| 1672 | // extension is actually enabled, since there is no UI otherwise. |
| 1673 | bool old_allow = AllowFileAccess(extension); |
| 1674 | if (allow == old_allow) |
| 1675 | return; |
| 1676 | |
[email protected] | 05c8218 | 2010-06-24 17:49:08 | [diff] [blame] | 1677 | extension_prefs_->SetAllowFileAccess(extension->id(), allow); |
[email protected] | 3aff9ad | 2011-04-01 20:26:48 | [diff] [blame] | 1678 | |
[email protected] | 84df833 | 2011-12-06 18:22:46 | [diff] [blame] | 1679 | bool extension_is_enabled = extensions_.Contains(extension->id()); |
[email protected] | 3aff9ad | 2011-04-01 20:26:48 | [diff] [blame] | 1680 | if (extension_is_enabled) |
| 1681 | ReloadExtension(extension->id()); |
[email protected] | 05c8218 | 2010-06-24 17:49:08 | [diff] [blame] | 1682 | } |
| 1683 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 1684 | bool ExtensionService::GetBrowserActionVisibility(const Extension* extension) { |
[email protected] | f681c78 | 2010-11-19 11:19:39 | [diff] [blame] | 1685 | return extension_prefs_->GetBrowserActionVisibility(extension); |
| 1686 | } |
| 1687 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 1688 | void ExtensionService::SetBrowserActionVisibility(const Extension* extension, |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 1689 | bool visible) { |
[email protected] | f681c78 | 2010-11-19 11:19:39 | [diff] [blame] | 1690 | extension_prefs_->SetBrowserActionVisibility(extension, visible); |
| 1691 | } |
| 1692 | |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 1693 | // Some extensions will autoupdate themselves externally from Chrome. These |
| 1694 | // are typically part of some larger client application package. To support |
| 1695 | // these, the extension will register its location in the the preferences file |
| 1696 | // (and also, on Windows, in the registry) and this code will periodically |
| 1697 | // check that location for a .crx file, which it will then install locally if |
| 1698 | // a new version is available. |
| 1699 | // Errors are reported through ExtensionErrorReporter. Succcess is not |
| 1700 | // reported. |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 1701 | void ExtensionService::CheckForExternalUpdates() { |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 1702 | CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 1703 | |
| 1704 | // Note that this installation is intentionally silent (since it didn't |
| 1705 | // go through the front-end). Extensions that are registered in this |
| 1706 | // way are effectively considered 'pre-bundled', and so implicitly |
| 1707 | // trusted. In general, if something has HKLM or filesystem access, |
| 1708 | // they could install an extension manually themselves anyway. |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 1709 | |
| 1710 | // If any external extension records give a URL, a provider will set |
| 1711 | // this to true. Used by OnExternalProviderReady() to see if we need |
| 1712 | // to start an update check to fetch a new external extension. |
| 1713 | external_extension_url_added_ = false; |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 1714 | |
| 1715 | // Ask each external extension provider to give us a call back for each |
| 1716 | // extension they know about. See OnExternalExtension(File|UpdateUrl)Found. |
| 1717 | ProviderCollection::const_iterator i; |
| 1718 | for (i = external_extension_providers_.begin(); |
| 1719 | i != external_extension_providers_.end(); ++i) { |
| 1720 | ExternalExtensionProviderInterface* provider = i->get(); |
| 1721 | provider->VisitRegisteredExtension(); |
| 1722 | } |
| 1723 | |
[email protected] | 50067e5 | 2011-10-20 23:17:07 | [diff] [blame] | 1724 | // Do any required work that we would have done after completion of all |
| 1725 | // providers. |
| 1726 | if (external_extension_providers_.empty()) { |
| 1727 | OnAllExternalProvidersReady(); |
| 1728 | } |
[email protected] | 9f1087e | 2009-06-15 17:29:32 | [diff] [blame] | 1729 | } |
| 1730 | |
[email protected] | 50067e5 | 2011-10-20 23:17:07 | [diff] [blame] | 1731 | void ExtensionService::OnExternalProviderReady( |
| 1732 | const ExternalExtensionProviderInterface* provider) { |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 1733 | CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
[email protected] | 50067e5 | 2011-10-20 23:17:07 | [diff] [blame] | 1734 | CHECK(provider->IsReady()); |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 1735 | |
| 1736 | // An external provider has finished loading. We only take action |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 1737 | // if all of them are finished. So we check them first. |
| 1738 | ProviderCollection::const_iterator i; |
| 1739 | for (i = external_extension_providers_.begin(); |
| 1740 | i != external_extension_providers_.end(); ++i) { |
| 1741 | ExternalExtensionProviderInterface* provider = i->get(); |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 1742 | if (!provider->IsReady()) |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 1743 | return; |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 1744 | } |
| 1745 | |
[email protected] | 50067e5 | 2011-10-20 23:17:07 | [diff] [blame] | 1746 | OnAllExternalProvidersReady(); |
| 1747 | } |
| 1748 | |
| 1749 | void ExtensionService::OnAllExternalProvidersReady() { |
| 1750 | CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 1751 | |
| 1752 | // Install any pending extensions. |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 1753 | if (external_extension_url_added_ && updater()) { |
| 1754 | external_extension_url_added_ = false; |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 1755 | updater()->CheckNow(); |
| 1756 | } |
| 1757 | |
| 1758 | // Uninstall all the unclaimed extensions. |
| 1759 | scoped_ptr<ExtensionPrefs::ExtensionsInfo> extensions_info( |
| 1760 | extension_prefs_->GetInstalledExtensionsInfo()); |
| 1761 | for (size_t i = 0; i < extensions_info->size(); ++i) { |
| 1762 | ExtensionInfo* info = extensions_info->at(i).get(); |
| 1763 | if (Extension::IsExternalLocation(info->extension_location)) |
| 1764 | CheckExternalUninstall(info->extension_id); |
| 1765 | } |
[email protected] | e5af875f | 2011-10-10 21:09:14 | [diff] [blame] | 1766 | IdentifyAlertableExtensions(); |
[email protected] | e5af875f | 2011-10-10 21:09:14 | [diff] [blame] | 1767 | } |
| 1768 | |
| 1769 | void ExtensionService::IdentifyAlertableExtensions() { |
| 1770 | CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 1771 | |
[email protected] | 08b8336 | 2011-10-19 05:23:17 | [diff] [blame] | 1772 | if (!CommandLine::ForCurrentProcess()->HasSwitch( |
| 1773 | switches::kEnableExtensionAlerts)) { |
| 1774 | return; // TODO(miket): enable unconditionally when done. |
| 1775 | } |
| 1776 | |
[email protected] | e5af875f | 2011-10-10 21:09:14 | [diff] [blame] | 1777 | // Build up the lists of extensions that require acknowledgment. |
| 1778 | // If this is the first time, grandfather extensions that would have |
| 1779 | // caused notification. |
| 1780 | scoped_ptr<ExtensionGlobalError> global_error( |
[email protected] | d8c8f25f | 2011-11-02 18:18:01 | [diff] [blame] | 1781 | new ExtensionGlobalError(AsWeakPtr())); |
[email protected] | e5af875f | 2011-10-10 21:09:14 | [diff] [blame] | 1782 | bool needs_alert = false; |
[email protected] | 84df833 | 2011-12-06 18:22:46 | [diff] [blame] | 1783 | for (ExtensionSet::const_iterator iter = extensions_.begin(); |
[email protected] | e5af875f | 2011-10-10 21:09:14 | [diff] [blame] | 1784 | iter != extensions_.end(); ++iter) { |
| 1785 | const Extension* e = *iter; |
[email protected] | e5af875f | 2011-10-10 21:09:14 | [diff] [blame] | 1786 | if (Extension::IsExternalLocation(e->location())) { |
| 1787 | if (!extension_prefs_->IsExternalExtensionAcknowledged(e->id())) { |
| 1788 | global_error->AddExternalExtension(e->id()); |
| 1789 | needs_alert = true; |
| 1790 | } |
| 1791 | } |
| 1792 | if (extension_prefs_->IsExtensionBlacklisted(e->id())) { |
| 1793 | if (!extension_prefs_->IsBlacklistedExtensionAcknowledged(e->id())) { |
| 1794 | global_error->AddBlacklistedExtension(e->id()); |
| 1795 | needs_alert = true; |
| 1796 | } |
| 1797 | } |
| 1798 | if (extension_prefs_->IsExtensionOrphaned(e->id())) { |
| 1799 | if (!extension_prefs_->IsOrphanedExtensionAcknowledged(e->id())) { |
| 1800 | global_error->AddOrphanedExtension(e->id()); |
| 1801 | needs_alert = true; |
| 1802 | } |
| 1803 | } |
| 1804 | } |
| 1805 | |
| 1806 | if (needs_alert) { |
| 1807 | if (extension_prefs_->SetAlertSystemFirstRun()) { |
| 1808 | global_error->set_accept_callback( |
| 1809 | base::Bind(&ExtensionService::HandleExtensionAlertAccept, |
| 1810 | base::Unretained(this))); |
| 1811 | global_error->set_cancel_callback( |
| 1812 | base::Bind(&ExtensionService::HandleExtensionAlertDetails, |
| 1813 | base::Unretained(this))); |
[email protected] | 62433d3 | 2011-10-12 22:33:12 | [diff] [blame] | 1814 | ShowExtensionAlert(global_error.release()); |
[email protected] | e5af875f | 2011-10-10 21:09:14 | [diff] [blame] | 1815 | } else { |
| 1816 | // First run. Just acknowledge all the extensions, silently, by |
| 1817 | // shortcutting the display of the UI and going straight to the |
| 1818 | // callback for pressing the Accept button. |
[email protected] | 62433d3 | 2011-10-12 22:33:12 | [diff] [blame] | 1819 | HandleExtensionAlertAccept(*global_error.get(), NULL); |
[email protected] | e5af875f | 2011-10-10 21:09:14 | [diff] [blame] | 1820 | } |
| 1821 | } |
| 1822 | } |
| 1823 | |
[email protected] | 62433d3 | 2011-10-12 22:33:12 | [diff] [blame] | 1824 | void ExtensionService::ShowExtensionAlert(ExtensionGlobalError* global_error) { |
| 1825 | CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 1826 | Browser* browser = BrowserList::GetLastActiveWithProfile(profile_); |
| 1827 | if (browser) { |
| 1828 | global_error->ShowBubbleView(browser); |
| 1829 | } |
| 1830 | } |
| 1831 | |
[email protected] | e5af875f | 2011-10-10 21:09:14 | [diff] [blame] | 1832 | void ExtensionService::HandleExtensionAlertAccept( |
[email protected] | 62433d3 | 2011-10-12 22:33:12 | [diff] [blame] | 1833 | const ExtensionGlobalError& global_error, Browser* browser) { |
[email protected] | e5af875f | 2011-10-10 21:09:14 | [diff] [blame] | 1834 | const ExtensionIdSet *extension_ids = |
| 1835 | global_error.get_external_extension_ids(); |
| 1836 | for (ExtensionIdSet::const_iterator iter = extension_ids->begin(); |
| 1837 | iter != extension_ids->end(); ++iter) { |
[email protected] | 47fc70c | 2011-12-06 07:29:51 | [diff] [blame] | 1838 | AcknowledgeExternalExtension(*iter); |
[email protected] | e5af875f | 2011-10-10 21:09:14 | [diff] [blame] | 1839 | } |
| 1840 | extension_ids = global_error.get_blacklisted_extension_ids(); |
| 1841 | for (ExtensionIdSet::const_iterator iter = extension_ids->begin(); |
| 1842 | iter != extension_ids->end(); ++iter) { |
| 1843 | extension_prefs_->AcknowledgeBlacklistedExtension(*iter); |
| 1844 | } |
| 1845 | extension_ids = global_error.get_orphaned_extension_ids(); |
| 1846 | for (ExtensionIdSet::const_iterator iter = extension_ids->begin(); |
| 1847 | iter != extension_ids->end(); ++iter) { |
| 1848 | extension_prefs_->AcknowledgeOrphanedExtension(*iter); |
| 1849 | } |
| 1850 | } |
| 1851 | |
[email protected] | 47fc70c | 2011-12-06 07:29:51 | [diff] [blame] | 1852 | void ExtensionService::AcknowledgeExternalExtension(const std::string& id) { |
| 1853 | extension_prefs_->AcknowledgeExternalExtension(id); |
| 1854 | } |
| 1855 | |
[email protected] | e5af875f | 2011-10-10 21:09:14 | [diff] [blame] | 1856 | void ExtensionService::HandleExtensionAlertDetails( |
[email protected] | 62433d3 | 2011-10-12 22:33:12 | [diff] [blame] | 1857 | const ExtensionGlobalError& global_error, Browser* browser) { |
| 1858 | if (browser) { |
| 1859 | browser->ShowExtensionsTab(); |
| 1860 | } |
[email protected] | 6c751e7 | 2010-11-23 10:11:10 | [diff] [blame] | 1861 | } |
| 1862 | |
[email protected] | a9f39a31 | 2010-12-23 22:14:27 | [diff] [blame] | 1863 | void ExtensionService::UnloadExtension( |
| 1864 | const std::string& extension_id, |
[email protected] | 814a7bf0f | 2011-08-13 05:30:59 | [diff] [blame] | 1865 | extension_misc::UnloadedExtensionReason reason) { |
[email protected] | 27e469a | 2010-01-11 20:35:09 | [diff] [blame] | 1866 | // Make sure the extension gets deleted after we return from this function. |
[email protected] | 9adb969 | 2010-10-29 23:14:02 | [diff] [blame] | 1867 | scoped_refptr<const Extension> extension( |
[email protected] | 8001df2 | 2011-04-28 19:59:47 | [diff] [blame] | 1868 | GetExtensionByIdInternal(extension_id, true, true, false)); |
[email protected] | 631cf82 | 2009-05-15 07:01:25 | [diff] [blame] | 1869 | |
[email protected] | fa0c9673 | 2010-11-17 00:14:23 | [diff] [blame] | 1870 | // This method can be called via PostTask, so the extension may have been |
| 1871 | // unloaded by the time this runs. |
[email protected] | dd163fb0 | 2011-05-04 22:22:17 | [diff] [blame] | 1872 | if (!extension) { |
| 1873 | // In case the extension may have crashed/uninstalled. Allow the profile to |
| 1874 | // clean up its RequestContexts. |
| 1875 | profile_->UnregisterExtensionWithRequestContexts(extension_id, reason); |
[email protected] | fa0c9673 | 2010-11-17 00:14:23 | [diff] [blame] | 1876 | return; |
[email protected] | dd163fb0 | 2011-05-04 22:22:17 | [diff] [blame] | 1877 | } |
[email protected] | 0c6da50 | 2009-08-14 22:32:39 | [diff] [blame] | 1878 | |
[email protected] | 1eb17508 | 2010-02-10 09:26:16 | [diff] [blame] | 1879 | // Keep information about the extension so that we can reload it later |
| 1880 | // even if it's not permanently installed. |
| 1881 | unloaded_extension_paths_[extension->id()] = extension->path(); |
| 1882 | |
[email protected] | f17dbd4 | 2010-08-16 23:21:10 | [diff] [blame] | 1883 | // Clean up if the extension is meant to be enabled after a reload. |
| 1884 | disabled_extension_paths_.erase(extension->id()); |
| 1885 | |
[email protected] | d7e9a86 | 2010-11-03 21:57:49 | [diff] [blame] | 1886 | // Clean up runtime data. |
| 1887 | extension_runtime_data_.erase(extension_id); |
| 1888 | |
[email protected] | 84df833 | 2011-12-06 18:22:46 | [diff] [blame] | 1889 | if (disabled_extensions_.Contains(extension->id())) { |
[email protected] | a9f39a31 | 2010-12-23 22:14:27 | [diff] [blame] | 1890 | UnloadedExtensionInfo details(extension, reason); |
| 1891 | details.already_disabled = true; |
[email protected] | 84df833 | 2011-12-06 18:22:46 | [diff] [blame] | 1892 | disabled_extensions_.Remove(extension->id()); |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 1893 | content::NotificationService::current()->Notify( |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 1894 | chrome::NOTIFICATION_EXTENSION_UNLOADED, |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 1895 | content::Source<Profile>(profile_), |
| 1896 | content::Details<UnloadedExtensionInfo>(&details)); |
[email protected] | dd163fb0 | 2011-05-04 22:22:17 | [diff] [blame] | 1897 | // Make sure the profile cleans up its RequestContexts when an already |
| 1898 | // disabled extension is unloaded (since they are also tracking the disabled |
| 1899 | // extensions). |
| 1900 | profile_->UnregisterExtensionWithRequestContexts(extension_id, reason); |
[email protected] | 0c6da50 | 2009-08-14 22:32:39 | [diff] [blame] | 1901 | return; |
| 1902 | } |
| 1903 | |
[email protected] | 84df833 | 2011-12-06 18:22:46 | [diff] [blame] | 1904 | // Remove the extension from our list. |
| 1905 | extensions_.Remove(extension->id()); |
[email protected] | 631cf82 | 2009-05-15 07:01:25 | [diff] [blame] | 1906 | |
[email protected] | a9f39a31 | 2010-12-23 22:14:27 | [diff] [blame] | 1907 | NotifyExtensionUnloaded(extension.get(), reason); |
[email protected] | 631cf82 | 2009-05-15 07:01:25 | [diff] [blame] | 1908 | } |
| 1909 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 1910 | void ExtensionService::UnloadAllExtensions() { |
[email protected] | c8d407e | 2011-04-28 21:27:17 | [diff] [blame] | 1911 | profile_->GetExtensionSpecialStoragePolicy()-> |
| 1912 | RevokeRightsForAllExtensions(); |
| 1913 | |
[email protected] | 84df833 | 2011-12-06 18:22:46 | [diff] [blame] | 1914 | extensions_.Clear(); |
| 1915 | disabled_extensions_.Clear(); |
| 1916 | terminated_extensions_.Clear(); |
[email protected] | d7e9a86 | 2010-11-03 21:57:49 | [diff] [blame] | 1917 | extension_runtime_data_.clear(); |
[email protected] | cd500f7 | 2010-06-25 23:44:32 | [diff] [blame] | 1918 | |
[email protected] | c6e4a341 | 2009-06-24 15:45:29 | [diff] [blame] | 1919 | // TODO(erikkay) should there be a notification for this? We can't use |
| 1920 | // EXTENSION_UNLOADED since that implies that the extension has been disabled |
| 1921 | // or uninstalled, and UnloadAll is just part of shutdown. |
[email protected] | 9f1087e | 2009-06-15 17:29:32 | [diff] [blame] | 1922 | } |
| 1923 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 1924 | void ExtensionService::ReloadExtensions() { |
[email protected] | 9f1087e | 2009-06-15 17:29:32 | [diff] [blame] | 1925 | UnloadAllExtensions(); |
[email protected] | d8c8f25f | 2011-11-02 18:18:01 | [diff] [blame] | 1926 | component_loader_->LoadAll(); |
| 1927 | extensions::InstalledLoader(this).LoadAllExtensions(); |
[email protected] | 9f1087e | 2009-06-15 17:29:32 | [diff] [blame] | 1928 | } |
| 1929 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 1930 | void ExtensionService::GarbageCollectExtensions() { |
[email protected] | 39d9f62c | 2010-12-03 10:48:50 | [diff] [blame] | 1931 | if (extension_prefs_->pref_service()->ReadOnly()) |
[email protected] | ba39967 | 2010-04-06 15:42:39 | [diff] [blame] | 1932 | return; |
| 1933 | |
[email protected] | ca3dbf5 | 2010-05-19 22:27:06 | [diff] [blame] | 1934 | scoped_ptr<ExtensionPrefs::ExtensionsInfo> info( |
| 1935 | extension_prefs_->GetInstalledExtensionsInfo()); |
| 1936 | |
| 1937 | std::map<std::string, FilePath> extension_paths; |
| 1938 | for (size_t i = 0; i < info->size(); ++i) |
| 1939 | extension_paths[info->at(i)->extension_id] = info->at(i)->extension_path; |
| 1940 | |
[email protected] | 14908b7 | 2011-04-20 06:54:36 | [diff] [blame] | 1941 | if (!BrowserThread::PostTask( |
| 1942 | BrowserThread::FILE, FROM_HERE, |
[email protected] | 53612e8 | 2011-10-18 18:00:36 | [diff] [blame] | 1943 | base::Bind( |
[email protected] | 14908b7 | 2011-04-20 06:54:36 | [diff] [blame] | 1944 | &extension_file_util::GarbageCollectExtensions, |
| 1945 | install_directory_, |
| 1946 | extension_paths))) |
| 1947 | NOTREACHED(); |
[email protected] | f6ccd65 | 2010-11-17 00:48:34 | [diff] [blame] | 1948 | |
| 1949 | // Also garbage-collect themes. We check |profile_| to be |
| 1950 | // defensive; in the future, we may call GarbageCollectExtensions() |
| 1951 | // from somewhere other than Init() (e.g., in a timer). |
| 1952 | if (profile_) { |
[email protected] | 1828037 | 2011-03-22 18:05:22 | [diff] [blame] | 1953 | ThemeServiceFactory::GetForProfile(profile_)->RemoveUnusedThemes(); |
[email protected] | f6ccd65 | 2010-11-17 00:48:34 | [diff] [blame] | 1954 | } |
[email protected] | 3cf4f099 | 2009-02-03 23:00:30 | [diff] [blame] | 1955 | } |
| 1956 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 1957 | void ExtensionService::OnLoadedInstalledExtensions() { |
[email protected] | 93fd78f4 | 2009-07-10 16:43:17 | [diff] [blame] | 1958 | if (updater_.get()) { |
| 1959 | updater_->Start(); |
| 1960 | } |
[email protected] | fa6a910 | 2010-11-22 15:38:50 | [diff] [blame] | 1961 | |
| 1962 | ready_ = true; |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 1963 | content::NotificationService::current()->Notify( |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 1964 | chrome::NOTIFICATION_EXTENSIONS_READY, |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 1965 | content::Source<Profile>(profile_), |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 1966 | content::NotificationService::NoDetails()); |
[email protected] | e72e8eb8 | 2009-06-18 17:21:51 | [diff] [blame] | 1967 | } |
| 1968 | |
[email protected] | 49cd157 | 2011-02-08 21:38:45 | [diff] [blame] | 1969 | void ExtensionService::AddExtension(const Extension* extension) { |
[email protected] | ae09ca6 | 2009-08-21 19:46:46 | [diff] [blame] | 1970 | // Ensure extension is deleted unless we transfer ownership. |
[email protected] | 9adb969 | 2010-10-29 23:14:02 | [diff] [blame] | 1971 | scoped_refptr<const Extension> scoped_extension(extension); |
[email protected] | 9f1087e | 2009-06-15 17:29:32 | [diff] [blame] | 1972 | |
[email protected] | c8d407e | 2011-04-28 21:27:17 | [diff] [blame] | 1973 | // TODO(jstritar): We may be able to get rid of this branch by overriding the |
| 1974 | // default extension state to DISABLED when the --disable-extensions flag |
| 1975 | // is set (http://crbug.com/29067). |
| 1976 | if (!extensions_enabled() && |
| 1977 | !extension->is_theme() && |
| 1978 | extension->location() != Extension::COMPONENT && |
| 1979 | !Extension::IsExternalLocation(extension->location())) |
| 1980 | return; |
| 1981 | |
| 1982 | SetBeingUpgraded(extension, false); |
| 1983 | |
[email protected] | 1eb17508 | 2010-02-10 09:26:16 | [diff] [blame] | 1984 | // The extension is now loaded, remove its data from unloaded extension map. |
| 1985 | unloaded_extension_paths_.erase(extension->id()); |
| 1986 | |
[email protected] | bb7f4095 | 2011-01-13 00:21:20 | [diff] [blame] | 1987 | // If a terminated extension is loaded, remove it from the terminated list. |
| 1988 | UntrackTerminatedExtension(extension->id()); |
| 1989 | |
[email protected] | f17dbd4 | 2010-08-16 23:21:10 | [diff] [blame] | 1990 | // If the extension was disabled for a reload, then enable it. |
| 1991 | if (disabled_extension_paths_.erase(extension->id()) > 0) |
| 1992 | EnableExtension(extension->id()); |
| 1993 | |
[email protected] | d728e00 | 2010-12-08 04:46:23 | [diff] [blame] | 1994 | // Check if the extension's privileges have changed and disable the |
| 1995 | // extension if necessary. |
[email protected] | 902fd7b | 2011-07-27 18:42:31 | [diff] [blame] | 1996 | InitializePermissions(extension); |
[email protected] | 0c6da50 | 2009-08-14 22:32:39 | [diff] [blame] | 1997 | |
[email protected] | ad83ca24 | 2011-07-29 01:32:25 | [diff] [blame] | 1998 | bool disabled = extension_prefs_->IsExtensionDisabled(extension->id()); |
[email protected] | 36429da | 2011-07-11 20:25:18 | [diff] [blame] | 1999 | if (disabled) { |
[email protected] | 84df833 | 2011-12-06 18:22:46 | [diff] [blame] | 2000 | disabled_extensions_.Insert(scoped_extension); |
| 2001 | // TODO(aa): This seems dodgy. AddExtension() could get called with a |
| 2002 | // disabled extension for other reasons other than that an update was |
| 2003 | // disabled, e.g. as in ExtensionManagementTest.InstallRequiresConfirm. |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 2004 | content::NotificationService::current()->Notify( |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 2005 | chrome::NOTIFICATION_EXTENSION_UPDATE_DISABLED, |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 2006 | content::Source<Profile>(profile_), |
| 2007 | content::Details<const Extension>(extension)); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 2008 | SyncExtensionChangeIfNeeded(*extension); |
[email protected] | c8d407e | 2011-04-28 21:27:17 | [diff] [blame] | 2009 | return; |
[email protected] | e72e8eb8 | 2009-06-18 17:21:51 | [diff] [blame] | 2010 | } |
[email protected] | aab98a5 | 2009-12-02 03:22:35 | [diff] [blame] | 2011 | |
[email protected] | 84df833 | 2011-12-06 18:22:46 | [diff] [blame] | 2012 | extensions_.Insert(scoped_extension); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 2013 | SyncExtensionChangeIfNeeded(*extension); |
[email protected] | c8d407e | 2011-04-28 21:27:17 | [diff] [blame] | 2014 | NotifyExtensionLoaded(extension); |
[email protected] | d1282c2 | 2011-10-18 02:00:39 | [diff] [blame] | 2015 | IdentifyAlertableExtensions(); |
[email protected] | aab98a5 | 2009-12-02 03:22:35 | [diff] [blame] | 2016 | } |
| 2017 | |
[email protected] | 902fd7b | 2011-07-27 18:42:31 | [diff] [blame] | 2018 | void ExtensionService::InitializePermissions(const Extension* extension) { |
| 2019 | // If the extension has used the optional permissions API, it will have a |
| 2020 | // custom set of active permissions defined in the extension prefs. Here, |
| 2021 | // we update the extension's active permissions based on the prefs. |
| 2022 | scoped_refptr<ExtensionPermissionSet> active_permissions = |
| 2023 | extension_prefs()->GetActivePermissions(extension->id()); |
| 2024 | |
| 2025 | if (active_permissions.get()) { |
| 2026 | // We restrict the active permissions to be within the bounds defined in the |
| 2027 | // extension's manifest. |
| 2028 | // a) active permissions must be a subset of optional + default permissions |
| 2029 | // b) active permissions must contains all default permissions |
| 2030 | scoped_refptr<ExtensionPermissionSet> total_permissions = |
| 2031 | ExtensionPermissionSet::CreateUnion( |
| 2032 | extension->required_permission_set(), |
| 2033 | extension->optional_permission_set()); |
| 2034 | |
| 2035 | // Make sure the active permissions contain no more than optional + default. |
| 2036 | scoped_refptr<ExtensionPermissionSet> adjusted_active = |
| 2037 | ExtensionPermissionSet::CreateIntersection( |
| 2038 | total_permissions.get(), active_permissions.get()); |
| 2039 | |
| 2040 | // Make sure the active permissions contain the default permissions. |
| 2041 | adjusted_active = ExtensionPermissionSet::CreateUnion( |
| 2042 | extension->required_permission_set(), adjusted_active.get()); |
| 2043 | |
[email protected] | c333e79 | 2012-01-06 16:57:39 | [diff] [blame] | 2044 | extensions::PermissionsUpdater perms_updater(profile()); |
| 2045 | perms_updater.UpdateActivePermissions(extension, adjusted_active); |
[email protected] | 902fd7b | 2011-07-27 18:42:31 | [diff] [blame] | 2046 | } |
| 2047 | |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 2048 | // We keep track of all permissions the user has granted each extension. |
| 2049 | // This allows extensions to gracefully support backwards compatibility |
| 2050 | // by including unknown permissions in their manifests. When the user |
| 2051 | // installs the extension, only the recognized permissions are recorded. |
| 2052 | // When the unknown permissions become recognized (e.g., through browser |
| 2053 | // upgrade), we can prompt the user to accept these new permissions. |
| 2054 | // Extensions can also silently upgrade to less permissions, and then |
| 2055 | // silently upgrade to a version that adds these permissions back. |
| 2056 | // |
| 2057 | // For example, pretend that Chrome 10 includes a permission "omnibox" |
| 2058 | // for an API that adds suggestions to the omnibox. An extension can |
| 2059 | // maintain backwards compatibility while still having "omnibox" in the |
| 2060 | // manifest. If a user installs the extension on Chrome 9, the browser |
| 2061 | // will record the permissions it recognized, not including "omnibox." |
| 2062 | // When upgrading to Chrome 10, "omnibox" will be recognized and Chrome |
| 2063 | // will disable the extension and prompt the user to approve the increase |
| 2064 | // in privileges. The extension could then release a new version that |
| 2065 | // removes the "omnibox" permission. When the user upgrades, Chrome will |
| 2066 | // still remember that "omnibox" had been granted, so that if the |
| 2067 | // extension once again includes "omnibox" in an upgrade, the extension |
| 2068 | // can upgrade without requiring this user's approval. |
| 2069 | const Extension* old = GetExtensionByIdInternal(extension->id(), |
[email protected] | 8001df2 | 2011-04-28 19:59:47 | [diff] [blame] | 2070 | true, true, false); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 2071 | bool is_extension_upgrade = old != NULL; |
| 2072 | bool is_privilege_increase = false; |
| 2073 | |
[email protected] | 902fd7b | 2011-07-27 18:42:31 | [diff] [blame] | 2074 | // We only need to compare the granted permissions to the current permissions |
| 2075 | // if the extension is not allowed to silently increase its permissions. |
| 2076 | if (!extension->CanSilentlyIncreasePermissions()) { |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 2077 | // Add all the recognized permissions if the granted permissions list |
| 2078 | // hasn't been initialized yet. |
[email protected] | 902fd7b | 2011-07-27 18:42:31 | [diff] [blame] | 2079 | scoped_refptr<ExtensionPermissionSet> granted_permissions = |
| 2080 | extension_prefs_->GetGrantedPermissions(extension->id()); |
[email protected] | 0d3e4a2 | 2011-06-23 19:02:52 | [diff] [blame] | 2081 | CHECK(granted_permissions.get()); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 2082 | |
| 2083 | // Here, we check if an extension's privileges have increased in a manner |
| 2084 | // that requires the user's approval. This could occur because the browser |
| 2085 | // upgraded and recognized additional privileges, or an extension upgrades |
| 2086 | // to a version that requires additional privileges. |
[email protected] | 0d3e4a2 | 2011-06-23 19:02:52 | [diff] [blame] | 2087 | is_privilege_increase = |
[email protected] | 902fd7b | 2011-07-27 18:42:31 | [diff] [blame] | 2088 | granted_permissions->HasLessPrivilegesThan( |
| 2089 | extension->GetActivePermissions()); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 2090 | } |
| 2091 | |
| 2092 | if (is_extension_upgrade) { |
[email protected] | 66e2687 | 2010-12-03 20:07:25 | [diff] [blame] | 2093 | // Other than for unpacked extensions, CrxInstaller should have guaranteed |
| 2094 | // that we aren't downgrading. |
| 2095 | if (extension->location() != Extension::LOAD) |
| 2096 | CHECK(extension->version()->CompareTo(*(old->version())) >= 0); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 2097 | |
| 2098 | // Extensions get upgraded if the privileges are allowed to increase or |
| 2099 | // the privileges haven't increased. |
| 2100 | if (!is_privilege_increase) { |
| 2101 | SetBeingUpgraded(old, true); |
| 2102 | SetBeingUpgraded(extension, true); |
| 2103 | } |
| 2104 | |
| 2105 | // To upgrade an extension in place, unload the old one and |
| 2106 | // then load the new one. |
[email protected] | 814a7bf0f | 2011-08-13 05:30:59 | [diff] [blame] | 2107 | UnloadExtension(old->id(), extension_misc::UNLOAD_REASON_UPDATE); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 2108 | old = NULL; |
| 2109 | } |
| 2110 | |
| 2111 | // Extension has changed permissions significantly. Disable it. A |
| 2112 | // notification should be sent by the caller. |
| 2113 | if (is_privilege_increase) { |
[email protected] | fe2dd774 | 2011-04-19 22:52:49 | [diff] [blame] | 2114 | if (!extension_prefs_->DidExtensionEscalatePermissions(extension->id())) { |
| 2115 | RecordPermissionMessagesHistogram( |
| 2116 | extension, "Extensions.Permissions_AutoDisable"); |
| 2117 | } |
[email protected] | b3317ad | 2011-04-28 23:46:00 | [diff] [blame] | 2118 | extension_prefs_->SetExtensionState(extension->id(), Extension::DISABLED); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 2119 | extension_prefs_->SetDidExtensionEscalatePermissions(extension, true); |
| 2120 | } |
| 2121 | } |
| 2122 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2123 | void ExtensionService::UpdateActiveExtensionsInCrashReporter() { |
[email protected] | c886596 | 2009-12-16 07:47:39 | [diff] [blame] | 2124 | std::set<std::string> extension_ids; |
[email protected] | 84df833 | 2011-12-06 18:22:46 | [diff] [blame] | 2125 | for (ExtensionSet::const_iterator iter = extensions_.begin(); |
| 2126 | iter != extensions_.end(); ++iter) { |
| 2127 | const Extension* extension = *iter; |
| 2128 | if (!extension->is_theme() && extension->location() != Extension::COMPONENT) |
| 2129 | extension_ids.insert(extension->id()); |
[email protected] | aab98a5 | 2009-12-02 03:22:35 | [diff] [blame] | 2130 | } |
| 2131 | |
| 2132 | child_process_logging::SetActiveExtensions(extension_ids); |
[email protected] | 6014d67 | 2008-12-05 00:38:25 | [diff] [blame] | 2133 | } |
| 2134 | |
[email protected] | 8266d66 | 2011-07-12 21:53:26 | [diff] [blame] | 2135 | void ExtensionService::OnExtensionInstalled( |
[email protected] | 36a5c4c | 2011-12-14 16:34:50 | [diff] [blame] | 2136 | const Extension* extension, |
| 2137 | bool from_webstore, |
| 2138 | const StringOrdinal& page_ordinal) { |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 2139 | CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
[email protected] | a8af9fdb | 2010-10-28 21:52:20 | [diff] [blame] | 2140 | |
[email protected] | 4416c5a | 2010-06-26 01:28:57 | [diff] [blame] | 2141 | // Ensure extension is deleted unless we transfer ownership. |
[email protected] | 9adb969 | 2010-10-29 23:14:02 | [diff] [blame] | 2142 | scoped_refptr<const Extension> scoped_extension(extension); |
[email protected] | c3cfb01 | 2011-04-06 22:07:35 | [diff] [blame] | 2143 | const std::string& id = extension->id(); |
[email protected] | 8a87a533 | 2011-08-11 17:54:59 | [diff] [blame] | 2144 | // Extensions installed by policy can't be disabled. So even if a previous |
| 2145 | // installation disabled the extension, make sure it is now enabled. |
| 2146 | bool initial_enable = |
| 2147 | !extension_prefs_->IsExtensionDisabled(id) || |
| 2148 | !Extension::UserMayDisable(extension->location()); |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 2149 | PendingExtensionInfo pending_extension_info; |
[email protected] | c3cfb01 | 2011-04-06 22:07:35 | [diff] [blame] | 2150 | if (pending_extension_manager()->GetById(id, &pending_extension_info)) { |
| 2151 | pending_extension_manager()->Remove(id); |
[email protected] | 8ef78fd | 2010-08-19 17:14:32 | [diff] [blame] | 2152 | |
[email protected] | 483d1ff | 2011-03-03 17:12:02 | [diff] [blame] | 2153 | if (!pending_extension_info.ShouldAllowInstall(*extension)) { |
[email protected] | 4416c5a | 2010-06-26 01:28:57 | [diff] [blame] | 2154 | LOG(WARNING) |
[email protected] | ae6cb302 | 2011-04-04 20:11:54 | [diff] [blame] | 2155 | << "ShouldAllowInstall() returned false for " |
[email protected] | c3cfb01 | 2011-04-06 22:07:35 | [diff] [blame] | 2156 | << id << " of type " << extension->GetType() |
[email protected] | 7fa19f8 | 2010-12-21 19:40:08 | [diff] [blame] | 2157 | << " and update URL " << extension->update_url().spec() |
| 2158 | << "; not installing"; |
[email protected] | ae6cb302 | 2011-04-04 20:11:54 | [diff] [blame] | 2159 | |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 2160 | content::NotificationService::current()->Notify( |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 2161 | chrome::NOTIFICATION_EXTENSION_INSTALL_NOT_ALLOWED, |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 2162 | content::Source<Profile>(profile_), |
| 2163 | content::Details<const Extension>(extension)); |
[email protected] | ae6cb302 | 2011-04-04 20:11:54 | [diff] [blame] | 2164 | |
[email protected] | 4416c5a | 2010-06-26 01:28:57 | [diff] [blame] | 2165 | // Delete the extension directory since we're not going to |
| 2166 | // load it. |
[email protected] | 14908b7 | 2011-04-20 06:54:36 | [diff] [blame] | 2167 | if (!BrowserThread::PostTask( |
| 2168 | BrowserThread::FILE, FROM_HERE, |
[email protected] | 53612e8 | 2011-10-18 18:00:36 | [diff] [blame] | 2169 | base::Bind(&extension_file_util::DeleteFile, |
| 2170 | extension->path(), true))) |
[email protected] | 14908b7 | 2011-04-20 06:54:36 | [diff] [blame] | 2171 | NOTREACHED(); |
[email protected] | 4416c5a | 2010-06-26 01:28:57 | [diff] [blame] | 2172 | return; |
| 2173 | } |
[email protected] | 4416c5a | 2010-06-26 01:28:57 | [diff] [blame] | 2174 | } else { |
[email protected] | c3cfb01 | 2011-04-06 22:07:35 | [diff] [blame] | 2175 | // We explicitly want to re-enable an uninstalled external |
| 2176 | // extension; if we're here, that means the user is manually |
| 2177 | // installing the extension. |
[email protected] | 6cc7dbae | 2011-04-29 21:18:33 | [diff] [blame] | 2178 | if (IsExternalExtensionUninstalled(id)) { |
| 2179 | initial_enable = true; |
| 2180 | } |
[email protected] | aa14270 | 2010-03-26 01:26:33 | [diff] [blame] | 2181 | } |
| 2182 | |
[email protected] | 0753302 | 2011-06-27 20:42:55 | [diff] [blame] | 2183 | // Do not record the install histograms for upgrades. |
| 2184 | if (!GetExtensionByIdInternal(extension->id(), true, true, false)) { |
| 2185 | UMA_HISTOGRAM_ENUMERATION("Extensions.InstallType", |
| 2186 | extension->GetType(), 100); |
| 2187 | RecordPermissionMessagesHistogram( |
| 2188 | extension, "Extensions.Permissions_Install"); |
| 2189 | } |
| 2190 | |
[email protected] | 4416c5a | 2010-06-26 01:28:57 | [diff] [blame] | 2191 | extension_prefs_->OnExtensionInstalled( |
[email protected] | 8266d66 | 2011-07-12 21:53:26 | [diff] [blame] | 2192 | extension, |
| 2193 | initial_enable ? Extension::ENABLED : Extension::DISABLED, |
[email protected] | cc829cf | 2011-08-22 21:01:35 | [diff] [blame] | 2194 | from_webstore, |
[email protected] | 36a5c4c | 2011-12-14 16:34:50 | [diff] [blame] | 2195 | page_ordinal); |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 2196 | |
[email protected] | cdfca970 | 2011-08-08 16:07:01 | [diff] [blame] | 2197 | // Unpacked extensions default to allowing file access, but if that has been |
| 2198 | // overridden, don't reset the value. |
[email protected] | b6e64fd | 2011-08-09 19:49:19 | [diff] [blame] | 2199 | if (Extension::ShouldAlwaysAllowFileAccess(extension->location()) && |
[email protected] | cdfca970 | 2011-08-08 16:07:01 | [diff] [blame] | 2200 | !extension_prefs_->HasAllowFileAccessSetting(id)) { |
| 2201 | extension_prefs_->SetAllowFileAccess(id, true); |
| 2202 | } |
| 2203 | |
[email protected] | b6cf240f | 2011-10-15 22:09:53 | [diff] [blame] | 2204 | // If the extension should automatically block network startup (e.g., it uses |
| 2205 | // the webRequest API), set the preference. Otherwise clear it, in case the |
| 2206 | // extension stopped using a relevant API. |
| 2207 | extension_prefs_->SetDelaysNetworkRequests( |
| 2208 | extension->id(), extension->ImplicitlyDelaysNetworkStartup()); |
| 2209 | |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 2210 | content::NotificationService::current()->Notify( |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 2211 | chrome::NOTIFICATION_EXTENSION_INSTALLED, |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 2212 | content::Source<Profile>(profile_), |
| 2213 | content::Details<const Extension>(extension)); |
[email protected] | 7577a5c5 | 2009-07-30 06:21:58 | [diff] [blame] | 2214 | |
[email protected] | 9de8328 | 2011-12-12 11:06:37 | [diff] [blame] | 2215 | // Temporary feature to always install shortcuts for platform apps to |
| 2216 | // facilitate early testing. |
| 2217 | // TODO(benwells): Remove before launching platform apps. |
| 2218 | if (extension->is_platform_app()) { |
| 2219 | StartInstallApplicationShortcut(extension); |
| 2220 | } |
| 2221 | |
[email protected] | 49cd157 | 2011-02-08 21:38:45 | [diff] [blame] | 2222 | // Transfer ownership of |extension| to AddExtension. |
| 2223 | AddExtension(scoped_extension); |
[email protected] | 4a19063 | 2009-05-09 01:07:42 | [diff] [blame] | 2224 | } |
| 2225 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2226 | const Extension* ExtensionService::GetExtensionByIdInternal( |
[email protected] | 8001df2 | 2011-04-28 19:59:47 | [diff] [blame] | 2227 | const std::string& id, bool include_enabled, bool include_disabled, |
| 2228 | bool include_terminated) const { |
[email protected] | e957fe5 | 2009-06-23 16:51:05 | [diff] [blame] | 2229 | std::string lowercase_id = StringToLowerASCII(id); |
[email protected] | 0c6da50 | 2009-08-14 22:32:39 | [diff] [blame] | 2230 | if (include_enabled) { |
[email protected] | 84df833 | 2011-12-06 18:22:46 | [diff] [blame] | 2231 | const Extension* extension = extensions_.GetByID(lowercase_id); |
| 2232 | if (extension) |
| 2233 | return extension; |
[email protected] | 0c6da50 | 2009-08-14 22:32:39 | [diff] [blame] | 2234 | } |
| 2235 | if (include_disabled) { |
[email protected] | 84df833 | 2011-12-06 18:22:46 | [diff] [blame] | 2236 | const Extension* extension = disabled_extensions_.GetByID(lowercase_id); |
| 2237 | if (extension) |
| 2238 | return extension; |
[email protected] | ce5c450 | 2009-05-06 16:46:11 | [diff] [blame] | 2239 | } |
[email protected] | 8001df2 | 2011-04-28 19:59:47 | [diff] [blame] | 2240 | if (include_terminated) { |
[email protected] | 84df833 | 2011-12-06 18:22:46 | [diff] [blame] | 2241 | const Extension* extension = terminated_extensions_.GetByID(lowercase_id); |
| 2242 | if (extension) |
| 2243 | return extension; |
[email protected] | 8001df2 | 2011-04-28 19:59:47 | [diff] [blame] | 2244 | } |
[email protected] | ce5c450 | 2009-05-06 16:46:11 | [diff] [blame] | 2245 | return NULL; |
| 2246 | } |
| 2247 | |
[email protected] | bb7f4095 | 2011-01-13 00:21:20 | [diff] [blame] | 2248 | void ExtensionService::TrackTerminatedExtension(const Extension* extension) { |
[email protected] | 84df833 | 2011-12-06 18:22:46 | [diff] [blame] | 2249 | if (!terminated_extensions_.Contains(extension->id())) |
| 2250 | terminated_extensions_.Insert(make_scoped_refptr(extension)); |
[email protected] | fa2416f | 2011-05-03 08:41:20 | [diff] [blame] | 2251 | |
[email protected] | b3f7fe2 | 2011-11-11 19:27:56 | [diff] [blame] | 2252 | UnloadExtension(extension->id(), extension_misc::UNLOAD_REASON_TERMINATE); |
[email protected] | bb7f4095 | 2011-01-13 00:21:20 | [diff] [blame] | 2253 | } |
| 2254 | |
| 2255 | void ExtensionService::UntrackTerminatedExtension(const std::string& id) { |
[email protected] | fa2416f | 2011-05-03 08:41:20 | [diff] [blame] | 2256 | std::string lowercase_id = StringToLowerASCII(id); |
[email protected] | 84df833 | 2011-12-06 18:22:46 | [diff] [blame] | 2257 | terminated_extensions_.Remove(lowercase_id); |
[email protected] | bb7f4095 | 2011-01-13 00:21:20 | [diff] [blame] | 2258 | } |
| 2259 | |
[email protected] | 0dfe05c | 2011-02-23 23:03:36 | [diff] [blame] | 2260 | const Extension* ExtensionService::GetTerminatedExtension( |
[email protected] | 8001df2 | 2011-04-28 19:59:47 | [diff] [blame] | 2261 | const std::string& id) const { |
| 2262 | return GetExtensionByIdInternal(id, false, false, true); |
| 2263 | } |
| 2264 | |
| 2265 | const Extension* ExtensionService::GetInstalledExtension( |
| 2266 | const std::string& id) const { |
| 2267 | return GetExtensionByIdInternal(id, true, true, true); |
[email protected] | 0dfe05c | 2011-02-23 23:03:36 | [diff] [blame] | 2268 | } |
| 2269 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2270 | const Extension* ExtensionService::GetWebStoreApp() { |
[email protected] | d307199 | 2010-10-08 15:24:07 | [diff] [blame] | 2271 | return GetExtensionById(extension_misc::kWebStoreAppId, false); |
| 2272 | } |
| 2273 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2274 | bool ExtensionService::ExtensionBindingsAllowed(const GURL& url) { |
[email protected] | 615d88f | 2011-12-13 01:47:44 | [diff] [blame] | 2275 | // Allow bindings for all packaged extensions and component hosted apps. |
| 2276 | const Extension* extension = extensions_.GetExtensionOrAppByURL( |
| 2277 | ExtensionURLInfo(url)); |
| 2278 | return extension && (!extension->is_hosted_app() || |
| 2279 | extension->location() == Extension::COMPONENT); |
[email protected] | 6d2e60bd | 2010-06-03 22:37:39 | [diff] [blame] | 2280 | } |
| 2281 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2282 | const SkBitmap& ExtensionService::GetOmniboxIcon( |
[email protected] | b671760b | 2010-07-15 21:13:47 | [diff] [blame] | 2283 | const std::string& extension_id) { |
| 2284 | return omnibox_icon_manager_.GetIcon(extension_id); |
| 2285 | } |
| 2286 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2287 | const SkBitmap& ExtensionService::GetOmniboxPopupIcon( |
[email protected] | 29d0d4ac | 2010-09-08 21:10:31 | [diff] [blame] | 2288 | const std::string& extension_id) { |
| 2289 | return omnibox_popup_icon_manager_.GetIcon(extension_id); |
| 2290 | } |
| 2291 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2292 | void ExtensionService::OnExternalExtensionFileFound( |
[email protected] | 8ef78fd | 2010-08-19 17:14:32 | [diff] [blame] | 2293 | const std::string& id, |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 2294 | const Version* version, |
[email protected] | 8ef78fd | 2010-08-19 17:14:32 | [diff] [blame] | 2295 | const FilePath& path, |
[email protected] | 1bf73cc3 | 2011-10-26 22:38:31 | [diff] [blame] | 2296 | Extension::Location location, |
[email protected] | 47fc70c | 2011-12-06 07:29:51 | [diff] [blame] | 2297 | int creation_flags, |
| 2298 | bool mark_acknowledged) { |
[email protected] | ab22ba4 | 2011-01-14 16:36:38 | [diff] [blame] | 2299 | CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 2300 | CHECK(Extension::IdIsValid(id)); |
[email protected] | 79c833b5 | 2011-04-05 18:31:01 | [diff] [blame] | 2301 | if (extension_prefs_->IsExternalExtensionUninstalled(id)) |
[email protected] | 683d070 | 2010-12-06 16:25:57 | [diff] [blame] | 2302 | return; |
[email protected] | a8af9fdb | 2010-10-28 21:52:20 | [diff] [blame] | 2303 | |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 2304 | DCHECK(version); |
| 2305 | |
[email protected] | 7577a5c5 | 2009-07-30 06:21:58 | [diff] [blame] | 2306 | // Before even bothering to unpack, check and see if we already have this |
[email protected] | 4c96793 | 2009-07-31 01:15:49 | [diff] [blame] | 2307 | // version. This is important because these extensions are going to get |
[email protected] | 7577a5c5 | 2009-07-30 06:21:58 | [diff] [blame] | 2308 | // installed on every startup. |
[email protected] | 9adb969 | 2010-10-29 23:14:02 | [diff] [blame] | 2309 | const Extension* existing = GetExtensionById(id, true); |
[email protected] | 7577a5c5 | 2009-07-30 06:21:58 | [diff] [blame] | 2310 | if (existing) { |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 2311 | switch (existing->version()->CompareTo(*version)) { |
[email protected] | 7577a5c5 | 2009-07-30 06:21:58 | [diff] [blame] | 2312 | case -1: // existing version is older, we should upgrade |
| 2313 | break; |
| 2314 | case 0: // existing version is same, do nothing |
| 2315 | return; |
| 2316 | case 1: // existing version is newer, uh-oh |
| 2317 | LOG(WARNING) << "Found external version of extension " << id |
| 2318 | << "that is older than current version. Current version " |
| 2319 | << "is: " << existing->VersionString() << ". New version " |
[email protected] | 16d90004 | 2012-01-04 21:24:32 | [diff] [blame] | 2320 | << "is: " << version->GetString() |
| 2321 | << ". Keeping current version."; |
[email protected] | 7577a5c5 | 2009-07-30 06:21:58 | [diff] [blame] | 2322 | return; |
| 2323 | } |
| 2324 | } |
| 2325 | |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 2326 | pending_extension_manager()->AddFromExternalFile(id, location); |
[email protected] | 9c635f2 | 2010-12-02 09:36:36 | [diff] [blame] | 2327 | |
[email protected] | 14908b7 | 2011-04-20 06:54:36 | [diff] [blame] | 2328 | // no client (silent install) |
[email protected] | d8c8f25f | 2011-11-02 18:18:01 | [diff] [blame] | 2329 | scoped_refptr<CrxInstaller> installer(CrxInstaller::Create(this, NULL)); |
[email protected] | 6dfbbf8 | 2010-03-12 23:09:16 | [diff] [blame] | 2330 | installer->set_install_source(location); |
| 2331 | installer->set_expected_id(id); |
[email protected] | cb0e5031 | 2011-05-09 15:03:07 | [diff] [blame] | 2332 | installer->set_expected_version(*version); |
| 2333 | installer->set_install_cause(extension_misc::INSTALL_CAUSE_EXTERNAL_FILE); |
[email protected] | 1bf73cc3 | 2011-10-26 22:38:31 | [diff] [blame] | 2334 | installer->set_creation_flags(creation_flags); |
[email protected] | 6dfbbf8 | 2010-03-12 23:09:16 | [diff] [blame] | 2335 | installer->InstallCrx(path); |
[email protected] | 47fc70c | 2011-12-06 07:29:51 | [diff] [blame] | 2336 | |
| 2337 | // Depending on the source, a new external extension might not need a user |
| 2338 | // notification on installation. For such extensions, mark them acknowledged |
| 2339 | // now to suppress the notification. |
| 2340 | if (mark_acknowledged) |
| 2341 | AcknowledgeExternalExtension(id); |
[email protected] | 7577a5c5 | 2009-07-30 06:21:58 | [diff] [blame] | 2342 | } |
| 2343 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2344 | void ExtensionService::ReportExtensionLoadError( |
[email protected] | d11c8e9 | 2009-10-20 23:26:40 | [diff] [blame] | 2345 | const FilePath& extension_path, |
| 2346 | const std::string &error, |
[email protected] | d11c8e9 | 2009-10-20 23:26:40 | [diff] [blame] | 2347 | bool be_noisy) { |
[email protected] | d8c8f25f | 2011-11-02 18:18:01 | [diff] [blame] | 2348 | content::NotificationService::current()->Notify( |
| 2349 | chrome::NOTIFICATION_EXTENSION_LOAD_ERROR, |
| 2350 | content::Source<Profile>(profile_), |
| 2351 | content::Details<const std::string>(&error)); |
[email protected] | d11c8e9 | 2009-10-20 23:26:40 | [diff] [blame] | 2352 | |
[email protected] | 8a205c0 | 2011-02-04 20:41:33 | [diff] [blame] | 2353 | std::string path_str = UTF16ToUTF8(extension_path.LossyDisplayName()); |
[email protected] | fc67082 | 2011-12-17 09:33:49 | [diff] [blame] | 2354 | string16 message = ASCIIToUTF16(base::StringPrintf( |
[email protected] | 18d4b6c | 2010-09-21 03:21:04 | [diff] [blame] | 2355 | "Could not load extension from '%s'. %s", |
[email protected] | fc67082 | 2011-12-17 09:33:49 | [diff] [blame] | 2356 | path_str.c_str(), error.c_str())); |
[email protected] | d11c8e9 | 2009-10-20 23:26:40 | [diff] [blame] | 2357 | ExtensionErrorReporter::GetInstance()->ReportError(message, be_noisy); |
| 2358 | } |
| 2359 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2360 | void ExtensionService::DidCreateRenderViewForBackgroundPage( |
[email protected] | 406027c0 | 2010-09-27 08:03:18 | [diff] [blame] | 2361 | ExtensionHost* host) { |
| 2362 | OrphanedDevTools::iterator iter = |
[email protected] | 2d2f6cfc | 2011-05-06 21:09:33 | [diff] [blame] | 2363 | orphaned_dev_tools_.find(host->extension_id()); |
[email protected] | 406027c0 | 2010-09-27 08:03:18 | [diff] [blame] | 2364 | if (iter == orphaned_dev_tools_.end()) |
| 2365 | return; |
| 2366 | |
[email protected] | 0e12d7d | 2011-12-01 16:21:44 | [diff] [blame] | 2367 | DevToolsAgentHost* agent = DevToolsAgentHostRegistry::GetDevToolsAgentHost( |
| 2368 | host->render_view_host()); |
| 2369 | content::DevToolsManager::GetInstance()->AttachClientHost(iter->second, |
| 2370 | agent); |
[email protected] | 406027c0 | 2010-09-27 08:03:18 | [diff] [blame] | 2371 | orphaned_dev_tools_.erase(iter); |
| 2372 | } |
| 2373 | |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 2374 | void ExtensionService::Observe(int type, |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 2375 | const content::NotificationSource& source, |
| 2376 | const content::NotificationDetails& details) { |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 2377 | switch (type) { |
| 2378 | case chrome::NOTIFICATION_EXTENSION_PROCESS_TERMINATED: { |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 2379 | if (profile_ != |
| 2380 | content::Source<Profile>(source).ptr()->GetOriginalProfile()) { |
[email protected] | bc535ee5 | 2010-08-31 18:40:32 | [diff] [blame] | 2381 | break; |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 2382 | } |
[email protected] | a4ed628 | 2009-12-14 20:51:16 | [diff] [blame] | 2383 | |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 2384 | ExtensionHost* host = content::Details<ExtensionHost>(details).ptr(); |
[email protected] | f128af4 | 2010-08-05 18:05:26 | [diff] [blame] | 2385 | |
[email protected] | fa2416f | 2011-05-03 08:41:20 | [diff] [blame] | 2386 | // Mark the extension as terminated and Unload it. We want it to |
| 2387 | // be in a consistent state: either fully working or not loaded |
| 2388 | // at all, but never half-crashed. We do it in a PostTask so |
| 2389 | // that other handlers of this notification will still have |
| 2390 | // access to the Extension and ExtensionHost. |
[email protected] | 14908b7 | 2011-04-20 06:54:36 | [diff] [blame] | 2391 | MessageLoop::current()->PostTask( |
| 2392 | FROM_HERE, |
[email protected] | 53612e8 | 2011-10-18 18:00:36 | [diff] [blame] | 2393 | base::Bind( |
[email protected] | fa2416f | 2011-05-03 08:41:20 | [diff] [blame] | 2394 | &ExtensionService::TrackTerminatedExtension, |
[email protected] | d8c8f25f | 2011-11-02 18:18:01 | [diff] [blame] | 2395 | AsWeakPtr(), |
[email protected] | fa2416f | 2011-05-03 08:41:20 | [diff] [blame] | 2396 | host->extension())); |
[email protected] | 31f7726 | 2009-12-02 20:48:53 | [diff] [blame] | 2397 | break; |
| 2398 | } |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 2399 | case content::NOTIFICATION_RENDERER_PROCESS_CREATED: { |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 2400 | content::RenderProcessHost* process = |
| 2401 | content::Source<content::RenderProcessHost>(source).ptr(); |
[email protected] | fc30ef08 | 2011-08-18 04:07:19 | [diff] [blame] | 2402 | Profile* host_profile = |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 2403 | Profile::FromBrowserContext(process->GetBrowserContext()); |
[email protected] | fc30ef08 | 2011-08-18 04:07:19 | [diff] [blame] | 2404 | if (!profile_->IsSameProfile(host_profile->GetOriginalProfile())) |
| 2405 | break; |
| 2406 | |
[email protected] | 77a6970c | 2011-04-23 16:58:56 | [diff] [blame] | 2407 | // Valid extension function names, used to setup bindings in renderer. |
| 2408 | std::vector<std::string> function_names; |
| 2409 | ExtensionFunctionDispatcher::GetAllFunctionNames(&function_names); |
| 2410 | process->Send(new ExtensionMsg_SetFunctionNames(function_names)); |
[email protected] | 31f7726 | 2009-12-02 20:48:53 | [diff] [blame] | 2411 | |
[email protected] | 77a6970c | 2011-04-23 16:58:56 | [diff] [blame] | 2412 | // Scripting whitelist. This is modified by tests and must be communicated |
| 2413 | // to renderers. |
| 2414 | process->Send(new ExtensionMsg_SetScriptingWhitelist( |
| 2415 | *Extension::GetScriptingWhitelist())); |
| 2416 | |
| 2417 | // Loaded extensions. |
[email protected] | 9776e82e | 2011-11-15 02:17:53 | [diff] [blame] | 2418 | std::vector<ExtensionMsg_Loaded_Params> loaded_extensions; |
[email protected] | 84df833 | 2011-12-06 18:22:46 | [diff] [blame] | 2419 | for (ExtensionSet::const_iterator iter = extensions_.begin(); |
| 2420 | iter != extensions_.end(); ++iter) { |
[email protected] | 1964726 | 2011-12-16 09:57:49 | [diff] [blame] | 2421 | // Renderers don't need to know about themes. |
| 2422 | if (!(*iter)->is_theme()) |
| 2423 | loaded_extensions.push_back(ExtensionMsg_Loaded_Params(*iter)); |
[email protected] | 77a6970c | 2011-04-23 16:58:56 | [diff] [blame] | 2424 | } |
[email protected] | 9776e82e | 2011-11-15 02:17:53 | [diff] [blame] | 2425 | process->Send(new ExtensionMsg_Loaded(loaded_extensions)); |
[email protected] | 77a6970c | 2011-04-23 16:58:56 | [diff] [blame] | 2426 | break; |
| 2427 | } |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 2428 | case content::NOTIFICATION_RENDERER_PROCESS_TERMINATED: { |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 2429 | content::RenderProcessHost* process = |
| 2430 | content::Source<content::RenderProcessHost>(source).ptr(); |
[email protected] | fc30ef08 | 2011-08-18 04:07:19 | [diff] [blame] | 2431 | Profile* host_profile = |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 2432 | Profile::FromBrowserContext(process->GetBrowserContext()); |
[email protected] | fc30ef08 | 2011-08-18 04:07:19 | [diff] [blame] | 2433 | if (!profile_->IsSameProfile(host_profile->GetOriginalProfile())) |
| 2434 | break; |
| 2435 | |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 2436 | installed_app_hosts_.erase(process->GetID()); |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 2437 | |
[email protected] | 6bc04fd8 | 2011-12-04 02:29:35 | [diff] [blame] | 2438 | process_map_.RemoveAllFromProcess(process->GetID()); |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 2439 | BrowserThread::PostTask( |
| 2440 | BrowserThread::IO, FROM_HERE, |
| 2441 | base::Bind(&ExtensionInfoMap::UnregisterAllExtensionsInProcess, |
| 2442 | profile_->GetExtensionInfoMap(), |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 2443 | process->GetID())); |
[email protected] | da5683db | 2011-04-23 17:12:21 | [diff] [blame] | 2444 | break; |
| 2445 | } |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 2446 | case chrome::NOTIFICATION_PREF_CHANGED: { |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 2447 | std::string* pref_name = content::Details<std::string>(details).ptr(); |
[email protected] | 6c751e7 | 2010-11-23 10:11:10 | [diff] [blame] | 2448 | if (*pref_name == prefs::kExtensionInstallAllowList || |
| 2449 | *pref_name == prefs::kExtensionInstallDenyList) { |
| 2450 | CheckAdminBlacklist(); |
[email protected] | 6c751e7 | 2010-11-23 10:11:10 | [diff] [blame] | 2451 | } else { |
| 2452 | NOTREACHED() << "Unexpected preference name."; |
| 2453 | } |
[email protected] | aa96d3a | 2010-08-21 08:45:25 | [diff] [blame] | 2454 | break; |
| 2455 | } |
[email protected] | d9126802 | 2011-08-26 13:17:37 | [diff] [blame] | 2456 | case chrome::NOTIFICATION_IMPORT_FINISHED: { |
[email protected] | cf593af | 2011-12-30 05:44:39 | [diff] [blame] | 2457 | InitAfterImport(); |
[email protected] | d9126802 | 2011-08-26 13:17:37 | [diff] [blame] | 2458 | break; |
| 2459 | } |
[email protected] | aa96d3a | 2010-08-21 08:45:25 | [diff] [blame] | 2460 | |
[email protected] | 4814b51 | 2009-11-07 00:12:29 | [diff] [blame] | 2461 | default: |
| 2462 | NOTREACHED() << "Unexpected notification type."; |
| 2463 | } |
| 2464 | } |
| 2465 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2466 | bool ExtensionService::HasApps() const { |
[email protected] | ec5b50d | 2010-10-09 16:35:18 | [diff] [blame] | 2467 | return !GetAppIds().empty(); |
| 2468 | } |
[email protected] | 377011d | 2010-07-20 04:18:50 | [diff] [blame] | 2469 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2470 | ExtensionIdSet ExtensionService::GetAppIds() const { |
[email protected] | ec5b50d | 2010-10-09 16:35:18 | [diff] [blame] | 2471 | ExtensionIdSet result; |
[email protected] | 84df833 | 2011-12-06 18:22:46 | [diff] [blame] | 2472 | for (ExtensionSet::const_iterator it = extensions_.begin(); |
[email protected] | 377011d | 2010-07-20 04:18:50 | [diff] [blame] | 2473 | it != extensions_.end(); ++it) { |
[email protected] | ec5b50d | 2010-10-09 16:35:18 | [diff] [blame] | 2474 | if ((*it)->is_app() && (*it)->location() != Extension::COMPONENT) |
| 2475 | result.insert((*it)->id()); |
[email protected] | 377011d | 2010-07-20 04:18:50 | [diff] [blame] | 2476 | } |
| 2477 | |
[email protected] | ec5b50d | 2010-10-09 16:35:18 | [diff] [blame] | 2478 | return result; |
[email protected] | 377011d | 2010-07-20 04:18:50 | [diff] [blame] | 2479 | } |
[email protected] | d7e9a86 | 2010-11-03 21:57:49 | [diff] [blame] | 2480 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2481 | bool ExtensionService::IsBackgroundPageReady(const Extension* extension) { |
[email protected] | a03d4448f | 2012-01-10 23:25:28 | [diff] [blame] | 2482 | return (!extension->has_background_page() || |
[email protected] | d7e9a86 | 2010-11-03 21:57:49 | [diff] [blame] | 2483 | extension_runtime_data_[extension->id()].background_page_ready); |
| 2484 | } |
| 2485 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2486 | void ExtensionService::SetBackgroundPageReady(const Extension* extension) { |
[email protected] | a03d4448f | 2012-01-10 23:25:28 | [diff] [blame] | 2487 | DCHECK(extension->has_background_page()); |
[email protected] | d7e9a86 | 2010-11-03 21:57:49 | [diff] [blame] | 2488 | extension_runtime_data_[extension->id()].background_page_ready = true; |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 2489 | content::NotificationService::current()->Notify( |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 2490 | chrome::NOTIFICATION_EXTENSION_BACKGROUND_PAGE_READY, |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 2491 | content::Source<const Extension>(extension), |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 2492 | content::NotificationService::NoDetails()); |
[email protected] | d7e9a86 | 2010-11-03 21:57:49 | [diff] [blame] | 2493 | } |
| 2494 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2495 | bool ExtensionService::IsBeingUpgraded(const Extension* extension) { |
[email protected] | d7e9a86 | 2010-11-03 21:57:49 | [diff] [blame] | 2496 | return extension_runtime_data_[extension->id()].being_upgraded; |
| 2497 | } |
| 2498 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2499 | void ExtensionService::SetBeingUpgraded(const Extension* extension, |
[email protected] | d7e9a86 | 2010-11-03 21:57:49 | [diff] [blame] | 2500 | bool value) { |
| 2501 | extension_runtime_data_[extension->id()].being_upgraded = value; |
| 2502 | } |
[email protected] | 1bead071 | 2010-11-27 17:41:53 | [diff] [blame] | 2503 | |
[email protected] | 39a5b53 | 2011-10-22 01:47:07 | [diff] [blame] | 2504 | bool ExtensionService::HasUsedWebRequest(const Extension* extension) { |
| 2505 | return extension_runtime_data_[extension->id()].has_used_webrequest; |
| 2506 | } |
| 2507 | |
| 2508 | void ExtensionService::SetHasUsedWebRequest(const Extension* extension, |
| 2509 | bool value) { |
| 2510 | extension_runtime_data_[extension->id()].has_used_webrequest = value; |
| 2511 | } |
| 2512 | |
[email protected] | 45644f6 | 2011-11-23 00:58:23 | [diff] [blame] | 2513 | base::PropertyBag* ExtensionService::GetPropertyBag( |
| 2514 | const Extension* extension) { |
[email protected] | 1bead071 | 2010-11-27 17:41:53 | [diff] [blame] | 2515 | return &extension_runtime_data_[extension->id()].property_bag; |
| 2516 | } |
[email protected] | cebc3dc | 2011-04-18 17:15:00 | [diff] [blame] | 2517 | |
| 2518 | void 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 | |
| 2528 | void 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] | ed0ba00 | 2011-05-26 16:55:13 | [diff] [blame] | 2534 | void ExtensionService::UpdatePluginListWithNaClModules() { |
[email protected] | 300c0ea | 2011-07-15 23:04:33 | [diff] [blame] | 2535 | // 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] | 1e12702 | 2011-11-29 21:11:47 | [diff] [blame] | 2539 | 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] | 300c0ea | 2011-07-15 23:04:33 | [diff] [blame] | 2546 | |
[email protected] | 1e12702 | 2011-11-29 21:11:47 | [diff] [blame] | 2547 | 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] | 300c0ea | 2011-07-15 23:04:33 | [diff] [blame] | 2553 | |
[email protected] | 1e12702 | 2011-11-29 21:11:47 | [diff] [blame] | 2554 | PluginService::GetInstance()-> |
| 2555 | UnregisterInternalPlugin(pepper_info->path); |
[email protected] | 300c0ea | 2011-07-15 23:04:33 | [diff] [blame] | 2556 | |
[email protected] | 1e12702 | 2011-11-29 21:11:47 | [diff] [blame] | 2557 | webkit::WebPluginInfo info = pepper_info->ToWebPluginInfo(); |
[email protected] | 300c0ea | 2011-07-15 23:04:33 | [diff] [blame] | 2558 | |
[email protected] | 1e12702 | 2011-11-29 21:11:47 | [diff] [blame] | 2559 | 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] | 300c0ea | 2011-07-15 23:04:33 | [diff] [blame] | 2571 | } |
[email protected] | 1e12702 | 2011-11-29 21:11:47 | [diff] [blame] | 2572 | |
| 2573 | PluginService::GetInstance()->RefreshPlugins(); |
| 2574 | PluginService::GetInstance()->RegisterInternalPlugin(info); |
| 2575 | // This plugin has been modified, no need to check the rest of its |
| 2576 | // types, but continue checking other plugins. |
| 2577 | break; |
[email protected] | ed0ba00 | 2011-05-26 16:55:13 | [diff] [blame] | 2578 | } |
| 2579 | } |
[email protected] | ed0ba00 | 2011-05-26 16:55:13 | [diff] [blame] | 2580 | } |
| 2581 | |
[email protected] | cebc3dc | 2011-04-18 17:15:00 | [diff] [blame] | 2582 | ExtensionService::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] | 9de8328 | 2011-12-12 11:06:37 | [diff] [blame] | 2591 | |
| 2592 | void ExtensionService::StartInstallApplicationShortcut( |
| 2593 | const Extension* extension) { |
| 2594 | #if !defined(OS_MACOSX) |
| 2595 | const int kAppIconSize = 32; |
| 2596 | |
| 2597 | shortcut_info_.extension_id = extension->id(); |
| 2598 | shortcut_info_.url = GURL(extension->launch_web_url()); |
| 2599 | shortcut_info_.title = UTF8ToUTF16(extension->name()); |
| 2600 | shortcut_info_.description = UTF8ToUTF16(extension->description()); |
| 2601 | shortcut_info_.create_in_applications_menu = true; |
| 2602 | shortcut_info_.create_in_quick_launch_bar = true; |
| 2603 | shortcut_info_.create_on_desktop = true; |
| 2604 | |
| 2605 | // The icon will be resized to |max_size|. |
| 2606 | const gfx::Size max_size(kAppIconSize, kAppIconSize); |
| 2607 | |
| 2608 | // Look for an icon. If there is no icon at the ideal size, we will resize |
| 2609 | // whatever we can get. Making a large icon smaller is prefered to making a |
| 2610 | // small icon larger, so look for a larger icon first: |
| 2611 | ExtensionResource icon_resource = extension->GetIconResource( |
| 2612 | kAppIconSize, |
| 2613 | ExtensionIconSet::MATCH_BIGGER); |
| 2614 | |
| 2615 | // If no icon exists that is the desired size or larger, get the |
| 2616 | // largest icon available: |
| 2617 | if (icon_resource.empty()) { |
| 2618 | icon_resource = extension->GetIconResource( |
| 2619 | kAppIconSize, |
| 2620 | ExtensionIconSet::MATCH_SMALLER); |
| 2621 | } |
| 2622 | |
| 2623 | // icon_resource may still be empty at this point, in which case LoadImage |
| 2624 | // which call the OnImageLoaded callback with a NULL image and exit |
| 2625 | // immediately. |
| 2626 | tracker_.LoadImage(extension, |
| 2627 | icon_resource, |
| 2628 | max_size, |
| 2629 | ImageLoadingTracker::DONT_CACHE); |
| 2630 | #endif |
| 2631 | } |
| 2632 | |
| 2633 | void ExtensionService::OnImageLoaded(SkBitmap *image, |
| 2634 | const ExtensionResource &resource, |
| 2635 | int index) { |
| 2636 | // If the image failed to load (e.g. if the resource being loaded was empty) |
| 2637 | // use the standard application icon. |
| 2638 | if (!image || image->isNull()) |
| 2639 | image = ExtensionIconSource::LoadImageByResourceId(IDR_APP_DEFAULT_ICON); |
| 2640 | |
| 2641 | shortcut_info_.favicon = *image; |
| 2642 | web_app::CreateShortcut(profile_->GetPath(), shortcut_info_); |
| 2643 | } |
[email protected] | e1fae1c | 2011-12-13 22:17:17 | [diff] [blame] | 2644 | |
| 2645 | extensions::SocketController* ExtensionService::socket_controller() { |
| 2646 | // TODO(miket): Find a better place for SocketController to live. It needs |
| 2647 | // to be scoped such that it can be created and destroyed on the IO thread. |
| 2648 | // |
| 2649 | // To coexist with certain unit tests that don't have an IO thread message |
| 2650 | // loop available at ExtensionService shutdown, we lazy-initialize this |
| 2651 | // object so that those cases neither create nor destroy a SocketController. |
| 2652 | CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 2653 | if (!socket_controller_) { |
| 2654 | socket_controller_ = new extensions::SocketController(); |
| 2655 | } |
| 2656 | return socket_controller_; |
| 2657 | } |