| 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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 * @type {!Array<SiteException>} | 49 * @type {!Array<SiteException>} |
| 50 */ | 50 */ |
| 51 sites: { | 51 sites: { |
| 52 type: Array, | 52 type: Array, |
| 53 value: function() { | 53 value: function() { |
| 54 return []; | 54 return []; |
| 55 }, | 55 }, |
| 56 }, | 56 }, |
| 57 | 57 |
| 58 /** | 58 /** |
| 59 * Whether this list is for the All Sites category. | |
| 60 */ | |
| 61 allSites: { | |
| 62 type: Boolean, | |
| 63 value: false, | |
| 64 }, | |
| 65 | |
| 66 /** | |
| 67 * The type of category this widget is displaying data for. Normally | 59 * The type of category this widget is displaying data for. Normally |
| 68 * either 'allow' or 'block', representing which sites are allowed or | 60 * either 'allow' or 'block', representing which sites are allowed or |
| 69 * blocked respectively. | 61 * blocked respectively. |
| 70 */ | 62 */ |
| 71 categorySubtype: { | 63 categorySubtype: { |
| 72 type: String, | 64 type: String, |
| 73 value: settings.INVALID_CATEGORY_SUBTYPE, | 65 value: settings.INVALID_CATEGORY_SUBTYPE, |
| 74 }, | 66 }, |
| 75 | 67 |
| 76 /** | 68 /** |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 this.onIncognitoStatusChanged_.bind(this)); | 116 this.onIncognitoStatusChanged_.bind(this)); |
| 125 }, | 117 }, |
| 126 | 118 |
| 127 /** | 119 /** |
| 128 * Called when a site changes permission. | 120 * Called when a site changes permission. |
| 129 * @param {string} category The category of the site that changed. | 121 * @param {string} category The category of the site that changed. |
| 130 * @param {string} site The site that changed. | 122 * @param {string} site The site that changed. |
| 131 * @private | 123 * @private |
| 132 */ | 124 */ |
| 133 siteWithinCategoryChanged_: function(category, site) { | 125 siteWithinCategoryChanged_: function(category, site) { |
| 134 if (category == this.category || this.allSites) | 126 if (category == this.category) |
| 135 this.configureWidget_(); | 127 this.configureWidget_(); |
| 136 }, | 128 }, |
| 137 | 129 |
| 138 /** | 130 /** |
| 139 * Called for each site list when incognito is enabled or disabled. Only | 131 * Called for each site list when incognito is enabled or disabled. Only |
| 140 * called on change (opening N incognito windows only fires one message). | 132 * called on change (opening N incognito windows only fires one message). |
| 141 * Another message is sent when the *last* incognito window closes. | 133 * Another message is sent when the *last* incognito window closes. |
| 142 * @private | 134 * @private |
| 143 */ | 135 */ |
| 144 onIncognitoStatusChanged_: function() { | 136 onIncognitoStatusChanged_: function() { |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 | 177 |
| 186 /** | 178 /** |
| 187 * @param {!SiteException} exception The content setting exception. | 179 * @param {!SiteException} exception The content setting exception. |
| 188 * @param {boolean} readOnlyList Whether the site exception list is read-only. | 180 * @param {boolean} readOnlyList Whether the site exception list is read-only. |
| 189 * @return {boolean} | 181 * @return {boolean} |
| 190 * @private | 182 * @private |
| 191 */ | 183 */ |
| 192 shouldHideResetButton_: function(exception, readOnlyList) { | 184 shouldHideResetButton_: function(exception, readOnlyList) { |
| 193 return exception.enforcement == | 185 return exception.enforcement == |
| 194 chrome.settingsPrivate.Enforcement.ENFORCED || | 186 chrome.settingsPrivate.Enforcement.ENFORCED || |
| 195 this.allSites || !(readOnlyList || !!exception.embeddingOrigin); | 187 !(readOnlyList || !!exception.embeddingOrigin); |
| 196 }, | 188 }, |
| 197 | 189 |
| 198 /** | 190 /** |
| 199 * @param {!SiteException} exception The content setting exception. | 191 * @param {!SiteException} exception The content setting exception. |
| 200 * @param {boolean} readOnlyList Whether the site exception list is read-only. | 192 * @param {boolean} readOnlyList Whether the site exception list is read-only. |
| 201 * @return {boolean} | 193 * @return {boolean} |
| 202 * @private | 194 * @private |
| 203 */ | 195 */ |
| 204 shouldHideActionMenu_: function(exception, readOnlyList) { | 196 shouldHideActionMenu_: function(exception, readOnlyList) { |
| 205 return exception.enforcement == | 197 return exception.enforcement == |
| 206 chrome.settingsPrivate.Enforcement.ENFORCED || | 198 chrome.settingsPrivate.Enforcement.ENFORCED || |
| 207 this.allSites || readOnlyList || !!exception.embeddingOrigin; | 199 readOnlyList || !!exception.embeddingOrigin; |
| 208 }, | 200 }, |
| 209 | 201 |
| 210 /** | 202 /** |
| 211 * A handler for the Add Site button. | 203 * A handler for the Add Site button. |
| 212 * @param {!Event} e | 204 * @param {!Event} e |
| 213 * @private | 205 * @private |
| 214 */ | 206 */ |
| 215 onAddSiteTap_: function(e) { | 207 onAddSiteTap_: function(e) { |
| 216 assert(!this.readOnlyList); | 208 assert(!this.readOnlyList); |
| 217 e.preventDefault(); | 209 e.preventDefault(); |
| 218 var dialog = document.createElement('add-site-dialog'); | 210 var dialog = document.createElement('add-site-dialog'); |
| 219 dialog.category = this.category; | 211 dialog.category = this.category; |
| 220 dialog.contentSetting = this.categorySubtype; | 212 dialog.contentSetting = this.categorySubtype; |
| 221 this.shadowRoot.appendChild(dialog); | 213 this.shadowRoot.appendChild(dialog); |
| 222 | 214 |
| 223 dialog.open(this.categorySubtype); | 215 dialog.open(this.categorySubtype); |
| 224 | 216 |
| 225 dialog.addEventListener('close', function() { | 217 dialog.addEventListener('close', function() { |
| 226 cr.ui.focusWithoutInk(assert(this.$.addSite)); | 218 cr.ui.focusWithoutInk(assert(this.$.addSite)); |
| 227 dialog.remove(); | 219 dialog.remove(); |
| 228 }.bind(this)); | 220 }.bind(this)); |
| 229 }, | 221 }, |
| 230 | 222 |
| 231 /** | 223 /** |
| 232 * Populate the sites list for display. | 224 * Populate the sites list for display. |
| 233 * @private | 225 * @private |
| 234 */ | 226 */ |
| 235 populateList_: function() { | 227 populateList_: function() { |
| 236 if (this.allSites) { | 228 this.browserProxy_.getExceptionList(this.category) |
| 237 this.getAllSitesList_().then(function(lists) { | 229 .then(function(exceptionList) { |
| 238 this.processExceptions_(lists); | |
| 239 this.closeActionMenu_(); | |
| 240 }.bind(this)); | |
| 241 } else { | |
| 242 this.browserProxy_.getExceptionList(this.category).then( | |
| 243 function(exceptionList) { | |
| 244 this.processExceptions_([exceptionList]); | 230 this.processExceptions_([exceptionList]); |
| 245 this.closeActionMenu_(); | 231 this.closeActionMenu_(); |
| 246 }.bind(this)); | 232 }.bind(this)); |
| 247 } | |
| 248 }, | 233 }, |
| 249 | 234 |
| 250 /** | 235 /** |
| 251 * Process the exception list returned from the native layer. | 236 * Process the exception list returned from the native layer. |
| 252 * @param {!Array<!Array<RawSiteException>>} data List of sites (exceptions) | 237 * @param {!Array<!Array<RawSiteException>>} data List of sites (exceptions) |
| 253 * to process. | 238 * to process. |
| 254 * @private | 239 * @private |
| 255 */ | 240 */ |
| 256 processExceptions_: function(data) { | 241 processExceptions_: function(data) { |
| 257 var sites = /** @type {!Array<RawSiteException>} */ ([]); | 242 var sites = /** @type {!Array<RawSiteException>} */ ([]); |
| 258 for (var i = 0; i < data.length; ++i) { | 243 for (var i = 0; i < data.length; ++i) { |
| 259 var exceptionList = data[i]; | 244 var exceptionList = data[i]; |
| 260 for (var k = 0; k < exceptionList.length; ++k) { | 245 for (var k = 0; k < exceptionList.length; ++k) { |
| 261 if (!this.allSites && | 246 if (exceptionList[k].setting == settings.PermissionValues.DEFAULT || |
| 262 (exceptionList[k].setting == settings.PermissionValues.DEFAULT || | 247 exceptionList[k].setting != this.categorySubtype) { |
| 263 exceptionList[k].setting != this.categorySubtype)) { | |
| 264 continue; | 248 continue; |
| 265 } | 249 } |
| 266 | 250 |
| 267 sites.push(exceptionList[k]); | 251 sites.push(exceptionList[k]); |
| 268 } | 252 } |
| 269 } | 253 } |
| 270 this.sites = this.toSiteArray_(sites); | 254 this.sites = this.toSiteArray_(sites); |
| 271 }, | 255 }, |
| 272 | 256 |
| 273 /** | 257 /** |
| 274 * Retrieves a list of all known sites (any category/setting). | |
| 275 * @return {!Promise} | |
| 276 * @private | |
| 277 */ | |
| 278 getAllSitesList_: function() { | |
| 279 var promiseList = []; | |
| 280 for (var type in settings.ContentSettingsTypes) { | |
| 281 if (settings.ContentSettingsTypes[type] == | |
| 282 settings.ContentSettingsTypes.PROTOCOL_HANDLERS || | |
| 283 settings.ContentSettingsTypes[type] == | |
| 284 settings.ContentSettingsTypes.USB_DEVICES || | |
| 285 settings.ContentSettingsTypes[type] == | |
| 286 settings.ContentSettingsTypes.ZOOM_LEVELS) { | |
| 287 // Some categories store their data in a custom way. | |
| 288 continue; | |
| 289 } | |
| 290 | |
| 291 promiseList.push( | |
| 292 this.browserProxy_.getExceptionList( | |
| 293 settings.ContentSettingsTypes[type])); | |
| 294 } | |
| 295 | |
| 296 return Promise.all(promiseList); | |
| 297 }, | |
| 298 | |
| 299 /** | |
| 300 * Converts a list of exceptions received from the C++ handler to | 258 * Converts a list of exceptions received from the C++ handler to |
| 301 * full SiteException objects. If this site-list is used as an all sites | 259 * full SiteException objects. |
| 302 * view, the list is sorted by site name, then protocol and port and de-duped | |
| 303 * (by origin). | |
| 304 * @param {!Array<RawSiteException>} sites A list of sites to convert. | 260 * @param {!Array<RawSiteException>} sites A list of sites to convert. |
| 305 * @return {!Array<SiteException>} A list of full SiteExceptions. Sorted and | 261 * @return {!Array<SiteException>} A list of full SiteExceptions. |
| 306 * deduped if allSites is set. | |
| 307 * @private | 262 * @private |
| 308 */ | 263 */ |
| 309 toSiteArray_: function(sites) { | 264 toSiteArray_: function(sites) { |
| 310 var self = this; | |
| 311 if (this.allSites) { | |
| 312 sites.sort(function(a, b) { | |
| 313 var url1 = self.toUrl(a.origin); | |
| 314 var url2 = self.toUrl(b.origin); | |
| 315 var comparison = url1.host.localeCompare(url2.host); | |
| 316 if (comparison == 0) { | |
| 317 comparison = url1.protocol.localeCompare(url2.protocol); | |
| 318 if (comparison == 0) { | |
| 319 comparison = url1.port.localeCompare(url2.port); | |
| 320 if (comparison == 0) { | |
| 321 // Compare hosts for the embedding origins. | |
| 322 var host1 = self.toUrl(a.embeddingOrigin); | |
| 323 var host2 = self.toUrl(b.embeddingOrigin); | |
| 324 host1 = (host1 == null) ? '' : host1.host; | |
| 325 host2 = (host2 == null) ? '' : host2.host; | |
| 326 return host1.localeCompare(host2); | |
| 327 } | |
| 328 } | |
| 329 } | |
| 330 return comparison; | |
| 331 }); | |
| 332 } | |
| 333 var results = /** @type {!Array<SiteException>} */([]); | 265 var results = /** @type {!Array<SiteException>} */([]); |
| 334 var lastOrigin = ''; | 266 var lastOrigin = ''; |
| 335 var lastEmbeddingOrigin = ''; | 267 var lastEmbeddingOrigin = ''; |
| 336 for (var i = 0; i < sites.length; ++i) { | 268 for (var i = 0; i < sites.length; ++i) { |
| 337 /** @type {!SiteException} */ | 269 /** @type {!SiteException} */ |
| 338 var siteException = this.expandSiteException(sites[i]); | 270 var siteException = this.expandSiteException(sites[i]); |
| 339 | 271 |
| 340 // The All Sites category can contain duplicates (from other categories). | |
| 341 if (this.allSites && siteException.origin == lastOrigin && | |
| 342 siteException.embeddingOrigin == lastEmbeddingOrigin) { | |
| 343 continue; | |
| 344 } | |
| 345 | |
| 346 results.push(siteException); | 272 results.push(siteException); |
| 347 lastOrigin = siteException.origin; | 273 lastOrigin = siteException.origin; |
| 348 lastEmbeddingOrigin = siteException.embeddingOrigin; | 274 lastEmbeddingOrigin = siteException.embeddingOrigin; |
| 349 } | 275 } |
| 350 return results; | 276 return results; |
| 351 }, | 277 }, |
| 352 | 278 |
| 353 /** | 279 /** |
| 354 * Set up the values to use for the action menu. | 280 * Set up the values to use for the action menu. |
| 355 * @private | 281 * @private |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 496 /** @private */ | 422 /** @private */ |
| 497 closeActionMenu_: function() { | 423 closeActionMenu_: function() { |
| 498 this.actionMenuSite_ = null; | 424 this.actionMenuSite_ = null; |
| 499 this.activeDialogAnchor_ = null; | 425 this.activeDialogAnchor_ = null; |
| 500 var actionMenu = /** @type {!CrActionMenuElement} */ ( | 426 var actionMenu = /** @type {!CrActionMenuElement} */ ( |
| 501 this.$$('dialog[is=cr-action-menu]')); | 427 this.$$('dialog[is=cr-action-menu]')); |
| 502 if (actionMenu.open) | 428 if (actionMenu.open) |
| 503 actionMenu.close(); | 429 actionMenu.close(); |
| 504 }, | 430 }, |
| 505 }); | 431 }); |
| OLD | NEW |