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