Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(382)

Side by Side Diff: chrome/browser/resources/settings/site_settings/site_details.js

Issue 2936003003: MD Settings: Set all content setting values in Site Details Javascript. (Closed)
Patch Set: Review comments. Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 /** 5 /**
6 * @fileoverview 6 * @fileoverview
7 * 'site-details' show the details (permissions and usage) for a given origin 7 * 'site-details' show the details (permissions and usage) for a given origin
8 * under Site Settings. 8 * under Site Settings.
9 */ 9 */
10 Polymer({ 10 Polymer({
11 is: 'site-details', 11 is: 'site-details',
12 12
13 behaviors: [SiteSettingsBehavior, settings.RouteObserverBehavior], 13 behaviors: [SiteSettingsBehavior, settings.RouteObserverBehavior],
14 14
15 properties: { 15 properties: {
16 /** 16 /**
17 * The site that this widget is showing details for. 17 * The origin that this widget is showing details for.
18 * @type {SiteException} 18 * @private
19 */ 19 */
20 site: { 20 origin: {
21 type: Object, 21 type: String,
22 observer: 'onSiteChanged_', 22 observer: 'onOriginChanged_',
23 }, 23 },
24 24
25 /** 25 /**
26 * The amount of data stored for the origin. 26 * The amount of data stored for the origin.
27 * @private 27 * @private
28 */ 28 */
29 storedData_: { 29 storedData_: {
30 type: String, 30 type: String,
31 value: '', 31 value: '',
32 }, 32 },
(...skipping 19 matching lines...) Expand all
52 52
53 /** 53 /**
54 * settings.RouteObserverBehavior 54 * settings.RouteObserverBehavior
55 * @param {!settings.Route} route 55 * @param {!settings.Route} route
56 * @protected 56 * @protected
57 */ 57 */
58 currentRouteChanged: function(route) { 58 currentRouteChanged: function(route) {
59 var site = settings.getQueryParameters().get('site'); 59 var site = settings.getQueryParameters().get('site');
60 if (!site) 60 if (!site)
61 return; 61 return;
62 this.browserProxy.getSiteDetails(site).then(function(siteInfo) { 62 this.origin = site;
63 this.site = this.expandSiteException(siteInfo);
64 }.bind(this));
65 }, 63 },
66 64
67 /** 65 /**
68 * Handler for when the origin changes. 66 * Handler for when the origin changes.
69 * @private 67 * @private
70 */ 68 */
71 onSiteChanged_: function() { 69 onOriginChanged_: function() {
72 // origin may be initially undefined if the user follows a direct 70 this.$.usageApi.fetchUsageTotal(this.toUrl(this.origin).hostname);
73 // link (URL) to this page. 71
74 var origin = this.site.origin; 72 // Retrieve the setting for each category shown.
75 if (origin !== undefined) 73 this.root.querySelectorAll('site-details-permission')
76 this.$.usageApi.fetchUsageTotal(this.toUrl(origin).hostname); 74 .forEach(function(element) {
75 this.browserProxy
76 .getCategoryPermissionForOrigin(element.category, this.origin)
77 .then(function(permissionResult) {
78 element.site = element.expandSiteException(permissionResult);
79 }.bind(element));
80 }.bind(this));
dschuyler 2017/06/26 22:07:05 IIUC, this will make a couple dozen (or so) querie
Patti Lor 2017/06/28 09:12:52 Done! getCategoryPermissionForOrigin -> getOriginP
77 }, 81 },
78 82
79 /** @private */ 83 /** @private */
80 onCloseDialog_: function() { 84 onCloseDialog_: function() {
81 this.$.confirmDeleteDialog.close(); 85 this.$.confirmDeleteDialog.close();
82 }, 86 },
83 87
84 /** 88 /**
85 * Confirms the deletion of storage for a site. 89 * Confirms the deletion of storage for a site.
86 * @param {!Event} e 90 * @param {!Event} e
87 * @private 91 * @private
88 */ 92 */
89 onConfirmClearStorage_: function(e) { 93 onConfirmClearStorage_: function(e) {
90 e.preventDefault(); 94 e.preventDefault();
91 this.confirmationDeleteMsg_ = loadTimeData.getStringF( 95 this.confirmationDeleteMsg_ = loadTimeData.getStringF(
92 'siteSettingsSiteRemoveConfirmation', 96 'siteSettingsSiteRemoveConfirmation', this.toUrl(this.origin).href);
93 this.toUrl(this.site.origin).href);
94 this.$.confirmDeleteDialog.showModal(); 97 this.$.confirmDeleteDialog.showModal();
95 }, 98 },
96 99
97 /** 100 /**
98 * Clears all data stored for the current origin. 101 * Clears all data stored for the current origin.
99 * @private 102 * @private
100 */ 103 */
101 onClearStorage_: function() { 104 onClearStorage_: function() {
102 this.$.usageApi.clearUsage( 105 this.$.usageApi.clearUsage(this.toUrl(this.origin).href, this.storageType_);
103 this.toUrl(this.site.origin).href, this.storageType_);
104 }, 106 },
105 107
106 /** 108 /**
107 * Called when usage has been deleted for an origin. 109 * Called when usage has been deleted for an origin.
108 * @param {!{detail: !{origin: string}}} event 110 * @param {!{detail: !{origin: string}}} event
109 * @private 111 * @private
110 */ 112 */
111 onUsageDeleted_: function(event) { 113 onUsageDeleted_: function(event) {
112 if (event.detail.origin == this.toUrl(this.site.origin).href) { 114 if (event.detail.origin == this.toUrl(this.origin).href) {
113 this.storedData_ = ''; 115 this.storedData_ = '';
114 this.navigateBackIfNoData_(); 116 this.navigateBackIfNoData_();
115 } 117 }
116 }, 118 },
117 119
118 /** 120 /**
119 * Resets all permissions and clears all data stored for the current origin. 121 * Resets all permissions and clears all data stored for the current origin.
120 * @private 122 * @private
121 */ 123 */
122 onClearAndReset_: function() { 124 onClearAndReset_: function() {
123 Array.prototype.forEach.call( 125 this.root.querySelectorAll('site-details-permission')
124 this.root.querySelectorAll('site-details-permission'), 126 .forEach(function(element) {
125 function(element) {
126 element.resetPermission(); 127 element.resetPermission();
127 }); 128 });
dschuyler 2017/06/26 22:07:05 Again (or similarly), WDYT of making a single call
Patti Lor 2017/06/28 09:12:52 Good idea! I had a quick look today, but I'll send
dschuyler 2017/06/28 23:55:52 SG
128 129
129 if (this.storedData_ != '') 130 if (this.storedData_ != '')
130 this.onClearStorage_(); 131 this.onClearStorage_();
131 else 132 else
132 this.navigateBackIfNoData_(); 133 this.navigateBackIfNoData_();
133 }, 134 },
134 135
135 /** 136 /**
136 * Navigate back if the UI is empty (everything been cleared). 137 * Navigate back if the UI is empty (everything been cleared).
137 * @private 138 * @private
138 */ 139 */
139 navigateBackIfNoData_: function() { 140 navigateBackIfNoData_: function() {
140 if (this.storedData_ == '' && !this.permissionShowing_()) 141 if (this.storedData_ == '' && !this.permissionShowing_())
141 settings.navigateToPreviousRoute(); 142 settings.navigateToPreviousRoute();
142 }, 143 },
143 144
144 /** 145 /**
145 * Returns true if one or more permission is showing. 146 * Returns true if one or more permission is showing.
146 * @private 147 * @private
147 */ 148 */
148 permissionShowing_: function() { 149 permissionShowing_: function() {
149 return Array.prototype.some.call( 150 return Array.prototype.some.call(
150 this.root.querySelectorAll('site-details-permission'), 151 this.root.querySelectorAll('site-details-permission'),
151 function(element) { 152 function(element) {
152 return element.offsetHeight > 0; 153 return element.offsetHeight > 0;
153 }); 154 });
154 }, 155 },
155 }); 156 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698