Bug 1867997 - Add QuotaManager::GetGroupFromValidatedPrincipalInfo; r=dom-storage-reviewers,jari

The planned group initialization will need an infallible way to get group from
PrincipalInfo, so this patch adds support for that.

Differential Revision: https://phabricator.services.mozilla.com/D196821
This commit is contained in:
Jan Varga 2024-10-18 01:32:36 +00:00
parent a8506400af
commit 8517ddc5a8
2 changed files with 34 additions and 1 deletions

View File

@ -174,6 +174,32 @@ Result<PrincipalInfo, nsresult> PrincipalMetadataToPrincipalInfo(
return std::move(principalInfo);
}
nsAutoCString GetGroupFromValidatedPrincipalInfo(
const PrincipalInfo& aPrincipalInfo) {
MOZ_ASSERT(IsPrincipalInfoValid(aPrincipalInfo));
switch (aPrincipalInfo.type()) {
case PrincipalInfo::TSystemPrincipalInfo: {
return nsAutoCString{GetGroupForChrome()};
}
case PrincipalInfo::TContentPrincipalInfo: {
const ContentPrincipalInfo& info =
aPrincipalInfo.get_ContentPrincipalInfo();
nsAutoCString suffix;
info.attrs().CreateSuffix(suffix);
return info.baseDomain() + suffix;
}
default: {
MOZ_CRASH("Should never get here!");
}
}
}
nsAutoCString GetOriginFromValidatedPrincipalInfo(
const PrincipalInfo& aPrincipalInfo) {
MOZ_ASSERT(IsPrincipalInfoValid(aPrincipalInfo));
@ -293,12 +319,14 @@ Result<nsAutoCString, nsresult> GetOriginFromWindow(
PrincipalMetadata GetInfoForChrome() {
return {{},
GetOriginForChrome(),
GetGroupForChrome(),
GetOriginForChrome(),
GetOriginForChrome(),
false};
}
nsLiteralCString GetGroupForChrome() { return nsLiteralCString{kChromeOrigin}; }
nsLiteralCString GetOriginForChrome() {
return nsLiteralCString{kChromeOrigin};
}

View File

@ -42,6 +42,9 @@ Result<PrincipalMetadata, nsresult> GetInfoFromValidatedPrincipalInfo(
Result<mozilla::ipc::PrincipalInfo, nsresult> PrincipalMetadataToPrincipalInfo(
const PrincipalMetadata& aPrincipalMetadata);
nsAutoCString GetGroupFromValidatedPrincipalInfo(
const mozilla::ipc::PrincipalInfo& aPrincipalInfo);
nsAutoCString GetOriginFromValidatedPrincipalInfo(
const mozilla::ipc::PrincipalInfo& aPrincipalInfo);
@ -57,6 +60,8 @@ Result<nsAutoCString, nsresult> GetOriginFromPrincipal(
Result<nsAutoCString, nsresult> GetOriginFromWindow(
nsPIDOMWindowOuter* aWindow);
nsLiteralCString GetGroupForChrome();
nsLiteralCString GetOriginForChrome();
PrincipalMetadata GetInfoForChrome();