Skip to content

Commit

Permalink
Do not do community learning in incognito windows
Browse files Browse the repository at this point in the history
  • Loading branch information
bcyphers committed Oct 28, 2020
1 parent 85bfd6b commit 86432ed
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 10 deletions.
15 changes: 13 additions & 2 deletions src/js/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -938,15 +938,26 @@ Badger.prototype = {
);
},

/**
* Is community learning generally enabled,
* and is tab_id in a regular (not incognito) window?
*/
isCommunityLearningEnabled(tab_id) {
return (
this.getSettings().getItem("shareLearning") &&
!incognito.isIncognito(tab_id)
);
},

/**
* Is any kind of learning (local or community) enabled on this tab?
*
* TODO: should community learning happen in incognito tabs?
*/
isLearningEnabled(tab_id) {
return (
this.getSettings().getItem("shareLearning") ||
this.isLocalLearningEnabled(tab_id)
this.isLocalLearningEnabled(tab_id) ||
this.isCommunityLearningEnabled(tab_id)
);
},

Expand Down
2 changes: 1 addition & 1 deletion src/js/heuristicblocking.js
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ HeuristicBlocker.prototype = {
}

// If community learning is enabled, queue up a request to the EFF server
if (badger.getSettings().getItem("shareLearning")) {
if (badger.isCommunityLearningEnabled(tab_id)) {
let page_fqdn = (new URI(this.tabUrls[tab_id])).host;
this.shareTrackerInfo(page_fqdn, tracker_fqdn, tracker_type);
}
Expand Down
21 changes: 14 additions & 7 deletions src/js/incognito.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,30 @@ function startListeners() {
chrome.tabs.onRemoved.addListener(onRemovedListener);
}

function isIncognito(tab_id) {
// if we don't have incognito data for whatever reason,
// default to "true"
if (!tabs.hasOwnProperty(tab_id)) {
return true;
}
// else, do not learn in incognito tabs
return tabs[tab_id];
}

function learningEnabled(tab_id) {
if (badger.getSettings().getItem("learnInIncognito")) {
// treat all pages as if they're not incognito
return true;
}
// if we don't have incognito data for whatever reason,
// default to disabled
if (!tabs.hasOwnProperty(tab_id)) {
return false;
}
// else, do not learn in incognito tabs
return !tabs[tab_id];

// otherwise, return true if this tab is _not_ incognito
return !isIncognito(tab_id);
}

/************************************** exports */
let exports = {
learningEnabled,
isIncognito,
startListeners,
};
return exports;
Expand Down

0 comments on commit 86432ed

Please sign in to comment.