Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 (function() { | |
| 6 'use strict'; | |
| 7 | |
| 8 /** | |
| 9 * 'site-data-details-subpage' Display cookie contents. | |
| 10 */ | |
| 11 Polymer({ | |
| 12 is: 'site-data-details-subpage', | |
| 13 | |
| 14 behaviors: [settings.RouteObserverBehavior, CookieTreeBehavior], | |
| 15 | |
| 16 properties: { | |
| 17 /** | |
| 18 * The cookie entries for the given site. | |
| 19 * @type {!Array<!CookieDataItem>} | |
| 20 * @private | |
| 21 */ | |
| 22 entries_: Array, | |
| 23 | |
| 24 /** Set the page title on the settings-subpage parent. */ | |
| 25 pageTitle: { | |
| 26 type: String, | |
| 27 notify: true, | |
| 28 }, | |
| 29 | |
| 30 /** | |
| 31 * The site to show details for. | |
| 32 * @type {!settings.CookieTreeNode} | |
| 33 * @private | |
| 34 */ | |
| 35 site_: Object, | |
| 36 }, | |
| 37 | |
| 38 attached: function() { | |
| 39 this.addEventListener('cookie-tree-changed', | |
| 40 this.onCookiesLoaded_.bind(this)); | |
| 41 | |
| 42 Polymer.dom(this).parentNode.querySelector( | |
| 43 '#siteDataDetailsRemoveAll').addEventListener( | |
|
Dan Beam
2016/11/01 06:33:27
what is this doing? adding an event listener to a
dschuyler
2016/11/01 18:55:34
The goal was to know when that button is pushed, w
| |
| 44 'tap', this.onRemoveAll_.bind(this)); | |
| 45 }, | |
| 46 | |
| 47 /** | |
| 48 * settings.RouteObserverBehavior | |
| 49 * @param {!settings.Route} route | |
| 50 * @protected | |
| 51 */ | |
| 52 currentRouteChanged: function(route) { | |
| 53 if (settings.getCurrentRoute() != settings.Route.SITE_SETTINGS_DATA_DETAILS) | |
|
Dan Beam
2016/11/01 06:33:27
can we use contains() instead of equality?
dschuyler
2016/11/01 18:55:35
I think that's a possibility, but it would also op
| |
| 54 return; | |
| 55 this.siteTitle_ = settings.getQueryParameters().get('site'); | |
| 56 if (this.siteTitle_ == undefined) | |
|
Dan Beam
2016/11/01 06:33:27
if (!this.siteTitle_)
dschuyler
2016/11/01 18:55:34
Done.
| |
| 57 return; | |
| 58 this.loadCookies().then(this.onCookiesLoaded_.bind(this)); | |
| 59 this.pageTitle = this.siteTitle_; | |
| 60 }, | |
| 61 | |
| 62 /** | |
| 63 * @return {!Array<CookieDataForDisplay>} | |
|
Dan Beam
2016/11/01 06:33:27
nit: !CookieDataForDisplay unless any of the items
dschuyler
2016/11/01 18:55:35
Done.
| |
| 64 * @private | |
| 65 */ | |
| 66 getCookieNodes_: function(cookie) { | |
| 67 var node = this.rootCookieNode.fetchNodeById(cookie.id, true); | |
| 68 if (!node) | |
| 69 return []; | |
| 70 return getCookieData(node.data); | |
| 71 }, | |
| 72 | |
| 73 /** | |
| 74 * settings.RouteObserverBehavior | |
| 75 * @private | |
| 76 */ | |
| 77 onCookiesLoaded_: function() { | |
| 78 var node = this.rootCookieNode.fetchNodeBySite(this.siteTitle_, false); | |
| 79 if (node) { | |
| 80 this.site_ = node; | |
| 81 this.entries_ = this.site_.getCookieList(); | |
| 82 } else { | |
| 83 this.entries_ = []; | |
| 84 } | |
| 85 }, | |
| 86 | |
| 87 /** | |
| 88 * Recursively look up a node path for a leaf node with a given id. | |
| 89 * @param {!settings.CookieTreeNode} node The node to start with. | |
| 90 * @param {string} currentPath The path constructed so far. | |
| 91 * @param {string} targetId The id of the target leaf node to look for. | |
| 92 * @return {string} The path of the node returned (or blank if not found). | |
| 93 * @private | |
| 94 */ | |
| 95 nodePath_: function(node, currentPath, targetId) { | |
| 96 if (node.data.id == targetId) | |
| 97 return currentPath; | |
| 98 | |
| 99 for (var i = 0; i < node.children_.length; ++i) { | |
| 100 var child = node.children_[i]; | |
| 101 var path = this.nodePath_( | |
| 102 child, currentPath + ',' + child.data.id, targetId); | |
| 103 if (path.length > 0) | |
| 104 return path; | |
| 105 } | |
| 106 return ''; | |
| 107 }, | |
| 108 | |
| 109 /** | |
| 110 * A handler for when the user opts to remove a single cookie. | |
| 111 * @param {!Event} item | |
| 112 * @return {string} | |
| 113 * @private | |
| 114 */ | |
| 115 getEntryDescription_: function(item) { | |
| 116 // Frequently there are multiple cookies per site. To avoid showing a list | |
| 117 // of '1 cookie', '1 cookie', ... etc, it is better to show the title of the | |
| 118 // cookie to differentiate them. | |
| 119 if (item.data.type == 'cookie') | |
| 120 return item.title; | |
| 121 return getCookieDataCategoryText(item.data.type, item.data.totalUsage); | |
| 122 }, | |
| 123 | |
| 124 /** | |
| 125 * A handler for when the user opts to remove a single cookie. | |
| 126 * @param {!Event} event | |
| 127 * @private | |
| 128 */ | |
| 129 onRemove_: function(event) { | |
| 130 this.browserProxy.removeCookie(this.nodePath_( | |
| 131 this.site_, this.site_.data.id, event.currentTarget.dataset.id)); | |
| 132 }, | |
| 133 | |
| 134 /** | |
| 135 * A handler for when the user opts to remove all cookies. | |
| 136 * @param {!Event} event | |
| 137 * @private | |
| 138 */ | |
| 139 onRemoveAll_: function(event) { | |
| 140 this.browserProxy.removeCookie(this.site_.data.id); | |
| 141 }, | |
| 142 }); | |
| 143 | |
| 144 })(); | |
| OLD | NEW |