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). | |
272 */ | |
273 ensureUrlHasScheme_: function(url) { | |
274 if (url.length == 0) return url; | |
275 return url.indexOf('://') != -1 ? url : 'http://' + url; | |
276 }, | |
277 | |
278 /** | |
279 * Converts an unordered site list to an ordered array, sorted by site name | 271 * Converts an unordered site list to an ordered array, sorted by site name |
280 * then protocol and de-duped (by origin). | 272 * then protocol and de-duped (by origin). |
281 * @param {!Array<SiteException>} sites A list of sites to sort and de-dup. | 273 * @param {!Array<SiteException>} sites A list of sites to sort and de-dup. |
282 * @private | 274 * @private |
283 */ | 275 */ |
284 toSiteArray_: function(sites) { | 276 toSiteArray_: function(sites) { |
285 var self = this; | 277 var self = this; |
286 sites.sort(function(a, b) { | 278 sites.sort(function(a, b) { |
287 // TODO(finnur): Hmm, it would probably be better to ensure scheme on the | 279 // TODO(finnur): Hmm, it would probably be better to ensure scheme on the |
288 // JS/C++ boundary. | 280 // JS/C++ boundary. |
289 var originA = self.ensureUrlHasScheme_(a.origin); | 281 var originA = self.ensureUrlHasScheme(a.origin); |
290 var originB = self.ensureUrlHasScheme_(b.origin); | 282 var originB = self.ensureUrlHasScheme(b.origin); |
291 var embeddingOriginA = self.ensureUrlHasScheme_(a.embeddingOrigin); | 283 var embeddingOriginA = self.ensureUrlHasScheme(a.embeddingOrigin); |
michaelpg
2016/04/11 03:55:35
you don't use these embedding* vars until 299, so
Finnur
2016/04/11 11:45:33
Done.
| |
292 var embeddingOriginB = self.ensureUrlHasScheme_(b.embeddingOrigin); | 284 var embeddingOriginB = self.ensureUrlHasScheme(b.embeddingOrigin); |
293 var url1 = new URL(originA); | 285 // Sorting needs protocol, port and host, but doesn't care about |
294 var url2 = new URL(originB); | 286 // wildcards, which cause the generated URL to be invalid. |
287 var url1 = new URL(originA.replace('[*.]', '')); | |
288 var url2 = new URL(originB.replace('[*.]', '')); | |
295 var embeddingUrl1 = embeddingOriginA.length == 0 ? '' : | 289 var embeddingUrl1 = embeddingOriginA.length == 0 ? '' : |
296 new URL(embeddingOriginA); | 290 new URL(embeddingOriginA.replace('[*.]')); |
michaelpg
2016/04/11 03:55:35
missing 2nd arg (apparently results in String(unde
Finnur
2016/04/11 11:45:33
Good catch. Explains the weirdness I was facing be
| |
297 var embeddingUrl2 = embeddingOriginB.length == 0 ? '' : | 291 var embeddingUrl2 = embeddingOriginB.length == 0 ? '' : |
298 new URL(embeddingOriginB); | 292 new URL(embeddingOriginB.replace('[*.]')); |
299 var comparison = url1.host.localeCompare(url2.host); | 293 var comparison = url1.host.localeCompare(url2.host); |
300 if (comparison == 0) { | 294 if (comparison == 0) { |
301 comparison = url1.protocol.localeCompare(url2.protocol); | 295 comparison = url1.protocol.localeCompare(url2.protocol); |
302 if (comparison == 0) { | 296 if (comparison == 0) { |
303 comparison = url1.port.localeCompare(url2.port); | 297 comparison = url1.port.localeCompare(url2.port); |
304 if (comparison == 0) | 298 if (comparison == 0) { |
305 return embeddingUrl1.host.localeCompare(embeddingUrl2.host); | 299 var host1 = embeddingUrl1.host === undefined ? |
300 '' : embeddingUrl1.host; | |
301 var host2 = embeddingUrl2.host === undefined ? | |
302 '' : embeddingUrl2.host; | |
303 return host1.localeCompare(host2); | |
304 } | |
306 } | 305 } |
307 } | 306 } |
308 return comparison; | 307 return comparison; |
309 }); | 308 }); |
310 var results = []; | 309 var results = []; |
311 var lastOrigin = ''; | 310 var lastOrigin = ''; |
312 var lastEmbeddingOrigin = ''; | 311 var lastEmbeddingOrigin = ''; |
313 for (var i = 0; i < sites.length; ++i) { | 312 for (var i = 0; i < sites.length; ++i) { |
314 var origin = sites[i].origin; | 313 var origin = sites[i].origin; |
315 var embeddingOrigin = sites[i].embeddingOrigin; | 314 var embeddingOrigin = sites[i].embeddingOrigin; |
316 | 315 |
317 // The All Sites category can contain duplicates (from other categories). | 316 var originForDisplay = origin.replace('[*.]', ''); |
318 if (origin == lastOrigin && embeddingOrigin == lastEmbeddingOrigin) | |
319 continue; | |
320 | |
321 var embeddingOriginForDisplay = ''; | 317 var embeddingOriginForDisplay = ''; |
322 if (embeddingOrigin != '*' && origin != embeddingOrigin) | 318 if (embeddingOrigin != '*' && origin != embeddingOrigin) |
323 embeddingOriginForDisplay = embeddingOrigin; | 319 embeddingOriginForDisplay = embeddingOrigin; |
324 | 320 |
321 // The All Sites category can contain duplicates (from other categories). | |
322 if (originForDisplay == lastOrigin && | |
323 embeddingOriginForDisplay == lastEmbeddingOrigin) { | |
324 continue; | |
325 } | |
326 | |
325 results.push({ | 327 results.push({ |
326 origin: origin, | 328 origin: origin, |
329 originForDisplay: originForDisplay, | |
327 embeddingOrigin: embeddingOrigin, | 330 embeddingOrigin: embeddingOrigin, |
328 embeddingOriginForDisplay: embeddingOriginForDisplay, | 331 embeddingOriginForDisplay: embeddingOriginForDisplay, |
329 }); | 332 }); |
330 | 333 |
331 lastOrigin = origin; | 334 lastOrigin = originForDisplay; |
332 lastEmbeddingOrigin = embeddingOrigin; | 335 lastEmbeddingOrigin = embeddingOriginForDisplay; |
333 } | 336 } |
334 return results; | 337 return results; |
335 }, | 338 }, |
336 | 339 |
337 /** | 340 /** |
338 * Setup the values to use for the action menu. | 341 * Setup the values to use for the action menu. |
339 * @private | 342 * @private |
340 */ | 343 */ |
341 setUpActionMenu_: function() { | 344 setUpActionMenu_: function() { |
342 this.showAllowAction_ = | 345 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. | 443 * Returns the icon to use for a given site. |
441 * @param {string} url The url of the site to fetch the icon for. | 444 * @param {string} url The url of the site to fetch the icon for. |
442 * @private | 445 * @private |
443 */ | 446 */ |
444 computeSiteIcon_: function(url) { | 447 computeSiteIcon_: function(url) { |
445 // TODO(finnur): For now, we're returning a placeholder image for each site | 448 // 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. | 449 // but the actual favicon for each site will need to be returned. |
447 return 'communication:message'; | 450 return 'communication:message'; |
448 }, | 451 }, |
449 }); | 452 }); |
OLD | NEW |