Bug 1207556 - Part 1: Stop reusing the loadinfo in StartCORSPreflight; r=sicking

This commit is contained in:
Ehsan Akhgari 2015-09-24 16:42:02 -04:00
parent e21bd1df78
commit 3414ffd758
3 changed files with 32 additions and 3 deletions

View File

@ -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<nsILoadInfo>
LoadInfo::Clone() const
{
nsRefPtr<LoadInfo> copy(new LoadInfo(*this));
return copy.forget();
}
NS_IMETHODIMP
LoadInfo::GetLoadingPrincipal(nsIPrincipal** aLoadingPrincipal)
{

View File

@ -50,6 +50,8 @@ public:
nsSecurityFlags aSecurityFlags,
nsContentPolicyType aContentPolicyType);
already_AddRefed<nsILoadInfo> 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<nsCOMPtr<nsIPrincipal>>& aRedirectChain);
LoadInfo(const LoadInfo& rhs);
friend nsresult
mozilla::ipc::LoadInfoArgsToLoadInfo(

View File

@ -41,6 +41,7 @@
#include "nsINetworkInterceptController.h"
#include "nsNullPrincipal.h"
#include "nsICorsPreflightCallback.h"
#include "mozilla/LoadInfo.h"
#include <algorithm>
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<nsILoadInfo> loadInfo = aRequestChannel->GetLoadInfo();
MOZ_ASSERT(loadInfo, "can not perform CORS preflight without a loadInfo");
if (!loadInfo) {
nsCOMPtr<nsILoadInfo> originalLoadInfo = aRequestChannel->GetLoadInfo();
MOZ_ASSERT(originalLoadInfo, "can not perform CORS preflight without a loadInfo");
if (!originalLoadInfo) {
return NS_ERROR_FAILURE;
}
nsCOMPtr<nsILoadInfo> loadInfo = static_cast<mozilla::LoadInfo*>
(originalLoadInfo.get())->Clone();
nsSecurityFlags securityMode = loadInfo->GetSecurityMode();
MOZ_ASSERT(securityMode == 0 ||