Bug 1741204 - Consolidate cookie policy into one Behavior policy. r=pbz

Differential Revision: https://phabricator.services.mozilla.com/D131825
This commit is contained in:
Mike Kaply 2021-11-23 18:57:53 +00:00
Родитель 59b28c6aa5
Коммит b3c7bf3a3e
3 изменённых файлов: 159 добавлений и 42 удалений

Просмотреть файл

@ -428,50 +428,10 @@ var Policies = {
});
}
if (
param.Default !== undefined ||
param.AcceptThirdParty !== undefined ||
param.RejectTracker !== undefined ||
param.Locked
) {
const ACCEPT_COOKIES = 0;
const REJECT_THIRD_PARTY_COOKIES = 1;
const REJECT_ALL_COOKIES = 2;
const REJECT_UNVISITED_THIRD_PARTY = 3;
const REJECT_TRACKER = 4;
let newCookieBehavior = ACCEPT_COOKIES;
if (param.Default !== undefined && !param.Default) {
newCookieBehavior = REJECT_ALL_COOKIES;
} else if (param.AcceptThirdParty) {
if (param.AcceptThirdParty == "never") {
newCookieBehavior = REJECT_THIRD_PARTY_COOKIES;
} else if (param.AcceptThirdParty == "from-visited") {
newCookieBehavior = REJECT_UNVISITED_THIRD_PARTY;
}
} else if (param.RejectTracker !== undefined && param.RejectTracker) {
newCookieBehavior = REJECT_TRACKER;
}
PoliciesUtils.setDefaultPref(
"network.cookie.cookieBehavior",
newCookieBehavior,
param.Locked
);
PoliciesUtils.setDefaultPref(
"network.cookie.cookieBehavior.pbmode",
newCookieBehavior,
param.Locked
);
}
const KEEP_COOKIES_UNTIL_EXPIRATION = 0;
const KEEP_COOKIES_UNTIL_END_OF_SESSION = 2;
if (param.ExpireAtSessionEnd !== undefined || param.Locked) {
let newLifetimePolicy = KEEP_COOKIES_UNTIL_EXPIRATION;
let newLifetimePolicy = Ci.nsICookieService.ACCEPT_NORMALLY;
if (param.ExpireAtSessionEnd) {
newLifetimePolicy = KEEP_COOKIES_UNTIL_END_OF_SESSION;
newLifetimePolicy = Ci.nsICookieService.ACCEPT_SESSION;
}
PoliciesUtils.setDefaultPref(
@ -480,6 +440,68 @@ var Policies = {
param.Locked
);
}
// New Cookie Behavior option takes precendence
let defaultPref = Services.prefs.getDefaultBranch("");
let newCookieBehavior = defaultPref.getIntPref(
"network.cookie.cookieBehavior"
);
let newCookieBehaviorPB = defaultPref.getIntPref(
"network.cookie.cookieBehavior.pbmode"
);
if ("Behavior" in param || "BehaviorPrivateBrowsing" in param) {
let behaviors = {
accept: Ci.nsICookieService.BEHAVIOR_ACCEPT,
"reject-foreign": Ci.nsICookieService.BEHAVIOR_REJECT_FOREIGN,
reject: Ci.nsICookieService.BEHAVIOR_REJECT,
"limit-foreign": Ci.nsICookieService.BEHAVIOR_LIMIT_FOREIGN,
"reject-tracker": Ci.nsICookieService.BEHAVIOR_REJECT_TRACKER,
"reject-tracker-and-partition-foreign":
Ci.nsICookieService.BEHAVIOR_REJECT_TRACKER_AND_PARTITION_FOREIGN,
};
if ("Behavior" in param) {
newCookieBehavior = behaviors[param.Behavior];
}
if ("BehaviorPrivateBrowsing" in param) {
newCookieBehaviorPB = behaviors[param.BehaviorPrivateBrowsing];
}
} else {
// Default, AcceptThirdParty, and RejectTracker are being
// deprecated in favor of Behavior. They will continue
// to be supported, though.
if (
param.Default !== undefined ||
param.AcceptThirdParty !== undefined ||
param.RejectTracker !== undefined ||
param.Locked
) {
newCookieBehavior = Ci.nsICookieService.BEHAVIOR_ACCEPT;
if (param.Default !== undefined && !param.Default) {
newCookieBehavior = Ci.nsICookieService.BEHAVIOR_REJECT;
} else if (param.AcceptThirdParty) {
if (param.AcceptThirdParty == "never") {
newCookieBehavior = Ci.nsICookieService.BEHAVIOR_REJECT_FOREIGN;
} else if (param.AcceptThirdParty == "from-visited") {
newCookieBehavior = Ci.nsICookieService.BEHAVIOR_LIMIT_FOREIGN;
}
} else if (param.RejectTracker) {
newCookieBehavior = Ci.nsICookieService.BEHAVIOR_REJECT_TRACKER;
}
}
// With the old cookie policy, we made private browsing the same.
newCookieBehaviorPB = newCookieBehavior;
}
// We set the values no matter what just in case the policy was only used to lock.
PoliciesUtils.setDefaultPref(
"network.cookie.cookieBehavior",
newCookieBehavior,
param.Locked
);
PoliciesUtils.setDefaultPref(
"network.cookie.cookieBehavior.pbmode",
newCookieBehaviorPB,
param.Locked
);
},
},

Просмотреть файл

@ -217,7 +217,18 @@
"Locked": {
"type": "boolean"
},
"Behavior": {
"type": "string",
"enum": ["accept", "reject-foreign", "reject", "limit-foreign", "reject-tracker", "reject-tracker-and-partition-foreign"]
},
"BehaviorPrivateBrowsing": {
"type": "string",
"enum": ["accept", "reject-foreign", "reject", "limit-foreign", "reject-tracker", "reject-tracker-and-partition-foreign"]
}
}
},

Просмотреть файл

@ -817,6 +817,90 @@ const POLICIES_TESTS = [
"network.http.windows-sso.enabled": true,
},
},
{
policies: {
Cookies: {
Behavior: "accept",
BehaviorPrivateBrowsing: "reject-foreign",
Locked: true,
},
},
lockedPrefs: {
"network.cookie.cookieBehavior": 0,
"network.cookie.cookieBehavior.pbmode": 1,
},
},
{
policies: {
Cookies: {
Behavior: "reject-foreign",
BehaviorPrivateBrowsing: "reject",
Locked: true,
},
},
lockedPrefs: {
"network.cookie.cookieBehavior": 1,
"network.cookie.cookieBehavior.pbmode": 2,
},
},
{
policies: {
Cookies: {
Behavior: "reject",
BehaviorPrivateBrowsing: "limit-foreign",
Locked: true,
},
},
lockedPrefs: {
"network.cookie.cookieBehavior": 2,
"network.cookie.cookieBehavior.pbmode": 3,
},
},
{
policies: {
Cookies: {
Behavior: "limit-foreign",
BehaviorPrivateBrowsing: "reject-tracker",
Locked: true,
},
},
lockedPrefs: {
"network.cookie.cookieBehavior": 3,
"network.cookie.cookieBehavior.pbmode": 4,
},
},
{
policies: {
Cookies: {
Behavior: "reject-tracker",
BehaviorPrivateBrowsing: "reject-tracker-and-partition-foreign",
Locked: true,
},
},
lockedPrefs: {
"network.cookie.cookieBehavior": 4,
"network.cookie.cookieBehavior.pbmode": 5,
},
},
{
policies: {
Cookies: {
Behavior: "reject-tracker-and-partition-foreign",
BehaviorPrivateBrowsing: "accept",
Locked: true,
},
},
lockedPrefs: {
"network.cookie.cookieBehavior": 5,
"network.cookie.cookieBehavior.pbmode": 0,
},
},
];
add_task(async function test_policy_simple_prefs() {