Skip to content

Commit

Permalink
Adding option to disable sending the DNT signal. Fixes #2038
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike Tung committed Jul 9, 2018
1 parent 2b9f1f2 commit 779ad89
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 4 deletions.
6 changes: 5 additions & 1 deletion src/_locales/en_US/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
"message": "Currently Privacy Badger only checks if third parties are using cookies, HTML5 local storage, or canvas fingerprinting to track your browsing. Some of these domains may be using tracking methods that Privacy Badger can't detect.",
"description": ""
},
"options_enable_dnt_checkbox": {
"message": "Enable sending DNT header",
"description": ""
},
"options_dnt_policy_setting": {
"message": "Check if sites comply with EFF's Do Not Track policy",
"description": "Checkbox label on the general settings page"
Expand Down Expand Up @@ -439,4 +443,4 @@
"message": "Oops. Something went wrong.",
"description": ""
}
}
}
8 changes: 8 additions & 0 deletions src/js/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,7 @@ Badger.prototype = {
showCounter: true,
showTrackingDomains: false,
socialWidgetReplacementEnabled: true,
DNTEnabled: true
},

/**
Expand Down Expand Up @@ -612,6 +613,13 @@ Badger.prototype = {
return this.getSettings().getItem("socialWidgetReplacementEnabled");
},

/**
* Check if social widget replacement functionality is enabled
*/
isDNTEnabled: function() {
return this.getSettings().getItem("DNTEnabled");
},

isCheckingDNTPolicyEnabled: function() {
return this.getSettings().getItem("checkForDNTPolicy");
},
Expand Down
19 changes: 19 additions & 0 deletions src/js/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ function loadOptions() {
$("#show_counter_checkbox").prop("checked", badger.showCounter());
$("#replace_social_widgets_checkbox").on("click", updateSocialWidgetReplacement);
$("#replace_social_widgets_checkbox").prop("checked", badger.isSocialWidgetReplacementEnabled());
$("#enable_dnt_checkbox").on("click", updateDNTCheckboxClicked);
$("#enable_dnt_checkbox").prop("checked", badger.isDNTEnabled());
$("#check_dnt_policy_checkbox").on("click", updateCheckingDNTPolicy);
$("#check_dnt_policy_checkbox").prop("checked", badger.isCheckingDNTPolicyEnabled());

Expand Down Expand Up @@ -316,6 +318,23 @@ function updateSocialWidgetReplacement() {
});
}

/**
* Update DNT checkbox clicked
*/
function updateDNTCheckboxClicked() {
const enabled = $("#enable_dnt_checkbox").prop("checked");

chrome.runtime.sendMessage({
type: "updateSettings",
data: {
DNTEnabled: enabled
}
});

$("#check_dnt_policy_checkbox").prop("checked", enabled).prop("disabled", enabled);
updateCheckingDNTPolicy();
}

function updateCheckingDNTPolicy() {
const enabled = $("#check_dnt_policy_checkbox").prop("checked");

Expand Down
12 changes: 9 additions & 3 deletions src/js/webrequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,9 @@ function onBeforeSendHeaders(details) {
if (!isThirdPartyDomain(requestDomain, tabDomain)) {
if (badger.isPrivacyBadgerEnabled(tabDomain)) {
// Still sending Do Not Track even if HTTP and cookie blocking are disabled
details.requestHeaders.push({name: "DNT", value: "1"});
if (badger.isDNTEnabled()) {
details.requestHeaders.push({name: "DNT", value: "1"});
}
return {requestHeaders: details.requestHeaders};
} else {
return {};
Expand Down Expand Up @@ -233,13 +235,17 @@ function onBeforeSendHeaders(details) {
let newHeaders = details.requestHeaders.filter(function (header) {
return (header.name.toLowerCase() != "cookie" && header.name.toLowerCase() != "referer");
});
newHeaders.push({name: "DNT", value: "1"});
if (badger.isDNTEnabled()) {
newHeaders.push({name: "DNT", value: "1"});
}
return {requestHeaders: newHeaders};
}

// if we are here, we're looking at a third party
// that's not yet blocked or cookieblocked
details.requestHeaders.push({name: "DNT", value: "1"});
if (badger.isDNTEnabled()) {
details.requestHeaders.push({name: "DNT", value: "1"});
}
return {requestHeaders: details.requestHeaders};
}

Expand Down
6 changes: 6 additions & 0 deletions src/skin/options.html
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,12 @@ <h1><span class="i18n_options_title"></span></h1>
<span class="i18n_options_social_widgets_checkbox"></span>
</label>
</div>
<div class="checkbox">
<label>
<input type="checkbox" id="enable_dnt_checkbox">
<span class="i18n_options_enable_dnt_checkbox"></span>
</label>
</div>
<div class="checkbox">
<label>
<input type="checkbox" id="check_dnt_policy_checkbox">
Expand Down

0 comments on commit 779ad89

Please sign in to comment.