From 6bd6101e6afed46dc3f3fb84905bac8af845c5bc Mon Sep 17 00:00:00 2001 From: gorhill Date: Mon, 6 Oct 2014 22:40:25 -0400 Subject: [PATCH] code review/testing: for dynamic filtering, it makes more sense to consider the top URL for 1st/3rd party status --- js/net-filtering.js | 16 ++++++++-------- js/pagestore.js | 20 ++++++++++++-------- 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/js/net-filtering.js b/js/net-filtering.js index 6a18cfa3a..68680eee9 100644 --- a/js/net-filtering.js +++ b/js/net-filtering.js @@ -1951,16 +1951,16 @@ FilterContainer.prototype.matchStringExactType = function(pageDetails, requestUR FirstParty : ThirdParty; - // This will be used by hostname-based filters - pageHostname = pageDetails.pageHostname || ''; - // Evaluate dynamic filters first. "Block" dynamic filters are always // "important", they override everything else. - var bf = this.matchDynamicFilters(pageHostname, requestType, party === FirstParty); + var bf = this.matchDynamicFilters(pageDetails.rootHostname, requestType, party === FirstParty); if ( bf !== '' && bf.slice(0, 2) !== '@@' ) { return bf; } + // This will be used by hostname-based filters + pageHostname = pageDetails.pageHostname || ''; + var type = typeNameToTypeValue[requestType]; var categories = this.categories; var buckets = this.buckets; @@ -2043,16 +2043,16 @@ FilterContainer.prototype.matchString = function(pageDetails, requestURL, reques } } - // This will be used by hostname-based filters - pageHostname = pageDetails.pageHostname || ''; - // Evaluate dynamic filters first. "Block" dynamic filters are always // "important", they override everything else. - var bf = this.matchDynamicFilters(pageHostname, requestType, party === FirstParty); + var bf = this.matchDynamicFilters(pageDetails.rootHostname, requestType, party === FirstParty); if ( bf !== '' && bf.slice(0, 2) !== '@@' ) { return bf; } + // This will be used by hostname-based filters + pageHostname = pageDetails.pageHostname || ''; + var type = typeNameToTypeValue[requestType]; var categories = this.categories; var buckets = this.buckets; diff --git a/js/pagestore.js b/js/pagestore.js index fc8c36bd7..ddd2940d2 100644 --- a/js/pagestore.js +++ b/js/pagestore.js @@ -219,35 +219,36 @@ var frameStoreJunkyardMax = 50; /******************************************************************************/ -var FrameStore = function(frameURL) { - this.init(frameURL); +var FrameStore = function(rootHostname, frameURL) { + this.init(rootHostname, frameURL); }; /******************************************************************************/ -FrameStore.factory = function(frameURL) { +FrameStore.factory = function(rootHostname, frameURL) { var entry = frameStoreJunkyard.pop(); if ( entry === undefined ) { - entry = new FrameStore(frameURL); + entry = new FrameStore(rootHostname, frameURL); } else { - entry.init(frameURL); + entry.init(rootHostname, frameURL); } return entry; }; /******************************************************************************/ -FrameStore.prototype.init = function(frameURL) { +FrameStore.prototype.init = function(rootHostname, frameURL) { var µburi = µb.URI; this.pageHostname = µburi.hostnameFromURI(frameURL); this.pageDomain = µburi.domainFromHostname(this.pageHostname); + this.rootHostname = rootHostname; return this; }; /******************************************************************************/ FrameStore.prototype.dispose = function() { - this.pageHostname = this.pageDomain = ''; + this.pageHostname = this.pageDomain = this.rootHostname = ''; if ( frameStoreJunkyard.length < frameStoreJunkyardMax ) { frameStoreJunkyard.push(this); } @@ -296,6 +297,7 @@ PageStore.prototype.init = function(tabId, pageURL) { // https://github.com/gorhill/uBlock/issues/185 // Use hostname if no domain can be extracted this.pageDomain = µb.URI.domainFromHostname(this.pageHostname) || this.pageHostname; + this.rootHostname = this.pageHostname; this.frames = {}; this.netFiltering = true; @@ -324,6 +326,7 @@ PageStore.prototype.reuse = function(pageURL, context) { this.pageURL = pageURL; this.pageHostname = µb.URI.hostnameFromURI(pageURL); this.pageDomain = µb.URI.domainFromHostname(this.pageHostname) || this.pageHostname; + this.rootHostname = this.pageHostname; return this; } // A new page is completely reloaded from scratch, reset all. @@ -348,6 +351,7 @@ PageStore.prototype.dispose = function() { this.previousPageURL = ''; this.pageHostname = ''; this.pageDomain = ''; + this.rootHostname = ''; this.disposeFrameStores(); this.netFilteringCache = this.netFilteringCache.dispose(); if ( pageStoreJunkyard.length < pageStoreJunkyardMax ) { @@ -376,7 +380,7 @@ PageStore.prototype.disposeFrameStores = function() { PageStore.prototype.addFrame = function(frameId, frameURL) { var frameStore = this.frames[frameId]; if ( frameStore === undefined ) { - this.frames[frameId] = frameStore = FrameStore.factory(frameURL); + this.frames[frameId] = frameStore = FrameStore.factory(this.rootHostname, frameURL); //console.debug('µBlock> PageStore.addFrame(%d, "%s")', frameId, frameURL); } return frameStore;