From ba31014503133de1038fbf10e9bf1ce6c7b28e85 Mon Sep 17 00:00:00 2001 From: gorhill Date: Thu, 8 Jan 2015 21:04:48 -0500 Subject: [PATCH] support elemhide filter option --- src/js/messaging.js | 2 +- src/js/pagestore.js | 13 +++++++++++++ src/js/static-net-filtering.js | 6 ++++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/js/messaging.js b/src/js/messaging.js index fe19ef1b2..638e2ab8d 100644 --- a/src/js/messaging.js +++ b/src/js/messaging.js @@ -402,7 +402,7 @@ var onMessage = function(details, sender, callback) { switch ( details.what ) { case 'retrieveGenericCosmeticSelectors': - if ( pageStore && pageStore.getNetFilteringSwitch() ) { + if ( pageStore && pageStore.getCosmeticFilteringSwitch() ) { response = µb.cosmeticFilteringEngine.retrieveGenericSelectors(details); } break; diff --git a/src/js/pagestore.js b/src/js/pagestore.js index 3214b57d1..9be222f8f 100644 --- a/src/js/pagestore.js +++ b/src/js/pagestore.js @@ -492,6 +492,12 @@ PageStore.prototype.init = function(tabId, pageURL) { this.skipLocalMirroring = false; this.netFilteringCache = NetFilteringResultCache.factory(); + // Support `elemhide` filter option. Called at this point so the required + // context is all setup at this point. + this.skipCosmeticFiltering = µb.staticNetFilteringEngine + .matchStringExactType(this, pageURL, 'cosmetic-filtering') + .charAt(1) === 'b'; + // Preserve old buffer if there is one already, it may be in use, and // overwritting it would required another read to restart it. if ( this.logBuffer instanceof LogBuffer === false ) { @@ -596,6 +602,13 @@ PageStore.prototype.getNetFilteringSwitch = function() { /******************************************************************************/ +PageStore.prototype.getCosmeticFilteringSwitch = function() { + return this.getNetFilteringSwitch() === false || + this.skipCosmeticFiltering == false; +}; + +/******************************************************************************/ + PageStore.prototype.filterRequest = function(context) { if ( this.getNetFilteringSwitch() === false ) { this.cacheResult(context, ''); diff --git a/src/js/static-net-filtering.js b/src/js/static-net-filtering.js index 3e2647a69..17b92e0b6 100644 --- a/src/js/static-net-filtering.js +++ b/src/js/static-net-filtering.js @@ -64,6 +64,7 @@ var typeNameToTypeValue = { 'xmlhttprequest': 6 << 4, 'sub_frame': 7 << 4, 'other': 8 << 4, +'cosmetic-filtering': 13 << 4, 'inline-script': 14 << 4, 'popup': 15 << 4 }; @@ -1245,6 +1246,11 @@ FilterParser.prototype.parse = function(s) { this.parseOptParty(not); continue; } + if ( opt === 'elemhide' && this.action === AllowAction ) { + this.types.push(typeNameToTypeValue['cosmetic-filtering']); + this.action = BlockAction; + continue; + } if ( this.toNormalizedType.hasOwnProperty(opt) ) { this.parseOptType(opt, not); continue;