| 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 * Enumeration mapping all possible controlled-by values for exceptions to | 6 * Enumeration mapping all possible controlled-by values for exceptions to |
| 7 * icons. | 7 * icons. |
| 8 * @enum {string} | 8 * @enum {string} |
| 9 */ | 9 */ |
| 10 var iconControlledBy = { | 10 var iconControlledBy = { |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 * @private | 55 * @private |
| 56 */ | 56 */ |
| 57 showEditExceptionDialog_: Boolean, | 57 showEditExceptionDialog_: Boolean, |
| 58 | 58 |
| 59 /** | 59 /** |
| 60 * Array of sites to display in the widget. | 60 * Array of sites to display in the widget. |
| 61 * @type {!Array<SiteException>} | 61 * @type {!Array<SiteException>} |
| 62 */ | 62 */ |
| 63 sites: { | 63 sites: { |
| 64 type: Array, | 64 type: Array, |
| 65 value: function() { return []; }, | 65 value: function() { |
| 66 return []; |
| 67 }, |
| 66 }, | 68 }, |
| 67 | 69 |
| 68 /** | 70 /** |
| 69 * Whether this list is for the All Sites category. | 71 * Whether this list is for the All Sites category. |
| 70 */ | 72 */ |
| 71 allSites: { | 73 allSites: { |
| 72 type: Boolean, | 74 type: Boolean, |
| 73 value: false, | 75 value: false, |
| 74 }, | 76 }, |
| 75 | 77 |
| 76 /** | 78 /** |
| 77 * The type of category this widget is displaying data for. Normally | 79 * The type of category this widget is displaying data for. Normally |
| 78 * either 'allow' or 'block', representing which sites are allowed or | 80 * either 'allow' or 'block', representing which sites are allowed or |
| 79 * blocked respectively. | 81 * blocked respectively. |
| 80 */ | 82 */ |
| 81 categorySubtype: { | 83 categorySubtype: { |
| 82 type: String, | 84 type: String, |
| 83 value: settings.INVALID_CATEGORY_SUBTYPE, | 85 value: settings.INVALID_CATEGORY_SUBTYPE, |
| 84 }, | 86 }, |
| 85 | 87 |
| 86 /** | 88 /** |
| 87 * Whether to show the Allow action in the action menu. | 89 * Whether to show the Allow action in the action menu. |
| 88 * @private | 90 * @private |
| 89 */ | 91 */ |
| 90 showAllowAction_: Boolean, | 92 showAllowAction_: Boolean, |
| (...skipping 30 matching lines...) Expand all Loading... |
| 121 type: Object, | 123 type: Object, |
| 122 values: { | 124 values: { |
| 123 ALLOW: 'Allow', | 125 ALLOW: 'Allow', |
| 124 BLOCK: 'Block', | 126 BLOCK: 'Block', |
| 125 RESET: 'Reset', | 127 RESET: 'Reset', |
| 126 SESSION_ONLY: 'SessionOnly', | 128 SESSION_ONLY: 'SessionOnly', |
| 127 } | 129 } |
| 128 }, | 130 }, |
| 129 }, | 131 }, |
| 130 | 132 |
| 131 observers: [ | 133 observers: ['configureWidget_(category, categorySubtype)'], |
| 132 'configureWidget_(category, categorySubtype)' | |
| 133 ], | |
| 134 | 134 |
| 135 ready: function() { | 135 ready: function() { |
| 136 this.addWebUIListener('contentSettingSitePermissionChanged', | 136 this.addWebUIListener('contentSettingSitePermissionChanged', |
| 137 this.siteWithinCategoryChanged_.bind(this)); | 137 this.siteWithinCategoryChanged_.bind(this)); |
| 138 this.addWebUIListener('onIncognitoStatusChanged', | 138 this.addWebUIListener('onIncognitoStatusChanged', |
| 139 this.onIncognitoStatusChanged_.bind(this)); | 139 this.onIncognitoStatusChanged_.bind(this)); |
| 140 }, | 140 }, |
| 141 | 141 |
| 142 /** | 142 /** |
| 143 * Called when a site changes permission. | 143 * Called when a site changes permission. |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 hasSites_: function() { | 207 hasSites_: function() { |
| 208 return !!this.sites.length; | 208 return !!this.sites.length; |
| 209 }, | 209 }, |
| 210 | 210 |
| 211 /** | 211 /** |
| 212 * @param {string} source Where the setting came from. | 212 * @param {string} source Where the setting came from. |
| 213 * @param {boolean} readOnlyList Whether the site exception list is read-only. | 213 * @param {boolean} readOnlyList Whether the site exception list is read-only. |
| 214 * @return {boolean} | 214 * @return {boolean} |
| 215 * @private | 215 * @private |
| 216 */ | 216 */ |
| 217 isResetButtonHidden_: function(source, readOnlyList) { |
| 218 return this.isExceptionControlled_(source) || this.allSites || |
| 219 !readOnlyList; |
| 220 }, |
| 221 |
| 222 /** |
| 223 * @param {string} source Where the setting came from. |
| 224 * @param {boolean} readOnlyList Whether the site exception list is read-only. |
| 225 * @return {boolean} |
| 226 * @private |
| 227 */ |
| 217 isActionMenuHidden_: function(source, readOnlyList) { | 228 isActionMenuHidden_: function(source, readOnlyList) { |
| 218 return this.isExceptionControlled_(source) || this.allSites || readOnlyList; | 229 return this.isExceptionControlled_(source) || this.allSites || readOnlyList; |
| 219 }, | 230 }, |
| 220 | 231 |
| 221 /** | 232 /** |
| 222 * A handler for the Add Site button. | 233 * A handler for the Add Site button. |
| 223 * @param {!Event} e | 234 * @param {!Event} e |
| 224 * @private | 235 * @private |
| 225 */ | 236 */ |
| 226 onAddSiteTap_: function(e) { | 237 onAddSiteTap_: function(e) { |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 408 * @private | 419 * @private |
| 409 */ | 420 */ |
| 410 onOriginTap_: function(event) { | 421 onOriginTap_: function(event) { |
| 411 if (!this.enableSiteSettings_) | 422 if (!this.enableSiteSettings_) |
| 412 return; | 423 return; |
| 413 settings.navigateTo(settings.Route.SITE_SETTINGS_SITE_DETAILS, | 424 settings.navigateTo(settings.Route.SITE_SETTINGS_SITE_DETAILS, |
| 414 new URLSearchParams('site=' + event.model.item.origin)); | 425 new URLSearchParams('site=' + event.model.item.origin)); |
| 415 }, | 426 }, |
| 416 | 427 |
| 417 /** | 428 /** |
| 418 * A handler for activating one of the menu action items. | 429 * @param {?SiteException} site |
| 419 * @param {string} action The permission to set (Allow, Block, SessionOnly, | |
| 420 * etc). | |
| 421 * @private | 430 * @private |
| 422 */ | 431 */ |
| 423 onActionMenuActivate_: function(action) { | 432 resetPermissionForOrigin_: function(site) { |
| 424 var origin = this.actionMenuSite_.origin; | 433 assert(site); |
| 425 var incognito = this.actionMenuSite_.incognito; | 434 this.browserProxy.resetCategoryPermissionForOrigin( |
| 426 var embeddingOrigin = this.actionMenuSite_.embeddingOrigin; | 435 site.origin, site.embeddingOrigin, this.category, site.incognito); |
| 427 if (action == settings.PermissionValues.DEFAULT) { | 436 }, |
| 428 this.browserProxy.resetCategoryPermissionForOrigin( | 437 |
| 429 origin, embeddingOrigin, this.category, incognito); | 438 /** |
| 430 } else { | 439 * @param {string} permissionValue |
| 431 this.browserProxy.setCategoryPermissionForOrigin( | 440 * @private |
| 432 origin, embeddingOrigin, this.category, action, incognito); | 441 */ |
| 433 } | 442 setPermissionForActionMenuSite_: function(permissionValue) { |
| 443 assert(this.actionMenuSite_); |
| 444 this.browserProxy.setCategoryPermissionForOrigin( |
| 445 this.actionMenuSite_.origin, this.actionMenuSite_.embeddingOrigin, |
| 446 this.category, permissionValue, this.actionMenuSite_.incognito); |
| 434 }, | 447 }, |
| 435 | 448 |
| 436 /** @private */ | 449 /** @private */ |
| 437 onAllowTap_: function() { | 450 onAllowTap_: function() { |
| 438 this.onActionMenuActivate_(settings.PermissionValues.ALLOW); | 451 this.setPermissionForActionMenuSite_(settings.PermissionValues.ALLOW); |
| 439 this.closeActionMenu_(); | 452 this.closeActionMenu_(); |
| 440 }, | 453 }, |
| 441 | 454 |
| 442 /** @private */ | 455 /** @private */ |
| 443 onBlockTap_: function() { | 456 onBlockTap_: function() { |
| 444 this.onActionMenuActivate_(settings.PermissionValues.BLOCK); | 457 this.setPermissionForActionMenuSite_(settings.PermissionValues.BLOCK); |
| 445 this.closeActionMenu_(); | 458 this.closeActionMenu_(); |
| 446 }, | 459 }, |
| 447 | 460 |
| 448 /** @private */ | 461 /** @private */ |
| 449 onSessionOnlyTap_: function() { | 462 onSessionOnlyTap_: function() { |
| 450 this.onActionMenuActivate_(settings.PermissionValues.SESSION_ONLY); | 463 this.setPermissionForActionMenuSite_( |
| 464 settings.PermissionValues.SESSION_ONLY); |
| 451 this.closeActionMenu_(); | 465 this.closeActionMenu_(); |
| 452 }, | 466 }, |
| 453 | 467 |
| 454 /** @private */ | 468 /** @private */ |
| 455 onEditTap_: function() { | 469 onEditTap_: function() { |
| 456 // Close action menu without resetting |this.actionMenuSite_| since it is | 470 // Close action menu without resetting |this.actionMenuSite_| since it is |
| 457 // bound to the dialog. | 471 // bound to the dialog. |
| 458 /** @type {!CrActionMenuElement} */ ( | 472 /** @type {!CrActionMenuElement} */ ( |
| 459 this.$$('dialog[is=cr-action-menu]')).close(); | 473 this.$$('dialog[is=cr-action-menu]')).close(); |
| 460 this.showEditExceptionDialog_ = true; | 474 this.showEditExceptionDialog_ = true; |
| 461 }, | 475 }, |
| 462 | 476 |
| 463 /** @private */ | 477 /** @private */ |
| 464 onEditExceptionDialogClosed_: function() { | 478 onEditExceptionDialogClosed_: function() { |
| 465 this.showEditExceptionDialog_ = false; | 479 this.showEditExceptionDialog_ = false; |
| 466 this.actionMenuSite_ = null; | 480 this.actionMenuSite_ = null; |
| 467 }, | 481 }, |
| 468 | 482 |
| 469 /** @private */ | 483 /** @private */ |
| 470 onResetTap_: function() { | 484 onResetTap_: function() { |
| 471 this.onActionMenuActivate_(settings.PermissionValues.DEFAULT); | 485 this.resetPermissionForOrigin_(this.actionMenuSite_); |
| 472 this.closeActionMenu_(); | 486 this.closeActionMenu_(); |
| 473 }, | 487 }, |
| 474 | 488 |
| 475 /** | 489 /** |
| 476 * Returns the appropriate site description to display. This can, for example, | 490 * Returns the appropriate site description to display. This can, for example, |
| 477 * be blank, an 'embedded on <site>' or 'Current incognito session' (or a | 491 * be blank, an 'embedded on <site>' or 'Current incognito session' (or a |
| 478 * mix of the last two). | 492 * mix of the last two). |
| 479 * @param {SiteException} item The site exception entry. | 493 * @param {SiteException} item The site exception entry. |
| 480 * @return {string} The site description. | 494 * @return {string} The site description. |
| 481 */ | 495 */ |
| 482 computeSiteDescription_: function(item) { | 496 computeSiteDescription_: function(item) { |
| 483 if (item.incognito && item.embeddingDisplayName.length > 0) { | 497 if (item.incognito && item.embeddingDisplayName.length > 0) { |
| 484 return loadTimeData.getStringF('embeddedIncognitoSite', | 498 return loadTimeData.getStringF('embeddedIncognitoSite', |
| 485 item.embeddingDisplayName); | 499 item.embeddingDisplayName); |
| 486 } | 500 } |
| 487 | 501 |
| 488 if (item.incognito) | 502 if (item.incognito) |
| 489 return loadTimeData.getString('incognitoSite'); | 503 return loadTimeData.getString('incognitoSite'); |
| 490 return item.embeddingDisplayName; | 504 return item.embeddingDisplayName; |
| 491 }, | 505 }, |
| 492 | 506 |
| 493 /** | 507 /** |
| 494 * @param {!{model: !{item: !SiteException}}} e | 508 * @param {!{model: !{item: !SiteException}}} e |
| 495 * @private | 509 * @private |
| 496 */ | 510 */ |
| 511 onResetButtonTap_: function(e) { |
| 512 this.resetPermissionForOrigin_(e.model.item); |
| 513 }, |
| 514 |
| 515 /** |
| 516 * @param {!{model: !{item: !SiteException}}} e |
| 517 * @private |
| 518 */ |
| 497 onShowActionMenuTap_: function(e) { | 519 onShowActionMenuTap_: function(e) { |
| 498 this.actionMenuSite_ = e.model.item; | 520 this.actionMenuSite_ = e.model.item; |
| 499 /** @type {!CrActionMenuElement} */ ( | 521 /** @type {!CrActionMenuElement} */ ( |
| 500 this.$$('dialog[is=cr-action-menu]')).showAt( | 522 this.$$('dialog[is=cr-action-menu]')).showAt( |
| 501 /** @type {!Element} */ ( | 523 /** @type {!Element} */ ( |
| 502 Polymer.dom(/** @type {!Event} */ (e)).localTarget)); | 524 Polymer.dom(/** @type {!Event} */ (e)).localTarget)); |
| 503 }, | 525 }, |
| 504 | 526 |
| 505 /** @private */ | 527 /** @private */ |
| 506 closeActionMenu_: function() { | 528 closeActionMenu_: function() { |
| 507 this.actionMenuSite_ = null; | 529 this.actionMenuSite_ = null; |
| 508 var actionMenu = /** @type {!CrActionMenuElement} */ ( | 530 var actionMenu = /** @type {!CrActionMenuElement} */ ( |
| 509 this.$$('dialog[is=cr-action-menu]')); | 531 this.$$('dialog[is=cr-action-menu]')); |
| 510 if (actionMenu.open) | 532 if (actionMenu.open) |
| 511 actionMenu.close(); | 533 actionMenu.close(); |
| 512 }, | 534 }, |
| 513 }); | 535 }); |
| OLD | NEW |