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 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
313 if (exceptionList[i].setting != this.categorySubtype) | 313 if (exceptionList[i].setting != this.categorySubtype) |
314 continue; | 314 continue; |
315 } | 315 } |
316 | 316 |
317 sites.push(exceptionList[i]); | 317 sites.push(exceptionList[i]); |
318 } | 318 } |
319 return sites; | 319 return sites; |
320 }, | 320 }, |
321 | 321 |
322 /** | 322 /** |
323 * Converts a string origin/pattern to a URL. | |
324 * @param {string} originOrPattern The origin/pattern to convert to URL. | |
325 * @return {URL} The URL to return (or null if origin is not a valid URL). | |
326 * @private | |
327 */ | |
328 toUrl_: function(originOrPattern) { | |
329 if (originOrPattern.length == 0) | |
330 return null; | |
331 // TODO(finnur): Hmm, it would probably be better to ensure scheme on the | |
332 // JS/C++ boundary. | |
333 // TODO(dschuyler): I agree. This filtering should be done in one go, rather | |
334 // that during the sort. The URL generation should be wrapped in a try/catch | |
335 // as well. | |
336 originOrPattern = originOrPattern.replace('*://', ''); | |
337 originOrPattern = originOrPattern.replace('[*.]', ''); | |
338 return new URL(this.ensureUrlHasScheme(originOrPattern)); | |
339 }, | |
340 | |
341 /** | |
342 * Converts an unordered site list to an ordered array, sorted by site name | 323 * Converts an unordered site list to an ordered array, sorted by site name |
343 * then protocol and de-duped (by origin). | 324 * then protocol and de-duped (by origin). |
344 * @param {!Array<SiteException>} sites A list of sites to sort and de-dupe. | 325 * @param {!Array<SiteException>} sites A list of sites to sort and de-dupe. |
345 * @return {!Array<SiteException>} Sorted and de-duped list. | 326 * @return {!Array<SiteException>} Sorted and de-duped list. |
346 * @private | 327 * @private |
347 */ | 328 */ |
348 toSiteArray_: function(sites) { | 329 toSiteArray_: function(sites) { |
349 var self = this; | 330 var self = this; |
350 sites.sort(function(a, b) { | 331 sites.sort(function(a, b) { |
351 var url1 = self.toUrl_(a.origin); | 332 var url1 = self.toUrl(a.origin); |
352 var url2 = self.toUrl_(b.origin); | 333 var url2 = self.toUrl(b.origin); |
353 var comparison = url1.host.localeCompare(url2.host); | 334 var comparison = url1.host.localeCompare(url2.host); |
354 if (comparison == 0) { | 335 if (comparison == 0) { |
355 comparison = url1.protocol.localeCompare(url2.protocol); | 336 comparison = url1.protocol.localeCompare(url2.protocol); |
356 if (comparison == 0) { | 337 if (comparison == 0) { |
357 comparison = url1.port.localeCompare(url2.port); | 338 comparison = url1.port.localeCompare(url2.port); |
358 if (comparison == 0) { | 339 if (comparison == 0) { |
359 // Compare hosts for the embedding origins. | 340 // Compare hosts for the embedding origins. |
360 var host1 = self.toUrl_(a.embeddingOrigin); | 341 var host1 = self.toUrl(a.embeddingOrigin); |
361 var host2 = self.toUrl_(b.embeddingOrigin); | 342 var host2 = self.toUrl(b.embeddingOrigin); |
362 host1 = (host1 == null) ? '' : host1.host; | 343 host1 = (host1 == null) ? '' : host1.host; |
363 host2 = (host2 == null) ? '' : host2.host; | 344 host2 = (host2 == null) ? '' : host2.host; |
364 return host1.localeCompare(host2); | 345 return host1.localeCompare(host2); |
365 } | 346 } |
366 } | 347 } |
367 } | 348 } |
368 return comparison; | 349 return comparison; |
369 }); | 350 }); |
370 var results = /** @type {!Array<SiteException>} */([]); | 351 var results = /** @type {!Array<SiteException>} */([]); |
371 var lastOrigin = ''; | 352 var lastOrigin = ''; |
372 var lastEmbeddingOrigin = ''; | 353 var lastEmbeddingOrigin = ''; |
373 for (var i = 0; i < sites.length; ++i) { | 354 for (var i = 0; i < sites.length; ++i) { |
374 var origin = sites[i].origin; | 355 /** @type {!SiteException} */ |
375 var originForDisplay = this.sanitizePort(this.toUrl_(origin).origin); | 356 var siteException = this.expandSiteException(sites[i]); |
376 | |
377 var embeddingOrigin = sites[i].embeddingOrigin; | |
378 var embeddingOriginForDisplay = ''; | |
379 if (origin != embeddingOrigin) { | |
380 embeddingOriginForDisplay = | |
381 this.getEmbedderString(embeddingOrigin, this.category); | |
382 } | |
383 | 357 |
384 // The All Sites category can contain duplicates (from other categories). | 358 // The All Sites category can contain duplicates (from other categories). |
385 if (originForDisplay == lastOrigin && | 359 if (siteException.originForDisplay == lastOrigin && |
386 embeddingOriginForDisplay == lastEmbeddingOrigin) { | 360 siteException.embeddingOriginForDisplay == lastEmbeddingOrigin) { |
387 continue; | 361 continue; |
388 } | 362 } |
389 | 363 |
390 results.push({ | 364 results.push(siteException); |
391 origin: origin, | 365 lastOrigin = siteException.originForDisplay; |
392 originForDisplay: originForDisplay, | 366 lastEmbeddingOrigin = siteException.embeddingOriginForDisplay; |
393 embeddingOrigin: embeddingOrigin, | |
394 embeddingOriginForDisplay: embeddingOriginForDisplay, | |
395 incognito: sites[i].incognito, | |
396 setting: sites[i].setting, | |
397 source: sites[i].source, | |
398 }); | |
399 | |
400 lastOrigin = originForDisplay; | |
401 lastEmbeddingOrigin = embeddingOriginForDisplay; | |
402 } | 367 } |
403 return results; | 368 return results; |
404 }, | 369 }, |
405 | 370 |
406 /** | 371 /** |
407 * Setup the values to use for the action menu. | 372 * Setup the values to use for the action menu. |
408 * @private | 373 * @private |
409 */ | 374 */ |
410 setUpActionMenu_: function() { | 375 setUpActionMenu_: function() { |
411 this.showAllowAction_ = | 376 this.showAllowAction_ = |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
535 // is redundant to also list all the sites that are blocked. | 500 // is redundant to also list all the sites that are blocked. |
536 if (this.isAllowList_()) | 501 if (this.isAllowList_()) |
537 return true; | 502 return true; |
538 | 503 |
539 if (this.isSessionOnlyList_()) | 504 if (this.isSessionOnlyList_()) |
540 return siteList.length > 0; | 505 return siteList.length > 0; |
541 | 506 |
542 return toggleState; | 507 return toggleState; |
543 }, | 508 }, |
544 }); | 509 }); |
OLD | NEW |