| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 cr.define('extensions', function() { | 5 cr.define('extensions', function() { |
| 6 'use strict'; | 6 'use strict'; |
| 7 | 7 |
| 8 /** | 8 /** |
| 9 * Compares two extensions to determine which should come first in the list. | |
| 10 * @param {chrome.developerPrivate.ExtensionInfo} a | |
| 11 * @param {chrome.developerPrivate.ExtensionInfo} b | |
| 12 * @return {number} | |
| 13 */ | |
| 14 var compareExtensions = function(a, b) { | |
| 15 function compare(x, y) { | |
| 16 return x < y ? -1 : (x > y ? 1 : 0); | |
| 17 } | |
| 18 function compareLocation(x, y) { | |
| 19 if (x.location == y.location) | |
| 20 return 0; | |
| 21 if (x.location == chrome.developerPrivate.Location.UNPACKED) | |
| 22 return -1; | |
| 23 if (y.location == chrome.developerPrivate.Location.UNPACKED) | |
| 24 return 1; | |
| 25 return 0; | |
| 26 } | |
| 27 return compareLocation(a, b) || | |
| 28 compare(a.name.toLowerCase(), b.name.toLowerCase()) || | |
| 29 compare(a.id, b.id); | |
| 30 }; | |
| 31 | |
| 32 /** | |
| 33 * @constructor | 9 * @constructor |
| 34 * @implements {extensions.ItemDelegate} | 10 * @implements {extensions.ItemDelegate} |
| 35 * @implements {extensions.SidebarDelegate} | 11 * @implements {extensions.SidebarDelegate} |
| 36 */ | 12 */ |
| 37 function Service() {} | 13 function Service() {} |
| 38 | 14 |
| 39 Service.prototype = { | 15 Service.prototype = { |
| 40 /** @private {boolean} */ | 16 /** @private {boolean} */ |
| 41 promptIsShowing_: false, | 17 promptIsShowing_: false, |
| 42 | 18 |
| 43 /** @param {extensions.Manager} manager */ | 19 /** @param {extensions.Manager} manager */ |
| 44 managerReady: function(manager) { | 20 managerReady: function(manager) { |
| 21 /** @private {extensions.Manager} */ |
| 45 this.manager_ = manager; | 22 this.manager_ = manager; |
| 23 /** @private {extensions.Sidebar} */ |
| 46 this.sidebar_ = manager.sidebar; | 24 this.sidebar_ = manager.sidebar; |
| 47 this.sidebar_.setDelegate(this); | 25 this.sidebar_.setDelegate(this); |
| 48 chrome.developerPrivate.onProfileStateChanged.addListener( | 26 chrome.developerPrivate.onProfileStateChanged.addListener( |
| 49 this.onProfileStateChanged_.bind(this)); | 27 this.onProfileStateChanged_.bind(this)); |
| 50 chrome.developerPrivate.onItemStateChanged.addListener( | 28 chrome.developerPrivate.onItemStateChanged.addListener( |
| 51 this.onItemStateChanged_.bind(this)); | 29 this.onItemStateChanged_.bind(this)); |
| 52 chrome.developerPrivate.getExtensionsInfo( | 30 chrome.developerPrivate.getExtensionsInfo( |
| 53 {includeDisabled: true, includeTerminated: true}, | 31 {includeDisabled: true, includeTerminated: true}, |
| 54 function(extensions) { | 32 function(extensions) { |
| 55 extensions.sort(compareExtensions); | 33 /** @private {Array<chrome.developerPrivate.ExtensionInfo>} */ |
| 56 this.extensions_ = extensions; | 34 this.extensions_ = extensions; |
| 57 for (let extension of extensions) | 35 for (let extension of extensions) |
| 58 this.manager_.addItem(extension, this); | 36 this.manager_.addItem(extension, this); |
| 59 }.bind(this)); | 37 }.bind(this)); |
| 60 chrome.developerPrivate.getProfileConfiguration( | 38 chrome.developerPrivate.getProfileConfiguration( |
| 61 this.onProfileStateChanged_.bind(this)); | 39 this.onProfileStateChanged_.bind(this)); |
| 62 }, | 40 }, |
| 63 | 41 |
| 64 /** | 42 /** |
| 65 * @param {chrome.developerPrivate.ProfileInfo} profileInfo | 43 * @param {chrome.developerPrivate.ProfileInfo} profileInfo |
| 66 * @private | 44 * @private |
| 67 */ | 45 */ |
| 68 onProfileStateChanged_: function(profileInfo) { | 46 onProfileStateChanged_: function(profileInfo) { |
| 47 /** @private {chrome.developerPrivate.ProfileInfo} */ |
| 69 this.profileInfo_ = profileInfo; | 48 this.profileInfo_ = profileInfo; |
| 70 this.sidebar_.inDevMode = profileInfo.inDeveloperMode; | 49 this.sidebar_.inDevMode = profileInfo.inDeveloperMode; |
| 71 this.manager_.forEachItem(function(item) { | 50 this.manager_.forEachItem(function(item) { |
| 72 item.inDevMode = profileInfo.inDeveloperMode; | 51 item.inDevMode = profileInfo.inDeveloperMode; |
| 73 }); | 52 }); |
| 74 }, | 53 }, |
| 75 | 54 |
| 76 /** | 55 /** |
| 77 * @param {chrome.developerPrivate.EventData} eventData | 56 * @param {chrome.developerPrivate.EventData} eventData |
| 78 * @private | 57 * @private |
| (...skipping 18 matching lines...) Expand all Loading... |
| 97 var existing = this.manager_.getItem(eventData.extensionInfo.id); | 76 var existing = this.manager_.getItem(eventData.extensionInfo.id); |
| 98 if (existing) { | 77 if (existing) { |
| 99 existing.data = eventData.extensionInfo; | 78 existing.data = eventData.extensionInfo; |
| 100 } else { | 79 } else { |
| 101 // If there's no existing item in the list, there shouldn't be an | 80 // If there's no existing item in the list, there shouldn't be an |
| 102 // extension with the same id in the data. | 81 // extension with the same id in the data. |
| 103 var currentIndex = this.extensions_.findIndex(function(extension) { | 82 var currentIndex = this.extensions_.findIndex(function(extension) { |
| 104 return extension.id == eventData.extensionInfo.id; | 83 return extension.id == eventData.extensionInfo.id; |
| 105 }); | 84 }); |
| 106 assert(currentIndex == -1); | 85 assert(currentIndex == -1); |
| 107 var newIndex = this.extensions_.findIndex(function(extension) { | 86 |
| 108 return compareExtensions(extension, | 87 this.extensions_.push(eventData.extensionInfo); |
| 109 assert(eventData.extensionInfo)) > 0; | 88 this.manager_.addItem(eventData.extensionInfo, this); |
| 110 }); | |
| 111 newIndex = newIndex == -1 ? this.extensions_.length : newIndex; | |
| 112 this.extensions_.splice(newIndex, 0, eventData.extensionInfo); | |
| 113 this.manager_.addItem(eventData.extensionInfo, this, newIndex); | |
| 114 } | 89 } |
| 115 break; | 90 break; |
| 116 case EventType.UNINSTALLED: | 91 case EventType.UNINSTALLED: |
| 117 var currentIndex = this.extensions_.findIndex(function(extension) { | 92 var currentIndex = this.extensions_.findIndex(function(extension) { |
| 118 return extension.id == eventData.item_id; | 93 return extension.id == eventData.item_id; |
| 119 }); | 94 }); |
| 120 this.extensions_.splice(currentIndex, 1); | 95 this.extensions_.splice(currentIndex, 1); |
| 121 this.manager_.removeItem(eventData.item_id); | 96 this.manager_.removeItem(eventData.item_id); |
| 122 break; | 97 break; |
| 123 default: | 98 default: |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 /** @override */ | 165 /** @override */ |
| 191 updateAllExtensions: function() { | 166 updateAllExtensions: function() { |
| 192 chrome.developerPrivate.autoUpdate(); | 167 chrome.developerPrivate.autoUpdate(); |
| 193 }, | 168 }, |
| 194 }; | 169 }; |
| 195 | 170 |
| 196 cr.addSingletonGetter(Service); | 171 cr.addSingletonGetter(Service); |
| 197 | 172 |
| 198 return {Service: Service}; | 173 return {Service: Service}; |
| 199 }); | 174 }); |
| OLD | NEW |