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

Side by Side 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: 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 unified diff | Download patch
OLDNEW
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 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 switch (eventData.event_type) { 241 switch (eventData.event_type) {
242 case EventType.VIEW_REGISTERED: 242 case EventType.VIEW_REGISTERED:
243 case EventType.VIEW_UNREGISTERED: 243 case EventType.VIEW_UNREGISTERED:
244 case EventType.INSTALLED: 244 case EventType.INSTALLED:
245 case EventType.LOADED: 245 case EventType.LOADED:
246 case EventType.UNLOADED: 246 case EventType.UNLOADED:
247 case EventType.ERROR_ADDED: 247 case EventType.ERROR_ADDED:
248 case EventType.PREFS_CHANGED: 248 case EventType.PREFS_CHANGED:
249 if (eventData.extensionInfo) 249 if (eventData.extensionInfo)
250 this.updateExtension_(eventData.extensionInfo); 250 this.updateExtension_(eventData.extensionInfo);
251 if (eventData.event_type == EventType.INSTALLED &&
252 this.extensions_.length == 1 &&
Dan Beam 2015/04/23 18:01:38 why length == 1? can't we just call this every ti
Devlin 2015/04/23 18:27:31 Sure.
253 this.onHasExtensionsChanged) {
254 this.onHasExtensionsChanged();
255 }
251 break; 256 break;
252 case EventType.UNINSTALLED: 257 case EventType.UNINSTALLED:
258 var index = this.getIndexOfExtension_(eventData.item_id);
259 this.extensions_.splice(index, 1);
253 var childNode = $(eventData.item_id); 260 var childNode = $(eventData.item_id);
254 childNode.parentNode.removeChild(childNode); 261 childNode.parentNode.removeChild(childNode);
262 if (this.extensions_.length == 0 && this.onHasExtensionsChanged)
263 this.onHasExtensionsChanged();
Dan Beam 2015/04/23 18:01:38 can't we just call this every time?
Devlin 2015/04/23 18:27:31 Ditto.
255 break; 264 break;
256 default: 265 default:
257 assertNotReached(); 266 assertNotReached();
258 } 267 }
259 }.bind(this)); 268 }.bind(this));
Dan Beam 2015/04/23 18:01:38 nit: if (eventData.event_type == EventType.INST
Devlin 2015/04/23 18:27:31 Done.
260 }, 269 },
261 270
262 /** 271 /**
263 * Updates the extensions on the page. 272 * Updates the extensions on the page.
264 * @param {boolean} incognitoAvailable Whether or not incognito is allowed. 273 * @param {boolean} incognitoAvailable Whether or not incognito is allowed.
265 * @param {boolean} enableAppInfoDialog Whether or not the app info dialog 274 * @param {boolean} enableAppInfoDialog Whether or not the app info dialog
266 * is enabled. 275 * is enabled.
267 * @return {Promise} A promise that is resolved once the extensions data is 276 * @return {Promise} A promise that is resolved once the extensions data is
268 * fully updated. 277 * fully updated.
269 */ 278 */
(...skipping 16 matching lines...) Expand all
286 }.bind(this)); 295 }.bind(this));
287 }.bind(this)); 296 }.bind(this));
288 return this.extensionsUpdated_; 297 return this.extensionsUpdated_;
289 }, 298 },
290 299
291 /** @return {number} The number of extensions being displayed. */ 300 /** @return {number} The number of extensions being displayed. */
292 getNumExtensions: function() { 301 getNumExtensions: function() {
293 return this.extensions_.length; 302 return this.extensions_.length;
294 }, 303 },
295 304
305 /**
306 * @param {string} id The id of the extension.
307 * @return {number} The index of the extension with the given id.
308 * @private
309 */
310 getIndexOfExtension_: function(id) {
311 for (var i = 0; i < this.extensions_.length; ++i) {
312 if (this.extensions_[i].id == id)
313 return i;
314 }
315 return -1;
316 },
317
296 getIdQueryParam_: function() { 318 getIdQueryParam_: function() {
297 return parseQueryParams(document.location)['id']; 319 return parseQueryParams(document.location)['id'];
298 }, 320 },
299 321
300 getOptionsQueryParam_: function() { 322 getOptionsQueryParam_: function() {
301 return parseQueryParams(document.location)['options']; 323 return parseQueryParams(document.location)['options'];
302 }, 324 },
303 325
304 /** 326 /**
305 * Creates or updates all extension items from scratch. 327 * Creates or updates all extension items from scratch.
(...skipping 717 matching lines...) Expand 10 before | Expand all | Expand 10 after
1023 overlay.setInitialFocus(); 1045 overlay.setInitialFocus();
1024 }, 1046 },
1025 1047
1026 /** 1048 /**
1027 * Updates the node for the extension. 1049 * Updates the node for the extension.
1028 * @param {!ExtensionInfo} extension The information about the extension to 1050 * @param {!ExtensionInfo} extension The information about the extension to
1029 * update. 1051 * update.
1030 * @private 1052 * @private
1031 */ 1053 */
1032 updateExtension_: function(extension) { 1054 updateExtension_: function(extension) {
1033 var currIndex = -1; 1055 var currIndex = this.getIndexOfExtension_(extension.id);
1034 for (var i = 0; i < this.extensions_.length; ++i) {
1035 if (this.extensions_[i].id == extension.id) {
1036 currIndex = i;
1037 break;
1038 }
1039 }
1040 if (currIndex != -1) { 1056 if (currIndex != -1) {
1041 // If there is a current version of the extension, update it with the 1057 // If there is a current version of the extension, update it with the
1042 // new version. 1058 // new version.
1043 this.extensions_[currIndex] = extension; 1059 this.extensions_[currIndex] = extension;
1044 } else { 1060 } else {
1045 // If the extension isn't found, push it back and sort. Technically, we 1061 // If the extension isn't found, push it back and sort. Technically, we
1046 // could optimize by inserting it at the right location, but since this 1062 // could optimize by inserting it at the right location, but since this
1047 // only happens on extension install, it's not worth it. 1063 // only happens on extension install, it's not worth it.
1048 this.extensions_.push(extension); 1064 this.extensions_.push(extension);
1049 this.extensions_.sort(compareExtensions); 1065 this.extensions_.sort(compareExtensions);
1050 } 1066 }
1051 1067
1052 var node = /** @type {ExtensionFocusRow} */ ($(extension.id)); 1068 var node = /** @type {ExtensionFocusRow} */ ($(extension.id));
1053 if (node) { 1069 if (node) {
1054 this.updateNode_(extension, node); 1070 this.updateNode_(extension, node);
1055 } else { 1071 } else {
1056 var nextExt = this.extensions_[this.extensions_.indexOf(extension) + 1]; 1072 var nextExt = this.extensions_[this.extensions_.indexOf(extension) + 1];
1057 this.createNode_(extension, nextExt ? $(nextExt.id) : null); 1073 this.createNode_(extension, nextExt ? $(nextExt.id) : null);
1058 } 1074 }
1059 } 1075 }
1060 }; 1076 };
1061 1077
1062 return { 1078 return {
1063 ExtensionList: ExtensionList 1079 ExtensionList: ExtensionList
1064 }; 1080 };
1065 }); 1081 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698