OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <include src="extension_error.js"> | 5 <include src="extension_error.js"> |
6 | 6 |
7 /////////////////////////////////////////////////////////////////////////////// | 7 /////////////////////////////////////////////////////////////////////////////// |
8 // ExtensionFocusRow: | 8 // ExtensionFocusRow: |
9 | 9 |
10 /** | 10 /** |
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
228 */ | 228 */ |
229 enableAppInfoDialog_: false, | 229 enableAppInfoDialog_: false, |
230 | 230 |
231 /** | 231 /** |
232 * Initializes the list. | 232 * Initializes the list. |
233 */ | 233 */ |
234 initialize: function() { | 234 initialize: function() { |
235 /** @private {!Array<ExtensionInfo>} */ | 235 /** @private {!Array<ExtensionInfo>} */ |
236 this.extensions_ = []; | 236 this.extensions_ = []; |
237 | 237 |
| 238 /** |
| 239 * |loadFinished| should be used for testing purposes and will be |
| 240 * fulfilled when this list has finished loading the first time. |
| 241 * @type {Promise} |
| 242 * */ |
| 243 this.loadFinished = new Promise(function(resolve, reject) { |
| 244 /** @private {function(?)} */ |
| 245 this.resolveLoadFinished_ = resolve; |
| 246 }.bind(this)); |
| 247 |
238 chrome.developerPrivate.onItemStateChanged.addListener( | 248 chrome.developerPrivate.onItemStateChanged.addListener( |
239 function(eventData) { | 249 function(eventData) { |
240 var EventType = chrome.developerPrivate.EventType; | 250 var EventType = chrome.developerPrivate.EventType; |
241 switch (eventData.event_type) { | 251 switch (eventData.event_type) { |
242 case EventType.VIEW_REGISTERED: | 252 case EventType.VIEW_REGISTERED: |
243 case EventType.VIEW_UNREGISTERED: | 253 case EventType.VIEW_UNREGISTERED: |
244 // For now, view notifications are handled through the WebUI. | 254 // For now, view notifications are handled through the WebUI. |
245 // TODO(devlin): Transition these. | 255 // TODO(devlin): Transition these. |
246 break; | 256 break; |
247 case EventType.INSTALLED: | 257 case EventType.INSTALLED: |
(...skipping 30 matching lines...) Expand all Loading... |
278 this.extensionsUpdated_ = new Promise(function(resolve, reject) { | 288 this.extensionsUpdated_ = new Promise(function(resolve, reject) { |
279 chrome.developerPrivate.getExtensionsInfo( | 289 chrome.developerPrivate.getExtensionsInfo( |
280 {includeDisabled: true, includeTerminated: true}, | 290 {includeDisabled: true, includeTerminated: true}, |
281 function(extensions) { | 291 function(extensions) { |
282 // Sort in order of unpacked vs. packed, followed by name, followed by | 292 // Sort in order of unpacked vs. packed, followed by name, followed by |
283 // id. | 293 // id. |
284 extensions.sort(compareExtensions); | 294 extensions.sort(compareExtensions); |
285 this.extensions_ = extensions; | 295 this.extensions_ = extensions; |
286 this.showExtensionNodes_(); | 296 this.showExtensionNodes_(); |
287 resolve(); | 297 resolve(); |
| 298 |
| 299 // |resolve| is async so it's necessary to use |then| here in order to |
| 300 // do work after other |then|s have finished. This is important so |
| 301 // elements are visible when these updates happen. |
| 302 this.extensionsUpdated_.then(function() { |
| 303 this.onUpdateFinished_(); |
| 304 this.resolveLoadFinished_(); |
| 305 }.bind(this)); |
288 }.bind(this)); | 306 }.bind(this)); |
289 }.bind(this)); | 307 }.bind(this)); |
290 return this.extensionsUpdated_; | 308 return this.extensionsUpdated_; |
291 }, | 309 }, |
292 | 310 |
| 311 /** |
| 312 * Updates elements that need to be visible in order to update properly. |
| 313 * @private |
| 314 */ |
| 315 onUpdateFinished_: function() { |
| 316 // Cannot focus or highlight a extension if there are none. |
| 317 if (this.extensions_.length == 0) |
| 318 return; |
| 319 |
| 320 assert(!this.hidden); |
| 321 assert(!this.parentElement.hidden); |
| 322 |
| 323 this.updateFocusableElements(); |
| 324 |
| 325 var idToHighlight = this.getIdQueryParam_(); |
| 326 if (idToHighlight && $(idToHighlight)) |
| 327 this.scrollToNode_(idToHighlight); |
| 328 |
| 329 var idToOpenOptions = this.getOptionsQueryParam_(); |
| 330 if (idToOpenOptions && $(idToOpenOptions)) |
| 331 this.showEmbeddedExtensionOptions_(idToOpenOptions, true); |
| 332 }, |
| 333 |
293 /** @return {number} The number of extensions being displayed. */ | 334 /** @return {number} The number of extensions being displayed. */ |
294 getNumExtensions: function() { | 335 getNumExtensions: function() { |
295 return this.extensions_.length; | 336 return this.extensions_.length; |
296 }, | 337 }, |
297 | 338 |
298 getIdQueryParam_: function() { | 339 getIdQueryParam_: function() { |
299 return parseQueryParams(document.location)['id']; | 340 return parseQueryParams(document.location)['id']; |
300 }, | 341 }, |
301 | 342 |
302 getOptionsQueryParam_: function() { | 343 getOptionsQueryParam_: function() { |
(...skipping 29 matching lines...) Expand all Loading... |
332 focusableNode.getEquivalentElement( | 373 focusableNode.getEquivalentElement( |
333 document.activeElement).focus(); | 374 document.activeElement).focus(); |
334 } | 375 } |
335 } | 376 } |
336 | 377 |
337 node.parentElement.removeChild(node); | 378 node.parentElement.removeChild(node); |
338 // Unregister the removed node from events. | 379 // Unregister the removed node from events. |
339 assertInstanceof(node, ExtensionFocusRow).destroy(); | 380 assertInstanceof(node, ExtensionFocusRow).destroy(); |
340 } | 381 } |
341 } | 382 } |
342 | |
343 var idToHighlight = this.getIdQueryParam_(); | |
344 if (idToHighlight && $(idToHighlight)) | |
345 this.scrollToNode_(idToHighlight); | |
346 | |
347 var idToOpenOptions = this.getOptionsQueryParam_(); | |
348 if (idToOpenOptions && $(idToOpenOptions)) | |
349 this.showEmbeddedExtensionOptions_(idToOpenOptions, true); | |
350 }, | 383 }, |
351 | 384 |
352 /** Updates each row's focusable elements without rebuilding the grid. */ | 385 /** Updates each row's focusable elements without rebuilding the grid. */ |
353 updateFocusableElements: function() { | 386 updateFocusableElements: function() { |
354 var rows = document.querySelectorAll('.extension-list-item-wrapper[id]'); | 387 var rows = document.querySelectorAll('.extension-list-item-wrapper[id]'); |
355 for (var i = 0; i < rows.length; ++i) { | 388 for (var i = 0; i < rows.length; ++i) { |
356 assertInstanceof(rows[i], ExtensionFocusRow).updateFocusableElements(); | 389 assertInstanceof(rows[i], ExtensionFocusRow).updateFocusableElements(); |
357 } | 390 } |
358 }, | 391 }, |
359 | 392 |
(...skipping 698 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1058 var nextExt = this.extensions_[this.extensions_.indexOf(extension) + 1]; | 1091 var nextExt = this.extensions_[this.extensions_.indexOf(extension) + 1]; |
1059 this.createNode_(extension, nextExt ? $(nextExt.id) : null); | 1092 this.createNode_(extension, nextExt ? $(nextExt.id) : null); |
1060 } | 1093 } |
1061 } | 1094 } |
1062 }; | 1095 }; |
1063 | 1096 |
1064 return { | 1097 return { |
1065 ExtensionList: ExtensionList | 1098 ExtensionList: ExtensionList |
1066 }; | 1099 }; |
1067 }); | 1100 }); |
OLD | NEW |