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 <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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 49 #include "grit/keyboard_resources.h" | 49 #include "grit/keyboard_resources.h" |
| 50 #include "ui/file_manager/grit/file_manager_resources.h" | 50 #include "ui/file_manager/grit/file_manager_resources.h" |
| 51 #include "ui/keyboard/keyboard_util.h" | 51 #include "ui/keyboard/keyboard_util.h" |
| 52 #endif | 52 #endif |
| 53 | 53 |
| 54 #if defined(GOOGLE_CHROME_BUILD) | 54 #if defined(GOOGLE_CHROME_BUILD) |
| 55 #include "chrome/browser/defaults.h" | 55 #include "chrome/browser/defaults.h" |
| 56 #endif | 56 #endif |
| 57 | 57 |
| 58 #if defined(OS_CHROMEOS) | 58 #if defined(OS_CHROMEOS) |
| 59 #include "chrome/browser/chromeos/accessibility/accessibility_manager.h" | |
| 60 #include "chromeos/chromeos_switches.h" | 59 #include "chromeos/chromeos_switches.h" |
| 61 #include "content/public/browser/site_instance.h" | 60 #include "content/public/browser/site_instance.h" |
| 62 #include "content/public/browser/storage_partition.h" | 61 #include "content/public/browser/storage_partition.h" |
| 63 #include "extensions/browser/extensions_browser_client.h" | 62 #include "extensions/browser/extensions_browser_client.h" |
| 64 #include "storage/browser/fileapi/file_system_context.h" | 63 #include "storage/browser/fileapi/file_system_context.h" |
| 65 #endif | 64 #endif |
| 66 | 65 |
| 67 using content::BrowserThread; | 66 using content::BrowserThread; |
| 68 | 67 |
| 69 namespace extensions { | 68 namespace extensions { |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 94 LOG(ERROR) << "Can't load " | 93 LOG(ERROR) << "Can't load " |
| 95 << root_directory.Append(manifest_filename).AsUTF8Unsafe() | 94 << root_directory.Append(manifest_filename).AsUTF8Unsafe() |
| 96 << ": " << error; | 95 << ": " << error; |
| 97 return nullptr; | 96 return nullptr; |
| 98 } | 97 } |
| 99 bool localized = extension_l10n_util::LocalizeExtension( | 98 bool localized = extension_l10n_util::LocalizeExtension( |
| 100 root_directory, manifest.get(), &error); | 99 root_directory, manifest.get(), &error); |
| 101 CHECK(localized) << error; | 100 CHECK(localized) << error; |
| 102 return manifest; | 101 return manifest; |
| 103 } | 102 } |
| 104 | |
| 105 bool IsNormalSession() { | |
| 106 return !base::CommandLine::ForCurrentProcess()->HasSwitch( | |
| 107 chromeos::switches::kGuestSession) && | |
| 108 user_manager::UserManager::IsInitialized() && | |
| 109 user_manager::UserManager::Get()->IsUserLoggedIn(); | |
| 110 } | |
| 111 #endif // defined(OS_CHROMEOS) | 103 #endif // defined(OS_CHROMEOS) |
| 112 | 104 |
| 113 } // namespace | 105 } // namespace |
| 114 | 106 |
| 115 ComponentLoader::ComponentExtensionInfo::ComponentExtensionInfo( | 107 ComponentLoader::ComponentExtensionInfo::ComponentExtensionInfo( |
| 116 const base::DictionaryValue* manifest, const base::FilePath& directory) | 108 const base::DictionaryValue* manifest, const base::FilePath& directory) |
| 117 : manifest(manifest), | 109 : manifest(manifest), |
| 118 root_directory(directory) { | 110 root_directory(directory) { |
| 119 if (!root_directory.IsAbsolute()) { | 111 if (!root_directory.IsAbsolute()) { |
| 120 CHECK(PathService::Get(chrome::DIR_RESOURCES, &root_directory)); | 112 CHECK(PathService::Get(chrome::DIR_RESOURCES, &root_directory)); |
| (...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 370 base::FilePath(FILE_PATH_LITERAL("image_loader"))); | 362 base::FilePath(FILE_PATH_LITERAL("image_loader"))); |
| 371 #endif // defined(IMAGE_LOADER_EXTENSION) | 363 #endif // defined(IMAGE_LOADER_EXTENSION) |
| 372 } | 364 } |
| 373 | 365 |
| 374 void ComponentLoader::AddNetworkSpeechSynthesisExtension() { | 366 void ComponentLoader::AddNetworkSpeechSynthesisExtension() { |
| 375 Add(IDR_NETWORK_SPEECH_SYNTHESIS_MANIFEST, | 367 Add(IDR_NETWORK_SPEECH_SYNTHESIS_MANIFEST, |
| 376 base::FilePath(FILE_PATH_LITERAL("network_speech_synthesis"))); | 368 base::FilePath(FILE_PATH_LITERAL("network_speech_synthesis"))); |
| 377 } | 369 } |
| 378 | 370 |
| 379 #if defined(OS_CHROMEOS) | 371 #if defined(OS_CHROMEOS) |
| 380 void ComponentLoader::AddChromeVoxExtension( | |
| 381 const base::Closure& done_cb) { | |
| 382 base::FilePath resources_path; | |
| 383 CHECK(PathService::Get(chrome::DIR_RESOURCES, &resources_path)); | |
| 384 | |
| 385 base::FilePath chromevox_path = | |
| 386 resources_path.Append(extension_misc::kChromeVoxExtensionPath); | |
| 387 | |
| 388 const base::FilePath::CharType* manifest_filename = | |
| 389 IsNormalSession() ? extensions::kManifestFilename | |
| 390 : extension_misc::kGuestManifestFilename; | |
| 391 AddWithManifestFile( | |
| 392 manifest_filename, | |
| 393 chromevox_path, | |
| 394 extension_misc::kChromeVoxExtensionId, | |
| 395 done_cb); | |
| 396 } | |
| 397 | |
| 398 void ComponentLoader::AddChromeOsSpeechSynthesisExtension() { | 372 void ComponentLoader::AddChromeOsSpeechSynthesisExtension() { |
| 399 const base::FilePath::CharType* manifest_filename = | 373 const base::FilePath::CharType* manifest_filename = |
| 400 IsNormalSession() ? extensions::kManifestFilename | 374 IsNormalSession() ? extensions::kManifestFilename |
| 401 : extension_misc::kGuestManifestFilename; | 375 : extension_misc::kGuestManifestFilename; |
| 402 AddWithManifestFile( | 376 AddWithManifestFile( |
| 403 manifest_filename, | 377 manifest_filename, |
| 404 base::FilePath(extension_misc::kSpeechSynthesisExtensionPath), | 378 base::FilePath(extension_misc::kSpeechSynthesisExtensionPath), |
| 405 extension_misc::kSpeechSynthesisExtensionId, | 379 extension_misc::kSpeechSynthesisExtensionId, |
| 406 base::Bind(&ComponentLoader::EnableFileSystemInGuestMode, | 380 base::Bind(&ComponentLoader::EnableFileSystemInGuestMode, |
| 407 weak_factory_.GetWeakPtr(), | 381 weak_factory_.GetWeakPtr(), |
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 618 base::FilePath(FILE_PATH_LITERAL("chromeos/first_run/app"))); | 592 base::FilePath(FILE_PATH_LITERAL("chromeos/first_run/app"))); |
| 619 | 593 |
| 620 Add(IDR_CONNECTIVITY_DIAGNOSTICS_MANIFEST, | 594 Add(IDR_CONNECTIVITY_DIAGNOSTICS_MANIFEST, |
| 621 base::FilePath(extension_misc::kConnectivityDiagnosticsPath)); | 595 base::FilePath(extension_misc::kConnectivityDiagnosticsPath)); |
| 622 Add(IDR_CONNECTIVITY_DIAGNOSTICS_LAUNCHER_MANIFEST, | 596 Add(IDR_CONNECTIVITY_DIAGNOSTICS_LAUNCHER_MANIFEST, |
| 623 base::FilePath(extension_misc::kConnectivityDiagnosticsLauncherPath)); | 597 base::FilePath(extension_misc::kConnectivityDiagnosticsLauncherPath)); |
| 624 | 598 |
| 625 Add(IDR_ARC_SUPPORT_MANIFEST, | 599 Add(IDR_ARC_SUPPORT_MANIFEST, |
| 626 base::FilePath(FILE_PATH_LITERAL("chromeos/arc_support"))); | 600 base::FilePath(FILE_PATH_LITERAL("chromeos/arc_support"))); |
| 627 } | 601 } |
| 628 | |
| 629 // Load ChromeVox extension now if spoken feedback is enabled. | |
| 630 if (chromeos::AccessibilityManager::Get() && | |
| 631 chromeos::AccessibilityManager::Get()->IsSpokenFeedbackEnabled()) { | |
| 632 AddChromeVoxExtension(base::Closure()); | |
| 633 } | |
| 634 #endif // defined(OS_CHROMEOS) | 602 #endif // defined(OS_CHROMEOS) |
| 635 | 603 |
| 636 #if defined(GOOGLE_CHROME_BUILD) | 604 #if defined(GOOGLE_CHROME_BUILD) |
| 637 #if !defined(OS_CHROMEOS) // http://crbug.com/314799 | 605 #if !defined(OS_CHROMEOS) // http://crbug.com/314799 |
| 638 AddNetworkSpeechSynthesisExtension(); | 606 AddNetworkSpeechSynthesisExtension(); |
| 639 #endif | 607 #endif |
| 640 | 608 |
| 641 #endif // defined(GOOGLE_CHROME_BUILD) | 609 #endif // defined(GOOGLE_CHROME_BUILD) |
| 642 | 610 |
| 643 Add(IDR_CRYPTOTOKEN_MANIFEST, | 611 Add(IDR_CRYPTOTOKEN_MANIFEST, |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 682 off_the_record_context, Extension::GetBaseURLFromExtensionId(id)); | 650 off_the_record_context, Extension::GetBaseURLFromExtensionId(id)); |
| 683 storage::FileSystemContext* file_system_context = | 651 storage::FileSystemContext* file_system_context = |
| 684 content::BrowserContext::GetStoragePartitionForSite( | 652 content::BrowserContext::GetStoragePartitionForSite( |
| 685 off_the_record_context, site)->GetFileSystemContext(); | 653 off_the_record_context, site)->GetFileSystemContext(); |
| 686 file_system_context->EnableTemporaryFileSystemInIncognito(); | 654 file_system_context->EnableTemporaryFileSystemInIncognito(); |
| 687 } | 655 } |
| 688 #endif | 656 #endif |
| 689 } | 657 } |
| 690 | 658 |
| 691 #if defined(OS_CHROMEOS) | 659 #if defined(OS_CHROMEOS) |
| 660 // static | |
| 661 bool ComponentLoader::IsNormalSession() { | |
|
Devlin
2016/08/04 16:18:33
Rather than exposing this logic to the a11y manage
dmazzoni
2016/08/04 17:54:38
Sounds good.
How about calling it something like
| |
| 662 return !base::CommandLine::ForCurrentProcess()->HasSwitch( | |
| 663 chromeos::switches::kGuestSession) && | |
| 664 user_manager::UserManager::IsInitialized() && | |
| 665 user_manager::UserManager::Get()->IsUserLoggedIn(); | |
| 666 } | |
| 667 | |
| 692 void ComponentLoader::AddWithManifestFile( | 668 void ComponentLoader::AddWithManifestFile( |
| 693 const base::FilePath::CharType* manifest_filename, | 669 const base::FilePath::CharType* manifest_filename, |
| 694 const base::FilePath& root_directory, | 670 const base::FilePath& root_directory, |
| 695 const char* extension_id, | 671 const char* extension_id, |
| 696 const base::Closure& done_cb) { | 672 const base::Closure& done_cb) { |
| 697 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 673 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 698 BrowserThread::PostTaskAndReplyWithResult( | 674 BrowserThread::PostTaskAndReplyWithResult( |
| 699 BrowserThread::FILE, | 675 BrowserThread::FILE, |
| 700 FROM_HERE, | 676 FROM_HERE, |
| 701 base::Bind(&LoadManifestOnFileThread, root_directory, manifest_filename), | 677 base::Bind(&LoadManifestOnFileThread, root_directory, manifest_filename), |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 718 manifest.release(), | 694 manifest.release(), |
| 719 root_directory, | 695 root_directory, |
| 720 false); | 696 false); |
| 721 CHECK_EQ(extension_id, actual_extension_id); | 697 CHECK_EQ(extension_id, actual_extension_id); |
| 722 if (!done_cb.is_null()) | 698 if (!done_cb.is_null()) |
| 723 done_cb.Run(); | 699 done_cb.Run(); |
| 724 } | 700 } |
| 725 #endif | 701 #endif |
| 726 | 702 |
| 727 } // namespace extensions | 703 } // namespace extensions |
| OLD | NEW |