Skip to content

Commit 86432ed

Browse files
committed
Do not do community learning in incognito windows
1 parent 85bfd6b commit 86432ed

File tree

3 files changed

+28
-10
lines changed

3 files changed

+28
-10
lines changed

src/js/background.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -938,15 +938,26 @@ Badger.prototype = {
938938
);
939939
},
940940

941+
/**
942+
* Is community learning generally enabled,
943+
* and is tab_id in a regular (not incognito) window?
944+
*/
945+
isCommunityLearningEnabled(tab_id) {
946+
return (
947+
this.getSettings().getItem("shareLearning") &&
948+
!incognito.isIncognito(tab_id)
949+
);
950+
},
951+
941952
/**
942953
* Is any kind of learning (local or community) enabled on this tab?
943954
*
944955
* TODO: should community learning happen in incognito tabs?
945956
*/
946957
isLearningEnabled(tab_id) {
947958
return (
948-
this.getSettings().getItem("shareLearning") ||
949-
this.isLocalLearningEnabled(tab_id)
959+
this.isLocalLearningEnabled(tab_id) ||
960+
this.isCommunityLearningEnabled(tab_id)
950961
);
951962
},
952963

src/js/heuristicblocking.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ HeuristicBlocker.prototype = {
328328
}
329329

330330
// If community learning is enabled, queue up a request to the EFF server
331-
if (badger.getSettings().getItem("shareLearning")) {
331+
if (badger.isCommunityLearningEnabled(tab_id)) {
332332
let page_fqdn = (new URI(this.tabUrls[tab_id])).host;
333333
this.shareTrackerInfo(page_fqdn, tracker_fqdn, tracker_type);
334334
}

src/js/incognito.js

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,23 +25,30 @@ function startListeners() {
2525
chrome.tabs.onRemoved.addListener(onRemovedListener);
2626
}
2727

28+
function isIncognito(tab_id) {
29+
// if we don't have incognito data for whatever reason,
30+
// default to "true"
31+
if (!tabs.hasOwnProperty(tab_id)) {
32+
return true;
33+
}
34+
// else, do not learn in incognito tabs
35+
return tabs[tab_id];
36+
}
37+
2838
function learningEnabled(tab_id) {
2939
if (badger.getSettings().getItem("learnInIncognito")) {
3040
// treat all pages as if they're not incognito
3141
return true;
3242
}
33-
// if we don't have incognito data for whatever reason,
34-
// default to disabled
35-
if (!tabs.hasOwnProperty(tab_id)) {
36-
return false;
37-
}
38-
// else, do not learn in incognito tabs
39-
return !tabs[tab_id];
43+
44+
// otherwise, return true if this tab is _not_ incognito
45+
return !isIncognito(tab_id);
4046
}
4147

4248
/************************************** exports */
4349
let exports = {
4450
learningEnabled,
51+
isIncognito,
4552
startListeners,
4653
};
4754
return exports;

0 commit comments

Comments
 (0)