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

Side by Side Diff: lib/contentPolicy.js

Issue 29338638: Issue 2401 - Integrate CSS property rule handling in Firefox (Closed)
Patch Set: Addressed comments Created March 30, 2016, 6:41 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/child/main.js ('k') | lib/cssProperties.js » ('j') | 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-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 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 return {allow, collapse, hits}; 138 return {allow, collapse, hits};
139 } 139 }
140 140
141 // Ignore whitelisted schemes 141 // Ignore whitelisted schemes
142 if (!this.isBlockableScheme(location)) 142 if (!this.isBlockableScheme(location))
143 return response(true, false); 143 return response(true, false);
144 144
145 // Interpret unknown types as "other" 145 // Interpret unknown types as "other"
146 contentType = this.contentTypes.get(contentType) || "OTHER"; 146 contentType = this.contentTypes.get(contentType) || "OTHER";
147 147
148 let wndLocation = frames[0].location;
149 let docDomain = getHostname(wndLocation);
150 let match = null;
151 let [sitekey, sitekeyFrame] = getSitekey(frames);
152 let nogeneric = false; 148 let nogeneric = false;
153 if (!match && Prefs.enabled) 149 if (Prefs.enabled)
154 { 150 {
155 let testSitekey = sitekey; 151 let whitelistHit =
156 let testSitekeyFrame = sitekeyFrame; 152 this.isFrameWhitelisted(frames, contentType == "ELEMHIDE");
157 for (let i = 0; i < frames.length; i++) 153 if (whitelistHit)
158 { 154 {
159 let frame = frames[i]; 155 let [frameIndex, matchType, docDomain, thirdParty, location, filter] = w hitelistHit;
160 let testWndLocation = frame.location; 156 addHit(frameIndex, matchType, docDomain, thirdParty, location, filter);
161 let parentWndLocation = frames[Math.min(i + 1, frames.length - 1)].locat ion; 157 if (matchType == "DOCUMENT" || matchType == "ELEMHIDE")
162 let parentDocDomain = getHostname(parentWndLocation);
163
164 let typeMap = RegExpFilter.typeMap.DOCUMENT;
165 if (contentType == "ELEMHIDE")
166 typeMap = typeMap | RegExpFilter.typeMap.ELEMHIDE;
167 let whitelistMatch = defaultMatcher.matchesAny(testWndLocation, typeMap, parentDocDomain, false, testSitekey);
168 if (whitelistMatch instanceof WhitelistFilter)
169 {
170 let whitelistType = (whitelistMatch.contentType & RegExpFilter.typeMap .DOCUMENT) ? "DOCUMENT" : "ELEMHIDE";
171 addHit(i, whitelistType, parentDocDomain, false, testWndLocation,
172 whitelistMatch);
173 return response(true, false); 158 return response(true, false);
174 } 159 else
175
176 let genericType = (contentType == "ELEMHIDE" ? "GENERICHIDE" : "GENERICB LOCK");
177 let nogenericMatch = defaultMatcher.matchesAny(testWndLocation,
178 RegExpFilter.typeMap[genericType], parentDocDomain, false, testSitek ey);
179 if (nogenericMatch instanceof WhitelistFilter)
180 {
181 nogeneric = true; 160 nogeneric = true;
182 addHit(i, genericType, parentDocDomain, false, testWndLocation,
183 nogenericMatch);
184 }
185
186 if (frame == testSitekeyFrame)
187 [testSitekey, testSitekeyFrame] = getSitekey(frames.slice(i + 1));
188 } 161 }
189 } 162 }
190 163
191 if (!match && contentType == "ELEMHIDE") 164 let match = null;
165 let wndLocation = frames[0].location;
166 let docDomain = getHostname(wndLocation);
167 let [sitekey, sitekeyFrame] = getSitekey(frames);
168 if (contentType == "ELEMHIDE")
192 { 169 {
193 match = ElemHide.getFilterByKey(location); 170 match = ElemHide.getFilterByKey(location);
194 location = match.text.replace(/^.*?#/, '#'); 171 location = match.text.replace(/^.*?#/, '#');
195 172
196 if (!match.isActiveOnDomain(docDomain)) 173 if (!match.isActiveOnDomain(docDomain))
197 return response(true, false); 174 return response(true, false);
198 175
199 let exception = ElemHide.getException(match, docDomain); 176 let exception = ElemHide.getException(match, docDomain);
200 if (exception) 177 if (exception)
201 { 178 {
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 { 210 {
234 let match = /^([\w\-]+):/.exec(location); 211 let match = /^([\w\-]+):/.exec(location);
235 scheme = match ? match[1] : null; 212 scheme = match ? match[1] : null;
236 } 213 }
237 else 214 else
238 scheme = location.scheme; 215 scheme = location.scheme;
239 return !this.whitelistSchemes.has(scheme); 216 return !this.whitelistSchemes.has(scheme);
240 }, 217 },
241 218
242 /** 219 /**
243 * Checks whether a page is whitelisted. 220 * Checks whether a top-level window is whitelisted.
244 * @param {String} url 221 * @param {String} url
245 * @param {String} [parentUrl] location of the parent page 222 * URL of the document loaded into the window
246 * @param {String} [sitekey] public key provided on the page 223 * @return {?WhitelistFilter}
247 * @return {Filter} filter that matched the URL or null if not whitelisted 224 * exception rule that matched the URL if any
248 */ 225 */
249 isWhitelisted: function(url, parentUrl, sitekey) 226 isWhitelisted: function(url)
250 { 227 {
251 if (!url) 228 if (!url)
252 return null; 229 return null;
253 230
254 // Do not apply exception rules to schemes on our whitelistschemes list. 231 // Do not apply exception rules to schemes on our whitelistschemes list.
255 if (!this.isBlockableScheme(url)) 232 if (!this.isBlockableScheme(url))
256 return null; 233 return null;
257 234
258 if (!parentUrl)
259 parentUrl = url;
260
261 // Ignore fragment identifier 235 // Ignore fragment identifier
262 let index = url.indexOf("#"); 236 let index = url.indexOf("#");
263 if (index >= 0) 237 if (index >= 0)
264 url = url.substring(0, index); 238 url = url.substring(0, index);
265 239
266 let result = defaultMatcher.matchesAny(url, RegExpFilter.typeMap.DOCUMENT, g etHostname(parentUrl), false, sitekey); 240 let result = defaultMatcher.matchesAny(url, RegExpFilter.typeMap.DOCUMENT,
241 getHostname(url), false, null);
267 return (result instanceof WhitelistFilter ? result : null); 242 return (result instanceof WhitelistFilter ? result : null);
268 }, 243 },
269 244
270 /** 245 /**
246 * Checks whether a frame is whitelisted.
247 * @param {Array} frames
248 * frame structure as returned by getFrames() in child/utils module.
249 * @param {boolean} isElemHide
250 * true if element hiding whitelisting should be considered
251 * @return {?Array}
252 * An array with the hit parameters: frameIndex, contentType, docDomain,
253 * thirdParty, location, filter. Note that the filter could be a
254 * genericblock/generichide exception rule. If nothing matched null is
255 * returned.
256 */
257 isFrameWhitelisted: function(frames, isElemHide)
258 {
259 let [sitekey, sitekeyFrame] = getSitekey(frames);
260 let nogenericHit = null;
261
262 let typeMap = RegExpFilter.typeMap.DOCUMENT;
263 if (isElemHide)
264 typeMap = typeMap | RegExpFilter.typeMap.ELEMHIDE;
265 let genericType = (isElemHide ? "GENERICHIDE" : "GENERICBLOCK");
266
267 for (let i = 0; i < frames.length; i++)
268 {
269 let frame = frames[i];
270 let wndLocation = frame.location;
271 let parentWndLocation = frames[Math.min(i + 1, frames.length - 1)].locatio n;
272 let parentDocDomain = getHostname(parentWndLocation);
273
274 let match = defaultMatcher.matchesAny(wndLocation, typeMap, parentDocDomai n, false, sitekey);
275 if (match instanceof WhitelistFilter)
276 {
277 let whitelistType = (whitelistMatch.contentType & RegExpFilter.typeMap.D OCUMENT) ? "DOCUMENT" : "ELEMHIDE";
278 return [i, whitelistType, parentDocDomain, false, wndLocation, match];
279 }
280
281 if (!nogenericHit)
282 {
283 match = defaultMatcher.matchesAny(wndLocation,
284 RegExpFilter.typeMap[genericType], parentDocDomain, false, sitekey);
285 if (match instanceof WhitelistFilter)
286 nogenericHit = [i, genericType, parentDocDomain, false, wndLocation, m atch];
287 }
288
289 if (frame == sitekeyFrame)
290 [sitekey, sitekeyFrame] = getSitekey(frames.slice(i + 1));
291 }
292
293 return nogenericHit;
294 },
295
296 /**
271 * Deletes nodes that were previously stored with a 297 * Deletes nodes that were previously stored with a
272 * RequestNotifier.storeNodesForEntries() call or similar. 298 * RequestNotifier.storeNodesForEntries() call or similar.
273 * @param {string} id unique ID of the nodes 299 * @param {string} id unique ID of the nodes
274 */ 300 */
275 deleteNodes: function(id) 301 deleteNodes: function(id)
276 { 302 {
277 port.emit("deleteNodes", id); 303 port.emit("deleteNodes", id);
278 }, 304 },
279 305
280 /** 306 /**
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
397 { 423 {
398 // EffectiveTLDService throws on IP addresses, just compare the host name 424 // EffectiveTLDService throws on IP addresses, just compare the host name
399 let host = ""; 425 let host = "";
400 try 426 try
401 { 427 {
402 host = uri.host; 428 host = uri.host;
403 } catch (e) {} 429 } catch (e) {}
404 return host != docDomain; 430 return host != docDomain;
405 } 431 }
406 } 432 }
OLDNEW
« no previous file with comments | « lib/child/main.js ('k') | lib/cssProperties.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld