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; }