Chromium Code Reviews| 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_extension_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_extension_provider_interface.h" | 18 #include "chrome/browser/extensions/external_provider_interface.h" |
| 19 #include "chrome/browser/extensions/external_policy_extension_loader.h" | 19 #include "chrome/browser/extensions/external_policy_loader.h" |
| 20 #include "chrome/browser/extensions/external_pref_extension_loader.h" | 20 #include "chrome/browser/extensions/external_pref_loader.h" |
|
Joao da Silva
2012/07/13 13:33:42
Nit: order
Devlin
2012/07/13 16:31:17
Done.
| |
| 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/pref_names.h" | 24 #include "chrome/common/pref_names.h" |
| 25 #include "content/public/browser/browser_thread.h" | 25 #include "content/public/browser/browser_thread.h" |
| 26 #include "ui/base/l10n/l10n_util.h" | 26 #include "ui/base/l10n/l10n_util.h" |
| 27 | 27 |
| 28 #if defined(OS_CHROMEOS) | 28 #if defined(OS_CHROMEOS) |
| 29 #include "chrome/browser/chromeos/login/user_manager.h" | 29 #include "chrome/browser/chromeos/login/user_manager.h" |
| 30 #include "chrome/browser/policy/app_pack_updater.h" | 30 #include "chrome/browser/policy/app_pack_updater.h" |
| 31 #include "chrome/browser/policy/browser_policy_connector.h" | 31 #include "chrome/browser/policy/browser_policy_connector.h" |
| 32 #endif | 32 #endif |
| 33 | 33 |
| 34 #if !defined(OS_CHROMEOS) | 34 #if !defined(OS_CHROMEOS) |
| 35 #include "chrome/browser/extensions/default_apps.h" | 35 #include "chrome/browser/extensions/default_apps.h" |
| 36 #endif | 36 #endif |
| 37 | 37 |
| 38 #if defined(OS_WIN) | 38 #if defined(OS_WIN) |
| 39 #include "chrome/browser/extensions/external_registry_extension_loader_win.h" | 39 #include "chrome/browser/extensions/external_registry_loader_win.h" |
| 40 #endif | 40 #endif |
| 41 | 41 |
| 42 using content::BrowserThread; | 42 using content::BrowserThread; |
| 43 using extensions::Extension; | 43 |
| 44 namespace extensions { | |
| 44 | 45 |
| 45 // Constants for keeping track of extension preferences in a dictionary. | 46 // Constants for keeping track of extension preferences in a dictionary. |
| 46 const char ExternalExtensionProviderImpl::kExternalCrx[] = "external_crx"; | 47 const char ExternalProviderImpl::kExternalCrx[] = "external_crx"; |
| 47 const char ExternalExtensionProviderImpl::kExternalVersion[] = | 48 const char ExternalProviderImpl::kExternalVersion[] = |
| 48 "external_version"; | 49 "external_version"; |
| 49 const char ExternalExtensionProviderImpl::kExternalUpdateUrl[] = | 50 const char ExternalProviderImpl::kExternalUpdateUrl[] = |
| 50 "external_update_url"; | 51 "external_update_url"; |
| 51 const char ExternalExtensionProviderImpl::kSupportedLocales[] = | 52 const char ExternalProviderImpl::kSupportedLocales[] = |
| 52 "supported_locales"; | 53 "supported_locales"; |
| 53 const char ExternalExtensionProviderImpl::kIsBookmarkApp[] = | 54 const char ExternalProviderImpl::kIsBookmarkApp[] = |
| 54 "is_bookmark_app"; | 55 "is_bookmark_app"; |
| 55 | 56 |
| 56 ExternalExtensionProviderImpl::ExternalExtensionProviderImpl( | 57 ExternalProviderImpl::ExternalProviderImpl( |
| 57 VisitorInterface* service, | 58 VisitorInterface* service, |
| 58 ExternalExtensionLoader* loader, | 59 ExternalLoader* loader, |
| 59 Extension::Location crx_location, | 60 Extension::Location crx_location, |
| 60 Extension::Location download_location, | 61 Extension::Location download_location, |
| 61 int creation_flags) | 62 int creation_flags) |
| 62 : crx_location_(crx_location), | 63 : crx_location_(crx_location), |
| 63 download_location_(download_location), | 64 download_location_(download_location), |
| 64 service_(service), | 65 service_(service), |
| 65 prefs_(NULL), | 66 prefs_(NULL), |
| 66 ready_(false), | 67 ready_(false), |
| 67 loader_(loader), | 68 loader_(loader), |
| 68 creation_flags_(creation_flags), | 69 creation_flags_(creation_flags), |
| 69 auto_acknowledge_(false) { | 70 auto_acknowledge_(false) { |
| 70 loader_->Init(this); | 71 loader_->Init(this); |
| 71 } | 72 } |
| 72 | 73 |
| 73 ExternalExtensionProviderImpl::~ExternalExtensionProviderImpl() { | 74 ExternalProviderImpl::~ExternalProviderImpl() { |
| 74 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 75 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 75 loader_->OwnerShutdown(); | 76 loader_->OwnerShutdown(); |
| 76 } | 77 } |
| 77 | 78 |
| 78 void ExternalExtensionProviderImpl::VisitRegisteredExtension() { | 79 void ExternalProviderImpl::VisitRegisteredExtension() { |
| 79 // The loader will call back to SetPrefs. | 80 // The loader will call back to SetPrefs. |
| 80 loader_->StartLoading(); | 81 loader_->StartLoading(); |
| 81 } | 82 } |
| 82 | 83 |
| 83 void ExternalExtensionProviderImpl::SetPrefs(DictionaryValue* prefs) { | 84 void ExternalProviderImpl::SetPrefs(DictionaryValue* prefs) { |
| 84 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 85 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 85 | 86 |
| 86 // Check if the service is still alive. It is possible that it went | 87 // Check if the service is still alive. It is possible that it went |
| 87 // away while |loader_| was working on the FILE thread. | 88 // away while |loader_| was working on the FILE thread. |
| 88 if (!service_) return; | 89 if (!service_) return; |
| 89 | 90 |
| 90 prefs_.reset(prefs); | 91 prefs_.reset(prefs); |
| 91 ready_ = true; // Queries for extensions are allowed from this point. | 92 ready_ = true; // Queries for extensions are allowed from this point. |
| 92 | 93 |
| 93 // Set of unsupported extensions that need to be deleted from prefs_. | 94 // Set of unsupported extensions that need to be deleted from prefs_. |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 251 for (std::set<std::string>::iterator it = unsupported_extensions.begin(); | 252 for (std::set<std::string>::iterator it = unsupported_extensions.begin(); |
| 252 it != unsupported_extensions.end(); ++it) { | 253 it != unsupported_extensions.end(); ++it) { |
| 253 // Remove extension for the list of know external extensions. The extension | 254 // Remove extension for the list of know external extensions. The extension |
| 254 // will be uninstalled later because provider doesn't provide it anymore. | 255 // will be uninstalled later because provider doesn't provide it anymore. |
| 255 prefs_->Remove(*it, NULL); | 256 prefs_->Remove(*it, NULL); |
| 256 } | 257 } |
| 257 | 258 |
| 258 service_->OnExternalProviderReady(this); | 259 service_->OnExternalProviderReady(this); |
| 259 } | 260 } |
| 260 | 261 |
| 261 void ExternalExtensionProviderImpl::ServiceShutdown() { | 262 void ExternalProviderImpl::ServiceShutdown() { |
| 262 service_ = NULL; | 263 service_ = NULL; |
| 263 } | 264 } |
| 264 | 265 |
| 265 bool ExternalExtensionProviderImpl::IsReady() const { | 266 bool ExternalProviderImpl::IsReady() const { |
| 266 return ready_; | 267 return ready_; |
| 267 } | 268 } |
| 268 | 269 |
| 269 bool ExternalExtensionProviderImpl::HasExtension( | 270 bool ExternalProviderImpl::HasExtension( |
| 270 const std::string& id) const { | 271 const std::string& id) const { |
| 271 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 272 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 272 CHECK(prefs_.get()); | 273 CHECK(prefs_.get()); |
| 273 CHECK(ready_); | 274 CHECK(ready_); |
| 274 return prefs_->HasKey(id); | 275 return prefs_->HasKey(id); |
| 275 } | 276 } |
| 276 | 277 |
| 277 bool ExternalExtensionProviderImpl::GetExtensionDetails( | 278 bool ExternalProviderImpl::GetExtensionDetails( |
| 278 const std::string& id, Extension::Location* location, | 279 const std::string& id, Extension::Location* location, |
| 279 scoped_ptr<Version>* version) const { | 280 scoped_ptr<Version>* version) const { |
| 280 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 281 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 281 CHECK(prefs_.get()); | 282 CHECK(prefs_.get()); |
| 282 CHECK(ready_); | 283 CHECK(ready_); |
| 283 DictionaryValue* extension = NULL; | 284 DictionaryValue* extension = NULL; |
| 284 if (!prefs_->GetDictionary(id, &extension)) | 285 if (!prefs_->GetDictionary(id, &extension)) |
| 285 return false; | 286 return false; |
| 286 | 287 |
| 287 Extension::Location loc = Extension::INVALID; | 288 Extension::Location loc = Extension::INVALID; |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 303 return false; | 304 return false; |
| 304 } | 305 } |
| 305 | 306 |
| 306 if (location) | 307 if (location) |
| 307 *location = loc; | 308 *location = loc; |
| 308 | 309 |
| 309 return true; | 310 return true; |
| 310 } | 311 } |
| 311 | 312 |
| 312 // static | 313 // static |
| 313 void ExternalExtensionProviderImpl::CreateExternalProviders( | 314 void ExternalProviderImpl::CreateExternalProviders( |
| 314 VisitorInterface* service, | 315 VisitorInterface* service, |
| 315 Profile* profile, | 316 Profile* profile, |
| 316 ProviderCollection* provider_list) { | 317 ProviderCollection* provider_list) { |
| 317 | 318 |
| 318 // On Mac OS, items in /Library/... should be written by the superuser. | 319 // On Mac OS, items in /Library/... should be written by the superuser. |
| 319 // Check that all components of the path are writable by root only. | 320 // Check that all components of the path are writable by root only. |
| 320 ExternalPrefExtensionLoader::Options check_admin_permissions_on_mac; | 321 ExternalPrefLoader::Options check_admin_permissions_on_mac; |
| 321 #if defined(OS_MACOSX) | 322 #if defined(OS_MACOSX) |
| 322 check_admin_permissions_on_mac = | 323 check_admin_permissions_on_mac = |
| 323 ExternalPrefExtensionLoader::ENSURE_PATH_CONTROLLED_BY_ADMIN; | 324 ExternalPrefLoader::ENSURE_PATH_CONTROLLED_BY_ADMIN; |
| 324 #else | 325 #else |
| 325 check_admin_permissions_on_mac = ExternalPrefExtensionLoader::NONE; | 326 check_admin_permissions_on_mac = ExternalPrefLoader::NONE; |
| 326 #endif | 327 #endif |
| 327 | 328 |
| 328 bool is_chromeos_demo_session = false; | 329 bool is_chromeos_demo_session = false; |
| 329 int bundled_extension_creation_flags = Extension::NO_FLAGS; | 330 int bundled_extension_creation_flags = Extension::NO_FLAGS; |
| 330 #if defined(OS_CHROMEOS) | 331 #if defined(OS_CHROMEOS) |
| 331 chromeos::UserManager* user_manager = chromeos::UserManager::Get(); | 332 chromeos::UserManager* user_manager = chromeos::UserManager::Get(); |
| 332 is_chromeos_demo_session = | 333 is_chromeos_demo_session = |
| 333 user_manager && user_manager->IsLoggedInAsDemoUser() && | 334 user_manager && user_manager->IsLoggedInAsDemoUser() && |
| 334 g_browser_process->browser_policy_connector()->GetDeviceMode() == | 335 g_browser_process->browser_policy_connector()->GetDeviceMode() == |
| 335 policy::DEVICE_MODE_KIOSK; | 336 policy::DEVICE_MODE_KIOSK; |
| 336 bundled_extension_creation_flags = Extension::FROM_WEBSTORE; | 337 bundled_extension_creation_flags = Extension::FROM_WEBSTORE; |
| 337 #endif | 338 #endif |
| 338 | 339 |
| 339 if (!is_chromeos_demo_session) { | 340 if (!is_chromeos_demo_session) { |
| 340 provider_list->push_back( | 341 provider_list->push_back( |
| 341 linked_ptr<ExternalExtensionProviderInterface>( | 342 linked_ptr<ExternalProviderInterface>( |
| 342 new ExternalExtensionProviderImpl( | 343 new ExternalProviderImpl( |
| 343 service, | 344 service, |
| 344 new ExternalPrefExtensionLoader( | 345 new ExternalPrefLoader(chrome::DIR_EXTERNAL_EXTENSIONS, |
| 345 chrome::DIR_EXTERNAL_EXTENSIONS, | 346 check_admin_permissions_on_mac), |
| 346 check_admin_permissions_on_mac), | |
| 347 Extension::EXTERNAL_PREF, | 347 Extension::EXTERNAL_PREF, |
| 348 Extension::EXTERNAL_PREF_DOWNLOAD, | 348 Extension::EXTERNAL_PREF_DOWNLOAD, |
| 349 bundled_extension_creation_flags))); | 349 bundled_extension_creation_flags))); |
| 350 } | 350 } |
| 351 | 351 |
| 352 #if defined(OS_CHROMEOS) || defined (OS_MACOSX) | 352 #if defined(OS_CHROMEOS) || defined (OS_MACOSX) |
| 353 // Define a per-user source of external extensions. | 353 // Define a per-user source of external extensions. |
| 354 // On Chrome OS, this serves as a source for OEM customization. | 354 // On Chrome OS, this serves as a source for OEM customization. |
| 355 provider_list->push_back( | 355 provider_list->push_back( |
| 356 linked_ptr<ExternalExtensionProviderInterface>( | 356 linked_ptr<ExternalProviderInterface>( |
| 357 new ExternalExtensionProviderImpl( | 357 new ExternalProviderImpl( |
| 358 service, | 358 service, |
| 359 new ExternalPrefExtensionLoader( | 359 new ExternalPrefLoader(chrome::DIR_USER_EXTERNAL_EXTENSIONS, |
| 360 chrome::DIR_USER_EXTERNAL_EXTENSIONS, | 360 ExternalPrefLoader::NONE), |
| 361 ExternalPrefExtensionLoader::NONE), | |
| 362 Extension::EXTERNAL_PREF, | 361 Extension::EXTERNAL_PREF, |
| 363 Extension::EXTERNAL_PREF_DOWNLOAD, | 362 Extension::EXTERNAL_PREF_DOWNLOAD, |
| 364 Extension::NO_FLAGS))); | 363 Extension::NO_FLAGS))); |
| 365 #endif | 364 #endif |
| 366 #if defined(OS_WIN) | 365 #if defined(OS_WIN) |
| 367 provider_list->push_back( | 366 provider_list->push_back( |
| 368 linked_ptr<ExternalExtensionProviderInterface>( | 367 linked_ptr<ExternalProviderInterface>( |
| 369 new ExternalExtensionProviderImpl( | 368 new ExternalProviderImpl( |
| 370 service, | 369 service, |
| 371 new ExternalRegistryExtensionLoader, | 370 new ExternalRegistryLoader, |
| 372 Extension::EXTERNAL_REGISTRY, | 371 Extension::EXTERNAL_REGISTRY, |
| 373 Extension::INVALID, | 372 Extension::INVALID, |
| 374 Extension::NO_FLAGS))); | 373 Extension::NO_FLAGS))); |
| 375 #endif | 374 #endif |
| 376 | 375 |
| 377 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) | 376 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) |
| 378 provider_list->push_back( | 377 provider_list->push_back( |
| 379 linked_ptr<ExternalExtensionProviderInterface>( | 378 linked_ptr<ExternalProviderInterface>( |
| 380 new ExternalExtensionProviderImpl( | 379 new ExternalProviderImpl( |
| 381 service, | 380 service, |
| 382 new ExternalPrefExtensionLoader( | 381 new ExternalPrefLoader(chrome::DIR_STANDALONE_EXTERNAL_EXTENSIONS, |
| 383 chrome::DIR_STANDALONE_EXTERNAL_EXTENSIONS, | 382 ExternalPrefLoader::NONE), |
| 384 ExternalPrefExtensionLoader::NONE), | |
| 385 Extension::EXTERNAL_PREF, | 383 Extension::EXTERNAL_PREF, |
| 386 Extension::EXTERNAL_PREF_DOWNLOAD, | 384 Extension::EXTERNAL_PREF_DOWNLOAD, |
| 387 Extension::NO_FLAGS))); | 385 Extension::NO_FLAGS))); |
| 388 #endif | 386 #endif |
| 389 | 387 |
| 390 provider_list->push_back( | 388 provider_list->push_back( |
| 391 linked_ptr<ExternalExtensionProviderInterface>( | 389 linked_ptr<ExternalProviderInterface>( |
| 392 new ExternalExtensionProviderImpl( | 390 new ExternalProviderImpl( |
| 393 service, | 391 service, |
| 394 new ExternalPolicyExtensionLoader(profile), | 392 new ExternalPolicyLoader(profile), |
| 395 Extension::INVALID, | 393 Extension::INVALID, |
| 396 Extension::EXTERNAL_POLICY_DOWNLOAD, | 394 Extension::EXTERNAL_POLICY_DOWNLOAD, |
| 397 Extension::NO_FLAGS))); | 395 Extension::NO_FLAGS))); |
| 398 | 396 |
| 399 #if !defined(OS_CHROMEOS) | 397 #if !defined(OS_CHROMEOS) |
| 400 provider_list->push_back( | 398 provider_list->push_back( |
| 401 linked_ptr<ExternalExtensionProviderInterface>( | 399 linked_ptr<ExternalProviderInterface>( |
| 402 new default_apps::Provider( | 400 new default_apps::Provider( |
| 403 profile, | 401 profile, |
| 404 service, | 402 service, |
| 405 new ExternalPrefExtensionLoader( | 403 new ExternalPrefLoader(chrome::DIR_DEFAULT_APPS, |
| 406 chrome::DIR_DEFAULT_APPS, | 404 ExternalPrefLoader::NONE), |
| 407 ExternalPrefExtensionLoader::NONE), | |
| 408 Extension::EXTERNAL_PREF, | 405 Extension::EXTERNAL_PREF, |
| 409 Extension::INVALID, | 406 Extension::INVALID, |
| 410 Extension::FROM_WEBSTORE))); | 407 Extension::FROM_WEBSTORE))); |
| 411 #endif | 408 #endif |
| 412 | 409 |
| 413 #if defined(OS_CHROMEOS) | 410 #if defined(OS_CHROMEOS) |
| 414 policy::BrowserPolicyConnector* connector = | 411 policy::BrowserPolicyConnector* connector = |
| 415 g_browser_process->browser_policy_connector(); | 412 g_browser_process->browser_policy_connector(); |
| 416 if (is_chromeos_demo_session && connector->GetAppPackUpdater()) { | 413 if (is_chromeos_demo_session && connector->GetAppPackUpdater()) { |
| 417 provider_list->push_back( | 414 provider_list->push_back( |
| 418 linked_ptr<ExternalExtensionProviderInterface>( | 415 linked_ptr<ExternalProviderInterface>( |
| 419 new ExternalExtensionProviderImpl( | 416 new ExternalProviderImpl( |
| 420 service, | 417 service, |
| 421 connector->GetAppPackUpdater()->CreateExternalExtensionLoader(), | 418 connector->GetAppPackUpdater()->CreateExternalLoader(), |
| 422 Extension::EXTERNAL_PREF, | 419 Extension::EXTERNAL_PREF, |
| 423 Extension::INVALID, | 420 Extension::INVALID, |
| 424 Extension::NO_FLAGS))); | 421 Extension::NO_FLAGS))); |
| 425 } | 422 } |
| 426 #endif | 423 #endif |
| 427 } | 424 } |
| 425 | |
| 426 } // namespace extensions | |
| OLD | NEW |