Bug 1818583 - Add a pref to control Email Tracking Protection in private windows. r=dimi

Differential Revision: https://phabricator.services.mozilla.com/D170822
This commit is contained in:
Tim Huang 2023-02-28 09:12:13 +00:00
parent 9e0ba81905
commit 5403065ddc
4 changed files with 68 additions and 7 deletions

View File

@ -12740,12 +12740,18 @@
value: true
mirror: always
# Block 3rd party emailtracking resources.
# Block 3rd party emailtracking resources in all mode.
- name: privacy.trackingprotection.emailtracking.enabled
type: bool
value: @IS_NIGHTLY_BUILD@
mirror: always
# Block 3rd party emailtracking resources in Private Browsing mode.
- name: privacy.trackingprotection.emailtracking.pbmode.enabled
type: bool
value: true
mirror: always
# Collecting 3rd party emailtracking telemetry.
- name: privacy.trackingprotection.emailtracking.data_collection.enabled
type: bool

View File

@ -15,6 +15,7 @@
#include "nsILoadContext.h"
#include "nsIHttpChannelInternal.h"
#include "nsIWebProgressListener.h"
#include "nsNetUtil.h"
namespace mozilla::net {
@ -91,7 +92,10 @@ UrlClassifierFeatureEmailTrackingProtection::MaybeCreate(nsIChannel* aChannel) {
aChannel));
// Check if the email tracking protection is enabled.
if (!StaticPrefs::privacy_trackingprotection_emailtracking_enabled()) {
if (!StaticPrefs::privacy_trackingprotection_emailtracking_enabled() &&
!(NS_UsePrivateBrowsing(aChannel) &&
StaticPrefs::
privacy_trackingprotection_emailtracking_pbmode_enabled())) {
return nullptr;
}

View File

@ -10,6 +10,7 @@ add_setup(async function() {
await SpecialPowers.pushPrefEnv({
set: [
["privacy.trackingprotection.enabled", false],
["privacy.trackingprotection.pbmode.enabled", false],
["privacy.trackingprotection.annotate_channels", false],
["privacy.trackingprotection.cryptomining.enabled", false],
["privacy.trackingprotection.emailtracking.enabled", true],
@ -48,12 +49,24 @@ function runTest(obj) {
"privacy.trackingprotection.emailtracking.enabled",
obj.protectionEnabled,
],
[
"privacy.trackingprotection.emailtracking.pbmode.enabled",
obj.protectionPrivateEnabled,
],
],
});
let win;
if (obj.testPrivate) {
win = await BrowserTestUtils.openNewBrowserWindow({ private: true });
} else {
win = window;
}
info("Creating a non-tracker top-level context");
let tab = BrowserTestUtils.addTab(gBrowser, TEST_TOP_PAGE);
let browser = gBrowser.getBrowserForTab(tab);
let tab = BrowserTestUtils.addTab(win.gBrowser, TEST_TOP_PAGE);
let browser = tab.linkedBrowser;
await BrowserTestUtils.browserLoaded(browser);
info("The non-tracker page opens an email tracker iframe");
@ -109,6 +122,9 @@ function runTest(obj) {
}
BrowserTestUtils.removeTab(tab);
if (obj.testPrivate) {
await BrowserTestUtils.closeWindow(win);
}
await SpecialPowers.popPrefEnv();
});
}
@ -117,6 +133,7 @@ runTest({
testName:
"EmailTracking-dataCollection feature enabled but not considered for tracking detection.",
protectionEnabled: false,
protectionPrivateEnabled: false,
loading: true,
expectedLogItems: [
[
@ -130,8 +147,36 @@ runTest({
runTest({
testName: "Emailtracking-protection feature enabled.",
protectionEnabled: true,
protectionPrivateEnabled: true,
loading: false,
expectedLogItems: [
[Ci.nsIWebProgressListener.STATE_BLOCKED_EMAILTRACKING_CONTENT, true, 2],
],
});
runTest({
testName:
"Emailtracking-protection feature enabled for private windows and doesn't block in normal windows",
protectionEnabled: false,
protectionPrivateEnabled: true,
loading: true,
expectedLogItems: [
[
Ci.nsIWebProgressListener.STATE_LOADED_EMAILTRACKING_LEVEL_1_CONTENT,
true,
2,
],
],
});
runTest({
testName:
"Emailtracking-protection feature enabled for private windows and block in private windows",
testPrivate: true,
protectionEnabled: true,
protectionPrivateEnabled: true,
loading: false,
expectedLogItems: [
[Ci.nsIWebProgressListener.STATE_BLOCKED_EMAILTRACKING_CONTENT, true, 1],
],
});

View File

@ -260,9 +260,15 @@ const FEATURES = [
"urlclassifier.features.emailtracking.allowlistTables",
],
enabled() {
return Services.prefs.getBoolPref(
"privacy.trackingprotection.emailtracking.enabled",
false
return (
Services.prefs.getBoolPref(
"privacy.trackingprotection.emailtracking.enabled",
false
) ||
Services.prefs.getBoolPref(
"privacy.trackingprotection.emailtracking.pbmode.enabled",
false
)
);
},
update() {