| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 * Clone a template within the extension error template collection. | 9 * Clone a template within the extension error template collection. |
| 10 * @param {string} templateName The class name of the template to clone. | 10 * @param {string} templateName The class name of the template to clone. |
| 11 * @return {HTMLElement} The clone of the template. | 11 * @return {HTMLElement} The clone of the template. |
| 12 */ | 12 */ |
| 13 function cloneTemplate(templateName) { | 13 function cloneTemplate(templateName) { |
| 14 return /** @type {HTMLElement} */($('template-collection-extension-error'). | 14 return /** @type {HTMLElement} */ ($('template-collection-extension-error') |
| 15 querySelector('.' + templateName).cloneNode(true)); | 15 .querySelector('.' + templateName) |
| 16 .cloneNode(true)); |
| 16 } | 17 } |
| 17 | 18 |
| 18 /** | 19 /** |
| 19 * Checks that an Extension ID follows the proper format (i.e., is 32 | 20 * Checks that an Extension ID follows the proper format (i.e., is 32 |
| 20 * characters long, is lowercase, and contains letters in the range [a, p]). | 21 * characters long, is lowercase, and contains letters in the range [a, p]). |
| 21 * @param {string} id The Extension ID to test. | 22 * @param {string} id The Extension ID to test. |
| 22 * @return {boolean} Whether or not the ID is valid. | 23 * @return {boolean} Whether or not the ID is valid. |
| 23 */ | 24 */ |
| 24 function idIsValid(id) { | 25 function idIsValid(id) { |
| 25 return /^[a-p]{32}$/.test(id); | 26 return /^[a-p]{32}$/.test(id); |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 var iconNode = document.createElement('img'); | 95 var iconNode = document.createElement('img'); |
| 95 iconNode.className = 'extension-error-icon'; | 96 iconNode.className = 'extension-error-icon'; |
| 96 iconNode.alt = loadTimeData.getString(iconAltTextKey); | 97 iconNode.alt = loadTimeData.getString(iconAltTextKey); |
| 97 this.insertBefore(iconNode, this.firstChild); | 98 this.insertBefore(iconNode, this.firstChild); |
| 98 | 99 |
| 99 var messageSpan = this.querySelector('.extension-error-message'); | 100 var messageSpan = this.querySelector('.extension-error-message'); |
| 100 messageSpan.textContent = error.message; | 101 messageSpan.textContent = error.message; |
| 101 | 102 |
| 102 var deleteButton = this.querySelector('.error-delete-button'); | 103 var deleteButton = this.querySelector('.error-delete-button'); |
| 103 deleteButton.addEventListener('click', function(e) { | 104 deleteButton.addEventListener('click', function(e) { |
| 104 this.dispatchEvent( | 105 this.dispatchEvent(new CustomEvent( |
| 105 new CustomEvent('deleteExtensionError', | 106 'deleteExtensionError', {bubbles: true, detail: this.error})); |
| 106 {bubbles: true, detail: this.error})); | |
| 107 }.bind(this)); | 107 }.bind(this)); |
| 108 | 108 |
| 109 this.addEventListener('click', function(e) { | 109 this.addEventListener('click', function(e) { |
| 110 if (e.target != deleteButton) | 110 if (e.target != deleteButton) |
| 111 this.requestActive_(); | 111 this.requestActive_(); |
| 112 }.bind(this)); | 112 }.bind(this)); |
| 113 | 113 |
| 114 this.addEventListener('keydown', function(e) { | 114 this.addEventListener('keydown', function(e) { |
| 115 if (e.key == 'Enter' && e.target != deleteButton) | 115 if (e.key == 'Enter' && e.target != deleteButton) |
| 116 this.requestActive_(); | 116 this.requestActive_(); |
| 117 }); | 117 }); |
| 118 }, | 118 }, |
| 119 | 119 |
| 120 /** | 120 /** |
| 121 * Bubble up an event to request to become active. | 121 * Bubble up an event to request to become active. |
| 122 * @private | 122 * @private |
| 123 */ | 123 */ |
| 124 requestActive_: function() { | 124 requestActive_: function() { |
| 125 this.dispatchEvent( | 125 this.dispatchEvent(new CustomEvent( |
| 126 new CustomEvent('highlightExtensionError', | 126 'highlightExtensionError', {bubbles: true, detail: this.error})); |
| 127 {bubbles: true, detail: this.error})); | |
| 128 }, | 127 }, |
| 129 }; | 128 }; |
| 130 | 129 |
| 131 /** | 130 /** |
| 132 * A variable length list of runtime or manifest errors for a given extension. | 131 * A variable length list of runtime or manifest errors for a given extension. |
| 133 * @param {Array<(RuntimeError|ManifestError)>} errors The list of extension | 132 * @param {Array<(RuntimeError|ManifestError)>} errors The list of extension |
| 134 * errors with which to populate the list. | 133 * errors with which to populate the list. |
| 135 * @param {string} extensionId The id of the extension. | 134 * @param {string} extensionId The id of the extension. |
| 136 * @constructor | 135 * @constructor |
| 137 * @extends {HTMLDivElement} | 136 * @extends {HTMLDivElement} |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 | 181 |
| 183 this.focusGrid_.ensureRowActive(); | 182 this.focusGrid_.ensureRowActive(); |
| 184 | 183 |
| 185 this.addEventListener('highlightExtensionError', function(e) { | 184 this.addEventListener('highlightExtensionError', function(e) { |
| 186 this.setActiveErrorNode_(e.target); | 185 this.setActiveErrorNode_(e.target); |
| 187 }); | 186 }); |
| 188 this.addEventListener('deleteExtensionError', function(e) { | 187 this.addEventListener('deleteExtensionError', function(e) { |
| 189 this.removeError_(e.detail); | 188 this.removeError_(e.detail); |
| 190 }); | 189 }); |
| 191 | 190 |
| 192 this.querySelector('#extension-error-list-clear').addEventListener( | 191 this.querySelector('#extension-error-list-clear') |
| 193 'click', function(e) { | 192 .addEventListener('click', function(e) { |
| 194 this.clear(true); | 193 this.clear(true); |
| 195 }.bind(this)); | 194 }.bind(this)); |
| 196 | 195 |
| 197 /** | 196 /** |
| 198 * The callback for the extension changed event. | 197 * The callback for the extension changed event. |
| 199 * @private {function(chrome.developerPrivate.EventData):void} | 198 * @private {function(chrome.developerPrivate.EventData):void} |
| 200 */ | 199 */ |
| 201 this.onItemStateChangedListener_ = function(data) { | 200 this.onItemStateChangedListener_ = function(data) { |
| 202 var type = chrome.developerPrivate.EventType; | 201 var type = chrome.developerPrivate.EventType; |
| 203 if ((data.event_type == type.ERRORS_REMOVED || | 202 if ((data.event_type == type.ERRORS_REMOVED || |
| 204 data.event_type == type.ERROR_ADDED) && | 203 data.event_type == type.ERROR_ADDED) && |
| 205 data.extensionInfo.id == this.extensionId_) { | 204 data.extensionInfo.id == this.extensionId_) { |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 264 | 263 |
| 265 // TODO(dbeam): in a world where this UI is actually used, we should | 264 // TODO(dbeam): in a world where this UI is actually used, we should |
| 266 // probably move the focus before removing |listElement|. | 265 // probably move the focus before removing |listElement|. |
| 267 listElement.parentNode.removeChild(listElement); | 266 listElement.parentNode.removeChild(listElement); |
| 268 | 267 |
| 269 if (wasActive) { | 268 if (wasActive) { |
| 270 index = Math.min(index, this.errors_.length - 1); | 269 index = Math.min(index, this.errors_.length - 1); |
| 271 this.setActiveError(index); // Gracefully handles the -1 case. | 270 this.setActiveError(index); // Gracefully handles the -1 case. |
| 272 } | 271 } |
| 273 | 272 |
| 274 chrome.developerPrivate.deleteExtensionErrors({ | 273 chrome.developerPrivate.deleteExtensionErrors( |
| 275 extensionId: error.extensionId, | 274 {extensionId: error.extensionId, errorIds: [error.id]}); |
| 276 errorIds: [error.id] | |
| 277 }); | |
| 278 | 275 |
| 279 if (this.errors_.length == 0) | 276 if (this.errors_.length == 0) |
| 280 this.querySelector('#no-errors-span').hidden = false; | 277 this.querySelector('#no-errors-span').hidden = false; |
| 281 }, | 278 }, |
| 282 | 279 |
| 283 /** | 280 /** |
| 284 * Updates the list of errors. | 281 * Updates the list of errors. |
| 285 * @param {!Array<(ManifestError|RuntimeError)>} newErrors The new list of | 282 * @param {!Array<(ManifestError|RuntimeError)>} newErrors The new list of |
| 286 * errors. | 283 * errors. |
| 287 * @private | 284 * @private |
| (...skipping 26 matching lines...) Expand all Loading... |
| 314 * @param {number} index The index to set to be active. | 311 * @param {number} index The index to set to be active. |
| 315 */ | 312 */ |
| 316 setActiveError: function(index) { | 313 setActiveError: function(index) { |
| 317 var errorList = this.querySelector('.extension-error-list-contents'); | 314 var errorList = this.querySelector('.extension-error-list-contents'); |
| 318 var item = errorList.children[index]; | 315 var item = errorList.children[index]; |
| 319 this.setActiveErrorNode_( | 316 this.setActiveErrorNode_( |
| 320 item ? item.querySelector('.extension-error-metadata') : null); | 317 item ? item.querySelector('.extension-error-metadata') : null); |
| 321 var node = null; | 318 var node = null; |
| 322 if (index >= 0 && index < errorList.children.length) { | 319 if (index >= 0 && index < errorList.children.length) { |
| 323 node = errorList.children[index].querySelector( | 320 node = errorList.children[index].querySelector( |
| 324 '.extension-error-metadata'); | 321 '.extension-error-metadata'); |
| 325 } | 322 } |
| 326 this.setActiveErrorNode_(node); | 323 this.setActiveErrorNode_(node); |
| 327 }, | 324 }, |
| 328 | 325 |
| 329 /** | 326 /** |
| 330 * Clears the list of all errors. | 327 * Clears the list of all errors. |
| 331 * @param {boolean} deleteErrors Whether or not the errors should be deleted | 328 * @param {boolean} deleteErrors Whether or not the errors should be deleted |
| 332 * on the backend. | 329 * on the backend. |
| 333 */ | 330 */ |
| 334 clear: function(deleteErrors) { | 331 clear: function(deleteErrors) { |
| 335 if (this.errors_.length == 0) | 332 if (this.errors_.length == 0) |
| 336 return; | 333 return; |
| 337 | 334 |
| 338 if (deleteErrors) { | 335 if (deleteErrors) { |
| 339 var ids = this.errors_.map(function(error) { return error.id; }); | 336 var ids = this.errors_.map(function(error) { |
| 340 chrome.developerPrivate.deleteExtensionErrors({ | 337 return error.id; |
| 341 extensionId: this.extensionId_, | |
| 342 errorIds: ids | |
| 343 }); | 338 }); |
| 339 chrome.developerPrivate.deleteExtensionErrors( |
| 340 {extensionId: this.extensionId_, errorIds: ids}); |
| 344 } | 341 } |
| 345 | 342 |
| 346 this.setActiveErrorNode_(null); | 343 this.setActiveErrorNode_(null); |
| 347 this.errors_.length = 0; | 344 this.errors_.length = 0; |
| 348 var errorList = this.querySelector('.extension-error-list-contents'); | 345 var errorList = this.querySelector('.extension-error-list-contents'); |
| 349 while (errorList.firstChild) | 346 while (errorList.firstChild) |
| 350 errorList.removeChild(errorList.firstChild); | 347 errorList.removeChild(errorList.firstChild); |
| 351 }, | 348 }, |
| 352 | 349 |
| 353 /** | 350 /** |
| 354 * Sets the active error in the list. | 351 * Sets the active error in the list. |
| 355 * @param {?} node The error to make active. | 352 * @param {?} node The error to make active. |
| 356 * @private | 353 * @private |
| 357 */ | 354 */ |
| 358 setActiveErrorNode_: function(node) { | 355 setActiveErrorNode_: function(node) { |
| 359 if (this.activeError_) | 356 if (this.activeError_) |
| 360 this.activeError_.classList.remove('extension-error-active'); | 357 this.activeError_.classList.remove('extension-error-active'); |
| 361 | 358 |
| 362 if (node) | 359 if (node) |
| 363 node.classList.add('extension-error-active'); | 360 node.classList.add('extension-error-active'); |
| 364 | 361 |
| 365 this.activeError_ = node; | 362 this.activeError_ = node; |
| 366 | 363 |
| 367 this.dispatchEvent( | 364 this.dispatchEvent(new CustomEvent( |
| 368 new CustomEvent('activeExtensionErrorChanged', | 365 'activeExtensionErrorChanged', |
| 369 {bubbles: true, detail: node ? node.error : null})); | 366 {bubbles: true, detail: node ? node.error : null})); |
| 370 }, | 367 }, |
| 371 }; | 368 }; |
| 372 | 369 |
| 373 return { | 370 return {ExtensionErrorList: ExtensionErrorList}; |
| 374 ExtensionErrorList: ExtensionErrorList | |
| 375 }; | |
| 376 }); | 371 }); |
| OLD | NEW |