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

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: 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 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 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 /** @type {?function()} */
239 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
240
238 /** 241 /**
239 * |loadFinished| should be used for testing purposes and will be 242 * |loadFinished| should be used for testing purposes and will be
240 * fulfilled when this list has finished loading the first time. 243 * fulfilled when this list has finished loading the first time.
241 * @type {Promise} 244 * @type {Promise}
242 * */ 245 * */
243 this.loadFinished = new Promise(function(resolve, reject) { 246 this.loadFinished = new Promise(function(resolve, reject) {
244 /** @private {function(?)} */ 247 /** @private {function(?)} */
245 this.resolveLoadFinished_ = resolve; 248 this.resolveLoadFinished_ = resolve;
246 }.bind(this)); 249 }.bind(this));
247 250
248 chrome.developerPrivate.onItemStateChanged.addListener( 251 chrome.developerPrivate.onItemStateChanged.addListener(
249 function(eventData) { 252 function(eventData) {
250 var EventType = chrome.developerPrivate.EventType; 253 var EventType = chrome.developerPrivate.EventType;
251 switch (eventData.event_type) { 254 switch (eventData.event_type) {
252 case EventType.VIEW_REGISTERED: 255 case EventType.VIEW_REGISTERED:
253 case EventType.VIEW_UNREGISTERED: 256 case EventType.VIEW_UNREGISTERED:
254 case EventType.INSTALLED: 257 case EventType.INSTALLED:
255 case EventType.LOADED: 258 case EventType.LOADED:
256 case EventType.UNLOADED: 259 case EventType.UNLOADED:
257 case EventType.ERROR_ADDED: 260 case EventType.ERROR_ADDED:
258 case EventType.PREFS_CHANGED: 261 case EventType.PREFS_CHANGED:
259 if (eventData.extensionInfo) 262 if (eventData.extensionInfo)
260 this.updateExtension_(eventData.extensionInfo); 263 this.updateExtension_(eventData.extensionInfo);
261 break; 264 break;
262 case EventType.UNINSTALLED: 265 case EventType.UNINSTALLED:
266 var index = this.getIndexOfExtension_(eventData.item_id);
267 this.extensions_.splice(index, 1);
263 var childNode = $(eventData.item_id); 268 var childNode = $(eventData.item_id);
264 childNode.parentNode.removeChild(childNode); 269 childNode.parentNode.removeChild(childNode);
265 break; 270 break;
266 default: 271 default:
267 assertNotReached(); 272 assertNotReached();
268 } 273 }
274
275 if ((eventData.event_type == EventType.INSTALLED ||
276 eventData.event_type == EventType.UNINSTALLED) &&
277 this.onExtensionCountChanged) {
278 this.onExtensionCountChanged();
279 }
269 }.bind(this)); 280 }.bind(this));
270 }, 281 },
271 282
272 /** 283 /**
273 * Updates the extensions on the page. 284 * Updates the extensions on the page.
274 * @param {boolean} incognitoAvailable Whether or not incognito is allowed. 285 * @param {boolean} incognitoAvailable Whether or not incognito is allowed.
275 * @param {boolean} enableAppInfoDialog Whether or not the app info dialog 286 * @param {boolean} enableAppInfoDialog Whether or not the app info dialog
276 * is enabled. 287 * is enabled.
277 * @return {Promise} A promise that is resolved once the extensions data is 288 * @return {Promise} A promise that is resolved once the extensions data is
278 * fully updated. 289 * fully updated.
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 var idToOpenOptions = this.getOptionsQueryParam_(); 338 var idToOpenOptions = this.getOptionsQueryParam_();
328 if (idToOpenOptions && $(idToOpenOptions)) 339 if (idToOpenOptions && $(idToOpenOptions))
329 this.showEmbeddedExtensionOptions_(idToOpenOptions, true); 340 this.showEmbeddedExtensionOptions_(idToOpenOptions, true);
330 }, 341 },
331 342
332 /** @return {number} The number of extensions being displayed. */ 343 /** @return {number} The number of extensions being displayed. */
333 getNumExtensions: function() { 344 getNumExtensions: function() {
334 return this.extensions_.length; 345 return this.extensions_.length;
335 }, 346 },
336 347
348 /**
349 * @param {string} id The id of the extension.
350 * @return {number} The index of the extension with the given id.
351 * @private
352 */
353 getIndexOfExtension_: function(id) {
354 for (var i = 0; i < this.extensions_.length; ++i) {
355 if (this.extensions_[i].id == id)
356 return i;
357 }
358 return -1;
359 },
360
337 getIdQueryParam_: function() { 361 getIdQueryParam_: function() {
338 return parseQueryParams(document.location)['id']; 362 return parseQueryParams(document.location)['id'];
339 }, 363 },
340 364
341 getOptionsQueryParam_: function() { 365 getOptionsQueryParam_: function() {
342 return parseQueryParams(document.location)['options']; 366 return parseQueryParams(document.location)['options'];
343 }, 367 },
344 368
345 /** 369 /**
346 * Creates or updates all extension items from scratch. 370 * Creates or updates all extension items from scratch.
(...skipping 709 matching lines...) Expand 10 before | Expand all | Expand 10 after
1056 overlay.setInitialFocus(); 1080 overlay.setInitialFocus();
1057 }, 1081 },
1058 1082
1059 /** 1083 /**
1060 * Updates the node for the extension. 1084 * Updates the node for the extension.
1061 * @param {!ExtensionInfo} extension The information about the extension to 1085 * @param {!ExtensionInfo} extension The information about the extension to
1062 * update. 1086 * update.
1063 * @private 1087 * @private
1064 */ 1088 */
1065 updateExtension_: function(extension) { 1089 updateExtension_: function(extension) {
1066 var currIndex = -1; 1090 var currIndex = this.getIndexOfExtension_(extension.id);
1067 for (var i = 0; i < this.extensions_.length; ++i) {
1068 if (this.extensions_[i].id == extension.id) {
1069 currIndex = i;
1070 break;
1071 }
1072 }
1073 if (currIndex != -1) { 1091 if (currIndex != -1) {
1074 // If there is a current version of the extension, update it with the 1092 // If there is a current version of the extension, update it with the
1075 // new version. 1093 // new version.
1076 this.extensions_[currIndex] = extension; 1094 this.extensions_[currIndex] = extension;
1077 } else { 1095 } else {
1078 // If the extension isn't found, push it back and sort. Technically, we 1096 // If the extension isn't found, push it back and sort. Technically, we
1079 // could optimize by inserting it at the right location, but since this 1097 // could optimize by inserting it at the right location, but since this
1080 // only happens on extension install, it's not worth it. 1098 // only happens on extension install, it's not worth it.
1081 this.extensions_.push(extension); 1099 this.extensions_.push(extension);
1082 this.extensions_.sort(compareExtensions); 1100 this.extensions_.sort(compareExtensions);
1083 } 1101 }
1084 1102
1085 var node = /** @type {ExtensionFocusRow} */ ($(extension.id)); 1103 var node = /** @type {ExtensionFocusRow} */ ($(extension.id));
1086 if (node) { 1104 if (node) {
1087 this.updateNode_(extension, node); 1105 this.updateNode_(extension, node);
1088 } else { 1106 } else {
1089 var nextExt = this.extensions_[this.extensions_.indexOf(extension) + 1]; 1107 var nextExt = this.extensions_[this.extensions_.indexOf(extension) + 1];
1090 this.createNode_(extension, nextExt ? $(nextExt.id) : null); 1108 this.createNode_(extension, nextExt ? $(nextExt.id) : null);
1091 } 1109 }
1092 } 1110 }
1093 }; 1111 };
1094 1112
1095 return { 1113 return {
1096 ExtensionList: ExtensionList 1114 ExtensionList: ExtensionList
1097 }; 1115 };
1098 }); 1116 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698