Bug 1179505 - Make LoadInfo arguments optional in ipdl (r=bent,sicking)
authorChristoph Kerschbaumer <mozilla@christophkerschbaumer.com>
Mon, 13 Jul 2015 22:43:13 -0700
changeset 252711 a29378ef825e59f8042d0cb4b202061130fcbec0
parent 252709 d8f5d0f09eecbaf32089c2f779fbb3b8a2b58816
child 252712 57055f96a040c99dc0f708a1470da3bdb9ffd8ca
push id29043
push userkwierso@gmail.com
push dateTue, 14 Jul 2015 22:12:22 +0000
treeherdermozilla-central@b32e6d86fd89 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbent, sicking
bugs1179505
milestone42.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1179505 - Make LoadInfo arguments optional in ipdl (r=bent,sicking)
ipc/glue/BackgroundUtils.cpp
ipc/glue/BackgroundUtils.h
netwerk/base/LoadInfo.h
netwerk/ipc/NeckoChannelParams.ipdlh
netwerk/protocol/ftp/FTPChannelParent.cpp
netwerk/protocol/ftp/FTPChannelParent.h
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
@@ -13,16 +13,22 @@
 #include "nsIURI.h"
 #include "nsNetUtil.h"
 #include "mozilla/LoadInfo.h"
 #include "nsNullPrincipal.h"
 #include "nsServiceManagerUtils.h"
 #include "nsString.h"
 
 namespace mozilla {
+namespace net {
+class OptionalLoadInfoArgs;
+}
+
+using namespace mozilla::net;
+
 namespace ipc {
 
 already_AddRefed<nsIPrincipal>
 PrincipalInfoToPrincipal(const PrincipalInfo& aPrincipalInfo,
                          nsresult* aOptionalResult)
 {
   MOZ_ASSERT(NS_IsMainThread());
   MOZ_ASSERT(aPrincipalInfo.type() != PrincipalInfo::T__None);
@@ -215,72 +221,76 @@ PrincipalToPrincipalInfo(nsIPrincipal* a
   }
 
   *aPrincipalInfo = ContentPrincipalInfo(appId, isInBrowserElement, spec);
   return NS_OK;
 }
 
 nsresult
 LoadInfoToLoadInfoArgs(nsILoadInfo *aLoadInfo,
-                       mozilla::net::LoadInfoArgs* aLoadInfoArgs)
+                       OptionalLoadInfoArgs* aOptionalLoadInfoArgs)
 {
-  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->upgradeInsecureRequests() = aLoadInfo->GetUpgradeInsecureRequests();
-    aLoadInfoArgs->innerWindowID() = aLoadInfo->GetInnerWindowID();
-    aLoadInfoArgs->outerWindowID() = aLoadInfo->GetOuterWindowID();
-    aLoadInfoArgs->parentOuterWindowID() = aLoadInfo->GetParentOuterWindowID();
+  if (!aLoadInfo) {
+    // if there is no loadInfo, then there is nothing to serialize
+    *aOptionalLoadInfoArgs = void_t();
     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());
+  nsresult rv = NS_OK;
+  PrincipalInfo requestingPrincipalInfo;
+  rv = PrincipalToPrincipalInfo(aLoadInfo->LoadingPrincipal(),
+                                &requestingPrincipalInfo);
   NS_ENSURE_SUCCESS(rv, rv);
-  aLoadInfoArgs->securityFlags() = nsILoadInfo::SEC_NORMAL;
-  aLoadInfoArgs->contentPolicyType() = nsIContentPolicy::TYPE_OTHER;
-  aLoadInfoArgs->upgradeInsecureRequests() = false;
-  aLoadInfoArgs->innerWindowID() = 0;
-  aLoadInfoArgs->outerWindowID() = 0;
-  aLoadInfoArgs->parentOuterWindowID() = 0;
+
+  PrincipalInfo triggeringPrincipalInfo;
+  rv = PrincipalToPrincipalInfo(aLoadInfo->TriggeringPrincipal(),
+                                &triggeringPrincipalInfo);
+
+  *aOptionalLoadInfoArgs =
+    LoadInfoArgs(
+      requestingPrincipalInfo,
+      triggeringPrincipalInfo,
+      aLoadInfo->GetSecurityFlags(),
+      aLoadInfo->GetContentPolicyType(),
+      aLoadInfo->GetUpgradeInsecureRequests(),
+      aLoadInfo->GetInnerWindowID(),
+      aLoadInfo->GetOuterWindowID(),
+      aLoadInfo->GetParentOuterWindowID());
+
   return NS_OK;
 }
 
 nsresult
-LoadInfoArgsToLoadInfo(const mozilla::net::LoadInfoArgs& aLoadInfoArgs,
+LoadInfoArgsToLoadInfo(const OptionalLoadInfoArgs& aOptionalLoadInfoArgs,
                        nsILoadInfo** outLoadInfo)
 {
+  if (aOptionalLoadInfoArgs.type() == OptionalLoadInfoArgs::Tvoid_t) {
+    *outLoadInfo = nullptr;
+    return NS_OK;
+  }
+
+  const LoadInfoArgs& loadInfoArgs =
+    aOptionalLoadInfoArgs.get_LoadInfoArgs();
+
   nsresult rv = NS_OK;
   nsCOMPtr<nsIPrincipal> requestingPrincipal =
-    PrincipalInfoToPrincipal(aLoadInfoArgs.requestingPrincipalInfo(), &rv);
+    PrincipalInfoToPrincipal(loadInfoArgs.requestingPrincipalInfo(), &rv);
   NS_ENSURE_SUCCESS(rv, rv);
   nsCOMPtr<nsIPrincipal> triggeringPrincipal =
-    PrincipalInfoToPrincipal(aLoadInfoArgs.triggeringPrincipalInfo(), &rv);
+    PrincipalInfoToPrincipal(loadInfoArgs.triggeringPrincipalInfo(), &rv);
   NS_ENSURE_SUCCESS(rv, rv);
 
   nsCOMPtr<nsILoadInfo> loadInfo =
     new mozilla::LoadInfo(requestingPrincipal,
                           triggeringPrincipal,
-                          aLoadInfoArgs.securityFlags(),
-                          aLoadInfoArgs.contentPolicyType(),
-                          aLoadInfoArgs.upgradeInsecureRequests(),
-                          aLoadInfoArgs.innerWindowID(),
-                          aLoadInfoArgs.outerWindowID(),
-                          aLoadInfoArgs.parentOuterWindowID());
+                          loadInfoArgs.securityFlags(),
+                          loadInfoArgs.contentPolicyType(),
+                          loadInfoArgs.upgradeInsecureRequests(),
+                          loadInfoArgs.innerWindowID(),
+                          loadInfoArgs.outerWindowID(),
+                          loadInfoArgs.parentOuterWindowID());
 
-  loadInfo.forget(outLoadInfo);
-  return NS_OK;
+   loadInfo.forget(outLoadInfo);
+   return NS_OK;
 }
 
 } // namespace ipc
 } // namespace mozilla
