| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 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 /** | 5 /** |
| 6 * @fileoverview | 6 * @fileoverview |
| 7 * 'site-data-details-dialog' provides a dialog to show details of site data | 7 * 'site-data-details-dialog' provides a dialog to show details of site data |
| 8 * stored by a given site. | 8 * stored by a given site. |
| 9 */ | 9 */ |
| 10 Polymer({ | 10 Polymer({ |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 | 46 |
| 47 /** | 47 /** |
| 48 * Opens the dialog. | 48 * Opens the dialog. |
| 49 * @param {!settings.CookieTreeNode} site The site to show data for. | 49 * @param {!settings.CookieTreeNode} site The site to show data for. |
| 50 */ | 50 */ |
| 51 open: function(site) { | 51 open: function(site) { |
| 52 this.site_ = site; | 52 this.site_ = site; |
| 53 this.populateDialog_(); | 53 this.populateDialog_(); |
| 54 this.listener_ = cr.addWebUIListener( | 54 this.listener_ = cr.addWebUIListener( |
| 55 'onTreeItemRemoved', this.onTreeItemRemoved_.bind(this)); | 55 'onTreeItemRemoved', this.onTreeItemRemoved_.bind(this)); |
| 56 this.$.dialog.open(); | 56 this.$.dialog.showModal(); |
| 57 }, | 57 }, |
| 58 | 58 |
| 59 /** | 59 /** |
| 60 * Populates the dialog with the data about the site. | 60 * Populates the dialog with the data about the site. |
| 61 * @private |
| 61 */ | 62 */ |
| 62 populateDialog_: function() { | 63 populateDialog_: function() { |
| 63 this.title_ = loadTimeData.getStringF('siteSettingsCookieDialog', | 64 this.title_ = loadTimeData.getStringF('siteSettingsCookieDialog', |
| 64 this.site_.data_.title); | 65 this.site_.data_.title); |
| 65 | 66 |
| 66 this.entries_ = this.site_.getCookieList(); | 67 this.entries_ = this.site_.getCookieList(); |
| 67 if (this.entries_.length < 2) { | 68 if (this.entries_.length < 2) { |
| 68 // When there's only one item to show, hide the picker and change the | 69 // When there's only one item to show, hide the picker and change the |
| 69 // 'Remove All' button to read 'Remove' instead. | 70 // 'Remove All' button to read 'Remove' instead. |
| 70 this.$.container.hidden = true; | 71 this.$.container.hidden = true; |
| 71 this.$.clear.textContent = | 72 this.$.clear.textContent = |
| 72 loadTimeData.getString('siteSettingsCookieRemove'); | 73 loadTimeData.getString('siteSettingsCookieRemove'); |
| 73 } else { | 74 } else { |
| 74 this.$.picker.selected = this.entries_[0].id; | 75 this.$.picker.selected = this.entries_[0].id; |
| 75 this.lastSelectedIndex_ = 0; | 76 this.lastSelectedIndex_ = 0; |
| 76 } | 77 } |
| 77 | 78 |
| 78 this.populateItem_(this.entries_[0].id, this.site_); | 79 this.populateItem_(this.entries_[0].id, this.site_); |
| 79 }, | 80 }, |
| 80 | 81 |
| 81 /** | 82 /** |
| 82 * Recursively look up a node path for a leaf node with a given id. | 83 * 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 {!settings.CookieTreeNode} node The node to start with. |
| 84 * @param {string} currentPath The path constructed so far. | 85 * @param {string} currentPath The path constructed so far. |
| 85 * @param {string} targetId The id of the target leaf node to look for. | 86 * @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 * @return {string} The path of the node returned (or blank if not found). |
| 88 * @private |
| 87 */ | 89 */ |
| 88 nodePath_: function(node, currentPath, targetId) { | 90 nodePath_: function(node, currentPath, targetId) { |
| 89 if (node.data_.id == targetId) | 91 if (node.data_.id == targetId) |
| 90 return currentPath; | 92 return currentPath; |
| 91 | 93 |
| 92 for (var i = 0; i < node.children_.length; ++i) { | 94 for (var i = 0; i < node.children_.length; ++i) { |
| 93 var child = node.children_[i]; | 95 var child = node.children_[i]; |
| 94 var path = this.nodePath_( | 96 var path = this.nodePath_( |
| 95 child, currentPath + ',' + child.data_.id, targetId); | 97 child, currentPath + ',' + child.data_.id, targetId); |
| 96 if (path.length > 0) | 98 if (path.length > 0) |
| 97 return path; | 99 return path; |
| 98 } | 100 } |
| 99 | 101 |
| 100 return ''; | 102 return ''; |
| 101 }, | 103 }, |
| 102 | 104 |
| 103 /** | 105 /** |
| 104 * Add the cookie data to the content section of this dialog. | 106 * Add the cookie data to the content section of this dialog. |
| 105 * @param {string} id The id of the cookie node to display. | 107 * @param {string} id The id of the cookie node to display. |
| 106 * @param {!settings.CookieTreeNode} site The current site. | 108 * @param {!settings.CookieTreeNode} site The current site. |
| 109 * @private |
| 107 */ | 110 */ |
| 108 populateItem_: function(id, site) { | 111 populateItem_: function(id, site) { |
| 109 // Out with the old... | 112 // Out with the old... |
| 110 var root = this.$.content; | 113 var root = this.$.content; |
| 111 while (root.lastChild) { | 114 while (root.lastChild) { |
| 112 root.removeChild(root.lastChild); | 115 root.removeChild(root.lastChild); |
| 113 } | 116 } |
| 114 | 117 |
| 115 // In with the new... | 118 // In with the new... |
| 116 var node = site.fetchNodeById(id, true); | 119 var node = site.fetchNodeById(id, true); |
| 117 if (node) | 120 if (node) |
| 118 site.addCookieData(root, node); | 121 site.addCookieData(root, node); |
| 119 }, | 122 }, |
| 120 | 123 |
| 124 /** @private */ |
| 121 onTreeItemRemoved_: function(args) { | 125 onTreeItemRemoved_: function(args) { |
| 122 this.entries_ = this.site_.getCookieList(); | 126 this.entries_ = this.site_.getCookieList(); |
| 123 if (args[0] == this.site_.data_.id || this.entries_.length == 0) { | 127 if (args[0] == this.site_.data_.id || this.entries_.length == 0) { |
| 124 this.$.dialog.close(); | 128 this.$.dialog.close(); |
| 125 return; | 129 return; |
| 126 } | 130 } |
| 127 | 131 |
| 128 if (this.entries_.length <= this.lastSelectedIndex_) | 132 if (this.entries_.length <= this.lastSelectedIndex_) |
| 129 this.lastSelectedIndex_ = this.entries_.length - 1; | 133 this.lastSelectedIndex_ = this.entries_.length - 1; |
| 130 var selectedId = this.entries_[this.lastSelectedIndex_].id; | 134 var selectedId = this.entries_[this.lastSelectedIndex_].id; |
| 131 this.$.picker.selected = selectedId; | 135 this.$.picker.selected = selectedId; |
| 132 this.populateItem_(selectedId, this.site_); | 136 this.populateItem_(selectedId, this.site_); |
| 133 }, | 137 }, |
| 134 | 138 |
| 135 /** | 139 /** |
| 136 * A handler for when the user changes the dropdown box (switches cookies). | 140 * A handler for when the user changes the dropdown box (switches cookies). |
| 141 * @private |
| 137 */ | 142 */ |
| 138 onItemSelected_: function(event) { | 143 onItemSelected_: function(event) { |
| 139 this.populateItem_(event.detail.selected, this.site_); | 144 this.populateItem_(event.detail.selected, this.site_); |
| 140 | 145 |
| 141 // Store the index of what was selected so we can re-select the next value | 146 // Store the index of what was selected so we can re-select the next value |
| 142 // when things get deleted. | 147 // when things get deleted. |
| 143 for (var i = 0; i < this.entries_.length; ++i) { | 148 for (var i = 0; i < this.entries_.length; ++i) { |
| 144 if (this.entries_[i].data.id == event.detail.selected) { | 149 if (this.entries_[i].data.id == event.detail.selected) { |
| 145 this.lastSelectedIndex_ = i; | 150 this.lastSelectedIndex_ = i; |
| 146 break; | 151 break; |
| 147 } | 152 } |
| 148 } | 153 } |
| 149 }, | 154 }, |
| 150 | 155 |
| 151 /** | 156 /** |
| 152 * A handler for when the user opts to remove a single cookie. | 157 * A handler for when the user opts to remove a single cookie. |
| 158 * @private |
| 153 */ | 159 */ |
| 154 onRemove_: function(event) { | 160 onRemove_: function(event) { |
| 155 this.browserProxy.removeCookie(this.nodePath_( | 161 this.browserProxy.removeCookie(this.nodePath_( |
| 156 this.site_, this.site_.data_.id, this.$.picker.selected)); | 162 this.site_, this.site_.data_.id, this.$.picker.selected)); |
| 157 }, | 163 }, |
| 158 | 164 |
| 159 /** | 165 /** |
| 160 * A handler for when the user opts to remove all cookies. | 166 * A handler for when the user opts to remove all cookies. |
| 167 * @private |
| 161 */ | 168 */ |
| 162 onRemoveAll_: function(event) { | 169 onRemoveAll_: function(event) { |
| 163 cr.removeWebUIListener(this.listener_); | 170 cr.removeWebUIListener(this.listener_); |
| 164 this.browserProxy.removeCookie(this.site_.data_.id); | 171 this.browserProxy.removeCookie(this.site_.data_.id); |
| 172 this.$.dialog.close(); |
| 173 }, |
| 174 |
| 175 /** @private */ |
| 176 onCancelTap_: function() { |
| 177 this.$.dialog.cancel(); |
| 165 }, | 178 }, |
| 166 }); | 179 }); |
| OLD | NEW |