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