| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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('options', function() { | 5 cr.define('options', function() { |
| 6 /** @const */ var DeletableItemList = options.DeletableItemList; | 6 /** @const */ var DeletableItemList = options.DeletableItemList; |
| 7 /** @const */ var DeletableItem = options.DeletableItem; | 7 /** @const */ var DeletableItem = options.DeletableItem; |
| 8 /** @const */ var ArrayDataModel = cr.ui.ArrayDataModel; | 8 /** @const */ var ArrayDataModel = cr.ui.ArrayDataModel; |
| 9 /** @const */ var ListSingleSelectionModel = cr.ui.ListSingleSelectionModel; | 9 /** @const */ var ListSingleSelectionModel = cr.ui.ListSingleSelectionModel; |
| 10 | 10 |
| (...skipping 596 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 607 */ | 607 */ |
| 608 var CookiesList = cr.ui.define('list'); | 608 var CookiesList = cr.ui.define('list'); |
| 609 | 609 |
| 610 CookiesList.prototype = { | 610 CookiesList.prototype = { |
| 611 __proto__: DeletableItemList.prototype, | 611 __proto__: DeletableItemList.prototype, |
| 612 | 612 |
| 613 /** @inheritDoc */ | 613 /** @inheritDoc */ |
| 614 decorate: function() { | 614 decorate: function() { |
| 615 DeletableItemList.prototype.decorate.call(this); | 615 DeletableItemList.prototype.decorate.call(this); |
| 616 this.classList.add('cookie-list'); | 616 this.classList.add('cookie-list'); |
| 617 this.data_ = []; | 617 this.dataModel = new ArrayDataModel([]); |
| 618 this.dataModel = new ArrayDataModel(this.data_); | |
| 619 this.addEventListener('keydown', this.handleKeyLeftRight_.bind(this)); | 618 this.addEventListener('keydown', this.handleKeyLeftRight_.bind(this)); |
| 620 var sm = new ListSingleSelectionModel(); | 619 var sm = new ListSingleSelectionModel(); |
| 621 sm.addEventListener('change', this.cookieSelectionChange_.bind(this)); | 620 sm.addEventListener('change', this.cookieSelectionChange_.bind(this)); |
| 622 sm.addEventListener('leadIndexChange', this.cookieLeadChange_.bind(this)); | 621 sm.addEventListener('leadIndexChange', this.cookieLeadChange_.bind(this)); |
| 623 this.selectionModel = sm; | 622 this.selectionModel = sm; |
| 624 this.infoNodes = {}; | 623 this.infoNodes = {}; |
| 625 this.fixedHeight = false; | 624 this.fixedHeight = false; |
| 626 var doc = this.ownerDocument; | 625 var doc = this.ownerDocument; |
| 627 // Create a table for each type of site data (e.g. cookies, databases, | 626 // Create a table for each type of site data (e.g. cookies, databases, |
| 628 // etc.) and save it so that we can reuse it for all origins. | 627 // etc.) and save it so that we can reuse it for all origins. |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 732 // We use the cached expanded item in order to allow it to maintain some | 731 // We use the cached expanded item in order to allow it to maintain some |
| 733 // state (like its fixed height, and which bubble is selected). | 732 // state (like its fixed height, and which bubble is selected). |
| 734 if (this.expandedItem && this.expandedItem.origin == data) | 733 if (this.expandedItem && this.expandedItem.origin == data) |
| 735 return this.expandedItem; | 734 return this.expandedItem; |
| 736 return new CookieListItem(data, this); | 735 return new CookieListItem(data, this); |
| 737 }, | 736 }, |
| 738 | 737 |
| 739 // from options.DeletableItemList | 738 // from options.DeletableItemList |
| 740 /** @inheritDoc */ | 739 /** @inheritDoc */ |
| 741 deleteItemAtIndex: function(index) { | 740 deleteItemAtIndex: function(index) { |
| 742 var item = this.data_[index]; | 741 var item = this.dataModel.item(index); |
| 743 if (item) { | 742 if (item) { |
| 744 var pathId = item.pathId; | 743 var pathId = item.pathId; |
| 745 if (pathId) | 744 if (pathId) |
| 746 chrome.send('removeCookie', [pathId]); | 745 chrome.send('removeCookie', [pathId]); |
| 747 } | 746 } |
| 748 }, | 747 }, |
| 749 | 748 |
| 750 /** | 749 /** |
| 751 * Insert the given list of cookie tree nodes at the given index. | 750 * Insert the given list of cookie tree nodes at the given index. |
| 752 * Both CookiesList and CookieTreeNode implement this API. | 751 * Both CookiesList and CookieTreeNode implement this API. |
| 753 * @param {Array.<Object>} data The data objects for the nodes to add. | 752 * @param {Array.<Object>} data The data objects for the nodes to add. |
| 754 * @param {number} start The index at which to start inserting the nodes. | 753 * @param {number} start The index at which to start inserting the nodes. |
| 755 */ | 754 */ |
| 756 insertAt: function(data, start) { | 755 insertAt: function(data, start) { |
| 757 spliceTreeNodes(data, start, this.dataModel); | 756 spliceTreeNodes(data, start, this.dataModel); |
| 758 }, | 757 }, |
| 759 | 758 |
| 760 /** | 759 /** |
| 761 * Remove a cookie tree node from the given index. | 760 * Remove a cookie tree node from the given index. |
| 762 * Both CookiesList and CookieTreeNode implement this API. | 761 * Both CookiesList and CookieTreeNode implement this API. |
| 763 * @param {number} index The index of the tree node to remove. | 762 * @param {number} index The index of the tree node to remove. |
| 764 */ | 763 */ |
| 765 remove: function(index) { | 764 remove: function(index) { |
| 766 if (index < this.data_.length) | 765 if (index < this.dataModel.length) |
| 767 this.dataModel.splice(index, 1); | 766 this.dataModel.splice(index, 1); |
| 768 }, | 767 }, |
| 769 | 768 |
| 770 /** | 769 /** |
| 771 * Clears the list. | 770 * Clears the list. |
| 772 * Both CookiesList and CookieTreeNode implement this API. | 771 * Both CookiesList and CookieTreeNode implement this API. |
| 773 * It is used by CookiesList.loadChildren(). | 772 * It is used by CookiesList.loadChildren(). |
| 774 */ | 773 */ |
| 775 clear: function() { | 774 clear: function() { |
| 776 parentLookup = {}; | 775 parentLookup = {}; |
| 777 this.data_ = []; | 776 this.dataModel.splice(0, this.dataModel.length); |
| 778 this.dataModel = new ArrayDataModel(this.data_); | |
| 779 this.redraw(); | 777 this.redraw(); |
| 780 }, | 778 }, |
| 781 | 779 |
| 782 /** | 780 /** |
| 783 * Add tree nodes by given parent. | 781 * Add tree nodes by given parent. |
| 784 * @param {Object} parent The parent node. | 782 * @param {Object} parent The parent node. |
| 785 * @param {number} start The index at which to start inserting the nodes. | 783 * @param {number} start The index at which to start inserting the nodes. |
| 786 * @param {Array} nodesData Nodes data array. | 784 * @param {Array} nodesData Nodes data array. |
| 787 * @private | 785 * @private |
| 788 */ | 786 */ |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 846 parent.clear(); | 844 parent.clear(); |
| 847 this.addByParent_(parent, 0, children); | 845 this.addByParent_(parent, 0, children); |
| 848 parent.endBatchUpdates(); | 846 parent.endBatchUpdates(); |
| 849 }, | 847 }, |
| 850 }; | 848 }; |
| 851 | 849 |
| 852 return { | 850 return { |
| 853 CookiesList: CookiesList | 851 CookiesList: CookiesList |
| 854 }; | 852 }; |
| 855 }); | 853 }); |
| OLD | NEW |