1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-09-02 17:19:38 +02:00

this foils "speculative pre-connections"

This commit is contained in:
gorhill 2015-08-15 16:00:51 -04:00
parent 5de5074f1c
commit 2d131e8fab

View File

@ -103,61 +103,107 @@ window.addEventListener('unload', function() {
vAPI.browserSettings = { vAPI.browserSettings = {
originalValues: {}, originalValues: {},
rememberOriginalValue: function(branch, setting) { rememberOriginalValue: function(path, setting) {
var key = branch + '.' + setting; var key = path + '.' + setting;
if ( this.originalValues.hasOwnProperty(key) ) { if ( this.originalValues.hasOwnProperty(key) ) {
return; return;
} }
var hasUserValue = false; var hasUserValue;
var branch = Services.prefs.getBranch(path + '.');
try { try {
hasUserValue = Services.prefs.getBranch(branch + '.').prefHasUserValue(setting); hasUserValue = branch.prefHasUserValue(setting);
} catch (ex) { } catch (ex) {
} }
this.originalValues[key] = hasUserValue ? this.getBool(branch, setting) : undefined; if ( hasUserValue !== undefined ) {
this.originalValues[key] = hasUserValue ? this.getValue(path, setting) : undefined;
}
}, },
clear: function(branch, setting) { clear: function(path, setting) {
var key = branch + '.' + setting; var key = path + '.' + setting;
// Value was not overriden -- nothing to restore // Value was not overriden -- nothing to restore
if ( this.originalValues.hasOwnProperty(key) === false ) { if ( this.originalValues.hasOwnProperty(key) === false ) {
return; return;
} }
var value = this.originalValues[key]; var value = this.originalValues[key];
// https://github.com/gorhill/uBlock/issues/292#issuecomment-109621979 // https://github.com/gorhill/uBlock/issues/292#issuecomment-109621979
// Forget the value immediately, it may change outside of // Forget the value immediately, it may change outside of
// uBlock control. // uBlock control.
delete this.originalValues[key]; delete this.originalValues[key];
// Original value was a default one // Original value was a default one
if ( value === undefined ) { if ( value === undefined ) {
try { try {
Services.prefs.getBranch(branch + '.').clearUserPref(setting); Services.prefs.getBranch(path + '.').clearUserPref(setting);
} catch (ex) { } catch (ex) {
} }
return; return;
} }
// Current value is same as original // Current value is same as original
if ( this.getBool(branch, setting) === value ) { if ( this.getValue(path, setting) === value ) {
return; return;
} }
// Reset to original value // Reset to original value
try { try {
Services.prefs.getBranch(branch + '.').setBoolPref(setting, value); this.setValue(path, setting, value);
} catch (ex) { } catch (ex) {
} }
}, },
getBool: function(branch, setting) { getValue: function(path, setting) {
try { var branch = Services.prefs.getBranch(path + '.');
return Services.prefs.getBranch(branch + '.').getBoolPref(setting);
} catch (ex) { // https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIPrefBranch#getPrefType%28%29
var getMethod;
switch ( branch.getPrefType(setting) ) {
// PREF_INT
case 64:
getMethod = 'getIntPref';
break;
// PREF_BOOL
case 128:
getMethod = 'getBoolPref';
break;
default:
break;
} }
if ( getMethod !== undefined ) {
try {
return branch[getMethod](setting);
} catch (ex) {
}
}
return undefined; return undefined;
}, },
setBool: function(branch, setting, value) { setValue: function(path, setting, value) {
try { var branch = Services.prefs.getBranch(path + '.');
Services.prefs.getBranch(branch + '.').setBoolPref(setting, value);
} catch (ex) { var setMethod;
switch ( typeof value ) {
// PREF_INT
case 'number':
setMethod = 'setIntPref';
break;
// PREF_BOOL
case 'boolean':
setMethod = 'setBoolPref';
break;
default:
break;
}
if ( setMethod !== undefined ) {
try {
branch[setMethod](setting, value);
} catch (ex) {
}
} }
}, },
@ -170,13 +216,19 @@ vAPI.browserSettings = {
switch ( setting ) { switch ( setting ) {
case 'prefetching': case 'prefetching':
this.rememberOriginalValue('network', 'prefetch-next'); this.rememberOriginalValue('network', 'prefetch-next');
// http://betanews.com/2015/08/15/firefox-stealthily-loads-webpages-when-you-hover-over-links-heres-how-to-stop-it/
// https://bugzilla.mozilla.org/show_bug.cgi?id=814169
// Sigh.
this.rememberOriginalValue('network.http', 'speculative-parallel-limit');
value = !!details[setting]; value = !!details[setting];
// https://github.com/gorhill/uBlock/issues/292 // https://github.com/gorhill/uBlock/issues/292
// "true" means "do not disable", i.e. leave entry alone // "true" means "do not disable", i.e. leave entry alone
if ( value === true ) { if ( value === true ) {
this.clear('network', 'prefetch-next'); this.clear('network', 'prefetch-next');
this.clear('network.http', 'speculative-parallel-limit');
} else { } else {
this.setBool('network', 'prefetch-next', false); this.setValue('network', 'prefetch-next', false);
this.setValue('network.http', 'speculative-parallel-limit', 0);
} }
break; break;
@ -190,8 +242,8 @@ vAPI.browserSettings = {
this.clear('browser', 'send_pings'); this.clear('browser', 'send_pings');
this.clear('beacon', 'enabled'); this.clear('beacon', 'enabled');
} else { } else {
this.setBool('browser', 'send_pings', false); this.setValue('browser', 'send_pings', false);
this.setBool('beacon', 'enabled', false); this.setValue('beacon', 'enabled', false);
} }
break; break;
@ -201,7 +253,7 @@ vAPI.browserSettings = {
if ( value === true ) { if ( value === true ) {
this.clear('media.peerconnection', 'enabled'); this.clear('media.peerconnection', 'enabled');
} else { } else {
this.setBool('media.peerconnection', 'enabled', false); this.setValue('media.peerconnection', 'enabled', false);
} }
break; break;
@ -2949,8 +3001,10 @@ vAPI.cloud = (function() {
var bin = { var bin = {
'source': options.deviceName || getDefaultDeviceName(), 'source': options.deviceName || getDefaultDeviceName(),
'tstamp': Date.now(), 'tstamp': Date.now(),
'data': data 'data': data,
'size': 0
}; };
bin.size = JSON.stringify(bin).length;
branch.setCharPref(datakey, JSON.stringify(bin)); branch.setCharPref(datakey, JSON.stringify(bin));
if ( typeof callback === 'function' ) { if ( typeof callback === 'function' ) {
callback(); callback();