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

Unified 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: Added ReloadExtensionImpl, enhanced loader handler to send ListValue of failures Created 6 years, 6 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/webui/extensions/extension_loader_handler.cc
diff --git a/chrome/browser/ui/webui/extensions/extension_loader_handler.cc b/chrome/browser/ui/webui/extensions/extension_loader_handler.cc
index 6e43177a4a3abd3fe57b684c2c362b5012a36f9b..2201f9187fc629b031dca6946d2737d62146582e 100644
--- a/chrome/browser/ui/webui/extensions/extension_loader_handler.cc
+++ b/chrome/browser/ui/webui/extensions/extension_loader_handler.cc
@@ -12,7 +12,6 @@
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
-#include "base/values.h"
#include "chrome/browser/extensions/unpacked_installer.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/chrome_select_file_policy.h"
@@ -131,8 +130,11 @@ void ExtensionLoaderHandler::FileHelper::MultiFilesSelected(
ExtensionLoaderHandler::ExtensionLoaderHandler(Profile* profile)
: profile_(profile),
file_helper_(new FileHelper(this)),
+ extension_error_reporter_observer_(this),
+ display_ready_(false),
weak_ptr_factory_(this) {
DCHECK(profile_);
+ extension_error_reporter_observer_.Add(ExtensionErrorReporter::GetInstance());
}
ExtensionLoaderHandler::~ExtensionLoaderHandler() {
@@ -155,6 +157,9 @@ void ExtensionLoaderHandler::GetLocalizedValues(
source->AddString(
"extensionLoadCouldNotLoadManifest",
l10n_util::GetStringUTF16(IDS_EXTENSIONS_LOAD_COULD_NOT_LOAD_MANIFEST));
+ source->AddString(
+ "extensionLoadAdditionalFailures",
+ l10n_util::GetStringUTF16(IDS_EXTENSIONS_LOAD_ADDITIONAL_FAILURES));
}
void ExtensionLoaderHandler::RegisterMessages() {
@@ -166,6 +171,18 @@ void ExtensionLoaderHandler::RegisterMessages() {
"extensionLoaderRetry",
base::Bind(&ExtensionLoaderHandler::HandleRetry,
weak_ptr_factory_.GetWeakPtr()));
+ web_ui()->RegisterMessageCallback(
+ "extensionLoaderIgnoreFailure",
+ base::Bind(&ExtensionLoaderHandler::HandleIgnoreFailure,
+ weak_ptr_factory_.GetWeakPtr()));
+ web_ui()->RegisterMessageCallback(
+ "extensionLoaderSetDisplayLoading",
+ base::Bind(&ExtensionLoaderHandler::HandleSetDisplayLoading,
+ weak_ptr_factory_.GetWeakPtr()));
+ web_ui()->RegisterMessageCallback(
+ "extensionLoaderDisplayFailures",
+ base::Bind(&ExtensionLoaderHandler::HandleDisplayFailures,
+ weak_ptr_factory_.GetWeakPtr()));
}
void ExtensionLoaderHandler::HandleLoadUnpacked(const base::ListValue* args) {
@@ -175,16 +192,34 @@ void ExtensionLoaderHandler::HandleLoadUnpacked(const base::ListValue* args) {
void ExtensionLoaderHandler::HandleRetry(const base::ListValue* args) {
DCHECK(args->empty());
- LoadUnpackedExtensionImpl(failed_path_);
+ LoadUnpackedExtensionImpl(failed_paths_.back());
Devlin 2014/07/07 20:44:22 We should probably pop, then run.
gpdavis 2014/07/09 01:35:57 But pop_back deletes the element and doesn't retur
Devlin 2014/07/09 19:53:17 Right, so because pop_back doesn't return it (one
gpdavis 2014/07/09 21:16:25 Done.
+ failed_paths_.pop_back();
+}
+
+void ExtensionLoaderHandler::HandleIgnoreFailure(const base::ListValue* args) {
+ DCHECK(args->empty());
+ failed_paths_.pop_back();
+}
+
+void ExtensionLoaderHandler::HandleSetDisplayLoading(
+ const base::ListValue* args) {
+ DCHECK(args->empty());
+ display_ready_ = false;
+}
+
+void ExtensionLoaderHandler::HandleDisplayFailures(
+ const base::ListValue* args) {
+ DCHECK(args->empty());
+ display_ready_ = true;
+
+ if (!failures_.empty())
+ NotifyFrontendOfFailure();
}
void ExtensionLoaderHandler::LoadUnpackedExtensionImpl(
const base::FilePath& file_path) {
scoped_refptr<UnpackedInstaller> installer = UnpackedInstaller::Create(
ExtensionSystem::Get(profile_)->extension_service());
- installer->set_on_failure_callback(
- base::Bind(&ExtensionLoaderHandler::OnLoadFailure,
- weak_ptr_factory_.GetWeakPtr()));
// We do our own error handling, so we don't want a load failure to trigger
// a dialog.
@@ -195,7 +230,7 @@ void ExtensionLoaderHandler::LoadUnpackedExtensionImpl(
void ExtensionLoaderHandler::OnLoadFailure(const base::FilePath& file_path,
const std::string& error) {
- failed_path_ = file_path;
+ failed_paths_.push_back(file_path);
size_t line = 0u;
size_t column = 0u;
std::string regex =
@@ -215,32 +250,46 @@ void ExtensionLoaderHandler::OnLoadFailure(const base::FilePath& file_path,
content::BrowserThread::GetBlockingPool(),
FROM_HERE,
base::Bind(&ReadFileToString, file_path.Append(kManifestFilename)),
- base::Bind(&ExtensionLoaderHandler::NotifyFrontendOfFailure,
+ base::Bind(&ExtensionLoaderHandler::AddFailure,
weak_ptr_factory_.GetWeakPtr(),
file_path,
error,
line));
}
-void ExtensionLoaderHandler::NotifyFrontendOfFailure(
+void ExtensionLoaderHandler::AddFailure(
const base::FilePath& file_path,
const std::string& error,
size_t line_number,
const std::string& manifest) {
- base::StringValue file_value(file_path.LossyDisplayName());
- base::StringValue error_value(base::UTF8ToUTF16(error));
+ base::StringValue* file_value =
Devlin 2014/07/07 20:44:21 inline these.
gpdavis 2014/07/09 01:35:57 Done.
+ new base::StringValue(file_path.LossyDisplayName());
+ base::StringValue* error_value =
+ new base::StringValue(base::UTF8ToUTF16(error));
- base::DictionaryValue manifest_value;
+ base::DictionaryValue* manifest_value = new base::DictionaryValue();
SourceHighlighter highlighter(manifest, line_number);
// If the line number is 0, this highlights no regions, but still adds the
// full manifest.
- highlighter.SetHighlightedRegions(&manifest_value);
+ highlighter.SetHighlightedRegions(manifest_value);
+
+ base::DictionaryValue* failure = new base::DictionaryValue();
Devlin 2014/07/07 20:44:21 For better or worse, we're overly paranoid about m
gpdavis 2014/07/09 01:35:57 You can never be overly paranoid about memory leak
Devlin 2014/07/09 19:53:17 Right, but we like extremely clear ownership model
gpdavis 2014/07/09 21:16:25 Ah, gotcha. I must have been doing something wron
+ failure->Set("path", file_value);
+ failure->Set("error", error_value);
+ failure->Set("manifest", manifest_value);
+ failures_.Append(failure);
+
+ // Only notify the frontend if the display is ready.
+ if (display_ready_) {
Devlin 2014/07/07 20:44:21 nit: no brackets around single-line ifs.
gpdavis 2014/07/09 01:35:57 Done.
+ NotifyFrontendOfFailure();
+ }
+}
+void ExtensionLoaderHandler::NotifyFrontendOfFailure() {
web_ui()->CallJavascriptFunction(
"extensions.ExtensionLoader.notifyLoadFailed",
- file_value,
- error_value,
- manifest_value);
+ failures_);
+ failures_.Clear();
}
} // namespace extensions

Powered by Google App Engine
This is Rietveld 408576698