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..ee13ce2912f311f82c03fdeab2bf44bd88948774 100644 |
--- a/chrome/browser/resources/extensions/extension_list.js |
+++ b/chrome/browser/resources/extensions/extension_list.js |
@@ -162,15 +162,26 @@ cr.define('extensions', function() { |
compare(a.id, b.id); |
} |
+ /** @interface */ |
+ function ExtensionListDelegate() {} |
+ |
+ ExtensionListDelegate.prototype = { |
+ /** |
+ * Called when the number of extensions in the list has changed. |
+ */ |
+ onExtensionCountChanged: assertNotReached, |
+ }; |
+ |
/** |
* Creates a new list of extensions. |
+ * @param {ExtensionListDelegate} delegate |
Devlin
2015/04/27 20:02:03
Strangely, this (and also lines 244 and 250, as we
Dan Beam
2015/04/27 21:02:27
this will work:
extensions.ExtensionListDelegate
Devlin
2015/04/27 21:11:54
Bummer indeed. Odd that it worked fine when putti
Devlin
2015/04/27 22:19:47
Fixed better, from offline conversation.
|
* @constructor |
* @extends {HTMLDivElement} |
*/ |
- function ExtensionList() { |
+ function ExtensionList(delegate) { |
var div = document.createElement('div'); |
div.__proto__ = ExtensionList.prototype; |
- div.initialize(); |
+ div.initialize(delegate); |
return div; |
} |
@@ -230,11 +241,15 @@ cr.define('extensions', function() { |
/** |
* Initializes the list. |
+ * @param {!ExtensionListDelegate} delegate |
*/ |
- initialize: function() { |
+ initialize: function(delegate) { |
/** @private {!Array<ExtensionInfo>} */ |
this.extensions_ = []; |
+ /** @private {!ExtensionListDelegate} */ |
+ 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,19 @@ 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) { |
+ this.delegate_.onExtensionCountChanged(); |
+ } |
}.bind(this)); |
}, |
@@ -334,6 +356,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 +1098,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. |