From c3f206e7049a886ba04cd03bafaba205d30b533a Mon Sep 17 00:00:00 2001 From: gorhill Date: Fri, 4 Dec 2015 11:15:09 -0500 Subject: [PATCH] #1010: new filter type: "popunder", to explicitly filter popunders --- src/js/logger-ui.js | 1 + src/js/static-net-filtering.js | 3 +++ src/js/tab.js | 21 ++++++++++++--------- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/js/logger-ui.js b/src/js/logger-ui.js index e93f9a551..db2911252 100644 --- a/src/js/logger-ui.js +++ b/src/js/logger-ui.js @@ -172,6 +172,7 @@ var filterDecompiler = (function() { 6: 'subdocument', 7: 'font', 8: 'other', + 11: 'popunder', 12: 'document', 13: 'elemhide', 14: 'inline-script', diff --git a/src/js/static-net-filtering.js b/src/js/static-net-filtering.js index f5ec6998b..0da57f70a 100644 --- a/src/js/static-net-filtering.js +++ b/src/js/static-net-filtering.js @@ -63,6 +63,7 @@ var typeNameToTypeValue = { 'sub_frame': 6 << 4, 'font': 7 << 4, 'other': 8 << 4, + 'popunder': 11 << 4, 'main_frame': 12 << 4, 'cosmetic-filtering': 13 << 4, 'inline-script': 14 << 4, @@ -79,6 +80,7 @@ var typeValueToTypeName = { 6: 'subdocument', 7: 'font', 8: 'other', + 11: 'popunder', 12: 'document', 13: 'cosmetic-filtering', 14: 'inline-script', @@ -1385,6 +1387,7 @@ FilterParser.prototype.toNormalizedType = { 'subdocument': 'sub_frame', 'font': 'font', 'other': 'other', + 'popunder': 'popunder', 'document': 'main_frame', 'elemhide': 'cosmetic-filtering', 'inline-script': 'inline-script', diff --git a/src/js/tab.js b/src/js/tab.js index 2ab5f9669..5919b72f4 100644 --- a/src/js/tab.js +++ b/src/js/tab.js @@ -516,7 +516,7 @@ vAPI.tabs.onPopupUpdated = (function() { // remember whether a popup or popunder was matched. var context = {}; - var popupMatch = function(openerURL, targetURL, clickedURL, popunder) { + var popupMatch = function(openerURL, targetURL, clickedURL, popupType) { var openerHostname = µb.URI.hostnameFromURI(openerURL); var openerDomain = µb.URI.domainFromHostname(openerHostname); @@ -533,7 +533,7 @@ vAPI.tabs.onPopupUpdated = (function() { if ( openerHostname !== '' ) { // Check user switch first if ( - popunder !== true && + popupType !== 'popunder' && targetURL !== clickedURL && µb.hnSwitches.evaluateZ('no-popups', openerHostname) ) { @@ -543,9 +543,9 @@ vAPI.tabs.onPopupUpdated = (function() { // https://github.com/gorhill/uBlock/issues/581 // Take into account popup-specific rules in dynamic URL filtering, OR // generic allow rules. - µb.sessionURLFiltering.evaluateZ(openerHostname, targetURL, 'popup'); + µb.sessionURLFiltering.evaluateZ(openerHostname, targetURL, popupType); if ( - µb.sessionURLFiltering.r === 1 && µb.sessionURLFiltering.type === 'popup' || + µb.sessionURLFiltering.r === 1 && µb.sessionURLFiltering.type === popupType || µb.sessionURLFiltering.r === 2 ) { return µb.sessionURLFiltering.toFilterString(); @@ -555,7 +555,7 @@ vAPI.tabs.onPopupUpdated = (function() { // Take into account `allow` rules in dynamic filtering: `block` rules // are ignored, as block rules are not meant to block specific types // like `popup` (just like with static filters). - µb.sessionFirewall.evaluateCellZY(openerHostname, context.requestHostname, 'popup'); + µb.sessionFirewall.evaluateCellZY(openerHostname, context.requestHostname, popupType); if ( µb.sessionFirewall.r === 2 ) { return µb.sessionFirewall.toFilterString(); } @@ -566,7 +566,7 @@ vAPI.tabs.onPopupUpdated = (function() { // Don't block if uBlock is turned off in popup's context if ( µb.getNetFilteringSwitch(targetURL) && - µb.staticNetFilteringEngine.matchStringExactType(context, targetURL, 'popup') !== undefined + µb.staticNetFilteringEngine.matchStringExactType(context, targetURL, popupType) !== undefined ) { return µb.staticNetFilteringEngine.toResultString(µb.logger.isEnabled()); } @@ -603,12 +603,15 @@ vAPI.tabs.onPopupUpdated = (function() { } // Popup test. - var result = popupMatch(openerURL, targetURL, µb.mouseURL); + var popupType = 'popup'; + var result = popupMatch(openerURL, targetURL, µb.mouseURL, popupType); // Popunder test. if ( result === '' ) { var tmp = openerTabId; openerTabId = targetTabId; targetTabId = tmp; - result = popupMatch(targetURL, openerURL, µb.mouseURL, true); + popupType = 'popunder'; + result = popupMatch(targetURL, openerURL, µb.mouseURL, popupType); + console.log('vAPI.tabs.onPopupUpdated: %s => %s (%s)', targetURL, openerURL, popupType); } // Log only for when there was a hit against an actual filter (allow or block). @@ -617,7 +620,7 @@ vAPI.tabs.onPopupUpdated = (function() { openerTabId, 'net', result, - 'popup', + popupType, context.requestURL, µb.URI.hostnameFromURI(context.rootURL), µb.URI.hostnameFromURI(context.rootURL)