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

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: Comments 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 738 matching lines...) Expand 10 before | Expand all | Expand 10 after
749 ~DeveloperPrivateAllowIncognitoFunction() {} 749 ~DeveloperPrivateAllowIncognitoFunction() {}
750 750
751 ExtensionFunction::ResponseAction DeveloperPrivateReloadFunction::Run() { 751 ExtensionFunction::ResponseAction DeveloperPrivateReloadFunction::Run() {
752 scoped_ptr<Reload::Params> params(Reload::Params::Create(*args_)); 752 scoped_ptr<Reload::Params> params(Reload::Params::Create(*args_));
753 EXTENSION_FUNCTION_VALIDATE(params.get()); 753 EXTENSION_FUNCTION_VALIDATE(params.get());
754 754
755 const Extension* extension = GetExtensionById(params->extension_id); 755 const Extension* extension = GetExtensionById(params->extension_id);
756 if (!extension) 756 if (!extension)
757 return RespondNow(Error(kNoSuchExtensionError)); 757 return RespondNow(Error(kNoSuchExtensionError));
758 758
759 bool fail_quietly = params->options && params->options->fail_quietly; 759 bool fail_quietly = params->options &&
760 params->options->fail_quietly &&
761 *params->options->fail_quietly;
760 762
761 ExtensionService* service = GetExtensionService(browser_context()); 763 ExtensionService* service = GetExtensionService(browser_context());
762 if (fail_quietly) 764 if (fail_quietly)
763 service->ReloadExtensionWithQuietFailure(params->extension_id); 765 service->ReloadExtensionWithQuietFailure(params->extension_id);
764 else 766 else
765 service->ReloadExtension(params->extension_id); 767 service->ReloadExtension(params->extension_id);
766 768
767 // TODO(devlin): We shouldn't return until the extension has finished trying 769 // TODO(devlin): We shouldn't return until the extension has finished trying
768 // to reload (and then we could also return the error). 770 // to reload (and then we could also return the error).
769 return RespondNow(NoArguments()); 771 return RespondNow(NoArguments());
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
864 return false; 866 return false;
865 } 867 }
866 868
867 DevToolsWindow::OpenDevToolsWindow( 869 DevToolsWindow::OpenDevToolsWindow(
868 content::WebContents::FromRenderViewHost(host)); 870 content::WebContents::FromRenderViewHost(host));
869 return true; 871 return true;
870 } 872 }
871 873
872 DeveloperPrivateInspectFunction::~DeveloperPrivateInspectFunction() {} 874 DeveloperPrivateInspectFunction::~DeveloperPrivateInspectFunction() {}
873 875
876 DeveloperPrivateLoadUnpackedFunction::DeveloperPrivateLoadUnpackedFunction()
877 : fail_quietly_(false) {
878 }
879
874 ExtensionFunction::ResponseAction DeveloperPrivateLoadUnpackedFunction::Run() { 880 ExtensionFunction::ResponseAction DeveloperPrivateLoadUnpackedFunction::Run() {
881 scoped_ptr<developer_private::LoadUnpacked::Params> params(
882 developer_private::LoadUnpacked::Params::Create(*args_));
883 EXTENSION_FUNCTION_VALIDATE(params);
884
875 if (!ShowPicker( 885 if (!ShowPicker(
876 ui::SelectFileDialog::SELECT_FOLDER, 886 ui::SelectFileDialog::SELECT_FOLDER,
877 l10n_util::GetStringUTF16(IDS_EXTENSION_LOAD_FROM_DIRECTORY), 887 l10n_util::GetStringUTF16(IDS_EXTENSION_LOAD_FROM_DIRECTORY),
878 ui::SelectFileDialog::FileTypeInfo(), 888 ui::SelectFileDialog::FileTypeInfo(),
879 0 /* file_type_index */)) { 889 0 /* file_type_index */)) {
880 return RespondNow(Error(kCouldNotShowSelectFileDialogError)); 890 return RespondNow(Error(kCouldNotShowSelectFileDialogError));
881 } 891 }
882 892
893 fail_quietly_ = params->options &&
894 params->options->fail_quietly &&
895 *params->options->fail_quietly;
896
883 AddRef(); // Balanced in FileSelected / FileSelectionCanceled. 897 AddRef(); // Balanced in FileSelected / FileSelectionCanceled.
884 return RespondLater(); 898 return RespondLater();
885 } 899 }
886 900
887 void DeveloperPrivateLoadUnpackedFunction::FileSelected( 901 void DeveloperPrivateLoadUnpackedFunction::FileSelected(
888 const base::FilePath& path) { 902 const base::FilePath& path) {
889 UnpackedInstaller::Create(GetExtensionService(browser_context()))->Load(path); 903 scoped_refptr<UnpackedInstaller> installer(
904 UnpackedInstaller::Create(GetExtensionService(browser_context())));
905 installer->set_be_noisy_on_failure(!fail_quietly_);
906 installer->set_completion_callback(
907 base::Bind(&DeveloperPrivateLoadUnpackedFunction::OnLoadComplete, this));
908 installer->Load(path);
909
890 DeveloperPrivateAPI::Get(browser_context())->SetLastUnpackedDirectory(path); 910 DeveloperPrivateAPI::Get(browser_context())->SetLastUnpackedDirectory(path);
891 // TODO(devlin): Shouldn't we wait until the extension is loaded? 911
892 Respond(NoArguments());
893 Release(); // Balanced in Run(). 912 Release(); // Balanced in Run().
894 } 913 }
895 914
896 void DeveloperPrivateLoadUnpackedFunction::FileSelectionCanceled() { 915 void DeveloperPrivateLoadUnpackedFunction::FileSelectionCanceled() {
897 // This isn't really an error, but we should keep it like this for 916 // This isn't really an error, but we should keep it like this for
898 // backward compatability. 917 // backward compatability.
899 Respond(Error(kFileSelectionCanceled)); 918 Respond(Error(kFileSelectionCanceled));
900 Release(); // Balanced in Run(). 919 Release(); // Balanced in Run().
901 } 920 }
902 921
922 void DeveloperPrivateLoadUnpackedFunction::OnLoadComplete(
923 const Extension* extension,
924 const base::FilePath& file_path,
925 const std::string& error) {
926 Respond(extension ? NoArguments() : Error(error));
927 }
928
903 bool DeveloperPrivateChooseEntryFunction::ShowPicker( 929 bool DeveloperPrivateChooseEntryFunction::ShowPicker(
904 ui::SelectFileDialog::Type picker_type, 930 ui::SelectFileDialog::Type picker_type,
905 const base::string16& select_title, 931 const base::string16& select_title,
906 const ui::SelectFileDialog::FileTypeInfo& info, 932 const ui::SelectFileDialog::FileTypeInfo& info,
907 int file_type_index) { 933 int file_type_index) {
908 content::WebContents* web_contents = GetSenderWebContents(); 934 content::WebContents* web_contents = GetSenderWebContents();
909 if (!web_contents) 935 if (!web_contents)
910 return false; 936 return false;
911 937
912 // The entry picker will hold a reference to this function instance, 938 // 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)); 1370 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0u, &dict));
1345 1371
1346 error_ui_util::HandleOpenDevTools(dict); 1372 error_ui_util::HandleOpenDevTools(dict);
1347 1373
1348 return true; 1374 return true;
1349 } 1375 }
1350 1376
1351 } // namespace api 1377 } // namespace api
1352 1378
1353 } // namespace extensions 1379 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698