Bug 1175352 - Refactor LoadInfo arguments to be more self contained (r=bent)
authorChristoph Kerschbaumer <mozilla@christophkerschbaumer.com>
Thu, 18 Jun 2015 15:37:20 -0700
changeset 267800 f25d12a330d60681967b721cb8a1291c5f868ba4
parent 267799 3b6fc232918a047057558db1aceddcee77af3b74
child 267801 c1b8e5419562452499cb65d1a4a20f5973983058
push id4932
push userjlund@mozilla.com
push dateMon, 10 Aug 2015 18:23:06 +0000
treeherdermozilla-esr52@6dd5a4f5f745 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbent
bugs1175352
milestone41.0a1
Bug 1175352 - Refactor LoadInfo arguments to be more self contained (r=bent)
ipc/glue/BackgroundUtils.cpp
ipc/glue/BackgroundUtils.h
netwerk/base/LoadInfo.h
netwerk/ipc/NeckoChannelParams.ipdlh
netwerk/protocol/ftp/FTPChannelChild.cpp
netwerk/protocol/ftp/FTPChannelParent.cpp
netwerk/protocol/ftp/FTPChannelParent.h
netwerk/protocol/http/HttpChannelChild.cpp
netwerk/protocol/http/HttpChannelParent.cpp
netwerk/protocol/http/HttpChannelParent.h
netwerk/protocol/websocket/PWebSocket.ipdl
netwerk/protocol/websocket/WebSocketChannelChild.cpp
netwerk/protocol/websocket/WebSocketChannelParent.cpp
netwerk/protocol/websocket/WebSocketChannelParent.h
--- a/ipc/glue/BackgroundUtils.cpp
+++ b/ipc/glue/BackgroundUtils.cpp
@@ -2,16 +2,17 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "BackgroundUtils.h"
 
 #include "MainThreadUtils.h"
 #include "mozilla/Assertions.h"
 #include "mozilla/ipc/PBackgroundSharedTypes.h"
+#include "mozilla/net/NeckoChannelParams.h"
 #include "nsPrincipal.h"
 #include "nsIScriptSecurityManager.h"
 #include "nsIURI.h"
 #include "nsNetUtil.h"
 #include "nsNullPrincipal.h"
 #include "nsServiceManagerUtils.h"
 #include "nsString.h"
 
@@ -211,10 +212,71 @@ PrincipalToPrincipalInfo(nsIPrincipal* a
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
   *aPrincipalInfo = ContentPrincipalInfo(appId, isInBrowserElement, spec);
   return NS_OK;
 }
 
+nsresult
+LoadInfoToLoadInfoArgs(nsILoadInfo *aLoadInfo,
+                       mozilla::net::LoadInfoArgs* aLoadInfoArgs)
+{
+  nsresult rv = NS_OK;
+
+  if (aLoadInfo) {
+    rv = PrincipalToPrincipalInfo(aLoadInfo->LoadingPrincipal(),
+                                  &aLoadInfoArgs->requestingPrincipalInfo());
+    NS_ENSURE_SUCCESS(rv, rv);
+    rv = PrincipalToPrincipalInfo(aLoadInfo->TriggeringPrincipal(),
+                                  &aLoadInfoArgs->triggeringPrincipalInfo());
+    NS_ENSURE_SUCCESS(rv, rv);
+    aLoadInfoArgs->securityFlags() = aLoadInfo->GetSecurityFlags();
+    aLoadInfoArgs->contentPolicyType() = aLoadInfo->GetContentPolicyType();
+    aLoadInfoArgs->innerWindowID() = aLoadInfo->GetInnerWindowID();
+    aLoadInfoArgs->outerWindowID() = aLoadInfo->GetOuterWindowID();
+    aLoadInfoArgs->parentOuterWindowID() = aLoadInfo->GetParentOuterWindowID();
+    return NS_OK;
+  }
+
+  // use default values if no loadInfo is provided
+  rv = PrincipalToPrincipalInfo(nsContentUtils::GetSystemPrincipal(),
+                                &aLoadInfoArgs->requestingPrincipalInfo());
+  NS_ENSURE_SUCCESS(rv, rv);
+  rv = PrincipalToPrincipalInfo(nsContentUtils::GetSystemPrincipal(),
+                                &aLoadInfoArgs->triggeringPrincipalInfo());
+  NS_ENSURE_SUCCESS(rv, rv);
+  aLoadInfoArgs->securityFlags() = nsILoadInfo::SEC_NORMAL;
+  aLoadInfoArgs->contentPolicyType() = nsIContentPolicy::TYPE_OTHER;
+  aLoadInfoArgs->innerWindowID() = 0;
+  aLoadInfoArgs->outerWindowID() = 0;
+  aLoadInfoArgs->parentOuterWindowID() = 0;
+  return NS_OK;
+}
+
+nsresult
+LoadInfoArgsToLoadInfo(const mozilla::net::LoadInfoArgs& aLoadInfoArgs,
+                       nsILoadInfo** outLoadInfo)
+{
+  nsresult rv = NS_OK;
+  nsCOMPtr<nsIPrincipal> requestingPrincipal =
+    PrincipalInfoToPrincipal(aLoadInfoArgs.requestingPrincipalInfo(), &rv);
+  NS_ENSURE_SUCCESS(rv, rv);
+  nsCOMPtr<nsIPrincipal> triggeringPrincipal =
+    PrincipalInfoToPrincipal(aLoadInfoArgs.triggeringPrincipalInfo(), &rv);
+  NS_ENSURE_SUCCESS(rv, rv);
+
+  nsCOMPtr<nsILoadInfo> loadInfo =
+    new mozilla::LoadInfo(requestingPrincipal,
+                          triggeringPrincipal,
+                          aLoadInfoArgs.securityFlags(),
+                          aLoadInfoArgs.contentPolicyType(),
+                          aLoadInfoArgs.innerWindowID(),
+                          aLoadInfoArgs.outerWindowID(),
+                          aLoadInfoArgs.parentOuterWindowID());
+
+  loadInfo.forget(outLoadInfo);
+  return NS_OK;
+}
+
 } // namespace ipc
 } // namespace mozilla
