From dd8500b3276f2cc6f4fd958a9a805a18b8bc84f1 Mon Sep 17 00:00:00 2001 From: Mark Striemer Date: Wed, 9 Aug 2017 15:47:02 -0500 Subject: [PATCH] Bug 1345158 - Implement privacy.websites.trackingProtectionMode r=aswan,bsilverberg MozReview-Commit-ID: Lf88M4V4JEJ --HG-- extra : rebase_source : 8b7a716a2e82ce31f0500afe0e4342ef7bc94064 --- toolkit/components/extensions/ext-privacy.js | 42 +++++++++++++++++++ .../extensions/schemas/privacy.json | 12 ++++++ .../test/xpcshell/test_ext_privacy.js | 13 ++++++ 3 files changed, 67 insertions(+) diff --git a/toolkit/components/extensions/ext-privacy.js b/toolkit/components/extensions/ext-privacy.js index fbbd73415c00..22a495031064 100644 --- a/toolkit/components/extensions/ext-privacy.js +++ b/toolkit/components/extensions/ext-privacy.js @@ -138,6 +138,36 @@ ExtensionPreferencesManager.addSetting("websites.referrersEnabled", { }, }); +ExtensionPreferencesManager.addSetting("websites.trackingProtectionMode", { + prefNames: [ + "privacy.trackingprotection.enabled", + "privacy.trackingprotection.pbmode.enabled", + ], + + setCallback(value) { + // Default to private browsing. + let prefs = { + "privacy.trackingprotection.enabled": false, + "privacy.trackingprotection.pbmode.enabled": true, + }; + + switch (value) { + case "private_browsing": + break; + + case "always": + prefs["privacy.trackingprotection.enabled"] = true; + break; + + case "never": + prefs["privacy.trackingprotection.pbmode.enabled"] = false; + break; + } + + return prefs; + }, +}); + this.privacy = class extends ExtensionAPI { getAPI(context) { let {extension} = context; @@ -196,6 +226,18 @@ this.privacy = class extends ExtensionAPI { () => { return Preferences.get("network.http.sendRefererHeader") !== 0; }), + trackingProtectionMode: getPrivacyAPI(extension, + "websites.trackingProtectionMode", + () => { + if (Preferences.get("privacy.trackingprotection.enabled")) { + return "always"; + } else if ( + Preferences.get("privacy.trackingprotection.pbmode.enabled")) { + return "private_browsing"; + } + return "never"; + }), + }, }, }; diff --git a/toolkit/components/extensions/schemas/privacy.json b/toolkit/components/extensions/schemas/privacy.json index d85afc4d7b95..1718727f1182 100644 --- a/toolkit/components/extensions/schemas/privacy.json +++ b/toolkit/components/extensions/schemas/privacy.json @@ -63,6 +63,14 @@ "namespace": "privacy.websites", "description": "Use the browser.privacy API to control usage of the features in the browser that can affect a user's privacy.", "permissions": ["privacy"], + "types": [ + { + "id": "TrackingProtectionModeOption", + "type": "string", + "enum": ["always", "never", "private_browsing"], + "description": "The mode for tracking protection." + } + ], "properties": { "thirdPartyCookiesAllowed": { "$ref": "types.Setting", @@ -81,6 +89,10 @@ "$ref": "types.Setting", "description": "Available on Windows and ChromeOS only: If enabled, the browser provides a unique ID to plugins in order to run protected content. The value of this preference is of type boolean, and the default value is true.", "unsupported": true + }, + "trackingProtectionMode": { + "$ref": "types.Setting", + "description": "Allow users to specify the mode for tracking protection. This setting's value is of type TrackingProtectionModeOption, defaulting to private_browsing_only." } } } diff --git a/toolkit/components/extensions/test/xpcshell/test_ext_privacy.js b/toolkit/components/extensions/test/xpcshell/test_ext_privacy.js index d447846cf2eb..079b53ced5c2 100644 --- a/toolkit/components/extensions/test/xpcshell/test_ext_privacy.js +++ b/toolkit/components/extensions/test/xpcshell/test_ext_privacy.js @@ -339,6 +339,19 @@ add_task(async function test_privacy_other_prefs() { "network.http.sendRefererHeader": 2, }); + await testSetting("websites.trackingProtectionMode", "always", { + "privacy.trackingprotection.enabled": true, + "privacy.trackingprotection.pbmode.enabled": true, + }); + await testSetting("websites.trackingProtectionMode", "never", { + "privacy.trackingprotection.enabled": false, + "privacy.trackingprotection.pbmode.enabled": false, + }); + await testSetting("websites.trackingProtectionMode", "private_browsing", { + "privacy.trackingprotection.enabled": false, + "privacy.trackingprotection.pbmode.enabled": true, + }); + await testSetting("services.passwordSavingEnabled", false, { "signon.rememberSignons": false,