Skip to content
Snippets Groups Projects
Commit c595dca0 authored by Thomas Rientjes's avatar Thomas Rientjes
Browse files

Improve overall stability

parent 28845c09
No related branches found
Tags v1.2.2
No related merge requests found
......@@ -66,7 +66,16 @@ var Interceptor = new Class({
httpChannel.setRequestHeader('Referer', null, false);
// Temporary fix for reported issues with the Play Store website.
if (httpChannel.referrer && httpChannel.referrer.host === 'play.google.com') {
// Temporary fix for reported issues with the Report URI website.
var requestDomain = null;
if (httpChannel.loadInfo && httpChannel.loadInfo.loadingDocument && httpChannel.loadInfo.loadingDocument.domain) {
requestDomain = httpChannel.loadInfo.loadingDocument.domain;
} else if (httpChannel.referrer && httpChannel.referrer.host) {
requestDomain = httpChannel.referrer.host;
}
if (requestDomain === 'play.google.com' || requestDomain === 'report-uri.io') {
this.handleMissingCandidate(httpChannel);
return;
}
......
......@@ -18,10 +18,32 @@
*/
var Interceptor = require('./interceptor');
var preferences = require('sdk/simple-prefs').prefs;
var tabs = require("sdk/tabs");
/**
* Main
*/
var interceptor = new Interceptor();
interceptor.register();
// Executed as soon as the add-on is loaded.
exports.main = function (options) {
// Initialize add-on state.
interceptor.register();
if (options.loadReason === 'install' || options.loadReason === 'upgrade') {
if (preferences['sdk.baseURI']) {
tabs.open(preferences['sdk.baseURI'] + 'static/release-notes.html');
}
}
};
// Executed as soon as the add-on is unloaded.
exports.onUnload = function () {
// Clean up add-on state.
interceptor.unregister()
};
......@@ -25,6 +25,25 @@ var preferences = require('sdk/simple-prefs').prefs;
*/
var mappings = require('./mappings');
/**
* Variables
*/
var whitelistedDomains = [];
/**
* Initializations
*/
applyWhitelistPreference();
/**
* Event Handlers
*/
require('sdk/simple-prefs').on('domainWhitelist', applyWhitelistPreference);
/**
* Public Methods
*/
......@@ -35,26 +54,23 @@ function isValidCandidate(httpChannel) {
return false;
}
//noinspection JSUnresolvedVariable
var domainWhitelist = preferences.domainWhitelist;
if (domainWhitelist.length > 0 && httpChannel.referrer) {
var requestDomain = null;
var whitelistedDomains = domainWhitelist.split(';');
for (var domain in whitelistedDomains) {
if (whitelistedDomains.hasOwnProperty(domain)) {
if (httpChannel.loadInfo && httpChannel.loadInfo.loadingDocument && httpChannel.loadInfo.loadingDocument.domain) {
requestDomain = normalizeDomain(httpChannel.loadInfo.loadingDocument.domain);
} else if (httpChannel.referrer && httpChannel.referrer.host) {
requestDomain = normalizeDomain(httpChannel.referrer.host);
}
if (whitelistedDomains[domain] === httpChannel.referrer.host ||
'www.' + whitelistedDomains[domain] === httpChannel.referrer.host) {
if (whitelistedDomains.length > 0 && requestDomain !== null) {
// Remove referer header from request.
httpChannel.setRequestHeader('Referer', null, false);
for (let domain of whitelistedDomains) {
return false;
}
if (domain === requestDomain) {
// Remove referer header from request.
httpChannel.setRequestHeader('Referer', null, false);
return false;
}
}
}
......@@ -106,11 +122,11 @@ exports.getLocalTarget = getLocalTarget;
function matchBasePath(hostMappings, channelPath) {
for (var basePath in hostMappings) {
for (let basePath in hostMappings) {
if (hostMappings.hasOwnProperty(basePath)) {
if (channelPath.indexOf(basePath) === 0) {
if (channelPath.startsWith(basePath)) {
return basePath;
}
}
......@@ -128,11 +144,11 @@ function matchResourcePath(resourceMappings, basePath, channelPath) {
versionNumber = resourcePath.match(/(?:\d{1,2}\.){1,3}\d{1,2}/);
resourcePattern = resourcePath.replace(versionNumber, '{version}');
for (var resourceMold in resourceMappings) {
for (let resourceMold in resourceMappings) {
if (resourceMappings.hasOwnProperty(resourceMold)) {
if (resourcePattern.indexOf(resourceMold) === 0) {
if (resourcePattern.startsWith(resourceMold)) {
var localTarget = {
path: resourceMappings[resourceMold].path,
......@@ -149,3 +165,24 @@ function matchResourcePath(resourceMappings, basePath, channelPath) {
return false;
}
function normalizeDomain(domain) {
domain = domain.toLowerCase().trim();
if (domain.startsWith('www.')) {
domain = domain.slice(4);
}
return domain;
}
function applyWhitelistPreference() {
whitelistedDomains = [];
//noinspection JSUnresolvedVariable
preferences.domainWhitelist.split(';').forEach(function(domain, index) {
whitelistedDomains[index] = normalizeDomain(domain);
});
}
......@@ -3,7 +3,7 @@
"author": "Thomas Rientjes",
"license": "MPL-2.0",
"title": "Decentraleyes",
"version": "1.2.0",
"version": "1.2.2",
"main": "lib/main.js",
"homepage": "https://addons.mozilla.org/en-US/firefox/addon/decentraleyes",
"name": "decentraleyes",
......
......@@ -65,7 +65,7 @@
<div class="container">
<h1>Decentraleyes <i>v1.2.0</i></h1>
<h1>Decentraleyes <i>v1.2.2</i></h1>
<br><br>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment