Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(261)

Side by Side Diff: chrome/browser/extensions/api/developer_private/developer_private_api.cc

Issue 979453002: [Extensions] Make chrome://extensions use developerPrivate for unpacked loading (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "apps/app_load_service.h" 7 #include "apps/app_load_service.h"
8 #include "apps/saved_files_service.h" 8 #include "apps/saved_files_service.h"
9 #include "base/base64.h" 9 #include "base/base64.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 27 matching lines...) Expand all
38 #include "chrome/common/extensions/api/developer_private.h" 38 #include "chrome/common/extensions/api/developer_private.h"
39 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h" 39 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h"
40 #include "chrome/common/url_constants.h" 40 #include "chrome/common/url_constants.h"
41 #include "chrome/grit/generated_resources.h" 41 #include "chrome/grit/generated_resources.h"
42 #include "content/public/browser/browser_thread.h" 42 #include "content/public/browser/browser_thread.h"
43 #include "content/public/browser/notification_service.h" 43 #include "content/public/browser/notification_service.h"
44 #include "content/public/browser/render_process_host.h" 44 #include "content/public/browser/render_process_host.h"
45 #include "content/public/browser/render_view_host.h" 45 #include "content/public/browser/render_view_host.h"
46 #include "content/public/browser/site_instance.h" 46 #include "content/public/browser/site_instance.h"
47 #include "content/public/browser/storage_partition.h" 47 #include "content/public/browser/storage_partition.h"
48 #include "content/public/browser/user_metrics.h"
48 #include "content/public/browser/web_contents.h" 49 #include "content/public/browser/web_contents.h"
49 #include "extensions/browser/api/device_permissions_manager.h" 50 #include "extensions/browser/api/device_permissions_manager.h"
50 #include "extensions/browser/app_window/app_window.h" 51 #include "extensions/browser/app_window/app_window.h"
51 #include "extensions/browser/app_window/app_window_registry.h" 52 #include "extensions/browser/app_window/app_window_registry.h"
52 #include "extensions/browser/extension_error.h" 53 #include "extensions/browser/extension_error.h"
53 #include "extensions/browser/extension_prefs.h" 54 #include "extensions/browser/extension_prefs.h"
54 #include "extensions/browser/extension_registry.h" 55 #include "extensions/browser/extension_registry.h"
55 #include "extensions/browser/extension_system.h" 56 #include "extensions/browser/extension_system.h"
56 #include "extensions/browser/management_policy.h" 57 #include "extensions/browser/management_policy.h"
57 #include "extensions/browser/notification_types.h" 58 #include "extensions/browser/notification_types.h"
(...skipping 691 matching lines...) Expand 10 before | Expand all | Expand 10 after
749 ~DeveloperPrivateAllowIncognitoFunction() {} 750 ~DeveloperPrivateAllowIncognitoFunction() {}
750 751
751 ExtensionFunction::ResponseAction DeveloperPrivateReloadFunction::Run() { 752 ExtensionFunction::ResponseAction DeveloperPrivateReloadFunction::Run() {
752 scoped_ptr<Reload::Params> params(Reload::Params::Create(*args_)); 753 scoped_ptr<Reload::Params> params(Reload::Params::Create(*args_));
753 EXTENSION_FUNCTION_VALIDATE(params.get()); 754 EXTENSION_FUNCTION_VALIDATE(params.get());
754 755
755 const Extension* extension = GetExtensionById(params->extension_id); 756 const Extension* extension = GetExtensionById(params->extension_id);
756 if (!extension) 757 if (!extension)
757 return RespondNow(Error(kNoSuchExtensionError)); 758 return RespondNow(Error(kNoSuchExtensionError));
758 759
759 bool fail_quietly = params->options && params->options->fail_quietly; 760 bool fail_quietly = params->options &&
761 params->options->fail_quietly &&
762 *params->options->fail_quietly;
760 763
761 ExtensionService* service = GetExtensionService(browser_context()); 764 ExtensionService* service = GetExtensionService(browser_context());
762 if (fail_quietly) 765 if (fail_quietly)
763 service->ReloadExtensionWithQuietFailure(params->extension_id); 766 service->ReloadExtensionWithQuietFailure(params->extension_id);
764 else 767 else
765 service->ReloadExtension(params->extension_id); 768 service->ReloadExtension(params->extension_id);
766 769
767 // TODO(devlin): We shouldn't return until the extension has finished trying 770 // TODO(devlin): We shouldn't return until the extension has finished trying
768 // to reload (and then we could also return the error). 771 // to reload (and then we could also return the error).
769 return RespondNow(NoArguments()); 772 return RespondNow(NoArguments());
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
864 return false; 867 return false;
865 } 868 }
866 869
867 DevToolsWindow::OpenDevToolsWindow( 870 DevToolsWindow::OpenDevToolsWindow(
868 content::WebContents::FromRenderViewHost(host)); 871 content::WebContents::FromRenderViewHost(host));
869 return true; 872 return true;
870 } 873 }
871 874
872 DeveloperPrivateInspectFunction::~DeveloperPrivateInspectFunction() {} 875 DeveloperPrivateInspectFunction::~DeveloperPrivateInspectFunction() {}
873 876
877 DeveloperPrivateLoadUnpackedFunction::DeveloperPrivateLoadUnpackedFunction()
878 : fail_quietly_(false) {
879 }
880
874 ExtensionFunction::ResponseAction DeveloperPrivateLoadUnpackedFunction::Run() { 881 ExtensionFunction::ResponseAction DeveloperPrivateLoadUnpackedFunction::Run() {
882 scoped_ptr<developer_private::LoadUnpacked::Params> params(
883 developer_private::LoadUnpacked::Params::Create(*args_));
884 EXTENSION_FUNCTION_VALIDATE(params);
885
875 if (!ShowPicker( 886 if (!ShowPicker(
876 ui::SelectFileDialog::SELECT_FOLDER, 887 ui::SelectFileDialog::SELECT_FOLDER,
877 l10n_util::GetStringUTF16(IDS_EXTENSION_LOAD_FROM_DIRECTORY), 888 l10n_util::GetStringUTF16(IDS_EXTENSION_LOAD_FROM_DIRECTORY),
878 ui::SelectFileDialog::FileTypeInfo(), 889 ui::SelectFileDialog::FileTypeInfo(),
879 0 /* file_type_index */)) { 890 0 /* file_type_index */)) {
880 return RespondNow(Error(kCouldNotShowSelectFileDialogError)); 891 return RespondNow(Error(kCouldNotShowSelectFileDialogError));
881 } 892 }
882 893
894 // If this call came from the web ui, we record it.
not at google - send to devlin 2015/03/03 22:22:10 Why only from the web UI? - if it's because we're
Devlin 2015/03/04 17:29:12 Was gonna ask about this. Happy to remove.
895 if (!extension())
896 content::RecordComputedAction("Options_LoadUnpackedExtension");
897
898 fail_quietly_ = params->options &&
899 params->options->fail_quietly &&
900 *params->options->fail_quietly;
901
883 AddRef(); // Balanced in FileSelected / FileSelectionCanceled. 902 AddRef(); // Balanced in FileSelected / FileSelectionCanceled.
884 return RespondLater(); 903 return RespondLater();
885 } 904 }
886 905
887 void DeveloperPrivateLoadUnpackedFunction::FileSelected( 906 void DeveloperPrivateLoadUnpackedFunction::FileSelected(
888 const base::FilePath& path) { 907 const base::FilePath& path) {
889 UnpackedInstaller::Create(GetExtensionService(browser_context()))->Load(path); 908 scoped_refptr<UnpackedInstaller> installer(
909 UnpackedInstaller::Create(GetExtensionService(browser_context())));
910 installer->set_be_noisy_on_failure(!fail_quietly_);
911 installer->set_completion_callback(
912 base::Bind(&DeveloperPrivateLoadUnpackedFunction::OnLoadComplete, this));
913 installer->Load(path);
914
890 DeveloperPrivateAPI::Get(browser_context())->SetLastUnpackedDirectory(path); 915 DeveloperPrivateAPI::Get(browser_context())->SetLastUnpackedDirectory(path);
891 // TODO(devlin): Shouldn't we wait until the extension is loaded? 916
892 Respond(NoArguments());
893 Release(); // Balanced in Run(). 917 Release(); // Balanced in Run().
894 } 918 }
895 919
896 void DeveloperPrivateLoadUnpackedFunction::FileSelectionCanceled() { 920 void DeveloperPrivateLoadUnpackedFunction::FileSelectionCanceled() {
897 // This isn't really an error, but we should keep it like this for 921 // This isn't really an error, but we should keep it like this for
898 // backward compatability. 922 // backward compatability.
899 Respond(Error(kFileSelectionCanceled)); 923 Respond(Error(kFileSelectionCanceled));
900 Release(); // Balanced in Run(). 924 Release(); // Balanced in Run().
901 } 925 }
902 926
927 void DeveloperPrivateLoadUnpackedFunction::OnLoadComplete(
928 const Extension* extension,
929 const base::FilePath& file_path,
930 const std::string& error) {
931 Respond(extension ? NoArguments() : Error(error));
932 }
933
903 bool DeveloperPrivateChooseEntryFunction::ShowPicker( 934 bool DeveloperPrivateChooseEntryFunction::ShowPicker(
904 ui::SelectFileDialog::Type picker_type, 935 ui::SelectFileDialog::Type picker_type,
905 const base::string16& select_title, 936 const base::string16& select_title,
906 const ui::SelectFileDialog::FileTypeInfo& info, 937 const ui::SelectFileDialog::FileTypeInfo& info,
907 int file_type_index) { 938 int file_type_index) {
908 content::WebContents* web_contents = GetSenderWebContents(); 939 content::WebContents* web_contents = GetSenderWebContents();
909 if (!web_contents) 940 if (!web_contents)
910 return false; 941 return false;
911 942
912 // The entry picker will hold a reference to this function instance, 943 // The entry picker will hold a reference to this function instance,
(...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after
1344 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0u, &dict)); 1375 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0u, &dict));
1345 1376
1346 error_ui_util::HandleOpenDevTools(dict); 1377 error_ui_util::HandleOpenDevTools(dict);
1347 1378
1348 return true; 1379 return true;
1349 } 1380 }
1350 1381
1351 } // namespace api 1382 } // namespace api
1352 1383
1353 } // namespace extensions 1384 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698