Skip to content

Commit

Permalink
Skip DNT policy checking when importing user data.
Browse files Browse the repository at this point in the history
  • Loading branch information
ghostwords committed Jan 4, 2018
1 parent 611ad70 commit 12fd302
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 13 deletions.
33 changes: 21 additions & 12 deletions src/js/heuristicblocking.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,24 +138,30 @@ HeuristicBlocker.prototype = {
/**
* Wraps _recordPrevalence for use outside of webRequest listeners.
*
* @param tracker_fqdn The fully qualified domain name of the tracker
* @param page_origin The base domain of the page where the tracker
* was detected
* @returns {*}
* @param {String} tracker_fqdn The fully qualified domain name of the tracker
* @param {String} page_origin The base domain of the page
* where the tracker was detected.
* @param {Boolean} skip_dnt_check Skip DNT policy checking if flag is true.
*
*/
updateTrackerPrevalence: function(tracker_fqdn, page_origin) {
updateTrackerPrevalence: function(tracker_fqdn, page_origin, skip_dnt_check) {
// abort if we already made a decision for this fqdn
let action = this.storage.getAction(tracker_fqdn);
if (action != constants.NO_TRACKING && action != constants.ALLOW) {
return;
}

this._recordPrevalence(tracker_fqdn, window.getBaseDomain(tracker_fqdn), page_origin);
this._recordPrevalence(
tracker_fqdn,
window.getBaseDomain(tracker_fqdn),
page_origin,
skip_dnt_check
);
},

/**
* Record HTTP request prevalence. Block a tracker if seen on more
* than [constants.TRACKING_THRESHOLD] pages
* than constants.TRACKING_THRESHOLD pages
*
* NOTE: This is a private function and should never be called directly.
* All calls should be routed through heuristicBlockingAccounting for normal usage
Expand All @@ -165,9 +171,10 @@ HeuristicBlocker.prototype = {
* @param {String} tracker_fqdn The FQDN of the third party tracker
* @param {String} tracker_origin Base domain of the third party tracker
* @param {String} page_origin The origin of the page where the third party
* tracker was loaded
* tracker was loaded.
* @param {Boolean} skip_dnt_check Skip DNT policy checking if flag is true.
*/
_recordPrevalence: function (tracker_fqdn, tracker_origin, page_origin) {
_recordPrevalence: function (tracker_fqdn, tracker_origin, page_origin, skip_dnt_check) {
var snitch_map = this.storage.getBadgerStorageObject('snitch_map');
var firstParties = [];
if (snitch_map.hasItem(tracker_origin)) {
Expand All @@ -181,9 +188,11 @@ HeuristicBlocker.prototype = {
// Check this just-seen-tracking-on-this-site,
// not-yet-blocked domain for DNT policy.
// We check heuristically-blocked domains in webrequest.js.
window.setTimeout(function () {
badger.checkForDNTPolicy(tracker_fqdn);
}, 10);
if (!skip_dnt_check) {
window.setTimeout(function () {
badger.checkForDNTPolicy(tracker_fqdn);
}, 10);
}

// record that we've seen this tracker on this domain (in snitch map)
firstParties.push(page_origin);
Expand Down
3 changes: 2 additions & 1 deletion src/js/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,8 @@ BadgerStorage.prototype = {
for (let origin in firstPartyOrigins) {
badger.heuristicBlocking.updateTrackerPrevalence(
tracker_fqdn,
firstPartyOrigins[origin]
firstPartyOrigins[origin],
true // skip DNT policy checking on data import
);
}
}
Expand Down

0 comments on commit 12fd302

Please sign in to comment.