This commit is contained in:
gorhill 2015-03-23 15:19:17 -04:00
parent 4a07482d46
commit cc3f33ef9a
3 changed files with 23 additions and 18 deletions

View File

@ -448,26 +448,27 @@ var pageStoreJunkyardMax = 10;
/******************************************************************************/ /******************************************************************************/
var PageStore = function(tabId, pageURL) { var PageStore = function(tabId, rawURL, pageURL) {
this.init(tabId, pageURL); this.init(tabId, rawURL, pageURL);
}; };
/******************************************************************************/ /******************************************************************************/
PageStore.factory = function(tabId, pageURL) { PageStore.factory = function(tabId, rawURL, pageURL) {
var entry = pageStoreJunkyard.pop(); var entry = pageStoreJunkyard.pop();
if ( entry === undefined ) { if ( entry === undefined ) {
entry = new PageStore(tabId, pageURL); entry = new PageStore(tabId, rawURL, pageURL);
} else { } else {
entry.init(tabId, pageURL); entry.init(tabId, rawURL, pageURL);
} }
return entry; return entry;
}; };
/******************************************************************************/ /******************************************************************************/
PageStore.prototype.init = function(tabId, pageURL) { PageStore.prototype.init = function(tabId, rawURL, pageURL) {
this.tabId = tabId; this.tabId = tabId;
this.rawURL = rawURL;
this.pageURL = pageURL; this.pageURL = pageURL;
this.pageHostname = µb.URI.hostnameFromURI(pageURL); this.pageHostname = µb.URI.hostnameFromURI(pageURL);
@ -507,7 +508,7 @@ PageStore.prototype.init = function(tabId, pageURL) {
/******************************************************************************/ /******************************************************************************/
PageStore.prototype.reuse = function(pageURL, context) { PageStore.prototype.reuse = function(rawURL, pageURL, context) {
// We can't do this: when force refreshing a page, the page store data // We can't do this: when force refreshing a page, the page store data
// needs to be reset // needs to be reset
//if ( pageURL === this.pageURL ) { //if ( pageURL === this.pageURL ) {
@ -520,6 +521,7 @@ PageStore.prototype.reuse = function(pageURL, context) {
// video thumbnail would not work, because the frame hierarchy structure // video thumbnail would not work, because the frame hierarchy structure
// was flushed from memory, while not really being flushed on the page. // was flushed from memory, while not really being flushed on the page.
if ( context === 'tabUpdated' ) { if ( context === 'tabUpdated' ) {
this.rawURL = rawURL;
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.pageHostname; this.pageDomain = µb.URI.domainFromHostname(this.pageHostname) || this.pageHostname;
@ -535,7 +537,7 @@ PageStore.prototype.reuse = function(pageURL, context) {
// A new page is completely reloaded from scratch, reset all. // A new page is completely reloaded from scratch, reset all.
this.disposeFrameStores(); this.disposeFrameStores();
this.netFilteringCache = this.netFilteringCache.dispose(); this.netFilteringCache = this.netFilteringCache.dispose();
this.init(this.tabId, pageURL); this.init(this.tabId, rawURL, pageURL);
return this; return this;
}; };
@ -548,7 +550,7 @@ PageStore.prototype.dispose = function() {
// need to release the memory taken by these, which can amount to // need to release the memory taken by these, which can amount to
// sizeable enough chunks (especially requests, through the request URL // sizeable enough chunks (especially requests, through the request URL
// used as a key). // used as a key).
this.pageURL = this.rawURL = this.pageURL =
this.pageHostname = this.pageDomain = this.pageHostname = this.pageDomain =
this.rootHostname = this.rootDomain = this.rootHostname = this.rootDomain =
this.requestURL = this.requestHostname = this.requestType = ''; this.requestURL = this.requestHostname = this.requestType = '';
@ -594,8 +596,13 @@ PageStore.prototype.setFrame = function(frameId, frameURL) {
/******************************************************************************/ /******************************************************************************/
PageStore.prototype.getNetFilteringSwitch = function() { PageStore.prototype.getNetFilteringSwitch = function() {
// https://github.com/gorhill/uBlock/issues/1078
// Use both the raw and normalized URLs.
if ( this.netFilteringReadTime < µb.netWhitelistModifyTime ) { if ( this.netFilteringReadTime < µb.netWhitelistModifyTime ) {
this.netFiltering = µb.getNetFilteringSwitch(this.pageURL); this.netFiltering = µb.getNetFilteringSwitch(this.pageURL);
if ( this.netFiltering && this.rawURL !== this.pageURL ) {
this.netFiltering = µb.getNetFilteringSwitch(this.rawURL);
}
this.netFilteringReadTime = Date.now(); this.netFilteringReadTime = Date.now();
} }
return this.netFiltering; return this.netFiltering;

View File

@ -198,7 +198,7 @@ vAPI.tabs.registerListeners();
// Tab is not bound // Tab is not bound
if ( !pageStore ) { if ( !pageStore ) {
return this.pageStores[tabId] = this.PageStore.factory(tabId, normalURL); return this.pageStores[tabId] = this.PageStore.factory(tabId, pageURL, normalURL);
} }
// https://github.com/gorhill/uBlock/issues/516 // https://github.com/gorhill/uBlock/issues/516
@ -210,7 +210,7 @@ vAPI.tabs.registerListeners();
// Rebind according to context. We rebind even if the URL did not change, // Rebind according to context. We rebind even if the URL did not change,
// as maybe the tab was force-reloaded, in which case the page stats must // as maybe the tab was force-reloaded, in which case the page stats must
// be all reset. // be all reset.
pageStore.reuse(normalURL, context); pageStore.reuse(pageURL, normalURL, context);
return pageStore; return pageStore;
}; };
@ -248,6 +248,7 @@ vAPI.tabs.registerListeners();
µb.pageStores[vAPI.noTabId] = µb.PageStore.factory( µb.pageStores[vAPI.noTabId] = µb.PageStore.factory(
vAPI.noTabId, vAPI.noTabId,
'',
µb.normalizePageURL(vAPI.noTabId) µb.normalizePageURL(vAPI.noTabId)
); );

View File

@ -66,18 +66,16 @@ var matchWhitelistDirective = function(url, hostname, directive) {
µBlock.getNetFilteringSwitch = function(url) { µBlock.getNetFilteringSwitch = function(url) {
var netWhitelist = this.netWhitelist; var netWhitelist = this.netWhitelist;
var buckets, i; var buckets, i, pos;
var pos = url.indexOf('#'); var targetHostname = this.URI.hostnameFromURI(url);
var targetURL = pos !== -1 ? url.slice(0, pos) : url;
var targetHostname = this.URI.hostnameFromURI(targetURL);
var key = targetHostname; var key = targetHostname;
for (;;) { for (;;) {
if ( netWhitelist.hasOwnProperty(key) ) { if ( netWhitelist.hasOwnProperty(key) ) {
buckets = netWhitelist[key]; buckets = netWhitelist[key];
i = buckets.length; i = buckets.length;
while ( i-- ) { while ( i-- ) {
if ( matchWhitelistDirective(targetURL, targetHostname, buckets[i]) ) { if ( matchWhitelistDirective(url, targetHostname, buckets[i]) ) {
// console.log('"%s" matche url "%s"', buckets[i], targetURL); // console.log('"%s" matche url "%s"', buckets[i], url);
return false; return false;
} }
} }
@ -286,7 +284,6 @@ var matchWhitelistDirective = function(url, hostname, directive) {
/******************************************************************************/ /******************************************************************************/
µBlock.toggleFirewallRule = function(details) { µBlock.toggleFirewallRule = function(details) {
var changed = false;
if ( details.action !== 0 ) { if ( details.action !== 0 ) {
this.sessionFirewall.setCellZ(details.srcHostname, details.desHostname, details.requestType, details.action); this.sessionFirewall.setCellZ(details.srcHostname, details.desHostname, details.requestType, details.action);
} else { } else {