Changes between Version 4 and Version 5 of Ticket #4329


Ignore:
Timestamp:
05/20/2017 02:33:15 AM (3 years ago)
Author:
mjethani
Comment:

I had a discussion with Sebastian and Dave and we think we can do better at least with $generichide. I'm updating the description based on this, along with more specific details on how this should work.

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #4329 – Description

    v4 v5  
    11=== Background === 
    2 Currently abp2blocklist completely ignores `$generichide` and `$genericblock` filter options. While we cannot support them properly it might be possible to do something with them, hopefully reducing false positives. Content blocking rules have a limited `unless-domain` trigger field which we could perhaps use for some of our generic rules. 
     2Currently `abp2blocklist` completely ignores `$generichide` and `$genericblock` filter options. While we cannot support them properly it might be possible to do something with them, hopefully reducing false positives. Content blocking rules have a limited `unless-domain` trigger field which we could perhaps use for some of our generic rules. 
    33 
    44=== What to change === 
    5 For `$generichide` and `$genericblock` exception filters take the hostname and put it (and the `www.` subdomain) into the `unless-domain` trigger for any generic blocking/hiding rules which don't already have an `if-domain` trigger. 
     5For `$generichide` exception filters, insert the rules between the generic element hiding rules and the domain-specific element hiding rules. 
     6 
     7The rules should be in the following order: 
     8 
     9 1.  Generic element hiding rules (`url-filter="^https?://", type="css-display-none"`) 
     10 2.  `$generichide` exceptions (`url-filter="<specific_url>", type="ignore-previous-rules"`) 
     11 3.  Domain-specific element hiding rules (`url-filter="^https?://<domain>", type="css-display-none"`) 
     12 4.  Other rules 
     13 5.  Other exceptions 
     14 
     15The following filters: 
     16 
     17{{{ 
     18##.ad 
     19blogspot.com##div.textad 
     20@@||googleblog.blogspot.com^$elemhide 
     21@@||youtube.com^$generichide 
     22}}} 
     23 
     24Should give us the following rules, in this order: 
     25 
     26{{{ 
     27[ 
     28  { 
     29    "trigger": { 
     30      "url-filter": "^https?://", 
     31      "url-filter-is-case-sensitive": true 
     32    }, 
     33    "action": { 
     34      "type": "css-display-none", 
     35      "selector": ".ad" 
     36    } 
     37  }, 
     38  {  
     39    "trigger": { 
     40      "url-filter": "^https?://([^/]+\\.)?youtube\\.com", 
     41      "url-filter-is-case-sensitive": true 
     42    }, 
     43    "action": { 
     44      "type": "ignore-previous-rules" 
     45    } 
     46  }, 
     47  { 
     48    "trigger": { 
     49      "url-filter": "^https?://([^/:]*\\.)?blogspot\\.com[/:]", 
     50      "url-filter-is-case-sensitive": true 
     51    }, 
     52    "action": { 
     53      "type": "css-display-none", 
     54      "selector": "div.textad" 
     55    } 
     56  }, 
     57  { 
     58    "trigger": { 
     59      "url-filter": "^https?://([^/]+\\.)?googleblog\\.blogspot\\.com", 
     60      "url-filter-is-case-sensitive": true 
     61    }, 
     62    "action": { 
     63      "type": "ignore-previous-rules" 
     64    } 
     65  } 
     66] 
     67}}} 
     68 
     69For `$genericblock` exception filters, take the hostname and put it into the `unless-domain` trigger for any generic blocking rules which don't already have an `if-domain` trigger. 
     70 
     71The following filters: 
     72 
     73{{{ 
     74_400x400.jpg|$image,domain=~facebook.com 
     75@@||twitter.com/hello|$genericblock 
     76}}} 
     77 
     78Should give us the following rules: 
     79 
     80{{{ 
     81[ 
     82  { 
     83    "trigger": { 
     84      "url-filter": "^https?://.*_400x400\\.jpg$", 
     85      "resource-type": [ 
     86        "image" 
     87      ], 
     88      "unless-domain": [ 
     89        "*twitter.com", 
     90        "*facebook.com" 
     91      ] 
     92    }, 
     93    "action": { 
     94      "type": "block" 
     95    } 
     96  } 
     97] 
     98}}} 
    699 
    7100=== Notes === 
    8101Limitations: 
    9  - The filter would often match all subdomains, where as the `unless-domain` field can only match the domain itself and any common subdomains we can think of in advance. (Like www. for example.) 
    10  - The `unless-domain` field can not be used when the `if-domain` field is already being used for a rule. 
    11  - See [https://developer.apple.com/library/ios/documentation/Extensions/Conceptual/ContentBlockingRules/CreatingRules/CreatingRules.html#//apple_ref/doc/uid/TP40016265-CH2-SW5 the related docs]. 
    12  
    13 Implementation detail: 
    14 There could be three shared arrays, one for no `$generichide` domains, one for no `$genericblock` domains and one for no `$generichide` or `$genericblock` domains. Then we can simply append domains to those, sharing the reference to the arrays between all rules that need to use them. 
     102 -  [genericblock] Adblock Plus exception filters will match the entire URL, whereas the `unless-domain` trigger will only match the hostname part, which means the rule will whitelist the entire domain instead of just the URL pattern 
     103 -  [generichide] In Adblock Plus filters `$domain` matches the domain of the parent document, whereas the `unless-domain` trigger matches the domain of the top-level document, which means the rule will not whitelist the domain if the document is not the top-level document