Bug 1768193 - Part 1: Use maybe to hold mIsThirdPartyContextToTopWindow in LoadInfo. r=anti-tracking-reviewers,necko-reviewers,bvandersloot,kershaw

In order to know if the mIsThirdPartyContextToTopWindow was set in the
loadInfo of the channel, we use maybe to hold the value. So, we can know
if it was set before.

This patch also addes two methods in LoadInfo to clear and know if the
value is set.

Differential Revision: https://phabricator.services.mozilla.com/D146491
This commit is contained in:
Tim Huang 2022-05-24 08:17:28 +00:00
Родитель b2cb0fdb6c
Коммит bebf6a1109
4 изменённых файлов: 46 добавлений и 16 удалений

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

@ -490,6 +490,13 @@ nsresult LoadInfoToLoadInfoArgs(nsILoadInfo* aLoadInfo,
nsCOMPtr<nsIURI> unstrippedURI;
Unused << aLoadInfo->GetUnstrippedURI(getter_AddRefs(unstrippedURI));
Maybe<bool> isThirdPartyContextToTopWindow;
if (static_cast<LoadInfo*>(aLoadInfo)
->HasIsThirdPartyContextToTopWindowSet()) {
isThirdPartyContextToTopWindow.emplace(
aLoadInfo->GetIsThirdPartyContextToTopWindow());
}
*aOptionalLoadInfoArgs = Some(LoadInfoArgs(
loadingPrincipalInfo, triggeringPrincipalInfo, principalToInheritInfo,
topLevelPrincipalInfo, optionalResultPrincipalURI,
@ -510,8 +517,7 @@ nsresult LoadInfoToLoadInfoArgs(nsILoadInfo* aLoadInfo,
aLoadInfo->GetInnerWindowID(), aLoadInfo->GetBrowsingContextID(),
aLoadInfo->GetFrameBrowsingContextID(),
aLoadInfo->GetInitialSecurityCheckDone(),
aLoadInfo->GetIsInThirdPartyContext(),
aLoadInfo->GetIsThirdPartyContextToTopWindow(),
aLoadInfo->GetIsInThirdPartyContext(), isThirdPartyContextToTopWindow,
aLoadInfo->GetIsFormSubmission(), aLoadInfo->GetSendCSPViolationEvents(),
aLoadInfo->GetOriginAttributes(), redirectChainIncludingInternalRedirects,
redirectChain, ipcClientInfo, ipcReservedClientInfo, ipcInitialClientInfo,
@ -728,6 +734,12 @@ nsresult LoadInfoArgsToLoadInfo(
loadingContext = frameBrowsingContext->GetEmbedderElement();
}
Maybe<bool> isThirdPartyContextToTopWindow;
if (loadInfoArgs.isThirdPartyContextToTopWindow().isSome()) {
isThirdPartyContextToTopWindow.emplace(
loadInfoArgs.isThirdPartyContextToTopWindow().ref());
}
RefPtr<mozilla::net::LoadInfo> loadInfo = new mozilla::net::LoadInfo(
loadingPrincipal, triggeringPrincipal, principalToInherit,
topLevelPrincipal, resultPrincipalURI, cookieJarSettings, cspToInherit,
@ -748,8 +760,7 @@ nsresult LoadInfoArgsToLoadInfo(
loadInfoArgs.forceInheritPrincipalDropped(), loadInfoArgs.innerWindowID(),
loadInfoArgs.browsingContextID(), loadInfoArgs.frameBrowsingContextID(),
loadInfoArgs.initialSecurityCheckDone(),
loadInfoArgs.isInThirdPartyContext(),
loadInfoArgs.isThirdPartyContextToTopWindow(),
loadInfoArgs.isInThirdPartyContext(), isThirdPartyContextToTopWindow,
loadInfoArgs.isFormSubmission(), loadInfoArgs.sendCSPViolationEvents(),
loadInfoArgs.originAttributes(),
std::move(redirectChainIncludingInternalRedirects),
@ -817,6 +828,13 @@ void LoadInfoToParentLoadInfoForwarder(
nsCOMPtr<nsIURI> unstrippedURI;
Unused << aLoadInfo->GetUnstrippedURI(getter_AddRefs(unstrippedURI));
Maybe<bool> isThirdPartyContextToTopWindow;
if (static_cast<LoadInfo*>(aLoadInfo)
->HasIsThirdPartyContextToTopWindowSet()) {
isThirdPartyContextToTopWindow.emplace(
aLoadInfo->GetIsThirdPartyContextToTopWindow());
}
*aForwarderArgsOut = ParentLoadInfoForwarderArgs(
aLoadInfo->GetAllowInsecureRedirectToDataURI(), ipcController, tainting,
aLoadInfo->GetSkipContentSniffing(), aLoadInfo->GetHttpsOnlyStatus(),
@ -829,8 +847,8 @@ void LoadInfoToParentLoadInfoForwarder(
aLoadInfo->GetAllowListFutureDocumentsCreatedFromThisRedirectChain(),
cookieJarSettingsArgs, aLoadInfo->GetRequestBlockingReason(),
aLoadInfo->GetStoragePermission(), aLoadInfo->GetIsMetaRefresh(),
aLoadInfo->GetIsThirdPartyContextToTopWindow(),
aLoadInfo->GetIsInThirdPartyContext(), unstrippedURI);
isThirdPartyContextToTopWindow, aLoadInfo->GetIsInThirdPartyContext(),
unstrippedURI);
}
nsresult MergeParentLoadInfoForwarder(
@ -905,8 +923,11 @@ nsresult MergeParentLoadInfoForwarder(
rv = aLoadInfo->SetIsMetaRefresh(aForwarderArgs.isMetaRefresh());
NS_ENSURE_SUCCESS(rv, rv);
rv = aLoadInfo->SetIsThirdPartyContextToTopWindow(
aForwarderArgs.isThirdPartyContextToTopWindow());
static_cast<LoadInfo*>(aLoadInfo)->ClearIsThirdPartyContextToTopWindow();
if (aForwarderArgs.isThirdPartyContextToTopWindow().isSome()) {
rv = aLoadInfo->SetIsThirdPartyContextToTopWindow(
aForwarderArgs.isThirdPartyContextToTopWindow().ref());
}
NS_ENSURE_SUCCESS(rv, rv);
rv = aLoadInfo->SetIsInThirdPartyContext(

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

@ -612,7 +612,7 @@ LoadInfo::LoadInfo(
bool aForceInheritPrincipalDropped, uint64_t aInnerWindowID,
uint64_t aBrowsingContextID, uint64_t aFrameBrowsingContextID,
bool aInitialSecurityCheckDone, bool aIsThirdPartyContext,
bool aIsThirdPartyContextToTopWindow, bool aIsFormSubmission,
const Maybe<bool>& aIsThirdPartyContextToTopWindow, bool aIsFormSubmission,
bool aSendCSPViolationEvents, const OriginAttributes& aOriginAttributes,
RedirectHistoryArray&& aRedirectChainIncludingInternalRedirects,
RedirectHistoryArray&& aRedirectChain,
@ -978,14 +978,15 @@ LoadInfo::SetIsInThirdPartyContext(bool aIsInThirdPartyContext) {
NS_IMETHODIMP
LoadInfo::GetIsThirdPartyContextToTopWindow(
bool* aIsThirdPartyContextToTopWindow) {
*aIsThirdPartyContextToTopWindow = mIsThirdPartyContextToTopWindow;
*aIsThirdPartyContextToTopWindow =
mIsThirdPartyContextToTopWindow.valueOr(true);
return NS_OK;
}
NS_IMETHODIMP
LoadInfo::SetIsThirdPartyContextToTopWindow(
bool aIsThirdPartyContextToTopWindow) {
mIsThirdPartyContextToTopWindow = aIsThirdPartyContextToTopWindow;
mIsThirdPartyContextToTopWindow = Some(aIsThirdPartyContextToTopWindow);
return NS_OK;
}

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

@ -178,6 +178,13 @@ class LoadInfo final : public nsILoadInfo {
mCspToInherit = aCspToInherit;
}
bool HasIsThirdPartyContextToTopWindowSet() {
return mIsThirdPartyContextToTopWindow.isSome();
}
void ClearIsThirdPartyContextToTopWindow() {
mIsThirdPartyContextToTopWindow.reset();
}
private:
// private constructor that is only allowed to be called from within
// HttpChannelParent and FTPChannelParent declared as friends undeneath.
@ -204,8 +211,9 @@ class LoadInfo final : public nsILoadInfo {
bool aForceInheritPrincipalDropped, uint64_t aInnerWindowID,
uint64_t aBrowsingContextID, uint64_t aFrameBrowsingContextID,
bool aInitialSecurityCheckDone, bool aIsThirdPartyContext,
bool aIsThirdPartyContextToTopWindow, bool aIsFormSubmission,
bool aSendCSPViolationEvents, const OriginAttributes& aOriginAttributes,
const Maybe<bool>& aIsThirdPartyContextToTopWindow,
bool aIsFormSubmission, bool aSendCSPViolationEvents,
const OriginAttributes& aOriginAttributes,
RedirectHistoryArray&& aRedirectChainIncludingInternalRedirects,
RedirectHistoryArray&& aRedirectChain,
nsTArray<nsCOMPtr<nsIPrincipal>>&& aAncestorPrincipals,
@ -300,7 +308,7 @@ class LoadInfo final : public nsILoadInfo {
bool mInitialSecurityCheckDone = false;
// NB: TYPE_DOCUMENT implies !third-party.
bool mIsThirdPartyContext = false;
bool mIsThirdPartyContextToTopWindow = true;
Maybe<bool> mIsThirdPartyContextToTopWindow;
bool mIsFormSubmission = false;
bool mSendCSPViolationEvents = true;
OriginAttributes mOriginAttributes;

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

@ -108,7 +108,7 @@ struct LoadInfoArgs
uint64_t frameBrowsingContextID;
bool initialSecurityCheckDone;
bool isInThirdPartyContext;
bool isThirdPartyContextToTopWindow;
bool? isThirdPartyContextToTopWindow;
bool isFormSubmission;
bool sendCSPViolationEvents;
OriginAttributes originAttributes;
@ -230,7 +230,7 @@ struct ParentLoadInfoForwarderArgs
bool isMetaRefresh;
bool isThirdPartyContextToTopWindow;
bool? isThirdPartyContextToTopWindow;
bool isInThirdPartyContext;