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

Add flag to disable remote updates #2394

Closed
wants to merge 2 commits into from
Closed
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
5 changes: 5 additions & 0 deletions src/data/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
"type": "string"
}
},
"fetchRemoteResources": {
"title": "Fetch remote resources",
"description": "Set to false to avoid fetching more recent versions of Privacy Badger resources over the Web from eff.org.",
"type": "boolean"
},
"learnInIncognito": {
"title": "Learn in Private/Incognito windows",
"description": "Enabling learning in Private/Incognito windows may leave traces of your private browsing history on your computer. By default, Privacy Badger will block trackers it already knows about in Private/Incognito windows, but it won't learn about new trackers. You might want to enable this option if a lot of your browsing happens in Private/Incognito windows.",
Expand Down
13 changes: 11 additions & 2 deletions src/js/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,10 @@ Badger.prototype = {
callback = _.noop;
}

if (!self.getSettings().getItem("fetchRemoteResources")) {
return callback(false);
}

utils.xhrRequest(constants.YELLOWLIST_URL, function (err, response) {
if (err) {
console.error(
Expand Down Expand Up @@ -397,12 +401,16 @@ Badger.prototype = {
/**
* Fetch acceptable DNT policy hashes from the EFF server
*/
updateDNTPolicyHashes: function() {
updateDNTPolicyHashes: function () {
var self = this;

if (!self.isCheckingDNTPolicyEnabled()) {
// user has disabled this, we can check when they re-enable
return ;
return;
}

if (!self.getSettings().getItem("fetchRemoteResources")) {
return;
}

utils.xhrRequest(constants.DNT_POLICIES_URL, function(err, response) {
Expand Down Expand Up @@ -493,6 +501,7 @@ Badger.prototype = {
defaultSettings: {
checkForDNTPolicy: true,
disabledSites: [],
fetchRemoteResources: true,
hideBlockedElements: true,
isFirstRun: true,
learnInIncognito: false,
Expand Down
27 changes: 27 additions & 0 deletions src/tests/tests/yellowlist.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,33 @@ QUnit.module("Yellowlist", (hooks) => {
}
});

QUnit.test("Disabling remote updates", (assert) => {
let done = assert.async();
assert.expect(3);

server.respondWith("GET", constants.YELLOWLIST_URL,
[200, {}, Object.keys(get_ylist()).join("\n")]);

badger.updateYellowlist(function (success) {
assert.ok(success, "updating works by default");

// disable remote updates
badger.getSettings().setItem("fetchRemoteResources", false);

badger.updateYellowlist(function (success2) {
assert.notOk(success2, "updating fails when remote updates are disabled");

// re-enable remote updates
badger.getSettings().setItem("fetchRemoteResources", true);

badger.updateYellowlist(function (success3) {
assert.ok(success3, "updating works again");
done();
});
});
});
});

QUnit.module("Removing domains", () => {
let TESTS = [
{
Expand Down