зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1071564 - Refactor the code to get the inner window ID from an nsIRequest* without using nsIDOMWindowUtils; r=baku
--HG-- extra : rebase_source : f9f8da4710a20abd675492537dc9a3ac6857b641
This commit is contained in:
Родитель
316cdafd62
Коммит
d8f98482ad
|
@ -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();
|
||||
|
||||
|
|
|
@ -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<nsILoadGroup> loadGroup;
|
||||
nsresult rv = aRequest->GetLoadGroup(getter_AddRefs(loadGroup));
|
||||
|
||||
if (NS_FAILED(rv) || !loadGroup) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIInterfaceRequestor> callbacks;
|
||||
rv = loadGroup->GetNotificationCallbacks(getter_AddRefs(callbacks));
|
||||
if (NS_FAILED(rv) || !callbacks) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsILoadContext> loadContext = do_GetInterface(callbacks);
|
||||
if (!loadContext) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIDOMWindow> window;
|
||||
rv = loadContext->GetAssociatedWindow(getter_AddRefs(window));
|
||||
if (NS_FAILED(rv) || !window) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsPIDOMWindow> 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,
|
||||
|
|
|
@ -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<nsILoadGroup> loadGroup;
|
||||
nsresult rv = aRequest->GetLoadGroup(getter_AddRefs(loadGroup));
|
||||
|
||||
if (NS_FAILED(rv) || !loadGroup) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIInterfaceRequestor> callbacks;
|
||||
rv = loadGroup->GetNotificationCallbacks(getter_AddRefs(callbacks));
|
||||
if (NS_FAILED(rv) || !callbacks) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsILoadContext> loadContext = do_GetInterface(callbacks);
|
||||
if (!loadContext) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIDOMWindow> window;
|
||||
rv = loadContext->GetAssociatedWindow(getter_AddRefs(window));
|
||||
if (NS_FAILED(rv) || !window) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsPIDOMWindow> pwindow = do_QueryInterface(window);
|
||||
if (!pwindow) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
nsPIDOMWindow* inner = pwindow->IsInnerWindow() ? pwindow.get() : pwindow->GetCurrentInnerWindow();
|
||||
|
||||
return inner ? inner->WindowID() : 0;
|
||||
}
|
||||
|
|
|
@ -48,25 +48,7 @@ LogBlockedRequest(nsIRequest* aRequest)
|
|||
nsresult rv = NS_OK;
|
||||
|
||||
// Get the innerWindowID associated with the XMLHTTPRequest
|
||||
uint64_t innerWindowID = 0;
|
||||
|
||||
nsCOMPtr<nsILoadGroup> loadGroup;
|
||||
aRequest->GetLoadGroup(getter_AddRefs(loadGroup));
|
||||
if (loadGroup) {
|
||||
nsCOMPtr<nsIInterfaceRequestor> callbacks;
|
||||
loadGroup->GetNotificationCallbacks(getter_AddRefs(callbacks));
|
||||
if (callbacks) {
|
||||
nsCOMPtr<nsILoadContext> loadContext = do_GetInterface(callbacks);
|
||||
if(loadContext) {
|
||||
nsCOMPtr<nsIDOMWindow> window;
|
||||
loadContext->GetAssociatedWindow(getter_AddRefs(window));
|
||||
if (window) {
|
||||
nsCOMPtr<nsIDOMWindowUtils> du = do_GetInterface(window);
|
||||
du->GetCurrentInnerWindowID(&innerWindowID);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
uint64_t innerWindowID = nsContentUtils::GetInnerWindowID(aRequest);
|
||||
|
||||
if (!innerWindowID) {
|
||||
return NS_ERROR_FAILURE;
|
||||
|
|
Загрузка…
Ссылка в новой задаче