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

Side by Side Diff: chrome/browser/ui/webui/extensions/extension_loader_handler.cc

Issue 342003005: Show alert failure for reloading unpacked extensions with bad manifest (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed patch set 4 comments Created 6 years, 5 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/extensions/extension_loader_handler.h" 5 #include "chrome/browser/ui/webui/extensions/extension_loader_handler.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/memory/ref_counted.h" 10 #include "base/memory/ref_counted.h"
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 } 124 }
125 125
126 void ExtensionLoaderHandler::FileHelper::MultiFilesSelected( 126 void ExtensionLoaderHandler::FileHelper::MultiFilesSelected(
127 const std::vector<base::FilePath>& files, void* params) { 127 const std::vector<base::FilePath>& files, void* params) {
128 NOTREACHED(); 128 NOTREACHED();
129 } 129 }
130 130
131 ExtensionLoaderHandler::ExtensionLoaderHandler(Profile* profile) 131 ExtensionLoaderHandler::ExtensionLoaderHandler(Profile* profile)
132 : profile_(profile), 132 : profile_(profile),
133 file_helper_(new FileHelper(this)), 133 file_helper_(new FileHelper(this)),
134 extension_error_reporter_observer_(this),
135 display_ready_(false),
134 weak_ptr_factory_(this) { 136 weak_ptr_factory_(this) {
135 DCHECK(profile_); 137 DCHECK(profile_);
138 extension_error_reporter_observer_.Add(ExtensionErrorReporter::GetInstance());
136 } 139 }
137 140
138 ExtensionLoaderHandler::~ExtensionLoaderHandler() { 141 ExtensionLoaderHandler::~ExtensionLoaderHandler() {
139 } 142 }
140 143
141 void ExtensionLoaderHandler::GetLocalizedValues( 144 void ExtensionLoaderHandler::GetLocalizedValues(
142 content::WebUIDataSource* source) { 145 content::WebUIDataSource* source) {
143 source->AddString( 146 source->AddString(
144 "extensionLoadErrorHeading", 147 "extensionLoadErrorHeading",
145 l10n_util::GetStringUTF16(IDS_EXTENSIONS_LOAD_ERROR_HEADING)); 148 l10n_util::GetStringUTF16(IDS_EXTENSIONS_LOAD_ERROR_HEADING));
(...skipping 13 matching lines...) Expand all
159 162
160 void ExtensionLoaderHandler::RegisterMessages() { 163 void ExtensionLoaderHandler::RegisterMessages() {
161 web_ui()->RegisterMessageCallback( 164 web_ui()->RegisterMessageCallback(
162 "extensionLoaderLoadUnpacked", 165 "extensionLoaderLoadUnpacked",
163 base::Bind(&ExtensionLoaderHandler::HandleLoadUnpacked, 166 base::Bind(&ExtensionLoaderHandler::HandleLoadUnpacked,
164 weak_ptr_factory_.GetWeakPtr())); 167 weak_ptr_factory_.GetWeakPtr()));
165 web_ui()->RegisterMessageCallback( 168 web_ui()->RegisterMessageCallback(
166 "extensionLoaderRetry", 169 "extensionLoaderRetry",
167 base::Bind(&ExtensionLoaderHandler::HandleRetry, 170 base::Bind(&ExtensionLoaderHandler::HandleRetry,
168 weak_ptr_factory_.GetWeakPtr())); 171 weak_ptr_factory_.GetWeakPtr()));
172 web_ui()->RegisterMessageCallback(
173 "extensionLoaderSetDisplayLoading",
174 base::Bind(&ExtensionLoaderHandler::HandleSetDisplayLoading,
175 weak_ptr_factory_.GetWeakPtr()));
176 web_ui()->RegisterMessageCallback(
177 "extensionLoaderDisplayFailures",
178 base::Bind(&ExtensionLoaderHandler::HandleDisplayFailures,
179 weak_ptr_factory_.GetWeakPtr()));
169 } 180 }
170 181
171 void ExtensionLoaderHandler::HandleLoadUnpacked(const base::ListValue* args) { 182 void ExtensionLoaderHandler::HandleLoadUnpacked(const base::ListValue* args) {
172 DCHECK(args->empty()); 183 DCHECK(args->empty());
173 file_helper_->ChooseFile(); 184 file_helper_->ChooseFile();
174 } 185 }
175 186
176 void ExtensionLoaderHandler::HandleRetry(const base::ListValue* args) { 187 void ExtensionLoaderHandler::HandleRetry(const base::ListValue* args) {
177 DCHECK(args->empty()); 188 DCHECK(args->empty());
178 LoadUnpackedExtensionImpl(failed_path_); 189 LoadUnpackedExtensionImpl(failed_path_);
179 } 190 }
180 191
192 void ExtensionLoaderHandler::HandleSetDisplayLoading(
193 const base::ListValue* args) {
194 DCHECK(args->empty());
195 display_ready_ = false;
196 }
197
198 void ExtensionLoaderHandler::HandleDisplayFailures(
199 const base::ListValue* args) {
200 DCHECK(args->empty());
201 display_ready_ = true;
202
203 if (failures_.empty())
204 return;
205
206 FailureData* failure = failures_[0];
207 NotifyFrontendOfFailure(failure->file_path,
208 failure->error,
209 failure->line_number,
210 failure->manifest);
211
212 base::string16 list = base::UTF8ToUTF16("Additional failures:");
gpdavis 2014/06/30 19:42:52 Is this what you meant by internationalization?
Devlin 2014/06/30 21:06:42 Not quite. This changes the string from UTF8 to U
gpdavis 2014/06/30 21:41:19 Wait-- I thought you had said this needed to be i1
Devlin 2014/06/30 22:32:36 Yeah, our libraries are funky. i18n and l10n are
gpdavis 2014/06/30 23:35:11 Ah, okay, that makes sense. But since we're outso
Devlin 2014/07/01 17:02:55 _almost_ anything that's user facing. There are a
213 for (size_t i = 1; i < failures_.size(); ++i) {
214 FailureData *failure = failures_[i];
Devlin 2014/06/30 21:06:42 nit: FailureData* failure - note the asterisk posi
gpdavis 2014/06/30 21:41:19 Done.
215 list.append(base::UTF8ToUTF16("\n"));
216 list.append(failure->file_path.LossyDisplayName());
217 }
218 failures_.clear();
219 base::StringValue list_value(list);
220 web_ui()->CallJavascriptFunction(
221 "extensions.ExtensionLoader.notifyAdditional",
gpdavis 2014/06/30 19:42:52 I've been thinking about how to go about condensin
Devlin 2014/06/30 21:06:42 For this, at least as a starting point, I wouldn't
gpdavis 2014/06/30 21:41:19 Oops-- thought I responded to that. Currently, mu
Devlin 2014/06/30 22:32:36 Good point that it'd be somewhat strange for a use
gpdavis 2014/06/30 23:35:11 Yeah, you're right, that is quite an edge case. I
Devlin 2014/07/01 17:02:55 I would envision something similar, though with mo
gpdavis 2014/07/01 20:58:55 I was already mostly done with this last night bef
222 list_value);
Devlin 2014/06/30 21:06:42 nit: inline the string value construction here.
gpdavis 2014/06/30 21:41:19 Done.
223 }
224
181 void ExtensionLoaderHandler::LoadUnpackedExtensionImpl( 225 void ExtensionLoaderHandler::LoadUnpackedExtensionImpl(
182 const base::FilePath& file_path) { 226 const base::FilePath& file_path) {
183 scoped_refptr<UnpackedInstaller> installer = UnpackedInstaller::Create( 227 scoped_refptr<UnpackedInstaller> installer = UnpackedInstaller::Create(
184 ExtensionSystem::Get(profile_)->extension_service()); 228 ExtensionSystem::Get(profile_)->extension_service());
185 installer->set_on_failure_callback(
186 base::Bind(&ExtensionLoaderHandler::OnLoadFailure,
187 weak_ptr_factory_.GetWeakPtr()));
188 229
189 // We do our own error handling, so we don't want a load failure to trigger 230 // We do our own error handling, so we don't want a load failure to trigger
190 // a dialog. 231 // a dialog.
191 installer->set_be_noisy_on_failure(false); 232 installer->set_be_noisy_on_failure(false);
192 233
193 installer->Load(file_path); 234 installer->Load(file_path);
194 } 235 }
195 236
196 void ExtensionLoaderHandler::OnLoadFailure(const base::FilePath& file_path, 237 void ExtensionLoaderHandler::OnLoadFailure(const base::FilePath& file_path,
197 const std::string& error) { 238 const std::string& error) {
(...skipping 22 matching lines...) Expand all
220 file_path, 261 file_path,
221 error, 262 error,
222 line)); 263 line));
223 } 264 }
224 265
225 void ExtensionLoaderHandler::NotifyFrontendOfFailure( 266 void ExtensionLoaderHandler::NotifyFrontendOfFailure(
226 const base::FilePath& file_path, 267 const base::FilePath& file_path,
227 const std::string& error, 268 const std::string& error,
228 size_t line_number, 269 size_t line_number,
229 const std::string& manifest) { 270 const std::string& manifest) {
271 // If the extensions page is not loaded, delay frontend notification.
272 if (!display_ready_) {
273 FailureData* failure = new FailureData(file_path,
274 error,
275 line_number,
276 manifest);
277 failures_.push_back(failure);
Devlin 2014/06/30 21:06:42 nit: inline the failuredata construction here.
gpdavis 2014/06/30 21:41:19 Done.
278 return;
279 }
280
230 base::StringValue file_value(file_path.LossyDisplayName()); 281 base::StringValue file_value(file_path.LossyDisplayName());
231 base::StringValue error_value(base::UTF8ToUTF16(error)); 282 base::StringValue error_value(base::UTF8ToUTF16(error));
232 283
233 base::DictionaryValue manifest_value; 284 base::DictionaryValue manifest_value;
234 SourceHighlighter highlighter(manifest, line_number); 285 SourceHighlighter highlighter(manifest, line_number);
235 // If the line number is 0, this highlights no regions, but still adds the 286 // If the line number is 0, this highlights no regions, but still adds the
236 // full manifest. 287 // full manifest.
237 highlighter.SetHighlightedRegions(&manifest_value); 288 highlighter.SetHighlightedRegions(&manifest_value);
238 289
239 web_ui()->CallJavascriptFunction( 290 web_ui()->CallJavascriptFunction(
240 "extensions.ExtensionLoader.notifyLoadFailed", 291 "extensions.ExtensionLoader.notifyLoadFailed",
241 file_value, 292 file_value,
242 error_value, 293 error_value,
243 manifest_value); 294 manifest_value);
244 } 295 }
245 296
246 } // namespace extensions 297 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698