| 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_policy_loader.h" |
| 19 #include "chrome/browser/extensions/external_policy_extension_loader.h" | 19 #include "chrome/browser/extensions/external_pref_loader.h" |
| 20 #include "chrome/browser/extensions/external_pref_extension_loader.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/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 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 250 for (std::set<std::string>::iterator it = unsupported_extensions.begin(); | 251 for (std::set<std::string>::iterator it = unsupported_extensions.begin(); |
| 251 it != unsupported_extensions.end(); ++it) { | 252 it != unsupported_extensions.end(); ++it) { |
| 252 // Remove extension for the list of know external extensions. The extension | 253 // Remove extension for the list of know external extensions. The extension |
| 253 // will be uninstalled later because provider doesn't provide it anymore. | 254 // will be uninstalled later because provider doesn't provide it anymore. |
| 254 prefs_->Remove(*it, NULL); | 255 prefs_->Remove(*it, NULL); |
| 255 } | 256 } |
| 256 | 257 |
| 257 service_->OnExternalProviderReady(this); | 258 service_->OnExternalProviderReady(this); |
| 258 } | 259 } |
| 259 | 260 |
| 260 void ExternalExtensionProviderImpl::ServiceShutdown() { | 261 void ExternalProviderImpl::ServiceShutdown() { |
| 261 service_ = NULL; | 262 service_ = NULL; |
| 262 } | 263 } |
| 263 | 264 |
| 264 bool ExternalExtensionProviderImpl::IsReady() const { | 265 bool ExternalProviderImpl::IsReady() const { |
| 265 return ready_; | 266 return ready_; |
| 266 } | 267 } |
| 267 | 268 |
| 268 bool ExternalExtensionProviderImpl::HasExtension( | 269 bool ExternalProviderImpl::HasExtension( |
| 269 const std::string& id) const { | 270 const std::string& id) const { |
| 270 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 271 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 271 CHECK(prefs_.get()); | 272 CHECK(prefs_.get()); |
| 272 CHECK(ready_); | 273 CHECK(ready_); |
| 273 return prefs_->HasKey(id); | 274 return prefs_->HasKey(id); |
| 274 } | 275 } |
| 275 | 276 |
| 276 bool ExternalExtensionProviderImpl::GetExtensionDetails( | 277 bool ExternalProviderImpl::GetExtensionDetails( |
| 277 const std::string& id, Extension::Location* location, | 278 const std::string& id, Extension::Location* location, |
| 278 scoped_ptr<Version>* version) const { | 279 scoped_ptr<Version>* version) const { |
| 279 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 280 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 280 CHECK(prefs_.get()); | 281 CHECK(prefs_.get()); |
| 281 CHECK(ready_); | 282 CHECK(ready_); |
| 282 DictionaryValue* extension = NULL; | 283 DictionaryValue* extension = NULL; |
| 283 if (!prefs_->GetDictionary(id, &extension)) | 284 if (!prefs_->GetDictionary(id, &extension)) |
| 284 return false; | 285 return false; |
| 285 | 286 |
| 286 Extension::Location loc = Extension::INVALID; | 287 Extension::Location loc = Extension::INVALID; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 302 return false; | 303 return false; |
| 303 } | 304 } |
| 304 | 305 |
| 305 if (location) | 306 if (location) |
| 306 *location = loc; | 307 *location = loc; |
| 307 | 308 |
| 308 return true; | 309 return true; |
| 309 } | 310 } |
| 310 | 311 |
| 311 // static | 312 // static |
| 312 void ExternalExtensionProviderImpl::CreateExternalProviders( | 313 void ExternalProviderImpl::CreateExternalProviders( |
| 313 VisitorInterface* service, | 314 VisitorInterface* service, |
| 314 Profile* profile, | 315 Profile* profile, |
| 315 ProviderCollection* provider_list) { | 316 ProviderCollection* provider_list) { |
| 316 | 317 |
| 317 // On Mac OS, items in /Library/... should be written by the superuser. | 318 // On Mac OS, items in /Library/... should be written by the superuser. |
| 318 // Check that all components of the path are writable by root only. | 319 // Check that all components of the path are writable by root only. |
| 319 ExternalPrefExtensionLoader::Options check_admin_permissions_on_mac; | 320 ExternalPrefLoader::Options check_admin_permissions_on_mac; |
| 320 #if defined(OS_MACOSX) | 321 #if defined(OS_MACOSX) |
| 321 check_admin_permissions_on_mac = | 322 check_admin_permissions_on_mac = |
| 322 ExternalPrefExtensionLoader::ENSURE_PATH_CONTROLLED_BY_ADMIN; | 323 ExternalPrefLoader::ENSURE_PATH_CONTROLLED_BY_ADMIN; |
| 323 #else | 324 #else |
| 324 check_admin_permissions_on_mac = ExternalPrefExtensionLoader::NONE; | 325 check_admin_permissions_on_mac = ExternalPrefLoader::NONE; |
| 325 #endif | 326 #endif |
| 326 | 327 |
| 327 bool is_chromeos_demo_session = false; | 328 bool is_chromeos_demo_session = false; |
| 328 int bundled_extension_creation_flags = Extension::NO_FLAGS; | 329 int bundled_extension_creation_flags = Extension::NO_FLAGS; |
| 329 #if defined(OS_CHROMEOS) | 330 #if defined(OS_CHROMEOS) |
| 330 chromeos::UserManager* user_manager = chromeos::UserManager::Get(); | 331 chromeos::UserManager* user_manager = chromeos::UserManager::Get(); |
| 331 is_chromeos_demo_session = | 332 is_chromeos_demo_session = |
| 332 user_manager && user_manager->IsLoggedInAsDemoUser() && | 333 user_manager && user_manager->IsLoggedInAsDemoUser() && |
| 333 g_browser_process->browser_policy_connector()->GetDeviceMode() == | 334 g_browser_process->browser_policy_connector()->GetDeviceMode() == |
| 334 policy::DEVICE_MODE_KIOSK; | 335 policy::DEVICE_MODE_KIOSK; |
| 335 bundled_extension_creation_flags = Extension::FROM_WEBSTORE; | 336 bundled_extension_creation_flags = Extension::FROM_WEBSTORE; |
| 336 #endif | 337 #endif |
| 337 | 338 |
| 338 if (!is_chromeos_demo_session) { | 339 if (!is_chromeos_demo_session) { |
| 339 provider_list->push_back( | 340 provider_list->push_back( |
| 340 linked_ptr<ExternalExtensionProviderInterface>( | 341 linked_ptr<ExternalProviderInterface>( |
| 341 new ExternalExtensionProviderImpl( | 342 new ExternalProviderImpl( |
| 342 service, | 343 service, |
| 343 new ExternalPrefExtensionLoader( | 344 new ExternalPrefLoader(chrome::DIR_EXTERNAL_EXTENSIONS, |
| 344 chrome::DIR_EXTERNAL_EXTENSIONS, | 345 check_admin_permissions_on_mac), |
| 345 check_admin_permissions_on_mac), | |
| 346 Extension::EXTERNAL_PREF, | 346 Extension::EXTERNAL_PREF, |
| 347 Extension::EXTERNAL_PREF_DOWNLOAD, | 347 Extension::EXTERNAL_PREF_DOWNLOAD, |
| 348 bundled_extension_creation_flags))); | 348 bundled_extension_creation_flags))); |
| 349 } | 349 } |
| 350 | 350 |
| 351 #if defined(OS_CHROMEOS) || defined (OS_MACOSX) | 351 #if defined(OS_CHROMEOS) || defined (OS_MACOSX) |
| 352 // Define a per-user source of external extensions. | 352 // Define a per-user source of external extensions. |
| 353 // On Chrome OS, this serves as a source for OEM customization. | 353 // On Chrome OS, this serves as a source for OEM customization. |
| 354 provider_list->push_back( | 354 provider_list->push_back( |
| 355 linked_ptr<ExternalExtensionProviderInterface>( | 355 linked_ptr<ExternalProviderInterface>( |
| 356 new ExternalExtensionProviderImpl( | 356 new ExternalProviderImpl( |
| 357 service, | 357 service, |
| 358 new ExternalPrefExtensionLoader( | 358 new ExternalPrefLoader(chrome::DIR_USER_EXTERNAL_EXTENSIONS, |
| 359 chrome::DIR_USER_EXTERNAL_EXTENSIONS, | 359 ExternalPrefLoader::NONE), |
| 360 ExternalPrefExtensionLoader::NONE), | |
| 361 Extension::EXTERNAL_PREF, | 360 Extension::EXTERNAL_PREF, |
| 362 Extension::EXTERNAL_PREF_DOWNLOAD, | 361 Extension::EXTERNAL_PREF_DOWNLOAD, |
| 363 Extension::NO_FLAGS))); | 362 Extension::NO_FLAGS))); |
| 364 #endif | 363 #endif |
| 365 #if defined(OS_WIN) | 364 #if defined(OS_WIN) |
| 366 provider_list->push_back( | 365 provider_list->push_back( |
| 367 linked_ptr<ExternalExtensionProviderInterface>( | 366 linked_ptr<ExternalProviderInterface>( |
| 368 new ExternalExtensionProviderImpl( | 367 new ExternalProviderImpl( |
| 369 service, | 368 service, |
| 370 new ExternalRegistryExtensionLoader, | 369 new ExternalRegistryLoader, |
| 371 Extension::EXTERNAL_REGISTRY, | 370 Extension::EXTERNAL_REGISTRY, |
| 372 Extension::INVALID, | 371 Extension::INVALID, |
| 373 Extension::NO_FLAGS))); | 372 Extension::NO_FLAGS))); |
| 374 #endif | 373 #endif |
| 375 | 374 |
| 376 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) | 375 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) |
| 377 provider_list->push_back( | 376 provider_list->push_back( |
| 378 linked_ptr<ExternalExtensionProviderInterface>( | 377 linked_ptr<ExternalProviderInterface>( |
| 379 new ExternalExtensionProviderImpl( | 378 new ExternalProviderImpl( |
| 380 service, | 379 service, |
| 381 new ExternalPrefExtensionLoader( | 380 new ExternalPrefLoader(chrome::DIR_STANDALONE_EXTERNAL_EXTENSIONS, |
| 382 chrome::DIR_STANDALONE_EXTERNAL_EXTENSIONS, | 381 ExternalPrefLoader::NONE), |
| 383 ExternalPrefExtensionLoader::NONE), | |
| 384 Extension::EXTERNAL_PREF, | 382 Extension::EXTERNAL_PREF, |
| 385 Extension::EXTERNAL_PREF_DOWNLOAD, | 383 Extension::EXTERNAL_PREF_DOWNLOAD, |
| 386 Extension::NO_FLAGS))); | 384 Extension::NO_FLAGS))); |
| 387 #endif | 385 #endif |
| 388 | 386 |
| 389 provider_list->push_back( | 387 provider_list->push_back( |
| 390 linked_ptr<ExternalExtensionProviderInterface>( | 388 linked_ptr<ExternalProviderInterface>( |
| 391 new ExternalExtensionProviderImpl( | 389 new ExternalProviderImpl( |
| 392 service, | 390 service, |
| 393 new ExternalPolicyExtensionLoader(profile), | 391 new ExternalPolicyLoader(profile), |
| 394 Extension::INVALID, | 392 Extension::INVALID, |
| 395 Extension::EXTERNAL_POLICY_DOWNLOAD, | 393 Extension::EXTERNAL_POLICY_DOWNLOAD, |
| 396 Extension::NO_FLAGS))); | 394 Extension::NO_FLAGS))); |
| 397 | 395 |
| 398 #if !defined(OS_CHROMEOS) | 396 #if !defined(OS_CHROMEOS) |
| 399 provider_list->push_back( | 397 provider_list->push_back( |
| 400 linked_ptr<ExternalExtensionProviderInterface>( | 398 linked_ptr<ExternalProviderInterface>( |
| 401 new default_apps::Provider( | 399 new default_apps::Provider( |
| 402 profile, | 400 profile, |
| 403 service, | 401 service, |
| 404 new ExternalPrefExtensionLoader( | 402 new ExternalPrefLoader(chrome::DIR_DEFAULT_APPS, |
| 405 chrome::DIR_DEFAULT_APPS, | 403 ExternalPrefLoader::NONE), |
| 406 ExternalPrefExtensionLoader::NONE), | |
| 407 Extension::EXTERNAL_PREF, | 404 Extension::EXTERNAL_PREF, |
| 408 Extension::INVALID, | 405 Extension::INVALID, |
| 409 Extension::FROM_WEBSTORE))); | 406 Extension::FROM_WEBSTORE))); |
| 410 #endif | 407 #endif |
| 411 | 408 |
| 412 #if defined(OS_CHROMEOS) | 409 #if defined(OS_CHROMEOS) |
| 413 policy::BrowserPolicyConnector* connector = | 410 policy::BrowserPolicyConnector* connector = |
| 414 g_browser_process->browser_policy_connector(); | 411 g_browser_process->browser_policy_connector(); |
| 415 if (is_chromeos_demo_session && connector->GetAppPackUpdater()) { | 412 if (is_chromeos_demo_session && connector->GetAppPackUpdater()) { |
| 416 provider_list->push_back( | 413 provider_list->push_back( |
| 417 linked_ptr<ExternalExtensionProviderInterface>( | 414 linked_ptr<ExternalProviderInterface>( |
| 418 new ExternalExtensionProviderImpl( | 415 new ExternalProviderImpl( |
| 419 service, | 416 service, |
| 420 connector->GetAppPackUpdater()->CreateExternalExtensionLoader(), | 417 connector->GetAppPackUpdater()->CreateExternalLoader(), |
| 421 Extension::EXTERNAL_PREF, | 418 Extension::EXTERNAL_PREF, |
| 422 Extension::INVALID, | 419 Extension::INVALID, |
| 423 Extension::NO_FLAGS))); | 420 Extension::NO_FLAGS))); |
| 424 } | 421 } |
| 425 #endif | 422 #endif |
| 426 } | 423 } |
| 424 |
| 425 } // namespace extensions |
| OLD | NEW |