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 <string> | 7 #include <string> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 #include "chrome/browser/search/hotword_service_factory.h" | 22 #include "chrome/browser/search/hotword_service_factory.h" |
23 #include "chrome/common/chrome_paths.h" | 23 #include "chrome/common/chrome_paths.h" |
24 #include "chrome/common/chrome_switches.h" | 24 #include "chrome/common/chrome_switches.h" |
25 #include "chrome/common/chrome_version_info.h" | 25 #include "chrome/common/chrome_version_info.h" |
26 #include "chrome/common/extensions/extension_constants.h" | 26 #include "chrome/common/extensions/extension_constants.h" |
27 #include "chrome/grit/generated_resources.h" | 27 #include "chrome/grit/generated_resources.h" |
28 #include "components/crx_file/id_util.h" | 28 #include "components/crx_file/id_util.h" |
29 #include "content/public/browser/browser_context.h" | 29 #include "content/public/browser/browser_context.h" |
30 #include "content/public/browser/browser_thread.h" | 30 #include "content/public/browser/browser_thread.h" |
31 #include "content/public/browser/plugin_service.h" | 31 #include "content/public/browser/plugin_service.h" |
| 32 #include "extensions/common/constants.h" |
32 #include "extensions/common/extension.h" | 33 #include "extensions/common/extension.h" |
33 #include "extensions/common/extension_l10n_util.h" | 34 #include "extensions/common/extension_l10n_util.h" |
34 #include "extensions/common/file_util.h" | 35 #include "extensions/common/file_util.h" |
35 #include "extensions/common/manifest_constants.h" | 36 #include "extensions/common/manifest_constants.h" |
36 #include "grit/browser_resources.h" | 37 #include "grit/browser_resources.h" |
37 #include "ui/base/l10n/l10n_util.h" | 38 #include "ui/base/l10n/l10n_util.h" |
38 #include "ui/base/resource/resource_bundle.h" | 39 #include "ui/base/resource/resource_bundle.h" |
39 | 40 |
40 #if defined(OS_CHROMEOS) | 41 #if defined(OS_CHROMEOS) |
41 #include "components/chrome_apps/grit/chrome_apps_resources.h" | 42 #include "components/chrome_apps/grit/chrome_apps_resources.h" |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 std::string id_input; | 81 std::string id_input; |
81 CHECK(manifest->GetString(manifest_keys::kPublicKey, &raw_key)); | 82 CHECK(manifest->GetString(manifest_keys::kPublicKey, &raw_key)); |
82 CHECK(Extension::ParsePEMKeyBytes(raw_key, &id_input)); | 83 CHECK(Extension::ParsePEMKeyBytes(raw_key, &id_input)); |
83 std::string id = crx_file::id_util::GenerateId(id_input); | 84 std::string id = crx_file::id_util::GenerateId(id_input); |
84 return id; | 85 return id; |
85 } | 86 } |
86 | 87 |
87 #if defined(OS_CHROMEOS) | 88 #if defined(OS_CHROMEOS) |
88 scoped_ptr<base::DictionaryValue> | 89 scoped_ptr<base::DictionaryValue> |
89 LoadManifestOnFileThread( | 90 LoadManifestOnFileThread( |
90 const base::FilePath& chromevox_path, const char* manifest_filename) { | 91 const base::FilePath& root_directory, |
| 92 const base::FilePath::CharType* manifest_filename) { |
91 DCHECK_CURRENTLY_ON(content::BrowserThread::FILE); | 93 DCHECK_CURRENTLY_ON(content::BrowserThread::FILE); |
92 std::string error; | 94 std::string error; |
93 scoped_ptr<base::DictionaryValue> manifest( | 95 scoped_ptr<base::DictionaryValue> manifest( |
94 file_util::LoadManifest(chromevox_path, manifest_filename, &error)); | 96 file_util::LoadManifest(root_directory, manifest_filename, &error)); |
95 CHECK(manifest) << error; | 97 if (!manifest) { |
| 98 LOG(ERROR) << "Can't load " |
| 99 << root_directory.Append(manifest_filename).AsUTF8Unsafe() |
| 100 << ": " << error; |
| 101 return nullptr; |
| 102 } |
96 bool localized = extension_l10n_util::LocalizeExtension( | 103 bool localized = extension_l10n_util::LocalizeExtension( |
97 chromevox_path, manifest.get(), &error); | 104 root_directory, manifest.get(), &error); |
98 CHECK(localized) << error; | 105 CHECK(localized) << error; |
99 return manifest.Pass(); | 106 return manifest.Pass(); |
100 } | 107 } |
101 | 108 |
102 bool IsNormalSession() { | 109 bool IsNormalSession() { |
103 return !base::CommandLine::ForCurrentProcess()->HasSwitch( | 110 return !base::CommandLine::ForCurrentProcess()->HasSwitch( |
104 chromeos::switches::kGuestSession) && | 111 chromeos::switches::kGuestSession) && |
105 user_manager::UserManager::IsInitialized() && | 112 user_manager::UserManager::IsInitialized() && |
106 user_manager::UserManager::Get()->IsUserLoggedIn(); | 113 user_manager::UserManager::Get()->IsUserLoggedIn(); |
107 } | 114 } |
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
388 } | 395 } |
389 | 396 |
390 void ComponentLoader::AddNetworkSpeechSynthesisExtension() { | 397 void ComponentLoader::AddNetworkSpeechSynthesisExtension() { |
391 Add(IDR_NETWORK_SPEECH_SYNTHESIS_MANIFEST, | 398 Add(IDR_NETWORK_SPEECH_SYNTHESIS_MANIFEST, |
392 base::FilePath(FILE_PATH_LITERAL("network_speech_synthesis"))); | 399 base::FilePath(FILE_PATH_LITERAL("network_speech_synthesis"))); |
393 } | 400 } |
394 | 401 |
395 #if defined(OS_CHROMEOS) | 402 #if defined(OS_CHROMEOS) |
396 void ComponentLoader::AddChromeVoxExtension( | 403 void ComponentLoader::AddChromeVoxExtension( |
397 const base::Closure& done_cb) { | 404 const base::Closure& done_cb) { |
398 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
399 base::FilePath resources_path; | 405 base::FilePath resources_path; |
400 PathService::Get(chrome::DIR_RESOURCES, &resources_path); | 406 CHECK(PathService::Get(chrome::DIR_RESOURCES, &resources_path)); |
401 | 407 |
402 base::FilePath chromevox_path = | 408 base::FilePath chromevox_path = |
403 resources_path.Append(extension_misc::kChromeVoxExtensionPath); | 409 resources_path.Append(extension_misc::kChromeVoxExtensionPath); |
404 | 410 |
405 const char* manifest_filename = | 411 const base::FilePath::CharType* manifest_filename = |
406 IsNormalSession() ? extension_misc::kChromeVoxManifestFilename | 412 IsNormalSession() ? extensions::kManifestFilename |
407 : extension_misc::kChromeVoxGuestManifestFilename; | 413 : extension_misc::kGuestManifestFilename; |
408 | 414 AddWithManifestFile( |
409 BrowserThread::PostTaskAndReplyWithResult( | 415 manifest_filename, |
410 BrowserThread::FILE, | 416 chromevox_path, |
411 FROM_HERE, | 417 extension_misc::kChromeVoxExtensionId, |
412 base::Bind(&LoadManifestOnFileThread, chromevox_path, manifest_filename), | 418 done_cb); |
413 base::Bind(&ComponentLoader::AddChromeVoxExtensionWithManifest, | |
414 weak_factory_.GetWeakPtr(), | |
415 chromevox_path, | |
416 done_cb)); | |
417 } | 419 } |
418 | 420 |
419 void ComponentLoader::AddChromeVoxExtensionWithManifest( | 421 void ComponentLoader::AddChromeOsSpeechSynthesisExtension() { |
420 const base::FilePath& chromevox_path, | 422 const base::FilePath::CharType* manifest_filename = |
421 const base::Closure& done_cb, | 423 IsNormalSession() ? extensions::kManifestFilename |
422 scoped_ptr<base::DictionaryValue> manifest) { | 424 : extension_misc::kGuestManifestFilename; |
423 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 425 AddWithManifestFile( |
424 std::string extension_id = Add(manifest.release(), chromevox_path, false); | 426 manifest_filename, |
425 CHECK_EQ(extension_misc::kChromeVoxExtensionId, extension_id); | 427 base::FilePath(extension_misc::kSpeechSynthesisExtensionPath), |
426 if (!done_cb.is_null()) | 428 extension_misc::kSpeechSynthesisExtensionId, |
427 done_cb.Run(); | 429 base::Bind(&ComponentLoader::EnableFileSystemInGuestMode, |
428 } | 430 weak_factory_.GetWeakPtr(), |
429 | 431 extension_misc::kChromeVoxExtensionId)); |
430 std::string ComponentLoader::AddChromeOsSpeechSynthesisExtension() { | |
431 int idr = IsNormalSession() ? IDR_SPEECH_SYNTHESIS_MANIFEST | |
432 : IDR_SPEECH_SYNTHESIS_GUEST_MANIFEST; | |
433 std::string id = Add(idr, | |
434 base::FilePath(extension_misc::kSpeechSynthesisExtensionPath)); | |
435 EnableFileSystemInGuestMode(id); | |
436 return id; | |
437 } | 432 } |
438 #endif | 433 #endif |
439 | 434 |
440 void ComponentLoader::AddWithNameAndDescription( | 435 void ComponentLoader::AddWithNameAndDescription( |
441 int manifest_resource_id, | 436 int manifest_resource_id, |
442 const base::FilePath& root_directory, | 437 const base::FilePath& root_directory, |
443 int name_string_id, | 438 int name_string_id, |
444 int description_string_id) { | 439 int description_string_id) { |
445 if (!ignore_whitelist_for_testing_ && | 440 if (!ignore_whitelist_for_testing_ && |
446 !IsComponentExtensionWhitelisted(manifest_resource_id)) | 441 !IsComponentExtensionWhitelisted(manifest_resource_id)) |
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
711 GURL site = content::SiteInstance::GetSiteForURL( | 706 GURL site = content::SiteInstance::GetSiteForURL( |
712 off_the_record_context, Extension::GetBaseURLFromExtensionId(id)); | 707 off_the_record_context, Extension::GetBaseURLFromExtensionId(id)); |
713 storage::FileSystemContext* file_system_context = | 708 storage::FileSystemContext* file_system_context = |
714 content::BrowserContext::GetStoragePartitionForSite( | 709 content::BrowserContext::GetStoragePartitionForSite( |
715 off_the_record_context, site)->GetFileSystemContext(); | 710 off_the_record_context, site)->GetFileSystemContext(); |
716 file_system_context->EnableTemporaryFileSystemInIncognito(); | 711 file_system_context->EnableTemporaryFileSystemInIncognito(); |
717 } | 712 } |
718 #endif | 713 #endif |
719 } | 714 } |
720 | 715 |
| 716 #if defined(OS_CHROMEOS) |
| 717 void ComponentLoader::AddWithManifestFile( |
| 718 const base::FilePath::CharType* manifest_filename, |
| 719 const base::FilePath& root_directory, |
| 720 const char* extension_id, |
| 721 const base::Closure& done_cb) { |
| 722 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 723 BrowserThread::PostTaskAndReplyWithResult( |
| 724 BrowserThread::FILE, |
| 725 FROM_HERE, |
| 726 base::Bind(&LoadManifestOnFileThread, root_directory, manifest_filename), |
| 727 base::Bind(&ComponentLoader::FinishAddWithManifestFile, |
| 728 weak_factory_.GetWeakPtr(), |
| 729 root_directory, |
| 730 extension_id, |
| 731 done_cb)); |
| 732 } |
| 733 |
| 734 void ComponentLoader::FinishAddWithManifestFile( |
| 735 const base::FilePath& root_directory, |
| 736 const char* extension_id, |
| 737 const base::Closure& done_cb, |
| 738 scoped_ptr<base::DictionaryValue> manifest) { |
| 739 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 740 if (!manifest) |
| 741 return; // Error already logged. |
| 742 std::string actual_extension_id = Add( |
| 743 manifest.release(), |
| 744 root_directory, |
| 745 false); |
| 746 CHECK_EQ(extension_id, actual_extension_id); |
| 747 if (!done_cb.is_null()) |
| 748 done_cb.Run(); |
| 749 } |
| 750 #endif |
| 751 |
721 } // namespace extensions | 752 } // namespace extensions |
OLD | NEW |