Bug 1207556 - Part 1: Stop reusing the loadinfo in StartCORSPreflight; r=sicking, a=lizzard
authorEhsan Akhgari <ehsan@mozilla.com>
Thu, 24 Sep 2015 16:42:02 -0400
changeset 297891 2bed87c716f690c7c743d13a387d4d5c73de0d1f
parent 297890 ac18fcc6bb9f96ffe0f6a4db3853f52c79c25d2e
child 297892 0cfc3ec58048a6a849867b2e5c3279c88302246a
push id962
push userjlund@mozilla.com
push dateFri, 04 Dec 2015 23:28:54 +0000
treeherdermozilla-release@23a2d286e80f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssicking, lizzard
bugs1207556
milestone43.0a2
Bug 1207556 - Part 1: Stop reusing the loadinfo in StartCORSPreflight; r=sicking, a=lizzard
netwerk/base/LoadInfo.cpp
netwerk/base/LoadInfo.h
netwerk/protocol/http/nsCORSListenerProxy.cpp
--- a/netwerk/base/LoadInfo.cpp
+++ b/netwerk/base/LoadInfo.cpp
@@ -78,16 +78,31 @@ LoadInfo::LoadInfo(nsIPrincipal* aLoadin
       nsCOMPtr<nsPIDOMWindow> piParent = do_QueryInterface(parent);
       mParentOuterWindowID = piParent->WindowID();
     }
 
     mUpgradeInsecureRequests = aLoadingContext->OwnerDoc()->GetUpgradeInsecureRequests();
   }
 }
 
+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,
                    nsContentPolicyType aContentPolicyType,
                    bool aUpgradeInsecureRequests,
                    uint64_t aInnerWindowID,
                    uint64_t aOuterWindowID,
                    uint64_t aParentOuterWindowID,
@@ -112,16 +127,23 @@ LoadInfo::LoadInfo(nsIPrincipal* aLoadin
 }
 
 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)
 {
   NS_ADDREF(*aLoadingPrincipal = mLoadingPrincipal);
   return NS_OK;
 }
 
 nsIPrincipal*
--- a/netwerk/base/LoadInfo.h
+++ b/netwerk/base/LoadInfo.h
@@ -45,32 +45,35 @@ public:
 
   // aLoadingPrincipal MUST NOT BE NULL.
   LoadInfo(nsIPrincipal* aLoadingPrincipal,
            nsIPrincipal* aTriggeringPrincipal,
            nsINode* aLoadingContext,
            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.
   // In e10s we can not serialize nsINode, hence we store the innerWindowID.
   // Please note that aRedirectChain uses swapElements.
   LoadInfo(nsIPrincipal* aLoadingPrincipal,
            nsIPrincipal* aTriggeringPrincipal,
            nsSecurityFlags aSecurityFlags,
            nsContentPolicyType aContentPolicyType,
            bool aUpgradeInsecureRequests,
            uint64_t aInnerWindowID,
            uint64_t aOuterWindowID,
            uint64_t aParentOuterWindowID,
            bool aEnforceSecurity,
            bool aInitialSecurityCheckDone,
            nsTArray<nsCOMPtr<nsIPrincipal>>& aRedirectChain);
+  LoadInfo(const LoadInfo& rhs);
 
   friend nsresult
   mozilla::ipc::LoadInfoArgsToLoadInfo(
     const mozilla::net::OptionalLoadInfoArgs& aLoadInfoArgs,
     nsILoadInfo** outLoadInfo);
 
   ~LoadInfo();
 
--- a/netwerk/protocol/http/nsCORSListenerProxy.cpp
+++ b/netwerk/protocol/http/nsCORSListenerProxy.cpp
@@ -36,16 +36,17 @@
 #include "nsILoadContext.h"
 #include "nsIConsoleService.h"
 #include "nsIDOMNode.h"
 #include "nsIDOMWindowUtils.h"
 #include "nsIDOMWindow.h"
 #include "nsINetworkInterceptController.h"
 #include "nsNullPrincipal.h"
 #include "nsICorsPreflightCallback.h"
+#include "mozilla/LoadInfo.h"
 #include <algorithm>
 
 using namespace mozilla;
 
 #define PREFLIGHT_CACHE_SIZE 100
 
 static bool gDisableCORS = false;
 static bool gDisableCORSPrivateData = false;
@@ -1305,22 +1306,25 @@ nsCORSListenerProxy::StartCORSPreflight(
   nsCOMPtr<nsIHttpChannel> httpChannel(do_QueryInterface(aRequestChannel));
   NS_ENSURE_TRUE(httpChannel, NS_ERROR_UNEXPECTED);
   httpChannel->GetRequestMethod(method);
 
   nsCOMPtr<nsIURI> uri;
   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 ||
              securityMode == nsILoadInfo::SEC_REQUIRE_CORS_DATA_INHERITS,
              "how did we end up here?");
 
   nsPreflightCache::CacheEntry* entry =
     sPreflightCache ?