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

Side by Side Diff: include.postload.js

Issue 5132310882025472: Issue 704 - Generate protocol-agnostic request blocking filters with "Block element" (Closed)
Patch Set: Addressed comments Created June 28, 2014, 9:42 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 261 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 var elt = currentElement; 272 var elt = currentElement;
273 var url = null; 273 var url = null;
274 if (currentElement.className && currentElement.className == "__adblockplus__ov erlay") 274 if (currentElement.className && currentElement.className == "__adblockplus__ov erlay")
275 { 275 {
276 elt = currentElement.prisoner; 276 elt = currentElement.prisoner;
277 url = currentElement.prisonerURL; 277 url = currentElement.prisonerURL;
278 } 278 }
279 else if (elt.src) 279 else if (elt.src)
280 url = elt.src; 280 url = elt.src;
281 281
282 // Only normalize when the element contains a URL (issue 328.)
283 // The URL is not always normalized, so do it here
284 if (url)
285 url = normalizeURL(relativeToAbsoluteUrl(url));
286
287 // Construct filters. The popup will retrieve these. 282 // Construct filters. The popup will retrieve these.
288 // Only one ID 283 // Only one ID
289 var elementId = elt.id ? elt.id.split(' ').join('') : null; 284 var elementId = elt.id ? elt.id.split(' ').join('') : null;
290 // Can have multiple classes, and there might be extraneous whitespace 285 // Can have multiple classes, and there might be extraneous whitespace
291 var elementClasses = null; 286 var elementClasses = null;
292 if (elt.className) 287 if (elt.className)
293 elementClasses = elt.className.replace(/\s+/g, ' ').replace(/^\s+|\s+$/g, '' ).split(' '); 288 elementClasses = elt.className.replace(/\s+/g, ' ').replace(/^\s+|\s+$/g, '' ).split(' ');
294 289
295 clickHideFilters = new Array(); 290 clickHideFilters = new Array();
296 selectorList = new Array(); 291 selectorList = new Array();
(...skipping 11 matching lines...) Expand all
308 { 303 {
309 var selector = ""; 304 var selector = "";
310 305
311 for (var i = 0; i < elt.classList.length; i++) 306 for (var i = 0; i < elt.classList.length; i++)
312 selector += "." + elt.classList[i].replace(/([^\w-])/g, "\\$1"); 307 selector += "." + elt.classList[i].replace(/([^\w-])/g, "\\$1");
313 308
314 addSelector(selector); 309 addSelector(selector);
315 } 310 }
316 311
317 if (url) 312 if (url)
318 { 313 clickHideFilters.push(normalizeURL(relativeToAbsoluteUrl(url)));
319 clickHideFilters.push(relativeToAbsoluteUrl(url));
320 selectorList.push(elt.localName + '[src="' + url + '"]');
321 }
322 314
323 // restore the original style, before generating the fallback filter that 315 // restore the original style, before generating the fallback filter that
324 // will include the style, and to prevent highlightElements from saving those 316 // will include the style, and to prevent highlightElements from saving those
325 currentElement.style.setProperty("-webkit-box-shadow", currentElement_boxShado w); 317 currentElement.style.setProperty("-webkit-box-shadow", currentElement_boxShado w);
326 currentElement.style.backgroundColor = currentElement_backgroundColor; 318 currentElement.style.backgroundColor = currentElement_backgroundColor;
327 319
328 // as last resort, create a filter based on inline styles 320 // as last resort, create a filter based on inline styles
329 if (clickHideFilters.length == 0 && elt.hasAttribute("style")) 321 if (clickHideFilters.length == 0 && elt.hasAttribute("style"))
330 addSelector(elt.localName + '[style="' + elt.getAttribute("style").replace(/ "/g, '\\"') + '"]'); 322 addSelector(elt.localName + '[style="' + elt.getAttribute("style").replace(/ "/g, '\\"') + '"]');
331 323
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
388 r = r + m[1]; 380 r = r + m[1];
389 } 381 }
390 } 382 }
391 return r; 383 return r;
392 } else { 384 } else {
393 return u; 385 return u;
394 } 386 }
395 } 387 }
396 388
397 // Does some degree of URL normalization 389 // Does some degree of URL normalization
398 function normalizeURL(url) 390 function normalizeURL(url)
Wladimir Palant 2014/09/30 21:27:42 The function name and comment no longer make sense
399 { 391 {
400 var components = url.match(/(.+:\/\/.+?)\/(.*)/); 392 var components = url.match(/(.+:\/\/)(.+?)\/(.*)/);
Wladimir Palant 2014/09/30 21:27:42 This regexp won't work correctly for something lik
401 if(!components) 393 if(!components)
402 return url; 394 return url;
Wladimir Palant 2014/09/30 21:27:42 I guess this would make more sense: return "|"
403 var newPath = removeDotSegments(components[2]); 395 var newPath = removeDotSegments(components[3]);
Wladimir Palant 2014/09/30 21:27:42 Do we still need the "dot removal"? This should be
404 if(newPath.length == 0) 396 if(newPath[0] != "/")
405 return components[1]; 397 newPath = "/" + newPath;
406 if(newPath[0] != '/') 398 return "||" + components[2] + newPath;
407 newPath = '/' + newPath;
408 return components[1] + newPath;
409 } 399 }
410 400
411 // Content scripts are apparently invoked on non-HTML documents, so we have to 401 // Content scripts are apparently invoked on non-HTML documents, so we have to
412 // check for that before doing stuff. |document instanceof HTMLDocument| check 402 // check for that before doing stuff. |document instanceof HTMLDocument| check
413 // will fail on some sites like planet.mozilla.org because WebKit creates 403 // will fail on some sites like planet.mozilla.org because WebKit creates
414 // Document instances for XHTML documents, have to test the root element. 404 // Document instances for XHTML documents, have to test the root element.
415 if (document.documentElement instanceof HTMLElement) 405 if (document.documentElement instanceof HTMLElement)
416 { 406 {
417 // Use a contextmenu handler to save the last element the user right-clicked o n. 407 // Use a contextmenu handler to save the last element the user right-clicked o n.
418 // To make things easier, we actually save the DOM event. 408 // To make things easier, we actually save the DOM event.
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
569 559
570 clickHide_deactivate(); 560 clickHide_deactivate();
571 } 561 }
572 break; 562 break;
573 default: 563 default:
574 sendResponse({}); 564 sendResponse({});
575 break; 565 break;
576 } 566 }
577 }); 567 });
578 } 568 }
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