diff --git a/content/base/public/nsContentUtils.h b/content/base/public/nsContentUtils.h index 8c68acc8ca37..b8f77b15a2fa 100644 --- a/content/base/public/nsContentUtils.h +++ b/content/base/public/nsContentUtils.h @@ -76,6 +76,7 @@ class nsIParser; class nsIParserService; class nsIPresShell; class nsIPrincipal; +class nsIRequest; class nsIRunnable; class nsIScriptContext; class nsIScriptGlobalObject; @@ -2173,6 +2174,11 @@ public: */ static bool IsForbiddenResponseHeader(const nsACString& aHeader); + /** + * Returns the inner window ID for the window associated with a request, + */ + static uint64_t GetInnerWindowID(nsIRequest* aRequest); + private: static bool InitializeEventTable(); diff --git a/content/base/src/nsCSPContext.cpp b/content/base/src/nsCSPContext.cpp index 79152757273f..e573dc69e218 100644 --- a/content/base/src/nsCSPContext.cpp +++ b/content/base/src/nsCSPContext.cpp @@ -18,7 +18,6 @@ #include "nsIDOMHTMLDocument.h" #include "nsIDOMHTMLElement.h" #include "nsIDOMNode.h" -#include "nsIDOMWindowUtils.h" #include "nsIHttpChannel.h" #include "nsIInterfaceRequestor.h" #include "nsIInterfaceRequestorUtils.h" @@ -491,47 +490,6 @@ nsCSPContext::LogViolationDetails(uint16_t aViolationType, #undef CASE_CHECK_AND_REPORT -uint64_t -getInnerWindowID(nsIRequest* aRequest) { - // can't do anything if there's no nsIRequest! - if (!aRequest) { - return 0; - } - - nsCOMPtr loadGroup; - nsresult rv = aRequest->GetLoadGroup(getter_AddRefs(loadGroup)); - - if (NS_FAILED(rv) || !loadGroup) { - return 0; - } - - nsCOMPtr callbacks; - rv = loadGroup->GetNotificationCallbacks(getter_AddRefs(callbacks)); - if (NS_FAILED(rv) || !callbacks) { - return 0; - } - - nsCOMPtr loadContext = do_GetInterface(callbacks); - if (!loadContext) { - return 0; - } - - nsCOMPtr window; - rv = loadContext->GetAssociatedWindow(getter_AddRefs(window)); - if (NS_FAILED(rv) || !window) { - return 0; - } - - nsCOMPtr pwindow = do_QueryInterface(window); - if (!pwindow) { - return 0; - } - - nsPIDOMWindow* inner = pwindow->IsInnerWindow() ? pwindow.get() : pwindow->GetCurrentInnerWindow(); - - return inner ? inner->WindowID() : 0; -} - NS_IMETHODIMP nsCSPContext::SetRequestContext(nsIURI* aSelfURI, nsIURI* aReferrer, @@ -550,7 +508,7 @@ nsCSPContext::SetRequestContext(nsIURI* aSelfURI, NS_ASSERTION(mSelfURI, "No aSelfURI and no URI available from channel in SetRequestContext, can not translate 'self' into actual URI"); if (aChannel) { - mInnerWindowID = getInnerWindowID(aChannel); + mInnerWindowID = nsContentUtils::GetInnerWindowID(aChannel); aChannel->GetLoadGroup(getter_AddRefs(mCallingChannelLoadGroup)); // Storing the nsINode from the LoadInfo of the original channel, diff --git a/content/base/src/nsContentUtils.cpp b/content/base/src/nsContentUtils.cpp index 33358827edd1..c4adf16fdc07 100644 --- a/content/base/src/nsContentUtils.cpp +++ b/content/base/src/nsContentUtils.cpp @@ -137,6 +137,7 @@ #include "nsIParserService.h" #include "nsIPermissionManager.h" #include "nsIPluginHost.h" +#include "nsIRequest.h" #include "nsIRunnable.h" #include "nsIScriptContext.h" #include "nsIScriptError.h" @@ -6963,3 +6964,45 @@ nsContentUtils::IsJavascriptMIMEType(const nsAString& aMIMEType) return false; } + +uint64_t +nsContentUtils::GetInnerWindowID(nsIRequest* aRequest) +{ + // can't do anything if there's no nsIRequest! + if (!aRequest) { + return 0; + } + + nsCOMPtr loadGroup; + nsresult rv = aRequest->GetLoadGroup(getter_AddRefs(loadGroup)); + + if (NS_FAILED(rv) || !loadGroup) { + return 0; + } + + nsCOMPtr callbacks; + rv = loadGroup->GetNotificationCallbacks(getter_AddRefs(callbacks)); + if (NS_FAILED(rv) || !callbacks) { + return 0; + } + + nsCOMPtr loadContext = do_GetInterface(callbacks); + if (!loadContext) { + return 0; + } + + nsCOMPtr window; + rv = loadContext->GetAssociatedWindow(getter_AddRefs(window)); + if (NS_FAILED(rv) || !window) { + return 0; + } + + nsCOMPtr pwindow = do_QueryInterface(window); + if (!pwindow) { + return 0; + } + + nsPIDOMWindow* inner = pwindow->IsInnerWindow() ? pwindow.get() : pwindow->GetCurrentInnerWindow(); + + return inner ? inner->WindowID() : 0; +} diff --git a/content/base/src/nsCrossSiteListenerProxy.cpp b/content/base/src/nsCrossSiteListenerProxy.cpp index ab238ea0bfc3..6a2ea5122a4c 100644 --- a/content/base/src/nsCrossSiteListenerProxy.cpp +++ b/content/base/src/nsCrossSiteListenerProxy.cpp @@ -48,25 +48,7 @@ LogBlockedRequest(nsIRequest* aRequest) nsresult rv = NS_OK; // Get the innerWindowID associated with the XMLHTTPRequest - uint64_t innerWindowID = 0; - - nsCOMPtr loadGroup; - aRequest->GetLoadGroup(getter_AddRefs(loadGroup)); - if (loadGroup) { - nsCOMPtr callbacks; - loadGroup->GetNotificationCallbacks(getter_AddRefs(callbacks)); - if (callbacks) { - nsCOMPtr loadContext = do_GetInterface(callbacks); - if(loadContext) { - nsCOMPtr window; - loadContext->GetAssociatedWindow(getter_AddRefs(window)); - if (window) { - nsCOMPtr du = do_GetInterface(window); - du->GetCurrentInnerWindowID(&innerWindowID); - } - } - } - } + uint64_t innerWindowID = nsContentUtils::GetInnerWindowID(aRequest); if (!innerWindowID) { return NS_ERROR_FAILURE;