Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 /** | |
| 6 * @fileoverview | |
| 7 * 'site-data-details-dialog' provides a dialog to show details of site data | |
| 8 * stored by a given site. | |
| 9 */ | |
| 10 Polymer({ | |
| 11 is: 'site-data-details-dialog', | |
| 12 | |
| 13 behaviors: [SiteSettingsBehavior], | |
| 14 | |
| 15 properties: { | |
| 16 /** | |
| 17 * The title of the dialog. | |
| 18 */ | |
| 19 title_: String, | |
| 20 | |
| 21 /** | |
| 22 * The site to show details for. | |
| 23 * @type {!settings.CookieTreeNode} | |
| 24 * @private | |
| 25 */ | |
| 26 site_: Object, | |
| 27 | |
| 28 /** | |
| 29 * The cookie entries for the given site. | |
| 30 * @type {!Array<!CookieDataItem>} | |
| 31 * @private | |
| 32 */ | |
| 33 entries_: Array, | |
| 34 | |
| 35 /** | |
| 36 * The index of the last selected item. | |
| 37 */ | |
| 38 lastSelectedIndex_: Number, | |
| 39 | |
| 40 /** | |
| 41 * Our WebUI listener. | |
| 42 * @type {?WebUIListener} | |
| 43 */ | |
| 44 listener_: Object, | |
| 45 }, | |
| 46 | |
| 47 /** | |
| 48 * Opens the dialog. | |
| 49 * @param {!settings.CookieTreeNode} site The site to show data for. | |
| 50 */ | |
| 51 open: function(site) { | |
| 52 this.site_ = site; | |
| 53 this.populateDialog_(); | |
| 54 this.listener_ = cr.addWebUIListener( | |
| 55 'onTreeItemRemoved', this.onTreeItemRemoved_.bind(this)); | |
| 56 this.$.dialog.open(); | |
| 57 }, | |
| 58 | |
| 59 /** | |
| 60 * Populates the dialog with the data about the site. | |
| 61 */ | |
| 62 populateDialog_: function() { | |
| 63 this.title_ = loadTimeData.getStringF('siteSettingsCookieDialog', | |
| 64 this.site_.data_.title); | |
| 65 | |
| 66 this.entries_ = this.site_.getCookieList(); | |
| 67 if (this.entries_.length < 2) { | |
| 68 // When there's only one item to show, hide the picker and change the | |
| 69 // 'Remove All' button to read 'Remove' instead. | |
| 70 this.$.container.hidden = true; | |
| 71 this.$.clear.textContent = | |
|
michaelpg
2016/07/06 17:31:00
when do you "undo" these changes to hidden and tex
Finnur
2016/07/07 10:54:01
So... The list of data stored by the website is mo
michaelpg
2016/07/07 20:21:29
Acknowledged. Could you please open a separate bug
Finnur
2016/07/08 09:40:47
The bug for the missing settings is here: http://c
| |
| 72 loadTimeData.getString('siteSettingsCookieRemove'); | |
| 73 } else { | |
| 74 this.$.picker.selected = this.entries_[0].id; | |
| 75 this.lastSelectedIndex_ = 0; | |
| 76 } | |
| 77 | |
| 78 this.populateItem_(this.entries_[0].id, this.site_); | |
| 79 }, | |
| 80 | |
| 81 /** | |
| 82 * Recursively look up a node path for a leaf node with a given id. | |
| 83 * @param {!settings.CookieTreeNode} node The node to start with. | |
| 84 * @param {string} currentPath The path constructed so far. | |
| 85 * @param {string} targetId The id of the target leaf node to look for. | |
| 86 * @return {string} The path of the node returned (or blank if not found). | |
| 87 */ | |
| 88 nodePath_: function(node, currentPath, targetId) { | |
| 89 if (node.data_.id == targetId) | |
| 90 return currentPath; | |
| 91 | |
| 92 for (var i = 0; i < node.children_.length; ++i) { | |
| 93 var child = node.children_[i]; | |
| 94 var path = this.nodePath_( | |
| 95 child, currentPath + ',' + child.data_.id, targetId); | |
| 96 if (path.length > 0) | |
| 97 return path; | |
| 98 } | |
| 99 | |
| 100 return ''; | |
| 101 }, | |
| 102 | |
| 103 /** | |
| 104 * Add the cookie data to the content section of this dialog. | |
| 105 * @param {string} id The id of the cookie node to display. | |
| 106 * @param {!settings.CookieTreeNode} site The current site. | |
| 107 */ | |
| 108 populateItem_: function(id, site) { | |
| 109 // Out with the old... | |
| 110 var root = this.$.content; | |
| 111 while (root.lastChild) { | |
| 112 root.removeChild(root.lastChild); | |
| 113 } | |
| 114 | |
| 115 // In with the new... | |
| 116 var node = site.fetchNodeById(id, true); | |
| 117 if (node) | |
| 118 site.addCookieData(root, node); | |
| 119 }, | |
| 120 | |
| 121 onTreeItemRemoved_: function(args) { | |
| 122 this.entries_ = this.site_.getCookieList(); | |
| 123 if (args[0] == this.site_.data_.id || this.entries_.length == 0) { | |
| 124 this.$.dialog.close(); | |
| 125 return; | |
| 126 } | |
| 127 | |
| 128 if (this.entries_.length <= this.lastSelectedIndex_) | |
| 129 this.lastSelectedIndex_ = this.entries_.length - 1; | |
| 130 var selectedId = this.entries_[this.lastSelectedIndex_].id; | |
| 131 this.$.picker.selected = selectedId; | |
| 132 this.populateItem_(selectedId, this.site_); | |
| 133 }, | |
| 134 | |
| 135 /** | |
| 136 * A handler for when the user changes the dropdown box (switches cookies). | |
| 137 */ | |
| 138 onItemSelected_: function(event) { | |
| 139 this.populateItem_(event.detail.selected, this.site_); | |
| 140 | |
| 141 // Store the index of what was selected so we can re-select the next value | |
| 142 // when things get deleted. | |
| 143 for (var i = 0; i < this.entries_.length; ++i) { | |
| 144 if (this.entries_[i].data.id == event.detail.selected) { | |
| 145 this.lastSelectedIndex_ = i; | |
| 146 break; | |
| 147 } | |
| 148 } | |
| 149 }, | |
| 150 | |
| 151 /** | |
| 152 * A handler for when the user opts to remove a single cookie. | |
| 153 */ | |
| 154 onRemove_: function(event) { | |
| 155 this.browserProxy.removeCookie(this.nodePath_( | |
| 156 this.site_, this.site_.data_.id, this.$.picker.selected)); | |
| 157 }, | |
| 158 | |
| 159 /** | |
| 160 * A handler for when the user opts to remove all cookies. | |
| 161 */ | |
| 162 onRemoveAll_: function(event) { | |
| 163 cr.removeWebUIListener(this.listener_); | |
| 164 this.browserProxy.removeCookie(this.site_.data_.id); | |
| 165 }, | |
| 166 }); | |
| OLD | NEW |