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

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

Issue 2055823003: Site Settings Desktop: Implement the 'Clear on exit' menu for Cookies. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Ready Created 4 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 * 'settings-site-list' shows a list of Allowed and Blocked sites for a given 7 * 'settings-site-list' shows a list of Allowed and Blocked sites for a given
8 * category. 8 * category.
9 */ 9 */
10 Polymer({ 10 Polymer({
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 * Whether to show the Allow action in the action menu. 72 * Whether to show the Allow action in the action menu.
73 */ 73 */
74 showAllowAction_: Boolean, 74 showAllowAction_: Boolean,
75 75
76 /** 76 /**
77 * Whether to show the Block action in the action menu. 77 * Whether to show the Block action in the action menu.
78 */ 78 */
79 showBlockAction_: Boolean, 79 showBlockAction_: Boolean,
80 80
81 /** 81 /**
82 * Whether to show the 'Clear on exit' action in the action
83 * menu.
84 */
85 showSessionOnlyAction_: Boolean,
86
87 /**
82 * All possible actions in the action menu. 88 * All possible actions in the action menu.
83 */ 89 */
84 actions_: { 90 actions_: {
85 readOnly: true, 91 readOnly: true,
86 type: Object, 92 type: Object,
87 values: { 93 values: {
88 ALLOW: 'Allow', 94 ALLOW: 'Allow',
89 BLOCK: 'Block', 95 BLOCK: 'Block',
90 RESET: 'Reset', 96 RESET: 'Reset',
97 SESSION_ONLY: 'SessionOnly',
91 } 98 }
92 }, 99 },
93
94 i18n_: {
95 readOnly: true,
96 type: Object,
97 value: function() {
98 return {
99 allowAction: loadTimeData.getString('siteSettingsActionAllow'),
100 blockAction: loadTimeData.getString('siteSettingsActionBlock'),
101 resetAction: loadTimeData.getString('siteSettingsActionReset'),
102 };
103 },
104 },
105 }, 100 },
106 101
107 observers: [ 102 observers: [
108 'configureWidget_(category, categorySubtype, categoryEnabled, allSites)' 103 'configureWidget_(category, categorySubtype, categoryEnabled, allSites)'
109 ], 104 ],
110 105
111 ready: function() { 106 ready: function() {
112 this.addWebUIListener('contentSettingSitePermissionChanged', 107 this.addWebUIListener('contentSettingSitePermissionChanged',
113 this.siteWithinCategoryChanged_.bind(this)); 108 this.siteWithinCategoryChanged_.bind(this));
114 }, 109 },
(...skipping 24 matching lines...) Expand all
139 this.setUpActionMenu_(); 134 this.setUpActionMenu_();
140 this.ensureOpened_(); 135 this.ensureOpened_();
141 this.populateList_(); 136 this.populateList_();
142 }, 137 },
143 138
144 /** 139 /**
145 * Ensures the widget is |opened| when needed when displayed initially. 140 * Ensures the widget is |opened| when needed when displayed initially.
146 * @private 141 * @private
147 */ 142 */
148 ensureOpened_: function() { 143 ensureOpened_: function() {
149 // Allowed list is always shown opened by default and All Sites is presented 144 // Allowed list and Clear on Exit lists are always shown opened by default
150 // all in one list (nothing closed by default). 145 // and All Sites is presented all in one list (nothing closed by default).
151 if (this.allSites || 146 if (this.allSites ||
152 this.categorySubtype == settings.PermissionValues.ALLOW) { 147 this.categorySubtype == settings.PermissionValues.ALLOW ||
148 this.categorySubtype == settings.PermissionValues.SESSION_ONLY) {
153 this.$.category.opened = true; 149 this.$.category.opened = true;
154 return; 150 return;
155 } 151 }
156 152
157 // Block list should only be shown opened if there is nothing to show in 153 // Block list should only be shown opened if there is nothing to show in
158 // the allowed list. 154 // the other lists.
159 if (this.category != settings.INVALID_CATEGORY_SUBTYPE) { 155 if (this.category != settings.INVALID_CATEGORY_SUBTYPE) {
160 this.browserProxy_.getExceptionList(this.category).then( 156 this.browserProxy_.getExceptionList(this.category).then(
161 function(exceptionList) { 157 function(exceptionList) {
162 var allowExists = exceptionList.some(function(exception) { 158 var othersExists = exceptionList.some(function(exception) {
163 return exception.setting == settings.PermissionValues.ALLOW; 159 return exception.setting == settings.PermissionValues.ALLOW ||
160 exception.setting == settings.PermissionValues.SESSION_ONLY;
164 }); 161 });
165 if (allowExists) 162 if (othersExists)
166 return; 163 return;
167 this.$.category.opened = true; 164 this.$.category.opened = true;
168 }.bind(this)); 165 }.bind(this));
169 } else { 166 } else {
170 this.$.category.opened = true; 167 this.$.category.opened = true;
171 } 168 }
172 }, 169 },
173 170
174 /** 171 /**
175 * Makes sure the visibility is correct for this widget. 172 * Makes sure the visibility is correct for this widget.
176 * @private 173 * @private
177 */ 174 */
178 updateCategoryVisibility_: function() { 175 updateCategoryVisibility_: function() {
179 this.$.category.hidden = !this.showSiteList_(this.categoryEnabled); 176 this.$.category.hidden =
177 !this.showSiteList_(this.sites, this.categoryEnabled);
180 }, 178 },
181 179
182 /** 180 /**
183 * A handler for the Add Site button. 181 * A handler for the Add Site button.
184 * @private 182 * @private
185 */ 183 */
186 onAddSiteTap_: function() { 184 onAddSiteTap_: function() {
187 var dialog = document.createElement('add-site-dialog'); 185 var dialog = document.createElement('add-site-dialog');
188 dialog.category = this.category; 186 dialog.category = this.category;
189 this.shadowRoot.appendChild(dialog); 187 this.shadowRoot.appendChild(dialog);
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 * add. 258 * add.
261 * @return {!Array<SiteException>} The list of sites. 259 * @return {!Array<SiteException>} The list of sites.
262 * @private 260 * @private
263 */ 261 */
264 appendSiteList_: function(sites, exceptionList) { 262 appendSiteList_: function(sites, exceptionList) {
265 for (var i = 0; i < exceptionList.length; ++i) { 263 for (var i = 0; i < exceptionList.length; ++i) {
266 if (this.category != settings.ALL_SITES) { 264 if (this.category != settings.ALL_SITES) {
267 if (exceptionList[i].setting == settings.PermissionValues.DEFAULT) 265 if (exceptionList[i].setting == settings.PermissionValues.DEFAULT)
268 continue; 266 continue;
269 267
270 // Filter out 'Block' values if this list is handling 'Allow' items. 268 if (exceptionList[i].setting != this.categorySubtype)
271 if (exceptionList[i].setting == settings.PermissionValues.BLOCK &&
272 this.categorySubtype != settings.PermissionValues.BLOCK) {
273 continue; 269 continue;
274 }
275 // Filter out 'Allow' values if this list is handling 'Block' items.
276 if (exceptionList[i].setting == settings.PermissionValues.ALLOW &&
277 this.categorySubtype != settings.PermissionValues.ALLOW) {
278 continue;
279 }
280 } 270 }
281 271
282 sites.push(exceptionList[i]); 272 sites.push(exceptionList[i]);
283 } 273 }
284 return sites; 274 return sites;
285 }, 275 },
286 276
287 /** 277 /**
288 * Converts a string origin/pattern to a URL. 278 * Converts a string origin/pattern to a URL.
289 * @param {string} originOrPattern The origin/pattern to convert to URL. 279 * @param {string} originOrPattern The origin/pattern to convert to URL.
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
364 } 354 }
365 return results; 355 return results;
366 }, 356 },
367 357
368 /** 358 /**
369 * Setup the values to use for the action menu. 359 * Setup the values to use for the action menu.
370 * @private 360 * @private
371 */ 361 */
372 setUpActionMenu_: function() { 362 setUpActionMenu_: function() {
373 this.showAllowAction_ = 363 this.showAllowAction_ =
374 this.categorySubtype == settings.PermissionValues.BLOCK; 364 this.categorySubtype != settings.PermissionValues.ALLOW;
375 this.showBlockAction_ = 365 this.showBlockAction_ =
376 this.categorySubtype == settings.PermissionValues.ALLOW; 366 this.categorySubtype != settings.PermissionValues.BLOCK;
367 this.showSessionOnlyAction_ =
368 this.categorySubtype != settings.PermissionValues.SESSION_ONLY &&
369 this.category == settings.ContentSettingsTypes.COOKIES;
377 }, 370 },
378 371
379 /** 372 /**
380 * A handler for selecting a site (by clicking on the origin). 373 * A handler for selecting a site (by clicking on the origin).
381 * @private 374 * @private
382 */ 375 */
383 onOriginTap_: function(event) { 376 onOriginTap_: function(event) {
384 this.selectedSite = event.model.item; 377 this.selectedSite = event.model.item;
385 var categorySelected = 378 var categorySelected =
386 this.allSites ? 379 this.allSites ?
387 'all-sites' : 380 'all-sites' :
388 'site-settings-category-' + this.computeCategoryTextId(this.category); 381 'site-settings-category-' + this.computeCategoryTextId(this.category);
389 this.currentRoute = { 382 this.currentRoute = {
390 page: this.currentRoute.page, 383 page: this.currentRoute.page,
391 section: 'privacy', 384 section: 'privacy',
392 subpage: ['site-settings', categorySelected, 'site-details'], 385 subpage: ['site-settings', categorySelected, 'site-details'],
393 }; 386 };
394 }, 387 },
395 388
396 /** 389 /**
397 * A handler for activating one of the menu action items. 390 * A handler for activating one of the menu action items.
398 * @param {!{model: !{item: !{origin: string}}, 391 * @param {!{model: !{item: !{origin: string}},
399 * detail: !{item: !{textContent: string}}}} event 392 * detail: !{selected: string}}} event
400 * @private 393 * @private
401 */ 394 */
402 onActionMenuIronActivate_: function(event) { 395 onActionMenuIronActivate_: function(event) {
403 var origin = event.model.item.origin; 396 var origin = event.model.item.origin;
404 var embeddingOrigin = event.model.item.embeddingOrigin; 397 var embeddingOrigin = event.model.item.embeddingOrigin;
405 var action = event.detail.item.textContent; 398 var action = event.detail.selected;
406 if (action == this.i18n_.resetAction) { 399 if (action == settings.PermissionValues.DEFAULT) {
407 this.resetCategoryPermissionForOrigin( 400 this.resetCategoryPermissionForOrigin(
408 origin, embeddingOrigin, this.category); 401 origin, embeddingOrigin, this.category);
409 } else { 402 } else {
410 var value = (action == this.i18n_.allowAction) ?
411 settings.PermissionValues.ALLOW :
412 settings.PermissionValues.BLOCK;
413 this.setCategoryPermissionForOrigin( 403 this.setCategoryPermissionForOrigin(
414 origin, embeddingOrigin, this.category, value); 404 origin, embeddingOrigin, this.category, action);
415 } 405 }
416 }, 406 },
417 407
418 /** 408 /**
419 * Returns the appropriate header value for display. 409 * Returns the appropriate header value for display.
420 * @param {Array<string>} siteList The list of all sites to display for this 410 * @param {Array<string>} siteList The list of all sites to display for this
421 * category subtype. 411 * category subtype.
422 * @param {boolean} toggleState The state of the global toggle for this 412 * @param {boolean} toggleState The state of the global toggle for this
423 * category. 413 * category.
424 * @private 414 * @private
425 */ 415 */
426 computeSiteListHeader_: function(siteList, toggleState) { 416 computeSiteListHeader_: function(siteList, toggleState) {
417 var title = '';
427 if (this.categorySubtype == settings.PermissionValues.ALLOW) { 418 if (this.categorySubtype == settings.PermissionValues.ALLOW) {
428 return loadTimeData.getStringF( 419 title = loadTimeData.getString(
429 'titleAndCount', 420 toggleState ? 'siteSettingsAllow' : 'siteSettingsExceptions');
430 loadTimeData.getString( 421 } else if (this.categorySubtype == settings.PermissionValues.BLOCK) {
431 toggleState ? 'siteSettingsAllow' : 'siteSettingsExceptions'), 422 title = loadTimeData.getString('siteSettingsBlock');
432 siteList.length); 423 } else if (this.categorySubtype == settings.PermissionValues.SESSION_ONLY) {
424 title = loadTimeData.getString('siteSettingsSessionOnly');
433 } else { 425 } else {
434 return loadTimeData.getStringF( 426 return title;
435 'titleAndCount',
436 loadTimeData.getString('siteSettingsBlock'),
437 siteList.length);
438 } 427 }
428 return loadTimeData.getStringF('titleAndCount', title, siteList.length);
439 }, 429 },
440 430
441 /** 431 /**
442 * Returns true if this widget is showing the allow list. 432 * Returns true if this widget is showing the Allow list.
443 * @private 433 * @private
444 */ 434 */
445 isAllowList_: function() { 435 isAllowList_: function() {
446 return this.categorySubtype == settings.PermissionValues.ALLOW; 436 return this.categorySubtype == settings.PermissionValues.ALLOW;
447 }, 437 },
448 438
449 /** 439 /**
440 * Returns true if this widget is showing the Session Only list.
441 * @private
442 */
443 isSessionOnlyList_: function() {
444 return this.categorySubtype == settings.PermissionValues.SESSION_ONLY;
445 },
446
447 /**
450 * Returns whether to show the site list. 448 * Returns whether to show the site list.
449 * @param {Array} siteList The list of all sites to display for this category
450 * subtype.
451 * @param {boolean} toggleState The state of the global toggle for this 451 * @param {boolean} toggleState The state of the global toggle for this
452 * category. 452 * category.
453 * @private 453 * @private
454 */ 454 */
455 showSiteList_: function(toggleState) { 455 showSiteList_: function(siteList, toggleState) {
456 // The Block list is only shown when the category is set to Allow since it 456 // The Block list is only shown when the category is set to Allow since it
457 // is redundant to also list all the sites that are blocked. 457 // is redundant to also list all the sites that are blocked.
458 if (this.isAllowList_()) 458 if (this.isAllowList_())
459 return true; 459 return true;
460 460
461 if (this.isSessionOnlyList_())
462 return siteList.length > 0;
463
461 return toggleState; 464 return toggleState;
462 }, 465 },
463 }); 466 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698