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.onLoadFinish_ = 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. | |
301 this.extensionsUpdated_.then(function() { | |
Dan Beam
2015/04/18 01:28:40
why not:
this.loadFinished_ = this.extensionUpd
hcarmona
2015/04/20 17:51:08
|updateExtensionsData| is called async, so the tes
Dan Beam
2015/04/20 17:56:00
ok, makes sense. thanks for explanation.
| |
302 // |onUpdateFinished_| should be called after the list becomes | |
303 // visible in extensions.js. | |
304 this.onUpdateFinished_(); | |
305 | |
306 // |onLoadFinish_| will resolve the |loadFinished| promise for | |
307 // testing purposes. | |
308 this.onLoadFinish_(); | |
309 }.bind(this)); | |
288 }.bind(this)); | 310 }.bind(this)); |
289 }.bind(this)); | 311 }.bind(this)); |
290 return this.extensionsUpdated_; | 312 return this.extensionsUpdated_; |
291 }, | 313 }, |
292 | 314 |
315 /** Updates elements that need to be visible in order to update properly. */ | |
Dan Beam
2015/04/18 01:28:41
/**
* Updates ...
* @private
*/
hcarmona
2015/04/20 17:51:08
Done.
| |
316 onUpdateFinished_: function() { | |
317 // Cannot focus or highlight a extension if there are none. | |
318 if (this.extensions_.length == 0) | |
319 return; | |
320 | |
321 assert(!this.hidden); | |
322 assert(!this.parentElement.hidden); | |
323 | |
324 this.updateFocusableElements(); | |
325 | |
326 var idToHighlight = this.getIdQueryParam_(); | |
327 if (idToHighlight && $(idToHighlight)) | |
328 this.scrollToNode_(idToHighlight); | |
329 | |
330 var idToOpenOptions = this.getOptionsQueryParam_(); | |
331 if (idToOpenOptions && $(idToOpenOptions)) | |
332 this.showEmbeddedExtensionOptions_(idToOpenOptions, true); | |
333 }, | |
334 | |
293 /** @return {number} The number of extensions being displayed. */ | 335 /** @return {number} The number of extensions being displayed. */ |
294 getNumExtensions: function() { | 336 getNumExtensions: function() { |
295 return this.extensions_.length; | 337 return this.extensions_.length; |
296 }, | 338 }, |
297 | 339 |
298 getIdQueryParam_: function() { | 340 getIdQueryParam_: function() { |
299 return parseQueryParams(document.location)['id']; | 341 return parseQueryParams(document.location)['id']; |
300 }, | 342 }, |
301 | 343 |
302 getOptionsQueryParam_: function() { | 344 getOptionsQueryParam_: function() { |
(...skipping 29 matching lines...) Expand all Loading... | |
332 focusableNode.getEquivalentElement( | 374 focusableNode.getEquivalentElement( |
333 document.activeElement).focus(); | 375 document.activeElement).focus(); |
334 } | 376 } |
335 } | 377 } |
336 | 378 |
337 node.parentElement.removeChild(node); | 379 node.parentElement.removeChild(node); |
338 // Unregister the removed node from events. | 380 // Unregister the removed node from events. |
339 assertInstanceof(node, ExtensionFocusRow).destroy(); | 381 assertInstanceof(node, ExtensionFocusRow).destroy(); |
340 } | 382 } |
341 } | 383 } |
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 }, | 384 }, |
351 | 385 |
352 /** Updates each row's focusable elements without rebuilding the grid. */ | 386 /** Updates each row's focusable elements without rebuilding the grid. */ |
353 updateFocusableElements: function() { | 387 updateFocusableElements: function() { |
354 var rows = document.querySelectorAll('.extension-list-item-wrapper[id]'); | 388 var rows = document.querySelectorAll('.extension-list-item-wrapper[id]'); |
355 for (var i = 0; i < rows.length; ++i) { | 389 for (var i = 0; i < rows.length; ++i) { |
356 assertInstanceof(rows[i], ExtensionFocusRow).updateFocusableElements(); | 390 assertInstanceof(rows[i], ExtensionFocusRow).updateFocusableElements(); |
357 } | 391 } |
358 }, | 392 }, |
359 | 393 |
(...skipping 698 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1058 var nextExt = this.extensions_[this.extensions_.indexOf(extension) + 1]; | 1092 var nextExt = this.extensions_[this.extensions_.indexOf(extension) + 1]; |
1059 this.createNode_(extension, nextExt ? $(nextExt.id) : null); | 1093 this.createNode_(extension, nextExt ? $(nextExt.id) : null); |
1060 } | 1094 } |
1061 } | 1095 } |
1062 }; | 1096 }; |
1063 | 1097 |
1064 return { | 1098 return { |
1065 ExtensionList: ExtensionList | 1099 ExtensionList: ExtensionList |
1066 }; | 1100 }; |
1067 }); | 1101 }); |
OLD | NEW |