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

Delta Between Two Patch Sets: background.js

Issue 29321504: Issue 2738 - Pass bit masks to matching functions (Closed)
Left Patch Set: Created July 9, 2015, 2:50 p.m.
Right 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:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | dependencies » ('j') | 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 283 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 return {filters: filters, exceptions: exceptions}; 294 return {filters: filters, exceptions: exceptions};
295 } 295 }
296 296
297 ext.onMessage.addListener(function (msg, sender, sendResponse) 297 ext.onMessage.addListener(function (msg, sender, sendResponse)
298 { 298 {
299 switch (msg.type) 299 switch (msg.type)
300 { 300 {
301 case "get-selectors": 301 case "get-selectors":
302 var selectors = []; 302 var selectors = [];
303 303
304 if (!isFrameWhitelisted(sender.page, sender.frame, "DOCUMENT") && 304 if (!isFrameWhitelisted(sender.page, sender.frame,
305 !isFrameWhitelisted(sender.page, sender.frame, "ELEMHIDE")) 305 RegExpFilter.typeMap.DOCUMENT | RegExpFilter.typeM ap.ELEMHIDE))
306 { 306 {
307 var noStyleRules = false; 307 var noStyleRules = false;
308 var host = extractHostFromFrame(sender.frame); 308 var host = extractHostFromFrame(sender.frame);
309 for (var i = 0; i < noStyleRulesHosts.length; i++) 309 for (var i = 0; i < noStyleRulesHosts.length; i++)
310 { 310 {
311 var noStyleHost = noStyleRulesHosts[i]; 311 var noStyleHost = noStyleRulesHosts[i];
312 if (host == noStyleHost || (host.length > noStyleHost.length && 312 if (host == noStyleHost || (host.length > noStyleHost.length &&
313 host.substr(host.length - noStyleHost.leng th - 1) == "." + noStyleHost)) 313 host.substr(host.length - noStyleHost.leng th - 1) == "." + noStyleHost))
314 { 314 {
315 noStyleRules = true; 315 noStyleRules = true;
316 } 316 }
317 } 317 }
318 selectors = ElemHide.getSelectorsForDomain(host, false); 318 selectors = ElemHide.getSelectorsForDomain(host, false);
319 if (noStyleRules) 319 if (noStyleRules)
320 { 320 {
321 selectors = selectors.filter(function(s) 321 selectors = selectors.filter(function(s)
322 { 322 {
323 return !/\[style[\^\$]?=/.test(s); 323 return !/\[style[\^\$]?=/.test(s);
324 }); 324 });
325 } 325 }
326 } 326 }
327 327
328 sendResponse(selectors); 328 sendResponse(selectors);
329 break; 329 break;
330 case "should-collapse": 330 case "should-collapse":
331 if (isFrameWhitelisted(sender.page, sender.frame, "DOCUMENT")) 331 if (isFrameWhitelisted(sender.page, sender.frame, RegExpFilter.typeMap.DOC UMENT))
332 { 332 {
333 sendResponse(false); 333 sendResponse(false);
334 break; 334 break;
335 } 335 }
336 336
337 var typeMask = RegExpFilter.typeMap[msg.mediatype];
337 var documentHost = extractHostFromFrame(sender.frame); 338 var documentHost = extractHostFromFrame(sender.frame);
338 var blocked = false; 339 var blocked = false;
339 340
340 for (var i = 0; i < msg.urls.length; i++) 341 for (var i = 0; i < msg.urls.length; i++)
341 { 342 {
342 var url = new URL(msg.urls[i], msg.baseURL); 343 var url = new URL(msg.urls[i], msg.baseURL);
343 var filter = defaultMatcher.matchesAny( 344 var filter = defaultMatcher.matchesAny(
344 stringifyURL(url), RegExpFilter.toTypeMask(msg.mediatype), 345 stringifyURL(url), typeMask,
Sebastian Noack 2015/07/09 15:28:52 This operation can be done outside of the loop.
kzar 2015/07/12 14:28:00 Done.
345 documentHost, isThirdParty(url, documentHost) 346 documentHost, isThirdParty(url, documentHost)
346 ); 347 );
347 348
348 if (filter instanceof BlockingFilter) 349 if (filter instanceof BlockingFilter)
349 { 350 {
350 if (filter.collapse != null) 351 if (filter.collapse != null)
351 { 352 {
352 sendResponse(filter.collapse); 353 sendResponse(filter.collapse);
353 return; 354 return;
354 } 355 }
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
423 break; 424 break;
424 } 425 }
425 }); 426 });
426 427
427 // update icon when page changes location 428 // update icon when page changes location
428 ext.pages.onLoading.addListener(function(page) 429 ext.pages.onLoading.addListener(function(page)
429 { 430 {
430 page.sendMessage({type: "clickhide-deactivate"}); 431 page.sendMessage({type: "clickhide-deactivate"});
431 refreshIconAndContextMenu(page); 432 refreshIconAndContextMenu(page);
432 }); 433 });
LEFTRIGHT
« no previous file | dependencies » ('j') | Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Toggle Comments ('s')

Powered by Google App Engine
This is Rietveld