2020-02-27 13:45:29 +01:00
|
|
|
/**
|
|
|
|
* Messenger
|
2020-06-30 18:41:58 +02:00
|
|
|
* Belongs to LocalCDN (since 2020-02-26)
|
|
|
|
* (Origin: Decentraleyes)
|
2020-02-27 13:45:29 +01:00
|
|
|
*
|
|
|
|
* @author Thomas Rientjes
|
|
|
|
* @since 2018-05-28
|
2020-06-30 18:41:58 +02:00
|
|
|
*
|
|
|
|
* @author nobody
|
|
|
|
* @since 2020-02-26
|
|
|
|
*
|
2020-02-27 13:45:29 +01:00
|
|
|
* @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';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Messenger
|
|
|
|
*/
|
|
|
|
|
|
|
|
var messenger = {};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Private Methods
|
|
|
|
*/
|
|
|
|
|
|
|
|
messenger._handleMessageReceived = function (message, sender, sendResponse) {
|
|
|
|
|
|
|
|
let topic, value;
|
|
|
|
|
|
|
|
topic = message.topic;
|
|
|
|
value = message.value;
|
|
|
|
|
|
|
|
if (topic === 'tab:fetch-injections') {
|
|
|
|
|
|
|
|
sendResponse({'value': stateManager.tabs[value].injections});
|
|
|
|
return MessageResponse.SYNCHRONOUS;
|
|
|
|
}
|
|
|
|
|
2020-10-17 07:09:30 +02:00
|
|
|
if (topic === 'domain:fetch-is-allowlisted') {
|
2020-02-27 13:45:29 +01:00
|
|
|
|
2020-10-17 07:09:30 +02:00
|
|
|
let allowlistRecord = requestAnalyzer.allowlistedDomains[value];
|
|
|
|
sendResponse({'value': Boolean(allowlistRecord)});
|
2020-02-27 13:45:29 +01:00
|
|
|
|
|
|
|
return MessageResponse.SYNCHRONOUS;
|
|
|
|
}
|
|
|
|
|
2020-10-17 07:09:30 +02:00
|
|
|
if (topic === 'allowlist:add-domain') {
|
2020-02-27 13:45:29 +01:00
|
|
|
|
2020-10-17 07:09:30 +02:00
|
|
|
stateManager.addDomainToAllowlist(value).then(function () {
|
2020-02-27 13:45:29 +01:00
|
|
|
sendResponse({'value': true});
|
|
|
|
});
|
|
|
|
|
|
|
|
return MessageResponse.ASYNCHRONOUS;
|
|
|
|
}
|
|
|
|
|
2020-10-17 07:09:30 +02:00
|
|
|
if (topic === 'allowlist:remove-domain') {
|
2020-02-27 13:45:29 +01:00
|
|
|
|
2020-10-17 07:09:30 +02:00
|
|
|
stateManager.removeDomainFromAllowlist(value).then(function () {
|
2020-02-27 13:45:29 +01:00
|
|
|
sendResponse({'value': true});
|
|
|
|
});
|
|
|
|
|
|
|
|
return MessageResponse.ASYNCHRONOUS;
|
|
|
|
}
|
2020-05-25 22:30:44 +02:00
|
|
|
|
|
|
|
if (topic === 'domain:fetch-is-manipulateDOM') {
|
|
|
|
|
2020-06-05 07:28:26 +02:00
|
|
|
let manipulateDOMRecord = requestAnalyzer.domainsManipulateDOM[value];
|
2020-05-25 22:30:44 +02:00
|
|
|
sendResponse({'value': Boolean(manipulateDOMRecord)});
|
|
|
|
|
|
|
|
return MessageResponse.SYNCHRONOUS;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (topic === 'manipulateDOM:add-domain') {
|
|
|
|
|
|
|
|
stateManager.addDomainToManipulateDOMlist(value).then(function () {
|
|
|
|
sendResponse({'value': true});
|
|
|
|
});
|
|
|
|
|
|
|
|
return MessageResponse.ASYNCHRONOUS;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (topic === 'manipulateDOM:remove-domain') {
|
|
|
|
|
|
|
|
stateManager.removeDomainFromManipulateDOMlist(value).then(function () {
|
|
|
|
sendResponse({'value': true});
|
|
|
|
});
|
|
|
|
|
|
|
|
return MessageResponse.ASYNCHRONOUS;
|
|
|
|
}
|
2020-10-25 00:09:42 +02:00
|
|
|
|
|
|
|
if (topic === 'deleteStatistic') {
|
|
|
|
storageManager.statistics = {};
|
|
|
|
}
|
2020-02-27 13:45:29 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Event Handlers
|
|
|
|
*/
|
|
|
|
|
|
|
|
chrome.runtime.onMessage.addListener(messenger._handleMessageReceived);
|