Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable on localhosts #2666

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/js/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -930,10 +930,10 @@ Badger.prototype = {
* and if tab_id is for an incognito window,
* is learning in incognito windows enabled?
*/
isLearningEnabled(tab_id) {
isLearningEnabled(tab_id, tab_host) {
return (
this.getSettings().getItem("learnLocally") &&
incognito.learningEnabled(tab_id)
incognito.learningEnabled(tab_id, tab_host)
);
},

Expand Down
2 changes: 1 addition & 1 deletion src/js/heuristicblocking.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ HeuristicBlocker.prototype = {
*/
heuristicBlockingAccounting: function (details, check_for_cookie_share) {
// ignore requests that are outside a tabbed window
if (details.tabId < 0 || !badger.isLearningEnabled(details.tabId)) {
if (details.tabId < 0 || !badger.isLearningEnabled(details.tabId, details.url)) {
return {};
}

Expand Down
6 changes: 5 additions & 1 deletion src/js/incognito.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function startListeners() {
chrome.tabs.onRemoved.addListener(onRemovedListener);
}

function learningEnabled(tab_id) {
function learningEnabled(tab_id, tab_host) {
if (badger.getSettings().getItem("learnInIncognito")) {
// treat all pages as if they're not incognito
return true;
Expand All @@ -35,6 +35,10 @@ function learningEnabled(tab_id) {
if (!tabs.hasOwnProperty(tab_id)) {
return false;
}
// if tab host is a localhost or any private domain, default to disabled
if (window.isPrivateDomain(tab_host)) {
return false;
}
// else, do not learn in incognito tabs
return !tabs[tab_id];
}
Expand Down
6 changes: 3 additions & 3 deletions src/js/webrequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ function onBeforeRequest(details) {
});

// if this is a heuristically- (not user-) blocked domain
if (action == constants.BLOCK && incognito.learningEnabled(tab_id)) {
if (action == constants.BLOCK && incognito.learningEnabled(tab_id, tab_host)) {
// check for DNT policy asynchronously
setTimeout(function () {
badger.checkForDNTPolicy(request_host);
Expand Down Expand Up @@ -966,7 +966,7 @@ function dispatcher(request, sender, sendResponse) {
frame_host = window.extractHostFromURL(request.frameUrl);

sendResponse(frame_host &&
badger.isLearningEnabled(sender.tab.id) &&
badger.isLearningEnabled(sender.tab.id, tab_host) &&
badger.isPrivacyBadgerEnabled(tab_host) &&
utils.isThirdPartyDomain(frame_host, tab_host));

Expand All @@ -977,7 +977,7 @@ function dispatcher(request, sender, sendResponse) {
let tab_host = window.extractHostFromURL(sender.tab.url);

sendResponse(
badger.isLearningEnabled(sender.tab.id) &&
badger.isLearningEnabled(sender.tab.id, tab_host) &&
badger.isPrivacyBadgerEnabled(tab_host));

break;
Expand Down
8 changes: 8 additions & 0 deletions src/tests/tests/tabData.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ function() {
},
});

QUnit.test("learning is disabled on localhost", function (assert) {
const LOCALSITE = "localhost";

assert.notOk(
badger.isLearningEnabled(this.tabId, LOCALSITE), "learning is disabled on localhost site"
);
});

QUnit.test("logging blocked domain", function (assert) {
const DOMAIN = "example.com";

Expand Down