From 0cda433ffa0c6824e9d8bae3d53d000b3b1be98b Mon Sep 17 00:00:00 2001 From: gorhill Date: Wed, 30 Jul 2014 01:05:35 -0400 Subject: [PATCH] this will fix #114 if I find cases which justify uncommenting out the code --- js/pagestore.js | 69 +++++++++++++++++++++++++++++++++++++++++++++++-- js/traffic.js | 18 ++++++++++++- 2 files changed, 84 insertions(+), 3 deletions(-) diff --git a/js/pagestore.js b/js/pagestore.js index 2d160b1c5..1d552001e 100644 --- a/js/pagestore.js +++ b/js/pagestore.js @@ -38,10 +38,56 @@ To create a log of net requests /******************************************************************************/ var µb = µBlock; +var frameStoreJunkyard = []; var pageStoreJunkyard = []; /******************************************************************************/ +var frameStoreFactory = function(frameURL) { + var entry = frameStoreJunkyard.pop(); + if ( entry ) { + return entry.init(frameURL); + } + return new FrameStore(frameURL); +}; + +var disposeFrameStores = function(map) { + for ( var k in map ) { + if ( map.hasOwnProperty(k) === false ) { + continue; + } + if ( frameStoreJunkyard.length > 50 ) { + break; + } + frameStoreJunkyard.push(map[k].dispose()); + } + return {}; +}; + +/******************************************************************************/ + +var FrameStore = function(frameURL) { + this.init(frameURL); +}; + +/******************************************************************************/ + +FrameStore.prototype.init = function(frameURL) { + var µburi = µb.URI; + this.pageHostname = µburi.hostnameFromURI(frameURL); + this.pageDomain = µburi.domainFromHostname(this.pageHostname); + return this; +}; + +/******************************************************************************/ + +FrameStore.prototype.dispose = function() { + this.pageHostname = this.pageDomain = ''; + return this; +}; + +/******************************************************************************/ + var pageStoreFactory = function(tabId, pageURL) { var entry = pageStoreJunkyard.pop(); if ( entry ) { @@ -52,9 +98,9 @@ var pageStoreFactory = function(tabId, pageURL) { /******************************************************************************/ -function PageStore(tabId, pageURL) { +var PageStore = function(tabId, pageURL) { this.init(tabId, pageURL); -} +}; /******************************************************************************/ @@ -64,6 +110,7 @@ PageStore.prototype.init = function(tabId, pageURL) { this.pageURL = pageURL; this.pageHostname = µb.URI.hostnameFromURI(pageURL); this.pageDomain = µb.URI.domainFromHostname(this.pageHostname); + this.frames = disposeFrameStores(this.frames); this.perLoadBlockedRequestCount = 0; this.perLoadAllowedRequestCount = 0; this.blockedRequests = {}; @@ -79,6 +126,7 @@ PageStore.prototype.reuse = function(pageURL) { this.pageURL = pageURL; this.pageHostname = µb.URI.hostnameFromURI(pageURL); this.pageDomain = µb.URI.domainFromHostname(this.pageHostname); + this.frames = disposeFrameStores(this.frames); this.perLoadBlockedRequestCount = 0; this.perLoadAllowedRequestCount = 0; this.blockedRequests = {}; @@ -104,6 +152,23 @@ PageStore.prototype.dispose = function() { /******************************************************************************/ +PageStore.prototype.addFrame = function(frameId, frameURL) { + var frameStore = this.frames[frameId]; + if ( frameStore === undefined ) { + this.frames[frameId] = frameStore = frameStoreFactory(frameURL); + //console.debug('µBlock> PageStore.addFrame(%d, "%s")', frameId, frameURL); + } + return frameStore; +}; + +/******************************************************************************/ + +PageStore.prototype.getFrame = function(frameId) { + return this.frames[frameId]; +}; + +/******************************************************************************/ + PageStore.prototype.recordRequest = function(type, url, reason) { var blocked = reason !== false && reason.slice(0, 2) !== '@@'; diff --git a/js/traffic.js b/js/traffic.js index af7131e8c..a1d295bd1 100644 --- a/js/traffic.js +++ b/js/traffic.js @@ -67,9 +67,20 @@ var onBeforeRequest = function(details) { return; } + // https://github.com/gorhill/uBlock/issues/114 + var requestContext = pageStore; + + //var frameStore; + //var frameId = details.frameId; + //if ( frameId > 0 ) { + // if ( frameStore = pageStore.getFrame(frameId) ) { + // requestContext = frameStore; + // } + //} + var reason = false; if ( µb.getNetFilteringSwitch(pageStore.pageHostname) ) { - reason = µb.abpFilters.matchString(pageStore, requestURL, requestType, requestHostname); + reason = µb.abpFilters.matchString(requestContext, requestURL, requestType, requestHostname); } // Record what happened. pageStore.recordRequest(requestType, requestURL, reason); @@ -77,6 +88,11 @@ var onBeforeRequest = function(details) { // Not blocked? if ( reason === false || reason.slice(0, 2) === '@@' ) { //console.debug('µBlock> onBeforeRequest()> ALLOW "%s" (%o)', details.url, details); + + // https://github.com/gorhill/uBlock/issues/114 + //if ( frameId > 0 && frameStore === undefined ) { + // pageStore.addFrame(frameId, requestURL); + //} return; }