Bug 1714608 - Replace custom partitionKey parsing method in SiteDataManager with ChromeUtils helper. r=timhuang

Differential Revision: https://phabricator.services.mozilla.com/D118726
This commit is contained in:
Paul Zuehlcke 2021-07-07 17:36:46 +00:00
Родитель cade0ddd2c
Коммит 6ae03e10fd
4 изменённых файлов: 48 добавлений и 27 удалений

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

@ -23,13 +23,6 @@ XPCOMUtils.defineLazyGetter(this, "gBrandBundle", function() {
);
});
XPCOMUtils.defineLazyPreferenceGetter(
this,
"gFirstPartyIsolateUseSite",
"privacy.firstparty.isolate.use_site",
false
);
var SiteDataManager = {
// A Map of sites and their disk usage according to Quota Manager.
// Key is base domain (group sites based on base domain across scheme, port,
@ -160,20 +153,6 @@ var SiteDataManager = {
return this._getCacheSizePromise;
},
_getBaseDomainFromPartitionKey(partitionKey) {
if (!partitionKey?.length) {
return undefined;
}
if (gFirstPartyIsolateUseSite) {
return partitionKey;
}
let entries = partitionKey.substr(1, partitionKey.length - 2).split(",");
if (entries.length < 2) {
return undefined;
}
return entries[1];
},
_getQuotaUsage(entryUpdatedCallback) {
this._cancelGetQuotaUsage();
this._getQuotaUsagePromise = new Promise(resolve => {
@ -192,9 +171,14 @@ var SiteDataManager = {
// Group dom storage by first party. If an entry is partitioned
// the first party site will be in the partitionKey, instead of
// the principal baseDomain.
let pkBaseDomain = this._getBaseDomainFromPartitionKey(
let pkBaseDomain;
try {
pkBaseDomain = ChromeUtils.getBaseDomainFromPartitionKey(
principal.originAttributes.partitionKey
);
} catch (e) {
Cu.reportError(e);
}
let site = this._getOrInsertSite(
pkBaseDomain || principal.baseDomain
);
@ -234,9 +218,14 @@ var SiteDataManager = {
// Group cookies by first party. If a cookie is partitioned the
// partitionKey will contain the first party site, instead of the host
// field.
let pkBaseDomain = this._getBaseDomainFromPartitionKey(
let pkBaseDomain;
try {
pkBaseDomain = ChromeUtils.getBaseDomainFromPartitionKey(
cookie.originAttributes.partitionKey
);
} catch (e) {
Cu.reportError(e);
}
let baseDomainOrHost =
pkBaseDomain || this.getBaseDomainFromHost(cookie.rawHost);
let site = this._getOrInsertSite(baseDomainOrHost);

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

@ -742,6 +742,24 @@ bool ChromeUtils::IsOriginAttributesEqual(
return aA == aB;
}
/* static */
void ChromeUtils::GetBaseDomainFromPartitionKey(dom::GlobalObject& aGlobal,
const nsAString& aPartitionKey,
nsAString& aBaseDomain,
ErrorResult& aRv) {
nsString scheme;
nsString pkBaseDomain;
int32_t port;
if (!mozilla::OriginAttributes::ParsePartitionKey(aPartitionKey, scheme,
pkBaseDomain, port)) {
aRv.Throw(NS_ERROR_FAILURE);
return;
}
aBaseDomain = pkBaseDomain;
}
#ifdef NIGHTLY_BUILD
/* static */
void ChromeUtils::GetRecentJSDevError(GlobalObject& aGlobal,

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

@ -124,6 +124,11 @@ class ChromeUtils {
aA.mPrivateBrowsingId == aB.mPrivateBrowsingId;
}
static void GetBaseDomainFromPartitionKey(dom::GlobalObject& aGlobal,
const nsAString& aPartitionKey,
nsAString& aBaseDomain,
ErrorResult& aRv);
// Implemented in js/xpconnect/loader/ChromeScriptLoader.cpp
static already_AddRefed<Promise> CompileScript(
GlobalObject& aGlobal, const nsAString& aUrl,

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

@ -307,6 +307,15 @@ partial namespace ChromeUtils {
isOriginAttributesEqual(optional OriginAttributesDictionary aA = {},
optional OriginAttributesDictionary aB = {});
/**
* Returns the base domain portion of a given partitionKey.
* Returns the empty string for an empty partitionKey.
* Throws for invalid partition keys.
*/
[Throws]
DOMString
getBaseDomainFromPartitionKey(DOMString partitionKey);
/**
* Loads and compiles the script at the given URL and returns an object
* which may be used to execute it repeatedly, in different globals, without