diff --git a/src/js/background.js b/src/js/background.js index 9981a1ceb1..7f7c86fd30 100644 --- a/src/js/background.js +++ b/src/js/background.js @@ -938,6 +938,17 @@ 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? * @@ -945,8 +956,8 @@ Badger.prototype = { */ isLearningEnabled(tab_id) { return ( - this.getSettings().getItem("shareLearning") || - this.isLocalLearningEnabled(tab_id) + this.isLocalLearningEnabled(tab_id) || + this.isCommunityLearningEnabled(tab_id) ); }, diff --git a/src/js/heuristicblocking.js b/src/js/heuristicblocking.js index b75e677a13..46441001fd 100644 --- a/src/js/heuristicblocking.js +++ b/src/js/heuristicblocking.js @@ -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); } diff --git a/src/js/incognito.js b/src/js/incognito.js index 56d2d9332d..c1bfdc1957 100644 --- a/src/js/incognito.js +++ b/src/js/incognito.js @@ -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;