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

Side by Side Diff: background.js

Issue 29321504: Issue 2738 - Pass bit masks to matching functions (Closed)
Patch Set: Updated adblockplus dependency Created July 14, 2015, 2:45 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 | « no previous file | dependencies » ('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-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 with(require("filterClasses")) 18 with(require("filterClasses"))
19 { 19 {
20 this.Filter = Filter; 20 this.Filter = Filter;
21 this.BlockingFilter = BlockingFilter; 21 this.BlockingFilter = BlockingFilter;
22 this.WhitelistFilter = WhitelistFilter; 22 this.WhitelistFilter = WhitelistFilter;
23 this.RegExpFilter = RegExpFilter;
23 } 24 }
24 with(require("subscriptionClasses")) 25 with(require("subscriptionClasses"))
25 { 26 {
26 this.Subscription = Subscription; 27 this.Subscription = Subscription;
27 this.DownloadableSubscription = DownloadableSubscription; 28 this.DownloadableSubscription = DownloadableSubscription;
28 this.SpecialSubscription = SpecialSubscription; 29 this.SpecialSubscription = SpecialSubscription;
29 } 30 }
30 with(require("whitelisting")) 31 with(require("whitelisting"))
31 { 32 {
32 this.isPageWhitelisted = isPageWhitelisted; 33 this.isPageWhitelisted = isPageWhitelisted;
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 return {filters: filters, exceptions: exceptions}; 294 return {filters: filters, exceptions: exceptions};
294 } 295 }
295 296
296 ext.onMessage.addListener(function (msg, sender, sendResponse) 297 ext.onMessage.addListener(function (msg, sender, sendResponse)
297 { 298 {
298 switch (msg.type) 299 switch (msg.type)
299 { 300 {
300 case "get-selectors": 301 case "get-selectors":
301 var selectors = []; 302 var selectors = [];
302 303
303 if (!isFrameWhitelisted(sender.page, sender.frame, "DOCUMENT") && 304 if (!isFrameWhitelisted(sender.page, sender.frame,
304 !isFrameWhitelisted(sender.page, sender.frame, "ELEMHIDE")) 305 RegExpFilter.typeMap.DOCUMENT | RegExpFilter.typeM ap.ELEMHIDE))
305 { 306 {
306 var noStyleRules = false; 307 var noStyleRules = false;
307 var host = extractHostFromFrame(sender.frame); 308 var host = extractHostFromFrame(sender.frame);
308 for (var i = 0; i < noStyleRulesHosts.length; i++) 309 for (var i = 0; i < noStyleRulesHosts.length; i++)
309 { 310 {
310 var noStyleHost = noStyleRulesHosts[i]; 311 var noStyleHost = noStyleRulesHosts[i];
311 if (host == noStyleHost || (host.length > noStyleHost.length && 312 if (host == noStyleHost || (host.length > noStyleHost.length &&
312 host.substr(host.length - noStyleHost.leng th - 1) == "." + noStyleHost)) 313 host.substr(host.length - noStyleHost.leng th - 1) == "." + noStyleHost))
313 { 314 {
314 noStyleRules = true; 315 noStyleRules = true;
315 } 316 }
316 } 317 }
317 selectors = ElemHide.getSelectorsForDomain(host, false); 318 selectors = ElemHide.getSelectorsForDomain(host, false);
318 if (noStyleRules) 319 if (noStyleRules)
319 { 320 {
320 selectors = selectors.filter(function(s) 321 selectors = selectors.filter(function(s)
321 { 322 {
322 return !/\[style[\^\$]?=/.test(s); 323 return !/\[style[\^\$]?=/.test(s);
323 }); 324 });
324 } 325 }
325 } 326 }
326 327
327 sendResponse(selectors); 328 sendResponse(selectors);
328 break; 329 break;
329 case "should-collapse": 330 case "should-collapse":
330 if (isFrameWhitelisted(sender.page, sender.frame, "DOCUMENT")) 331 if (isFrameWhitelisted(sender.page, sender.frame, RegExpFilter.typeMap.DOC UMENT))
331 { 332 {
332 sendResponse(false); 333 sendResponse(false);
333 break; 334 break;
334 } 335 }
335 336
337 var typeMask = RegExpFilter.typeMap[msg.mediatype];
336 var documentHost = extractHostFromFrame(sender.frame); 338 var documentHost = extractHostFromFrame(sender.frame);
337 var blocked = false; 339 var blocked = false;
338 340
339 for (var i = 0; i < msg.urls.length; i++) 341 for (var i = 0; i < msg.urls.length; i++)
340 { 342 {
341 var url = new URL(msg.urls[i], msg.baseURL); 343 var url = new URL(msg.urls[i], msg.baseURL);
342 var filter = defaultMatcher.matchesAny( 344 var filter = defaultMatcher.matchesAny(
343 stringifyURL(url), msg.mediatype, 345 stringifyURL(url), typeMask,
344 documentHost, isThirdParty(url, documentHost) 346 documentHost, isThirdParty(url, documentHost)
345 ); 347 );
346 348
347 if (filter instanceof BlockingFilter) 349 if (filter instanceof BlockingFilter)
348 { 350 {
349 if (filter.collapse != null) 351 if (filter.collapse != null)
350 { 352 {
351 sendResponse(filter.collapse); 353 sendResponse(filter.collapse);
352 return; 354 return;
353 } 355 }
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
422 break; 424 break;
423 } 425 }
424 }); 426 });
425 427
426 // update icon when page changes location 428 // update icon when page changes location
427 ext.pages.onLoading.addListener(function(page) 429 ext.pages.onLoading.addListener(function(page)
428 { 430 {
429 page.sendMessage({type: "clickhide-deactivate"}); 431 page.sendMessage({type: "clickhide-deactivate"});
430 refreshIconAndContextMenu(page); 432 refreshIconAndContextMenu(page);
431 }); 433 });
OLDNEW
« no previous file with comments | « no previous file | dependencies » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld