Chromium Code Reviews| 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 |
| 75 ready: function() { | 69 ready: function() { |
| 76 /** @type {extensions.Sidebar} */ | 70 /** @type {extensions.Sidebar} */ |
| 77 this.sidebar = | 71 this.sidebar = |
| 78 /** @type {extensions.Sidebar} */(this.$$('extensions-sidebar')); | 72 /** @type {extensions.Sidebar} */(this.$$('extensions-sidebar')); |
| 79 this.service = extensions.Service.getInstance(); | 73 this.service = extensions.Service.getInstance(); |
| 80 this.service.managerReady(this); | 74 this.service.managerReady(this); |
| 81 this.scrollHelper_ = new ScrollHelper(this); | 75 this.listHelper_ = new ListHelper(this); |
| 82 this.sidebar.setScrollDelegate(this.scrollHelper_); | 76 this.sidebar.setListDelegate(this.listHelper_); |
| 83 this.$.toolbar.setSearchDelegate(new SearchHelper(this)); | 77 this.$.toolbar.setSearchDelegate(new SearchHelper(this)); |
| 84 }, | 78 }, |
| 85 | 79 |
| 86 /** | 80 /** |
| 87 * @param {chrome.developerPrivate.ExtensionType} type The type of item. | 81 * @param {chrome.developerPrivate.ExtensionType} type The type of item. |
| 88 * @return {string} The ID of the list that the item belongs in. | 82 * @return {string} The ID of the list that the item belongs in. |
| 89 * @private | 83 * @private |
| 90 */ | 84 */ |
| 91 getListId_: function(type) { | 85 getListId_: function(type) { |
| 92 var listId; | 86 var listId; |
| 93 var ExtensionType = chrome.developerPrivate.ExtensionType; | 87 var ExtensionType = chrome.developerPrivate.ExtensionType; |
| 94 switch (type) { | 88 switch (type) { |
| 95 case ExtensionType.HOSTED_APP: | 89 case ExtensionType.HOSTED_APP: |
| 96 case ExtensionType.LEGACY_PACKAGED_APP: | 90 case ExtensionType.LEGACY_PACKAGED_APP: |
| 97 listId = 'websites'; | |
| 98 break; | |
| 99 case ExtensionType.PLATFORM_APP: | 91 case ExtensionType.PLATFORM_APP: |
| 100 listId = 'apps'; | 92 listId = 'apps'; |
| 101 break; | 93 break; |
| 102 case ExtensionType.EXTENSION: | 94 case ExtensionType.EXTENSION: |
| 103 case ExtensionType.SHARED_MODULE: | 95 case ExtensionType.SHARED_MODULE: |
| 104 listId = 'extensions'; | 96 listId = 'extensions'; |
| 105 break; | 97 break; |
| 106 case ExtensionType.THEME: | 98 case ExtensionType.THEME: |
| 107 assertNotReached( | 99 assertNotReached( |
| 108 'Don\'t send themes to the chrome://extensions page'); | 100 'Don\'t send themes to the chrome://extensions page'); |
| 109 break; | 101 break; |
| 110 } | 102 } |
| 111 assert(listId); | 103 assert(listId); |
| 112 return listId; | 104 return listId; |
| 113 }, | 105 }, |
| 114 | 106 |
| 115 /** | 107 /** |
| 116 * @param {string} listId The list to look for the item in. | 108 * @param {string} listId The list to look for the item in. |
| 117 * @param {string} itemId The id of the item to look for. | 109 * @param {string} itemId The id of the item to look for. |
| 118 * @return {number} The index of the item in the list, or -1 if not found. | 110 * @return {number} The index of the item in the list, or -1 if not found. |
| 119 * @private | 111 * @private |
| 120 */ | 112 */ |
| 121 getIndexInList_: function(listId, itemId) { | 113 getIndexInList_: function(listId, itemId) { |
| 122 return this[listId].findIndex(function(item) { | 114 return this[listId].findIndex(function(item) { |
| 123 return item.id == itemId; | 115 return item.id == itemId; |
| 124 }); | 116 }); |
| 125 }, | 117 }, |
| 126 | 118 |
| 127 /** | 119 /** |
| 128 * @param {!Array<!chrome.developerPrivate.ExtensionInfo>} list | |
| 129 * @return {boolean} Whether the list should be visible. | 120 * @return {boolean} Whether the list should be visible. |
| 130 */ | 121 */ |
| 131 computeListHidden_: function(list) { | 122 computeListHidden_: function(a, b, c, d) { |
|
Dan Beam
2016/04/26 01:32:12
why a, b, c, d with no doc?
Devlin
2016/04/26 17:24:18
Whoops, was debugging. Removed.
| |
| 132 return list.length == 0; | 123 return this.$['items-list'].items.length == 0; |
| 133 }, | 124 }, |
| 134 | 125 |
| 135 /** | 126 /** |
| 136 * Creates and adds a new extensions-item element to the list, inserting it | 127 * Creates and adds a new extensions-item element to the list, inserting it |
| 137 * into its sorted position in the relevant section. | 128 * into its sorted position in the relevant section. |
| 138 * @param {!chrome.developerPrivate.ExtensionInfo} item The extension | 129 * @param {!chrome.developerPrivate.ExtensionInfo} item The extension |
| 139 * the new element is representing. | 130 * the new element is representing. |
| 140 */ | 131 */ |
| 141 addItem: function(item) { | 132 addItem: function(item) { |
| 142 var listId = this.getListId_(item.type); | 133 var listId = this.getListId_(item.type); |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 166 * @param {!chrome.developerPrivate.ExtensionInfo} item The data for the | 157 * @param {!chrome.developerPrivate.ExtensionInfo} item The data for the |
| 167 * item to remove. | 158 * item to remove. |
| 168 */ | 159 */ |
| 169 removeItem: function(item) { | 160 removeItem: function(item) { |
| 170 var listId = this.getListId_(item.type); | 161 var listId = this.getListId_(item.type); |
| 171 var index = this.getIndexInList_(listId, item.id); | 162 var index = this.getIndexInList_(listId, item.id); |
| 172 // We should never try and remove a non-existent item. | 163 // We should never try and remove a non-existent item. |
| 173 assert(index >= 0); | 164 assert(index >= 0); |
| 174 this.splice(listId, index, 1); | 165 this.splice(listId, index, 1); |
| 175 }, | 166 }, |
| 167 | |
|
Dan Beam
2016/04/26 01:32:12
doc
Devlin
2016/04/26 17:24:18
Done.
| |
| 168 showDetailsFor: function(data) { | |
| 169 this.$['details-view'].set('data', data); | |
| 170 this.$.pages.selected = 1; | |
| 171 }, | |
| 172 | |
|
Dan Beam
2016/04/26 01:32:12
/** @private */
Devlin
2016/04/26 17:24:18
Done.
| |
| 173 onDetailsViewClose_: function() { | |
| 174 this.$.pages.selected = 0; | |
| 175 } | |
| 176 }); | 176 }); |
| 177 | 177 |
| 178 /** | 178 /** |
| 179 * @param {extensions.Manager} manager | 179 * @param {extensions.Manager} manager |
|
Dan Beam
2016/04/26 01:32:12
a helper that takes a manager and implements a del
Devlin
2016/04/26 17:24:18
It's okay, we don't yet have Factory, Impl, or hal
| |
| 180 * @constructor | 180 * @constructor |
| 181 * @implements {extensions.SidebarScrollDelegate} | 181 * @implements {extensions.SidebarListDelegate} |
| 182 */ | 182 */ |
| 183 function ScrollHelper(manager) { | 183 function ListHelper(manager) { |
| 184 this.items_ = manager.$.items; | 184 this.manager = manager; |
| 185 } | 185 } |
| 186 | 186 |
| 187 ScrollHelper.prototype = { | 187 ListHelper.prototype = { |
| 188 /** @override */ | 188 /** @override */ |
| 189 scrollToExtensions: function() { | 189 showExtensions: function() { |
| 190 this.items_.scrollTop = | 190 this.manager.$['items-list'].set('items', this.manager.extensions); |
|
Dan Beam
2016/04/26 01:32:12
why not just ask for for an items list element if
Devlin
2016/04/26 17:24:18
We also use manager.extensions and manager.apps.
| |
| 191 this.items_.querySelector('#extensions-list').offsetTop; | |
| 192 }, | 191 }, |
| 193 | 192 |
| 194 /** @override */ | 193 /** @override */ |
| 195 scrollToApps: function() { | 194 showApps: function() { |
| 196 this.items_.scrollTop = | 195 this.manager.$['items-list'].set('items', this.manager.apps); |
| 197 this.items_.querySelector('#apps-list').offsetTop; | |
| 198 }, | |
| 199 | |
| 200 /** @override */ | |
| 201 scrollToWebsites: function() { | |
| 202 this.items_.scrollTop = | |
| 203 this.items_.querySelector('#websites-list').offsetTop; | |
| 204 }, | 196 }, |
| 205 }; | 197 }; |
| 206 | 198 |
| 207 /** | 199 /** |
| 208 * @param {extensions.Manager} manager | 200 * @param {extensions.Manager} manager |
| 209 * @constructor | 201 * @constructor |
| 210 * @implements {SearchFieldDelegate} | 202 * @implements {SearchFieldDelegate} |
| 211 */ | 203 */ |
| 212 function SearchHelper(manager) { | 204 function SearchHelper(manager) { |
| 213 this.manager_ = manager; | 205 this.manager_ = manager; |
| 214 } | 206 } |
| 215 | 207 |
| 216 SearchHelper.prototype = { | 208 SearchHelper.prototype = { |
| 217 /** @override */ | 209 /** @override */ |
| 218 onSearchTermSearch: function(searchTerm) { | 210 onSearchTermSearch: function(searchTerm) { |
| 219 this.manager_.filter = searchTerm; | 211 this.manager_.filter = searchTerm; |
| 220 }, | 212 }, |
| 221 }; | 213 }; |
| 222 | 214 |
| 223 return {Manager: Manager}; | 215 return {Manager: Manager}; |
| 224 }); | 216 }); |
| OLD | NEW |