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, WebUIListenerBehavior], | |
| 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( | |
|
michaelpg
2016/07/04 19:44:21
cr => this?
Finnur
2016/07/05 11:04:49
I'm not sure what you mean here. A straight s/cr/t
michaelpg
2016/07/05 18:01:11
Noted. Then can we remove WebUIListenerBehavior?
Finnur
2016/07/06 09:57:35
Ah, yes! Done.
| |
| 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 = | |
| 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 site.addCookieData(root, site.fetchNodeById(id, true)); | |
| 117 }, | |
| 118 | |
| 119 onTreeItemRemoved_: function(args) { | |
| 120 this.entries_ = this.site_.getCookieList(); | |
| 121 if (args[0] == this.site_.data.id || this.entries_.length == 0) { | |
| 122 this.$.dialog.close(); | |
| 123 return; | |
| 124 } | |
| 125 | |
| 126 if (this.entries_.length <= this.lastSelectedIndex_) | |
| 127 this.lastSelectedIndex_ = this.entries_.length - 1; | |
| 128 var selectedId = this.entries_[this.lastSelectedIndex_].id; | |
| 129 this.$.picker.selected = selectedId; | |
| 130 this.populateItem_(selectedId, this.site_); | |
| 131 }, | |
| 132 | |
| 133 /** | |
| 134 * A handler for when the user changes the dropdown box (switches cookies). | |
| 135 */ | |
| 136 onItemSelected_: function(event) { | |
| 137 this.populateItem_(event.detail.selected, this.site_); | |
| 138 | |
| 139 // Store the index of what was selected so we can re-select the next value | |
| 140 // when things get deleted. | |
| 141 for (var i = 0; i < this.entries_.length; ++i) { | |
| 142 if (this.entries_[i].data.id == event.detail.selected) { | |
| 143 this.lastSelectedIndex_ = i; | |
| 144 break; | |
| 145 } | |
| 146 } | |
| 147 }, | |
| 148 | |
| 149 /** | |
| 150 * A handler for when the user opts to remove a single cookie. | |
| 151 */ | |
| 152 onRemove_: function(event) { | |
| 153 this.browserProxy.removeCookie( | |
| 154 this.nodePath_(this.site_, this.site_.data.id, this.$.picker.selected)); | |
| 155 }, | |
| 156 | |
| 157 /** | |
| 158 * A handler for when the user opts to remove all cookies. | |
| 159 */ | |
| 160 onRemoveAll_: function(event) { | |
| 161 cr.removeWebUIListener(this.listener_); | |
| 162 this.browserProxy.removeCookie(this.site_.data.id); | |
| 163 }, | |
| 164 }); | |
| OLD | NEW |