[email protected] | 1e8c93f | 2010-02-08 22:58:31 | [diff] [blame] | 1 | // Copyright (c) 2010 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 | |
| 5 | #include "chrome/browser/extensions/extensions_service.h" |
| 6 | |
[email protected] | 24b538a | 2010-02-27 01:22:44 | [diff] [blame] | 7 | #include "base/basictypes.h" |
[email protected] | e2eb4311 | 2009-05-29 21:19:54 | [diff] [blame] | 8 | #include "base/command_line.h" |
[email protected] | 6014d67 | 2008-12-05 00:38:25 | [diff] [blame] | 9 | #include "base/file_util.h" |
[email protected] | cc2c343 | 2009-11-06 17:24:36 | [diff] [blame] | 10 | #include "base/histogram.h" |
[email protected] | cd500f7 | 2010-06-25 23:44:32 | [diff] [blame] | 11 | #include "base/stl_util-inl.h" |
[email protected] | 24b538a | 2010-02-27 01:22:44 | [diff] [blame] | 12 | #include "base/string16.h" |
[email protected] | 6014d67 | 2008-12-05 00:38:25 | [diff] [blame] | 13 | #include "base/string_util.h" |
[email protected] | cc2c343 | 2009-11-06 17:24:36 | [diff] [blame] | 14 | #include "base/time.h" |
[email protected] | cc65591 | 2009-01-29 23:19:19 | [diff] [blame] | 15 | #include "base/values.h" |
[email protected] | aa14270 | 2010-03-26 01:26:33 | [diff] [blame] | 16 | #include "base/version.h" |
[email protected] | 15730c4 | 2009-09-03 00:03:20 | [diff] [blame] | 17 | #include "chrome/browser/browser_process.h" |
[email protected] | dbb92e0d | 2009-08-20 16:18:21 | [diff] [blame] | 18 | #include "chrome/browser/chrome_thread.h" |
[email protected] | 4814b51 | 2009-11-07 00:12:29 | [diff] [blame] | 19 | #include "chrome/browser/debugger/devtools_manager.h" |
[email protected] | 7577a5c5 | 2009-07-30 06:21:58 | [diff] [blame] | 20 | #include "chrome/browser/extensions/crx_installer.h" |
[email protected] | 5cbe1e2 | 2010-01-30 01:18:56 | [diff] [blame] | 21 | #include "chrome/browser/extensions/extension_accessibility_api.h" |
[email protected] | 840b0db | 2009-11-20 03:00:38 | [diff] [blame] | 22 | #include "chrome/browser/extensions/extension_bookmarks_module.h" |
[email protected] | b68d5ed | 2009-04-16 02:41:28 | [diff] [blame] | 23 | #include "chrome/browser/extensions/extension_browser_event_router.h" |
[email protected] | 2c5e1e1 | 2010-06-10 13:14:44 | [diff] [blame] | 24 | #include "chrome/browser/extensions/extension_cookies_api.h" |
[email protected] | c10da4b0 | 2010-03-25 14:38:32 | [diff] [blame] | 25 | #include "chrome/browser/extensions/extension_data_deleter.h" |
[email protected] | 86c008e8 | 2009-08-28 20:26:05 | [diff] [blame] | 26 | #include "chrome/browser/extensions/extension_dom_ui.h" |
[email protected] | 14a000d | 2010-04-29 21:44:24 | [diff] [blame] | 27 | #include "chrome/browser/extensions/extension_error_reporter.h" |
[email protected] | de768a83 | 2009-10-30 05:25:01 | [diff] [blame] | 28 | #include "chrome/browser/extensions/extension_history_api.h" |
[email protected] | b1748b1d8 | 2009-11-30 20:32:56 | [diff] [blame] | 29 | #include "chrome/browser/extensions/extension_host.h" |
[email protected] | 4814b51 | 2009-11-07 00:12:29 | [diff] [blame] | 30 | #include "chrome/browser/extensions/extension_process_manager.h" |
[email protected] | 93fd78f4 | 2009-07-10 16:43:17 | [diff] [blame] | 31 | #include "chrome/browser/extensions/extension_updater.h" |
[email protected] | a1257b1 | 2009-06-12 02:51:34 | [diff] [blame] | 32 | #include "chrome/browser/extensions/external_extension_provider.h" |
| 33 | #include "chrome/browser/extensions/external_pref_extension_provider.h" |
[email protected] | 56ad379 | 2010-05-28 17:45:33 | [diff] [blame] | 34 | #include "chrome/browser/net/chrome_url_request_context.h" |
[email protected] | 052313b | 2010-02-19 09:43:08 | [diff] [blame] | 35 | #include "chrome/browser/pref_service.h" |
[email protected] | 81e6378 | 2009-02-27 19:35:09 | [diff] [blame] | 36 | #include "chrome/browser/profile.h" |
[email protected] | 56ad379 | 2010-05-28 17:45:33 | [diff] [blame] | 37 | #include "chrome/browser/search_engines/template_url_model.h" |
[email protected] | aab98a5 | 2009-12-02 03:22:35 | [diff] [blame] | 38 | #include "chrome/common/child_process_logging.h" |
[email protected] | e2eb4311 | 2009-05-29 21:19:54 | [diff] [blame] | 39 | #include "chrome/common/chrome_switches.h" |
[email protected] | 5b1a0e2 | 2009-05-26 19:00:58 | [diff] [blame] | 40 | #include "chrome/common/extensions/extension.h" |
[email protected] | d7b36dc | 2009-10-29 21:47:40 | [diff] [blame] | 41 | #include "chrome/common/extensions/extension_constants.h" |
[email protected] | 05c8218 | 2010-06-24 17:49:08 | [diff] [blame] | 42 | #include "chrome/common/extensions/extension_error_utils.h" |
[email protected] | 7c927b6 | 2010-02-24 09:54:13 | [diff] [blame] | 43 | #include "chrome/common/extensions/extension_file_util.h" |
[email protected] | c6d474f8 | 2009-12-16 21:11:06 | [diff] [blame] | 44 | #include "chrome/common/extensions/extension_l10n_util.h" |
[email protected] | 8289126 | 2008-12-24 00:21:26 | [diff] [blame] | 45 | #include "chrome/common/notification_service.h" |
[email protected] | 4814b51 | 2009-11-07 00:12:29 | [diff] [blame] | 46 | #include "chrome/common/notification_type.h" |
[email protected] | 1952c7d | 2010-03-04 23:48:34 | [diff] [blame] | 47 | #include "chrome/common/json_value_serializer.h" |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 48 | #include "chrome/common/pref_names.h" |
[email protected] | a5720987 | 2009-05-04 22:53:14 | [diff] [blame] | 49 | #include "chrome/common/url_constants.h" |
[email protected] | c10da4b0 | 2010-03-25 14:38:32 | [diff] [blame] | 50 | #include "googleurl/src/gurl.h" |
[email protected] | 24b538a | 2010-02-27 01:22:44 | [diff] [blame] | 51 | #include "webkit/database/database_tracker.h" |
| 52 | #include "webkit/database/database_util.h" |
[email protected] | c6463165 | 2009-04-29 22:24:31 | [diff] [blame] | 53 | |
[email protected] | 79db623 | 2009-02-13 20:51:20 | [diff] [blame] | 54 | #if defined(OS_WIN) |
[email protected] | a1257b1 | 2009-06-12 02:51:34 | [diff] [blame] | 55 | #include "chrome/browser/extensions/external_registry_extension_provider_win.h" |
[email protected] | 79db623 | 2009-02-13 20:51:20 | [diff] [blame] | 56 | #endif |
[email protected] | 6014d67 | 2008-12-05 00:38:25 | [diff] [blame] | 57 | |
[email protected] | 5ef47ec | 2010-01-28 05:58:05 | [diff] [blame] | 58 | using base::Time; |
| 59 | |
[email protected] | c6d474f8 | 2009-12-16 21:11:06 | [diff] [blame] | 60 | namespace errors = extension_manifest_errors; |
| 61 | |
[email protected] | b6ab96d | 2009-08-20 18:58:19 | [diff] [blame] | 62 | namespace { |
| 63 | |
[email protected] | 2111b1a | 2010-03-12 18:12:44 | [diff] [blame] | 64 | static bool ShouldReloadExtensionManifest(const ExtensionInfo& info) { |
| 65 | // Always reload LOAD extension manifests, because they can change on disk |
| 66 | // independent of the manifest in our prefs. |
| 67 | if (info.extension_location == Extension::LOAD) |
| 68 | return true; |
| 69 | |
| 70 | // Otherwise, reload the manifest it needs to be relocalized. |
| 71 | return extension_l10n_util::ShouldRelocalizeManifest(info); |
| 72 | } |
| 73 | |
[email protected] | c6d474f8 | 2009-12-16 21:11:06 | [diff] [blame] | 74 | } // namespace |
[email protected] | b6ab96d | 2009-08-20 18:58:19 | [diff] [blame] | 75 | |
[email protected] | aa14270 | 2010-03-26 01:26:33 | [diff] [blame] | 76 | PendingExtensionInfo::PendingExtensionInfo(const GURL& update_url, |
[email protected] | aa14270 | 2010-03-26 01:26:33 | [diff] [blame] | 77 | bool is_theme, |
[email protected] | 4416c5a | 2010-06-26 01:28:57 | [diff] [blame^] | 78 | bool install_silently, |
| 79 | bool enable_on_install, |
| 80 | bool enable_incognito_on_install) |
[email protected] | aa14270 | 2010-03-26 01:26:33 | [diff] [blame] | 81 | : update_url(update_url), |
[email protected] | aa14270 | 2010-03-26 01:26:33 | [diff] [blame] | 82 | is_theme(is_theme), |
[email protected] | 4416c5a | 2010-06-26 01:28:57 | [diff] [blame^] | 83 | install_silently(install_silently), |
| 84 | enable_on_install(enable_on_install), |
| 85 | enable_incognito_on_install(enable_incognito_on_install) {} |
[email protected] | aa14270 | 2010-03-26 01:26:33 | [diff] [blame] | 86 | |
| 87 | PendingExtensionInfo::PendingExtensionInfo() |
| 88 | : update_url(), |
[email protected] | aa14270 | 2010-03-26 01:26:33 | [diff] [blame] | 89 | is_theme(false), |
[email protected] | 4416c5a | 2010-06-26 01:28:57 | [diff] [blame^] | 90 | install_silently(false), |
| 91 | enable_on_install(false), |
| 92 | enable_incognito_on_install(false) {} |
[email protected] | aa14270 | 2010-03-26 01:26:33 | [diff] [blame] | 93 | |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 94 | // ExtensionsService. |
[email protected] | 6014d67 | 2008-12-05 00:38:25 | [diff] [blame] | 95 | |
[email protected] | cc65591 | 2009-01-29 23:19:19 | [diff] [blame] | 96 | const char* ExtensionsService::kInstallDirectoryName = "Extensions"; |
| 97 | const char* ExtensionsService::kCurrentVersionFileName = "Current Version"; |
[email protected] | 494c06e | 2009-07-25 01:06:42 | [diff] [blame] | 98 | |
[email protected] | 334e04a | 2010-06-24 23:34:44 | [diff] [blame] | 99 | bool ExtensionsService::IsGalleryDownloadURL(const GURL& download_url) { |
[email protected] | b7c2f25 | 2009-12-08 00:47:23 | [diff] [blame] | 100 | if (StartsWithASCII(download_url.spec(), |
[email protected] | 334e04a | 2010-06-24 23:34:44 | [diff] [blame] | 101 | extension_urls::kMiniGalleryDownloadPrefix, false)) |
| 102 | return true; |
[email protected] | b7c2f25 | 2009-12-08 00:47:23 | [diff] [blame] | 103 | |
[email protected] | 334e04a | 2010-06-24 23:34:44 | [diff] [blame] | 104 | GURL gallery_download_prefix(extension_urls::kGalleryDownloadPrefix); |
| 105 | if (download_url.host() == gallery_download_prefix.host() && |
| 106 | StartsWithASCII(download_url.path(), |
| 107 | gallery_download_prefix.path(), false)) |
[email protected] | b7c2f25 | 2009-12-08 00:47:23 | [diff] [blame] | 108 | return true; |
[email protected] | b7c2f25 | 2009-12-08 00:47:23 | [diff] [blame] | 109 | |
[email protected] | 473ff6e | 2010-05-12 15:31:55 | [diff] [blame] | 110 | // Allow command line gallery url to be referrer for the gallery downloads. |
| 111 | std::string command_line_gallery_url = |
| 112 | CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
[email protected] | 2bce5e1 | 2010-05-13 01:18:07 | [diff] [blame] | 113 | switches::kAppsGalleryURL); |
[email protected] | 473ff6e | 2010-05-12 15:31:55 | [diff] [blame] | 114 | if (!command_line_gallery_url.empty() && |
| 115 | StartsWithASCII(download_url.spec(), |
[email protected] | 334e04a | 2010-06-24 23:34:44 | [diff] [blame] | 116 | extension_urls::kGalleryDownloadPrefix, false)) |
[email protected] | 473ff6e | 2010-05-12 15:31:55 | [diff] [blame] | 117 | return true; |
[email protected] | 334e04a | 2010-06-24 23:34:44 | [diff] [blame] | 118 | |
| 119 | return false; |
| 120 | } |
| 121 | |
| 122 | // static |
| 123 | bool ExtensionsService::IsDownloadFromGallery(const GURL& download_url, |
| 124 | const GURL& referrer_url) { |
| 125 | if (!IsGalleryDownloadURL(download_url)) |
| 126 | return false; |
| 127 | |
| 128 | if (StartsWithASCII(referrer_url.spec(), |
| 129 | extension_urls::kMiniGalleryBrowsePrefix, false)) |
| 130 | return true; |
| 131 | |
| 132 | if (StartsWithASCII(referrer_url.spec(), |
| 133 | Extension::ChromeStoreURL(), false)) |
| 134 | return true; |
| 135 | |
| 136 | // Allow command line gallery url to be referrer for the gallery downloads. |
| 137 | std::string command_line_gallery_url = |
| 138 | CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 139 | switches::kAppsGalleryURL); |
| 140 | if (!command_line_gallery_url.empty() && |
| 141 | StartsWithASCII(referrer_url.spec(), |
| 142 | command_line_gallery_url, false)) |
| 143 | return true; |
[email protected] | 473ff6e | 2010-05-12 15:31:55 | [diff] [blame] | 144 | |
[email protected] | b7c2f25 | 2009-12-08 00:47:23 | [diff] [blame] | 145 | return false; |
| 146 | } |
| 147 | |
[email protected] | ac02528 | 2009-12-16 19:16:38 | [diff] [blame] | 148 | bool ExtensionsService::IsDownloadFromMiniGallery(const GURL& download_url) { |
| 149 | return StartsWithASCII(download_url.spec(), |
| 150 | extension_urls::kMiniGalleryDownloadPrefix, |
| 151 | false); // case_sensitive |
| 152 | } |
| 153 | |
[email protected] | 81e6378 | 2009-02-27 19:35:09 | [diff] [blame] | 154 | ExtensionsService::ExtensionsService(Profile* profile, |
[email protected] | 36a784c | 2009-06-23 06:21:08 | [diff] [blame] | 155 | const CommandLine* command_line, |
[email protected] | a9b00ac | 2009-06-25 21:03:23 | [diff] [blame] | 156 | PrefService* prefs, |
| 157 | const FilePath& install_directory, |
[email protected] | 93fd78f4 | 2009-07-10 16:43:17 | [diff] [blame] | 158 | bool autoupdate_enabled) |
[email protected] | 6ef635e4 | 2009-07-26 06:16:12 | [diff] [blame] | 159 | : profile_(profile), |
| 160 | extension_prefs_(new ExtensionPrefs(prefs, install_directory)), |
[email protected] | a9b00ac | 2009-06-25 21:03:23 | [diff] [blame] | 161 | install_directory_(install_directory), |
[email protected] | 6d60703b | 2009-08-29 01:29:23 | [diff] [blame] | 162 | extensions_enabled_(true), |
[email protected] | e81dba3 | 2009-06-19 20:19:13 | [diff] [blame] | 163 | show_extensions_prompts_(true), |
[email protected] | e0360f2c | 2009-12-07 22:34:31 | [diff] [blame] | 164 | ready_(false), |
| 165 | ALLOW_THIS_IN_INITIALIZER_LIST(toolbar_model_(this)) { |
[email protected] | 36a784c | 2009-06-23 06:21:08 | [diff] [blame] | 166 | // Figure out if extension installation should be enabled. |
[email protected] | 6d60703b | 2009-08-29 01:29:23 | [diff] [blame] | 167 | if (command_line->HasSwitch(switches::kDisableExtensions)) { |
| 168 | extensions_enabled_ = false; |
| 169 | } else if (profile->GetPrefs()->GetBoolean(prefs::kDisableExtensions)) { |
| 170 | extensions_enabled_ = false; |
[email protected] | 6b75ec3 | 2009-08-14 06:37:18 | [diff] [blame] | 171 | } |
[email protected] | 36a784c | 2009-06-23 06:21:08 | [diff] [blame] | 172 | |
[email protected] | 4814b51 | 2009-11-07 00:12:29 | [diff] [blame] | 173 | registrar_.Add(this, NotificationType::EXTENSION_HOST_DID_STOP_LOADING, |
| 174 | NotificationService::AllSources()); |
[email protected] | a4ed628 | 2009-12-14 20:51:16 | [diff] [blame] | 175 | registrar_.Add(this, NotificationType::EXTENSION_PROCESS_TERMINATED, |
[email protected] | 31f7726 | 2009-12-02 20:48:53 | [diff] [blame] | 176 | Source<Profile>(profile_)); |
[email protected] | 4814b51 | 2009-11-07 00:12:29 | [diff] [blame] | 177 | |
[email protected] | 93fd78f4 | 2009-07-10 16:43:17 | [diff] [blame] | 178 | // Set up the ExtensionUpdater |
| 179 | if (autoupdate_enabled) { |
| 180 | int update_frequency = kDefaultUpdateFrequencySeconds; |
| 181 | if (command_line->HasSwitch(switches::kExtensionsUpdateFrequency)) { |
[email protected] | c4e52f0d | 2009-11-06 19:55:16 | [diff] [blame] | 182 | update_frequency = StringToInt(command_line->GetSwitchValueASCII( |
| 183 | switches::kExtensionsUpdateFrequency)); |
[email protected] | 93fd78f4 | 2009-07-10 16:43:17 | [diff] [blame] | 184 | } |
[email protected] | 95d2919 | 2009-10-30 01:49:06 | [diff] [blame] | 185 | updater_ = new ExtensionUpdater(this, prefs, update_frequency); |
[email protected] | 93fd78f4 | 2009-07-10 16:43:17 | [diff] [blame] | 186 | } |
| 187 | |
[email protected] | 95d2919 | 2009-10-30 01:49:06 | [diff] [blame] | 188 | backend_ = new ExtensionsServiceBackend(install_directory_); |
[email protected] | 6014d67 | 2008-12-05 00:38:25 | [diff] [blame] | 189 | } |
| 190 | |
| 191 | ExtensionsService::~ExtensionsService() { |
[email protected] | 9f1087e | 2009-06-15 17:29:32 | [diff] [blame] | 192 | UnloadAllExtensions(); |
[email protected] | 93fd78f4 | 2009-07-10 16:43:17 | [diff] [blame] | 193 | if (updater_.get()) { |
| 194 | updater_->Stop(); |
| 195 | } |
[email protected] | 6014d67 | 2008-12-05 00:38:25 | [diff] [blame] | 196 | } |
| 197 | |
[email protected] | c5ae74ab | 2010-04-15 18:14:37 | [diff] [blame] | 198 | void ExtensionsService::InitEventRouters() { |
| 199 | ExtensionHistoryEventRouter::GetInstance()->ObserveProfile(profile_); |
| 200 | ExtensionAccessibilityEventRouter::GetInstance()->ObserveProfile(profile_); |
[email protected] | 56ee015 | 2010-06-16 01:54:42 | [diff] [blame] | 201 | ExtensionBrowserEventRouter::GetInstance()->Init(profile_); |
[email protected] | c5ae74ab | 2010-04-15 18:14:37 | [diff] [blame] | 202 | ExtensionBookmarkEventRouter::GetSingleton()->Observe( |
| 203 | profile_->GetBookmarkModel()); |
[email protected] | 2c5e1e1 | 2010-06-10 13:14:44 | [diff] [blame] | 204 | ExtensionCookiesEventRouter::GetInstance()->Init(); |
[email protected] | c5ae74ab | 2010-04-15 18:14:37 | [diff] [blame] | 205 | } |
| 206 | |
[email protected] | 9f1087e | 2009-06-15 17:29:32 | [diff] [blame] | 207 | void ExtensionsService::Init() { |
[email protected] | c6e4a341 | 2009-06-24 15:45:29 | [diff] [blame] | 208 | DCHECK(!ready_); |
[email protected] | 93fd78f4 | 2009-07-10 16:43:17 | [diff] [blame] | 209 | DCHECK_EQ(extensions_.size(), 0u); |
[email protected] | 9f1087e | 2009-06-15 17:29:32 | [diff] [blame] | 210 | |
[email protected] | 95dd38f | 2009-10-20 20:09:15 | [diff] [blame] | 211 | // Hack: we need to ensure the ResourceDispatcherHost is ready before we load |
| 212 | // the first extension, because its members listen for loaded notifications. |
| 213 | g_browser_process->resource_dispatcher_host(); |
| 214 | |
[email protected] | 9f1087e | 2009-06-15 17:29:32 | [diff] [blame] | 215 | LoadAllExtensions(); |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 216 | |
[email protected] | 9f1087e | 2009-06-15 17:29:32 | [diff] [blame] | 217 | // TODO(erikkay) this should probably be deferred to a future point |
| 218 | // rather than running immediately at startup. |
[email protected] | 93fd78f4 | 2009-07-10 16:43:17 | [diff] [blame] | 219 | CheckForExternalUpdates(); |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 220 | |
[email protected] | 9f1087e | 2009-06-15 17:29:32 | [diff] [blame] | 221 | // TODO(erikkay) this should probably be deferred as well. |
| 222 | GarbageCollectExtensions(); |
[email protected] | 6014d67 | 2008-12-05 00:38:25 | [diff] [blame] | 223 | } |
| 224 | |
[email protected] | 3cf4f099 | 2009-02-03 23:00:30 | [diff] [blame] | 225 | void ExtensionsService::InstallExtension(const FilePath& extension_path) { |
[email protected] | 6dfbbf8 | 2010-03-12 23:09:16 | [diff] [blame] | 226 | scoped_refptr<CrxInstaller> installer( |
| 227 | new CrxInstaller(install_directory_, |
| 228 | this, // frontend |
| 229 | NULL)); // no client (silent install) |
| 230 | installer->set_allow_privilege_increase(true); |
| 231 | installer->InstallCrx(extension_path); |
[email protected] | 3cf4f099 | 2009-02-03 23:00:30 | [diff] [blame] | 232 | } |
| 233 | |
[email protected] | aa14270 | 2010-03-26 01:26:33 | [diff] [blame] | 234 | namespace { |
| 235 | // TODO(akalin): Put this somewhere where both crx_installer.cc and |
| 236 | // this file can use it. |
| 237 | void DeleteFileHelper(const FilePath& path, bool recursive) { |
| 238 | DCHECK(ChromeThread::CurrentlyOn(ChromeThread::FILE)); |
| 239 | file_util::Delete(path, recursive); |
| 240 | } |
| 241 | } // namespace |
| 242 | |
[email protected] | e957fe5 | 2009-06-23 16:51:05 | [diff] [blame] | 243 | void ExtensionsService::UpdateExtension(const std::string& id, |
[email protected] | 5c851620 | 2010-03-18 21:43:34 | [diff] [blame] | 244 | const FilePath& extension_path, |
| 245 | const GURL& download_url) { |
[email protected] | aa14270 | 2010-03-26 01:26:33 | [diff] [blame] | 246 | PendingExtensionMap::const_iterator it = pending_extensions_.find(id); |
| 247 | if ((it == pending_extensions_.end()) && |
| 248 | !GetExtensionByIdInternal(id, true, true)) { |
| 249 | LOG(WARNING) << "Will not update extension " << id |
| 250 | << " because it is not installed or pending"; |
| 251 | // Delete extension_path since we're not creating a CrxInstaller |
| 252 | // that would do it for us. |
| 253 | ChromeThread::PostTask( |
| 254 | ChromeThread::FILE, FROM_HERE, |
| 255 | NewRunnableFunction(&DeleteFileHelper, extension_path, false)); |
[email protected] | 4c96793 | 2009-07-31 01:15:49 | [diff] [blame] | 256 | return; |
[email protected] | e957fe5 | 2009-06-23 16:51:05 | [diff] [blame] | 257 | } |
| 258 | |
[email protected] | aa14270 | 2010-03-26 01:26:33 | [diff] [blame] | 259 | // We want a silent install only for non-pending extensions and |
| 260 | // pending extensions that have install_silently set. |
| 261 | ExtensionInstallUI* client = |
| 262 | ((it == pending_extensions_.end()) || it->second.install_silently) ? |
| 263 | NULL : new ExtensionInstallUI(profile_); |
| 264 | |
[email protected] | 6dfbbf8 | 2010-03-12 23:09:16 | [diff] [blame] | 265 | scoped_refptr<CrxInstaller> installer( |
| 266 | new CrxInstaller(install_directory_, |
| 267 | this, // frontend |
[email protected] | aa14270 | 2010-03-26 01:26:33 | [diff] [blame] | 268 | client)); |
[email protected] | 6dfbbf8 | 2010-03-12 23:09:16 | [diff] [blame] | 269 | installer->set_expected_id(id); |
| 270 | installer->set_delete_source(true); |
[email protected] | 9f72aa0 | 2010-06-25 10:01:05 | [diff] [blame] | 271 | installer->set_limit_web_extent_to_download_host(true); |
[email protected] | 5c851620 | 2010-03-18 21:43:34 | [diff] [blame] | 272 | installer->set_original_url(download_url); |
[email protected] | 6dfbbf8 | 2010-03-12 23:09:16 | [diff] [blame] | 273 | installer->InstallCrx(extension_path); |
[email protected] | e957fe5 | 2009-06-23 16:51:05 | [diff] [blame] | 274 | } |
| 275 | |
[email protected] | aa14270 | 2010-03-26 01:26:33 | [diff] [blame] | 276 | void ExtensionsService::AddPendingExtension( |
| 277 | const std::string& id, const GURL& update_url, |
[email protected] | 4416c5a | 2010-06-26 01:28:57 | [diff] [blame^] | 278 | bool is_theme, bool install_silently, |
| 279 | bool enable_on_install, bool enable_incognito_on_install) { |
[email protected] | aa14270 | 2010-03-26 01:26:33 | [diff] [blame] | 280 | if (GetExtensionByIdInternal(id, true, true)) { |
[email protected] | efee9f26 | 2010-03-29 21:26:25 | [diff] [blame] | 281 | LOG(DFATAL) << "Trying to add pending extension " << id |
| 282 | << " which already exists"; |
[email protected] | aa14270 | 2010-03-26 01:26:33 | [diff] [blame] | 283 | return; |
| 284 | } |
[email protected] | 4416c5a | 2010-06-26 01:28:57 | [diff] [blame^] | 285 | AddPendingExtensionInternal( |
| 286 | id, update_url, is_theme, install_silently, |
| 287 | enable_on_install, enable_incognito_on_install); |
[email protected] | aa14270 | 2010-03-26 01:26:33 | [diff] [blame] | 288 | } |
| 289 | |
| 290 | void ExtensionsService::AddPendingExtensionInternal( |
| 291 | const std::string& id, const GURL& update_url, |
[email protected] | 4416c5a | 2010-06-26 01:28:57 | [diff] [blame^] | 292 | bool is_theme, bool install_silently, |
| 293 | bool enable_on_install, bool enable_incognito_on_install) { |
[email protected] | aa14270 | 2010-03-26 01:26:33 | [diff] [blame] | 294 | pending_extensions_[id] = |
[email protected] | 4416c5a | 2010-06-26 01:28:57 | [diff] [blame^] | 295 | PendingExtensionInfo(update_url, is_theme, install_silently, |
| 296 | enable_on_install, enable_incognito_on_install); |
[email protected] | aa14270 | 2010-03-26 01:26:33 | [diff] [blame] | 297 | } |
| 298 | |
[email protected] | 9cddd470 | 2009-07-27 22:09:40 | [diff] [blame] | 299 | void ExtensionsService::ReloadExtension(const std::string& extension_id) { |
[email protected] | b65272f | 2009-08-31 15:47:06 | [diff] [blame] | 300 | FilePath path; |
[email protected] | 61b41161 | 2009-11-10 23:17:41 | [diff] [blame] | 301 | Extension* current_extension = GetExtensionById(extension_id, false); |
[email protected] | 9cddd470 | 2009-07-27 22:09:40 | [diff] [blame] | 302 | |
[email protected] | b65272f | 2009-08-31 15:47:06 | [diff] [blame] | 303 | // Unload the extension if it's loaded. It might not be loaded if it crashed. |
| 304 | if (current_extension) { |
[email protected] | 4814b51 | 2009-11-07 00:12:29 | [diff] [blame] | 305 | // If the extension has an inspector open for its background page, detach |
| 306 | // the inspector and hang onto a cookie for it, so that we can reattach |
| 307 | // later. |
| 308 | ExtensionProcessManager* manager = profile_->GetExtensionProcessManager(); |
| 309 | ExtensionHost* host = manager->GetBackgroundHostForExtension( |
| 310 | current_extension); |
| 311 | if (host) { |
| 312 | // Look for an open inspector for the background page. |
| 313 | int devtools_cookie = DevToolsManager::GetInstance()->DetachClientHost( |
| 314 | host->render_view_host()); |
| 315 | if (devtools_cookie >= 0) |
| 316 | orphaned_dev_tools_[extension_id] = devtools_cookie; |
| 317 | } |
| 318 | |
[email protected] | b65272f | 2009-08-31 15:47:06 | [diff] [blame] | 319 | path = current_extension->path(); |
| 320 | UnloadExtension(extension_id); |
[email protected] | 1eb17508 | 2010-02-10 09:26:16 | [diff] [blame] | 321 | } else { |
| 322 | path = unloaded_extension_paths_[extension_id]; |
[email protected] | b65272f | 2009-08-31 15:47:06 | [diff] [blame] | 323 | } |
| 324 | |
[email protected] | e6090e4 | 2010-03-23 22:44:08 | [diff] [blame] | 325 | // Check the installed extensions to see if what we're reloading was already |
| 326 | // installed. |
| 327 | scoped_ptr<ExtensionInfo> installed_extension( |
| 328 | extension_prefs_->GetInstalledExtensionInfo(extension_id)); |
| 329 | if (installed_extension.get() && |
| 330 | installed_extension->extension_manifest.get()) { |
| 331 | LoadInstalledExtension(*installed_extension, false); |
| 332 | } else { |
| 333 | // We should always be able to remember the extension's path. If it's not in |
| 334 | // the map, someone failed to update |unloaded_extension_paths_|. |
| 335 | CHECK(!path.empty()); |
| 336 | LoadExtension(path); |
| 337 | } |
[email protected] | 9cddd470 | 2009-07-27 22:09:40 | [diff] [blame] | 338 | } |
| 339 | |
[email protected] | 27b985d | 2009-06-25 17:53:15 | [diff] [blame] | 340 | void ExtensionsService::UninstallExtension(const std::string& extension_id, |
| 341 | bool external_uninstall) { |
[email protected] | 0c6da50 | 2009-08-14 22:32:39 | [diff] [blame] | 342 | Extension* extension = GetExtensionByIdInternal(extension_id, true, true); |
[email protected] | 631cf82 | 2009-05-15 07:01:25 | [diff] [blame] | 343 | |
[email protected] | 9f1087e | 2009-06-15 17:29:32 | [diff] [blame] | 344 | // Callers should not send us nonexistant extensions. |
[email protected] | e72e8eb8 | 2009-06-18 17:21:51 | [diff] [blame] | 345 | DCHECK(extension); |
[email protected] | 9f1087e | 2009-06-15 17:29:32 | [diff] [blame] | 346 | |
[email protected] | 831aa21 | 2010-03-26 13:55:19 | [diff] [blame] | 347 | // Get hold of information we need after unloading, since the extension |
| 348 | // pointer will be invalid then. |
| 349 | GURL extension_url(extension->url()); |
| 350 | Extension::Location location(extension->location()); |
| 351 | |
| 352 | // Also copy the extension identifier since the reference might have been |
| 353 | // obtained via Extension::id(). |
| 354 | std::string extension_id_copy(extension_id); |
| 355 | |
[email protected] | 56ad379 | 2010-05-28 17:45:33 | [diff] [blame] | 356 | if (profile_->GetTemplateURLModel()) |
| 357 | profile_->GetTemplateURLModel()->UnregisterExtensionKeyword(extension); |
| 358 | |
[email protected] | 831aa21 | 2010-03-26 13:55:19 | [diff] [blame] | 359 | // Unload before doing more cleanup to ensure that nothing is hanging on to |
| 360 | // any of these resources. |
| 361 | UnloadExtension(extension_id); |
| 362 | |
| 363 | extension_prefs_->OnExtensionUninstalled(extension_id_copy, location, |
| 364 | external_uninstall); |
[email protected] | 9f1087e | 2009-06-15 17:29:32 | [diff] [blame] | 365 | |
| 366 | // Tell the backend to start deleting installed extensions on the file thread. |
[email protected] | 831aa21 | 2010-03-26 13:55:19 | [diff] [blame] | 367 | if (Extension::LOAD != location) { |
[email protected] | 95d2919 | 2009-10-30 01:49:06 | [diff] [blame] | 368 | ChromeThread::PostTask( |
| 369 | ChromeThread::FILE, FROM_HERE, |
| 370 | NewRunnableFunction( |
[email protected] | ca3dbf5 | 2010-05-19 22:27:06 | [diff] [blame] | 371 | &extension_file_util::UninstallExtension, |
| 372 | install_directory_, |
| 373 | extension_id_copy)); |
[email protected] | 9f1087e | 2009-06-15 17:29:32 | [diff] [blame] | 374 | } |
| 375 | |
[email protected] | c10da4b0 | 2010-03-25 14:38:32 | [diff] [blame] | 376 | ClearExtensionData(extension_url); |
| 377 | } |
| 378 | |
| 379 | void ExtensionsService::ClearExtensionData(const GURL& extension_url) { |
| 380 | scoped_refptr<ExtensionDataDeleter> deleter( |
| 381 | new ExtensionDataDeleter(profile_, extension_url)); |
| 382 | deleter->StartDeleting(); |
[email protected] | 9f1087e | 2009-06-15 17:29:32 | [diff] [blame] | 383 | } |
| 384 | |
[email protected] | 0c6da50 | 2009-08-14 22:32:39 | [diff] [blame] | 385 | void ExtensionsService::EnableExtension(const std::string& extension_id) { |
| 386 | Extension* extension = GetExtensionByIdInternal(extension_id, false, true); |
| 387 | if (!extension) { |
| 388 | NOTREACHED() << "Trying to enable an extension that isn't disabled."; |
| 389 | return; |
| 390 | } |
| 391 | |
[email protected] | e8c729a | 2010-03-09 19:55:19 | [diff] [blame] | 392 | extension_prefs_->SetExtensionState(extension, Extension::ENABLED); |
[email protected] | 1784e83a | 2009-09-08 21:01:52 | [diff] [blame] | 393 | |
[email protected] | 0c6da50 | 2009-08-14 22:32:39 | [diff] [blame] | 394 | // Move it over to the enabled list. |
[email protected] | 0c6da50 | 2009-08-14 22:32:39 | [diff] [blame] | 395 | extensions_.push_back(extension); |
| 396 | ExtensionList::iterator iter = std::find(disabled_extensions_.begin(), |
| 397 | disabled_extensions_.end(), |
| 398 | extension); |
| 399 | disabled_extensions_.erase(iter); |
| 400 | |
[email protected] | 86c008e8 | 2009-08-28 20:26:05 | [diff] [blame] | 401 | ExtensionDOMUI::RegisterChromeURLOverrides(profile_, |
| 402 | extension->GetChromeURLOverrides()); |
| 403 | |
[email protected] | 62d30f4 | 2009-10-01 22:36:06 | [diff] [blame] | 404 | NotifyExtensionLoaded(extension); |
[email protected] | aab98a5 | 2009-12-02 03:22:35 | [diff] [blame] | 405 | UpdateActiveExtensionsInCrashReporter(); |
[email protected] | 0c6da50 | 2009-08-14 22:32:39 | [diff] [blame] | 406 | } |
| 407 | |
[email protected] | 1784e83a | 2009-09-08 21:01:52 | [diff] [blame] | 408 | void ExtensionsService::DisableExtension(const std::string& extension_id) { |
| 409 | Extension* extension = GetExtensionByIdInternal(extension_id, true, false); |
[email protected] | b2ba996 | 2009-12-10 20:10:15 | [diff] [blame] | 410 | // The extension may have been disabled already. |
| 411 | if (!extension) |
[email protected] | 1784e83a | 2009-09-08 21:01:52 | [diff] [blame] | 412 | return; |
[email protected] | 1784e83a | 2009-09-08 21:01:52 | [diff] [blame] | 413 | |
[email protected] | e8c729a | 2010-03-09 19:55:19 | [diff] [blame] | 414 | extension_prefs_->SetExtensionState(extension, Extension::DISABLED); |
[email protected] | 1784e83a | 2009-09-08 21:01:52 | [diff] [blame] | 415 | |
| 416 | // Move it over to the disabled list. |
| 417 | disabled_extensions_.push_back(extension); |
| 418 | ExtensionList::iterator iter = std::find(extensions_.begin(), |
| 419 | extensions_.end(), |
| 420 | extension); |
| 421 | extensions_.erase(iter); |
| 422 | |
| 423 | ExtensionDOMUI::UnregisterChromeURLOverrides(profile_, |
| 424 | extension->GetChromeURLOverrides()); |
| 425 | |
[email protected] | 62d30f4 | 2009-10-01 22:36:06 | [diff] [blame] | 426 | NotifyExtensionUnloaded(extension); |
[email protected] | aab98a5 | 2009-12-02 03:22:35 | [diff] [blame] | 427 | UpdateActiveExtensionsInCrashReporter(); |
[email protected] | 1784e83a | 2009-09-08 21:01:52 | [diff] [blame] | 428 | } |
| 429 | |
[email protected] | 9f1087e | 2009-06-15 17:29:32 | [diff] [blame] | 430 | void ExtensionsService::LoadExtension(const FilePath& extension_path) { |
[email protected] | 95d2919 | 2009-10-30 01:49:06 | [diff] [blame] | 431 | ChromeThread::PostTask( |
| 432 | ChromeThread::FILE, FROM_HERE, |
| 433 | NewRunnableMethod( |
| 434 | backend_.get(), |
| 435 | &ExtensionsServiceBackend::LoadSingleExtension, |
| 436 | extension_path, scoped_refptr<ExtensionsService>(this))); |
[email protected] | 9f1087e | 2009-06-15 17:29:32 | [diff] [blame] | 437 | } |
| 438 | |
[email protected] | 1952c7d | 2010-03-04 23:48:34 | [diff] [blame] | 439 | void ExtensionsService::LoadComponentExtensions() { |
| 440 | for (RegisteredComponentExtensions::iterator it = |
| 441 | component_extension_manifests_.begin(); |
| 442 | it != component_extension_manifests_.end(); ++it) { |
| 443 | JSONStringValueSerializer serializer(it->manifest); |
[email protected] | ba39967 | 2010-04-06 15:42:39 | [diff] [blame] | 444 | scoped_ptr<Value> manifest(serializer.Deserialize(NULL, NULL)); |
[email protected] | 999731f | 2010-03-22 19:13:53 | [diff] [blame] | 445 | if (!manifest.get()) { |
[email protected] | 960ef8ae | 2010-05-06 17:12:29 | [diff] [blame] | 446 | DLOG(ERROR) << "Failed to retrieve manifest for extension"; |
[email protected] | 999731f | 2010-03-22 19:13:53 | [diff] [blame] | 447 | continue; |
| 448 | } |
[email protected] | 1952c7d | 2010-03-04 23:48:34 | [diff] [blame] | 449 | |
| 450 | scoped_ptr<Extension> extension(new Extension(it->root_directory)); |
| 451 | extension->set_location(Extension::COMPONENT); |
| 452 | |
| 453 | std::string error; |
| 454 | if (!extension->InitFromValue( |
| 455 | *static_cast<DictionaryValue*>(manifest.get()), |
| 456 | true, // require key |
| 457 | &error)) { |
| 458 | NOTREACHED(); |
| 459 | return; |
| 460 | } |
| 461 | |
| 462 | OnExtensionLoaded(extension.release(), false); // Don't allow privilege |
| 463 | // increase. |
| 464 | } |
| 465 | } |
| 466 | |
[email protected] | 9f1087e | 2009-06-15 17:29:32 | [diff] [blame] | 467 | void ExtensionsService::LoadAllExtensions() { |
[email protected] | cc2c343 | 2009-11-06 17:24:36 | [diff] [blame] | 468 | base::TimeTicks start_time = base::TimeTicks::Now(); |
| 469 | |
[email protected] | 1952c7d | 2010-03-04 23:48:34 | [diff] [blame] | 470 | // Load any component extensions. |
| 471 | LoadComponentExtensions(); |
| 472 | |
[email protected] | e72e8eb8 | 2009-06-18 17:21:51 | [diff] [blame] | 473 | // Load the previously installed extensions. |
[email protected] | c6d474f8 | 2009-12-16 21:11:06 | [diff] [blame] | 474 | scoped_ptr<ExtensionPrefs::ExtensionsInfo> info( |
[email protected] | e6090e4 | 2010-03-23 22:44:08 | [diff] [blame] | 475 | extension_prefs_->GetInstalledExtensionsInfo()); |
[email protected] | c6d474f8 | 2009-12-16 21:11:06 | [diff] [blame] | 476 | |
| 477 | // If any extensions need localization, we bounce them all to the file thread |
| 478 | // for re-reading and localization. |
| 479 | for (size_t i = 0; i < info->size(); ++i) { |
[email protected] | 2111b1a | 2010-03-12 18:12:44 | [diff] [blame] | 480 | if (ShouldReloadExtensionManifest(*info->at(i))) { |
[email protected] | c6d474f8 | 2009-12-16 21:11:06 | [diff] [blame] | 481 | ChromeThread::PostTask( |
| 482 | ChromeThread::FILE, FROM_HERE, NewRunnableMethod( |
| 483 | backend_.get(), |
[email protected] | 2111b1a | 2010-03-12 18:12:44 | [diff] [blame] | 484 | &ExtensionsServiceBackend::ReloadExtensionManifests, |
[email protected] | c6d474f8 | 2009-12-16 21:11:06 | [diff] [blame] | 485 | info.release(), // Callee takes ownership of the memory. |
| 486 | start_time, |
| 487 | scoped_refptr<ExtensionsService>(this))); |
| 488 | return; |
| 489 | } |
| 490 | } |
| 491 | |
| 492 | // Don't update prefs. |
| 493 | // Callee takes ownership of the memory. |
| 494 | ContinueLoadAllExtensions(info.release(), start_time, false); |
| 495 | } |
| 496 | |
| 497 | void ExtensionsService::ContinueLoadAllExtensions( |
| 498 | ExtensionPrefs::ExtensionsInfo* extensions_info, |
| 499 | base::TimeTicks start_time, |
| 500 | bool write_to_prefs) { |
| 501 | scoped_ptr<ExtensionPrefs::ExtensionsInfo> info(extensions_info); |
| 502 | |
| 503 | for (size_t i = 0; i < info->size(); ++i) { |
| 504 | LoadInstalledExtension(*info->at(i), write_to_prefs); |
| 505 | } |
| 506 | |
[email protected] | ae09ca6 | 2009-08-21 19:46:46 | [diff] [blame] | 507 | OnLoadedInstalledExtensions(); |
[email protected] | cc2c343 | 2009-11-06 17:24:36 | [diff] [blame] | 508 | |
| 509 | UMA_HISTOGRAM_COUNTS_100("Extensions.LoadAll", extensions_.size()); |
| 510 | UMA_HISTOGRAM_COUNTS_100("Extensions.Disabled", disabled_extensions_.size()); |
| 511 | |
[email protected] | 1952c7d | 2010-03-04 23:48:34 | [diff] [blame] | 512 | UMA_HISTOGRAM_TIMES("Extensions.LoadAllTime", |
| 513 | base::TimeTicks::Now() - start_time); |
[email protected] | cc2c343 | 2009-11-06 17:24:36 | [diff] [blame] | 514 | |
[email protected] | 1952c7d | 2010-03-04 23:48:34 | [diff] [blame] | 515 | int user_script_count = 0; |
| 516 | int extension_count = 0; |
| 517 | int theme_count = 0; |
| 518 | int external_count = 0; |
| 519 | int page_action_count = 0; |
| 520 | int browser_action_count = 0; |
| 521 | ExtensionList::iterator ex; |
| 522 | for (ex = extensions_.begin(); ex != extensions_.end(); ++ex) { |
| 523 | // Don't count component extensions, since they are only extensions as an |
| 524 | // implementation detail. |
| 525 | if ((*ex)->location() == Extension::COMPONENT) |
| 526 | continue; |
| 527 | |
[email protected] | e8c729a | 2010-03-09 19:55:19 | [diff] [blame] | 528 | // Don't count unpacked extensions, since they're a developer-specific |
| 529 | // feature. |
| 530 | if ((*ex)->location() == Extension::LOAD) |
| 531 | continue; |
| 532 | |
[email protected] | 3ba0fd3 | 2010-06-19 05:39:10 | [diff] [blame] | 533 | if ((*ex)->is_theme()) { |
[email protected] | 1952c7d | 2010-03-04 23:48:34 | [diff] [blame] | 534 | theme_count++; |
| 535 | } else if ((*ex)->converted_from_user_script()) { |
| 536 | user_script_count++; |
| 537 | } else { |
| 538 | extension_count++; |
[email protected] | cc2c343 | 2009-11-06 17:24:36 | [diff] [blame] | 539 | } |
[email protected] | 1952c7d | 2010-03-04 23:48:34 | [diff] [blame] | 540 | if (Extension::IsExternalLocation((*ex)->location())) { |
| 541 | external_count++; |
| 542 | } |
| 543 | if ((*ex)->page_action() != NULL) { |
| 544 | page_action_count++; |
| 545 | } |
| 546 | if ((*ex)->browser_action() != NULL) { |
| 547 | browser_action_count++; |
| 548 | } |
[email protected] | cc2c343 | 2009-11-06 17:24:36 | [diff] [blame] | 549 | } |
[email protected] | 1952c7d | 2010-03-04 23:48:34 | [diff] [blame] | 550 | UMA_HISTOGRAM_COUNTS_100("Extensions.LoadExtension", extension_count); |
| 551 | UMA_HISTOGRAM_COUNTS_100("Extensions.LoadUserScript", user_script_count); |
| 552 | UMA_HISTOGRAM_COUNTS_100("Extensions.LoadTheme", theme_count); |
| 553 | UMA_HISTOGRAM_COUNTS_100("Extensions.LoadExternal", external_count); |
| 554 | UMA_HISTOGRAM_COUNTS_100("Extensions.LoadPageAction", page_action_count); |
| 555 | UMA_HISTOGRAM_COUNTS_100("Extensions.LoadBrowserAction", |
| 556 | browser_action_count); |
[email protected] | ae09ca6 | 2009-08-21 19:46:46 | [diff] [blame] | 557 | } |
| 558 | |
[email protected] | c6d474f8 | 2009-12-16 21:11:06 | [diff] [blame] | 559 | void ExtensionsService::LoadInstalledExtension(const ExtensionInfo& info, |
| 560 | bool write_to_prefs) { |
[email protected] | ae09ca6 | 2009-08-21 19:46:46 | [diff] [blame] | 561 | std::string error; |
| 562 | Extension* extension = NULL; |
[email protected] | c6d474f8 | 2009-12-16 21:11:06 | [diff] [blame] | 563 | if (info.extension_manifest.get()) { |
| 564 | scoped_ptr<Extension> tmp(new Extension(info.extension_path)); |
[email protected] | e8c729a | 2010-03-09 19:55:19 | [diff] [blame] | 565 | bool require_key = info.extension_location != Extension::LOAD; |
| 566 | if (tmp->InitFromValue(*info.extension_manifest, require_key, &error)) |
[email protected] | ae09ca6 | 2009-08-21 19:46:46 | [diff] [blame] | 567 | extension = tmp.release(); |
[email protected] | ae09ca6 | 2009-08-21 19:46:46 | [diff] [blame] | 568 | } else { |
[email protected] | c6d474f8 | 2009-12-16 21:11:06 | [diff] [blame] | 569 | error = errors::kManifestUnreadable; |
[email protected] | ae09ca6 | 2009-08-21 19:46:46 | [diff] [blame] | 570 | } |
| 571 | |
| 572 | if (!extension) { |
[email protected] | c6d474f8 | 2009-12-16 21:11:06 | [diff] [blame] | 573 | ReportExtensionLoadError(info.extension_path, |
[email protected] | d11c8e9 | 2009-10-20 23:26:40 | [diff] [blame] | 574 | error, |
| 575 | NotificationType::EXTENSION_INSTALL_ERROR, |
| 576 | false); |
[email protected] | ae09ca6 | 2009-08-21 19:46:46 | [diff] [blame] | 577 | return; |
| 578 | } |
| 579 | |
[email protected] | c6d474f8 | 2009-12-16 21:11:06 | [diff] [blame] | 580 | extension->set_location(info.extension_location); |
| 581 | |
| 582 | if (write_to_prefs) |
| 583 | extension_prefs_->UpdateManifest(extension); |
| 584 | |
[email protected] | 2a40953 | 2009-08-28 19:39:44 | [diff] [blame] | 585 | OnExtensionLoaded(extension, true); |
[email protected] | ae09ca6 | 2009-08-21 19:46:46 | [diff] [blame] | 586 | |
[email protected] | c6d474f8 | 2009-12-16 21:11:06 | [diff] [blame] | 587 | if (info.extension_location == Extension::EXTERNAL_PREF || |
| 588 | info.extension_location == Extension::EXTERNAL_REGISTRY) { |
[email protected] | 95d2919 | 2009-10-30 01:49:06 | [diff] [blame] | 589 | ChromeThread::PostTask( |
| 590 | ChromeThread::FILE, FROM_HERE, |
| 591 | NewRunnableMethod( |
[email protected] | c6d474f8 | 2009-12-16 21:11:06 | [diff] [blame] | 592 | backend_.get(), |
| 593 | &ExtensionsServiceBackend::CheckExternalUninstall, |
| 594 | scoped_refptr<ExtensionsService>(this), |
| 595 | info.extension_id, |
| 596 | info.extension_location)); |
[email protected] | ae09ca6 | 2009-08-21 19:46:46 | [diff] [blame] | 597 | } |
[email protected] | 9f1087e | 2009-06-15 17:29:32 | [diff] [blame] | 598 | } |
| 599 | |
[email protected] | 62d30f4 | 2009-10-01 22:36:06 | [diff] [blame] | 600 | void ExtensionsService::NotifyExtensionLoaded(Extension* extension) { |
[email protected] | 57a777f7 | 2010-03-31 01:09:42 | [diff] [blame] | 601 | // The ChromeURLRequestContexts need to be first to know that the extension |
[email protected] | 62d30f4 | 2009-10-01 22:36:06 | [diff] [blame] | 602 | // was loaded, otherwise a race can arise where a renderer that is created |
| 603 | // 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] | 604 | // that the request context doesn't yet know about. The profile is responsible |
| 605 | // for ensuring its URLRequestContexts appropriately discover the loaded |
| 606 | // extension. |
| 607 | if (profile_) { |
| 608 | profile_->RegisterExtensionWithRequestContexts(extension); |
[email protected] | 24b538a | 2010-02-27 01:22:44 | [diff] [blame] | 609 | |
| 610 | // Check if this permission requires unlimited storage quota |
| 611 | if (extension->HasApiPermission(Extension::kUnlimitedStoragePermission)) { |
| 612 | string16 origin_identifier = |
| 613 | webkit_database::DatabaseUtil::GetOriginIdentifier(extension->url()); |
| 614 | ChromeThread::PostTask( |
| 615 | ChromeThread::FILE, FROM_HERE, |
| 616 | NewRunnableMethod( |
| 617 | profile_->GetDatabaseTracker(), |
| 618 | &webkit_database::DatabaseTracker::SetOriginQuotaInMemory, |
| 619 | origin_identifier, |
| 620 | kint64max)); |
| 621 | } |
[email protected] | 62d30f4 | 2009-10-01 22:36:06 | [diff] [blame] | 622 | } |
| 623 | |
[email protected] | 57a777f7 | 2010-03-31 01:09:42 | [diff] [blame] | 624 | LOG(INFO) << "Sending EXTENSION_LOADED"; |
| 625 | |
[email protected] | 62d30f4 | 2009-10-01 22:36:06 | [diff] [blame] | 626 | NotificationService::current()->Notify( |
| 627 | NotificationType::EXTENSION_LOADED, |
[email protected] | 24e7a9d | 2009-11-04 11:11:34 | [diff] [blame] | 628 | Source<Profile>(profile_), |
[email protected] | 62d30f4 | 2009-10-01 22:36:06 | [diff] [blame] | 629 | Details<Extension>(extension)); |
| 630 | } |
| 631 | |
| 632 | void ExtensionsService::NotifyExtensionUnloaded(Extension* extension) { |
| 633 | LOG(INFO) << "Sending EXTENSION_UNLOADED"; |
| 634 | |
| 635 | NotificationService::current()->Notify( |
| 636 | NotificationType::EXTENSION_UNLOADED, |
[email protected] | 24e7a9d | 2009-11-04 11:11:34 | [diff] [blame] | 637 | Source<Profile>(profile_), |
[email protected] | 62d30f4 | 2009-10-01 22:36:06 | [diff] [blame] | 638 | Details<Extension>(extension)); |
| 639 | |
[email protected] | 57a777f7 | 2010-03-31 01:09:42 | [diff] [blame] | 640 | if (profile_) { |
| 641 | profile_->UnregisterExtensionWithRequestContexts(extension); |
| 642 | |
| 643 | // Check if this permission required unlimited storage quota, reset its |
| 644 | // in-memory quota. |
| 645 | if (extension->HasApiPermission(Extension::kUnlimitedStoragePermission)) { |
| 646 | string16 origin_identifier = |
| 647 | webkit_database::DatabaseUtil::GetOriginIdentifier(extension->url()); |
[email protected] | 95d2919 | 2009-10-30 01:49:06 | [diff] [blame] | 648 | ChromeThread::PostTask( |
[email protected] | 57a777f7 | 2010-03-31 01:09:42 | [diff] [blame] | 649 | ChromeThread::FILE, FROM_HERE, |
[email protected] | be180c80 | 2009-10-23 06:33:31 | [diff] [blame] | 650 | NewRunnableMethod( |
[email protected] | 57a777f7 | 2010-03-31 01:09:42 | [diff] [blame] | 651 | profile_->GetDatabaseTracker(), |
| 652 | &webkit_database::DatabaseTracker::ResetOriginQuotaInMemory, |
| 653 | origin_identifier)); |
[email protected] | 62d30f4 | 2009-10-01 22:36:06 | [diff] [blame] | 654 | } |
| 655 | } |
| 656 | } |
| 657 | |
[email protected] | 6b75ec3 | 2009-08-14 06:37:18 | [diff] [blame] | 658 | void ExtensionsService::UpdateExtensionBlacklist( |
| 659 | const std::vector<std::string>& blacklist) { |
| 660 | // Use this set to indicate if an extension in the blacklist has been used. |
| 661 | std::set<std::string> blacklist_set; |
| 662 | for (unsigned int i = 0; i < blacklist.size(); ++i) { |
| 663 | if (Extension::IdIsValid(blacklist[i])) { |
| 664 | blacklist_set.insert(blacklist[i]); |
| 665 | } |
| 666 | } |
| 667 | extension_prefs_->UpdateBlacklist(blacklist_set); |
| 668 | std::vector<std::string> to_be_removed; |
| 669 | // Loop current extensions, unload installed extensions. |
| 670 | for (ExtensionList::const_iterator iter = extensions_.begin(); |
| 671 | iter != extensions_.end(); ++iter) { |
| 672 | Extension* extension = (*iter); |
| 673 | if (blacklist_set.find(extension->id()) != blacklist_set.end()) { |
| 674 | to_be_removed.push_back(extension->id()); |
| 675 | } |
| 676 | } |
| 677 | |
| 678 | // UnloadExtension will change the extensions_ list. So, we should |
| 679 | // call it outside the iterator loop. |
| 680 | for (unsigned int i = 0; i < to_be_removed.size(); ++i) { |
| 681 | UnloadExtension(to_be_removed[i]); |
| 682 | } |
| 683 | } |
| 684 | |
[email protected] | cb0ce1e02 | 2010-03-10 19:54:41 | [diff] [blame] | 685 | bool ExtensionsService::IsIncognitoEnabled(const Extension* extension) { |
| 686 | // If this is a component extension we always allow it to work in incognito |
| 687 | // mode. |
| 688 | if (extension->location() == Extension::COMPONENT) |
| 689 | return true; |
| 690 | |
| 691 | // Check the prefs. |
| 692 | return extension_prefs_->IsIncognitoEnabled(extension->id()); |
[email protected] | db7331a | 2010-02-25 22:10:50 | [diff] [blame] | 693 | } |
[email protected] | 55a3569 | 2010-02-11 23:25:21 | [diff] [blame] | 694 | |
[email protected] | cb0ce1e02 | 2010-03-10 19:54:41 | [diff] [blame] | 695 | void ExtensionsService::SetIsIncognitoEnabled(Extension* extension, |
[email protected] | db7331a | 2010-02-25 22:10:50 | [diff] [blame] | 696 | bool enabled) { |
[email protected] | cb0ce1e02 | 2010-03-10 19:54:41 | [diff] [blame] | 697 | extension_prefs_->SetIsIncognitoEnabled(extension->id(), enabled); |
[email protected] | c1499f3d | 2010-03-05 00:33:24 | [diff] [blame] | 698 | |
| 699 | // Broadcast unloaded and loaded events to update browser state. |
| 700 | NotifyExtensionUnloaded(extension); |
| 701 | NotifyExtensionLoaded(extension); |
[email protected] | 55a3569 | 2010-02-11 23:25:21 | [diff] [blame] | 702 | } |
| 703 | |
[email protected] | 05c8218 | 2010-06-24 17:49:08 | [diff] [blame] | 704 | bool ExtensionsService::AllowFileAccess(const Extension* extension) { |
| 705 | return (CommandLine::ForCurrentProcess()->HasSwitch( |
[email protected] | 334e04a | 2010-06-24 23:34:44 | [diff] [blame] | 706 | switches::kDisableExtensionsFileAccessCheck) || |
[email protected] | 05c8218 | 2010-06-24 17:49:08 | [diff] [blame] | 707 | extension_prefs_->AllowFileAccess(extension->id())); |
| 708 | } |
| 709 | |
| 710 | void ExtensionsService::SetAllowFileAccess(Extension* extension, bool allow) { |
| 711 | extension_prefs_->SetAllowFileAccess(extension->id(), allow); |
| 712 | NotificationService::current()->Notify( |
| 713 | NotificationType::EXTENSION_USER_SCRIPTS_UPDATED, |
| 714 | Source<Profile>(profile_), |
| 715 | Details<Extension>(extension)); |
| 716 | } |
| 717 | |
| 718 | bool ExtensionsService::CanExecuteScriptOnHost(Extension* extension, |
| 719 | const GURL& url, |
| 720 | std::string* error) const { |
| 721 | // No extensions are allowed to execute script on the gallery because that |
| 722 | // would allow extensions to manipulate their own install pages. |
| 723 | if (url.host() == GURL(Extension::ChromeStoreURL()).host()) { |
| 724 | if (error) |
| 725 | *error = errors::kCannotScriptGallery; |
| 726 | return false; |
| 727 | } |
| 728 | |
| 729 | if (extension->HasHostPermission(url)) |
| 730 | return true; |
| 731 | |
| 732 | if (error) { |
| 733 | *error = ExtensionErrorUtils::FormatErrorMessage(errors::kCannotAccessPage, |
| 734 | url.spec()); |
| 735 | } |
| 736 | |
| 737 | return false; |
| 738 | } |
| 739 | |
[email protected] | 93fd78f4 | 2009-07-10 16:43:17 | [diff] [blame] | 740 | void ExtensionsService::CheckForExternalUpdates() { |
[email protected] | 9f1087e | 2009-06-15 17:29:32 | [diff] [blame] | 741 | // This installs or updates externally provided extensions. |
[email protected] | 7577a5c5 | 2009-07-30 06:21:58 | [diff] [blame] | 742 | // TODO(aa): Why pass this list into the provider, why not just filter it |
| 743 | // later? |
[email protected] | 9f1087e | 2009-06-15 17:29:32 | [diff] [blame] | 744 | std::set<std::string> killed_extensions; |
[email protected] | e72e8eb8 | 2009-06-18 17:21:51 | [diff] [blame] | 745 | extension_prefs_->GetKilledExtensionIds(&killed_extensions); |
[email protected] | 95d2919 | 2009-10-30 01:49:06 | [diff] [blame] | 746 | ChromeThread::PostTask( |
| 747 | ChromeThread::FILE, FROM_HERE, |
| 748 | NewRunnableMethod( |
| 749 | backend_.get(), &ExtensionsServiceBackend::CheckForExternalUpdates, |
| 750 | killed_extensions, scoped_refptr<ExtensionsService>(this))); |
[email protected] | 9f1087e | 2009-06-15 17:29:32 | [diff] [blame] | 751 | } |
| 752 | |
| 753 | void ExtensionsService::UnloadExtension(const std::string& extension_id) { |
[email protected] | 27e469a | 2010-01-11 20:35:09 | [diff] [blame] | 754 | // Make sure the extension gets deleted after we return from this function. |
[email protected] | 0c6da50 | 2009-08-14 22:32:39 | [diff] [blame] | 755 | scoped_ptr<Extension> extension( |
| 756 | GetExtensionByIdInternal(extension_id, true, true)); |
[email protected] | 631cf82 | 2009-05-15 07:01:25 | [diff] [blame] | 757 | |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 758 | // Callers should not send us nonexistant extensions. |
[email protected] | 0c6da50 | 2009-08-14 22:32:39 | [diff] [blame] | 759 | CHECK(extension.get()); |
| 760 | |
[email protected] | 1eb17508 | 2010-02-10 09:26:16 | [diff] [blame] | 761 | // Keep information about the extension so that we can reload it later |
| 762 | // even if it's not permanently installed. |
| 763 | unloaded_extension_paths_[extension->id()] = extension->path(); |
| 764 | |
[email protected] | 86c008e8 | 2009-08-28 20:26:05 | [diff] [blame] | 765 | ExtensionDOMUI::UnregisterChromeURLOverrides(profile_, |
| 766 | extension->GetChromeURLOverrides()); |
| 767 | |
[email protected] | 0c6da50 | 2009-08-14 22:32:39 | [diff] [blame] | 768 | ExtensionList::iterator iter = std::find(disabled_extensions_.begin(), |
| 769 | disabled_extensions_.end(), |
| 770 | extension.get()); |
| 771 | if (iter != disabled_extensions_.end()) { |
[email protected] | 0c6da50 | 2009-08-14 22:32:39 | [diff] [blame] | 772 | disabled_extensions_.erase(iter); |
[email protected] | 86693068 | 2009-08-18 22:53:47 | [diff] [blame] | 773 | NotificationService::current()->Notify( |
| 774 | NotificationType::EXTENSION_UNLOADED_DISABLED, |
[email protected] | 24e7a9d | 2009-11-04 11:11:34 | [diff] [blame] | 775 | Source<Profile>(profile_), |
[email protected] | 86693068 | 2009-08-18 22:53:47 | [diff] [blame] | 776 | Details<Extension>(extension.get())); |
[email protected] | 0c6da50 | 2009-08-14 22:32:39 | [diff] [blame] | 777 | return; |
| 778 | } |
| 779 | |
| 780 | iter = std::find(extensions_.begin(), extensions_.end(), extension.get()); |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 781 | |
[email protected] | 631cf82 | 2009-05-15 07:01:25 | [diff] [blame] | 782 | // Remove the extension from our list. |
| 783 | extensions_.erase(iter); |
| 784 | |
[email protected] | 62d30f4 | 2009-10-01 22:36:06 | [diff] [blame] | 785 | NotifyExtensionUnloaded(extension.get()); |
[email protected] | aab98a5 | 2009-12-02 03:22:35 | [diff] [blame] | 786 | UpdateActiveExtensionsInCrashReporter(); |
[email protected] | 631cf82 | 2009-05-15 07:01:25 | [diff] [blame] | 787 | } |
| 788 | |
[email protected] | 9f1087e | 2009-06-15 17:29:32 | [diff] [blame] | 789 | void ExtensionsService::UnloadAllExtensions() { |
[email protected] | cd500f7 | 2010-06-25 23:44:32 | [diff] [blame] | 790 | STLDeleteContainerPointers(extensions_.begin(), extensions_.end()); |
[email protected] | 9f1087e | 2009-06-15 17:29:32 | [diff] [blame] | 791 | extensions_.clear(); |
[email protected] | c6e4a341 | 2009-06-24 15:45:29 | [diff] [blame] | 792 | |
[email protected] | cd500f7 | 2010-06-25 23:44:32 | [diff] [blame] | 793 | STLDeleteContainerPointers(disabled_extensions_.begin(), |
| 794 | disabled_extensions_.end()); |
| 795 | disabled_extensions_.clear(); |
| 796 | |
[email protected] | c6e4a341 | 2009-06-24 15:45:29 | [diff] [blame] | 797 | // TODO(erikkay) should there be a notification for this? We can't use |
| 798 | // EXTENSION_UNLOADED since that implies that the extension has been disabled |
| 799 | // or uninstalled, and UnloadAll is just part of shutdown. |
[email protected] | 9f1087e | 2009-06-15 17:29:32 | [diff] [blame] | 800 | } |
| 801 | |
| 802 | void ExtensionsService::ReloadExtensions() { |
| 803 | UnloadAllExtensions(); |
| 804 | LoadAllExtensions(); |
| 805 | } |
| 806 | |
| 807 | void ExtensionsService::GarbageCollectExtensions() { |
[email protected] | ba39967 | 2010-04-06 15:42:39 | [diff] [blame] | 808 | if (extension_prefs_->pref_service()->read_only()) |
| 809 | return; |
| 810 | |
[email protected] | ca3dbf5 | 2010-05-19 22:27:06 | [diff] [blame] | 811 | scoped_ptr<ExtensionPrefs::ExtensionsInfo> info( |
| 812 | extension_prefs_->GetInstalledExtensionsInfo()); |
| 813 | |
| 814 | std::map<std::string, FilePath> extension_paths; |
| 815 | for (size_t i = 0; i < info->size(); ++i) |
| 816 | extension_paths[info->at(i)->extension_id] = info->at(i)->extension_path; |
| 817 | |
[email protected] | 95d2919 | 2009-10-30 01:49:06 | [diff] [blame] | 818 | ChromeThread::PostTask( |
| 819 | ChromeThread::FILE, FROM_HERE, |
| 820 | NewRunnableFunction( |
| 821 | &extension_file_util::GarbageCollectExtensions, install_directory_, |
[email protected] | ca3dbf5 | 2010-05-19 22:27:06 | [diff] [blame] | 822 | extension_paths)); |
[email protected] | 3cf4f099 | 2009-02-03 23:00:30 | [diff] [blame] | 823 | } |
| 824 | |
[email protected] | e72e8eb8 | 2009-06-18 17:21:51 | [diff] [blame] | 825 | void ExtensionsService::OnLoadedInstalledExtensions() { |
[email protected] | e81dba3 | 2009-06-19 20:19:13 | [diff] [blame] | 826 | ready_ = true; |
[email protected] | 93fd78f4 | 2009-07-10 16:43:17 | [diff] [blame] | 827 | if (updater_.get()) { |
| 828 | updater_->Start(); |
| 829 | } |
[email protected] | e72e8eb8 | 2009-06-18 17:21:51 | [diff] [blame] | 830 | NotificationService::current()->Notify( |
| 831 | NotificationType::EXTENSIONS_READY, |
[email protected] | 24e7a9d | 2009-11-04 11:11:34 | [diff] [blame] | 832 | Source<Profile>(profile_), |
[email protected] | e72e8eb8 | 2009-06-18 17:21:51 | [diff] [blame] | 833 | NotificationService::NoDetails()); |
| 834 | } |
| 835 | |
[email protected] | 6d2e60bd | 2010-06-03 22:37:39 | [diff] [blame] | 836 | void ExtensionsService::OnExtensionLoaded(Extension* extension, |
[email protected] | 2a40953 | 2009-08-28 19:39:44 | [diff] [blame] | 837 | bool allow_privilege_increase) { |
[email protected] | ae09ca6 | 2009-08-21 19:46:46 | [diff] [blame] | 838 | // Ensure extension is deleted unless we transfer ownership. |
| 839 | scoped_ptr<Extension> scoped_extension(extension); |
[email protected] | 9f1087e | 2009-06-15 17:29:32 | [diff] [blame] | 840 | |
[email protected] | 1eb17508 | 2010-02-10 09:26:16 | [diff] [blame] | 841 | // The extension is now loaded, remove its data from unloaded extension map. |
| 842 | unloaded_extension_paths_.erase(extension->id()); |
| 843 | |
[email protected] | ceefd3d | 2010-03-12 09:10:29 | [diff] [blame] | 844 | // TODO(aa): Need to re-evaluate this branch. Does this still make sense now |
| 845 | // that extensions are enabled by default? |
[email protected] | ae09ca6 | 2009-08-21 19:46:46 | [diff] [blame] | 846 | if (extensions_enabled() || |
[email protected] | 3ba0fd3 | 2010-06-19 05:39:10 | [diff] [blame] | 847 | extension->is_theme() || |
[email protected] | ae09ca6 | 2009-08-21 19:46:46 | [diff] [blame] | 848 | extension->location() == Extension::LOAD || |
| 849 | Extension::IsExternalLocation(extension->location())) { |
| 850 | Extension* old = GetExtensionByIdInternal(extension->id(), true, true); |
| 851 | if (old) { |
[email protected] | ca3dbf5 | 2010-05-19 22:27:06 | [diff] [blame] | 852 | // CrxInstaller should have guaranteed that we aren't downgrading. |
| 853 | CHECK(extension->version()->CompareTo(*(old->version())) >= 0); |
[email protected] | 0c6da50 | 2009-08-14 22:32:39 | [diff] [blame] | 854 | |
[email protected] | ca3dbf5 | 2010-05-19 22:27:06 | [diff] [blame] | 855 | bool allow_silent_upgrade = |
| 856 | allow_privilege_increase || !Extension::IsPrivilegeIncrease( |
| 857 | old, extension); |
[email protected] | 1e8c93f | 2010-02-08 22:58:31 | [diff] [blame] | 858 | |
[email protected] | ca3dbf5 | 2010-05-19 22:27:06 | [diff] [blame] | 859 | // Extensions get upgraded if silent upgrades are allowed, otherwise |
| 860 | // they get disabled. |
| 861 | if (allow_silent_upgrade) { |
| 862 | old->set_being_upgraded(true); |
| 863 | extension->set_being_upgraded(true); |
| 864 | } |
[email protected] | 0c6da50 | 2009-08-14 22:32:39 | [diff] [blame] | 865 | |
[email protected] | ca3dbf5 | 2010-05-19 22:27:06 | [diff] [blame] | 866 | // To upgrade an extension in place, unload the old one and |
| 867 | // then load the new one. |
| 868 | UnloadExtension(old->id()); |
| 869 | old = NULL; |
| 870 | |
| 871 | if (!allow_silent_upgrade) { |
| 872 | // Extension has changed permissions significantly. Disable it. We |
| 873 | // send a notification below. |
| 874 | extension_prefs_->SetExtensionState(extension, Extension::DISABLED); |
| 875 | extension_prefs_->SetDidExtensionEscalatePermissions(extension, true); |
[email protected] | 0c6da50 | 2009-08-14 22:32:39 | [diff] [blame] | 876 | } |
[email protected] | ba74f35 | 2009-06-11 18:54:45 | [diff] [blame] | 877 | } |
[email protected] | 86a27407 | 2009-06-11 02:06:45 | [diff] [blame] | 878 | |
[email protected] | ae09ca6 | 2009-08-21 19:46:46 | [diff] [blame] | 879 | switch (extension_prefs_->GetExtensionState(extension->id())) { |
| 880 | case Extension::ENABLED: |
| 881 | extensions_.push_back(scoped_extension.release()); |
| 882 | |
[email protected] | 62d30f4 | 2009-10-01 22:36:06 | [diff] [blame] | 883 | NotifyExtensionLoaded(extension); |
[email protected] | ae09ca6 | 2009-08-21 19:46:46 | [diff] [blame] | 884 | |
[email protected] | e8c729a | 2010-03-09 19:55:19 | [diff] [blame] | 885 | ExtensionDOMUI::RegisterChromeURLOverrides(profile_, |
| 886 | extension->GetChromeURLOverrides()); |
[email protected] | ae09ca6 | 2009-08-21 19:46:46 | [diff] [blame] | 887 | break; |
| 888 | case Extension::DISABLED: |
[email protected] | 6d27a7b | 2009-12-18 23:25:45 | [diff] [blame] | 889 | disabled_extensions_.push_back(scoped_extension.release()); |
[email protected] | d11c8e9 | 2009-10-20 23:26:40 | [diff] [blame] | 890 | NotificationService::current()->Notify( |
| 891 | NotificationType::EXTENSION_UPDATE_DISABLED, |
[email protected] | 24e7a9d | 2009-11-04 11:11:34 | [diff] [blame] | 892 | Source<Profile>(profile_), |
[email protected] | d11c8e9 | 2009-10-20 23:26:40 | [diff] [blame] | 893 | Details<Extension>(extension)); |
[email protected] | ae09ca6 | 2009-08-21 19:46:46 | [diff] [blame] | 894 | break; |
| 895 | default: |
[email protected] | d11c8e9 | 2009-10-20 23:26:40 | [diff] [blame] | 896 | NOTREACHED(); |
[email protected] | ae09ca6 | 2009-08-21 19:46:46 | [diff] [blame] | 897 | break; |
[email protected] | 811f343 | 2009-07-25 19:38:21 | [diff] [blame] | 898 | } |
[email protected] | e72e8eb8 | 2009-06-18 17:21:51 | [diff] [blame] | 899 | } |
[email protected] | aab98a5 | 2009-12-02 03:22:35 | [diff] [blame] | 900 | |
[email protected] | 1e8c93f | 2010-02-08 22:58:31 | [diff] [blame] | 901 | extension->set_being_upgraded(false); |
| 902 | |
[email protected] | aab98a5 | 2009-12-02 03:22:35 | [diff] [blame] | 903 | UpdateActiveExtensionsInCrashReporter(); |
| 904 | } |
| 905 | |
| 906 | void ExtensionsService::UpdateActiveExtensionsInCrashReporter() { |
[email protected] | c886596 | 2009-12-16 07:47:39 | [diff] [blame] | 907 | std::set<std::string> extension_ids; |
[email protected] | aab98a5 | 2009-12-02 03:22:35 | [diff] [blame] | 908 | for (size_t i = 0; i < extensions_.size(); ++i) { |
[email protected] | 3ba0fd3 | 2010-06-19 05:39:10 | [diff] [blame] | 909 | if (!extensions_[i]->is_theme()) |
[email protected] | c886596 | 2009-12-16 07:47:39 | [diff] [blame] | 910 | extension_ids.insert(extensions_[i]->id()); |
[email protected] | aab98a5 | 2009-12-02 03:22:35 | [diff] [blame] | 911 | } |
| 912 | |
| 913 | child_process_logging::SetActiveExtensions(extension_ids); |
[email protected] | 6014d67 | 2008-12-05 00:38:25 | [diff] [blame] | 914 | } |
| 915 | |
[email protected] | 2a40953 | 2009-08-28 19:39:44 | [diff] [blame] | 916 | void ExtensionsService::OnExtensionInstalled(Extension* extension, |
| 917 | bool allow_privilege_increase) { |
[email protected] | 4416c5a | 2010-06-26 01:28:57 | [diff] [blame^] | 918 | // Ensure extension is deleted unless we transfer ownership. |
| 919 | scoped_ptr<Extension> scoped_extension(extension); |
| 920 | Extension::State initial_state = Extension::DISABLED; |
| 921 | bool initial_enable_incognito = false; |
[email protected] | aa14270 | 2010-03-26 01:26:33 | [diff] [blame] | 922 | PendingExtensionMap::iterator it = |
| 923 | pending_extensions_.find(extension->id()); |
[email protected] | 4416c5a | 2010-06-26 01:28:57 | [diff] [blame^] | 924 | if (it != pending_extensions_.end()) { |
| 925 | // Set initial state from pending extension data. |
| 926 | if (it->second.is_theme != extension->is_theme()) { |
| 927 | LOG(WARNING) |
| 928 | << "Not installing pending extension " << extension->id() |
| 929 | << " with is_theme = " << extension->is_theme() |
| 930 | << "; expected is_theme = " << it->second.is_theme; |
| 931 | // Delete the extension directory since we're not going to |
| 932 | // load it. |
| 933 | ChromeThread::PostTask( |
| 934 | ChromeThread::FILE, FROM_HERE, |
| 935 | NewRunnableFunction(&DeleteFileHelper, extension->path(), true)); |
| 936 | return; |
| 937 | } |
| 938 | if (it->second.is_theme) { |
| 939 | DCHECK(it->second.enable_on_install); |
| 940 | initial_state = Extension::ENABLED; |
| 941 | DCHECK(!it->second.enable_incognito_on_install); |
| 942 | initial_enable_incognito = false; |
| 943 | } else { |
| 944 | initial_state = |
| 945 | it->second.enable_on_install ? |
| 946 | Extension::ENABLED : Extension::DISABLED; |
| 947 | initial_enable_incognito = |
| 948 | it->second.enable_incognito_on_install; |
| 949 | } |
| 950 | |
| 951 | pending_extensions_.erase(it); |
| 952 | } else { |
| 953 | // Make sure we don't enable a disabled extension. |
| 954 | Extension::State existing_state = |
| 955 | extension_prefs_->GetExtensionState(extension->id()); |
| 956 | initial_state = |
| 957 | (existing_state == Extension::DISABLED) ? |
| 958 | Extension::DISABLED : Extension::ENABLED; |
| 959 | initial_enable_incognito = false; |
[email protected] | aa14270 | 2010-03-26 01:26:33 | [diff] [blame] | 960 | } |
| 961 | |
[email protected] | 4416c5a | 2010-06-26 01:28:57 | [diff] [blame^] | 962 | extension_prefs_->OnExtensionInstalled( |
| 963 | extension, initial_state, initial_enable_incognito); |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 964 | |
[email protected] | 4a19063 | 2009-05-09 01:07:42 | [diff] [blame] | 965 | // If the extension is a theme, tell the profile (and therefore ThemeProvider) |
| 966 | // to apply it. |
[email protected] | 3ba0fd3 | 2010-06-19 05:39:10 | [diff] [blame] | 967 | if (extension->is_theme()) { |
[email protected] | 9ceb0734 | 2009-07-26 04:09:23 | [diff] [blame] | 968 | NotificationService::current()->Notify( |
| 969 | NotificationType::THEME_INSTALLED, |
[email protected] | 24e7a9d | 2009-11-04 11:11:34 | [diff] [blame] | 970 | Source<Profile>(profile_), |
[email protected] | 9ceb0734 | 2009-07-26 04:09:23 | [diff] [blame] | 971 | Details<Extension>(extension)); |
[email protected] | 9197f3b | 2009-06-02 00:49:27 | [diff] [blame] | 972 | } else { |
| 973 | NotificationService::current()->Notify( |
| 974 | NotificationType::EXTENSION_INSTALLED, |
[email protected] | 24e7a9d | 2009-11-04 11:11:34 | [diff] [blame] | 975 | Source<Profile>(profile_), |
[email protected] | 9197f3b | 2009-06-02 00:49:27 | [diff] [blame] | 976 | Details<Extension>(extension)); |
[email protected] | 4a19063 | 2009-05-09 01:07:42 | [diff] [blame] | 977 | } |
[email protected] | 7577a5c5 | 2009-07-30 06:21:58 | [diff] [blame] | 978 | |
[email protected] | 6d2e60bd | 2010-06-03 22:37:39 | [diff] [blame] | 979 | if (profile_->GetTemplateURLModel()) |
[email protected] | 56ad379 | 2010-05-28 17:45:33 | [diff] [blame] | 980 | profile_->GetTemplateURLModel()->RegisterExtensionKeyword(extension); |
[email protected] | 4416c5a | 2010-06-26 01:28:57 | [diff] [blame^] | 981 | |
| 982 | // Transfer ownership of |extension| to OnExtensionLoaded. |
| 983 | OnExtensionLoaded(scoped_extension.release(), allow_privilege_increase); |
[email protected] | 4a19063 | 2009-05-09 01:07:42 | [diff] [blame] | 984 | } |
| 985 | |
[email protected] | 0c6da50 | 2009-08-14 22:32:39 | [diff] [blame] | 986 | Extension* ExtensionsService::GetExtensionByIdInternal(const std::string& id, |
| 987 | bool include_enabled, |
| 988 | bool include_disabled) { |
[email protected] | e957fe5 | 2009-06-23 16:51:05 | [diff] [blame] | 989 | std::string lowercase_id = StringToLowerASCII(id); |
[email protected] | 0c6da50 | 2009-08-14 22:32:39 | [diff] [blame] | 990 | if (include_enabled) { |
| 991 | for (ExtensionList::const_iterator iter = extensions_.begin(); |
| 992 | iter != extensions_.end(); ++iter) { |
| 993 | if ((*iter)->id() == lowercase_id) |
| 994 | return *iter; |
| 995 | } |
| 996 | } |
| 997 | if (include_disabled) { |
| 998 | for (ExtensionList::const_iterator iter = disabled_extensions_.begin(); |
| 999 | iter != disabled_extensions_.end(); ++iter) { |
| 1000 | if ((*iter)->id() == lowercase_id) |
| 1001 | return *iter; |
| 1002 | } |
[email protected] | ce5c450 | 2009-05-06 16:46:11 | [diff] [blame] | 1003 | } |
| 1004 | return NULL; |
| 1005 | } |
| 1006 | |
[email protected] | 9f1087e | 2009-06-15 17:29:32 | [diff] [blame] | 1007 | Extension* ExtensionsService::GetExtensionByURL(const GURL& url) { |
[email protected] | a888b29e6 | 2010-04-01 13:38:57 | [diff] [blame] | 1008 | return url.scheme() != chrome::kExtensionScheme ? NULL : |
| 1009 | GetExtensionById(url.host(), false); |
| 1010 | } |
| 1011 | |
| 1012 | Extension* ExtensionsService::GetExtensionByWebExtent(const GURL& url) { |
| 1013 | for (size_t i = 0; i < extensions_.size(); ++i) { |
| 1014 | if (extensions_[i]->web_extent().ContainsURL(url)) |
| 1015 | return extensions_[i]; |
| 1016 | } |
| 1017 | return NULL; |
[email protected] | 9f1087e | 2009-06-15 17:29:32 | [diff] [blame] | 1018 | } |
| 1019 | |
[email protected] | 6d2e60bd | 2010-06-03 22:37:39 | [diff] [blame] | 1020 | Extension* ExtensionsService::GetExtensionByOverlappingWebExtent( |
[email protected] | 9f72aa0 | 2010-06-25 10:01:05 | [diff] [blame] | 1021 | const ExtensionExtent& extent) { |
| 1022 | // TODO(aa): Make this work for the new extents. http://crbug.com/47445. |
[email protected] | 6d2e60bd | 2010-06-03 22:37:39 | [diff] [blame] | 1023 | return NULL; |
| 1024 | } |
| 1025 | |
[email protected] | a1257b1 | 2009-06-12 02:51:34 | [diff] [blame] | 1026 | void ExtensionsService::ClearProvidersForTesting() { |
[email protected] | 95d2919 | 2009-10-30 01:49:06 | [diff] [blame] | 1027 | ChromeThread::PostTask( |
| 1028 | ChromeThread::FILE, FROM_HERE, |
| 1029 | NewRunnableMethod( |
| 1030 | backend_.get(), &ExtensionsServiceBackend::ClearProvidersForTesting)); |
[email protected] | a1257b1 | 2009-06-12 02:51:34 | [diff] [blame] | 1031 | } |
| 1032 | |
| 1033 | void ExtensionsService::SetProviderForTesting( |
| 1034 | Extension::Location location, ExternalExtensionProvider* test_provider) { |
[email protected] | 95d2919 | 2009-10-30 01:49:06 | [diff] [blame] | 1035 | ChromeThread::PostTask( |
| 1036 | ChromeThread::FILE, FROM_HERE, |
| 1037 | NewRunnableMethod( |
| 1038 | backend_.get(), &ExtensionsServiceBackend::SetProviderForTesting, |
| 1039 | location, test_provider)); |
[email protected] | a1257b1 | 2009-06-12 02:51:34 | [diff] [blame] | 1040 | } |
| 1041 | |
[email protected] | 7577a5c5 | 2009-07-30 06:21:58 | [diff] [blame] | 1042 | void ExtensionsService::OnExternalExtensionFound(const std::string& id, |
| 1043 | const std::string& version, |
| 1044 | const FilePath& path, |
| 1045 | Extension::Location location) { |
| 1046 | // Before even bothering to unpack, check and see if we already have this |
[email protected] | 4c96793 | 2009-07-31 01:15:49 | [diff] [blame] | 1047 | // version. This is important because these extensions are going to get |
[email protected] | 7577a5c5 | 2009-07-30 06:21:58 | [diff] [blame] | 1048 | // installed on every startup. |
[email protected] | 61b41161 | 2009-11-10 23:17:41 | [diff] [blame] | 1049 | Extension* existing = GetExtensionById(id, true); |
[email protected] | a3a63ff8 | 2009-08-04 06:44:11 | [diff] [blame] | 1050 | scoped_ptr<Version> other(Version::GetVersionFromString(version)); |
[email protected] | 7577a5c5 | 2009-07-30 06:21:58 | [diff] [blame] | 1051 | if (existing) { |
[email protected] | a3a63ff8 | 2009-08-04 06:44:11 | [diff] [blame] | 1052 | switch (existing->version()->CompareTo(*other)) { |
[email protected] | 7577a5c5 | 2009-07-30 06:21:58 | [diff] [blame] | 1053 | case -1: // existing version is older, we should upgrade |
| 1054 | break; |
| 1055 | case 0: // existing version is same, do nothing |
| 1056 | return; |
| 1057 | case 1: // existing version is newer, uh-oh |
| 1058 | LOG(WARNING) << "Found external version of extension " << id |
| 1059 | << "that is older than current version. Current version " |
| 1060 | << "is: " << existing->VersionString() << ". New version " |
| 1061 | << "is: " << version << ". Keeping current version."; |
| 1062 | return; |
| 1063 | } |
| 1064 | } |
| 1065 | |
[email protected] | 6dfbbf8 | 2010-03-12 23:09:16 | [diff] [blame] | 1066 | scoped_refptr<CrxInstaller> installer( |
| 1067 | new CrxInstaller(install_directory_, |
| 1068 | this, // frontend |
| 1069 | NULL)); // no client (silent install) |
| 1070 | installer->set_install_source(location); |
| 1071 | installer->set_expected_id(id); |
| 1072 | installer->set_allow_privilege_increase(true); |
| 1073 | installer->InstallCrx(path); |
[email protected] | 7577a5c5 | 2009-07-30 06:21:58 | [diff] [blame] | 1074 | } |
| 1075 | |
[email protected] | d11c8e9 | 2009-10-20 23:26:40 | [diff] [blame] | 1076 | void ExtensionsService::ReportExtensionLoadError( |
| 1077 | const FilePath& extension_path, |
| 1078 | const std::string &error, |
| 1079 | NotificationType type, |
| 1080 | bool be_noisy) { |
| 1081 | NotificationService* service = NotificationService::current(); |
| 1082 | service->Notify(type, |
[email protected] | 24e7a9d | 2009-11-04 11:11:34 | [diff] [blame] | 1083 | Source<Profile>(profile_), |
[email protected] | d11c8e9 | 2009-10-20 23:26:40 | [diff] [blame] | 1084 | Details<const std::string>(&error)); |
| 1085 | |
| 1086 | // TODO(port): note that this isn't guaranteed to work properly on Linux. |
[email protected] | 99efb7b1 | 2009-12-18 02:39:16 | [diff] [blame] | 1087 | std::string path_str = WideToUTF8(extension_path.ToWStringHack()); |
[email protected] | d11c8e9 | 2009-10-20 23:26:40 | [diff] [blame] | 1088 | std::string message = StringPrintf("Could not load extension from '%s'. %s", |
| 1089 | path_str.c_str(), error.c_str()); |
| 1090 | ExtensionErrorReporter::GetInstance()->ReportError(message, be_noisy); |
| 1091 | } |
| 1092 | |
[email protected] | 4814b51 | 2009-11-07 00:12:29 | [diff] [blame] | 1093 | void ExtensionsService::Observe(NotificationType type, |
| 1094 | const NotificationSource& source, |
| 1095 | const NotificationDetails& details) { |
| 1096 | switch (type.value) { |
| 1097 | case NotificationType::EXTENSION_HOST_DID_STOP_LOADING: { |
| 1098 | ExtensionHost* host = Details<ExtensionHost>(details).ptr(); |
| 1099 | OrphanedDevTools::iterator iter = |
| 1100 | orphaned_dev_tools_.find(host->extension()->id()); |
| 1101 | if (iter == orphaned_dev_tools_.end()) |
| 1102 | return; |
| 1103 | |
| 1104 | DevToolsManager::GetInstance()->AttachClientHost( |
| 1105 | iter->second, host->render_view_host()); |
| 1106 | orphaned_dev_tools_.erase(iter); |
| 1107 | break; |
| 1108 | } |
| 1109 | |
[email protected] | a4ed628 | 2009-12-14 20:51:16 | [diff] [blame] | 1110 | case NotificationType::EXTENSION_PROCESS_TERMINATED: { |
[email protected] | 31f7726 | 2009-12-02 20:48:53 | [diff] [blame] | 1111 | DCHECK_EQ(profile_, Source<Profile>(source).ptr()); |
[email protected] | a4ed628 | 2009-12-14 20:51:16 | [diff] [blame] | 1112 | |
[email protected] | 31f7726 | 2009-12-02 20:48:53 | [diff] [blame] | 1113 | // Unload the entire extension. We want it to be in a consistent state: |
| 1114 | // either fully working or not loaded at all, but never half-crashed. |
[email protected] | 597cceb | 2010-03-22 16:27:01 | [diff] [blame] | 1115 | UnloadExtension(Details<ExtensionHost>(details).ptr()->extension()->id()); |
[email protected] | 31f7726 | 2009-12-02 20:48:53 | [diff] [blame] | 1116 | break; |
| 1117 | } |
| 1118 | |
[email protected] | 4814b51 | 2009-11-07 00:12:29 | [diff] [blame] | 1119 | default: |
| 1120 | NOTREACHED() << "Unexpected notification type."; |
| 1121 | } |
| 1122 | } |
| 1123 | |
| 1124 | |
[email protected] | 6014d67 | 2008-12-05 00:38:25 | [diff] [blame] | 1125 | // ExtensionsServicesBackend |
| 1126 | |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 1127 | ExtensionsServiceBackend::ExtensionsServiceBackend( |
[email protected] | 95d2919 | 2009-10-30 01:49:06 | [diff] [blame] | 1128 | const FilePath& install_directory) |
[email protected] | 0c7bc4b | 2009-05-30 01:47:08 | [diff] [blame] | 1129 | : frontend_(NULL), |
| 1130 | install_directory_(install_directory), |
[email protected] | 95d2919 | 2009-10-30 01:49:06 | [diff] [blame] | 1131 | alert_on_error_(false) { |
[email protected] | 7577a5c5 | 2009-07-30 06:21:58 | [diff] [blame] | 1132 | // TODO(aa): This ends up doing blocking IO on the UI thread because it reads |
| 1133 | // pref data in the ctor and that is called on the UI thread. Would be better |
| 1134 | // to re-read data each time we list external extensions, anyway. |
[email protected] | a1257b1 | 2009-06-12 02:51:34 | [diff] [blame] | 1135 | external_extension_providers_[Extension::EXTERNAL_PREF] = |
[email protected] | da50530a | 2009-06-15 17:43:01 | [diff] [blame] | 1136 | linked_ptr<ExternalExtensionProvider>( |
[email protected] | 27b985d | 2009-06-25 17:53:15 | [diff] [blame] | 1137 | new ExternalPrefExtensionProvider()); |
[email protected] | a1257b1 | 2009-06-12 02:51:34 | [diff] [blame] | 1138 | #if defined(OS_WIN) |
| 1139 | external_extension_providers_[Extension::EXTERNAL_REGISTRY] = |
[email protected] | da50530a | 2009-06-15 17:43:01 | [diff] [blame] | 1140 | linked_ptr<ExternalExtensionProvider>( |
| 1141 | new ExternalRegistryExtensionProvider()); |
[email protected] | a1257b1 | 2009-06-12 02:51:34 | [diff] [blame] | 1142 | #endif |
| 1143 | } |
| 1144 | |
| 1145 | ExtensionsServiceBackend::~ExtensionsServiceBackend() { |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 1146 | } |
| 1147 | |
[email protected] | b0beaa66 | 2009-02-26 00:04:15 | [diff] [blame] | 1148 | void ExtensionsServiceBackend::LoadSingleExtension( |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 1149 | const FilePath& path_in, scoped_refptr<ExtensionsService> frontend) { |
[email protected] | b0beaa66 | 2009-02-26 00:04:15 | [diff] [blame] | 1150 | frontend_ = frontend; |
| 1151 | |
| 1152 | // Explicit UI loads are always noisy. |
| 1153 | alert_on_error_ = true; |
| 1154 | |
[email protected] | cc5da33 | 2009-03-04 08:02:51 | [diff] [blame] | 1155 | FilePath extension_path = path_in; |
[email protected] | f36fa4fb | 2009-06-19 18:23:50 | [diff] [blame] | 1156 | file_util::AbsolutePath(&extension_path); |
[email protected] | bf24d2c | 2009-02-24 23:07:45 | [diff] [blame] | 1157 | |
| 1158 | LOG(INFO) << "Loading single extension from " << |
[email protected] | 99efb7b1 | 2009-12-18 02:39:16 | [diff] [blame] | 1159 | extension_path.BaseName().value(); |
[email protected] | bf24d2c | 2009-02-24 23:07:45 | [diff] [blame] | 1160 | |
[email protected] | ab6f2b2 | 2009-07-28 23:28:37 | [diff] [blame] | 1161 | std::string error; |
| 1162 | Extension* extension = extension_file_util::LoadExtension( |
| 1163 | extension_path, |
| 1164 | false, // Don't require id |
| 1165 | &error); |
| 1166 | |
| 1167 | if (!extension) { |
| 1168 | ReportExtensionLoadError(extension_path, error); |
| 1169 | return; |
[email protected] | 0877fd9 | 2009-02-03 16:34:06 | [diff] [blame] | 1170 | } |
[email protected] | ab6f2b2 | 2009-07-28 23:28:37 | [diff] [blame] | 1171 | |
| 1172 | extension->set_location(Extension::LOAD); |
[email protected] | e8c729a | 2010-03-09 19:55:19 | [diff] [blame] | 1173 | |
| 1174 | // Report this as an installed extension so that it gets remembered in the |
| 1175 | // prefs. |
| 1176 | ChromeThread::PostTask( |
| 1177 | ChromeThread::UI, FROM_HERE, |
| 1178 | NewRunnableMethod(frontend_, &ExtensionsService::OnExtensionInstalled, |
| 1179 | extension, true)); |
[email protected] | 0877fd9 | 2009-02-03 16:34:06 | [diff] [blame] | 1180 | } |
| 1181 | |
[email protected] | 6014d67 | 2008-12-05 00:38:25 | [diff] [blame] | 1182 | void ExtensionsServiceBackend::ReportExtensionLoadError( |
[email protected] | cc5da33 | 2009-03-04 08:02:51 | [diff] [blame] | 1183 | const FilePath& extension_path, const std::string &error) { |
[email protected] | 95d2919 | 2009-10-30 01:49:06 | [diff] [blame] | 1184 | ChromeThread::PostTask( |
| 1185 | ChromeThread::UI, FROM_HERE, |
| 1186 | NewRunnableMethod( |
| 1187 | frontend_, |
[email protected] | d11c8e9 | 2009-10-20 23:26:40 | [diff] [blame] | 1188 | &ExtensionsService::ReportExtensionLoadError, extension_path, |
| 1189 | error, NotificationType::EXTENSION_INSTALL_ERROR, alert_on_error_)); |
[email protected] | 6014d67 | 2008-12-05 00:38:25 | [diff] [blame] | 1190 | } |
| 1191 | |
[email protected] | a1257b1 | 2009-06-12 02:51:34 | [diff] [blame] | 1192 | bool ExtensionsServiceBackend::LookupExternalExtension( |
| 1193 | const std::string& id, Version** version, Extension::Location* location) { |
| 1194 | scoped_ptr<Version> extension_version; |
| 1195 | for (ProviderMap::const_iterator i = external_extension_providers_.begin(); |
| 1196 | i != external_extension_providers_.end(); ++i) { |
[email protected] | da50530a | 2009-06-15 17:43:01 | [diff] [blame] | 1197 | const ExternalExtensionProvider* provider = i->second.get(); |
[email protected] | a1257b1 | 2009-06-12 02:51:34 | [diff] [blame] | 1198 | extension_version.reset(provider->RegisteredVersion(id, location)); |
| 1199 | if (extension_version.get()) { |
| 1200 | if (version) |
| 1201 | *version = extension_version.release(); |
| 1202 | return true; |
| 1203 | } |
| 1204 | } |
| 1205 | return false; |
| 1206 | } |
| 1207 | |
[email protected] | b0beaa66 | 2009-02-26 00:04:15 | [diff] [blame] | 1208 | // Some extensions will autoupdate themselves externally from Chrome. These |
| 1209 | // are typically part of some larger client application package. To support |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 1210 | // these, the extension will register its location in the the preferences file |
| 1211 | // (and also, on Windows, in the registry) and this code will periodically |
[email protected] | b0beaa66 | 2009-02-26 00:04:15 | [diff] [blame] | 1212 | // check that location for a .crx file, which it will then install locally if |
| 1213 | // a new version is available. |
| 1214 | void ExtensionsServiceBackend::CheckForExternalUpdates( |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 1215 | std::set<std::string> ids_to_ignore, |
| 1216 | scoped_refptr<ExtensionsService> frontend) { |
[email protected] | b0beaa66 | 2009-02-26 00:04:15 | [diff] [blame] | 1217 | // Note that this installation is intentionally silent (since it didn't |
| 1218 | // go through the front-end). Extensions that are registered in this |
| 1219 | // way are effectively considered 'pre-bundled', and so implicitly |
| 1220 | // trusted. In general, if something has HKLM or filesystem access, |
| 1221 | // they could install an extension manually themselves anyway. |
| 1222 | alert_on_error_ = false; |
| 1223 | frontend_ = frontend; |
[email protected] | b0beaa66 | 2009-02-26 00:04:15 | [diff] [blame] | 1224 | |
[email protected] | a1257b1 | 2009-06-12 02:51:34 | [diff] [blame] | 1225 | // Ask each external extension provider to give us a call back for each |
| 1226 | // extension they know about. See OnExternalExtensionFound. |
| 1227 | for (ProviderMap::const_iterator i = external_extension_providers_.begin(); |
| 1228 | i != external_extension_providers_.end(); ++i) { |
[email protected] | da50530a | 2009-06-15 17:43:01 | [diff] [blame] | 1229 | ExternalExtensionProvider* provider = i->second.get(); |
[email protected] | a1257b1 | 2009-06-12 02:51:34 | [diff] [blame] | 1230 | provider->VisitRegisteredExtension(this, ids_to_ignore); |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 1231 | } |
[email protected] | b0beaa66 | 2009-02-26 00:04:15 | [diff] [blame] | 1232 | } |
| 1233 | |
[email protected] | ae09ca6 | 2009-08-21 19:46:46 | [diff] [blame] | 1234 | void ExtensionsServiceBackend::CheckExternalUninstall( |
| 1235 | scoped_refptr<ExtensionsService> frontend, const std::string& id, |
| 1236 | Extension::Location location) { |
[email protected] | a1257b1 | 2009-06-12 02:51:34 | [diff] [blame] | 1237 | // Check if the providers know about this extension. |
| 1238 | ProviderMap::const_iterator i = external_extension_providers_.find(location); |
[email protected] | ae09ca6 | 2009-08-21 19:46:46 | [diff] [blame] | 1239 | if (i == external_extension_providers_.end()) { |
| 1240 | NOTREACHED() << "CheckExternalUninstall called for non-external extension " |
| 1241 | << location; |
| 1242 | return; |
[email protected] | b0beaa66 | 2009-02-26 00:04:15 | [diff] [blame] | 1243 | } |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 1244 | |
[email protected] | ae09ca6 | 2009-08-21 19:46:46 | [diff] [blame] | 1245 | scoped_ptr<Version> version; |
| 1246 | version.reset(i->second->RegisteredVersion(id, NULL)); |
| 1247 | if (version.get()) |
| 1248 | return; // Yup, known extension, don't uninstall. |
| 1249 | |
| 1250 | // This is an external extension that we don't have registered. Uninstall. |
[email protected] | 95d2919 | 2009-10-30 01:49:06 | [diff] [blame] | 1251 | ChromeThread::PostTask( |
| 1252 | ChromeThread::UI, FROM_HERE, |
| 1253 | NewRunnableMethod( |
| 1254 | frontend.get(), &ExtensionsService::UninstallExtension, id, true)); |
[email protected] | b0beaa66 | 2009-02-26 00:04:15 | [diff] [blame] | 1255 | } |
| 1256 | |
[email protected] | a1257b1 | 2009-06-12 02:51:34 | [diff] [blame] | 1257 | void ExtensionsServiceBackend::ClearProvidersForTesting() { |
| 1258 | external_extension_providers_.clear(); |
| 1259 | } |
| 1260 | |
| 1261 | void ExtensionsServiceBackend::SetProviderForTesting( |
| 1262 | Extension::Location location, |
| 1263 | ExternalExtensionProvider* test_provider) { |
| 1264 | DCHECK(test_provider); |
[email protected] | da50530a | 2009-06-15 17:43:01 | [diff] [blame] | 1265 | external_extension_providers_[location] = |
| 1266 | linked_ptr<ExternalExtensionProvider>(test_provider); |
[email protected] | a1257b1 | 2009-06-12 02:51:34 | [diff] [blame] | 1267 | } |
| 1268 | |
| 1269 | void ExtensionsServiceBackend::OnExternalExtensionFound( |
[email protected] | 7577a5c5 | 2009-07-30 06:21:58 | [diff] [blame] | 1270 | const std::string& id, const Version* version, const FilePath& path, |
| 1271 | Extension::Location location) { |
[email protected] | 95d2919 | 2009-10-30 01:49:06 | [diff] [blame] | 1272 | ChromeThread::PostTask( |
| 1273 | ChromeThread::UI, FROM_HERE, |
| 1274 | NewRunnableMethod( |
| 1275 | frontend_, &ExtensionsService::OnExternalExtensionFound, id, |
| 1276 | version->GetString(), path, location)); |
[email protected] | cc65591 | 2009-01-29 23:19:19 | [diff] [blame] | 1277 | } |
[email protected] | c6d474f8 | 2009-12-16 21:11:06 | [diff] [blame] | 1278 | |
[email protected] | 2111b1a | 2010-03-12 18:12:44 | [diff] [blame] | 1279 | void ExtensionsServiceBackend::ReloadExtensionManifests( |
[email protected] | c6d474f8 | 2009-12-16 21:11:06 | [diff] [blame] | 1280 | ExtensionPrefs::ExtensionsInfo* extensions_to_reload, |
| 1281 | base::TimeTicks start_time, |
| 1282 | scoped_refptr<ExtensionsService> frontend) { |
| 1283 | frontend_ = frontend; |
| 1284 | |
| 1285 | for (size_t i = 0; i < extensions_to_reload->size(); ++i) { |
| 1286 | ExtensionInfo* info = extensions_to_reload->at(i).get(); |
[email protected] | 2111b1a | 2010-03-12 18:12:44 | [diff] [blame] | 1287 | if (!ShouldReloadExtensionManifest(*info)) |
[email protected] | c6d474f8 | 2009-12-16 21:11:06 | [diff] [blame] | 1288 | continue; |
| 1289 | |
| 1290 | // We need to reload original manifest in order to localize properly. |
| 1291 | std::string error; |
| 1292 | scoped_ptr<Extension> extension(extension_file_util::LoadExtension( |
| 1293 | info->extension_path, false, &error)); |
| 1294 | |
| 1295 | if (extension.get()) |
| 1296 | extensions_to_reload->at(i)->extension_manifest.reset( |
| 1297 | static_cast<DictionaryValue*>( |
| 1298 | extension->manifest_value()->DeepCopy())); |
| 1299 | } |
| 1300 | |
| 1301 | // Finish installing on UI thread. |
| 1302 | ChromeThread::PostTask( |
| 1303 | ChromeThread::UI, FROM_HERE, |
| 1304 | NewRunnableMethod( |
| 1305 | frontend_, |
| 1306 | &ExtensionsService::ContinueLoadAllExtensions, |
| 1307 | extensions_to_reload, |
| 1308 | start_time, |
| 1309 | true)); |
| 1310 | } |