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/component_loader.h" | 5 #include "chrome/browser/extensions/component_loader.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/json/json_string_value_serializer.h" | 9 #include "base/json/json_string_value_serializer.h" |
| 10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
| 11 #include "base/prefs/pref_change_registrar.h" | 11 #include "base/prefs/pref_change_registrar.h" |
| 12 #include "base/prefs/pref_notifier.h" | 12 #include "base/prefs/pref_notifier.h" |
|
Joao da Silva
2013/05/16 08:27:35
nit: these 2 are not used
Mattias Nissler (ping if slow)
2013/05/16 12:08:21
Done.
| |
| 13 #include "base/prefs/pref_service.h" | 13 #include "base/prefs/pref_service.h" |
| 14 #include "chrome/browser/extensions/extension_service.h" | 14 #include "chrome/browser/extensions/extension_service.h" |
| 15 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
| 16 #include "chrome/common/chrome_notification_types.h" | 16 #include "chrome/common/chrome_notification_types.h" |
| 17 #include "chrome/common/chrome_paths.h" | 17 #include "chrome/common/chrome_paths.h" |
| 18 #include "chrome/common/chrome_switches.h" | 18 #include "chrome/common/chrome_switches.h" |
| 19 #include "chrome/common/extensions/extension.h" | 19 #include "chrome/common/extensions/extension.h" |
| 20 #include "chrome/common/extensions/extension_file_util.h" | 20 #include "chrome/common/extensions/extension_file_util.h" |
| 21 #include "chrome/common/extensions/extension_manifest_constants.h" | 21 #include "chrome/common/extensions/extension_manifest_constants.h" |
| 22 #include "chrome/common/pref_names.h" | 22 #include "chrome/common/pref_names.h" |
| 23 #include "components/user_prefs/pref_registry_syncable.h" | 23 #include "components/user_prefs/pref_registry_syncable.h" |
|
Joao da Silva
2013/05/16 08:27:35
nit: not used
Mattias Nissler (ping if slow)
2013/05/16 12:08:21
Done.
| |
| 24 #include "content/public/browser/notification_details.h" | 24 #include "content/public/browser/notification_details.h" |
| 25 #include "content/public/browser/notification_source.h" | 25 #include "content/public/browser/notification_source.h" |
| 26 #include "extensions/common/id_util.h" | 26 #include "extensions/common/id_util.h" |
| 27 #include "grit/browser_resources.h" | 27 #include "grit/browser_resources.h" |
| 28 #include "ui/base/resource/resource_bundle.h" | 28 #include "ui/base/resource/resource_bundle.h" |
| 29 | 29 |
| 30 #if defined(USE_AURA) | 30 #if defined(USE_AURA) |
| 31 #include "grit/keyboard_resources.h" | 31 #include "grit/keyboard_resources.h" |
| 32 #endif | 32 #endif |
| 33 | 33 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 79 root_directory = root_directory.Append(directory); | 79 root_directory = root_directory.Append(directory); |
| 80 } | 80 } |
| 81 extension_id = GenerateId(manifest, root_directory); | 81 extension_id = GenerateId(manifest, root_directory); |
| 82 } | 82 } |
| 83 | 83 |
| 84 ComponentLoader::ComponentLoader(ExtensionServiceInterface* extension_service, | 84 ComponentLoader::ComponentLoader(ExtensionServiceInterface* extension_service, |
| 85 PrefService* profile_prefs, | 85 PrefService* profile_prefs, |
| 86 PrefService* local_state) | 86 PrefService* local_state) |
| 87 : profile_prefs_(profile_prefs), | 87 : profile_prefs_(profile_prefs), |
| 88 local_state_(local_state), | 88 local_state_(local_state), |
| 89 extension_service_(extension_service) { | 89 extension_service_(extension_service) {} |
| 90 pref_change_registrar_.Init(profile_prefs); | |
| 91 | |
| 92 // This pref is set by policy. We have to watch it for change because on | |
| 93 // ChromeOS, policy isn't loaded until after the browser process is started. | |
| 94 pref_change_registrar_.Add( | |
| 95 prefs::kEnterpriseWebStoreURL, | |
| 96 base::Bind(&ComponentLoader::AddOrReloadEnterpriseWebStore, | |
| 97 base::Unretained(this))); | |
| 98 } | |
| 99 | 90 |
| 100 ComponentLoader::~ComponentLoader() { | 91 ComponentLoader::~ComponentLoader() { |
| 101 ClearAllRegistered(); | 92 ClearAllRegistered(); |
| 102 } | 93 } |
| 103 | 94 |
| 104 void ComponentLoader::LoadAll() { | 95 void ComponentLoader::LoadAll() { |
| 105 for (RegisteredComponentExtensions::iterator it = | 96 for (RegisteredComponentExtensions::iterator it = |
| 106 component_extensions_.begin(); | 97 component_extensions_.begin(); |
| 107 it != component_extensions_.end(); ++it) { | 98 it != component_extensions_.end(); ++it) { |
| 108 Load(*it); | 99 Load(*it); |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 277 command_line->GetSwitchValuePath(switches::kImageLoaderExtensionPath)); | 268 command_line->GetSwitchValuePath(switches::kImageLoaderExtensionPath)); |
| 278 Add(IDR_IMAGE_LOADER_MANIFEST, image_loader_extension_path); | 269 Add(IDR_IMAGE_LOADER_MANIFEST, image_loader_extension_path); |
| 279 return; | 270 return; |
| 280 } | 271 } |
| 281 #endif // NDEBUG | 272 #endif // NDEBUG |
| 282 Add(IDR_IMAGE_LOADER_MANIFEST, | 273 Add(IDR_IMAGE_LOADER_MANIFEST, |
| 283 base::FilePath(FILE_PATH_LITERAL("image_loader"))); | 274 base::FilePath(FILE_PATH_LITERAL("image_loader"))); |
| 284 #endif // defined(IMAGE_LOADER_EXTENSION) | 275 #endif // defined(IMAGE_LOADER_EXTENSION) |
| 285 } | 276 } |
| 286 | 277 |
| 287 void ComponentLoader::AddOrReloadEnterpriseWebStore() { | |
| 288 base::FilePath path(FILE_PATH_LITERAL("enterprise_web_store")); | |
| 289 | |
| 290 // Remove the extension if it was already loaded. | |
| 291 Remove(path); | |
| 292 | |
| 293 std::string enterprise_webstore_url = | |
| 294 profile_prefs_->GetString(prefs::kEnterpriseWebStoreURL); | |
| 295 | |
| 296 // Load the extension only if the URL preference is set. | |
| 297 if (!enterprise_webstore_url.empty()) { | |
| 298 std::string manifest_contents = | |
| 299 ResourceBundle::GetSharedInstance().GetRawDataResource( | |
| 300 IDR_ENTERPRISE_WEBSTORE_MANIFEST).as_string(); | |
| 301 | |
| 302 // The manifest is missing some values that are provided by policy. | |
| 303 DictionaryValue* manifest = ParseManifest(manifest_contents); | |
| 304 if (manifest) { | |
| 305 std::string name = | |
| 306 profile_prefs_->GetString(prefs::kEnterpriseWebStoreName); | |
| 307 manifest->SetString("app.launch.web_url", enterprise_webstore_url); | |
| 308 manifest->SetString("name", name); | |
| 309 Add(manifest, path); | |
| 310 } | |
| 311 } | |
| 312 } | |
| 313 | |
| 314 void ComponentLoader::AddChromeApp() { | 278 void ComponentLoader::AddChromeApp() { |
| 315 #if defined(ENABLE_APP_LIST) | 279 #if defined(ENABLE_APP_LIST) |
| 316 std::string manifest_contents = | 280 std::string manifest_contents = |
| 317 ResourceBundle::GetSharedInstance().GetRawDataResource( | 281 ResourceBundle::GetSharedInstance().GetRawDataResource( |
| 318 IDR_CHROME_APP_MANIFEST).as_string(); | 282 IDR_CHROME_APP_MANIFEST).as_string(); |
| 319 | 283 |
| 320 // The Value is kept for the lifetime of the ComponentLoader. This is | 284 // The Value is kept for the lifetime of the ComponentLoader. This is |
| 321 // required in case LoadAll() is called again. | 285 // required in case LoadAll() is called again. |
| 322 DictionaryValue* manifest = ParseManifest(manifest_contents); | 286 DictionaryValue* manifest = ParseManifest(manifest_contents); |
| 323 | 287 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 370 DCHECK(!skip_session_components); | 334 DCHECK(!skip_session_components); |
| 371 Add(IDR_BOOKMARKS_MANIFEST, | 335 Add(IDR_BOOKMARKS_MANIFEST, |
| 372 base::FilePath(FILE_PATH_LITERAL("bookmark_manager"))); | 336 base::FilePath(FILE_PATH_LITERAL("bookmark_manager"))); |
| 373 // Cloud Print component app. Not required on Chrome OS. | 337 // Cloud Print component app. Not required on Chrome OS. |
| 374 Add(IDR_CLOUDPRINT_MANIFEST, | 338 Add(IDR_CLOUDPRINT_MANIFEST, |
| 375 base::FilePath(FILE_PATH_LITERAL("cloud_print"))); | 339 base::FilePath(FILE_PATH_LITERAL("cloud_print"))); |
| 376 #endif | 340 #endif |
| 377 | 341 |
| 378 if (!skip_session_components) { | 342 if (!skip_session_components) { |
| 379 Add(IDR_WEBSTORE_MANIFEST, base::FilePath(FILE_PATH_LITERAL("web_store"))); | 343 Add(IDR_WEBSTORE_MANIFEST, base::FilePath(FILE_PATH_LITERAL("web_store"))); |
| 380 | |
| 381 // If a URL for the enterprise webstore has been specified, load the | |
| 382 // component extension. This extension might also be loaded later, because | |
| 383 // it is specified by policy, and on ChromeOS policies are loaded after | |
| 384 // the browser process has started. | |
| 385 AddOrReloadEnterpriseWebStore(); | |
| 386 | |
| 387 AddChromeApp(); | 344 AddChromeApp(); |
| 388 } | 345 } |
| 389 | 346 |
| 390 AddKeyboardApp(); | 347 AddKeyboardApp(); |
| 391 | 348 |
| 392 AddDefaultComponentExtensionsWithBackgroundPages(skip_session_components); | 349 AddDefaultComponentExtensionsWithBackgroundPages(skip_session_components); |
| 393 } | 350 } |
| 394 | 351 |
| 395 void ComponentLoader::AddDefaultComponentExtensionsWithBackgroundPages( | 352 void ComponentLoader::AddDefaultComponentExtensionsWithBackgroundPages( |
| 396 bool skip_session_components) { | 353 bool skip_session_components) { |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 478 | 435 |
| 479 void ComponentLoader::UnloadComponent(ComponentExtensionInfo* component) { | 436 void ComponentLoader::UnloadComponent(ComponentExtensionInfo* component) { |
| 480 delete component->manifest; | 437 delete component->manifest; |
| 481 if (extension_service_->is_ready()) { | 438 if (extension_service_->is_ready()) { |
| 482 extension_service_-> | 439 extension_service_-> |
| 483 UnloadExtension(component->extension_id, | 440 UnloadExtension(component->extension_id, |
| 484 extension_misc::UNLOAD_REASON_DISABLE); | 441 extension_misc::UNLOAD_REASON_DISABLE); |
| 485 } | 442 } |
| 486 } | 443 } |
| 487 | 444 |
| 488 // static | |
| 489 void ComponentLoader::RegisterUserPrefs( | |
| 490 user_prefs::PrefRegistrySyncable* registry) { | |
| 491 registry->RegisterStringPref( | |
| 492 prefs::kEnterpriseWebStoreURL, | |
| 493 std::string() /* default_value */, | |
| 494 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | |
| 495 registry->RegisterStringPref( | |
| 496 prefs::kEnterpriseWebStoreName, | |
| 497 std::string() /* default_value */, | |
| 498 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | |
| 499 } | |
| 500 | |
| 501 } // namespace extensions | 445 } // namespace extensions |
| OLD | NEW |