--- a/ipc/glue/BackgroundUtils.h
+++ b/ipc/glue/BackgroundUtils.h
@@ -35,19 +35,21 @@ struct ParamTraits<mozilla::OriginAttrib
            aResult->PopulateFromSuffix(suffix);
   }
 };
 
 } // namespace IPC
 
 namespace mozilla {
 namespace net {
-class LoadInfoArgs;
+class OptionalLoadInfoArgs;
 } // namespace net
 
+using namespace mozilla::net;
+
 namespace ipc {
 
 class PrincipalInfo;
 
 /**
  * Convert a PrincipalInfo to an nsIPrincipal.
  *
  * MUST be called on the main thread only.
@@ -65,23 +67,21 @@ nsresult
 PrincipalToPrincipalInfo(nsIPrincipal* aPrincipal,
                          PrincipalInfo* aPrincipalInfo);
 
 /**
  * Convert a LoadInfo to LoadInfoArgs struct.
  */
 nsresult
 LoadInfoToLoadInfoArgs(nsILoadInfo *aLoadInfo,
-                       mozilla::net::LoadInfoArgs* outLoadInfoArgs);
+                       OptionalLoadInfoArgs* outOptionalLoadInfoArgs);
 
 /**
  * Convert LoadInfoArgs to a LoadInfo.
  */
 nsresult
-LoadInfoArgsToLoadInfo(const mozilla::net::LoadInfoArgs& aLoadInfoArgs,
+LoadInfoArgsToLoadInfo(const OptionalLoadInfoArgs& aOptionalLoadInfoArgs,
                        nsILoadInfo** outLoadInfo);
 
-
-
 } // namespace ipc
 } // namespace mozilla
 
 #endif // mozilla_ipc_backgroundutils_h__
