| 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 listeners: {'cookie-tree-changed': 'onCookiesLoaded_'}, |
| 39 |
| 40 /** |
| 41 * settings.RouteObserverBehavior |
| 42 * @param {!settings.Route} route |
| 43 * @protected |
| 44 */ |
| 45 currentRouteChanged: function(route) { |
| 46 if (settings.getCurrentRoute() != settings.Route.SITE_SETTINGS_DATA_DETAILS) |
| 47 return; |
| 48 this.siteTitle_ = settings.getQueryParameters().get('site'); |
| 49 if (!this.siteTitle_) |
| 50 return; |
| 51 this.loadCookies().then(this.onCookiesLoaded_.bind(this)); |
| 52 this.pageTitle = this.siteTitle_; |
| 53 }, |
| 54 |
| 55 /** |
| 56 * @return {!Array<!CookieDataForDisplay>} |
| 57 * @private |
| 58 */ |
| 59 getCookieNodes_: function(cookie) { |
| 60 var node = this.rootCookieNode.fetchNodeById(cookie.id, true); |
| 61 if (!node) |
| 62 return []; |
| 63 return getCookieData(node.data); |
| 64 }, |
| 65 |
| 66 /** |
| 67 * settings.RouteObserverBehavior |
| 68 * @private |
| 69 */ |
| 70 onCookiesLoaded_: function() { |
| 71 var node = this.rootCookieNode.fetchNodeBySite(this.siteTitle_); |
| 72 if (node) { |
| 73 this.site_ = node; |
| 74 this.entries_ = this.site_.getCookieList(); |
| 75 } else { |
| 76 this.entries_ = []; |
| 77 } |
| 78 }, |
| 79 |
| 80 /** |
| 81 * Recursively look up a node path for a leaf node with a given id. |
| 82 * @param {!settings.CookieTreeNode} node The node to start with. |
| 83 * @param {string} currentPath The path constructed so far. |
| 84 * @param {string} targetId The id of the target leaf node to look for. |
| 85 * @return {string} The path of the node returned (or blank if not found). |
| 86 * @private |
| 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 return ''; |
| 100 }, |
| 101 |
| 102 /** |
| 103 * A handler for when the user opts to remove a single cookie. |
| 104 * @param {!Event} item |
| 105 * @return {string} |
| 106 * @private |
| 107 */ |
| 108 getEntryDescription_: function(item) { |
| 109 // Frequently there are multiple cookies per site. To avoid showing a list |
| 110 // of '1 cookie', '1 cookie', ... etc, it is better to show the title of the |
| 111 // cookie to differentiate them. |
| 112 if (item.data.type == 'cookie') |
| 113 return item.title; |
| 114 return getCookieDataCategoryText(item.data.type, item.data.totalUsage); |
| 115 }, |
| 116 |
| 117 /** |
| 118 * A handler for when the user opts to remove a single cookie. |
| 119 * @param {!Event} event |
| 120 * @private |
| 121 */ |
| 122 onRemove_: function(event) { |
| 123 this.browserProxy.removeCookie(this.nodePath_( |
| 124 this.site_, this.site_.data.id, event.currentTarget.dataset.id)); |
| 125 }, |
| 126 |
| 127 /** |
| 128 * A handler for when the user opts to remove all cookies. |
| 129 */ |
| 130 removeAll: function() { |
| 131 this.browserProxy.removeCookie(this.site_.data.id); |
| 132 }, |
| 133 }); |
| 134 |
| 135 })(); |
| OLD | NEW |