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

Delta Between Two Patch Sets: lib/url.js

Issue 5564089086509056: Issue 1801 - Use URL objects to process URLs in the background page (Closed)
Left Patch Set: Created Jan. 25, 2015, 1:18 p.m.
Right Patch Set: Rebased and addressed comments Created Feb. 11, 2015, 5:06 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « lib/basedomain.js ('k') | lib/whitelisting.js » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
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)
kzar 2015/01/26 10:27:38 Took me a second to grok this loop, wouldn't a whi
Sebastian Noack 2015/01/26 10:38:39 I think this a typical case for-lops exist for, to
kzar 2015/01/26 17:19:05 Hmm well I guess it's subjective which form is eas
Sebastian Noack 2015/01/26 17:26:31 As long as you don't consider for-loops generally
Wladimir Palant 2015/02/11 13:45:45 I think I wrote the for loop in the original code,
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
(...skipping 12 matching lines...) Expand all
99 99
100 let host = getDecodedHostname(url); 100 let host = getDecodedHostname(url);
101 if (url.port) 101 if (url.port)
102 host += ":" + url.port; 102 host += ":" + url.port;
103 return protocol + "//" + host + url.pathname + url.search; 103 return protocol + "//" + host + url.pathname + url.search;
104 } 104 }
105 exports.stringifyURL = stringifyURL; 105 exports.stringifyURL = stringifyURL;
106 106
107 function isDomain(hostname) 107 function isDomain(hostname)
108 { 108 {
109 return /[^\d.]/.test(hostname) && hostname.indexOf(":") == -1; 109 // No hostname or IPv4 address, also considering hexadecimal octets.
Wladimir Palant 2015/02/09 12:54:29 new URL("http://0x5bec7a38/").hostname - gives you
Sebastian Noack 2015/02/11 10:55:51 Done.
110 if (/^((0x[\da-f]+|\d+)(\.|$))*$/i.test(hostname))
111 return false;
112
113 // IPv6 address. Since there can't be colons in domains, we can
114 // just check whether there are any colons to exclude IPv6 addresses.
115 return hostname.indexOf(":") == -1;
110 } 116 }
111 117
112 function getBaseDomain(hostname) 118 function getBaseDomain(hostname)
113 { 119 {
114 let bits = hostname.split("."); 120 let bits = hostname.split(".");
115 let cutoff = bits.length - 2; 121 let cutoff = bits.length - 2;
116 122
117 for (let i = 0; i < bits.length; i++) 123 for (let i = 0; i < bits.length; i++)
118 { 124 {
119 let offset = publicSuffixes[bits.slice(i).join(".")]; 125 let offset = publicSuffixes[bits.slice(i).join(".")];
(...skipping 25 matching lines...) Expand all
145 151
146 if (requestHost == documentHost) 152 if (requestHost == documentHost)
147 return false; 153 return false;
148 154
149 if (!isDomain(requestHost) || !isDomain(documentHost)) 155 if (!isDomain(requestHost) || !isDomain(documentHost))
150 return true; 156 return true;
151 157
152 return getBaseDomain(requestHost) != getBaseDomain(documentHost); 158 return getBaseDomain(requestHost) != getBaseDomain(documentHost);
153 } 159 }
154 exports.isThirdParty = isThirdParty; 160 exports.isThirdParty = isThirdParty;
LEFTRIGHT

Powered by Google App Engine
This is Rietveld