OLD | NEW |
---|---|
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; |
(...skipping 23 matching lines...) Expand all Loading... | |
38 this.reason_ = this.querySelector('#extension-load-error-reason'); | 42 this.reason_ = this.querySelector('#extension-load-error-reason'); |
39 | 43 |
40 /** | 44 /** |
41 * The element which displays the manifest code. | 45 * The element which displays the manifest code. |
42 * @type {ExtensionCode} | 46 * @type {ExtensionCode} |
43 * @private | 47 * @private |
44 */ | 48 */ |
45 this.manifest_ = new extensions.ExtensionCode( | 49 this.manifest_ = new extensions.ExtensionCode( |
46 this.querySelector('#extension-load-error-manifest')); | 50 this.querySelector('#extension-load-error-manifest')); |
47 | 51 |
52 /** | |
53 * The element which displays information about additional errors. | |
54 * @type {HTMLPreElement} | |
55 * @private | |
56 */ | |
57 this.additional_ = this.querySelector('#extension-load-error-additional'); | |
58 | |
59 /** | |
60 * An array of failures for keeping track of multiple active failures. | |
61 * @type {Array} | |
Devlin
2014/07/01 22:14:17
Array of whats? (document)
gpdavis
2014/07/01 23:48:09
An array of failures! Just kidding.
Added in a F
| |
62 * @private | |
63 */ | |
64 this.failures_ = []; | |
65 | |
48 this.querySelector('#extension-load-error-retry-button').addEventListener( | 66 this.querySelector('#extension-load-error-retry-button').addEventListener( |
49 'click', function(e) { | 67 'click', function(e) { |
50 chrome.send('extensionLoaderRetry'); | 68 chrome.send('extensionLoaderRetry', |
51 this.hide_(); | 69 [this.failures_[this.failures_.length - 1].path_]); |
Devlin
2014/07/01 22:14:17
We can't do this. We deliberately do not allow We
gpdavis
2014/07/01 23:48:10
Rats. I suppose I'll add a vector of file paths a
| |
70 this.remove_(); | |
52 }.bind(this)); | 71 }.bind(this)); |
53 | 72 |
54 this.querySelector('#extension-load-error-give-up-button'). | 73 this.querySelector('#extension-load-error-give-up-button'). |
55 addEventListener('click', function(e) { | 74 addEventListener('click', function(e) { |
56 this.hide_(); | 75 this.remove_(); |
57 }.bind(this)); | 76 }.bind(this)); |
77 | |
78 chrome.send('extensionLoaderDisplayFailures'); | |
58 }, | 79 }, |
59 | 80 |
60 /** | 81 /** |
61 * Display the load error to the user. | 82 * Add a failure to failures_ array. If there is already a displayed |
Devlin
2014/07/01 22:14:17
nit: one space after a period (Clint will never fo
gpdavis
2014/07/01 23:48:10
He most certainly has not ;) Done.
| |
83 * failure, display the additional failures element. | |
62 * @param {string} path The path from which the extension was loaded. | 84 * @param {string} path The path from which the extension was loaded. |
63 * @param {string} reason The reason the extension failed to load. | 85 * @param {string} reason The reason the extension failed to load. |
64 * @param {string} manifest The manifest object, with highlighted regions. | 86 * @param {string} manifest The manifest object, with highlighted regions. |
65 */ | 87 */ |
66 show: function(path, reason, manifest) { | 88 add: function(path, reason, manifest) { |
67 this.path_.textContent = path; | 89 if (this.failures_.length == 1) { |
Devlin
2014/07/01 22:14:17
nit: no brackets around single-line if
gpdavis
2014/07/01 23:48:10
Done.
| |
68 this.reason_.textContent = reason; | 90 this.additional_.hidden = false; |
91 } | |
69 | 92 |
70 manifest.message = reason; | 93 this.failures_.push({ |
94 path_: path, | |
95 reason_: reason, | |
96 manifest_: manifest | |
97 }); | |
98 | |
99 this.show_(); | |
100 }, | |
101 | |
102 /** | |
103 * Remove a failure from failures_ array. If this was the last failure, | |
104 * hide the error UI. If this was the last additional failure, hide | |
105 * the additional failures UI. | |
106 * @private | |
107 */ | |
108 remove_: function() { | |
109 this.failures_.pop(); | |
110 if (this.failures_.length == 0) { | |
111 this.hidden = true; | |
112 } else { | |
113 if (this.failures_.length == 1) { | |
Devlin
2014/07/01 22:14:17
nit: brackets.
gpdavis
2014/07/01 23:48:10
Done.
| |
114 this.additional_.hidden = true; | |
115 } | |
116 this.show_(); | |
117 } | |
118 }, | |
119 | |
120 /** | |
121 * Display the load error to the user. The last failure gets its manifest | |
122 * and error displayed, while additional failures have their path names | |
Devlin
2014/07/01 22:14:17
I don't think we wrap like this for these comments
gpdavis
2014/07/01 23:48:10
See line 176. Should I do it a different way?
Devlin
2014/07/02 17:46:49
I think that we only line-wrap for param declarati
| |
123 * displayed in the additional failures element. | |
124 * @private | |
125 */ | |
126 show_: function() { | |
127 var failure = this.failures_[this.failures_.length - 1]; | |
128 this.path_.textContent = failure.path_; | |
129 this.reason_.textContent = failure.reason_; | |
130 | |
131 failure.manifest_.message = failure.reason_; | |
71 this.manifest_.populate( | 132 this.manifest_.populate( |
72 manifest, | 133 failure.manifest_, |
73 loadTimeData.getString('extensionLoadCouldNotLoadManifest')); | 134 loadTimeData.getString('extensionLoadCouldNotLoadManifest')); |
74 this.hidden = false; | 135 this.hidden = false; |
75 this.manifest_.scrollToError(); | 136 this.manifest_.scrollToError(); |
76 }, | |
77 | 137 |
78 /** | 138 this.additional_.textContent = 'Additional failures:'; |
Devlin
2014/07/01 22:14:17
this will still have to be i18n'd. ;)
gpdavis
2014/07/01 23:48:10
How do in JS?
gpdavis
2014/07/02 00:49:36
This was a premature request for help. Got it fig
| |
79 * Hide the extension load error. | 139 for (var i = 0; i < this.failures_.length - 1; ++i) { |
80 * @private | 140 this.additional_.textContent += '\n' + this.failures_[i].path_; |
Devlin
2014/07/01 22:14:17
nit: no brackets around 1-line for loops
gpdavis
2014/07/01 23:48:09
Done.
| |
81 */ | 141 } |
82 hide_: function() { | |
83 this.hidden = true; | |
84 } | 142 } |
85 }; | 143 }; |
86 | 144 |
87 /** | 145 /** |
88 * The ExtensionLoader is the class in charge of loading unpacked extensions. | 146 * The ExtensionLoader is the class in charge of loading unpacked extensions. |
89 * @constructor | 147 * @constructor |
90 */ | 148 */ |
91 function ExtensionLoader() { | 149 function ExtensionLoader() { |
92 /** | 150 /** |
93 * The ExtensionLoadError to show any errors from loading an unpacked | 151 * The ExtensionLoadError to show any errors from loading an unpacked |
(...skipping 10 matching lines...) Expand all Loading... | |
104 /** | 162 /** |
105 * Begin the sequence of loading an unpacked extension. If an error is | 163 * Begin the sequence of loading an unpacked extension. If an error is |
106 * encountered, this object will get notified via notifyFailed(). | 164 * encountered, this object will get notified via notifyFailed(). |
107 */ | 165 */ |
108 loadUnpacked: function() { | 166 loadUnpacked: function() { |
109 chrome.send('extensionLoaderLoadUnpacked'); | 167 chrome.send('extensionLoaderLoadUnpacked'); |
110 }, | 168 }, |
111 | 169 |
112 /** | 170 /** |
113 * Notify the ExtensionLoader that loading an unpacked extension failed. | 171 * Notify the ExtensionLoader that loading an unpacked extension failed. |
114 * Show the ExtensionLoadError. | 172 * Add the failure to failures_ and show the ExtensionLoadError. |
115 * @param {string} filePath The path to the unpacked extension. | 173 * @param {string} filePath The path to the unpacked extension. |
116 * @param {string} reason The reason the extension failed to load. | 174 * @param {string} reason The reason the extension failed to load. |
117 * @param {Object} manifest An object with three strings: beforeHighlight, | 175 * @param {Object} manifest An object with three strings: beforeHighlight, |
118 * afterHighlight, and highlight. These represent three portions of the | 176 * afterHighlight, and highlight. These represent three portions of the |
119 * file's content to display - the portion which is most relevant and | 177 * file's content to display - the portion which is most relevant and |
120 * should be emphasized (highlight), and the parts both before and after | 178 * should be emphasized (highlight), and the parts both before and after |
121 * this portion. These may be empty. | 179 * this portion. These may be empty. |
122 */ | 180 */ |
123 notifyFailed: function(filePath, reason, manifest) { | 181 notifyFailed: function(filePath, reason, manifest) { |
124 this.loadError_.show(filePath, reason, manifest); | 182 this.loadError_.add(filePath, reason, manifest); |
125 } | 183 }, |
126 }; | 184 }; |
127 | 185 |
128 /* | 186 /* |
129 * A static forwarding function for ExtensionLoader.notifyFailed. | 187 * A static forwarding function for ExtensionLoader.notifyFailed. |
130 * @param {string} filePath The path to the unpacked extension. | 188 * @param {string} filePath The path to the unpacked extension. |
131 * @param {string} reason The reason the extension failed to load. | 189 * @param {string} reason The reason the extension failed to load. |
132 * @param {Object} manifest The manifest of the failed extension. | 190 * @param {Object} manifest The manifest of the failed extension. |
133 * @see ExtensionLoader.notifyFailed | 191 * @see ExtensionLoader.notifyFailed |
134 */ | 192 */ |
135 ExtensionLoader.notifyLoadFailed = function(filePath, reason, manifest) { | 193 ExtensionLoader.notifyLoadFailed = function(filePath, reason, manifest) { |
136 ExtensionLoader.getInstance().notifyFailed(filePath, reason, manifest); | 194 ExtensionLoader.getInstance().notifyFailed(filePath, reason, manifest); |
137 }; | 195 }; |
138 | 196 |
139 return { | 197 return { |
140 ExtensionLoader: ExtensionLoader | 198 ExtensionLoader: ExtensionLoader |
141 }; | 199 }; |
142 }); | 200 }); |
OLD | NEW |