diff --git a/.eslintignore b/.eslintignore index f65d276918bf91d9b8e7d2d93cb3cf5cf8449378..fbdc9feff58e373abb099c8ee87ff86bdce62472 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1,4 +1,3 @@ locale data preferences -webextension diff --git a/lib/main.js b/lib/main.js index 5f7f0e0ee655f453588f8c953534ba384b9e49fe..93040ef48fa437dbc339a7037bbc5c074487f82b 100644 --- a/lib/main.js +++ b/lib/main.js @@ -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; -} diff --git a/package.json b/package.json index 53c8c8cf766deaf9e4a4bb166f7ce8311d53127d..1c63d1c0bb2f4f7aebc3f98083b2b8355ee917f9 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,6 @@ { "author": "Thomas Rientjes", "description": "Local emulation of Content Delivery Networks.", - "hasEmbeddedWebExtension": true, "homepage": "https://decentraleyes.org", "id": "jid1-BoFifL9Vbdl2zQ@jetpack", "license": "MPL-2.0", diff --git a/webextension/background.js b/webextension/background.js deleted file mode 100644 index 59d4b6b3680cba41d3f91a0044db05e95d90d114..0000000000000000000000000000000000000000 --- a/webextension/background.js +++ /dev/null @@ -1,90 +0,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); - } -}); diff --git a/webextension/manifest.json b/webextension/manifest.json deleted file mode 100644 index 1482a00bd361a555e0a5bc5745e8da143ef52539..0000000000000000000000000000000000000000 --- a/webextension/manifest.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "manifest_version": 2, - "name": "Decentraleyes Module", - "version": "1.4.2", - - "author": "Thomas Rientjes", - - "background": { - - "scripts": [ - "background.js" - ] - }, - - "permissions": [ - "storage" - ] -}