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 cr.define('extensions', function() { | 5 cr.define('extensions', function() { |
6 'use strict'; | 6 'use strict'; |
7 | 7 |
8 /** | 8 /** |
9 * Construct an ExtensionLoadError around the given |div|. | 9 * Construct an ExtensionLoadError around the given |div|. |
10 * @param {HTMLDivElement} div The HTML div for the extension load error. | 10 * @param {HTMLDivElement} div The HTML div for the extension load error. |
11 * @constructor | 11 * @constructor |
12 * @extends {HTMLDivElement} | |
13 */ | 12 */ |
14 function ExtensionLoadError(div) { | 13 function ExtensionLoadError(div) { |
15 div.__proto__ = ExtensionLoadError.prototype; | 14 div.__proto__ = ExtensionLoadError.prototype; |
16 div.init(); | 15 div.init(); |
17 return div; | 16 return div; |
18 } | 17 } |
19 | 18 |
20 /** | 19 /** |
21 * Construct a Failure. | 20 * Construct a Failure. |
22 * @param {string} filePath The path to the unpacked extension. | 21 * @param {string} filePath The path to the unpacked extension. |
23 * @param {string} error The reason the extension failed to load. | 22 * @param {string} error The reason the extension failed to load. |
24 * @param {ExtensionHighlight} manifest Three 'highlight' strings in | 23 * @param {Object} manifest An object with three strings: beforeHighlight, |
25 * |manifest| represent three portions of the file's content to display - | 24 * afterHighlight, and highlight. These represent three portions of the |
26 * the portion which is most relevant and should be emphasized | 25 * file's content to display - the portion which is most relevant and |
27 * (highlight), and the parts both before and after this portion. These | 26 * should be emphasized (highlight), and the parts both before and after |
28 * may be empty. | 27 * this portion. These may be empty. |
29 * @param {HTMLLIElement} listElement The HTML element used for displaying the | 28 * @param {HTMLLIElement} listElement The HTML element used for displaying the |
30 * failure path for the additional failures UI. | 29 * failure path for the additional failures UI. |
31 * @constructor | 30 * @constructor |
32 * @extends {HTMLDivElement} | |
33 */ | 31 */ |
34 function Failure(filePath, error, manifest, listElement) { | 32 function Failure(filePath, error, manifest, listElement) { |
35 this.path = filePath; | 33 this.path = filePath; |
36 this.error = error; | 34 this.error = error; |
37 this.manifest = manifest; | 35 this.manifest = manifest; |
38 this.listElement = listElement; | 36 this.listElement = listElement; |
39 } | 37 } |
40 | 38 |
41 ExtensionLoadError.prototype = { | 39 ExtensionLoadError.prototype = { |
42 __proto__: HTMLDivElement.prototype, | 40 __proto__: HTMLDivElement.prototype, |
43 | 41 |
44 /** | 42 /** |
45 * Initialize the ExtensionLoadError div. | 43 * Initialize the ExtensionLoadError div. |
46 */ | 44 */ |
47 init: function() { | 45 init: function() { |
48 /** | 46 /** |
49 * The element which displays the path of the extension. | 47 * The element which displays the path of the extension. |
50 * @type {HTMLElement} | 48 * @type {HTMLSpanElement} |
51 * @private | 49 * @private |
52 */ | 50 */ |
53 this.path_ = /** @type {HTMLElement} */( | 51 this.path_ = this.querySelector('#extension-load-error-path'); |
54 this.querySelector('#extension-load-error-path')); | |
55 | 52 |
56 /** | 53 /** |
57 * The element which displays the reason the extension failed to load. | 54 * The element which displays the reason the extension failed to load. |
58 * @type {HTMLElement} | 55 * @type {HTMLSpanElement} |
59 * @private | 56 * @private |
60 */ | 57 */ |
61 this.reason_ = /** @type {HTMLElement} */( | 58 this.reason_ = this.querySelector('#extension-load-error-reason'); |
62 this.querySelector('#extension-load-error-reason')); | |
63 | 59 |
64 /** | 60 /** |
65 * The element which displays the manifest code. | 61 * The element which displays the manifest code. |
66 * @type {extensions.ExtensionCode} | 62 * @type {ExtensionCode} |
67 * @private | 63 * @private |
68 */ | 64 */ |
69 this.manifest_ = new extensions.ExtensionCode( | 65 this.manifest_ = new extensions.ExtensionCode( |
70 this.querySelector('#extension-load-error-manifest')); | 66 this.querySelector('#extension-load-error-manifest')); |
71 | 67 |
72 /** | 68 /** |
73 * The element which displays information about additional errors. | 69 * The element which displays information about additional errors. |
74 * @type {HTMLElement} | 70 * @type {HTMLULElement} |
75 * @private | 71 * @private |
76 */ | 72 */ |
77 this.additional_ = /** @type {HTMLUListElement} */( | 73 this.additional_ = this.querySelector('#extension-load-error-additional'); |
78 this.querySelector('#extension-load-error-additional')); | |
79 this.additional_.list = this.additional_.getElementsByTagName('ul')[0]; | 74 this.additional_.list = this.additional_.getElementsByTagName('ul')[0]; |
80 | 75 |
81 /** | 76 /** |
82 * An array of Failures for keeping track of multiple active failures. | 77 * An array of Failures for keeping track of multiple active failures. |
83 * @type {Array.<Failure>} | 78 * @type {Array.<Failure>} |
84 * @private | 79 * @private |
85 */ | 80 */ |
86 this.failures_ = []; | 81 this.failures_ = []; |
87 | 82 |
88 this.querySelector('#extension-load-error-retry-button').addEventListener( | 83 this.querySelector('#extension-load-error-retry-button').addEventListener( |
(...skipping 16 matching lines...) Expand all Loading... |
105 * failure, display the additional failures element. | 100 * failure, display the additional failures element. |
106 * @param {Array.<Object>} failures Array of failures containing paths, | 101 * @param {Array.<Object>} failures Array of failures containing paths, |
107 * errors, and manifests. | 102 * errors, and manifests. |
108 * @private | 103 * @private |
109 */ | 104 */ |
110 add_: function(failures) { | 105 add_: function(failures) { |
111 // If a failure is already being displayed, unhide the last item. | 106 // If a failure is already being displayed, unhide the last item. |
112 if (this.failures_.length > 0) | 107 if (this.failures_.length > 0) |
113 this.failures_[this.failures_.length - 1].listElement.hidden = false; | 108 this.failures_[this.failures_.length - 1].listElement.hidden = false; |
114 failures.forEach(function(failure) { | 109 failures.forEach(function(failure) { |
115 var listItem = /** @type {HTMLLIElement} */( | 110 var listItem = document.createElement('li'); |
116 document.createElement('li')); | |
117 listItem.textContent = failure.path; | 111 listItem.textContent = failure.path; |
118 this.additional_.list.appendChild(listItem); | 112 this.additional_.list.appendChild(listItem); |
119 this.failures_.push(new Failure(failure.path, | 113 this.failures_.push(new Failure(failure.path, |
120 failure.error, | 114 failure.error, |
121 failure.manifest, | 115 failure.manifest, |
122 listItem)); | 116 listItem)); |
123 }.bind(this)); | 117 }.bind(this)); |
124 // Hide the last item because the UI is displaying its information. | 118 // Hide the last item because the UI is displaying its information. |
125 this.failures_[this.failures_.length - 1].listElement.hidden = true; | 119 this.failures_[this.failures_.length - 1].listElement.hidden = true; |
126 this.show_(); | 120 this.show_(); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 * The ExtensionLoader is the class in charge of loading unpacked extensions. | 165 * The ExtensionLoader is the class in charge of loading unpacked extensions. |
172 * @constructor | 166 * @constructor |
173 */ | 167 */ |
174 function ExtensionLoader() { | 168 function ExtensionLoader() { |
175 /** | 169 /** |
176 * The ExtensionLoadError to show any errors from loading an unpacked | 170 * The ExtensionLoadError to show any errors from loading an unpacked |
177 * extension. | 171 * extension. |
178 * @type {ExtensionLoadError} | 172 * @type {ExtensionLoadError} |
179 * @private | 173 * @private |
180 */ | 174 */ |
181 this.loadError_ = new ExtensionLoadError( | 175 this.loadError_ = new ExtensionLoadError($('extension-load-error')); |
182 /** @type {HTMLDivElement} */($('extension-load-error'))); | |
183 } | 176 } |
184 | 177 |
185 cr.addSingletonGetter(ExtensionLoader); | 178 cr.addSingletonGetter(ExtensionLoader); |
186 | 179 |
187 ExtensionLoader.prototype = { | 180 ExtensionLoader.prototype = { |
188 /** | 181 /** |
189 * Begin the sequence of loading an unpacked extension. If an error is | 182 * Begin the sequence of loading an unpacked extension. If an error is |
190 * encountered, this object will get notified via notifyFailed(). | 183 * encountered, this object will get notified via notifyFailed(). |
191 */ | 184 */ |
192 loadUnpacked: function() { | 185 loadUnpacked: function() { |
193 chrome.send('extensionLoaderLoadUnpacked'); | 186 chrome.send('extensionLoaderLoadUnpacked'); |
194 }, | 187 }, |
195 | 188 |
196 /** | 189 /** |
197 * Notify the ExtensionLoader that loading an unpacked extension failed. | 190 * Notify the ExtensionLoader that loading an unpacked extension failed. |
198 * Add the failure to failures_ and show the ExtensionLoadError. | 191 * Add the failure to failures_ and show the ExtensionLoadError. |
199 * @param {Array.<Object>} failures Array of failures containing paths, | 192 * @param {Array.<Object>} failures Array of failures containing paths, |
200 * errors, and manifests. | 193 * errors, and manifests. |
201 */ | 194 */ |
202 notifyFailed: function(failures) { | 195 notifyFailed: function(failures) { |
203 this.loadError_.add_(failures); | 196 this.loadError_.add_(failures); |
204 }, | 197 }, |
205 }; | 198 }; |
206 | 199 |
207 /** | 200 /* |
208 * A static forwarding function for ExtensionLoader.notifyFailed. | 201 * A static forwarding function for ExtensionLoader.notifyFailed. |
209 * @param {Array.<Object>} failures Array of failures containing paths, | 202 * @param {Array.<Object>} failures Array of failures containing paths, |
210 * errors, and manifests. | 203 * errors, and manifests. |
211 * @see ExtensionLoader.notifyFailed | 204 * @see ExtensionLoader.notifyFailed |
212 */ | 205 */ |
213 ExtensionLoader.notifyLoadFailed = function(failures) { | 206 ExtensionLoader.notifyLoadFailed = function(failures) { |
214 ExtensionLoader.getInstance().notifyFailed(failures); | 207 ExtensionLoader.getInstance().notifyFailed(failures); |
215 }; | 208 }; |
216 | 209 |
217 return { | 210 return { |
218 ExtensionLoader: ExtensionLoader | 211 ExtensionLoader: ExtensionLoader |
219 }; | 212 }; |
220 }); | 213 }); |
OLD | NEW |