[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 1 | // Copyright (c) 2011 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] | e5af875f | 2011-10-10 21:09:14 | [diff] [blame] | 11 | #include "base/callback.h" |
[email protected] | 62433d3 | 2011-10-12 22:33:12 | [diff] [blame] | 12 | #include "base/command_line.h" |
[email protected] | 6014d67 | 2008-12-05 00:38:25 | [diff] [blame] | 13 | #include "base/file_util.h" |
[email protected] | 005bab0 | 2011-10-07 18:36:00 | [diff] [blame] | 14 | #include "base/json/json_value_serializer.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] | cebc3dc | 2011-04-18 17:15:00 | [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] | 15730c4 | 2009-09-03 00:03:20 | [diff] [blame] | 29 | #include "chrome/browser/browser_process.h" |
[email protected] | dfba876 | 2011-09-02 12:49:54 | [diff] [blame] | 30 | #include "chrome/browser/chrome_plugin_service_filter.h" |
[email protected] | af9db5f | 2011-10-05 05:13:15 | [diff] [blame] | 31 | #include "chrome/browser/extensions/app_notification_manager.h" |
[email protected] | 18cc5a5 | 2011-04-15 16:03:38 | [diff] [blame] | 32 | #include "chrome/browser/extensions/apps_promo.h" |
[email protected] | e078590 | 2011-05-19 23:34:17 | [diff] [blame] | 33 | #include "chrome/browser/extensions/crx_installer.h" |
[email protected] | 49098f70 | 2011-10-13 03:47:18 | [diff] [blame] | 34 | #include "chrome/browser/extensions/default_apps_trial.h" |
[email protected] | 5cbe1e2 | 2010-01-30 01:18:56 | [diff] [blame] | 35 | #include "chrome/browser/extensions/extension_accessibility_api.h" |
[email protected] | 840b0db | 2009-11-20 03:00:38 | [diff] [blame] | 36 | #include "chrome/browser/extensions/extension_bookmarks_module.h" |
[email protected] | b68d5ed | 2009-04-16 02:41:28 | [diff] [blame] | 37 | #include "chrome/browser/extensions/extension_browser_event_router.h" |
[email protected] | 2c5e1e1 | 2010-06-10 13:14:44 | [diff] [blame] | 38 | #include "chrome/browser/extensions/extension_cookies_api.h" |
[email protected] | c10da4b0 | 2010-03-25 14:38:32 | [diff] [blame] | 39 | #include "chrome/browser/extensions/extension_data_deleter.h" |
[email protected] | 370e950 | 2011-09-14 19:31:44 | [diff] [blame] | 40 | #include "chrome/browser/extensions/extension_downloads_api.h" |
[email protected] | 14a000d | 2010-04-29 21:44:24 | [diff] [blame] | 41 | #include "chrome/browser/extensions/extension_error_reporter.h" |
[email protected] | e5af875f | 2011-10-10 21:09:14 | [diff] [blame] | 42 | #include "chrome/browser/extensions/extension_global_error.h" |
[email protected] | de768a83 | 2009-10-30 05:25:01 | [diff] [blame] | 43 | #include "chrome/browser/extensions/extension_history_api.h" |
[email protected] | b1748b1d8 | 2009-11-30 20:32:56 | [diff] [blame] | 44 | #include "chrome/browser/extensions/extension_host.h" |
[email protected] | 14da67b0 | 2011-08-02 05:49:13 | [diff] [blame] | 45 | #include "chrome/browser/extensions/extension_input_ime_api.h" |
[email protected] | 5fb88938 | 2011-06-03 00:29:20 | [diff] [blame] | 46 | #include "chrome/browser/extensions/extension_install_ui.h" |
[email protected] | 7596ce7 | 2010-08-30 05:10:46 | [diff] [blame] | 47 | #include "chrome/browser/extensions/extension_management_api.h" |
[email protected] | 118de789 | 2011-03-16 13:31:40 | [diff] [blame] | 48 | #include "chrome/browser/extensions/extension_preference_api.h" |
[email protected] | 4814b51 | 2009-11-07 00:12:29 | [diff] [blame] | 49 | #include "chrome/browser/extensions/extension_process_manager.h" |
[email protected] | 8a661f8 | 2010-10-19 21:47:11 | [diff] [blame] | 50 | #include "chrome/browser/extensions/extension_processes_api.h" |
[email protected] | 19eb8015 | 2011-02-26 00:28:43 | [diff] [blame] | 51 | #include "chrome/browser/extensions/extension_special_storage_policy.h" |
[email protected] | 90310d9 | 2011-04-17 07:35:04 | [diff] [blame] | 52 | #include "chrome/browser/extensions/extension_sync_data.h" |
[email protected] | 93fd78f4 | 2009-07-10 16:43:17 | [diff] [blame] | 53 | #include "chrome/browser/extensions/extension_updater.h" |
[email protected] | 8f9d4eb | 2011-02-05 01:39:10 | [diff] [blame] | 54 | #include "chrome/browser/extensions/extension_web_ui.h" |
[email protected] | 784688a6 | 2010-09-13 07:06:52 | [diff] [blame] | 55 | #include "chrome/browser/extensions/extension_webnavigation_api.h" |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 56 | #include "chrome/browser/extensions/external_extension_provider_impl.h" |
[email protected] | 42b79565 | 2011-02-22 23:32:38 | [diff] [blame] | 57 | #include "chrome/browser/extensions/external_extension_provider_interface.h" |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 58 | #include "chrome/browser/extensions/pending_extension_manager.h" |
[email protected] | 56ad379 | 2010-05-28 17:45:33 | [diff] [blame] | 59 | #include "chrome/browser/net/chrome_url_request_context.h" |
[email protected] | 37858e5 | 2010-08-26 00:22:02 | [diff] [blame] | 60 | #include "chrome/browser/prefs/pref_service.h" |
[email protected] | 8ecad5e | 2010-12-02 21:18:33 | [diff] [blame] | 61 | #include "chrome/browser/profiles/profile.h" |
[email protected] | 8e5c89a | 2011-06-07 18:13:33 | [diff] [blame] | 62 | #include "chrome/browser/search_engines/template_url_service.h" |
| 63 | #include "chrome/browser/search_engines/template_url_service_factory.h" |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 64 | #include "chrome/browser/sync/api/sync_change.h" |
[email protected] | 1828037 | 2011-03-22 18:05:22 | [diff] [blame] | 65 | #include "chrome/browser/themes/theme_service.h" |
[email protected] | a0ea76c | 2011-03-23 17:36:42 | [diff] [blame] | 66 | #include "chrome/browser/themes/theme_service_factory.h" |
[email protected] | e5af875f | 2011-10-10 21:09:14 | [diff] [blame] | 67 | #include "chrome/browser/ui/browser.h" |
[email protected] | 62433d3 | 2011-10-12 22:33:12 | [diff] [blame] | 68 | #include "chrome/browser/ui/browser_list.h" |
[email protected] | e5af875f | 2011-10-10 21:09:14 | [diff] [blame] | 69 | #include "chrome/browser/ui/global_error_service.h" |
| 70 | #include "chrome/browser/ui/global_error_service_factory.h" |
[email protected] | c8d407e | 2011-04-28 21:27:17 | [diff] [blame] | 71 | #include "chrome/browser/ui/webui/chrome_url_data_manager.h" |
| 72 | #include "chrome/browser/ui/webui/favicon_source.h" |
[email protected] | 7c5c6f3a | 2011-04-28 19:56:49 | [diff] [blame] | 73 | #include "chrome/browser/ui/webui/ntp/shown_sections_handler.h" |
[email protected] | aab98a5 | 2009-12-02 03:22:35 | [diff] [blame] | 74 | #include "chrome/common/child_process_logging.h" |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 75 | #include "chrome/common/chrome_notification_types.h" |
[email protected] | cebc3dc | 2011-04-18 17:15:00 | [diff] [blame] | 76 | #include "chrome/common/chrome_paths.h" |
[email protected] | e2eb4311 | 2009-05-29 21:19:54 | [diff] [blame] | 77 | #include "chrome/common/chrome_switches.h" |
[email protected] | 5b1a0e2 | 2009-05-26 19:00:58 | [diff] [blame] | 78 | #include "chrome/common/extensions/extension.h" |
[email protected] | d7b36dc | 2009-10-29 21:47:40 | [diff] [blame] | 79 | #include "chrome/common/extensions/extension_constants.h" |
[email protected] | 05c8218 | 2010-06-24 17:49:08 | [diff] [blame] | 80 | #include "chrome/common/extensions/extension_error_utils.h" |
[email protected] | 7c927b6 | 2010-02-24 09:54:13 | [diff] [blame] | 81 | #include "chrome/common/extensions/extension_file_util.h" |
[email protected] | c6d474f8 | 2009-12-16 21:11:06 | [diff] [blame] | 82 | #include "chrome/common/extensions/extension_l10n_util.h" |
[email protected] | 77a6970c | 2011-04-23 16:58:56 | [diff] [blame] | 83 | #include "chrome/common/extensions/extension_messages.h" |
[email protected] | a315ba9 | 2010-11-16 14:12:21 | [diff] [blame] | 84 | #include "chrome/common/extensions/extension_resource.h" |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 85 | #include "chrome/common/pref_names.h" |
[email protected] | a5720987 | 2009-05-04 22:53:14 | [diff] [blame] | 86 | #include "chrome/common/url_constants.h" |
[email protected] | 5f945a0e | 2011-03-01 17:47:53 | [diff] [blame] | 87 | #include "content/browser/browser_thread.h" |
[email protected] | b46442d7e | 2011-06-29 02:16:06 | [diff] [blame] | 88 | #include "content/browser/debugger/devtools_manager.h" |
[email protected] | 2de30759 | 2011-04-05 21:16:58 | [diff] [blame] | 89 | #include "content/browser/plugin_process_host.h" |
| 90 | #include "content/browser/plugin_service.h" |
[email protected] | 77a6970c | 2011-04-23 16:58:56 | [diff] [blame] | 91 | #include "content/browser/renderer_host/render_process_host.h" |
[email protected] | 333b1de | 2011-09-12 18:28:50 | [diff] [blame] | 92 | #include "content/browser/user_metrics.h" |
[email protected] | b3841c50 | 2011-03-09 01:21:31 | [diff] [blame] | 93 | #include "content/common/notification_service.h" |
[email protected] | cebc3dc | 2011-04-18 17:15:00 | [diff] [blame] | 94 | #include "content/common/pepper_plugin_registry.h" |
[email protected] | 0d6e9bd | 2011-10-18 04:29:16 | [diff] [blame^] | 95 | #include "content/public/browser/notification_types.h" |
[email protected] | c10da4b0 | 2010-03-25 14:38:32 | [diff] [blame] | 96 | #include "googleurl/src/gurl.h" |
[email protected] | 1debbbb6 | 2010-10-06 17:23:44 | [diff] [blame] | 97 | #include "net/base/registry_controlled_domain.h" |
[email protected] | 24b538a | 2010-02-27 01:22:44 | [diff] [blame] | 98 | #include "webkit/database/database_tracker.h" |
| 99 | #include "webkit/database/database_util.h" |
[email protected] | 2de30759 | 2011-04-05 21:16:58 | [diff] [blame] | 100 | #include "webkit/plugins/npapi/plugin_list.h" |
[email protected] | c6463165 | 2009-04-29 22:24:31 | [diff] [blame] | 101 | |
[email protected] | eed367e | 2011-04-12 03:43:31 | [diff] [blame] | 102 | #if defined(OS_CHROMEOS) |
[email protected] | 14da67b0 | 2011-08-02 05:49:13 | [diff] [blame] | 103 | #include "chrome/browser/chromeos/cros/cros_library.h" |
[email protected] | eed367e | 2011-04-12 03:43:31 | [diff] [blame] | 104 | #include "chrome/browser/chromeos/extensions/file_browser_event_router.h" |
[email protected] | be5bd574 | 2011-07-14 07:21:01 | [diff] [blame] | 105 | #include "chrome/browser/chromeos/extensions/input_method_event_router.h" |
[email protected] | ce980204 | 2011-05-27 10:11:40 | [diff] [blame] | 106 | #include "chrome/browser/chromeos/extensions/media_player_event_router.h" |
[email protected] | 14da67b0 | 2011-08-02 05:49:13 | [diff] [blame] | 107 | #include "chrome/browser/chromeos/input_method/input_method_manager.h" |
| 108 | #include "chrome/browser/extensions/extension_input_ime_api.h" |
[email protected] | b777b33 | 2011-04-16 04:01:08 | [diff] [blame] | 109 | #include "webkit/fileapi/file_system_context.h" |
| 110 | #include "webkit/fileapi/file_system_mount_point_provider.h" |
| 111 | #include "webkit/fileapi/file_system_path_manager.h" |
[email protected] | eed367e | 2011-04-12 03:43:31 | [diff] [blame] | 112 | #endif |
| 113 | |
[email protected] | 27072cad | 2011-05-09 19:46:40 | [diff] [blame] | 114 | #if defined(OS_CHROMEOS) && defined(TOUCH_UI) |
| 115 | #include "chrome/browser/extensions/extension_input_ui_api.h" |
| 116 | #endif |
| 117 | |
[email protected] | 5ef47ec | 2010-01-28 05:58:05 | [diff] [blame] | 118 | using base::Time; |
| 119 | |
[email protected] | c6d474f8 | 2009-12-16 21:11:06 | [diff] [blame] | 120 | namespace errors = extension_manifest_errors; |
| 121 | |
[email protected] | b6ab96d | 2009-08-20 18:58:19 | [diff] [blame] | 122 | namespace { |
| 123 | |
[email protected] | 29d0d4ac | 2010-09-08 21:10:31 | [diff] [blame] | 124 | #if defined(OS_LINUX) |
| 125 | static const int kOmniboxIconPaddingLeft = 2; |
| 126 | static const int kOmniboxIconPaddingRight = 2; |
| 127 | #elif defined(OS_MACOSX) |
| 128 | static const int kOmniboxIconPaddingLeft = 0; |
| 129 | static const int kOmniboxIconPaddingRight = 2; |
| 130 | #else |
| 131 | static const int kOmniboxIconPaddingLeft = 0; |
| 132 | static const int kOmniboxIconPaddingRight = 0; |
| 133 | #endif |
| 134 | |
[email protected] | 300c0ea | 2011-07-15 23:04:33 | [diff] [blame] | 135 | const char* kNaClPluginMimeType = "application/x-nacl"; |
| 136 | |
[email protected] | a315ba9 | 2010-11-16 14:12:21 | [diff] [blame] | 137 | // The following enumeration is used in histograms matching |
| 138 | // Extensions.ManifestReload* . Values may be added, as long |
| 139 | // as existing values are not changed. |
| 140 | enum ManifestReloadReason { |
| 141 | NOT_NEEDED = 0, // Reload not needed. |
| 142 | UNPACKED_DIR, // Unpacked directory |
| 143 | NEEDS_RELOCALIZATION, // The local has changed since we read this extension. |
| 144 | NUM_MANIFEST_RELOAD_REASONS |
| 145 | }; |
[email protected] | 2111b1a | 2010-03-12 18:12:44 | [diff] [blame] | 146 | |
[email protected] | a315ba9 | 2010-11-16 14:12:21 | [diff] [blame] | 147 | ManifestReloadReason ShouldReloadExtensionManifest(const ExtensionInfo& info) { |
| 148 | // Always reload manifests of unpacked extensions, because they can change |
| 149 | // on disk independent of the manifest in our prefs. |
| 150 | if (info.extension_location == Extension::LOAD) |
| 151 | return UNPACKED_DIR; |
| 152 | |
| 153 | // Reload the manifest if it needs to be relocalized. |
| 154 | if (extension_l10n_util::ShouldRelocalizeManifest(info)) |
| 155 | return NEEDS_RELOCALIZATION; |
| 156 | |
| 157 | return NOT_NEEDED; |
[email protected] | 2111b1a | 2010-03-12 18:12:44 | [diff] [blame] | 158 | } |
| 159 | |
[email protected] | 2de30759 | 2011-04-05 21:16:58 | [diff] [blame] | 160 | static void ForceShutdownPlugin(const FilePath& plugin_path) { |
| 161 | PluginProcessHost* plugin = |
| 162 | PluginService::GetInstance()->FindNpapiPluginProcess(plugin_path); |
| 163 | if (plugin) |
| 164 | plugin->ForceShutdown(); |
| 165 | } |
| 166 | |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 167 | static bool IsSyncableExtension(const Extension& extension) { |
| 168 | return extension.GetSyncType() == Extension::SYNC_TYPE_EXTENSION; |
| 169 | } |
| 170 | |
| 171 | static bool IsSyncableApp(const Extension& extension) { |
| 172 | return extension.GetSyncType() == Extension::SYNC_TYPE_APP; |
| 173 | } |
| 174 | |
[email protected] | 5fb88938 | 2011-06-03 00:29:20 | [diff] [blame] | 175 | // Manages an ExtensionInstallUI for a particular extension. |
| 176 | class SimpleExtensionLoadPrompt : public ExtensionInstallUI::Delegate { |
| 177 | public: |
| 178 | SimpleExtensionLoadPrompt(Profile* profile, |
| 179 | base::WeakPtr<ExtensionService> extension_service, |
| 180 | const Extension* extension); |
| 181 | ~SimpleExtensionLoadPrompt(); |
| 182 | |
| 183 | void ShowPrompt(); |
| 184 | |
| 185 | // ExtensionInstallUI::Delegate |
| 186 | virtual void InstallUIProceed(); |
[email protected] | d828fac | 2011-06-28 05:43:04 | [diff] [blame] | 187 | virtual void InstallUIAbort(bool user_initiated); |
[email protected] | 5fb88938 | 2011-06-03 00:29:20 | [diff] [blame] | 188 | |
| 189 | private: |
| 190 | base::WeakPtr<ExtensionService> extension_service_; |
| 191 | scoped_ptr<ExtensionInstallUI> install_ui_; |
| 192 | scoped_refptr<const Extension> extension_; |
| 193 | }; |
| 194 | |
| 195 | SimpleExtensionLoadPrompt::SimpleExtensionLoadPrompt( |
| 196 | Profile* profile, |
| 197 | base::WeakPtr<ExtensionService> extension_service, |
| 198 | const Extension* extension) |
| 199 | : extension_service_(extension_service), |
| 200 | install_ui_(new ExtensionInstallUI(profile)), |
| 201 | extension_(extension) { |
| 202 | } |
| 203 | |
| 204 | SimpleExtensionLoadPrompt::~SimpleExtensionLoadPrompt() { |
| 205 | } |
| 206 | |
| 207 | void SimpleExtensionLoadPrompt::ShowPrompt() { |
| 208 | install_ui_->ConfirmInstall(this, extension_); |
| 209 | } |
| 210 | |
| 211 | void SimpleExtensionLoadPrompt::InstallUIProceed() { |
| 212 | if (extension_service_.get()) |
[email protected] | 8266d66 | 2011-07-12 21:53:26 | [diff] [blame] | 213 | extension_service_->OnExtensionInstalled( |
[email protected] | f1b6665 | 2011-08-25 23:30:58 | [diff] [blame] | 214 | extension_, false, -1); // Not from web store. |
[email protected] | 5fb88938 | 2011-06-03 00:29:20 | [diff] [blame] | 215 | delete this; |
| 216 | } |
| 217 | |
[email protected] | d828fac | 2011-06-28 05:43:04 | [diff] [blame] | 218 | void SimpleExtensionLoadPrompt::InstallUIAbort(bool user_initiated) { |
[email protected] | 5fb88938 | 2011-06-03 00:29:20 | [diff] [blame] | 219 | delete this; |
| 220 | } |
| 221 | |
[email protected] | c6d474f8 | 2009-12-16 21:11:06 | [diff] [blame] | 222 | } // namespace |
[email protected] | b6ab96d | 2009-08-20 18:58:19 | [diff] [blame] | 223 | |
[email protected] | ad63a79 | 2011-06-16 06:41:11 | [diff] [blame] | 224 | bool ExtensionService::ComponentExtensionInfo::Equals( |
| 225 | const ComponentExtensionInfo& other) const { |
| 226 | return other.manifest == manifest && other.root_directory == root_directory; |
| 227 | } |
| 228 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 229 | ExtensionService::ExtensionRuntimeData::ExtensionRuntimeData() |
[email protected] | d7e9a86 | 2010-11-03 21:57:49 | [diff] [blame] | 230 | : background_page_ready(false), |
| 231 | being_upgraded(false) { |
| 232 | } |
| 233 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 234 | ExtensionService::ExtensionRuntimeData::~ExtensionRuntimeData() { |
[email protected] | d7e9a86 | 2010-11-03 21:57:49 | [diff] [blame] | 235 | } |
| 236 | |
[email protected] | cebc3dc | 2011-04-18 17:15:00 | [diff] [blame] | 237 | ExtensionService::NaClModuleInfo::NaClModuleInfo() { |
| 238 | } |
| 239 | |
| 240 | ExtensionService::NaClModuleInfo::~NaClModuleInfo() { |
| 241 | } |
| 242 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 243 | // ExtensionService. |
[email protected] | 6014d67 | 2008-12-05 00:38:25 | [diff] [blame] | 244 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 245 | const char* ExtensionService::kInstallDirectoryName = "Extensions"; |
[email protected] | b7f853e28 | 2011-08-10 09:24:20 | [diff] [blame] | 246 | const char* ExtensionService::kSettingsDirectoryName = "Extension Settings"; |
[email protected] | 494c06e | 2009-07-25 01:06:42 | [diff] [blame] | 247 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 248 | // Implements IO for the ExtensionService. |
[email protected] | 7a4c685 | 2010-09-16 03:44:22 | [diff] [blame] | 249 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 250 | class ExtensionServiceBackend |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 251 | : public base::RefCountedThreadSafe<ExtensionServiceBackend> { |
[email protected] | 7a4c685 | 2010-09-16 03:44:22 | [diff] [blame] | 252 | public: |
[email protected] | 1f830eb | 2010-09-28 08:25:14 | [diff] [blame] | 253 | // |install_directory| is a path where to look for extensions to load. |
[email protected] | 14908b7 | 2011-04-20 06:54:36 | [diff] [blame] | 254 | ExtensionServiceBackend( |
| 255 | base::WeakPtr<ExtensionService> frontend, |
| 256 | const FilePath& install_directory); |
[email protected] | 7a4c685 | 2010-09-16 03:44:22 | [diff] [blame] | 257 | |
| 258 | // Loads a single extension from |path| where |path| is the top directory of |
[email protected] | e49002a | 2011-07-13 03:40:44 | [diff] [blame] | 259 | // a specific extension where its manifest file lives. If |prompt_for_plugins| |
| 260 | // is true and the extension contains plugins, we prompt the user before |
| 261 | // loading. |
[email protected] | 7a4c685 | 2010-09-16 03:44:22 | [diff] [blame] | 262 | // Errors are reported through ExtensionErrorReporter. On success, |
[email protected] | 49cd157 | 2011-02-08 21:38:45 | [diff] [blame] | 263 | // AddExtension() is called. |
[email protected] | 7a4c685 | 2010-09-16 03:44:22 | [diff] [blame] | 264 | // TODO(erikkay): It might be useful to be able to load a packed extension |
| 265 | // (presumably into memory) without installing it. |
[email protected] | e49002a | 2011-07-13 03:40:44 | [diff] [blame] | 266 | void LoadSingleExtension(const FilePath &path, bool prompt_for_plugins); |
[email protected] | 7a4c685 | 2010-09-16 03:44:22 | [diff] [blame] | 267 | |
[email protected] | 7a4c685 | 2010-09-16 03:44:22 | [diff] [blame] | 268 | private: |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 269 | friend class base::RefCountedThreadSafe<ExtensionServiceBackend>; |
[email protected] | 7a4c685 | 2010-09-16 03:44:22 | [diff] [blame] | 270 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 271 | virtual ~ExtensionServiceBackend(); |
[email protected] | 7a4c685 | 2010-09-16 03:44:22 | [diff] [blame] | 272 | |
[email protected] | d10f460 | 2011-06-16 15:44:50 | [diff] [blame] | 273 | // LoadSingleExtension needs to check the file access preference, which needs |
| 274 | // to happen back on the UI thread, so it posts CheckExtensionFileAccess on |
| 275 | // the UI thread. In turn, once that gets the pref, it goes back to the |
| 276 | // file thread with LoadSingleExtensionWithFileAccess. |
[email protected] | e49002a | 2011-07-13 03:40:44 | [diff] [blame] | 277 | void CheckExtensionFileAccess(const FilePath& extension_path, |
| 278 | bool prompt_for_plugins); |
[email protected] | d10f460 | 2011-06-16 15:44:50 | [diff] [blame] | 279 | void LoadSingleExtensionWithFileAccess( |
[email protected] | e49002a | 2011-07-13 03:40:44 | [diff] [blame] | 280 | const FilePath &path, bool allow_file_access, bool prompt_for_plugins); |
[email protected] | d10f460 | 2011-06-16 15:44:50 | [diff] [blame] | 281 | |
[email protected] | 7a4c685 | 2010-09-16 03:44:22 | [diff] [blame] | 282 | // Notify the frontend that there was an error loading an extension. |
| 283 | void ReportExtensionLoadError(const FilePath& extension_path, |
| 284 | const std::string& error); |
| 285 | |
[email protected] | 14908b7 | 2011-04-20 06:54:36 | [diff] [blame] | 286 | // Notify the frontend that an extension was installed. |
[email protected] | e49002a | 2011-07-13 03:40:44 | [diff] [blame] | 287 | void OnLoadSingleExtension(const scoped_refptr<const Extension>& extension, |
| 288 | bool prompt_for_plugins); |
[email protected] | 14908b7 | 2011-04-20 06:54:36 | [diff] [blame] | 289 | |
| 290 | base::WeakPtr<ExtensionService> frontend_; |
[email protected] | 7a4c685 | 2010-09-16 03:44:22 | [diff] [blame] | 291 | |
| 292 | // The top-level extensions directory being installed to. |
| 293 | FilePath install_directory_; |
| 294 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 295 | DISALLOW_COPY_AND_ASSIGN(ExtensionServiceBackend); |
[email protected] | 7a4c685 | 2010-09-16 03:44:22 | [diff] [blame] | 296 | }; |
| 297 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 298 | ExtensionServiceBackend::ExtensionServiceBackend( |
[email protected] | 14908b7 | 2011-04-20 06:54:36 | [diff] [blame] | 299 | base::WeakPtr<ExtensionService> frontend, |
[email protected] | aebe23a3 | 2010-12-10 22:15:48 | [diff] [blame] | 300 | const FilePath& install_directory) |
[email protected] | 14908b7 | 2011-04-20 06:54:36 | [diff] [blame] | 301 | : frontend_(frontend), |
| 302 | install_directory_(install_directory) { |
| 303 | CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
[email protected] | 7a4c685 | 2010-09-16 03:44:22 | [diff] [blame] | 304 | } |
| 305 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 306 | ExtensionServiceBackend::~ExtensionServiceBackend() { |
[email protected] | 14908b7 | 2011-04-20 06:54:36 | [diff] [blame] | 307 | CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || |
| 308 | BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
[email protected] | 7a4c685 | 2010-09-16 03:44:22 | [diff] [blame] | 309 | } |
| 310 | |
[email protected] | e49002a | 2011-07-13 03:40:44 | [diff] [blame] | 311 | void ExtensionServiceBackend::LoadSingleExtension(const FilePath& path_in, |
| 312 | bool prompt_for_plugins) { |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 313 | CHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
[email protected] | a8af9fdb | 2010-10-28 21:52:20 | [diff] [blame] | 314 | |
[email protected] | 7a4c685 | 2010-09-16 03:44:22 | [diff] [blame] | 315 | FilePath extension_path = path_in; |
| 316 | file_util::AbsolutePath(&extension_path); |
| 317 | |
[email protected] | e49002a | 2011-07-13 03:40:44 | [diff] [blame] | 318 | BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
[email protected] | 704d77e | 2011-10-17 18:05:29 | [diff] [blame] | 319 | NewRunnableMethod(this, |
| 320 | &ExtensionServiceBackend::CheckExtensionFileAccess, |
| 321 | extension_path, prompt_for_plugins)); |
[email protected] | d10f460 | 2011-06-16 15:44:50 | [diff] [blame] | 322 | } |
| 323 | |
| 324 | void ExtensionServiceBackend::CheckExtensionFileAccess( |
[email protected] | e49002a | 2011-07-13 03:40:44 | [diff] [blame] | 325 | const FilePath& extension_path, bool prompt_for_plugins) { |
[email protected] | d10f460 | 2011-06-16 15:44:50 | [diff] [blame] | 326 | CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 327 | std::string id = Extension::GenerateIdForPath(extension_path); |
[email protected] | cdfca970 | 2011-08-08 16:07:01 | [diff] [blame] | 328 | // Unpacked extensions default to allowing file access, but if that has been |
| 329 | // overridden, don't reset the value. |
| 330 | bool allow_file_access = |
| 331 | Extension::ShouldAlwaysAllowFileAccess(Extension::LOAD); |
| 332 | if (frontend_->extension_prefs()->HasAllowFileAccessSetting(id)) |
| 333 | allow_file_access = frontend_->extension_prefs()->AllowFileAccess(id); |
[email protected] | d10f460 | 2011-06-16 15:44:50 | [diff] [blame] | 334 | |
[email protected] | e49002a | 2011-07-13 03:40:44 | [diff] [blame] | 335 | BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
[email protected] | 704d77e | 2011-10-17 18:05:29 | [diff] [blame] | 336 | NewRunnableMethod( |
| 337 | this, |
[email protected] | e49002a | 2011-07-13 03:40:44 | [diff] [blame] | 338 | &ExtensionServiceBackend::LoadSingleExtensionWithFileAccess, |
[email protected] | 704d77e | 2011-10-17 18:05:29 | [diff] [blame] | 339 | extension_path, allow_file_access, prompt_for_plugins)); |
[email protected] | d10f460 | 2011-06-16 15:44:50 | [diff] [blame] | 340 | } |
| 341 | |
[email protected] | d10f460 | 2011-06-16 15:44:50 | [diff] [blame] | 342 | void ExtensionServiceBackend::LoadSingleExtensionWithFileAccess( |
[email protected] | e49002a | 2011-07-13 03:40:44 | [diff] [blame] | 343 | const FilePath& extension_path, |
| 344 | bool allow_file_access, |
| 345 | bool prompt_for_plugins) { |
[email protected] | d10f460 | 2011-06-16 15:44:50 | [diff] [blame] | 346 | CHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 347 | int flags = allow_file_access ? |
[email protected] | 3aff9ad | 2011-04-01 20:26:48 | [diff] [blame] | 348 | Extension::ALLOW_FILE_ACCESS : Extension::NO_FLAGS; |
[email protected] | 83048a2 | 2011-03-29 00:14:13 | [diff] [blame] | 349 | if (Extension::ShouldDoStrictErrorChecking(Extension::LOAD)) |
| 350 | flags |= Extension::STRICT_ERROR_CHECKS; |
[email protected] | 7a4c685 | 2010-09-16 03:44:22 | [diff] [blame] | 351 | std::string error; |
[email protected] | ad8e04a | 2010-11-01 04:16:27 | [diff] [blame] | 352 | scoped_refptr<const Extension> extension(extension_file_util::LoadExtension( |
[email protected] | 7a4c685 | 2010-09-16 03:44:22 | [diff] [blame] | 353 | extension_path, |
[email protected] | 9288808 | 2010-10-18 19:24:57 | [diff] [blame] | 354 | Extension::LOAD, |
[email protected] | 83048a2 | 2011-03-29 00:14:13 | [diff] [blame] | 355 | flags, |
[email protected] | ad8e04a | 2010-11-01 04:16:27 | [diff] [blame] | 356 | &error)); |
[email protected] | 7a4c685 | 2010-09-16 03:44:22 | [diff] [blame] | 357 | |
| 358 | if (!extension) { |
[email protected] | e49002a | 2011-07-13 03:40:44 | [diff] [blame] | 359 | BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
[email protected] | 704d77e | 2011-10-17 18:05:29 | [diff] [blame] | 360 | NewRunnableMethod( |
[email protected] | 8a4fd81b | 2011-10-17 17:27:31 | [diff] [blame] | 361 | this, |
[email protected] | 704d77e | 2011-10-17 18:05:29 | [diff] [blame] | 362 | &ExtensionServiceBackend::ReportExtensionLoadError, |
[email protected] | e49002a | 2011-07-13 03:40:44 | [diff] [blame] | 363 | extension_path, error)); |
[email protected] | 7a4c685 | 2010-09-16 03:44:22 | [diff] [blame] | 364 | return; |
| 365 | } |
| 366 | |
[email protected] | 7a4c685 | 2010-09-16 03:44:22 | [diff] [blame] | 367 | // Report this as an installed extension so that it gets remembered in the |
| 368 | // prefs. |
[email protected] | e49002a | 2011-07-13 03:40:44 | [diff] [blame] | 369 | BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
[email protected] | 704d77e | 2011-10-17 18:05:29 | [diff] [blame] | 370 | NewRunnableMethod( |
| 371 | this, |
[email protected] | e49002a | 2011-07-13 03:40:44 | [diff] [blame] | 372 | &ExtensionServiceBackend::OnLoadSingleExtension, |
[email protected] | 704d77e | 2011-10-17 18:05:29 | [diff] [blame] | 373 | extension, prompt_for_plugins)); |
[email protected] | 7a4c685 | 2010-09-16 03:44:22 | [diff] [blame] | 374 | } |
| 375 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 376 | void ExtensionServiceBackend::ReportExtensionLoadError( |
[email protected] | 7a4c685 | 2010-09-16 03:44:22 | [diff] [blame] | 377 | const FilePath& extension_path, const std::string &error) { |
[email protected] | 14908b7 | 2011-04-20 06:54:36 | [diff] [blame] | 378 | CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 379 | if (frontend_.get()) |
| 380 | frontend_->ReportExtensionLoadError( |
[email protected] | 655b2b1a | 2011-10-13 17:13:06 | [diff] [blame] | 381 | extension_path, error, true /* alert_on_error */); |
[email protected] | 14908b7 | 2011-04-20 06:54:36 | [diff] [blame] | 382 | } |
| 383 | |
[email protected] | 5fb88938 | 2011-06-03 00:29:20 | [diff] [blame] | 384 | void ExtensionServiceBackend::OnLoadSingleExtension( |
[email protected] | e49002a | 2011-07-13 03:40:44 | [diff] [blame] | 385 | const scoped_refptr<const Extension>& extension, bool prompt_for_plugins) { |
[email protected] | 14908b7 | 2011-04-20 06:54:36 | [diff] [blame] | 386 | CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 387 | if (frontend_.get()) |
[email protected] | e49002a | 2011-07-13 03:40:44 | [diff] [blame] | 388 | frontend_->OnLoadSingleExtension(extension, prompt_for_plugins); |
[email protected] | 7a4c685 | 2010-09-16 03:44:22 | [diff] [blame] | 389 | } |
| 390 | |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 391 | void ExtensionService::CheckExternalUninstall(const std::string& id) { |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 392 | CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
[email protected] | a8af9fdb | 2010-10-28 21:52:20 | [diff] [blame] | 393 | |
[email protected] | 7a4c685 | 2010-09-16 03:44:22 | [diff] [blame] | 394 | // Check if the providers know about this extension. |
[email protected] | 0a60a2e | 2010-10-25 16:15:21 | [diff] [blame] | 395 | ProviderCollection::const_iterator i; |
| 396 | for (i = external_extension_providers_.begin(); |
| 397 | i != external_extension_providers_.end(); ++i) { |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 398 | DCHECK(i->get()->IsReady()); |
[email protected] | 0a60a2e | 2010-10-25 16:15:21 | [diff] [blame] | 399 | if (i->get()->HasExtension(id)) |
| 400 | return; // Yup, known extension, don't uninstall. |
[email protected] | 7a4c685 | 2010-09-16 03:44:22 | [diff] [blame] | 401 | } |
| 402 | |
[email protected] | 0f48fca | 2011-05-19 18:46:35 | [diff] [blame] | 403 | // We get the list of external extensions to check from preferences. |
| 404 | // It is possible that an extension has preferences but is not loaded. |
| 405 | // For example, an extension that requires experimental permissions |
| 406 | // will not be loaded if the experimental command line flag is not used. |
| 407 | // In this case, do not uninstall. |
| 408 | const Extension* extension = GetInstalledExtension(id); |
| 409 | if (!extension) { |
| 410 | // We can't call UninstallExtension with an unloaded/invalid |
| 411 | // extension ID. |
| 412 | LOG(WARNING) << "Attempted uninstallation of unloaded/invalid extension " |
| 413 | << "with id: " << id; |
| 414 | return; |
| 415 | } |
[email protected] | d6ebc979 | 2011-04-07 18:18:33 | [diff] [blame] | 416 | UninstallExtension(id, true, NULL); |
[email protected] | 7a4c685 | 2010-09-16 03:44:22 | [diff] [blame] | 417 | } |
| 418 | |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 419 | void ExtensionService::ClearProvidersForTesting() { |
[email protected] | 7a4c685 | 2010-09-16 03:44:22 | [diff] [blame] | 420 | external_extension_providers_.clear(); |
| 421 | } |
| 422 | |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 423 | void ExtensionService::AddProviderForTesting( |
| 424 | ExternalExtensionProviderInterface* test_provider) { |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 425 | CHECK(test_provider); |
[email protected] | 0a60a2e | 2010-10-25 16:15:21 | [diff] [blame] | 426 | external_extension_providers_.push_back( |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 427 | linked_ptr<ExternalExtensionProviderInterface>(test_provider)); |
[email protected] | 7a4c685 | 2010-09-16 03:44:22 | [diff] [blame] | 428 | } |
| 429 | |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 430 | void ExtensionService::OnExternalExtensionUpdateUrlFound( |
[email protected] | 7a4c685 | 2010-09-16 03:44:22 | [diff] [blame] | 431 | const std::string& id, |
[email protected] | 21a5a67 | 2010-11-04 10:47:42 | [diff] [blame] | 432 | const GURL& update_url, |
| 433 | Extension::Location location) { |
[email protected] | ab22ba4 | 2011-01-14 16:36:38 | [diff] [blame] | 434 | CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 435 | CHECK(Extension::IdIsValid(id)); |
[email protected] | a8af9fdb | 2010-10-28 21:52:20 | [diff] [blame] | 436 | |
[email protected] | 8a87a533 | 2011-08-11 17:54:59 | [diff] [blame] | 437 | const Extension* extension = GetExtensionById(id, true); |
| 438 | if (extension) { |
| 439 | // Already installed. Skip this install if the current location has |
| 440 | // higher priority than |location|. |
| 441 | Extension::Location current = extension->location(); |
| 442 | if (current == Extension::GetHigherPriorityLocation(current, location)) |
| 443 | return; |
| 444 | // Otherwise, overwrite the current installation. |
[email protected] | 7a4c685 | 2010-09-16 03:44:22 | [diff] [blame] | 445 | } |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 446 | pending_extension_manager()->AddFromExternalUpdateUrl( |
| 447 | id, update_url, location); |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 448 | external_extension_url_added_ |= true; |
[email protected] | 7a4c685 | 2010-09-16 03:44:22 | [diff] [blame] | 449 | } |
| 450 | |
[email protected] | 454434f | 2011-08-24 04:00:00 | [diff] [blame] | 451 | // If a download url matches one of these patterns and has a referrer of the |
| 452 | // webstore, then we're willing to treat that as a gallery download. |
| 453 | static const char* kAllowedDownloadURLPatterns[] = { |
| 454 | "https://clients2.google.com/service/update2*", |
| 455 | "https://clients2.googleusercontent.com/crx/*" |
| 456 | }; |
| 457 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 458 | bool ExtensionService::IsDownloadFromGallery(const GURL& download_url, |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 459 | const GURL& referrer_url) { |
[email protected] | d307199 | 2010-10-08 15:24:07 | [diff] [blame] | 460 | // Special-case the themes mini-gallery. |
| 461 | // TODO(erikkay) When that gallery goes away, remove this code. |
| 462 | if (IsDownloadFromMiniGallery(download_url) && |
| 463 | StartsWithASCII(referrer_url.spec(), |
| 464 | extension_urls::kMiniGalleryBrowsePrefix, false)) { |
[email protected] | 334e04a | 2010-06-24 23:34:44 | [diff] [blame] | 465 | return true; |
[email protected] | 1debbbb6 | 2010-10-06 17:23:44 | [diff] [blame] | 466 | } |
[email protected] | 473ff6e | 2010-05-12 15:31:55 | [diff] [blame] | 467 | |
[email protected] | 9adb969 | 2010-10-29 23:14:02 | [diff] [blame] | 468 | const Extension* download_extension = GetExtensionByWebExtent(download_url); |
| 469 | const Extension* referrer_extension = GetExtensionByWebExtent(referrer_url); |
| 470 | const Extension* webstore_app = GetWebStoreApp(); |
[email protected] | d307199 | 2010-10-08 15:24:07 | [diff] [blame] | 471 | |
| 472 | bool referrer_valid = (referrer_extension == webstore_app); |
| 473 | bool download_valid = (download_extension == webstore_app); |
| 474 | |
[email protected] | 454434f | 2011-08-24 04:00:00 | [diff] [blame] | 475 | // We also allow the download to be from a small set of trusted paths. |
| 476 | if (!download_valid) { |
| 477 | for (size_t i = 0; i < arraysize(kAllowedDownloadURLPatterns); i++) { |
| 478 | URLPattern pattern(URLPattern::SCHEME_HTTPS, |
| 479 | kAllowedDownloadURLPatterns[i]); |
| 480 | if (pattern.MatchesURL(download_url)) { |
| 481 | download_valid = true; |
| 482 | break; |
| 483 | } |
| 484 | } |
| 485 | } |
| 486 | |
[email protected] | d307199 | 2010-10-08 15:24:07 | [diff] [blame] | 487 | // If the command-line gallery URL is set, then be a bit more lenient. |
| 488 | GURL store_url = |
| 489 | GURL(CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 490 | switches::kAppsGalleryURL)); |
| 491 | if (!store_url.is_empty()) { |
| 492 | std::string store_tld = |
| 493 | net::RegistryControlledDomainService::GetDomainAndRegistry(store_url); |
| 494 | if (!referrer_valid) { |
| 495 | std::string referrer_tld = |
| 496 | net::RegistryControlledDomainService::GetDomainAndRegistry( |
| 497 | referrer_url); |
| 498 | // The referrer gets stripped when transitioning from https to http, |
| 499 | // or when hitting an unknown test cert and that commonly happens in |
| 500 | // testing environments. Given this, we allow an empty referrer when |
| 501 | // the command-line flag is set. |
| 502 | // Otherwise, the TLD must match the TLD of the command-line url. |
| 503 | referrer_valid = referrer_url.is_empty() || (referrer_tld == store_tld); |
| 504 | } |
| 505 | |
| 506 | if (!download_valid) { |
| 507 | std::string download_tld = |
| 508 | net::RegistryControlledDomainService::GetDomainAndRegistry( |
[email protected] | 04866c4 | 2011-05-03 20:03:50 | [diff] [blame] | 509 | download_url); |
[email protected] | d307199 | 2010-10-08 15:24:07 | [diff] [blame] | 510 | |
| 511 | // Otherwise, the TLD must match the TLD of the command-line url. |
| 512 | download_valid = (download_tld == store_tld); |
| 513 | } |
| 514 | } |
| 515 | |
| 516 | return (referrer_valid && download_valid); |
[email protected] | b7c2f25 | 2009-12-08 00:47:23 | [diff] [blame] | 517 | } |
| 518 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 519 | bool ExtensionService::IsDownloadFromMiniGallery(const GURL& download_url) { |
[email protected] | ac02528 | 2009-12-16 19:16:38 | [diff] [blame] | 520 | return StartsWithASCII(download_url.spec(), |
| 521 | extension_urls::kMiniGalleryDownloadPrefix, |
| 522 | false); // case_sensitive |
| 523 | } |
| 524 | |
[email protected] | d969667 | 2011-03-15 22:45:09 | [diff] [blame] | 525 | const Extension* ExtensionService::GetInstalledApp(const GURL& url) { |
[email protected] | ffb204f2 | 2010-12-05 23:20:27 | [diff] [blame] | 526 | // Check for hosted app. |
[email protected] | d969667 | 2011-03-15 22:45:09 | [diff] [blame] | 527 | const Extension* app = GetExtensionByWebExtent(url); |
| 528 | if (app) |
| 529 | return app; |
[email protected] | ffb204f2 | 2010-12-05 23:20:27 | [diff] [blame] | 530 | |
| 531 | // Check for packaged app. |
[email protected] | d969667 | 2011-03-15 22:45:09 | [diff] [blame] | 532 | app = GetExtensionByURL(url); |
| 533 | if (app && app->is_app()) |
| 534 | return app; |
| 535 | |
| 536 | return NULL; |
| 537 | } |
| 538 | |
| 539 | bool ExtensionService::IsInstalledApp(const GURL& url) { |
| 540 | return !!GetInstalledApp(url); |
[email protected] | ffb204f2 | 2010-12-05 23:20:27 | [diff] [blame] | 541 | } |
| 542 | |
[email protected] | da5683db | 2011-04-23 17:12:21 | [diff] [blame] | 543 | void ExtensionService::SetInstalledAppForRenderer(int renderer_child_id, |
| 544 | const Extension* app) { |
| 545 | installed_app_hosts_[renderer_child_id] = app; |
| 546 | } |
| 547 | |
| 548 | const Extension* ExtensionService::GetInstalledAppForRenderer( |
| 549 | int renderer_child_id) { |
| 550 | InstalledAppMap::iterator i = installed_app_hosts_.find(renderer_child_id); |
| 551 | if (i == installed_app_hosts_.end()) |
| 552 | return NULL; |
| 553 | return i->second; |
| 554 | } |
| 555 | |
[email protected] | 6aeac834 | 2010-10-01 20:21:18 | [diff] [blame] | 556 | // static |
[email protected] | d6ebc979 | 2011-04-07 18:18:33 | [diff] [blame] | 557 | // This function is used to implement the command-line switch |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 558 | // --uninstall-extension, and to uninstall an extension via sync. The LOG |
| 559 | // statements within this function are used to inform the user if the uninstall |
| 560 | // cannot be done. |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 561 | bool ExtensionService::UninstallExtensionHelper( |
| 562 | ExtensionService* extensions_service, |
[email protected] | 6aeac834 | 2010-10-01 20:21:18 | [diff] [blame] | 563 | const std::string& extension_id) { |
[email protected] | 6aeac834 | 2010-10-01 20:21:18 | [diff] [blame] | 564 | |
[email protected] | 95da88c4 | 2011-03-31 10:07:33 | [diff] [blame] | 565 | const Extension* extension = |
[email protected] | 8001df2 | 2011-04-28 19:59:47 | [diff] [blame] | 566 | extensions_service->GetInstalledExtension(extension_id); |
[email protected] | 95da88c4 | 2011-03-31 10:07:33 | [diff] [blame] | 567 | |
[email protected] | d6ebc979 | 2011-04-07 18:18:33 | [diff] [blame] | 568 | // We can't call UninstallExtension with an invalid extension ID. |
[email protected] | 95da88c4 | 2011-03-31 10:07:33 | [diff] [blame] | 569 | if (!extension) { |
[email protected] | 6aeac834 | 2010-10-01 20:21:18 | [diff] [blame] | 570 | LOG(WARNING) << "Attempted uninstallation of non-existent extension with " |
[email protected] | 95da88c4 | 2011-03-31 10:07:33 | [diff] [blame] | 571 | << "id: " << extension_id; |
| 572 | return false; |
[email protected] | 6aeac834 | 2010-10-01 20:21:18 | [diff] [blame] | 573 | } |
| 574 | |
[email protected] | d6ebc979 | 2011-04-07 18:18:33 | [diff] [blame] | 575 | // The following call to UninstallExtension will not allow an uninstall of a |
| 576 | // policy-controlled extension. |
| 577 | std::string error; |
| 578 | if (!extensions_service->UninstallExtension(extension_id, false, &error)) { |
| 579 | LOG(WARNING) << "Cannot uninstall extension with id " << extension_id |
| 580 | << ": " << error; |
| 581 | return false; |
| 582 | } |
[email protected] | 95da88c4 | 2011-03-31 10:07:33 | [diff] [blame] | 583 | |
[email protected] | 6aeac834 | 2010-10-01 20:21:18 | [diff] [blame] | 584 | return true; |
| 585 | } |
| 586 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 587 | ExtensionService::ExtensionService(Profile* profile, |
[email protected] | f0841cd | 2011-01-19 15:07:24 | [diff] [blame] | 588 | const CommandLine* command_line, |
| 589 | const FilePath& install_directory, |
| 590 | ExtensionPrefs* extension_prefs, |
[email protected] | 0436b10 | 2011-04-15 18:30:03 | [diff] [blame] | 591 | bool autoupdate_enabled, |
| 592 | bool extensions_enabled) |
[email protected] | 14908b7 | 2011-04-20 06:54:36 | [diff] [blame] | 593 | : weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), |
[email protected] | 704d77e | 2011-10-17 18:05:29 | [diff] [blame] | 594 | method_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), |
[email protected] | 14908b7 | 2011-04-20 06:54:36 | [diff] [blame] | 595 | profile_(profile), |
[email protected] | 73c4793 | 2010-12-06 18:13:43 | [diff] [blame] | 596 | extension_prefs_(extension_prefs), |
[email protected] | fc84e0e | 2011-09-27 19:18:22 | [diff] [blame] | 597 | extension_settings_frontend_( |
[email protected] | adfc546 | 2011-09-21 19:07:13 | [diff] [blame] | 598 | profile->GetPath().AppendASCII(kSettingsDirectoryName)), |
[email protected] | 14908b7 | 2011-04-20 06:54:36 | [diff] [blame] | 599 | pending_extension_manager_(*ALLOW_THIS_IN_INITIALIZER_LIST(this)), |
[email protected] | a9b00ac | 2009-06-25 21:03:23 | [diff] [blame] | 600 | install_directory_(install_directory), |
[email protected] | 0436b10 | 2011-04-15 18:30:03 | [diff] [blame] | 601 | extensions_enabled_(extensions_enabled), |
[email protected] | e81dba3 | 2009-06-19 20:19:13 | [diff] [blame] | 602 | show_extensions_prompts_(true), |
[email protected] | 3ecda25 | 2010-11-18 19:50:55 | [diff] [blame] | 603 | ready_(false), |
[email protected] | 14908b7 | 2011-04-20 06:54:36 | [diff] [blame] | 604 | toolbar_model_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), |
[email protected] | 8b28030 | 2011-10-13 22:22:23 | [diff] [blame] | 605 | menu_manager_(profile), |
[email protected] | af9db5f | 2011-10-05 05:13:15 | [diff] [blame] | 606 | app_notification_manager_(new AppNotificationManager(profile)), |
[email protected] | 902fd7b | 2011-07-27 18:42:31 | [diff] [blame] | 607 | permissions_manager_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), |
[email protected] | 18cc5a5 | 2011-04-15 16:03:38 | [diff] [blame] | 608 | apps_promo_(profile->GetPrefs()), |
[email protected] | 655b2b1a | 2011-10-13 17:13:06 | [diff] [blame] | 609 | webstore_installer_(profile), |
[email protected] | 7c1490da | 2011-10-11 18:53:25 | [diff] [blame] | 610 | event_routers_initialized_(false), |
| 611 | extension_warnings_(profile) { |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 612 | CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
[email protected] | a8af9fdb | 2010-10-28 21:52:20 | [diff] [blame] | 613 | |
[email protected] | 36a784c | 2009-06-23 06:21:08 | [diff] [blame] | 614 | // Figure out if extension installation should be enabled. |
[email protected] | 6d60703b | 2009-08-29 01:29:23 | [diff] [blame] | 615 | if (command_line->HasSwitch(switches::kDisableExtensions)) { |
| 616 | extensions_enabled_ = false; |
| 617 | } else if (profile->GetPrefs()->GetBoolean(prefs::kDisableExtensions)) { |
| 618 | extensions_enabled_ = false; |
[email protected] | 6b75ec3 | 2009-08-14 06:37:18 | [diff] [blame] | 619 | } |
[email protected] | 36a784c | 2009-06-23 06:21:08 | [diff] [blame] | 620 | |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 621 | registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_PROCESS_TERMINATED, |
[email protected] | 2f48b8d9 | 2011-10-17 15:14:35 | [diff] [blame] | 622 | NotificationService::AllBrowserContextsAndSources()); |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 623 | registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_CREATED, |
[email protected] | 2f48b8d9 | 2011-10-17 15:14:35 | [diff] [blame] | 624 | NotificationService::AllBrowserContextsAndSources()); |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 625 | registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_TERMINATED, |
[email protected] | 2f48b8d9 | 2011-10-17 15:14:35 | [diff] [blame] | 626 | NotificationService::AllBrowserContextsAndSources()); |
[email protected] | 2fb7dc98 | 2010-09-29 12:24:28 | [diff] [blame] | 627 | pref_change_registrar_.Init(profile->GetPrefs()); |
| 628 | pref_change_registrar_.Add(prefs::kExtensionInstallAllowList, this); |
| 629 | pref_change_registrar_.Add(prefs::kExtensionInstallDenyList, this); |
[email protected] | 4814b51 | 2009-11-07 00:12:29 | [diff] [blame] | 630 | |
[email protected] | 93fd78f4 | 2009-07-10 16:43:17 | [diff] [blame] | 631 | // Set up the ExtensionUpdater |
| 632 | if (autoupdate_enabled) { |
| 633 | int update_frequency = kDefaultUpdateFrequencySeconds; |
| 634 | if (command_line->HasSwitch(switches::kExtensionsUpdateFrequency)) { |
[email protected] | e83326f | 2010-07-31 17:29:25 | [diff] [blame] | 635 | base::StringToInt(command_line->GetSwitchValueASCII( |
| 636 | switches::kExtensionsUpdateFrequency), |
| 637 | &update_frequency); |
[email protected] | 93fd78f4 | 2009-07-10 16:43:17 | [diff] [blame] | 638 | } |
[email protected] | 82b6e51 | 2011-04-12 20:33:27 | [diff] [blame] | 639 | updater_.reset(new ExtensionUpdater(this, |
| 640 | extension_prefs, |
| 641 | profile->GetPrefs(), |
| 642 | profile, |
| 643 | update_frequency)); |
[email protected] | 93fd78f4 | 2009-07-10 16:43:17 | [diff] [blame] | 644 | } |
| 645 | |
[email protected] | 14908b7 | 2011-04-20 06:54:36 | [diff] [blame] | 646 | backend_ = |
| 647 | new ExtensionServiceBackend(weak_ptr_factory_.GetWeakPtr(), |
| 648 | install_directory_); |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 649 | |
[email protected] | af9db5f | 2011-10-05 05:13:15 | [diff] [blame] | 650 | app_notification_manager_->Init(); |
| 651 | |
[email protected] | 0436b10 | 2011-04-15 18:30:03 | [diff] [blame] | 652 | if (extensions_enabled_) { |
[email protected] | 87353134 | 2011-03-09 12:16:05 | [diff] [blame] | 653 | ExternalExtensionProviderImpl::CreateExternalProviders( |
| 654 | this, profile_, &external_extension_providers_); |
| 655 | } |
[email protected] | b671760b | 2010-07-15 21:13:47 | [diff] [blame] | 656 | |
[email protected] | aa96d3a | 2010-08-21 08:45:25 | [diff] [blame] | 657 | // Use monochrome icons for Omnibox icons. |
[email protected] | 29d0d4ac | 2010-09-08 21:10:31 | [diff] [blame] | 658 | omnibox_popup_icon_manager_.set_monochrome(true); |
[email protected] | b671760b | 2010-07-15 21:13:47 | [diff] [blame] | 659 | omnibox_icon_manager_.set_monochrome(true); |
[email protected] | 29d0d4ac | 2010-09-08 21:10:31 | [diff] [blame] | 660 | omnibox_icon_manager_.set_padding(gfx::Insets(0, kOmniboxIconPaddingLeft, |
| 661 | 0, kOmniboxIconPaddingRight)); |
[email protected] | cb0e5031 | 2011-05-09 15:03:07 | [diff] [blame] | 662 | |
| 663 | // How long is the path to the Extensions directory? |
| 664 | UMA_HISTOGRAM_CUSTOM_COUNTS("Extensions.ExtensionRootPathLength", |
| 665 | install_directory_.value().length(), 0, 500, 100); |
[email protected] | 6014d67 | 2008-12-05 00:38:25 | [diff] [blame] | 666 | } |
| 667 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 668 | const ExtensionList* ExtensionService::extensions() const { |
[email protected] | ddb1e5a | 2010-12-13 20:10:45 | [diff] [blame] | 669 | return &extensions_; |
| 670 | } |
| 671 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 672 | const ExtensionList* ExtensionService::disabled_extensions() const { |
[email protected] | ddb1e5a | 2010-12-13 20:10:45 | [diff] [blame] | 673 | return &disabled_extensions_; |
| 674 | } |
| 675 | |
[email protected] | bb7f4095 | 2011-01-13 00:21:20 | [diff] [blame] | 676 | const ExtensionList* ExtensionService::terminated_extensions() const { |
| 677 | return &terminated_extensions_; |
| 678 | } |
| 679 | |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 680 | PendingExtensionManager* ExtensionService::pending_extension_manager() { |
| 681 | return &pending_extension_manager_; |
[email protected] | ddb1e5a | 2010-12-13 20:10:45 | [diff] [blame] | 682 | } |
| 683 | |
[email protected] | ad63a79 | 2011-06-16 06:41:11 | [diff] [blame] | 684 | void ExtensionService::UnregisterComponentExtension( |
| 685 | const ComponentExtensionInfo& info) { |
| 686 | RegisteredComponentExtensions new_component_extension_manifests; |
| 687 | for (RegisteredComponentExtensions::iterator it = |
| 688 | component_extension_manifests_.begin(); |
| 689 | it != component_extension_manifests_.end(); ++it) { |
| 690 | if (!it->Equals(info)) |
| 691 | new_component_extension_manifests.push_back(*it); |
| 692 | } |
| 693 | component_extension_manifests_.swap(new_component_extension_manifests); |
| 694 | } |
| 695 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 696 | ExtensionService::~ExtensionService() { |
[email protected] | c8d407e | 2011-04-28 21:27:17 | [diff] [blame] | 697 | // No need to unload extensions here because they are profile-scoped, and the |
| 698 | // profile is in the process of being deleted. |
[email protected] | 94b4ffc | 2011-02-04 05:55:17 | [diff] [blame] | 699 | |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 700 | ProviderCollection::const_iterator i; |
| 701 | for (i = external_extension_providers_.begin(); |
| 702 | i != external_extension_providers_.end(); ++i) { |
| 703 | ExternalExtensionProviderInterface* provider = i->get(); |
| 704 | provider->ServiceShutdown(); |
| 705 | } |
[email protected] | 6014d67 | 2008-12-05 00:38:25 | [diff] [blame] | 706 | } |
| 707 | |
[email protected] | d9126802 | 2011-08-26 13:17:37 | [diff] [blame] | 708 | void ExtensionService::InitEventRoutersAfterImport() { |
| 709 | registrar_.Add(this, chrome::NOTIFICATION_IMPORT_FINISHED, |
| 710 | Source<Profile>(profile_)); |
| 711 | } |
| 712 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 713 | void ExtensionService::InitEventRouters() { |
[email protected] | b3d62312b1 | 2010-10-14 21:10:18 | [diff] [blame] | 714 | if (event_routers_initialized_) |
| 715 | return; |
| 716 | |
[email protected] | 370e950 | 2011-09-14 19:31:44 | [diff] [blame] | 717 | downloads_event_router_.reset(new ExtensionDownloadsEventRouter(profile_)); |
[email protected] | f825df2 | 2011-06-28 17:36:10 | [diff] [blame] | 718 | history_event_router_.reset(new ExtensionHistoryEventRouter()); |
| 719 | history_event_router_->ObserveProfile(profile_); |
[email protected] | 97d2f1d | 2011-01-15 00:41:08 | [diff] [blame] | 720 | browser_event_router_.reset(new ExtensionBrowserEventRouter(profile_)); |
| 721 | browser_event_router_->Init(); |
[email protected] | 118de789 | 2011-03-16 13:31:40 | [diff] [blame] | 722 | preference_event_router_.reset(new ExtensionPreferenceEventRouter(profile_)); |
[email protected] | f825df2 | 2011-06-28 17:36:10 | [diff] [blame] | 723 | bookmark_event_router_.reset(new ExtensionBookmarkEventRouter( |
| 724 | profile_->GetBookmarkModel())); |
| 725 | bookmark_event_router_->Init(); |
| 726 | cookies_event_router_.reset(new ExtensionCookiesEventRouter(profile_)); |
| 727 | cookies_event_router_->Init(); |
| 728 | management_event_router_.reset(new ExtensionManagementEventRouter(profile_)); |
| 729 | management_event_router_->Init(); |
[email protected] | 7da9a823 | 2011-05-27 21:07:11 | [diff] [blame] | 730 | ExtensionProcessesEventRouter::GetInstance()->ObserveProfile(profile_); |
[email protected] | f825df2 | 2011-06-28 17:36:10 | [diff] [blame] | 731 | web_navigation_event_router_.reset( |
| 732 | new ExtensionWebNavigationEventRouter(profile_)); |
| 733 | web_navigation_event_router_->Init(); |
[email protected] | 27072cad | 2011-05-09 19:46:40 | [diff] [blame] | 734 | |
[email protected] | eed367e | 2011-04-12 03:43:31 | [diff] [blame] | 735 | #if defined(OS_CHROMEOS) |
[email protected] | b16fc2e | 2011-07-21 21:32:58 | [diff] [blame] | 736 | file_browser_event_router_.reset( |
| 737 | new ExtensionFileBrowserEventRouter(profile_)); |
| 738 | file_browser_event_router_->ObserveFileSystemEvents(); |
[email protected] | 771a618 | 2011-10-05 16:32:52 | [diff] [blame] | 739 | |
| 740 | input_method_event_router_.reset( |
| 741 | new chromeos::ExtensionInputMethodEventRouter); |
[email protected] | be5bd574 | 2011-07-14 07:21:01 | [diff] [blame] | 742 | |
[email protected] | c8bf09be | 2011-06-25 03:22:27 | [diff] [blame] | 743 | ExtensionMediaPlayerEventRouter::GetInstance()->Init(profile_); |
[email protected] | 14da67b0 | 2011-08-02 05:49:13 | [diff] [blame] | 744 | ExtensionInputImeEventRouter::GetInstance()->Init(); |
[email protected] | eed367e | 2011-04-12 03:43:31 | [diff] [blame] | 745 | #endif |
[email protected] | 27072cad | 2011-05-09 19:46:40 | [diff] [blame] | 746 | |
| 747 | #if defined(OS_CHROMEOS) && defined(TOUCH_UI) |
| 748 | ExtensionInputUiEventRouter::GetInstance()->Init(); |
| 749 | #endif |
| 750 | |
[email protected] | b3d62312b1 | 2010-10-14 21:10:18 | [diff] [blame] | 751 | event_routers_initialized_ = true; |
[email protected] | c5ae74ab | 2010-04-15 18:14:37 | [diff] [blame] | 752 | } |
| 753 | |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 754 | const Extension* ExtensionService::GetExtensionById( |
| 755 | const std::string& id, bool include_disabled) const { |
[email protected] | 8001df2 | 2011-04-28 19:59:47 | [diff] [blame] | 756 | return GetExtensionByIdInternal(id, true, include_disabled, false); |
[email protected] | 78994ab0 | 2010-12-08 18:06:44 | [diff] [blame] | 757 | } |
| 758 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 759 | void ExtensionService::Init() { |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 760 | CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
[email protected] | a8af9fdb | 2010-10-28 21:52:20 | [diff] [blame] | 761 | |
[email protected] | fa6a910 | 2010-11-22 15:38:50 | [diff] [blame] | 762 | DCHECK(!ready_); // Can't redo init. |
[email protected] | 93fd78f4 | 2009-07-10 16:43:17 | [diff] [blame] | 763 | DCHECK_EQ(extensions_.size(), 0u); |
[email protected] | 9f1087e | 2009-06-15 17:29:32 | [diff] [blame] | 764 | |
[email protected] | 95dd38f | 2009-10-20 20:09:15 | [diff] [blame] | 765 | // Hack: we need to ensure the ResourceDispatcherHost is ready before we load |
| 766 | // the first extension, because its members listen for loaded notifications. |
| 767 | g_browser_process->resource_dispatcher_host(); |
| 768 | |
[email protected] | 9f1087e | 2009-06-15 17:29:32 | [diff] [blame] | 769 | LoadAllExtensions(); |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 770 | |
[email protected] | 9f1087e | 2009-06-15 17:29:32 | [diff] [blame] | 771 | // TODO(erikkay) this should probably be deferred to a future point |
| 772 | // rather than running immediately at startup. |
[email protected] | 93fd78f4 | 2009-07-10 16:43:17 | [diff] [blame] | 773 | CheckForExternalUpdates(); |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 774 | |
[email protected] | 9f1087e | 2009-06-15 17:29:32 | [diff] [blame] | 775 | // TODO(erikkay) this should probably be deferred as well. |
| 776 | GarbageCollectExtensions(); |
[email protected] | 6014d67 | 2008-12-05 00:38:25 | [diff] [blame] | 777 | } |
| 778 | |
[email protected] | 420a0ec | 2011-06-01 01:07:03 | [diff] [blame] | 779 | bool ExtensionService::UpdateExtension( |
| 780 | const std::string& id, |
| 781 | const FilePath& extension_path, |
| 782 | const GURL& download_url, |
| 783 | CrxInstaller** out_crx_installer) { |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 784 | CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
[email protected] | a8af9fdb | 2010-10-28 21:52:20 | [diff] [blame] | 785 | |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 786 | PendingExtensionInfo pending_extension_info; |
| 787 | bool is_pending_extension = pending_extension_manager_.GetById( |
| 788 | id, &pending_extension_info); |
[email protected] | 8ef78fd | 2010-08-19 17:14:32 | [diff] [blame] | 789 | |
[email protected] | 8001df2 | 2011-04-28 19:59:47 | [diff] [blame] | 790 | const Extension* extension = |
| 791 | GetExtensionByIdInternal(id, true, true, false); |
[email protected] | 5eb375e9 | 2010-11-26 07:50:41 | [diff] [blame] | 792 | if (!is_pending_extension && !extension) { |
[email protected] | aa14270 | 2010-03-26 01:26:33 | [diff] [blame] | 793 | LOG(WARNING) << "Will not update extension " << id |
| 794 | << " because it is not installed or pending"; |
| 795 | // Delete extension_path since we're not creating a CrxInstaller |
| 796 | // that would do it for us. |
[email protected] | 14908b7 | 2011-04-20 06:54:36 | [diff] [blame] | 797 | if (!BrowserThread::PostTask( |
| 798 | BrowserThread::FILE, FROM_HERE, |
[email protected] | 704d77e | 2011-10-17 18:05:29 | [diff] [blame] | 799 | NewRunnableFunction( |
[email protected] | 14908b7 | 2011-04-20 06:54:36 | [diff] [blame] | 800 | extension_file_util::DeleteFile, extension_path, false))) |
| 801 | NOTREACHED(); |
[email protected] | 420a0ec | 2011-06-01 01:07:03 | [diff] [blame] | 802 | |
| 803 | return false; |
[email protected] | e957fe5 | 2009-06-23 16:51:05 | [diff] [blame] | 804 | } |
| 805 | |
[email protected] | aa14270 | 2010-03-26 01:26:33 | [diff] [blame] | 806 | // We want a silent install only for non-pending extensions and |
| 807 | // pending extensions that have install_silently set. |
| 808 | ExtensionInstallUI* client = |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 809 | (!is_pending_extension || pending_extension_info.install_silently()) ? |
[email protected] | aa14270 | 2010-03-26 01:26:33 | [diff] [blame] | 810 | NULL : new ExtensionInstallUI(profile_); |
| 811 | |
[email protected] | 14908b7 | 2011-04-20 06:54:36 | [diff] [blame] | 812 | scoped_refptr<CrxInstaller> installer(MakeCrxInstaller(client)); |
[email protected] | 6dfbbf8 | 2010-03-12 23:09:16 | [diff] [blame] | 813 | installer->set_expected_id(id); |
[email protected] | ec5b50d | 2010-10-09 16:35:18 | [diff] [blame] | 814 | if (is_pending_extension) |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 815 | installer->set_install_source(pending_extension_info.install_source()); |
[email protected] | 5eb375e9 | 2010-11-26 07:50:41 | [diff] [blame] | 816 | else if (extension) |
| 817 | installer->set_install_source(extension->location()); |
[email protected] | 0d3e4a2 | 2011-06-23 19:02:52 | [diff] [blame] | 818 | if (pending_extension_info.install_silently()) |
| 819 | installer->set_allow_silent_install(true); |
[email protected] | 3d72972 | 2011-09-20 02:57:09 | [diff] [blame] | 820 | if (extension && extension->from_webstore()) |
| 821 | installer->set_is_gallery_install(true); |
[email protected] | 6dfbbf8 | 2010-03-12 23:09:16 | [diff] [blame] | 822 | installer->set_delete_source(true); |
[email protected] | 655b2b1a | 2011-10-13 17:13:06 | [diff] [blame] | 823 | installer->set_download_url(download_url); |
[email protected] | cb0e5031 | 2011-05-09 15:03:07 | [diff] [blame] | 824 | installer->set_install_cause(extension_misc::INSTALL_CAUSE_UPDATE); |
[email protected] | 6dfbbf8 | 2010-03-12 23:09:16 | [diff] [blame] | 825 | installer->InstallCrx(extension_path); |
[email protected] | 420a0ec | 2011-06-01 01:07:03 | [diff] [blame] | 826 | |
| 827 | if (out_crx_installer) |
| 828 | *out_crx_installer = installer; |
| 829 | |
| 830 | return true; |
[email protected] | e957fe5 | 2009-06-23 16:51:05 | [diff] [blame] | 831 | } |
| 832 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 833 | void ExtensionService::ReloadExtension(const std::string& extension_id) { |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 834 | CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
[email protected] | b65272f | 2009-08-31 15:47:06 | [diff] [blame] | 835 | FilePath path; |
[email protected] | 9adb969 | 2010-10-29 23:14:02 | [diff] [blame] | 836 | const Extension* current_extension = GetExtensionById(extension_id, false); |
[email protected] | 9cddd470 | 2009-07-27 22:09:40 | [diff] [blame] | 837 | |
[email protected] | f17dbd4 | 2010-08-16 23:21:10 | [diff] [blame] | 838 | // 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] | 839 | if (current_extension) { |
[email protected] | 4814b51 | 2009-11-07 00:12:29 | [diff] [blame] | 840 | // If the extension has an inspector open for its background page, detach |
| 841 | // the inspector and hang onto a cookie for it, so that we can reattach |
| 842 | // later. |
| 843 | ExtensionProcessManager* manager = profile_->GetExtensionProcessManager(); |
| 844 | ExtensionHost* host = manager->GetBackgroundHostForExtension( |
| 845 | current_extension); |
| 846 | if (host) { |
| 847 | // Look for an open inspector for the background page. |
| 848 | int devtools_cookie = DevToolsManager::GetInstance()->DetachClientHost( |
| 849 | host->render_view_host()); |
| 850 | if (devtools_cookie >= 0) |
| 851 | orphaned_dev_tools_[extension_id] = devtools_cookie; |
| 852 | } |
| 853 | |
[email protected] | b65272f | 2009-08-31 15:47:06 | [diff] [blame] | 854 | path = current_extension->path(); |
[email protected] | f17dbd4 | 2010-08-16 23:21:10 | [diff] [blame] | 855 | DisableExtension(extension_id); |
| 856 | disabled_extension_paths_[extension_id] = path; |
[email protected] | 1eb17508 | 2010-02-10 09:26:16 | [diff] [blame] | 857 | } else { |
| 858 | path = unloaded_extension_paths_[extension_id]; |
[email protected] | b65272f | 2009-08-31 15:47:06 | [diff] [blame] | 859 | } |
| 860 | |
[email protected] | e6090e4 | 2010-03-23 22:44:08 | [diff] [blame] | 861 | // Check the installed extensions to see if what we're reloading was already |
| 862 | // installed. |
| 863 | scoped_ptr<ExtensionInfo> installed_extension( |
| 864 | extension_prefs_->GetInstalledExtensionInfo(extension_id)); |
| 865 | if (installed_extension.get() && |
| 866 | installed_extension->extension_manifest.get()) { |
| 867 | LoadInstalledExtension(*installed_extension, false); |
| 868 | } else { |
| 869 | // We should always be able to remember the extension's path. If it's not in |
| 870 | // the map, someone failed to update |unloaded_extension_paths_|. |
| 871 | CHECK(!path.empty()); |
| 872 | LoadExtension(path); |
| 873 | } |
[email protected] | 9cddd470 | 2009-07-27 22:09:40 | [diff] [blame] | 874 | } |
| 875 | |
[email protected] | fa2416f | 2011-05-03 08:41:20 | [diff] [blame] | 876 | bool ExtensionService::UninstallExtension( |
| 877 | const std::string& extension_id_unsafe, |
| 878 | bool external_uninstall, |
| 879 | std::string* error) { |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 880 | CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
[email protected] | a8af9fdb | 2010-10-28 21:52:20 | [diff] [blame] | 881 | |
[email protected] | fa2416f | 2011-05-03 08:41:20 | [diff] [blame] | 882 | // Copy the extension identifier since the reference might have been |
| 883 | // obtained via Extension::id() and the extension may be deleted in |
| 884 | // this function. |
| 885 | std::string extension_id(extension_id_unsafe); |
| 886 | |
[email protected] | 0d6ec3a7 | 2011-09-02 02:09:43 | [diff] [blame] | 887 | scoped_refptr<const Extension> extension(GetInstalledExtension(extension_id)); |
[email protected] | 631cf82 | 2009-05-15 07:01:25 | [diff] [blame] | 888 | |
[email protected] | e7afe245 | 2010-08-22 16:19:13 | [diff] [blame] | 889 | // Callers should not send us nonexistent extensions. |
[email protected] | aebe23a3 | 2010-12-10 22:15:48 | [diff] [blame] | 890 | CHECK(extension); |
[email protected] | 9f1087e | 2009-06-15 17:29:32 | [diff] [blame] | 891 | |
[email protected] | 95da88c4 | 2011-03-31 10:07:33 | [diff] [blame] | 892 | // Policy change which triggers an uninstall will always set |
| 893 | // |external_uninstall| to true so this is the only way to uninstall |
| 894 | // managed extensions. |
[email protected] | 0d6ec3a7 | 2011-09-02 02:09:43 | [diff] [blame] | 895 | if (!Extension::UserMayDisable(extension->location()) && |
| 896 | !external_uninstall) { |
[email protected] | d6ebc979 | 2011-04-07 18:18:33 | [diff] [blame] | 897 | NotificationService::current()->Notify( |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 898 | chrome::NOTIFICATION_EXTENSION_UNINSTALL_NOT_ALLOWED, |
[email protected] | d6ebc979 | 2011-04-07 18:18:33 | [diff] [blame] | 899 | Source<Profile>(profile_), |
| 900 | Details<const Extension>(extension)); |
| 901 | if (error != NULL) { |
| 902 | *error = errors::kCannotUninstallManagedExtension; |
| 903 | } |
| 904 | return false; |
| 905 | } |
[email protected] | 95da88c4 | 2011-03-31 10:07:33 | [diff] [blame] | 906 | |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 907 | // Extract the data we need for sync now, but don't actually sync until we've |
| 908 | // completed the uninstallation. |
| 909 | SyncBundle* sync_bundle = GetSyncBundleForExtension(*extension); |
| 910 | |
| 911 | SyncChange sync_change; |
| 912 | if (sync_bundle) { |
| 913 | ExtensionSyncData extension_sync_data(*extension, |
| 914 | IsExtensionEnabled(extension_id), |
| 915 | IsIncognitoEnabled(extension_id)); |
| 916 | sync_change = extension_sync_data.GetSyncChange(SyncChange::ACTION_DELETE); |
| 917 | } |
| 918 | |
[email protected] | 9b21765 | 2010-10-08 22:04:23 | [diff] [blame] | 919 | UMA_HISTOGRAM_ENUMERATION("Extensions.UninstallType", |
[email protected] | 7fa19f8 | 2010-12-21 19:40:08 | [diff] [blame] | 920 | extension->GetType(), 100); |
[email protected] | fe2dd774 | 2011-04-19 22:52:49 | [diff] [blame] | 921 | RecordPermissionMessagesHistogram( |
| 922 | extension, "Extensions.Permissions_Uninstall"); |
[email protected] | 9b21765 | 2010-10-08 22:04:23 | [diff] [blame] | 923 | |
[email protected] | 8e5c89a | 2011-06-07 18:13:33 | [diff] [blame] | 924 | TemplateURLService* url_service = |
| 925 | TemplateURLServiceFactory::GetForProfile(profile_); |
| 926 | if (url_service) |
| 927 | url_service->UnregisterExtensionKeyword(extension); |
[email protected] | 56ad379 | 2010-05-28 17:45:33 | [diff] [blame] | 928 | |
[email protected] | 831aa21 | 2010-03-26 13:55:19 | [diff] [blame] | 929 | // Unload before doing more cleanup to ensure that nothing is hanging on to |
| 930 | // any of these resources. |
[email protected] | 814a7bf0f | 2011-08-13 05:30:59 | [diff] [blame] | 931 | UnloadExtension(extension_id, extension_misc::UNLOAD_REASON_UNINSTALL); |
[email protected] | 831aa21 | 2010-03-26 13:55:19 | [diff] [blame] | 932 | |
[email protected] | 0d6ec3a7 | 2011-09-02 02:09:43 | [diff] [blame] | 933 | extension_prefs_->OnExtensionUninstalled(extension_id, extension->location(), |
[email protected] | 831aa21 | 2010-03-26 13:55:19 | [diff] [blame] | 934 | external_uninstall); |
[email protected] | 9f1087e | 2009-06-15 17:29:32 | [diff] [blame] | 935 | |
| 936 | // Tell the backend to start deleting installed extensions on the file thread. |
[email protected] | 0d6ec3a7 | 2011-09-02 02:09:43 | [diff] [blame] | 937 | if (Extension::LOAD != extension->location()) { |
[email protected] | 14908b7 | 2011-04-20 06:54:36 | [diff] [blame] | 938 | if (!BrowserThread::PostTask( |
| 939 | BrowserThread::FILE, FROM_HERE, |
[email protected] | 704d77e | 2011-10-17 18:05:29 | [diff] [blame] | 940 | NewRunnableFunction( |
[email protected] | 14908b7 | 2011-04-20 06:54:36 | [diff] [blame] | 941 | &extension_file_util::UninstallExtension, |
| 942 | install_directory_, |
[email protected] | fa2416f | 2011-05-03 08:41:20 | [diff] [blame] | 943 | extension_id))) |
[email protected] | 14908b7 | 2011-04-20 06:54:36 | [diff] [blame] | 944 | NOTREACHED(); |
[email protected] | 9f1087e | 2009-06-15 17:29:32 | [diff] [blame] | 945 | } |
| 946 | |
[email protected] | 0d6ec3a7 | 2011-09-02 02:09:43 | [diff] [blame] | 947 | GURL launch_web_url_origin(extension->launch_web_url()); |
| 948 | launch_web_url_origin = launch_web_url_origin.GetOrigin(); |
| 949 | bool is_storage_isolated = |
| 950 | (extension->is_storage_isolated() && |
| 951 | extension->HasAPIPermission(ExtensionAPIPermission::kExperimental)); |
| 952 | |
| 953 | if (extension->is_hosted_app() && |
| 954 | !profile_->GetExtensionSpecialStoragePolicy()-> |
| 955 | IsStorageProtected(launch_web_url_origin)) { |
[email protected] | dc0b5a1 | 2011-10-14 00:06:13 | [diff] [blame] | 956 | ExtensionDataDeleter::StartDeleting( |
| 957 | profile_, extension_id, launch_web_url_origin, is_storage_isolated); |
[email protected] | 0d6ec3a7 | 2011-09-02 02:09:43 | [diff] [blame] | 958 | } |
[email protected] | dc0b5a1 | 2011-10-14 00:06:13 | [diff] [blame] | 959 | ExtensionDataDeleter::StartDeleting( |
| 960 | profile_, extension_id, extension->url(), is_storage_isolated); |
[email protected] | 0d6ec3a7 | 2011-09-02 02:09:43 | [diff] [blame] | 961 | |
[email protected] | 0dfe05c | 2011-02-23 23:03:36 | [diff] [blame] | 962 | UntrackTerminatedExtension(extension_id); |
[email protected] | 21103034 | 2010-09-30 18:41:06 | [diff] [blame] | 963 | |
| 964 | // Notify interested parties that we've uninstalled this extension. |
| 965 | NotificationService::current()->Notify( |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 966 | chrome::NOTIFICATION_EXTENSION_UNINSTALLED, |
[email protected] | 21103034 | 2010-09-30 18:41:06 | [diff] [blame] | 967 | Source<Profile>(profile_), |
[email protected] | 3e873e5 | 2011-10-10 00:30:25 | [diff] [blame] | 968 | Details<const std::string>(&extension_id)); |
[email protected] | d6ebc979 | 2011-04-07 18:18:33 | [diff] [blame] | 969 | |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 970 | if (sync_bundle && sync_bundle->HasExtensionId(extension_id)) { |
| 971 | sync_bundle->sync_processor->ProcessSyncChanges( |
| 972 | FROM_HERE, SyncChangeList(1, sync_change)); |
| 973 | sync_bundle->synced_extensions.erase(extension_id); |
| 974 | } |
| 975 | |
[email protected] | 333b1de | 2011-09-12 18:28:50 | [diff] [blame] | 976 | // Track the uninstallation. |
[email protected] | 49098f70 | 2011-10-13 03:47:18 | [diff] [blame] | 977 | UMA_HISTOGRAM_ENUMERATION("Extensions.ExtensionUninstalled", 1, 2); |
| 978 | |
| 979 | static bool default_apps_trial_exists = |
| 980 | base::FieldTrialList::TrialExists(kDefaultAppsTrial_Name); |
| 981 | if (default_apps_trial_exists) { |
| 982 | UMA_HISTOGRAM_ENUMERATION( |
| 983 | base::FieldTrial::MakeName("Extensions.ExtensionUninstalled", |
| 984 | kDefaultAppsTrial_Name), |
| 985 | 1, 2); |
| 986 | } |
[email protected] | 333b1de | 2011-09-12 18:28:50 | [diff] [blame] | 987 | |
[email protected] | 7c1490da | 2011-10-11 18:53:25 | [diff] [blame] | 988 | // Uninstalling one extension might have solved the problems of others. |
| 989 | // Therefore, we clear warnings of this type for all extensions. |
| 990 | std::set<ExtensionWarningSet::WarningType> warnings; |
| 991 | extension_warnings_.GetWarningsAffectingExtension(extension_id, &warnings); |
| 992 | extension_warnings_.ClearWarnings(warnings); |
| 993 | |
[email protected] | d6ebc979 | 2011-04-07 18:18:33 | [diff] [blame] | 994 | return true; |
[email protected] | c10da4b0 | 2010-03-25 14:38:32 | [diff] [blame] | 995 | } |
| 996 | |
[email protected] | c3cfb01 | 2011-04-06 22:07:35 | [diff] [blame] | 997 | bool ExtensionService::IsExtensionEnabled( |
| 998 | const std::string& extension_id) const { |
[email protected] | 36429da | 2011-07-11 20:25:18 | [diff] [blame] | 999 | const Extension* extension = |
[email protected] | ad83ca24 | 2011-07-29 01:32:25 | [diff] [blame] | 1000 | GetExtensionByIdInternal(extension_id, true, false, true); |
[email protected] | 36429da | 2011-07-11 20:25:18 | [diff] [blame] | 1001 | if (extension) |
| 1002 | return true; |
| 1003 | |
[email protected] | ad83ca24 | 2011-07-29 01:32:25 | [diff] [blame] | 1004 | extension = |
| 1005 | GetExtensionByIdInternal(extension_id, false, true, false); |
| 1006 | if (extension) |
| 1007 | return false; |
| 1008 | |
| 1009 | // If the extension hasn't been loaded yet, check the prefs for it. Assume |
| 1010 | // enabled unless otherwise noted. |
| 1011 | return !extension_prefs_->IsExtensionDisabled(extension_id) && |
| 1012 | !extension_prefs_->IsExternalExtensionUninstalled(extension_id); |
[email protected] | c3cfb01 | 2011-04-06 22:07:35 | [diff] [blame] | 1013 | } |
| 1014 | |
| 1015 | bool ExtensionService::IsExternalExtensionUninstalled( |
| 1016 | const std::string& extension_id) const { |
| 1017 | return extension_prefs_->IsExternalExtensionUninstalled(extension_id); |
| 1018 | } |
| 1019 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 1020 | void ExtensionService::EnableExtension(const std::string& extension_id) { |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 1021 | CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
[email protected] | a8af9fdb | 2010-10-28 21:52:20 | [diff] [blame] | 1022 | |
[email protected] | 06f9256 | 2011-04-29 19:27:31 | [diff] [blame] | 1023 | if (IsExtensionEnabled(extension_id)) |
[email protected] | 0c6da50 | 2009-08-14 22:32:39 | [diff] [blame] | 1024 | return; |
[email protected] | 0c6da50 | 2009-08-14 22:32:39 | [diff] [blame] | 1025 | |
[email protected] | b3317ad | 2011-04-28 23:46:00 | [diff] [blame] | 1026 | extension_prefs_->SetExtensionState(extension_id, Extension::ENABLED); |
[email protected] | 1784e83a | 2009-09-08 21:01:52 | [diff] [blame] | 1027 | |
[email protected] | 06f9256 | 2011-04-29 19:27:31 | [diff] [blame] | 1028 | const Extension* extension = |
| 1029 | GetExtensionByIdInternal(extension_id, false, true, false); |
| 1030 | // This can happen if sync enables an extension that is not |
| 1031 | // installed yet. |
| 1032 | if (!extension) |
| 1033 | return; |
| 1034 | |
[email protected] | 0c6da50 | 2009-08-14 22:32:39 | [diff] [blame] | 1035 | // Move it over to the enabled list. |
[email protected] | 00cd9c4 | 2010-11-02 20:15:57 | [diff] [blame] | 1036 | extensions_.push_back(make_scoped_refptr(extension)); |
[email protected] | 0c6da50 | 2009-08-14 22:32:39 | [diff] [blame] | 1037 | ExtensionList::iterator iter = std::find(disabled_extensions_.begin(), |
| 1038 | disabled_extensions_.end(), |
| 1039 | extension); |
| 1040 | disabled_extensions_.erase(iter); |
| 1041 | |
[email protected] | f681c78 | 2010-11-19 11:19:39 | [diff] [blame] | 1042 | // Make sure any browser action contained within it is not hidden. |
| 1043 | extension_prefs_->SetBrowserActionVisibility(extension, true); |
| 1044 | |
[email protected] | 62d30f4 | 2009-10-01 22:36:06 | [diff] [blame] | 1045 | NotifyExtensionLoaded(extension); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 1046 | |
| 1047 | SyncExtensionChangeIfNeeded(*extension); |
[email protected] | 0c6da50 | 2009-08-14 22:32:39 | [diff] [blame] | 1048 | } |
| 1049 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 1050 | void ExtensionService::DisableExtension(const std::string& extension_id) { |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 1051 | CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
[email protected] | a8af9fdb | 2010-10-28 21:52:20 | [diff] [blame] | 1052 | |
[email protected] | b2ba996 | 2009-12-10 20:10:15 | [diff] [blame] | 1053 | // The extension may have been disabled already. |
[email protected] | 06f9256 | 2011-04-29 19:27:31 | [diff] [blame] | 1054 | if (!IsExtensionEnabled(extension_id)) |
[email protected] | 1784e83a | 2009-09-08 21:01:52 | [diff] [blame] | 1055 | return; |
[email protected] | 1784e83a | 2009-09-08 21:01:52 | [diff] [blame] | 1056 | |
[email protected] | 06f9256 | 2011-04-29 19:27:31 | [diff] [blame] | 1057 | const Extension* extension = GetInstalledExtension(extension_id); |
| 1058 | // |extension| can be NULL if sync disables an extension that is not |
| 1059 | // installed yet. |
| 1060 | if (extension && !Extension::UserMayDisable(extension->location())) |
[email protected] | 95da88c4 | 2011-03-31 10:07:33 | [diff] [blame] | 1061 | return; |
| 1062 | |
[email protected] | b3317ad | 2011-04-28 23:46:00 | [diff] [blame] | 1063 | extension_prefs_->SetExtensionState(extension_id, Extension::DISABLED); |
[email protected] | 1784e83a | 2009-09-08 21:01:52 | [diff] [blame] | 1064 | |
[email protected] | 06f9256 | 2011-04-29 19:27:31 | [diff] [blame] | 1065 | extension = GetExtensionByIdInternal(extension_id, true, false, true); |
| 1066 | if (!extension) |
| 1067 | return; |
| 1068 | |
[email protected] | 1784e83a | 2009-09-08 21:01:52 | [diff] [blame] | 1069 | // Move it over to the disabled list. |
[email protected] | 00cd9c4 | 2010-11-02 20:15:57 | [diff] [blame] | 1070 | disabled_extensions_.push_back(make_scoped_refptr(extension)); |
[email protected] | 1784e83a | 2009-09-08 21:01:52 | [diff] [blame] | 1071 | ExtensionList::iterator iter = std::find(extensions_.begin(), |
| 1072 | extensions_.end(), |
| 1073 | extension); |
[email protected] | 06f9256 | 2011-04-29 19:27:31 | [diff] [blame] | 1074 | if (iter != extensions_.end()) { |
| 1075 | extensions_.erase(iter); |
| 1076 | } else { |
| 1077 | iter = std::find(terminated_extensions_.begin(), |
| 1078 | terminated_extensions_.end(), |
| 1079 | extension); |
| 1080 | terminated_extensions_.erase(iter); |
| 1081 | } |
[email protected] | 1784e83a | 2009-09-08 21:01:52 | [diff] [blame] | 1082 | |
[email protected] | 814a7bf0f | 2011-08-13 05:30:59 | [diff] [blame] | 1083 | NotifyExtensionUnloaded(extension, extension_misc::UNLOAD_REASON_DISABLE); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 1084 | |
| 1085 | SyncExtensionChangeIfNeeded(*extension); |
[email protected] | 7c1490da | 2011-10-11 18:53:25 | [diff] [blame] | 1086 | |
| 1087 | // Deactivating one extension might have solved the problems of others. |
| 1088 | // Therefore, we clear warnings of this type for all extensions. |
| 1089 | std::set<ExtensionWarningSet::WarningType> warnings; |
| 1090 | extension_warnings_.GetWarningsAffectingExtension(extension_id, &warnings); |
| 1091 | extension_warnings_.ClearWarnings(warnings); |
[email protected] | 1784e83a | 2009-09-08 21:01:52 | [diff] [blame] | 1092 | } |
| 1093 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 1094 | void ExtensionService::GrantPermissions(const Extension* extension) { |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1095 | CHECK(extension); |
| 1096 | |
[email protected] | 902fd7b | 2011-07-27 18:42:31 | [diff] [blame] | 1097 | // We only maintain the granted permissions prefs for extensions that can't |
| 1098 | // silently increase their permissions. |
| 1099 | if (extension->CanSilentlyIncreasePermissions()) |
| 1100 | return; |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1101 | |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1102 | extension_prefs_->AddGrantedPermissions(extension->id(), |
[email protected] | 902fd7b | 2011-07-27 18:42:31 | [diff] [blame] | 1103 | extension->GetActivePermissions()); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1104 | } |
| 1105 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 1106 | void ExtensionService::GrantPermissionsAndEnableExtension( |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1107 | const Extension* extension) { |
| 1108 | CHECK(extension); |
[email protected] | fe2dd774 | 2011-04-19 22:52:49 | [diff] [blame] | 1109 | RecordPermissionMessagesHistogram( |
| 1110 | extension, "Extensions.Permissions_ReEnable"); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1111 | GrantPermissions(extension); |
| 1112 | extension_prefs_->SetDidExtensionEscalatePermissions(extension, false); |
| 1113 | EnableExtension(extension->id()); |
| 1114 | } |
| 1115 | |
[email protected] | 902fd7b | 2011-07-27 18:42:31 | [diff] [blame] | 1116 | void ExtensionService::UpdateActivePermissions( |
| 1117 | const Extension* extension, |
| 1118 | const ExtensionPermissionSet* permissions) { |
| 1119 | extension_prefs()->SetActivePermissions(extension->id(), permissions); |
| 1120 | extension->SetActivePermissions(permissions); |
| 1121 | } |
| 1122 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 1123 | void ExtensionService::LoadExtension(const FilePath& extension_path) { |
[email protected] | 71eb1e6d | 2011-08-02 22:57:40 | [diff] [blame] | 1124 | LoadExtension(extension_path, true); |
| 1125 | } |
| 1126 | |
| 1127 | void ExtensionService::LoadExtension(const FilePath& extension_path, |
| 1128 | bool prompt_for_plugins) { |
[email protected] | e49002a | 2011-07-13 03:40:44 | [diff] [blame] | 1129 | BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
[email protected] | 704d77e | 2011-10-17 18:05:29 | [diff] [blame] | 1130 | NewRunnableMethod(backend_.get(), |
| 1131 | &ExtensionServiceBackend::LoadSingleExtension, |
| 1132 | extension_path, prompt_for_plugins)); |
[email protected] | e49002a | 2011-07-13 03:40:44 | [diff] [blame] | 1133 | } |
| 1134 | |
| 1135 | void ExtensionService::LoadExtensionFromCommandLine( |
[email protected] | 67d2d80 | 2011-07-21 02:54:28 | [diff] [blame] | 1136 | const FilePath& path_in) { |
| 1137 | |
| 1138 | // Load extensions from the command line synchronously to avoid a race |
| 1139 | // between extension loading and loading an URL from the command line. |
| 1140 | base::ThreadRestrictions::ScopedAllowIO allow_io; |
| 1141 | |
| 1142 | FilePath extension_path = path_in; |
| 1143 | file_util::AbsolutePath(&extension_path); |
| 1144 | |
| 1145 | std::string id = Extension::GenerateIdForPath(extension_path); |
[email protected] | cdfca970 | 2011-08-08 16:07:01 | [diff] [blame] | 1146 | bool allow_file_access = |
| 1147 | Extension::ShouldAlwaysAllowFileAccess(Extension::LOAD); |
| 1148 | if (extension_prefs()->HasAllowFileAccessSetting(id)) |
| 1149 | allow_file_access = extension_prefs()->AllowFileAccess(id); |
[email protected] | 67d2d80 | 2011-07-21 02:54:28 | [diff] [blame] | 1150 | |
| 1151 | int flags = Extension::NO_FLAGS; |
[email protected] | cdfca970 | 2011-08-08 16:07:01 | [diff] [blame] | 1152 | if (allow_file_access) |
[email protected] | 67d2d80 | 2011-07-21 02:54:28 | [diff] [blame] | 1153 | flags |= Extension::ALLOW_FILE_ACCESS; |
| 1154 | if (Extension::ShouldDoStrictErrorChecking(Extension::LOAD)) |
| 1155 | flags |= Extension::STRICT_ERROR_CHECKS; |
| 1156 | |
| 1157 | std::string error; |
| 1158 | scoped_refptr<const Extension> extension(extension_file_util::LoadExtension( |
| 1159 | extension_path, |
| 1160 | Extension::LOAD, |
| 1161 | flags, |
| 1162 | &error)); |
| 1163 | |
| 1164 | if (!extension) { |
[email protected] | 655b2b1a | 2011-10-13 17:13:06 | [diff] [blame] | 1165 | ReportExtensionLoadError(extension_path, error, true); |
[email protected] | 67d2d80 | 2011-07-21 02:54:28 | [diff] [blame] | 1166 | return; |
| 1167 | } |
| 1168 | |
| 1169 | OnLoadSingleExtension(extension, false); |
[email protected] | 9f1087e | 2009-06-15 17:29:32 | [diff] [blame] | 1170 | } |
| 1171 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 1172 | void ExtensionService::LoadComponentExtensions() { |
[email protected] | 1952c7d | 2010-03-04 23:48:34 | [diff] [blame] | 1173 | for (RegisteredComponentExtensions::iterator it = |
| 1174 | component_extension_manifests_.begin(); |
| 1175 | it != component_extension_manifests_.end(); ++it) { |
[email protected] | 61b55b6 | 2011-03-24 09:03:10 | [diff] [blame] | 1176 | LoadComponentExtension(*it); |
[email protected] | 1952c7d | 2010-03-04 23:48:34 | [diff] [blame] | 1177 | } |
| 1178 | } |
| 1179 | |
[email protected] | a964e11 | 2011-04-14 21:52:51 | [diff] [blame] | 1180 | const Extension* ExtensionService::LoadComponentExtension( |
[email protected] | 61b55b6 | 2011-03-24 09:03:10 | [diff] [blame] | 1181 | const ComponentExtensionInfo &info) { |
| 1182 | JSONStringValueSerializer serializer(info.manifest); |
| 1183 | scoped_ptr<Value> manifest(serializer.Deserialize(NULL, NULL)); |
| 1184 | if (!manifest.get()) { |
[email protected] | 0b05c26 | 2011-08-11 01:42:21 | [diff] [blame] | 1185 | LOG(ERROR) << "Failed to parse manifest for extension"; |
[email protected] | a964e11 | 2011-04-14 21:52:51 | [diff] [blame] | 1186 | return NULL; |
[email protected] | 61b55b6 | 2011-03-24 09:03:10 | [diff] [blame] | 1187 | } |
| 1188 | |
[email protected] | 83048a2 | 2011-03-29 00:14:13 | [diff] [blame] | 1189 | int flags = Extension::REQUIRE_KEY; |
| 1190 | if (Extension::ShouldDoStrictErrorChecking(Extension::COMPONENT)) |
| 1191 | flags |= Extension::STRICT_ERROR_CHECKS; |
[email protected] | 61b55b6 | 2011-03-24 09:03:10 | [diff] [blame] | 1192 | std::string error; |
| 1193 | scoped_refptr<const Extension> extension(Extension::Create( |
| 1194 | info.root_directory, |
| 1195 | Extension::COMPONENT, |
| 1196 | *static_cast<DictionaryValue*>(manifest.get()), |
[email protected] | 83048a2 | 2011-03-29 00:14:13 | [diff] [blame] | 1197 | flags, |
[email protected] | 61b55b6 | 2011-03-24 09:03:10 | [diff] [blame] | 1198 | &error)); |
| 1199 | if (!extension.get()) { |
[email protected] | 0b05c26 | 2011-08-11 01:42:21 | [diff] [blame] | 1200 | LOG(ERROR) << error; |
[email protected] | a964e11 | 2011-04-14 21:52:51 | [diff] [blame] | 1201 | return NULL; |
[email protected] | 61b55b6 | 2011-03-24 09:03:10 | [diff] [blame] | 1202 | } |
| 1203 | AddExtension(extension); |
[email protected] | a964e11 | 2011-04-14 21:52:51 | [diff] [blame] | 1204 | return extension; |
[email protected] | 61b55b6 | 2011-03-24 09:03:10 | [diff] [blame] | 1205 | } |
| 1206 | |
[email protected] | ad63a79 | 2011-06-16 06:41:11 | [diff] [blame] | 1207 | void ExtensionService::UnloadComponentExtension( |
| 1208 | const ComponentExtensionInfo& info) { |
| 1209 | JSONStringValueSerializer serializer(info.manifest); |
| 1210 | scoped_ptr<Value> manifest(serializer.Deserialize(NULL, NULL)); |
| 1211 | if (!manifest.get()) { |
[email protected] | 0b05c26 | 2011-08-11 01:42:21 | [diff] [blame] | 1212 | LOG(ERROR) << "Failed to parse manifest for extension"; |
[email protected] | ad63a79 | 2011-06-16 06:41:11 | [diff] [blame] | 1213 | return; |
| 1214 | } |
| 1215 | std::string public_key; |
| 1216 | std::string public_key_bytes; |
| 1217 | std::string id; |
| 1218 | if (!static_cast<DictionaryValue*>(manifest.get())-> |
| 1219 | GetString(extension_manifest_keys::kPublicKey, &public_key) || |
| 1220 | !Extension::ParsePEMKeyBytes(public_key, &public_key_bytes) || |
| 1221 | !Extension::GenerateId(public_key_bytes, &id)) { |
[email protected] | 0b05c26 | 2011-08-11 01:42:21 | [diff] [blame] | 1222 | LOG(ERROR) << "Failed to get extension id"; |
[email protected] | ad63a79 | 2011-06-16 06:41:11 | [diff] [blame] | 1223 | return; |
| 1224 | } |
[email protected] | 814a7bf0f | 2011-08-13 05:30:59 | [diff] [blame] | 1225 | UnloadExtension(id, extension_misc::UNLOAD_REASON_DISABLE); |
[email protected] | ad63a79 | 2011-06-16 06:41:11 | [diff] [blame] | 1226 | } |
| 1227 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 1228 | void ExtensionService::LoadAllExtensions() { |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 1229 | CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
[email protected] | a315ba9 | 2010-11-16 14:12:21 | [diff] [blame] | 1230 | |
[email protected] | cc2c343 | 2009-11-06 17:24:36 | [diff] [blame] | 1231 | base::TimeTicks start_time = base::TimeTicks::Now(); |
| 1232 | |
[email protected] | 1952c7d | 2010-03-04 23:48:34 | [diff] [blame] | 1233 | // Load any component extensions. |
| 1234 | LoadComponentExtensions(); |
| 1235 | |
[email protected] | e72e8eb8 | 2009-06-18 17:21:51 | [diff] [blame] | 1236 | // Load the previously installed extensions. |
[email protected] | a315ba9 | 2010-11-16 14:12:21 | [diff] [blame] | 1237 | scoped_ptr<ExtensionPrefs::ExtensionsInfo> extensions_info( |
[email protected] | e6090e4 | 2010-03-23 22:44:08 | [diff] [blame] | 1238 | extension_prefs_->GetInstalledExtensionsInfo()); |
[email protected] | c6d474f8 | 2009-12-16 21:11:06 | [diff] [blame] | 1239 | |
[email protected] | a315ba9 | 2010-11-16 14:12:21 | [diff] [blame] | 1240 | std::vector<int> reload_reason_counts(NUM_MANIFEST_RELOAD_REASONS, 0); |
| 1241 | bool should_write_prefs = false; |
| 1242 | |
| 1243 | for (size_t i = 0; i < extensions_info->size(); ++i) { |
| 1244 | ExtensionInfo* info = extensions_info->at(i).get(); |
| 1245 | |
| 1246 | ManifestReloadReason reload_reason = ShouldReloadExtensionManifest(*info); |
| 1247 | ++reload_reason_counts[reload_reason]; |
| 1248 | UMA_HISTOGRAM_ENUMERATION("Extensions.ManifestReloadEnumValue", |
| 1249 | reload_reason, 100); |
| 1250 | |
| 1251 | if (reload_reason != NOT_NEEDED) { |
| 1252 | // Reloading and extension reads files from disk. We do this on the |
| 1253 | // UI thread because reloads should be very rare, and the complexity |
| 1254 | // added by delaying the time when the extensions service knows about |
| 1255 | // all extensions is significant. See crbug.com/37548 for details. |
| 1256 | // |allow_io| disables tests that file operations run on the file |
| 1257 | // thread. |
| 1258 | base::ThreadRestrictions::ScopedAllowIO allow_io; |
| 1259 | |
| 1260 | std::string error; |
| 1261 | scoped_refptr<const Extension> extension( |
| 1262 | extension_file_util::LoadExtension( |
[email protected] | 542258c | 2011-03-04 21:25:31 | [diff] [blame] | 1263 | info->extension_path, |
| 1264 | info->extension_location, |
[email protected] | 2af666c | 2011-10-16 16:23:19 | [diff] [blame] | 1265 | GetExtensionCreateFlagsForInstalledExtension(info), |
[email protected] | 542258c | 2011-03-04 21:25:31 | [diff] [blame] | 1266 | &error)); |
[email protected] | a315ba9 | 2010-11-16 14:12:21 | [diff] [blame] | 1267 | |
| 1268 | if (extension.get()) { |
| 1269 | extensions_info->at(i)->extension_manifest.reset( |
| 1270 | static_cast<DictionaryValue*>( |
| 1271 | extension->manifest_value()->DeepCopy())); |
| 1272 | should_write_prefs = true; |
| 1273 | } |
[email protected] | c6d474f8 | 2009-12-16 21:11:06 | [diff] [blame] | 1274 | } |
| 1275 | } |
| 1276 | |
[email protected] | a315ba9 | 2010-11-16 14:12:21 | [diff] [blame] | 1277 | for (size_t i = 0; i < extensions_info->size(); ++i) { |
| 1278 | LoadInstalledExtension(*extensions_info->at(i), should_write_prefs); |
[email protected] | c6d474f8 | 2009-12-16 21:11:06 | [diff] [blame] | 1279 | } |
| 1280 | |
[email protected] | ae09ca6 | 2009-08-21 19:46:46 | [diff] [blame] | 1281 | OnLoadedInstalledExtensions(); |
[email protected] | cc2c343 | 2009-11-06 17:24:36 | [diff] [blame] | 1282 | |
[email protected] | a315ba9 | 2010-11-16 14:12:21 | [diff] [blame] | 1283 | // The histograms Extensions.ManifestReload* allow us to validate |
| 1284 | // the assumption that reloading manifest is a rare event. |
| 1285 | UMA_HISTOGRAM_COUNTS_100("Extensions.ManifestReloadNotNeeded", |
| 1286 | reload_reason_counts[NOT_NEEDED]); |
| 1287 | UMA_HISTOGRAM_COUNTS_100("Extensions.ManifestReloadUnpackedDir", |
| 1288 | reload_reason_counts[UNPACKED_DIR]); |
| 1289 | UMA_HISTOGRAM_COUNTS_100("Extensions.ManifestReloadNeedsRelocalization", |
| 1290 | reload_reason_counts[NEEDS_RELOCALIZATION]); |
| 1291 | |
[email protected] | cc2c343 | 2009-11-06 17:24:36 | [diff] [blame] | 1292 | UMA_HISTOGRAM_COUNTS_100("Extensions.LoadAll", extensions_.size()); |
| 1293 | UMA_HISTOGRAM_COUNTS_100("Extensions.Disabled", disabled_extensions_.size()); |
| 1294 | |
[email protected] | 1952c7d | 2010-03-04 23:48:34 | [diff] [blame] | 1295 | UMA_HISTOGRAM_TIMES("Extensions.LoadAllTime", |
| 1296 | base::TimeTicks::Now() - start_time); |
[email protected] | cc2c343 | 2009-11-06 17:24:36 | [diff] [blame] | 1297 | |
[email protected] | d101c4a | 2011-07-22 22:51:36 | [diff] [blame] | 1298 | int app_user_count = 0; |
| 1299 | int app_external_count = 0; |
[email protected] | 9b21765 | 2010-10-08 22:04:23 | [diff] [blame] | 1300 | int hosted_app_count = 0; |
| 1301 | int packaged_app_count = 0; |
[email protected] | 1952c7d | 2010-03-04 23:48:34 | [diff] [blame] | 1302 | int user_script_count = 0; |
[email protected] | d101c4a | 2011-07-22 22:51:36 | [diff] [blame] | 1303 | int extension_user_count = 0; |
| 1304 | int extension_external_count = 0; |
[email protected] | 1952c7d | 2010-03-04 23:48:34 | [diff] [blame] | 1305 | int theme_count = 0; |
[email protected] | 1952c7d | 2010-03-04 23:48:34 | [diff] [blame] | 1306 | int page_action_count = 0; |
| 1307 | int browser_action_count = 0; |
| 1308 | ExtensionList::iterator ex; |
| 1309 | for (ex = extensions_.begin(); ex != extensions_.end(); ++ex) { |
[email protected] | 9b21765 | 2010-10-08 22:04:23 | [diff] [blame] | 1310 | Extension::Location location = (*ex)->location(); |
[email protected] | 7fa19f8 | 2010-12-21 19:40:08 | [diff] [blame] | 1311 | Extension::Type type = (*ex)->GetType(); |
[email protected] | 9b21765 | 2010-10-08 22:04:23 | [diff] [blame] | 1312 | if ((*ex)->is_app()) { |
| 1313 | UMA_HISTOGRAM_ENUMERATION("Extensions.AppLocation", |
| 1314 | location, 100); |
| 1315 | } else if (type == Extension::TYPE_EXTENSION) { |
| 1316 | UMA_HISTOGRAM_ENUMERATION("Extensions.ExtensionLocation", |
| 1317 | location, 100); |
| 1318 | } |
| 1319 | |
[email protected] | 1952c7d | 2010-03-04 23:48:34 | [diff] [blame] | 1320 | // Don't count component extensions, since they are only extensions as an |
| 1321 | // implementation detail. |
[email protected] | 9b21765 | 2010-10-08 22:04:23 | [diff] [blame] | 1322 | if (location == Extension::COMPONENT) |
[email protected] | 1952c7d | 2010-03-04 23:48:34 | [diff] [blame] | 1323 | continue; |
| 1324 | |
[email protected] | e8c729a | 2010-03-09 19:55:19 | [diff] [blame] | 1325 | // Don't count unpacked extensions, since they're a developer-specific |
| 1326 | // feature. |
[email protected] | 9b21765 | 2010-10-08 22:04:23 | [diff] [blame] | 1327 | if (location == Extension::LOAD) |
[email protected] | e8c729a | 2010-03-09 19:55:19 | [diff] [blame] | 1328 | continue; |
| 1329 | |
[email protected] | 9b21765 | 2010-10-08 22:04:23 | [diff] [blame] | 1330 | // Using an enumeration shows us the total installed ratio across all users. |
| 1331 | // Using the totals per user at each startup tells us the distribution of |
| 1332 | // usage for each user (e.g. 40% of users have at least one app installed). |
| 1333 | UMA_HISTOGRAM_ENUMERATION("Extensions.LoadType", type, 100); |
| 1334 | switch (type) { |
| 1335 | case Extension::TYPE_THEME: |
[email protected] | a315ba9 | 2010-11-16 14:12:21 | [diff] [blame] | 1336 | ++theme_count; |
[email protected] | 9b21765 | 2010-10-08 22:04:23 | [diff] [blame] | 1337 | break; |
| 1338 | case Extension::TYPE_USER_SCRIPT: |
[email protected] | a315ba9 | 2010-11-16 14:12:21 | [diff] [blame] | 1339 | ++user_script_count; |
[email protected] | 9b21765 | 2010-10-08 22:04:23 | [diff] [blame] | 1340 | break; |
| 1341 | case Extension::TYPE_HOSTED_APP: |
[email protected] | a315ba9 | 2010-11-16 14:12:21 | [diff] [blame] | 1342 | ++hosted_app_count; |
[email protected] | d101c4a | 2011-07-22 22:51:36 | [diff] [blame] | 1343 | if (Extension::IsExternalLocation(location)) { |
| 1344 | ++app_external_count; |
| 1345 | } else { |
| 1346 | ++app_user_count; |
| 1347 | } |
[email protected] | 9b21765 | 2010-10-08 22:04:23 | [diff] [blame] | 1348 | break; |
| 1349 | case Extension::TYPE_PACKAGED_APP: |
[email protected] | a315ba9 | 2010-11-16 14:12:21 | [diff] [blame] | 1350 | ++packaged_app_count; |
[email protected] | d101c4a | 2011-07-22 22:51:36 | [diff] [blame] | 1351 | if (Extension::IsExternalLocation(location)) { |
| 1352 | ++app_external_count; |
| 1353 | } else { |
| 1354 | ++app_user_count; |
| 1355 | } |
[email protected] | 9b21765 | 2010-10-08 22:04:23 | [diff] [blame] | 1356 | break; |
| 1357 | case Extension::TYPE_EXTENSION: |
| 1358 | default: |
[email protected] | d101c4a | 2011-07-22 22:51:36 | [diff] [blame] | 1359 | if (Extension::IsExternalLocation(location)) { |
| 1360 | ++extension_external_count; |
| 1361 | } else { |
| 1362 | ++extension_user_count; |
| 1363 | } |
[email protected] | 9b21765 | 2010-10-08 22:04:23 | [diff] [blame] | 1364 | break; |
[email protected] | cc2c343 | 2009-11-06 17:24:36 | [diff] [blame] | 1365 | } |
[email protected] | 9b21765 | 2010-10-08 22:04:23 | [diff] [blame] | 1366 | if ((*ex)->page_action() != NULL) |
[email protected] | a315ba9 | 2010-11-16 14:12:21 | [diff] [blame] | 1367 | ++page_action_count; |
[email protected] | 9b21765 | 2010-10-08 22:04:23 | [diff] [blame] | 1368 | if ((*ex)->browser_action() != NULL) |
[email protected] | a315ba9 | 2010-11-16 14:12:21 | [diff] [blame] | 1369 | ++browser_action_count; |
[email protected] | fe2dd774 | 2011-04-19 22:52:49 | [diff] [blame] | 1370 | |
| 1371 | RecordPermissionMessagesHistogram( |
| 1372 | ex->get(), "Extensions.Permissions_Load"); |
[email protected] | cc2c343 | 2009-11-06 17:24:36 | [diff] [blame] | 1373 | } |
[email protected] | d101c4a | 2011-07-22 22:51:36 | [diff] [blame] | 1374 | UMA_HISTOGRAM_COUNTS_100("Extensions.LoadApp", |
| 1375 | app_user_count + app_external_count); |
| 1376 | UMA_HISTOGRAM_COUNTS_100("Extensions.LoadAppUser", app_user_count); |
| 1377 | UMA_HISTOGRAM_COUNTS_100("Extensions.LoadAppExternal", app_external_count); |
[email protected] | 9b21765 | 2010-10-08 22:04:23 | [diff] [blame] | 1378 | UMA_HISTOGRAM_COUNTS_100("Extensions.LoadHostedApp", hosted_app_count); |
| 1379 | UMA_HISTOGRAM_COUNTS_100("Extensions.LoadPackagedApp", packaged_app_count); |
[email protected] | d101c4a | 2011-07-22 22:51:36 | [diff] [blame] | 1380 | UMA_HISTOGRAM_COUNTS_100("Extensions.LoadExtension", |
| 1381 | extension_user_count + extension_external_count); |
| 1382 | UMA_HISTOGRAM_COUNTS_100("Extensions.LoadExtensionUser", |
| 1383 | extension_user_count); |
| 1384 | UMA_HISTOGRAM_COUNTS_100("Extensions.LoadExtensionExternal", |
| 1385 | extension_external_count); |
[email protected] | 1952c7d | 2010-03-04 23:48:34 | [diff] [blame] | 1386 | UMA_HISTOGRAM_COUNTS_100("Extensions.LoadUserScript", user_script_count); |
| 1387 | UMA_HISTOGRAM_COUNTS_100("Extensions.LoadTheme", theme_count); |
[email protected] | 1952c7d | 2010-03-04 23:48:34 | [diff] [blame] | 1388 | UMA_HISTOGRAM_COUNTS_100("Extensions.LoadPageAction", page_action_count); |
| 1389 | UMA_HISTOGRAM_COUNTS_100("Extensions.LoadBrowserAction", |
| 1390 | browser_action_count); |
[email protected] | ae09ca6 | 2009-08-21 19:46:46 | [diff] [blame] | 1391 | } |
| 1392 | |
[email protected] | fe2dd774 | 2011-04-19 22:52:49 | [diff] [blame] | 1393 | // static |
| 1394 | void ExtensionService::RecordPermissionMessagesHistogram( |
| 1395 | const Extension* e, const char* histogram) { |
| 1396 | // Since this is called from multiple sources, and since the Histogram macros |
| 1397 | // use statics, we need to manually lookup the Histogram ourselves. |
| 1398 | base::Histogram* counter = base::LinearHistogram::FactoryGet( |
| 1399 | histogram, |
| 1400 | 1, |
[email protected] | 0d3e4a2 | 2011-06-23 19:02:52 | [diff] [blame] | 1401 | ExtensionPermissionMessage::kEnumBoundary, |
| 1402 | ExtensionPermissionMessage::kEnumBoundary + 1, |
[email protected] | fe2dd774 | 2011-04-19 22:52:49 | [diff] [blame] | 1403 | base::Histogram::kUmaTargetedHistogramFlag); |
| 1404 | |
[email protected] | 0d3e4a2 | 2011-06-23 19:02:52 | [diff] [blame] | 1405 | ExtensionPermissionMessages permissions = e->GetPermissionMessages(); |
[email protected] | fe2dd774 | 2011-04-19 22:52:49 | [diff] [blame] | 1406 | if (permissions.empty()) { |
[email protected] | 0d3e4a2 | 2011-06-23 19:02:52 | [diff] [blame] | 1407 | counter->Add(ExtensionPermissionMessage::kNone); |
[email protected] | fe2dd774 | 2011-04-19 22:52:49 | [diff] [blame] | 1408 | } else { |
[email protected] | 0d3e4a2 | 2011-06-23 19:02:52 | [diff] [blame] | 1409 | for (ExtensionPermissionMessages::iterator it = permissions.begin(); |
| 1410 | it != permissions.end(); ++it) |
| 1411 | counter->Add(it->id()); |
[email protected] | fe2dd774 | 2011-04-19 22:52:49 | [diff] [blame] | 1412 | } |
| 1413 | } |
| 1414 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 1415 | void ExtensionService::LoadInstalledExtension(const ExtensionInfo& info, |
[email protected] | 542258c | 2011-03-04 21:25:31 | [diff] [blame] | 1416 | bool write_to_prefs) { |
[email protected] | ae09ca6 | 2009-08-21 19:46:46 | [diff] [blame] | 1417 | std::string error; |
[email protected] | 9adb969 | 2010-10-29 23:14:02 | [diff] [blame] | 1418 | scoped_refptr<const Extension> extension(NULL); |
[email protected] | 306a2bd | 2010-08-11 14:56:36 | [diff] [blame] | 1419 | if (!extension_prefs_->IsExtensionAllowedByPolicy(info.extension_id)) { |
| 1420 | error = errors::kDisabledByPolicy; |
| 1421 | } else if (info.extension_manifest.get()) { |
[email protected] | 66e4eb3 | 2010-10-27 20:37:41 | [diff] [blame] | 1422 | extension = Extension::Create( |
[email protected] | 542258c | 2011-03-04 21:25:31 | [diff] [blame] | 1423 | info.extension_path, |
| 1424 | info.extension_location, |
| 1425 | *info.extension_manifest, |
[email protected] | 2af666c | 2011-10-16 16:23:19 | [diff] [blame] | 1426 | GetExtensionCreateFlagsForInstalledExtension(&info), |
[email protected] | 542258c | 2011-03-04 21:25:31 | [diff] [blame] | 1427 | &error); |
[email protected] | ae09ca6 | 2009-08-21 19:46:46 | [diff] [blame] | 1428 | } else { |
[email protected] | c6d474f8 | 2009-12-16 21:11:06 | [diff] [blame] | 1429 | error = errors::kManifestUnreadable; |
[email protected] | ae09ca6 | 2009-08-21 19:46:46 | [diff] [blame] | 1430 | } |
| 1431 | |
[email protected] | 199cc8bc7 | 2011-09-27 16:22:34 | [diff] [blame] | 1432 | // Once installed, non-unpacked extensions cannot change their IDs (e.g., by |
| 1433 | // updating the 'key' field in their manifest). |
| 1434 | if (extension && |
| 1435 | extension->location() != Extension::LOAD && |
| 1436 | info.extension_id != extension->id()) { |
| 1437 | error = errors::kCannotChangeExtensionID; |
| 1438 | extension = NULL; |
| 1439 | UserMetrics::RecordAction(UserMetricsAction("Extensions.IDChangedError")); |
| 1440 | } |
| 1441 | |
[email protected] | ae09ca6 | 2009-08-21 19:46:46 | [diff] [blame] | 1442 | if (!extension) { |
[email protected] | 655b2b1a | 2011-10-13 17:13:06 | [diff] [blame] | 1443 | ReportExtensionLoadError(info.extension_path, error, false); |
[email protected] | ae09ca6 | 2009-08-21 19:46:46 | [diff] [blame] | 1444 | return; |
| 1445 | } |
| 1446 | |
[email protected] | c6d474f8 | 2009-12-16 21:11:06 | [diff] [blame] | 1447 | if (write_to_prefs) |
| 1448 | extension_prefs_->UpdateManifest(extension); |
| 1449 | |
[email protected] | 49cd157 | 2011-02-08 21:38:45 | [diff] [blame] | 1450 | AddExtension(extension); |
[email protected] | 9f1087e | 2009-06-15 17:29:32 | [diff] [blame] | 1451 | } |
| 1452 | |
[email protected] | 2af666c | 2011-10-16 16:23:19 | [diff] [blame] | 1453 | int ExtensionService::GetExtensionCreateFlagsForInstalledExtension( |
| 1454 | const ExtensionInfo* info) { |
| 1455 | int flags = Extension::NO_FLAGS; |
| 1456 | if (info->extension_location != Extension::LOAD) |
| 1457 | flags |= Extension::REQUIRE_KEY; |
| 1458 | if (Extension::ShouldDoStrictErrorChecking(info->extension_location)) |
| 1459 | flags |= Extension::STRICT_ERROR_CHECKS; |
| 1460 | if (extension_prefs_->AllowFileAccess(info->extension_id)) |
| 1461 | flags |= Extension::ALLOW_FILE_ACCESS; |
| 1462 | if (extension_prefs_->IsFromWebStore(info->extension_id)) |
| 1463 | flags |= Extension::FROM_WEBSTORE; |
| 1464 | if (extension_prefs_->IsFromBookmark(info->extension_id)) |
| 1465 | flags |= Extension::FROM_BOOKMARK; |
| 1466 | return flags; |
| 1467 | } |
| 1468 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 1469 | void ExtensionService::NotifyExtensionLoaded(const Extension* extension) { |
[email protected] | 57a777f7 | 2010-03-31 01:09:42 | [diff] [blame] | 1470 | // The ChromeURLRequestContexts need to be first to know that the extension |
[email protected] | 62d30f4 | 2009-10-01 22:36:06 | [diff] [blame] | 1471 | // was loaded, otherwise a race can arise where a renderer that is created |
| 1472 | // 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] | 1473 | // that the request context doesn't yet know about. The profile is responsible |
| 1474 | // for ensuring its URLRequestContexts appropriately discover the loaded |
| 1475 | // extension. |
[email protected] | c8d407e | 2011-04-28 21:27:17 | [diff] [blame] | 1476 | profile_->RegisterExtensionWithRequestContexts(extension); |
[email protected] | 62d30f4 | 2009-10-01 22:36:06 | [diff] [blame] | 1477 | |
[email protected] | c8d407e | 2011-04-28 21:27:17 | [diff] [blame] | 1478 | // Tell subsystems that use the EXTENSION_LOADED notification about the new |
| 1479 | // extension. |
[email protected] | 62d30f4 | 2009-10-01 22:36:06 | [diff] [blame] | 1480 | NotificationService::current()->Notify( |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 1481 | chrome::NOTIFICATION_EXTENSION_LOADED, |
[email protected] | 24e7a9d | 2009-11-04 11:11:34 | [diff] [blame] | 1482 | Source<Profile>(profile_), |
[email protected] | 9adb969 | 2010-10-29 23:14:02 | [diff] [blame] | 1483 | Details<const Extension>(extension)); |
[email protected] | 2de30759 | 2011-04-05 21:16:58 | [diff] [blame] | 1484 | |
[email protected] | c8d407e | 2011-04-28 21:27:17 | [diff] [blame] | 1485 | // Tell renderers about the new extension. |
[email protected] | 77a6970c | 2011-04-23 16:58:56 | [diff] [blame] | 1486 | for (RenderProcessHost::iterator i(RenderProcessHost::AllHostsIterator()); |
| 1487 | !i.IsAtEnd(); i.Advance()) { |
[email protected] | c8d407e | 2011-04-28 21:27:17 | [diff] [blame] | 1488 | RenderProcessHost* host = i.GetCurrentValue(); |
[email protected] | 9b62ecf | 2011-07-27 20:23:08 | [diff] [blame] | 1489 | Profile* host_profile = |
| 1490 | Profile::FromBrowserContext(host->browser_context()); |
| 1491 | if (host_profile->GetOriginalProfile() == profile_->GetOriginalProfile()) { |
[email protected] | c8d407e | 2011-04-28 21:27:17 | [diff] [blame] | 1492 | host->Send( |
[email protected] | 1537964 | 2011-08-11 22:22:05 | [diff] [blame] | 1493 | new ExtensionMsg_Loaded(ExtensionMsg_Loaded_Params(extension))); |
[email protected] | c8d407e | 2011-04-28 21:27:17 | [diff] [blame] | 1494 | } |
[email protected] | 77a6970c | 2011-04-23 16:58:56 | [diff] [blame] | 1495 | } |
| 1496 | |
[email protected] | c8d407e | 2011-04-28 21:27:17 | [diff] [blame] | 1497 | // Tell a random-ass collection of other subsystems about the new extension. |
| 1498 | // TODO(aa): What should we do with all this goop? Can it move into the |
| 1499 | // relevant objects via EXTENSION_LOADED? |
| 1500 | |
| 1501 | profile_->GetExtensionSpecialStoragePolicy()-> |
| 1502 | GrantRightsForExtension(extension); |
| 1503 | |
| 1504 | UpdateActiveExtensionsInCrashReporter(); |
| 1505 | |
| 1506 | ExtensionWebUI::RegisterChromeURLOverrides( |
| 1507 | profile_, extension->GetChromeURLOverrides()); |
| 1508 | |
[email protected] | 8e5c89a | 2011-06-07 18:13:33 | [diff] [blame] | 1509 | TemplateURLService* url_service = |
| 1510 | TemplateURLServiceFactory::GetForProfile(profile_); |
| 1511 | if (url_service) |
| 1512 | url_service->RegisterExtensionKeyword(extension); |
[email protected] | c8d407e | 2011-04-28 21:27:17 | [diff] [blame] | 1513 | |
| 1514 | // Load the icon for omnibox-enabled extensions so it will be ready to display |
| 1515 | // in the URL bar. |
| 1516 | if (!extension->omnibox_keyword().empty()) { |
| 1517 | omnibox_popup_icon_manager_.LoadIcon(extension); |
| 1518 | omnibox_icon_manager_.LoadIcon(extension); |
| 1519 | } |
| 1520 | |
| 1521 | // If the extension has permission to load chrome://favicon/ resources we need |
| 1522 | // to make sure that the FaviconSource is registered with the |
| 1523 | // ChromeURLDataManager. |
| 1524 | if (extension->HasHostPermission(GURL(chrome::kChromeUIFaviconURL))) { |
| 1525 | FaviconSource* favicon_source = new FaviconSource(profile_, |
| 1526 | FaviconSource::FAVICON); |
| 1527 | profile_->GetChromeURLDataManager()->AddDataSource(favicon_source); |
| 1528 | } |
| 1529 | |
| 1530 | // TODO(mpcomplete): This ends up affecting all profiles. See crbug.com/80757. |
[email protected] | 2de30759 | 2011-04-05 21:16:58 | [diff] [blame] | 1531 | bool plugins_changed = false; |
| 1532 | for (size_t i = 0; i < extension->plugins().size(); ++i) { |
| 1533 | const Extension::PluginInfo& plugin = extension->plugins()[i]; |
| 1534 | webkit::npapi::PluginList::Singleton()->RefreshPlugins(); |
| 1535 | webkit::npapi::PluginList::Singleton()->AddExtraPluginPath(plugin.path); |
| 1536 | plugins_changed = true; |
[email protected] | 476a2703 | 2011-09-13 13:40:49 | [diff] [blame] | 1537 | ChromePluginServiceFilter* filter = |
| 1538 | ChromePluginServiceFilter::GetInstance(); |
| 1539 | if (plugin.is_public) { |
| 1540 | filter->RestrictPluginToProfileAndOrigin( |
| 1541 | plugin.path, profile_, GURL()); |
| 1542 | } else { |
| 1543 | filter->RestrictPluginToProfileAndOrigin( |
| 1544 | plugin.path, profile_, extension->url()); |
[email protected] | 2de30759 | 2011-04-05 21:16:58 | [diff] [blame] | 1545 | } |
| 1546 | } |
[email protected] | 84396dbc | 2011-04-14 06:33:42 | [diff] [blame] | 1547 | |
| 1548 | bool nacl_modules_changed = false; |
| 1549 | for (size_t i = 0; i < extension->nacl_modules().size(); ++i) { |
| 1550 | const Extension::NaClModuleInfo& module = extension->nacl_modules()[i]; |
[email protected] | cebc3dc | 2011-04-18 17:15:00 | [diff] [blame] | 1551 | RegisterNaClModule(module.url, module.mime_type); |
[email protected] | 84396dbc | 2011-04-14 06:33:42 | [diff] [blame] | 1552 | nacl_modules_changed = true; |
| 1553 | } |
| 1554 | |
[email protected] | ed0ba00 | 2011-05-26 16:55:13 | [diff] [blame] | 1555 | if (nacl_modules_changed) |
| 1556 | UpdatePluginListWithNaClModules(); |
[email protected] | 84396dbc | 2011-04-14 06:33:42 | [diff] [blame] | 1557 | |
| 1558 | if (plugins_changed || nacl_modules_changed) |
[email protected] | 45a22e6 | 2011-10-12 09:48:02 | [diff] [blame] | 1559 | PluginService::GetInstance()->PurgePluginListCache(profile_, false); |
[email protected] | b4d9d12 | 2011-06-17 01:58:54 | [diff] [blame] | 1560 | |
[email protected] | 14da67b0 | 2011-08-02 05:49:13 | [diff] [blame] | 1561 | #if defined(OS_CHROMEOS) |
| 1562 | #if defined(TOUCH_UI) |
[email protected] | c8d4e946 | 2011-06-29 23:18:57 | [diff] [blame] | 1563 | chromeos::input_method::InputMethodManager* input_method_manager = |
| 1564 | chromeos::input_method::InputMethodManager::GetInstance(); |
[email protected] | 14da67b0 | 2011-08-02 05:49:13 | [diff] [blame] | 1565 | #endif |
[email protected] | b4d9d12 | 2011-06-17 01:58:54 | [diff] [blame] | 1566 | for (std::vector<Extension::InputComponentInfo>::const_iterator component = |
| 1567 | extension->input_components().begin(); |
| 1568 | component != extension->input_components().end(); |
| 1569 | ++component) { |
[email protected] | 14da67b0 | 2011-08-02 05:49:13 | [diff] [blame] | 1570 | if (component->type == Extension::INPUT_COMPONENT_TYPE_IME) { |
| 1571 | ExtensionInputImeEventRouter::GetInstance()->RegisterIme( |
| 1572 | profile_, extension->id(), *component); |
| 1573 | } |
| 1574 | #if defined(TOUCH_UI) |
[email protected] | b4d9d12 | 2011-06-17 01:58:54 | [diff] [blame] | 1575 | if (component->type == Extension::INPUT_COMPONENT_TYPE_VIRTUAL_KEYBOARD && |
| 1576 | !component->layouts.empty()) { |
| 1577 | const bool is_system = |
| 1578 | !Extension::IsExternalLocation(extension->location()); |
[email protected] | cbd4c04 | 2011-08-13 18:22:19 | [diff] [blame] | 1579 | input_method_manager->RegisterVirtualKeyboard( |
| 1580 | extension->url(), |
| 1581 | component->name, // human-readable name of the keyboard extension. |
| 1582 | component->layouts, |
| 1583 | is_system); |
[email protected] | b4d9d12 | 2011-06-17 01:58:54 | [diff] [blame] | 1584 | } |
[email protected] | 14da67b0 | 2011-08-02 05:49:13 | [diff] [blame] | 1585 | #endif |
[email protected] | b4d9d12 | 2011-06-17 01:58:54 | [diff] [blame] | 1586 | } |
| 1587 | #endif |
[email protected] | 62d30f4 | 2009-10-01 22:36:06 | [diff] [blame] | 1588 | } |
| 1589 | |
[email protected] | a9f39a31 | 2010-12-23 22:14:27 | [diff] [blame] | 1590 | void ExtensionService::NotifyExtensionUnloaded( |
[email protected] | 814a7bf0f | 2011-08-13 05:30:59 | [diff] [blame] | 1591 | const Extension* extension, |
| 1592 | extension_misc::UnloadedExtensionReason reason) { |
[email protected] | a9f39a31 | 2010-12-23 22:14:27 | [diff] [blame] | 1593 | UnloadedExtensionInfo details(extension, reason); |
[email protected] | 62d30f4 | 2009-10-01 22:36:06 | [diff] [blame] | 1594 | NotificationService::current()->Notify( |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 1595 | chrome::NOTIFICATION_EXTENSION_UNLOADED, |
[email protected] | 24e7a9d | 2009-11-04 11:11:34 | [diff] [blame] | 1596 | Source<Profile>(profile_), |
[email protected] | a9f39a31 | 2010-12-23 22:14:27 | [diff] [blame] | 1597 | Details<UnloadedExtensionInfo>(&details)); |
[email protected] | 62d30f4 | 2009-10-01 22:36:06 | [diff] [blame] | 1598 | |
[email protected] | 77a6970c | 2011-04-23 16:58:56 | [diff] [blame] | 1599 | for (RenderProcessHost::iterator i(RenderProcessHost::AllHostsIterator()); |
| 1600 | !i.IsAtEnd(); i.Advance()) { |
[email protected] | c8d407e | 2011-04-28 21:27:17 | [diff] [blame] | 1601 | RenderProcessHost* host = i.GetCurrentValue(); |
[email protected] | 9b62ecf | 2011-07-27 20:23:08 | [diff] [blame] | 1602 | Profile* host_profile = |
| 1603 | Profile::FromBrowserContext(host->browser_context()); |
| 1604 | if (host_profile->GetOriginalProfile() == profile_->GetOriginalProfile()) |
[email protected] | c8d407e | 2011-04-28 21:27:17 | [diff] [blame] | 1605 | host->Send(new ExtensionMsg_Unloaded(extension->id())); |
[email protected] | 77a6970c | 2011-04-23 16:58:56 | [diff] [blame] | 1606 | } |
| 1607 | |
[email protected] | dd163fb0 | 2011-05-04 22:22:17 | [diff] [blame] | 1608 | profile_->UnregisterExtensionWithRequestContexts(extension->id(), reason); |
[email protected] | c8d407e | 2011-04-28 21:27:17 | [diff] [blame] | 1609 | profile_->GetExtensionSpecialStoragePolicy()-> |
| 1610 | RevokeRightsForExtension(extension); |
| 1611 | |
| 1612 | ExtensionWebUI::UnregisterChromeURLOverrides( |
| 1613 | profile_, extension->GetChromeURLOverrides()); |
| 1614 | |
[email protected] | b777b33 | 2011-04-16 04:01:08 | [diff] [blame] | 1615 | #if defined(OS_CHROMEOS) |
| 1616 | // Revoke external file access to |
[email protected] | c8d407e | 2011-04-28 21:27:17 | [diff] [blame] | 1617 | if (profile_->GetFileSystemContext() && |
| 1618 | profile_->GetFileSystemContext()->path_manager() && |
| 1619 | profile_->GetFileSystemContext()->path_manager()->external_provider()) { |
| 1620 | profile_->GetFileSystemContext()->path_manager()->external_provider()-> |
| 1621 | RevokeAccessForExtension(extension->id()); |
[email protected] | 62d30f4 | 2009-10-01 22:36:06 | [diff] [blame] | 1622 | } |
[email protected] | c8d407e | 2011-04-28 21:27:17 | [diff] [blame] | 1623 | #endif |
| 1624 | |
| 1625 | UpdateActiveExtensionsInCrashReporter(); |
[email protected] | 2de30759 | 2011-04-05 21:16:58 | [diff] [blame] | 1626 | |
| 1627 | bool plugins_changed = false; |
| 1628 | for (size_t i = 0; i < extension->plugins().size(); ++i) { |
| 1629 | const Extension::PluginInfo& plugin = extension->plugins()[i]; |
[email protected] | 14908b7 | 2011-04-20 06:54:36 | [diff] [blame] | 1630 | if (!BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
[email protected] | 704d77e | 2011-10-17 18:05:29 | [diff] [blame] | 1631 | NewRunnableFunction(&ForceShutdownPlugin, |
| 1632 | plugin.path))) |
[email protected] | 14908b7 | 2011-04-20 06:54:36 | [diff] [blame] | 1633 | NOTREACHED(); |
[email protected] | 2de30759 | 2011-04-05 21:16:58 | [diff] [blame] | 1634 | webkit::npapi::PluginList::Singleton()->RefreshPlugins(); |
| 1635 | webkit::npapi::PluginList::Singleton()->RemoveExtraPluginPath( |
| 1636 | plugin.path); |
| 1637 | plugins_changed = true; |
[email protected] | 476a2703 | 2011-09-13 13:40:49 | [diff] [blame] | 1638 | ChromePluginServiceFilter::GetInstance()->UnrestrictPlugin(plugin.path); |
[email protected] | 2de30759 | 2011-04-05 21:16:58 | [diff] [blame] | 1639 | } |
[email protected] | 84396dbc | 2011-04-14 06:33:42 | [diff] [blame] | 1640 | |
| 1641 | bool nacl_modules_changed = false; |
| 1642 | for (size_t i = 0; i < extension->nacl_modules().size(); ++i) { |
| 1643 | const Extension::NaClModuleInfo& module = extension->nacl_modules()[i]; |
[email protected] | cebc3dc | 2011-04-18 17:15:00 | [diff] [blame] | 1644 | UnregisterNaClModule(module.url); |
[email protected] | 84396dbc | 2011-04-14 06:33:42 | [diff] [blame] | 1645 | nacl_modules_changed = true; |
| 1646 | } |
| 1647 | |
[email protected] | ed0ba00 | 2011-05-26 16:55:13 | [diff] [blame] | 1648 | if (nacl_modules_changed) |
| 1649 | UpdatePluginListWithNaClModules(); |
[email protected] | 84396dbc | 2011-04-14 06:33:42 | [diff] [blame] | 1650 | |
| 1651 | if (plugins_changed || nacl_modules_changed) |
[email protected] | 45a22e6 | 2011-10-12 09:48:02 | [diff] [blame] | 1652 | PluginService::GetInstance()->PurgePluginListCache(profile_, false); |
[email protected] | 62d30f4 | 2009-10-01 22:36:06 | [diff] [blame] | 1653 | } |
| 1654 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 1655 | void ExtensionService::UpdateExtensionBlacklist( |
[email protected] | 6b75ec3 | 2009-08-14 06:37:18 | [diff] [blame] | 1656 | const std::vector<std::string>& blacklist) { |
| 1657 | // Use this set to indicate if an extension in the blacklist has been used. |
| 1658 | std::set<std::string> blacklist_set; |
| 1659 | for (unsigned int i = 0; i < blacklist.size(); ++i) { |
| 1660 | if (Extension::IdIsValid(blacklist[i])) { |
| 1661 | blacklist_set.insert(blacklist[i]); |
| 1662 | } |
| 1663 | } |
| 1664 | extension_prefs_->UpdateBlacklist(blacklist_set); |
| 1665 | std::vector<std::string> to_be_removed; |
| 1666 | // Loop current extensions, unload installed extensions. |
| 1667 | for (ExtensionList::const_iterator iter = extensions_.begin(); |
| 1668 | iter != extensions_.end(); ++iter) { |
[email protected] | 9adb969 | 2010-10-29 23:14:02 | [diff] [blame] | 1669 | const Extension* extension = (*iter); |
[email protected] | 6b75ec3 | 2009-08-14 06:37:18 | [diff] [blame] | 1670 | if (blacklist_set.find(extension->id()) != blacklist_set.end()) { |
| 1671 | to_be_removed.push_back(extension->id()); |
| 1672 | } |
| 1673 | } |
| 1674 | |
| 1675 | // UnloadExtension will change the extensions_ list. So, we should |
| 1676 | // call it outside the iterator loop. |
| 1677 | for (unsigned int i = 0; i < to_be_removed.size(); ++i) { |
[email protected] | 814a7bf0f | 2011-08-13 05:30:59 | [diff] [blame] | 1678 | UnloadExtension(to_be_removed[i], extension_misc::UNLOAD_REASON_DISABLE); |
[email protected] | 6b75ec3 | 2009-08-14 06:37:18 | [diff] [blame] | 1679 | } |
| 1680 | } |
| 1681 | |
[email protected] | 0a071a3 | 2011-02-08 00:18:24 | [diff] [blame] | 1682 | Profile* ExtensionService::profile() { |
| 1683 | return profile_; |
| 1684 | } |
| 1685 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 1686 | ExtensionPrefs* ExtensionService::extension_prefs() { |
[email protected] | ddb1e5a | 2010-12-13 20:10:45 | [diff] [blame] | 1687 | return extension_prefs_; |
| 1688 | } |
| 1689 | |
[email protected] | fc84e0e | 2011-09-27 19:18:22 | [diff] [blame] | 1690 | ExtensionSettingsFrontend* ExtensionService::extension_settings_frontend() { |
| 1691 | return &extension_settings_frontend_; |
[email protected] | b7f853e28 | 2011-08-10 09:24:20 | [diff] [blame] | 1692 | } |
| 1693 | |
[email protected] | b790b07 | 2011-05-20 09:46:44 | [diff] [blame] | 1694 | ExtensionContentSettingsStore* |
| 1695 | ExtensionService::GetExtensionContentSettingsStore() { |
| 1696 | return extension_prefs()->content_settings_store(); |
| 1697 | } |
| 1698 | |
[email protected] | 2859946f | 2011-04-04 18:18:06 | [diff] [blame] | 1699 | ExtensionUpdater* ExtensionService::updater() { |
| 1700 | return updater_.get(); |
| 1701 | } |
| 1702 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 1703 | void ExtensionService::CheckAdminBlacklist() { |
[email protected] | aa96d3a | 2010-08-21 08:45:25 | [diff] [blame] | 1704 | std::vector<std::string> to_be_removed; |
| 1705 | // Loop through extensions list, unload installed extensions. |
| 1706 | for (ExtensionList::const_iterator iter = extensions_.begin(); |
| 1707 | iter != extensions_.end(); ++iter) { |
[email protected] | 9adb969 | 2010-10-29 23:14:02 | [diff] [blame] | 1708 | const Extension* extension = (*iter); |
[email protected] | aa96d3a | 2010-08-21 08:45:25 | [diff] [blame] | 1709 | if (!extension_prefs_->IsExtensionAllowedByPolicy(extension->id())) |
| 1710 | to_be_removed.push_back(extension->id()); |
| 1711 | } |
| 1712 | |
| 1713 | // UnloadExtension will change the extensions_ list. So, we should |
| 1714 | // call it outside the iterator loop. |
| 1715 | for (unsigned int i = 0; i < to_be_removed.size(); ++i) |
[email protected] | 814a7bf0f | 2011-08-13 05:30:59 | [diff] [blame] | 1716 | UnloadExtension(to_be_removed[i], extension_misc::UNLOAD_REASON_DISABLE); |
[email protected] | aa96d3a | 2010-08-21 08:45:25 | [diff] [blame] | 1717 | } |
| 1718 | |
[email protected] | 3120660 | 2011-04-13 23:07:32 | [diff] [blame] | 1719 | void ExtensionService::CheckForUpdatesSoon() { |
[email protected] | c3cfb01 | 2011-04-06 22:07:35 | [diff] [blame] | 1720 | if (updater()) { |
[email protected] | 3120660 | 2011-04-13 23:07:32 | [diff] [blame] | 1721 | updater()->CheckSoon(); |
[email protected] | c3cfb01 | 2011-04-06 22:07:35 | [diff] [blame] | 1722 | } else { |
[email protected] | 3120660 | 2011-04-13 23:07:32 | [diff] [blame] | 1723 | LOG(WARNING) << "CheckForUpdatesSoon() called with auto-update turned off"; |
[email protected] | c3cfb01 | 2011-04-06 22:07:35 | [diff] [blame] | 1724 | } |
| 1725 | } |
| 1726 | |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 1727 | namespace { |
| 1728 | bool IsSyncableNone(const Extension& extension) { return false; } |
| 1729 | } // namespace |
| 1730 | |
| 1731 | ExtensionService::SyncBundle::SyncBundle() |
| 1732 | : filter(IsSyncableNone), |
| 1733 | sync_processor(NULL) { |
[email protected] | b05fb9ff | 2011-04-23 00:07:56 | [diff] [blame] | 1734 | } |
| 1735 | |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 1736 | ExtensionService::SyncBundle::~SyncBundle() { |
| 1737 | } |
| 1738 | |
| 1739 | bool ExtensionService::SyncBundle::HasExtensionId(const std::string& id) const { |
| 1740 | return synced_extensions.find(id) != synced_extensions.end(); |
| 1741 | } |
| 1742 | |
| 1743 | bool ExtensionService::SyncBundle::HasPendingExtensionId(const std::string& id) |
| 1744 | const { |
| 1745 | return pending_sync_data.find(id) != pending_sync_data.end(); |
| 1746 | } |
| 1747 | |
| 1748 | void ExtensionService::SyncExtensionChangeIfNeeded(const Extension& extension) { |
| 1749 | SyncBundle* sync_bundle = GetSyncBundleForExtension(extension); |
| 1750 | if (sync_bundle) { |
| 1751 | ExtensionSyncData extension_sync_data(extension, |
| 1752 | IsExtensionEnabled(extension.id()), |
| 1753 | IsIncognitoEnabled(extension.id())); |
| 1754 | |
| 1755 | SyncChangeList sync_change_list(1, extension_sync_data.GetSyncChange( |
| 1756 | sync_bundle->HasExtensionId(extension.id()) ? |
| 1757 | SyncChange::ACTION_UPDATE : SyncChange::ACTION_ADD)); |
| 1758 | sync_bundle->sync_processor->ProcessSyncChanges( |
| 1759 | FROM_HERE, sync_change_list); |
| 1760 | sync_bundle->synced_extensions.insert(extension.id()); |
| 1761 | sync_bundle->pending_sync_data.erase(extension.id()); |
[email protected] | b05fb9ff | 2011-04-23 00:07:56 | [diff] [blame] | 1762 | } |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 1763 | } |
| 1764 | |
| 1765 | ExtensionService::SyncBundle* ExtensionService::GetSyncBundleForExtension( |
| 1766 | const Extension& extension) { |
| 1767 | if (app_sync_bundle_.filter(extension)) |
| 1768 | return &app_sync_bundle_; |
| 1769 | else if (extension_sync_bundle_.filter(extension)) |
| 1770 | return &extension_sync_bundle_; |
| 1771 | else |
| 1772 | return NULL; |
| 1773 | } |
| 1774 | |
| 1775 | ExtensionService::SyncBundle* |
| 1776 | ExtensionService::GetSyncBundleForExtensionSyncData( |
| 1777 | const ExtensionSyncData& extension_sync_data) { |
| 1778 | switch (extension_sync_data.type()) { |
| 1779 | case Extension::SYNC_TYPE_APP: |
| 1780 | return &app_sync_bundle_; |
| 1781 | case Extension::SYNC_TYPE_EXTENSION: |
| 1782 | return &extension_sync_bundle_; |
| 1783 | default: |
| 1784 | NOTREACHED(); |
| 1785 | return NULL; |
| 1786 | } |
| 1787 | } |
| 1788 | |
| 1789 | #define GET_SYNC_BUNDLE_FOR_MODEL_TYPE_BODY() \ |
| 1790 | do { \ |
| 1791 | switch (type) { \ |
| 1792 | case syncable::APPS: \ |
| 1793 | return &app_sync_bundle_; \ |
| 1794 | case syncable::EXTENSIONS: \ |
| 1795 | return &extension_sync_bundle_; \ |
| 1796 | default: \ |
| 1797 | NOTREACHED(); \ |
| 1798 | return NULL; \ |
| 1799 | } \ |
| 1800 | } while (0) |
| 1801 | |
| 1802 | const ExtensionService::SyncBundle* |
| 1803 | ExtensionService::GetSyncBundleForModelTypeConst( |
| 1804 | syncable::ModelType type) const { |
| 1805 | GET_SYNC_BUNDLE_FOR_MODEL_TYPE_BODY(); |
| 1806 | } |
| 1807 | |
| 1808 | ExtensionService::SyncBundle* ExtensionService::GetSyncBundleForModelType( |
| 1809 | syncable::ModelType type) { |
| 1810 | GET_SYNC_BUNDLE_FOR_MODEL_TYPE_BODY(); |
| 1811 | } |
| 1812 | |
| 1813 | #undef GET_SYNC_BUNDLE_FOR_MODEL_TYPE_BODY |
| 1814 | |
| 1815 | SyncError ExtensionService::MergeDataAndStartSyncing( |
| 1816 | syncable::ModelType type, |
| 1817 | const SyncDataList& initial_sync_data, |
| 1818 | SyncChangeProcessor* sync_processor) { |
| 1819 | CHECK(sync_processor); |
| 1820 | |
| 1821 | SyncBundle* bundle = NULL; |
| 1822 | |
| 1823 | switch (type) { |
| 1824 | case syncable::EXTENSIONS: |
| 1825 | bundle = &extension_sync_bundle_; |
| 1826 | bundle->filter = IsSyncableExtension; |
| 1827 | break; |
| 1828 | |
| 1829 | case syncable::APPS: |
| 1830 | bundle = &app_sync_bundle_; |
| 1831 | bundle->filter = IsSyncableApp; |
| 1832 | break; |
| 1833 | |
| 1834 | default: |
| 1835 | LOG(FATAL) << "Got " << type << " ModelType"; |
| 1836 | } |
| 1837 | |
| 1838 | bundle->sync_processor = sync_processor; |
| 1839 | |
| 1840 | for (SyncDataList::const_iterator i = initial_sync_data.begin(); |
| 1841 | i != initial_sync_data.end(); |
| 1842 | ++i) { |
| 1843 | ExtensionSyncData extension_sync_data = ExtensionSyncData(*i); |
| 1844 | bundle->synced_extensions.insert(extension_sync_data.id()); |
| 1845 | ProcessExtensionSyncData(extension_sync_data, *bundle); |
| 1846 | } |
| 1847 | |
| 1848 | SyncDataList sync_data_list = GetAllSyncData(type); |
| 1849 | SyncChangeList sync_change_list; |
| 1850 | for (SyncDataList::const_iterator i = sync_data_list.begin(); |
| 1851 | i != sync_data_list.end(); |
| 1852 | ++i) { |
| 1853 | if (bundle->HasExtensionId(i->GetTag())) |
| 1854 | sync_change_list.push_back(SyncChange(SyncChange::ACTION_UPDATE, *i)); |
| 1855 | else |
| 1856 | sync_change_list.push_back(SyncChange(SyncChange::ACTION_ADD, *i)); |
| 1857 | } |
| 1858 | bundle->sync_processor->ProcessSyncChanges(FROM_HERE, sync_change_list); |
| 1859 | |
| 1860 | return SyncError(); |
| 1861 | } |
| 1862 | |
| 1863 | void ExtensionService::StopSyncing(syncable::ModelType type) { |
| 1864 | SyncBundle* bundle = GetSyncBundleForModelType(type); |
| 1865 | CHECK(bundle); |
| 1866 | // This is the simplest way to clear out the bundle. |
| 1867 | *bundle = SyncBundle(); |
| 1868 | } |
| 1869 | |
| 1870 | SyncDataList ExtensionService::GetAllSyncData(syncable::ModelType type) const { |
| 1871 | const SyncBundle* bundle = GetSyncBundleForModelTypeConst(type); |
| 1872 | CHECK(bundle); |
| 1873 | std::vector<ExtensionSyncData> extension_sync_data = GetSyncDataList(*bundle); |
| 1874 | SyncDataList result(extension_sync_data.size()); |
| 1875 | for (int i = 0; i < static_cast<int>(extension_sync_data.size()); ++i) { |
| 1876 | result[i] = extension_sync_data[i].GetSyncData(); |
| 1877 | } |
| 1878 | return result; |
| 1879 | } |
| 1880 | |
| 1881 | SyncError ExtensionService::ProcessSyncChanges( |
| 1882 | const tracked_objects::Location& from_here, |
| 1883 | const SyncChangeList& change_list) { |
| 1884 | for (SyncChangeList::const_iterator i = change_list.begin(); |
| 1885 | i != change_list.end(); |
| 1886 | ++i) { |
| 1887 | ExtensionSyncData extension_sync_data = ExtensionSyncData(*i); |
| 1888 | SyncBundle* bundle = GetSyncBundleForExtensionSyncData(extension_sync_data); |
| 1889 | CHECK(bundle); |
| 1890 | |
| 1891 | if (extension_sync_data.uninstalled()) |
| 1892 | bundle->synced_extensions.erase(extension_sync_data.id()); |
| 1893 | else |
| 1894 | bundle->synced_extensions.insert(extension_sync_data.id()); |
| 1895 | ProcessExtensionSyncData(extension_sync_data, *bundle); |
| 1896 | } |
| 1897 | |
| 1898 | return SyncError(); |
[email protected] | b05fb9ff | 2011-04-23 00:07:56 | [diff] [blame] | 1899 | } |
| 1900 | |
| 1901 | void ExtensionService::GetSyncDataListHelper( |
| 1902 | const ExtensionList& extensions, |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 1903 | const SyncBundle& bundle, |
[email protected] | b05fb9ff | 2011-04-23 00:07:56 | [diff] [blame] | 1904 | std::vector<ExtensionSyncData>* sync_data_list) const { |
| 1905 | for (ExtensionList::const_iterator it = extensions.begin(); |
| 1906 | it != extensions.end(); ++it) { |
| 1907 | const Extension& extension = **it; |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 1908 | if (bundle.filter(extension) && |
| 1909 | // If we have pending extension data for this extension, then this |
| 1910 | // version is out of date. We'll sync back the version we got from |
| 1911 | // sync. |
| 1912 | !bundle.HasPendingExtensionId(extension.id())) { |
| 1913 | sync_data_list->push_back( |
| 1914 | ExtensionSyncData(extension, |
| 1915 | IsExtensionEnabled(extension.id()), |
| 1916 | IsIncognitoEnabled(extension.id()))); |
[email protected] | b05fb9ff | 2011-04-23 00:07:56 | [diff] [blame] | 1917 | } |
| 1918 | } |
| 1919 | } |
| 1920 | |
| 1921 | std::vector<ExtensionSyncData> ExtensionService::GetSyncDataList( |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 1922 | const SyncBundle& bundle) const { |
| 1923 | std::vector<ExtensionSyncData> extension_sync_list; |
| 1924 | GetSyncDataListHelper(extensions_, bundle, &extension_sync_list); |
| 1925 | GetSyncDataListHelper(disabled_extensions_, bundle, &extension_sync_list); |
| 1926 | GetSyncDataListHelper(terminated_extensions_, bundle, &extension_sync_list); |
| 1927 | |
| 1928 | for (std::map<std::string, ExtensionSyncData>::const_iterator i = |
| 1929 | bundle.pending_sync_data.begin(); |
| 1930 | i != bundle.pending_sync_data.end(); |
| 1931 | ++i) { |
| 1932 | extension_sync_list.push_back(i->second); |
| 1933 | } |
| 1934 | |
| 1935 | return extension_sync_list; |
[email protected] | b05fb9ff | 2011-04-23 00:07:56 | [diff] [blame] | 1936 | } |
| 1937 | |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 1938 | void ExtensionService::ProcessExtensionSyncData( |
[email protected] | 90310d9 | 2011-04-17 07:35:04 | [diff] [blame] | 1939 | const ExtensionSyncData& extension_sync_data, |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 1940 | SyncBundle& bundle) { |
| 1941 | const std::string& id = extension_sync_data.id(); |
[email protected] | 96e989b | 2011-08-30 19:35:06 | [diff] [blame] | 1942 | const Extension* extension = GetInstalledExtension(id); |
| 1943 | |
| 1944 | // TODO(bolms): we should really handle this better. The particularly bad |
| 1945 | // case is where an app becomes an extension or vice versa, and we end up with |
| 1946 | // a zombie extension that won't go away. |
| 1947 | if (extension && !bundle.filter(*extension)) |
| 1948 | return; |
[email protected] | 90310d9 | 2011-04-17 07:35:04 | [diff] [blame] | 1949 | |
| 1950 | // Handle uninstalls first. |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 1951 | if (extension_sync_data.uninstalled()) { |
[email protected] | 90310d9 | 2011-04-17 07:35:04 | [diff] [blame] | 1952 | std::string error; |
| 1953 | if (!UninstallExtensionHelper(this, id)) { |
| 1954 | LOG(WARNING) << "Could not uninstall extension " << id |
| 1955 | << " for sync"; |
| 1956 | } |
| 1957 | return; |
| 1958 | } |
| 1959 | |
[email protected] | 06f9256 | 2011-04-29 19:27:31 | [diff] [blame] | 1960 | // Set user settings. |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 1961 | if (extension_sync_data.enabled()) { |
[email protected] | 06f9256 | 2011-04-29 19:27:31 | [diff] [blame] | 1962 | EnableExtension(id); |
| 1963 | } else { |
| 1964 | DisableExtension(id); |
| 1965 | } |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 1966 | SetIsIncognitoEnabled(id, extension_sync_data.incognito_enabled()); |
[email protected] | 81b14cc | 2011-04-29 00:39:37 | [diff] [blame] | 1967 | |
[email protected] | 90310d9 | 2011-04-17 07:35:04 | [diff] [blame] | 1968 | if (extension) { |
[email protected] | 06f9256 | 2011-04-29 19:27:31 | [diff] [blame] | 1969 | // If the extension is already installed, check if it's outdated. |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 1970 | int result = extension->version()->CompareTo(extension_sync_data.version()); |
[email protected] | 90310d9 | 2011-04-17 07:35:04 | [diff] [blame] | 1971 | if (result < 0) { |
| 1972 | // Extension is outdated. |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 1973 | bundle.pending_sync_data[extension_sync_data.id()] = extension_sync_data; |
[email protected] | 90310d9 | 2011-04-17 07:35:04 | [diff] [blame] | 1974 | CheckForUpdatesSoon(); |
[email protected] | 90310d9 | 2011-04-17 07:35:04 | [diff] [blame] | 1975 | } |
[email protected] | 06f9256 | 2011-04-29 19:27:31 | [diff] [blame] | 1976 | } else { |
[email protected] | 06f9256 | 2011-04-29 19:27:31 | [diff] [blame] | 1977 | // TODO(akalin): Replace silent update with a list of enabled |
| 1978 | // permissions. |
[email protected] | 6cc7dbae | 2011-04-29 21:18:33 | [diff] [blame] | 1979 | const bool kInstallSilently = true; |
[email protected] | 06f9256 | 2011-04-29 19:27:31 | [diff] [blame] | 1980 | if (!pending_extension_manager()->AddFromSync( |
| 1981 | id, |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 1982 | extension_sync_data.update_url(), |
| 1983 | bundle.filter, |
[email protected] | 6cc7dbae | 2011-04-29 21:18:33 | [diff] [blame] | 1984 | kInstallSilently)) { |
[email protected] | 06f9256 | 2011-04-29 19:27:31 | [diff] [blame] | 1985 | LOG(WARNING) << "Could not add pending extension for " << id; |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 1986 | // This means that the extension is already pending installation, with a |
| 1987 | // non-INTERNAL location. Add to pending_sync_data, even though it will |
| 1988 | // never be removed (we'll never install a syncable version of the |
| 1989 | // extension), so that GetAllSyncData() continues to send it. |
[email protected] | 06f9256 | 2011-04-29 19:27:31 | [diff] [blame] | 1990 | } |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 1991 | // Track pending extensions so that we can return them in GetAllSyncData(). |
| 1992 | bundle.pending_sync_data[extension_sync_data.id()] = extension_sync_data; |
[email protected] | 06f9256 | 2011-04-29 19:27:31 | [diff] [blame] | 1993 | CheckForUpdatesSoon(); |
[email protected] | 90310d9 | 2011-04-17 07:35:04 | [diff] [blame] | 1994 | } |
[email protected] | 90310d9 | 2011-04-17 07:35:04 | [diff] [blame] | 1995 | } |
| 1996 | |
[email protected] | c3cfb01 | 2011-04-06 22:07:35 | [diff] [blame] | 1997 | bool ExtensionService::IsIncognitoEnabled( |
| 1998 | const std::string& extension_id) const { |
| 1999 | // If this is an existing component extension we always allow it to |
| 2000 | // work in incognito mode. |
[email protected] | 81b14cc | 2011-04-29 00:39:37 | [diff] [blame] | 2001 | const Extension* extension = GetInstalledExtension(extension_id); |
[email protected] | c3cfb01 | 2011-04-06 22:07:35 | [diff] [blame] | 2002 | if (extension && extension->location() == Extension::COMPONENT) |
[email protected] | cb0ce1e02 | 2010-03-10 19:54:41 | [diff] [blame] | 2003 | return true; |
| 2004 | |
| 2005 | // Check the prefs. |
[email protected] | c3cfb01 | 2011-04-06 22:07:35 | [diff] [blame] | 2006 | return extension_prefs_->IsIncognitoEnabled(extension_id); |
[email protected] | db7331a | 2010-02-25 22:10:50 | [diff] [blame] | 2007 | } |
[email protected] | 55a3569 | 2010-02-11 23:25:21 | [diff] [blame] | 2008 | |
[email protected] | c3cfb01 | 2011-04-06 22:07:35 | [diff] [blame] | 2009 | void ExtensionService::SetIsIncognitoEnabled( |
| 2010 | const std::string& extension_id, bool enabled) { |
[email protected] | 81b14cc | 2011-04-29 00:39:37 | [diff] [blame] | 2011 | const Extension* extension = GetInstalledExtension(extension_id); |
[email protected] | c3cfb01 | 2011-04-06 22:07:35 | [diff] [blame] | 2012 | if (extension && extension->location() == Extension::COMPONENT) { |
| 2013 | // This shouldn't be called for component extensions. |
| 2014 | NOTREACHED(); |
| 2015 | return; |
| 2016 | } |
| 2017 | |
[email protected] | 8c6c8c2 | 2011-03-09 12:52:34 | [diff] [blame] | 2018 | // Broadcast unloaded and loaded events to update browser state. Only bother |
| 2019 | // if the value changed and the extension is actually enabled, since there is |
| 2020 | // no UI otherwise. |
[email protected] | c3cfb01 | 2011-04-06 22:07:35 | [diff] [blame] | 2021 | bool old_enabled = extension_prefs_->IsIncognitoEnabled(extension_id); |
[email protected] | 8c6c8c2 | 2011-03-09 12:52:34 | [diff] [blame] | 2022 | if (enabled == old_enabled) |
| 2023 | return; |
| 2024 | |
[email protected] | c3cfb01 | 2011-04-06 22:07:35 | [diff] [blame] | 2025 | extension_prefs_->SetIsIncognitoEnabled(extension_id, enabled); |
[email protected] | 81b14cc | 2011-04-29 00:39:37 | [diff] [blame] | 2026 | |
| 2027 | // If the extension is enabled (and not terminated), unload and |
| 2028 | // reload it to update UI. |
| 2029 | const Extension* enabled_extension = GetExtensionById(extension_id, false); |
| 2030 | if (enabled_extension) { |
[email protected] | 814a7bf0f | 2011-08-13 05:30:59 | [diff] [blame] | 2031 | NotifyExtensionUnloaded( |
| 2032 | enabled_extension, extension_misc::UNLOAD_REASON_DISABLE); |
[email protected] | 81b14cc | 2011-04-29 00:39:37 | [diff] [blame] | 2033 | NotifyExtensionLoaded(enabled_extension); |
[email protected] | 568f33d | 2010-08-04 17:06:41 | [diff] [blame] | 2034 | } |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 2035 | |
| 2036 | if (extension) |
| 2037 | SyncExtensionChangeIfNeeded(*extension); |
[email protected] | 55a3569 | 2010-02-11 23:25:21 | [diff] [blame] | 2038 | } |
| 2039 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2040 | bool ExtensionService::CanCrossIncognito(const Extension* extension) { |
[email protected] | 2a8f24e | 2010-11-03 21:37:05 | [diff] [blame] | 2041 | // We allow the extension to see events and data from another profile iff it |
| 2042 | // uses "spanning" behavior and it has incognito access. "split" mode |
| 2043 | // extensions only see events for a matching profile. |
[email protected] | 0c41298f | 2011-09-13 21:17:22 | [diff] [blame] | 2044 | CHECK(extension); |
[email protected] | c3cfb01 | 2011-04-06 22:07:35 | [diff] [blame] | 2045 | return IsIncognitoEnabled(extension->id()) && |
| 2046 | !extension->incognito_split_mode(); |
[email protected] | 2a8f24e | 2010-11-03 21:37:05 | [diff] [blame] | 2047 | } |
| 2048 | |
[email protected] | 5ef7b00 | 2011-05-12 23:16:20 | [diff] [blame] | 2049 | bool ExtensionService::CanLoadInIncognito(const Extension* extension) const { |
| 2050 | if (extension->is_hosted_app()) |
| 2051 | return true; |
| 2052 | // Packaged apps and regular extensions need to be enabled specifically for |
| 2053 | // incognito (and split mode should be set). |
| 2054 | return extension->incognito_split_mode() && |
| 2055 | IsIncognitoEnabled(extension->id()); |
| 2056 | } |
| 2057 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2058 | bool ExtensionService::AllowFileAccess(const Extension* extension) { |
[email protected] | 05c8218 | 2010-06-24 17:49:08 | [diff] [blame] | 2059 | return (CommandLine::ForCurrentProcess()->HasSwitch( |
[email protected] | 334e04a | 2010-06-24 23:34:44 | [diff] [blame] | 2060 | switches::kDisableExtensionsFileAccessCheck) || |
[email protected] | 05c8218 | 2010-06-24 17:49:08 | [diff] [blame] | 2061 | extension_prefs_->AllowFileAccess(extension->id())); |
| 2062 | } |
| 2063 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2064 | void ExtensionService::SetAllowFileAccess(const Extension* extension, |
[email protected] | 3aff9ad | 2011-04-01 20:26:48 | [diff] [blame] | 2065 | bool allow) { |
| 2066 | // Reload to update browser state. Only bother if the value changed and the |
| 2067 | // extension is actually enabled, since there is no UI otherwise. |
| 2068 | bool old_allow = AllowFileAccess(extension); |
| 2069 | if (allow == old_allow) |
| 2070 | return; |
| 2071 | |
[email protected] | 05c8218 | 2010-06-24 17:49:08 | [diff] [blame] | 2072 | extension_prefs_->SetAllowFileAccess(extension->id(), allow); |
[email protected] | 3aff9ad | 2011-04-01 20:26:48 | [diff] [blame] | 2073 | |
| 2074 | bool extension_is_enabled = std::find(extensions_.begin(), extensions_.end(), |
| 2075 | extension) != extensions_.end(); |
| 2076 | if (extension_is_enabled) |
| 2077 | ReloadExtension(extension->id()); |
[email protected] | 05c8218 | 2010-06-24 17:49:08 | [diff] [blame] | 2078 | } |
| 2079 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2080 | bool ExtensionService::GetBrowserActionVisibility(const Extension* extension) { |
[email protected] | f681c78 | 2010-11-19 11:19:39 | [diff] [blame] | 2081 | return extension_prefs_->GetBrowserActionVisibility(extension); |
| 2082 | } |
| 2083 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2084 | void ExtensionService::SetBrowserActionVisibility(const Extension* extension, |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 2085 | bool visible) { |
[email protected] | f681c78 | 2010-11-19 11:19:39 | [diff] [blame] | 2086 | extension_prefs_->SetBrowserActionVisibility(extension, visible); |
| 2087 | } |
| 2088 | |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 2089 | // Some extensions will autoupdate themselves externally from Chrome. These |
| 2090 | // are typically part of some larger client application package. To support |
| 2091 | // these, the extension will register its location in the the preferences file |
| 2092 | // (and also, on Windows, in the registry) and this code will periodically |
| 2093 | // check that location for a .crx file, which it will then install locally if |
| 2094 | // a new version is available. |
| 2095 | // Errors are reported through ExtensionErrorReporter. Succcess is not |
| 2096 | // reported. |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2097 | void ExtensionService::CheckForExternalUpdates() { |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 2098 | CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 2099 | |
| 2100 | // Note that this installation is intentionally silent (since it didn't |
| 2101 | // go through the front-end). Extensions that are registered in this |
| 2102 | // way are effectively considered 'pre-bundled', and so implicitly |
| 2103 | // trusted. In general, if something has HKLM or filesystem access, |
| 2104 | // they could install an extension manually themselves anyway. |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 2105 | |
| 2106 | // If any external extension records give a URL, a provider will set |
| 2107 | // this to true. Used by OnExternalProviderReady() to see if we need |
| 2108 | // to start an update check to fetch a new external extension. |
| 2109 | external_extension_url_added_ = false; |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 2110 | |
| 2111 | // Ask each external extension provider to give us a call back for each |
| 2112 | // extension they know about. See OnExternalExtension(File|UpdateUrl)Found. |
| 2113 | ProviderCollection::const_iterator i; |
| 2114 | for (i = external_extension_providers_.begin(); |
| 2115 | i != external_extension_providers_.end(); ++i) { |
| 2116 | ExternalExtensionProviderInterface* provider = i->get(); |
| 2117 | provider->VisitRegisteredExtension(); |
| 2118 | } |
| 2119 | |
| 2120 | // Uninstall of unclaimed extensions will happen after all the providers |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 2121 | // had reported ready. Every provider calls OnExternalProviderReady() |
| 2122 | // when it finishes, and OnExternalProviderReady() only acts when all |
| 2123 | // providers are ready. In case there are no providers, we call it |
| 2124 | // to trigger removal of extensions that used to have an external source. |
| 2125 | if (external_extension_providers_.empty()) |
| 2126 | OnExternalProviderReady(); |
[email protected] | 9f1087e | 2009-06-15 17:29:32 | [diff] [blame] | 2127 | } |
| 2128 | |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 2129 | void ExtensionService::OnExternalProviderReady() { |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 2130 | CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 2131 | |
| 2132 | // An external provider has finished loading. We only take action |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 2133 | // if all of them are finished. So we check them first. |
| 2134 | ProviderCollection::const_iterator i; |
| 2135 | for (i = external_extension_providers_.begin(); |
| 2136 | i != external_extension_providers_.end(); ++i) { |
| 2137 | ExternalExtensionProviderInterface* provider = i->get(); |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 2138 | if (!provider->IsReady()) |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 2139 | return; |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 2140 | } |
| 2141 | |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 2142 | // All the providers are ready. Install any pending extensions. |
| 2143 | if (external_extension_url_added_ && updater()) { |
| 2144 | external_extension_url_added_ = false; |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 2145 | updater()->CheckNow(); |
| 2146 | } |
| 2147 | |
| 2148 | // Uninstall all the unclaimed extensions. |
| 2149 | scoped_ptr<ExtensionPrefs::ExtensionsInfo> extensions_info( |
| 2150 | extension_prefs_->GetInstalledExtensionsInfo()); |
| 2151 | for (size_t i = 0; i < extensions_info->size(); ++i) { |
| 2152 | ExtensionInfo* info = extensions_info->at(i).get(); |
| 2153 | if (Extension::IsExternalLocation(info->extension_location)) |
| 2154 | CheckExternalUninstall(info->extension_id); |
| 2155 | } |
[email protected] | e5af875f | 2011-10-10 21:09:14 | [diff] [blame] | 2156 | IdentifyAlertableExtensions(); |
[email protected] | e5af875f | 2011-10-10 21:09:14 | [diff] [blame] | 2157 | } |
| 2158 | |
| 2159 | void ExtensionService::IdentifyAlertableExtensions() { |
[email protected] | d1282c2 | 2011-10-18 02:00:39 | [diff] [blame] | 2160 | #if 0 // TODO(miket): enable upon completion of feature. |
[email protected] | e5af875f | 2011-10-10 21:09:14 | [diff] [blame] | 2161 | CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 2162 | |
| 2163 | // Build up the lists of extensions that require acknowledgment. |
| 2164 | // If this is the first time, grandfather extensions that would have |
| 2165 | // caused notification. |
| 2166 | scoped_ptr<ExtensionGlobalError> global_error( |
| 2167 | new ExtensionGlobalError(weak_ptr_factory_.GetWeakPtr())); |
| 2168 | bool needs_alert = false; |
| 2169 | for (ExtensionList::const_iterator iter = extensions_.begin(); |
| 2170 | iter != extensions_.end(); ++iter) { |
| 2171 | const Extension* e = *iter; |
| 2172 | if (!IsExtensionEnabled(e->id())) { |
| 2173 | continue; |
| 2174 | } |
| 2175 | if (Extension::IsExternalLocation(e->location())) { |
| 2176 | if (!extension_prefs_->IsExternalExtensionAcknowledged(e->id())) { |
| 2177 | global_error->AddExternalExtension(e->id()); |
| 2178 | needs_alert = true; |
| 2179 | } |
| 2180 | } |
| 2181 | if (extension_prefs_->IsExtensionBlacklisted(e->id())) { |
| 2182 | if (!extension_prefs_->IsBlacklistedExtensionAcknowledged(e->id())) { |
| 2183 | global_error->AddBlacklistedExtension(e->id()); |
| 2184 | needs_alert = true; |
| 2185 | } |
| 2186 | } |
| 2187 | if (extension_prefs_->IsExtensionOrphaned(e->id())) { |
| 2188 | if (!extension_prefs_->IsOrphanedExtensionAcknowledged(e->id())) { |
| 2189 | global_error->AddOrphanedExtension(e->id()); |
| 2190 | needs_alert = true; |
| 2191 | } |
| 2192 | } |
| 2193 | } |
| 2194 | |
| 2195 | if (needs_alert) { |
| 2196 | if (extension_prefs_->SetAlertSystemFirstRun()) { |
| 2197 | global_error->set_accept_callback( |
| 2198 | base::Bind(&ExtensionService::HandleExtensionAlertAccept, |
| 2199 | base::Unretained(this))); |
| 2200 | global_error->set_cancel_callback( |
| 2201 | base::Bind(&ExtensionService::HandleExtensionAlertDetails, |
| 2202 | base::Unretained(this))); |
[email protected] | 62433d3 | 2011-10-12 22:33:12 | [diff] [blame] | 2203 | ShowExtensionAlert(global_error.release()); |
[email protected] | e5af875f | 2011-10-10 21:09:14 | [diff] [blame] | 2204 | } else { |
| 2205 | // First run. Just acknowledge all the extensions, silently, by |
| 2206 | // shortcutting the display of the UI and going straight to the |
| 2207 | // callback for pressing the Accept button. |
[email protected] | 62433d3 | 2011-10-12 22:33:12 | [diff] [blame] | 2208 | HandleExtensionAlertAccept(*global_error.get(), NULL); |
[email protected] | e5af875f | 2011-10-10 21:09:14 | [diff] [blame] | 2209 | } |
| 2210 | } |
[email protected] | d1282c2 | 2011-10-18 02:00:39 | [diff] [blame] | 2211 | #endif |
[email protected] | e5af875f | 2011-10-10 21:09:14 | [diff] [blame] | 2212 | } |
| 2213 | |
[email protected] | 62433d3 | 2011-10-12 22:33:12 | [diff] [blame] | 2214 | void ExtensionService::ShowExtensionAlert(ExtensionGlobalError* global_error) { |
| 2215 | CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 2216 | Browser* browser = BrowserList::GetLastActiveWithProfile(profile_); |
| 2217 | if (browser) { |
| 2218 | global_error->ShowBubbleView(browser); |
| 2219 | } |
| 2220 | } |
| 2221 | |
[email protected] | e5af875f | 2011-10-10 21:09:14 | [diff] [blame] | 2222 | void ExtensionService::HandleExtensionAlertAccept( |
[email protected] | 62433d3 | 2011-10-12 22:33:12 | [diff] [blame] | 2223 | const ExtensionGlobalError& global_error, Browser* browser) { |
[email protected] | e5af875f | 2011-10-10 21:09:14 | [diff] [blame] | 2224 | const ExtensionIdSet *extension_ids = |
| 2225 | global_error.get_external_extension_ids(); |
| 2226 | for (ExtensionIdSet::const_iterator iter = extension_ids->begin(); |
| 2227 | iter != extension_ids->end(); ++iter) { |
| 2228 | extension_prefs_->AcknowledgeExternalExtension(*iter); |
| 2229 | } |
| 2230 | extension_ids = global_error.get_blacklisted_extension_ids(); |
| 2231 | for (ExtensionIdSet::const_iterator iter = extension_ids->begin(); |
| 2232 | iter != extension_ids->end(); ++iter) { |
| 2233 | extension_prefs_->AcknowledgeBlacklistedExtension(*iter); |
| 2234 | } |
| 2235 | extension_ids = global_error.get_orphaned_extension_ids(); |
| 2236 | for (ExtensionIdSet::const_iterator iter = extension_ids->begin(); |
| 2237 | iter != extension_ids->end(); ++iter) { |
| 2238 | extension_prefs_->AcknowledgeOrphanedExtension(*iter); |
| 2239 | } |
| 2240 | } |
| 2241 | |
| 2242 | void ExtensionService::HandleExtensionAlertDetails( |
[email protected] | 62433d3 | 2011-10-12 22:33:12 | [diff] [blame] | 2243 | const ExtensionGlobalError& global_error, Browser* browser) { |
| 2244 | if (browser) { |
| 2245 | browser->ShowExtensionsTab(); |
| 2246 | } |
[email protected] | 6c751e7 | 2010-11-23 10:11:10 | [diff] [blame] | 2247 | } |
| 2248 | |
[email protected] | a9f39a31 | 2010-12-23 22:14:27 | [diff] [blame] | 2249 | void ExtensionService::UnloadExtension( |
| 2250 | const std::string& extension_id, |
[email protected] | 814a7bf0f | 2011-08-13 05:30:59 | [diff] [blame] | 2251 | extension_misc::UnloadedExtensionReason reason) { |
[email protected] | 27e469a | 2010-01-11 20:35:09 | [diff] [blame] | 2252 | // Make sure the extension gets deleted after we return from this function. |
[email protected] | 9adb969 | 2010-10-29 23:14:02 | [diff] [blame] | 2253 | scoped_refptr<const Extension> extension( |
[email protected] | 8001df2 | 2011-04-28 19:59:47 | [diff] [blame] | 2254 | GetExtensionByIdInternal(extension_id, true, true, false)); |
[email protected] | 631cf82 | 2009-05-15 07:01:25 | [diff] [blame] | 2255 | |
[email protected] | fa0c9673 | 2010-11-17 00:14:23 | [diff] [blame] | 2256 | // This method can be called via PostTask, so the extension may have been |
| 2257 | // unloaded by the time this runs. |
[email protected] | dd163fb0 | 2011-05-04 22:22:17 | [diff] [blame] | 2258 | if (!extension) { |
| 2259 | // In case the extension may have crashed/uninstalled. Allow the profile to |
| 2260 | // clean up its RequestContexts. |
| 2261 | profile_->UnregisterExtensionWithRequestContexts(extension_id, reason); |
[email protected] | fa0c9673 | 2010-11-17 00:14:23 | [diff] [blame] | 2262 | return; |
[email protected] | dd163fb0 | 2011-05-04 22:22:17 | [diff] [blame] | 2263 | } |
[email protected] | 0c6da50 | 2009-08-14 22:32:39 | [diff] [blame] | 2264 | |
[email protected] | 1eb17508 | 2010-02-10 09:26:16 | [diff] [blame] | 2265 | // Keep information about the extension so that we can reload it later |
| 2266 | // even if it's not permanently installed. |
| 2267 | unloaded_extension_paths_[extension->id()] = extension->path(); |
| 2268 | |
[email protected] | f17dbd4 | 2010-08-16 23:21:10 | [diff] [blame] | 2269 | // Clean up if the extension is meant to be enabled after a reload. |
| 2270 | disabled_extension_paths_.erase(extension->id()); |
| 2271 | |
[email protected] | d7e9a86 | 2010-11-03 21:57:49 | [diff] [blame] | 2272 | // Clean up runtime data. |
| 2273 | extension_runtime_data_.erase(extension_id); |
| 2274 | |
[email protected] | 0c6da50 | 2009-08-14 22:32:39 | [diff] [blame] | 2275 | ExtensionList::iterator iter = std::find(disabled_extensions_.begin(), |
| 2276 | disabled_extensions_.end(), |
| 2277 | extension.get()); |
| 2278 | if (iter != disabled_extensions_.end()) { |
[email protected] | a9f39a31 | 2010-12-23 22:14:27 | [diff] [blame] | 2279 | UnloadedExtensionInfo details(extension, reason); |
| 2280 | details.already_disabled = true; |
[email protected] | 0c6da50 | 2009-08-14 22:32:39 | [diff] [blame] | 2281 | disabled_extensions_.erase(iter); |
[email protected] | 86693068 | 2009-08-18 22:53:47 | [diff] [blame] | 2282 | NotificationService::current()->Notify( |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 2283 | chrome::NOTIFICATION_EXTENSION_UNLOADED, |
[email protected] | 24e7a9d | 2009-11-04 11:11:34 | [diff] [blame] | 2284 | Source<Profile>(profile_), |
[email protected] | a9f39a31 | 2010-12-23 22:14:27 | [diff] [blame] | 2285 | Details<UnloadedExtensionInfo>(&details)); |
[email protected] | dd163fb0 | 2011-05-04 22:22:17 | [diff] [blame] | 2286 | // Make sure the profile cleans up its RequestContexts when an already |
| 2287 | // disabled extension is unloaded (since they are also tracking the disabled |
| 2288 | // extensions). |
| 2289 | profile_->UnregisterExtensionWithRequestContexts(extension_id, reason); |
[email protected] | 0c6da50 | 2009-08-14 22:32:39 | [diff] [blame] | 2290 | return; |
| 2291 | } |
| 2292 | |
| 2293 | iter = std::find(extensions_.begin(), extensions_.end(), extension.get()); |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 2294 | |
[email protected] | 631cf82 | 2009-05-15 07:01:25 | [diff] [blame] | 2295 | // Remove the extension from our list. |
| 2296 | extensions_.erase(iter); |
| 2297 | |
[email protected] | a9f39a31 | 2010-12-23 22:14:27 | [diff] [blame] | 2298 | NotifyExtensionUnloaded(extension.get(), reason); |
[email protected] | 631cf82 | 2009-05-15 07:01:25 | [diff] [blame] | 2299 | } |
| 2300 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2301 | void ExtensionService::UnloadAllExtensions() { |
[email protected] | c8d407e | 2011-04-28 21:27:17 | [diff] [blame] | 2302 | profile_->GetExtensionSpecialStoragePolicy()-> |
| 2303 | RevokeRightsForAllExtensions(); |
| 2304 | |
[email protected] | 9f1087e | 2009-06-15 17:29:32 | [diff] [blame] | 2305 | extensions_.clear(); |
[email protected] | cd500f7 | 2010-06-25 23:44:32 | [diff] [blame] | 2306 | disabled_extensions_.clear(); |
[email protected] | bb7f4095 | 2011-01-13 00:21:20 | [diff] [blame] | 2307 | terminated_extension_ids_.clear(); |
| 2308 | terminated_extensions_.clear(); |
[email protected] | d7e9a86 | 2010-11-03 21:57:49 | [diff] [blame] | 2309 | extension_runtime_data_.clear(); |
[email protected] | cd500f7 | 2010-06-25 23:44:32 | [diff] [blame] | 2310 | |
[email protected] | c6e4a341 | 2009-06-24 15:45:29 | [diff] [blame] | 2311 | // TODO(erikkay) should there be a notification for this? We can't use |
| 2312 | // EXTENSION_UNLOADED since that implies that the extension has been disabled |
| 2313 | // or uninstalled, and UnloadAll is just part of shutdown. |
[email protected] | 9f1087e | 2009-06-15 17:29:32 | [diff] [blame] | 2314 | } |
| 2315 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2316 | void ExtensionService::ReloadExtensions() { |
[email protected] | 9f1087e | 2009-06-15 17:29:32 | [diff] [blame] | 2317 | UnloadAllExtensions(); |
| 2318 | LoadAllExtensions(); |
| 2319 | } |
| 2320 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2321 | void ExtensionService::GarbageCollectExtensions() { |
[email protected] | 39d9f62c | 2010-12-03 10:48:50 | [diff] [blame] | 2322 | if (extension_prefs_->pref_service()->ReadOnly()) |
[email protected] | ba39967 | 2010-04-06 15:42:39 | [diff] [blame] | 2323 | return; |
| 2324 | |
[email protected] | ca3dbf5 | 2010-05-19 22:27:06 | [diff] [blame] | 2325 | scoped_ptr<ExtensionPrefs::ExtensionsInfo> info( |
| 2326 | extension_prefs_->GetInstalledExtensionsInfo()); |
| 2327 | |
| 2328 | std::map<std::string, FilePath> extension_paths; |
| 2329 | for (size_t i = 0; i < info->size(); ++i) |
| 2330 | extension_paths[info->at(i)->extension_id] = info->at(i)->extension_path; |
| 2331 | |
[email protected] | 14908b7 | 2011-04-20 06:54:36 | [diff] [blame] | 2332 | if (!BrowserThread::PostTask( |
| 2333 | BrowserThread::FILE, FROM_HERE, |
[email protected] | 704d77e | 2011-10-17 18:05:29 | [diff] [blame] | 2334 | NewRunnableFunction( |
[email protected] | 14908b7 | 2011-04-20 06:54:36 | [diff] [blame] | 2335 | &extension_file_util::GarbageCollectExtensions, |
| 2336 | install_directory_, |
| 2337 | extension_paths))) |
| 2338 | NOTREACHED(); |
[email protected] | f6ccd65 | 2010-11-17 00:48:34 | [diff] [blame] | 2339 | |
| 2340 | // Also garbage-collect themes. We check |profile_| to be |
| 2341 | // defensive; in the future, we may call GarbageCollectExtensions() |
| 2342 | // from somewhere other than Init() (e.g., in a timer). |
| 2343 | if (profile_) { |
[email protected] | 1828037 | 2011-03-22 18:05:22 | [diff] [blame] | 2344 | ThemeServiceFactory::GetForProfile(profile_)->RemoveUnusedThemes(); |
[email protected] | f6ccd65 | 2010-11-17 00:48:34 | [diff] [blame] | 2345 | } |
[email protected] | 3cf4f099 | 2009-02-03 23:00:30 | [diff] [blame] | 2346 | } |
| 2347 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2348 | void ExtensionService::OnLoadedInstalledExtensions() { |
[email protected] | 93fd78f4 | 2009-07-10 16:43:17 | [diff] [blame] | 2349 | if (updater_.get()) { |
| 2350 | updater_->Start(); |
| 2351 | } |
[email protected] | fa6a910 | 2010-11-22 15:38:50 | [diff] [blame] | 2352 | |
| 2353 | ready_ = true; |
[email protected] | e72e8eb8 | 2009-06-18 17:21:51 | [diff] [blame] | 2354 | NotificationService::current()->Notify( |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 2355 | chrome::NOTIFICATION_EXTENSIONS_READY, |
[email protected] | 24e7a9d | 2009-11-04 11:11:34 | [diff] [blame] | 2356 | Source<Profile>(profile_), |
[email protected] | e72e8eb8 | 2009-06-18 17:21:51 | [diff] [blame] | 2357 | NotificationService::NoDetails()); |
| 2358 | } |
| 2359 | |
[email protected] | 49cd157 | 2011-02-08 21:38:45 | [diff] [blame] | 2360 | void ExtensionService::AddExtension(const Extension* extension) { |
[email protected] | ae09ca6 | 2009-08-21 19:46:46 | [diff] [blame] | 2361 | // Ensure extension is deleted unless we transfer ownership. |
[email protected] | 9adb969 | 2010-10-29 23:14:02 | [diff] [blame] | 2362 | scoped_refptr<const Extension> scoped_extension(extension); |
[email protected] | 9f1087e | 2009-06-15 17:29:32 | [diff] [blame] | 2363 | |
[email protected] | c8d407e | 2011-04-28 21:27:17 | [diff] [blame] | 2364 | // TODO(jstritar): We may be able to get rid of this branch by overriding the |
| 2365 | // default extension state to DISABLED when the --disable-extensions flag |
| 2366 | // is set (http://crbug.com/29067). |
| 2367 | if (!extensions_enabled() && |
| 2368 | !extension->is_theme() && |
| 2369 | extension->location() != Extension::COMPONENT && |
| 2370 | !Extension::IsExternalLocation(extension->location())) |
| 2371 | return; |
| 2372 | |
| 2373 | SetBeingUpgraded(extension, false); |
| 2374 | |
[email protected] | 1eb17508 | 2010-02-10 09:26:16 | [diff] [blame] | 2375 | // The extension is now loaded, remove its data from unloaded extension map. |
| 2376 | unloaded_extension_paths_.erase(extension->id()); |
| 2377 | |
[email protected] | bb7f4095 | 2011-01-13 00:21:20 | [diff] [blame] | 2378 | // If a terminated extension is loaded, remove it from the terminated list. |
| 2379 | UntrackTerminatedExtension(extension->id()); |
| 2380 | |
[email protected] | f17dbd4 | 2010-08-16 23:21:10 | [diff] [blame] | 2381 | // If the extension was disabled for a reload, then enable it. |
| 2382 | if (disabled_extension_paths_.erase(extension->id()) > 0) |
| 2383 | EnableExtension(extension->id()); |
| 2384 | |
[email protected] | d728e00 | 2010-12-08 04:46:23 | [diff] [blame] | 2385 | // Check if the extension's privileges have changed and disable the |
| 2386 | // extension if necessary. |
[email protected] | 902fd7b | 2011-07-27 18:42:31 | [diff] [blame] | 2387 | InitializePermissions(extension); |
[email protected] | 0c6da50 | 2009-08-14 22:32:39 | [diff] [blame] | 2388 | |
[email protected] | ad83ca24 | 2011-07-29 01:32:25 | [diff] [blame] | 2389 | bool disabled = extension_prefs_->IsExtensionDisabled(extension->id()); |
[email protected] | 36429da | 2011-07-11 20:25:18 | [diff] [blame] | 2390 | if (disabled) { |
[email protected] | c8d407e | 2011-04-28 21:27:17 | [diff] [blame] | 2391 | disabled_extensions_.push_back(scoped_extension); |
| 2392 | // TODO(aa): This seems dodgy. It seems that AddExtension() could get called |
| 2393 | // with a disabled extension for other reasons other than that an update was |
| 2394 | // disabled. |
| 2395 | NotificationService::current()->Notify( |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 2396 | chrome::NOTIFICATION_EXTENSION_UPDATE_DISABLED, |
[email protected] | c8d407e | 2011-04-28 21:27:17 | [diff] [blame] | 2397 | Source<Profile>(profile_), |
| 2398 | Details<const Extension>(extension)); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 2399 | SyncExtensionChangeIfNeeded(*extension); |
[email protected] | c8d407e | 2011-04-28 21:27:17 | [diff] [blame] | 2400 | return; |
[email protected] | e72e8eb8 | 2009-06-18 17:21:51 | [diff] [blame] | 2401 | } |
[email protected] | aab98a5 | 2009-12-02 03:22:35 | [diff] [blame] | 2402 | |
[email protected] | c8d407e | 2011-04-28 21:27:17 | [diff] [blame] | 2403 | extensions_.push_back(scoped_extension); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 2404 | SyncExtensionChangeIfNeeded(*extension); |
[email protected] | c8d407e | 2011-04-28 21:27:17 | [diff] [blame] | 2405 | NotifyExtensionLoaded(extension); |
[email protected] | d1282c2 | 2011-10-18 02:00:39 | [diff] [blame] | 2406 | IdentifyAlertableExtensions(); |
[email protected] | aab98a5 | 2009-12-02 03:22:35 | [diff] [blame] | 2407 | } |
| 2408 | |
[email protected] | 902fd7b | 2011-07-27 18:42:31 | [diff] [blame] | 2409 | void ExtensionService::InitializePermissions(const Extension* extension) { |
| 2410 | // If the extension has used the optional permissions API, it will have a |
| 2411 | // custom set of active permissions defined in the extension prefs. Here, |
| 2412 | // we update the extension's active permissions based on the prefs. |
| 2413 | scoped_refptr<ExtensionPermissionSet> active_permissions = |
| 2414 | extension_prefs()->GetActivePermissions(extension->id()); |
| 2415 | |
| 2416 | if (active_permissions.get()) { |
| 2417 | // We restrict the active permissions to be within the bounds defined in the |
| 2418 | // extension's manifest. |
| 2419 | // a) active permissions must be a subset of optional + default permissions |
| 2420 | // b) active permissions must contains all default permissions |
| 2421 | scoped_refptr<ExtensionPermissionSet> total_permissions = |
| 2422 | ExtensionPermissionSet::CreateUnion( |
| 2423 | extension->required_permission_set(), |
| 2424 | extension->optional_permission_set()); |
| 2425 | |
| 2426 | // Make sure the active permissions contain no more than optional + default. |
| 2427 | scoped_refptr<ExtensionPermissionSet> adjusted_active = |
| 2428 | ExtensionPermissionSet::CreateIntersection( |
| 2429 | total_permissions.get(), active_permissions.get()); |
| 2430 | |
| 2431 | // Make sure the active permissions contain the default permissions. |
| 2432 | adjusted_active = ExtensionPermissionSet::CreateUnion( |
| 2433 | extension->required_permission_set(), adjusted_active.get()); |
| 2434 | |
| 2435 | UpdateActivePermissions(extension, adjusted_active); |
| 2436 | } |
| 2437 | |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 2438 | // We keep track of all permissions the user has granted each extension. |
| 2439 | // This allows extensions to gracefully support backwards compatibility |
| 2440 | // by including unknown permissions in their manifests. When the user |
| 2441 | // installs the extension, only the recognized permissions are recorded. |
| 2442 | // When the unknown permissions become recognized (e.g., through browser |
| 2443 | // upgrade), we can prompt the user to accept these new permissions. |
| 2444 | // Extensions can also silently upgrade to less permissions, and then |
| 2445 | // silently upgrade to a version that adds these permissions back. |
| 2446 | // |
| 2447 | // For example, pretend that Chrome 10 includes a permission "omnibox" |
| 2448 | // for an API that adds suggestions to the omnibox. An extension can |
| 2449 | // maintain backwards compatibility while still having "omnibox" in the |
| 2450 | // manifest. If a user installs the extension on Chrome 9, the browser |
| 2451 | // will record the permissions it recognized, not including "omnibox." |
| 2452 | // When upgrading to Chrome 10, "omnibox" will be recognized and Chrome |
| 2453 | // will disable the extension and prompt the user to approve the increase |
| 2454 | // in privileges. The extension could then release a new version that |
| 2455 | // removes the "omnibox" permission. When the user upgrades, Chrome will |
| 2456 | // still remember that "omnibox" had been granted, so that if the |
| 2457 | // extension once again includes "omnibox" in an upgrade, the extension |
| 2458 | // can upgrade without requiring this user's approval. |
| 2459 | const Extension* old = GetExtensionByIdInternal(extension->id(), |
[email protected] | 8001df2 | 2011-04-28 19:59:47 | [diff] [blame] | 2460 | true, true, false); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 2461 | bool is_extension_upgrade = old != NULL; |
| 2462 | bool is_privilege_increase = false; |
| 2463 | |
[email protected] | 902fd7b | 2011-07-27 18:42:31 | [diff] [blame] | 2464 | // We only need to compare the granted permissions to the current permissions |
| 2465 | // if the extension is not allowed to silently increase its permissions. |
| 2466 | if (!extension->CanSilentlyIncreasePermissions()) { |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 2467 | // Add all the recognized permissions if the granted permissions list |
| 2468 | // hasn't been initialized yet. |
[email protected] | 902fd7b | 2011-07-27 18:42:31 | [diff] [blame] | 2469 | scoped_refptr<ExtensionPermissionSet> granted_permissions = |
| 2470 | extension_prefs_->GetGrantedPermissions(extension->id()); |
[email protected] | 0d3e4a2 | 2011-06-23 19:02:52 | [diff] [blame] | 2471 | CHECK(granted_permissions.get()); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 2472 | |
| 2473 | // Here, we check if an extension's privileges have increased in a manner |
| 2474 | // that requires the user's approval. This could occur because the browser |
| 2475 | // upgraded and recognized additional privileges, or an extension upgrades |
| 2476 | // to a version that requires additional privileges. |
[email protected] | 0d3e4a2 | 2011-06-23 19:02:52 | [diff] [blame] | 2477 | is_privilege_increase = |
[email protected] | 902fd7b | 2011-07-27 18:42:31 | [diff] [blame] | 2478 | granted_permissions->HasLessPrivilegesThan( |
| 2479 | extension->GetActivePermissions()); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 2480 | } |
| 2481 | |
| 2482 | if (is_extension_upgrade) { |
[email protected] | 66e2687 | 2010-12-03 20:07:25 | [diff] [blame] | 2483 | // Other than for unpacked extensions, CrxInstaller should have guaranteed |
| 2484 | // that we aren't downgrading. |
| 2485 | if (extension->location() != Extension::LOAD) |
| 2486 | CHECK(extension->version()->CompareTo(*(old->version())) >= 0); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 2487 | |
| 2488 | // Extensions get upgraded if the privileges are allowed to increase or |
| 2489 | // the privileges haven't increased. |
| 2490 | if (!is_privilege_increase) { |
| 2491 | SetBeingUpgraded(old, true); |
| 2492 | SetBeingUpgraded(extension, true); |
| 2493 | } |
| 2494 | |
| 2495 | // To upgrade an extension in place, unload the old one and |
| 2496 | // then load the new one. |
[email protected] | 814a7bf0f | 2011-08-13 05:30:59 | [diff] [blame] | 2497 | UnloadExtension(old->id(), extension_misc::UNLOAD_REASON_UPDATE); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 2498 | old = NULL; |
| 2499 | } |
| 2500 | |
| 2501 | // Extension has changed permissions significantly. Disable it. A |
| 2502 | // notification should be sent by the caller. |
| 2503 | if (is_privilege_increase) { |
[email protected] | fe2dd774 | 2011-04-19 22:52:49 | [diff] [blame] | 2504 | if (!extension_prefs_->DidExtensionEscalatePermissions(extension->id())) { |
| 2505 | RecordPermissionMessagesHistogram( |
| 2506 | extension, "Extensions.Permissions_AutoDisable"); |
| 2507 | } |
[email protected] | b3317ad | 2011-04-28 23:46:00 | [diff] [blame] | 2508 | extension_prefs_->SetExtensionState(extension->id(), Extension::DISABLED); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 2509 | extension_prefs_->SetDidExtensionEscalatePermissions(extension, true); |
| 2510 | } |
| 2511 | } |
| 2512 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2513 | void ExtensionService::UpdateActiveExtensionsInCrashReporter() { |
[email protected] | c886596 | 2009-12-16 07:47:39 | [diff] [blame] | 2514 | std::set<std::string> extension_ids; |
[email protected] | aab98a5 | 2009-12-02 03:22:35 | [diff] [blame] | 2515 | for (size_t i = 0; i < extensions_.size(); ++i) { |
[email protected] | 2a500c1b | 2010-11-05 15:27:34 | [diff] [blame] | 2516 | if (!extensions_[i]->is_theme() && |
| 2517 | extensions_[i]->location() != Extension::COMPONENT) |
[email protected] | c886596 | 2009-12-16 07:47:39 | [diff] [blame] | 2518 | extension_ids.insert(extensions_[i]->id()); |
[email protected] | aab98a5 | 2009-12-02 03:22:35 | [diff] [blame] | 2519 | } |
| 2520 | |
| 2521 | child_process_logging::SetActiveExtensions(extension_ids); |
[email protected] | 6014d67 | 2008-12-05 00:38:25 | [diff] [blame] | 2522 | } |
| 2523 | |
[email protected] | e49002a | 2011-07-13 03:40:44 | [diff] [blame] | 2524 | void ExtensionService::OnLoadSingleExtension(const Extension* extension, |
| 2525 | bool prompt_for_plugins) { |
[email protected] | 5fb88938 | 2011-06-03 00:29:20 | [diff] [blame] | 2526 | // If this is a new install of an extension with plugins, prompt the user |
| 2527 | // first. |
[email protected] | e49002a | 2011-07-13 03:40:44 | [diff] [blame] | 2528 | if (show_extensions_prompts_ && prompt_for_plugins && |
[email protected] | 5fb88938 | 2011-06-03 00:29:20 | [diff] [blame] | 2529 | !extension->plugins().empty() && |
| 2530 | disabled_extension_paths_.find(extension->id()) == |
| 2531 | disabled_extension_paths_.end()) { |
| 2532 | SimpleExtensionLoadPrompt* prompt = new SimpleExtensionLoadPrompt( |
| 2533 | profile_, weak_ptr_factory_.GetWeakPtr(), extension); |
| 2534 | prompt->ShowPrompt(); |
| 2535 | return; // continues in SimpleExtensionLoadPrompt::InstallUI* |
| 2536 | } |
[email protected] | f1b6665 | 2011-08-25 23:30:58 | [diff] [blame] | 2537 | OnExtensionInstalled(extension, false, -1); // Not from web store. |
[email protected] | 5fb88938 | 2011-06-03 00:29:20 | [diff] [blame] | 2538 | } |
| 2539 | |
[email protected] | 8266d66 | 2011-07-12 21:53:26 | [diff] [blame] | 2540 | void ExtensionService::OnExtensionInstalled( |
[email protected] | cc829cf | 2011-08-22 21:01:35 | [diff] [blame] | 2541 | const Extension* extension, bool from_webstore, int page_index) { |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 2542 | CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
[email protected] | a8af9fdb | 2010-10-28 21:52:20 | [diff] [blame] | 2543 | |
[email protected] | 4416c5a | 2010-06-26 01:28:57 | [diff] [blame] | 2544 | // Ensure extension is deleted unless we transfer ownership. |
[email protected] | 9adb969 | 2010-10-29 23:14:02 | [diff] [blame] | 2545 | scoped_refptr<const Extension> scoped_extension(extension); |
[email protected] | c3cfb01 | 2011-04-06 22:07:35 | [diff] [blame] | 2546 | const std::string& id = extension->id(); |
[email protected] | 8a87a533 | 2011-08-11 17:54:59 | [diff] [blame] | 2547 | // Extensions installed by policy can't be disabled. So even if a previous |
| 2548 | // installation disabled the extension, make sure it is now enabled. |
| 2549 | bool initial_enable = |
| 2550 | !extension_prefs_->IsExtensionDisabled(id) || |
| 2551 | !Extension::UserMayDisable(extension->location()); |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 2552 | PendingExtensionInfo pending_extension_info; |
[email protected] | c3cfb01 | 2011-04-06 22:07:35 | [diff] [blame] | 2553 | if (pending_extension_manager()->GetById(id, &pending_extension_info)) { |
| 2554 | pending_extension_manager()->Remove(id); |
[email protected] | 8ef78fd | 2010-08-19 17:14:32 | [diff] [blame] | 2555 | |
[email protected] | 483d1ff | 2011-03-03 17:12:02 | [diff] [blame] | 2556 | if (!pending_extension_info.ShouldAllowInstall(*extension)) { |
[email protected] | 4416c5a | 2010-06-26 01:28:57 | [diff] [blame] | 2557 | LOG(WARNING) |
[email protected] | ae6cb302 | 2011-04-04 20:11:54 | [diff] [blame] | 2558 | << "ShouldAllowInstall() returned false for " |
[email protected] | c3cfb01 | 2011-04-06 22:07:35 | [diff] [blame] | 2559 | << id << " of type " << extension->GetType() |
[email protected] | 7fa19f8 | 2010-12-21 19:40:08 | [diff] [blame] | 2560 | << " and update URL " << extension->update_url().spec() |
| 2561 | << "; not installing"; |
[email protected] | ae6cb302 | 2011-04-04 20:11:54 | [diff] [blame] | 2562 | |
| 2563 | NotificationService::current()->Notify( |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 2564 | chrome::NOTIFICATION_EXTENSION_INSTALL_NOT_ALLOWED, |
[email protected] | ae6cb302 | 2011-04-04 20:11:54 | [diff] [blame] | 2565 | Source<Profile>(profile_), |
| 2566 | Details<const Extension>(extension)); |
| 2567 | |
[email protected] | 4416c5a | 2010-06-26 01:28:57 | [diff] [blame] | 2568 | // Delete the extension directory since we're not going to |
| 2569 | // load it. |
[email protected] | 14908b7 | 2011-04-20 06:54:36 | [diff] [blame] | 2570 | if (!BrowserThread::PostTask( |
| 2571 | BrowserThread::FILE, FROM_HERE, |
[email protected] | 704d77e | 2011-10-17 18:05:29 | [diff] [blame] | 2572 | NewRunnableFunction(&extension_file_util::DeleteFile, |
| 2573 | extension->path(), true))) |
[email protected] | 14908b7 | 2011-04-20 06:54:36 | [diff] [blame] | 2574 | NOTREACHED(); |
[email protected] | 4416c5a | 2010-06-26 01:28:57 | [diff] [blame] | 2575 | return; |
| 2576 | } |
[email protected] | 4416c5a | 2010-06-26 01:28:57 | [diff] [blame] | 2577 | } else { |
[email protected] | c3cfb01 | 2011-04-06 22:07:35 | [diff] [blame] | 2578 | // We explicitly want to re-enable an uninstalled external |
| 2579 | // extension; if we're here, that means the user is manually |
| 2580 | // installing the extension. |
[email protected] | 6cc7dbae | 2011-04-29 21:18:33 | [diff] [blame] | 2581 | if (IsExternalExtensionUninstalled(id)) { |
| 2582 | initial_enable = true; |
| 2583 | } |
[email protected] | aa14270 | 2010-03-26 01:26:33 | [diff] [blame] | 2584 | } |
| 2585 | |
[email protected] | 0753302 | 2011-06-27 20:42:55 | [diff] [blame] | 2586 | // Do not record the install histograms for upgrades. |
| 2587 | if (!GetExtensionByIdInternal(extension->id(), true, true, false)) { |
| 2588 | UMA_HISTOGRAM_ENUMERATION("Extensions.InstallType", |
| 2589 | extension->GetType(), 100); |
| 2590 | RecordPermissionMessagesHistogram( |
| 2591 | extension, "Extensions.Permissions_Install"); |
| 2592 | } |
| 2593 | |
[email protected] | eda3c36 | 2010-11-12 08:08:23 | [diff] [blame] | 2594 | ShownSectionsHandler::OnExtensionInstalled(profile_->GetPrefs(), extension); |
[email protected] | 4416c5a | 2010-06-26 01:28:57 | [diff] [blame] | 2595 | extension_prefs_->OnExtensionInstalled( |
[email protected] | 8266d66 | 2011-07-12 21:53:26 | [diff] [blame] | 2596 | extension, |
| 2597 | initial_enable ? Extension::ENABLED : Extension::DISABLED, |
[email protected] | cc829cf | 2011-08-22 21:01:35 | [diff] [blame] | 2598 | from_webstore, |
| 2599 | page_index); |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 2600 | |
[email protected] | cdfca970 | 2011-08-08 16:07:01 | [diff] [blame] | 2601 | // Unpacked extensions default to allowing file access, but if that has been |
| 2602 | // overridden, don't reset the value. |
[email protected] | b6e64fd | 2011-08-09 19:49:19 | [diff] [blame] | 2603 | if (Extension::ShouldAlwaysAllowFileAccess(extension->location()) && |
[email protected] | cdfca970 | 2011-08-08 16:07:01 | [diff] [blame] | 2604 | !extension_prefs_->HasAllowFileAccessSetting(id)) { |
| 2605 | extension_prefs_->SetAllowFileAccess(id, true); |
| 2606 | } |
| 2607 | |
[email protected] | b6cf240f | 2011-10-15 22:09:53 | [diff] [blame] | 2608 | // If the extension should automatically block network startup (e.g., it uses |
| 2609 | // the webRequest API), set the preference. Otherwise clear it, in case the |
| 2610 | // extension stopped using a relevant API. |
| 2611 | extension_prefs_->SetDelaysNetworkRequests( |
| 2612 | extension->id(), extension->ImplicitlyDelaysNetworkStartup()); |
| 2613 | |
[email protected] | a3e61e8 | 2011-04-15 20:32:08 | [diff] [blame] | 2614 | NotificationService::current()->Notify( |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 2615 | chrome::NOTIFICATION_EXTENSION_INSTALLED, |
[email protected] | a3e61e8 | 2011-04-15 20:32:08 | [diff] [blame] | 2616 | Source<Profile>(profile_), |
| 2617 | Details<const Extension>(extension)); |
[email protected] | 7577a5c5 | 2009-07-30 06:21:58 | [diff] [blame] | 2618 | |
[email protected] | 49cd157 | 2011-02-08 21:38:45 | [diff] [blame] | 2619 | // Transfer ownership of |extension| to AddExtension. |
| 2620 | AddExtension(scoped_extension); |
[email protected] | 4a19063 | 2009-05-09 01:07:42 | [diff] [blame] | 2621 | } |
| 2622 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2623 | const Extension* ExtensionService::GetExtensionByIdInternal( |
[email protected] | 8001df2 | 2011-04-28 19:59:47 | [diff] [blame] | 2624 | const std::string& id, bool include_enabled, bool include_disabled, |
| 2625 | bool include_terminated) const { |
[email protected] | e957fe5 | 2009-06-23 16:51:05 | [diff] [blame] | 2626 | std::string lowercase_id = StringToLowerASCII(id); |
[email protected] | 0c6da50 | 2009-08-14 22:32:39 | [diff] [blame] | 2627 | if (include_enabled) { |
| 2628 | for (ExtensionList::const_iterator iter = extensions_.begin(); |
| 2629 | iter != extensions_.end(); ++iter) { |
| 2630 | if ((*iter)->id() == lowercase_id) |
| 2631 | return *iter; |
| 2632 | } |
| 2633 | } |
| 2634 | if (include_disabled) { |
| 2635 | for (ExtensionList::const_iterator iter = disabled_extensions_.begin(); |
| 2636 | iter != disabled_extensions_.end(); ++iter) { |
| 2637 | if ((*iter)->id() == lowercase_id) |
| 2638 | return *iter; |
| 2639 | } |
[email protected] | ce5c450 | 2009-05-06 16:46:11 | [diff] [blame] | 2640 | } |
[email protected] | 8001df2 | 2011-04-28 19:59:47 | [diff] [blame] | 2641 | if (include_terminated) { |
| 2642 | for (ExtensionList::const_iterator iter = terminated_extensions_.begin(); |
| 2643 | iter != terminated_extensions_.end(); ++iter) { |
| 2644 | if ((*iter)->id() == lowercase_id) |
| 2645 | return *iter; |
| 2646 | } |
| 2647 | } |
[email protected] | ce5c450 | 2009-05-06 16:46:11 | [diff] [blame] | 2648 | return NULL; |
| 2649 | } |
| 2650 | |
[email protected] | bb7f4095 | 2011-01-13 00:21:20 | [diff] [blame] | 2651 | void ExtensionService::TrackTerminatedExtension(const Extension* extension) { |
| 2652 | if (terminated_extension_ids_.insert(extension->id()).second) |
| 2653 | terminated_extensions_.push_back(make_scoped_refptr(extension)); |
[email protected] | fa2416f | 2011-05-03 08:41:20 | [diff] [blame] | 2654 | |
[email protected] | 814a7bf0f | 2011-08-13 05:30:59 | [diff] [blame] | 2655 | UnloadExtension(extension->id(), extension_misc::UNLOAD_REASON_DISABLE); |
[email protected] | bb7f4095 | 2011-01-13 00:21:20 | [diff] [blame] | 2656 | } |
| 2657 | |
| 2658 | void ExtensionService::UntrackTerminatedExtension(const std::string& id) { |
[email protected] | fa2416f | 2011-05-03 08:41:20 | [diff] [blame] | 2659 | std::string lowercase_id = StringToLowerASCII(id); |
| 2660 | if (terminated_extension_ids_.erase(lowercase_id) <= 0) |
[email protected] | bb7f4095 | 2011-01-13 00:21:20 | [diff] [blame] | 2661 | return; |
| 2662 | |
[email protected] | bb7f4095 | 2011-01-13 00:21:20 | [diff] [blame] | 2663 | for (ExtensionList::iterator iter = terminated_extensions_.begin(); |
| 2664 | iter != terminated_extensions_.end(); ++iter) { |
| 2665 | if ((*iter)->id() == lowercase_id) { |
| 2666 | terminated_extensions_.erase(iter); |
| 2667 | return; |
| 2668 | } |
| 2669 | } |
| 2670 | } |
| 2671 | |
[email protected] | 0dfe05c | 2011-02-23 23:03:36 | [diff] [blame] | 2672 | const Extension* ExtensionService::GetTerminatedExtension( |
[email protected] | 8001df2 | 2011-04-28 19:59:47 | [diff] [blame] | 2673 | const std::string& id) const { |
| 2674 | return GetExtensionByIdInternal(id, false, false, true); |
| 2675 | } |
| 2676 | |
| 2677 | const Extension* ExtensionService::GetInstalledExtension( |
| 2678 | const std::string& id) const { |
| 2679 | return GetExtensionByIdInternal(id, true, true, true); |
[email protected] | 0dfe05c | 2011-02-23 23:03:36 | [diff] [blame] | 2680 | } |
| 2681 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2682 | const Extension* ExtensionService::GetWebStoreApp() { |
[email protected] | d307199 | 2010-10-08 15:24:07 | [diff] [blame] | 2683 | return GetExtensionById(extension_misc::kWebStoreAppId, false); |
| 2684 | } |
| 2685 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2686 | const Extension* ExtensionService::GetExtensionByURL(const GURL& url) { |
[email protected] | a888b29e6 | 2010-04-01 13:38:57 | [diff] [blame] | 2687 | return url.scheme() != chrome::kExtensionScheme ? NULL : |
| 2688 | GetExtensionById(url.host(), false); |
| 2689 | } |
| 2690 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2691 | const Extension* ExtensionService::GetExtensionByWebExtent(const GURL& url) { |
[email protected] | a888b29e6 | 2010-04-01 13:38:57 | [diff] [blame] | 2692 | for (size_t i = 0; i < extensions_.size(); ++i) { |
[email protected] | cced75a | 2011-05-20 08:31:12 | [diff] [blame] | 2693 | if (extensions_[i]->web_extent().MatchesURL(url)) |
[email protected] | a888b29e6 | 2010-04-01 13:38:57 | [diff] [blame] | 2694 | return extensions_[i]; |
| 2695 | } |
| 2696 | return NULL; |
[email protected] | 9f1087e | 2009-06-15 17:29:32 | [diff] [blame] | 2697 | } |
| 2698 | |
[email protected] | f9c292b3 | 2011-09-13 16:14:05 | [diff] [blame] | 2699 | const Extension* ExtensionService::GetDisabledExtensionByWebExtent( |
| 2700 | const GURL& url) { |
| 2701 | for (size_t i = 0; i < disabled_extensions_.size(); ++i) { |
| 2702 | if (disabled_extensions_[i]->web_extent().MatchesURL(url)) |
| 2703 | return disabled_extensions_[i]; |
| 2704 | } |
| 2705 | return NULL; |
| 2706 | } |
| 2707 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2708 | bool ExtensionService::ExtensionBindingsAllowed(const GURL& url) { |
[email protected] | 056ad2a | 2011-07-12 02:13:55 | [diff] [blame] | 2709 | // Allow bindings for all packaged extensions. |
| 2710 | // Note that GetExtensionByURL may return an Extension for hosted apps |
| 2711 | // if the URL came from GetEffectiveURL. |
| 2712 | const Extension* extension = GetExtensionByURL(url); |
| 2713 | if (extension && extension->GetType() != Extension::TYPE_HOSTED_APP) |
[email protected] | 583d45c1 | 2010-08-31 02:48:12 | [diff] [blame] | 2714 | return true; |
| 2715 | |
| 2716 | // Allow bindings for all component, hosted apps. |
[email protected] | 056ad2a | 2011-07-12 02:13:55 | [diff] [blame] | 2717 | if (!extension) |
| 2718 | extension = GetExtensionByWebExtent(url); |
[email protected] | 583d45c1 | 2010-08-31 02:48:12 | [diff] [blame] | 2719 | return (extension && extension->location() == Extension::COMPONENT); |
| 2720 | } |
| 2721 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2722 | const Extension* ExtensionService::GetExtensionByOverlappingWebExtent( |
[email protected] | cced75a | 2011-05-20 08:31:12 | [diff] [blame] | 2723 | const URLPatternSet& extent) { |
[email protected] | 22c966c | 2010-06-26 06:35:02 | [diff] [blame] | 2724 | for (size_t i = 0; i < extensions_.size(); ++i) { |
| 2725 | if (extensions_[i]->web_extent().OverlapsWith(extent)) |
| 2726 | return extensions_[i]; |
| 2727 | } |
| 2728 | |
[email protected] | 6d2e60bd | 2010-06-03 22:37:39 | [diff] [blame] | 2729 | return NULL; |
| 2730 | } |
| 2731 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2732 | const SkBitmap& ExtensionService::GetOmniboxIcon( |
[email protected] | b671760b | 2010-07-15 21:13:47 | [diff] [blame] | 2733 | const std::string& extension_id) { |
| 2734 | return omnibox_icon_manager_.GetIcon(extension_id); |
| 2735 | } |
| 2736 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2737 | const SkBitmap& ExtensionService::GetOmniboxPopupIcon( |
[email protected] | 29d0d4ac | 2010-09-08 21:10:31 | [diff] [blame] | 2738 | const std::string& extension_id) { |
| 2739 | return omnibox_popup_icon_manager_.GetIcon(extension_id); |
| 2740 | } |
| 2741 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2742 | void ExtensionService::OnExternalExtensionFileFound( |
[email protected] | 8ef78fd | 2010-08-19 17:14:32 | [diff] [blame] | 2743 | const std::string& id, |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 2744 | const Version* version, |
[email protected] | 8ef78fd | 2010-08-19 17:14:32 | [diff] [blame] | 2745 | const FilePath& path, |
| 2746 | Extension::Location location) { |
[email protected] | ab22ba4 | 2011-01-14 16:36:38 | [diff] [blame] | 2747 | CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 2748 | CHECK(Extension::IdIsValid(id)); |
[email protected] | 79c833b5 | 2011-04-05 18:31:01 | [diff] [blame] | 2749 | if (extension_prefs_->IsExternalExtensionUninstalled(id)) |
[email protected] | 683d070 | 2010-12-06 16:25:57 | [diff] [blame] | 2750 | return; |
[email protected] | a8af9fdb | 2010-10-28 21:52:20 | [diff] [blame] | 2751 | |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 2752 | DCHECK(version); |
| 2753 | |
[email protected] | 7577a5c5 | 2009-07-30 06:21:58 | [diff] [blame] | 2754 | // Before even bothering to unpack, check and see if we already have this |
[email protected] | 4c96793 | 2009-07-31 01:15:49 | [diff] [blame] | 2755 | // version. This is important because these extensions are going to get |
[email protected] | 7577a5c5 | 2009-07-30 06:21:58 | [diff] [blame] | 2756 | // installed on every startup. |
[email protected] | 9adb969 | 2010-10-29 23:14:02 | [diff] [blame] | 2757 | const Extension* existing = GetExtensionById(id, true); |
[email protected] | 7577a5c5 | 2009-07-30 06:21:58 | [diff] [blame] | 2758 | if (existing) { |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 2759 | switch (existing->version()->CompareTo(*version)) { |
[email protected] | 7577a5c5 | 2009-07-30 06:21:58 | [diff] [blame] | 2760 | case -1: // existing version is older, we should upgrade |
| 2761 | break; |
| 2762 | case 0: // existing version is same, do nothing |
| 2763 | return; |
| 2764 | case 1: // existing version is newer, uh-oh |
| 2765 | LOG(WARNING) << "Found external version of extension " << id |
| 2766 | << "that is older than current version. Current version " |
| 2767 | << "is: " << existing->VersionString() << ". New version " |
| 2768 | << "is: " << version << ". Keeping current version."; |
| 2769 | return; |
| 2770 | } |
| 2771 | } |
| 2772 | |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 2773 | pending_extension_manager()->AddFromExternalFile(id, location); |
[email protected] | 9c635f2 | 2010-12-02 09:36:36 | [diff] [blame] | 2774 | |
[email protected] | 14908b7 | 2011-04-20 06:54:36 | [diff] [blame] | 2775 | // no client (silent install) |
| 2776 | scoped_refptr<CrxInstaller> installer(MakeCrxInstaller(NULL)); |
[email protected] | 6dfbbf8 | 2010-03-12 23:09:16 | [diff] [blame] | 2777 | installer->set_install_source(location); |
| 2778 | installer->set_expected_id(id); |
[email protected] | cb0e5031 | 2011-05-09 15:03:07 | [diff] [blame] | 2779 | installer->set_expected_version(*version); |
| 2780 | installer->set_install_cause(extension_misc::INSTALL_CAUSE_EXTERNAL_FILE); |
[email protected] | 6dfbbf8 | 2010-03-12 23:09:16 | [diff] [blame] | 2781 | installer->InstallCrx(path); |
[email protected] | 7577a5c5 | 2009-07-30 06:21:58 | [diff] [blame] | 2782 | } |
| 2783 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2784 | void ExtensionService::ReportExtensionLoadError( |
[email protected] | d11c8e9 | 2009-10-20 23:26:40 | [diff] [blame] | 2785 | const FilePath& extension_path, |
| 2786 | const std::string &error, |
[email protected] | d11c8e9 | 2009-10-20 23:26:40 | [diff] [blame] | 2787 | bool be_noisy) { |
| 2788 | NotificationService* service = NotificationService::current(); |
[email protected] | 655b2b1a | 2011-10-13 17:13:06 | [diff] [blame] | 2789 | service->Notify(chrome::NOTIFICATION_EXTENSION_LOAD_ERROR, |
[email protected] | 24e7a9d | 2009-11-04 11:11:34 | [diff] [blame] | 2790 | Source<Profile>(profile_), |
[email protected] | d11c8e9 | 2009-10-20 23:26:40 | [diff] [blame] | 2791 | Details<const std::string>(&error)); |
| 2792 | |
[email protected] | 8a205c0 | 2011-02-04 20:41:33 | [diff] [blame] | 2793 | std::string path_str = UTF16ToUTF8(extension_path.LossyDisplayName()); |
[email protected] | 18d4b6c | 2010-09-21 03:21:04 | [diff] [blame] | 2794 | std::string message = base::StringPrintf( |
| 2795 | "Could not load extension from '%s'. %s", |
| 2796 | path_str.c_str(), error.c_str()); |
[email protected] | d11c8e9 | 2009-10-20 23:26:40 | [diff] [blame] | 2797 | ExtensionErrorReporter::GetInstance()->ReportError(message, be_noisy); |
| 2798 | } |
| 2799 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2800 | void ExtensionService::DidCreateRenderViewForBackgroundPage( |
[email protected] | 406027c0 | 2010-09-27 08:03:18 | [diff] [blame] | 2801 | ExtensionHost* host) { |
| 2802 | OrphanedDevTools::iterator iter = |
[email protected] | 2d2f6cfc | 2011-05-06 21:09:33 | [diff] [blame] | 2803 | orphaned_dev_tools_.find(host->extension_id()); |
[email protected] | 406027c0 | 2010-09-27 08:03:18 | [diff] [blame] | 2804 | if (iter == orphaned_dev_tools_.end()) |
| 2805 | return; |
| 2806 | |
| 2807 | DevToolsManager::GetInstance()->AttachClientHost( |
| 2808 | iter->second, host->render_view_host()); |
| 2809 | orphaned_dev_tools_.erase(iter); |
| 2810 | } |
| 2811 | |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 2812 | void ExtensionService::Observe(int type, |
[email protected] | fa2416f | 2011-05-03 08:41:20 | [diff] [blame] | 2813 | const NotificationSource& source, |
| 2814 | const NotificationDetails& details) { |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 2815 | switch (type) { |
| 2816 | case chrome::NOTIFICATION_EXTENSION_PROCESS_TERMINATED: { |
[email protected] | bc535ee5 | 2010-08-31 18:40:32 | [diff] [blame] | 2817 | if (profile_ != Source<Profile>(source).ptr()->GetOriginalProfile()) |
| 2818 | break; |
[email protected] | a4ed628 | 2009-12-14 20:51:16 | [diff] [blame] | 2819 | |
[email protected] | f128af4 | 2010-08-05 18:05:26 | [diff] [blame] | 2820 | ExtensionHost* host = Details<ExtensionHost>(details).ptr(); |
| 2821 | |
[email protected] | fa2416f | 2011-05-03 08:41:20 | [diff] [blame] | 2822 | // Mark the extension as terminated and Unload it. We want it to |
| 2823 | // be in a consistent state: either fully working or not loaded |
| 2824 | // at all, but never half-crashed. We do it in a PostTask so |
| 2825 | // that other handlers of this notification will still have |
| 2826 | // access to the Extension and ExtensionHost. |
[email protected] | 14908b7 | 2011-04-20 06:54:36 | [diff] [blame] | 2827 | MessageLoop::current()->PostTask( |
| 2828 | FROM_HERE, |
[email protected] | 704d77e | 2011-10-17 18:05:29 | [diff] [blame] | 2829 | method_factory_.NewRunnableMethod( |
[email protected] | fa2416f | 2011-05-03 08:41:20 | [diff] [blame] | 2830 | &ExtensionService::TrackTerminatedExtension, |
| 2831 | host->extension())); |
[email protected] | 31f7726 | 2009-12-02 20:48:53 | [diff] [blame] | 2832 | break; |
| 2833 | } |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 2834 | case content::NOTIFICATION_RENDERER_PROCESS_CREATED: { |
[email protected] | 77a6970c | 2011-04-23 16:58:56 | [diff] [blame] | 2835 | RenderProcessHost* process = Source<RenderProcessHost>(source).ptr(); |
[email protected] | fc30ef08 | 2011-08-18 04:07:19 | [diff] [blame] | 2836 | Profile* host_profile = |
| 2837 | Profile::FromBrowserContext(process->browser_context()); |
| 2838 | if (!profile_->IsSameProfile(host_profile->GetOriginalProfile())) |
| 2839 | break; |
| 2840 | |
[email protected] | 77a6970c | 2011-04-23 16:58:56 | [diff] [blame] | 2841 | // Valid extension function names, used to setup bindings in renderer. |
| 2842 | std::vector<std::string> function_names; |
| 2843 | ExtensionFunctionDispatcher::GetAllFunctionNames(&function_names); |
| 2844 | process->Send(new ExtensionMsg_SetFunctionNames(function_names)); |
[email protected] | 31f7726 | 2009-12-02 20:48:53 | [diff] [blame] | 2845 | |
[email protected] | 77a6970c | 2011-04-23 16:58:56 | [diff] [blame] | 2846 | // Scripting whitelist. This is modified by tests and must be communicated |
| 2847 | // to renderers. |
| 2848 | process->Send(new ExtensionMsg_SetScriptingWhitelist( |
| 2849 | *Extension::GetScriptingWhitelist())); |
| 2850 | |
| 2851 | // Loaded extensions. |
| 2852 | for (size_t i = 0; i < extensions_.size(); ++i) { |
| 2853 | process->Send(new ExtensionMsg_Loaded( |
[email protected] | 1537964 | 2011-08-11 22:22:05 | [diff] [blame] | 2854 | ExtensionMsg_Loaded_Params(extensions_[i]))); |
[email protected] | 77a6970c | 2011-04-23 16:58:56 | [diff] [blame] | 2855 | } |
| 2856 | break; |
| 2857 | } |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 2858 | case content::NOTIFICATION_RENDERER_PROCESS_TERMINATED: { |
[email protected] | da5683db | 2011-04-23 17:12:21 | [diff] [blame] | 2859 | RenderProcessHost* process = Source<RenderProcessHost>(source).ptr(); |
[email protected] | fc30ef08 | 2011-08-18 04:07:19 | [diff] [blame] | 2860 | Profile* host_profile = |
| 2861 | Profile::FromBrowserContext(process->browser_context()); |
| 2862 | if (!profile_->IsSameProfile(host_profile->GetOriginalProfile())) |
| 2863 | break; |
| 2864 | |
[email protected] | da5683db | 2011-04-23 17:12:21 | [diff] [blame] | 2865 | installed_app_hosts_.erase(process->id()); |
| 2866 | break; |
| 2867 | } |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 2868 | case chrome::NOTIFICATION_PREF_CHANGED: { |
[email protected] | aa96d3a | 2010-08-21 08:45:25 | [diff] [blame] | 2869 | std::string* pref_name = Details<std::string>(details).ptr(); |
[email protected] | 6c751e7 | 2010-11-23 10:11:10 | [diff] [blame] | 2870 | if (*pref_name == prefs::kExtensionInstallAllowList || |
| 2871 | *pref_name == prefs::kExtensionInstallDenyList) { |
| 2872 | CheckAdminBlacklist(); |
[email protected] | 6c751e7 | 2010-11-23 10:11:10 | [diff] [blame] | 2873 | } else { |
| 2874 | NOTREACHED() << "Unexpected preference name."; |
| 2875 | } |
[email protected] | aa96d3a | 2010-08-21 08:45:25 | [diff] [blame] | 2876 | break; |
| 2877 | } |
[email protected] | d9126802 | 2011-08-26 13:17:37 | [diff] [blame] | 2878 | case chrome::NOTIFICATION_IMPORT_FINISHED: { |
| 2879 | registrar_.Remove(this, chrome::NOTIFICATION_IMPORT_FINISHED, |
| 2880 | Source<Profile>(profile_)); |
| 2881 | InitEventRouters(); |
| 2882 | break; |
| 2883 | } |
[email protected] | aa96d3a | 2010-08-21 08:45:25 | [diff] [blame] | 2884 | |
[email protected] | 4814b51 | 2009-11-07 00:12:29 | [diff] [blame] | 2885 | default: |
| 2886 | NOTREACHED() << "Unexpected notification type."; |
| 2887 | } |
| 2888 | } |
| 2889 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2890 | bool ExtensionService::HasApps() const { |
[email protected] | ec5b50d | 2010-10-09 16:35:18 | [diff] [blame] | 2891 | return !GetAppIds().empty(); |
| 2892 | } |
[email protected] | 377011d | 2010-07-20 04:18:50 | [diff] [blame] | 2893 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2894 | ExtensionIdSet ExtensionService::GetAppIds() const { |
[email protected] | ec5b50d | 2010-10-09 16:35:18 | [diff] [blame] | 2895 | ExtensionIdSet result; |
[email protected] | 377011d | 2010-07-20 04:18:50 | [diff] [blame] | 2896 | for (ExtensionList::const_iterator it = extensions_.begin(); |
| 2897 | it != extensions_.end(); ++it) { |
[email protected] | ec5b50d | 2010-10-09 16:35:18 | [diff] [blame] | 2898 | if ((*it)->is_app() && (*it)->location() != Extension::COMPONENT) |
| 2899 | result.insert((*it)->id()); |
[email protected] | 377011d | 2010-07-20 04:18:50 | [diff] [blame] | 2900 | } |
| 2901 | |
[email protected] | ec5b50d | 2010-10-09 16:35:18 | [diff] [blame] | 2902 | return result; |
[email protected] | 377011d | 2010-07-20 04:18:50 | [diff] [blame] | 2903 | } |
[email protected] | d7e9a86 | 2010-11-03 21:57:49 | [diff] [blame] | 2904 | |
[email protected] | 14908b7 | 2011-04-20 06:54:36 | [diff] [blame] | 2905 | scoped_refptr<CrxInstaller> ExtensionService::MakeCrxInstaller( |
| 2906 | ExtensionInstallUI* client) { |
| 2907 | return new CrxInstaller(weak_ptr_factory_.GetWeakPtr(), client); |
| 2908 | } |
| 2909 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2910 | bool ExtensionService::IsBackgroundPageReady(const Extension* extension) { |
[email protected] | d7e9a86 | 2010-11-03 21:57:49 | [diff] [blame] | 2911 | return (extension->background_url().is_empty() || |
| 2912 | extension_runtime_data_[extension->id()].background_page_ready); |
| 2913 | } |
| 2914 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2915 | void ExtensionService::SetBackgroundPageReady(const Extension* extension) { |
[email protected] | d7e9a86 | 2010-11-03 21:57:49 | [diff] [blame] | 2916 | DCHECK(!extension->background_url().is_empty()); |
| 2917 | extension_runtime_data_[extension->id()].background_page_ready = true; |
| 2918 | NotificationService::current()->Notify( |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 2919 | chrome::NOTIFICATION_EXTENSION_BACKGROUND_PAGE_READY, |
[email protected] | d7e9a86 | 2010-11-03 21:57:49 | [diff] [blame] | 2920 | Source<const Extension>(extension), |
| 2921 | NotificationService::NoDetails()); |
| 2922 | } |
| 2923 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2924 | bool ExtensionService::IsBeingUpgraded(const Extension* extension) { |
[email protected] | d7e9a86 | 2010-11-03 21:57:49 | [diff] [blame] | 2925 | return extension_runtime_data_[extension->id()].being_upgraded; |
| 2926 | } |
| 2927 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2928 | void ExtensionService::SetBeingUpgraded(const Extension* extension, |
[email protected] | d7e9a86 | 2010-11-03 21:57:49 | [diff] [blame] | 2929 | bool value) { |
| 2930 | extension_runtime_data_[extension->id()].being_upgraded = value; |
| 2931 | } |
[email protected] | 1bead071 | 2010-11-27 17:41:53 | [diff] [blame] | 2932 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2933 | PropertyBag* ExtensionService::GetPropertyBag(const Extension* extension) { |
[email protected] | 1bead071 | 2010-11-27 17:41:53 | [diff] [blame] | 2934 | return &extension_runtime_data_[extension->id()].property_bag; |
| 2935 | } |
[email protected] | cebc3dc | 2011-04-18 17:15:00 | [diff] [blame] | 2936 | |
| 2937 | void ExtensionService::RegisterNaClModule(const GURL& url, |
| 2938 | const std::string& mime_type) { |
| 2939 | NaClModuleInfo info; |
| 2940 | info.url = url; |
| 2941 | info.mime_type = mime_type; |
| 2942 | |
| 2943 | DCHECK(FindNaClModule(url) == nacl_module_list_.end()); |
| 2944 | nacl_module_list_.push_front(info); |
| 2945 | } |
| 2946 | |
| 2947 | void ExtensionService::UnregisterNaClModule(const GURL& url) { |
| 2948 | NaClModuleInfoList::iterator iter = FindNaClModule(url); |
| 2949 | DCHECK(iter != nacl_module_list_.end()); |
| 2950 | nacl_module_list_.erase(iter); |
| 2951 | } |
| 2952 | |
[email protected] | ed0ba00 | 2011-05-26 16:55:13 | [diff] [blame] | 2953 | void ExtensionService::UpdatePluginListWithNaClModules() { |
[email protected] | 300c0ea | 2011-07-15 23:04:33 | [diff] [blame] | 2954 | // An extension has been added which has a nacl_module component, which means |
| 2955 | // there is a MIME type that module wants to handle, so we need to add that |
| 2956 | // MIME type to plugins which handle NaCl modules in order to allow the |
| 2957 | // individual modules to handle these types. |
[email protected] | ed0ba00 | 2011-05-26 16:55:13 | [diff] [blame] | 2958 | const PepperPluginInfo* pepper_info = NULL; |
| 2959 | std::vector<PepperPluginInfo> plugins; |
| 2960 | PepperPluginRegistry::ComputeList(&plugins); |
[email protected] | 300c0ea | 2011-07-15 23:04:33 | [diff] [blame] | 2961 | |
| 2962 | // Search the entire plugin list for plugins that handle the NaCl MIME type. |
| 2963 | // There can be multiple plugins like this, for instance the internal NaCl |
| 2964 | // plugin and a plugin registered by --register-pepper-plugins during tests. |
[email protected] | ed0ba00 | 2011-05-26 16:55:13 | [diff] [blame] | 2965 | for (size_t i = 0; i < plugins.size(); ++i) { |
[email protected] | 300c0ea | 2011-07-15 23:04:33 | [diff] [blame] | 2966 | pepper_info = &plugins[i]; |
| 2967 | CHECK(pepper_info); |
[email protected] | 91d9f3d | 2011-08-14 05:24:44 | [diff] [blame] | 2968 | std::vector<webkit::WebPluginMimeType>::const_iterator mime_iter; |
[email protected] | 300c0ea | 2011-07-15 23:04:33 | [diff] [blame] | 2969 | // Check each MIME type the plugins handle for the NaCl MIME type. |
| 2970 | for (mime_iter = pepper_info->mime_types.begin(); |
| 2971 | mime_iter != pepper_info->mime_types.end(); ++mime_iter) { |
| 2972 | if (mime_iter->mime_type == kNaClPluginMimeType) { |
| 2973 | // This plugin handles "application/x-nacl". |
| 2974 | |
| 2975 | webkit::npapi::PluginList::Singleton()-> |
| 2976 | UnregisterInternalPlugin(pepper_info->path); |
| 2977 | |
[email protected] | 91d9f3d | 2011-08-14 05:24:44 | [diff] [blame] | 2978 | webkit::WebPluginInfo info = pepper_info->ToWebPluginInfo(); |
[email protected] | 300c0ea | 2011-07-15 23:04:33 | [diff] [blame] | 2979 | |
| 2980 | for (ExtensionService::NaClModuleInfoList::const_iterator iter = |
| 2981 | nacl_module_list_.begin(); |
| 2982 | iter != nacl_module_list_.end(); ++iter) { |
| 2983 | // Add the MIME type specified in the extension to this NaCl plugin, |
| 2984 | // With an extra "nacl" argument to specify the location of the NaCl |
| 2985 | // manifest file. |
[email protected] | 91d9f3d | 2011-08-14 05:24:44 | [diff] [blame] | 2986 | webkit::WebPluginMimeType mime_type_info; |
[email protected] | 300c0ea | 2011-07-15 23:04:33 | [diff] [blame] | 2987 | mime_type_info.mime_type = iter->mime_type; |
| 2988 | mime_type_info.additional_param_names.push_back(UTF8ToUTF16("nacl")); |
| 2989 | mime_type_info.additional_param_values.push_back( |
| 2990 | UTF8ToUTF16(iter->url.spec())); |
| 2991 | info.mime_types.push_back(mime_type_info); |
| 2992 | } |
| 2993 | |
| 2994 | webkit::npapi::PluginList::Singleton()->RefreshPlugins(); |
| 2995 | webkit::npapi::PluginList::Singleton()->RegisterInternalPlugin(info); |
| 2996 | // This plugin has been modified, no need to check the rest of its |
| 2997 | // types, but continue checking other plugins. |
| 2998 | break; |
| 2999 | } |
[email protected] | ed0ba00 | 2011-05-26 16:55:13 | [diff] [blame] | 3000 | } |
| 3001 | } |
[email protected] | ed0ba00 | 2011-05-26 16:55:13 | [diff] [blame] | 3002 | } |
| 3003 | |
[email protected] | cebc3dc | 2011-04-18 17:15:00 | [diff] [blame] | 3004 | ExtensionService::NaClModuleInfoList::iterator |
| 3005 | ExtensionService::FindNaClModule(const GURL& url) { |
| 3006 | for (NaClModuleInfoList::iterator iter = nacl_module_list_.begin(); |
| 3007 | iter != nacl_module_list_.end(); ++iter) { |
| 3008 | if (iter->url == url) |
| 3009 | return iter; |
| 3010 | } |
| 3011 | return nacl_module_list_.end(); |
| 3012 | } |