this will fix #114 if I find cases which justify uncommenting out the code

This commit is contained in:
gorhill 2014-07-30 01:05:35 -04:00
parent 8e344c1b55
commit 0cda433ffa
2 changed files with 84 additions and 3 deletions

View File

@ -38,10 +38,56 @@ To create a log of net requests
/******************************************************************************/ /******************************************************************************/
var µb = µBlock; var µb = µBlock;
var frameStoreJunkyard = [];
var pageStoreJunkyard = []; 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 pageStoreFactory = function(tabId, pageURL) {
var entry = pageStoreJunkyard.pop(); var entry = pageStoreJunkyard.pop();
if ( entry ) { if ( entry ) {
@ -52,9 +98,9 @@ var pageStoreFactory = function(tabId, pageURL) {
/******************************************************************************/ /******************************************************************************/
function PageStore(tabId, pageURL) { var PageStore = function(tabId, pageURL) {
this.init(tabId, pageURL); this.init(tabId, pageURL);
} };
/******************************************************************************/ /******************************************************************************/
@ -64,6 +110,7 @@ PageStore.prototype.init = function(tabId, pageURL) {
this.pageURL = pageURL; this.pageURL = pageURL;
this.pageHostname = µb.URI.hostnameFromURI(pageURL); this.pageHostname = µb.URI.hostnameFromURI(pageURL);
this.pageDomain = µb.URI.domainFromHostname(this.pageHostname); this.pageDomain = µb.URI.domainFromHostname(this.pageHostname);
this.frames = disposeFrameStores(this.frames);
this.perLoadBlockedRequestCount = 0; this.perLoadBlockedRequestCount = 0;
this.perLoadAllowedRequestCount = 0; this.perLoadAllowedRequestCount = 0;
this.blockedRequests = {}; this.blockedRequests = {};
@ -79,6 +126,7 @@ PageStore.prototype.reuse = function(pageURL) {
this.pageURL = pageURL; this.pageURL = pageURL;
this.pageHostname = µb.URI.hostnameFromURI(pageURL); this.pageHostname = µb.URI.hostnameFromURI(pageURL);
this.pageDomain = µb.URI.domainFromHostname(this.pageHostname); this.pageDomain = µb.URI.domainFromHostname(this.pageHostname);
this.frames = disposeFrameStores(this.frames);
this.perLoadBlockedRequestCount = 0; this.perLoadBlockedRequestCount = 0;
this.perLoadAllowedRequestCount = 0; this.perLoadAllowedRequestCount = 0;
this.blockedRequests = {}; 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) { PageStore.prototype.recordRequest = function(type, url, reason) {
var blocked = reason !== false && reason.slice(0, 2) !== '@@'; var blocked = reason !== false && reason.slice(0, 2) !== '@@';

View File

@ -67,9 +67,20 @@ var onBeforeRequest = function(details) {
return; 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; var reason = false;
if ( µb.getNetFilteringSwitch(pageStore.pageHostname) ) { if ( µb.getNetFilteringSwitch(pageStore.pageHostname) ) {
reason = µb.abpFilters.matchString(pageStore, requestURL, requestType, requestHostname); reason = µb.abpFilters.matchString(requestContext, requestURL, requestType, requestHostname);
} }
// Record what happened. // Record what happened.
pageStore.recordRequest(requestType, requestURL, reason); pageStore.recordRequest(requestType, requestURL, reason);
@ -77,6 +88,11 @@ var onBeforeRequest = function(details) {
// Not blocked? // Not blocked?
if ( reason === false || reason.slice(0, 2) === '@@' ) { if ( reason === false || reason.slice(0, 2) === '@@' ) {
//console.debug('µBlock> onBeforeRequest()> ALLOW "%s" (%o)', details.url, details); //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; return;
} }