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