[email protected] | a12ce8b2 | 2012-01-17 18:40:53 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | 5df038b | 2012-07-16 19:03:27 | [diff] [blame] | 5 | #include "chrome/browser/extensions/external_provider_impl.h" |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 6 | |
[email protected] | 8a839a0 | 2013-03-07 05:23:33 | [diff] [blame] | 7 | #include <set> |
| 8 | #include <vector> |
| 9 | |
[email protected] | 83b59325a | 2011-10-14 15:58:07 | [diff] [blame] | 10 | #include "base/command_line.h" |
[email protected] | 5799981 | 2013-02-24 05:40:52 | [diff] [blame] | 11 | #include "base/files/file_path.h" |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 12 | #include "base/logging.h" |
[email protected] | 3b63f8f4 | 2011-03-28 01:54:15 | [diff] [blame] | 13 | #include "base/memory/linked_ptr.h" |
[email protected] | 51a7a9d | 2011-09-27 17:21:41 | [diff] [blame] | 14 | #include "base/metrics/field_trial.h" |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 15 | #include "base/path_service.h" |
[email protected] | 46acbf1 | 2013-06-10 18:43:42 | [diff] [blame] | 16 | #include "base/strings/string_util.h" |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 17 | #include "base/values.h" |
| 18 | #include "base/version.h" |
[email protected] | 8a839a0 | 2013-03-07 05:23:33 | [diff] [blame] | 19 | #include "chrome/browser/app_mode/app_mode_utils.h" |
[email protected] | e601e82 | 2011-10-05 19:25:37 | [diff] [blame] | 20 | #include "chrome/browser/browser_process.h" |
[email protected] | 51a7a9d | 2011-09-27 17:21:41 | [diff] [blame] | 21 | #include "chrome/browser/extensions/extension_service.h" |
[email protected] | 19eac6d | 2013-05-30 06:51:03 | [diff] [blame] | 22 | #include "chrome/browser/extensions/extension_system.h" |
[email protected] | 8aa50c775 | 2013-05-23 12:57:50 | [diff] [blame] | 23 | #include "chrome/browser/extensions/external_component_loader.h" |
[email protected] | 5df038b | 2012-07-16 19:03:27 | [diff] [blame] | 24 | #include "chrome/browser/extensions/external_policy_loader.h" |
| 25 | #include "chrome/browser/extensions/external_pref_loader.h" |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 26 | #include "chrome/browser/profiles/profile.h" |
[email protected] | f0841cd | 2011-01-19 15:07:24 | [diff] [blame] | 27 | #include "chrome/common/chrome_paths.h" |
[email protected] | 83b59325a | 2011-10-14 15:58:07 | [diff] [blame] | 28 | #include "chrome/common/chrome_switches.h" |
| 29 | #include "chrome/common/pref_names.h" |
[email protected] | c38831a1 | 2011-10-28 12:44:49 | [diff] [blame] | 30 | #include "content/public/browser/browser_thread.h" |
[email protected] | 301116c6 | 2013-11-26 10:37:45 | [diff] [blame] | 31 | #include "extensions/browser/external_provider_interface.h" |
[email protected] | e4452d3 | 2013-11-15 23:07:41 | [diff] [blame] | 32 | #include "extensions/common/extension.h" |
[email protected] | d42c1115 | 2013-08-22 19:36:32 | [diff] [blame] | 33 | #include "extensions/common/manifest.h" |
[email protected] | 9d32ded07 | 2011-10-11 16:31:05 | [diff] [blame] | 34 | #include "ui/base/l10n/l10n_util.h" |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 35 | |
[email protected] | 944dfa8 | 2012-03-20 02:07:51 | [diff] [blame] | 36 | #if defined(OS_CHROMEOS) |
[email protected] | af98488 | 2013-10-21 21:08:51 | [diff] [blame] | 37 | #include "chrome/browser/chromeos/extensions/device_local_account_external_policy_loader.h" |
[email protected] | a456773 | 2013-07-25 21:01:20 | [diff] [blame] | 38 | #include "chrome/browser/chromeos/extensions/external_pref_cache_loader.h" |
[email protected] | af98488 | 2013-10-21 21:08:51 | [diff] [blame] | 39 | #include "chrome/browser/chromeos/login/user.h" |
[email protected] | 944dfa8 | 2012-03-20 02:07:51 | [diff] [blame] | 40 | #include "chrome/browser/chromeos/login/user_manager.h" |
[email protected] | b39d2571 | 2013-03-14 09:53:40 | [diff] [blame] | 41 | #include "chrome/browser/chromeos/policy/app_pack_updater.h" |
[email protected] | 9727582 | 2014-01-21 19:30:36 | [diff] [blame^] | 42 | #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" |
[email protected] | af98488 | 2013-10-21 21:08:51 | [diff] [blame] | 43 | #include "chrome/browser/chromeos/policy/device_local_account.h" |
| 44 | #include "chrome/browser/chromeos/policy/device_local_account_policy_service.h" |
[email protected] | b39d2571 | 2013-03-14 09:53:40 | [diff] [blame] | 45 | #else |
[email protected] | 86c6b9e3 | 2011-10-25 17:09:10 | [diff] [blame] | 46 | #include "chrome/browser/extensions/default_apps.h" |
| 47 | #endif |
| 48 | |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 49 | #if defined(OS_WIN) |
[email protected] | 5df038b | 2012-07-16 19:03:27 | [diff] [blame] | 50 | #include "chrome/browser/extensions/external_registry_loader_win.h" |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 51 | #endif |
| 52 | |
[email protected] | 631bb74 | 2011-11-02 11:29:39 | [diff] [blame] | 53 | using content::BrowserThread; |
[email protected] | 5df038b | 2012-07-16 19:03:27 | [diff] [blame] | 54 | |
| 55 | namespace extensions { |
[email protected] | 631bb74 | 2011-11-02 11:29:39 | [diff] [blame] | 56 | |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 57 | // Constants for keeping track of extension preferences in a dictionary. |
[email protected] | 5df038b | 2012-07-16 19:03:27 | [diff] [blame] | 58 | const char ExternalProviderImpl::kExternalCrx[] = "external_crx"; |
[email protected] | 7425d7df | 2012-11-28 14:35:42 | [diff] [blame] | 59 | const char ExternalProviderImpl::kExternalVersion[] = "external_version"; |
| 60 | const char ExternalProviderImpl::kExternalUpdateUrl[] = "external_update_url"; |
| 61 | const char ExternalProviderImpl::kSupportedLocales[] = "supported_locales"; |
| 62 | const char ExternalProviderImpl::kIsBookmarkApp[] = "is_bookmark_app"; |
| 63 | const char ExternalProviderImpl::kIsFromWebstore[] = "is_from_webstore"; |
[email protected] | 19eac6d | 2013-05-30 06:51:03 | [diff] [blame] | 64 | const char ExternalProviderImpl::kKeepIfPresent[] = "keep_if_present"; |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 65 | |
[email protected] | af98488 | 2013-10-21 21:08:51 | [diff] [blame] | 66 | ExternalProviderImpl::ExternalProviderImpl( |
| 67 | VisitorInterface* service, |
| 68 | const scoped_refptr<ExternalLoader>& loader, |
| 69 | Profile* profile, |
| 70 | Manifest::Location crx_location, |
| 71 | Manifest::Location download_location, |
| 72 | int creation_flags) |
[email protected] | 4b4c013 | 2013-06-12 17:58:55 | [diff] [blame] | 73 | : crx_location_(crx_location), |
| 74 | download_location_(download_location), |
| 75 | service_(service), |
| 76 | ready_(false), |
| 77 | loader_(loader), |
| 78 | profile_(profile), |
| 79 | creation_flags_(creation_flags), |
| 80 | auto_acknowledge_(false) { |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 81 | loader_->Init(this); |
| 82 | } |
| 83 | |
[email protected] | 5df038b | 2012-07-16 19:03:27 | [diff] [blame] | 84 | ExternalProviderImpl::~ExternalProviderImpl() { |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 85 | CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 86 | loader_->OwnerShutdown(); |
| 87 | } |
| 88 | |
[email protected] | 5df038b | 2012-07-16 19:03:27 | [diff] [blame] | 89 | void ExternalProviderImpl::VisitRegisteredExtension() { |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 90 | // The loader will call back to SetPrefs. |
| 91 | loader_->StartLoading(); |
| 92 | } |
| 93 | |
[email protected] | aeca23f | 2013-06-21 22:34:41 | [diff] [blame] | 94 | void ExternalProviderImpl::SetPrefs(base::DictionaryValue* prefs) { |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 95 | CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 96 | |
[email protected] | 47fc70c | 2011-12-06 07:29:51 | [diff] [blame] | 97 | // Check if the service is still alive. It is possible that it went |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 98 | // away while |loader_| was working on the FILE thread. |
| 99 | if (!service_) return; |
| 100 | |
| 101 | prefs_.reset(prefs); |
[email protected] | 8a839a0 | 2013-03-07 05:23:33 | [diff] [blame] | 102 | ready_ = true; // Queries for extensions are allowed from this point. |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 103 | |
[email protected] | 9d32ded07 | 2011-10-11 16:31:05 | [diff] [blame] | 104 | // Set of unsupported extensions that need to be deleted from prefs_. |
| 105 | std::set<std::string> unsupported_extensions; |
| 106 | |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 107 | // Notify ExtensionService about all the extensions this provider has. |
[email protected] | aeca23f | 2013-06-21 22:34:41 | [diff] [blame] | 108 | for (base::DictionaryValue::Iterator i(*prefs_); !i.IsAtEnd(); i.Advance()) { |
[email protected] | 02d9b27 | 2013-03-06 12:54:56 | [diff] [blame] | 109 | const std::string& extension_id = i.key(); |
[email protected] | aeca23f | 2013-06-21 22:34:41 | [diff] [blame] | 110 | const base::DictionaryValue* extension = NULL; |
[email protected] | ab22ba4 | 2011-01-14 16:36:38 | [diff] [blame] | 111 | |
| 112 | if (!Extension::IdIsValid(extension_id)) { |
| 113 | LOG(WARNING) << "Malformed extension dictionary: key " |
| 114 | << extension_id.c_str() << " is not a valid id."; |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 115 | continue; |
[email protected] | ab22ba4 | 2011-01-14 16:36:38 | [diff] [blame] | 116 | } |
| 117 | |
[email protected] | 02d9b27 | 2013-03-06 12:54:56 | [diff] [blame] | 118 | if (!i.value().GetAsDictionary(&extension)) { |
[email protected] | ab22ba4 | 2011-01-14 16:36:38 | [diff] [blame] | 119 | LOG(WARNING) << "Malformed extension dictionary: key " |
| 120 | << extension_id.c_str() |
| 121 | << " has a value that is not a dictionary."; |
| 122 | continue; |
| 123 | } |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 124 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 125 | base::FilePath::StringType external_crx; |
[email protected] | cb1078de | 2013-12-23 20:04:22 | [diff] [blame] | 126 | const base::Value* external_version_value = NULL; |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 127 | std::string external_version; |
| 128 | std::string external_update_url; |
| 129 | |
| 130 | bool has_external_crx = extension->GetString(kExternalCrx, &external_crx); |
[email protected] | 0d461c5 | 2012-07-03 19:29:41 | [diff] [blame] | 131 | |
| 132 | bool has_external_version = false; |
| 133 | if (extension->Get(kExternalVersion, &external_version_value)) { |
[email protected] | cb1078de | 2013-12-23 20:04:22 | [diff] [blame] | 134 | if (external_version_value->IsType(base::Value::TYPE_STRING)) { |
[email protected] | 0d461c5 | 2012-07-03 19:29:41 | [diff] [blame] | 135 | external_version_value->GetAsString(&external_version); |
| 136 | has_external_version = true; |
| 137 | } else { |
| 138 | LOG(WARNING) << "Malformed extension dictionary for extension: " |
| 139 | << extension_id.c_str() << ". " << kExternalVersion |
| 140 | << " value must be a string."; |
| 141 | continue; |
| 142 | } |
| 143 | } |
| 144 | |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 145 | bool has_external_update_url = extension->GetString(kExternalUpdateUrl, |
| 146 | &external_update_url); |
| 147 | if (has_external_crx != has_external_version) { |
| 148 | LOG(WARNING) << "Malformed extension dictionary for extension: " |
| 149 | << extension_id.c_str() << ". " << kExternalCrx |
| 150 | << " and " << kExternalVersion << " must be used together."; |
| 151 | continue; |
| 152 | } |
| 153 | |
| 154 | if (has_external_crx == has_external_update_url) { |
| 155 | LOG(WARNING) << "Malformed extension dictionary for extension: " |
| 156 | << extension_id.c_str() << ". Exactly one of the " |
| 157 | << "followng keys should be used: " << kExternalCrx |
| 158 | << ", " << kExternalUpdateUrl << "."; |
| 159 | continue; |
| 160 | } |
| 161 | |
[email protected] | 9d32ded07 | 2011-10-11 16:31:05 | [diff] [blame] | 162 | // Check that extension supports current browser locale. |
[email protected] | aeca23f | 2013-06-21 22:34:41 | [diff] [blame] | 163 | const base::ListValue* supported_locales = NULL; |
[email protected] | 9d32ded07 | 2011-10-11 16:31:05 | [diff] [blame] | 164 | if (extension->GetList(kSupportedLocales, &supported_locales)) { |
| 165 | std::vector<std::string> browser_locales; |
| 166 | l10n_util::GetParentLocales(g_browser_process->GetApplicationLocale(), |
| 167 | &browser_locales); |
| 168 | |
| 169 | size_t num_locales = supported_locales->GetSize(); |
| 170 | bool locale_supported = false; |
| 171 | for (size_t j = 0; j < num_locales; j++) { |
| 172 | std::string current_locale; |
| 173 | if (supported_locales->GetString(j, ¤t_locale) && |
| 174 | l10n_util::IsValidLocaleSyntax(current_locale)) { |
| 175 | current_locale = l10n_util::NormalizeLocale(current_locale); |
| 176 | if (std::find(browser_locales.begin(), browser_locales.end(), |
| 177 | current_locale) != browser_locales.end()) { |
| 178 | locale_supported = true; |
| 179 | break; |
| 180 | } |
| 181 | } else { |
| 182 | LOG(WARNING) << "Unrecognized locale '" << current_locale |
| 183 | << "' found as supported locale for extension: " |
| 184 | << extension_id; |
| 185 | } |
| 186 | } |
| 187 | |
| 188 | if (!locale_supported) { |
| 189 | unsupported_extensions.insert(extension_id); |
[email protected] | 19eac6d | 2013-05-30 06:51:03 | [diff] [blame] | 190 | VLOG(1) << "Skip installing (or uninstall) external extension: " |
| 191 | << extension_id << " because the extension doesn't support " |
| 192 | << "the browser locale."; |
[email protected] | 9d32ded07 | 2011-10-11 16:31:05 | [diff] [blame] | 193 | continue; |
| 194 | } |
| 195 | } |
| 196 | |
[email protected] | f121003b | 2012-05-04 21:57:47 | [diff] [blame] | 197 | int creation_flags = creation_flags_; |
| 198 | bool is_bookmark_app; |
| 199 | if (extension->GetBoolean(kIsBookmarkApp, &is_bookmark_app) && |
| 200 | is_bookmark_app) { |
| 201 | creation_flags |= Extension::FROM_BOOKMARK; |
| 202 | } |
[email protected] | 7425d7df | 2012-11-28 14:35:42 | [diff] [blame] | 203 | bool is_from_webstore; |
| 204 | if (extension->GetBoolean(kIsFromWebstore, &is_from_webstore) && |
| 205 | is_from_webstore) { |
| 206 | creation_flags |= Extension::FROM_WEBSTORE; |
| 207 | } |
[email protected] | 19eac6d | 2013-05-30 06:51:03 | [diff] [blame] | 208 | bool keep_if_present; |
| 209 | if (extension->GetBoolean(kKeepIfPresent, &keep_if_present) && |
| 210 | keep_if_present && profile_) { |
| 211 | ExtensionServiceInterface* extension_service = |
| 212 | ExtensionSystem::Get(profile_)->extension_service(); |
| 213 | const Extension* extension = extension_service ? |
| 214 | extension_service->GetExtensionById(extension_id, true) : NULL; |
| 215 | if (!extension) { |
| 216 | VLOG(1) << "Skip installing (or uninstall) external extension: " |
| 217 | << extension_id << " because the extension should be kept " |
| 218 | << "only if it is already installed."; |
| 219 | continue; |
| 220 | } |
| 221 | } |
[email protected] | f121003b | 2012-05-04 21:57:47 | [diff] [blame] | 222 | |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 223 | if (has_external_crx) { |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 224 | if (crx_location_ == Manifest::INVALID_LOCATION) { |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 225 | LOG(WARNING) << "This provider does not support installing external " |
| 226 | << "extensions from crx files."; |
| 227 | continue; |
| 228 | } |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 229 | if (external_crx.find(base::FilePath::kParentDirectory) != |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 230 | base::StringPiece::npos) { |
| 231 | LOG(WARNING) << "Path traversal not allowed in path: " |
| 232 | << external_crx.c_str(); |
| 233 | continue; |
| 234 | } |
| 235 | |
[email protected] | f0841cd | 2011-01-19 15:07:24 | [diff] [blame] | 236 | // If the path is relative, and the provider has a base path, |
| 237 | // build the absolute path to the crx file. |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 238 | base::FilePath path(external_crx); |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 239 | if (!path.IsAbsolute()) { |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 240 | base::FilePath base_path = loader_->GetBaseCrxFilePath(); |
[email protected] | f0841cd | 2011-01-19 15:07:24 | [diff] [blame] | 241 | if (base_path.empty()) { |
| 242 | LOG(WARNING) << "File path " << external_crx.c_str() |
| 243 | << " is relative. An absolute path is required."; |
| 244 | continue; |
| 245 | } |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 246 | path = base_path.Append(external_crx); |
| 247 | } |
| 248 | |
[email protected] | c5e4a222 | 2014-01-03 16:06:13 | [diff] [blame] | 249 | Version version(external_version); |
[email protected] | 12126d37 | 2012-07-11 18:40:53 | [diff] [blame] | 250 | if (!version.IsValid()) { |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 251 | LOG(WARNING) << "Malformed extension dictionary for extension: " |
| 252 | << extension_id.c_str() << ". Invalid version string \"" |
| 253 | << external_version << "\"."; |
| 254 | continue; |
| 255 | } |
[email protected] | 12126d37 | 2012-07-11 18:40:53 | [diff] [blame] | 256 | service_->OnExternalExtensionFileFound(extension_id, &version, path, |
[email protected] | f121003b | 2012-05-04 21:57:47 | [diff] [blame] | 257 | crx_location_, creation_flags, |
[email protected] | 47fc70c | 2011-12-06 07:29:51 | [diff] [blame] | 258 | auto_acknowledge_); |
[email protected] | 8a839a0 | 2013-03-07 05:23:33 | [diff] [blame] | 259 | } else { // if (has_external_update_url) |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 260 | CHECK(has_external_update_url); // Checking of keys above ensures this. |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 261 | if (download_location_ == Manifest::INVALID_LOCATION) { |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 262 | LOG(WARNING) << "This provider does not support installing external " |
| 263 | << "extensions from update URLs."; |
| 264 | continue; |
| 265 | } |
| 266 | GURL update_url(external_update_url); |
| 267 | if (!update_url.is_valid()) { |
| 268 | LOG(WARNING) << "Malformed extension dictionary for extension: " |
[email protected] | ab22ba4 | 2011-01-14 16:36:38 | [diff] [blame] | 269 | << extension_id.c_str() << ". Key " << kExternalUpdateUrl |
| 270 | << " has value \"" << external_update_url |
| 271 | << "\", which is not a valid URL."; |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 272 | continue; |
| 273 | } |
| 274 | service_->OnExternalExtensionUpdateUrlFound( |
[email protected] | 464213a | 2013-10-15 01:06:48 | [diff] [blame] | 275 | extension_id, update_url, download_location_, creation_flags, |
| 276 | auto_acknowledge_); |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 277 | } |
| 278 | } |
| 279 | |
[email protected] | 9d32ded07 | 2011-10-11 16:31:05 | [diff] [blame] | 280 | for (std::set<std::string>::iterator it = unsupported_extensions.begin(); |
| 281 | it != unsupported_extensions.end(); ++it) { |
| 282 | // Remove extension for the list of know external extensions. The extension |
| 283 | // will be uninstalled later because provider doesn't provide it anymore. |
| 284 | prefs_->Remove(*it, NULL); |
| 285 | } |
| 286 | |
[email protected] | 50067e5 | 2011-10-20 23:17:07 | [diff] [blame] | 287 | service_->OnExternalProviderReady(this); |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 288 | } |
| 289 | |
[email protected] | 5df038b | 2012-07-16 19:03:27 | [diff] [blame] | 290 | void ExternalProviderImpl::ServiceShutdown() { |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 291 | service_ = NULL; |
| 292 | } |
| 293 | |
[email protected] | 5df038b | 2012-07-16 19:03:27 | [diff] [blame] | 294 | bool ExternalProviderImpl::IsReady() const { |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 295 | return ready_; |
| 296 | } |
| 297 | |
[email protected] | 5df038b | 2012-07-16 19:03:27 | [diff] [blame] | 298 | bool ExternalProviderImpl::HasExtension( |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 299 | const std::string& id) const { |
| 300 | CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 301 | CHECK(prefs_.get()); |
| 302 | CHECK(ready_); |
| 303 | return prefs_->HasKey(id); |
| 304 | } |
| 305 | |
[email protected] | 5df038b | 2012-07-16 19:03:27 | [diff] [blame] | 306 | bool ExternalProviderImpl::GetExtensionDetails( |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 307 | const std::string& id, Manifest::Location* location, |
[email protected] | c5e4a222 | 2014-01-03 16:06:13 | [diff] [blame] | 308 | scoped_ptr<Version>* version) const { |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 309 | CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 310 | CHECK(prefs_.get()); |
| 311 | CHECK(ready_); |
[email protected] | aeca23f | 2013-06-21 22:34:41 | [diff] [blame] | 312 | base::DictionaryValue* extension = NULL; |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 313 | if (!prefs_->GetDictionary(id, &extension)) |
| 314 | return false; |
| 315 | |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 316 | Manifest::Location loc = Manifest::INVALID_LOCATION; |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 317 | if (extension->HasKey(kExternalUpdateUrl)) { |
| 318 | loc = download_location_; |
| 319 | |
| 320 | } else if (extension->HasKey(kExternalCrx)) { |
| 321 | loc = crx_location_; |
| 322 | |
| 323 | std::string external_version; |
| 324 | if (!extension->GetString(kExternalVersion, &external_version)) |
| 325 | return false; |
| 326 | |
| 327 | if (version) |
[email protected] | c5e4a222 | 2014-01-03 16:06:13 | [diff] [blame] | 328 | version->reset(new Version(external_version)); |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 329 | |
| 330 | } else { |
| 331 | NOTREACHED(); // Chrome should not allow prefs to get into this state. |
| 332 | return false; |
| 333 | } |
| 334 | |
| 335 | if (location) |
| 336 | *location = loc; |
| 337 | |
| 338 | return true; |
| 339 | } |
| 340 | |
| 341 | // static |
[email protected] | 5df038b | 2012-07-16 19:03:27 | [diff] [blame] | 342 | void ExternalProviderImpl::CreateExternalProviders( |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 343 | VisitorInterface* service, |
| 344 | Profile* profile, |
| 345 | ProviderCollection* provider_list) { |
[email protected] | af98488 | 2013-10-21 21:08:51 | [diff] [blame] | 346 | scoped_refptr<ExternalLoader> external_loader; |
| 347 | extensions::Manifest::Location crx_location = Manifest::INVALID_LOCATION; |
| 348 | #if defined(OS_CHROMEOS) |
[email protected] | 9727582 | 2014-01-21 19:30:36 | [diff] [blame^] | 349 | policy::BrowserPolicyConnectorChromeOS* connector = |
| 350 | g_browser_process->platform_part()->browser_policy_connector_chromeos(); |
[email protected] | 2d4cfed | 2014-01-14 13:59:57 | [diff] [blame] | 351 | bool is_chrome_os_public_session = false; |
[email protected] | af98488 | 2013-10-21 21:08:51 | [diff] [blame] | 352 | const chromeos::User* user = |
| 353 | chromeos::UserManager::Get()->GetUserByProfile(profile); |
[email protected] | 2d4cfed | 2014-01-14 13:59:57 | [diff] [blame] | 354 | policy::DeviceLocalAccount::Type account_type; |
| 355 | if (user && policy::IsDeviceLocalAccountUser(user->email(), &account_type)) { |
| 356 | if (account_type == policy::DeviceLocalAccount::TYPE_PUBLIC_SESSION) |
| 357 | is_chrome_os_public_session = true; |
[email protected] | af98488 | 2013-10-21 21:08:51 | [diff] [blame] | 358 | policy::DeviceLocalAccountPolicyBroker* broker = |
[email protected] | 9727582 | 2014-01-21 19:30:36 | [diff] [blame^] | 359 | connector->GetDeviceLocalAccountPolicyService()->GetBrokerForUser( |
| 360 | user->email()); |
[email protected] | af98488 | 2013-10-21 21:08:51 | [diff] [blame] | 361 | if (broker) { |
| 362 | external_loader = broker->extension_loader(); |
| 363 | crx_location = Manifest::EXTERNAL_POLICY; |
| 364 | } else { |
| 365 | NOTREACHED(); |
| 366 | } |
| 367 | } else { |
| 368 | external_loader = new ExternalPolicyLoader(profile); |
| 369 | } |
| 370 | #else |
| 371 | external_loader = new ExternalPolicyLoader(profile); |
| 372 | #endif |
| 373 | |
[email protected] | b9f4fe5 | 2012-11-09 21:40:59 | [diff] [blame] | 374 | // Policies are mandatory so they can't be skipped with command line flag. |
[email protected] | af98488 | 2013-10-21 21:08:51 | [diff] [blame] | 375 | if (external_loader) { |
| 376 | provider_list->push_back( |
| 377 | linked_ptr<ExternalProviderInterface>( |
| 378 | new ExternalProviderImpl( |
| 379 | service, |
| 380 | external_loader, |
| 381 | profile, |
| 382 | crx_location, |
| 383 | Manifest::EXTERNAL_POLICY_DOWNLOAD, |
| 384 | Extension::NO_FLAGS))); |
| 385 | } |
[email protected] | b9f4fe5 | 2012-11-09 21:40:59 | [diff] [blame] | 386 | |
| 387 | // In tests don't install extensions from default external sources. |
| 388 | // It would only slowdown tests and make them flaky. |
| 389 | if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 390 | switches::kDisableDefaultApps)) |
| 391 | return; |
[email protected] | 73e4c36 | 2011-09-22 14:47:18 | [diff] [blame] | 392 | |
[email protected] | 8a839a0 | 2013-03-07 05:23:33 | [diff] [blame] | 393 | // No external app install in app mode. |
| 394 | if (chrome::IsRunningInForcedAppMode()) |
| 395 | return; |
| 396 | |
[email protected] | 73e4c36 | 2011-09-22 14:47:18 | [diff] [blame] | 397 | // On Mac OS, items in /Library/... should be written by the superuser. |
| 398 | // Check that all components of the path are writable by root only. |
[email protected] | 5df038b | 2012-07-16 19:03:27 | [diff] [blame] | 399 | ExternalPrefLoader::Options check_admin_permissions_on_mac; |
[email protected] | 73e4c36 | 2011-09-22 14:47:18 | [diff] [blame] | 400 | #if defined(OS_MACOSX) |
[email protected] | 0edc5541 | 2011-11-07 16:47:33 | [diff] [blame] | 401 | check_admin_permissions_on_mac = |
[email protected] | 5df038b | 2012-07-16 19:03:27 | [diff] [blame] | 402 | ExternalPrefLoader::ENSURE_PATH_CONTROLLED_BY_ADMIN; |
[email protected] | 73e4c36 | 2011-09-22 14:47:18 | [diff] [blame] | 403 | #else |
[email protected] | 5df038b | 2012-07-16 19:03:27 | [diff] [blame] | 404 | check_admin_permissions_on_mac = ExternalPrefLoader::NONE; |
[email protected] | 73e4c36 | 2011-09-22 14:47:18 | [diff] [blame] | 405 | #endif |
| 406 | |
[email protected] | d6f7b10 | 2012-05-04 13:59:05 | [diff] [blame] | 407 | bool is_chromeos_demo_session = false; |
| 408 | int bundled_extension_creation_flags = Extension::NO_FLAGS; |
[email protected] | 03d3ba01 | 2012-04-02 22:36:13 | [diff] [blame] | 409 | #if defined(OS_CHROMEOS) |
[email protected] | d6f7b10 | 2012-05-04 13:59:05 | [diff] [blame] | 410 | chromeos::UserManager* user_manager = chromeos::UserManager::Get(); |
| 411 | is_chromeos_demo_session = |
| 412 | user_manager && user_manager->IsLoggedInAsDemoUser() && |
[email protected] | 9727582 | 2014-01-21 19:30:36 | [diff] [blame^] | 413 | connector->GetDeviceMode() == policy::DEVICE_MODE_RETAIL_KIOSK; |
[email protected] | 5861bcd | 2012-10-16 21:40:19 | [diff] [blame] | 414 | bundled_extension_creation_flags = Extension::FROM_WEBSTORE | |
| 415 | Extension::WAS_INSTALLED_BY_DEFAULT; |
[email protected] | a456773 | 2013-07-25 21:01:20 | [diff] [blame] | 416 | #endif |
| 417 | |
[email protected] | ebb489f | 2013-09-19 22:08:52 | [diff] [blame] | 418 | #if defined(OS_LINUX) && !defined(OS_CHROMEOS) |
| 419 | if (!profile->IsManaged()) { |
[email protected] | d6f7b10 | 2012-05-04 13:59:05 | [diff] [blame] | 420 | provider_list->push_back( |
[email protected] | 5df038b | 2012-07-16 19:03:27 | [diff] [blame] | 421 | linked_ptr<ExternalProviderInterface>( |
| 422 | new ExternalProviderImpl( |
[email protected] | d6f7b10 | 2012-05-04 13:59:05 | [diff] [blame] | 423 | service, |
[email protected] | ebb489f | 2013-09-19 22:08:52 | [diff] [blame] | 424 | new ExternalPrefLoader( |
| 425 | chrome::DIR_STANDALONE_EXTERNAL_EXTENSIONS, |
| 426 | ExternalPrefLoader::NONE), |
[email protected] | 19eac6d | 2013-05-30 06:51:03 | [diff] [blame] | 427 | profile, |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 428 | Manifest::EXTERNAL_PREF, |
| 429 | Manifest::EXTERNAL_PREF_DOWNLOAD, |
[email protected] | d6f7b10 | 2012-05-04 13:59:05 | [diff] [blame] | 430 | bundled_extension_creation_flags))); |
| 431 | } |
[email protected] | 5bed2ec3 | 2013-08-29 22:55:46 | [diff] [blame] | 432 | #endif |
[email protected] | d6f7b10 | 2012-05-04 13:59:05 | [diff] [blame] | 433 | |
[email protected] | 5bed2ec3 | 2013-08-29 22:55:46 | [diff] [blame] | 434 | #if defined(OS_CHROMEOS) |
[email protected] | 2d4cfed | 2014-01-14 13:59:57 | [diff] [blame] | 435 | if (!is_chromeos_demo_session && !is_chrome_os_public_session) { |
[email protected] | ebb489f | 2013-09-19 22:08:52 | [diff] [blame] | 436 | int external_apps_path_id = profile->IsManaged() ? |
| 437 | chrome::DIR_MANAGED_USERS_DEFAULT_APPS : |
| 438 | chrome::DIR_STANDALONE_EXTERNAL_EXTENSIONS; |
| 439 | provider_list->push_back( |
| 440 | linked_ptr<ExternalProviderInterface>( |
| 441 | new ExternalProviderImpl( |
| 442 | service, |
[email protected] | 170d1d1 | 2013-10-30 03:32:19 | [diff] [blame] | 443 | new chromeos::ExternalPrefCacheLoader( |
| 444 | external_apps_path_id, profile), |
[email protected] | ebb489f | 2013-09-19 22:08:52 | [diff] [blame] | 445 | profile, |
| 446 | Manifest::EXTERNAL_PREF, |
| 447 | Manifest::EXTERNAL_PREF_DOWNLOAD, |
| 448 | bundled_extension_creation_flags))); |
| 449 | } |
| 450 | |
[email protected] | 9727582 | 2014-01-21 19:30:36 | [diff] [blame^] | 451 | policy::AppPackUpdater* app_pack_updater = connector->GetAppPackUpdater(); |
[email protected] | 5bed2ec3 | 2013-08-29 22:55:46 | [diff] [blame] | 452 | if (is_chromeos_demo_session && app_pack_updater && |
| 453 | !app_pack_updater->created_external_loader()) { |
| 454 | provider_list->push_back( |
| 455 | linked_ptr<ExternalProviderInterface>( |
| 456 | new ExternalProviderImpl( |
| 457 | service, |
| 458 | app_pack_updater->CreateExternalLoader(), |
| 459 | profile, |
| 460 | Manifest::EXTERNAL_PREF, |
| 461 | Manifest::INVALID_LOCATION, |
| 462 | Extension::NO_FLAGS))); |
| 463 | } |
| 464 | #endif |
| 465 | |
| 466 | if (!profile->IsManaged() && !is_chromeos_demo_session) { |
[email protected] | 93f3ad2 | 2014-01-16 17:37:22 | [diff] [blame] | 467 | #if !defined(OS_WIN) |
[email protected] | 5bed2ec3 | 2013-08-29 22:55:46 | [diff] [blame] | 468 | provider_list->push_back( |
| 469 | linked_ptr<ExternalProviderInterface>( |
| 470 | new ExternalProviderImpl( |
| 471 | service, |
| 472 | new ExternalPrefLoader(chrome::DIR_EXTERNAL_EXTENSIONS, |
| 473 | check_admin_permissions_on_mac), |
| 474 | profile, |
| 475 | Manifest::EXTERNAL_PREF, |
| 476 | Manifest::EXTERNAL_PREF_DOWNLOAD, |
| 477 | bundled_extension_creation_flags))); |
[email protected] | 93f3ad2 | 2014-01-16 17:37:22 | [diff] [blame] | 478 | #endif |
[email protected] | 5bed2ec3 | 2013-08-29 22:55:46 | [diff] [blame] | 479 | |
[email protected] | 7da1221 | 2013-02-14 10:53:49 | [diff] [blame] | 480 | // Define a per-user source of external extensions. |
| 481 | // On Chrome OS, this serves as a source for OEM customization. |
[email protected] | 2d4cfed | 2014-01-14 13:59:57 | [diff] [blame] | 482 | #if defined(OS_CHROMEOS) |
| 483 | if (!is_chrome_os_public_session) { |
| 484 | #endif |
| 485 | #if defined(OS_CHROMEOS) || defined(OS_MACOSX) |
| 486 | provider_list->push_back( |
| 487 | linked_ptr<ExternalProviderInterface>( |
| 488 | new ExternalProviderImpl( |
| 489 | service, |
| 490 | new ExternalPrefLoader(chrome::DIR_USER_EXTERNAL_EXTENSIONS, |
| 491 | ExternalPrefLoader::NONE), |
| 492 | profile, |
| 493 | Manifest::EXTERNAL_PREF, |
| 494 | Manifest::EXTERNAL_PREF_DOWNLOAD, |
| 495 | Extension::NO_FLAGS))); |
| 496 | #endif |
| 497 | #if defined(OS_CHROMEOS) |
| 498 | } |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 499 | #endif |
[email protected] | 7da1221 | 2013-02-14 10:53:49 | [diff] [blame] | 500 | |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 501 | #if defined(OS_WIN) |
[email protected] | 7da1221 | 2013-02-14 10:53:49 | [diff] [blame] | 502 | provider_list->push_back( |
| 503 | linked_ptr<ExternalProviderInterface>( |
| 504 | new ExternalProviderImpl( |
| 505 | service, |
| 506 | new ExternalRegistryLoader, |
[email protected] | 19eac6d | 2013-05-30 06:51:03 | [diff] [blame] | 507 | profile, |
[email protected] | 7da1221 | 2013-02-14 10:53:49 | [diff] [blame] | 508 | Manifest::EXTERNAL_REGISTRY, |
[email protected] | 096d2b8 | 2013-12-20 09:03:20 | [diff] [blame] | 509 | Manifest::EXTERNAL_PREF_DOWNLOAD, |
[email protected] | 7da1221 | 2013-02-14 10:53:49 | [diff] [blame] | 510 | Extension::NO_FLAGS))); |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 511 | #endif |
[email protected] | ed7bbb5 | 2012-05-02 11:07:29 | [diff] [blame] | 512 | |
[email protected] | 98b4aca6 | 2011-09-28 01:27:23 | [diff] [blame] | 513 | #if !defined(OS_CHROMEOS) |
[email protected] | 7da1221 | 2013-02-14 10:53:49 | [diff] [blame] | 514 | // The default apps are installed as INTERNAL but use the external |
| 515 | // extension installer codeflow. |
| 516 | provider_list->push_back( |
| 517 | linked_ptr<ExternalProviderInterface>( |
| 518 | new default_apps::Provider( |
| 519 | profile, |
| 520 | service, |
| 521 | new ExternalPrefLoader(chrome::DIR_DEFAULT_APPS, |
| 522 | ExternalPrefLoader::NONE), |
| 523 | Manifest::INTERNAL, |
| 524 | Manifest::INVALID_LOCATION, |
| 525 | Extension::FROM_WEBSTORE | |
| 526 | Extension::WAS_INSTALLED_BY_DEFAULT))); |
[email protected] | 98b4aca6 | 2011-09-28 01:27:23 | [diff] [blame] | 527 | #endif |
[email protected] | 944dfa8 | 2012-03-20 02:07:51 | [diff] [blame] | 528 | |
[email protected] | 5bed2ec3 | 2013-08-29 22:55:46 | [diff] [blame] | 529 | provider_list->push_back( |
[email protected] | 8aa50c775 | 2013-05-23 12:57:50 | [diff] [blame] | 530 | linked_ptr<ExternalProviderInterface>( |
| 531 | new ExternalProviderImpl( |
| 532 | service, |
[email protected] | 914fac713 | 2013-12-17 00:21:26 | [diff] [blame] | 533 | new ExternalComponentLoader(profile), |
[email protected] | 19eac6d | 2013-05-30 06:51:03 | [diff] [blame] | 534 | profile, |
[email protected] | 8aa50c775 | 2013-05-23 12:57:50 | [diff] [blame] | 535 | Manifest::INVALID_LOCATION, |
[email protected] | 47ba44b2 | 2013-10-02 22:20:07 | [diff] [blame] | 536 | Manifest::EXTERNAL_COMPONENT, |
[email protected] | 8aa50c775 | 2013-05-23 12:57:50 | [diff] [blame] | 537 | Extension::FROM_WEBSTORE | Extension::WAS_INSTALLED_BY_DEFAULT))); |
[email protected] | 5bed2ec3 | 2013-08-29 22:55:46 | [diff] [blame] | 538 | } |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 539 | } |
[email protected] | 5df038b | 2012-07-16 19:03:27 | [diff] [blame] | 540 | |
| 541 | } // namespace extensions |