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

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

Issue 2846723002: [MD settings] separate all-sites from site-list (Closed)
Patch Set: Created 3 years, 8 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-list' shows a list of Allowed and Blocked sites for a given 7 * 'site-list' shows a list of Allowed and Blocked sites for a given
8 * category. 8 * category.
9 */ 9 */
10 Polymer({ 10 Polymer({
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 * @type {!Array<SiteException>} 49 * @type {!Array<SiteException>}
50 */ 50 */
51 sites: { 51 sites: {
52 type: Array, 52 type: Array,
53 value: function() { 53 value: function() {
54 return []; 54 return [];
55 }, 55 },
56 }, 56 },
57 57
58 /** 58 /**
59 * Whether this list is for the All Sites category.
60 */
61 allSites: {
62 type: Boolean,
63 value: false,
64 },
65
66 /**
67 * The type of category this widget is displaying data for. Normally 59 * The type of category this widget is displaying data for. Normally
68 * either 'allow' or 'block', representing which sites are allowed or 60 * either 'allow' or 'block', representing which sites are allowed or
69 * blocked respectively. 61 * blocked respectively.
70 */ 62 */
71 categorySubtype: { 63 categorySubtype: {
72 type: String, 64 type: String,
73 value: settings.INVALID_CATEGORY_SUBTYPE, 65 value: settings.INVALID_CATEGORY_SUBTYPE,
74 }, 66 },
75 67
76 /** 68 /**
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 this.onIncognitoStatusChanged_.bind(this)); 115 this.onIncognitoStatusChanged_.bind(this));
124 }, 116 },
125 117
126 /** 118 /**
127 * Called when a site changes permission. 119 * Called when a site changes permission.
128 * @param {string} category The category of the site that changed. 120 * @param {string} category The category of the site that changed.
129 * @param {string} site The site that changed. 121 * @param {string} site The site that changed.
130 * @private 122 * @private
131 */ 123 */
132 siteWithinCategoryChanged_: function(category, site) { 124 siteWithinCategoryChanged_: function(category, site) {
133 if (category == this.category || this.allSites) 125 if (category == this.category)
134 this.configureWidget_(); 126 this.configureWidget_();
135 }, 127 },
136 128
137 /** 129 /**
138 * Called for each site list when incognito is enabled or disabled. Only 130 * Called for each site list when incognito is enabled or disabled. Only
139 * called on change (opening N incognito windows only fires one message). 131 * called on change (opening N incognito windows only fires one message).
140 * Another message is sent when the *last* incognito window closes. 132 * Another message is sent when the *last* incognito window closes.
141 * @private 133 * @private
142 */ 134 */
143 onIncognitoStatusChanged_: function() { 135 onIncognitoStatusChanged_: function() {
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 176
185 /** 177 /**
186 * @param {chrome.settingsPrivate.Enforcement} enforcement The level of 178 * @param {chrome.settingsPrivate.Enforcement} enforcement The level of
187 * enforcement. 179 * enforcement.
188 * @param {boolean} readOnlyList Whether the site exception list is read-only. 180 * @param {boolean} readOnlyList Whether the site exception list is read-only.
189 * @return {boolean} 181 * @return {boolean}
190 * @private 182 * @private
191 */ 183 */
192 isResetButtonHidden_: function(enforcement, readOnlyList) { 184 isResetButtonHidden_: function(enforcement, readOnlyList) {
193 return enforcement == chrome.settingsPrivate.Enforcement.ENFORCED || 185 return enforcement == chrome.settingsPrivate.Enforcement.ENFORCED ||
194 this.allSites || !readOnlyList; 186 !readOnlyList;
195 }, 187 },
196 188
197 /** 189 /**
198 * @param {string} enforcement Whether the exception is controlled. 190 * @param {string} enforcement Whether the exception is controlled.
199 * @param {boolean} readOnlyList Whether the site exception list is read-only. 191 * @param {boolean} readOnlyList Whether the site exception list is read-only.
200 * @return {boolean} 192 * @return {boolean}
201 * @private 193 * @private
202 */ 194 */
203 isActionMenuHidden_: function(enforcement, readOnlyList) { 195 isActionMenuHidden_: function(enforcement, readOnlyList) {
204 return enforcement == chrome.settingsPrivate.Enforcement.ENFORCED || 196 return enforcement == chrome.settingsPrivate.Enforcement.ENFORCED ||
205 this.allSites || readOnlyList; 197 readOnlyList;
206 }, 198 },
207 199
208 /** 200 /**
209 * A handler for the Add Site button. 201 * A handler for the Add Site button.
210 * @param {!Event} e 202 * @param {!Event} e
211 * @private 203 * @private
212 */ 204 */
213 onAddSiteTap_: function(e) { 205 onAddSiteTap_: function(e) {
214 assert(!this.readOnlyList); 206 assert(!this.readOnlyList);
215 e.preventDefault(); 207 e.preventDefault();
216 var dialog = document.createElement('add-site-dialog'); 208 var dialog = document.createElement('add-site-dialog');
217 dialog.category = this.category; 209 dialog.category = this.category;
218 dialog.contentSetting = this.categorySubtype; 210 dialog.contentSetting = this.categorySubtype;
219 this.shadowRoot.appendChild(dialog); 211 this.shadowRoot.appendChild(dialog);
220 212
221 dialog.open(this.categorySubtype); 213 dialog.open(this.categorySubtype);
222 214
223 dialog.addEventListener('close', function() { 215 dialog.addEventListener('close', function() {
224 this.$.addSite.focus(); 216 this.$.addSite.focus();
225 dialog.remove(); 217 dialog.remove();
226 }.bind(this)); 218 }.bind(this));
227 }, 219 },
228 220
229 /** 221 /**
230 * Populate the sites list for display. 222 * Populate the sites list for display.
231 * @private 223 * @private
232 */ 224 */
233 populateList_: function() { 225 populateList_: function() {
234 if (this.allSites) { 226 this.browserProxy_.getExceptionList(this.category)
235 this.getAllSitesList_().then(function(lists) { 227 .then(function(exceptionList) {
236 this.processExceptions_(lists);
237 this.closeActionMenu_();
238 }.bind(this));
239 } else {
240 this.browserProxy_.getExceptionList(this.category).then(
241 function(exceptionList) {
242 this.processExceptions_([exceptionList]); 228 this.processExceptions_([exceptionList]);
243 this.closeActionMenu_(); 229 this.closeActionMenu_();
244 }.bind(this)); 230 }.bind(this));
245 }
246 }, 231 },
247 232
248 /** 233 /**
249 * Process the exception list returned from the native layer. 234 * Process the exception list returned from the native layer.
250 * @param {!Array<!Array<RawSiteException>>} data List of sites (exceptions) 235 * @param {!Array<!Array<RawSiteException>>} data List of sites (exceptions)
251 * to process. 236 * to process.
252 * @private 237 * @private
253 */ 238 */
254 processExceptions_: function(data) { 239 processExceptions_: function(data) {
255 var sites = /** @type {!Array<RawSiteException>} */ ([]); 240 var sites = /** @type {!Array<RawSiteException>} */ ([]);
256 for (var i = 0; i < data.length; ++i) { 241 for (var i = 0; i < data.length; ++i) {
257 var exceptionList = data[i]; 242 var exceptionList = data[i];
258 for (var k = 0; k < exceptionList.length; ++k) { 243 for (var k = 0; k < exceptionList.length; ++k) {
259 if (!this.allSites && 244 if (exceptionList[k].setting == settings.PermissionValues.DEFAULT ||
260 (exceptionList[k].setting == settings.PermissionValues.DEFAULT || 245 exceptionList[k].setting != this.categorySubtype) {
261 exceptionList[k].setting != this.categorySubtype)) {
262 continue; 246 continue;
263 } 247 }
264 248
265 sites.push(exceptionList[k]); 249 sites.push(exceptionList[k]);
266 } 250 }
267 } 251 }
268 this.sites = this.toSiteArray_(sites); 252 this.sites = this.toSiteArray_(sites);
269 }, 253 },
270 254
271 /** 255 /**
272 * Retrieves a list of all known sites (any category/setting).
273 * @return {!Promise}
274 * @private
275 */
276 getAllSitesList_: function() {
277 var promiseList = [];
278 for (var type in settings.ContentSettingsTypes) {
279 if (settings.ContentSettingsTypes[type] ==
280 settings.ContentSettingsTypes.PROTOCOL_HANDLERS ||
281 settings.ContentSettingsTypes[type] ==
282 settings.ContentSettingsTypes.USB_DEVICES ||
283 settings.ContentSettingsTypes[type] ==
284 settings.ContentSettingsTypes.ZOOM_LEVELS) {
285 // Some categories store their data in a custom way.
286 continue;
287 }
288
289 promiseList.push(
290 this.browserProxy_.getExceptionList(
291 settings.ContentSettingsTypes[type]));
292 }
293
294 return Promise.all(promiseList);
295 },
296
297 /**
298 * Converts a list of exceptions received from the C++ handler to 256 * Converts a list of exceptions received from the C++ handler to
299 * full SiteException objects. If this site-list is used as an all sites 257 * full SiteException objects.
300 * view, the list is sorted by site name, then protocol and port and de-duped
301 * (by origin).
302 * @param {!Array<RawSiteException>} sites A list of sites to convert. 258 * @param {!Array<RawSiteException>} sites A list of sites to convert.
303 * @return {!Array<SiteException>} A list of full SiteExceptions. Sorted and 259 * @return {!Array<SiteException>} A list of full SiteExceptions.
304 * deduped if allSites is set.
305 * @private 260 * @private
306 */ 261 */
307 toSiteArray_: function(sites) { 262 toSiteArray_: function(sites) {
308 var self = this;
309 if (this.allSites) {
310 sites.sort(function(a, b) {
311 var url1 = self.toUrl(a.origin);
312 var url2 = self.toUrl(b.origin);
313 var comparison = url1.host.localeCompare(url2.host);
314 if (comparison == 0) {
315 comparison = url1.protocol.localeCompare(url2.protocol);
316 if (comparison == 0) {
317 comparison = url1.port.localeCompare(url2.port);
318 if (comparison == 0) {
319 // Compare hosts for the embedding origins.
320 var host1 = self.toUrl(a.embeddingOrigin);
321 var host2 = self.toUrl(b.embeddingOrigin);
322 host1 = (host1 == null) ? '' : host1.host;
323 host2 = (host2 == null) ? '' : host2.host;
324 return host1.localeCompare(host2);
325 }
326 }
327 }
328 return comparison;
329 });
330 }
331 var results = /** @type {!Array<SiteException>} */([]); 263 var results = /** @type {!Array<SiteException>} */([]);
332 var lastOrigin = ''; 264 var lastOrigin = '';
333 var lastEmbeddingOrigin = ''; 265 var lastEmbeddingOrigin = '';
334 for (var i = 0; i < sites.length; ++i) { 266 for (var i = 0; i < sites.length; ++i) {
335 /** @type {!SiteException} */ 267 /** @type {!SiteException} */
336 var siteException = this.expandSiteException(sites[i]); 268 var siteException = this.expandSiteException(sites[i]);
337 269
338 // The All Sites category can contain duplicates (from other categories).
339 if (this.allSites && siteException.origin == lastOrigin &&
340 siteException.embeddingOrigin == lastEmbeddingOrigin) {
341 continue;
342 }
343
344 results.push(siteException); 270 results.push(siteException);
345 lastOrigin = siteException.origin; 271 lastOrigin = siteException.origin;
346 lastEmbeddingOrigin = siteException.embeddingOrigin; 272 lastEmbeddingOrigin = siteException.embeddingOrigin;
347 } 273 }
348 return results; 274 return results;
349 }, 275 },
350 276
351 /** 277 /**
352 * Set up the values to use for the action menu. 278 * Set up the values to use for the action menu.
353 * @private 279 * @private
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
494 /** @private */ 420 /** @private */
495 closeActionMenu_: function() { 421 closeActionMenu_: function() {
496 this.actionMenuSite_ = null; 422 this.actionMenuSite_ = null;
497 this.activeDialogAnchor_ = null; 423 this.activeDialogAnchor_ = null;
498 var actionMenu = /** @type {!CrActionMenuElement} */ ( 424 var actionMenu = /** @type {!CrActionMenuElement} */ (
499 this.$$('dialog[is=cr-action-menu]')); 425 this.$$('dialog[is=cr-action-menu]'));
500 if (actionMenu.open) 426 if (actionMenu.open)
501 actionMenu.close(); 427 actionMenu.close();
502 }, 428 },
503 }); 429 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698