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

Side by Side Diff: lib/url.js

Issue 6318719470927872: Noissue - Fixed documentation where parameters where mistakently indicated as optional (Closed)
Patch Set: Fixed typo Created March 2, 2015, 5:20 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
« no previous file with comments | « lib/icon.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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-2015 Eyeo GmbH 3 * Copyright (C) 2006-2015 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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 this[prop] = anchor[prop]; 42 this[prop] = anchor[prop];
43 }; 43 };
44 } 44 }
45 45
46 return URL; 46 return URL;
47 })(); 47 })();
48 48
49 /** 49 /**
50 * Gets the IDN-decoded hostname from a URL object. 50 * Gets the IDN-decoded hostname from a URL object.
51 * 51 *
52 * @param {URL} [url] 52 * @param {URL} url
53 * @return {string} 53 * @return {string}
54 */ 54 */
55 function getDecodedHostname(url) 55 function getDecodedHostname(url)
56 { 56 {
57 let hostname = url.hostname; 57 let hostname = url.hostname;
58 58
59 if (hostname.indexOf("xn--") == -1) 59 if (hostname.indexOf("xn--") == -1)
60 return hostname; 60 return hostname;
61 61
62 return punycode.toUnicode(hostname); 62 return punycode.toUnicode(hostname);
63 } 63 }
64 exports.getDecodedHostname = getDecodedHostname; 64 exports.getDecodedHostname = getDecodedHostname;
65 65
66 /** 66 /**
67 * Gets the IDN-decoded hostname from the URL of a frame. 67 * Gets the IDN-decoded hostname from the URL of a frame.
68 * If the URL don't have host information (like "about:blank" 68 * If the URL don't have host information (like "about:blank"
69 * and "data:" URLs) it falls back to the parent frame. 69 * and "data:" URLs) it falls back to the parent frame.
70 * 70 *
71 * @param {Frame} [frame] 71 * @param {Frame} frame
72 * @return {string} 72 * @return {string}
73 */ 73 */
74 function extractHostFromFrame(frame) 74 function extractHostFromFrame(frame)
75 { 75 {
76 for (; frame; frame = frame.parent) 76 for (; frame; frame = frame.parent)
77 { 77 {
78 let hostname = getDecodedHostname(frame.url); 78 let hostname = getDecodedHostname(frame.url);
79 if (hostname) 79 if (hostname)
80 return hostname; 80 return hostname;
81 } 81 }
82 82
83 return ""; 83 return "";
84 } 84 }
85 exports.extractHostFromFrame = extractHostFromFrame; 85 exports.extractHostFromFrame = extractHostFromFrame;
86 86
87 /** 87 /**
88 * Converts a URL object into a string. For HTTP(S) URLs 88 * Converts a URL object into a string. For HTTP(S) URLs
89 * the hostname gets IDN-decoded and the hash is stripped. 89 * the hostname gets IDN-decoded and the hash is stripped.
90 * 90 *
91 * @param {URL} [url] 91 * @param {URL} url
92 * @return {string} 92 * @return {string}
93 */ 93 */
94 function stringifyURL(url) 94 function stringifyURL(url)
95 { 95 {
96 let protocol = url.protocol; 96 let protocol = url.protocol;
97 let href = url.href; 97 let href = url.href;
98 98
99 if (protocol == "http:" || protocol == "https:") 99 if (protocol == "http:" || protocol == "https:")
100 { 100 {
101 let hostname = url.hostname; 101 let hostname = url.hostname;
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 141
142 if (cutoff <= 0) 142 if (cutoff <= 0)
143 return hostname; 143 return hostname;
144 144
145 return bits.slice(cutoff).join("."); 145 return bits.slice(cutoff).join(".");
146 } 146 }
147 147
148 /** 148 /**
149 * Checks whether the request's origin is different from the document's origin. 149 * Checks whether the request's origin is different from the document's origin.
150 * 150 *
151 * @param {URL} [url] The request URL 151 * @param {URL} url The request URL
152 * @param {string} [documentHost] The IDN-decoded hostname of the document 152 * @param {string} documentHost The IDN-decoded hostname of the document
153 * @return {Boolean} 153 * @return {Boolean}
154 */ 154 */
155 function isThirdParty(url, documentHost) 155 function isThirdParty(url, documentHost)
156 { 156 {
157 let requestHost = getDecodedHostname(url).replace(/\.+$/, ""); 157 let requestHost = getDecodedHostname(url).replace(/\.+$/, "");
158 documentHost = documentHost.replace(/\.+$/, ""); 158 documentHost = documentHost.replace(/\.+$/, "");
159 159
160 if (requestHost == documentHost) 160 if (requestHost == documentHost)
161 return false; 161 return false;
162 162
163 if (!isDomain(requestHost) || !isDomain(documentHost)) 163 if (!isDomain(requestHost) || !isDomain(documentHost))
164 return true; 164 return true;
165 165
166 return getBaseDomain(requestHost) != getBaseDomain(documentHost); 166 return getBaseDomain(requestHost) != getBaseDomain(documentHost);
167 } 167 }
168 exports.isThirdParty = isThirdParty; 168 exports.isThirdParty = isThirdParty;
OLDNEW
« no previous file with comments | « lib/icon.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld