Index: chrome/browser/resources/md_extensions/manager.js |
diff --git a/chrome/browser/resources/md_extensions/manager.js b/chrome/browser/resources/md_extensions/manager.js |
index f7f94d83c77f69597c872471172c6c30a39e4ca7..b340796a96b619f26a3c5d6679dbc8594eb4e8f5 100644 |
--- a/chrome/browser/resources/md_extensions/manager.js |
+++ b/chrome/browser/resources/md_extensions/manager.js |
@@ -3,6 +3,32 @@ |
// found in the LICENSE file. |
cr.define('extensions', function() { |
+ 'use strict'; |
+ |
+ /** |
+ * Compares two extensions to determine which should come first in the list. |
Devlin
2015/11/18 00:38:57
note: copy-paste from service.js
|
+ * @param {chrome.developerPrivate.ExtensionInfo} a |
+ * @param {chrome.developerPrivate.ExtensionInfo} b |
+ * @return {number} |
+ */ |
+ var compareExtensions = function(a, b) { |
+ function compare(x, y) { |
+ return x < y ? -1 : (x > y ? 1 : 0); |
+ } |
+ function compareLocation(x, y) { |
+ if (x.location == y.location) |
+ return 0; |
+ if (x.location == chrome.developerPrivate.Location.UNPACKED) |
+ return -1; |
+ if (y.location == chrome.developerPrivate.Location.UNPACKED) |
+ return 1; |
+ return 0; |
+ } |
+ return compareLocation(a, b) || |
+ compare(a.name.toLowerCase(), b.name.toLowerCase()) || |
+ compare(a.id, b.id); |
+ }; |
+ |
var Manager = Polymer({ |
is: 'extensions-manager', |
@@ -13,6 +39,7 @@ cr.define('extensions', function() { |
}, |
ready: function() { |
+ /** @type {extensions.Sidebar} */ |
this.sidebar = this.$$('extensions-sidebar'); |
extensions.Service.getInstance().managerReady(this); |
this.sidebar.setScrollDelegate(new ScrollHelper(this)); |
@@ -23,10 +50,8 @@ cr.define('extensions', function() { |
* @param {!chrome.developerPrivate.ExtensionInfo} extension The extension |
* the item is representing. |
* @param {!extensions.ItemDelegate} delegate The delegate for the item. |
- * @param {!number=} opt_index The index at which to place the item. If |
- * not present, the item is appended to the end of the list. |
*/ |
- addItem: function(extension, delegate, opt_index) { |
+ addItem: function(extension, delegate) { |
var listId; |
var ExtensionType = chrome.developerPrivate.ExtensionType; |
switch (extension.type) { |
@@ -49,9 +74,12 @@ cr.define('extensions', function() { |
assert(listId); |
var extensionItem = new extensions.Item(extension, delegate); |
var itemList = this.$[listId]; |
- var refNode = opt_index !== undefined ? |
- itemList.children[opt_index] : undefined; |
- itemList.insertBefore(extensionItem, refNode); |
+ |
+ var insertBeforeChild = Array.prototype.find.call(itemList.children, |
+ function(item) { |
+ return compareExtensions(item.data, extension) > 0; |
+ }); |
+ itemList.insertBefore(extensionItem, insertBeforeChild); |
}, |
/** |