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 /** | 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 Loading... | |
| 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 | 100 |
| 94 i18n_: { | 101 i18n_: { |
|
michaelpg
2016/06/09 18:43:42
do you still need this in the JS? if not, remove a
Finnur
2016/06/10 14:20:46
Good catch. Done.
| |
| 95 readOnly: true, | 102 readOnly: true, |
| 96 type: Object, | 103 type: Object, |
| 97 value: function() { | 104 value: function() { |
| 98 return { | 105 return { |
| 99 allowAction: loadTimeData.getString('siteSettingsActionAllow'), | 106 allowAction: loadTimeData.getString('siteSettingsActionAllow'), |
| 100 blockAction: loadTimeData.getString('siteSettingsActionBlock'), | 107 blockAction: loadTimeData.getString('siteSettingsActionBlock'), |
| 101 resetAction: loadTimeData.getString('siteSettingsActionReset'), | 108 resetAction: loadTimeData.getString('siteSettingsActionReset'), |
| 109 sessionOnlyAction: | |
| 110 loadTimeData.getString('siteSettingsActionSessionOnly'), | |
| 102 }; | 111 }; |
| 103 }, | 112 }, |
| 104 }, | 113 }, |
| 105 }, | 114 }, |
| 106 | 115 |
| 107 observers: [ | 116 observers: [ |
| 108 'configureWidget_(category, categorySubtype, categoryEnabled, allSites)' | 117 'configureWidget_(category, categorySubtype, categoryEnabled, allSites)' |
| 109 ], | 118 ], |
| 110 | 119 |
| 111 ready: function() { | 120 ready: function() { |
| 121 this.PermissionValues = settings.PermissionValues; | |
|
michaelpg
2016/06/09 18:43:42
consider making this a readOnly property of SiteSe
Finnur
2016/06/10 14:20:46
Done.
| |
| 112 this.addWebUIListener('contentSettingSitePermissionChanged', | 122 this.addWebUIListener('contentSettingSitePermissionChanged', |
| 113 this.siteWithinCategoryChanged_.bind(this)); | 123 this.siteWithinCategoryChanged_.bind(this)); |
| 114 }, | 124 }, |
| 115 | 125 |
| 116 /** | 126 /** |
| 117 * Called when a site changes permission. | 127 * Called when a site changes permission. |
| 118 * @param {string} category The category of the site that changed. | 128 * @param {string} category The category of the site that changed. |
| 119 * @param {string} site The site that changed. | 129 * @param {string} site The site that changed. |
| 120 * @private | 130 * @private |
| 121 */ | 131 */ |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 139 this.setUpActionMenu_(); | 149 this.setUpActionMenu_(); |
| 140 this.ensureOpened_(); | 150 this.ensureOpened_(); |
| 141 this.populateList_(); | 151 this.populateList_(); |
| 142 }, | 152 }, |
| 143 | 153 |
| 144 /** | 154 /** |
| 145 * Ensures the widget is |opened| when needed when displayed initially. | 155 * Ensures the widget is |opened| when needed when displayed initially. |
| 146 * @private | 156 * @private |
| 147 */ | 157 */ |
| 148 ensureOpened_: function() { | 158 ensureOpened_: function() { |
| 149 // Allowed list is always shown opened by default and All Sites is presented | 159 // Allowed list and Clear on Exit lists are always shown opened by default |
| 150 // all in one list (nothing closed by default). | 160 // and All Sites is presented all in one list (nothing closed by default). |
| 151 if (this.allSites || | 161 if (this.allSites || |
| 152 this.categorySubtype == settings.PermissionValues.ALLOW) { | 162 this.categorySubtype == settings.PermissionValues.ALLOW || |
| 163 this.categorySubtype == settings.PermissionValues.SESSION_ONLY) { | |
| 153 this.$.category.opened = true; | 164 this.$.category.opened = true; |
| 154 return; | 165 return; |
| 155 } | 166 } |
| 156 | 167 |
| 157 // Block list should only be shown opened if there is nothing to show in | 168 // Block list should only be shown opened if there is nothing to show in |
| 158 // the allowed list. | 169 // the other lists. |
| 159 if (this.category != settings.INVALID_CATEGORY_SUBTYPE) { | 170 if (this.category != settings.INVALID_CATEGORY_SUBTYPE) { |
| 160 this.browserProxy_.getExceptionList(this.category).then( | 171 this.browserProxy_.getExceptionList(this.category).then( |
| 161 function(exceptionList) { | 172 function(exceptionList) { |
| 162 var allowExists = exceptionList.some(function(exception) { | 173 var othersExists = exceptionList.some(function(exception) { |
| 163 return exception.setting == settings.PermissionValues.ALLOW; | 174 return exception.setting == settings.PermissionValues.ALLOW || |
| 175 exception.setting == settings.PermissionValues.SESSION_ONLY; | |
| 164 }); | 176 }); |
| 165 if (allowExists) | 177 if (othersExists) |
| 166 return; | 178 return; |
| 167 this.$.category.opened = true; | 179 this.$.category.opened = true; |
| 168 }.bind(this)); | 180 }.bind(this)); |
| 169 } else { | 181 } else { |
| 170 this.$.category.opened = true; | 182 this.$.category.opened = true; |
| 171 } | 183 } |
| 172 }, | 184 }, |
| 173 | 185 |
| 174 /** | 186 /** |
| 175 * Makes sure the visibility is correct for this widget (e.g. hidden if the | 187 * Makes sure the visibility is correct for this widget (e.g. hidden if the |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 246 * add. | 258 * add. |
| 247 * @return {!Array<SiteException>} The list of sites. | 259 * @return {!Array<SiteException>} The list of sites. |
| 248 * @private | 260 * @private |
| 249 */ | 261 */ |
| 250 appendSiteList_: function(sites, exceptionList) { | 262 appendSiteList_: function(sites, exceptionList) { |
| 251 for (var i = 0; i < exceptionList.length; ++i) { | 263 for (var i = 0; i < exceptionList.length; ++i) { |
| 252 if (this.category != settings.ALL_SITES) { | 264 if (this.category != settings.ALL_SITES) { |
| 253 if (exceptionList[i].setting == settings.PermissionValues.DEFAULT) | 265 if (exceptionList[i].setting == settings.PermissionValues.DEFAULT) |
| 254 continue; | 266 continue; |
| 255 | 267 |
| 256 // Filter out 'Block' values if this list is handling 'Allow' items. | 268 if (exceptionList[i].setting != this.categorySubtype) |
| 257 if (exceptionList[i].setting == settings.PermissionValues.BLOCK && | |
| 258 this.categorySubtype != settings.PermissionValues.BLOCK) { | |
| 259 continue; | 269 continue; |
| 260 } | |
| 261 // Filter out 'Allow' values if this list is handling 'Block' items. | |
| 262 if (exceptionList[i].setting == settings.PermissionValues.ALLOW && | |
| 263 this.categorySubtype != settings.PermissionValues.ALLOW) { | |
| 264 continue; | |
| 265 } | |
| 266 } | 270 } |
| 267 | 271 |
| 268 sites.push(exceptionList[i]); | 272 sites.push(exceptionList[i]); |
| 269 } | 273 } |
| 270 return sites; | 274 return sites; |
| 271 }, | 275 }, |
| 272 | 276 |
| 273 /** | 277 /** |
| 274 * Converts a string origin/pattern to a URL. | 278 * Converts a string origin/pattern to a URL. |
| 275 * @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 Loading... | |
| 350 } | 354 } |
| 351 return results; | 355 return results; |
| 352 }, | 356 }, |
| 353 | 357 |
| 354 /** | 358 /** |
| 355 * Setup the values to use for the action menu. | 359 * Setup the values to use for the action menu. |
| 356 * @private | 360 * @private |
| 357 */ | 361 */ |
| 358 setUpActionMenu_: function() { | 362 setUpActionMenu_: function() { |
| 359 this.showAllowAction_ = | 363 this.showAllowAction_ = |
| 360 this.categorySubtype == settings.PermissionValues.BLOCK; | 364 this.categorySubtype != settings.PermissionValues.ALLOW; |
| 361 this.showBlockAction_ = | 365 this.showBlockAction_ = |
| 362 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; | |
| 363 }, | 370 }, |
| 364 | 371 |
| 365 /** | 372 /** |
| 366 * A handler for selecting a site (by clicking on the origin). | 373 * A handler for selecting a site (by clicking on the origin). |
| 367 * @private | 374 * @private |
| 368 */ | 375 */ |
| 369 onOriginTap_: function(event) { | 376 onOriginTap_: function(event) { |
| 370 this.selectedSite = event.model.item; | 377 this.selectedSite = event.model.item; |
| 371 var categorySelected = | 378 var categorySelected = |
| 372 this.allSites ? | 379 this.allSites ? |
| 373 'all-sites' : | 380 'all-sites' : |
| 374 'site-settings-category-' + this.computeCategoryTextId(this.category); | 381 'site-settings-category-' + this.computeCategoryTextId(this.category); |
| 375 this.currentRoute = { | 382 this.currentRoute = { |
| 376 page: this.currentRoute.page, | 383 page: this.currentRoute.page, |
| 377 section: 'privacy', | 384 section: 'privacy', |
| 378 subpage: ['site-settings', categorySelected, 'site-details'], | 385 subpage: ['site-settings', categorySelected, 'site-details'], |
| 379 }; | 386 }; |
| 380 }, | 387 }, |
| 381 | 388 |
| 382 /** | 389 /** |
| 383 * A handler for activating one of the menu action items. | 390 * A handler for activating one of the menu action items. |
| 384 * @param {!{model: !{item: !{origin: string}}, | 391 * @param {!{model: !{item: !{origin: string}}, |
| 385 * detail: !{item: !{textContent: string}}}} event | 392 * detail: !{selected: string}}} event |
| 386 * @private | 393 * @private |
| 387 */ | 394 */ |
| 388 onActionMenuIronActivate_: function(event) { | 395 onActionMenuIronActivate_: function(event) { |
| 389 var origin = event.model.item.origin; | 396 var origin = event.model.item.origin; |
| 390 var embeddingOrigin = event.model.item.embeddingOrigin; | 397 var embeddingOrigin = event.model.item.embeddingOrigin; |
| 391 var action = event.detail.item.textContent; | 398 var action = event.detail.selected; |
| 392 if (action == this.i18n_.resetAction) { | 399 if (action == settings.PermissionValues.DEFAULT) { |
| 393 this.resetCategoryPermissionForOrigin( | 400 this.resetCategoryPermissionForOrigin( |
| 394 origin, embeddingOrigin, this.category); | 401 origin, embeddingOrigin, this.category); |
| 395 } else { | 402 } else { |
| 396 var value = (action == this.i18n_.allowAction) ? | |
| 397 settings.PermissionValues.ALLOW : | |
| 398 settings.PermissionValues.BLOCK; | |
| 399 this.setCategoryPermissionForOrigin( | 403 this.setCategoryPermissionForOrigin( |
| 400 origin, embeddingOrigin, this.category, value); | 404 origin, embeddingOrigin, this.category, action); |
| 401 } | 405 } |
| 402 }, | 406 }, |
| 403 | 407 |
| 404 /** | 408 /** |
| 405 * Returns the appropriate header value for display. | 409 * Returns the appropriate header value for display. |
| 406 * @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 |
| 407 * category subtype. | 411 * category subtype. |
| 408 * @param {boolean} toggleState The state of the global toggle for this | 412 * @param {boolean} toggleState The state of the global toggle for this |
| 409 * category. | 413 * category. |
| 410 * @private | 414 * @private |
| 411 */ | 415 */ |
| 412 computeSiteListHeader_: function(siteList, toggleState) { | 416 computeSiteListHeader_: function(siteList, toggleState) { |
| 413 if (this.categorySubtype == settings.PermissionValues.ALLOW) { | 417 if (this.categorySubtype == settings.PermissionValues.ALLOW) { |
|
michaelpg
2016/06/09 18:43:42
suggested cleanup:
var title = '';
if (this.categ
Finnur
2016/06/10 14:20:46
Done.
| |
| 414 return loadTimeData.getStringF( | 418 return loadTimeData.getStringF( |
| 415 'titleAndCount', | 419 'titleAndCount', |
| 416 loadTimeData.getString( | 420 loadTimeData.getString( |
| 417 toggleState ? 'siteSettingsAllow' : 'siteSettingsExceptions'), | 421 toggleState ? 'siteSettingsAllow' : 'siteSettingsExceptions'), |
| 418 siteList.length); | 422 siteList.length); |
| 419 } else { | 423 } else if (this.categorySubtype == settings.PermissionValues.BLOCK) { |
| 420 return loadTimeData.getStringF( | 424 return loadTimeData.getStringF( |
| 421 'titleAndCount', | 425 'titleAndCount', |
| 422 loadTimeData.getString('siteSettingsBlock'), | 426 loadTimeData.getString('siteSettingsBlock'), |
| 423 siteList.length); | 427 siteList.length); |
| 428 } else if (this.categorySubtype == settings.PermissionValues.SESSION_ONLY) { | |
| 429 return loadTimeData.getStringF( | |
| 430 'titleAndCount', | |
| 431 loadTimeData.getString('siteSettingsSessionOnly'), | |
| 432 siteList.length); | |
| 424 } | 433 } |
| 425 }, | 434 }, |
| 426 | 435 |
| 427 /** | 436 /** |
| 428 * Returns true if this widget is showing the allow list. | 437 * Returns true if this widget is showing the Block list. |
| 429 * @private | 438 * @private |
| 430 */ | 439 */ |
| 431 isAllowList_: function() { | 440 isBlockList_: function() { |
| 432 return this.categorySubtype == settings.PermissionValues.ALLOW; | 441 return this.categorySubtype == settings.PermissionValues.BLOCK; |
| 433 }, | 442 }, |
| 434 | 443 |
| 435 /** | 444 /** |
| 436 * Returns whether to show the site list. | 445 * Returns whether to show the site list. |
| 437 * @param {Array} siteList The list of all sites to display for this category | 446 * @param {Array} siteList The list of all sites to display for this category |
| 438 * subtype. | 447 * subtype. |
| 439 * @param {boolean} toggleState The state of the global toggle for this | 448 * @param {boolean} toggleState The state of the global toggle for this |
| 440 * category. | 449 * category. |
| 441 * @private | 450 * @private |
| 442 */ | 451 */ |
| 443 showSiteList_: function(siteList, toggleState) { | 452 showSiteList_: function(siteList, toggleState) { |
| 444 if (siteList.length == 0) | 453 if (siteList.length == 0) |
| 445 return false; | 454 return false; |
| 446 | 455 |
| 447 // 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 |
| 448 // is redundant to also list all the sites that are blocked. | 457 // is redundant to also list all the sites that are blocked. |
| 449 if (this.isAllowList_()) | 458 if (!this.isBlockList_()) |
| 450 return true; | 459 return true; |
| 451 | 460 |
| 452 return toggleState; | 461 return toggleState; |
| 453 }, | 462 }, |
| 454 }); | 463 }); |
| OLD | NEW |