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