Commit 6b6c97b8 authored by smayya's avatar smayya
Browse files

Bug 1623038 - Replace URIParams with nsIURI in PHttpChannel.ipdl. r=necko-reviewers,valentin

This issue ports the changes from review D68003 and fixes various build errors occurred in the original review.

Differential Revision: https://phabricator.services.mozilla.com/D154249
parent cc504014
Loading
Loading
Loading
Loading
+5 −5
Original line number Diff line number Diff line
@@ -277,15 +277,15 @@ struct CorsPreflightArgs

struct HttpChannelOpenArgs
{
  URIParams                   uri;
  nsIURI                      uri;
  // - TODO: bug 571161: unclear if any HTTP channel clients ever
  // set originalURI != uri (about:credits?); also not clear if
  // chrome channel would ever need to know.  Get rid of next arg?
  URIParams?                  original;
  URIParams?                  doc;
  nsIURI                      original;
  nsIURI                      doc;
  nsIReferrerInfo             referrerInfo;
  URIParams?                  apiRedirectTo;
  URIParams?                  topWindowURI;
  nsIURI                      apiRedirectTo;
  nsIURI                      topWindowURI;
  uint32_t                    loadFlags;
  RequestHeaderTuples         requestHeaders;
  nsCString                   requestMethod;
+28 −37
Original line number Diff line number Diff line
@@ -1274,7 +1274,7 @@ mozilla::ipc::IPCResult HttpChannelChild::RecvReportSecurityMessage(
}

mozilla::ipc::IPCResult HttpChannelChild::RecvRedirect1Begin(
    const uint32_t& aRegistrarId, const URIParams& aNewUri,
    const uint32_t& aRegistrarId, nsIURI* aNewUri,
    const uint32_t& aNewLoadFlags, const uint32_t& aRedirectFlags,
    const ParentLoadInfoForwarderArgs& aLoadInfoForwarder,
    const nsHttpResponseHead& aResponseHead,
@@ -1290,11 +1290,12 @@ mozilla::ipc::IPCResult HttpChannelChild::RecvRedirect1Begin(
  MOZ_ASSERT(!nsHttpResponseHead(aResponseHead).HasHeader(nsHttp::Set_Cookie));

  mEventQ->RunOrEnqueue(new NeckoTargetChannelFunctionEvent(
      this, [self = UnsafePtr<HttpChannelChild>(this), aRegistrarId, aNewUri,
             aNewLoadFlags, aRedirectFlags, aLoadInfoForwarder, aResponseHead,
      this, [self = UnsafePtr<HttpChannelChild>(this), aRegistrarId,
             newUri = RefPtr{aNewUri}, aNewLoadFlags, aRedirectFlags,
             aLoadInfoForwarder, aResponseHead,
             aSecurityInfoSerialization = nsCString(aSecurityInfoSerialization),
             aChannelId, aTiming]() {
        self->Redirect1Begin(aRegistrarId, aNewUri, aNewLoadFlags,
        self->Redirect1Begin(aRegistrarId, newUri, aNewLoadFlags,
                             aRedirectFlags, aLoadInfoForwarder, aResponseHead,
                             aSecurityInfoSerialization, aChannelId, aTiming);
      }));
@@ -1342,7 +1343,7 @@ nsresult HttpChannelChild::SetupRedirect(nsIURI* uri,
}

void HttpChannelChild::Redirect1Begin(
    const uint32_t& registrarId, const URIParams& newOriginalURI,
    const uint32_t& registrarId, nsIURI* newOriginalURI,
    const uint32_t& newLoadFlags, const uint32_t& redirectFlags,
    const ParentLoadInfoForwarderArgs& loadInfoForwarder,
    const nsHttpResponseHead& responseHead,
@@ -1352,10 +1353,9 @@ void HttpChannelChild::Redirect1Begin(

  LOG(("HttpChannelChild::Redirect1Begin [this=%p]\n", this));

  ipc::MergeParentLoadInfoForwarder(loadInfoForwarder, mLoadInfo);

  nsCOMPtr<nsIURI> uri = DeserializeURI(newOriginalURI);
  MOZ_ASSERT(newOriginalURI, "newOriginalURI should not be null");

  ipc::MergeParentLoadInfoForwarder(loadInfoForwarder, mLoadInfo);
  ResourceTimingStructArgsToTimingsStruct(timing, mTransactionTimings);

  if (profiler_thread_is_being_profiled_for_markers()) {
@@ -1370,8 +1370,8 @@ void HttpChannelChild::Redirect1Begin(
        0, kCacheUnknown, mLoadInfo->GetInnerWindowID(),
        mLoadInfo->GetOriginAttributes().mPrivateBrowsingId > 0,
        &mTransactionTimings, std::move(mSource),
        Some(nsDependentCString(contentType.get())), uri, redirectFlags,
        channelId);
        Some(nsDependentCString(contentType.get())), newOriginalURI,
        redirectFlags, channelId);
  }

  if (!securityInfoSerialization.IsEmpty()) {
@@ -1382,7 +1382,7 @@ void HttpChannelChild::Redirect1Begin(
  }

  nsCOMPtr<nsIChannel> newChannel;
  rv = SetupRedirect(uri, &responseHead, redirectFlags,
  rv = SetupRedirect(newOriginalURI, &responseHead, redirectFlags,
                     getter_AddRefs(newChannel));

  if (NS_SUCCEEDED(rv)) {
@@ -1688,8 +1688,9 @@ NS_IMETHODIMP
HttpChannelChild::OnRedirectVerifyCallback(nsresult aResult) {
  LOG(("HttpChannelChild::OnRedirectVerifyCallback [this=%p]\n", this));
  MOZ_ASSERT(NS_IsMainThread());
  Maybe<URIParams> redirectURI;
  nsresult rv;
  nsCOMPtr<nsIURI> redirectURI;

  DebugOnly<nsresult> rv;

  nsCOMPtr<nsIHttpChannel> newHttpChannel =
      do_QueryInterface(mRedirectChannelChild);
@@ -1720,17 +1721,14 @@ HttpChannelChild::OnRedirectVerifyCallback(nsresult aResult) {
  nsCOMPtr<nsIHttpChannelChild> newHttpChannelChild =
      do_QueryInterface(mRedirectChannelChild);
  if (newHttpChannelChild && NS_SUCCEEDED(aResult)) {
    rv = newHttpChannelChild->AddCookiesToRequest();
    MOZ_ASSERT(NS_SUCCEEDED(rv));
    rv = newHttpChannelChild->GetClientSetRequestHeaders(&headerTuples);
    MOZ_ASSERT(NS_SUCCEEDED(rv));
    MOZ_ASSERT(NS_SUCCEEDED(newHttpChannelChild->AddCookiesToRequest()));

    MOZ_ASSERT(NS_SUCCEEDED(
        newHttpChannelChild->GetClientSetRequestHeaders(&headerTuples)));

    newHttpChannelChild->GetClientSetCorsPreflightParameters(corsPreflightArgs);
  }

  /* If the redirect was canceled, bypass OMR and send an empty API
   * redirect URI */
  SerializeURI(nullptr, redirectURI);

  if (NS_SUCCEEDED(aResult)) {
    // Note: this is where we would notify "http-on-modify-response" observers.
    // We have deliberately disabled this for child processes (see bug 806753)
@@ -1742,14 +1740,8 @@ HttpChannelChild::OnRedirectVerifyCallback(nsresult aResult) {
    nsCOMPtr<nsIHttpChannelInternal> newHttpChannelInternal =
        do_QueryInterface(mRedirectChannelChild);
    if (newHttpChannelInternal) {
      nsCOMPtr<nsIURI> apiRedirectURI;
      rv = newHttpChannelInternal->GetApiRedirectToURI(
          getter_AddRefs(apiRedirectURI));
      if (NS_SUCCEEDED(rv) && apiRedirectURI) {
        /* If there was an API redirect of this channel, we need to send it
         * up here, since it can't be sent via SendAsyncOpen. */
        SerializeURI(apiRedirectURI, redirectURI);
      }
      Unused << newHttpChannelInternal->GetApiRedirectToURI(
          getter_AddRefs(redirectURI));
    }

    nsCOMPtr<nsIRequest> request = do_QueryInterface(mRedirectChannelChild);
@@ -2112,10 +2104,10 @@ nsresult HttpChannelChild::ContinueAsyncOpen() {
  HttpChannelOpenArgs openArgs;
  // No access to HttpChannelOpenArgs members, but they each have a
  // function with the struct name that returns a ref.
  SerializeURI(mURI, openArgs.uri());
  SerializeURI(mOriginalURI, openArgs.original());
  SerializeURI(mDocumentURI, openArgs.doc());
  SerializeURI(mAPIRedirectToURI, openArgs.apiRedirectTo());
  openArgs.uri() = mURI;
  openArgs.original() = mOriginalURI;
  openArgs.doc() = mDocumentURI;
  openArgs.apiRedirectTo() = mAPIRedirectToURI;
  openArgs.loadFlags() = mLoadFlags;
  openArgs.requestHeaders() = mClientSetRequestHeaders;
  mRequestHead.Method(openArgs.requestMethod());
@@ -2135,7 +2127,7 @@ nsresult HttpChannelChild::ContinueAsyncOpen() {
  nsCOMPtr<nsIURI> uri;
  GetTopWindowURI(mURI, getter_AddRefs(uri));

  SerializeURI(mTopWindowURI, openArgs.topWindowURI());
  openArgs.topWindowURI() = mTopWindowURI;

  openArgs.preflightArgs() = optionalCorsPreflightArgs;

@@ -2669,9 +2661,8 @@ NS_IMETHODIMP
HttpChannelChild::RemoveCorsPreflightCacheEntry(
    nsIURI* aURI, nsIPrincipal* aPrincipal,
    const OriginAttributes& aOriginAttributes) {
  URIParams uri;
  SerializeURI(aURI, uri);
  PrincipalInfo principalInfo;
  MOZ_ASSERT(aURI, "aURI should not be null");
  nsresult rv = PrincipalToPrincipalInfo(aPrincipal, &principalInfo);
  if (NS_WARN_IF(NS_FAILED(rv))) {
    return rv;
@@ -2680,7 +2671,7 @@ HttpChannelChild::RemoveCorsPreflightCacheEntry(
  // Be careful to not attempt to send a message to the parent after the
  // actor has been destroyed.
  if (CanSend()) {
    result = SendRemoveCorsPreflightCacheEntry(uri, principalInfo,
    result = SendRemoveCorsPreflightCacheEntry(aURI, principalInfo,
                                               aOriginAttributes);
  }
  return result ? NS_OK : NS_ERROR_FAILURE;
+2 −3
Original line number Diff line number Diff line
@@ -124,7 +124,7 @@ class HttpChannelChild final : public PHttpChannelChild,
  mozilla::ipc::IPCResult RecvOnStartRequestSent() override;
  mozilla::ipc::IPCResult RecvFailedAsyncOpen(const nsresult& status) override;
  mozilla::ipc::IPCResult RecvRedirect1Begin(
      const uint32_t& registrarId, const URIParams& newURI,
      const uint32_t& registrarId, nsIURI* newOriginalURI,
      const uint32_t& newLoadFlags, const uint32_t& redirectFlags,
      const ParentLoadInfoForwarderArgs& loadInfoForwarder,
      const nsHttpResponseHead& responseHead,
@@ -397,8 +397,7 @@ class HttpChannelChild final : public PHttpChannelChild,
                     const nsHttpHeaderArray& aResponseTrailers);
  void FailedAsyncOpen(const nsresult& status);
  void HandleAsyncAbort();
  void Redirect1Begin(const uint32_t& registrarId,
                      const URIParams& newOriginalURI,
  void Redirect1Begin(const uint32_t& registrarId, nsIURI* newOriginalURI,
                      const uint32_t& newLoadFlags,
                      const uint32_t& redirectFlags,
                      const ParentLoadInfoForwarderArgs& loadInfoForwarder,
+28 −35
Original line number Diff line number Diff line
@@ -354,10 +354,9 @@ void HttpChannelParent::InvokeAsyncOpen(nsresult rv) {
}

bool HttpChannelParent::DoAsyncOpen(
    const URIParams& aURI, const Maybe<URIParams>& aOriginalURI,
    const Maybe<URIParams>& aDocURI, nsIReferrerInfo* aReferrerInfo,
    const Maybe<URIParams>& aAPIRedirectToURI,
    const Maybe<URIParams>& aTopWindowURI, const uint32_t& aLoadFlags,
    nsIURI* aURI, nsIURI* aOriginalURI, nsIURI* aDocURI,
    nsIReferrerInfo* aReferrerInfo, nsIURI* aAPIRedirectToURI,
    nsIURI* aTopWindowURI, const uint32_t& aLoadFlags,
    const RequestHeaderTuples& requestHeaders, const nsCString& requestMethod,
    const Maybe<IPCStream>& uploadStream, const bool& uploadStreamHasHeaders,
    const int16_t& priority, const ClassOfService& classOfService,
@@ -385,20 +384,12 @@ bool HttpChannelParent::DoAsyncOpen(
    const TimeStamp& aHandleFetchEventEnd,
    const bool& aForceMainDocumentChannel,
    const TimeStamp& aNavigationStartTimeStamp) {
  nsCOMPtr<nsIURI> uri = DeserializeURI(aURI);
  if (!uri) {
    // URIParams does MOZ_ASSERT if null, but we need to protect opt builds from
    // null deref here.
    return false;
  }
  nsCOMPtr<nsIURI> originalUri = DeserializeURI(aOriginalURI);
  nsCOMPtr<nsIURI> docUri = DeserializeURI(aDocURI);
  nsCOMPtr<nsIURI> apiRedirectToUri = DeserializeURI(aAPIRedirectToURI);
  nsCOMPtr<nsIURI> topWindowUri = DeserializeURI(aTopWindowURI);
  MOZ_ASSERT(aURI, "aURI should not be NULL");

  LOG(("HttpChannelParent RecvAsyncOpen [this=%p uri=%s, gid=%" PRIu64
       " top bid=%" PRIx64 "]\n",
       this, uri->GetSpecOrDefault().get(), aChannelId, aTopBrowsingContextId));
       this, aURI->GetSpecOrDefault().get(), aChannelId,
       aTopBrowsingContextId));

  nsresult rv;

@@ -413,7 +404,7 @@ bool HttpChannelParent::DoAsyncOpen(
  }

  nsCOMPtr<nsIChannel> channel;
  rv = NS_NewChannelInternal(getter_AddRefs(channel), uri, loadInfo, nullptr,
  rv = NS_NewChannelInternal(getter_AddRefs(channel), aURI, loadInfo, nullptr,
                             nullptr, nullptr, aLoadFlags, ios);
  if (NS_FAILED(rv)) {
    return SendFailedAsyncOpen(rv);
@@ -446,8 +437,14 @@ bool HttpChannelParent::DoAsyncOpen(

  if (doResumeAt) httpChannel->ResumeAt(startPos, entityID);

  if (originalUri) httpChannel->SetOriginalURI(originalUri);
  if (docUri) httpChannel->SetDocumentURI(docUri);
  if (aOriginalURI) {
    httpChannel->SetOriginalURI(aOriginalURI);
  }

  if (aDocURI) {
    httpChannel->SetDocumentURI(aDocURI);
  }

  if (aReferrerInfo) {
    // Referrer header is computed in child no need to recompute here
    rv =
@@ -455,9 +452,12 @@ bool HttpChannelParent::DoAsyncOpen(
    MOZ_ASSERT(NS_SUCCEEDED(rv));
  }

  if (apiRedirectToUri) httpChannel->RedirectTo(apiRedirectToUri);
  if (topWindowUri) {
    httpChannel->SetTopWindowURI(topWindowUri);
  if (aAPIRedirectToURI) {
    httpChannel->RedirectTo(aAPIRedirectToURI);
  }

  if (aTopWindowURI) {
    httpChannel->SetTopWindowURI(aTopWindowURI);
  }

  if (aLoadFlags != nsIRequest::LOAD_NORMAL) {
@@ -740,7 +740,7 @@ mozilla::ipc::IPCResult HttpChannelParent::RecvRedirect2Verify(
    const uint32_t& aSourceRequestBlockingReason,
    const Maybe<ChildLoadInfoForwarderArgs>& aTargetLoadInfoForwarder,
    const uint32_t& loadFlags, nsIReferrerInfo* aReferrerInfo,
    const Maybe<URIParams>& aAPIRedirectURI,
    nsIURI* aAPIRedirectURI,
    const Maybe<CorsPreflightArgs>& aCorsPreflightArgs) {
  LOG(("HttpChannelParent::RecvRedirect2Verify [this=%p result=%" PRIx32 "]\n",
       this, static_cast<uint32_t>(aResult)));
@@ -757,10 +757,8 @@ mozilla::ipc::IPCResult HttpChannelParent::RecvRedirect2Verify(
        do_QueryInterface(mRedirectChannel);

    if (newHttpChannel) {
      nsCOMPtr<nsIURI> apiRedirectUri = DeserializeURI(aAPIRedirectURI);

      if (apiRedirectUri) {
        rv = newHttpChannel->RedirectTo(apiRedirectUri);
      if (aAPIRedirectURI) {
        rv = newHttpChannel->RedirectTo(aAPIRedirectURI);
        MOZ_ASSERT(NS_SUCCEEDED(rv));
      }

@@ -941,11 +939,9 @@ mozilla::ipc::IPCResult HttpChannelParent::RecvDocumentChannelCleanup(
}

mozilla::ipc::IPCResult HttpChannelParent::RecvRemoveCorsPreflightCacheEntry(
    const URIParams& uri,
    const mozilla::ipc::PrincipalInfo& requestingPrincipal,
    nsIURI* uri, const mozilla::ipc::PrincipalInfo& requestingPrincipal,
    const OriginAttributes& originAttributes) {
  nsCOMPtr<nsIURI> deserializedURI = DeserializeURI(uri);
  if (!deserializedURI) {
  if (!uri) {
    return IPC_FAIL_NO_REASON(this);
  }
  auto principalOrErr = PrincipalInfoToPrincipal(requestingPrincipal);
@@ -953,7 +949,7 @@ mozilla::ipc::IPCResult HttpChannelParent::RecvRemoveCorsPreflightCacheEntry(
    return IPC_FAIL_NO_REASON(this);
  }
  nsCOMPtr<nsIPrincipal> principal = principalOrErr.unwrap();
  nsCORSListenerProxy::RemoveFromCorsPreflightCache(deserializedURI, principal,
  nsCORSListenerProxy::RemoveFromCorsPreflightCache(uri, principal,
                                                    originAttributes);
  return IPC_OK();
}
@@ -1704,9 +1700,6 @@ HttpChannelParent::StartRedirect(nsIChannel* newChannel, uint32_t redirectFlags,
  nsCOMPtr<nsIURI> newOriginalURI;
  newChannel->GetOriginalURI(getter_AddRefs(newOriginalURI));

  URIParams uriParams;
  SerializeURI(newOriginalURI, uriParams);

  uint32_t newLoadFlags = nsIRequest::LOAD_NORMAL;
  MOZ_ALWAYS_SUCCEEDS(newChannel->GetLoadFlags(&newLoadFlags));

@@ -1745,7 +1738,7 @@ HttpChannelParent::StartRedirect(nsIChannel* newChannel, uint32_t redirectFlags,
  bool result = false;
  if (!mIPCClosed) {
    result = SendRedirect1Begin(
        mRedirectChannelId, uriParams, newLoadFlags, redirectFlags,
        mRedirectChannelId, newOriginalURI, newLoadFlags, redirectFlags,
        loadInfoForwarderArg, *responseHead, secInfoSerialization, channelId,
        mChannel->GetPeerAddr(), GetTimingAttributes(mChannel));
  }
+6 −7
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@
#include "nsHttpChannel.h"
#include "mozilla/dom/ipc/IdType.h"
#include "nsIMultiPartChannel.h"
#include "nsIURI.h"

class nsICacheEntry;

@@ -128,10 +129,9 @@ class HttpChannelParent final : public nsIInterfaceRequestor,
  [[nodiscard]] bool ConnectChannel(const uint32_t& registrarId);

  [[nodiscard]] bool DoAsyncOpen(
      const URIParams& uri, const Maybe<URIParams>& originalUri,
      const Maybe<URIParams>& docUri, nsIReferrerInfo* aReferrerInfo,
      const Maybe<URIParams>& aAPIRedirectToURI,
      const Maybe<URIParams>& topWindowUri, const uint32_t& loadFlags,
      nsIURI* uri, nsIURI* originalUri, nsIURI* docUri,
      nsIReferrerInfo* aReferrerInfo, nsIURI* aAPIRedirectToURI,
      nsIURI* topWindowUri, const uint32_t& loadFlags,
      const RequestHeaderTuples& requestHeaders, const nsCString& requestMethod,
      const Maybe<IPCStream>& uploadStream, const bool& uploadStreamHasHeaders,
      const int16_t& priority, const ClassOfService& classOfService,
@@ -175,13 +175,12 @@ class HttpChannelParent final : public nsIInterfaceRequestor,
      const uint32_t& aSourceRequestBlockingReason,
      const Maybe<ChildLoadInfoForwarderArgs>& aTargetLoadInfoForwarder,
      const uint32_t& loadFlags, nsIReferrerInfo* aReferrerInfo,
      const Maybe<URIParams>& apiRedirectUri,
      nsIURI* apiRedirectUri,
      const Maybe<CorsPreflightArgs>& aCorsPreflightArgs) override;
  virtual mozilla::ipc::IPCResult RecvDocumentChannelCleanup(
      const bool& clearCacheEntry) override;
  virtual mozilla::ipc::IPCResult RecvRemoveCorsPreflightCacheEntry(
      const URIParams& uri,
      const mozilla::ipc::PrincipalInfo& requestingPrincipal,
      nsIURI* uri, const mozilla::ipc::PrincipalInfo& requestingPrincipal,
      const OriginAttributes& originAttributes) override;
  virtual mozilla::ipc::IPCResult RecvBytesRead(const int32_t& aCount) override;
  virtual mozilla::ipc::IPCResult RecvOpenOriginalCacheInputStream() override;
Loading