| 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 * '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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 */ | 70 */ |
| 71 showBlockAction_: Boolean, | 71 showBlockAction_: Boolean, |
| 72 | 72 |
| 73 /** | 73 /** |
| 74 * Whether to show the 'Clear on exit' action in the action | 74 * Whether to show the 'Clear on exit' action in the action |
| 75 * menu. | 75 * menu. |
| 76 */ | 76 */ |
| 77 showSessionOnlyAction_: Boolean, | 77 showSessionOnlyAction_: Boolean, |
| 78 | 78 |
| 79 /** | 79 /** |
| 80 * Keeps track of the incognito status of the current profile (whether one |
| 81 * exists). |
| 82 */ |
| 83 incognitoProfileActive_: { |
| 84 type: Boolean, |
| 85 value: false, |
| 86 }, |
| 87 |
| 88 /** |
| 80 * All possible actions in the action menu. | 89 * All possible actions in the action menu. |
| 81 */ | 90 */ |
| 82 actions_: { | 91 actions_: { |
| 83 readOnly: true, | 92 readOnly: true, |
| 84 type: Object, | 93 type: Object, |
| 85 values: { | 94 values: { |
| 86 ALLOW: 'Allow', | 95 ALLOW: 'Allow', |
| 87 BLOCK: 'Block', | 96 BLOCK: 'Block', |
| 88 RESET: 'Reset', | 97 RESET: 'Reset', |
| 89 SESSION_ONLY: 'SessionOnly', | 98 SESSION_ONLY: 'SessionOnly', |
| 90 } | 99 } |
| 91 }, | 100 }, |
| 92 }, | 101 }, |
| 93 | 102 |
| 94 observers: [ | 103 observers: [ |
| 95 'configureWidget_(category, categorySubtype, categoryEnabled, allSites)' | 104 'configureWidget_(category, categorySubtype, categoryEnabled, allSites)' |
| 96 ], | 105 ], |
| 97 | 106 |
| 98 ready: function() { | 107 ready: function() { |
| 99 this.addWebUIListener('contentSettingSitePermissionChanged', | 108 this.addWebUIListener('contentSettingSitePermissionChanged', |
| 100 this.siteWithinCategoryChanged_.bind(this)); | 109 this.siteWithinCategoryChanged_.bind(this)); |
| 110 this.addWebUIListener('onIncognitoStatusChanged', |
| 111 this.onIncognitoStatusChanged_.bind(this)); |
| 101 }, | 112 }, |
| 102 | 113 |
| 103 /** | 114 /** |
| 104 * Called when a site changes permission. | 115 * Called when a site changes permission. |
| 105 * @param {string} category The category of the site that changed. | 116 * @param {string} category The category of the site that changed. |
| 106 * @param {string} site The site that changed. | 117 * @param {string} site The site that changed. |
| 107 * @private | 118 * @private |
| 108 */ | 119 */ |
| 109 siteWithinCategoryChanged_: function(category, site) { | 120 siteWithinCategoryChanged_: function(category, site) { |
| 110 if (category == this.category) | 121 if (category == this.category) |
| 111 this.configureWidget_(); | 122 this.configureWidget_(); |
| 112 }, | 123 }, |
| 113 | 124 |
| 125 onIncognitoStatusChanged_: function(incognitoEnabled) { |
| 126 // A change notification is not sent for each site that is deleted during |
| 127 // incognito profile destruction. Therefore, we reconfigure the list when |
| 128 // the incognito profile is destroyed, except for SESSION_ONLY, which won't |
| 129 // have any incognito exceptions. |
| 130 if (this.categorySubtype == settings.PermissionValues.SESSION_ONLY) |
| 131 return; |
| 132 |
| 133 if (this.incognitoProfileActive_) |
| 134 this.configureWidget_(); // The incognito profile is being destroyed. |
| 135 |
| 136 this.incognitoProfileActive_ = incognitoEnabled; |
| 137 }, |
| 138 |
| 114 /** | 139 /** |
| 115 * Configures the action menu, visibility of the widget and shows the list. | 140 * Configures the action menu, visibility of the widget and shows the list. |
| 116 * @private | 141 * @private |
| 117 */ | 142 */ |
| 118 configureWidget_: function() { | 143 configureWidget_: function() { |
| 119 // The observer for All Sites fires before the attached/ready event, so | 144 // The observer for All Sites fires before the attached/ready event, so |
| 120 // initialize this here. | 145 // initialize this here. |
| 121 if (this.browserProxy_ === undefined) { | 146 if (this.browserProxy_ === undefined) { |
| 122 this.browserProxy_ = | 147 this.browserProxy_ = |
| 123 settings.SiteSettingsPrefsBrowserProxyImpl.getInstance(); | 148 settings.SiteSettingsPrefsBrowserProxyImpl.getInstance(); |
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 334 var host1 = self.toUrl_(a.embeddingOrigin); | 359 var host1 = self.toUrl_(a.embeddingOrigin); |
| 335 var host2 = self.toUrl_(b.embeddingOrigin); | 360 var host2 = self.toUrl_(b.embeddingOrigin); |
| 336 host1 = (host1 == null) ? '' : host1.host; | 361 host1 = (host1 == null) ? '' : host1.host; |
| 337 host2 = (host2 == null) ? '' : host2.host; | 362 host2 = (host2 == null) ? '' : host2.host; |
| 338 return host1.localeCompare(host2); | 363 return host1.localeCompare(host2); |
| 339 } | 364 } |
| 340 } | 365 } |
| 341 } | 366 } |
| 342 return comparison; | 367 return comparison; |
| 343 }); | 368 }); |
| 344 var results = []; | 369 var results = /** @type {!Array<SiteException>} */ []; |
| 345 var lastOrigin = ''; | 370 var lastOrigin = ''; |
| 346 var lastEmbeddingOrigin = ''; | 371 var lastEmbeddingOrigin = ''; |
| 347 for (var i = 0; i < sites.length; ++i) { | 372 for (var i = 0; i < sites.length; ++i) { |
| 348 var origin = sites[i].origin; | 373 var origin = sites[i].origin; |
| 349 var originForDisplay = this.sanitizePort(origin.replace('[*.]', '')); | 374 var originForDisplay = this.sanitizePort(origin.replace('[*.]', '')); |
| 350 | 375 |
| 351 var embeddingOrigin = sites[i].embeddingOrigin; | 376 var embeddingOrigin = sites[i].embeddingOrigin; |
| 352 var embeddingOriginForDisplay = ''; | 377 var embeddingOriginForDisplay = ''; |
| 353 if (origin != embeddingOrigin) { | 378 if (origin != embeddingOrigin) { |
| 354 embeddingOriginForDisplay = | 379 embeddingOriginForDisplay = |
| 355 this.getEmbedderString(embeddingOrigin, this.category); | 380 this.getEmbedderString(embeddingOrigin, this.category); |
| 356 } | 381 } |
| 357 | 382 |
| 358 // The All Sites category can contain duplicates (from other categories). | 383 // The All Sites category can contain duplicates (from other categories). |
| 359 if (originForDisplay == lastOrigin && | 384 if (originForDisplay == lastOrigin && |
| 360 embeddingOriginForDisplay == lastEmbeddingOrigin) { | 385 embeddingOriginForDisplay == lastEmbeddingOrigin) { |
| 361 continue; | 386 continue; |
| 362 } | 387 } |
| 363 | 388 |
| 364 results.push({ | 389 results.push({ |
| 365 origin: origin, | 390 origin: origin, |
| 366 originForDisplay: originForDisplay, | 391 originForDisplay: originForDisplay, |
| 367 embeddingOrigin: embeddingOrigin, | 392 embeddingOrigin: embeddingOrigin, |
| 368 embeddingOriginForDisplay: embeddingOriginForDisplay, | 393 embeddingOriginForDisplay: embeddingOriginForDisplay, |
| 394 incognito: sites[i].incognito, |
| 369 source: sites[i].source, | 395 source: sites[i].source, |
| 370 }); | 396 }); |
| 371 | 397 |
| 372 lastOrigin = originForDisplay; | 398 lastOrigin = originForDisplay; |
| 373 lastEmbeddingOrigin = embeddingOriginForDisplay; | 399 lastEmbeddingOrigin = embeddingOriginForDisplay; |
| 374 } | 400 } |
| 375 return results; | 401 return results; |
| 376 }, | 402 }, |
| 377 | 403 |
| 378 /** | 404 /** |
| 379 * Setup the values to use for the action menu. | 405 * Setup the values to use for the action menu. |
| 380 * @private | 406 * @private |
| 381 */ | 407 */ |
| 382 setUpActionMenu_: function() { | 408 setUpActionMenu_: function() { |
| 383 this.showAllowAction_ = | 409 this.showAllowAction_ = |
| 384 this.categorySubtype != settings.PermissionValues.ALLOW; | 410 this.categorySubtype != settings.PermissionValues.ALLOW; |
| 385 this.showBlockAction_ = | 411 this.showBlockAction_ = |
| 386 this.categorySubtype != settings.PermissionValues.BLOCK; | 412 this.categorySubtype != settings.PermissionValues.BLOCK; |
| 387 this.showSessionOnlyAction_ = | 413 this.showSessionOnlyAction_ = |
| 388 this.categorySubtype != settings.PermissionValues.SESSION_ONLY && | 414 this.categorySubtype != settings.PermissionValues.SESSION_ONLY && |
| 389 this.category == settings.ContentSettingsTypes.COOKIES; | 415 this.category == settings.ContentSettingsTypes.COOKIES; |
| 390 }, | 416 }, |
| 391 | 417 |
| 392 /** | 418 /** |
| 419 * Whether to show the Session Only menu item for a given site. |
| 420 * @param {SiteException} site The site in question. |
| 421 * @return {boolean} Whether to show the menu item. |
| 422 */ |
| 423 showSessionOnlyActionForSite_: function(site) { |
| 424 // It makes no sense to show "clear on exit" for exceptions that only apply |
| 425 // to incognito. It gives the impression that they might under some |
| 426 // circumstances not be cleared on exit, which isn't true. |
| 427 if (site.incognito) |
| 428 return false; |
| 429 |
| 430 return this.showSessionOnlyAction_; |
| 431 }, |
| 432 |
| 433 /** |
| 393 * A handler for selecting a site (by clicking on the origin). | 434 * A handler for selecting a site (by clicking on the origin). |
| 394 * @private | 435 * @private |
| 395 */ | 436 */ |
| 396 onOriginTap_: function(event) { | 437 onOriginTap_: function(event) { |
| 397 this.selectedSite = event.model.item; | 438 this.selectedSite = event.model.item; |
| 398 if (this.isPolicyControlled_(this.selectedSite.source)) | 439 if (this.isPolicyControlled_(this.selectedSite.source)) |
| 399 return; | 440 return; |
| 400 | 441 |
| 401 settings.navigateTo(settings.Route.SITE_SETTINGS_SITE_DETAILS); | 442 settings.navigateTo(settings.Route.SITE_SETTINGS_SITE_DETAILS); |
| 402 }, | 443 }, |
| 403 | 444 |
| 404 /** | 445 /** |
| 405 * A handler for activating one of the menu action items. | 446 * A handler for activating one of the menu action items. |
| 406 * @param {!{model: !{item: !{origin: string}}, | 447 * @param {!{model: !{item: !{origin: string}}, |
| 407 * detail: !{selected: string}}} event | 448 * detail: !{selected: string}}} event |
| 408 * @private | 449 * @private |
| 409 */ | 450 */ |
| 410 onActionMenuIronActivate_: function(event) { | 451 onActionMenuIronActivate_: function(event) { |
| 411 var origin = event.model.item.origin; | 452 var origin = event.model.item.origin; |
| 453 var incognito = event.model.item.incognito; |
| 412 var embeddingOrigin = event.model.item.embeddingOrigin; | 454 var embeddingOrigin = event.model.item.embeddingOrigin; |
| 413 var action = event.detail.selected; | 455 var action = event.detail.selected; |
| 414 if (action == settings.PermissionValues.DEFAULT) { | 456 if (action == settings.PermissionValues.DEFAULT) { |
| 415 this.resetCategoryPermissionForOrigin( | 457 this.browserProxy.resetCategoryPermissionForOrigin( |
| 416 origin, embeddingOrigin, this.category); | 458 origin, embeddingOrigin, this.category, incognito); |
| 417 } else { | 459 } else { |
| 418 this.setCategoryPermissionForOrigin( | 460 this.browserProxy.setCategoryPermissionForOrigin( |
| 419 origin, embeddingOrigin, this.category, action); | 461 origin, embeddingOrigin, this.category, action, incognito); |
| 420 } | 462 } |
| 421 }, | 463 }, |
| 422 | 464 |
| 423 /** | 465 /** |
| 424 * Returns the appropriate header value for display. | 466 * Returns the appropriate header value for display. |
| 425 * @param {Array<string>} siteList The list of all sites to display for this | 467 * @param {Array<string>} siteList The list of all sites to display for this |
| 426 * category subtype. | 468 * category subtype. |
| 427 * @param {boolean} toggleState The state of the global toggle for this | 469 * @param {boolean} toggleState The state of the global toggle for this |
| 428 * category. | 470 * category. |
| 429 * @private | 471 * @private |
| 430 */ | 472 */ |
| 431 computeSiteListHeader_: function(siteList, toggleState) { | 473 computeSiteListHeader_: function(siteList, toggleState) { |
| 432 var title = ''; | 474 var title = ''; |
| 433 if (this.categorySubtype == settings.PermissionValues.ALLOW) { | 475 if (this.categorySubtype == settings.PermissionValues.ALLOW) { |
| 434 title = loadTimeData.getString( | 476 title = loadTimeData.getString( |
| 435 toggleState ? 'siteSettingsAllow' : 'siteSettingsExceptions'); | 477 toggleState ? 'siteSettingsAllow' : 'siteSettingsExceptions'); |
| 436 } else if (this.categorySubtype == settings.PermissionValues.BLOCK) { | 478 } else if (this.categorySubtype == settings.PermissionValues.BLOCK) { |
| 437 title = loadTimeData.getString('siteSettingsBlock'); | 479 title = loadTimeData.getString('siteSettingsBlock'); |
| 438 } else if (this.categorySubtype == settings.PermissionValues.SESSION_ONLY) { | 480 } else if (this.categorySubtype == settings.PermissionValues.SESSION_ONLY) { |
| 439 title = loadTimeData.getString('siteSettingsSessionOnly'); | 481 title = loadTimeData.getString('siteSettingsSessionOnly'); |
| 440 } else { | 482 } else { |
| 441 return title; | 483 return title; |
| 442 } | 484 } |
| 443 return loadTimeData.getStringF('titleAndCount', title, siteList.length); | 485 return loadTimeData.getStringF('titleAndCount', title, siteList.length); |
| 444 }, | 486 }, |
| 445 | 487 |
| 446 /** | 488 /** |
| 489 * Returns the appropriate site description to display. This can, for example, |
| 490 * be blank, an 'embedded on <site>' or 'Current incognito session' (or a |
| 491 * mix of the last two). |
| 492 * @param {SiteException} item The site exception entry. |
| 493 * @return {string} The site description. |
| 494 */ |
| 495 computeSiteDescription_: function(item) { |
| 496 if (item.incognito && item.embeddingOriginForDisplay.length > 0) { |
| 497 return loadTimeData.getStringF('embeddedIncognitoSite', |
| 498 item.embeddingOriginForDisplay); |
| 499 } |
| 500 |
| 501 if (item.incognito) |
| 502 return loadTimeData.getString('incognitoSite'); |
| 503 return item.embeddingOriginForDisplay; |
| 504 }, |
| 505 |
| 506 /** |
| 447 * Returns true if this widget is showing the Allow list. | 507 * Returns true if this widget is showing the Allow list. |
| 448 * @private | 508 * @private |
| 449 */ | 509 */ |
| 450 isAllowList_: function() { | 510 isAllowList_: function() { |
| 451 return this.categorySubtype == settings.PermissionValues.ALLOW; | 511 return this.categorySubtype == settings.PermissionValues.ALLOW; |
| 452 }, | 512 }, |
| 453 | 513 |
| 454 /** | 514 /** |
| 455 * Returns true if this widget is showing the Session Only list. | 515 * Returns true if this widget is showing the Session Only list. |
| 456 * @private | 516 * @private |
| (...skipping 15 matching lines...) Expand all Loading... |
| 472 // is redundant to also list all the sites that are blocked. | 532 // is redundant to also list all the sites that are blocked. |
| 473 if (this.isAllowList_()) | 533 if (this.isAllowList_()) |
| 474 return true; | 534 return true; |
| 475 | 535 |
| 476 if (this.isSessionOnlyList_()) | 536 if (this.isSessionOnlyList_()) |
| 477 return siteList.length > 0; | 537 return siteList.length > 0; |
| 478 | 538 |
| 479 return toggleState; | 539 return toggleState; |
| 480 }, | 540 }, |
| 481 }); | 541 }); |
| OLD | NEW |