|
24 | 24 |
|
25 | 25 | /******************************************************************************/ |
26 | 26 |
|
27 | | -(function(){ |
| 27 | +HTTPSB.abpFilters = (function(){ |
28 | 28 |
|
29 | 29 | /******************************************************************************/ |
30 | 30 |
|
@@ -63,7 +63,7 @@ var pageHostname = ''; |
63 | 63 |
|
64 | 64 | var reIgnoreEmpty = /^\s+$/; |
65 | 65 | var reIgnoreComment = /^\[|^!/; |
66 | | -var reHostnameRule = /^[0-9a-z.-]+[0-9a-z]$/; |
| 66 | +var reHostnameRule = /^[0-9a-z][0-9a-z.-]+[0-9a-z]$/; |
67 | 67 | var reHostnameToken = /^[0-9a-z]+/g; |
68 | 68 | var reGoodToken = /[%0-9a-z]{2,}/g; |
69 | 69 |
|
@@ -679,6 +679,9 @@ var FilterContainer = function() { |
679 | 679 | this.allowFilterCount = 0; |
680 | 680 | this.blockFilterCount = 0; |
681 | 681 |
|
| 682 | + // This is for filters which are strictly a 3rd-party hostname |
| 683 | + this.blocked3rdPartyHostnames = new HTTPSB.LiquidDict(); |
| 684 | + |
682 | 685 | // Used during URL matching |
683 | 686 | this.categoryBuckets = new Array(8); |
684 | 687 | this.reAnyToken = /[%0-9a-z]+/g; |
@@ -736,11 +739,18 @@ FilterContainer.prototype.add = function(s) { |
736 | 739 | this.supportedFilterCount += 1; |
737 | 740 |
|
738 | 741 | // Ignore optionless hostname rules, these will be taken care of by HTTPSB. |
739 | | - if ( parsed.hostname && !parsed.fopts && parsed.action === BlockAction && reHostnameRule.test(parsed.f) ) { |
| 742 | + if ( parsed.hostname && parsed.fopts === '' && parsed.action === BlockAction && reHostnameRule.test(parsed.f) ) { |
740 | 743 | return false; |
741 | 744 | } |
742 | 745 |
|
743 | | - if ( this.addFilter(parsed) === false ) { |
| 746 | + // Pure third-party hostnames, use more efficient liquid dict |
| 747 | + var r; |
| 748 | + if ( parsed.hostname && parsed.fopts === 'third-party' && parsed.action === BlockAction && reHostnameRule.test(parsed.f) ) { |
| 749 | + r = this.blocked3rdPartyHostnames.add(parsed.f); |
| 750 | + } else { |
| 751 | + r = this.addFilter(parsed); |
| 752 | + } |
| 753 | + if ( r === false ) { |
744 | 754 | return false; |
745 | 755 | } |
746 | 756 |
|
@@ -848,6 +858,7 @@ FilterContainer.prototype.reset = function() { |
848 | 858 | this.allowFilterCount = 0; |
849 | 859 | this.blockFilterCount = 0; |
850 | 860 | this.categories = {}; |
| 861 | + this.blocked3rdPartyHostnames.reset(); |
851 | 862 | }; |
852 | 863 |
|
853 | 864 | /******************************************************************************/ |
@@ -1048,6 +1059,7 @@ with the new code. |
1048 | 1059 |
|
1049 | 1060 | FilterContainer.prototype.freeze = function() { |
1050 | 1061 | // histogram('allFilters', this.categories); |
| 1062 | + this.blocked3rdPartyHostnames.freeze(); |
1051 | 1063 | }; |
1052 | 1064 |
|
1053 | 1065 | /******************************************************************************/ |
@@ -1151,26 +1163,32 @@ FilterContainer.prototype.matchString = function(pageStats, url, requestType, re |
1151 | 1163 | ThirdParty; |
1152 | 1164 | var domainParty = this.toDomainBits(pageDomain); |
1153 | 1165 | var type = typeNameToTypeValue[requestType]; |
| 1166 | + var categories = this.categories; |
| 1167 | + var categoryBuckets = this.categoryBuckets; |
1154 | 1168 |
|
1155 | 1169 | // This will be used by hostname-based filter |
1156 | 1170 | pageHostname = pageStats.pageHostname; |
1157 | 1171 |
|
1158 | | - var categories = this.categories; |
1159 | | - var categoryBuckets = this.categoryBuckets; |
| 1172 | + var bf = false; |
| 1173 | + if ( party === ThirdParty && this.blocked3rdPartyHostnames.test(requestHostname) ) { |
| 1174 | + bf = '||' + requestHostname + '^$third-party'; |
| 1175 | + } |
1160 | 1176 |
|
1161 | 1177 | // Test against block filters |
1162 | | - categoryBuckets[7] = categories[this.makeCategoryKey(BlockAnyTypeAnyParty)]; |
1163 | | - categoryBuckets[6] = categories[this.makeCategoryKey(BlockAnyType | party)]; |
1164 | | - categoryBuckets[5] = categories[this.makeCategoryKey(BlockAnyTypeOneParty | domainParty)]; |
1165 | | - categoryBuckets[4] = categories[this.makeCategoryKey(BlockAnyTypeOtherParties | domainParty)]; |
1166 | | - categoryBuckets[3] = categories[this.makeCategoryKey(BlockAnyParty | type)]; |
1167 | | - categoryBuckets[2] = categories[this.makeCategoryKey(BlockAction | type | party)]; |
1168 | | - categoryBuckets[1] = categories[this.makeCategoryKey(BlockOneParty | type | domainParty)]; |
1169 | | - categoryBuckets[0] = categories[this.makeCategoryKey(BlockOtherParties | type | domainParty)]; |
1170 | | - |
1171 | | - var bf = this.matchTokens(); |
1172 | | - |
1173 | | - // If there was no block filter, no need to test against allow filters |
| 1178 | + if ( bf === false ) { |
| 1179 | + categoryBuckets[7] = categories[this.makeCategoryKey(BlockAnyTypeAnyParty)]; |
| 1180 | + categoryBuckets[6] = categories[this.makeCategoryKey(BlockAnyType | party)]; |
| 1181 | + categoryBuckets[5] = categories[this.makeCategoryKey(BlockAnyTypeOneParty | domainParty)]; |
| 1182 | + categoryBuckets[4] = categories[this.makeCategoryKey(BlockAnyTypeOtherParties | domainParty)]; |
| 1183 | + categoryBuckets[3] = categories[this.makeCategoryKey(BlockAnyParty | type)]; |
| 1184 | + categoryBuckets[2] = categories[this.makeCategoryKey(BlockAction | type | party)]; |
| 1185 | + categoryBuckets[1] = categories[this.makeCategoryKey(BlockOneParty | type | domainParty)]; |
| 1186 | + categoryBuckets[0] = categories[this.makeCategoryKey(BlockOtherParties | type | domainParty)]; |
| 1187 | + |
| 1188 | + // If there is no block filter, no need to test against allow filters |
| 1189 | + bf = this.matchTokens(); |
| 1190 | + } |
| 1191 | + |
1174 | 1192 | if ( bf === false ) { |
1175 | 1193 | return false; |
1176 | 1194 | } |
@@ -1200,7 +1218,7 @@ FilterContainer.prototype.getFilterCount = function() { |
1200 | 1218 |
|
1201 | 1219 | /******************************************************************************/ |
1202 | 1220 |
|
1203 | | -HTTPSB.abpFilters = new FilterContainer(); |
| 1221 | +return new FilterContainer(); |
1204 | 1222 |
|
1205 | 1223 | /******************************************************************************/ |
1206 | 1224 |
|
|
0 commit comments