this fixes #7, #36

pull/2/head
Raymond Hill 10 years ago
parent ce6305210c
commit d01ab961b8

@ -439,6 +439,54 @@ var onMessage = function(request, sender, callback) {
/******************************************************************************/
/******************************************************************************/
// privacy.js
(function() {
var onMessage = function(request, sender, callback) {
var µm = µMatrix;
// Async
switch ( request.what ) {
default:
break;
}
// Sync
var response;
switch ( request.what ) {
case 'getPrivacySettings':
response = {
userSettings: µm.userSettings,
matrixSwitches: {
'https-strict': µm.pMatrix.evaluateSwitch('https-strict', '*') === 1,
'ua-spoof': µm.pMatrix.evaluateSwitch('ua-spoof', '*') === 1,
}
};
break;
case 'setMatrixSwitch':
µm.tMatrix.setSwitch(request.switchName, '*', request.state);
if ( µm.pMatrix.setSwitch(request.switchName, '*', request.state) ) {
µm.saveMatrix();
}
break;
default:
return µm.messaging.defaultHandler(request, sender, callback);
}
callback(response);
};
µMatrix.messaging.listen('privacy.js', onMessage);
})();
/******************************************************************************/
/******************************************************************************/
// user-rules.js
(function() {

@ -19,6 +19,8 @@
Home: https://github.com/gorhill/uMatrix
*/
/* global messaging, uDom */
/******************************************************************************/
(function() {
@ -27,7 +29,7 @@
messaging.start('privacy.js');
var cachedUserSettings = {};
var cachedPrivacySettings = {};
/******************************************************************************/
@ -41,8 +43,18 @@ function changeUserSettings(name, value) {
/******************************************************************************/
function changeMatrixSwitch(name, state) {
messaging.tell({
what: 'setMatrixSwitch',
switchName: name,
state: state
});
}
/******************************************************************************/
function onChangeValueHandler(uelem, setting, min, max) {
var oldVal = cachedUserSettings[setting];
var oldVal = cachedPrivacySettings.userSettings[setting];
var newVal = Math.round(parseFloat(uelem.val()));
if ( typeof newVal !== 'number' ) {
newVal = oldVal;
@ -67,33 +79,26 @@ function prepareToDie() {
/******************************************************************************/
var installEventHandlers = function() {
uDom('#delete-unused-session-cookies').on('change', function(){
changeUserSettings('deleteUnusedSessionCookies', this.checked);
uDom('[data-setting-bool]').on('change', function(){
var settingName = this.getAttribute('data-setting-bool');
if ( typeof settingName === 'string' && settingName !== '' ) {
changeUserSettings(settingName, this.checked);
}
});
uDom('[data-matrix-switch]').on('change', function(){
var switchName = this.getAttribute('data-matrix-switch');
if ( typeof switchName === 'string' && switchName !== '' ) {
changeMatrixSwitch(switchName, this.checked);
}
});
uDom('#delete-unused-session-cookies-after').on('change', function(){
onChangeValueHandler(uDom(this), 'deleteUnusedSessionCookiesAfter', 15, 1440);
});
uDom('#delete-blacklisted-cookies').on('change', function(){
changeUserSettings('deleteCookies', this.checked);
});
uDom('#delete-blacklisted-localstorage').on('change', function(){
changeUserSettings('deleteLocalStorage', this.checked);
});
uDom('#clear-browser-cache').on('change', function(){
changeUserSettings('clearBrowserCache', this.checked);
});
uDom('#clear-browser-cache-after').on('change', function(){
onChangeValueHandler(uDom(this), 'clearBrowserCacheAfter', 15, 1440);
});
uDom('#process-referer').on('change', function(){
changeUserSettings('processReferer', this.checked);
});
uDom('#process-hyperlink-auditing').on('change', function(){
changeUserSettings('processHyperlinkAuditing', this.checked);
});
uDom('#spoof-user-agent').on('change', function(){
changeUserSettings('spoofUserAgent', this.checked);
});
uDom('#spoof-user-agent-every').on('change', function(){
onChangeValueHandler(uDom(this), 'spoofUserAgentEvery', 2, 999);
});
@ -108,25 +113,35 @@ var installEventHandlers = function() {
/******************************************************************************/
uDom.onLoad(function() {
var onUserSettingsReceived = function(userSettings) {
var onSettingsReceived = function(privacySettings) {
// Cache copy
cachedUserSettings = userSettings;
cachedPrivacySettings = privacySettings;
var userSettings = privacySettings.userSettings;
var matrixSwitches = privacySettings.matrixSwitches;
uDom('[data-setting-bool]').forEach(function(elem){
var settingName = elem.attr('data-setting-bool');
if ( typeof settingName === 'string' && settingName !== '' ) {
elem.prop('checked', userSettings[settingName] === true);
}
});
uDom('[data-matrix-switch]').forEach(function(elem){
var switchName = elem.attr('data-matrix-switch');
if ( typeof switchName === 'string' && switchName !== '' ) {
elem.prop('checked', matrixSwitches[switchName] === true);
}
});
uDom('#delete-unused-session-cookies').prop('checked', userSettings.deleteUnusedSessionCookies === true);
uDom('#delete-unused-session-cookies-after').val(userSettings.deleteUnusedSessionCookiesAfter);
uDom('#delete-blacklisted-cookies').prop('checked', userSettings.deleteCookies === true);
uDom('#delete-blacklisted-localstorage').prop('checked', userSettings.deleteLocalStorage);
uDom('#clear-browser-cache').prop('checked', userSettings.clearBrowserCache === true);
uDom('#clear-browser-cache-after').val(userSettings.clearBrowserCacheAfter);
uDom('#process-referer').prop('checked', userSettings.processReferer);
uDom('#process-hyperlink-auditing').prop('checked', userSettings.processHyperlinkAuditing);
uDom('#spoof-user-agent').prop('checked', userSettings.spoofUserAgent);
uDom('#spoof-user-agent-every').val(userSettings.spoofUserAgentEvery);
uDom('#spoof-user-agent-with').val(userSettings.spoofUserAgentWith);
installEventHandlers();
};
messaging.ask({ what: 'getUserSettings' }, onUserSettingsReceived);
messaging.ask({ what: 'getPrivacySettings' }, onSettingsReceived);
});
/******************************************************************************/

@ -83,7 +83,10 @@
/******************************************************************************/
µMatrix.loadMatrix = function() {
µMatrix.loadMatrix = function(callback) {
if ( typeof callback !== 'function' ) {
callback = this.noopFunc;
}
var µm = this;
var onLoaded = function(bin) {
if ( bin.hasOwnProperty('userMatrix') ) {
@ -95,6 +98,7 @@
µm.pMatrix.setCell('*', '*', 'doc', µm.Matrix.Green);
µm.saveMatrix();
µm.tMatrix.assign(µm.pMatrix);
callback();
}
};
this.XAL.keyvalGetOne('userMatrix', onLoaded);
@ -396,9 +400,28 @@
}
var µm = this;
var settingsReady = false;
var matrixReady = false;
// User settings are in memory
var onUserSettingsReady = function(settings) {
// TODO: to remove when everybody (and their backup file) has their
// ua-spoof setting converted into a matrix switch.
var onSettingsAndMatrixReady = function() {
if ( !settingsReady || !matrixReady ) {
return;
}
if ( µm.userSettings.hasOwnProperty('spoofUserAgent') === false ) {
return;
}
if ( µm.userSettings.spoofUserAgent ) {
µm.tMatrix.setSwitch('ua-spoof', '*', 1);
µm.pMatrix.setSwitch('ua-spoof', '*', 1);
µm.saveMatrix();
}
delete µm.userSettings.spoofUserAgent;
µm.saveUserSettings();
};
var onSettingsReady = function(settings) {
// Never auto-update at boot time
µm.loadUpdatableAssets(false, callback);
@ -406,9 +429,16 @@
if ( settings.autoUpdate ) {
µm.updater.restart(µm.firstUpdateAfter);
}
settingsReady = true;
onSettingsAndMatrixReady();
};
var onMatrixReady = function() {
matrixReady = true;
onSettingsAndMatrixReady();
};
this.loadUserSettings(onUserSettingsReady);
this.loadMatrix();
this.loadUserSettings(onSettingsReady);
this.loadMatrix(onMatrixReady);
this.getBytesInUse();
};

@ -33,8 +33,8 @@
<button id="buttonMtxSwitches" type="button" class="dropdown-menu-button fa scopeRel" tabindex="-1">&#xf141;</button>
<div class="dropdown-menu">
<ul id="mtxSwitches">
<li id="mtxSwitch_https-strict" class="dropdown-menu-entry"><span>Strict HTTPS</span>
<li id="mtxSwitch_ua-spoof" class="dropdown-menu-entry"><span>User agent spoofing</span>
<li id="mtxSwitch_https-strict" class="dropdown-menu-entry"><span data-i18n="matrixSwitchNoMixedContent"></span>
<li id="mtxSwitch_ua-spoof" class="dropdown-menu-entry"><span data-i18n="matrixSwitchUASpoof"></span>
</ul>
</div>
<div class="dropdown-menu-capture"></div>

@ -46,11 +46,11 @@ html.rtl #spoof-user-agent-with {
<ul>
<li>
<input id="delete-blacklisted-cookies" type="checkbox"><label data-i18n="privacyDeleteBlockedCookiesPrompt" for="delete-blacklisted-cookies"></label>
<input id="delete-blacklisted-cookies" type="checkbox" data-setting-bool="deleteCookies"><label data-i18n="privacyDeleteBlockedCookiesPrompt" for="delete-blacklisted-cookies"></label>
<button class="whatisthis"></button>
<div class="whatisthis-expandable para" data-i18n="privacyDeleteBlockedCookiesHelp"></div>
<li>
<input id="delete-unused-session-cookies" type="checkbox"><label data-i18n="privacyDeleteNonBlockedSessionCookiesPrompt1" for="delete-unused-session-cookies"></label>
<input id="delete-unused-session-cookies" type="checkbox" data-setting-bool="deleteUnusedSessionCookies"><label data-i18n="privacyDeleteNonBlockedSessionCookiesPrompt1" for="delete-unused-session-cookies"></label>
<input id="delete-unused-session-cookies-after" type="text" value="60" size="3"><span data-i18n="privacyDeleteNonBlockedSessionCookiesPrompt2"></span>
<button class="whatisthis"></button>
<div class="whatisthis-expandable para" data-i18n="privacyDeleteNonBlockedSessionCookiesHelp"></div>
@ -73,23 +73,27 @@ html.rtl #spoof-user-agent-with {
of these cookies so that they cannot be used to track you.
-->
<li>
<input id="delete-blacklisted-localstorage" type="checkbox"><label data-i18n="privacyDeleteBlockedLocalStoragePrompt" for="delete-blacklisted-localstorage"></label>
<input id="delete-blacklisted-localstorage" type="checkbox" data-setting-bool="deleteLocalStorage"><label data-i18n="privacyDeleteBlockedLocalStoragePrompt" for="delete-blacklisted-localstorage"></label>
<li>
<input id="clear-browser-cache" type="checkbox"><label data-i18n="privacyClearCachePrompt1" for="clear-browser-cache"></label>
<input id="clear-browser-cache" type="checkbox" data-setting-bool="clearBrowserCache"><label data-i18n="privacyClearCachePrompt1" for="clear-browser-cache"></label>
<input id="clear-browser-cache-after" type="text" value="60" size="3"> <label data-i18n="privacyClearCachePrompt2" for="clear-browser-cache-after"></label>
<button class="whatisthis"></button>
<div class="whatisthis-expandable para" data-i18n="privacyClearCacheHelp"></div>
<li>
<input id="process-referer" type="checkbox"><label data-i18n="privacyProcessRefererPrompt" for="process-referer"></label>
<input id="process-referer" type="checkbox" data-setting-bool="processReferer"><label data-i18n="privacyProcessRefererPrompt" for="process-referer"></label>
<button class="whatisthis"></button>
<div class="whatisthis-expandable para" data-i18n="privacyProcessRefererHelp"></div>
<li>
<input id="process-hyperlink-auditing" type="checkbox"><label data-i18n="privacyProcessHyperlinkAuditingPrompt" for="process-hyperlink-auditing"></label>
<input id="no-mixed-content" type="checkbox" data-matrix-switch="https-strict"><label data-i18n="privacyNoMixedContentPrompt" for="no-mixed-content"></label>
<button class="whatisthis"></button>
<div class="whatisthis-expandable para" data-i18n="privacyNoMixedContentHelp"></div>
<li>
<input id="process-hyperlink-auditing" type="checkbox" data-setting-bool="processHyperlinkAuditing"><label data-i18n="privacyProcessHyperlinkAuditingPrompt" for="process-hyperlink-auditing"></label>
<button class="whatisthis"></button>
<div class="whatisthis-expandable para" data-i18n="privacyProcessHyperlinkAuditingHelp"></div>
<li>&nbsp;
<li>
<input id="spoof-user-agent" type="checkbox"><label data-i18n="privacySpoofUserAgentPrompt1" for="spoof-user-agent"></label> <input id="spoof-user-agent-every" type="text" value="5" size="3"> <span data-i18n="privacySpoofUserAgentPrompt2"></span>
<input id="spoof-user-agent" type="checkbox" data-matrix-switch="ua-spoof"><label data-i18n="privacySpoofUserAgentPrompt1" for="spoof-user-agent"></label> <input id="spoof-user-agent-every" type="text" value="5" size="3"> <span data-i18n="privacySpoofUserAgentPrompt2"></span>
<button class="whatisthis"></button>
<div class="whatisthis-expandable para" data-i18n="privacySpoofUserAgentHelp"></div>
<textarea id="spoof-user-agent-with" spellcheck="false"></textarea>

@ -107,6 +107,14 @@
"message": "{{count}} blacklisted hostname(s)",
"description": "Appears in the metadata row of bottom-most group: **mind the limited width**"
},
"matrixSwitchNoMixedContent" : {
"message": "Strict HTTPS",
"description": ""
},
"matrixSwitchUASpoof" : {
"message": "User agent spoofing",
"description": ""
},
"statsPageTitle" : {
@ -341,6 +349,14 @@
"message": "<p>From Wikipedia: &ldquo;HTTP referer is an HTTP header field that identifies the address of the webpage that linked to the resource being requested. ... <b>Because referer information can violate privacy, some web browsers allow the user to disable the sending of referer information.</b>&rdquo;</p><p>If this setting is checked, <i>µMatrix</i> will remove the HTTP referer information if <b>both</b> of the following conditions are true:<ul style='padding-left:1em;list-style-type:disc;'><li>The domain name of the HTTP referer does not match the domain name of the URL of the request (that is, the referer is third-party to the web page);<li>The hostname of the request is not whitelisted.</ul></p>",
"description": ""
},
"privacyNoMixedContentPrompt" : {
"message": "Strict HTTPS: forbid mixed content.",
"description": ""
},
"privacyNoMixedContentHelp" : {
"message": "<p>From <a href='https://developer.mozilla.org/en-US/docs/Security/MixedContent'>Mozilla Developer Network</a>:</p><blockquote>If [a] HTTPS page includes content retrieved through regular, cleartext HTTP, then the connection is only partially encrypted: the unencrypted content is accessible to sniffers and can be modified by man-in-the-middle attackers, and therefore the connection is not safeguarded anymore. When a webpage exhibits this behavior, it is called a mixed content page.</blockquote>",
"description": ""
},
"privacyProcessHyperlinkAuditingPrompt" : {
"message": "Block all <a href='http://www.whatwg.org/specs/web-apps/current-work/multipage/links.html#hyperlink-auditing'>hyperlink auditing</a> attempts.",
"description": ""

Loading…
Cancel
Save