1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-11-16 23:42:39 +01:00

important fixes: #150 + a case where a tab could still be unbound

This commit is contained in:
gorhill 2015-04-29 12:21:46 -04:00
parent 427659eab2
commit 5205f1474c
6 changed files with 63 additions and 6 deletions

View File

@ -2173,7 +2173,7 @@ vAPI.onLoadAllCompleted = function() {
var tabId = this.tabs.getTabId(tab);
var browser = getBrowserForTab(tab);
µb.tabContextManager.commit(tabId, browser.currentURI.asciiSpec);
µb.tabContextManager.commit(tabId);
µb.bindTabToPageStats(tabId, browser.currentURI.asciiSpec);
browser.messageManager.sendAsyncMessage(
location.host + '-load-completed'

View File

@ -88,7 +88,7 @@ return {
// read-only
systemSettings: {
compiledMagic: 'akjbdyreyxgm',
compiledMagic: 'eopszukpnrct',
selfieMagic: 'spqmeuaftfra'
},

View File

@ -209,6 +209,10 @@ housekeep itself.
if ( vAPI.isBehindTheSceneTabId(this.tabId) ) {
return;
}
var count = this.stack.length;
if ( count !== 0 && this.stack[count - 1] === url ) {
return;
}
this.stack.push(url);
this.update();
};

View File

@ -287,6 +287,9 @@ var onHeadersReceived = function(details) {
return { 'responseHeaders': details.responseHeaders };
};
/******************************************************************************/
var onRootFrameHeadersReceived = function(details) {
var tabId = details.tabId;
var requestURL = details.url;
@ -297,6 +300,8 @@ var onRootFrameHeadersReceived = function(details) {
// ...
if ( headerValue(details.responseHeaders, 'content-disposition').lastIndexOf('attachment', 0) === 0 ) {
µb.tabContextManager.unpush(tabId, requestURL);
} else {
µb.tabContextManager.push(tabId, requestURL);
}
// Lookup the page store associated with this tab id.
@ -304,7 +309,6 @@ var onRootFrameHeadersReceived = function(details) {
if ( !pageStore ) {
pageStore = µb.bindTabToPageStats(tabId, 'beforeRequest');
}
// I can't think of how pageStore could be null at this point.
var context = pageStore.createContextFromPage();
context.requestURL = requestURL + '{inline-script}';

View File

@ -72,10 +72,10 @@ var reIPAddressNaive = /^\d+\.\d+\.\d+\.\d+$|^\[[\da-zA-Z:]+\]$/;
// Accurate tests
// Source.: http://stackoverflow.com/questions/5284147/validating-ipv4-addresses-with-regexp/5284410#5284410
var reIPv4 = /^((25[0-5]|2[0-4]\d|[01]?\d\d?)(\.|$)){4}/;
//var reIPv4 = /^((25[0-5]|2[0-4]\d|[01]?\d\d?)(\.|$)){4}/;
// Source: http://forums.intermapper.com/viewtopic.php?p=1096#1096
var reIPv6 = /^\s*((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f]{1,4}){0,4}:((25[0-5]|2[0-4]\d|1\d\d|[1-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-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))(%.+)?\s*$/;
/******************************************************************************/
@ -366,11 +366,18 @@ var domainCachePrune = function() {
}
};
var domainCacheReset = function() {
domainCache = {};
domainCacheCount = 0;
};
var domainCache = {};
var domainCacheCount = 0;
var domainCacheCountLowWaterMark = 75;
var domainCacheCountHighWaterMark = 100;
psl.onChanged.addListener(domainCacheReset);
/******************************************************************************/
URI.domainFromURI = function(uri) {

View File

@ -33,6 +33,8 @@
;(function(root) {
'use strict';
/******************************************************************************/
var exceptions = {};
@ -45,6 +47,8 @@ var selfieMagic = 'iscjsfsaolnm';
var cutoffLength = 256;
var mustPunycode = /[^a-z0-9.-]/;
var onChangedListeners = [];
/******************************************************************************/
// In the context of this code, a domain is defined as:
@ -234,6 +238,7 @@ function parse(text, toAscii) {
}
crystallize(exceptions);
crystallize(rules);
callListeners(onChangedListeners);
}
/******************************************************************************/
@ -302,11 +307,47 @@ function fromSelfie(selfie) {
}
rules = selfie.rules;
exceptions = selfie.exceptions;
callListeners(onChangedListeners);
return true;
}
/******************************************************************************/
var addListener = function(listeners, callback) {
if ( typeof callback !== 'function' ) {
return;
}
if ( listeners.indexOf(callback) === -1 ) {
listeners.push(callback);
}
};
var removeListener = function(listeners, callback) {
var pos = listeners.indexOf(callback);
if ( pos !== -1 ) {
listeners.splice(pos, 1);
}
};
var callListeners = function(listeners) {
for ( var i = 0; i < listeners.length; i++ ) {
listeners[i]();
}
};
/******************************************************************************/
var onChanged = {
addListener: function(callback) {
addListener(onChangedListeners, callback);
},
removeListener: function(callback) {
removeListener(onChangedListeners, callback);
}
};
/******************************************************************************/
// Public API
root = root || window;
@ -317,7 +358,8 @@ root.publicSuffixList = {
'getDomain': getDomain,
'getPublicSuffix': getPublicSuffix,
'toSelfie': toSelfie,
'fromSelfie': fromSelfie
'fromSelfie': fromSelfie,
'onChanged': onChanged
};
/******************************************************************************/