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

Side by Side Diff: include.postload.js

Issue 5945877571043328: Issue 705 - Generate element hiding instead request blocking filters for non-HTTP URLs (Closed)
Patch Set: Rebased Created Oct. 23, 2014, 11:15 a.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 | 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 <http://adblockplus.org/>, 2 * This file is part of Adblock Plus <http://adblockplus.org/>,
3 * Copyright (C) 2006-2014 Eyeo GmbH 3 * Copyright (C) 2006-2014 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 363 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 374
375 clickHideFilters = new Array(); 375 clickHideFilters = new Array();
376 selectorList = new Array(); 376 selectorList = new Array();
377 377
378 var addSelector = function(selector) 378 var addSelector = function(selector)
379 { 379 {
380 clickHideFilters.push(document.domain + "##" + selector); 380 clickHideFilters.push(document.domain + "##" + selector);
381 selectorList.push(selector); 381 selectorList.push(selector);
382 }; 382 };
383 383
384 var addSelectorFromAttribute = function(element, attribute)
385 {
386 var value = element.getAttribute(attribute);
387 if (value)
388 addSelector(element.localName + "[" + attribute + '="' + value.replace(/"/ g, '\\"') + '"]');
Wladimir Palant 2014/10/24 17:56:55 This isn't a sufficient escaping approach. First o
Sebastian Noack 2014/10/30 16:36:24 The attribute name is hard-coded in the calling co
389 };
390
384 if (elementId) 391 if (elementId)
385 addSelector("#" + elementId); 392 addSelector("#" + elementId);
386 393
387 if (elementClasses && elementClasses.length > 0) 394 if (elementClasses && elementClasses.length > 0)
388 { 395 {
389 var selector = ""; 396 var selector = "";
390 397
391 for (var i = 0; i < elt.classList.length; i++) 398 for (var i = 0; i < elt.classList.length; i++)
392 selector += "." + elt.classList[i].replace(/([^\w-])/, "\\$1"); 399 selector += "." + elt.classList[i].replace(/([^\w-])/, "\\$1");
393 400
394 addSelector(selector); 401 addSelector(selector);
395 } 402 }
396 403
397 if (url) 404 if (url)
398 { 405 {
399 clickHideFilters.push(url.replace(/^[\w\-]+:\/+(?:www\.)?/, "||")); 406 if (/^https?:/i.test(url))
400 selectorList.push('[src="' + elt.getAttribute("src") + '"]'); 407 {
408 clickHideFilters.push(url.replace(/^[\w\-]+:\/+(?:www\.)?/, "||"));
409 selectorList.push('[src="' + elt.getAttribute("src") + '"]');
410 }
411 else
412 addSelectorFromAttribute(elt, "src");
401 } 413 }
402 414
403 // Show popup 415 // Show popup
404 clickHide_showDialog(e.clientX, e.clientY, clickHideFilters); 416 clickHide_showDialog(e.clientX, e.clientY, clickHideFilters);
405 417
406 // restore the original style, before generating the fallback filter that 418 // restore the original style, before generating the fallback filter that
407 // will include the style, and to prevent highlightElements from saving those 419 // will include the style, and to prevent highlightElements from saving those
408 unhighlightElement(currentElement); 420 unhighlightElement(currentElement);
409 421
410 // as last resort, create a filter based on inline styles 422 // as last resort, create a filter based on inline styles
411 if (clickHideFilters.length == 0 && elt.hasAttribute("style")) 423 if (clickHideFilters.length == 0)
412 addSelector(elt.localName + '[style="' + elt.getAttribute("style").replace(/ "/g, '\\"') + '"]'); 424 addSelectorFromAttribute(elt, "style");
413 425
414 // Highlight the elements specified by selector in yellow 426 // Highlight the elements specified by selector in yellow
415 highlightElements(selectorList.join(",")); 427 highlightElements(selectorList.join(","));
416 // Now, actually highlight the element the user clicked on in red 428 // Now, actually highlight the element the user clicked on in red
417 highlightElement(currentElement, "#fd1708", "#f6a1b5"); 429 highlightElement(currentElement, "#fd1708", "#f6a1b5");
418 430
419 // Make sure the browser doesn't handle this click 431 // Make sure the browser doesn't handle this click
420 e.preventDefault(); 432 e.preventDefault();
421 e.stopPropagation(); 433 e.stopPropagation();
422 } 434 }
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
634 break; 646 break;
635 default: 647 default:
636 sendResponse({}); 648 sendResponse({});
637 break; 649 break;
638 } 650 }
639 }); 651 });
640 652
641 if (window == window.top) 653 if (window == window.top)
642 ext.backgroundPage.sendMessage({type: "report-html-page"}); 654 ext.backgroundPage.sendMessage({type: "report-html-page"});
643 } 655 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld