Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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 (function() { | 5 (function() { |
| 6 'use strict'; | 6 'use strict'; |
| 7 | 7 |
| 8 /** | 8 /** |
| 9 * 'site-data-details-subpage' Display cookie contents. | 9 * 'site-data-details-subpage' Display cookie contents. |
| 10 */ | 10 */ |
| 11 Polymer({ | 11 Polymer({ |
| 12 is: 'site-data-details-subpage', | 12 is: 'site-data-details-subpage', |
| 13 | 13 |
| 14 behaviors: [settings.RouteObserverBehavior, CookieTreeBehavior], | 14 behaviors: [settings.RouteObserverBehavior, WebUIListenerBehavior], |
| 15 | 15 |
| 16 properties: { | 16 properties: { |
| 17 /** | 17 /** |
| 18 * The browser proxy used to retrieve and change cookies. | |
| 19 * @type {settings.SiteSettingsPrefsBrowserProxy} | |
| 20 */ | |
| 21 browserProxy: Object, | |
| 22 | |
| 23 /** | |
| 18 * The cookie entries for the given site. | 24 * The cookie entries for the given site. |
| 19 * @type {!Array<!CookieDataItem>} | 25 * @type {!Array<!CookieDataItem>} |
| 20 * @private | 26 * @private |
| 21 */ | 27 */ |
| 22 entries_: Array, | 28 entries_: Array, |
| 23 | 29 |
| 24 /** Set the page title on the settings-subpage parent. */ | 30 /** Set the page title on the settings-subpage parent. */ |
| 25 pageTitle: { | 31 pageTitle: { |
| 26 type: String, | 32 type: String, |
| 27 notify: true, | 33 notify: true, |
| 28 }, | 34 }, |
| 29 | 35 |
| 30 /** | 36 /** @private */ |
| 31 * The site to show details for. | 37 site_: String, |
| 32 * @type {!settings.CookieTreeNode} | 38 |
| 33 * @private | 39 /** @private */ |
| 34 */ | 40 siteId_: String, |
| 35 site_: Object, | |
| 36 }, | 41 }, |
| 37 | 42 |
| 38 listeners: {'cookie-tree-changed': 'onCookiesLoaded_'}, | 43 /** @override */ |
| 44 ready: function() { | |
| 45 this.browserProxy = | |
| 46 settings.SiteSettingsPrefsBrowserProxyImpl.getInstance(); | |
| 47 | |
| 48 this.addWebUIListener('onTreeItemRemoved', | |
| 49 this.getCookieDetails_.bind(this)); | |
| 50 }, | |
| 39 | 51 |
| 40 /** | 52 /** |
| 41 * settings.RouteObserverBehavior | 53 * settings.RouteObserverBehavior |
| 42 * @param {!settings.Route} route | 54 * @param {!settings.Route} route |
| 43 * @protected | 55 * @protected |
| 44 */ | 56 */ |
| 45 currentRouteChanged: function(route) { | 57 currentRouteChanged: function(route) { |
| 46 if (settings.getCurrentRoute() != settings.Route.SITE_SETTINGS_DATA_DETAILS) | 58 if (settings.getCurrentRoute() != settings.Route.SITE_SETTINGS_DATA_DETAILS) |
| 47 return; | 59 return; |
| 48 this.siteTitle_ = settings.getQueryParameters().get('site'); | 60 var site = settings.getQueryParameters().get('site'); |
| 49 if (!this.siteTitle_) | 61 if (site == undefined || site == this.site_) |
|
Dan Beam
2016/11/04 02:03:35
nit: can we use === here for things like comparing
dschuyler
2016/11/04 18:17:42
Done.
dschuyler
2016/11/04 18:48:21
Ah, closure noticed that the change allowed site t
Dan Beam
2016/11/04 18:48:54
great, still lgtm
| |
| 50 return; | 62 return; |
| 51 this.loadCookies().then(this.onCookiesLoaded_.bind(this)); | 63 this.site_ = site; |
| 52 this.pageTitle = loadTimeData.getStringF('siteSettingsCookieSubpage', | 64 this.pageTitle = loadTimeData.getStringF('siteSettingsCookieSubpage', site); |
| 53 this.siteTitle_); | 65 this.getCookieDetails_(); |
| 66 }, | |
| 67 | |
| 68 /** @private */ | |
| 69 getCookieDetails_: function() { | |
| 70 if (!this.site_) | |
| 71 return; | |
| 72 this.browserProxy.getCookieDetails(this.site_).then( | |
| 73 this.onCookiesLoaded_.bind(this), | |
| 74 this.onCookiesLoadFailed_.bind(this)); | |
| 54 }, | 75 }, |
| 55 | 76 |
| 56 /** | 77 /** |
| 57 * @return {!Array<!CookieDataForDisplay>} | 78 * @return {!Array<!CookieDataForDisplay>} |
| 58 * @private | 79 * @private |
| 59 */ | 80 */ |
| 60 getCookieNodes_: function(cookie) { | 81 getCookieNodes_: function(node) { |
| 61 var node = this.rootCookieNode.fetchNodeById(cookie.id, true); | 82 return getCookieData(node); |
| 62 if (!node) | |
| 63 return []; | |
| 64 return getCookieData(node.data); | |
| 65 }, | 83 }, |
| 66 | 84 |
| 67 /** | 85 /** |
| 68 * settings.RouteObserverBehavior | 86 * @param {!CookieDataSummaryItem} cookies |
| 69 * @private | 87 * @private |
| 70 */ | 88 */ |
| 71 onCookiesLoaded_: function() { | 89 onCookiesLoaded_: function(cookies) { |
| 72 var node = this.rootCookieNode.fetchNodeBySite(this.siteTitle_); | 90 this.siteId_ = cookies.id; |
| 73 if (node) { | 91 this.entries_ = cookies.children; |
| 74 this.site_ = node; | 92 // Set up flag for expanding cookie details. |
| 75 this.entries_ = this.site_.getCookieList(); | 93 this.entries_.map(function(e) { return e.expanded_ = false; }); |
| 76 // Set up flag for expanding cookie details. | |
| 77 this.entries_.map(function(e) { return e.expanded_ = false; }); | |
| 78 } else { | |
| 79 this.entries_ = []; | |
| 80 } | |
| 81 }, | 94 }, |
| 82 | 95 |
| 83 /** | 96 /** |
| 84 * Recursively look up a node path for a leaf node with a given id. | 97 * The site was not found. E.g. The site data may have been deleted or the |
| 85 * @param {!settings.CookieTreeNode} node The node to start with. | 98 * site URL parameter may be mistyped. |
| 86 * @param {string} currentPath The path constructed so far. | |
| 87 * @param {string} targetId The id of the target leaf node to look for. | |
| 88 * @return {string} The path of the node returned (or blank if not found). | |
| 89 * @private | 99 * @private |
| 90 */ | 100 */ |
| 91 nodePath_: function(node, currentPath, targetId) { | 101 onCookiesLoadFailed_: function() { |
| 92 if (node.data.id == targetId) | 102 this.siteId_ = ''; |
| 93 return currentPath; | 103 this.entries_ = []; |
| 94 | |
| 95 for (var i = 0; i < node.children_.length; ++i) { | |
| 96 var child = node.children_[i]; | |
| 97 var path = this.nodePath_( | |
| 98 child, currentPath + ',' + child.data.id, targetId); | |
| 99 if (path.length > 0) | |
| 100 return path; | |
| 101 } | |
| 102 return ''; | |
| 103 }, | 104 }, |
| 104 | 105 |
| 105 /** | 106 /** |
| 106 * A handler for when the user opts to remove a single cookie. | 107 * A handler for when the user opts to remove a single cookie. |
| 107 * @param {!Event} item | 108 * @param {!CookieDetails} item |
| 108 * @return {string} | 109 * @return {string} |
| 109 * @private | 110 * @private |
| 110 */ | 111 */ |
| 111 getEntryDescription_: function(item) { | 112 getEntryDescription_: function(item) { |
| 112 // Frequently there are multiple cookies per site. To avoid showing a list | 113 // Frequently there are multiple cookies per site. To avoid showing a list |
| 113 // of '1 cookie', '1 cookie', ... etc, it is better to show the title of the | 114 // of '1 cookie', '1 cookie', ... etc, it is better to show the title of the |
| 114 // cookie to differentiate them. | 115 // cookie to differentiate them. |
| 115 if (item.data.type == 'cookie') | 116 if (item.type == 'cookie') |
| 116 return item.title; | 117 return item.title; |
| 117 return getCookieDataCategoryText(item.data.type, item.data.totalUsage); | 118 return getCookieDataCategoryText(item.type, item.totalUsage); |
| 118 }, | 119 }, |
| 119 | 120 |
| 120 /** | 121 /** |
| 121 * A handler for when the user opts to remove a single cookie. | 122 * A handler for when the user opts to remove a single cookie. |
| 122 * @param {!Event} event | 123 * @param {!Event} event |
| 123 * @private | 124 * @private |
| 124 */ | 125 */ |
| 125 onRemove_: function(event) { | 126 onRemove_: function(event) { |
| 126 this.browserProxy.removeCookie(this.nodePath_( | 127 this.browserProxy.removeCookie( |
| 127 this.site_, this.site_.data.id, event.currentTarget.dataset.id)); | 128 /** @type {!CookieDetails} */(event.currentTarget.dataset).idPath); |
| 128 }, | 129 }, |
| 129 | 130 |
| 130 /** | 131 /** |
| 131 * A handler for when the user opts to remove all cookies. | 132 * A handler for when the user opts to remove all cookies. |
| 132 */ | 133 */ |
| 133 removeAll: function() { | 134 removeAll: function() { |
| 134 this.browserProxy.removeCookie(this.site_.data.id); | 135 this.browserProxy.removeCookie(this.siteId_); |
| 135 }, | 136 }, |
| 136 }); | 137 }); |
| 137 | 138 |
| 138 })(); | 139 })(); |
| OLD | NEW |