--- a/ipc/glue/BackgroundUtils.h
+++ b/ipc/glue/BackgroundUtils.h
@@ -33,16 +33,20 @@ struct ParamTraits<mozilla::OriginAttrib
     return ReadParam(aMsg, aIter, &suffix) &&
            aResult->PopulateFromSuffix(suffix);
   }
 };
 
 } // IPC namespace
 
 namespace mozilla {
+namespace net {
+class LoadInfoArgs;
+}
+
 namespace ipc {
 
 class PrincipalInfo;
 
 /**
  * Convert a PrincipalInfo to an nsIPrincipal.
  *
  * MUST be called on the main thread only.
@@ -55,12 +59,28 @@ PrincipalInfoToPrincipal(const Principal
  * Convert an nsIPrincipal to a PrincipalInfo.
  *
  * MUST be called on the main thread only.
  */
 nsresult
 PrincipalToPrincipalInfo(nsIPrincipal* aPrincipal,
                          PrincipalInfo* aPrincipalInfo);
 
+/**
+ * Convert a LoadInfo to LoadInfoArgs struct.
+ */
+nsresult
+LoadInfoToLoadInfoArgs(nsILoadInfo *aLoadInfo,
+                       mozilla::net::LoadInfoArgs* outLoadInfoArgs);
+
+/**
+ * Convert LoadInfoArgs to a LoadInfo.
+ */
+nsresult
+LoadInfoArgsToLoadInfo(const mozilla::net::LoadInfoArgs& aLoadInfoArgs,
+                       nsILoadInfo** outLoadInfo);
+
+
+
 } // namespace ipc
 } // namespace mozilla
 
 #endif // mozilla_ipc_backgroundutils_h__
