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

Side by Side Diff: lib/contentPolicy.js

Issue 29356078: Issue 524 - Stop using @-moz-document (Closed) Base URL: https://hg.adblockplus.org/adblockplus
Patch Set: Improved comment Created Oct. 6, 2016, 12:24 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 12 matching lines...) Expand all
23 23
24 let {XPCOMUtils} = Cu.import("resource://gre/modules/XPCOMUtils.jsm", {}); 24 let {XPCOMUtils} = Cu.import("resource://gre/modules/XPCOMUtils.jsm", {});
25 let {Services} = Cu.import("resource://gre/modules/Services.jsm", {}); 25 let {Services} = Cu.import("resource://gre/modules/Services.jsm", {});
26 26
27 let {Utils} = require("utils"); 27 let {Utils} = require("utils");
28 let {port} = require("messaging"); 28 let {port} = require("messaging");
29 let {Prefs} = require("prefs"); 29 let {Prefs} = require("prefs");
30 let {FilterStorage} = require("filterStorage"); 30 let {FilterStorage} = require("filterStorage");
31 let {BlockingFilter, WhitelistFilter, RegExpFilter} = require("filterClasses"); 31 let {BlockingFilter, WhitelistFilter, RegExpFilter} = require("filterClasses");
32 let {defaultMatcher} = require("matcher"); 32 let {defaultMatcher} = require("matcher");
33 let {ElemHide} = require("elemHide");
34 33
35 /** 34 /**
36 * Public policy checking functions and auxiliary objects 35 * Public policy checking functions and auxiliary objects
37 * @class 36 * @class
38 */ 37 */
39 var Policy = exports.Policy = 38 var Policy = exports.Policy =
40 { 39 {
41 /** 40 /**
42 * Map of content types reported by Firefox to the respecitve content types 41 * Map of content types reported by Firefox to the respecitve content types
43 * used by Adblock Plus. Other content types are simply mapped to OTHER. 42 * used by Adblock Plus. Other content types are simply mapped to OTHER.
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 onShutdown.add(() => 105 onShutdown.add(() =>
107 { 106 {
108 Utils.styleService.unregisterSheet(collapseStyle, Ci.nsIStyleSheetService. USER_SHEET); 107 Utils.styleService.unregisterSheet(collapseStyle, Ci.nsIStyleSheetService. USER_SHEET);
109 }); 108 });
110 }, 109 },
111 110
112 /** 111 /**
113 * Checks whether a node should be blocked, hides it if necessary 112 * Checks whether a node should be blocked, hides it if necessary
114 * @param {Object} data request data 113 * @param {Object} data request data
115 * @param {String} data.contentType 114 * @param {String} data.contentType
116 * @param {String} data.location location of the request, filter key if conte ntType is ELEMHIDE 115 * @param {String} data.location location of the request
kzar 2016/10/06 13:02:32 FWIW I'm happy to see this change, I remember this
117 * @param {Object[]} data.frames 116 * @param {Object[]} data.frames
118 * @param {Boolean} data.isPrivate true if the request belongs to a private b rowsing window 117 * @param {Boolean} data.isPrivate true if the request belongs to a private b rowsing window
119 * @return {Object} An object containing properties allow, collapse and hits 118 * @return {Object} An object containing properties allow, collapse and hits
120 * indicating how this request should be handled. 119 * indicating how this request should be handled.
121 */ 120 */
122 shouldAllow: function({contentType, location, frames, isPrivate}) 121 shouldAllow: function({contentType, location, frames, isPrivate})
123 { 122 {
124 let hits = []; 123 let hits = [];
125 124
126 function addHit(frameIndex, contentType, docDomain, thirdParty, location, fi lter) 125 function addHit(frameIndex, contentType, docDomain, thirdParty, location, fi lter)
(...skipping 16 matching lines...) Expand all
143 if (!this.isBlockableScheme(location)) 142 if (!this.isBlockableScheme(location))
144 return response(true, false); 143 return response(true, false);
145 144
146 // Interpret unknown types as "other" 145 // Interpret unknown types as "other"
147 contentType = this.contentTypes.get(contentType) || "OTHER"; 146 contentType = this.contentTypes.get(contentType) || "OTHER";
148 147
149 let nogeneric = false; 148 let nogeneric = false;
150 if (Prefs.enabled) 149 if (Prefs.enabled)
151 { 150 {
152 let whitelistHit = 151 let whitelistHit =
153 this.isFrameWhitelisted(frames, contentType == "ELEMHIDE"); 152 this.isFrameWhitelisted(frames, false);
154 if (whitelistHit) 153 if (whitelistHit)
155 { 154 {
156 let [frameIndex, matchType, docDomain, thirdParty, location, filter] = w hitelistHit; 155 let [frameIndex, matchType, docDomain, thirdParty, location, filter] = w hitelistHit;
157 addHit(frameIndex, matchType, docDomain, thirdParty, location, filter); 156 addHit(frameIndex, matchType, docDomain, thirdParty, location, filter);
158 if (matchType == "DOCUMENT" || matchType == "ELEMHIDE") 157 if (matchType == "DOCUMENT")
159 return response(true, false); 158 return response(true, false);
160 else 159 else
161 nogeneric = true; 160 nogeneric = true;
162 } 161 }
163 } 162 }
164 163
165 let match = null; 164 let match = null;
166 let wndLocation = frames[0].location; 165 let wndLocation = frames[0].location;
167 let docDomain = getHostname(wndLocation); 166 let docDomain = getHostname(wndLocation);
168 let [sitekey, sitekeyFrame] = getSitekey(frames); 167 let [sitekey, sitekeyFrame] = getSitekey(frames);
169 if (contentType == "ELEMHIDE")
170 {
171 match = ElemHide.getFilterByKey(location);
172 location = match.text.replace(/^.*?#/, '#');
173 168
174 if (!match.isActiveOnDomain(docDomain)) 169 let thirdParty = isThirdParty(location, docDomain);
175 return response(true, false);
176
177 let exception = ElemHide.getException(match, docDomain);
178 if (exception)
179 {
180 addHit(null, contentType, docDomain, false, location, exception);
181 return response(true, false);
182 }
183
184 if (nogeneric && match.isGeneric())
185 return response(true, false);
186 }
187
188 let thirdParty = (contentType == "ELEMHIDE" ? false : isThirdParty(location, docDomain));
189 let collapse = false; 170 let collapse = false;
190 if (!match && Prefs.enabled && RegExpFilter.typeMap.hasOwnProperty(contentTy pe)) 171 if (!match && Prefs.enabled && RegExpFilter.typeMap.hasOwnProperty(contentTy pe))
191 { 172 {
192 match = defaultMatcher.matchesAny(location, RegExpFilter.typeMap[contentTy pe], 173 match = defaultMatcher.matchesAny(location, RegExpFilter.typeMap[contentTy pe],
193 docDomain, thirdParty, sitekey, nogeneri c); 174 docDomain, thirdParty, sitekey, nogeneri c);
194 if (match instanceof BlockingFilter && !this.nonVisualTypes.has(contentTyp e)) 175 if (match instanceof BlockingFilter && !this.nonVisualTypes.has(contentTyp e))
195 collapse = (match.collapse != null ? match.collapse : !Prefs.fastcollaps e); 176 collapse = (match.collapse != null ? match.collapse : !Prefs.fastcollaps e);
196 } 177 }
197 addHit(null, contentType, docDomain, thirdParty, location, match); 178 addHit(null, contentType, docDomain, thirdParty, location, match);
198 179
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
424 { 405 {
425 // EffectiveTLDService throws on IP addresses, just compare the host name 406 // EffectiveTLDService throws on IP addresses, just compare the host name
426 let host = ""; 407 let host = "";
427 try 408 try
428 { 409 {
429 host = uri.host; 410 host = uri.host;
430 } catch (e) {} 411 } catch (e) {}
431 return host != docDomain; 412 return host != docDomain;
432 } 413 }
433 } 414 }
OLDNEW
« lib/child/elemHide.js ('K') | « lib/child/elemHide.js ('k') | lib/elemHideFF.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld