Skip to content

Commit

Permalink
Bug 1842754 - Make LoadInfoArgs non-optional over IPC r=necko-reviewe…
Browse files Browse the repository at this point in the history
…rs,jesup

This makes all occurences of LoadInfoArgs non-optional also when
converting between nsILoadInfo in BackgroundUtils.h.

Differential Revision: https://phabricator.services.mozilla.com/D185299
  • Loading branch information
mb committed Aug 8, 2023
1 parent 6975f47 commit f37405f
Show file tree
Hide file tree
Showing 29 changed files with 87 additions and 123 deletions.
6 changes: 1 addition & 5 deletions dom/ipc/ContentChild.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4284,16 +4284,12 @@ mozilla::ipc::IPCResult ContentChild::RecvScriptError(
}

mozilla::ipc::IPCResult ContentChild::RecvReportFrameTimingData(
const mozilla::Maybe<LoadInfoArgs>& loadInfoArgs, const nsString& entryName,
const LoadInfoArgs& loadInfoArgs, const nsString& entryName,
const nsString& initiatorType, UniquePtr<PerformanceTimingData>&& aData) {
if (!aData) {
return IPC_FAIL(this, "aData should not be null");
}

if (loadInfoArgs.isNothing()) {
return IPC_FAIL(this, "loadInfoArgs should not be null");
}

nsCOMPtr<nsILoadInfo> loadInfo;
nsresult rv = mozilla::ipc::LoadInfoArgsToLoadInfo(
loadInfoArgs, NOT_REMOTE_TYPE, getter_AddRefs(loadInfo));
Expand Down
5 changes: 2 additions & 3 deletions dom/ipc/ContentChild.h
Original file line number Diff line number Diff line change
Expand Up @@ -729,9 +729,8 @@ class ContentChild final : public PContentChild,
const uint64_t& aInnerWindowId, const bool& aFromChromeContext);

mozilla::ipc::IPCResult RecvReportFrameTimingData(
const mozilla::Maybe<LoadInfoArgs>& loadInfoArgs,
const nsString& entryName, const nsString& initiatorType,
UniquePtr<PerformanceTimingData>&& aData);
const LoadInfoArgs& loadInfoArgs, const nsString& entryName,
const nsString& initiatorType, UniquePtr<PerformanceTimingData>&& aData);

mozilla::ipc::IPCResult RecvLoadURI(
const MaybeDiscarded<BrowsingContext>& aContext,
Expand Down
15 changes: 5 additions & 10 deletions dom/ipc/ContentParent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4709,7 +4709,7 @@ mozilla::ipc::IPCResult ContentParent::RecvAddSecurityState(

already_AddRefed<PExternalHelperAppParent>
ContentParent::AllocPExternalHelperAppParent(
nsIURI* uri, const Maybe<mozilla::net::LoadInfoArgs>& aLoadInfoArgs,
nsIURI* uri, const mozilla::net::LoadInfoArgs& aLoadInfoArgs,
const nsACString& aMimeContentType, const nsACString& aContentDisposition,
const uint32_t& aContentDispositionHint,
const nsAString& aContentDispositionFilename, const bool& aForceSave,
Expand All @@ -4724,7 +4724,7 @@ ContentParent::AllocPExternalHelperAppParent(

mozilla::ipc::IPCResult ContentParent::RecvPExternalHelperAppConstructor(
PExternalHelperAppParent* actor, nsIURI* uri,
const Maybe<LoadInfoArgs>& loadInfoArgs, const nsACString& aMimeContentType,
const LoadInfoArgs& loadInfoArgs, const nsACString& aMimeContentType,
const nsACString& aContentDisposition,
const uint32_t& aContentDispositionHint,
const nsAString& aContentDispositionFilename, const bool& aForceSave,
Expand Down Expand Up @@ -5073,19 +5073,14 @@ mozilla::ipc::IPCResult ContentParent::RecvConsoleMessage(
}

mozilla::ipc::IPCResult ContentParent::RecvReportFrameTimingData(
const mozilla::Maybe<LoadInfoArgs>& loadInfoArgs,
const nsAString& entryName, const nsAString& initiatorType,
UniquePtr<PerformanceTimingData>&& aData) {
const LoadInfoArgs& loadInfoArgs, const nsAString& entryName,
const nsAString& initiatorType, UniquePtr<PerformanceTimingData>&& aData) {
if (!aData) {
return IPC_FAIL(this, "aData should not be null");
}

if (loadInfoArgs.isNothing()) {
return IPC_FAIL(this, "loadInfoArgs should not be null");
}

RefPtr<WindowGlobalParent> parent =
WindowGlobalParent::GetByInnerWindowId(loadInfoArgs->innerWindowID());
WindowGlobalParent::GetByInnerWindowId(loadInfoArgs.innerWindowID());
if (!parent || !parent->GetContentParent()) {
return IPC_OK();
}
Expand Down
11 changes: 5 additions & 6 deletions dom/ipc/ContentParent.h
Original file line number Diff line number Diff line change
Expand Up @@ -938,7 +938,7 @@ class ContentParent final : public PContentParent,
bool DeallocPScriptCacheParent(PScriptCacheParent* shell);

already_AddRefed<PExternalHelperAppParent> AllocPExternalHelperAppParent(
nsIURI* aUri, const Maybe<mozilla::net::LoadInfoArgs>& aLoadInfoArgs,
nsIURI* aUri, const mozilla::net::LoadInfoArgs& aLoadInfoArgs,
const nsACString& aMimeContentType, const nsACString& aContentDisposition,
const uint32_t& aContentDispositionHint,
const nsAString& aContentDispositionFilename, const bool& aForceSave,
Expand All @@ -948,8 +948,8 @@ class ContentParent final : public PContentParent,

mozilla::ipc::IPCResult RecvPExternalHelperAppConstructor(
PExternalHelperAppParent* actor, nsIURI* uri,
const Maybe<LoadInfoArgs>& loadInfoArgs,
const nsACString& aMimeContentType, const nsACString& aContentDisposition,
const LoadInfoArgs& loadInfoArgs, const nsACString& aMimeContentType,
const nsACString& aContentDisposition,
const uint32_t& aContentDispositionHint,
const nsAString& aContentDispositionFilename, const bool& aForceSave,
const int64_t& aContentLength, const bool& aWasFileChannel,
Expand Down Expand Up @@ -1073,9 +1073,8 @@ class ContentParent final : public PContentParent,
const uint64_t& aInnerWindowId, const bool& aIsFromChromeContext);

mozilla::ipc::IPCResult RecvReportFrameTimingData(
const mozilla::Maybe<LoadInfoArgs>& loadInfoArgs,
const nsAString& entryName, const nsAString& initiatorType,
UniquePtr<PerformanceTimingData>&& aData);
const LoadInfoArgs& loadInfoArgs, const nsAString& entryName,
const nsAString& initiatorType, UniquePtr<PerformanceTimingData>&& aData);

mozilla::ipc::IPCResult RecvScriptErrorWithStack(
const nsAString& aMessage, const nsAString& aSourceName,
Expand Down
4 changes: 2 additions & 2 deletions dom/ipc/PContent.ipdl
Original file line number Diff line number Diff line change
Expand Up @@ -1185,7 +1185,7 @@ parent:
// Pass true for aShouldCloseWindow to specify that aContext was opened specifically
// for this load, and should be closed once we've handled it.
async PExternalHelperApp(nullable nsIURI uri,
LoadInfoArgs? loadInfoArgs,
LoadInfoArgs loadInfoArgs,
nsCString aMimeContentType,
nsCString aContentDisposition,
uint32_t aContentDispositionHint,
Expand Down Expand Up @@ -1851,7 +1851,7 @@ both:
* loadInfo is passed in order to enforce same-origin security checks
* aData must be non-null.
*/
async ReportFrameTimingData(LoadInfoArgs? loadInfo, nsString entryName,
async ReportFrameTimingData(LoadInfoArgs loadInfo, nsString entryName,
nsString initiatorType,
UniquePtr<PerformanceTimingData> aData);

Expand Down
4 changes: 2 additions & 2 deletions dom/media/webrtc/jsapi/PeerConnectionImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4623,11 +4623,11 @@ std::unique_ptr<NrSocketProxyConfig> PeerConnectionImpl::GetProxyConfig()
new net::LoadInfo(doc->NodePrincipal(), doc->NodePrincipal(), doc, 0,
nsIContentPolicy::TYPE_INVALID);

Maybe<net::LoadInfoArgs> loadInfoArgs;
net::LoadInfoArgs loadInfoArgs;
MOZ_ALWAYS_SUCCEEDS(
mozilla::ipc::LoadInfoToLoadInfoArgs(loadInfo, &loadInfoArgs));
return std::unique_ptr<NrSocketProxyConfig>(new NrSocketProxyConfig(
net::WebrtcProxyConfig(id, alpn, *loadInfoArgs, mForceProxy)));
net::WebrtcProxyConfig(id, alpn, loadInfoArgs, mForceProxy)));
}

std::map<uint64_t, PeerConnectionAutoTimer>
Expand Down
5 changes: 2 additions & 3 deletions dom/media/webrtc/transport/ipc/WebrtcTCPSocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -399,16 +399,15 @@ nsresult WebrtcTCPSocket::OpenWithHttpProxy() {
}

nsCOMPtr<nsILoadInfo> loadInfo;
Maybe<net::LoadInfoArgs> loadInfoArgs = Some(mProxyConfig->loadInfoArgs());

// FIXME: We don't know the remote type of the process which provided these
// LoadInfoArgs. Pass in `NOT_REMOTE_TYPE` as the origin process to blindly
// accept whatever value was passed by the other side for now, as we aren't
// using it for security checks here.
// If this code ever starts checking the triggering remote type, this needs to
// be changed.
rv = ipc::LoadInfoArgsToLoadInfo(loadInfoArgs, NOT_REMOTE_TYPE,
getter_AddRefs(loadInfo));
rv = ipc::LoadInfoArgsToLoadInfo(mProxyConfig->loadInfoArgs(),
NOT_REMOTE_TYPE, getter_AddRefs(loadInfo));
if (NS_FAILED(rv)) {
LOG(("WebrtcTCPSocket %p: could not init load info\n", this));
return rv;
Expand Down
51 changes: 22 additions & 29 deletions ipc/glue/BackgroundUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ nsresult RHEntryToRHEntryInfo(nsIRedirectHistoryEntry* aRHEntry,
}

nsresult LoadInfoToLoadInfoArgs(nsILoadInfo* aLoadInfo,
Maybe<LoadInfoArgs>* aOptionalLoadInfoArgs) {
LoadInfoArgs* outLoadInfoArgs) {
nsresult rv = NS_OK;
Maybe<PrincipalInfo> loadingPrincipalInfo;
if (nsIPrincipal* loadingPrin = aLoadInfo->GetLoadingPrincipal()) {
Expand Down Expand Up @@ -541,7 +541,7 @@ nsresult LoadInfoToLoadInfoArgs(nsILoadInfo* aLoadInfo,
redirectChain, interceptionInfo->FromThirdParty()));
}

*aOptionalLoadInfoArgs = Some(LoadInfoArgs(
*outLoadInfoArgs = LoadInfoArgs(
loadingPrincipalInfo, triggeringPrincipalInfo, principalToInheritInfo,
topLevelPrincipalInfo, optionalResultPrincipalURI, triggeringRemoteType,
aLoadInfo->GetSandboxedNullPrincipalID(), aLoadInfo->GetSecurityFlags(),
Expand Down Expand Up @@ -584,23 +584,23 @@ nsresult LoadInfoToLoadInfoArgs(nsILoadInfo* aLoadInfo,
aLoadInfo->GetStoragePermission(), aLoadInfo->GetIsMetaRefresh(),
aLoadInfo->GetLoadingEmbedderPolicy(),
aLoadInfo->GetIsOriginTrialCoepCredentiallessEnabledForTopLevel(),
unstrippedURI, interceptionInfoArg));
unstrippedURI, interceptionInfoArg);

return NS_OK;
}

nsresult LoadInfoArgsToLoadInfo(
const Maybe<LoadInfoArgs>& aOptionalLoadInfoArgs,
const nsACString& aOriginRemoteType, nsILoadInfo** outLoadInfo) {
return LoadInfoArgsToLoadInfo(aOptionalLoadInfoArgs, aOriginRemoteType,
nullptr, outLoadInfo);
nsresult LoadInfoArgsToLoadInfo(const LoadInfoArgs& aLoadInfoArgs,
const nsACString& aOriginRemoteType,
nsILoadInfo** outLoadInfo) {
return LoadInfoArgsToLoadInfo(aLoadInfoArgs, aOriginRemoteType, nullptr,
outLoadInfo);
}
nsresult LoadInfoArgsToLoadInfo(
const Maybe<LoadInfoArgs>& aOptionalLoadInfoArgs,
const nsACString& aOriginRemoteType, nsINode* aCspToInheritLoadingContext,
nsILoadInfo** outLoadInfo) {
nsresult LoadInfoArgsToLoadInfo(const LoadInfoArgs& aLoadInfoArgs,
const nsACString& aOriginRemoteType,
nsINode* aCspToInheritLoadingContext,
nsILoadInfo** outLoadInfo) {
RefPtr<LoadInfo> loadInfo;
nsresult rv = LoadInfoArgsToLoadInfo(aOptionalLoadInfoArgs, aOriginRemoteType,
nsresult rv = LoadInfoArgsToLoadInfo(aLoadInfoArgs, aOriginRemoteType,
aCspToInheritLoadingContext,
getter_AddRefs(loadInfo));
NS_ENSURE_SUCCESS(rv, rv);
Expand All @@ -609,23 +609,16 @@ nsresult LoadInfoArgsToLoadInfo(
return NS_OK;
}

nsresult LoadInfoArgsToLoadInfo(
const Maybe<LoadInfoArgs>& aOptionalLoadInfoArgs,
const nsACString& aOriginRemoteType, LoadInfo** outLoadInfo) {
return LoadInfoArgsToLoadInfo(aOptionalLoadInfoArgs, aOriginRemoteType,
nullptr, outLoadInfo);
nsresult LoadInfoArgsToLoadInfo(const LoadInfoArgs& aLoadInfoArgs,
const nsACString& aOriginRemoteType,
LoadInfo** outLoadInfo) {
return LoadInfoArgsToLoadInfo(aLoadInfoArgs, aOriginRemoteType, nullptr,
outLoadInfo);
}
nsresult LoadInfoArgsToLoadInfo(
const Maybe<LoadInfoArgs>& aOptionalLoadInfoArgs,
const nsACString& aOriginRemoteType, nsINode* aCspToInheritLoadingContext,
LoadInfo** outLoadInfo) {
if (aOptionalLoadInfoArgs.isNothing()) {
*outLoadInfo = nullptr;
return NS_OK;
}

const LoadInfoArgs& loadInfoArgs = aOptionalLoadInfoArgs.ref();

nsresult LoadInfoArgsToLoadInfo(const LoadInfoArgs& loadInfoArgs,
const nsACString& aOriginRemoteType,
nsINode* aCspToInheritLoadingContext,
LoadInfo** outLoadInfo) {
nsCOMPtr<nsIPrincipal> loadingPrincipal;
if (loadInfoArgs.requestingPrincipalInfo().isSome()) {
auto loadingPrincipalOrErr =
Expand Down
33 changes: 16 additions & 17 deletions ipc/glue/BackgroundUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,27 +135,26 @@ nsresult RHEntryToRHEntryInfo(
/**
* Convert a LoadInfo to LoadInfoArgs struct.
*/
nsresult LoadInfoToLoadInfoArgs(
nsILoadInfo* aLoadInfo,
Maybe<mozilla::net::LoadInfoArgs>* outOptionalLoadInfoArgs);
nsresult LoadInfoToLoadInfoArgs(nsILoadInfo* aLoadInfo,
mozilla::net::LoadInfoArgs* outLoadInfoArgs);

/**
* Convert LoadInfoArgs to a LoadInfo.
*/
nsresult LoadInfoArgsToLoadInfo(
const Maybe<mozilla::net::LoadInfoArgs>& aOptionalLoadInfoArgs,
const nsACString& aOriginRemoteType, nsILoadInfo** outLoadInfo);
nsresult LoadInfoArgsToLoadInfo(
const Maybe<mozilla::net::LoadInfoArgs>& aOptionalLoadInfoArgs,
const nsACString& aOriginRemoteType, nsINode* aCspToInheritLoadingContext,
nsILoadInfo** outLoadInfo);
nsresult LoadInfoArgsToLoadInfo(
const Maybe<net::LoadInfoArgs>& aOptionalLoadInfoArgs,
const nsACString& aOriginRemoteType, mozilla::net::LoadInfo** outLoadInfo);
nsresult LoadInfoArgsToLoadInfo(
const Maybe<net::LoadInfoArgs>& aOptionalLoadInfoArgs,
const nsACString& aOriginRemoteType, nsINode* aCspToInheritLoadingContext,
mozilla::net::LoadInfo** outLoadInfo);
nsresult LoadInfoArgsToLoadInfo(const mozilla::net::LoadInfoArgs& aLoadInfoArgs,
const nsACString& aOriginRemoteType,
nsILoadInfo** outLoadInfo);
nsresult LoadInfoArgsToLoadInfo(const mozilla::net::LoadInfoArgs& aLoadInfoArgs,
const nsACString& aOriginRemoteType,
nsINode* aCspToInheritLoadingContext,
nsILoadInfo** outLoadInfo);
nsresult LoadInfoArgsToLoadInfo(const net::LoadInfoArgs& aLoadInfoArgs,
const nsACString& aOriginRemoteType,
mozilla::net::LoadInfo** outLoadInfo);
nsresult LoadInfoArgsToLoadInfo(const net::LoadInfoArgs& aLoadInfoArgs,
const nsACString& aOriginRemoteType,
nsINode* aCspToInheritLoadingContext,
mozilla::net::LoadInfo** outLoadInfo);

/**
* Fills ParentLoadInfoForwarderArgs with properties we want to carry to child
Expand Down
10 changes: 5 additions & 5 deletions netwerk/base/LoadInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ class LoadInfo;

namespace ipc {
// we have to forward declare that function so we can use it as a friend.
nsresult LoadInfoArgsToLoadInfo(
const Maybe<mozilla::net::LoadInfoArgs>& aLoadInfoArgs,
const nsACString& aOriginRemoteType, nsINode* aCspToInheritLoadingContext,
net::LoadInfo** outLoadInfo);
nsresult LoadInfoArgsToLoadInfo(const mozilla::net::LoadInfoArgs& aLoadInfoArgs,
const nsACString& aOriginRemoteType,
nsINode* aCspToInheritLoadingContext,
net::LoadInfo** outLoadInfo);
} // namespace ipc

namespace net {
Expand Down Expand Up @@ -252,7 +252,7 @@ class LoadInfo final : public nsILoadInfo {
const RedirectHistoryArray& aArra);

friend nsresult mozilla::ipc::LoadInfoArgsToLoadInfo(
const Maybe<mozilla::net::LoadInfoArgs>& aLoadInfoArgs,
const mozilla::net::LoadInfoArgs& aLoadInfoArgs,
const nsACString& aOriginRemoteType, nsINode* aCspToInheritLoadingContext,
net::LoadInfo** outLoadInfo);

Expand Down
7 changes: 0 additions & 7 deletions netwerk/ipc/DocumentLoadListener.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2135,13 +2135,6 @@ DocumentLoadListener::RedirectToRealChannel(
args.timing() = std::move(mTiming);
}

auto loadInfo = args.loadInfo();

if (loadInfo.isNothing()) {
return PDocumentChannelParent::RedirectToRealChannelPromise::
CreateAndReject(ipc::ResponseRejectReason::SendError, __func__);
}

cp->TransmitBlobDataIfBlobURL(args.uri());

if (CanonicalBrowsingContext* bc = GetDocumentBrowsingContext()) {
Expand Down
6 changes: 3 additions & 3 deletions netwerk/ipc/NeckoChannelParams.ipdlh
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ struct HttpChannelOpenArgs
nsCString contentTypeHint;
nsString integrityMetadata;
IPCStream? uploadStream;
LoadInfoArgs? loadInfo;
LoadInfoArgs loadInfo;
uint32_t loadFlags;
uint32_t thirdPartyFlags;
uint32_t tlsFlags;
Expand Down Expand Up @@ -478,7 +478,7 @@ struct RedirectToRealChannelArgs {
nullable nsIURI uri;
uint32_t newLoadFlags;
ReplacementChannelConfigInit? init;
LoadInfoArgs? loadInfo;
LoadInfoArgs loadInfo;
uint64_t channelId;
nullable nsIURI originalURI;
uint32_t redirectMode;
Expand Down Expand Up @@ -585,7 +585,7 @@ struct GIOChannelOpenArgs
uint64_t startPos;
nsCString entityID;
IPCStream? uploadStream;
LoadInfoArgs? loadInfo;
LoadInfoArgs loadInfo;
uint32_t loadFlags;
};

Expand Down
17 changes: 4 additions & 13 deletions netwerk/ipc/NeckoParent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,9 @@ static PBOverrideStatus PBOverrideStatusFromLoadContext(
}

static already_AddRefed<nsIPrincipal> GetRequestingPrincipal(
const Maybe<LoadInfoArgs>& aOptionalLoadInfoArgs) {
if (aOptionalLoadInfoArgs.isNothing()) {
return nullptr;
}

const LoadInfoArgs& loadInfoArgs = aOptionalLoadInfoArgs.ref();
const LoadInfoArgs& aLoadInfoArgs) {
const Maybe<PrincipalInfo>& optionalPrincipalInfo =
loadInfoArgs.requestingPrincipalInfo();
aLoadInfoArgs.requestingPrincipalInfo();

if (optionalPrincipalInfo.isNothing()) {
return nullptr;
Expand Down Expand Up @@ -794,7 +789,7 @@ mozilla::ipc::IPCResult NeckoParent::RecvEnsureHSTSData(
}

mozilla::ipc::IPCResult NeckoParent::RecvGetPageThumbStream(
nsIURI* aURI, const Maybe<LoadInfoArgs>& aLoadInfoArgs,
nsIURI* aURI, const LoadInfoArgs& aLoadInfoArgs,
GetPageThumbStreamResolver&& aResolver) {
// Only the privileged about content process is allowed to access
// things over the moz-page-thumb protocol. Any other content process
Expand Down Expand Up @@ -839,7 +834,7 @@ mozilla::ipc::IPCResult NeckoParent::RecvGetPageThumbStream(
}

mozilla::ipc::IPCResult NeckoParent::RecvGetPageIconStream(
nsIURI* aURI, const Maybe<LoadInfoArgs>& aLoadInfoArgs,
nsIURI* aURI, const LoadInfoArgs& aLoadInfoArgs,
GetPageIconStreamResolver&& aResolver) {
#ifdef MOZ_PLACES
const nsACString& remoteType =
Expand All @@ -855,10 +850,6 @@ mozilla::ipc::IPCResult NeckoParent::RecvGetPageIconStream(
return IPC_FAIL(this, "Wrong process type");
}

if (aLoadInfoArgs.isNothing()) {
return IPC_FAIL(this, "Page-icon request must include loadInfo");
}

nsCOMPtr<nsILoadInfo> loadInfo;
nsresult rv = mozilla::ipc::LoadInfoArgsToLoadInfo(aLoadInfoArgs, remoteType,
getter_AddRefs(loadInfo));
Expand Down
Loading

0 comments on commit f37405f

Please sign in to comment.