--- a/netwerk/base/LoadInfo.h
+++ b/netwerk/base/LoadInfo.h
@@ -13,19 +13,24 @@
 #include "nsIWeakReferenceUtils.h" // for nsWeakPtr
 #include "nsIURI.h"
 
 class nsINode;
 
 namespace mozilla {
 
 namespace net {
-class HttpChannelParent;
-class FTPChannelParent;
-class WebSocketChannelParent;
+class LoadInfoArgs;
+}
+
+namespace ipc {
+// we have to forward declare that function so we can use it as a friend.
+nsresult
+LoadInfoArgsToLoadInfo(const mozilla::net::LoadInfoArgs& aLoadInfoArgs,
+                       nsILoadInfo** outLoadInfo);
 }
 
 /**
  * Class that provides an nsILoadInfo implementation.
  *
  * Note that there is no reason why this class should be MOZ_EXPORT, but
  * Thunderbird relies on some insane hacks which require this, so we'll leave it
  * as is for now, but hopefully we'll be able to remove the MOZ_EXPORT keyword
@@ -52,19 +57,19 @@ private:
   LoadInfo(nsIPrincipal* aLoadingPrincipal,
            nsIPrincipal* aTriggeringPrincipal,
            nsSecurityFlags aSecurityFlags,
            nsContentPolicyType aContentPolicyType,
            uint64_t aInnerWindowID,
            uint64_t aOuterWindowID,
            uint64_t aParentOuterWindowID);
 
-  friend class net::HttpChannelParent;
-  friend class net::FTPChannelParent;
-  friend class net::WebSocketChannelParent;
+  friend nsresult
+  mozilla::ipc::LoadInfoArgsToLoadInfo(const mozilla::net::LoadInfoArgs& aLoadInfoArgs,
+                                       nsILoadInfo** outLoadInfo);
 
   ~LoadInfo();
 
   nsCOMPtr<nsIPrincipal> mLoadingPrincipal;
   nsCOMPtr<nsIPrincipal> mTriggeringPrincipal;
   nsWeakPtr mLoadingContext;
   nsSecurityFlags mSecurityFlags;
   nsContentPolicyType mContentPolicyType;
--- a/netwerk/ipc/NeckoChannelParams.ipdlh
+++ b/netwerk/ipc/NeckoChannelParams.ipdlh
@@ -16,16 +16,31 @@ using struct mozilla::void_t from "ipc/I
 using RequestHeaderTuples from "mozilla/net/PHttpChannelParams.h";
 using struct nsHttpAtom from "nsHttp.h";
 using class nsHttpResponseHead from "nsHttpResponseHead.h";
 
 namespace mozilla {
 namespace net {
 
 //-----------------------------------------------------------------------------
+// LoadInfo IPDL structs
+//-----------------------------------------------------------------------------
+
+struct LoadInfoArgs
+{
+  PrincipalInfo requestingPrincipalInfo;
+  PrincipalInfo triggeringPrincipalInfo;
+  uint32_t      securityFlags;
+  uint32_t      contentPolicyType;
+  uint64_t      innerWindowID;
+  uint64_t      outerWindowID;
+  uint64_t      parentOuterWindowID;
+};
+
+//-----------------------------------------------------------------------------
 // HTTP IPDL structs
 //-----------------------------------------------------------------------------
 
 union OptionalHttpResponseHead
 {
   void_t;
   nsHttpResponseHead;
 };
@@ -56,23 +71,17 @@ struct HttpChannelOpenArgs
   bool                        resumeAt;
   uint64_t                    startPos;
   nsCString                   entityID;
   bool                        chooseApplicationCache;
   nsCString                   appCacheClientID;
   bool                        allowSpdy;
   bool                        allowAltSvc;
   OptionalFileDescriptorSet   fds;
-  PrincipalInfo               requestingPrincipalInfo;
-  PrincipalInfo               triggeringPrincipalInfo;
-  uint32_t                    securityFlags;
-  uint32_t                    contentPolicyType;
-  uint64_t                    innerWindowID;
-  uint64_t                    outerWindowID;
-  uint64_t                    parentOuterWindowID;
+  LoadInfoArgs                loadInfo;
   OptionalHttpResponseHead    synthesizedResponseHead;
   uint32_t                    cacheKey;
 };
 
 struct HttpChannelConnectArgs
 {
   uint32_t channelId;
   bool shouldIntercept;
@@ -89,23 +98,17 @@ union HttpChannelCreationArgs
 //-----------------------------------------------------------------------------
 
 struct FTPChannelOpenArgs
 {
   URIParams                 uri;
   uint64_t                  startPos;
   nsCString                 entityID;
   OptionalInputStreamParams uploadStream;
-  PrincipalInfo             requestingPrincipalInfo;
-  PrincipalInfo             triggeringPrincipalInfo;
-  uint32_t                  securityFlags;
-  uint32_t                  contentPolicyType;
-  uint64_t                  innerWindowID;
-  uint64_t                  outerWindowID;
-  uint64_t                  parentOuterWindowID;
+  LoadInfoArgs              loadInfo;
 };
 
 struct FTPChannelConnectArgs
 {
   uint32_t channelId;
 };
 
 union FTPChannelCreationArgs
@@ -131,25 +134,10 @@ union ChannelDiverterArgs
 //-----------------------------------------------------------------------------
 
 struct RtspChannelConnectArgs
 {
   URIParams uri;
   uint32_t channelId;
 };
 
-//-----------------------------------------------------------------------------
-// WS IPDL structs
-//-----------------------------------------------------------------------------
-
-struct WebSocketLoadInfoArgs
-{
-  PrincipalInfo requestingPrincipalInfo;
-  PrincipalInfo triggeringPrincipalInfo;
-  uint32_t      securityFlags;
-  uint32_t      contentPolicyType;
-  uint64_t      innerWindowID;
-  uint64_t      outerWindowID;
-  uint64_t      parentOuterWindowID;
-};
-
 } // namespace ipc
 } // namespace mozilla
--- a/netwerk/protocol/ftp/FTPChannelChild.cpp
+++ b/netwerk/protocol/ftp/FTPChannelChild.cpp
@@ -136,55 +136,16 @@ NS_IMETHODIMP
 FTPChannelChild::GetUploadStream(nsIInputStream** stream)
 {
   NS_ENSURE_ARG_POINTER(stream);
   *stream = mUploadStream;
   NS_IF_ADDREF(*stream);
   return NS_OK;
 }
 
-//-----------------------------------------------------------------------------
-
-// helper function to assign loadInfo to openArgs
-void
-propagateLoadInfo(nsILoadInfo *aLoadInfo,
-                  FTPChannelOpenArgs& openArgs)
-{
-  mozilla::ipc::PrincipalInfo requestingPrincipalInfo;
-  mozilla::ipc::PrincipalInfo triggeringPrincipalInfo;
-
-  if (aLoadInfo) {
-    mozilla::ipc::PrincipalToPrincipalInfo(aLoadInfo->LoadingPrincipal(),
-                                           &requestingPrincipalInfo);
-    openArgs.requestingPrincipalInfo() = requestingPrincipalInfo;
-
-    mozilla::ipc::PrincipalToPrincipalInfo(aLoadInfo->TriggeringPrincipal(),
-                                           &triggeringPrincipalInfo);
-    openArgs.triggeringPrincipalInfo() = triggeringPrincipalInfo;
-
-    openArgs.securityFlags() = aLoadInfo->GetSecurityFlags();
-    openArgs.contentPolicyType() = aLoadInfo->GetContentPolicyType();
-    openArgs.innerWindowID() = aLoadInfo->GetInnerWindowID();
-    openArgs.outerWindowID() = aLoadInfo->GetOuterWindowID();
-    openArgs.parentOuterWindowID() = aLoadInfo->GetParentOuterWindowID();
-    return;
-  }
-
-  // use default values if no loadInfo is provided
-  mozilla::ipc::PrincipalToPrincipalInfo(nsContentUtils::GetSystemPrincipal(),
-                                         &requestingPrincipalInfo);
-  openArgs.requestingPrincipalInfo() = requestingPrincipalInfo;
-  openArgs.triggeringPrincipalInfo() = requestingPrincipalInfo;
-  openArgs.securityFlags() = nsILoadInfo::SEC_NORMAL;
-  openArgs.contentPolicyType() = nsIContentPolicy::TYPE_OTHER;
-  openArgs.innerWindowID() = 0;
-  openArgs.outerWindowID() = 0;
-  openArgs.parentOuterWindowID() = 0;
-}
-
 NS_IMETHODIMP
 FTPChannelChild::AsyncOpen(::nsIStreamListener* listener, nsISupports* aContext)
 {
   LOG(("FTPChannelChild::AsyncOpen [this=%p]\n", this));
 
   NS_ENSURE_TRUE((gNeckoChild), NS_ERROR_FAILURE);
   NS_ENSURE_ARG_POINTER(listener);
   NS_ENSURE_TRUE(!mIsPending, NS_ERROR_IN_PROGRESS);
@@ -228,17 +189,18 @@ FTPChannelChild::AsyncOpen(::nsIStreamLi
   FTPChannelOpenArgs openArgs;
   SerializeURI(nsBaseChannel::URI(), openArgs.uri());
   openArgs.startPos() = mStartPos;
   openArgs.entityID() = mEntityID;
   openArgs.uploadStream() = uploadStream;
 
   nsCOMPtr<nsILoadInfo> loadInfo;
   GetLoadInfo(getter_AddRefs(loadInfo));
-  propagateLoadInfo(loadInfo, openArgs);
+  rv = mozilla::ipc::LoadInfoToLoadInfoArgs(loadInfo, &openArgs.loadInfo());
+  NS_ENSURE_SUCCESS(rv, rv);
 
   gNeckoChild->
     SendPFTPChannelConstructor(this, tabChild, IPC::SerializedLoadContext(this),
                                openArgs);
 
   // The socket transport layer in the chrome process now has a logical ref to
   // us until OnStopRequest is called.
   AddIPDLReference();
--- a/netwerk/protocol/ftp/FTPChannelParent.cpp
+++ b/netwerk/protocol/ftp/FTPChannelParent.cpp
@@ -83,19 +83,17 @@ NS_IMPL_ISUPPORTS(FTPChannelParent,
 bool
 FTPChannelParent::Init(const FTPChannelCreationArgs& aArgs)
 {
   switch (aArgs.type()) {
   case FTPChannelCreationArgs::TFTPChannelOpenArgs:
   {
     const FTPChannelOpenArgs& a = aArgs.get_FTPChannelOpenArgs();
     return DoAsyncOpen(a.uri(), a.startPos(), a.entityID(), a.uploadStream(),
-                       a.requestingPrincipalInfo(), a.triggeringPrincipalInfo(),
-                       a.securityFlags(), a.contentPolicyType(),
-                       a.innerWindowID(), a.outerWindowID(), a.parentOuterWindowID());
+                       a.loadInfo());
   }
   case FTPChannelCreationArgs::TFTPChannelConnectArgs:
   {
     const FTPChannelConnectArgs& cArgs = aArgs.get_FTPChannelConnectArgs();
     return ConnectChannel(cArgs.channelId());
   }
   default:
     NS_NOTREACHED("unknown open type");
@@ -103,23 +101,17 @@ FTPChannelParent::Init(const FTPChannelC
   }
 }
 
 bool
 FTPChannelParent::DoAsyncOpen(const URIParams& aURI,
                               const uint64_t& aStartPos,
                               const nsCString& aEntityID,
                               const OptionalInputStreamParams& aUploadStream,
-                              const ipc::PrincipalInfo& aRequestingPrincipalInfo,
-                              const ipc::PrincipalInfo& aTriggeringPrincipalInfo,
-                              const uint32_t& aSecurityFlags,
-                              const uint32_t& aContentPolicyType,
-                              const uint64_t& aInnerWindowID,
-                              const uint64_t& aOuterWindowID,
-                              const uint64_t& aParentOuterWindowID)
+                              const LoadInfoArgs& aLoadInfoArgs)
 {
   nsCOMPtr<nsIURI> uri = DeserializeURI(aURI);
   if (!uri)
       return false;
 
 #ifdef DEBUG
   nsCString uriSpec;
   uri->GetSpec(uriSpec);
@@ -138,31 +130,22 @@ FTPChannelParent::DoAsyncOpen(const URIP
   if (app_offline)
     return SendFailedAsyncOpen(NS_ERROR_OFFLINE);
 
   nsresult rv;
   nsCOMPtr<nsIIOService> ios(do_GetIOService(&rv));
   if (NS_FAILED(rv))
     return SendFailedAsyncOpen(rv);
 
-  nsCOMPtr<nsIPrincipal> requestingPrincipal =
-    mozilla::ipc::PrincipalInfoToPrincipal(aRequestingPrincipalInfo, &rv);
+  nsCOMPtr<nsILoadInfo> loadInfo;
+  rv = mozilla::ipc::LoadInfoArgsToLoadInfo(aLoadInfoArgs,
+                                            getter_AddRefs(loadInfo));
   if (NS_FAILED(rv)) {
     return SendFailedAsyncOpen(rv);
   }
-  nsCOMPtr<nsIPrincipal> triggeringPrincipal =
-    mozilla::ipc::PrincipalInfoToPrincipal(aTriggeringPrincipalInfo, &rv);
-  if (NS_FAILED(rv)) {
-    return SendFailedAsyncOpen(rv);
-  }
-
-  nsCOMPtr<nsILoadInfo> loadInfo =
-    new mozilla::LoadInfo(requestingPrincipal, triggeringPrincipal,
-                          aSecurityFlags, aContentPolicyType,
-                          aInnerWindowID, aOuterWindowID, aParentOuterWindowID);
 
   nsCOMPtr<nsIChannel> chan;
   rv = NS_NewChannelInternal(getter_AddRefs(chan), uri, loadInfo,
                              nullptr, nullptr,
                              nsIRequest::LOAD_NORMAL, ios);
 
   if (NS_FAILED(rv))
     return SendFailedAsyncOpen(rv);
--- a/netwerk/protocol/ftp/FTPChannelParent.h
+++ b/netwerk/protocol/ftp/FTPChannelParent.h
@@ -59,23 +59,17 @@ protected:
   nsresult ResumeForDiversion();
 
   // Asynchronously calls NotifyDiversionFailed.
   void FailDiversion(nsresult aErrorCode, bool aSkipResume = true);
 
   bool DoAsyncOpen(const URIParams& aURI, const uint64_t& aStartPos,
                    const nsCString& aEntityID,
                    const OptionalInputStreamParams& aUploadStream,
-                   const ipc::PrincipalInfo& aRequestingPrincipalInfo,
-                   const ipc::PrincipalInfo& aTriggeringPrincipalInfo,
-                   const uint32_t& aSecurityFlags,
-                   const uint32_t& aContentPolicyType,
-                   const uint64_t& aInnerWindowID,
-                   const uint64_t& aOuterWindowID,
-                   const uint64_t& aParentOuterWindowID);
+                   const LoadInfoArgs& aLoadInfoArgs);
 
   // used to connect redirected-to channel in parent with just created
   // ChildChannel.  Used during HTTP->FTP redirects.
   bool ConnectChannel(const uint32_t& channelId);
 
   virtual bool RecvCancel(const nsresult& status) override;
   virtual bool RecvSuspend() override;
   virtual bool RecvResume() override;
--- a/netwerk/protocol/http/HttpChannelChild.cpp
+++ b/netwerk/protocol/http/HttpChannelChild.cpp
@@ -1469,53 +1469,16 @@ HttpChannelChild::Resume()
 
   return rv;
 }
 
 //-----------------------------------------------------------------------------
 // HttpChannelChild::nsIChannel
 //-----------------------------------------------------------------------------
 
-// helper function to assign loadInfo to openArgs
-void
-propagateLoadInfo(nsILoadInfo *aLoadInfo,
-                  HttpChannelOpenArgs& openArgs)
-{
-  mozilla::ipc::PrincipalInfo requestingPrincipalInfo;
-  mozilla::ipc::PrincipalInfo triggeringPrincipalInfo;
-
-  if (aLoadInfo) {
-    mozilla::ipc::PrincipalToPrincipalInfo(aLoadInfo->LoadingPrincipal(),
-                                           &requestingPrincipalInfo);
-    openArgs.requestingPrincipalInfo() = requestingPrincipalInfo;
-
-    mozilla::ipc::PrincipalToPrincipalInfo(aLoadInfo->TriggeringPrincipal(),
-                                           &triggeringPrincipalInfo);
-    openArgs.triggeringPrincipalInfo() = triggeringPrincipalInfo;
-
-    openArgs.securityFlags() = aLoadInfo->GetSecurityFlags();
-    openArgs.contentPolicyType() = aLoadInfo->GetContentPolicyType();
-    openArgs.innerWindowID() = aLoadInfo->GetInnerWindowID();
-    openArgs.outerWindowID() = aLoadInfo->GetOuterWindowID();
-    openArgs.parentOuterWindowID() = aLoadInfo->GetParentOuterWindowID();
-    return;
-  }
-
-  // use default values if no loadInfo is provided
-  mozilla::ipc::PrincipalToPrincipalInfo(nsContentUtils::GetSystemPrincipal(),
-                                         &requestingPrincipalInfo);
-  openArgs.requestingPrincipalInfo() = requestingPrincipalInfo;
-  openArgs.triggeringPrincipalInfo() = requestingPrincipalInfo;
-  openArgs.securityFlags() = nsILoadInfo::SEC_NORMAL;
-  openArgs.contentPolicyType() = nsIContentPolicy::TYPE_OTHER;
-  openArgs.innerWindowID() = 0;
-  openArgs.outerWindowID() = 0;
-  openArgs.parentOuterWindowID() = 0;
-}
-
 NS_IMETHODIMP
 HttpChannelChild::GetSecurityInfo(nsISupports **aSecurityInfo)
 {
   NS_ENSURE_ARG_POINTER(aSecurityInfo);
   NS_IF_ADDREF(*aSecurityInfo = mSecurityInfo);
   return NS_OK;
 }
 
@@ -1710,17 +1673,18 @@ HttpChannelChild::ContinueAsyncOpen()
 
     nsresult rv = container->GetData(&cacheKey);
     if (NS_FAILED(rv)) {
       return rv;
     }
   }
   openArgs.cacheKey() = cacheKey;
 
-  propagateLoadInfo(mLoadInfo, openArgs);
+  nsresult rv = mozilla::ipc::LoadInfoToLoadInfoArgs(mLoadInfo, &openArgs.loadInfo());
+  NS_ENSURE_SUCCESS(rv, rv);
 
   // The socket transport in the chrome process now holds a logical ref to us
   // until OnStopRequest, or we do a redirect, or we hit an IPDL error.
   AddIPDLReference();
 
   PBrowserOrId browser = static_cast<ContentChild*>(gNeckoChild->Manager())
                          ->GetBrowserOrId(tabChild);
   gNeckoChild->SendPHttpChannelConstructor(this, browser,
--- a/netwerk/protocol/http/HttpChannelParent.cpp
+++ b/netwerk/protocol/http/HttpChannelParent.cpp
@@ -115,20 +115,17 @@ HttpChannelParent::Init(const HttpChanne
                        a.referrerPolicy(), a.apiRedirectTo(), a.topWindowURI(),
                        a.loadFlags(), a.requestHeaders(),
                        a.requestMethod(), a.uploadStream(),
                        a.uploadStreamHasHeaders(), a.priority(), a.classOfService(),
                        a.redirectionLimit(), a.allowPipelining(), a.allowSTS(),
                        a.thirdPartyFlags(), a.resumeAt(), a.startPos(),
                        a.entityID(), a.chooseApplicationCache(),
                        a.appCacheClientID(), a.allowSpdy(), a.allowAltSvc(), a.fds(),
-                       a.requestingPrincipalInfo(), a.triggeringPrincipalInfo(),
-                       a.securityFlags(), a.contentPolicyType(),
-                       a.innerWindowID(), a.outerWindowID(), a.parentOuterWindowID(),
-                       a.synthesizedResponseHead(), a.cacheKey());
+                       a.loadInfo(), a.synthesizedResponseHead(), a.cacheKey());
   }
   case HttpChannelCreationArgs::THttpChannelConnectArgs:
   {
     const HttpChannelConnectArgs& cArgs = aArgs.get_HttpChannelConnectArgs();
     return ConnectChannel(cArgs.channelId(), cArgs.shouldIntercept());
   }
   default:
     NS_NOTREACHED("unknown open type");
@@ -272,23 +269,17 @@ HttpChannelParent::DoAsyncOpen(  const U
                                  const bool&                doResumeAt,
                                  const uint64_t&            startPos,
                                  const nsCString&           entityID,
                                  const bool&                chooseApplicationCache,
                                  const nsCString&           appCacheClientID,
                                  const bool&                allowSpdy,
                                  const bool&                allowAltSvc,
                                  const OptionalFileDescriptorSet& aFds,
-                                 const ipc::PrincipalInfo&  aRequestingPrincipalInfo,
-                                 const ipc::PrincipalInfo&  aTriggeringPrincipalInfo,
-                                 const uint32_t&            aSecurityFlags,
-                                 const uint32_t&            aContentPolicyType,
-                                 const uint64_t&            aInnerWindowID,
-                                 const uint64_t&            aOuterWindowID,
-                                 const uint64_t&            aParentOuterWindowID,
+                                 const LoadInfoArgs&        aLoadInfoArgs,
                                  const OptionalHttpResponseHead& aSynthesizedResponseHead,
                                  const uint32_t&            aCacheKey)
 {
   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;
@@ -305,45 +296,36 @@ HttpChannelParent::DoAsyncOpen(  const U
        this, uriSpec.get()));
 
   nsresult rv;
 
   nsCOMPtr<nsIIOService> ios(do_GetIOService(&rv));
   if (NS_FAILED(rv))
     return SendFailedAsyncOpen(rv);
 
-  nsCOMPtr<nsIPrincipal> requestingPrincipal =
-    mozilla::ipc::PrincipalInfoToPrincipal(aRequestingPrincipalInfo, &rv);
-  if (NS_FAILED(rv)) {
-    return SendFailedAsyncOpen(rv);
-  }
-  nsCOMPtr<nsIPrincipal> triggeringPrincipal =
-    mozilla::ipc::PrincipalInfoToPrincipal(aTriggeringPrincipalInfo, &rv);
-  if (NS_FAILED(rv)) {
-    return SendFailedAsyncOpen(rv);
-  }
-
   bool appOffline = false;
   uint32_t appId = GetAppId();
   if (appId != NECKO_UNKNOWN_APP_ID &&
       appId != NECKO_NO_APP_ID) {
     gIOService->IsAppOffline(appId, &appOffline);
   }
 
   uint32_t loadFlags = aLoadFlags;
   if (appOffline) {
     loadFlags |= nsICachingChannel::LOAD_ONLY_FROM_CACHE;
     loadFlags |= nsIRequest::LOAD_FROM_CACHE;
     loadFlags |= nsICachingChannel::LOAD_NO_NETWORK_IO;
   }
 
-  nsCOMPtr<nsILoadInfo> loadInfo =
-    new mozilla::LoadInfo(requestingPrincipal, triggeringPrincipal,
-                          aSecurityFlags, aContentPolicyType,
-                          aInnerWindowID, aOuterWindowID, aParentOuterWindowID);
+  nsCOMPtr<nsILoadInfo> loadInfo;
+  rv = mozilla::ipc::LoadInfoArgsToLoadInfo(aLoadInfoArgs,
+                                            getter_AddRefs(loadInfo));
+  if (NS_FAILED(rv)) {
+    return SendFailedAsyncOpen(rv);
+  }
 
   nsCOMPtr<nsIChannel> channel;
   rv = NS_NewChannelInternal(getter_AddRefs(channel), uri, loadInfo,
                              nullptr, nullptr, loadFlags, ios);
 
   if (NS_FAILED(rv))
     return SendFailedAsyncOpen(rv);
 
--- a/netwerk/protocol/http/HttpChannelParent.h
+++ b/netwerk/protocol/http/HttpChannelParent.h
@@ -111,23 +111,17 @@ protected:
                    const bool&                doResumeAt,
                    const uint64_t&            startPos,
                    const nsCString&           entityID,
                    const bool&                chooseApplicationCache,
                    const nsCString&           appCacheClientID,
                    const bool&                allowSpdy,
                    const bool&                allowAltSvc,
                    const OptionalFileDescriptorSet& aFds,
-                   const ipc::PrincipalInfo&  aRequestingPrincipalInfo,
-                   const ipc::PrincipalInfo&  aTriggeringPrincipalInfo,
-                   const uint32_t&            aSecurityFlags,
-                   const uint32_t&            aContentPolicyType,
-                   const uint64_t&            aInnerWindowID,
-                   const uint64_t&            aOuterWindowID,
-                   const uint64_t&            aParentOuterWindowID,
+                   const LoadInfoArgs&        aLoadInfoArgs,
                    const OptionalHttpResponseHead& aSynthesizedResponseHead,
                    const uint32_t&            aCacheKey);
 
   virtual bool RecvSetPriority(const uint16_t& priority) override;
   virtual bool RecvSetClassOfService(const uint32_t& cos) override;
   virtual bool RecvSetCacheTokenCachedCharset(const nsCString& charset) override;
   virtual bool RecvSuspend() override;
   virtual bool RecvResume() override;
--- a/netwerk/protocol/websocket/PWebSocket.ipdl
+++ b/netwerk/protocol/websocket/PWebSocket.ipdl
@@ -28,17 +28,17 @@ parent:
             nsCString aOrigin,
             nsCString aProtocol,
             bool aSecure,
             // ping values only meaningful if client set them
             uint32_t aPingInterval,
             bool aClientSetPingInterval,
             uint32_t aPingTimeout,
             bool aClientSetPingTimeout,
-            WebSocketLoadInfoArgs aLoadInfoArgs);
+            LoadInfoArgs aLoadInfoArgs);
   Close(uint16_t code, nsCString reason);
   SendMsg(nsCString aMsg);
   SendBinaryMsg(nsCString aMsg);
   SendBinaryStream(InputStreamParams aStream, uint32_t aLength);
 
   DeleteSelf();
 
 child:
--- a/netwerk/protocol/websocket/WebSocketChannelChild.cpp
+++ b/netwerk/protocol/websocket/WebSocketChannelChild.cpp
@@ -448,37 +448,16 @@ WebSocketChannelChild::OnServerClose(con
   LOG(("WebSocketChannelChild::RecvOnServerClose() %p\n", this));
   if (mListenerMT) {
     AutoEventEnqueuer ensureSerialDispatch(mEventQ);
     mListenerMT->mListener->OnServerClose(mListenerMT->mContext, aCode,
                                           aReason);
   }
 }
 
-// helper function to assign loadInfo to wsArgs
-void
-propagateLoadInfo(nsILoadInfo *aLoadInfo,
-                  WebSocketLoadInfoArgs& wsArgs)
-{
-  mozilla::ipc::PrincipalInfo requestingPrincipalInfo;
-  mozilla::ipc::PrincipalInfo triggeringPrincipalInfo;
-
-  mozilla::ipc::PrincipalToPrincipalInfo(aLoadInfo->LoadingPrincipal(),
-                                         &requestingPrincipalInfo);
-  wsArgs.requestingPrincipalInfo() = requestingPrincipalInfo;
-  mozilla::ipc::PrincipalToPrincipalInfo(aLoadInfo->TriggeringPrincipal(),
-                                         &triggeringPrincipalInfo);
-  wsArgs.triggeringPrincipalInfo() = triggeringPrincipalInfo;
-  wsArgs.securityFlags() = aLoadInfo->GetSecurityFlags();
-  wsArgs.contentPolicyType() = aLoadInfo->GetContentPolicyType();
-  wsArgs.innerWindowID() = aLoadInfo->GetInnerWindowID();
-  wsArgs.outerWindowID() = aLoadInfo->GetOuterWindowID();
-  wsArgs.parentOuterWindowID() = aLoadInfo->GetParentOuterWindowID();
-}
-
 NS_IMETHODIMP
 WebSocketChannelChild::AsyncOpen(nsIURI *aURI,
                                  const nsACString &aOrigin,
                                  nsIWebSocketListener *aListener,
                                  nsISupports *aContext)
 {
   LOG(("WebSocketChannelChild::AsyncOpen() %p\n", this));
 
@@ -499,24 +478,25 @@ WebSocketChannelChild::AsyncOpen(nsIURI 
   }
 
   URIParams uri;
   SerializeURI(aURI, uri);
 
   // Corresponding release in DeallocPWebSocket
   AddIPDLReference();
 
-  WebSocketLoadInfoArgs wsArgs;
-  propagateLoadInfo(mLoadInfo, wsArgs);
+  LoadInfoArgs loadInfoArgs;
+  nsresult rv = LoadInfoToLoadInfoArgs(mLoadInfo, &loadInfoArgs);
+  NS_ENSURE_SUCCESS(rv, rv);
 
   gNeckoChild->SendPWebSocketConstructor(this, tabChild,
                                          IPC::SerializedLoadContext(this));
   if (!SendAsyncOpen(uri, nsCString(aOrigin), mProtocol, mEncrypted,
                      mPingInterval, mClientSetPingInterval,
-                     mPingResponseTimeout, mClientSetPingTimeout, wsArgs)) {
+                     mPingResponseTimeout, mClientSetPingTimeout, loadInfoArgs)) {
     return NS_ERROR_UNEXPECTED;
   }
 
   mOriginalURI = aURI;
   mURI = mOriginalURI;
   mListenerMT = new ListenerAndContextContainer(aListener, aContext);
   mOrigin = aOrigin;
   mWasOpened = 1;
--- a/netwerk/protocol/websocket/WebSocketChannelParent.cpp
+++ b/netwerk/protocol/websocket/WebSocketChannelParent.cpp
@@ -61,23 +61,22 @@ bool
 WebSocketChannelParent::RecvAsyncOpen(const URIParams& aURI,
                                       const nsCString& aOrigin,
                                       const nsCString& aProtocol,
                                       const bool& aSecure,
                                       const uint32_t& aPingInterval,
                                       const bool& aClientSetPingInterval,
                                       const uint32_t& aPingTimeout,
                                       const bool& aClientSetPingTimeout,
-                                      const WebSocketLoadInfoArgs& aLoadInfoArgs)
+                                      const LoadInfoArgs& aLoadInfoArgs)
 {
   LOG(("WebSocketChannelParent::RecvAsyncOpen() %p\n", this));
 
   nsresult rv;
   nsCOMPtr<nsIURI> uri;
-  nsCOMPtr<nsIPrincipal> requestingPrincipal, triggeringPrincipal;
   nsCOMPtr<nsILoadInfo> loadInfo;
 
   bool appOffline = false;
   uint32_t appId = GetAppId();
   if (appId != NECKO_UNKNOWN_APP_ID &&
       appId != NECKO_NO_APP_ID) {
     gIOService->IsAppOffline(appId, &appOffline);
     if (appOffline) {
@@ -90,35 +89,20 @@ WebSocketChannelParent::RecvAsyncOpen(co
       do_CreateInstance("@mozilla.org/network/protocol;1?name=wss", &rv);
   } else {
     mChannel =
       do_CreateInstance("@mozilla.org/network/protocol;1?name=ws", &rv);
   }
   if (NS_FAILED(rv))
     goto fail;
 
-  requestingPrincipal =
-    mozilla::ipc::PrincipalInfoToPrincipal(aLoadInfoArgs.requestingPrincipalInfo(), &rv);
-  if (NS_FAILED(rv)) {
-    goto fail;
-  }
-
-  triggeringPrincipal =
-    mozilla::ipc::PrincipalInfoToPrincipal(aLoadInfoArgs.triggeringPrincipalInfo(), &rv);
-  if (NS_FAILED(rv)) {
+  rv = LoadInfoArgsToLoadInfo(aLoadInfoArgs, getter_AddRefs(loadInfo));
+  if (NS_FAILED(rv))
     goto fail;
-  }
 
-  loadInfo = new LoadInfo(requestingPrincipal,
-                          triggeringPrincipal,
-                          aLoadInfoArgs.securityFlags(),
-                          aLoadInfoArgs.contentPolicyType(),
-                          aLoadInfoArgs.innerWindowID(),
-                          aLoadInfoArgs.outerWindowID(),
-                          aLoadInfoArgs.parentOuterWindowID());
   rv = mChannel->SetLoadInfo(loadInfo);
   if (NS_FAILED(rv)) {
     goto fail;
   }
 
   rv = mChannel->SetNotificationCallbacks(this);
   if (NS_FAILED(rv))
     goto fail;
--- a/netwerk/protocol/websocket/WebSocketChannelParent.h
+++ b/netwerk/protocol/websocket/WebSocketChannelParent.h
@@ -41,17 +41,17 @@ class WebSocketChannelParent : public PW
   bool RecvAsyncOpen(const URIParams& aURI,
                      const nsCString& aOrigin,
                      const nsCString& aProtocol,
                      const bool& aSecure,
                      const uint32_t& aPingInterval,
                      const bool& aClientSetPingInterval,
                      const uint32_t& aPingTimeout,
                      const bool& aClientSetPingTimeout,
-                     const WebSocketLoadInfoArgs& aLoadInfoArgs) override;
+                     const LoadInfoArgs& aLoadInfoArgs) override;
   bool RecvClose(const uint16_t & code, const nsCString & reason) override;
   bool RecvSendMsg(const nsCString& aMsg) override;
   bool RecvSendBinaryMsg(const nsCString& aMsg) override;
   bool RecvSendBinaryStream(const InputStreamParams& aStream,
                             const uint32_t& aLength) override;
   bool RecvDeleteSelf() override;
 
   void ActorDestroy(ActorDestroyReason why) override;