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

Unified Diff: chrome/browser/resources/extensions/extension_loader.js

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: Moved path handling back to C++ 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/resources/extensions/extension_loader.js
diff --git a/chrome/browser/resources/extensions/extension_loader.js b/chrome/browser/resources/extensions/extension_loader.js
index fb57c18b139075cba35b00c733df28187052c4c9..c52a62449917761f1bad2d4e0f4969ac7f750c92 100644
--- a/chrome/browser/resources/extensions/extension_loader.js
+++ b/chrome/browser/resources/extensions/extension_loader.js
@@ -2,6 +2,10 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+window.addEventListener('beforeunload', function() {
+ chrome.send('extensionLoaderSetDisplayLoading');
+});
+
cr.define('extensions', function() {
'use strict';
@@ -16,6 +20,19 @@ cr.define('extensions', function() {
return div;
}
+ /**
+ * Construct a Failure.
+ * @param {string} filePath The path to the unpacked extension.
+ * @param {string} reason The reason the extension failed to load.
+ * @param {Object} manifest The manifest of the failed extension.
+ * @constructor
+ */
+ function Failure(filePath, reason, manifest) {
+ this.path_ = filePath;
Devlin 2014/07/02 17:46:50 no trailing _ if it's not a private var.
gpdavis 2014/07/02 19:13:54 Done.
+ this.reason_ = reason;
+ this.manifest_ = manifest;
+ }
+
ExtensionLoadError.prototype = {
__proto__: HTMLDivElement.prototype,
@@ -45,42 +62,90 @@ cr.define('extensions', function() {
this.manifest_ = new extensions.ExtensionCode(
this.querySelector('#extension-load-error-manifest'));
+ /**
+ * The element which displays information about additional errors.
+ * @type {HTMLPreElement}
+ * @private
+ */
+ this.additional_ = this.querySelector('#extension-load-error-additional');
+
+ /**
+ * An array of Failures for keeping track of multiple active failures.
+ * @type {Array}
Devlin 2014/07/02 17:46:50 There's a syntax for saying what the array is full
gpdavis 2014/07/02 19:13:55 Done.
+ * @private
+ */
+ this.failures_ = [];
+
this.querySelector('#extension-load-error-retry-button').addEventListener(
'click', function(e) {
chrome.send('extensionLoaderRetry');
- this.hide_();
+ this.remove_();
}.bind(this));
this.querySelector('#extension-load-error-give-up-button').
addEventListener('click', function(e) {
- this.hide_();
+ chrome.send('extensionLoaderGiveUp');
+ this.remove_();
}.bind(this));
+
+ chrome.send('extensionLoaderDisplayFailures');
},
/**
- * Display the load error to the user.
+ * Add a failure to failures_ array. If there is already a displayed
+ * failure, display the additional failures element.
* @param {string} path The path from which the extension was loaded.
* @param {string} reason The reason the extension failed to load.
* @param {string} manifest The manifest object, with highlighted regions.
*/
- show: function(path, reason, manifest) {
- this.path_.textContent = path;
- this.reason_.textContent = reason;
+ add: function(path, reason, manifest) {
+ if (this.failures_.length == 1)
+ this.additional_.hidden = false;
Devlin 2014/07/02 17:46:50 Let's put the logic for showing/hidding |additiona
gpdavis 2014/07/02 19:13:55 Done.
- manifest.message = reason;
- this.manifest_.populate(
- manifest,
- loadTimeData.getString('extensionLoadCouldNotLoadManifest'));
- this.hidden = false;
- this.manifest_.scrollToError();
+ this.failures_.push(new Failure(path, reason, manifest));
+
+ this.show_();
+ },
+
+ /**
+ * Remove a failure from failures_ array. If this was the last failure,
+ * hide the error UI. If this was the last additional failure, hide
+ * the additional failures UI.
+ * @private
+ */
+ remove_: function() {
+ this.failures_.pop();
+ if (this.failures_.length == 0) {
+ this.hidden = true;
+ } else {
+ if (this.failures_.length == 1)
+ this.additional_.hidden = true;
+ this.show_();
+ }
},
/**
- * Hide the extension load error.
+ * Display the load error to the user. The last failure gets its manifest
+ * and error displayed, while additional failures have their path names
+ * displayed in the additional failures element.
* @private
*/
- hide_: function() {
- this.hidden = true;
+ show_: function() {
+ var failure = this.failures_[this.failures_.length - 1];
+ this.path_.textContent = failure.path_;
+ this.reason_.textContent = failure.reason_;
+
+ failure.manifest_.message = failure.reason_;
+ this.manifest_.populate(
+ failure.manifest_,
+ loadTimeData.getString('extensionLoadCouldNotLoadManifest'));
+ this.hidden = false;
+ this.manifest_.scrollToError();
+
+ this.additional_.textContent =
+ loadTimeData.getString('extensionLoadAdditionalFailures');
+ for (var i = 0; i < this.failures_.length - 1; ++i)
+ this.additional_.textContent += '\n' + this.failures_[i].path_;
}
};
@@ -111,7 +176,7 @@ cr.define('extensions', function() {
/**
* Notify the ExtensionLoader that loading an unpacked extension failed.
- * Show the ExtensionLoadError.
+ * Add the failure to failures_ and show the ExtensionLoadError.
* @param {string} filePath The path to the unpacked extension.
* @param {string} reason The reason the extension failed to load.
* @param {Object} manifest An object with three strings: beforeHighlight,
@@ -121,8 +186,8 @@ cr.define('extensions', function() {
* this portion. These may be empty.
*/
notifyFailed: function(filePath, reason, manifest) {
- this.loadError_.show(filePath, reason, manifest);
- }
+ this.loadError_.add(filePath, reason, manifest);
+ },
};
/*

Powered by Google App Engine
This is Rietveld 408576698