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

Remove embedded WebExtension

parent 0b52b576
Branches pale-moon
No related tags found
No related merge requests found
locale
data
preferences
webextension
......@@ -17,8 +17,6 @@
* Imports
*/
var webextension = null;
var self = require('sdk/self');
var tabs = require('sdk/tabs');
......@@ -36,7 +34,6 @@ var LoadWatcher = require('./load-watcher');
*/
var preferences = simplePreferences.prefs;
var webextensionPort = null;
/**
* Initializations
......@@ -74,65 +71,6 @@ exports.main = function (options) {
}
}
}
try {
webextension = require('sdk/webextension');
} catch (exception) {
return;
}
// Initialize the embedded WebExtension.
webextension.startup().then(({browser}) => {
browser.runtime.onConnect.addListener((port) => {
if (port.name === 'webextension') {
webextensionPort = port;
simplePreferences.on('', function (preferenceName) {
let content = null;
if (preferenceName === 'amountInjected') {
return;
}
if (preferenceName === 'domainWhitelist') {
let domainWhitelist = preferences['domainWhitelist'];
content = {
'whitelistedDomains': _parseDomainWhitelist(domainWhitelist)
};
} else {
content = {
[preferenceName]: preferences[preferenceName]
};
}
port.postMessage({
'subject': 'update-preferences',
'content': content
});
});
let domainWhitelist = preferences['domainWhitelist'];
port.postMessage({
'subject': 'migrate-preferences',
'content': {
'amountInjected': preferences['amountInjected'],
'blockMissing': preferences['blockMissing'],
'whitelistedDomains': _parseDomainWhitelist(domainWhitelist),
'showReleaseNotes': preferences['showReleaseNotes']
}
});
}
});
});
};
// Executed as soon as the add-on is unloaded.
......@@ -141,40 +79,3 @@ exports.onUnload = function () {
// Clean up add-on state.
interceptor.unregister();
};
// Sends injection updates to the WebExtension.
exports.broadcastInjection = function () {
if (webextensionPort !== null) {
webextensionPort.postMessage({
'subject': 'register-injection'
});
}
};
/**
* Private Methods
*/
function _parseDomainWhitelist (value) {
let whitelistedDomains = {};
value.split(';').forEach(function (domain) {
whitelistedDomains[_normalizeDomain(domain)] = true;
});
return whitelistedDomains;
}
function _normalizeDomain (domain) {
domain = domain.toLowerCase().trim();
if (domain.startsWith('www.')) {
domain = domain.slice(4);
}
return domain;
}
{
"author": "Thomas Rientjes",
"description": "Local emulation of Content Delivery Networks.",
"hasEmbeddedWebExtension": true,
"homepage": "https://decentraleyes.org",
"id": "jid1-BoFifL9Vbdl2zQ@jetpack",
"license": "MPL-2.0",
......
/**
* Embedded WebExtension - Background Script
* Belongs to Decentraleyes.
*
* @author Thomas Rientjes
* @since 2017-08-18
* @license MPL 2.0
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/.
*/
'use strict';
/**
* Variables
*/
var webextensionPort = {};
var amountInjected = null;
var pendingCount = 0;
/**
* Initializations
*/
webextensionPort = browser.runtime.connect({name: 'webextension'});
/**
* Event Handlers
*/
webextensionPort.onMessage.addListener((message) => {
if (message.subject === 'migrate-preferences') {
browser.storage.local.get(function (items) {
// Covers storage API failures.
if (items === null) {
return;
}
for (let preference of Object.keys(message.content)) {
// Makes sure no existing preferences are overwritten.
if (!items.hasOwnProperty(preference)) {
browser.storage.local.set({
[preference]: message.content[preference]
});
}
}
});
}
if (message.subject === 'register-injection') {
if (amountInjected !== null && !isNaN(amountInjected)) {
++amountInjected;
browser.storage.local.set({amountInjected});
}
++pendingCount;
if (pendingCount > 1) {
return;
}
chrome.storage.local.get({
// The stored amount, or zero.
'amountInjected': 0
}, function (items) {
// Accounts for the fact that the storage API is asynchronous.
amountInjected = (items && items.amountInjected || 0) + pendingCount;
browser.storage.local.set({amountInjected});
});
}
if (message.subject === 'update-preferences') {
chrome.storage.local.set(message.content);
}
});
{
"manifest_version": 2,
"name": "Decentraleyes Module",
"version": "1.4.2",
"author": "Thomas Rientjes",
"background": {
"scripts": [
"background.js"
]
},
"permissions": [
"storage"
]
}
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