--- a/netwerk/base/LoadInfo.h
+++ b/netwerk/base/LoadInfo.h
@@ -13,23 +13,23 @@
 #include "nsIWeakReferenceUtils.h" // for nsWeakPtr
 #include "nsIURI.h"
 
 class nsINode;
 
 namespace mozilla {
 
 namespace net {
-class LoadInfoArgs;
+class OptionalLoadInfoArgs;
 } // namespace net
 
 namespace ipc {
 // we have to forward declare that function so we can use it as a friend.
 nsresult
-LoadInfoArgsToLoadInfo(const mozilla::net::LoadInfoArgs& aLoadInfoArgs,
+LoadInfoArgsToLoadInfo(const mozilla::net::OptionalLoadInfoArgs& aLoadInfoArgs,
                        nsILoadInfo** outLoadInfo);
 } // namespace ipc
 
 /**
  * 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
@@ -59,18 +59,19 @@ private:
            nsSecurityFlags aSecurityFlags,
            nsContentPolicyType aContentPolicyType,
            bool aUpgradeInsecureRequests,
            uint64_t aInnerWindowID,
            uint64_t aOuterWindowID,
            uint64_t aParentOuterWindowID);
 
   friend nsresult
-  mozilla::ipc::LoadInfoArgsToLoadInfo(const mozilla::net::LoadInfoArgs& aLoadInfoArgs,
-                                       nsILoadInfo** outLoadInfo);
+  mozilla::ipc::LoadInfoArgsToLoadInfo(
+    const mozilla::net::OptionalLoadInfoArgs& 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
@@ -31,16 +31,25 @@ struct LoadInfoArgs
   uint32_t      securityFlags;
   uint32_t      contentPolicyType;
   bool          upgradeInsecureRequests;
   uint64_t      innerWindowID;
   uint64_t      outerWindowID;
   uint64_t      parentOuterWindowID;
 };
 
+/**
+ * Not every channel necessarily has a loadInfo attached.
+ */
+union OptionalLoadInfoArgs
+{
+  void_t;
+  LoadInfoArgs;
+};
+
 //-----------------------------------------------------------------------------
 // HTTP IPDL structs
 //-----------------------------------------------------------------------------
 
 union OptionalHttpResponseHead
 {
   void_t;
   nsHttpResponseHead;
@@ -72,17 +81,17 @@ struct HttpChannelOpenArgs
   bool                        resumeAt;
   uint64_t                    startPos;
   nsCString                   entityID;
   bool                        chooseApplicationCache;
   nsCString                   appCacheClientID;
   bool                        allowSpdy;
   bool                        allowAltSvc;
   OptionalFileDescriptorSet   fds;
-  LoadInfoArgs                loadInfo;
+  OptionalLoadInfoArgs        loadInfo;
   OptionalHttpResponseHead    synthesizedResponseHead;
   uint32_t                    cacheKey;
 };
 
 struct HttpChannelConnectArgs
 {
   uint32_t channelId;
   bool shouldIntercept;
@@ -99,17 +108,17 @@ union HttpChannelCreationArgs
 //-----------------------------------------------------------------------------
 
 struct FTPChannelOpenArgs
 {
   URIParams                 uri;
   uint64_t                  startPos;
   nsCString                 entityID;
   OptionalInputStreamParams uploadStream;
-  LoadInfoArgs              loadInfo;
+  OptionalLoadInfoArgs      loadInfo;
 };
 
 struct FTPChannelConnectArgs
 {
   uint32_t channelId;
 };
 
 union FTPChannelCreationArgs
--- a/netwerk/protocol/ftp/FTPChannelParent.cpp
+++ b/netwerk/protocol/ftp/FTPChannelParent.cpp
@@ -102,17 +102,17 @@ FTPChannelParent::Init(const FTPChannelC
   }
 }
 
 bool
 FTPChannelParent::DoAsyncOpen(const URIParams& aURI,
                               const uint64_t& aStartPos,
                               const nsCString& aEntityID,
                               const OptionalInputStreamParams& aUploadStream,
-                              const LoadInfoArgs& aLoadInfoArgs)
+                              const OptionalLoadInfoArgs& aLoadInfoArgs)
 {
   nsCOMPtr<nsIURI> uri = DeserializeURI(aURI);
   if (!uri)
       return false;
 
 #ifdef DEBUG
   nsCString uriSpec;
   uri->GetSpec(uriSpec);
--- a/netwerk/protocol/ftp/FTPChannelParent.h
+++ b/netwerk/protocol/ftp/FTPChannelParent.h
@@ -60,17 +60,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 LoadInfoArgs& aLoadInfoArgs);
+                   const OptionalLoadInfoArgs& 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/HttpChannelParent.cpp
+++ b/netwerk/protocol/http/HttpChannelParent.cpp
@@ -269,17 +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 LoadInfoArgs&        aLoadInfoArgs,
+                                 const OptionalLoadInfoArgs& 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;
--- a/netwerk/protocol/http/HttpChannelParent.h
+++ b/netwerk/protocol/http/HttpChannelParent.h
@@ -111,17 +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 LoadInfoArgs&        aLoadInfoArgs,
+                   const OptionalLoadInfoArgs& 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,
-            LoadInfoArgs aLoadInfoArgs);
+            OptionalLoadInfoArgs 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
@@ -478,17 +478,17 @@ WebSocketChannelChild::AsyncOpen(nsIURI 
   }
 
   URIParams uri;
   SerializeURI(aURI, uri);
 
   // Corresponding release in DeallocPWebSocket
   AddIPDLReference();
 
-  LoadInfoArgs loadInfoArgs;
+  OptionalLoadInfoArgs 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, loadInfoArgs)) {
--- a/netwerk/protocol/websocket/WebSocketChannelParent.cpp
+++ b/netwerk/protocol/websocket/WebSocketChannelParent.cpp
@@ -61,17 +61,17 @@ 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 LoadInfoArgs& aLoadInfoArgs)
+                                      const OptionalLoadInfoArgs& aLoadInfoArgs)
 {
   LOG(("WebSocketChannelParent::RecvAsyncOpen() %p\n", this));
 
   nsresult rv;
   nsCOMPtr<nsIURI> uri;
   nsCOMPtr<nsILoadInfo> loadInfo;
 
   bool appOffline = false;
--- 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 LoadInfoArgs& aLoadInfoArgs) override;
+                     const OptionalLoadInfoArgs& 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;