Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(7071)

Unified Diff: chrome/browser/resources/extensions/extension_list.js

Issue 1105683003: [Extensions Page] Add a listener on extension list for "hasExtensions" changing (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Dan's Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..8067aa1f00d6f351fdfd4cb2530d8760b4d4ebc6 100644
--- a/chrome/browser/resources/extensions/extension_list.js
+++ b/chrome/browser/resources/extensions/extension_list.js
@@ -235,6 +235,9 @@ cr.define('extensions', function() {
/** @private {!Array<ExtensionInfo>} */
this.extensions_ = [];
+ /** @type {?function()} */
+ this.onExtensionCountChanged = null;
Dan Beam 2015/04/27 16:17:05 why does this need to ever be assigned/created dyn
Devlin 2015/04/27 18:28:30 Per offline conversation, extracted this into a de
+
/**
* |loadFinished| should be used for testing purposes and will be
* fulfilled when this list has finished loading the first time.
@@ -260,12 +263,20 @@ 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.onExtensionCountChanged) {
+ this.onExtensionCountChanged();
+ }
}.bind(this));
},
@@ -334,6 +345,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 +1087,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.

Powered by Google App Engine
This is Rietveld 408576698