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 * 'settings-site-list' shows a list of Allowed and Blocked sites for a given | 7 * 'settings-site-list' shows a list of Allowed and Blocked sites for a given |
8 * category. | 8 * category. |
9 */ | 9 */ |
10 Polymer({ | 10 Polymer({ |
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
261 continue; | 261 continue; |
262 } | 262 } |
263 } | 263 } |
264 | 264 |
265 sites.push(exceptionList[i]); | 265 sites.push(exceptionList[i]); |
266 } | 266 } |
267 return sites; | 267 return sites; |
268 }, | 268 }, |
269 | 269 |
270 /** | 270 /** |
271 * Ensures the URL has a scheme (assumes http if omitted). | 271 * Converts a string origin/pattern to a URL. |
272 * @param {string} originOrPattern The origin/pattern to convert to URL. | |
273 * @return {URL} The URL to return (or null if origin is not a valid URL). | |
michaelpg
2016/04/11 14:14:32
be explicit about nullable types: {!URL}
| |
274 * @private | |
272 */ | 275 */ |
273 ensureUrlHasScheme_: function(url) { | 276 toUrl_: function(originOrPattern) { |
274 if (url.length == 0) return url; | 277 if (originOrPattern.length == 0) |
275 return url.indexOf('://') != -1 ? url : 'http://' + url; | 278 return null; |
279 // TODO(finnur): Hmm, it would probably be better to ensure scheme on the | |
280 // JS/C++ boundary. | |
281 return new URL( | |
282 this.ensureUrlHasScheme(originOrPattern.replace('[*.]', ''))); | |
276 }, | 283 }, |
277 | 284 |
278 /** | 285 /** |
279 * Converts an unordered site list to an ordered array, sorted by site name | 286 * Converts an unordered site list to an ordered array, sorted by site name |
280 * then protocol and de-duped (by origin). | 287 * then protocol and de-duped (by origin). |
281 * @param {!Array<SiteException>} sites A list of sites to sort and de-dup. | 288 * @param {!Array<SiteException>} sites A list of sites to sort and de-dup. |
282 * @private | 289 * @private |
283 */ | 290 */ |
284 toSiteArray_: function(sites) { | 291 toSiteArray_: function(sites) { |
285 var self = this; | 292 var self = this; |
286 sites.sort(function(a, b) { | 293 sites.sort(function(a, b) { |
287 // TODO(finnur): Hmm, it would probably be better to ensure scheme on the | 294 var url1 = self.toUrl_(a.origin); |
288 // JS/C++ boundary. | 295 var url2 = self.toUrl_(b.origin); |
289 var originA = self.ensureUrlHasScheme_(a.origin); | |
290 var originB = self.ensureUrlHasScheme_(b.origin); | |
291 var embeddingOriginA = self.ensureUrlHasScheme_(a.embeddingOrigin); | |
292 var embeddingOriginB = self.ensureUrlHasScheme_(b.embeddingOrigin); | |
293 var url1 = new URL(originA); | |
294 var url2 = new URL(originB); | |
295 var embeddingUrl1 = embeddingOriginA.length == 0 ? '' : | |
296 new URL(embeddingOriginA); | |
297 var embeddingUrl2 = embeddingOriginB.length == 0 ? '' : | |
298 new URL(embeddingOriginB); | |
299 var comparison = url1.host.localeCompare(url2.host); | 296 var comparison = url1.host.localeCompare(url2.host); |
300 if (comparison == 0) { | 297 if (comparison == 0) { |
301 comparison = url1.protocol.localeCompare(url2.protocol); | 298 comparison = url1.protocol.localeCompare(url2.protocol); |
302 if (comparison == 0) { | 299 if (comparison == 0) { |
303 comparison = url1.port.localeCompare(url2.port); | 300 comparison = url1.port.localeCompare(url2.port); |
304 if (comparison == 0) | 301 if (comparison == 0) { |
305 return embeddingUrl1.host.localeCompare(embeddingUrl2.host); | 302 // Compare hosts for the embedding origins. |
303 var host1 = self.toUrl_(a.embeddingOrigin); | |
304 var host2 = self.toUrl_(b.embeddingOrigin); | |
305 host1 = (host1 == null) ? '' : host1.host; | |
306 host2 = (host2 == null) ? '' : host2.host; | |
307 return host1.localeCompare(host2); | |
308 } | |
306 } | 309 } |
307 } | 310 } |
308 return comparison; | 311 return comparison; |
309 }); | 312 }); |
310 var results = []; | 313 var results = []; |
311 var lastOrigin = ''; | 314 var lastOrigin = ''; |
312 var lastEmbeddingOrigin = ''; | 315 var lastEmbeddingOrigin = ''; |
313 for (var i = 0; i < sites.length; ++i) { | 316 for (var i = 0; i < sites.length; ++i) { |
314 var origin = sites[i].origin; | 317 var origin = sites[i].origin; |
315 var embeddingOrigin = sites[i].embeddingOrigin; | 318 var embeddingOrigin = sites[i].embeddingOrigin; |
316 | 319 |
317 // The All Sites category can contain duplicates (from other categories). | 320 var originForDisplay = origin.replace('[*.]', ''); |
318 if (origin == lastOrigin && embeddingOrigin == lastEmbeddingOrigin) | |
319 continue; | |
320 | |
321 var embeddingOriginForDisplay = ''; | 321 var embeddingOriginForDisplay = ''; |
322 if (embeddingOrigin != '*' && origin != embeddingOrigin) | 322 if (embeddingOrigin != '*' && origin != embeddingOrigin) |
323 embeddingOriginForDisplay = embeddingOrigin; | 323 embeddingOriginForDisplay = embeddingOrigin; |
324 | 324 |
325 // The All Sites category can contain duplicates (from other categories). | |
326 if (originForDisplay == lastOrigin && | |
327 embeddingOriginForDisplay == lastEmbeddingOrigin) { | |
328 continue; | |
329 } | |
330 | |
325 results.push({ | 331 results.push({ |
326 origin: origin, | 332 origin: origin, |
333 originForDisplay: originForDisplay, | |
327 embeddingOrigin: embeddingOrigin, | 334 embeddingOrigin: embeddingOrigin, |
328 embeddingOriginForDisplay: embeddingOriginForDisplay, | 335 embeddingOriginForDisplay: embeddingOriginForDisplay, |
329 }); | 336 }); |
330 | 337 |
331 lastOrigin = origin; | 338 lastOrigin = originForDisplay; |
332 lastEmbeddingOrigin = embeddingOrigin; | 339 lastEmbeddingOrigin = embeddingOriginForDisplay; |
333 } | 340 } |
334 return results; | 341 return results; |
335 }, | 342 }, |
336 | 343 |
337 /** | 344 /** |
338 * Setup the values to use for the action menu. | 345 * Setup the values to use for the action menu. |
339 * @private | 346 * @private |
340 */ | 347 */ |
341 setUpActionMenu_: function() { | 348 setUpActionMenu_: function() { |
342 this.showAllowAction_ = | 349 this.showAllowAction_ = |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
440 * Returns the icon to use for a given site. | 447 * Returns the icon to use for a given site. |
441 * @param {string} url The url of the site to fetch the icon for. | 448 * @param {string} url The url of the site to fetch the icon for. |
442 * @private | 449 * @private |
443 */ | 450 */ |
444 computeSiteIcon_: function(url) { | 451 computeSiteIcon_: function(url) { |
445 // TODO(finnur): For now, we're returning a placeholder image for each site | 452 // TODO(finnur): For now, we're returning a placeholder image for each site |
446 // but the actual favicon for each site will need to be returned. | 453 // but the actual favicon for each site will need to be returned. |
447 return 'communication:message'; | 454 return 'communication:message'; |
448 }, | 455 }, |
449 }); | 456 }); |
OLD | NEW |