From 1fe4e1e1491eeb81447a702075fd78d22ec9cea3 Mon Sep 17 00:00:00 2001 From: Christoph Kerschbaumer Date: Mon, 13 Jul 2015 22:43:13 -0700 Subject: [PATCH] Bug 1179505 - Make LoadInfo arguments optional in ipdl (r=bent,sicking) --- ipc/glue/BackgroundUtils.cpp | 88 +++++++++++-------- ipc/glue/BackgroundUtils.h | 10 +-- netwerk/base/LoadInfo.h | 9 +- netwerk/ipc/NeckoChannelParams.ipdlh | 13 ++- netwerk/protocol/ftp/FTPChannelParent.cpp | 2 +- netwerk/protocol/ftp/FTPChannelParent.h | 2 +- netwerk/protocol/http/HttpChannelParent.cpp | 2 +- netwerk/protocol/http/HttpChannelParent.h | 2 +- netwerk/protocol/websocket/PWebSocket.ipdl | 2 +- .../websocket/WebSocketChannelChild.cpp | 2 +- .../websocket/WebSocketChannelParent.cpp | 2 +- .../websocket/WebSocketChannelParent.h | 2 +- 12 files changed, 78 insertions(+), 58 deletions(-) diff --git a/ipc/glue/BackgroundUtils.cpp b/ipc/glue/BackgroundUtils.cpp index fdc0f0dc137..19dc5580aa9 100644 --- a/ipc/glue/BackgroundUtils.cpp +++ b/ipc/glue/BackgroundUtils.cpp @@ -18,6 +18,12 @@ #include "nsString.h" namespace mozilla { +namespace net { +class OptionalLoadInfoArgs; +} + +using namespace mozilla::net; + namespace ipc { already_AddRefed @@ -220,66 +226,70 @@ PrincipalToPrincipalInfo(nsIPrincipal* aPrincipal, 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()); + nsresult rv = NS_OK; + PrincipalInfo requestingPrincipalInfo; + rv = PrincipalToPrincipalInfo(aLoadInfo->LoadingPrincipal(), + &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->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 requestingPrincipal = - PrincipalInfoToPrincipal(aLoadInfoArgs.requestingPrincipalInfo(), &rv); + PrincipalInfoToPrincipal(loadInfoArgs.requestingPrincipalInfo(), &rv); NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr triggeringPrincipal = - PrincipalInfoToPrincipal(aLoadInfoArgs.triggeringPrincipalInfo(), &rv); + PrincipalInfoToPrincipal(loadInfoArgs.triggeringPrincipalInfo(), &rv); NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr 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 diff --git a/ipc/glue/BackgroundUtils.h b/ipc/glue/BackgroundUtils.h index 8848f313b74..62d16a2187a 100644 --- a/ipc/glue/BackgroundUtils.h +++ b/ipc/glue/BackgroundUtils.h @@ -40,9 +40,11 @@ struct ParamTraits namespace mozilla { namespace net { -class LoadInfoArgs; +class OptionalLoadInfoArgs; } // namespace net +using namespace mozilla::net; + namespace ipc { class PrincipalInfo; @@ -70,17 +72,15 @@ PrincipalToPrincipalInfo(nsIPrincipal* aPrincipal, */ 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 diff --git a/netwerk/base/LoadInfo.h b/netwerk/base/LoadInfo.h index d0747a89b14..11540469a91 100644 --- a/netwerk/base/LoadInfo.h +++ b/netwerk/base/LoadInfo.h @@ -18,13 +18,13 @@ 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 @@ -64,8 +64,9 @@ private: 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(); diff --git a/netwerk/ipc/NeckoChannelParams.ipdlh b/netwerk/ipc/NeckoChannelParams.ipdlh index b98274fa8f4..195cd6aecd7 100644 --- a/netwerk/ipc/NeckoChannelParams.ipdlh +++ b/netwerk/ipc/NeckoChannelParams.ipdlh @@ -36,6 +36,15 @@ struct LoadInfoArgs uint64_t parentOuterWindowID; }; +/** + * Not every channel necessarily has a loadInfo attached. + */ +union OptionalLoadInfoArgs +{ + void_t; + LoadInfoArgs; +}; + //----------------------------------------------------------------------------- // HTTP IPDL structs //----------------------------------------------------------------------------- @@ -77,7 +86,7 @@ struct HttpChannelOpenArgs bool allowSpdy; bool allowAltSvc; OptionalFileDescriptorSet fds; - LoadInfoArgs loadInfo; + OptionalLoadInfoArgs loadInfo; OptionalHttpResponseHead synthesizedResponseHead; uint32_t cacheKey; }; @@ -104,7 +113,7 @@ struct FTPChannelOpenArgs uint64_t startPos; nsCString entityID; OptionalInputStreamParams uploadStream; - LoadInfoArgs loadInfo; + OptionalLoadInfoArgs loadInfo; }; struct FTPChannelConnectArgs diff --git a/netwerk/protocol/ftp/FTPChannelParent.cpp b/netwerk/protocol/ftp/FTPChannelParent.cpp index c921ae71ca4..aaa13136523 100644 --- a/netwerk/protocol/ftp/FTPChannelParent.cpp +++ b/netwerk/protocol/ftp/FTPChannelParent.cpp @@ -107,7 +107,7 @@ FTPChannelParent::DoAsyncOpen(const URIParams& aURI, const uint64_t& aStartPos, const nsCString& aEntityID, const OptionalInputStreamParams& aUploadStream, - const LoadInfoArgs& aLoadInfoArgs) + const OptionalLoadInfoArgs& aLoadInfoArgs) { nsCOMPtr uri = DeserializeURI(aURI); if (!uri) diff --git a/netwerk/protocol/ftp/FTPChannelParent.h b/netwerk/protocol/ftp/FTPChannelParent.h index 3d70443ff76..db5be931e1d 100644 --- a/netwerk/protocol/ftp/FTPChannelParent.h +++ b/netwerk/protocol/ftp/FTPChannelParent.h @@ -65,7 +65,7 @@ protected: 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. diff --git a/netwerk/protocol/http/HttpChannelParent.cpp b/netwerk/protocol/http/HttpChannelParent.cpp index a7276d2bfd4..9f251d58378 100644 --- a/netwerk/protocol/http/HttpChannelParent.cpp +++ b/netwerk/protocol/http/HttpChannelParent.cpp @@ -274,7 +274,7 @@ HttpChannelParent::DoAsyncOpen( const URIParams& aURI, const bool& allowSpdy, const bool& allowAltSvc, const OptionalFileDescriptorSet& aFds, - const LoadInfoArgs& aLoadInfoArgs, + const OptionalLoadInfoArgs& aLoadInfoArgs, const OptionalHttpResponseHead& aSynthesizedResponseHead, const uint32_t& aCacheKey) { diff --git a/netwerk/protocol/http/HttpChannelParent.h b/netwerk/protocol/http/HttpChannelParent.h index fb9274d82f5..e4997b79cd4 100644 --- a/netwerk/protocol/http/HttpChannelParent.h +++ b/netwerk/protocol/http/HttpChannelParent.h @@ -116,7 +116,7 @@ protected: const bool& allowSpdy, const bool& allowAltSvc, const OptionalFileDescriptorSet& aFds, - const LoadInfoArgs& aLoadInfoArgs, + const OptionalLoadInfoArgs& aLoadInfoArgs, const OptionalHttpResponseHead& aSynthesizedResponseHead, const uint32_t& aCacheKey); diff --git a/netwerk/protocol/websocket/PWebSocket.ipdl b/netwerk/protocol/websocket/PWebSocket.ipdl index 6c44c41094b..16e4f7684e1 100644 --- a/netwerk/protocol/websocket/PWebSocket.ipdl +++ b/netwerk/protocol/websocket/PWebSocket.ipdl @@ -33,7 +33,7 @@ parent: bool aClientSetPingInterval, uint32_t aPingTimeout, bool aClientSetPingTimeout, - LoadInfoArgs aLoadInfoArgs); + OptionalLoadInfoArgs aLoadInfoArgs); Close(uint16_t code, nsCString reason); SendMsg(nsCString aMsg); SendBinaryMsg(nsCString aMsg); diff --git a/netwerk/protocol/websocket/WebSocketChannelChild.cpp b/netwerk/protocol/websocket/WebSocketChannelChild.cpp index 6316ce09649..51ecf312615 100644 --- a/netwerk/protocol/websocket/WebSocketChannelChild.cpp +++ b/netwerk/protocol/websocket/WebSocketChannelChild.cpp @@ -483,7 +483,7 @@ WebSocketChannelChild::AsyncOpen(nsIURI *aURI, // Corresponding release in DeallocPWebSocket AddIPDLReference(); - LoadInfoArgs loadInfoArgs; + OptionalLoadInfoArgs loadInfoArgs; nsresult rv = LoadInfoToLoadInfoArgs(mLoadInfo, &loadInfoArgs); NS_ENSURE_SUCCESS(rv, rv); diff --git a/netwerk/protocol/websocket/WebSocketChannelParent.cpp b/netwerk/protocol/websocket/WebSocketChannelParent.cpp index 5825df9e8a3..dd479192023 100644 --- a/netwerk/protocol/websocket/WebSocketChannelParent.cpp +++ b/netwerk/protocol/websocket/WebSocketChannelParent.cpp @@ -66,7 +66,7 @@ WebSocketChannelParent::RecvAsyncOpen(const URIParams& aURI, const bool& aClientSetPingInterval, const uint32_t& aPingTimeout, const bool& aClientSetPingTimeout, - const LoadInfoArgs& aLoadInfoArgs) + const OptionalLoadInfoArgs& aLoadInfoArgs) { LOG(("WebSocketChannelParent::RecvAsyncOpen() %p\n", this)); diff --git a/netwerk/protocol/websocket/WebSocketChannelParent.h b/netwerk/protocol/websocket/WebSocketChannelParent.h index 870daef5630..47c09bb8295 100644 --- a/netwerk/protocol/websocket/WebSocketChannelParent.h +++ b/netwerk/protocol/websocket/WebSocketChannelParent.h @@ -46,7 +46,7 @@ class WebSocketChannelParent : public PWebSocketParent, 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;