| 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 */ | 12 */ |
| 13 function ExtensionLoadError(div) { | 13 function ExtensionLoadError(div) { |
| 14 div.__proto__ = ExtensionLoadError.prototype; | 14 div.__proto__ = ExtensionLoadError.prototype; |
| 15 div.init(); | 15 div.init(); |
| 16 return div; | 16 return div; |
| 17 } | 17 } |
| 18 | 18 |
| 19 /** | 19 /** |
| 20 * Construct a Failure. | 20 * Construct a Failure. |
| 21 * @param {string} filePath The path to the unpacked extension. | 21 * @param {string} filePath The path to the unpacked extension. |
| 22 * @param {string} reason The reason the extension failed to load. | 22 * @param {string} error The reason the extension failed to load. |
| 23 * @param {Object} manifest An object with three strings: beforeHighlight, | 23 * @param {Object} manifest An object with three strings: beforeHighlight, |
| 24 * afterHighlight, and highlight. These represent three portions of the | 24 * afterHighlight, and highlight. These represent three portions of the |
| 25 * file's content to display - the portion which is most relevant and | 25 * file's content to display - the portion which is most relevant and |
| 26 * should be emphasized (highlight), and the parts both before and after | 26 * should be emphasized (highlight), and the parts both before and after |
| 27 * this portion. These may be empty. | 27 * this portion. These may be empty. |
| 28 * @param {HTMLLIElement} listElement The HTML element used for displaying the | 28 * @param {HTMLLIElement} listElement The HTML element used for displaying the |
| 29 * failure path for the additional failures UI. | 29 * failure path for the additional failures UI. |
| 30 * @constructor | 30 * @constructor |
| 31 */ | 31 */ |
| 32 function Failure(filePath, reason, manifest, listElement) { | 32 function Failure(filePath, error, manifest, listElement) { |
| 33 this.path = filePath; | 33 this.path = filePath; |
| 34 this.reason = reason; | 34 this.error = error; |
| 35 this.manifest = manifest; | 35 this.manifest = manifest; |
| 36 this.listElement = listElement; | 36 this.listElement = listElement; |
| 37 } | 37 } |
| 38 | 38 |
| 39 ExtensionLoadError.prototype = { | 39 ExtensionLoadError.prototype = { |
| 40 __proto__: HTMLDivElement.prototype, | 40 __proto__: HTMLDivElement.prototype, |
| 41 | 41 |
| 42 /** | 42 /** |
| 43 * Initialize the ExtensionLoadError div. | 43 * Initialize the ExtensionLoadError div. |
| 44 */ | 44 */ |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 * Add a failure to failures_ array. If there is already a displayed | 99 * Add a failure to failures_ array. If there is already a displayed |
| 100 * failure, display the additional failures element. | 100 * failure, display the additional failures element. |
| 101 * @param {Array.<Object>} failures Array of failures containing paths, | 101 * @param {Array.<Object>} failures Array of failures containing paths, |
| 102 * errors, and manifests. | 102 * errors, and manifests. |
| 103 * @private | 103 * @private |
| 104 */ | 104 */ |
| 105 add_: function(failures) { | 105 add_: function(failures) { |
| 106 // If a failure is already being displayed, unhide the last item. | 106 // If a failure is already being displayed, unhide the last item. |
| 107 if (this.failures_.length > 0) | 107 if (this.failures_.length > 0) |
| 108 this.failures_[this.failures_.length - 1].listElement.hidden = false; | 108 this.failures_[this.failures_.length - 1].listElement.hidden = false; |
| 109 for (var i = 0; i < failures.length; ++i) { | 109 failures.forEach(function(failure) { |
| 110 var listItem = document.createElement('li'); | 110 var listItem = document.createElement('li'); |
| 111 listItem.textContent = failures[i].path; | 111 listItem.textContent = failure.path; |
| 112 this.additional_.list.appendChild(listItem); | 112 this.additional_.list.appendChild(listItem); |
| 113 failures[i].listElement = listItem; | 113 this.failures_.push(new Failure(failure.path, |
| 114 this.failures_.push(failures[i]); | 114 failure.error, |
| 115 } | 115 failure.manifest, |
| 116 listItem)); |
| 117 }.bind(this)); |
| 116 // Hide the last item because the UI is displaying its information. | 118 // Hide the last item because the UI is displaying its information. |
| 117 this.failures_[this.failures_.length - 1].listElement.hidden = true; | 119 this.failures_[this.failures_.length - 1].listElement.hidden = true; |
| 118 this.show_(); | 120 this.show_(); |
| 119 }, | 121 }, |
| 120 | 122 |
| 121 /** | 123 /** |
| 122 * Remove a failure from |failures_| array. If this was the last failure, | 124 * Remove a failure from |failures_| array. If this was the last failure, |
| 123 * hide the error UI. If this was the last additional failure, hide | 125 * hide the error UI. If this was the last additional failure, hide |
| 124 * the additional failures UI. | 126 * the additional failures UI. |
| 125 * @private | 127 * @private |
| (...skipping 13 matching lines...) Expand all Loading... |
| 139 /** | 141 /** |
| 140 * Display the load error to the user. The last failure gets its manifest | 142 * Display the load error to the user. The last failure gets its manifest |
| 141 * and error displayed, while additional failures have their path names | 143 * and error displayed, while additional failures have their path names |
| 142 * displayed in the additional failures element. | 144 * displayed in the additional failures element. |
| 143 * @private | 145 * @private |
| 144 */ | 146 */ |
| 145 show_: function() { | 147 show_: function() { |
| 146 assert(this.failures_.length >= 1); | 148 assert(this.failures_.length >= 1); |
| 147 var failure = this.failures_[this.failures_.length - 1]; | 149 var failure = this.failures_[this.failures_.length - 1]; |
| 148 this.path_.textContent = failure.path; | 150 this.path_.textContent = failure.path; |
| 149 this.reason_.textContent = failure.reason; | 151 this.reason_.textContent = failure.error; |
| 150 | 152 |
| 151 failure.manifest.message = failure.reason; | 153 failure.manifest.message = failure.error; |
| 152 this.manifest_.populate( | 154 this.manifest_.populate( |
| 153 failure.manifest, | 155 failure.manifest, |
| 154 loadTimeData.getString('extensionLoadCouldNotLoadManifest')); | 156 loadTimeData.getString('extensionLoadCouldNotLoadManifest')); |
| 155 this.hidden = false; | 157 this.hidden = false; |
| 156 this.manifest_.scrollToError(); | 158 this.manifest_.scrollToError(); |
| 157 | 159 |
| 158 this.additional_.hidden = this.failures_.length == 1; | 160 this.additional_.hidden = this.failures_.length == 1; |
| 159 } | 161 } |
| 160 }; | 162 }; |
| 161 | 163 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 * @see ExtensionLoader.notifyFailed | 204 * @see ExtensionLoader.notifyFailed |
| 203 */ | 205 */ |
| 204 ExtensionLoader.notifyLoadFailed = function(failures) { | 206 ExtensionLoader.notifyLoadFailed = function(failures) { |
| 205 ExtensionLoader.getInstance().notifyFailed(failures); | 207 ExtensionLoader.getInstance().notifyFailed(failures); |
| 206 }; | 208 }; |
| 207 | 209 |
| 208 return { | 210 return { |
| 209 ExtensionLoader: ExtensionLoader | 211 ExtensionLoader: ExtensionLoader |
| 210 }; | 212 }; |
| 211 }); | 213 }); |
| OLD | NEW |