mirror of
https://github.com/Synzvato/decentraleyes.git
synced 2025-12-23 15:28:26 -05:00
Improve compatibility with private browsing
This commit is contained in:
@@ -16,6 +16,7 @@
|
||||
"helpers": true,
|
||||
"interceptor": true,
|
||||
"mappings": true,
|
||||
"MessageResponse": true,
|
||||
"requestAnalyzer": true,
|
||||
"requestSanitizer": true,
|
||||
"Resource": true,
|
||||
|
||||
@@ -34,6 +34,11 @@ const Header = {
|
||||
'REFERER': 'Referer'
|
||||
};
|
||||
|
||||
const MessageResponse = {
|
||||
'ASYNCHRONOUS': true,
|
||||
'SYNCHRONOUS': false
|
||||
};
|
||||
|
||||
const Resource = {
|
||||
'MAPPING_EXPRESSION': /\.map$/i,
|
||||
'VERSION_EXPRESSION': /(?:\d{1,2}\.){1,3}\d{1,2}/,
|
||||
|
||||
70
core/messenger.js
Normal file
70
core/messenger.js
Normal file
@@ -0,0 +1,70 @@
|
||||
/**
|
||||
* Messenger
|
||||
* Belongs to Decentraleyes.
|
||||
*
|
||||
* @author Thomas Rientjes
|
||||
* @since 2018-05-28
|
||||
* @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;
|
||||
}
|
||||
|
||||
if (topic === 'domain:fetch-is-whitelisted') {
|
||||
|
||||
let whitelistRecord = requestAnalyzer.whitelistedDomains[value];
|
||||
sendResponse({'value': Boolean(whitelistRecord)});
|
||||
|
||||
return MessageResponse.SYNCHRONOUS;
|
||||
}
|
||||
|
||||
if (topic === 'whitelist:add-domain') {
|
||||
|
||||
stateManager.addDomainToWhitelist(value).then(function () {
|
||||
sendResponse({'value': true});
|
||||
});
|
||||
|
||||
return MessageResponse.ASYNCHRONOUS;
|
||||
}
|
||||
|
||||
if (topic === 'whitelist:remove-domain') {
|
||||
|
||||
stateManager.removeDomainFromWhitelist(value).then(function () {
|
||||
sendResponse({'value': true});
|
||||
});
|
||||
|
||||
return MessageResponse.ASYNCHRONOUS;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Event Handlers
|
||||
*/
|
||||
|
||||
chrome.runtime.onMessage.addListener(messenger._handleMessageReceived);
|
||||
@@ -74,7 +74,7 @@ stateManager.addDomainToWhitelist = function (domain) {
|
||||
});
|
||||
};
|
||||
|
||||
stateManager.deleteDomainFromWhitelist = function (domain) {
|
||||
stateManager.removeDomainFromWhitelist = function (domain) {
|
||||
|
||||
return new Promise((resolve) => {
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
<script src="../../core/state-manager.js"></script>
|
||||
<script src="../../core/request-analyzer.js"></script>
|
||||
<script src="../../core/file-guard.js"></script>
|
||||
<script src="../../core/messenger.js"></script>
|
||||
<script src="../../core/interceptor.js"></script>
|
||||
<script src="../../core/main.js"></script>
|
||||
|
||||
|
||||
@@ -30,11 +30,10 @@ popup._renderContents = function () {
|
||||
|
||||
popup._renderNonContextualContents();
|
||||
|
||||
if (popup._backgroundPage !== null) {
|
||||
|
||||
popup._determineTargetTab()
|
||||
.then(popup._renderContextualContents);
|
||||
}
|
||||
popup._determineTargetTab()
|
||||
.then(popup._determineDomainWhitelistStatus)
|
||||
.then(popup._determineResourceInjections)
|
||||
.then(popup._renderContextualContents);
|
||||
};
|
||||
|
||||
popup._renderNonContextualContents = function () {
|
||||
@@ -55,24 +54,12 @@ popup._renderNonContextualContents = function () {
|
||||
|
||||
popup._renderContextualContents = function () {
|
||||
|
||||
let injections, groupedInjections;
|
||||
|
||||
popup._domain = helpers.extractDomainFromUrl(popup._targetTab.url);
|
||||
|
||||
popup._requestAnalyzer = popup._backgroundPage.requestAnalyzer;
|
||||
popup._stateManager = popup._backgroundPage.stateManager;
|
||||
|
||||
if (popup._domain !== null) {
|
||||
|
||||
popup._domain = helpers.normalizeDomain(popup._domain);
|
||||
popup._renderDomainWhitelistPanel();
|
||||
}
|
||||
|
||||
injections = popup._stateManager.tabs[popup._targetTab.id].injections;
|
||||
groupedInjections = popup._groupResourceInjections(injections);
|
||||
|
||||
if (Object.keys(groupedInjections).length > 0) {
|
||||
popup._renderInjectionPanel(groupedInjections);
|
||||
if (Object.keys(popup._resourceInjections).length > 0) {
|
||||
popup._renderInjectionPanel(popup._resourceInjections);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -87,7 +74,7 @@ popup._renderDomainWhitelistPanel = function () {
|
||||
protectionToggleElement.setAttribute('dir', popup._scriptDirection);
|
||||
domainIndicatorElement.innerText = popup._domain;
|
||||
|
||||
if (popup._requestAnalyzer.whitelistedDomains[popup._domain]) {
|
||||
if (popup._domainIsWhitelisted === true) {
|
||||
|
||||
let enableProtectionTitle = chrome.i18n.getMessage('enableProtectionTitle');
|
||||
|
||||
@@ -119,23 +106,59 @@ popup._renderInjectionPanel = function (groupedInjections) {
|
||||
|
||||
popup._enableProtection = function () {
|
||||
|
||||
popup._stateManager.deleteDomainFromWhitelist(popup._domain)
|
||||
.then(popup._onProtectionToggled);
|
||||
let message = {
|
||||
'topic': 'whitelist:remove-domain',
|
||||
'value': popup._domain
|
||||
};
|
||||
|
||||
chrome.runtime.sendMessage(message, function () {
|
||||
popup._onProtectionToggled();
|
||||
});
|
||||
};
|
||||
|
||||
popup._disableProtection = function () {
|
||||
|
||||
popup._stateManager.addDomainToWhitelist(popup._domain)
|
||||
.then(popup._onProtectionToggled);
|
||||
let message = {
|
||||
'topic': 'whitelist:add-domain',
|
||||
'value': popup._domain
|
||||
};
|
||||
|
||||
chrome.runtime.sendMessage(message, function () {
|
||||
popup._onProtectionToggled();
|
||||
});
|
||||
};
|
||||
|
||||
popup._determineBackgroundPage = function () {
|
||||
popup._determineDomainWhitelistStatus = function () {
|
||||
|
||||
return new Promise((resolve) => {
|
||||
|
||||
chrome.runtime.getBackgroundPage(function (backgroundPage) {
|
||||
let message = {
|
||||
'topic': 'domain:fetch-is-whitelisted',
|
||||
'value': popup._domain
|
||||
};
|
||||
|
||||
chrome.runtime.sendMessage(message, function (response) {
|
||||
|
||||
popup._domainIsWhitelisted = response.value;
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
popup._determineResourceInjections = function () {
|
||||
|
||||
return new Promise((resolve) => {
|
||||
|
||||
let message = {
|
||||
'topic': 'tab:fetch-injections',
|
||||
'value': popup._targetTab.id
|
||||
};
|
||||
|
||||
chrome.runtime.sendMessage(message, function (response) {
|
||||
|
||||
let groupedInjections = popup._groupResourceInjections(response.value);
|
||||
popup._resourceInjections = groupedInjections;
|
||||
|
||||
popup._backgroundPage = backgroundPage;
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
@@ -148,6 +171,12 @@ popup._determineTargetTab = function () {
|
||||
chrome.tabs.query({'active': true, 'currentWindow': true}, function (tabs) {
|
||||
|
||||
popup._targetTab = tabs[0];
|
||||
popup._domain = helpers.extractDomainFromUrl(tabs[0].url);
|
||||
|
||||
if (popup._domain !== null) {
|
||||
popup._domain = helpers.normalizeDomain(popup._domain);
|
||||
}
|
||||
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
@@ -292,8 +321,7 @@ popup._onDocumentLoaded = function () {
|
||||
popup._version = helpers.formatVersion(manifest.version);
|
||||
popup._scriptDirection = helpers.determineScriptDirection(language);
|
||||
|
||||
popup._determineBackgroundPage()
|
||||
.then(popup._determineAmountInjected)
|
||||
popup._determineAmountInjected()
|
||||
.then(popup._renderContents);
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user