Bug 1551056 - Get rid of BasePrincipal::CloneForcingFirstPartyDomain, r=Ehsan

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Andrea Marchesini 2019-05-22 22:35:40 +00:00
Родитель ba6373e9aa
Коммит 37d54b0154
3 изменённых файлов: 14 добавлений и 38 удалений

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

@ -341,19 +341,6 @@ already_AddRefed<BasePrincipal> BasePrincipal::CreateCodebasePrincipal(
return BasePrincipal::CreateCodebasePrincipal(uri, attrs);
}
already_AddRefed<BasePrincipal> BasePrincipal::CloneForcingFirstPartyDomain(
nsIURI* aURI) {
if (NS_WARN_IF(!IsCodebasePrincipal())) {
return nullptr;
}
OriginAttributes attrs = OriginAttributesRef();
// XXX this is slow. Maybe we should consider to make it faster.
attrs.SetFirstPartyDomain(false, aURI, true /* aForced */);
return CloneForcingOriginAttributes(attrs);
}
already_AddRefed<BasePrincipal> BasePrincipal::CloneForcingOriginAttributes(
const OriginAttributes& aOriginAttributes) {
if (NS_WARN_IF(!IsCodebasePrincipal())) {

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

@ -156,8 +156,6 @@ class BasePrincipal : public nsJSPrincipals {
PrincipalKind Kind() const { return mKind; }
already_AddRefed<BasePrincipal> CloneForcingFirstPartyDomain(nsIURI* aURI);
already_AddRefed<BasePrincipal> CloneForcingOriginAttributes(
const OriginAttributes& aOriginAttributes);

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

@ -16,24 +16,21 @@ namespace mozilla {
namespace {
already_AddRefed<nsIURI> MaybeGetFirstPartyURI(nsIChannel* aChannel) {
bool ChooseOriginAttributes(nsIChannel* aChannel, OriginAttributes& aAttrs) {
MOZ_ASSERT(aChannel);
if (!StaticPrefs::privacy_storagePrincipal_enabledForTrackers()) {
return nullptr;
return false;
}
// Let's use the storage principal only if we need to partition the cookie
// jar.
nsContentUtils::StorageAccess access =
nsContentUtils::StorageAllowedForChannel(aChannel);
if (access != nsContentUtils::StorageAccess::ePartitionedOrDeny) {
return nullptr;
if (nsContentUtils::StorageAllowedForChannel(aChannel) !=
nsContentUtils::StorageAccess::ePartitionedOrDeny) {
return false;
}
nsCOMPtr<nsIHttpChannel> httpChannel = do_QueryInterface(aChannel);
if (!httpChannel) {
return nullptr;
return false;
}
MOZ_ASSERT(httpChannel->IsThirdPartyTrackingResource());
@ -41,16 +38,17 @@ already_AddRefed<nsIURI> MaybeGetFirstPartyURI(nsIChannel* aChannel) {
nsCOMPtr<nsILoadInfo> loadInfo = aChannel->LoadInfo();
nsCOMPtr<nsIPrincipal> toplevelPrincipal = loadInfo->GetTopLevelPrincipal();
if (!toplevelPrincipal) {
return nullptr;
return false;
}
nsCOMPtr<nsIURI> principalURI;
nsresult rv = toplevelPrincipal->GetURI(getter_AddRefs(principalURI));
if (NS_WARN_IF(NS_FAILED(rv))) {
return nullptr;
return false;
}
return principalURI.forget();
aAttrs.SetFirstPartyDomain(false, principalURI, true /* aForced */);
return true;
}
} // namespace
@ -68,16 +66,15 @@ nsresult StoragePrincipalHelper::Create(nsIChannel* aChannel,
storagePrincipal.forget(aStoragePrincipal);
});
nsCOMPtr<nsIURI> principalURI = MaybeGetFirstPartyURI(aChannel);
if (!principalURI) {
OriginAttributes attrs = aPrincipal->OriginAttributesRef();
if (!ChooseOriginAttributes(aChannel, attrs)) {
return NS_OK;
}
scopeExit.release();
nsCOMPtr<nsIPrincipal> storagePrincipal =
BasePrincipal::Cast(aPrincipal)
->CloneForcingFirstPartyDomain(principalURI);
BasePrincipal::Cast(aPrincipal)->CloneForcingOriginAttributes(attrs);
storagePrincipal.forget(aStoragePrincipal);
return NS_OK;
@ -88,13 +85,7 @@ nsresult StoragePrincipalHelper::PrepareOriginAttributes(
nsIChannel* aChannel, OriginAttributes& aOriginAttributes) {
MOZ_ASSERT(aChannel);
nsCOMPtr<nsIURI> principalURI = MaybeGetFirstPartyURI(aChannel);
if (!principalURI) {
return NS_OK;
}
aOriginAttributes.SetFirstPartyDomain(false, principalURI,
true /* aForced */);
ChooseOriginAttributes(aChannel, aOriginAttributes);
return NS_OK;
}