ADP and Background Images

Various discussions related to Adblock Plus development
Post Reply
rodrogue
Posts: 4
Joined: Thu Nov 19, 2015 8:06 pm

ADP and Background Images

Post by rodrogue »

I was looking through the source code trying to understand how it works - I'm just not a javascript person.

How does ADP determine which HTML entities actually have a valid background property?

<body background=<url>> = Valid
<span background=<url>> = Not Valid

I seen how it determines the type options $images, $media and what it looks for. Just not sure how it determines which HTML elements the background is valid on.
User avatar
mapx
Posts: 21940
Joined: Thu Jan 06, 2011 2:01 pm

Re: ADP and Background Images

Post by mapx »

Do you have some real example / issue ?
rodrogue
Posts: 4
Joined: Thu Nov 19, 2015 8:06 pm

Re: ADP and Background Images

Post by rodrogue »

I don't have an issue, I'm just trying to understand how it magically knows all elements that have a background element.

For instance I'm looking at the include.preload.js for chrome.

I can see see how it's matching the type options

Code: Select all

var typeMap = {
  "img": "IMAGE",
  "input": "IMAGE",
  "picture": "IMAGE",
  "audio": "MEDIA",
  "video": "MEDIA",
  "frame": "SUBDOCUMENT",
  "iframe": "SUBDOCUMENT",
  "object": "OBJECT",
  "embed": "OBJECT"
};
Then I can see where it's looking for the URLS based on the element

Code: Select all

function getURLsFromElement(element)
{
  var urls;
  switch (element.localName)
  {
    case "object":
      urls = getURLsFromObjectElement(element);
      break;

    case "video":
    case "audio":
    case "picture":
      urls = getURLsFromMediaElement(element);
      break;

    default:
      urls = getURLsFromAttributes(element);
      break;
  }
I can follow the logic a little, but when it comes to backgrounds - I don't see any type of mappings - How does it know that <body> <table> etc are valid tags? and that <span> isn't - I don't see where it's searching to find the background element url, it works great and finds them, I just don't know how..
lewisje
Posts: 2743
Joined: Mon Jun 14, 2010 12:07 pm

Re: ADP and Background Images

Post by lewisje »

I believe that the webRequest API tells ABP what kind of request it was; ABP does not scan the HTML of pages that it blocks ads on to determine what and how to block them.

For Firefox, nsIContentPolicy is similar.
There's a buzzin' in my brain I really can't explain; I think about it before they make me go to bed.
Post Reply