| 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 "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/file_path.h" | 8 #include "base/file_path.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/memory/linked_ptr.h" | 10 #include "base/memory/linked_ptr.h" |
| 11 #include "base/metrics/field_trial.h" | 11 #include "base/metrics/field_trial.h" |
| 12 #include "base/path_service.h" | 12 #include "base/path_service.h" |
| 13 #include "base/string_util.h" | 13 #include "base/string_util.h" |
| 14 #include "base/values.h" | 14 #include "base/values.h" |
| 15 #include "base/version.h" | 15 #include "base/version.h" |
| 16 #include "chrome/browser/browser_process.h" | 16 #include "chrome/browser/browser_process.h" |
| 17 #include "chrome/browser/extensions/extension_service.h" | 17 #include "chrome/browser/extensions/extension_service.h" |
| 18 #include "chrome/browser/extensions/external_policy_loader.h" | 18 #include "chrome/browser/extensions/external_policy_loader.h" |
| 19 #include "chrome/browser/extensions/external_pref_loader.h" | 19 #include "chrome/browser/extensions/external_pref_loader.h" |
| 20 #include "chrome/browser/extensions/external_provider_interface.h" | 20 #include "chrome/browser/extensions/external_provider_interface.h" |
| 21 #include "chrome/browser/profiles/profile.h" | 21 #include "chrome/browser/profiles/profile.h" |
| 22 #include "chrome/common/chrome_paths.h" | 22 #include "chrome/common/chrome_paths.h" |
| 23 #include "chrome/common/chrome_switches.h" | 23 #include "chrome/common/chrome_switches.h" |
| 24 #include "chrome/common/extensions/extension.h" |
| 25 #include "chrome/common/extensions/manifest.h" |
| 24 #include "chrome/common/pref_names.h" | 26 #include "chrome/common/pref_names.h" |
| 25 #include "content/public/browser/browser_thread.h" | 27 #include "content/public/browser/browser_thread.h" |
| 26 #include "ui/base/l10n/l10n_util.h" | 28 #include "ui/base/l10n/l10n_util.h" |
| 27 | 29 |
| 28 #if defined(OS_CHROMEOS) | 30 #if defined(OS_CHROMEOS) |
| 29 #include "chrome/browser/chromeos/login/user_manager.h" | 31 #include "chrome/browser/chromeos/login/user_manager.h" |
| 30 #include "chrome/browser/policy/app_pack_updater.h" | 32 #include "chrome/browser/policy/app_pack_updater.h" |
| 31 #include "chrome/browser/policy/browser_policy_connector.h" | 33 #include "chrome/browser/policy/browser_policy_connector.h" |
| 32 #endif | 34 #endif |
| 33 | 35 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 47 const char ExternalProviderImpl::kExternalCrx[] = "external_crx"; | 49 const char ExternalProviderImpl::kExternalCrx[] = "external_crx"; |
| 48 const char ExternalProviderImpl::kExternalVersion[] = "external_version"; | 50 const char ExternalProviderImpl::kExternalVersion[] = "external_version"; |
| 49 const char ExternalProviderImpl::kExternalUpdateUrl[] = "external_update_url"; | 51 const char ExternalProviderImpl::kExternalUpdateUrl[] = "external_update_url"; |
| 50 const char ExternalProviderImpl::kSupportedLocales[] = "supported_locales"; | 52 const char ExternalProviderImpl::kSupportedLocales[] = "supported_locales"; |
| 51 const char ExternalProviderImpl::kIsBookmarkApp[] = "is_bookmark_app"; | 53 const char ExternalProviderImpl::kIsBookmarkApp[] = "is_bookmark_app"; |
| 52 const char ExternalProviderImpl::kIsFromWebstore[] = "is_from_webstore"; | 54 const char ExternalProviderImpl::kIsFromWebstore[] = "is_from_webstore"; |
| 53 | 55 |
| 54 ExternalProviderImpl::ExternalProviderImpl( | 56 ExternalProviderImpl::ExternalProviderImpl( |
| 55 VisitorInterface* service, | 57 VisitorInterface* service, |
| 56 ExternalLoader* loader, | 58 ExternalLoader* loader, |
| 57 Extension::Location crx_location, | 59 Manifest::Location crx_location, |
| 58 Extension::Location download_location, | 60 Manifest::Location download_location, |
| 59 int creation_flags) | 61 int creation_flags) |
| 60 : crx_location_(crx_location), | 62 : crx_location_(crx_location), |
| 61 download_location_(download_location), | 63 download_location_(download_location), |
| 62 service_(service), | 64 service_(service), |
| 63 prefs_(NULL), | 65 prefs_(NULL), |
| 64 ready_(false), | 66 ready_(false), |
| 65 loader_(loader), | 67 loader_(loader), |
| 66 creation_flags_(creation_flags), | 68 creation_flags_(creation_flags), |
| 67 auto_acknowledge_(false) { | 69 auto_acknowledge_(false) { |
| 68 loader_->Init(this); | 70 loader_->Init(this); |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 is_bookmark_app) { | 190 is_bookmark_app) { |
| 189 creation_flags |= Extension::FROM_BOOKMARK; | 191 creation_flags |= Extension::FROM_BOOKMARK; |
| 190 } | 192 } |
| 191 bool is_from_webstore; | 193 bool is_from_webstore; |
| 192 if (extension->GetBoolean(kIsFromWebstore, &is_from_webstore) && | 194 if (extension->GetBoolean(kIsFromWebstore, &is_from_webstore) && |
| 193 is_from_webstore) { | 195 is_from_webstore) { |
| 194 creation_flags |= Extension::FROM_WEBSTORE; | 196 creation_flags |= Extension::FROM_WEBSTORE; |
| 195 } | 197 } |
| 196 | 198 |
| 197 if (has_external_crx) { | 199 if (has_external_crx) { |
| 198 if (crx_location_ == Extension::INVALID) { | 200 if (crx_location_ == Manifest::INVALID_LOCATION) { |
| 199 LOG(WARNING) << "This provider does not support installing external " | 201 LOG(WARNING) << "This provider does not support installing external " |
| 200 << "extensions from crx files."; | 202 << "extensions from crx files."; |
| 201 continue; | 203 continue; |
| 202 } | 204 } |
| 203 if (external_crx.find(FilePath::kParentDirectory) != | 205 if (external_crx.find(FilePath::kParentDirectory) != |
| 204 base::StringPiece::npos) { | 206 base::StringPiece::npos) { |
| 205 LOG(WARNING) << "Path traversal not allowed in path: " | 207 LOG(WARNING) << "Path traversal not allowed in path: " |
| 206 << external_crx.c_str(); | 208 << external_crx.c_str(); |
| 207 continue; | 209 continue; |
| 208 } | 210 } |
| (...skipping 16 matching lines...) Expand all Loading... |
| 225 LOG(WARNING) << "Malformed extension dictionary for extension: " | 227 LOG(WARNING) << "Malformed extension dictionary for extension: " |
| 226 << extension_id.c_str() << ". Invalid version string \"" | 228 << extension_id.c_str() << ". Invalid version string \"" |
| 227 << external_version << "\"."; | 229 << external_version << "\"."; |
| 228 continue; | 230 continue; |
| 229 } | 231 } |
| 230 service_->OnExternalExtensionFileFound(extension_id, &version, path, | 232 service_->OnExternalExtensionFileFound(extension_id, &version, path, |
| 231 crx_location_, creation_flags, | 233 crx_location_, creation_flags, |
| 232 auto_acknowledge_); | 234 auto_acknowledge_); |
| 233 } else { // if (has_external_update_url) | 235 } else { // if (has_external_update_url) |
| 234 CHECK(has_external_update_url); // Checking of keys above ensures this. | 236 CHECK(has_external_update_url); // Checking of keys above ensures this. |
| 235 if (download_location_ == Extension::INVALID) { | 237 if (download_location_ == Manifest::INVALID_LOCATION) { |
| 236 LOG(WARNING) << "This provider does not support installing external " | 238 LOG(WARNING) << "This provider does not support installing external " |
| 237 << "extensions from update URLs."; | 239 << "extensions from update URLs."; |
| 238 continue; | 240 continue; |
| 239 } | 241 } |
| 240 GURL update_url(external_update_url); | 242 GURL update_url(external_update_url); |
| 241 if (!update_url.is_valid()) { | 243 if (!update_url.is_valid()) { |
| 242 LOG(WARNING) << "Malformed extension dictionary for extension: " | 244 LOG(WARNING) << "Malformed extension dictionary for extension: " |
| 243 << extension_id.c_str() << ". Key " << kExternalUpdateUrl | 245 << extension_id.c_str() << ". Key " << kExternalUpdateUrl |
| 244 << " has value \"" << external_update_url | 246 << " has value \"" << external_update_url |
| 245 << "\", which is not a valid URL."; | 247 << "\", which is not a valid URL."; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 270 | 272 |
| 271 bool ExternalProviderImpl::HasExtension( | 273 bool ExternalProviderImpl::HasExtension( |
| 272 const std::string& id) const { | 274 const std::string& id) const { |
| 273 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 275 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 274 CHECK(prefs_.get()); | 276 CHECK(prefs_.get()); |
| 275 CHECK(ready_); | 277 CHECK(ready_); |
| 276 return prefs_->HasKey(id); | 278 return prefs_->HasKey(id); |
| 277 } | 279 } |
| 278 | 280 |
| 279 bool ExternalProviderImpl::GetExtensionDetails( | 281 bool ExternalProviderImpl::GetExtensionDetails( |
| 280 const std::string& id, Extension::Location* location, | 282 const std::string& id, Manifest::Location* location, |
| 281 scoped_ptr<Version>* version) const { | 283 scoped_ptr<Version>* version) const { |
| 282 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 284 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 283 CHECK(prefs_.get()); | 285 CHECK(prefs_.get()); |
| 284 CHECK(ready_); | 286 CHECK(ready_); |
| 285 DictionaryValue* extension = NULL; | 287 DictionaryValue* extension = NULL; |
| 286 if (!prefs_->GetDictionary(id, &extension)) | 288 if (!prefs_->GetDictionary(id, &extension)) |
| 287 return false; | 289 return false; |
| 288 | 290 |
| 289 Extension::Location loc = Extension::INVALID; | 291 Manifest::Location loc = Manifest::INVALID_LOCATION; |
| 290 if (extension->HasKey(kExternalUpdateUrl)) { | 292 if (extension->HasKey(kExternalUpdateUrl)) { |
| 291 loc = download_location_; | 293 loc = download_location_; |
| 292 | 294 |
| 293 } else if (extension->HasKey(kExternalCrx)) { | 295 } else if (extension->HasKey(kExternalCrx)) { |
| 294 loc = crx_location_; | 296 loc = crx_location_; |
| 295 | 297 |
| 296 std::string external_version; | 298 std::string external_version; |
| 297 if (!extension->GetString(kExternalVersion, &external_version)) | 299 if (!extension->GetString(kExternalVersion, &external_version)) |
| 298 return false; | 300 return false; |
| 299 | 301 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 315 void ExternalProviderImpl::CreateExternalProviders( | 317 void ExternalProviderImpl::CreateExternalProviders( |
| 316 VisitorInterface* service, | 318 VisitorInterface* service, |
| 317 Profile* profile, | 319 Profile* profile, |
| 318 ProviderCollection* provider_list) { | 320 ProviderCollection* provider_list) { |
| 319 // Policies are mandatory so they can't be skipped with command line flag. | 321 // Policies are mandatory so they can't be skipped with command line flag. |
| 320 provider_list->push_back( | 322 provider_list->push_back( |
| 321 linked_ptr<ExternalProviderInterface>( | 323 linked_ptr<ExternalProviderInterface>( |
| 322 new ExternalProviderImpl( | 324 new ExternalProviderImpl( |
| 323 service, | 325 service, |
| 324 new ExternalPolicyLoader(profile), | 326 new ExternalPolicyLoader(profile), |
| 325 Extension::INVALID, | 327 Manifest::INVALID_LOCATION, |
| 326 Extension::EXTERNAL_POLICY_DOWNLOAD, | 328 Manifest::EXTERNAL_POLICY_DOWNLOAD, |
| 327 Extension::NO_FLAGS))); | 329 Extension::NO_FLAGS))); |
| 328 | 330 |
| 329 // In tests don't install extensions from default external sources. | 331 // In tests don't install extensions from default external sources. |
| 330 // It would only slowdown tests and make them flaky. | 332 // It would only slowdown tests and make them flaky. |
| 331 if (CommandLine::ForCurrentProcess()->HasSwitch( | 333 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 332 switches::kDisableDefaultApps)) | 334 switches::kDisableDefaultApps)) |
| 333 return; | 335 return; |
| 334 | 336 |
| 335 // On Mac OS, items in /Library/... should be written by the superuser. | 337 // On Mac OS, items in /Library/... should be written by the superuser. |
| 336 // Check that all components of the path are writable by root only. | 338 // Check that all components of the path are writable by root only. |
| (...skipping 17 matching lines...) Expand all Loading... |
| 354 Extension::WAS_INSTALLED_BY_DEFAULT; | 356 Extension::WAS_INSTALLED_BY_DEFAULT; |
| 355 #endif | 357 #endif |
| 356 | 358 |
| 357 if (!is_chromeos_demo_session) { | 359 if (!is_chromeos_demo_session) { |
| 358 provider_list->push_back( | 360 provider_list->push_back( |
| 359 linked_ptr<ExternalProviderInterface>( | 361 linked_ptr<ExternalProviderInterface>( |
| 360 new ExternalProviderImpl( | 362 new ExternalProviderImpl( |
| 361 service, | 363 service, |
| 362 new ExternalPrefLoader(chrome::DIR_EXTERNAL_EXTENSIONS, | 364 new ExternalPrefLoader(chrome::DIR_EXTERNAL_EXTENSIONS, |
| 363 check_admin_permissions_on_mac), | 365 check_admin_permissions_on_mac), |
| 364 Extension::EXTERNAL_PREF, | 366 Manifest::EXTERNAL_PREF, |
| 365 Extension::EXTERNAL_PREF_DOWNLOAD, | 367 Manifest::EXTERNAL_PREF_DOWNLOAD, |
| 366 bundled_extension_creation_flags))); | 368 bundled_extension_creation_flags))); |
| 367 } | 369 } |
| 368 | 370 |
| 369 #if defined(OS_CHROMEOS) || defined (OS_MACOSX) | 371 #if defined(OS_CHROMEOS) || defined (OS_MACOSX) |
| 370 // Define a per-user source of external extensions. | 372 // Define a per-user source of external extensions. |
| 371 // On Chrome OS, this serves as a source for OEM customization. | 373 // On Chrome OS, this serves as a source for OEM customization. |
| 372 provider_list->push_back( | 374 provider_list->push_back( |
| 373 linked_ptr<ExternalProviderInterface>( | 375 linked_ptr<ExternalProviderInterface>( |
| 374 new ExternalProviderImpl( | 376 new ExternalProviderImpl( |
| 375 service, | 377 service, |
| 376 new ExternalPrefLoader(chrome::DIR_USER_EXTERNAL_EXTENSIONS, | 378 new ExternalPrefLoader(chrome::DIR_USER_EXTERNAL_EXTENSIONS, |
| 377 ExternalPrefLoader::NONE), | 379 ExternalPrefLoader::NONE), |
| 378 Extension::EXTERNAL_PREF, | 380 Manifest::EXTERNAL_PREF, |
| 379 Extension::EXTERNAL_PREF_DOWNLOAD, | 381 Manifest::EXTERNAL_PREF_DOWNLOAD, |
| 380 Extension::NO_FLAGS))); | 382 Extension::NO_FLAGS))); |
| 381 #endif | 383 #endif |
| 382 #if defined(OS_WIN) | 384 #if defined(OS_WIN) |
| 383 provider_list->push_back( | 385 provider_list->push_back( |
| 384 linked_ptr<ExternalProviderInterface>( | 386 linked_ptr<ExternalProviderInterface>( |
| 385 new ExternalProviderImpl( | 387 new ExternalProviderImpl( |
| 386 service, | 388 service, |
| 387 new ExternalRegistryLoader, | 389 new ExternalRegistryLoader, |
| 388 Extension::EXTERNAL_REGISTRY, | 390 Manifest::EXTERNAL_REGISTRY, |
| 389 Extension::INVALID, | 391 Manifest::INVALID_LOCATION, |
| 390 Extension::NO_FLAGS))); | 392 Extension::NO_FLAGS))); |
| 391 #endif | 393 #endif |
| 392 | 394 |
| 393 #if defined(OS_LINUX) | 395 #if defined(OS_LINUX) |
| 394 provider_list->push_back( | 396 provider_list->push_back( |
| 395 linked_ptr<ExternalProviderInterface>( | 397 linked_ptr<ExternalProviderInterface>( |
| 396 new ExternalProviderImpl( | 398 new ExternalProviderImpl( |
| 397 service, | 399 service, |
| 398 new ExternalPrefLoader(chrome::DIR_STANDALONE_EXTERNAL_EXTENSIONS, | 400 new ExternalPrefLoader(chrome::DIR_STANDALONE_EXTERNAL_EXTENSIONS, |
| 399 ExternalPrefLoader::NONE), | 401 ExternalPrefLoader::NONE), |
| 400 Extension::EXTERNAL_PREF, | 402 Manifest::EXTERNAL_PREF, |
| 401 Extension::EXTERNAL_PREF_DOWNLOAD, | 403 Manifest::EXTERNAL_PREF_DOWNLOAD, |
| 402 bundled_extension_creation_flags))); | 404 bundled_extension_creation_flags))); |
| 403 #endif | 405 #endif |
| 404 | 406 |
| 405 #if !defined(OS_CHROMEOS) | 407 #if !defined(OS_CHROMEOS) |
| 406 // The default apps are installed as INTERNAL but use the external | 408 // The default apps are installed as INTERNAL but use the external |
| 407 // extension installer codeflow. | 409 // extension installer codeflow. |
| 408 provider_list->push_back( | 410 provider_list->push_back( |
| 409 linked_ptr<ExternalProviderInterface>( | 411 linked_ptr<ExternalProviderInterface>( |
| 410 new default_apps::Provider( | 412 new default_apps::Provider( |
| 411 profile, | 413 profile, |
| 412 service, | 414 service, |
| 413 new ExternalPrefLoader(chrome::DIR_DEFAULT_APPS, | 415 new ExternalPrefLoader(chrome::DIR_DEFAULT_APPS, |
| 414 ExternalPrefLoader::NONE), | 416 ExternalPrefLoader::NONE), |
| 415 Extension::INTERNAL, | 417 Manifest::INTERNAL, |
| 416 Extension::INVALID, | 418 Manifest::INVALID_LOCATION, |
| 417 Extension::FROM_WEBSTORE | | 419 Extension::FROM_WEBSTORE | |
| 418 Extension::WAS_INSTALLED_BY_DEFAULT))); | 420 Extension::WAS_INSTALLED_BY_DEFAULT))); |
| 419 #endif | 421 #endif |
| 420 | 422 |
| 421 #if defined(OS_CHROMEOS) | 423 #if defined(OS_CHROMEOS) |
| 422 policy::BrowserPolicyConnector* connector = | 424 policy::BrowserPolicyConnector* connector = |
| 423 g_browser_process->browser_policy_connector(); | 425 g_browser_process->browser_policy_connector(); |
| 424 if (is_chromeos_demo_session && connector->GetAppPackUpdater()) { | 426 if (is_chromeos_demo_session && connector->GetAppPackUpdater()) { |
| 425 provider_list->push_back( | 427 provider_list->push_back( |
| 426 linked_ptr<ExternalProviderInterface>( | 428 linked_ptr<ExternalProviderInterface>( |
| 427 new ExternalProviderImpl( | 429 new ExternalProviderImpl( |
| 428 service, | 430 service, |
| 429 connector->GetAppPackUpdater()->CreateExternalLoader(), | 431 connector->GetAppPackUpdater()->CreateExternalLoader(), |
| 430 Extension::EXTERNAL_PREF, | 432 Manifest::EXTERNAL_PREF, |
| 431 Extension::INVALID, | 433 Manifest::INVALID_LOCATION, |
| 432 Extension::NO_FLAGS))); | 434 Extension::NO_FLAGS))); |
| 433 } | 435 } |
| 434 #endif | 436 #endif |
| 435 } | 437 } |
| 436 | 438 |
| 437 } // namespace extensions | 439 } // namespace extensions |
| OLD | NEW |