Verified Commit 279cb69a authored by Thomas Rientjes's avatar Thomas Rientjes
Browse files

Update existing codebase

parent a744c454
......@@ -17,7 +17,7 @@
* Imports
*/
var { Cc, Ci } = require('chrome');
var {Cc, Ci} = require('chrome');
var self = require('sdk/self');
//noinspection JSUnresolvedFunction
......@@ -34,7 +34,7 @@ var files = require('./files');
* Constants
*/
const DELIVERY_NOTICE = '/**\n * Local delivery by Decentraleyes (' + self.version + ').\n */\n\n';
const DELIVERY_NOTICE = `/**\n * Local delivery by Decentraleyes (${self.version}).\n */\n\n`;
/**
* Variables
......@@ -46,7 +46,7 @@ var resourceData = self.data;
* Public Methods
*/
function getRedirectionURI(targetPath, characterSet, type) {
function getRedirectionURI (targetPath, characterSet, type) {
var data, dataURI, redirectionURI;
......@@ -67,9 +67,7 @@ exports.getRedirectionURI = getRedirectionURI;
* Private Methods
*/
function _loadResource(targetPath) {
var resource;
function _loadResource (targetPath) {
// Find the result inside a static path index.
if (!files[targetPath]) {
......@@ -77,24 +75,24 @@ function _loadResource(targetPath) {
}
// Attempt to load resource contents.
return resource = resourceData.load(targetPath);
return resourceData.load(targetPath);
}
function _buildDataURI(type, characterSet, data) {
function _buildDataURI (type, characterSet, data) {
var addNotice, dataURI;
//noinspection JSUnresolvedVariable
addNotice = require('sdk/simple-prefs').prefs.addNotice;
dataURI = 'data:' + type + ';charset=' + characterSet + ',';
dataURI = `data:${type};charset=${characterSet},`;
// Remove the syntax invalidation character.
data = data.substring(1);
if (!addNotice) {
dataURI = dataURI + encodeURIComponent(data);
if (addNotice) {
dataURI += encodeURIComponent(DELIVERY_NOTICE + data);
} else {
dataURI = dataURI + encodeURIComponent(DELIVERY_NOTICE + data);
dataURI += encodeURIComponent(data);
}
return dataURI;
......
......@@ -17,9 +17,9 @@
* Imports
*/
var { Class } = require('sdk/core/heritage');
var { Unknown } = require('sdk/platform/xpcom');
var { Cc, Ci, Cr } = require('chrome');
var {Class} = require('sdk/core/heritage');
var {Unknown} = require('sdk/platform/xpcom');
var {Cc, Ci, Cr} = require('chrome');
var main = require('./main');
......@@ -55,15 +55,15 @@ var storage = simpleStorage.storage;
var Interceptor = new Class({
extends: Unknown,
interfaces: ['nsIObserver'],
topic: 'http-on-modify-request',
'extends': Unknown,
'interfaces': ['nsIObserver'],
'topic': 'http-on-modify-request',
register: function () {
'register': function () {
observerService.addObserver(this, this.topic, false);
},
unregister: function () {
'unregister': function () {
observerService.removeObserver(this, this.topic);
},
......@@ -71,9 +71,9 @@ var Interceptor = new Class({
* Called whenever an HTTP request is made.
* @param httpChannel
*/
observe: function (httpChannel) {
'observe': function (httpChannel) {
var validCandidate, target, characterSet, redirectionURI;
var validCandidate, target, characterSet, redirectionURI, initiatorDomain;
// Enable runtime discovery.
httpChannel.QueryInterface(Ci.nsIHttpChannel);
......@@ -107,11 +107,12 @@ var Interceptor = new Class({
}
// Fix for reported edge-case issues with specific websites.
var initiatorDomain =
httpChannel.loadInfo && httpChannel.loadInfo.loadingDocument && httpChannel.loadInfo.loadingDocument.domain ||
initiatorDomain =
httpChannel.loadInfo && httpChannel.loadInfo.loadingDocument &&
httpChannel.loadInfo.loadingDocument.domain ||
httpChannel.referrer && httpChannel.referrer.host;
if (storage.taintedDomains[initiatorDomain] || /yandex\./.test(initiatorDomain)) {
if (storage.taintedDomains[initiatorDomain] || (/yandex\./).test(initiatorDomain)) {
return this.handleMissingCandidate(httpChannel);
}
......@@ -127,7 +128,7 @@ var Interceptor = new Class({
* Called when a valid candidate cannot be injected.
* @param httpChannel
*/
handleMissingCandidate: function (httpChannel) {
'handleMissingCandidate': function (httpChannel) {
//noinspection JSUnresolvedVariable
if (preferences.blockMissing) {
......
......@@ -17,9 +17,9 @@
* Imports
*/
var { Class } = require('sdk/core/heritage');
var { Unknown, Factory } = require('sdk/platform/xpcom');
var { Cc, Ci, Cu } = require('chrome');
var {Class} = require('sdk/core/heritage');
var {Unknown, Factory} = require('sdk/platform/xpcom');
var {Cc, Ci, Cu} = require('chrome');
var xpcom = require('sdk/platform/xpcom');
......@@ -52,13 +52,14 @@ const REQUEST_ACCEPTATION = Ci.nsIContentPolicy.ACCEPT;
* Variables
*/
var storage = simpleStorage.storage;
var LoadWatcher, storage, undetectableTaintedDomains, factory, unload;
storage = simpleStorage.storage;
/**
* Tainted domains that are not automatically detectable.
* @var {object} undetectableTaintedDomains
*/
var undetectableTaintedDomains = {
undetectableTaintedDomains = {
'identi.ca': true,
'minigames.mail.ru': true,
......@@ -73,7 +74,7 @@ var undetectableTaintedDomains = {
Object.extend = function (destination, source) {
for (var property in source) {
for (let property in source) {
if (source.hasOwnProperty(property)) {
destination[property] = source[property];
......@@ -90,21 +91,23 @@ storage.taintedDomains = Object.extend(storage.taintedDomains, undetectableTaint
* Load Watcher Class
*/
var LoadWatcher = new Class({
LoadWatcher = new Class({
extends: Unknown,
interfaces: ['nsIContentPolicy'],
get wrappedJSObject() {
return this
'extends': Unknown,
'interfaces': ['nsIContentPolicy'],
// eslint-disable-next-line quote-props
get wrappedJSObject () {
return this;
},
register: function () {
'register': function () {
categoryManager.deleteCategoryEntry('content-policy', CONTRACT_ID, false);
categoryManager.addCategoryEntry('content-policy', CONTRACT_ID, CONTRACT_ID, false, true);
},
shouldLoad: function (contentType, contentLocation, requestOrigin, node) {
'shouldLoad': function (contentType, contentLocation, requestOrigin, node) {
let contentHost;
......@@ -116,7 +119,7 @@ var LoadWatcher = new Class({
return REQUEST_ACCEPTATION;
}
if (contentType == SCRIPT_CONTENT_TYPE && mappings[contentHost]) {
if (contentType === SCRIPT_CONTENT_TYPE && mappings[contentHost]) {
if (node instanceof SCRIPT_ELEMENT) {
......@@ -137,22 +140,22 @@ var LoadWatcher = new Class({
* Load Watcher Factory
*/
var factory = Factory({
factory = Factory({
contract: CONTRACT_ID,
Component: LoadWatcher,
unregister: false
'contract': CONTRACT_ID,
'Component': LoadWatcher,
'unregister': false
});
/**
* Unregister
*/
var unload = require('sdk/system/unload');
unload = require('sdk/system/unload');
unload.when(function () {
function trueUnregister() {
function trueUnregister () {
categoryManager.deleteCategoryEntry('content-policy', CONTRACT_ID, false);
......
......@@ -21,7 +21,7 @@ var preferences = require('sdk/simple-prefs');
var webextension = null;
var self = require('sdk/self');
var tabs = require("sdk/tabs");
var tabs = require('sdk/tabs');
var Interceptor = require('./interceptor');
var LoadWatcher = require('./load-watcher');
......@@ -58,10 +58,12 @@ exports.main = function (options) {
// Display the release notes if desired.
if (preferences.prefs.showReleaseNotes) {
if (options.loadReason === 'install' || (options.loadReason === 'upgrade' && !featurelessVersions[self.version])) {
let loadReason = options.loadReason;
if (loadReason === 'install' || (loadReason === 'upgrade' && !featurelessVersions[self.version])) {
if (preferences.prefs['sdk.baseURI']) {
tabs.open(preferences.prefs['sdk.baseURI'] + 'static/release-notes.html');
tabs.open(`${preferences.prefs['sdk.baseURI']}static/release-notes.html`);
}
}
}
......@@ -73,9 +75,9 @@ exports.main = function (options) {
}
// Initialize the embedded WebExtension.
webextension.startup().then(({ browser }) => {
webextension.startup().then(({browser}) => {
browser.runtime.onConnect.addListener(port => {
browser.runtime.onConnect.addListener((port) => {
if (port.name === 'webextension') {
......@@ -148,7 +150,7 @@ exports.broadcastInjection = function () {
* Private Methods
*/
function _parseDomainWhitelist(value) {
function _parseDomainWhitelist (value) {
let whitelistedDomains = {};
......@@ -159,7 +161,7 @@ function _parseDomainWhitelist(value) {
return whitelistedDomains;
}
function _normalizeDomain(domain) {
function _normalizeDomain (domain) {
domain = domain.toLowerCase().trim();
......
......@@ -43,96 +43,96 @@ var mappings = {
// Common Shorthand Notations [Deprecated]
'dojo/1/dojo/dojo.': {
path: 'resources/dojo/1.6.1/dojo/dojo.js.dec',
type: 'application/javascript'
'path': 'resources/dojo/1.6.1/dojo/dojo.js.dec',
'type': 'application/javascript'
},
'jquery/1/jquery.': {
path: 'resources/jquery/1.11.1/jquery.min.js.dec',
type: 'application/javascript'
'path': 'resources/jquery/1.11.1/jquery.min.js.dec',
'type': 'application/javascript'
},
'jquery/1.2/jquery.min.js': {
path: 'resources/jquery/1.2.6/jquery.min.js.dec',
type: 'application/javascript'
'path': 'resources/jquery/1.2.6/jquery.min.js.dec',
'type': 'application/javascript'
},
'jquery/1.2/jquery.js': {
path: 'resources/jquery/1.2.6/jquery.min.js.dec',
type: 'application/javascript'
'path': 'resources/jquery/1.2.6/jquery.min.js.dec',
'type': 'application/javascript'
},
'jquery/1.3/jquery.min.js': {
path: 'resources/jquery/1.3.2/jquery.min.js.dec',
type: 'application/javascript'
'path': 'resources/jquery/1.3.2/jquery.min.js.dec',
'type': 'application/javascript'
},
'jquery/1.3/jquery.js': {
path: 'resources/jquery/1.3.2/jquery.min.js.dec',
type: 'application/javascript'
'path': 'resources/jquery/1.3.2/jquery.min.js.dec',
'type': 'application/javascript'
},
'jquery/1.4/jquery.min.js': {
path: 'resources/jquery/1.4.4/jquery.min.js.dec',
type: 'application/javascript'
'path': 'resources/jquery/1.4.4/jquery.min.js.dec',
'type': 'application/javascript'
},
'jquery/1.4/jquery.js': {
path: 'resources/jquery/1.4.4/jquery.min.js.dec',
type: 'application/javascript'
'path': 'resources/jquery/1.4.4/jquery.min.js.dec',
'type': 'application/javascript'
},
'jquery/1.5/jquery.min.js': {
path: 'resources/jquery/1.5.2/jquery.min.js.dec',
type: 'application/javascript'
'path': 'resources/jquery/1.5.2/jquery.min.js.dec',
'type': 'application/javascript'
},
'jquery/1.5/jquery.js': {
path: 'resources/jquery/1.5.2/jquery.min.js.dec',
type: 'application/javascript'
'path': 'resources/jquery/1.5.2/jquery.min.js.dec',
'type': 'application/javascript'
},
'jquery/1.6/jquery.min.js': {
path: 'resources/jquery/1.6.4/jquery.min.js.dec',
type: 'application/javascript'
'path': 'resources/jquery/1.6.4/jquery.min.js.dec',
'type': 'application/javascript'
},
'jquery/1.6/jquery.js': {
path: 'resources/jquery/1.6.4/jquery.min.js.dec',
type: 'application/javascript'
'path': 'resources/jquery/1.6.4/jquery.min.js.dec',
'type': 'application/javascript'
},
'jquery/1.7/jquery.min.js': {
path: 'resources/jquery/1.7.2/jquery.min.js.dec',
type: 'application/javascript'
'path': 'resources/jquery/1.7.2/jquery.min.js.dec',
'type': 'application/javascript'
},
'jquery/1.7/jquery.js': {
path: 'resources/jquery/1.7.2/jquery.min.js.dec',
type: 'application/javascript'
'path': 'resources/jquery/1.7.2/jquery.min.js.dec',
'type': 'application/javascript'
},
'jquery/1.8/jquery.min.js': {
path: 'resources/jquery/1.8.3/jquery.min.js.dec',
type: 'application/javascript'
'path': 'resources/jquery/1.8.3/jquery.min.js.dec',
'type': 'application/javascript'
},
'jquery/1.8/jquery.js': {
path: 'resources/jquery/1.8.3/jquery.min.js.dec',
type: 'application/javascript'
'path': 'resources/jquery/1.8.3/jquery.min.js.dec',
'type': 'application/javascript'
},
'jqueryui/1/jquery-ui.js': {
path: 'resources/jqueryui/1.10.4/jquery-ui.min.js.dec',
type: 'application/javascript'
'path': 'resources/jqueryui/1.10.4/jquery-ui.min.js.dec',
'type': 'application/javascript'
},
'jqueryui/1/jquery-ui.min.js': {
path: 'resources/jqueryui/1.10.4/jquery-ui.min.js.dec',
type: 'application/javascript'
'path': 'resources/jqueryui/1.10.4/jquery-ui.min.js.dec',
'type': 'application/javascript'
},
'mootools/1/mootools-yui-compressed.': {
path: 'resources/mootools/1.1.2/mootools-yui-compressed.js.dec',
type: 'application/javascript'
'path': 'resources/mootools/1.1.2/mootools-yui-compressed.js.dec',
'type': 'application/javascript'
},
'prototype/1/prototype.': {
path: 'resources/prototype/1.7.1.0/prototype.js.dec',
type: 'application/javascript'
'path': 'resources/prototype/1.7.1.0/prototype.js.dec',
'type': 'application/javascript'
},
'scriptaculous/1/scriptaculous.': {
path: 'resources/scriptaculous/1.9.0/scriptaculous.js.dec',
type: 'application/javascript'
'path': 'resources/scriptaculous/1.9.0/scriptaculous.js.dec',
'type': 'application/javascript'
},
'swfobject/2/swfobject.': {
path: 'resources/swfobject/2.2/swfobject.js.dec',
type: 'application/javascript'
'path': 'resources/swfobject/2.2/swfobject.js.dec',
'type': 'application/javascript'
},
'webfont/1/webfont.': {
path: 'resources/webfont/1.5.18/webfont.js.dec',
type: 'application/javascript'
'path': 'resources/webfont/1.5.18/webfont.js.dec',
'type': 'application/javascript'
}
}
},
......@@ -182,52 +182,52 @@ var mappings = {
// Common Shorthand Notations [Deprecated]
'jquery-latest.': {
path: 'resources/jquery/1.11.1/jquery.min.js.dec',
type: 'application/javascript'
'path': 'resources/jquery/1.11.1/jquery.min.js.dec',
'type': 'application/javascript'
},
'jquery.': {
path: 'resources/jquery/1.11.1/jquery.min.js.dec',
type: 'application/javascript'
'path': 'resources/jquery/1.11.1/jquery.min.js.dec',
'type': 'application/javascript'
},
'jquery-1.3.min.js': {
path: 'resources/jquery/1.3.0/jquery.min.js.dec',
type: 'application/javascript'
'path': 'resources/jquery/1.3.0/jquery.min.js.dec',
'type': 'application/javascript'
},
'jquery-1.3.js': {
path: 'resources/jquery/1.3.0/jquery.min.js.dec',
type: 'application/javascript'
'path': 'resources/jquery/1.3.0/jquery.min.js.dec',
'type': 'application/javascript'
},
'jquery-1.4.min.js': {
path: 'resources/jquery/1.4.0/jquery.min.js.dec',
type: 'application/javascript'
'path': 'resources/jquery/1.4.0/jquery.min.js.dec',
'type': 'application/javascript'
},
'jquery-1.4.js': {
path: 'resources/jquery/1.4.0/jquery.min.js.dec',
type: 'application/javascript'
'path': 'resources/jquery/1.4.0/jquery.min.js.dec',
'type': 'application/javascript'
},
'jquery-1.5.min.js': {
path: 'resources/jquery/1.5.0/jquery.min.js.dec',
type: 'application/javascript'
'path': 'resources/jquery/1.5.0/jquery.min.js.dec',
'type': 'application/javascript'
},
'jquery-1.5.js': {
path: 'resources/jquery/1.5.0/jquery.min.js.dec',
type: 'application/javascript'
'path': 'resources/jquery/1.5.0/jquery.min.js.dec',
'type': 'application/javascript'
},
'jquery-1.6.min.js': {
path: 'resources/jquery/1.6.0/jquery.min.js.dec',
type: 'application/javascript'
'path': 'resources/jquery/1.6.0/jquery.min.js.dec',
'type': 'application/javascript'
},
'jquery-1.6.js': {
path: 'resources/jquery/1.6.0/jquery.min.js.dec',
type: 'application/javascript'
'path': 'resources/jquery/1.6.0/jquery.min.js.dec',
'type': 'application/javascript'
},
'jquery-1.7.min.js': {
path: 'resources/jquery/1.7.0/jquery.min.js.dec',
type: 'application/javascript'
'path': 'resources/jquery/1.7.0/jquery.min.js.dec',
'type': 'application/javascript'
},
'jquery-1.7.js': {
path: 'resources/jquery/1.7.0/jquery.min.js.dec',
type: 'application/javascript'
'path': 'resources/jquery/1.7.0/jquery.min.js.dec',
'type': 'application/javascript'
}
}
},
......
......@@ -65,13 +65,15 @@ simplePreferences.on('domainWhitelist', _applyWhitelistPreference);
exports.isValidCandidate = function (httpChannel) {
var initiatorDomain;
// See if the request is targeted at a Content Delivery Network.
if (mappings[httpChannel.URI.host] === undefined) {
return false;
}
// Attempt to determine the domain of the request initiator.
var initiatorDomain =
initiatorDomain =
httpChannel.loadInfo && httpChannel.loadInfo.loadingDocument && httpChannel.loadInfo.loadingDocument.domain ||
httpChannel.referrer && httpChannel.referrer.host;
......@@ -117,7 +119,7 @@ exports.getLocalTarget = function (channelHost, channelPath) {
* Private Methods
*/
function _matchBasePath(hostMappings, channelPath) {
function _matchBasePath (hostMappings, channelPath) {
for (let basePath of Object.keys(hostMappings)) {
......@@ -129,7 +131,7 @@ function _matchBasePath(hostMappings, channelPath) {
return false;
}
function _findLocalTarget(resourceMappings, basePath, channelPath) {
function _findLocalTarget (resourceMappings, basePath, channelPath) {
var resourcePath, versionNumber, resourcePattern;
......@@ -143,8 +145,8 @@ function _findLocalTarget(resourceMappings, basePath, channelPath) {
// Prepare and return a local target.
return {
path: resourceMappings[resourcePath].path,
type: resourceMappings[resourcePath].type
'path': resourceMappings[resourcePath].path,
'type': resourceMappings[resourcePath].type
};
}
......@@ -155,8 +157,8 @@ function _findLocalTarget(resourceMappings, basePath, channelPath) {
// Prepare and return a local target.
return {
path: resourceMappings[resourceMold].path.replace(VERSION_PLACEHOLDER, versionNumber),
type: resourceMappings[resourceMold].type
'path': resourceMappings[resourceMold].path.replace(VERSION_PLACEHOLDER, versionNumber),
'type': resourceMappings[resourceMold].type
};
}
}
......@@ -164,7 +166,7 @@ function _findLocalTarget(resourceMappings, basePath, channelPath) {
return false;
}
function _normalizeDomain(domain) {
function _normalizeDomain (domain) {
domain = domain.toLowerCase().trim();
......@@ -175,7 +177,7 @@ function _normalizeDomain(domain) {
return domain;
}
function _applyWhitelistPreference() {
function _applyWhitelistPreference () {
whitelistedDomains = {};
......
......@@ -20,74 +20,74 @@
var resources = {
// AngularJS
angular: {
path: 'resources/angularjs/{version}/angular.min.js.dec',
type: 'application/javascript'
'angular': {
'path': 'resources/angularjs/{version}/angular.min.js.dec',
'type': 'application/javascript'
},
// Backbone.js
backbone: {
path: 'resources/backbone.js/{version}/backbone-min.js.dec',
type: 'application/javascript'
'backbone': {
'path': 'resources/backbone.js/{version}/backbone-min.js.dec',
'type': 'application/javascript'
},
// Dojo
dojo: {
path: 'resources/dojo/{version}/dojo/dojo.js.dec',
type: 'application/javascript'
'dojo': {
'path': 'resources/dojo/{version}/dojo/dojo.js.dec',