Adblock plus rule implementation

Source: Internet
Author: User

In the previous article, we talked about adbock plus matching rules, but some rules need other information, rather than simply URL strings.

Such as domain information, such as third-party rules. Currently, only script, image, stylesheet, third-party, and domain rules are supported. script, image, and stylesheet rules are matched by the file extension in the URL string. Third-party, domain is parsed using the kurl class. Therefore, the new filterrule interface is designed as follows:

normal
0

7.8 lbs
0
2

false
false

microsoftinternetexplorer4

# Ifndef filter_h

# Define filter_h

# Include "platformstring. H"

# Include "filtermanager. H"

# Include <WTF/vector. h>

# Include <WTF/hashmap. h>

# Include "kurl. H"

Namespace WebCore {

Class filterrule {

Public:

/*

 FirstManagerYou have already determined that the rule is filtered rather than hidden.

 To@@Start with whitelist,ManagerPriority

 To|At the beginning, the filter does not match the protocol name and is removed.|

 To|Start, remove|Otherwise, add*

 Contain$Type specified rules, remove these strings, and process the type

 To|End, remove|Otherwise, add*

 */

Filterrule (const string & rule );

/*

 Whether to filter. If it is a white list, it should not be filtered if it matches. Otherwise, it should be filtered.

 Type is used to filter onlyAdlbock plusThe type specified in the rule.

 */

Bool shouldfilter (const kurl & mainurl, const
Kurl & URL, filtertype t );

//Whether it is a whitelist

Bool iswhitefilter () {return m_isexception ;}

//Whether to filter by type, such as filtering scripts only. This may require a lot of information and will not be considered for the moment, suchDomainType Filter,

Bool isneedmimetype () {return m_type! = 0 ;}

Const string & getregularfilter () {return
M_refilter ;}

Const string & getwholerule () {return
M_rule ;}

// Inline const stringvector &Constantsforfastsearch () {return constants ;}

Void print ();

PRIVATE:

Bool m_isexception; // start @@//Whitelist

Bool m_ismatchprotocol;

/*

 Adblock rule describe
In regular expression

 */

String m_refilter;

// Stringvector constants;

String m_rule;

/*

 Type options: Determine
Which types of elements a filter can block (or whitelist in case of an exception
Rule). Multiple Type options can be specified to indicate that the filter shocould
Be applied to several types of elements. Possible types are:

 */

Filtertype m_type;

/*

Restriction to third-party/first-party
Requests: if the third-party option is

Specified, the filter is only applied
To requests from a different origin

Than the currently viewed page.
Similarly ,~ Third-party restricts the filter

To requests from the same origin
As the currently viewed page.

*/

Bool m_filterthirdparty;

Bool m_matchfirstparty;

/*

Domain restrictions: the option
Domain = example.com means that the filter

Shocould only be applied on pages
From "example.com" domain. multiple domains

Can be specified using "|" as separator:
With the option

Domain = example.com | example.net
Filter will only be applied on pages from

"Example.com" or "example.net" domains.
If a domain name is preceded

"~", The filter shoshould not be applied
On pages from this domain. For example,

Domain = ~ Example.com means that
Filter shoshould be applied on pages from any

Domain but "example.com" and domain = example.com | ~ Foo.example.com
Restricts

The filter to the "example.com"
Domain With the exception

"Foo.example.com" subdomain.

*/

Vector <string> m_domains;

Vector <string> m_inversedomains;

PRIVATE:

Bool ismatchtype (const kurl & URL, filtertype
T );

Bool ismatchthirdparty (const kurl &
Host, const kurl & other );

Bool ismatchdomains (const kurl & URL );

Bool processdomains (string & Ds );

};

//Hide rules, including##Rules

Class hiderule {

Public:

/*

 Set##The previous string is resolved as a group of domain names, and the subsequent strings are unblocked.CSSSelector.

 */

Hiderule (const string & R );

//Hide applicable rulesDomain. If it is null, it applies to all; otherwise, it applies only to the specifiedDomain

Const stringvector & domains ();

// Example.com ,~ Foo.example.com # *. Worker sor

// *. Specify sorYesSelector

Const string & selector ();

Void print ();

PRIVATE:

String m_sel;

Stringvector m_domains;

};

}

# Endif // filter_h


 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.