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

Delta Between Two Patch Sets: messageResponder.js

Issue 29329677: Issue 2396 - Add CSS property filter message responder (Closed)
Left Patch Set: Created Nov. 3, 2015, 10:12 a.m.
Right Patch Set: Remove specificOnly parameter from getRulesForDomain stub Created Nov. 5, 2015, 3:54 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 | « background.js ('k') | no next file » | 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 12 matching lines...) Expand all
23 var Prefs = require("prefs").Prefs; 23 var Prefs = require("prefs").Prefs;
24 var Utils = require("utils").Utils; 24 var Utils = require("utils").Utils;
25 var FilterStorage = require("filterStorage").FilterStorage; 25 var FilterStorage = require("filterStorage").FilterStorage;
26 var FilterNotifier = require("filterNotifier").FilterNotifier; 26 var FilterNotifier = require("filterNotifier").FilterNotifier;
27 var defaultMatcher = require("matcher").defaultMatcher; 27 var defaultMatcher = require("matcher").defaultMatcher;
28 var CSSRules = require("cssRules").CSSRules; 28 var CSSRules = require("cssRules").CSSRules;
29 29
30 var filterClasses = require("filterClasses"); 30 var filterClasses = require("filterClasses");
31 var Filter = filterClasses.Filter; 31 var Filter = filterClasses.Filter;
32 var BlockingFilter = filterClasses.BlockingFilter; 32 var BlockingFilter = filterClasses.BlockingFilter;
33 var RegExpFilter = filterClasses.RegExpFilter;
33 var Synchronizer = require("synchronizer").Synchronizer; 34 var Synchronizer = require("synchronizer").Synchronizer;
34 35
35 var subscriptionClasses = require("subscriptionClasses"); 36 var subscriptionClasses = require("subscriptionClasses");
36 var Subscription = subscriptionClasses.Subscription; 37 var Subscription = subscriptionClasses.Subscription;
37 var DownloadableSubscription = subscriptionClasses.DownloadableSubscription; 38 var DownloadableSubscription = subscriptionClasses.DownloadableSubscription;
38 var SpecialSubscription = subscriptionClasses.SpecialSubscription; 39 var SpecialSubscription = subscriptionClasses.SpecialSubscription;
39 40
40 function convertObject(keys, obj) 41 function convertObject(keys, obj)
41 { 42 {
42 var result = {}; 43 var result = {};
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 sendMessage("app", "error", [result.error.toString()], sender.page); 189 sendMessage("app", "error", [result.error.toString()], sender.page);
189 else if (result.filter) 190 else if (result.filter)
190 FilterStorage.addFilter(result.filter); 191 FilterStorage.addFilter(result.filter);
191 break; 192 break;
192 case "filters.blocked": 193 case "filters.blocked":
193 var filter = defaultMatcher.matchesAny(message.url, message.requestType, 194 var filter = defaultMatcher.matchesAny(message.url, message.requestType,
194 message.docDomain, message.thirdParty); 195 message.docDomain, message.thirdParty);
195 callback(filter instanceof BlockingFilter); 196 callback(filter instanceof BlockingFilter);
196 break; 197 break;
197 case "filters.get": 198 case "filters.get":
198 if (message.what == "cssproperties" && "domain" in message) 199 if (message.what == "cssproperties")
Thomas Greiner 2015/11/03 10:57:02 This condition allows the following invalid messag
kzar 2015/11/03 14:09:51 Done.
199 { 200 {
200 callback(CSSRules.getRulesForDomain( 201 var filters = [];
Thomas Greiner 2015/11/03 10:57:02 Please avoid forcing everything into a single stat
kzar 2015/11/03 14:09:51 I thought it was pretty readable as it was but fai
Thomas Greiner 2015/11/03 14:26:01 Thanks, I appreciate it. It would've even allowed
kzar 2015/11/03 15:49:49 Done.
201 message.domain, message.specificOnly).map(function(filter) 202 var isFrameWhitelisted = require("whitelisting").isFrameWhitelisted;
Thomas Greiner 2015/11/03 10:57:03 The content script doesn't know whether it's suppo
kzar 2015/11/03 14:09:51 Done.
203
204 if (!isFrameWhitelisted(sender.page, sender.frame,
205 RegExpFilter.typeMap.DOCUMENT |
206 RegExpFilter.typeMap.ELEMHIDE))
207 {
208 filters = CSSRules.getRulesForDomain(sender.frame.url.hostname);
209 filters = filters.map(function(filter)
202 { 210 {
203 return { 211 return {
204 prefix: filter.selectorPrefix, 212 prefix: filter.selectorPrefix,
205 suffix: filter.selectorSuffix, 213 suffix: filter.selectorSuffix,
206 regexp: filter.regexpString() 214 regexp: filter.regexpString
Thomas Greiner 2015/11/03 10:57:03 `CSSPropertyFilter.prototype.regexpString` is a st
kzar 2015/11/03 14:09:51 Whoops good point, Done.
207 }; 215 };
208 }) 216 });
209 ); 217 }
218 callback(filters);
210 break; 219 break;
211 } 220 }
212 221
213 var subscription = Subscription.fromURL(message.subscriptionUrl); 222 var subscription = Subscription.fromURL(message.subscriptionUrl);
214 if (!subscription) 223 if (!subscription)
215 { 224 {
216 callback([]); 225 callback([]);
217 break; 226 break;
218 } 227 }
219 228
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
332 subscription.title = message.title; 341 subscription.title = message.title;
333 subscription.homepage = message.homepage; 342 subscription.homepage = message.homepage;
334 FilterStorage.addSubscription(subscription); 343 FilterStorage.addSubscription(subscription);
335 if (!subscription.lastDownload) 344 if (!subscription.lastDownload)
336 Synchronizer.execute(subscription); 345 Synchronizer.execute(subscription);
337 } 346 }
338 break; 347 break;
339 } 348 }
340 }); 349 });
341 })(this); 350 })(this);
LEFTRIGHT

Powered by Google App Engine
This is Rietveld