Skip to content

Loading…

Whitelist directives must override strict blocking #1229

Merged
merged 2 commits into from

2 participants

@gorhill

No description provided.

@chrisaljoudi chrisaljoudi merged commit b0eed4a into chrisaljoudi:master

1 check passed

Details continuous-integration/travis-ci/pr The Travis CI build passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 98 additions and 20 deletions.
  1. +3 −0 platform/chromium/vapi-client.js
  2. +76 −15 src/js/contentscript-end.js
  3. +13 −4 src/js/messaging.js
  4. +6 −1 src/js/traffic.js
View
3 platform/chromium/vapi-client.js
@@ -150,6 +150,9 @@ vAPI.messaging = {
},
close: function() {
delete vAPI.messaging.channels[this.channelName];
+ if ( Object.keys(vAPI.messaging.channels).length === 0 ) {
+ vAPI.messaging.close();
+ }
}
};
View
91 src/js/contentscript-end.js
@@ -57,9 +57,35 @@ if ( vAPI.contentscriptEndInjected ) {
vAPI.contentscriptEndInjected = true;
/******************************************************************************/
+/******************************************************************************/
+
+var shutdownJobs = (function() {
+ var jobs = [];
+
+ return {
+ add: function(job) {
+ jobs.push(job);
+ },
+ exec: function() {
+ //console.debug('Shutting down...');
+ var job;
+ while ( job = jobs.pop() ) {
+ job();
+ }
+ }
+ };
+})();
+
+/******************************************************************************/
+/******************************************************************************/
var messager = vAPI.messaging.channel('contentscript-end.js');
+// https://github.com/gorhill/uMatrix/issues/144
+shutdownJobs.add(function() {
+ messager.close();
+});
+
/******************************************************************************/
// https://github.com/chrisaljoudi/uBlock/issues/789
@@ -119,7 +145,14 @@ var uBlockCollapser = (function() {
this.collapse = false;
};
- var onProcessed = function(requests) {
+ var onProcessed = function(response) {
+ // https://github.com/gorhill/uMatrix/issues/144
+ if ( response.shutdown ) {
+ shutdownJobs.exec();
+ return;
+ }
+
+ var requests = response.result;
if ( requests === null || Array.isArray(requests) === false ) {
return;
}
@@ -314,24 +347,32 @@ var uBlockCollapser = (function() {
firstRetrieveHandler = null;
// These are sent only once
- if ( response ) {
- if ( response.highGenerics ) {
- highGenerics = response.highGenerics;
+ var result = response && response.result;
+ if ( result ) {
+ if ( result.highGenerics ) {
+ highGenerics = result.highGenerics;
}
- if ( response.donthide ) {
- processLowGenerics(response.donthide, nullArray);
+ if ( result.donthide ) {
+ processLowGenerics(result.donthide, nullArray);
}
}
nextRetrieveHandler(response);
};
- var nextRetrieveHandler = function(selectors) {
+ var nextRetrieveHandler = function(response) {
+ // https://github.com/gorhill/uMatrix/issues/144
+ if ( response && response.shutdown ) {
+ shutdownJobs.exec();
+ return;
+ }
+
//var tStart = timer.now();
//console.debug('µBlock> contextNodes = %o', contextNodes);
+ var result = response && response.result;
var hideSelectors = [];
- if ( selectors && selectors.hide.length ) {
- processLowGenerics(selectors.hide, hideSelectors);
+ if ( result && result.hide.length ) {
+ processLowGenerics(result.hide, hideSelectors);
}
if ( highGenerics ) {
if ( highGenerics.hideLowCount ) {
@@ -688,6 +729,14 @@ var uBlockCollapser = (function() {
childList: true,
subtree: true
});
+
+ // https://github.com/gorhill/uMatrix/issues/144
+ shutdownJobs.add(function() {
+ treeObserver.disconnect();
+ if ( addedNodeListsTimer !== null ) {
+ clearTimeout(addedNodeListsTimer);
+ }
+ });
})();
/******************************************************************************/
@@ -700,12 +749,19 @@ var uBlockCollapser = (function() {
// - Elements dynamically added to the page
// - Elements which resource URL changes
-var onResourceFailed = function(ev) {
- //console.debug('onResourceFailed(%o)', ev);
- uBlockCollapser.add(ev.target);
- uBlockCollapser.process();
-};
-document.addEventListener('error', onResourceFailed, true);
+(function() {
+ var onResourceFailed = function(ev) {
+ //console.debug('onResourceFailed(%o)', ev);
+ uBlockCollapser.add(ev.target);
+ uBlockCollapser.process();
+ };
+ document.addEventListener('error', onResourceFailed, true);
+
+ // https://github.com/gorhill/uMatrix/issues/144
+ shutdownJobs.add(function() {
+ document.removeEventListener('error', onResourceFailed, true);
+ });
+})();
/******************************************************************************/
/******************************************************************************/
@@ -764,6 +820,11 @@ document.addEventListener('error', onResourceFailed, true);
};
window.addEventListener('contextmenu', onContextMenu, true);
+
+ // https://github.com/gorhill/uMatrix/issues/144
+ shutdownJobs.add(function() {
+ document.removeEventListener('contextmenu', onContextMenu, true);
+ });
})();
/******************************************************************************/
View
17 src/js/messaging.js
@@ -496,9 +496,12 @@ var onMessage = function(details, sender, callback) {
switch ( details.what ) {
case 'retrieveGenericCosmeticSelectors':
- if ( pageStore && pageStore.getGenericCosmeticFilteringSwitch()
- && (!frameStore || frameStore.getNetFilteringSwitch()) ) {
- response = µb.cosmeticFilteringEngine.retrieveGenericSelectors(details);
+ response = {
+ shutdown: !pageStore || !pageStore.getNetFilteringSwitch() || (frameStore && !frameStore.getNetFilteringSwitch()),
+ result: null
+ };
+ if(pageStore && pageStore.getGenericCosmeticFilteringSwitch()) {
+ response.result = µb.cosmeticFilteringEngine.retrieveGenericSelectors(details);
}
break;
@@ -508,7 +511,13 @@ var onMessage = function(details, sender, callback) {
// Evaluate many requests
case 'filterRequests':
- response = filterRequests(pageStore, details);
+ response = {
+ shutdown: !pageStore || !pageStore.getNetFilteringSwitch(),
+ result: null
+ };
+ if(pageStore) {
+ response.result = filterRequests(pageStore, details);
+ }
break;
default:
View
7 src/js/traffic.js
@@ -199,6 +199,11 @@ var onBeforeRootFrameRequest = function(details) {
var result = '';
+ // If the site is whitelisted, disregard strict blocking
+ if ( µb.getNetFilteringSwitch(requestURL) === false ) {
+ result = 'ua:whitelisted';
+ }
+
// Permanently unrestricted?
if ( result === '' && µb.hnSwitches.evaluateZ('dontBlockDoc', requestHostname) ) {
result = 'ua:dontBlockDoc true';
@@ -217,7 +222,7 @@ var onBeforeRootFrameRequest = function(details) {
}
// Filtering
- if ( result === '' && µb.getNetFilteringSwitch(requestURL) ) {
+ if ( result === '' ) {
result = µb.staticNetFilteringEngine.matchString(context);
// https://github.com/chrisaljoudi/uBlock/issues/1128
// Do not block if the match begins after the hostname.
Something went wrong with that request. Please try again.