| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/extensions/external_provider_impl.h" | 5 #include "chrome/browser/extensions/external_provider_impl.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <set> | 9 #include <set> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 #include "chrome/browser/policy/profile_policy_connector.h" | 32 #include "chrome/browser/policy/profile_policy_connector.h" |
| 33 #include "chrome/browser/policy/profile_policy_connector_factory.h" | 33 #include "chrome/browser/policy/profile_policy_connector_factory.h" |
| 34 #include "chrome/browser/profiles/profile.h" | 34 #include "chrome/browser/profiles/profile.h" |
| 35 #include "chrome/common/chrome_paths.h" | 35 #include "chrome/common/chrome_paths.h" |
| 36 #include "chrome/common/chrome_switches.h" | 36 #include "chrome/common/chrome_switches.h" |
| 37 #include "chrome/common/extensions/extension_constants.h" | 37 #include "chrome/common/extensions/extension_constants.h" |
| 38 #include "chrome/common/pref_names.h" | 38 #include "chrome/common/pref_names.h" |
| 39 #include "components/crx_file/id_util.h" | 39 #include "components/crx_file/id_util.h" |
| 40 #include "content/public/browser/browser_thread.h" | 40 #include "content/public/browser/browser_thread.h" |
| 41 #include "extensions/browser/extension_system.h" | 41 #include "extensions/browser/extension_system.h" |
| 42 #include "extensions/browser/external_install_info.h" |
| 42 #include "extensions/browser/external_provider_interface.h" | 43 #include "extensions/browser/external_provider_interface.h" |
| 43 #include "extensions/common/extension.h" | 44 #include "extensions/common/extension.h" |
| 44 #include "extensions/common/manifest.h" | 45 #include "extensions/common/manifest.h" |
| 45 #include "ui/base/l10n/l10n_util.h" | 46 #include "ui/base/l10n/l10n_util.h" |
| 46 | 47 |
| 47 #if defined(OS_CHROMEOS) | 48 #if defined(OS_CHROMEOS) |
| 48 #include "chrome/browser/chromeos/app_mode/kiosk_app_manager.h" | 49 #include "chrome/browser/chromeos/app_mode/kiosk_app_manager.h" |
| 49 #include "chrome/browser/chromeos/customization/customization_document.h" | 50 #include "chrome/browser/chromeos/customization/customization_document.h" |
| 50 #include "chrome/browser/chromeos/extensions/device_local_account_external_polic
y_loader.h" | 51 #include "chrome/browser/chromeos/extensions/device_local_account_external_polic
y_loader.h" |
| 51 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" | 52 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 void ExternalProviderImpl::SetPrefs(base::DictionaryValue* prefs) { | 114 void ExternalProviderImpl::SetPrefs(base::DictionaryValue* prefs) { |
| 114 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 115 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 115 | 116 |
| 116 // Check if the service is still alive. It is possible that it went | 117 // Check if the service is still alive. It is possible that it went |
| 117 // away while |loader_| was working on the FILE thread. | 118 // away while |loader_| was working on the FILE thread. |
| 118 if (!service_) return; | 119 if (!service_) return; |
| 119 | 120 |
| 120 prefs_.reset(prefs); | 121 prefs_.reset(prefs); |
| 121 ready_ = true; // Queries for extensions are allowed from this point. | 122 ready_ = true; // Queries for extensions are allowed from this point. |
| 122 | 123 |
| 124 ScopedVector<ExternalInstallInfoUpdateUrl> external_update_url_extensions; |
| 125 ScopedVector<ExternalInstallInfoFile> external_file_extensions; |
| 126 |
| 127 RetrieveExtensionsFromPrefs(&external_update_url_extensions, |
| 128 &external_file_extensions); |
| 129 for (const auto& extension : external_update_url_extensions) |
| 130 service_->OnExternalExtensionUpdateUrlFound(*extension, true); |
| 131 |
| 132 for (const auto& extension : external_file_extensions) |
| 133 service_->OnExternalExtensionFileFound(*extension); |
| 134 |
| 135 service_->OnExternalProviderReady(this); |
| 136 } |
| 137 |
| 138 void ExternalProviderImpl::UpdatePrefs(base::DictionaryValue* prefs) { |
| 139 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 140 // We only expect updates from windows registry. |
| 141 CHECK(crx_location_ == Manifest::EXTERNAL_REGISTRY); |
| 142 |
| 143 // Check if the service is still alive. It is possible that it went |
| 144 // away while |loader_| was working on the FILE thread. |
| 145 if (!service_) |
| 146 return; |
| 147 |
| 148 std::set<std::string> removed_extensions; |
| 149 // Find extensions that were removed by this ExternalProvider. |
| 150 for (base::DictionaryValue::Iterator i(*prefs_); !i.IsAtEnd(); i.Advance()) { |
| 151 const std::string& extension_id = i.key(); |
| 152 // Don't bother about invalid ids. |
| 153 if (!crx_file::id_util::IdIsValid(extension_id)) |
| 154 continue; |
| 155 if (!prefs->HasKey(extension_id)) |
| 156 removed_extensions.insert(extension_id); |
| 157 } |
| 158 |
| 159 prefs_.reset(prefs); |
| 160 |
| 161 ScopedVector<ExternalInstallInfoUpdateUrl> external_update_url_extensions; |
| 162 ScopedVector<ExternalInstallInfoFile> external_file_extensions; |
| 163 RetrieveExtensionsFromPrefs(&external_update_url_extensions, |
| 164 &external_file_extensions); |
| 165 |
| 166 // Notify ExtensionService about completion of finding incremental updates |
| 167 // from this provider. |
| 168 // Provide the list of added and removed extensions. |
| 169 service_->OnExternalProviderUpdateComplete( |
| 170 this, external_update_url_extensions, external_file_extensions, |
| 171 removed_extensions); |
| 172 } |
| 173 |
| 174 void ExternalProviderImpl::RetrieveExtensionsFromPrefs( |
| 175 ScopedVector<ExternalInstallInfoUpdateUrl>* external_update_url_extensions, |
| 176 ScopedVector<ExternalInstallInfoFile>* external_file_extensions) { |
| 123 // Set of unsupported extensions that need to be deleted from prefs_. | 177 // Set of unsupported extensions that need to be deleted from prefs_. |
| 124 std::set<std::string> unsupported_extensions; | 178 std::set<std::string> unsupported_extensions; |
| 125 | 179 |
| 126 // Notify ExtensionService about all the extensions this provider has. | 180 // Discover all the extensions this provider has. |
| 127 for (base::DictionaryValue::Iterator i(*prefs_); !i.IsAtEnd(); i.Advance()) { | 181 for (base::DictionaryValue::Iterator i(*prefs_); !i.IsAtEnd(); i.Advance()) { |
| 128 const std::string& extension_id = i.key(); | 182 const std::string& extension_id = i.key(); |
| 129 const base::DictionaryValue* extension = NULL; | 183 const base::DictionaryValue* extension = NULL; |
| 130 | 184 |
| 131 if (!crx_file::id_util::IdIsValid(extension_id)) { | 185 if (!crx_file::id_util::IdIsValid(extension_id)) { |
| 132 LOG(WARNING) << "Malformed extension dictionary: key " | 186 LOG(WARNING) << "Malformed extension dictionary: key " |
| 133 << extension_id.c_str() << " is not a valid id."; | 187 << extension_id.c_str() << " is not a valid id."; |
| 134 continue; | 188 continue; |
| 135 } | 189 } |
| 136 | 190 |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 282 if (!path.IsAbsolute()) { | 336 if (!path.IsAbsolute()) { |
| 283 base::FilePath base_path = loader_->GetBaseCrxFilePath(); | 337 base::FilePath base_path = loader_->GetBaseCrxFilePath(); |
| 284 if (base_path.empty()) { | 338 if (base_path.empty()) { |
| 285 LOG(WARNING) << "File path " << external_crx.c_str() | 339 LOG(WARNING) << "File path " << external_crx.c_str() |
| 286 << " is relative. An absolute path is required."; | 340 << " is relative. An absolute path is required."; |
| 287 continue; | 341 continue; |
| 288 } | 342 } |
| 289 path = base_path.Append(external_crx); | 343 path = base_path.Append(external_crx); |
| 290 } | 344 } |
| 291 | 345 |
| 292 Version version(external_version); | 346 scoped_ptr<Version> version(new Version(external_version)); |
| 293 if (!version.IsValid()) { | 347 if (!version->IsValid()) { |
| 294 LOG(WARNING) << "Malformed extension dictionary for extension: " | 348 LOG(WARNING) << "Malformed extension dictionary for extension: " |
| 295 << extension_id.c_str() << ". Invalid version string \"" | 349 << extension_id.c_str() << ". Invalid version string \"" |
| 296 << external_version << "\"."; | 350 << external_version << "\"."; |
| 297 continue; | 351 continue; |
| 298 } | 352 } |
| 299 service_->OnExternalExtensionFileFound(extension_id, &version, path, | 353 external_file_extensions->push_back(new ExternalInstallInfoFile( |
| 300 crx_location_, creation_flags, | 354 extension_id, std::move(version), path, crx_location_, creation_flags, |
| 301 auto_acknowledge_, | 355 auto_acknowledge_, install_immediately_)); |
| 302 install_immediately_); | |
| 303 } else { // if (has_external_update_url) | 356 } else { // if (has_external_update_url) |
| 304 CHECK(has_external_update_url); // Checking of keys above ensures this. | 357 CHECK(has_external_update_url); // Checking of keys above ensures this. |
| 305 if (download_location_ == Manifest::INVALID_LOCATION) { | 358 if (download_location_ == Manifest::INVALID_LOCATION) { |
| 306 LOG(WARNING) << "This provider does not support installing external " | 359 LOG(WARNING) << "This provider does not support installing external " |
| 307 << "extensions from update URLs."; | 360 << "extensions from update URLs."; |
| 308 continue; | 361 continue; |
| 309 } | 362 } |
| 310 GURL update_url(external_update_url); | 363 scoped_ptr<GURL> update_url(new GURL(external_update_url)); |
| 311 if (!update_url.is_valid()) { | 364 if (!update_url->is_valid()) { |
| 312 LOG(WARNING) << "Malformed extension dictionary for extension: " | 365 LOG(WARNING) << "Malformed extension dictionary for extension: " |
| 313 << extension_id.c_str() << ". Key " << kExternalUpdateUrl | 366 << extension_id.c_str() << ". Key " << kExternalUpdateUrl |
| 314 << " has value \"" << external_update_url | 367 << " has value \"" << external_update_url |
| 315 << "\", which is not a valid URL."; | 368 << "\", which is not a valid URL."; |
| 316 continue; | 369 continue; |
| 317 } | 370 } |
| 318 service_->OnExternalExtensionUpdateUrlFound(extension_id, | 371 external_update_url_extensions->push_back( |
| 319 install_parameter, | 372 new ExternalInstallInfoUpdateUrl( |
| 320 update_url, | 373 extension_id, install_parameter, std::move(update_url), |
| 321 download_location_, | 374 download_location_, creation_flags, auto_acknowledge_)); |
| 322 creation_flags, | |
| 323 auto_acknowledge_); | |
| 324 } | 375 } |
| 325 } | 376 } |
| 326 | 377 |
| 327 for (std::set<std::string>::iterator it = unsupported_extensions.begin(); | 378 for (std::set<std::string>::iterator it = unsupported_extensions.begin(); |
| 328 it != unsupported_extensions.end(); ++it) { | 379 it != unsupported_extensions.end(); ++it) { |
| 329 // Remove extension for the list of know external extensions. The extension | 380 // Remove extension for the list of know external extensions. The extension |
| 330 // will be uninstalled later because provider doesn't provide it anymore. | 381 // will be uninstalled later because provider doesn't provide it anymore. |
| 331 prefs_->Remove(*it, NULL); | 382 prefs_->Remove(*it, NULL); |
| 332 } | 383 } |
| 333 | |
| 334 service_->OnExternalProviderReady(this); | |
| 335 } | 384 } |
| 336 | 385 |
| 337 void ExternalProviderImpl::ServiceShutdown() { | 386 void ExternalProviderImpl::ServiceShutdown() { |
| 338 service_ = NULL; | 387 service_ = NULL; |
| 339 } | 388 } |
| 340 | 389 |
| 341 bool ExternalProviderImpl::IsReady() const { | 390 bool ExternalProviderImpl::IsReady() const { |
| 342 return ready_; | 391 return ready_; |
| 343 } | 392 } |
| 344 | 393 |
| (...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 691 new ExternalProviderImpl( | 740 new ExternalProviderImpl( |
| 692 service, | 741 service, |
| 693 new ExternalComponentLoader(profile), | 742 new ExternalComponentLoader(profile), |
| 694 profile, | 743 profile, |
| 695 Manifest::INVALID_LOCATION, | 744 Manifest::INVALID_LOCATION, |
| 696 Manifest::EXTERNAL_COMPONENT, | 745 Manifest::EXTERNAL_COMPONENT, |
| 697 Extension::FROM_WEBSTORE | Extension::WAS_INSTALLED_BY_DEFAULT))); | 746 Extension::FROM_WEBSTORE | Extension::WAS_INSTALLED_BY_DEFAULT))); |
| 698 } | 747 } |
| 699 | 748 |
| 700 } // namespace extensions | 749 } // namespace extensions |
| OLD | NEW |