| 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 |
| 11 * @param {chrome.developerPrivate.ExtensionInfo} b | 11 * @param {chrome.developerPrivate.ExtensionInfo} b |
| 12 * @return {number} | 12 * @return {number} |
| 13 */ | 13 */ |
| 14 var compareExtensions = function(a, b) { | 14 var compareExtensions = function(a, b) { |
| 15 function compare(x, y) { | 15 function compare(x, y) { |
| 16 return x < y ? -1 : (x > y ? 1 : 0); | 16 return x < y ? -1 : (x > y ? 1 : 0); |
| 17 } | 17 } |
| 18 function compareLocation(x, y) { | 18 function compareLocation(x, y) { |
| 19 if (x.location == y.location) | 19 if (x.location == y.location) |
| 20 return 0; | 20 return 0; |
| 21 if (x.location == chrome.developerPrivate.Location.UNPACKED) | 21 if (x.location == chrome.developerPrivate.Location.UNPACKED) |
| 22 return -1; | 22 return -1; |
| 23 if (y.location == chrome.developerPrivate.Location.UNPACKED) | 23 if (y.location == chrome.developerPrivate.Location.UNPACKED) |
| 24 return 1; | 24 return 1; |
| 25 return 0; | 25 return 0; |
| 26 } | 26 } |
| 27 return compareLocation(a, b) || | 27 return compareLocation(a, b) || |
| 28 compare(a.name.toLowerCase(), b.name.toLowerCase()) || | 28 compare(a.name.toLowerCase(), b.name.toLowerCase()) || |
| 29 compare(a.id, b.id); | 29 compare(a.id, b.id); |
| 30 }; | 30 }; |
| 31 | 31 |
| 32 var Manager = Polymer({ | 32 var Manager = Polymer({ |
| 33 is: 'extensions-manager', | 33 is: 'extensions-manager', |
| 34 | 34 |
| 35 behaviors: [I18nBehavior], | 35 behaviors: [I18nBehavior], |
| 36 | 36 |
| 37 properties: { | 37 properties: { |
| 38 /** @type {extensions.Sidebar} */ | 38 /** @type {extensions.Sidebar} */ |
| 39 sidebar: Object, | 39 sidebar: Object, |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 | 79 |
| 80 /** | 80 /** |
| 81 * The current page being shown. | 81 * The current page being shown. |
| 82 * @private {!PageState} | 82 * @private {!PageState} |
| 83 */ | 83 */ |
| 84 currentPage_: Object, | 84 currentPage_: Object, |
| 85 | 85 |
| 86 /** @type {!Array<!chrome.developerPrivate.ExtensionInfo>} */ | 86 /** @type {!Array<!chrome.developerPrivate.ExtensionInfo>} */ |
| 87 extensions: { | 87 extensions: { |
| 88 type: Array, | 88 type: Array, |
| 89 value: function() { return []; }, | 89 value: function() { |
| 90 return []; |
| 91 }, |
| 90 }, | 92 }, |
| 91 | 93 |
| 92 /** @type {!Array<!chrome.developerPrivate.ExtensionInfo>} */ | 94 /** @type {!Array<!chrome.developerPrivate.ExtensionInfo>} */ |
| 93 apps: { | 95 apps: { |
| 94 type: Array, | 96 type: Array, |
| 95 value: function() { return []; }, | 97 value: function() { |
| 98 return []; |
| 99 }, |
| 96 }, | 100 }, |
| 97 }, | 101 }, |
| 98 | 102 |
| 99 listeners: { | 103 listeners: { |
| 100 'items-list.extension-item-show-details': 'onShouldShowItemDetails_', | 104 'items-list.extension-item-show-details': 'onShouldShowItemDetails_', |
| 101 'items-list.extension-item-show-errors': 'onShouldShowItemErrors_', | 105 'items-list.extension-item-show-errors': 'onShouldShowItemErrors_', |
| 102 }, | 106 }, |
| 103 | 107 |
| 104 created: function() { | 108 created: function() { |
| 105 this.readyPromiseResolver = new PromiseResolver(); | 109 this.readyPromiseResolver = new PromiseResolver(); |
| 106 }, | 110 }, |
| 107 | 111 |
| 108 ready: function() { | 112 ready: function() { |
| 109 /** @type {extensions.Sidebar} */ | 113 /** @type {extensions.Sidebar} */ |
| 110 this.sidebar = | 114 this.sidebar = |
| 111 /** @type {extensions.Sidebar} */(this.$$('extensions-sidebar')); | 115 /** @type {extensions.Sidebar} */ (this.$$('extensions-sidebar')); |
| 112 this.toolbar = | 116 this.toolbar = |
| 113 /** @type {extensions.Toolbar} */(this.$$('extensions-toolbar')); | 117 /** @type {extensions.Toolbar} */ (this.$$('extensions-toolbar')); |
| 114 this.listHelper_ = new ListHelper(this); | 118 this.listHelper_ = new ListHelper(this); |
| 115 this.sidebar.setListDelegate(this.listHelper_); | 119 this.sidebar.setListDelegate(this.listHelper_); |
| 116 this.readyPromiseResolver.resolve(); | 120 this.readyPromiseResolver.resolve(); |
| 117 this.currentPage_ = {page: Page.LIST}; | 121 this.currentPage_ = {page: Page.LIST}; |
| 118 this.navigationHelper_ = | 122 this.navigationHelper_ = |
| 119 new extensions.NavigationHelper(function(newPage) { | 123 new extensions.NavigationHelper(function(newPage) { |
| 120 this.changePage(newPage, true); | 124 this.changePage(newPage, true); |
| 121 }.bind(this)); | 125 }.bind(this)); |
| 122 this.optionsDialog.addEventListener('close', function() { | 126 this.optionsDialog.addEventListener('close', function() { |
| 123 // We update the page when the options dialog closes, but only if we're | 127 // We update the page when the options dialog closes, but only if we're |
| 124 // still on the details page. We could be on a different page if the | 128 // still on the details page. We could be on a different page if the |
| 125 // user hit back while the options dialog was visible; in that case, the | 129 // user hit back while the options dialog was visible; in that case, the |
| 126 // new page is already correct. | 130 // new page is already correct. |
| 127 if (this.currentPage_.page == Page.DETAILS) { | 131 if (this.currentPage_.page == Page.DETAILS) { |
| 128 // This will update the currentPage_ and the NavigationHelper; since | 132 // This will update the currentPage_ and the NavigationHelper; since |
| 129 // the active page is already the details page, no main page | 133 // the active page is already the details page, no main page |
| 130 // transition occurs. | 134 // transition occurs. |
| 131 this.changePage( | 135 this.changePage( |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 221 return item.id == itemId; | 225 return item.id == itemId; |
| 222 }); | 226 }); |
| 223 }, | 227 }, |
| 224 | 228 |
| 225 /** | 229 /** |
| 226 * @return {?chrome.developerPrivate.ExtensionInfo} | 230 * @return {?chrome.developerPrivate.ExtensionInfo} |
| 227 * @private | 231 * @private |
| 228 */ | 232 */ |
| 229 getData_: function(id) { | 233 getData_: function(id) { |
| 230 return this.extensions[this.getIndexInList_('extensions', id)] || | 234 return this.extensions[this.getIndexInList_('extensions', id)] || |
| 231 this.apps[this.getIndexInList_('apps', id)]; | 235 this.apps[this.getIndexInList_('apps', id)]; |
| 232 }, | 236 }, |
| 233 | 237 |
| 234 /** | 238 /** |
| 235 * @return {boolean} Whether the list should be visible. | 239 * @return {boolean} Whether the list should be visible. |
| 236 * @private | 240 * @private |
| 237 */ | 241 */ |
| 238 computeListHidden_: function() { | 242 computeListHidden_: function() { |
| 239 return this.$['items-list'].items.length == 0; | 243 return this.$['items-list'].items.length == 0; |
| 240 }, | 244 }, |
| 241 | 245 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 269 this.set([listId, index], item); | 273 this.set([listId, index], item); |
| 270 | 274 |
| 271 // Update the subpage if it is open and displaying the item. If it's not | 275 // Update the subpage if it is open and displaying the item. If it's not |
| 272 // open, we don't update the data even if it's displaying that item. We'll | 276 // open, we don't update the data even if it's displaying that item. We'll |
| 273 // set the item correctly before opening the page. It's a little weird | 277 // set the item correctly before opening the page. It's a little weird |
| 274 // that the DOM will have stale data, but there's no point in causing the | 278 // that the DOM will have stale data, but there's no point in causing the |
| 275 // extra work. | 279 // extra work. |
| 276 if (this.detailViewItem_ && this.detailViewItem_.id == item.id && | 280 if (this.detailViewItem_ && this.detailViewItem_.id == item.id && |
| 277 this.$.pages.selected == Page.DETAILS) { | 281 this.$.pages.selected == Page.DETAILS) { |
| 278 this.detailViewItem_ = item; | 282 this.detailViewItem_ = item; |
| 279 } else if (this.errorPageItem_ && this.errorPageItem_.id == item.id && | 283 } else if ( |
| 280 this.$.pages.selected == Page.ERRORS) { | 284 this.errorPageItem_ && this.errorPageItem_.id == item.id && |
| 285 this.$.pages.selected == Page.ERRORS) { |
| 281 this.errorPageItem_ = item; | 286 this.errorPageItem_ = item; |
| 282 } | 287 } |
| 283 }, | 288 }, |
| 284 | 289 |
| 285 /** | 290 /** |
| 286 * @param {!chrome.developerPrivate.ExtensionInfo} item The data for the | 291 * @param {!chrome.developerPrivate.ExtensionInfo} item The data for the |
| 287 * item to remove. | 292 * item to remove. |
| 288 */ | 293 */ |
| 289 removeItem: function(item) { | 294 removeItem: function(item) { |
| 290 var listId = this.getListId_(item.type); | 295 var listId = this.getListId_(item.type); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 339 data = assert(this.getData_(newPage.extensionId)); | 344 data = assert(this.getData_(newPage.extensionId)); |
| 340 | 345 |
| 341 if (toPage == Page.DETAILS) | 346 if (toPage == Page.DETAILS) |
| 342 this.detailViewItem_ = assert(data); | 347 this.detailViewItem_ = assert(data); |
| 343 else if (toPage == Page.ERRORS) | 348 else if (toPage == Page.ERRORS) |
| 344 this.errorPageItem_ = assert(data); | 349 this.errorPageItem_ = assert(data); |
| 345 | 350 |
| 346 if (fromPage != toPage) { | 351 if (fromPage != toPage) { |
| 347 var entry; | 352 var entry; |
| 348 var exit; | 353 var exit; |
| 349 if (fromPage == Page.LIST && (toPage == Page.DETAILS || | 354 if (fromPage == Page.LIST && |
| 350 toPage == Page.ERRORS)) { | 355 (toPage == Page.DETAILS || toPage == Page.ERRORS)) { |
| 351 this.$['items-list'].willShowItemSubpage(data.id); | 356 this.$['items-list'].willShowItemSubpage(data.id); |
| 352 entry = [extensions.Animation.HERO]; | 357 entry = [extensions.Animation.HERO]; |
| 353 // The item grid can be larger than the detail view that we're | 358 // The item grid can be larger than the detail view that we're |
| 354 // hero'ing into, so we want to also fade out to avoid any jarring. | 359 // hero'ing into, so we want to also fade out to avoid any jarring. |
| 355 exit = [extensions.Animation.HERO, extensions.Animation.FADE_OUT]; | 360 exit = [extensions.Animation.HERO, extensions.Animation.FADE_OUT]; |
| 356 } else if (toPage == Page.LIST) { | 361 } else if (toPage == Page.LIST) { |
| 357 entry = [extensions.Animation.FADE_IN]; | 362 entry = [extensions.Animation.FADE_IN]; |
| 358 exit = [extensions.Animation.SCALE_DOWN]; | 363 exit = [extensions.Animation.SCALE_DOWN]; |
| 359 } else { | 364 } else { |
| 360 assert(toPage == Page.DETAILS || | 365 assert(toPage == Page.DETAILS || toPage == Page.SHORTCUTS); |
| 361 toPage == Page.SHORTCUTS); | |
| 362 entry = [extensions.Animation.FADE_IN]; | 366 entry = [extensions.Animation.FADE_IN]; |
| 363 exit = [extensions.Animation.FADE_OUT]; | 367 exit = [extensions.Animation.FADE_OUT]; |
| 364 } | 368 } |
| 365 | 369 |
| 366 this.getPage_(fromPage).animationHelper.setExitAnimations(exit); | 370 this.getPage_(fromPage).animationHelper.setExitAnimations(exit); |
| 367 this.getPage_(toPage).animationHelper.setEntryAnimations(entry); | 371 this.getPage_(toPage).animationHelper.setEntryAnimations(entry); |
| 368 this.$.pages.selected = toPage; | 372 this.$.pages.selected = toPage; |
| 369 } | 373 } |
| 370 | 374 |
| 371 if (newPage.subpage) { | 375 if (newPage.subpage) { |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 433 var items; | 437 var items; |
| 434 switch (type) { | 438 switch (type) { |
| 435 case extensions.ShowingType.EXTENSIONS: | 439 case extensions.ShowingType.EXTENSIONS: |
| 436 items = this.manager_.extensions; | 440 items = this.manager_.extensions; |
| 437 break; | 441 break; |
| 438 case extensions.ShowingType.APPS: | 442 case extensions.ShowingType.APPS: |
| 439 items = this.manager_.apps; | 443 items = this.manager_.apps; |
| 440 break; | 444 break; |
| 441 } | 445 } |
| 442 | 446 |
| 443 this.manager_.$/* hack */ ['items-list'].set('items', assert(items)); | 447 this.manager_.$ /* hack */['items-list'].set('items', assert(items)); |
| 444 this.manager_.changePage({page: Page.LIST}); | 448 this.manager_.changePage({page: Page.LIST}); |
| 445 }, | 449 }, |
| 446 | 450 |
| 447 /** @override */ | 451 /** @override */ |
| 448 showKeyboardShortcuts: function() { | 452 showKeyboardShortcuts: function() { |
| 449 this.manager_.changePage({page: Page.SHORTCUTS}); | 453 this.manager_.changePage({page: Page.SHORTCUTS}); |
| 450 }, | 454 }, |
| 451 }; | 455 }; |
| 452 | 456 |
| 453 return {Manager: Manager}; | 457 return {Manager: Manager}; |
| 454 }); | 458 }); |
| OLD | NEW |