Skip to content
This repository has been archived by the owner on Jun 8, 2018. It is now read-only.

Commit

Permalink
Improve overall stability
Browse files Browse the repository at this point in the history
  • Loading branch information
Synzvato committed Dec 21, 2015
1 parent 28845c0 commit c595dca
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 23 deletions.
11 changes: 10 additions & 1 deletion lib/interceptor.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
24 changes: 23 additions & 1 deletion lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
};
75 changes: 56 additions & 19 deletions lib/request-analyzer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -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;
}
}
}
Expand Down Expand Up @@ -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;
}
}
Expand All @@ -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,
Expand All @@ -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);
});
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion static/release-notes.html
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand Down

0 comments on commit c595dca

Please sign in to comment.