From afd77a3cef58bc2a047147a43a51e54cb3d10b44 Mon Sep 17 00:00:00 2001 From: gorhill Date: Thu, 22 Oct 2015 09:45:21 -0400 Subject: [PATCH] this fixes #854. Unlike PageStore, TabContext is best placed to keep track of whitelist status --- src/js/pagestore.js | 17 +---------------- src/js/tab.js | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/src/js/pagestore.js b/src/js/pagestore.js index 40975c357..abcd167ef 100644 --- a/src/js/pagestore.js +++ b/src/js/pagestore.js @@ -300,8 +300,6 @@ PageStore.prototype.init = function(tabId) { this.hostnameToCountMap = {}; this.contentLastModified = 0; this.frames = {}; - this.netFiltering = true; - this.netFilteringReadTime = 0; this.perLoadBlockedRequestCount = 0; this.perLoadAllowedRequestCount = 0; this.hiddenElementCount = ''; // Empty string means "unknown" @@ -351,7 +349,6 @@ PageStore.prototype.reuse = function(context) { // As part of https://github.com/chrisaljoudi/uBlock/issues/405 // URL changed, force a re-evaluation of filtering switch this.rawURL = tabContext.rawURL; - this.netFilteringReadTime = 0; return this; } @@ -444,19 +441,7 @@ PageStore.prototype.createContextFromFrameHostname = function(frameHostname) { /******************************************************************************/ PageStore.prototype.getNetFilteringSwitch = function() { - var tabContext = µb.tabContextManager.lookup(this.tabId); - if ( this.netFilteringReadTime > µb.netWhitelistModifyTime ) { - return this.netFiltering; - } - - // https://github.com/chrisaljoudi/uBlock/issues/1078 - // Use both the raw and normalized URLs. - this.netFiltering = µb.getNetFilteringSwitch(tabContext.normalURL); - if ( this.netFiltering && tabContext.rawURL !== tabContext.normalURL ) { - this.netFiltering = µb.getNetFilteringSwitch(tabContext.rawURL); - } - this.netFilteringReadTime = Date.now(); - return this.netFiltering; + return µb.tabContextManager.lookup(this.tabId).getNetFilteringSwitch(); }; /******************************************************************************/ diff --git a/src/js/tab.js b/src/js/tab.js index d7ce86308..6a571a412 100644 --- a/src/js/tab.js +++ b/src/js/tab.js @@ -155,6 +155,8 @@ housekeep itself. this.rootDomain = ''; this.commitTimer = null; this.gcTimer = null; + this.netFiltering = true; + this.netFilteringReadTime = 0; tabContexts[tabId] = this; }; @@ -228,6 +230,7 @@ housekeep itself. // Update just force all properties to be updated to match the most recent // root URL. TabContext.prototype.update = function() { + this.netFilteringReadTime = 0; if ( this.stack.length === 0 ) { this.rawURL = this.normalURL = this.rootHostname = this.rootDomain = ''; return; @@ -291,6 +294,20 @@ housekeep itself. this.update(); }; + TabContext.prototype.getNetFilteringSwitch = function() { + if ( this.netFilteringReadTime > µb.netWhitelistModifyTime ) { + return this.netFiltering; + } + // https://github.com/chrisaljoudi/uBlock/issues/1078 + // Use both the raw and normalized URLs. + this.netFiltering = µb.getNetFilteringSwitch(this.normalURL); + if ( this.netFiltering && this.rawURL !== this.normalURL ) { + this.netFiltering = µb.getNetFilteringSwitch(this.rawURL); + } + this.netFilteringReadTime = Date.now(); + return this.netFiltering; + }; + // These are to be used for the API of the tab context manager. var push = function(tabId, url) {