| 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" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 #include "ui/base/resource/resource_bundle.h" | 28 #include "ui/base/resource/resource_bundle.h" |
| 29 | 29 |
| 30 #if defined(OFFICIAL_BUILD) | 30 #if defined(OFFICIAL_BUILD) |
| 31 #include "chrome/browser/defaults.h" | 31 #include "chrome/browser/defaults.h" |
| 32 #endif | 32 #endif |
| 33 | 33 |
| 34 #if defined(OS_CHROMEOS) | 34 #if defined(OS_CHROMEOS) |
| 35 #include "chrome/browser/chromeos/login/user_manager.h" | 35 #include "chrome/browser/chromeos/login/user_manager.h" |
| 36 #endif | 36 #endif |
| 37 | 37 |
| 38 #if defined(USE_ASH) |
| 39 #include "grit/chromium_strings.h" |
| 40 #include "ui/base/l10n/l10n_util.h" |
| 41 #endif |
| 42 |
| 38 namespace extensions { | 43 namespace extensions { |
| 39 | 44 |
| 40 ComponentLoader::ComponentLoader(ExtensionServiceInterface* extension_service, | 45 ComponentLoader::ComponentLoader(ExtensionServiceInterface* extension_service, |
| 41 PrefService* prefs, | 46 PrefService* prefs, |
| 42 PrefService* local_state) | 47 PrefService* local_state) |
| 43 : prefs_(prefs), | 48 : prefs_(prefs), |
| 44 local_state_(local_state), | 49 local_state_(local_state), |
| 45 extension_service_(extension_service) { | 50 extension_service_(extension_service) { |
| 46 pref_change_registrar_.Init(prefs); | 51 pref_change_registrar_.Init(prefs); |
| 47 | 52 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 int manifest_resource_id, | 94 int manifest_resource_id, |
| 90 const FilePath& root_directory) { | 95 const FilePath& root_directory) { |
| 91 std::string manifest_contents = | 96 std::string manifest_contents = |
| 92 ResourceBundle::GetSharedInstance().GetRawDataResource( | 97 ResourceBundle::GetSharedInstance().GetRawDataResource( |
| 93 manifest_resource_id, | 98 manifest_resource_id, |
| 94 ui::SCALE_FACTOR_NONE).as_string(); | 99 ui::SCALE_FACTOR_NONE).as_string(); |
| 95 return Add(manifest_contents, root_directory); | 100 return Add(manifest_contents, root_directory); |
| 96 } | 101 } |
| 97 | 102 |
| 98 const Extension* ComponentLoader::Add( | 103 const Extension* ComponentLoader::Add( |
| 99 std::string& manifest_contents, | 104 const std::string& manifest_contents, |
| 100 const FilePath& root_directory) { | 105 const FilePath& root_directory) { |
| 101 // The Value is kept for the lifetime of the ComponentLoader. This is | 106 // The Value is kept for the lifetime of the ComponentLoader. This is |
| 102 // required in case LoadAll() is called again. | 107 // required in case LoadAll() is called again. |
| 103 DictionaryValue* manifest = ParseManifest(manifest_contents); | 108 DictionaryValue* manifest = ParseManifest(manifest_contents); |
| 104 if (manifest) | 109 if (manifest) |
| 105 return Add(manifest, root_directory); | 110 return Add(manifest, root_directory); |
| 106 return NULL; | 111 return NULL; |
| 107 } | 112 } |
| 108 | 113 |
| 109 const Extension* ComponentLoader::Add( | 114 const Extension* ComponentLoader::Add( |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 270 DictionaryValue* manifest = ParseManifest(manifest_contents); | 275 DictionaryValue* manifest = ParseManifest(manifest_contents); |
| 271 if (manifest) { | 276 if (manifest) { |
| 272 std::string name = prefs_->GetString(prefs::kEnterpriseWebStoreName); | 277 std::string name = prefs_->GetString(prefs::kEnterpriseWebStoreName); |
| 273 manifest->SetString("app.launch.web_url", enterprise_webstore_url); | 278 manifest->SetString("app.launch.web_url", enterprise_webstore_url); |
| 274 manifest->SetString("name", name); | 279 manifest->SetString("name", name); |
| 275 Add(manifest, path); | 280 Add(manifest, path); |
| 276 } | 281 } |
| 277 } | 282 } |
| 278 } | 283 } |
| 279 | 284 |
| 285 void ComponentLoader::AddChromeApp() { |
| 286 #if defined(USE_ASH) |
| 287 std::string manifest_contents = |
| 288 ResourceBundle::GetSharedInstance().GetRawDataResource( |
| 289 IDR_CHROME_APP_MANIFEST, |
| 290 ui::SCALE_FACTOR_NONE).as_string(); |
| 291 |
| 292 // The Value is kept for the lifetime of the ComponentLoader. This is |
| 293 // required in case LoadAll() is called again. |
| 294 DictionaryValue* manifest = ParseManifest(manifest_contents); |
| 295 |
| 296 // Update manifest to use a proper name. |
| 297 manifest->SetString(extension_manifest_keys::kName, |
| 298 l10n_util::GetStringUTF8(IDS_SHORT_PRODUCT_NAME)); |
| 299 |
| 300 if (manifest) |
| 301 Add(manifest, FilePath(FILE_PATH_LITERAL("chrome_app"))); |
| 302 #endif |
| 303 } |
| 304 |
| 280 void ComponentLoader::AddDefaultComponentExtensions() { | 305 void ComponentLoader::AddDefaultComponentExtensions() { |
| 281 #if defined(OS_CHROMEOS) | 306 #if defined(OS_CHROMEOS) |
| 282 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kGuestSession)) | 307 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kGuestSession)) |
| 283 Add(IDR_BOOKMARKS_MANIFEST, | 308 Add(IDR_BOOKMARKS_MANIFEST, |
| 284 FilePath(FILE_PATH_LITERAL("bookmark_manager"))); | 309 FilePath(FILE_PATH_LITERAL("bookmark_manager"))); |
| 285 #else | 310 #else |
| 286 Add(IDR_BOOKMARKS_MANIFEST, FilePath(FILE_PATH_LITERAL("bookmark_manager"))); | 311 Add(IDR_BOOKMARKS_MANIFEST, FilePath(FILE_PATH_LITERAL("bookmark_manager"))); |
| 287 #endif | 312 #endif |
| 288 | 313 |
| 289 #if defined(OS_CHROMEOS) | 314 #if defined(OS_CHROMEOS) |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 339 .AppendASCII(extension_misc::kChromeVoxDirectoryName); | 364 .AppendASCII(extension_misc::kChromeVoxDirectoryName); |
| 340 Add(IDR_CHROMEVOX_MANIFEST, path); | 365 Add(IDR_CHROMEVOX_MANIFEST, path); |
| 341 } | 366 } |
| 342 #endif | 367 #endif |
| 343 | 368 |
| 344 // If a URL for the enterprise webstore has been specified, load the | 369 // If a URL for the enterprise webstore has been specified, load the |
| 345 // component extension. This extension might also be loaded later, because | 370 // component extension. This extension might also be loaded later, because |
| 346 // it is specified by policy, and on ChromeOS policies are loaded after | 371 // it is specified by policy, and on ChromeOS policies are loaded after |
| 347 // the browser process has started. | 372 // the browser process has started. |
| 348 AddOrReloadEnterpriseWebStore(); | 373 AddOrReloadEnterpriseWebStore(); |
| 374 |
| 375 #if defined(USE_ASH) |
| 376 AddChromeApp(); |
| 377 #endif |
| 349 } | 378 } |
| 350 | 379 |
| 351 void ComponentLoader::Observe( | 380 void ComponentLoader::Observe( |
| 352 int type, | 381 int type, |
| 353 const content::NotificationSource& source, | 382 const content::NotificationSource& source, |
| 354 const content::NotificationDetails& details) { | 383 const content::NotificationDetails& details) { |
| 355 if (type == chrome::NOTIFICATION_PREF_CHANGED) { | 384 if (type == chrome::NOTIFICATION_PREF_CHANGED) { |
| 356 const std::string* name = | 385 const std::string* name = |
| 357 content::Details<const std::string>(details).ptr(); | 386 content::Details<const std::string>(details).ptr(); |
| 358 if (*name == prefs::kEnterpriseWebStoreURL) | 387 if (*name == prefs::kEnterpriseWebStoreURL) |
| 359 AddOrReloadEnterpriseWebStore(); | 388 AddOrReloadEnterpriseWebStore(); |
| 360 else | 389 else |
| 361 NOTREACHED(); | 390 NOTREACHED(); |
| 362 } else { | 391 } else { |
| 363 NOTREACHED(); | 392 NOTREACHED(); |
| 364 } | 393 } |
| 365 } | 394 } |
| 366 | 395 |
| 367 // static | 396 // static |
| 368 void ComponentLoader::RegisterUserPrefs(PrefService* prefs) { | 397 void ComponentLoader::RegisterUserPrefs(PrefService* prefs) { |
| 369 prefs->RegisterStringPref(prefs::kEnterpriseWebStoreURL, | 398 prefs->RegisterStringPref(prefs::kEnterpriseWebStoreURL, |
| 370 std::string() /* default_value */, | 399 std::string() /* default_value */, |
| 371 PrefService::UNSYNCABLE_PREF); | 400 PrefService::UNSYNCABLE_PREF); |
| 372 prefs->RegisterStringPref(prefs::kEnterpriseWebStoreName, | 401 prefs->RegisterStringPref(prefs::kEnterpriseWebStoreName, |
| 373 std::string() /* default_value */, | 402 std::string() /* default_value */, |
| 374 PrefService::UNSYNCABLE_PREF); | 403 PrefService::UNSYNCABLE_PREF); |
| 375 } | 404 } |
| 376 | 405 |
| 377 } // namespace extensions | 406 } // namespace extensions |
| OLD | NEW |