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

Side by Side 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, 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 window.addEventListener('beforeunload', function() {
6 chrome.send('extensionLoaderSetDisplayLoading');
7 });
8
5 cr.define('extensions', function() { 9 cr.define('extensions', function() {
6 'use strict'; 10 'use strict';
7 11
8 /** 12 /**
9 * Construct an ExtensionLoadError around the given |div|. 13 * Construct an ExtensionLoadError around the given |div|.
10 * @param {HTMLDivElement} div The HTML div for the extension load error. 14 * @param {HTMLDivElement} div The HTML div for the extension load error.
11 * @constructor 15 * @constructor
12 */ 16 */
13 function ExtensionLoadError(div) { 17 function ExtensionLoadError(div) {
14 div.__proto__ = ExtensionLoadError.prototype; 18 div.__proto__ = ExtensionLoadError.prototype;
15 div.init(); 19 div.init();
16 return div; 20 return div;
17 } 21 }
18 22
23 /**
24 * Construct a Failure.
25 * @param {string} filePath The path to the unpacked extension.
26 * @param {string} reason The reason the extension failed to load.
27 * @param {Object} manifest The manifest of the failed extension.
28 * @constructor
29 */
30 function Failure(filePath, reason, manifest) {
31 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.
32 this.reason_ = reason;
33 this.manifest_ = manifest;
34 }
35
19 ExtensionLoadError.prototype = { 36 ExtensionLoadError.prototype = {
20 __proto__: HTMLDivElement.prototype, 37 __proto__: HTMLDivElement.prototype,
21 38
22 /** 39 /**
23 * Initialize the ExtensionLoadError div. 40 * Initialize the ExtensionLoadError div.
24 */ 41 */
25 init: function() { 42 init: function() {
26 /** 43 /**
27 * The element which displays the path of the extension. 44 * The element which displays the path of the extension.
28 * @type {HTMLSpanElement} 45 * @type {HTMLSpanElement}
29 * @private 46 * @private
30 */ 47 */
31 this.path_ = this.querySelector('#extension-load-error-path'); 48 this.path_ = this.querySelector('#extension-load-error-path');
32 49
33 /** 50 /**
34 * The element which displays the reason the extension failed to load. 51 * The element which displays the reason the extension failed to load.
35 * @type {HTMLSpanElement} 52 * @type {HTMLSpanElement}
36 * @private 53 * @private
37 */ 54 */
38 this.reason_ = this.querySelector('#extension-load-error-reason'); 55 this.reason_ = this.querySelector('#extension-load-error-reason');
39 56
40 /** 57 /**
41 * The element which displays the manifest code. 58 * The element which displays the manifest code.
42 * @type {ExtensionCode} 59 * @type {ExtensionCode}
43 * @private 60 * @private
44 */ 61 */
45 this.manifest_ = new extensions.ExtensionCode( 62 this.manifest_ = new extensions.ExtensionCode(
46 this.querySelector('#extension-load-error-manifest')); 63 this.querySelector('#extension-load-error-manifest'));
47 64
65 /**
66 * The element which displays information about additional errors.
67 * @type {HTMLPreElement}
68 * @private
69 */
70 this.additional_ = this.querySelector('#extension-load-error-additional');
71
72 /**
73 * An array of Failures for keeping track of multiple active failures.
74 * @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.
75 * @private
76 */
77 this.failures_ = [];
78
48 this.querySelector('#extension-load-error-retry-button').addEventListener( 79 this.querySelector('#extension-load-error-retry-button').addEventListener(
49 'click', function(e) { 80 'click', function(e) {
50 chrome.send('extensionLoaderRetry'); 81 chrome.send('extensionLoaderRetry');
51 this.hide_(); 82 this.remove_();
52 }.bind(this)); 83 }.bind(this));
53 84
54 this.querySelector('#extension-load-error-give-up-button'). 85 this.querySelector('#extension-load-error-give-up-button').
55 addEventListener('click', function(e) { 86 addEventListener('click', function(e) {
56 this.hide_(); 87 chrome.send('extensionLoaderGiveUp');
88 this.remove_();
57 }.bind(this)); 89 }.bind(this));
90
91 chrome.send('extensionLoaderDisplayFailures');
58 }, 92 },
59 93
60 /** 94 /**
61 * Display the load error to the user. 95 * Add a failure to failures_ array. If there is already a displayed
96 * failure, display the additional failures element.
62 * @param {string} path The path from which the extension was loaded. 97 * @param {string} path The path from which the extension was loaded.
63 * @param {string} reason The reason the extension failed to load. 98 * @param {string} reason The reason the extension failed to load.
64 * @param {string} manifest The manifest object, with highlighted regions. 99 * @param {string} manifest The manifest object, with highlighted regions.
65 */ 100 */
66 show: function(path, reason, manifest) { 101 add: function(path, reason, manifest) {
67 this.path_.textContent = path; 102 if (this.failures_.length == 1)
68 this.reason_.textContent = reason; 103 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.
69 104
70 manifest.message = reason; 105 this.failures_.push(new Failure(path, reason, manifest));
106
107 this.show_();
108 },
109
110 /**
111 * Remove a failure from failures_ array. If this was the last failure,
112 * hide the error UI. If this was the last additional failure, hide
113 * the additional failures UI.
114 * @private
115 */
116 remove_: function() {
117 this.failures_.pop();
118 if (this.failures_.length == 0) {
119 this.hidden = true;
120 } else {
121 if (this.failures_.length == 1)
122 this.additional_.hidden = true;
123 this.show_();
124 }
125 },
126
127 /**
128 * Display the load error to the user. The last failure gets its manifest
129 * and error displayed, while additional failures have their path names
130 * displayed in the additional failures element.
131 * @private
132 */
133 show_: function() {
134 var failure = this.failures_[this.failures_.length - 1];
135 this.path_.textContent = failure.path_;
136 this.reason_.textContent = failure.reason_;
137
138 failure.manifest_.message = failure.reason_;
71 this.manifest_.populate( 139 this.manifest_.populate(
72 manifest, 140 failure.manifest_,
73 loadTimeData.getString('extensionLoadCouldNotLoadManifest')); 141 loadTimeData.getString('extensionLoadCouldNotLoadManifest'));
74 this.hidden = false; 142 this.hidden = false;
75 this.manifest_.scrollToError(); 143 this.manifest_.scrollToError();
76 },
77 144
78 /** 145 this.additional_.textContent =
79 * Hide the extension load error. 146 loadTimeData.getString('extensionLoadAdditionalFailures');
80 * @private 147 for (var i = 0; i < this.failures_.length - 1; ++i)
81 */ 148 this.additional_.textContent += '\n' + this.failures_[i].path_;
82 hide_: function() {
83 this.hidden = true;
84 } 149 }
85 }; 150 };
86 151
87 /** 152 /**
88 * The ExtensionLoader is the class in charge of loading unpacked extensions. 153 * The ExtensionLoader is the class in charge of loading unpacked extensions.
89 * @constructor 154 * @constructor
90 */ 155 */
91 function ExtensionLoader() { 156 function ExtensionLoader() {
92 /** 157 /**
93 * The ExtensionLoadError to show any errors from loading an unpacked 158 * The ExtensionLoadError to show any errors from loading an unpacked
(...skipping 10 matching lines...) Expand all
104 /** 169 /**
105 * Begin the sequence of loading an unpacked extension. If an error is 170 * Begin the sequence of loading an unpacked extension. If an error is
106 * encountered, this object will get notified via notifyFailed(). 171 * encountered, this object will get notified via notifyFailed().
107 */ 172 */
108 loadUnpacked: function() { 173 loadUnpacked: function() {
109 chrome.send('extensionLoaderLoadUnpacked'); 174 chrome.send('extensionLoaderLoadUnpacked');
110 }, 175 },
111 176
112 /** 177 /**
113 * Notify the ExtensionLoader that loading an unpacked extension failed. 178 * Notify the ExtensionLoader that loading an unpacked extension failed.
114 * Show the ExtensionLoadError. 179 * Add the failure to failures_ and show the ExtensionLoadError.
115 * @param {string} filePath The path to the unpacked extension. 180 * @param {string} filePath The path to the unpacked extension.
116 * @param {string} reason The reason the extension failed to load. 181 * @param {string} reason The reason the extension failed to load.
117 * @param {Object} manifest An object with three strings: beforeHighlight, 182 * @param {Object} manifest An object with three strings: beforeHighlight,
118 * afterHighlight, and highlight. These represent three portions of the 183 * afterHighlight, and highlight. These represent three portions of the
119 * file's content to display - the portion which is most relevant and 184 * file's content to display - the portion which is most relevant and
120 * should be emphasized (highlight), and the parts both before and after 185 * should be emphasized (highlight), and the parts both before and after
121 * this portion. These may be empty. 186 * this portion. These may be empty.
122 */ 187 */
123 notifyFailed: function(filePath, reason, manifest) { 188 notifyFailed: function(filePath, reason, manifest) {
124 this.loadError_.show(filePath, reason, manifest); 189 this.loadError_.add(filePath, reason, manifest);
125 } 190 },
126 }; 191 };
127 192
128 /* 193 /*
129 * A static forwarding function for ExtensionLoader.notifyFailed. 194 * A static forwarding function for ExtensionLoader.notifyFailed.
130 * @param {string} filePath The path to the unpacked extension. 195 * @param {string} filePath The path to the unpacked extension.
131 * @param {string} reason The reason the extension failed to load. 196 * @param {string} reason The reason the extension failed to load.
132 * @param {Object} manifest The manifest of the failed extension. 197 * @param {Object} manifest The manifest of the failed extension.
133 * @see ExtensionLoader.notifyFailed 198 * @see ExtensionLoader.notifyFailed
134 */ 199 */
135 ExtensionLoader.notifyLoadFailed = function(filePath, reason, manifest) { 200 ExtensionLoader.notifyLoadFailed = function(filePath, reason, manifest) {
136 ExtensionLoader.getInstance().notifyFailed(filePath, reason, manifest); 201 ExtensionLoader.getInstance().notifyFailed(filePath, reason, manifest);
137 }; 202 };
138 203
139 return { 204 return {
140 ExtensionLoader: ExtensionLoader 205 ExtensionLoader: ExtensionLoader
141 }; 206 };
142 }); 207 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698