| 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. | 9 * Compares two extensions to determine which should come first in the list. |
| 10 * @param {chrome.developerPrivate.ExtensionInfo} a | 10 * @param {chrome.developerPrivate.ExtensionInfo} a |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 extensions: { | 53 extensions: { |
| 54 type: Array, | 54 type: Array, |
| 55 value: function() { return []; }, | 55 value: function() { return []; }, |
| 56 }, | 56 }, |
| 57 | 57 |
| 58 /** @type {!Array<!chrome.developerPrivate.ExtensionInfo>} */ | 58 /** @type {!Array<!chrome.developerPrivate.ExtensionInfo>} */ |
| 59 apps: { | 59 apps: { |
| 60 type: Array, | 60 type: Array, |
| 61 value: function() { return []; }, | 61 value: function() { return []; }, |
| 62 }, | 62 }, |
| 63 | |
| 64 /** @type {!Array<!chrome.developerPrivate.ExtensionInfo>} */ | |
| 65 websites: { | |
| 66 type: Array, | |
| 67 value: function() { return []; }, | |
| 68 }, | |
| 69 }, | 63 }, |
| 70 | 64 |
| 71 behaviors: [ | 65 behaviors: [ |
| 72 I18nBehavior, | 66 I18nBehavior, |
| 73 ], | 67 ], |
| 74 | 68 |
| 69 listeners: { |
| 70 'items-list.extension-item-show-details': 'showItemDetails_', |
| 71 }, |
| 72 |
| 75 created: function() { | 73 created: function() { |
| 76 this.readyPromiseResolver = new PromiseResolver(); | 74 this.readyPromiseResolver = new PromiseResolver(); |
| 77 }, | 75 }, |
| 78 | 76 |
| 79 ready: function() { | 77 ready: function() { |
| 80 /** @type {extensions.Sidebar} */ | 78 /** @type {extensions.Sidebar} */ |
| 81 this.sidebar = | 79 this.sidebar = |
| 82 /** @type {extensions.Sidebar} */(this.$$('extensions-sidebar')); | 80 /** @type {extensions.Sidebar} */(this.$$('extensions-sidebar')); |
| 83 this.scrollHelper_ = new ScrollHelper(this); | 81 this.listHelper_ = new ListHelper(this); |
| 84 this.sidebar.setScrollDelegate(this.scrollHelper_); | 82 this.sidebar.setListDelegate(this.listHelper_); |
| 85 this.$.toolbar.setSearchDelegate(new SearchHelper(this)); | 83 this.$.toolbar.setSearchDelegate(new SearchHelper(this)); |
| 86 this.readyPromiseResolver.resolve(); | 84 this.readyPromiseResolver.resolve(); |
| 87 }, | 85 }, |
| 88 | 86 |
| 89 /** | 87 /** |
| 90 * @param {chrome.developerPrivate.ExtensionType} type The type of item. | 88 * @param {chrome.developerPrivate.ExtensionType} type The type of item. |
| 91 * @return {string} The ID of the list that the item belongs in. | 89 * @return {string} The ID of the list that the item belongs in. |
| 92 * @private | 90 * @private |
| 93 */ | 91 */ |
| 94 getListId_: function(type) { | 92 getListId_: function(type) { |
| 95 var listId; | 93 var listId; |
| 96 var ExtensionType = chrome.developerPrivate.ExtensionType; | 94 var ExtensionType = chrome.developerPrivate.ExtensionType; |
| 97 switch (type) { | 95 switch (type) { |
| 98 case ExtensionType.HOSTED_APP: | 96 case ExtensionType.HOSTED_APP: |
| 99 case ExtensionType.LEGACY_PACKAGED_APP: | 97 case ExtensionType.LEGACY_PACKAGED_APP: |
| 100 listId = 'websites'; | |
| 101 break; | |
| 102 case ExtensionType.PLATFORM_APP: | 98 case ExtensionType.PLATFORM_APP: |
| 103 listId = 'apps'; | 99 listId = 'apps'; |
| 104 break; | 100 break; |
| 105 case ExtensionType.EXTENSION: | 101 case ExtensionType.EXTENSION: |
| 106 case ExtensionType.SHARED_MODULE: | 102 case ExtensionType.SHARED_MODULE: |
| 107 listId = 'extensions'; | 103 listId = 'extensions'; |
| 108 break; | 104 break; |
| 109 case ExtensionType.THEME: | 105 case ExtensionType.THEME: |
| 110 assertNotReached( | 106 assertNotReached( |
| 111 'Don\'t send themes to the chrome://extensions page'); | 107 'Don\'t send themes to the chrome://extensions page'); |
| 112 break; | 108 break; |
| 113 } | 109 } |
| 114 assert(listId); | 110 assert(listId); |
| 115 return listId; | 111 return listId; |
| 116 }, | 112 }, |
| 117 | 113 |
| 118 /** | 114 /** |
| 119 * @param {string} listId The list to look for the item in. | 115 * @param {string} listId The list to look for the item in. |
| 120 * @param {string} itemId The id of the item to look for. | 116 * @param {string} itemId The id of the item to look for. |
| 121 * @return {number} The index of the item in the list, or -1 if not found. | 117 * @return {number} The index of the item in the list, or -1 if not found. |
| 122 * @private | 118 * @private |
| 123 */ | 119 */ |
| 124 getIndexInList_: function(listId, itemId) { | 120 getIndexInList_: function(listId, itemId) { |
| 125 return this[listId].findIndex(function(item) { | 121 return this[listId].findIndex(function(item) { |
| 126 return item.id == itemId; | 122 return item.id == itemId; |
| 127 }); | 123 }); |
| 128 }, | 124 }, |
| 129 | 125 |
| 130 /** | 126 /** |
| 131 * @param {!Array<!chrome.developerPrivate.ExtensionInfo>} list | |
| 132 * @return {boolean} Whether the list should be visible. | 127 * @return {boolean} Whether the list should be visible. |
| 128 * @private |
| 133 */ | 129 */ |
| 134 computeListHidden_: function(list) { | 130 computeListHidden_: function() { |
| 135 return list.length == 0; | 131 return this.$['items-list'].items.length == 0; |
| 136 }, | 132 }, |
| 137 | 133 |
| 138 /** | 134 /** |
| 139 * Creates and adds a new extensions-item element to the list, inserting it | 135 * Creates and adds a new extensions-item element to the list, inserting it |
| 140 * into its sorted position in the relevant section. | 136 * into its sorted position in the relevant section. |
| 141 * @param {!chrome.developerPrivate.ExtensionInfo} item The extension | 137 * @param {!chrome.developerPrivate.ExtensionInfo} item The extension |
| 142 * the new element is representing. | 138 * the new element is representing. |
| 143 */ | 139 */ |
| 144 addItem: function(item) { | 140 addItem: function(item) { |
| 145 var listId = this.getListId_(item.type); | 141 var listId = this.getListId_(item.type); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 169 * @param {!chrome.developerPrivate.ExtensionInfo} item The data for the | 165 * @param {!chrome.developerPrivate.ExtensionInfo} item The data for the |
| 170 * item to remove. | 166 * item to remove. |
| 171 */ | 167 */ |
| 172 removeItem: function(item) { | 168 removeItem: function(item) { |
| 173 var listId = this.getListId_(item.type); | 169 var listId = this.getListId_(item.type); |
| 174 var index = this.getIndexInList_(listId, item.id); | 170 var index = this.getIndexInList_(listId, item.id); |
| 175 // We should never try and remove a non-existent item. | 171 // We should never try and remove a non-existent item. |
| 176 assert(index >= 0); | 172 assert(index >= 0); |
| 177 this.splice(listId, index, 1); | 173 this.splice(listId, index, 1); |
| 178 }, | 174 }, |
| 175 |
| 176 /** |
| 177 * Shows the detailed view for a given item. |
| 178 * @param {CustomEvent} e |
| 179 * @private |
| 180 */ |
| 181 showItemDetails_: function(e) { |
| 182 this.$['details-view'].set('data', assert(e.detail.element.data)); |
| 183 this.$.pages.selected = 1; |
| 184 }, |
| 185 |
| 186 /** @private */ |
| 187 onDetailsViewClose_: function() { |
| 188 this.$.pages.selected = 0; |
| 189 } |
| 179 }); | 190 }); |
| 180 | 191 |
| 181 /** | 192 /** |
| 182 * @param {extensions.Manager} manager | 193 * @param {extensions.Manager} manager |
| 183 * @constructor | 194 * @constructor |
| 184 * @implements {extensions.SidebarScrollDelegate} | 195 * @implements {extensions.SidebarListDelegate} |
| 185 */ | 196 */ |
| 186 function ScrollHelper(manager) { | 197 function ListHelper(manager) { |
| 187 this.items_ = manager.$.items; | 198 this.manager_ = manager; |
| 188 } | 199 } |
| 189 | 200 |
| 190 ScrollHelper.prototype = { | 201 ListHelper.prototype = { |
| 191 /** @override */ | 202 /** @override */ |
| 192 scrollToExtensions: function() { | 203 showType: function(type) { |
| 193 this.items_.scrollTop = | 204 var items; |
| 194 this.items_.querySelector('#extensions-list').offsetTop; | 205 switch (type) { |
| 195 }, | 206 case extensions.ShowingType.EXTENSIONS: |
| 196 | 207 items = this.manager_.extensions; |
| 197 /** @override */ | 208 break; |
| 198 scrollToApps: function() { | 209 case extensions.ShowingType.APPS: |
| 199 this.items_.scrollTop = | 210 items = this.manager_.apps; |
| 200 this.items_.querySelector('#apps-list').offsetTop; | 211 break; |
| 201 }, | 212 } |
| 202 | 213 this.manager_.$['items-list'].set('items', assert(items)); |
| 203 /** @override */ | 214 } |
| 204 scrollToWebsites: function() { | |
| 205 this.items_.scrollTop = | |
| 206 this.items_.querySelector('#websites-list').offsetTop; | |
| 207 }, | |
| 208 }; | 215 }; |
| 209 | 216 |
| 210 /** | 217 /** |
| 211 * @param {extensions.Manager} manager | 218 * @param {extensions.Manager} manager |
| 212 * @constructor | 219 * @constructor |
| 213 * @implements {SearchFieldDelegate} | 220 * @implements {SearchFieldDelegate} |
| 214 */ | 221 */ |
| 215 function SearchHelper(manager) { | 222 function SearchHelper(manager) { |
| 216 this.manager_ = manager; | 223 this.manager_ = manager; |
| 217 } | 224 } |
| 218 | 225 |
| 219 SearchHelper.prototype = { | 226 SearchHelper.prototype = { |
| 220 /** @override */ | 227 /** @override */ |
| 221 onSearchTermSearch: function(searchTerm) { | 228 onSearchTermSearch: function(searchTerm) { |
| 222 this.manager_.filter = searchTerm; | 229 this.manager_.filter = searchTerm; |
| 223 }, | 230 }, |
| 224 }; | 231 }; |
| 225 | 232 |
| 226 return {Manager: Manager}; | 233 return {Manager: Manager}; |
| 227 }); | 234 }); |
| OLD | NEW |