Skip to content

Commit c3f206e

Browse files
committed
gorhill#1010: new filter type: "popunder", to explicitly filter popunders
1 parent 2532ca1 commit c3f206e

3 files changed

Lines changed: 16 additions & 9 deletions

File tree

src/js/logger-ui.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ var filterDecompiler = (function() {
172172
6: 'subdocument',
173173
7: 'font',
174174
8: 'other',
175+
11: 'popunder',
175176
12: 'document',
176177
13: 'elemhide',
177178
14: 'inline-script',

src/js/static-net-filtering.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ var typeNameToTypeValue = {
6363
'sub_frame': 6 << 4,
6464
'font': 7 << 4,
6565
'other': 8 << 4,
66+
'popunder': 11 << 4,
6667
'main_frame': 12 << 4,
6768
'cosmetic-filtering': 13 << 4,
6869
'inline-script': 14 << 4,
@@ -79,6 +80,7 @@ var typeValueToTypeName = {
7980
6: 'subdocument',
8081
7: 'font',
8182
8: 'other',
83+
11: 'popunder',
8284
12: 'document',
8385
13: 'cosmetic-filtering',
8486
14: 'inline-script',
@@ -1385,6 +1387,7 @@ FilterParser.prototype.toNormalizedType = {
13851387
'subdocument': 'sub_frame',
13861388
'font': 'font',
13871389
'other': 'other',
1390+
'popunder': 'popunder',
13881391
'document': 'main_frame',
13891392
'elemhide': 'cosmetic-filtering',
13901393
'inline-script': 'inline-script',

src/js/tab.js

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,7 @@ vAPI.tabs.onPopupUpdated = (function() {
516516
// remember whether a popup or popunder was matched.
517517
var context = {};
518518

519-
var popupMatch = function(openerURL, targetURL, clickedURL, popunder) {
519+
var popupMatch = function(openerURL, targetURL, clickedURL, popupType) {
520520
var openerHostname = µb.URI.hostnameFromURI(openerURL);
521521
var openerDomain = µb.URI.domainFromHostname(openerHostname);
522522

@@ -533,7 +533,7 @@ vAPI.tabs.onPopupUpdated = (function() {
533533
if ( openerHostname !== '' ) {
534534
// Check user switch first
535535
if (
536-
popunder !== true &&
536+
popupType !== 'popunder' &&
537537
targetURL !== clickedURL &&
538538
µb.hnSwitches.evaluateZ('no-popups', openerHostname)
539539
) {
@@ -543,9 +543,9 @@ vAPI.tabs.onPopupUpdated = (function() {
543543
// https://github.com/gorhill/uBlock/issues/581
544544
// Take into account popup-specific rules in dynamic URL filtering, OR
545545
// generic allow rules.
546-
µb.sessionURLFiltering.evaluateZ(openerHostname, targetURL, 'popup');
546+
µb.sessionURLFiltering.evaluateZ(openerHostname, targetURL, popupType);
547547
if (
548-
µb.sessionURLFiltering.r === 1 && µb.sessionURLFiltering.type === 'popup' ||
548+
µb.sessionURLFiltering.r === 1 && µb.sessionURLFiltering.type === popupType ||
549549
µb.sessionURLFiltering.r === 2
550550
) {
551551
return µb.sessionURLFiltering.toFilterString();
@@ -555,7 +555,7 @@ vAPI.tabs.onPopupUpdated = (function() {
555555
// Take into account `allow` rules in dynamic filtering: `block` rules
556556
// are ignored, as block rules are not meant to block specific types
557557
// like `popup` (just like with static filters).
558-
µb.sessionFirewall.evaluateCellZY(openerHostname, context.requestHostname, 'popup');
558+
µb.sessionFirewall.evaluateCellZY(openerHostname, context.requestHostname, popupType);
559559
if ( µb.sessionFirewall.r === 2 ) {
560560
return µb.sessionFirewall.toFilterString();
561561
}
@@ -566,7 +566,7 @@ vAPI.tabs.onPopupUpdated = (function() {
566566
// Don't block if uBlock is turned off in popup's context
567567
if (
568568
µb.getNetFilteringSwitch(targetURL) &&
569-
µb.staticNetFilteringEngine.matchStringExactType(context, targetURL, 'popup') !== undefined
569+
µb.staticNetFilteringEngine.matchStringExactType(context, targetURL, popupType) !== undefined
570570
) {
571571
return µb.staticNetFilteringEngine.toResultString(µb.logger.isEnabled());
572572
}
@@ -603,12 +603,15 @@ vAPI.tabs.onPopupUpdated = (function() {
603603
}
604604

605605
// Popup test.
606-
var result = popupMatch(openerURL, targetURL, µb.mouseURL);
606+
var popupType = 'popup';
607+
var result = popupMatch(openerURL, targetURL, µb.mouseURL, popupType);
607608

608609
// Popunder test.
609610
if ( result === '' ) {
610611
var tmp = openerTabId; openerTabId = targetTabId; targetTabId = tmp;
611-
result = popupMatch(targetURL, openerURL, µb.mouseURL, true);
612+
popupType = 'popunder';
613+
result = popupMatch(targetURL, openerURL, µb.mouseURL, popupType);
614+
console.log('vAPI.tabs.onPopupUpdated: %s => %s (%s)', targetURL, openerURL, popupType);
612615
}
613616

614617
// Log only for when there was a hit against an actual filter (allow or block).
@@ -617,7 +620,7 @@ vAPI.tabs.onPopupUpdated = (function() {
617620
openerTabId,
618621
'net',
619622
result,
620-
'popup',
623+
popupType,
621624
context.requestURL,
622625
µb.URI.hostnameFromURI(context.rootURL),
623626
µb.URI.hostnameFromURI(context.rootURL)

0 commit comments

Comments
 (0)