Chromium Code Reviews| 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. |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 52 div.__proto__ = ExtensionError.prototype; | 52 div.__proto__ = ExtensionError.prototype; |
| 53 div.decorateWithError_(error, boundary); | 53 div.decorateWithError_(error, boundary); |
| 54 return div; | 54 return div; |
| 55 } | 55 } |
| 56 | 56 |
| 57 ExtensionError.prototype = { | 57 ExtensionError.prototype = { |
| 58 __proto__: cr.ui.FocusRow.prototype, | 58 __proto__: cr.ui.FocusRow.prototype, |
| 59 | 59 |
| 60 /** @override */ | 60 /** @override */ |
| 61 getEquivalentElement: function(element) { | 61 getEquivalentElement: function(element) { |
| 62 if (element.classList.contains('extension-error-metadata')) | 62 return element.classList.contains('error-delete-button') ? |
| 63 return this; | 63 this.deleteButton_ : this.messageSpan_; |
|
Dan Beam
2015/08/11 02:46:54
returning a default within |this| seems like a bet
| |
| 64 if (element.classList.contains('error-delete-button')) { | |
| 65 return /** @type {!HTMLElement} */ (this.querySelector( | |
| 66 '.error-delete-button')); | |
| 67 } | |
| 68 assertNotReached(); | |
| 69 return element; | |
| 70 }, | 64 }, |
| 71 | 65 |
| 72 /** | 66 /** |
| 73 * @param {(RuntimeError|ManifestError)} error The error the element should | 67 * @param {(RuntimeError|ManifestError)} error The error the element should |
| 74 * represent. | 68 * represent. |
| 75 * @param {Element} boundary The boundary for the FocusGrid. | 69 * @param {Element} boundary The boundary for the FocusGrid. |
| 76 * @private | 70 * @private |
| 77 */ | 71 */ |
| 78 decorateWithError_: function(error, boundary) { | 72 decorateWithError_: function(error, boundary) { |
| 79 this.decorate(boundary); | 73 this.decorate(boundary); |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 104 this.classList.add('extension-error-severity-warning'); | 98 this.classList.add('extension-error-severity-warning'); |
| 105 } | 99 } |
| 106 | 100 |
| 107 var iconNode = document.createElement('img'); | 101 var iconNode = document.createElement('img'); |
| 108 iconNode.className = 'extension-error-icon'; | 102 iconNode.className = 'extension-error-icon'; |
| 109 // TODO(hcarmona): Populate alt text with a proper description since this | 103 // TODO(hcarmona): Populate alt text with a proper description since this |
| 110 // icon conveys the severity of the error. (info, warning, fatal). | 104 // icon conveys the severity of the error. (info, warning, fatal). |
| 111 iconNode.alt = ''; | 105 iconNode.alt = ''; |
| 112 this.insertBefore(iconNode, this.firstChild); | 106 this.insertBefore(iconNode, this.firstChild); |
| 113 | 107 |
| 114 var messageSpan = this.querySelector('.extension-error-message'); | 108 this.messageSpan_ = this.querySelector('.extension-error-message'); |
| 115 messageSpan.textContent = error.message; | 109 this.messageSpan_.textContent = error.message; |
| 116 | 110 |
| 117 var deleteButton = this.querySelector('.error-delete-button'); | 111 this.deleteButton_ = this.querySelector('.error-delete-button'); |
| 118 deleteButton.addEventListener('click', function(e) { | 112 this.deleteButton_.addEventListener('click', function(e) { |
|
Dan Beam
2015/08/11 02:46:54
^ this never worked for keyboard events
| |
| 119 this.dispatchEvent( | 113 this.dispatchEvent( |
| 120 new CustomEvent('deleteExtensionError', | 114 new CustomEvent('deleteExtensionError', |
| 121 {bubbles: true, detail: this.error})); | 115 {bubbles: true, detail: this.error})); |
| 122 }.bind(this)); | 116 }.bind(this)); |
| 123 | 117 |
| 124 this.addEventListener('click', function(e) { | 118 this.addEventListener('click', function(e) { |
| 125 if (e.target != deleteButton) | 119 if (e.target != this.deleteButton_) |
| 126 this.requestActive_(); | 120 this.requestActive_(); |
| 127 }.bind(this)); | 121 }.bind(this)); |
| 128 this.addEventListener('keydown', function(e) { | 122 this.addEventListener('keydown', function(e) { |
| 129 if (e.keyIdentifier == 'Enter' && e.target != deleteButton) | 123 if (e.keyIdentifier == 'Enter' && e.target != this.deleteButton_) |
| 130 this.requestActive_(); | 124 this.requestActive_(); |
| 131 }); | 125 }); |
| 132 | 126 |
| 133 this.addFocusableElement(this); | 127 this.addFocusableElement(this.messageSpan_); |
| 134 this.addFocusableElement(deleteButton); | 128 this.addFocusableElement(this.deleteButton_); |
| 135 }, | 129 }, |
| 136 | 130 |
| 137 /** | 131 /** |
| 138 * Bubble up an event to request to become active. | 132 * Bubble up an event to request to become active. |
| 139 * @private | 133 * @private |
| 140 */ | 134 */ |
| 141 requestActive_: function() { | 135 requestActive_: function() { |
| 142 this.dispatchEvent( | 136 this.dispatchEvent( |
| 143 new CustomEvent('highlightExtensionError', | 137 new CustomEvent('highlightExtensionError', |
| 144 {bubbles: true, detail: this.error})); | 138 {bubbles: true, detail: this.error})); |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 172 /** | 166 /** |
| 173 * @private {!Array<(ManifestError|RuntimeError)>} | 167 * @private {!Array<(ManifestError|RuntimeError)>} |
| 174 */ | 168 */ |
| 175 this.errors_ = []; | 169 this.errors_ = []; |
| 176 | 170 |
| 177 this.focusGrid_ = new cr.ui.FocusGrid(); | 171 this.focusGrid_ = new cr.ui.FocusGrid(); |
| 178 this.listContents_ = this.querySelector('.extension-error-list-contents'); | 172 this.listContents_ = this.querySelector('.extension-error-list-contents'); |
| 179 | 173 |
| 180 errors.forEach(this.addError_, this); | 174 errors.forEach(this.addError_, this); |
| 181 | 175 |
| 176 this.focusGrid_.ensureRowActive(); | |
|
Dan Beam
2015/08/11 02:46:53
this was never called initially
| |
| 177 | |
| 182 this.addEventListener('highlightExtensionError', function(e) { | 178 this.addEventListener('highlightExtensionError', function(e) { |
| 183 this.setActiveErrorNode_(e.target); | 179 this.setActiveErrorNode_(e.target); |
| 184 }); | 180 }); |
| 185 this.addEventListener('deleteExtensionError', function(e) { | 181 this.addEventListener('deleteExtensionError', function(e) { |
| 186 this.removeError_(e.detail); | 182 this.removeError_(e.detail); |
| 187 }); | 183 }); |
| 188 | 184 |
| 189 this.querySelector('#extension-error-list-clear').addEventListener( | 185 this.querySelector('#extension-error-list-clear').addEventListener( |
| 190 'click', function(e) { | 186 'click', function(e) { |
| 191 this.clear(true); | 187 this.clear(true); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 243 break; | 239 break; |
| 244 } | 240 } |
| 245 assert(index != this.errors_.length); | 241 assert(index != this.errors_.length); |
| 246 var errorList = this.querySelector('.extension-error-list-contents'); | 242 var errorList = this.querySelector('.extension-error-list-contents'); |
| 247 | 243 |
| 248 var wasActive = | 244 var wasActive = |
| 249 this.activeError_ && this.activeError_.error.id == error.id; | 245 this.activeError_ && this.activeError_.error.id == error.id; |
| 250 | 246 |
| 251 this.errors_.splice(index, 1); | 247 this.errors_.splice(index, 1); |
| 252 var listElement = errorList.children[index]; | 248 var listElement = errorList.children[index]; |
| 249 | |
| 250 var focusRow = assertInstanceof(listElement, ExtensionError); | |
|
Dan Beam
2015/08/11 02:46:54
nodes were removed from the DOM but not from |this
| |
| 251 this.focusGrid_.removeRow(focusRow); | |
| 252 this.focusGrid_.ensureRowActive(); | |
| 253 | |
| 254 // TODO(dbeam): in a world where this UI is actually used, we should | |
| 255 // probably move the focus before removing |listElement|. | |
| 253 listElement.parentNode.removeChild(listElement); | 256 listElement.parentNode.removeChild(listElement); |
| 254 | 257 |
| 255 if (wasActive) { | 258 if (wasActive) { |
| 256 index = Math.min(index, this.errors_.length - 1); | 259 index = Math.min(index, this.errors_.length - 1); |
| 257 this.setActiveError(index); // Gracefully handles the -1 case. | 260 this.setActiveError(index); // Gracefully handles the -1 case. |
| 258 } | 261 } |
| 259 | 262 |
| 260 chrome.developerPrivate.deleteExtensionErrors({ | 263 chrome.developerPrivate.deleteExtensionErrors({ |
| 261 extensionId: error.extensionId, | 264 extensionId: error.extensionId, |
| 262 errorIds: [error.id] | 265 errorIds: [error.id] |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 353 this.dispatchEvent( | 356 this.dispatchEvent( |
| 354 new CustomEvent('activeExtensionErrorChanged', | 357 new CustomEvent('activeExtensionErrorChanged', |
| 355 {bubbles: true, detail: node ? node.error : null})); | 358 {bubbles: true, detail: node ? node.error : null})); |
| 356 }, | 359 }, |
| 357 }; | 360 }; |
| 358 | 361 |
| 359 return { | 362 return { |
| 360 ExtensionErrorList: ExtensionErrorList | 363 ExtensionErrorList: ExtensionErrorList |
| 361 }; | 364 }; |
| 362 }); | 365 }); |
| OLD | NEW |