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" |
11 #include "base/json/json_string_value_serializer.h" | 11 #include "base/json/json_string_value_serializer.h" |
12 #include "base/metrics/field_trial.h" | |
13 #include "base/metrics/histogram_macros.h" | 12 #include "base/metrics/histogram_macros.h" |
14 #include "base/path_service.h" | 13 #include "base/path_service.h" |
15 #include "base/time/time.h" | 14 #include "base/time/time.h" |
16 #include "base/trace_event/trace_event.h" | 15 #include "base/trace_event/trace_event.h" |
17 #include "build/build_config.h" | 16 #include "build/build_config.h" |
18 #include "chrome/browser/extensions/component_extensions_whitelist/whitelist.h" | 17 #include "chrome/browser/extensions/component_extensions_whitelist/whitelist.h" |
19 #include "chrome/browser/extensions/data_deleter.h" | 18 #include "chrome/browser/extensions/data_deleter.h" |
20 #include "chrome/browser/extensions/extension_service.h" | 19 #include "chrome/browser/extensions/extension_service.h" |
21 #include "chrome/browser/pdf/pdf_extension_util.h" | 20 #include "chrome/browser/pdf/pdf_extension_util.h" |
22 #include "chrome/browser/profiles/profile.h" | 21 #include "chrome/browser/profiles/profile.h" |
23 #include "chrome/browser/search/hotword_service.h" | 22 #include "chrome/browser/search/hotword_service.h" |
24 #include "chrome/browser/search/hotword_service_factory.h" | 23 #include "chrome/browser/search/hotword_service_factory.h" |
25 #include "chrome/browser/signin/signin_manager_factory.h" | |
26 #include "chrome/common/channel_info.h" | 24 #include "chrome/common/channel_info.h" |
27 #include "chrome/common/chrome_paths.h" | 25 #include "chrome/common/chrome_paths.h" |
28 #include "chrome/common/chrome_switches.h" | 26 #include "chrome/common/chrome_switches.h" |
29 #include "chrome/common/extensions/extension_constants.h" | 27 #include "chrome/common/extensions/extension_constants.h" |
30 #include "chrome/common/features.h" | 28 #include "chrome/common/features.h" |
31 #include "chrome/grit/chromium_strings.h" | 29 #include "chrome/grit/chromium_strings.h" |
32 #include "chrome/grit/generated_resources.h" | 30 #include "chrome/grit/generated_resources.h" |
33 #include "components/crx_file/id_util.h" | 31 #include "components/crx_file/id_util.h" |
34 #include "components/signin/core/browser/signin_manager.h" | |
35 #include "components/signin/core/browser/signin_manager_base.h" | |
36 #include "components/version_info/version_info.h" | 32 #include "components/version_info/version_info.h" |
37 #include "content/public/browser/browser_thread.h" | 33 #include "content/public/browser/browser_thread.h" |
38 #include "content/public/browser/plugin_service.h" | 34 #include "content/public/browser/plugin_service.h" |
39 #include "content/public/common/content_switches.h" | 35 #include "content/public/common/content_switches.h" |
40 #include "extensions/common/constants.h" | 36 #include "extensions/common/constants.h" |
41 #include "extensions/common/extension.h" | 37 #include "extensions/common/extension.h" |
42 #include "extensions/common/extension_l10n_util.h" | 38 #include "extensions/common/extension_l10n_util.h" |
43 #include "extensions/common/file_util.h" | 39 #include "extensions/common/file_util.h" |
44 #include "extensions/common/manifest_constants.h" | 40 #include "extensions/common/manifest_constants.h" |
45 #include "grit/browser_resources.h" | 41 #include "grit/browser_resources.h" |
(...skipping 15 matching lines...) Expand all Loading... |
61 | 57 |
62 #if defined(OS_CHROMEOS) | 58 #if defined(OS_CHROMEOS) |
63 #include "chrome/browser/chromeos/accessibility/accessibility_manager.h" | 59 #include "chrome/browser/chromeos/accessibility/accessibility_manager.h" |
64 #include "chromeos/chromeos_switches.h" | 60 #include "chromeos/chromeos_switches.h" |
65 #include "content/public/browser/site_instance.h" | 61 #include "content/public/browser/site_instance.h" |
66 #include "content/public/browser/storage_partition.h" | 62 #include "content/public/browser/storage_partition.h" |
67 #include "extensions/browser/extensions_browser_client.h" | 63 #include "extensions/browser/extensions_browser_client.h" |
68 #include "storage/browser/fileapi/file_system_context.h" | 64 #include "storage/browser/fileapi/file_system_context.h" |
69 #endif | 65 #endif |
70 | 66 |
71 #if defined(ENABLE_APP_LIST) && defined(OS_CHROMEOS) | |
72 #include "chrome/browser/ui/app_list/google_now_extension.h" | |
73 #endif | |
74 | |
75 using content::BrowserThread; | 67 using content::BrowserThread; |
76 | 68 |
77 namespace extensions { | 69 namespace extensions { |
78 | 70 |
79 namespace { | 71 namespace { |
80 | 72 |
81 static bool enable_background_extensions_during_testing = false; | 73 static bool enable_background_extensions_during_testing = false; |
82 | 74 |
83 std::string GenerateId(const base::DictionaryValue* manifest, | 75 std::string GenerateId(const base::DictionaryValue* manifest, |
84 const base::FilePath& path) { | 76 const base::FilePath& path) { |
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
373 Add(IDR_IMAGE_LOADER_MANIFEST, | 365 Add(IDR_IMAGE_LOADER_MANIFEST, |
374 base::FilePath(FILE_PATH_LITERAL("image_loader"))); | 366 base::FilePath(FILE_PATH_LITERAL("image_loader"))); |
375 #endif // defined(IMAGE_LOADER_EXTENSION) | 367 #endif // defined(IMAGE_LOADER_EXTENSION) |
376 } | 368 } |
377 | 369 |
378 void ComponentLoader::AddNetworkSpeechSynthesisExtension() { | 370 void ComponentLoader::AddNetworkSpeechSynthesisExtension() { |
379 Add(IDR_NETWORK_SPEECH_SYNTHESIS_MANIFEST, | 371 Add(IDR_NETWORK_SPEECH_SYNTHESIS_MANIFEST, |
380 base::FilePath(FILE_PATH_LITERAL("network_speech_synthesis"))); | 372 base::FilePath(FILE_PATH_LITERAL("network_speech_synthesis"))); |
381 } | 373 } |
382 | 374 |
383 void ComponentLoader::AddGoogleNowExtension() { | |
384 #if BUILDFLAG(ENABLE_GOOGLE_NOW) | |
385 const char kEnablePrefix[] = "Enable"; | |
386 const char kFieldTrialName[] = "GoogleNow"; | |
387 std::string enable_prefix(kEnablePrefix); | |
388 std::string field_trial_result = | |
389 base::FieldTrialList::FindFullName(kFieldTrialName); | |
390 | |
391 bool enabled_via_field_trial = | |
392 field_trial_result.compare(0, enable_prefix.length(), enable_prefix) == 0; | |
393 | |
394 // Enable the feature on trybots and trunk builds. | |
395 bool enabled_via_trunk_build = | |
396 chrome::GetChannel() == version_info::Channel::UNKNOWN; | |
397 | |
398 bool is_authenticated = | |
399 SigninManagerFactory::GetForProfile(profile_)->IsAuthenticated(); | |
400 | |
401 bool enabled = | |
402 (enabled_via_field_trial && is_authenticated) || enabled_via_trunk_build; | |
403 | |
404 #if defined(ENABLE_APP_LIST) && defined(OS_CHROMEOS) | |
405 // Don't load if newer trial is running (== new extension id is available). | |
406 std::string ignored_extension_id; | |
407 if (GetGoogleNowExtensionId(&ignored_extension_id)) { | |
408 enabled = false; | |
409 } | |
410 #endif // defined(ENABLE_APP_LIST) && defined(OS_CHROMEOS) | |
411 | |
412 const int google_now_manifest_id = IDR_GOOGLE_NOW_MANIFEST; | |
413 const base::FilePath root_directory = | |
414 base::FilePath(FILE_PATH_LITERAL("google_now")); | |
415 if (enabled) { | |
416 Add(google_now_manifest_id, root_directory); | |
417 } else { | |
418 DeleteData(google_now_manifest_id, root_directory); | |
419 } | |
420 #endif // BUILDFLAG(ENABLE_GOOGLE_NOW) | |
421 } | |
422 | |
423 #if defined(OS_CHROMEOS) | 375 #if defined(OS_CHROMEOS) |
424 void ComponentLoader::AddChromeVoxExtension( | 376 void ComponentLoader::AddChromeVoxExtension( |
425 const base::Closure& done_cb) { | 377 const base::Closure& done_cb) { |
426 base::FilePath resources_path; | 378 base::FilePath resources_path; |
427 CHECK(PathService::Get(chrome::DIR_RESOURCES, &resources_path)); | 379 CHECK(PathService::Get(chrome::DIR_RESOURCES, &resources_path)); |
428 | 380 |
429 base::FilePath chromevox_path = | 381 base::FilePath chromevox_path = |
430 resources_path.Append(extension_misc::kChromeVoxExtensionPath); | 382 resources_path.Append(extension_misc::kChromeVoxExtensionPath); |
431 | 383 |
432 const base::FilePath::CharType* manifest_filename = | 384 const base::FilePath::CharType* manifest_filename = |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
623 AddVideoPlayerExtension(); | 575 AddVideoPlayerExtension(); |
624 AddAudioPlayerExtension(); | 576 AddAudioPlayerExtension(); |
625 AddFileManagerExtension(); | 577 AddFileManagerExtension(); |
626 AddGalleryExtension(); | 578 AddGalleryExtension(); |
627 AddWebstoreWidgetExtension(); | 579 AddWebstoreWidgetExtension(); |
628 | 580 |
629 AddHangoutServicesExtension(); | 581 AddHangoutServicesExtension(); |
630 AddHotwordAudioVerificationApp(); | 582 AddHotwordAudioVerificationApp(); |
631 AddHotwordHelperExtension(); | 583 AddHotwordHelperExtension(); |
632 AddImageLoaderExtension(); | 584 AddImageLoaderExtension(); |
633 AddGoogleNowExtension(); | |
634 | 585 |
635 bool install_feedback = enable_background_extensions_during_testing; | 586 bool install_feedback = enable_background_extensions_during_testing; |
636 #if defined(GOOGLE_CHROME_BUILD) | 587 #if defined(GOOGLE_CHROME_BUILD) |
637 install_feedback = true; | 588 install_feedback = true; |
638 #endif // defined(GOOGLE_CHROME_BUILD) | 589 #endif // defined(GOOGLE_CHROME_BUILD) |
639 if (install_feedback) | 590 if (install_feedback) |
640 Add(IDR_FEEDBACK_MANIFEST, base::FilePath(FILE_PATH_LITERAL("feedback"))); | 591 Add(IDR_FEEDBACK_MANIFEST, base::FilePath(FILE_PATH_LITERAL("feedback"))); |
641 | 592 |
642 #if defined(ENABLE_SETTINGS_APP) | 593 #if defined(ENABLE_SETTINGS_APP) |
643 Add(IDR_SETTINGS_APP_MANIFEST, | 594 Add(IDR_SETTINGS_APP_MANIFEST, |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
704 if (!enable_background_extensions_during_testing && | 655 if (!enable_background_extensions_during_testing && |
705 (command_line->HasSwitch(switches::kTestType) || | 656 (command_line->HasSwitch(switches::kTestType) || |
706 command_line->HasSwitch( | 657 command_line->HasSwitch( |
707 switches::kDisableComponentExtensionsWithBackgroundPages))) { | 658 switches::kDisableComponentExtensionsWithBackgroundPages))) { |
708 return; | 659 return; |
709 } | 660 } |
710 | 661 |
711 AddHangoutServicesExtension(); | 662 AddHangoutServicesExtension(); |
712 } | 663 } |
713 | 664 |
714 void ComponentLoader::DeleteData(int manifest_resource_id, | |
715 const base::FilePath& root_directory) { | |
716 std::string manifest_contents = | |
717 ResourceBundle::GetSharedInstance().GetRawDataResource( | |
718 manifest_resource_id).as_string(); | |
719 base::DictionaryValue* manifest = ParseManifest(manifest_contents); | |
720 if (!manifest) | |
721 return; | |
722 | |
723 ComponentExtensionInfo info(manifest, root_directory); | |
724 std::string error; | |
725 scoped_refptr<const Extension> extension(CreateExtension(info, &error)); | |
726 if (!extension.get()) { | |
727 LOG(ERROR) << error; | |
728 return; | |
729 } | |
730 | |
731 DataDeleter::StartDeleting( | |
732 profile_, extension.get(), base::Bind(base::DoNothing)); | |
733 } | |
734 | |
735 void ComponentLoader::UnloadComponent(ComponentExtensionInfo* component) { | 665 void ComponentLoader::UnloadComponent(ComponentExtensionInfo* component) { |
736 delete component->manifest; | 666 delete component->manifest; |
737 if (extension_service_->is_ready()) { | 667 if (extension_service_->is_ready()) { |
738 extension_service_-> | 668 extension_service_-> |
739 RemoveComponentExtension(component->extension_id); | 669 RemoveComponentExtension(component->extension_id); |
740 } | 670 } |
741 } | 671 } |
742 | 672 |
743 void ComponentLoader::EnableFileSystemInGuestMode(const std::string& id) { | 673 void ComponentLoader::EnableFileSystemInGuestMode(const std::string& id) { |
744 #if defined(OS_CHROMEOS) | 674 #if defined(OS_CHROMEOS) |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
789 manifest.release(), | 719 manifest.release(), |
790 root_directory, | 720 root_directory, |
791 false); | 721 false); |
792 CHECK_EQ(extension_id, actual_extension_id); | 722 CHECK_EQ(extension_id, actual_extension_id); |
793 if (!done_cb.is_null()) | 723 if (!done_cb.is_null()) |
794 done_cb.Run(); | 724 done_cb.Run(); |
795 } | 725 } |
796 #endif | 726 #endif |
797 | 727 |
798 } // namespace extensions | 728 } // namespace extensions |
OLD | NEW |