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/api/developer_private/developer_private_api.
h" | 5 #include "chrome/browser/extensions/api/developer_private/developer_private_api.
h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 #include "chrome/browser/extensions/api/developer_private/extension_info_generat
or.h" | 22 #include "chrome/browser/extensions/api/developer_private/extension_info_generat
or.h" |
23 #include "chrome/browser/extensions/api/developer_private/show_permissions_dialo
g_helper.h" | 23 #include "chrome/browser/extensions/api/developer_private/show_permissions_dialo
g_helper.h" |
24 #include "chrome/browser/extensions/api/extension_action/extension_action_api.h" | 24 #include "chrome/browser/extensions/api/extension_action/extension_action_api.h" |
25 #include "chrome/browser/extensions/devtools_util.h" | 25 #include "chrome/browser/extensions/devtools_util.h" |
26 #include "chrome/browser/extensions/extension_commands_global_registry.h" | 26 #include "chrome/browser/extensions/extension_commands_global_registry.h" |
27 #include "chrome/browser/extensions/extension_service.h" | 27 #include "chrome/browser/extensions/extension_service.h" |
28 #include "chrome/browser/extensions/extension_tab_util.h" | 28 #include "chrome/browser/extensions/extension_tab_util.h" |
29 #include "chrome/browser/extensions/extension_ui_util.h" | 29 #include "chrome/browser/extensions/extension_ui_util.h" |
30 #include "chrome/browser/extensions/extension_util.h" | 30 #include "chrome/browser/extensions/extension_util.h" |
31 #include "chrome/browser/extensions/install_verifier.h" | 31 #include "chrome/browser/extensions/install_verifier.h" |
| 32 #include "chrome/browser/extensions/path_util.h" |
32 #include "chrome/browser/extensions/scripting_permissions_modifier.h" | 33 #include "chrome/browser/extensions/scripting_permissions_modifier.h" |
33 #include "chrome/browser/extensions/shared_module_service.h" | 34 #include "chrome/browser/extensions/shared_module_service.h" |
34 #include "chrome/browser/extensions/unpacked_installer.h" | 35 #include "chrome/browser/extensions/unpacked_installer.h" |
35 #include "chrome/browser/extensions/updater/extension_updater.h" | 36 #include "chrome/browser/extensions/updater/extension_updater.h" |
36 #include "chrome/browser/extensions/webstore_reinstaller.h" | 37 #include "chrome/browser/extensions/webstore_reinstaller.h" |
37 #include "chrome/browser/platform_util.h" | 38 #include "chrome/browser/platform_util.h" |
38 #include "chrome/browser/prefs/incognito_mode_prefs.h" | 39 #include "chrome/browser/prefs/incognito_mode_prefs.h" |
39 #include "chrome/browser/profiles/profile.h" | 40 #include "chrome/browser/profiles/profile.h" |
40 #include "chrome/browser/ui/apps/app_info_dialog.h" | 41 #include "chrome/browser/ui/apps/app_info_dialog.h" |
41 #include "chrome/browser/ui/browser_finder.h" | 42 #include "chrome/browser/ui/browser_finder.h" |
42 #include "chrome/browser/ui/extensions/app_launch_params.h" | 43 #include "chrome/browser/ui/extensions/app_launch_params.h" |
43 #include "chrome/browser/ui/extensions/application_launch.h" | 44 #include "chrome/browser/ui/extensions/application_launch.h" |
44 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 45 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 46 #include "chrome/browser/ui/webui/extensions/extension_loader_handler.h" |
45 #include "chrome/common/extensions/api/developer_private.h" | 47 #include "chrome/common/extensions/api/developer_private.h" |
46 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h" | 48 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h" |
47 #include "chrome/common/pref_names.h" | 49 #include "chrome/common/pref_names.h" |
48 #include "chrome/common/url_constants.h" | 50 #include "chrome/common/url_constants.h" |
49 #include "chrome/grit/generated_resources.h" | 51 #include "chrome/grit/generated_resources.h" |
50 #include "content/public/browser/browser_thread.h" | 52 #include "content/public/browser/browser_thread.h" |
51 #include "content/public/browser/notification_service.h" | 53 #include "content/public/browser/notification_service.h" |
52 #include "content/public/browser/render_frame_host.h" | 54 #include "content/public/browser/render_frame_host.h" |
53 #include "content/public/browser/render_process_host.h" | 55 #include "content/public/browser/render_process_host.h" |
54 #include "content/public/browser/site_instance.h" | 56 #include "content/public/browser/site_instance.h" |
(...skipping 661 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
716 target_extension, | 718 target_extension, |
717 source_context_type() == Feature::WEBUI_CONTEXT, | 719 source_context_type() == Feature::WEBUI_CONTEXT, |
718 base::Bind(&DeveloperPrivateShowPermissionsDialogFunction::Finish, this)); | 720 base::Bind(&DeveloperPrivateShowPermissionsDialogFunction::Finish, this)); |
719 return RespondLater(); | 721 return RespondLater(); |
720 } | 722 } |
721 | 723 |
722 void DeveloperPrivateShowPermissionsDialogFunction::Finish() { | 724 void DeveloperPrivateShowPermissionsDialogFunction::Finish() { |
723 Respond(NoArguments()); | 725 Respond(NoArguments()); |
724 } | 726 } |
725 | 727 |
726 DeveloperPrivateLoadUnpackedFunction::DeveloperPrivateLoadUnpackedFunction() | 728 DeveloperPrivateLoadUnpackedFunction::DeveloperPrivateLoadUnpackedFunction() {} |
727 : fail_quietly_(false) { | |
728 } | |
729 | 729 |
730 ExtensionFunction::ResponseAction DeveloperPrivateLoadUnpackedFunction::Run() { | 730 ExtensionFunction::ResponseAction DeveloperPrivateLoadUnpackedFunction::Run() { |
731 std::unique_ptr<developer::LoadUnpacked::Params> params( | 731 std::unique_ptr<developer::LoadUnpacked::Params> params( |
732 developer::LoadUnpacked::Params::Create(*args_)); | 732 developer::LoadUnpacked::Params::Create(*args_)); |
733 EXTENSION_FUNCTION_VALIDATE(params); | 733 EXTENSION_FUNCTION_VALIDATE(params); |
734 | 734 |
735 if (!ShowPicker( | 735 if (!ShowPicker( |
736 ui::SelectFileDialog::SELECT_FOLDER, | 736 ui::SelectFileDialog::SELECT_FOLDER, |
737 l10n_util::GetStringUTF16(IDS_EXTENSION_LOAD_FROM_DIRECTORY), | 737 l10n_util::GetStringUTF16(IDS_EXTENSION_LOAD_FROM_DIRECTORY), |
738 ui::SelectFileDialog::FileTypeInfo(), | 738 ui::SelectFileDialog::FileTypeInfo(), |
739 0 /* file_type_index */)) { | 739 0 /* file_type_index */)) { |
740 return RespondNow(Error(kCouldNotShowSelectFileDialogError)); | 740 return RespondNow(Error(kCouldNotShowSelectFileDialogError)); |
741 } | 741 } |
742 | 742 |
743 fail_quietly_ = params->options && | 743 fail_quietly_ = params->options && |
744 params->options->fail_quietly && | 744 params->options->fail_quietly && |
745 *params->options->fail_quietly; | 745 *params->options->fail_quietly; |
746 | 746 |
| 747 populate_error_ = params->options && params->options->populate_error && |
| 748 *params->options->populate_error; |
| 749 |
747 AddRef(); // Balanced in FileSelected / FileSelectionCanceled. | 750 AddRef(); // Balanced in FileSelected / FileSelectionCanceled. |
748 return RespondLater(); | 751 return RespondLater(); |
749 } | 752 } |
750 | 753 |
751 void DeveloperPrivateLoadUnpackedFunction::FileSelected( | 754 void DeveloperPrivateLoadUnpackedFunction::FileSelected( |
752 const base::FilePath& path) { | 755 const base::FilePath& path) { |
753 scoped_refptr<UnpackedInstaller> installer( | 756 scoped_refptr<UnpackedInstaller> installer( |
754 UnpackedInstaller::Create(GetExtensionService(browser_context()))); | 757 UnpackedInstaller::Create(GetExtensionService(browser_context()))); |
755 installer->set_be_noisy_on_failure(!fail_quietly_); | 758 installer->set_be_noisy_on_failure(!fail_quietly_); |
756 installer->set_completion_callback( | 759 installer->set_completion_callback( |
757 base::Bind(&DeveloperPrivateLoadUnpackedFunction::OnLoadComplete, this)); | 760 base::Bind(&DeveloperPrivateLoadUnpackedFunction::OnLoadComplete, this)); |
758 installer->Load(path); | 761 installer->Load(path); |
759 | 762 |
760 DeveloperPrivateAPI::Get(browser_context())->SetLastUnpackedDirectory(path); | 763 DeveloperPrivateAPI::Get(browser_context())->SetLastUnpackedDirectory(path); |
761 | 764 |
762 Release(); // Balanced in Run(). | 765 Release(); // Balanced in Run(). |
763 } | 766 } |
764 | 767 |
765 void DeveloperPrivateLoadUnpackedFunction::FileSelectionCanceled() { | 768 void DeveloperPrivateLoadUnpackedFunction::FileSelectionCanceled() { |
766 // This isn't really an error, but we should keep it like this for | 769 // This isn't really an error, but we should keep it like this for |
767 // backward compatability. | 770 // backward compatability. |
768 Respond(Error(kFileSelectionCanceled)); | 771 Respond(Error(kFileSelectionCanceled)); |
769 Release(); // Balanced in Run(). | 772 Release(); // Balanced in Run(). |
770 } | 773 } |
771 | 774 |
772 void DeveloperPrivateLoadUnpackedFunction::OnLoadComplete( | 775 void DeveloperPrivateLoadUnpackedFunction::OnLoadComplete( |
773 const Extension* extension, | 776 const Extension* extension, |
774 const base::FilePath& file_path, | 777 const base::FilePath& file_path, |
775 const std::string& error) { | 778 const std::string& error) { |
776 Respond(extension ? NoArguments() : Error(error)); | 779 if (extension || !populate_error_) { |
| 780 Respond(extension ? NoArguments() : Error(error)); |
| 781 return; |
| 782 } |
| 783 |
| 784 ExtensionLoaderHandler::GetManifestError( |
| 785 error, file_path, |
| 786 base::Bind(&DeveloperPrivateLoadUnpackedFunction::OnGotManifestError, |
| 787 this)); |
| 788 } |
| 789 |
| 790 void DeveloperPrivateLoadUnpackedFunction::OnGotManifestError( |
| 791 const base::FilePath& file_path, |
| 792 const std::string& error, |
| 793 size_t line_number, |
| 794 const std::string& manifest) { |
| 795 base::FilePath prettified_path = path_util::PrettifyPath(file_path); |
| 796 |
| 797 SourceHighlighter highlighter(manifest, line_number); |
| 798 developer::LoadError response; |
| 799 response.error = error; |
| 800 response.path = base::UTF16ToUTF8(prettified_path.LossyDisplayName()); |
| 801 |
| 802 response.source = base::MakeUnique<developer::ErrorFileSource>(); |
| 803 response.source->before_highlight = highlighter.GetBeforeFeature(); |
| 804 response.source->highlight = highlighter.GetFeature(); |
| 805 response.source->after_highlight = highlighter.GetAfterFeature(); |
| 806 |
| 807 Respond(OneArgument(response.ToValue())); |
777 } | 808 } |
778 | 809 |
779 bool DeveloperPrivateChooseEntryFunction::ShowPicker( | 810 bool DeveloperPrivateChooseEntryFunction::ShowPicker( |
780 ui::SelectFileDialog::Type picker_type, | 811 ui::SelectFileDialog::Type picker_type, |
781 const base::string16& select_title, | 812 const base::string16& select_title, |
782 const ui::SelectFileDialog::FileTypeInfo& info, | 813 const ui::SelectFileDialog::FileTypeInfo& info, |
783 int file_type_index) { | 814 int file_type_index) { |
784 content::WebContents* web_contents = GetSenderWebContents(); | 815 content::WebContents* web_contents = GetSenderWebContents(); |
785 if (!web_contents) | 816 if (!web_contents) |
786 return false; | 817 return false; |
(...skipping 669 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1456 update.extension_id, update.command_name, *update.keybinding); | 1487 update.extension_id, update.command_name, *update.keybinding); |
1457 } | 1488 } |
1458 | 1489 |
1459 return RespondNow(NoArguments()); | 1490 return RespondNow(NoArguments()); |
1460 } | 1491 } |
1461 | 1492 |
1462 | 1493 |
1463 } // namespace api | 1494 } // namespace api |
1464 | 1495 |
1465 } // namespace extensions | 1496 } // namespace extensions |
OLD | NEW |