diff --git a/netwerk/base/LoadInfo.cpp b/netwerk/base/LoadInfo.cpp index 9b7747dbc340..80be5951f468 100644 --- a/netwerk/base/LoadInfo.cpp +++ b/netwerk/base/LoadInfo.cpp @@ -83,6 +83,21 @@ LoadInfo::LoadInfo(nsIPrincipal* aLoadingPrincipal, } } +LoadInfo::LoadInfo(const LoadInfo& rhs) + : mLoadingPrincipal(rhs.mLoadingPrincipal) + , mTriggeringPrincipal(rhs.mTriggeringPrincipal) + , mLoadingContext(rhs.mLoadingContext) + , mSecurityFlags(rhs.mSecurityFlags) + , mContentPolicyType(rhs.mContentPolicyType) + , mUpgradeInsecureRequests(rhs.mUpgradeInsecureRequests) + , mInnerWindowID(rhs.mInnerWindowID) + , mOuterWindowID(rhs.mOuterWindowID) + , mParentOuterWindowID(rhs.mParentOuterWindowID) + , mEnforceSecurity(false) + , mInitialSecurityCheckDone(false) +{ +} + LoadInfo::LoadInfo(nsIPrincipal* aLoadingPrincipal, nsIPrincipal* aTriggeringPrincipal, nsSecurityFlags aSecurityFlags, @@ -117,6 +132,13 @@ LoadInfo::~LoadInfo() NS_IMPL_ISUPPORTS(LoadInfo, nsILoadInfo) +already_AddRefed +LoadInfo::Clone() const +{ + nsRefPtr copy(new LoadInfo(*this)); + return copy.forget(); +} + NS_IMETHODIMP LoadInfo::GetLoadingPrincipal(nsIPrincipal** aLoadingPrincipal) { diff --git a/netwerk/base/LoadInfo.h b/netwerk/base/LoadInfo.h index 799e8f144b72..cad67a47f8d2 100644 --- a/netwerk/base/LoadInfo.h +++ b/netwerk/base/LoadInfo.h @@ -50,6 +50,8 @@ public: nsSecurityFlags aSecurityFlags, nsContentPolicyType aContentPolicyType); + already_AddRefed Clone() const; + private: // private constructor that is only allowed to be called from within // HttpChannelParent and FTPChannelParent declared as friends undeneath. @@ -66,6 +68,7 @@ private: bool aEnforceSecurity, bool aInitialSecurityCheckDone, nsTArray>& aRedirectChain); + LoadInfo(const LoadInfo& rhs); friend nsresult mozilla::ipc::LoadInfoArgsToLoadInfo( diff --git a/netwerk/protocol/http/nsCORSListenerProxy.cpp b/netwerk/protocol/http/nsCORSListenerProxy.cpp index 6b154a90fe36..8bf4f132d5d1 100644 --- a/netwerk/protocol/http/nsCORSListenerProxy.cpp +++ b/netwerk/protocol/http/nsCORSListenerProxy.cpp @@ -41,6 +41,7 @@ #include "nsINetworkInterceptController.h" #include "nsNullPrincipal.h" #include "nsICorsPreflightCallback.h" +#include "mozilla/LoadInfo.h" #include using namespace mozilla; @@ -1310,12 +1311,15 @@ nsCORSListenerProxy::StartCORSPreflight(nsIChannel* aRequestChannel, nsresult rv = NS_GetFinalChannelURI(aRequestChannel, getter_AddRefs(uri)); NS_ENSURE_SUCCESS(rv, rv); - nsCOMPtr loadInfo = aRequestChannel->GetLoadInfo(); - MOZ_ASSERT(loadInfo, "can not perform CORS preflight without a loadInfo"); - if (!loadInfo) { + nsCOMPtr originalLoadInfo = aRequestChannel->GetLoadInfo(); + MOZ_ASSERT(originalLoadInfo, "can not perform CORS preflight without a loadInfo"); + if (!originalLoadInfo) { return NS_ERROR_FAILURE; } + nsCOMPtr loadInfo = static_cast + (originalLoadInfo.get())->Clone(); + nsSecurityFlags securityMode = loadInfo->GetSecurityMode(); MOZ_ASSERT(securityMode == 0 ||