Verified Commit 89d0191e authored by Thomas Rientjes's avatar Thomas Rientjes
Browse files

Resolve #163 by making metadata sanitation optional

parent ab6c387b
......@@ -161,6 +161,22 @@ stateManager._updateTab = function (details) {
}
};
stateManager._stripMetadata = function (requestDetails) {
for (let i = 0; i < requestDetails.requestHeaders.length; ++i) {
if (requestDetails.requestHeaders[i].name === 'Origin') {
requestDetails.requestHeaders.splice(i, 1);
} else if (requestDetails.requestHeaders[i].name === 'Referer') {
requestDetails.requestHeaders.splice(i, 1);
}
}
return {
'requestHeaders': requestDetails.requestHeaders
};
};
stateManager._handleStorageChanged = function (changes) {
if ('showIconBadge' in changes) {
......@@ -174,6 +190,24 @@ stateManager._handleStorageChanged = function (changes) {
});
}
}
if ('stripMetadata' in changes) {
let onBeforeSendHeaders;
onBeforeSendHeaders = chrome.webRequest.onBeforeSendHeaders;
onBeforeSendHeaders.removeListener(stateManager._stripMetadata, {
'urls': stateManager.validHosts
}, [BLOCKING_ACTION, REQUEST_HEADERS]);
if (changes.stripMetadata.newValue !== false) {
onBeforeSendHeaders.addListener(stateManager._stripMetadata, {
'urls': stateManager.validHosts
}, [BLOCKING_ACTION, REQUEST_HEADERS]);
}
}
};
stateManager._removeIconBadgeFromTab = function (tab) {
......@@ -241,19 +275,8 @@ chrome.webRequest.onBeforeRedirect.addListener(function (requestDetails) {
}, {'urls': ['*://*/*']});
chrome.webRequest.onBeforeSendHeaders.addListener(function (requestDetails) {
for (let i = 0; i < requestDetails.requestHeaders.length; ++i) {
if (requestDetails.requestHeaders[i].name === 'Origin') {
requestDetails.requestHeaders.splice(i, 1);
} else if (requestDetails.requestHeaders[i].name === 'Referer') {
requestDetails.requestHeaders.splice(i, 1);
}
}
return {requestHeaders: requestDetails.requestHeaders};
}, {urls: stateManager.validHosts}, [BLOCKING_ACTION, REQUEST_HEADERS]);
chrome.webRequest.onBeforeSendHeaders.addListener(stateManager._stripMetadata, {
'urls': stateManager.validHosts
}, [BLOCKING_ACTION, REQUEST_HEADERS]);
chrome.storage.onChanged.addListener(stateManager._handleStorageChanged);
......@@ -78,7 +78,7 @@
<label class="label-checkbox">
<input class="input-checkbox" data-option="stripMetadata" type="checkbox" disabled>
<input class="input-checkbox" data-option="stripMetadata" type="checkbox">
<span data-i18n-content="stripMetadataTitle"></span>
</label>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment