Bug 1540810 - Part 1: Add a cookie settings API for partitioning third-party content; r=baku

Differential Revision: https://phabricator.services.mozilla.com/D54572

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Ehsan Akhgari 2020-02-28 19:39:58 +00:00
Родитель 9b414b6cd2
Коммит 50ef8c407b
4 изменённых файлов: 66 добавлений и 2 удалений

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

@ -16000,7 +16000,13 @@ nsICookieSettings* Document::CookieSettings() {
// If we are here, this is probably a javascript: URL document. In any case,
// we must have a nsCookieSettings. Let's create it.
if (!mCookieSettings) {
mCookieSettings = net::CookieSettings::Create();
Document* inProcessParent = GetInProcessParentDocument();
mCookieSettings =
inProcessParent
? net::CookieSettings::Create(
inProcessParent->CookieSettings()->GetCookieBehavior())
: net::CookieSettings::Create();
}
return mCookieSettings;

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

@ -81,6 +81,16 @@ already_AddRefed<nsICookieSettings> CookieSettings::Create() {
return cookieSettings.forget();
}
// static
already_AddRefed<nsICookieSettings> CookieSettings::Create(
uint32_t aCookieBehavior) {
MOZ_ASSERT(NS_IsMainThread());
RefPtr<CookieSettings> cookieSettings =
new CookieSettings(aCookieBehavior, eProgressive);
return cookieSettings.forget();
}
CookieSettings::CookieSettings(uint32_t aCookieBehavior, State aState)
: mCookieBehavior(aCookieBehavior), mState(aState), mToBeMerged(false) {
MOZ_ASSERT(NS_IsMainThread());
@ -124,6 +134,23 @@ CookieSettings::GetLimitForeignContexts(bool* aLimitForeignContexts) {
return NS_OK;
}
NS_IMETHODIMP
CookieSettings::GetPartitionForeign(bool* aPartitionForeign) {
*aPartitionForeign =
mCookieBehavior ==
nsICookieService::BEHAVIOR_REJECT_TRACKER_AND_PARTITION_FOREIGN;
return NS_OK;
}
NS_IMETHODIMP
CookieSettings::SetPartitionForeign(bool aPartitionForeign) {
if (aPartitionForeign) {
mCookieBehavior =
nsICookieService::BEHAVIOR_REJECT_TRACKER_AND_PARTITION_FOREIGN;
}
return NS_OK;
}
NS_IMETHODIMP
CookieSettings::CookiePermission(nsIPrincipal* aPrincipal,
uint32_t* aCookiePermission) {
@ -262,12 +289,36 @@ void CookieSettings::Serialize(CookieSettingsArgs& aData) {
void CookieSettings::Merge(const CookieSettingsArgs& aData) {
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(mCookieBehavior == aData.cookieBehavior());
MOZ_ASSERT(
mCookieBehavior == aData.cookieBehavior() ||
(mCookieBehavior == nsICookieService::BEHAVIOR_REJECT_TRACKER &&
aData.cookieBehavior() ==
nsICookieService::BEHAVIOR_REJECT_TRACKER_AND_PARTITION_FOREIGN) ||
(mCookieBehavior ==
nsICookieService::BEHAVIOR_REJECT_TRACKER_AND_PARTITION_FOREIGN &&
aData.cookieBehavior() == nsICookieService::BEHAVIOR_REJECT_TRACKER));
if (mState == eFixed) {
return;
}
// Merge cookie behavior pref values
if (mCookieBehavior == nsICookieService::BEHAVIOR_REJECT_TRACKER &&
aData.cookieBehavior() ==
nsICookieService::BEHAVIOR_REJECT_TRACKER_AND_PARTITION_FOREIGN) {
// If the other side has decided to partition third-party cookies, update
// our side.
mCookieBehavior =
nsICookieService::BEHAVIOR_REJECT_TRACKER_AND_PARTITION_FOREIGN;
}
if (mCookieBehavior ==
nsICookieService::BEHAVIOR_REJECT_TRACKER_AND_PARTITION_FOREIGN &&
aData.cookieBehavior() == nsICookieService::BEHAVIOR_REJECT_TRACKER) {
// If we've decided to partition third-party cookies, the other side may not
// have caught up yet. Do nothing.
}
// Ignore all other cases.
PermissionComparator comparator;
for (const CookiePermissionData& data : aData.cookiePermissions()) {

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

@ -113,6 +113,8 @@ class CookieSettings final : public nsICookieSettings {
static already_AddRefed<nsICookieSettings> Create();
static already_AddRefed<nsICookieSettings> Create(uint32_t aCookieBehavior);
static CookieSettings* Cast(nsICookieSettings* aCS) {
return static_cast<CookieSettings*>(aCS);
}

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

@ -28,6 +28,11 @@ interface nsICookieSettings : nsISupports
[infallible] readonly attribute boolean limitForeignContexts;
/**
* Whether our cookie behavior mandates partitioning third-party content.
*/
[infallible] attribute boolean partitionForeign;
/**
* CookiePermission at the loading of the document for a particular
* principal. It returns the same cookiePermission also in case it changes