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