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. |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 | 43 |
44 /** | 44 /** |
45 * Initialize the ExtensionLoadError div. | 45 * Initialize the ExtensionLoadError div. |
46 */ | 46 */ |
47 init: function() { | 47 init: function() { |
48 /** | 48 /** |
49 * The element which displays the path of the extension. | 49 * The element which displays the path of the extension. |
50 * @type {HTMLElement} | 50 * @type {HTMLElement} |
51 * @private | 51 * @private |
52 */ | 52 */ |
53 this.path_ = /** @type {HTMLElement} */( | 53 this.path_ = /** @type {HTMLElement} */ ( |
54 this.querySelector('#extension-load-error-path')); | 54 this.querySelector('#extension-load-error-path')); |
55 | 55 |
56 /** | 56 /** |
57 * The element which displays the reason the extension failed to load. | 57 * The element which displays the reason the extension failed to load. |
58 * @type {HTMLElement} | 58 * @type {HTMLElement} |
59 * @private | 59 * @private |
60 */ | 60 */ |
61 this.reason_ = /** @type {HTMLElement} */( | 61 this.reason_ = /** @type {HTMLElement} */ ( |
62 this.querySelector('#extension-load-error-reason')); | 62 this.querySelector('#extension-load-error-reason')); |
63 | 63 |
64 /** | 64 /** |
65 * The element which displays the manifest code. | 65 * The element which displays the manifest code. |
66 * @type {extensions.ExtensionCode} | 66 * @type {extensions.ExtensionCode} |
67 * @private | 67 * @private |
68 */ | 68 */ |
69 this.manifest_ = new extensions.ExtensionCode( | 69 this.manifest_ = new extensions.ExtensionCode( |
70 this.querySelector('#extension-load-error-manifest')); | 70 this.querySelector('#extension-load-error-manifest')); |
71 | 71 |
72 /** | 72 /** |
73 * The element which displays information about additional errors. | 73 * The element which displays information about additional errors. |
74 * @type {HTMLElement} | 74 * @type {HTMLElement} |
75 * @private | 75 * @private |
76 */ | 76 */ |
77 this.additional_ = /** @type {HTMLUListElement} */( | 77 this.additional_ = /** @type {HTMLUListElement} */ ( |
78 this.querySelector('#extension-load-error-additional')); | 78 this.querySelector('#extension-load-error-additional')); |
79 this.additional_.list = this.additional_.getElementsByTagName('ul')[0]; | 79 this.additional_.list = this.additional_.getElementsByTagName('ul')[0]; |
80 | 80 |
81 /** | 81 /** |
82 * An array of Failures for keeping track of multiple active failures. | 82 * An array of Failures for keeping track of multiple active failures. |
83 * @type {Array<Failure>} | 83 * @type {Array<Failure>} |
84 * @private | 84 * @private |
85 */ | 85 */ |
86 this.failures_ = []; | 86 this.failures_ = []; |
87 | 87 |
88 this.querySelector('#extension-load-error-retry-button').addEventListener( | 88 this.querySelector('#extension-load-error-retry-button') |
89 'click', function(e) { | 89 .addEventListener('click', function(e) { |
90 chrome.send('extensionLoaderRetry'); | 90 chrome.send('extensionLoaderRetry'); |
91 this.remove_(); | 91 this.remove_(); |
92 }.bind(this)); | 92 }.bind(this)); |
93 | 93 |
94 this.querySelector('#extension-load-error-give-up-button'). | 94 this.querySelector('#extension-load-error-give-up-button') |
95 addEventListener('click', function(e) { | 95 .addEventListener('click', function(e) { |
96 chrome.send('extensionLoaderIgnoreFailure'); | 96 chrome.send('extensionLoaderIgnoreFailure'); |
97 this.remove_(); | 97 this.remove_(); |
98 }.bind(this)); | 98 }.bind(this)); |
99 | 99 |
100 chrome.send('extensionLoaderDisplayFailures'); | 100 chrome.send('extensionLoaderDisplayFailures'); |
101 }, | 101 }, |
102 | 102 |
103 /** | 103 /** |
104 * Add a failure to failures_ array. If there is already a displayed | 104 * Add a failure to failures_ array. If there is already a displayed |
105 * failure, display the additional failures element. | 105 * failure, display the additional failures element. |
106 * @param {Array<Object>} failures Array of failures containing paths, | 106 * @param {Array<Object>} failures Array of failures containing paths, |
107 * errors, and manifests. | 107 * errors, and manifests. |
108 * @private | 108 * @private |
109 */ | 109 */ |
110 add_: function(failures) { | 110 add_: function(failures) { |
111 // If a failure is already being displayed, unhide the last item. | 111 // If a failure is already being displayed, unhide the last item. |
112 if (this.failures_.length > 0) | 112 if (this.failures_.length > 0) |
113 this.failures_[this.failures_.length - 1].listElement.hidden = false; | 113 this.failures_[this.failures_.length - 1].listElement.hidden = false; |
114 failures.forEach(function(failure) { | 114 failures.forEach(function(failure) { |
115 var listItem = /** @type {HTMLLIElement} */( | 115 var listItem = |
116 document.createElement('li')); | 116 /** @type {HTMLLIElement} */ (document.createElement('li')); |
117 listItem.textContent = failure.path; | 117 listItem.textContent = failure.path; |
118 this.additional_.list.appendChild(listItem); | 118 this.additional_.list.appendChild(listItem); |
119 this.failures_.push(new Failure(failure.path, | 119 this.failures_.push(new Failure( |
120 failure.error, | 120 failure.path, failure.error, failure.manifest, listItem)); |
121 failure.manifest, | |
122 listItem)); | |
123 }.bind(this)); | 121 }.bind(this)); |
124 // Hide the last item because the UI is displaying its information. | 122 // Hide the last item because the UI is displaying its information. |
125 this.failures_[this.failures_.length - 1].listElement.hidden = true; | 123 this.failures_[this.failures_.length - 1].listElement.hidden = true; |
126 this.show_(); | 124 this.show_(); |
127 }, | 125 }, |
128 | 126 |
129 /** | 127 /** |
130 * Remove a failure from |failures_| array. If this was the last failure, | 128 * Remove a failure from |failures_| array. If this was the last failure, |
131 * hide the error UI. If this was the last additional failure, hide | 129 * hide the error UI. If this was the last additional failure, hide |
132 * the additional failures UI. | 130 * the additional failures UI. |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 * @constructor | 170 * @constructor |
173 */ | 171 */ |
174 function ExtensionLoader() { | 172 function ExtensionLoader() { |
175 /** | 173 /** |
176 * The ExtensionLoadError to show any errors from loading an unpacked | 174 * The ExtensionLoadError to show any errors from loading an unpacked |
177 * extension. | 175 * extension. |
178 * @type {ExtensionLoadError} | 176 * @type {ExtensionLoadError} |
179 * @private | 177 * @private |
180 */ | 178 */ |
181 this.loadError_ = new ExtensionLoadError( | 179 this.loadError_ = new ExtensionLoadError( |
182 /** @type {HTMLDivElement} */($('extension-load-error'))); | 180 /** @type {HTMLDivElement} */ ($('extension-load-error'))); |
183 } | 181 } |
184 | 182 |
185 cr.addSingletonGetter(ExtensionLoader); | 183 cr.addSingletonGetter(ExtensionLoader); |
186 | 184 |
187 ExtensionLoader.prototype = { | 185 ExtensionLoader.prototype = { |
188 /** | 186 /** |
189 * Whether or not we are currently loading an unpacked extension. | 187 * Whether or not we are currently loading an unpacked extension. |
190 * @private {boolean} | 188 * @private {boolean} |
191 */ | 189 */ |
192 isLoading_: false, | 190 isLoading_: false, |
(...skipping 28 matching lines...) Expand all Loading... |
221 /** | 219 /** |
222 * A static forwarding function for ExtensionLoader.notifyFailed. | 220 * A static forwarding function for ExtensionLoader.notifyFailed. |
223 * @param {Array<Object>} failures Array of failures containing paths, | 221 * @param {Array<Object>} failures Array of failures containing paths, |
224 * errors, and manifests. | 222 * errors, and manifests. |
225 * @see ExtensionLoader.notifyFailed | 223 * @see ExtensionLoader.notifyFailed |
226 */ | 224 */ |
227 ExtensionLoader.notifyLoadFailed = function(failures) { | 225 ExtensionLoader.notifyLoadFailed = function(failures) { |
228 ExtensionLoader.getInstance().notifyFailed(failures); | 226 ExtensionLoader.getInstance().notifyFailed(failures); |
229 }; | 227 }; |
230 | 228 |
231 return { | 229 return {ExtensionLoader: ExtensionLoader}; |
232 ExtensionLoader: ExtensionLoader | |
233 }; | |
234 }); | 230 }); |
OLD | NEW |