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

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: Fixed be_noisy, support interaction with multiple failures 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 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 void ExtensionLoaderHandler::FileHelper::FileSelected( 121 void ExtensionLoaderHandler::FileHelper::FileSelected(
122 const base::FilePath& path, int index, void* params) { 122 const base::FilePath& path, int index, void* params) {
123 loader_handler_->LoadUnpackedExtensionImpl(path); 123 loader_handler_->LoadUnpackedExtensionImpl(path);
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::FailureData::FailureData(base::FilePath file_path,
132 std::string error,
133 size_t line_number,
134 std::string manifest)
135 : file_path(file_path),
136 error(error),
137 line_number(line_number),
138 manifest(manifest) {}
139
131 ExtensionLoaderHandler::ExtensionLoaderHandler(Profile* profile) 140 ExtensionLoaderHandler::ExtensionLoaderHandler(Profile* profile)
132 : profile_(profile), 141 : profile_(profile),
133 file_helper_(new FileHelper(this)), 142 file_helper_(new FileHelper(this)),
143 extension_error_reporter_observer_(this),
144 display_ready_(false),
134 weak_ptr_factory_(this) { 145 weak_ptr_factory_(this) {
135 DCHECK(profile_); 146 DCHECK(profile_);
147 extension_error_reporter_observer_.Add(ExtensionErrorReporter::GetInstance());
136 } 148 }
137 149
138 ExtensionLoaderHandler::~ExtensionLoaderHandler() { 150 ExtensionLoaderHandler::~ExtensionLoaderHandler() {
139 } 151 }
140 152
141 void ExtensionLoaderHandler::GetLocalizedValues( 153 void ExtensionLoaderHandler::GetLocalizedValues(
142 content::WebUIDataSource* source) { 154 content::WebUIDataSource* source) {
143 source->AddString( 155 source->AddString(
144 "extensionLoadErrorHeading", 156 "extensionLoadErrorHeading",
145 l10n_util::GetStringUTF16(IDS_EXTENSIONS_LOAD_ERROR_HEADING)); 157 l10n_util::GetStringUTF16(IDS_EXTENSIONS_LOAD_ERROR_HEADING));
(...skipping 13 matching lines...) Expand all
159 171
160 void ExtensionLoaderHandler::RegisterMessages() { 172 void ExtensionLoaderHandler::RegisterMessages() {
161 web_ui()->RegisterMessageCallback( 173 web_ui()->RegisterMessageCallback(
162 "extensionLoaderLoadUnpacked", 174 "extensionLoaderLoadUnpacked",
163 base::Bind(&ExtensionLoaderHandler::HandleLoadUnpacked, 175 base::Bind(&ExtensionLoaderHandler::HandleLoadUnpacked,
164 weak_ptr_factory_.GetWeakPtr())); 176 weak_ptr_factory_.GetWeakPtr()));
165 web_ui()->RegisterMessageCallback( 177 web_ui()->RegisterMessageCallback(
166 "extensionLoaderRetry", 178 "extensionLoaderRetry",
167 base::Bind(&ExtensionLoaderHandler::HandleRetry, 179 base::Bind(&ExtensionLoaderHandler::HandleRetry,
168 weak_ptr_factory_.GetWeakPtr())); 180 weak_ptr_factory_.GetWeakPtr()));
181 web_ui()->RegisterMessageCallback(
182 "extensionLoaderSetDisplayLoading",
183 base::Bind(&ExtensionLoaderHandler::HandleSetDisplayLoading,
184 weak_ptr_factory_.GetWeakPtr()));
185 web_ui()->RegisterMessageCallback(
186 "extensionLoaderDisplayFailures",
187 base::Bind(&ExtensionLoaderHandler::HandleDisplayFailures,
188 weak_ptr_factory_.GetWeakPtr()));
169 } 189 }
170 190
171 void ExtensionLoaderHandler::HandleLoadUnpacked(const base::ListValue* args) { 191 void ExtensionLoaderHandler::HandleLoadUnpacked(const base::ListValue* args) {
172 DCHECK(args->empty()); 192 DCHECK(args->empty());
173 file_helper_->ChooseFile(); 193 file_helper_->ChooseFile();
174 } 194 }
175 195
176 void ExtensionLoaderHandler::HandleRetry(const base::ListValue* args) { 196 void ExtensionLoaderHandler::HandleRetry(const base::ListValue* args) {
197 DCHECK(!args->empty());
198 base::string16 path;
199 args->GetString(0, &path);
200 LoadUnpackedExtensionImpl(base::FilePath::FromUTF16Unsafe(path));
201 }
202
203 void ExtensionLoaderHandler::HandleSetDisplayLoading(
204 const base::ListValue* args) {
177 DCHECK(args->empty()); 205 DCHECK(args->empty());
178 LoadUnpackedExtensionImpl(failed_path_); 206 display_ready_ = false;
207 }
208
209 void ExtensionLoaderHandler::HandleDisplayFailures(
210 const base::ListValue* args) {
211 DCHECK(args->empty());
212 display_ready_ = true;
213
214 if (failures_.empty())
215 return;
216
217 for (size_t i = 0; i < failures_.size(); ++i) {
218 FailureData* failure = failures_[i];
219 NotifyFrontendOfFailure(failure->file_path,
220 failure->error,
221 failure->line_number,
222 failure->manifest);
223 }
224 failures_.clear();
179 } 225 }
180 226
181 void ExtensionLoaderHandler::LoadUnpackedExtensionImpl( 227 void ExtensionLoaderHandler::LoadUnpackedExtensionImpl(
182 const base::FilePath& file_path) { 228 const base::FilePath& file_path) {
183 scoped_refptr<UnpackedInstaller> installer = UnpackedInstaller::Create( 229 scoped_refptr<UnpackedInstaller> installer = UnpackedInstaller::Create(
184 ExtensionSystem::Get(profile_)->extension_service()); 230 ExtensionSystem::Get(profile_)->extension_service());
185 installer->set_on_failure_callback(
186 base::Bind(&ExtensionLoaderHandler::OnLoadFailure,
187 weak_ptr_factory_.GetWeakPtr()));
188 231
189 // We do our own error handling, so we don't want a load failure to trigger 232 // We do our own error handling, so we don't want a load failure to trigger
190 // a dialog. 233 // a dialog.
191 installer->set_be_noisy_on_failure(false); 234 installer->set_be_noisy_on_failure(false);
192 235
193 installer->Load(file_path); 236 installer->Load(file_path);
194 } 237 }
195 238
196 void ExtensionLoaderHandler::OnLoadFailure(const base::FilePath& file_path, 239 void ExtensionLoaderHandler::OnLoadFailure(const base::FilePath& file_path,
197 const std::string& error) { 240 const std::string& error) {
198 failed_path_ = file_path;
199 size_t line = 0u; 241 size_t line = 0u;
200 size_t column = 0u; 242 size_t column = 0u;
201 std::string regex = 243 std::string regex =
202 base::StringPrintf("%s Line: (\\d+), column: (\\d+), Syntax error.", 244 base::StringPrintf("%s Line: (\\d+), column: (\\d+), Syntax error.",
203 manifest_errors::kManifestParseError); 245 manifest_errors::kManifestParseError);
204 // If this was a JSON parse error, we can highlight the exact line with the 246 // If this was a JSON parse error, we can highlight the exact line with the
205 // error. Otherwise, we should still display the manifest (for consistency, 247 // error. Otherwise, we should still display the manifest (for consistency,
206 // reference, and so that if we ever make this really fancy and add an editor, 248 // reference, and so that if we ever make this really fancy and add an editor,
207 // it's ready). 249 // it's ready).
208 // 250 //
(...skipping 11 matching lines...) Expand all
220 file_path, 262 file_path,
221 error, 263 error,
222 line)); 264 line));
223 } 265 }
224 266
225 void ExtensionLoaderHandler::NotifyFrontendOfFailure( 267 void ExtensionLoaderHandler::NotifyFrontendOfFailure(
226 const base::FilePath& file_path, 268 const base::FilePath& file_path,
227 const std::string& error, 269 const std::string& error,
228 size_t line_number, 270 size_t line_number,
229 const std::string& manifest) { 271 const std::string& manifest) {
272 // If the extensions page is not loaded, delay frontend notification.
273 if (!display_ready_) {
274 failures_.push_back(new FailureData(file_path,
275 error,
276 line_number,
277 manifest));
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