Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: lib/url.js

Issue 29371763: Issue 4795 - Use modern JavaScript syntax (Closed)
Patch Set: Created Jan. 13, 2017, 12:11 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2016 Eyeo GmbH 3 * Copyright (C) 2006-2016 Eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 10 matching lines...) Expand all
21 let punycode = require("punycode"); 21 let punycode = require("punycode");
22 22
23 let getDecodedHostname = 23 let getDecodedHostname =
24 /** 24 /**
25 * Gets the IDN-decoded hostname from a URL object. 25 * Gets the IDN-decoded hostname from a URL object.
26 * 26 *
27 * @param {URL} url 27 * @param {URL} url
28 * @return {string} 28 * @return {string}
29 * @static 29 * @static
30 */ 30 */
31 exports.getDecodedHostname = function(url) 31 exports.getDecodedHostname = url =>
32 { 32 {
33 let hostname = url.hostname; 33 let hostname = url.hostname;
34 34
35 if (hostname.indexOf("xn--") == -1) 35 if (hostname.indexOf("xn--") == -1)
36 return hostname; 36 return hostname;
37 37
38 return punycode.toUnicode(hostname); 38 return punycode.toUnicode(hostname);
39 }; 39 };
40 40
41 /** 41 /**
42 * Gets the IDN-decoded hostname from the URL of a frame. 42 * Gets the IDN-decoded hostname from the URL of a frame.
43 * If the URL don't have host information (like "about:blank" 43 * If the URL don't have host information (like "about:blank"
44 * and "data:" URLs) it falls back to the parent frame. 44 * and "data:" URLs) it falls back to the parent frame.
45 * 45 *
46 * @param {Frame} frame 46 * @param {Frame} frame
47 * @return {string} 47 * @return {string}
48 */ 48 */
49 exports.extractHostFromFrame = function(frame) 49 exports.extractHostFromFrame = frame =>
50 { 50 {
51 for (; frame; frame = frame.parent) 51 for (; frame; frame = frame.parent)
52 { 52 {
53 let hostname = getDecodedHostname(frame.url); 53 let hostname = getDecodedHostname(frame.url);
54 if (hostname) 54 if (hostname)
55 return hostname; 55 return hostname;
56 } 56 }
57 57
58 return ""; 58 return "";
59 }; 59 };
60 60
61 /** 61 /**
62 * Converts a URL object into a string. For HTTP(S) URLs 62 * Converts a URL object into a string. For HTTP(S) URLs
63 * the hostname gets IDN-decoded and the hash is stripped. 63 * the hostname gets IDN-decoded and the hash is stripped.
64 * 64 *
65 * @param {URL} url 65 * @param {URL} url
66 * @return {string} 66 * @return {string}
67 */ 67 */
68 exports.stringifyURL = function(url) 68 exports.stringifyURL = url =>
69 { 69 {
70 let protocol = url.protocol; 70 let protocol = url.protocol;
71 let href = url.href; 71 let href = url.href;
72 72
73 if (protocol == "http:" || protocol == "https:") 73 if (protocol == "http:" || protocol == "https:")
74 { 74 {
75 let hostname = url.hostname; 75 let hostname = url.hostname;
76 if (hostname.indexOf("xn--") != -1) 76 if (hostname.indexOf("xn--") != -1)
77 href = href.replace(hostname, punycode.toUnicode(hostname)); 77 href = href.replace(hostname, punycode.toUnicode(hostname));
78 78
(...skipping 16 matching lines...) Expand all
95 return hostname.indexOf(":") == -1; 95 return hostname.indexOf(":") == -1;
96 } 96 }
97 97
98 /** 98 /**
99 * Checks whether the request's origin is different from the document's origin. 99 * Checks whether the request's origin is different from the document's origin.
100 * 100 *
101 * @param {URL} url The request URL 101 * @param {URL} url The request URL
102 * @param {string} documentHost The IDN-decoded hostname of the document 102 * @param {string} documentHost The IDN-decoded hostname of the document
103 * @return {Boolean} 103 * @return {Boolean}
104 */ 104 */
105 exports.isThirdParty = function(url, documentHost) 105 exports.isThirdParty = (url, documentHost) =>
106 { 106 {
107 let requestHost = getDecodedHostname(url).replace(/\.+$/, ""); 107 let requestHost = getDecodedHostname(url).replace(/\.+$/, "");
108 documentHost = documentHost.replace(/\.+$/, ""); 108 documentHost = documentHost.replace(/\.+$/, "");
109 109
110 if (requestHost == documentHost) 110 if (requestHost == documentHost)
111 return false; 111 return false;
112 112
113 if (!isDomain(requestHost) || !isDomain(documentHost)) 113 if (!isDomain(requestHost) || !isDomain(documentHost))
114 return true; 114 return true;
115 115
116 return getDomain(requestHost) != getDomain(documentHost); 116 return getDomain(requestHost) != getDomain(documentHost);
117 }; 117 };
OLDNEW
« chrome/ext/common.js ('K') | « lib/tldjs.js ('k') | lib/utils.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld