| 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 = { |
| 11 'extension': 'cr:extension', | 11 'extension': 'cr:extension', |
| 12 'HostedApp': 'cr:extension', | 12 'HostedApp': 'cr:extension', |
| 13 'platform_app': 'cr:extension', | 13 'platform_app': 'cr:extension', |
| 14 'policy' : 'cr:domain', | 14 'policy': 'cr:domain', |
| 15 }; | 15 }; |
| 16 | 16 |
| 17 /** | 17 /** |
| 18 * @fileoverview | 18 * @fileoverview |
| 19 * 'site-list' shows a list of Allowed and Blocked sites for a given | 19 * 'site-list' shows a list of Allowed and Blocked sites for a given |
| 20 * category. | 20 * category. |
| 21 */ | 21 */ |
| 22 Polymer({ | 22 Polymer({ |
| 23 | 23 |
| 24 is: 'site-list', | 24 is: 'site-list', |
| (...skipping 14 matching lines...) Expand all Loading... |
| 39 * @private {?SiteException} | 39 * @private {?SiteException} |
| 40 */ | 40 */ |
| 41 actionMenuSite_: Object, | 41 actionMenuSite_: Object, |
| 42 | 42 |
| 43 /** | 43 /** |
| 44 * Array of sites to display in the widget. | 44 * Array of sites to display in the widget. |
| 45 * @type {!Array<SiteException>} | 45 * @type {!Array<SiteException>} |
| 46 */ | 46 */ |
| 47 sites: { | 47 sites: { |
| 48 type: Array, | 48 type: Array, |
| 49 value: function() { return []; }, | 49 value: function() { |
| 50 return []; |
| 51 }, |
| 50 }, | 52 }, |
| 51 | 53 |
| 52 /** | 54 /** |
| 53 * Whether this list is for the All Sites category. | 55 * Whether this list is for the All Sites category. |
| 54 */ | 56 */ |
| 55 allSites: { | 57 allSites: { |
| 56 type: Boolean, | 58 type: Boolean, |
| 57 value: false, | 59 value: false, |
| 58 }, | 60 }, |
| 59 | 61 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 type: Object, | 102 type: Object, |
| 101 values: { | 103 values: { |
| 102 ALLOW: 'Allow', | 104 ALLOW: 'Allow', |
| 103 BLOCK: 'Block', | 105 BLOCK: 'Block', |
| 104 RESET: 'Reset', | 106 RESET: 'Reset', |
| 105 SESSION_ONLY: 'SessionOnly', | 107 SESSION_ONLY: 'SessionOnly', |
| 106 } | 108 } |
| 107 }, | 109 }, |
| 108 }, | 110 }, |
| 109 | 111 |
| 110 observers: [ | 112 observers: ['configureWidget_(category, categorySubtype)'], |
| 111 'configureWidget_(category, categorySubtype)' | |
| 112 ], | |
| 113 | 113 |
| 114 ready: function() { | 114 ready: function() { |
| 115 this.addWebUIListener('contentSettingSitePermissionChanged', | 115 this.addWebUIListener( |
| 116 'contentSettingSitePermissionChanged', |
| 116 this.siteWithinCategoryChanged_.bind(this)); | 117 this.siteWithinCategoryChanged_.bind(this)); |
| 117 this.addWebUIListener('onIncognitoStatusChanged', | 118 this.addWebUIListener( |
| 118 this.onIncognitoStatusChanged_.bind(this)); | 119 'onIncognitoStatusChanged', this.onIncognitoStatusChanged_.bind(this)); |
| 119 }, | 120 }, |
| 120 | 121 |
| 121 /** | 122 /** |
| 122 * Called when a site changes permission. | 123 * Called when a site changes permission. |
| 123 * @param {string} category The category of the site that changed. | 124 * @param {string} category The category of the site that changed. |
| 124 * @param {string} site The site that changed. | 125 * @param {string} site The site that changed. |
| 125 * @private | 126 * @private |
| 126 */ | 127 */ |
| 127 siteWithinCategoryChanged_: function(category, site) { | 128 siteWithinCategoryChanged_: function(category, site) { |
| 128 if (category == this.category || this.allSites) | 129 if (category == this.category || this.allSites) |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 /** | 219 /** |
| 219 * Populate the sites list for display. | 220 * Populate the sites list for display. |
| 220 * @private | 221 * @private |
| 221 */ | 222 */ |
| 222 populateList_: function() { | 223 populateList_: function() { |
| 223 if (this.allSites) { | 224 if (this.allSites) { |
| 224 this.getAllSitesList_().then(function(lists) { | 225 this.getAllSitesList_().then(function(lists) { |
| 225 this.processExceptions_(lists); | 226 this.processExceptions_(lists); |
| 226 }.bind(this)); | 227 }.bind(this)); |
| 227 } else { | 228 } else { |
| 228 this.browserProxy_.getExceptionList(this.category).then( | 229 this.browserProxy_.getExceptionList(this.category) |
| 229 function(exceptionList) { | 230 .then(function(exceptionList) { |
| 230 this.processExceptions_([exceptionList]); | 231 this.processExceptions_([exceptionList]); |
| 231 }.bind(this)); | 232 }.bind(this)); |
| 232 } | 233 } |
| 233 }, | 234 }, |
| 234 | 235 |
| 235 /** | 236 /** |
| 236 * Process the exception list returned from the native layer. | 237 * Process the exception list returned from the native layer. |
| 237 * @param {!Array<!Array<SiteException>>} data List of sites (exceptions) to | 238 * @param {!Array<!Array<SiteException>>} data List of sites (exceptions) to |
| 238 * process. | 239 * process. |
| 239 * @private | 240 * @private |
| 240 */ | 241 */ |
| 241 processExceptions_: function(data) { | 242 processExceptions_: function(data) { |
| 242 var sites = []; | 243 var sites = []; |
| 243 for (var i = 0; i < data.length; ++i) | 244 for (var i = 0; i < data.length; ++i) |
| 244 sites = this.appendSiteList_(sites, data[i]); | 245 sites = this.appendSiteList_(sites, data[i]); |
| 245 this.sites = this.toSiteArray_(sites); | 246 this.sites = this.toSiteArray_(sites); |
| 246 }, | 247 }, |
| 247 | 248 |
| 248 /** | 249 /** |
| 249 * Retrieves a list of all known sites (any category/setting). | 250 * Retrieves a list of all known sites (any category/setting). |
| 250 * @return {!Promise} | 251 * @return {!Promise} |
| 251 * @private | 252 * @private |
| 252 */ | 253 */ |
| 253 getAllSitesList_: function() { | 254 getAllSitesList_: function() { |
| 254 var promiseList = []; | 255 var promiseList = []; |
| 255 for (var type in settings.ContentSettingsTypes) { | 256 for (var type in settings.ContentSettingsTypes) { |
| 256 if (settings.ContentSettingsTypes[type] == | 257 if (settings.ContentSettingsTypes[type] == |
| 257 settings.ContentSettingsTypes.PROTOCOL_HANDLERS || | 258 settings.ContentSettingsTypes.PROTOCOL_HANDLERS || |
| 258 settings.ContentSettingsTypes[type] == | 259 settings.ContentSettingsTypes[type] == |
| 259 settings.ContentSettingsTypes.USB_DEVICES || | 260 settings.ContentSettingsTypes.USB_DEVICES || |
| 260 settings.ContentSettingsTypes[type] == | 261 settings.ContentSettingsTypes[type] == |
| 261 settings.ContentSettingsTypes.ZOOM_LEVELS) { | 262 settings.ContentSettingsTypes.ZOOM_LEVELS) { |
| 262 // Some categories store their data in a custom way. | 263 // Some categories store their data in a custom way. |
| 263 continue; | 264 continue; |
| 264 } | 265 } |
| 265 | 266 |
| 266 promiseList.push( | 267 promiseList.push(this.browserProxy_.getExceptionList( |
| 267 this.browserProxy_.getExceptionList( | 268 settings.ContentSettingsTypes[type])); |
| 268 settings.ContentSettingsTypes[type])); | |
| 269 } | 269 } |
| 270 | 270 |
| 271 return Promise.all(promiseList); | 271 return Promise.all(promiseList); |
| 272 }, | 272 }, |
| 273 | 273 |
| 274 /** | 274 /** |
| 275 * Appends to |list| the sites for a given category and subtype. | 275 * Appends to |list| the sites for a given category and subtype. |
| 276 * @param {!Array<SiteException>} sites The site list to add to. | 276 * @param {!Array<SiteException>} sites The site list to add to. |
| 277 * @param {!Array<SiteException>} exceptionList List of sites (exceptions) to | 277 * @param {!Array<SiteException>} exceptionList List of sites (exceptions) to |
| 278 * add. | 278 * add. |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 321 var host2 = self.toUrl(b.embeddingOrigin); | 321 var host2 = self.toUrl(b.embeddingOrigin); |
| 322 host1 = (host1 == null) ? '' : host1.host; | 322 host1 = (host1 == null) ? '' : host1.host; |
| 323 host2 = (host2 == null) ? '' : host2.host; | 323 host2 = (host2 == null) ? '' : host2.host; |
| 324 return host1.localeCompare(host2); | 324 return host1.localeCompare(host2); |
| 325 } | 325 } |
| 326 } | 326 } |
| 327 } | 327 } |
| 328 return comparison; | 328 return comparison; |
| 329 }); | 329 }); |
| 330 } | 330 } |
| 331 var results = /** @type {!Array<SiteException>} */([]); | 331 var results = /** @type {!Array<SiteException>} */ ([]); |
| 332 var lastOrigin = ''; | 332 var lastOrigin = ''; |
| 333 var lastEmbeddingOrigin = ''; | 333 var lastEmbeddingOrigin = ''; |
| 334 for (var i = 0; i < sites.length; ++i) { | 334 for (var i = 0; i < sites.length; ++i) { |
| 335 /** @type {!SiteException} */ | 335 /** @type {!SiteException} */ |
| 336 var siteException = this.expandSiteException(sites[i]); | 336 var siteException = this.expandSiteException(sites[i]); |
| 337 | 337 |
| 338 // The All Sites category can contain duplicates (from other categories). | 338 // The All Sites category can contain duplicates (from other categories). |
| 339 if (this.allSites && siteException.origin == lastOrigin && | 339 if (this.allSites && siteException.origin == lastOrigin && |
| 340 siteException.embeddingOrigin == lastEmbeddingOrigin) { | 340 siteException.embeddingOrigin == lastEmbeddingOrigin) { |
| 341 continue; | 341 continue; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 378 }, | 378 }, |
| 379 | 379 |
| 380 /** | 380 /** |
| 381 * A handler for selecting a site (by clicking on the origin). | 381 * A handler for selecting a site (by clicking on the origin). |
| 382 * @param {!{model: !{item: !SiteException}}} event | 382 * @param {!{model: !{item: !SiteException}}} event |
| 383 * @private | 383 * @private |
| 384 */ | 384 */ |
| 385 onOriginTap_: function(event) { | 385 onOriginTap_: function(event) { |
| 386 if (!this.enableSiteSettings_) | 386 if (!this.enableSiteSettings_) |
| 387 return; | 387 return; |
| 388 settings.navigateTo(settings.Route.SITE_SETTINGS_SITE_DETAILS, | 388 settings.navigateTo( |
| 389 settings.Route.SITE_SETTINGS_SITE_DETAILS, |
| 389 new URLSearchParams('site=' + event.model.item.origin)); | 390 new URLSearchParams('site=' + event.model.item.origin)); |
| 390 }, | 391 }, |
| 391 | 392 |
| 392 /** | 393 /** |
| 393 * A handler for activating one of the menu action items. | 394 * A handler for activating one of the menu action items. |
| 394 * @param {string} action The permission to set (Allow, Block, SessionOnly, | 395 * @param {string} action The permission to set (Allow, Block, SessionOnly, |
| 395 * etc). | 396 * etc). |
| 396 * @private | 397 * @private |
| 397 */ | 398 */ |
| 398 onActionMenuActivate_: function(action) { | 399 onActionMenuActivate_: function(action) { |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 434 | 435 |
| 435 /** | 436 /** |
| 436 * Returns the appropriate site description to display. This can, for example, | 437 * Returns the appropriate site description to display. This can, for example, |
| 437 * be blank, an 'embedded on <site>' or 'Current incognito session' (or a | 438 * be blank, an 'embedded on <site>' or 'Current incognito session' (or a |
| 438 * mix of the last two). | 439 * mix of the last two). |
| 439 * @param {SiteException} item The site exception entry. | 440 * @param {SiteException} item The site exception entry. |
| 440 * @return {string} The site description. | 441 * @return {string} The site description. |
| 441 */ | 442 */ |
| 442 computeSiteDescription_: function(item) { | 443 computeSiteDescription_: function(item) { |
| 443 if (item.incognito && item.embeddingDisplayName.length > 0) { | 444 if (item.incognito && item.embeddingDisplayName.length > 0) { |
| 444 return loadTimeData.getStringF('embeddedIncognitoSite', | 445 return loadTimeData.getStringF( |
| 445 item.embeddingDisplayName); | 446 'embeddedIncognitoSite', item.embeddingDisplayName); |
| 446 } | 447 } |
| 447 | 448 |
| 448 if (item.incognito) | 449 if (item.incognito) |
| 449 return loadTimeData.getString('incognitoSite'); | 450 return loadTimeData.getString('incognitoSite'); |
| 450 return item.embeddingDisplayName; | 451 return item.embeddingDisplayName; |
| 451 }, | 452 }, |
| 452 | 453 |
| 453 /** | 454 /** |
| 454 * @param {!{model: !{item: !SiteException}}} e | 455 * @param {!{model: !{item: !SiteException}}} e |
| 455 * @private | 456 * @private |
| 456 */ | 457 */ |
| 457 onShowActionMenuTap_: function(e) { | 458 onShowActionMenuTap_: function(e) { |
| 458 this.actionMenuSite_ = e.model.item; | 459 this.actionMenuSite_ = e.model.item; |
| 459 /** @type {!CrActionMenuElement} */ ( | 460 /** @type {!CrActionMenuElement} */ (this.$$('dialog[is=cr-action-menu]')) |
| 460 this.$$('dialog[is=cr-action-menu]')).showAt( | 461 .showAt( |
| 461 /** @type {!Element} */ ( | 462 /** @type {!Element} */ ( |
| 462 Polymer.dom(/** @type {!Event} */ (e)).localTarget)); | 463 Polymer.dom(/** @type {!Event} */ (e)).localTarget)); |
| 463 }, | 464 }, |
| 464 | 465 |
| 465 /** @private */ | 466 /** @private */ |
| 466 closeActionMenu_: function() { | 467 closeActionMenu_: function() { |
| 467 this.actionMenuSite_ = null; | 468 this.actionMenuSite_ = null; |
| 468 /** @type {!CrActionMenuElement} */ ( | 469 /** @type {!CrActionMenuElement} */ (this.$$('dialog[is=cr-action-menu]')) |
| 469 this.$$('dialog[is=cr-action-menu]')).close(); | 470 .close(); |
| 470 }, | 471 }, |
| 471 }); | 472 }); |
| OLD | NEW |