From 35106dcd9048db9e60656f77b70c2aeae8217610 Mon Sep 17 00:00:00 2001 From: gorhill Date: Fri, 24 Jul 2015 19:27:23 -0400 Subject: [PATCH] new dynamic rule type: "3p-passive", for css/images --- src/_locales/en/messages.json | 4 +++ src/js/dynamic-net-filtering.js | 55 +++++---------------------------- src/js/messaging.js | 2 ++ src/js/popup.js | 2 +- src/popup.html | 1 + 5 files changed, 15 insertions(+), 49 deletions(-) diff --git a/src/_locales/en/messages.json b/src/_locales/en/messages.json index 798d8df43..5044b413f 100644 --- a/src/_locales/en/messages.json +++ b/src/_locales/en/messages.json @@ -103,6 +103,10 @@ "message":"3rd-party", "description":"" }, + "popup3pPassiveRulePrompt":{ + "message":"3rd-party css/images", + "description":"" + }, "popupInlineScriptRulePrompt":{ "message":"inline scripts", "description":"" diff --git a/src/js/dynamic-net-filtering.js b/src/js/dynamic-net-filtering.js index 2f916165f..774843799 100644 --- a/src/js/dynamic-net-filtering.js +++ b/src/js/dynamic-net-filtering.js @@ -46,7 +46,8 @@ var supportedDynamicTypes = { 'inline-script': true, '1p-script': true, '3p-script': true, - '3p-frame': true + '3p-frame': true, + '3p-passive': true }; var typeBitOffsets = { @@ -56,7 +57,8 @@ var typeBitOffsets = { '3p-script': 6, '3p-frame': 8, 'image': 10, - '3p': 12 + '3p': 12, + '3p-passive': 14 }; var actionToNameMap = { @@ -386,7 +388,9 @@ Matrix.prototype.evaluateCellZY = function(srcHostname, desHostname, type) { // Specific party if ( thirdParty ) { // 3rd-party, specific type - if ( type === 'script' ) { + if ( type === 'image' || type === 'stylesheet' ) { + if ( this.evaluateCellZ(srcHostname, '*', '3p-passive') !== 0 ) { return this; } + } else 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; } @@ -588,51 +592,6 @@ Matrix.prototype.fromString = function(text, append) { /******************************************************************************/ -Matrix.prototype.fromObsoleteSelfie = function(selfie) { - if ( selfie === '' ) { - return ''; - } - var bin = {}; - try { - bin = JSON.parse(selfie); - } catch(e) { - } - var filters = bin.filters; - var bits, val; - for ( var hostname in filters ) { - if ( filters.hasOwnProperty(hostname) === false ) { - continue; - } - bits = filters[hostname]; - val = bits & 3; - if ( val === 1 ) { - this.setCell(hostname, '*', 'inline-script', 1); - } else if ( val === 2 ) { - this.setCell(hostname, '*', 'inline-script', 3); - } - val = (bits >> 2) & 3; - if ( val === 1 ) { - this.setCell(hostname, '*', '1p-script', 1); - } else if ( val === 2 ) { - this.setCell(hostname, '*', '1p-script', 3); - } - val = (bits >> 4) & 3; - if ( val === 1 ) { - this.setCell(hostname, '*', '3p-script', 1); - } else if ( val === 2 ) { - this.setCell(hostname, '*', '3p-script', 3); - } - val = (bits >> 8) & 3; - if ( val === 1 ) { - this.setCell(hostname, '*', '3p-frame', 1); - } else if ( val === 2 ) { - this.setCell(hostname, '*', '3p-frame', 3); - } - } -}; - -/******************************************************************************/ - Matrix.prototype.toSelfie = function() { return { magicId: magicId, diff --git a/src/js/messaging.js b/src/js/messaging.js index 1e22bbf92..eaef2c77b 100644 --- a/src/js/messaging.js +++ b/src/js/messaging.js @@ -245,6 +245,7 @@ var getFirewallRules = function(srcHostname, desHostnames) { r['/ * *'] = df.evaluateCellZY('*', '*', '*').toFilterString(); r['/ * image'] = df.evaluateCellZY('*', '*', 'image').toFilterString(); r['/ * 3p'] = df.evaluateCellZY('*', '*', '3p').toFilterString(); + r['/ * 3p-passive'] = df.evaluateCellZY('*', '*', '3p-passive').toFilterString(); r['/ * inline-script'] = df.evaluateCellZY('*', '*', 'inline-script').toFilterString(); r['/ * 1p-script'] = df.evaluateCellZY('*', '*', '1p-script').toFilterString(); r['/ * 3p-script'] = df.evaluateCellZY('*', '*', '3p-script').toFilterString(); @@ -256,6 +257,7 @@ var getFirewallRules = function(srcHostname, desHostnames) { r['. * *'] = df.evaluateCellZY(srcHostname, '*', '*').toFilterString(); r['. * image'] = df.evaluateCellZY(srcHostname, '*', 'image').toFilterString(); r['. * 3p'] = df.evaluateCellZY(srcHostname, '*', '3p').toFilterString(); + r['. * 3p-passive'] = df.evaluateCellZY(srcHostname, '*', '3p-passive').toFilterString(); r['. * inline-script'] = df.evaluateCellZY(srcHostname, '*', 'inline-script').toFilterString(); r['. * 1p-script'] = df.evaluateCellZY(srcHostname, '*', '1p-script').toFilterString(); r['. * 3p-script'] = df.evaluateCellZY(srcHostname, '*', '3p-script').toFilterString(); diff --git a/src/js/popup.js b/src/js/popup.js index f8a4af7e9..86a2026c4 100644 --- a/src/js/popup.js +++ b/src/js/popup.js @@ -321,7 +321,7 @@ var buildAllFirewallRows = function() { // Remove and reuse all rows: the order may have changed, we can't just // reuse them in-place. - rowsToRecycle = uDom('#firewallContainer > div:nth-of-type(7) ~ div').detach(); + rowsToRecycle = uDom('#firewallContainer > div:nth-of-type(8) ~ div').detach(); var n = allHostnameRows.length; for ( var i = 0; i < n; i++ ) { diff --git a/src/popup.html b/src/popup.html index ef35b5659..cd31225b4 100644 --- a/src/popup.html +++ b/src/popup.html @@ -38,6 +38,7 @@
+