Skip to content
This repository has been archived by the owner on Sep 9, 2022. It is now read-only.

Commit

Permalink
this fixes #690
Browse files Browse the repository at this point in the history
  • Loading branch information
gorhill committed Feb 4, 2015
1 parent c4ee65b commit 9c2277f
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 29 deletions.
4 changes: 4 additions & 0 deletions src/_locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,10 @@
"message":"images",
"description":""
},
"popup3pAnyRulePrompt":{
"message":"3rd-party",
"description":""
},
"popupInlineScriptRulePrompt":{
"message":"inline scripts",
"description":""
Expand Down
8 changes: 4 additions & 4 deletions src/css/popup.css
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ p {
#switch .fa {
color: green;
cursor: pointer;
font-size: 96px;
font-size: 108px;
margin: 0;
}
#switch .fa:hover {
Expand Down Expand Up @@ -195,8 +195,8 @@ body.dirty #refresh:hover {
-moz-box-sizing: border-box;
color: #000;
display: inline-block;
height: 24px;
line-height: 24px;
height: 22px;
line-height: 22px;
overflow: hidden;
position: relative;
vertical-align: top;
Expand Down Expand Up @@ -261,7 +261,7 @@ body.dirty #refresh:hover {
}
#actionSelector > span {
display: inline-block;
height: 24px;
height: 22px;
opacity: 0.2;
width: 33.33%;
}
Expand Down
57 changes: 35 additions & 22 deletions src/js/dynamic-net-filtering.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,12 @@ var Matrix = function() {
/******************************************************************************/

var supportedDynamicTypes = {
'3p': true,
'image': true,
'inline-script': true,
'1p-script': true,
'3p-script': true,
'3p-frame': true,
'image': true
'3p-frame': true
};

var typeBitOffsets = {
Expand All @@ -53,7 +54,7 @@ var typeBitOffsets = {
'3p-script': 6,
'3p-frame': 8,
'image': 10,
'3p-any': 12
'3p': 12
};

var actionToNameMap = {
Expand Down Expand Up @@ -200,6 +201,9 @@ Matrix.prototype.clearRegisters = function() {
/******************************************************************************/

var is3rdParty = function(srcHostname, desHostname) {
if ( desHostname === '*' ) {
return false;
}
var srcDomain = domainFromHostname(srcHostname);
if ( srcDomain === '' ) {
srcDomain = desHostname;
Expand All @@ -217,6 +221,7 @@ var domainFromHostname = µBlock.URI.domainFromHostname;
/******************************************************************************/

Matrix.prototype.evaluateCellZ = function(srcHostname, desHostname, type) {
this.type = type;
var bitOffset = typeBitOffsets[type];
var s = srcHostname;
var v;
Expand All @@ -226,6 +231,7 @@ Matrix.prototype.evaluateCellZ = function(srcHostname, desHostname, type) {
if ( v !== undefined ) {
v = v >> bitOffset & 3;
if ( v !== 0 ) {
this.r = v;
return v;
}
}
Expand All @@ -235,44 +241,51 @@ Matrix.prototype.evaluateCellZ = function(srcHostname, desHostname, type) {
}
}
// srcHostname is '*' at this point
this.r = 0;
return 0;
};

/******************************************************************************/

Matrix.prototype.evaluateCellZY = function(srcHostname, desHostname, type) {
this.r = 0;
// Precedence: from most specific to least specific

// Specific-destination + any type
this.type = '*';
// Specific-destination, any party, any type
var d = desHostname;
while ( d !== '*' ) {
this.y = d;
this.r = this.evaluateCellZ(srcHostname, d, '*');
if ( this.r !== 0 ) { return this; }
if ( this.evaluateCellZ(srcHostname, d, '*') !== 0 ) { return this; }
d = toBroaderHostname(d);
}

// Any destination + specific-type
var thirdParty = is3rdParty(srcHostname, desHostname);

// Any destination
this.y = '*';

if ( type === 'script' ) {
type = is3rdParty(srcHostname, desHostname) ? '3p-script' : '1p-script';
} else if ( type === 'sub_frame' && is3rdParty(srcHostname, desHostname) ) {
type = '3p-frame';
// Specific party
if ( thirdParty ) {
// 3rd-party, specific type
if ( type === 'script' ) {
if ( this.evaluateCellZ(srcHostname, '*', '3p-script') !== 0 ) { return this; }
} else if ( type === 'sub_frame' ) {
if ( this.evaluateCellZ(srcHostname, '*', '3p-frame') !== 0 ) { return this; }
}
// 3rd-party, any type
if ( this.evaluateCellZ(srcHostname, '*', '3p') !== 0 ) { return this; }

} else if ( type === 'script' ) {
// 1st party, specific type
if ( this.evaluateCellZ(srcHostname, '*', '1p-script') !== 0 ) { return this; }
}
// Is this a type suitable for dynamic filtering purpose?

// Any destination, any party, specific type
if ( supportedDynamicTypes.hasOwnProperty(type) ) {
this.type = type;
this.r = this.evaluateCellZ(srcHostname, '*', type);
if ( this.r !== 0 ) { return this; }
if ( this.evaluateCellZ(srcHostname, '*', type) !== 0 ) { return this; }
}

// https://github.com/gorhill/uBlock/issues/682
// Any destination, any type
this.type = '*';
this.r = this.evaluateCellZ(srcHostname, '*', '*');
if ( this.r !== 0 ) { return this; }
// Any destination, any party, any type
if ( this.evaluateCellZ(srcHostname, '*', '*') !== 0 ) { return this; }

this.type = '';
return this;
Expand Down
2 changes: 2 additions & 0 deletions src/js/messaging.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ var getDynamicFilterRules = function(srcHostname, desHostnames) {
var dFiltering = µb.dynamicNetFilteringEngine;
r['/ * *'] = dFiltering.evaluateCellZY('*', '*', '*').toFilterString();
r['/ * image'] = dFiltering.evaluateCellZY('*', '*', 'image').toFilterString();
r['/ * 3p'] = dFiltering.evaluateCellZY('*', '*', '3p').toFilterString();
r['/ * inline-script'] = dFiltering.evaluateCellZY('*', '*', 'inline-script').toFilterString();
r['/ * 1p-script'] = dFiltering.evaluateCellZY('*', '*', '1p-script').toFilterString();
r['/ * 3p-script'] = dFiltering.evaluateCellZY('*', '*', '3p-script').toFilterString();
Expand All @@ -157,6 +158,7 @@ var getDynamicFilterRules = function(srcHostname, desHostnames) {

r['. * *'] = dFiltering.evaluateCellZY(srcHostname, '*', '*').toFilterString();
r['. * image'] = dFiltering.evaluateCellZY(srcHostname, '*', 'image').toFilterString();
r['. * 3p'] = dFiltering.evaluateCellZY(srcHostname, '*', '3p').toFilterString();
r['. * inline-script'] = dFiltering.evaluateCellZY(srcHostname, '*', 'inline-script').toFilterString();
r['. * 1p-script'] = dFiltering.evaluateCellZY(srcHostname, '*', '1p-script').toFilterString();
r['. * 3p-script'] = dFiltering.evaluateCellZY(srcHostname, '*', '3p-script').toFilterString();
Expand Down
6 changes: 3 additions & 3 deletions src/js/popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,9 @@ var updateDynamicFilterCell = function(scope, des, type, rule) {
var ownRule = false;
var matches = reSrcHostnameFromRule.exec(rule);
if ( matches !== null ) {
ownRule = matches[2] === des &&
matches[3] === type &&
matches[1] === scopeToSrcHostnameMap[scope];
ownRule = (matches[2] !== '*' || matches[3] === type) &&
(matches[2] === des) &&
(matches[1] === scopeToSrcHostnameMap[scope]);
}
cell.toggleClass('ownRule', ownRule);

Expand Down
1 change: 1 addition & 0 deletions src/popup.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
<div id="dynamicFilteringContainer">
<div><span data-i18n="popupAnyRulePrompt"></span><span data-src="/" data-des="*" data-type="*"> </span><span data-src="." data-des="*" data-type="*"></span></div>
<div><span data-i18n="popupImageRulePrompt"></span><span data-src="/" data-des="*" data-type="image"> </span><span data-src="." data-des="*" data-type="image"></span></div>
<div><span data-i18n="popup3pAnyRulePrompt"></span><span data-src="/" data-des="*" data-type="3p"> </span><span data-src="." data-des="*" data-type="3p"></span></div>
<div><span data-i18n="popupInlineScriptRulePrompt"></span><span data-src="/" data-des="*" data-type="inline-script"> </span><span data-src="." data-des="*" data-type="inline-script"> </span></div>
<div><span data-i18n="popup1pScriptRulePrompt"></span><span data-src="/" data-des="*" data-type="1p-script"> </span><span data-src="." data-des="*" data-type="1p-script"> </span></div>
<div><span data-i18n="popup3pScriptRulePrompt"></span><span data-src="/" data-des="*" data-type="3p-script"> </span><span data-src="." data-des="*" data-type="3p-script"> </span></div>
Expand Down

0 comments on commit 9c2277f

Please sign in to comment.