| 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 26 matching lines...) Expand all Loading... |
| 37 /** | 37 /** |
| 38 * The site that was selected by the user in the dropdown list. | 38 * The site that was selected by the user in the dropdown list. |
| 39 * @type {SiteException} | 39 * @type {SiteException} |
| 40 */ | 40 */ |
| 41 selectedSite: { | 41 selectedSite: { |
| 42 type: Object, | 42 type: Object, |
| 43 notify: true, | 43 notify: true, |
| 44 }, | 44 }, |
| 45 | 45 |
| 46 /** | 46 /** |
| 47 * The site serving as the model for the currenly open action menu. | 47 * The site serving as the model for the currently open action menu. |
| 48 * @private {?SiteException} | 48 * @private {?SiteException} |
| 49 */ | 49 */ |
| 50 actionMenuSite_: Object, | 50 actionMenuSite_: Object, |
| 51 | 51 |
| 52 /** | 52 /** |
| 53 * Array of sites to display in the widget. | 53 * Array of sites to display in the widget. |
| 54 * @type {!Array<SiteException>} | 54 * @type {!Array<SiteException>} |
| 55 */ | 55 */ |
| 56 sites: { | 56 sites: { |
| 57 type: Array, | 57 type: Array, |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 values: { | 120 values: { |
| 121 ALLOW: 'Allow', | 121 ALLOW: 'Allow', |
| 122 BLOCK: 'Block', | 122 BLOCK: 'Block', |
| 123 RESET: 'Reset', | 123 RESET: 'Reset', |
| 124 SESSION_ONLY: 'SessionOnly', | 124 SESSION_ONLY: 'SessionOnly', |
| 125 } | 125 } |
| 126 }, | 126 }, |
| 127 }, | 127 }, |
| 128 | 128 |
| 129 observers: [ | 129 observers: [ |
| 130 'configureWidget_(category, categorySubtype, categoryEnabled, allSites)' | 130 'configureWidget_(category, categorySubtype)' |
| 131 ], | 131 ], |
| 132 | 132 |
| 133 ready: function() { | 133 ready: function() { |
| 134 this.addWebUIListener('contentSettingSitePermissionChanged', | 134 this.addWebUIListener('contentSettingSitePermissionChanged', |
| 135 this.siteWithinCategoryChanged_.bind(this)); | 135 this.siteWithinCategoryChanged_.bind(this)); |
| 136 this.addWebUIListener('onIncognitoStatusChanged', | 136 this.addWebUIListener('onIncognitoStatusChanged', |
| 137 this.onIncognitoStatusChanged_.bind(this)); | 137 this.onIncognitoStatusChanged_.bind(this)); |
| 138 }, | 138 }, |
| 139 | 139 |
| 140 /** | 140 /** |
| (...skipping 28 matching lines...) Expand all Loading... |
| 169 configureWidget_: function() { | 169 configureWidget_: function() { |
| 170 // The observer for All Sites fires before the attached/ready event, so | 170 // The observer for All Sites fires before the attached/ready event, so |
| 171 // initialize this here. | 171 // initialize this here. |
| 172 if (this.browserProxy_ === undefined) { | 172 if (this.browserProxy_ === undefined) { |
| 173 this.browserProxy_ = | 173 this.browserProxy_ = |
| 174 settings.SiteSettingsPrefsBrowserProxyImpl.getInstance(); | 174 settings.SiteSettingsPrefsBrowserProxyImpl.getInstance(); |
| 175 } | 175 } |
| 176 | 176 |
| 177 this.setUpActionMenu_(); | 177 this.setUpActionMenu_(); |
| 178 this.populateList_(); | 178 this.populateList_(); |
| 179 |
| 180 // The Session permissions are only for cookies. |
| 181 if (this.categorySubtype == settings.PermissionValues.SESSION_ONLY) { |
| 182 this.$.category.hidden = |
| 183 this.category != settings.ContentSettingsTypes.COOKIES; |
| 184 } |
| 179 }, | 185 }, |
| 180 | 186 |
| 181 /** | 187 /** |
| 182 * Returns which icon, if any, should represent the fact that this exception | 188 * Returns which icon, if any, should represent the fact that this exception |
| 183 * is controlled. | 189 * is controlled. |
| 184 * @param {!SiteException} item The item from the list we're computing the | 190 * @param {!SiteException} item The item from the list we're computing the |
| 185 * icon for. | 191 * icon for. |
| 186 * @return {string} The icon to show (or blank, if none). | 192 * @return {string} The icon to show (or blank, if none). |
| 187 */ | 193 */ |
| 188 computeIconControlledBy_: function(item) { | 194 computeIconControlledBy_: function(item) { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 203 /** | 209 /** |
| 204 * @param {string} source Where the setting came from. | 210 * @param {string} source Where the setting came from. |
| 205 * @return {boolean} | 211 * @return {boolean} |
| 206 * @private | 212 * @private |
| 207 */ | 213 */ |
| 208 shouldShowMenu_: function(source) { | 214 shouldShowMenu_: function(source) { |
| 209 return !(this.isExceptionControlled_(source) || this.allSites); | 215 return !(this.isExceptionControlled_(source) || this.allSites); |
| 210 }, | 216 }, |
| 211 | 217 |
| 212 /** | 218 /** |
| 213 * Makes sure the visibility is correct for this widget. | |
| 214 * @private | |
| 215 */ | |
| 216 updateCategoryVisibility_: function() { | |
| 217 this.$.category.hidden = | |
| 218 !this.showSiteList_(this.sites, this.categoryEnabled); | |
| 219 }, | |
| 220 | |
| 221 /** | |
| 222 * A handler for the Add Site button. | 219 * A handler for the Add Site button. |
| 223 * @private | 220 * @private |
| 224 */ | 221 */ |
| 225 onAddSiteTap_: function() { | 222 onAddSiteTap_: function() { |
| 226 var dialog = document.createElement('add-site-dialog'); | 223 var dialog = document.createElement('add-site-dialog'); |
| 227 dialog.category = this.category; | 224 dialog.category = this.category; |
| 225 dialog.contentSetting = this.categorySubtype; |
| 228 this.shadowRoot.appendChild(dialog); | 226 this.shadowRoot.appendChild(dialog); |
| 229 | 227 |
| 230 dialog.open(this.categorySubtype); | 228 dialog.open(this.categorySubtype); |
| 231 | 229 |
| 232 dialog.addEventListener('close', function() { | 230 dialog.addEventListener('close', function() { |
| 233 dialog.remove(); | 231 dialog.remove(); |
| 234 }); | 232 }); |
| 235 }, | 233 }, |
| 236 | 234 |
| 237 /** | 235 /** |
| (...skipping 17 matching lines...) Expand all Loading... |
| 255 * Process the exception list returned from the native layer. | 253 * Process the exception list returned from the native layer. |
| 256 * @param {!Array<!Array<SiteException>>} data List of sites (exceptions) to | 254 * @param {!Array<!Array<SiteException>>} data List of sites (exceptions) to |
| 257 * process. | 255 * process. |
| 258 * @private | 256 * @private |
| 259 */ | 257 */ |
| 260 processExceptions_: function(data) { | 258 processExceptions_: function(data) { |
| 261 var sites = []; | 259 var sites = []; |
| 262 for (var i = 0; i < data.length; ++i) | 260 for (var i = 0; i < data.length; ++i) |
| 263 sites = this.appendSiteList_(sites, data[i]); | 261 sites = this.appendSiteList_(sites, data[i]); |
| 264 this.sites = this.toSiteArray_(sites); | 262 this.sites = this.toSiteArray_(sites); |
| 265 this.updateCategoryVisibility_(); | |
| 266 }, | 263 }, |
| 267 | 264 |
| 268 /** | 265 /** |
| 269 * Retrieves a list of all known sites (any category/setting). | 266 * Retrieves a list of all known sites (any category/setting). |
| 270 * @return {!Promise} | 267 * @return {!Promise} |
| 271 * @private | 268 * @private |
| 272 */ | 269 */ |
| 273 getAllSitesList_: function() { | 270 getAllSitesList_: function() { |
| 274 var promiseList = []; | 271 var promiseList = []; |
| 275 for (var type in settings.ContentSettingsTypes) { | 272 for (var type in settings.ContentSettingsTypes) { |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 357 } | 354 } |
| 358 | 355 |
| 359 results.push(siteException); | 356 results.push(siteException); |
| 360 lastOrigin = siteException.originForDisplay; | 357 lastOrigin = siteException.originForDisplay; |
| 361 lastEmbeddingOrigin = siteException.embeddingOriginForDisplay; | 358 lastEmbeddingOrigin = siteException.embeddingOriginForDisplay; |
| 362 } | 359 } |
| 363 return results; | 360 return results; |
| 364 }, | 361 }, |
| 365 | 362 |
| 366 /** | 363 /** |
| 367 * Setup the values to use for the action menu. | 364 * Set up the values to use for the action menu. |
| 368 * @private | 365 * @private |
| 369 */ | 366 */ |
| 370 setUpActionMenu_: function() { | 367 setUpActionMenu_: function() { |
| 371 this.showAllowAction_ = | 368 this.showAllowAction_ = |
| 372 this.categorySubtype != settings.PermissionValues.ALLOW; | 369 this.categorySubtype != settings.PermissionValues.ALLOW; |
| 373 this.showBlockAction_ = | 370 this.showBlockAction_ = |
| 374 this.categorySubtype != settings.PermissionValues.BLOCK; | 371 this.categorySubtype != settings.PermissionValues.BLOCK; |
| 375 this.showSessionOnlyAction_ = | 372 this.showSessionOnlyAction_ = |
| 376 this.categorySubtype != settings.PermissionValues.SESSION_ONLY && | 373 this.categorySubtype != settings.PermissionValues.SESSION_ONLY && |
| 377 this.category == settings.ContentSettingsTypes.COOKIES; | 374 this.category == settings.ContentSettingsTypes.COOKIES; |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 460 return loadTimeData.getStringF('embeddedIncognitoSite', | 457 return loadTimeData.getStringF('embeddedIncognitoSite', |
| 461 item.embeddingOriginForDisplay); | 458 item.embeddingOriginForDisplay); |
| 462 } | 459 } |
| 463 | 460 |
| 464 if (item.incognito) | 461 if (item.incognito) |
| 465 return loadTimeData.getString('incognitoSite'); | 462 return loadTimeData.getString('incognitoSite'); |
| 466 return item.embeddingOriginForDisplay; | 463 return item.embeddingOriginForDisplay; |
| 467 }, | 464 }, |
| 468 | 465 |
| 469 /** | 466 /** |
| 470 * Returns true if this widget is showing the Allow list. | |
| 471 * @private | |
| 472 */ | |
| 473 isAllowList_: function() { | |
| 474 return this.categorySubtype == settings.PermissionValues.ALLOW; | |
| 475 }, | |
| 476 | |
| 477 /** | |
| 478 * Returns true if this widget is showing the Session Only list. | |
| 479 * @private | |
| 480 */ | |
| 481 isSessionOnlyList_: function() { | |
| 482 return this.categorySubtype == settings.PermissionValues.SESSION_ONLY; | |
| 483 }, | |
| 484 | |
| 485 /** | |
| 486 * Returns whether to show the site list. | |
| 487 * @param {Array} siteList The list of all sites to display for this category | |
| 488 * subtype. | |
| 489 * @param {boolean} toggleState The state of the global toggle for this | |
| 490 * category. | |
| 491 * @private | |
| 492 */ | |
| 493 showSiteList_: function(siteList, toggleState) { | |
| 494 // The Block list is only shown when the category is set to Allow since it | |
| 495 // is redundant to also list all the sites that are blocked. | |
| 496 if (this.isAllowList_()) | |
| 497 return true; | |
| 498 | |
| 499 if (this.isSessionOnlyList_()) | |
| 500 return siteList.length > 0; | |
| 501 | |
| 502 return toggleState; | |
| 503 }, | |
| 504 | |
| 505 /** | |
| 506 * @param {!{model: !{item: !SiteException}}} e | 467 * @param {!{model: !{item: !SiteException}}} e |
| 507 * @private | 468 * @private |
| 508 */ | 469 */ |
| 509 onShowActionMenuTap_: function(e) { | 470 onShowActionMenuTap_: function(e) { |
| 510 this.actionMenuSite_ = e.model.item; | 471 this.actionMenuSite_ = e.model.item; |
| 511 /** @type {!CrActionMenuElement} */ ( | 472 /** @type {!CrActionMenuElement} */ ( |
| 512 this.$$('dialog[is=cr-action-menu]')).showAt( | 473 this.$$('dialog[is=cr-action-menu]')).showAt( |
| 513 /** @type {!Element} */ ( | 474 /** @type {!Element} */ ( |
| 514 Polymer.dom(/** @type {!Event} */ (e)).localTarget)); | 475 Polymer.dom(/** @type {!Event} */ (e)).localTarget)); |
| 515 }, | 476 }, |
| 516 | 477 |
| 517 /** @private */ | 478 /** @private */ |
| 518 closeActionMenu_: function() { | 479 closeActionMenu_: function() { |
| 519 this.actionMenuSite_ = null; | 480 this.actionMenuSite_ = null; |
| 520 /** @type {!CrActionMenuElement} */ ( | 481 /** @type {!CrActionMenuElement} */ ( |
| 521 this.$$('dialog[is=cr-action-menu]')).close(); | 482 this.$$('dialog[is=cr-action-menu]')).close(); |
| 522 }, | 483 }, |
| 523 }); | 484 }); |
| OLD | NEW |