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

Side by Side Diff: messageResponder.js

Issue 29329677: Issue 2396 - Add CSS property filter message responder (Closed)
Patch Set: Avoid breaking the background.html test page Created Nov. 3, 2015, 4:16 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 | « background.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
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 14 * You should have received a copy of the GNU General Public License
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */ 16 */
17 17
18 (function(global) 18 (function(global)
19 { 19 {
20 if (!global.ext) 20 if (!global.ext)
21 global.ext = require("ext_background"); 21 global.ext = require("ext_background");
22 22
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 28 var CSSRules = require("cssRules").CSSRules;
29
29 var filterClasses = require("filterClasses"); 30 var filterClasses = require("filterClasses");
30 var Filter = filterClasses.Filter; 31 var Filter = filterClasses.Filter;
31 var BlockingFilter = filterClasses.BlockingFilter; 32 var BlockingFilter = filterClasses.BlockingFilter;
33 var RegExpFilter = filterClasses.RegExpFilter;
32 var Synchronizer = require("synchronizer").Synchronizer; 34 var Synchronizer = require("synchronizer").Synchronizer;
33 35
34 var subscriptionClasses = require("subscriptionClasses"); 36 var subscriptionClasses = require("subscriptionClasses");
35 var Subscription = subscriptionClasses.Subscription; 37 var Subscription = subscriptionClasses.Subscription;
36 var DownloadableSubscription = subscriptionClasses.DownloadableSubscription; 38 var DownloadableSubscription = subscriptionClasses.DownloadableSubscription;
37 var SpecialSubscription = subscriptionClasses.SpecialSubscription; 39 var SpecialSubscription = subscriptionClasses.SpecialSubscription;
38 40
39 function convertObject(keys, obj) 41 function convertObject(keys, obj)
40 { 42 {
41 var result = {}; 43 var result = {};
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 sendMessage("app", "error", [result.error.toString()], sender.page); 189 sendMessage("app", "error", [result.error.toString()], sender.page);
188 else if (result.filter) 190 else if (result.filter)
189 FilterStorage.addFilter(result.filter); 191 FilterStorage.addFilter(result.filter);
190 break; 192 break;
191 case "filters.blocked": 193 case "filters.blocked":
192 var filter = defaultMatcher.matchesAny(message.url, message.requestType, 194 var filter = defaultMatcher.matchesAny(message.url, message.requestType,
193 message.docDomain, message.thirdParty); 195 message.docDomain, message.thirdParty);
194 callback(filter instanceof BlockingFilter); 196 callback(filter instanceof BlockingFilter);
195 break; 197 break;
196 case "filters.get": 198 case "filters.get":
199 if (message.what == "cssproperties")
200 {
201 var filters = [];
202 var isFrameWhitelisted = require("whitelisting").isFrameWhitelisted;
203
204 if (message.domain &&
205 !isFrameWhitelisted(sender.page, sender.frame,
206 RegExpFilter.typeMap.DOCUMENT |
207 RegExpFilter.typeMap.ELEMHIDE))
Wladimir Palant 2015/11/05 13:02:13 This is going to be rather problematic in Firefox.
kzar 2015/11/05 15:51:04 Acknowledged.
208 {
209 var specificOnly = isFrameWhitelisted(
210 sender.page, sender.frame, RegExpFilter.typeMap.GENERICHIDE
211 );
Wladimir Palant 2015/11/05 13:02:13 This check makes no sense, CSS property rules are
kzar 2015/11/05 15:51:04 Done.
212 filters = CSSRules.getRulesForDomain(message.domain, specificOnly);
213 filters = filters.map(function(filter)
214 {
215 return {
216 prefix: filter.selectorPrefix,
217 suffix: filter.selectorSuffix,
218 regexp: filter.regexpString
219 };
220 });
221 }
222 callback(filters);
223 break;
224 }
225
197 var subscription = Subscription.fromURL(message.subscriptionUrl); 226 var subscription = Subscription.fromURL(message.subscriptionUrl);
198 if (!subscription) 227 if (!subscription)
199 { 228 {
200 callback([]); 229 callback([]);
201 break; 230 break;
202 } 231 }
203 232
204 callback(subscription.filters.map(convertFilter)); 233 callback(subscription.filters.map(convertFilter));
205 break; 234 break;
206 case "filters.importRaw": 235 case "filters.importRaw":
207 var result = require("filterValidation").parseFilters(message.text); 236 var result = require("filterValidation").parseFilters(message.text);
208 var errors = []; 237 var errors = [];
209 for (var i = 0; i < result.errors.length; i++) 238 for (var i = 0; i < result.errors.length; i++)
210 { 239 {
211 var error = result.errors[i]; 240 var error = result.errors[i];
212 if (error.type != "unexpected-filter-list-header") 241 if (error.type != "unexpected-filter-list-header")
213 errors.push(error.toString()); 242 errors.push(error.toString());
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
316 subscription.title = message.title; 345 subscription.title = message.title;
317 subscription.homepage = message.homepage; 346 subscription.homepage = message.homepage;
318 FilterStorage.addSubscription(subscription); 347 FilterStorage.addSubscription(subscription);
319 if (!subscription.lastDownload) 348 if (!subscription.lastDownload)
320 Synchronizer.execute(subscription); 349 Synchronizer.execute(subscription);
321 } 350 }
322 break; 351 break;
323 } 352 }
324 }); 353 });
325 })(this); 354 })(this);
OLDNEW
« no previous file with comments | « background.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld