From 9c2277fccfa97289de964504b4801d6e7d2e30f1 Mon Sep 17 00:00:00 2001 From: gorhill Date: Wed, 4 Feb 2015 12:51:43 -0500 Subject: [PATCH] this fixes #690 --- src/_locales/en/messages.json | 4 +++ src/css/popup.css | 8 ++--- src/js/dynamic-net-filtering.js | 61 ++++++++++++++++++++------------- src/js/messaging.js | 2 ++ src/js/popup.js | 6 ++-- src/popup.html | 1 + 6 files changed, 51 insertions(+), 31 deletions(-) diff --git a/src/_locales/en/messages.json b/src/_locales/en/messages.json index 84666bcdc..31547b90f 100644 --- a/src/_locales/en/messages.json +++ b/src/_locales/en/messages.json @@ -159,6 +159,10 @@ "message":"images", "description":"" }, + "popup3pAnyRulePrompt":{ + "message":"3rd-party", + "description":"" + }, "popupInlineScriptRulePrompt":{ "message":"inline scripts", "description":"" diff --git a/src/css/popup.css b/src/css/popup.css index 0a3a6016d..1af20e3b4 100644 --- a/src/css/popup.css +++ b/src/css/popup.css @@ -85,7 +85,7 @@ p { #switch .fa { color: green; cursor: pointer; - font-size: 96px; + font-size: 108px; margin: 0; } #switch .fa:hover { @@ -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; @@ -261,7 +261,7 @@ body.dirty #refresh:hover { } #actionSelector > span { display: inline-block; - height: 24px; + height: 22px; opacity: 0.2; width: 33.33%; } diff --git a/src/js/dynamic-net-filtering.js b/src/js/dynamic-net-filtering.js index e776f8c93..4ed0b45d0 100644 --- a/src/js/dynamic-net-filtering.js +++ b/src/js/dynamic-net-filtering.js @@ -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 = { @@ -53,7 +54,7 @@ var typeBitOffsets = { '3p-script': 6, '3p-frame': 8, 'image': 10, - '3p-any': 12 + '3p': 12 }; var actionToNameMap = { @@ -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; @@ -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; @@ -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; } } @@ -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'; - } - // Is this a type suitable for dynamic filtering purpose? - if ( supportedDynamicTypes.hasOwnProperty(type) ) { - this.type = type; - this.r = this.evaluateCellZ(srcHostname, '*', type); - if ( this.r !== 0 ) { return this; } + // 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; } } - // 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, specific type + if ( supportedDynamicTypes.hasOwnProperty(type) ) { + if ( this.evaluateCellZ(srcHostname, '*', type) !== 0 ) { return this; } + } + + // Any destination, any party, any type + if ( this.evaluateCellZ(srcHostname, '*', '*') !== 0 ) { return this; } this.type = ''; return this; diff --git a/src/js/messaging.js b/src/js/messaging.js index acb20f92e..b80289d07 100644 --- a/src/js/messaging.js +++ b/src/js/messaging.js @@ -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(); @@ -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(); diff --git a/src/js/popup.js b/src/js/popup.js index 6144b95aa..5e814d430 100644 --- a/src/js/popup.js +++ b/src/js/popup.js @@ -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); diff --git a/src/popup.html b/src/popup.html index 4aa436101..f134cd0ee 100644 --- a/src/popup.html +++ b/src/popup.html @@ -28,6 +28,7 @@
+