Chromium Code Reviews| Index: chrome/browser/resources/extensions/extension_list.js |
| diff --git a/chrome/browser/resources/extensions/extension_list.js b/chrome/browser/resources/extensions/extension_list.js |
| index 35eea3414ddc7a06f35e288132525dddf6acdeb4..37c5a1535fe6cf1ff6759a100c182f0b234d8d88 100644 |
| --- a/chrome/browser/resources/extensions/extension_list.js |
| +++ b/chrome/browser/resources/extensions/extension_list.js |
| @@ -164,16 +164,27 @@ cr.define('extensions', function() { |
| /** |
| * Creates a new list of extensions. |
| + * @param {ExtensionList.Delegate} delegate |
|
Devlin
2015/04/27 18:28:30
This causes a Closure Compiler error (ExtensionLis
Dan Beam
2015/04/27 18:47:59
ExtensionList.Delegate -> ExtensionListDelegate (t
|
| * @constructor |
| * @extends {HTMLDivElement} |
| */ |
| - function ExtensionList() { |
| + function ExtensionList(delegate) { |
| var div = document.createElement('div'); |
| div.__proto__ = ExtensionList.prototype; |
| - div.initialize(); |
| + div.initialize(delegate); |
| return div; |
| } |
| + /** @interface */ |
| + ExtensionList.Delegate = function() {}; |
| + |
| + ExtensionList.Delegate.prototype = { |
| + /** |
| + * Called when the number of extensions in the list has changed. |
| + */ |
| + onExtensionCountChanged: assertNotReached, |
| + }; |
| + |
| /** |
| * @type {Object<string, number>} A map from extension id to last reloaded |
| * timestamp. The timestamp is recorded when the user click the 'Reload' |
| @@ -230,11 +241,15 @@ cr.define('extensions', function() { |
| /** |
| * Initializes the list. |
| + * @param {!ExtensionList.Delegate} delegate |
| */ |
| - initialize: function() { |
| + initialize: function(delegate) { |
| /** @private {!Array<ExtensionInfo>} */ |
| this.extensions_ = []; |
| + /** @private {!ExtensionList.Delegate} */ |
| + this.delegate_ = delegate; |
| + |
| /** |
| * |loadFinished| should be used for testing purposes and will be |
| * fulfilled when this list has finished loading the first time. |
| @@ -260,12 +275,18 @@ cr.define('extensions', function() { |
| this.updateExtension_(eventData.extensionInfo); |
| break; |
| case EventType.UNINSTALLED: |
| + var index = this.getIndexOfExtension_(eventData.item_id); |
| + this.extensions_.splice(index, 1); |
| var childNode = $(eventData.item_id); |
| childNode.parentNode.removeChild(childNode); |
| break; |
| default: |
| assertNotReached(); |
| } |
| + |
| + if (eventData.event_type == EventType.INSTALLED || |
| + eventData.event_type == EventType.UNINSTALLED) |
|
Dan Beam
2015/04/27 18:47:59
curlies
Devlin
2015/04/27 20:02:03
Done.
|
| + this.delegate_.onExtensionCountChanged(); |
| }.bind(this)); |
| }, |
| @@ -334,6 +355,19 @@ cr.define('extensions', function() { |
| return this.extensions_.length; |
| }, |
| + /** |
| + * @param {string} id The id of the extension. |
| + * @return {number} The index of the extension with the given id. |
| + * @private |
| + */ |
| + getIndexOfExtension_: function(id) { |
| + for (var i = 0; i < this.extensions_.length; ++i) { |
| + if (this.extensions_[i].id == id) |
| + return i; |
| + } |
| + return -1; |
| + }, |
| + |
| getIdQueryParam_: function() { |
| return parseQueryParams(document.location)['id']; |
| }, |
| @@ -1063,13 +1097,7 @@ cr.define('extensions', function() { |
| * @private |
| */ |
| updateExtension_: function(extension) { |
| - var currIndex = -1; |
| - for (var i = 0; i < this.extensions_.length; ++i) { |
| - if (this.extensions_[i].id == extension.id) { |
| - currIndex = i; |
| - break; |
| - } |
| - } |
| + var currIndex = this.getIndexOfExtension_(extension.id); |
| if (currIndex != -1) { |
| // If there is a current version of the extension, update it with the |
| // new version. |