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

Side by Side Diff: chrome/browser/ui/webui/options/pack_extension_handler.cc

Issue 9703039: Extensions: Don't pass the selected unpacked extension path from JS to C++ (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Review fixes. Created 8 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 | Annotate | Revision Log
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/ui/webui/options/pack_extension_handler.h" 5 #include "chrome/browser/ui/webui/options/pack_extension_handler.h"
6 6
7 #include "chrome/browser/extensions/extension_creator.h" 7 #include "chrome/browser/extensions/extension_creator.h"
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/utf_string_conversions.h" 9 #include "base/utf_string_conversions.h"
10 #include "content/public/browser/web_contents.h"
11 #include "content/public/browser/web_contents_view.h"
10 #include "content/public/browser/web_ui.h" 12 #include "content/public/browser/web_ui.h"
11 #include "grit/generated_resources.h" 13 #include "grit/generated_resources.h"
12 #include "ui/base/l10n/l10n_util.h" 14 #include "ui/base/l10n/l10n_util.h"
13 15
14 PackExtensionHandler::PackExtensionHandler() { 16 PackExtensionHandler::PackExtensionHandler() {
15 } 17 }
16 18
17 PackExtensionHandler::~PackExtensionHandler() { 19 PackExtensionHandler::~PackExtensionHandler() {
20 // There may be pending file dialogs, we need to tell them that we've gone
21 // away so they don't try and call back to us.
22 if (load_extension_dialog_)
23 load_extension_dialog_->ListenerDestroyed();
24
18 if (pack_job_.get()) 25 if (pack_job_.get())
19 pack_job_->ClearClient(); 26 pack_job_->ClearClient();
20 } 27 }
21 28
22 void PackExtensionHandler::Initialize() { 29 void PackExtensionHandler::Initialize() {
23 } 30 }
24 31
25 void PackExtensionHandler::GetLocalizedValues( 32 void PackExtensionHandler::GetLocalizedValues(
26 DictionaryValue* localized_strings) { 33 DictionaryValue* localized_strings) {
27 DCHECK(localized_strings); 34 DCHECK(localized_strings);
(...skipping 17 matching lines...) Expand all
45 l10n_util::GetStringUTF16(IDS_EXTENSION_PACK_DIALOG_BROWSE)); 52 l10n_util::GetStringUTF16(IDS_EXTENSION_PACK_DIALOG_BROWSE));
46 localized_strings->SetString("packExtensionProceedAnyway", 53 localized_strings->SetString("packExtensionProceedAnyway",
47 l10n_util::GetStringUTF16(IDS_EXTENSION_PROCEED_ANYWAY)); 54 l10n_util::GetStringUTF16(IDS_EXTENSION_PROCEED_ANYWAY));
48 localized_strings->SetString("packExtensionWarningTitle", 55 localized_strings->SetString("packExtensionWarningTitle",
49 l10n_util::GetStringUTF16(IDS_EXTENSION_PACK_WARNING_TITLE)); 56 l10n_util::GetStringUTF16(IDS_EXTENSION_PACK_WARNING_TITLE));
50 localized_strings->SetString("packExtensionErrorTitle", 57 localized_strings->SetString("packExtensionErrorTitle",
51 l10n_util::GetStringUTF16(IDS_EXTENSION_PACK_ERROR_TITLE)); 58 l10n_util::GetStringUTF16(IDS_EXTENSION_PACK_ERROR_TITLE));
52 } 59 }
53 60
54 void PackExtensionHandler::RegisterMessages() { 61 void PackExtensionHandler::RegisterMessages() {
55 // Setup handlers specific to this panel. 62 web_ui()->RegisterMessageCallback(
56 web_ui()->RegisterMessageCallback("pack", 63 "pack",
57 base::Bind(&PackExtensionHandler::HandlePackMessage, 64 base::Bind(&PackExtensionHandler::HandlePackMessage,
58 base::Unretained(this))); 65 base::Unretained(this)));
66 web_ui()->RegisterMessageCallback(
67 "packExtensionSelectFilePath",
68 base::Bind(&PackExtensionHandler::HandleSelectFilePathMessage,
69 base::Unretained(this)));
59 } 70 }
60 71
61 void PackExtensionHandler::OnPackSuccess(const FilePath& crx_file, 72 void PackExtensionHandler::OnPackSuccess(const FilePath& crx_file,
62 const FilePath& pem_file) { 73 const FilePath& pem_file) {
63 ListValue arguments; 74 ListValue arguments;
64 arguments.Append(Value::CreateStringValue( 75 arguments.Append(Value::CreateStringValue(
65 UTF16ToUTF8(PackExtensionJob::StandardSuccessMessage(crx_file, 76 UTF16ToUTF8(PackExtensionJob::StandardSuccessMessage(crx_file,
66 pem_file)))); 77 pem_file))));
67 web_ui()->CallJavascriptFunction( 78 web_ui()->CallJavascriptFunction(
68 "PackExtensionOverlay.showSuccessMessage", arguments); 79 "PackExtensionOverlay.showSuccessMessage", arguments);
69 } 80 }
70 81
71 void PackExtensionHandler::OnPackFailure(const std::string& error, 82 void PackExtensionHandler::OnPackFailure(const std::string& error,
72 ExtensionCreator::ErrorType type) { 83 ExtensionCreator::ErrorType type) {
73 if (type == ExtensionCreator::kCRXExists) { 84 if (type == ExtensionCreator::kCRXExists) {
74 base::StringValue error_str(error); 85 base::StringValue error_str(error);
75 base::StringValue extension_path_str(extension_path_); 86 base::StringValue extension_path_str(extension_path_);
76 base::StringValue key_path_str(private_key_path_); 87 base::StringValue key_path_str(private_key_path_);
77 base::FundamentalValue overwrite_flag(ExtensionCreator::kOverwriteCRX); 88 base::FundamentalValue overwrite_flag(ExtensionCreator::kOverwriteCRX);
78 89
79 web_ui()->CallJavascriptFunction( 90 web_ui()->CallJavascriptFunction(
80 "ExtensionSettings.askToOverrideWarning", error_str, extension_path_str, 91 "ExtensionSettings.askToOverrideWarning", error_str, extension_path_str,
81 key_path_str, overwrite_flag); 92 key_path_str, overwrite_flag);
82 } else { 93 } else {
83 ShowAlert(error); 94 ShowAlert(error);
84 } 95 }
85 } 96 }
86 97
98 void PackExtensionHandler::FileSelected(const FilePath& path, int index,
99 void* params) {
100 ListValue results;
101 results.Append(Value::CreateStringValue(path.value()));
102 web_ui()->CallJavascriptFunction("window.handleFilePathSelected", results);
103 }
104
105 void PackExtensionHandler::MultiFilesSelected(
106 const std::vector<FilePath>& files, void* params) {
107 NOTREACHED();
108 }
109
87 void PackExtensionHandler::HandlePackMessage(const ListValue* args) { 110 void PackExtensionHandler::HandlePackMessage(const ListValue* args) {
88 111
89 CHECK_EQ(3U, args->GetSize()); 112 DCHECK_EQ(3U, args->GetSize());
90 CHECK(args->GetString(0, &extension_path_)); 113
91 CHECK(args->GetString(1, &private_key_path_)); 114 if (!args->GetString(0, &extension_path_) ||
115 !args->GetString(1, &private_key_path_))
Evan Stade 2012/03/20 19:56:07 curlies
James Hawkins 2012/03/23 21:49:38 The C++ style guide does not require braces for mu
Evan Stade 2012/03/23 21:54:09 chrome convention, supported by style guide: "cond
James Hawkins 2012/03/23 22:04:34 OK, then it's an 'Optional nit'. I've seen plenty
116 NOTREACHED();
92 117
93 double flags_double = 0.0; 118 double flags_double = 0.0;
94 CHECK(args->GetDouble(2, &flags_double)); 119 if (!args->GetDouble(2, &flags_double))
120 NOTREACHED();
121
95 int run_flags = static_cast<int>(flags_double); 122 int run_flags = static_cast<int>(flags_double);
96 123
97 FilePath root_directory = 124 FilePath root_directory =
98 FilePath::FromWStringHack(UTF8ToWide(extension_path_)); 125 FilePath::FromWStringHack(UTF8ToWide(extension_path_));
99 FilePath key_file = FilePath::FromWStringHack(UTF8ToWide(private_key_path_)); 126 FilePath key_file = FilePath::FromWStringHack(UTF8ToWide(private_key_path_));
100 127
101 if (root_directory.empty()) { 128 if (root_directory.empty()) {
102 if (extension_path_.empty()) { 129 if (extension_path_.empty()) {
103 ShowAlert(l10n_util::GetStringUTF8( 130 ShowAlert(l10n_util::GetStringUTF8(
104 IDS_EXTENSION_PACK_DIALOG_ERROR_ROOT_REQUIRED)); 131 IDS_EXTENSION_PACK_DIALOG_ERROR_ROOT_REQUIRED));
105 } else { 132 } else {
106 ShowAlert(l10n_util::GetStringUTF8( 133 ShowAlert(l10n_util::GetStringUTF8(
107 IDS_EXTENSION_PACK_DIALOG_ERROR_ROOT_INVALID)); 134 IDS_EXTENSION_PACK_DIALOG_ERROR_ROOT_INVALID));
108 } 135 }
109 136
110 return; 137 return;
111 } 138 }
112 139
113 if (!private_key_path_.empty() && key_file.empty()) { 140 if (!private_key_path_.empty() && key_file.empty()) {
114 ShowAlert(l10n_util::GetStringUTF8( 141 ShowAlert(l10n_util::GetStringUTF8(
115 IDS_EXTENSION_PACK_DIALOG_ERROR_KEY_INVALID)); 142 IDS_EXTENSION_PACK_DIALOG_ERROR_KEY_INVALID));
116 return; 143 return;
117 } 144 }
118 145
119 pack_job_ = new PackExtensionJob(this, root_directory, key_file, run_flags); 146 pack_job_ = new PackExtensionJob(this, root_directory, key_file, run_flags);
120 pack_job_->Start(); 147 pack_job_->Start();
121 } 148 }
122 149
150 void PackExtensionHandler::HandleSelectFilePathMessage(
151 const ListValue* args) {
152 DCHECK_EQ(2U, args->GetSize());
153
154 std::string select_type;
155 if (!args->GetString(0, &select_type))
156 NOTREACHED();
157
158 std::string operation;
159 if (!args->GetString(1, &operation))
160 NOTREACHED();
161
162 SelectFileDialog::Type type = SelectFileDialog::SELECT_FOLDER;
163 SelectFileDialog::FileTypeInfo info;
164 int file_type_index = 0;
165 if (select_type == "file")
166 type = SelectFileDialog::SELECT_OPEN_FILE;
167
168 string16 select_title;
169 if (operation == "load") {
170 select_title = l10n_util::GetStringUTF16(IDS_EXTENSION_LOAD_FROM_DIRECTORY);
171 } else if (operation == "pem") {
172 select_title = l10n_util::GetStringUTF16(
173 IDS_EXTENSION_PACK_DIALOG_SELECT_KEY);
174 info.extensions.push_back(std::vector<FilePath::StringType>());
175 info.extensions.front().push_back(FILE_PATH_LITERAL("pem"));
176 info.extension_description_overrides.push_back(
177 l10n_util::GetStringUTF16(
178 IDS_EXTENSION_PACK_DIALOG_KEY_FILE_TYPE_DESCRIPTION));
179 info.include_all_files = true;
180 file_type_index = 1;
181 } else {
182 NOTREACHED();
183 }
184
185 load_extension_dialog_ = SelectFileDialog::Create(this);
186 load_extension_dialog_->SelectFile(
187 type, select_title, FilePath(), &info, file_type_index,
188 FILE_PATH_LITERAL(""), web_ui()->GetWebContents(),
189 web_ui()->GetWebContents()->GetView()->GetTopLevelNativeWindow(), NULL);
190 }
191
123 void PackExtensionHandler::ShowAlert(const std::string& message) { 192 void PackExtensionHandler::ShowAlert(const std::string& message) {
124 ListValue arguments; 193 ListValue arguments;
125 arguments.Append(Value::CreateStringValue(message)); 194 arguments.Append(Value::CreateStringValue(message));
126 web_ui()->CallJavascriptFunction("PackExtensionOverlay.showError", arguments); 195 web_ui()->CallJavascriptFunction("PackExtensionOverlay.showError", arguments);
127 } 196 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/options/pack_extension_handler.h ('k') | chrome/browser/ui/webui/options2/options_ui2.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698