Bug 1345158 - Implement privacy.websites.trackingProtectionMode r?aswan
MozReview-Commit-ID: Lf88M4V4JEJ
--- a/toolkit/components/extensions/ext-privacy.js
+++ b/toolkit/components/extensions/ext-privacy.js
@@ -133,16 +133,46 @@ ExtensionPreferencesManager.addSetting("
// Values for network.http.sendRefererHeader:
// 0=don't send any, 1=send only on clicks, 2=send on image requests as well
// http://searchfox.org/mozilla-central/rev/61054508641ee76f9c49bcf7303ef3cfb6b410d2/modules/libpref/init/all.js#1585
setCallback(value) {
return {[this.prefNames[0]]: value ? 2 : 0};
},
});
+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;
return {
privacy: {
network: {
networkPredictionEnabled: getPrivacyAPI(extension,
"network.networkPredictionEnabled",
@@ -191,13 +221,25 @@ this.privacy = class extends ExtensionAP
() => {
return Preferences.get("browser.send_pings");
}),
referrersEnabled: getPrivacyAPI(extension,
"websites.referrersEnabled",
() => {
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";
+ }),
+
},
},
};
}
};
--- a/toolkit/components/extensions/schemas/privacy.json
+++ b/toolkit/components/extensions/schemas/privacy.json
@@ -58,16 +58,24 @@
"description": "If enabled, the password manager will ask if you want to save passwords. This preference's value is a boolean, defaulting to <code>true</code>."
}
}
},
{
"namespace": "privacy.websites",
"description": "Use the <code>browser.privacy</code> 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",
"description": "If disabled, the browser blocks third-party sites from setting cookies. The value of this preference is of type boolean, and the default value is <code>true</code>.",
"unsupported": true
},
"hyperlinkAuditingEnabled": {
"$ref": "types.Setting",
@@ -76,12 +84,16 @@
"referrersEnabled": {
"$ref": "types.Setting",
"description": "If enabled, the browser sends <code>referer</code> headers with your requests. Yes, the name of this preference doesn't match the misspelled header. No, we're not going to change it. The value of this preference is of type boolean, and the default value is <code>true</code>."
},
"protectedContentEnabled": {
"$ref": "types.Setting",
"description": "<strong>Available on Windows and ChromeOS only</strong>: 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 <code>true</code>.",
"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 <code>private_browsing_only</code>."
}
}
}
]
--- a/toolkit/components/extensions/test/xpcshell/test_ext_privacy.js
+++ b/toolkit/components/extensions/test/xpcshell/test_ext_privacy.js
@@ -334,16 +334,29 @@ add_task(async function test_privacy_oth
{
"network.http.sendRefererHeader": 0,
});
await testSetting("websites.referrersEnabled", true,
{
"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,
});
await testSetting("services.passwordSavingEnabled", true,
{
"signon.rememberSignons": true,
});