зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1507991 - Part 2: Serialize domain in ContentPrincipalInfo, r=baku
This is needed to maintain full feature parity with the existing nsIPrincipal serializer while switching to using the PrincipalInfo-based one. Depends on D20853 Differential Revision: https://phabricator.services.mozilla.com/D20854 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
cc951d5b97
Коммит
e1231c52dd
|
@ -245,8 +245,9 @@ static bool ReadPrincipalInfo(JSStructuredCloneReader* aReader, uint32_t aTag,
|
|||
|
||||
MOZ_DIAGNOSTIC_ASSERT(!originNoSuffix.IsEmpty());
|
||||
|
||||
aInfo =
|
||||
ContentPrincipalInfo(attrs, originNoSuffix, spec, std::move(policies));
|
||||
// XXX: Do we care about mDomain for structured clone?
|
||||
aInfo = ContentPrincipalInfo(attrs, originNoSuffix, spec, Nothing(),
|
||||
std::move(policies));
|
||||
} else {
|
||||
#ifdef FUZZING
|
||||
return false;
|
||||
|
|
|
@ -114,7 +114,7 @@ nsresult CreatePrincipalInfo(nsILineInputStream* aStream,
|
|||
// CSP will be applied during the script load.
|
||||
nsTArray<mozilla::ipc::ContentSecurityPolicy> policies;
|
||||
aEntry->principal() = mozilla::ipc::ContentPrincipalInfo(
|
||||
attrs, origin, aEntry->scope(), std::move(policies));
|
||||
attrs, origin, aEntry->scope(), Nothing(), std::move(policies));
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
|
|
@ -274,7 +274,8 @@ TEST(ServiceWorkerRegistrar, TestWriteData) {
|
|||
|
||||
nsTArray<mozilla::ipc::ContentSecurityPolicy> policies;
|
||||
reg.principal() = mozilla::ipc::ContentPrincipalInfo(
|
||||
mozilla::OriginAttributes(i, i % 2), spec, spec, std::move(policies));
|
||||
mozilla::OriginAttributes(i, i % 2), spec, spec, Nothing(),
|
||||
std::move(policies));
|
||||
|
||||
swr->TestRegisterServiceWorker(reg);
|
||||
}
|
||||
|
@ -863,7 +864,8 @@ TEST(ServiceWorkerRegistrar, TestDedupeWrite) {
|
|||
|
||||
nsTArray<mozilla::ipc::ContentSecurityPolicy> policies;
|
||||
reg.principal() = mozilla::ipc::ContentPrincipalInfo(
|
||||
mozilla::OriginAttributes(0, false), spec, spec, std::move(policies));
|
||||
mozilla::OriginAttributes(0, false), spec, spec, Nothing(),
|
||||
std::move(policies));
|
||||
|
||||
swr->TestRegisterServiceWorker(reg);
|
||||
}
|
||||
|
|
|
@ -104,6 +104,19 @@ already_AddRefed<nsIPrincipal> PrincipalInfoToPrincipal(
|
|||
MOZ_CRASH("Origin must be available when deserialized");
|
||||
}
|
||||
|
||||
if (info.domain()) {
|
||||
nsCOMPtr<nsIURI> domain;
|
||||
rv = NS_NewURI(getter_AddRefs(domain), *info.domain());
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
rv = principal->SetDomain(domain);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
if (info.securityPolicies().Length() > 0) {
|
||||
nsCOMPtr<nsIContentSecurityPolicy> csp =
|
||||
do_CreateInstance(NS_CSPCONTEXT_CONTRACTID, &rv);
|
||||
|
@ -276,6 +289,21 @@ nsresult PrincipalToPrincipalInfo(nsIPrincipal* aPrincipal,
|
|||
return rv;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIURI> domainUri;
|
||||
rv = aPrincipal->GetDomain(getter_AddRefs(domainUri));
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
Maybe<nsCString> domain;
|
||||
if (domainUri) {
|
||||
domain.emplace();
|
||||
rv = domainUri->GetSpec(domain.ref());
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIContentSecurityPolicy> csp;
|
||||
rv = aPrincipal->GetCsp(getter_AddRefs(csp));
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
|
@ -289,7 +317,7 @@ nsresult PrincipalToPrincipalInfo(nsIPrincipal* aPrincipal,
|
|||
|
||||
*aPrincipalInfo =
|
||||
ContentPrincipalInfo(aPrincipal->OriginAttributesRef(), originNoSuffix,
|
||||
spec, std::move(policies));
|
||||
spec, domain, std::move(policies));
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
|
|
@ -30,6 +30,8 @@ struct ContentPrincipalInfo
|
|||
|
||||
nsCString spec;
|
||||
|
||||
nsCString? domain;
|
||||
|
||||
ContentSecurityPolicy[] securityPolicies;
|
||||
};
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче